Skip to content

Commit

Permalink
fix(teams): Deprecated team repo endpoint (#603)
Browse files Browse the repository at this point in the history
Co-authored-by: Stephen Collings <[email protected]>
  • Loading branch information
decyjphr and stevoland authored Feb 28, 2024
1 parent c2db40b commit d495aeb
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 16 deletions.
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

0 comments on commit d495aeb

Please sign in to comment.