-
-
Notifications
You must be signed in to change notification settings - Fork 6.4k
feat(meta): require collaborators to be active #7775
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
+205
−2
Merged
Changes from 8 commits
Commits
Show all changes
9 commits
Select commit
Hold shift + click to select a range
e521d91
feat(meta): require collaborators to me active
avivkeller 5c3d22e
fixup!
avivkeller 0ec595b
Update .github/workflows/find-inactive-collaborators.yml
avivkeller de47182
store workflow in .github
avivkeller c99039c
use local list
avivkeller d42745d
remove unused tests
avivkeller 5af6ebe
use more lenient matching
avivkeller babb4d4
fixup!
avivkeller bf73db8
code review
avivkeller File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or 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,121 @@ | ||
import { readFile } from 'node:fs/promises'; | ||
|
||
const CONFIG = { | ||
GOVERNANCE_FILE: 'GOVERNANCE.md', | ||
CURRENT_MEMBERS_HEADER: '#### Current Members', | ||
INACTIVE_MONTHS: 12, | ||
ISSUE_TITLE: 'Inactive Collaborator Report', | ||
ISSUE_LABELS: ['meta', 'inactive-collaborator-report'], | ||
}; | ||
|
||
// Get date N months ago in YYYY-MM-DD format | ||
const getDateMonthsAgo = (months = CONFIG.INACTIVE_MONTHS) => { | ||
const date = new Date(); | ||
date.setMonth(date.getMonth() - months); | ||
return date.toISOString().split('T')[0]; | ||
}; | ||
|
||
// Parse collaborator usernames from governance file | ||
async function parseCollaborators() { | ||
const content = await readFile(CONFIG.GOVERNANCE_FILE, 'utf8'); | ||
const lines = content.split('\n'); | ||
const collaborators = []; | ||
|
||
const startIndex = | ||
lines.findIndex(l => l.startsWith(CONFIG.CURRENT_MEMBERS_HEADER)) + 1; | ||
if (startIndex <= 0) return collaborators; | ||
|
||
for (let i = startIndex; i < lines.length; i++) { | ||
const line = lines[i]; | ||
if (line.startsWith('#')) break; | ||
|
||
const match = line.match(/^\s*-\s*\[([^\]]+)\]/); | ||
if (match) collaborators.push(match[1]); | ||
} | ||
|
||
return collaborators; | ||
} | ||
|
||
// Check if users have been active since cutoff date | ||
async function getInactiveUsers(github, usernames, repo, cutoffDate) { | ||
const inactiveUsers = []; | ||
|
||
for (const username of usernames) { | ||
const { data } = await github.rest.search.commits({ | ||
q: `author:${username} repo:${repo} committer-date:>=${cutoffDate}`, | ||
per_page: 1, | ||
}); | ||
|
||
if (data.total_count === 0) { | ||
inactiveUsers.push(username); | ||
} | ||
} | ||
|
||
return inactiveUsers; | ||
} | ||
|
||
// Generate report for inactive members | ||
function formatReport(inactiveMembers, cutoffDate) { | ||
if (!inactiveMembers.length) return null; | ||
|
||
const today = getDateMonthsAgo(0); | ||
return `# Inactive Collaborators Report | ||
|
||
Last updated: ${today} | ||
Checking for inactivity since: ${cutoffDate} | ||
|
||
## Inactive Collaborators (${inactiveMembers.length}) | ||
|
||
| Login | | ||
| ----- | | ||
${inactiveMembers.map(m => `| @${m} |`).join('\n')} | ||
|
||
## What happens next? | ||
|
||
Team maintainers should review this list and contact inactive collaborators to confirm their continued interest in participating in the project.`; | ||
} | ||
|
||
async function createOrUpdateIssue(github, context, report) { | ||
if (!report) return; | ||
|
||
const { owner, repo } = context.repo; | ||
const { data: issues } = await github.rest.issues.listForRepo({ | ||
owner, | ||
repo, | ||
state: 'open', | ||
labels: CONFIG.ISSUE_LABELS[1], | ||
per_page: 1, | ||
}); | ||
|
||
if (issues.total_count > 0) { | ||
await github.rest.issues.update({ | ||
owner, | ||
repo, | ||
issue_number: issues.items[0].number, | ||
body: report, | ||
}); | ||
} else { | ||
await github.rest.issues.create({ | ||
owner, | ||
repo, | ||
title: CONFIG.ISSUE_TITLE, | ||
body: report, | ||
labels: CONFIG.ISSUE_LABELS, | ||
}); | ||
} | ||
} | ||
|
||
export default async function (github, context) { | ||
const cutoffDate = getDateMonthsAgo(); | ||
const collaborators = await parseCollaborators(); | ||
|
||
const inactiveMembers = await getInactiveUsers( | ||
github, | ||
collaborators, | ||
`${context.repo.owner}/${context.repo.repo}`, | ||
cutoffDate | ||
); | ||
const report = formatReport(inactiveMembers, cutoffDate); | ||
|
||
await createOrUpdateIssue(github, context, report); | ||
} |
This file contains hidden or 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,34 @@ | ||
name: Find inactive collaborators | ||
|
||
on: | ||
schedule: | ||
# Run every Monday at 4:05 AM UTC. | ||
- cron: 5 4 * * 1 | ||
|
||
workflow_dispatch: | ||
|
||
env: | ||
NODE_VERSION: lts/* | ||
avivkeller marked this conversation as resolved.
Show resolved
Hide resolved
|
||
|
||
permissions: {} | ||
|
||
jobs: | ||
find: | ||
if: github.repository == 'nodejs/nodejs.org' | ||
runs-on: ubuntu-latest | ||
|
||
steps: | ||
- name: Harden Runner | ||
uses: step-security/harden-runner@0634a2670c59f64b4a01f0f96f84700a4088b9f0 # v2.12.0 | ||
with: | ||
egress-policy: audit | ||
|
||
- uses: actions/checkout@11bd71901bbe5b1630ceea73d27597364c9af683 # v4.2.2 | ||
|
||
- name: Report inactive collaborators | ||
id: inactive | ||
uses: actions/github-script@60a0d83039c74a4aee543508d2ffcb1c3799cdea # v7.0.1 | ||
with: | ||
script: | | ||
const report = await import("${{github.workspace}}/.github/scripts/report-inactive-collaborators.mjs"); | ||
report(github, exec) |
This file contains hidden or 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 hidden or 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
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.