WARNING: THIS SITE IS A MIRROR OF GITHUB.COM / IT CANNOT LOGIN OR REGISTER ACCOUNTS / THE CONTENTS ARE PROVIDED AS-IS / THIS SITE ASSUMES NO RESPONSIBILITY FOR ANY DISPLAYED CONTENT OR LINKS / IF YOU FOUND SOMETHING MAY NOT GOOD FOR EVERYONE, CONTACT ADMIN AT ilovescratch@foxmail.com
Skip to content

Commit 32a0878

Browse files
authored
Multiple improvements related to the kick process and general code centralization.
* Centralizes logic for retrieving members. * Centralizes dry run logic. * Safely checks for ISSUE_WITHOUT_MENTION env var. * Fixes bug where kick action was not checking out the repo, which is required to read the db.json file.
1 parent 9361572 commit 32a0878

File tree

7 files changed

+61
-48
lines changed

7 files changed

+61
-48
lines changed

.github/actions/audit/action.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ runs:
2222
with:
2323
path: main
2424
repository: oss-tooling/user-inactivity
25-
ref: v1.1.4
25+
ref: v1.1.5
2626

2727
- uses: actions/checkout@v3
2828
with:

.github/actions/kick/action.yml

Lines changed: 17 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,9 @@ inputs:
55
description: the github organization to audit
66
repo:
77
description: name of repo where inactive user issues are created
8+
branch:
9+
description: branch to store activity data on
10+
default: main
811
inactivity-duration:
912
description: the amount of days a user can be inactive for
1013
default: 30
@@ -16,12 +19,24 @@ inputs:
1619
description: the app installation id
1720
runs:
1821
using: composite
19-
steps:
22+
steps:
23+
- uses: actions/checkout@v3
24+
with:
25+
ref: ${{ inputs.branch }}
26+
path: activity
27+
2028
- uses: actions/checkout@v3
2129
with:
2230
path: main
2331
repository: oss-tooling/user-inactivity
24-
ref: v1.1.4
32+
ref: v1.1.5
33+
34+
- name: Move db.json
35+
run: |
36+
if test -f "${{ github.workspace }}/activity/db.json"; then
37+
mv ${{ github.workspace }}/activity/db.json ${{ github.workspace }}/main/db.json
38+
fi
39+
shell: bash
2540

2641
- name: Install dependencies
2742
run: npm install

.github/actions/report/action.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ runs:
2424
with:
2525
path: main
2626
repository: oss-tooling/user-inactivity
27-
ref: v1.1.4
27+
ref: v1.1.5
2828

2929
- uses: actions/checkout@v3
3030
with:

lib/inactiveUsers.js

Lines changed: 21 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,27 @@ exports.inactiveUsers = (octokit, options) => {
77
inactiveUsers: {
88
audit: audit(octokit, options),
99
report: report(octokit, options),
10-
kick: kick(octokit, options)
10+
kick: kick(octokit, options),
11+
getOrgMemberData: async (org, issueRepo) => {
12+
const [ members, userIssues, outsideCollaborators ] = await Promise.all([
13+
octokit.paginate(octokit.orgs.listMembers, {
14+
org,
15+
role: 'member',
16+
per_page: 100
17+
}),
18+
octokit.paginate(octokit.issues.listForRepo, {
19+
owner: org,
20+
repo: issueRepo,
21+
state: 'open',
22+
per_page: 100,
23+
}),
24+
octokit.paginate(octokit.orgs.listOutsideCollaborators, {
25+
org,
26+
per_page: 100
27+
})
28+
])
29+
return { members, userIssues, outsideCollaborators }
30+
}
1131
}
1232
}
1333
}

lib/kick.js

Lines changed: 11 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
const database = require('./database')
2-
const { inactiveUserLabel } = require('./utils')
2+
const { dryRun } = require('./utils')
33

