Skip to content

Commit b0805f0

Browse files
authored
Avoid double counting outside collaborators, preventing deletions (#810)
* Clean up debug logging in diffable.js Signed-off-by: Kyle Harding <[email protected]> * 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]> --------- Signed-off-by: Kyle Harding <[email protected]>
1 parent e315287 commit b0805f0

File tree

2 files changed

+10
-8
lines changed

2 files changed

+10
-8
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)

lib/plugins/diffable.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -90,9 +90,9 @@ module.exports = class Diffable extends ErrorStash {
9090
const mergeDeep = new MergeDeep(this.log, this.github, ignorableFields)
9191
const compare = mergeDeep.compareDeep(existingRecords, filteredEntries)
9292
const results = { msg: 'Changes found', additions: compare.additions, modifications: compare.modifications, deletions: compare.deletions }
93-
this.log.debug(`Results of comparing ${this.constructor.name} diffable target ${JSON.stringify(existingRecords)} with source ${JSON.stringify(filteredEntries)} is ${results}`)
93+
this.log.debug(`Results of comparing ${this.constructor.name} diffable target ${JSON.stringify(existingRecords)} with source ${JSON.stringify(filteredEntries)} is ${JSON.stringify(results)}`)
9494
if (!compare.hasChanges) {
95-
this.log.debug(`There are no changes for ${this.constructor.name} for repo ${this.repo}. Skipping changes`)
95+
this.log.debug(`There are no changes for ${this.constructor.name} for repo ${this.repo.repo}. Skipping changes`)
9696
return Promise.resolve()
9797
} else {
9898
if (this.nop) {

0 commit comments

Comments
 (0)