- Notifications
You must be signed in to change notification settings - Fork35
Find stale repositories in a GitHub organization.
License
github/stale-repos
Folders and files
Name | Name | Last commit message | Last commit date | |
---|---|---|---|---|
Repository files navigation
(Used by thegithub
organization!)
This project identifies and reports repositories with no activity for configurable amount of time, in order to surface inactive repos to be considered for archival.The current approach assumes that the repos that you want to evaluate are available in a single GitHub organization.For the purpose of this action, a repository is considered inactive if it has not had apush
in a configurable amount of days (can also be configured to determine activity based on default branch. SeeACTIVITY_METHOD
for more details.).
This action was developed by GitHub so that we can keep our open source projects well maintained, and it was made open source in the hopes that it would help you too!We are actively using and are archiving things in batches since there are many repositories on our report.To find out more about how GitHub manages its open source, check out thegithub-ospo repository.
If you are looking to identify stale pull requests and issues, check outactions/stale
If you need support using this project or have questions about it, pleaseopen up an issue in this repository.Requests made directly to GitHub staff or support team will be redirected here to open an issue.GitHub SLA's and support/services contracts do not apply to this repository.
All feedback regarding our GitHub Actions, as a whole, should be communicated throughissues on our github-ospo repository.
- Create a repository to host this GitHub Action or select an existing repository.
- Create the env values from the sample workflow below (
GH_TOKEN
,ORGANIZATION
,EXEMPT_TOPICS
) with your information as plain text or repository secrets. More info oncreating secrets.Note: Your GitHub token will need to have read access to all the repositories in the organization that you want evaluated - Copy the below example workflow to your repository and put it in the
.github/workflows/
directory with the file extension.yml
(ie..github/workflows/stale_repos.yml
)
Below are the allowed configuration options:
This action can be configured to authenticate with GitHub App Installation or Personal Access Token (PAT). If all configuration options are provided, the GitHub App Installation configuration has precedence. You can choose one of the following methods to authenticate:
field | required | default | description |
---|---|---|---|
GH_APP_ID | True | "" | GitHub Application ID. Seedocumentation for more details. |
GH_APP_INSTALLATION_ID | True | "" | GitHub Application Installation ID. Seedocumentation for more details. |
GH_APP_PRIVATE_KEY | True | "" | GitHub Application Private Key. Seedocumentation for more details. |
GITHUB_APP_ENTERPRISE_ONLY | False | false | Set this input totrue if your app is created in GHE and communicates with GHE. |
field | required | default | description |
---|---|---|---|
GH_TOKEN | True | "" | The GitHub Token used to scan the repository. Must have read access to all repository you are interested in scanning. |
field | required | default | description |
---|---|---|---|
ACTIVITY_METHOD | false | "pushed" | How to get the last active date of the repository. Defaults topushed , which is the last time any branch had a push. Can also be set todefault_branch_updated to instead measure from the latest commit on the default branch (good for filtering out dependabot ) |
GH_ENTERPRISE_URL | false | "" | URL of GitHub Enterprise instance to use for auth instead of github.com |
INACTIVE_DAYS | true | The number of days used to determine if repository is stale, based onpush events | |
EXEMPT_REPOS | false | Comma separated list of repositories to exempt from being flagged as stale. Supports Unix shell-style wildcards. ie.EXEMPT_REPOS = "stale-repos,test-repo,conf-*" | |
EXEMPT_TOPICS | false | Comma separated list of topics to exempt from being flagged as stale | |
ORGANIZATION | false | The organization to scan for stale repositories. If no organization is provided, this tool will search through repositories owned by the GH_TOKEN owner | |
ADDITIONAL_METRICS | false | Configure additional metrics like days since last release or days since last pull request. This allows for more detailed reporting on repository activity. To include both metrics, setADDITIONAL_METRICS: "release,pr" | |
SKIP_EMPTY_REPORTS | false | true | Skips report creation when no stale repositories are identified. Setting this input tofalse means reports are always created, even when they contain no results. |
WORKFLOW_SUMMARY_ENABLED | false | false | When set totrue , automatically adds the stale repository report to the GitHub Actions workflow summary. This eliminates the need to manually add a step to display the Markdown content in the workflow summary. |
name:stale repo identifieron:workflow_dispatch:schedule: -cron:"3 2 1 * *"permissions:contents:readjobs:build:name:stale repo identifierruns-on:ubuntu-latestpermissions:contents:readissues:writesteps: -uses:actions/checkout@v4 -name:Run stale_repos tooluses:github/stale-repos@v6env:GH_TOKEN:${{ secrets.GH_TOKEN }}ORGANIZATION:${{ secrets.ORGANIZATION }}EXEMPT_TOPICS:"keep,template"INACTIVE_DAYS:365ACTIVITY_METHOD:"pushed"ADDITIONAL_METRICS:"release,pr"# This next step updates an existing issue. If you want a new issue every time, remove this step and remove the `issue-number: ${{ env.issue_number }}` line below. -name:Check for the stale report issuerun:| ISSUE_NUMBER=$(gh search issues "Stale-repository-report" --match title --json number --jq ".[0].number") echo "issue_number=$ISSUE_NUMBER" >> "$GITHUB_ENV"env:GH_TOKEN:${{ secrets.GITHUB_TOKEN }} -name:Create issueuses:peter-evans/create-issue-from-file@v5with:issue-number:${{ env.issue_number }}title:Stale-repository-reportcontent-filepath:./stale_repos.mdassignees:<YOUR_GITHUB_HANDLE_HERE>token:${{ secrets.GITHUB_TOKEN }}
You can automatically include the stale repository report in your GitHub Actions workflow summary by settingWORKFLOW_SUMMARY_ENABLED: true
. This eliminates the need for additional steps to display the results.
name:stale repo identifieron:workflow_dispatch:schedule: -cron:"3 2 1 * *"permissions:contents:readjobs:build:name:stale repo identifierruns-on:ubuntu-lateststeps: -name:Run stale_repos tooluses:github/stale-repos@v6env:GH_TOKEN:${{ secrets.GH_TOKEN }}ORGANIZATION:${{ secrets.ORGANIZATION }}EXEMPT_TOPICS:"keep,template"INACTIVE_DAYS:365ADDITIONAL_METRICS:"release,pr"WORKFLOW_SUMMARY_ENABLED:true
WhenWORKFLOW_SUMMARY_ENABLED
is set totrue
, the stale repository report will be automatically added to the GitHub Actions workflow summary, making it easy to see the results directly in the workflow run page.
#Inactive RepositoriesThe following repos have not had a push event for more than 3 days:| Repository URL| Days Inactive| Last Push Date| Visibility| Days Since Last Release| Days Since Last PR|| ---------------------------------| ------------:| -------------:| ---------:| ----------------------:| -----------------:||https://github.com/github/.github| 5| 2020-1-30| private| 10| 7|
The action outputs inactive repos in JSON format for further actions as seen below or use the JSON contents from the file:stale_repos.json
.
Example usage:
name:stale repo identifieron:workflow_dispatch:schedule: -cron:"3 2 1 * *"permissions:contents:readjobs:build:name:stale repo identifierruns-on:ubuntu-lateststeps: -name:Run stale_repos toolid:stale-reposuses:github/stale-repos@v3env:GH_TOKEN:${{ secrets.GH_TOKEN }}ORGANIZATION:${{ secrets.ORGANIZATION }}EXEMPT_TOPICS:"keep,template"INACTIVE_DAYS:365ADDITIONAL_METRICS:"release,pr" -name:Print output of stale_repos toolrun:echo "${{ steps.stale-repos.outputs.inactiveRepos }}" -uses:actions/github-script@v6with:script:| const repos = ${{ steps.stale-repos.outputs.inactiveRepos }} for (const repo of repos) { console.log(repo); const issue = await github.rest.issues.create({ owner: <ORG_OWNER>, repo: <REPOSITORY>, title: 'Stale repo' + repo.url, body: 'This repo is stale. Please contact the owner to make it active again.', }); console.log(issue); }github-token:${{ secrets.GH_TOKEN }}
You can utilize the GitHub Actions Matrix Strategy as shown below to run against multiple organizations. Note that this workflow example uses a manual trigger instead of a cron based trigger. Either works, this is just another option to consider.
on: -workflow_dispatchname:Run the reportpermissions:contents:readjobs:report:name:run reportruns-on:ubuntu-lateststrategy:matrix:org:[org1, org2]steps: -name:"run stale-repos"uses:github/stale-repos@v3env:GH_TOKEN:${{ secrets.GH_TOKEN }}ORGANIZATION:${{ matrix.org }}INACTIVE_DAYS:365ADDITIONAL_METRICS:"release,pr"
You can authenticate as a GitHub App Installation by providing additional environment variables. IfGH_TOKEN
is set alongside these GitHub App Installation variables, theGH_TOKEN
will be ignored and not used.
on: -workflow_dispatchname:Run the reportpermissions:contents:readjobs:build:name:stale repo identifierruns-on:ubuntu-lateststeps: -uses:actions/checkout@v4 -name:Run stale_repos tooluses:github/stale-repos@v6env:GH_APP_ID:${{ secrets.GH_APP_ID }}GH_APP_INSTALLATION_ID:${{ secrets.GH_APP_INSTALLATION_ID }}GH_APP_PRIVATE_KEY:${{ secrets.GH_APP_PRIVATE_KEY }}#GITHUB_APP_ENTERPRISE_ONLY: true --> Set this if the gh app was created in GHE and the endpoint is also a GHE instanceORGANIZATION:${{ secrets.ORGANIZATION }}EXEMPT_TOPICS:"keep,template"INACTIVE_DAYS:365ACTIVITY_METHOD:"pushed"ADDITIONAL_METRICS:"release,pr"
- Have Python v3.11 or greater installed
- Copy
.env-example
to.env
- Fill out the
.env
file with atoken from a user that has access to the organization to scan (listed below). Tokens should have admin:org or read:org access. - Fill out the
.env
file with the desiredinactive_days value. This should be a whole positive number representing the amount of inactivity that you want for flagging stale repos. - (Optional) Fill out the
.env
file with therepository topicsexempt_topics that you want to filter out from the stale repos report. This should be a comma separated list of topics. - (Optional) Fill out the
.env
file with the exactorganization that you want to search in - (Optional) Fill out the
.env
file with the exactURL of the GitHub Enterprise that you want to search in. Keep empty if you want to search in the publicgithub.com
. pip install -r requirements.txt
- Run
python3 ./stale_repos.py
, which will output a list of repositories and the length of their inactivity
- Have Python v3.11 or greater installed
pip install -r requirements.txt -r requirements-test.txt
make lint
make test
Looking for more resources for your open source program office (OSPO)? Check out thegithub-ospo
repository for a variety of tools designed to support your needs.
About
Find stale repositories in a GitHub organization.
Topics
Resources
License
Code of conduct
Contributing
Security policy
Uh oh!
There was an error while loading.Please reload this page.
Stars
Watchers
Forks
Packages0
Uh oh!
There was an error while loading.Please reload this page.
Uh oh!
There was an error while loading.Please reload this page.