Skip to content

Commit 8a4e34d

Browse files
authored
Merge pull request #29 from akbast/main
Add inactive repos as action output
2 parents 2d6249e + 8b0a74a commit 8a4e34d

File tree

3 files changed

+73
-0
lines changed

3 files changed

+73
-0
lines changed

README.md

Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -83,6 +83,54 @@ The following repos have not had a push event for more than 3 days:
8383
| https://github.com/github/.github | 5 |
8484
```
8585

86+
### Using JSON instead of Markdown
87+
88+
The action outputs inactive repos in JSON format for further actions.
89+
90+
Example usage:
91+
```yaml
92+
name: stale repo identifier
93+
94+
on:
95+
workflow_dispatch:
96+
schedule:
97+
- cron: '3 2 1 * *'
98+
99+
jobs:
100+
build:
101+
name: stale repo identifier
102+
runs-on: ubuntu-latest
103+
104+
steps:
105+
- name: Checkout code
106+
uses: actions/checkout@v3
107+
108+
- name: Run stale_repos tool
109+
id: stale-repos
110+
uses: docker://ghcr.io/github/stale_repos:v1
111+
env:
112+
GH_TOKEN: ${{ secrets.GH_TOKEN }}
113+
ORGANIZATION: ${{ secrets.ORGANIZATION }}
114+
INACTIVE_DAYS: 365
115+
116+
- name: Print output of stale_repos tool
117+
run: echo "${{ steps.stale-repos.outputs.inactiveRepos }}"
118+
- uses: actions/github-script@v6
119+
with:
120+
script: |
121+
const repos = ${{ steps.stale-repos.outputs.inactiveRepos }}
122+
for (const repo of repos) {
123+
console.log(repo);
124+
const issue = await github.rest.issues.create({
125+
owner: <ORG_OWNER>,
126+
repo: <REPOSITORY>,
127+
title: 'Stale repo' + repo.url,
128+
body: 'This repo is stale. Please contact the owner to make it active again.',
129+
});
130+
console.log(issue);
131+
}
132+
github-token: ${{ secrets.GH_TOKEN }}
133+
```
86134
## Local usage without Docker
87135
88136
1. Copy `.env-example` to `.env`

action.yml

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,9 @@
22
name: 'stale-repos'
33
author: 'github'
44
description: 'A GitHub Action to identify stale repos within an organization that should be considered for archival.'
5+
outputs:
6+
inactiveRepos:
7+
description: "Inactive Repos in the organization"
58
runs:
69
using: 'docker'
710
image: 'docker://ghcr.io/github/stale_repos:v1'

stale_repos.py

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
#!/usr/bin/env python
22
""" Find stale repositories in a GitHub organization. """
33

4+
import json
45
import os
56
from datetime import datetime, timezone
67
from os.path import dirname, join
@@ -50,6 +51,7 @@ def main():
5051
github_connection, inactive_days_threshold, organization
5152
)
5253

54+
output_to_json(inactive_repos)
5355
# Write the list of inactive repos to a csv file
5456
write_to_markdown(inactive_repos, inactive_days_threshold)
5557

@@ -104,6 +106,26 @@ def write_to_markdown(inactive_repos, inactive_days_threshold, file=None):
104106
file.write(f"| {repo_url} | {days_inactive} |\n")
105107
print("Wrote stale repos to stale_repos.md")
106108

109+
def output_to_json(inactive_repos):
110+
"""Convert the list of inactive repos to a json string.
111+
112+
Args:
113+
inactive_repos: A list of tuples containing the repo and days inactive.
114+
115+
"""
116+
# json structure is like following
117+
# [
118+
# {
119+
# "url": "https://github.com/owner/repo",
120+
# "daysInactive": 366
121+
# }
122+
# ]
123+
inactive_repos_json = []
124+
for repo_url, days_inactive in inactive_repos:
125+
inactive_repos_json.append({"url": repo_url, "daysInactive": days_inactive})
126+
inactive_repos_json = json.dumps(inactive_repos_json)
127+
128+
print(f"::set-output name=inactiveRepos::{inactive_repos_json}")
107129

108130
def auth_to_github():
109131
"""Connect to GitHub.com or GitHub Enterprise, depending on env variables."""

0 commit comments

Comments
 (0)