Skip to content
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

Merge 590 #603

Merged
merged 2 commits into from
Feb 28, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 5 additions & 6 deletions lib/plugins/teams.js
Original file line number Diff line number Diff line change
@@ -1,16 +1,15 @@
const Diffable = require('./diffable')
const NopCommand = require('../nopcommand')
// it is necessary to use this endpoint until GitHub Enterprise supports
// the modern version under /orgs
const teamRepoEndpoint = '/teams/:team_id/repos/:owner/:repo'

const teamRepoEndpoint = '/orgs/:owner/teams/:team_slug/repos/:owner/:repo'
module.exports = class Teams extends Diffable {
async find () {
this.log.debug(`Finding teams for ${this.repo.owner}/${this.repo.repo}`)
return this.github.paginate(this.github.repos.listTeams, this.repo)
}

comparator (existing, attrs) {
return existing.slug === attrs.name
return existing.slug === attrs.name.toLowerCase()
}

changed (existing, attrs) {
Expand Down Expand Up @@ -74,13 +73,13 @@ module.exports = class Teams extends Diffable {
return Promise.resolve([
new NopCommand(this.constructor.name, this.repo, this.github.request.endpoint(
`DELETE ${teamRepoEndpoint}`,
{ team_id: existing.id, ...this.repo, org: this.repo.owner }
{ team_slug: existing.slug, ...this.repo, org: this.repo.owner }
), 'DELETE Team')
])
}
return this.github.request(
`DELETE ${teamRepoEndpoint}`,
{ team_id: existing.id, ...this.repo, org: this.repo.owner }
{ team_slug: existing.slug, ...this.repo, org: this.repo.owner }
)
}

Expand Down
20 changes: 10 additions & 10 deletions test/unit/lib/plugins/teams.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -23,12 +23,12 @@ describe('Teams', () => {
beforeEach(() => {
github = {
paginate: jest.fn()
.mockResolvedValue()
.mockImplementation(async (fetch) => {
const response = await fetch()
return response.data
}),
.mockImplementation(async (fetch) => {
const response = await fetch()
return response.data
}),
teams: {
create: jest.fn().mockResolvedValue(),
getByName: jest.fn(),
addOrUpdateRepoPermissionsInOrg: jest.fn().mockResolvedValue()
},
Expand Down Expand Up @@ -61,7 +61,7 @@ describe('Teams', () => {
await plugin.sync()

expect(github.request).toHaveBeenCalledWith(
'PUT /teams/:team_id/repos/:owner/:repo',
'PUT /orgs/:owner/teams/:team_slug/repos/:owner/:repo',
{
org,
owner: org,
Expand All @@ -81,17 +81,17 @@ describe('Teams', () => {
permission: 'pull'
})

expectTeamDeleted(removedTeamId)
expectTeamDeleted(removedTeamName)
})

function expectTeamDeleted(teamId) {
function expectTeamDeleted(teamSlug) {
expect(github.request).toHaveBeenCalledWith(
'DELETE /teams/:team_id/repos/:owner/:repo',
'DELETE /orgs/:owner/teams/:team_slug/repos/:owner/:repo',
{
org,
owner: org,
repo: 'test',
team_id: teamId
team_slug: teamSlug
}
)
}
Expand Down
Loading