-
Notifications
You must be signed in to change notification settings - Fork 6
64 lines (55 loc) · 2.51 KB
/
older-than-2y.yml
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
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