Add uses/delete_unsuccessful_workflow_runs.py: a script that paginates GitHub Actions workflow runs and deletes any run whose conclusion is not 'success'. It prints per-run actions and totals (checked, deleted, kept). Requires a Personal Access Token with 'repo' and 'workflow' scopes and user configuration of OWNER, REPO, and TOKEN. Useful for cleaning failed/cancelled/timed-out runs while preserving successful history.
GitHub REST API Use
A collection of Python scripts demonstrating practical uses of the GitHub REST API for repository management and automation.
Overview
This repository contains ready-to-use Python scripts for common GitHub repository management tasks that can be performed using the GitHub REST API. These scripts help automate repetitive tasks and streamline repository workflows.
Requirements
- Python 3.6+
requestslibrary:pip install requests- GitHub Personal Access Token (PAT) with appropriate permissions
Setup
-
Clone this repository:
git clone https://github.com/username/gh-api-use.git cd gh-api-use -
Install the required Python package:
pip install requests -
Create a GitHub Personal Access Token:
- Go to GitHub > Settings > Developer settings > Personal access tokens
- Generate a new token with the necessary permissions (usually
reposcope) - Copy your token for use in the scripts
Usage
Each script follows a similar pattern:
-
Open the script you want to use and replace the configuration variables:
TOKEN: Your GitHub Personal Access TokenOWNER: Your GitHub username or organization nameREPO: Target repository name- Other script-specific settings
-
Run the script:
python uses/script_name.py -
Check the console output for results
Permissions
Different scripts require different token scopes:
repo- For repository operations (all scripts)workflow- For GitHub Actions workflow operationsadmin- For repository administration tasks
Contributing
Contributions are welcome! Please feel free to submit a pull request.
License
Copyright © Xi Xu
Licensed under the GPL-3.0 license.