Skip to content

Commit

Permalink
Merge pull request #29 from akbast/main
Browse files Browse the repository at this point in the history
Add inactive repos as action output
  • Loading branch information
zkoppert committed Jun 6, 2023
2 parents 2d6249e + 8b0a74a commit 8a4e34d
Show file tree
Hide file tree
Showing 3 changed files with 73 additions and 0 deletions.
48 changes: 48 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -83,6 +83,54 @@ The following repos have not had a push event for more than 3 days:
| https://github.com/github/.github | 5 |
```

### Using JSON instead of Markdown

The action outputs inactive repos in JSON format for further actions.

Example usage:
```yaml
name: stale repo identifier

on:
workflow_dispatch:
schedule:
- cron: '3 2 1 * *'

jobs:
build:
name: stale repo identifier
runs-on: ubuntu-latest

steps:
- name: Checkout code
uses: actions/checkout@v3

- name: Run stale_repos tool
id: stale-repos
uses: docker://ghcr.io/github/stale_repos:v1
env:
GH_TOKEN: ${{ secrets.GH_TOKEN }}
ORGANIZATION: ${{ secrets.ORGANIZATION }}
INACTIVE_DAYS: 365

- name: Print output of stale_repos tool
run: echo "${{ steps.stale-repos.outputs.inactiveRepos }}"
- uses: actions/github-script@v6
with:
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 }}
```
## Local usage without Docker
1. Copy `.env-example` to `.env`
Expand Down
3 changes: 3 additions & 0 deletions action.yml
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,9 @@
name: 'stale-repos'
author: 'github'
description: 'A GitHub Action to identify stale repos within an organization that should be considered for archival.'
outputs:
inactiveRepos:
description: "Inactive Repos in the organization"
runs:
using: 'docker'
image: 'docker://ghcr.io/github/stale_repos:v1'
Expand Down
22 changes: 22 additions & 0 deletions stale_repos.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
#!/usr/bin/env python
""" Find stale repositories in a GitHub organization. """

import json
import os
from datetime import datetime, timezone
from os.path import dirname, join
Expand Down Expand Up @@ -50,6 +51,7 @@ def main():
github_connection, inactive_days_threshold, organization
)

output_to_json(inactive_repos)
# Write the list of inactive repos to a csv file
write_to_markdown(inactive_repos, inactive_days_threshold)

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

def output_to_json(inactive_repos):
"""Convert the list of inactive repos to a json string.
Args:
inactive_repos: A list of tuples containing the repo and days inactive.
"""
# json structure is like following
# [
# {
# "url": "https://github.com/owner/repo",
# "daysInactive": 366
# }
# ]
inactive_repos_json = []
for repo_url, days_inactive in inactive_repos:
inactive_repos_json.append({"url": repo_url, "daysInactive": days_inactive})
inactive_repos_json = json.dumps(inactive_repos_json)

print(f"::set-output name=inactiveRepos::{inactive_repos_json}")

def auth_to_github():
"""Connect to github.com or GitHub Enterprise, depending on env variables."""
Expand Down

0 comments on commit 8a4e34d

Please sign in to comment.