44
const preserveAccountComment = (user) => {
5-
if (process.env.ISSUE_WITHOUT_MENTION.toLowerCase() === 'true') {
5+
if (process.env.ISSUE_WITHOUT_MENTION && process.env.ISSUE_WITHOUT_MENTION.toLowerCase() === 'true') {
66
return `Thank you, I will mark your account active. Please remember this ${database.INACTIVE_DURATION} day audit will be part of the continuous monitoring for GitHub, so please maintain activity of one of the following to avoid be pulled as inactive again.
77
1. Commits
88
2. Created issue(s)
@@ -40,7 +40,7 @@ const removeCollaboratorFromOrg = async (client, owner, login) => {
4040
}
4141

4242
const createComment = async (client, owner, repo, number, comment) => {
43-
if (process.env.DRY_RUN.toLowerCase() !== 'true') {
43+
if (!dryRun) {
4444
await client.issues.createComment({
4545
owner: owner,
4646
repo: repo,
@@ -51,7 +51,7 @@ const createComment = async (client, owner, repo, number, comment) => {
5151
}
5252

5353
const closeIssue = async (client, owner, repo, number) => {
54-
if (process.env.DRY_RUN.toLowerCase() !== 'true') {
54+
if (!dryRun) {
5555
await client.issues.update({
5656
owner: owner,
5757
repo: repo,
@@ -62,7 +62,7 @@ const closeIssue = async (client, owner, repo, number) => {
6262
}
6363

6464
const addLabels = async (client, owner, repo, number, labels) => {
65-
if (process.env.DRY_RUN.toLowerCase() !== 'true') {
65+
if (!dryRun) {
6666
await client.issues.addLabels({
6767
owner: owner,
6868
repo: repo,
@@ -73,30 +73,16 @@ const addLabels = async (client, owner, repo, number, labels) => {
7373
}
7474

7575
exports.kick = (octokit) => async (org, repo) => {
76-
const [members, outsideCollaborators, issues] = await Promise.all([
77-
octokit.paginate(octokit.orgs.listMembers, {
78-
org,
79-
role: 'member',
80-
per_page: 100
81-
}),
82-
octokit.paginate(octokit.orgs.listOutsideCollaborators, {
83-
org,
84-
per_page: 100
85-
}, (response) => response.data.map((collaborator) => collaborator.login)),
86-
octokit.paginate(octokit.issues.listForRepo, {
87-
owner: org,
88-
repo,
89-
state: 'open',
90-
labels: [inactiveUserLabel],
91-
sort: 'created',
92-
direction: 'desc',
93-
per_page: 100
94-
})
95-
])
76+
const { members: orgMembers, userIssues: issues, outsideCollaborators: outsideCollaboratorsRaw} = await octokit.inactiveUsers.getOrgMemberData(org, repo)
77+
78+
const members = orgMembers.concat(outsideCollaboratorsRaw)
79+
const outsideCollaborators = outsideCollaboratorsRaw.map(collaborator => collaborator.login)
9680

9781
const _expiredUsers = await database.getExpiredUsers(members)
9882
const expiredUsers = _expiredUsers.map(user => user.login)
9983

84+
console.log(expiredUsers)
85+
10086
const expirationDate = new Date()
10187
expirationDate.setDate(expirationDate.getDate() - 3)
10288

lib/report.js

Lines changed: 8 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -3,22 +3,12 @@ const database = require('./database')
33
const utils = require('./utils')
44

55
exports.report = (octokit) => async (org, repo, body) => {
6-
console.log('Retrieving list of all organization users')
7-
const members = await octokit.paginate(octokit.orgs.listMembers, {
8-
org,
9-
role: 'member',
10-
per_page: 100
11-
})
12-
13-
console.log('Retrieving all active issues')
14-
const _issues = await octokit.paginate(octokit.issues.listForRepo, {
15-
owner: org,
16-
repo,
17-
state: 'open',
18-
per_page: 100
19-
})
20-
21-
const usernames = _issues.map(issue => issue.title.toLowerCase())
6+
const { members: orgMembers, userIssues, outsideCollaborators } = await octokit.inactiveUsers.getOrgMemberData(org, repo)
7+
8+
const usersWithIssues = userIssues.map(issue => issue.title.toLowerCase())
9+
const members = orgMembers.concat(outsideCollaborators)
10+
11+
console.log(`${members.length} users found in the organization (${orgMembers.length} members and ${outsideCollaborators.length} outside collaborators)`)
2212

2313
const expiredUsers = await database.getExpiredUsers(members)
2414
console.log(`${expiredUsers.length} users found with no activity in the last ${database.INACTIVE_DURATION} days`)
@@ -28,12 +18,12 @@ exports.report = (octokit) => async (org, repo, body) => {
2818
console.log(`Skipping: ${expiredUser.login} is a bot account`)
2919
continue
3020
}
31-
if (usernames.includes(expiredUser.login.toLowerCase())) {
21+
if (usersWithIssues.includes(expiredUser.login.toLowerCase())) {
3222
console.log(`Skipping: ${expiredUser.login} already has an issue open`)
3323
continue
3424
}
3525
console.log(`Sending notification for ${expiredUser.login}`)
36-
if (process.env.DRY_RUN.toLowerCase() !== 'true') {
26+
if (!utils.dryRun) {
3727
await octokit.issues.create({
3828
owner: org,
3929
repo,

lib/utils.js

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -53,3 +53,5 @@ exports.registerSecrets = async () => {
5353
}
5454

5555
exports.inactiveUserLabel = 'inactive-user'
56+
57+
exports.dryRun = process.env.DRY_RUN ? process.env.DRY_RUN.toLowerCase() == 'true' : false

0 commit comments

Comments
 (0)