-
Notifications
You must be signed in to change notification settings - Fork 6
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
309f8c6
commit 918bd26
Showing
3 changed files
with
81 additions
and
51 deletions.
There are no files selected for viewing
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
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,42 @@ | ||
function formatInMessage (r) { | ||
const 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` | ||
} | ||
|
||
module.exports = async ({ github, context, inputs, actionPath, core, debug = false }) => { | ||
const { default: sendSlackMessage } = await import(`${actionPath}/src/sendSlackMessage.js`) | ||
|
||
const org = context.repo.owner | ||
|
||
const v = await github.paginate('GET /orgs/{org}/repos', { | ||
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 '' | ||
|
||
let message = `${org} has ${reposOlderThanDate.length} outdated repositories.\nConsider archiving them.` | ||
|
||
if (nonForks.length !== 0) message += '\n\nRepositories:\n' | ||
for (let i = 0; i < nonForks.length; i++) { | ||
const r = nonForks[i] | ||
message += formatInMessage(r) | ||
} | ||
|
||
if (forks.length !== 0) message += '\n\nForks:\n' | ||
for (let i = 0; i < forks.length; i++) { | ||
const r = forks[i] | ||
message += formatInMessage(r) | ||
} | ||
|
||
core.setSecret(message) | ||
|
||
if (message.length > 0) { await sendSlackMessage({ debug, username: 'older-than-2y', message: `[older-than-2y] ${message}`, color: 'blue', channel: '#security-hotspots', token: inputs.slack_token }) } | ||
} |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
name: older-than-2y | ||
description: Older Than 2 Years Informer | ||
inputs: | ||
github_token: | ||
description: 'GitHub Token' | ||
required: true | ||
slack_token: | ||
description: 'Slack Token' | ||
required: true | ||
debug: | ||
description: 'Debug mode' | ||
required: false | ||
runs: | ||
using: 'composite' | ||
steps: | ||
- uses: actions/setup-node@60edb5dd545a775178f52524783378180af0d1f8 # v4.0.2 | ||
with: | ||
node-version: '20.x' | ||
- id: npm | ||
run: cd ${{ github.action_path }}/../..; npm ci | ||
shell: bash | ||
- name: Older Than 2 Years Informer | ||
id: older-than-2y | ||
uses: actions/github-script@60a0d83039c74a4aee543508d2ffcb1c3799cdea # v7.0.1 | ||
env: | ||
DEBUG: ${{ (inputs.debug == 'true' || runner.debug) && 'true' || 'false'}} | ||
with: | ||
github-token: ${{ inputs.github_token }} | ||
script: | | ||
const actionPath = '${{ github.action_path }}/../../' | ||
const inputs = ${{ toJson(inputs) }} | ||
const script = require('${{ github.action_path }}/action.cjs') | ||
await script({github, context, inputs, actionPath, core, | ||
debug: process.env.DEBUG === 'true'}) |