Skip to content
Draft
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
5 changes: 3 additions & 2 deletions .github/workflows/node-ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,9 @@ jobs:
strategy:
matrix:
node:
- 18.17.0
- 20.6.1
- 20.18.0
- 22.11.0
- 24.5.0
steps:
- uses: actions/checkout@08c6903cd8c0fde910a37f88322edcfb5dd907a8 # v5.0.0
- name: Setup node
Expand Down
37 changes: 20 additions & 17 deletions lib/plugins/collaborators.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,21 +12,21 @@ export default class Collaborators extends Diffable {
}
}

find () {
return this.github.repos
.listCollaborators({ repo: this.repo.repo, owner: this.repo.owner, affiliation: 'direct' })
.then(res => {
return res.data.map(user => {
return {
// Force all usernames to lowercase to avoid comparison issues.
username: user.login.toLowerCase(),
permission:
(user.permissions.admin && 'admin') ||
(user.permissions.push && 'push') ||
(user.permissions.pull && 'pull')
}
})
})
async find () {
const { data: collaborators } = await this.github.request('GET /repos/{owner}/{repo}/collaborators', {
repo: this.repo.repo,
owner: this.repo.owner,
affiliation: 'direct'
})

return collaborators.map(collaborator => ({
// Force all usernames to lowercase to avoid comparison issues.
username: collaborator.login.toLowerCase(),
permission:
(collaborator.permissions.admin && 'admin') ||
(collaborator.permissions.push && 'push') ||
(collaborator.permissions.pull && 'pull')
}))
}

comparator (existing, attrs) {
Expand All @@ -42,10 +42,13 @@ export default class Collaborators extends Diffable {
}

add (attrs) {
return this.github.repos.addCollaborator(Object.assign({}, attrs, this.repo))
return this.github.request('PUT /repos/{owner}/{repo}/collaborators/{username}', { ...attrs, ...this.repo })
}

remove (existing) {
return this.github.repos.removeCollaborator(Object.assign({ username: existing.username }, this.repo))
return this.github.request('DELETE /repos/{owner}/{repo}/collaborators/{username}', {
username: existing.username,
...this.repo
})
}
}
9 changes: 4 additions & 5 deletions lib/plugins/labels.js
Original file line number Diff line number Diff line change
Expand Up @@ -19,8 +19,7 @@ export default class Labels extends Diffable {
}

find () {
const options = this.github.issues.listLabelsForRepo.endpoint.merge(this.wrapAttrs({ per_page: 100 }))
return this.github.paginate(options)
return this.github.paginate('GET /repos/{owner}/{repo}/labels', this.wrapAttrs({ per_page: 100 }))
}

comparator (existing, attrs) {
Expand All @@ -32,15 +31,15 @@ export default class Labels extends Diffable {
}

update (existing, attrs) {
return this.github.issues.updateLabel(this.wrapAttrs(attrs))
return this.github.request('PATCH /repos/{owner}/{repo}/labels/{name}', this.wrapAttrs(attrs))
}

add (attrs) {
return this.github.issues.createLabel(this.wrapAttrs(attrs))
return this.github.request('POST /repos/{owner}/{repo}/labels', this.wrapAttrs(attrs))
}

remove (existing) {
return this.github.issues.deleteLabel(this.wrapAttrs({ name: existing.name }))
return this.github.request('DELETE /repos/{owner}/{repo}/labels/{name}', this.wrapAttrs({ name: existing.name }))
}

wrapAttrs (attrs) {
Expand Down
26 changes: 17 additions & 9 deletions lib/plugins/milestones.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,10 +14,7 @@ export default class Milestones extends Diffable {
}

find () {
const options = this.github.issues.listMilestones.endpoint.merge(
Object.assign({ per_page: 100, state: 'all' }, this.repo)
)
return this.github.paginate(options)
return this.github.paginate('GET /repos/{owner}/{repo}/milestones', { per_page: 100, state: 'all', ...this.repo })
}

comparator (existing, attrs) {
Expand All @@ -31,20 +28,31 @@ export default class Milestones extends Diffable {
update (existing, attrs) {
const { owner, repo } = this.repo

return this.github.issues.updateMilestone(
Object.assign({ milestone_number: existing.number }, attrs, { owner, repo })
)
return this.github.request('PATCH /repos/{owner}/{repo}/milestones/{milestone_number}', {
milestone_number: existing.number,
...attrs,
owner,
repo
})
}

add (attrs) {
const { owner, repo } = this.repo

return this.github.issues.createMilestone(Object.assign({}, attrs, { owner, repo }))
return this.github.request('POST /repos/{owner}/{repo}/milestones', {
...attrs,
owner,
repo
})
}

remove (existing) {
const { owner, repo } = this.repo

return this.github.issues.deleteMilestone(Object.assign({ milestone_number: existing.number }, { owner, repo }))
return this.github.request('DELETE /repos/{owner}/{repo}/milestones/{milestone_number}', {
milestone_number: existing.number,
owner,
repo
})
}
}
48 changes: 23 additions & 25 deletions lib/plugins/repository.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,33 +3,31 @@ const enableAutomatedSecurityFixes = ({ github, settings, enabled }) => {
return Promise.resolve()
}

const args = {
const verb = enabled ? 'PUT' : 'DELETE'

return github.request(`${verb} /repos/{owner}/{repo}/automated-security-fixes`, {
owner: settings.owner,
repo: settings.repo,
mediaType: {
previews: ['london']
}
}
const methodName = enabled ? 'enableAutomatedSecurityFixes' : 'disableAutomatedSecurityFixes'

return github.repos[methodName](args)
})
}

const enableVulnerabilityAlerts = ({ github, settings, enabled }) => {
if (enabled === undefined) {
return Promise.resolve()
}

const args = {
const verb = enabled ? 'PUT' : 'DELETE'

return github.request(`${verb} /repos/{owner}/{repo}/vulnerability-alerts`, {
owner: settings.owner,
repo: settings.repo,
mediaType: {
previews: ['dorian']
}
}
const methodName = enabled ? 'enableVulnerabilityAlerts' : 'disableVulnerabilityAlerts'

return github.repos[methodName](args)
})
}

export default class Repository {
Expand All @@ -46,23 +44,23 @@ export default class Repository {
delete this.settings.enable_automated_security_fixes
}

sync () {
async sync () {
this.settings.name = this.settings.name || this.settings.repo
return this.github.repos
.update(this.settings)
.then(() => {
if (this.topics) {
return this.github.repos.replaceAllTopics({
owner: this.settings.owner,
repo: this.settings.repo,
names: this.topics.split(/\s*,\s*/),
mediaType: {
previews: ['mercy']
}
})

await this.github.request('PATCH /repos/{owner}/{repo}', this.settings)

if (this.topics) {
await this.github.request('PUT /repos/{owner}/{repo}/topics', {
owner: this.settings.owner,
repo: this.settings.repo,
names: this.topics.split(/\s*,\s*/),
mediaType: {
previews: ['mercy']
}
})
.then(() => enableVulnerabilityAlerts({ enabled: this.enableVulnerabilityAlerts, ...this }))
.then(() => enableAutomatedSecurityFixes({ enabled: this.enableAutomatedSecurityFixes, ...this }))
}

await enableVulnerabilityAlerts({ enabled: this.enableVulnerabilityAlerts, ...this })
await enableAutomatedSecurityFixes({ enabled: this.enableAutomatedSecurityFixes, ...this })
}
}
22 changes: 17 additions & 5 deletions lib/plugins/rulesets.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,15 @@ import Diffable from './diffable.js'

export default class Rulesets extends Diffable {
async find () {
const { data: rulesets } = await this.github.repos.getRepoRulesets({ ...this.repo, includes_parents: false })
const { data: rulesets } = await this.github.request('GET /repos/{owner}/{repo}/rulesets', {
...this.repo,
includes_parents: false
})

const expandedRulesetsData = await Promise.all(
rulesets.map(({ id }) => this.github.repos.getRepoRuleset({ ...this.repo, ruleset_id: id }))
rulesets.map(({ id }) =>
this.github.request('GET /repos/{owner}/{repo}/rulesets/{ruleset_id}', { ...this.repo, ruleset_id: id })
)
)

return expandedRulesetsData.map(({ data }) => data)
Expand All @@ -34,14 +39,21 @@ export default class Rulesets extends Diffable {
}

update (existing, attrs) {
return this.github.repos.updateRepoRuleset({ ...this.repo, ruleset_id: existing.id, ...attrs })
return this.github.request('PUT /repos/{owner}/{repo}/rulesets/{ruleset_id}', {
...this.repo,
ruleset_id: existing.id,
...attrs
})
}

remove (existing) {
return this.github.repos.deleteRepoRuleset({ ...this.repo, ruleset_id: existing.id })
return this.github.request('DELETE /repos/{owner}/{repo}/rulesets/{ruleset_id}', {
...this.repo,
ruleset_id: existing.id
})
}

async add (attrs) {
await this.github.repos.createRepoRuleset({ ...this.repo, ...attrs })
await this.github.request('POST /repos/{owner}/{repo}/rulesets', { ...this.repo, ...attrs })
}
}
6 changes: 3 additions & 3 deletions lib/plugins/teams.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,11 @@ import Diffable from './diffable.js'

// 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 = '/teams/{team_id}/repos/{owner}/{repo}'

export default class Teams extends Diffable {
find () {
return this.github.repos.listTeams(this.repo).then(res => res.data)
return this.github.request('GET /repos/{owner}/{repo}/teams', this.repo).then(res => res.data)
}

comparator (existing, attrs) {
Expand All @@ -22,7 +22,7 @@ export default class Teams extends Diffable {
}

async add (attrs) {
const { data: existing } = await this.github.request('GET /orgs/:org/teams/:team_slug', {
const { data: existing } = await this.github.request('GET /orgs/{org}/teams/{team_slug}', {
org: this.repo.owner,
team_slug: attrs.name
})
Expand Down
Loading