Skip to content

Commit ce15e59

Browse files
committed
Avoid double counting outside collaborators, preventing deletions
The 'direct' affiliation of collaborators includes the 'outside' collaborators, and in testing when the resulting source contained duplicates the test function was not deleting collaborators. Signed-off-by: Kyle Harding <[email protected]>
1 parent b8c60fe commit ce15e59

File tree

1 file changed

+8
-6
lines changed

1 file changed

+8
-6
lines changed

lib/plugins/collaborators.js

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -15,9 +15,12 @@ module.exports = class Collaborators extends Diffable {
1515
}
1616

1717
find () {
18-
// this.log.debug(`Finding collaborators for { repo: ${this.repo.repo}, owner: ${this.repo.owner}, affiliation: 'direct', 'outside', and 'pending invites' }`)
18+
// https://docs.github.com/en/rest/collaborators/collaborators?apiVersion=2022-11-28
19+
// 'outside' means all outside collaborators of an organization-owned repository.
20+
// 'direct' means all collaborators with permissions to an organization-owned repository, regardless of organization membership status. (includes outside collaborators)
21+
// 'all' means all collaborators the authenticated user can see.
22+
// We are using 'direct' to avoid double listing users outside collaborators and team members.
1923
return Promise.all([this.github.repos.listCollaborators({ repo: this.repo.repo, owner: this.repo.owner, affiliation: 'direct' }),
20-
this.github.repos.listCollaborators({ repo: this.repo.repo, owner: this.repo.owner, affiliation: 'outside' }),
2124
this.github.repos.listInvitations({ repo: this.repo.repo, owner: this.repo.owner })])
2225
.then(res => {
2326
const mapCollaborator = user => {
@@ -31,9 +34,8 @@ module.exports = class Collaborators extends Diffable {
3134
}
3235
}
3336

34-
const results0 = (res[0].data || []).map(mapCollaborator)
35-
const results1 = (res[1].data || []).map(mapCollaborator)
36-
const results2 = (res[2].data || []).map(invite => {
37+
const results1 = (res[0].data || []).map(mapCollaborator)
38+
const results2 = (res[1].data || []).map(invite => {
3739
return {
3840
// Force all usernames to lowercase to avoid comparison issues.
3941
username: invite.invitee.login.toLowerCase(),
@@ -44,7 +46,7 @@ module.exports = class Collaborators extends Diffable {
4446
(invite.permissions === 'write' && 'push')
4547
}
4648
})
47-
return results0.concat(results1).concat(results2)
49+
return results1.concat(results2)
4850
})
4951
.catch(e => {
5052
this.logError(e)

0 commit comments

Comments
 (0)