Skip to content

Commit

Permalink
New workflow: older-than-2y
Browse files Browse the repository at this point in the history
  • Loading branch information
thypon committed Oct 13, 2023
1 parent ed97abb commit 92e0bb2
Showing 1 changed file with 63 additions and 0 deletions.
63 changes: 63 additions & 0 deletions .github/workflows/older-than-2y.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,63 @@
name: Older Than 2 Years Informer
on:
schedule:
# Every month, first day of the month
- cron: '0 0 1 * *'

jobs:
build:
runs-on: ubuntu-latest
steps:
- name: Older Than 2 Years Informer
id: older-than-2y
uses: actions/github-script@d7906e4ad0b1822421a7e6a35d5ca353c962f410 # v6.4.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

0 comments on commit 92e0bb2

Please sign in to comment.