-
-
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
Merged
Changes from 2 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,35 @@ | ||
name: Find inactive collaborators | ||
|
||
on: | ||
schedule: | ||
# Run every Monday at 4:05 AM UTC. | ||
- cron: 5 4 * * 1 | ||
|
||
workflow_dispatch: | ||
|
||
env: | ||
NODE_VERSION: lts/* | ||
|
||
permissions: {} | ||
|
||
jobs: | ||
find: | ||
if: github.repository == 'nodejs/node' | ||
avivkeller marked this conversation as resolved.
Show resolved
Hide resolved
|
||
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: Create inactive collaborators report | ||
uses: actions/github-script@60a0d83039c74a4aee543508d2ffcb1c3799cdea # v7.0.1 | ||
with: | ||
github-token: ${{ secrets.READ_ONLY_PUBLIC_REPO_TOKEN }} | ||
script: | | ||
const { reportInactiveCollaborators } = await import("${{github.workspace}}/apps/site/scripts/find-inactive-collaborators/index.mjs"); | ||
|
||
await reportInactiveCollaborators(core, github); |
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
226 changes: 226 additions & 0 deletions
226
apps/site/scripts/find-inactive-collaborators/__tests__/index.test.mjs
avivkeller marked this conversation as resolved.
Show resolved
Hide resolved
|
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,226 @@ | ||
import assert from 'node:assert/strict'; | ||
import { beforeEach, describe, it, mock } from 'node:test'; | ||
|
||
import { | ||
findInactiveMembers, | ||
isActiveMember, | ||
getDateMonthsAgo, | ||
reportInactiveCollaborators, | ||
createOrUpdateInactiveCollaboratorsIssue, | ||
findInactiveCollaboratorsIssue, | ||
formatIssueBody, | ||
} from '../index.mjs'; | ||
|
||
// Test constants | ||
const MOCK_DATE = new Date('2025-05-23T14:33:31Z'); | ||
const CUTOFF_DATE = '2024-05-23'; | ||
const TEST_MEMBERS = [ | ||
{ login: 'active-user' }, | ||
{ login: 'inactive-user' }, | ||
{ login: 'active-user-issues' }, | ||
]; | ||
|
||
describe('Inactive Collaborators Tests', () => { | ||
let core, github; | ||
|
||
mock.timers.enable({ apis: ['Date'], now: MOCK_DATE }); | ||
|
||
beforeEach(() => { | ||
// Simplified mocks | ||
const logs = [], | ||
warnings = []; | ||
core = { | ||
info: msg => logs.push(msg), | ||
warning: msg => warnings.push(msg), | ||
getLogs: () => [...logs], | ||
getWarnings: () => [...warnings], | ||
clearLogs: () => { | ||
logs.length = 0; | ||
}, | ||
}; | ||
|
||
github = { | ||
rest: { | ||
search: { | ||
commits: async ({ q }) => ({ | ||
data: { | ||
total_count: q.includes('author:active-user') ? 5 : 0, | ||
items: q.includes('author:active-user') | ||
? [{ sha: 'abc123' }] | ||
: [], | ||
}, | ||
}), | ||
issuesAndPullRequests: async ({ q }) => ({ | ||
data: { | ||
total_count: q.includes('involves:active-user-issues') ? 3 : 0, | ||
items: q.includes('involves:active-user-issues') | ||
? [{ number: 123 }] | ||
: [], | ||
}, | ||
}), | ||
}, | ||
teams: { | ||
listMembersInOrg: async () => ({ data: TEST_MEMBERS }), | ||
}, | ||
issues: { | ||
listForRepo: async ({ repo }) => ({ | ||
data: | ||
repo === 'repo-with-issue' | ||
? [ | ||
{ | ||
number: 42, | ||
title: 'Inactive Collaborators Report', | ||
body: 'Previous report', | ||
}, | ||
] | ||
: [], | ||
}), | ||
create: async ({ title, body }) => ({ | ||
data: { number: 99, title, body }, | ||
}), | ||
update: async ({ issue_number, body }) => ({ | ||
data: { number: issue_number, body }, | ||
}), | ||
}, | ||
}, | ||
}; | ||
}); | ||
|
||
describe('Utilities and core functionality', () => { | ||
it('correctly formats dates with different month offsets', () => { | ||
assert.equal(getDateMonthsAgo(12), CUTOFF_DATE); | ||
assert.equal(getDateMonthsAgo(0), '2025-05-23'); | ||
assert.equal(getDateMonthsAgo(6), '2024-11-23'); | ||
}); | ||
|
||
it('correctly identifies active and inactive users', async () => { | ||
assert.equal( | ||
await isActiveMember('active-user', CUTOFF_DATE, github), | ||
true | ||
); | ||
assert.equal( | ||
await isActiveMember('active-user-issues', CUTOFF_DATE, github), | ||
true | ||
); | ||
assert.equal( | ||
await isActiveMember('inactive-user', CUTOFF_DATE, github), | ||
false | ||
); | ||
}); | ||
|
||
it('finds inactive members from the team list', async () => { | ||
const inactiveMembers = await findInactiveMembers( | ||
TEST_MEMBERS, | ||
core, | ||
github | ||
); | ||
|
||
assert.partialDeepStrictEqual(inactiveMembers, [ | ||
{ login: 'inactive-user' }, | ||
]); | ||
}); | ||
}); | ||
|
||
describe('Issue management', () => { | ||
it('formats issue body correctly', () => { | ||
const inactiveMembers = [ | ||
{ | ||
login: 'inactive-user', | ||
inactive_since: CUTOFF_DATE, | ||
}, | ||
]; | ||
|
||
const body = formatIssueBody(inactiveMembers, CUTOFF_DATE); | ||
|
||
assert.ok(body.includes('# Inactive Collaborators Report')); | ||
assert.ok(body.includes('## Inactive Collaborators (1)')); | ||
assert.ok(body.includes('@inactive-user')); | ||
}); | ||
|
||
it('handles empty inactive members list', () => { | ||
assert.ok(!formatIssueBody([], CUTOFF_DATE)); | ||
}); | ||
|
||
it('manages issue creation and updates', async () => { | ||
const inactiveMembers = [ | ||
{ login: 'inactive-user', inactive_since: CUTOFF_DATE }, | ||
]; | ||
|
||
// Test finding issues | ||
const existingIssue = await findInactiveCollaboratorsIssue( | ||
github, | ||
'nodejs', | ||
'repo-with-issue' | ||
); | ||
const nonExistingIssue = await findInactiveCollaboratorsIssue( | ||
github, | ||
'nodejs', | ||
'repo-without-issue' | ||
); | ||
|
||
assert.equal(existingIssue?.number, 42); | ||
assert.equal(nonExistingIssue, null); | ||
|
||
// Test updating existing issues | ||
const updatedIssueNum = await createOrUpdateInactiveCollaboratorsIssue({ | ||
github, | ||
core, | ||
org: 'nodejs', | ||
repo: 'repo-with-issue', | ||
inactiveMembers, | ||
cutoffDate: CUTOFF_DATE, | ||
}); | ||
assert.equal(updatedIssueNum, 42); | ||
|
||
// Test creating new issues | ||
const newIssueNum = await createOrUpdateInactiveCollaboratorsIssue({ | ||
github, | ||
core, | ||
org: 'nodejs', | ||
repo: 'repo-without-issue', | ||
inactiveMembers, | ||
cutoffDate: CUTOFF_DATE, | ||
}); | ||
assert.equal(newIssueNum, 99); | ||
}); | ||
}); | ||
|
||
describe('Complete workflow', () => { | ||
it('correctly executes the full report generation workflow', async () => { | ||
await reportInactiveCollaborators(core, github, { | ||
org: 'nodejs', | ||
teamSlug: 'team', | ||
repo: 'repo', | ||
monthsInactive: 12, | ||
}); | ||
|
||
const logs = core.getLogs(); | ||
assert.ok( | ||
logs.some(log => log.includes('Checking inactive collaborators')) | ||
); | ||
assert.ok( | ||
logs.some(log => | ||
log.includes('Inactive collaborators report available at:') | ||
) | ||
); | ||
}); | ||
|
||
it('uses default parameters when not specified', async () => { | ||
const customGithub = { | ||
...github, | ||
rest: { | ||
...github.rest, | ||
teams: { | ||
listMembersInOrg: async ({ org, team_slug }) => { | ||
assert.equal(org, 'nodejs'); | ||
assert.equal(team_slug, 'nodejs-website'); | ||
return { data: [] }; | ||
}, | ||
}, | ||
}, | ||
}; | ||
|
||
await reportInactiveCollaborators(core, customGithub); | ||
}); | ||
}); | ||
}); |
Oops, something went wrong.
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.