Older Than 2 Years Informer #17
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
name: Older Than 2 Years Informer | |
on: | |
schedule: | |
# Every month, first day of the month | |
- cron: '0 0 1 * *' | |
workflow_dispatch: | |
jobs: | |
build: | |
runs-on: ubuntu-latest | |
steps: | |
- name: Older Than 2 Years Informer | |
id: older-than-2y | |
uses: actions/github-script@60a0d83039c74a4aee543508d2ffcb1c3799cdea # v7.0.1 | |
with: | |
github-token: ${{ secrets.GH_PAT }} | |
script: | | |
const org = process.env.GITHUB_REPOSITORY_OWNER; | |
function formatInMessage(r) { | |
var pushedAt = new Date(r.pushed_at); | |
return `- ${r.private ? '😎 ' : ''} ${r.full_name} ${r.html_url}\t🌟 ${r.stargazers_count}🍴${r.forks} - Last pushed ${pushedAt.getFullYear()}/${pushedAt.getMonth()}/${pushedAt.getDay()+1}\n` | |
} | |
const v = await github.paginate('GET /orgs/{org}/repos', { | |
org: org, | |
headers: { | |
'X-GitHub-Api-Version': '2022-11-28' | |
} | |
}) | |
const maxOlderDate = ((d) => d.setDate(d.getDate() - 2*365))(new Date()); // 2 years | |
const reposOlderThanDate = v.filter(r => r.archived === false).filter(r => r.disabled === false).filter(r => new Date(r.pushed_at) < maxOlderDate) | |
const forks = reposOlderThanDate.filter(r => r.fork === true) | |
const nonForks = reposOlderThanDate.filter(r => r.fork === false) | |
// console.log(reposOlderThanDate[0]) // DEBUG | |
if (reposOlderThanDate.length == 0) return ""; | |
var message = `${org} has ${reposOlderThanDate.length} outdated repositories.\nConsider archiving them.` | |
if (nonForks.length !== 0) message += "\n\nRepositories:\n" | |
for (var i = 0; i < nonForks.length; i++) { | |
var r = nonForks[i] | |
message += formatInMessage(r) | |
} | |
if (forks.length !== 0) message += "\n\nForks:\n" | |
for (var i = 0; i < forks.length; i++) { | |
var r = forks[i] | |
message += formatInMessage(r) | |
} | |
core.setSecret(message); | |
return message; | |
- uses: actions-ecosystem/action-slack-notifier@fc778468d09c43a6f4d1b8cccaca59766656996a # v1.1.0 | |
if: ${{ fromJson(steps.older-than-2y.outputs.result) != '' }} | |
with: | |
slack_token: ${{ secrets.HOTSPOTS_SLACK_TOKEN }} | |
message: | | |
[older-than-2y] ${{ fromJson(steps.older-than-2y.outputs.result) }} | |
channel: secops-hotspots | |
color: blue | |
verbose: false |