Skip to content
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
5 changes: 3 additions & 2 deletions .github/workflows/create-pre-release.yml
Original file line number Diff line number Diff line change
Expand Up @@ -71,9 +71,10 @@ jobs:
- name: Run Functional Tests
id: functionaltest
run: |
docker run --env APP_ID=${{ secrets.APP_ID }} --env PRIVATE_KEY=${{ secrets.PRIVATE_KEY }} --env WEBHOOK_SECRET=${{ secrets.WEBHOOK_SECRET }} -d -p 3000:3000 ${{ env.REGISTRY }}/${{ env.IMAGE_NAME }}:main-enterprise
CONTAINER_ID=$(docker run --env APP_ID=${{ secrets.APP_ID }} --env PRIVATE_KEY=${{ secrets.PRIVATE_KEY }} --env WEBHOOK_SECRET=${{ secrets.WEBHOOK_SECRET }} --env NODE_ENV=development -d -p 3000:3000 ${{ env.REGISTRY }}/${{ env.IMAGE_NAME }}:main-enterprise)
sleep 10
curl http://localhost:3000
docker logs $CONTAINER_ID || true
curl --fail --retry 5 --retry-delay 3 --retry-connrefused http://localhost:3000
- run: echo "${{ github.ref }}"
- name: Tag a final release
id: prerelease
Expand Down
1 change: 0 additions & 1 deletion Dockerfile
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
FROM node:22-alpine
WORKDIR /opt/safe-settings
ENV NODE_ENV production
ENV HOST=0.0.0.0
## Set the Labels
LABEL version="1.0" \
description="Probot app which is a modified version of Settings Probot GitHub App" \
Expand Down
14 changes: 7 additions & 7 deletions index.js
Original file line number Diff line number Diff line change
Expand Up @@ -199,7 +199,7 @@ module.exports = (robot, { getRouter }, Settings = require('./lib/settings')) =>
async function createCheckRun (context, pull_request, head_sha, head_branch) {
const { payload } = context
// robot.log.debug(`Check suite was requested! for ${context.repo()} ${pull_request.number} ${head_sha} ${head_branch}`)
const res = await context.octokit.checks.create({
const res = await context.octokit.rest.checks.create({
owner: payload.repository.owner.login,
repo: payload.repository.name,
name: 'Safe-setting validator',
Expand All @@ -211,13 +211,13 @@ module.exports = (robot, { getRouter }, Settings = require('./lib/settings')) =>
async function info () {
const github = await robot.auth()
const installations = await github.paginate(
github.apps.listInstallations.endpoint.merge({ per_page: 100 })
github.rest.apps.listInstallations.endpoint.merge({ per_page: 100 })
)
robot.log.debug(`installations: ${JSON.stringify(installations)}`)
if (installations.length > 0) {
const installation = installations[0]
const github = await robot.auth(installation.id)
const app = await github.apps.getAuthenticated()
const app = await github.rest.apps.getAuthenticated()
appSlug = app.data.slug
robot.log.debug(`Validated the app is configured properly = \n${JSON.stringify(app.data, null, 2)}`)
}
Expand All @@ -228,7 +228,7 @@ module.exports = (robot, { getRouter }, Settings = require('./lib/settings')) =>
const github = await robot.auth()

const installations = await github.paginate(
github.apps.listInstallations.endpoint.merge({ per_page: 100 })
github.rest.apps.listInstallations.endpoint.merge({ per_page: 100 })
)

if (installations.length > 0) {
Expand Down Expand Up @@ -577,11 +577,11 @@ module.exports = (robot, { getRouter }, Settings = require('./lib/settings')) =>
output: { title: 'Starting NOP', summary: 'initiating...' }
}
robot.log.debug(`Updating check run ${JSON.stringify(params)}`)
await context.octokit.checks.update(params)
await context.octokit.rest.checks.update(params)

params = Object.assign(context.repo(), { pull_number: pull_request.number })

const changes = await context.octokit.pulls.listFiles(params)
const changes = await context.octokit.rest.pulls.listFiles(params)
const files = changes.data.map(f => { return f.filename })

const settingsModified = files.includes(Settings.FILE_PATH)
Expand Down Expand Up @@ -609,7 +609,7 @@ module.exports = (robot, { getRouter }, Settings = require('./lib/settings')) =>
output: { title: 'No Safe-settings changes detected', summary: 'No changes detected' }
}
robot.log.debug(`Completing check run ${JSON.stringify(params)}`)
await context.octokit.checks.update(params)
await context.octokit.rest.checks.update(params)
})

robot.on('repository.created', async context => {
Expand Down
2 changes: 1 addition & 1 deletion lib/configManager.js
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ module.exports = class ConfigManager {
try {
const repo = { owner: this.context.repo().owner, repo: env.ADMIN_REPO }
const params = Object.assign(repo, { path: filePath, ref: this.ref })
const response = await this.context.octokit.repos.getContent(params).catch(e => {
const response = await this.context.octokit.rest.repos.getContent(params).catch(e => {
this.log.error(`Error getting settings ${e}`)
})

Expand Down
6 changes: 3 additions & 3 deletions lib/plugins/archive.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ module.exports = class Archive {

async getRepo () {
try {
const { data } = await this.github.repos.get({
const { data } = await this.github.rest.repos.get({
owner: this.repo.owner,
repo: this.repo.repo
})
Expand All @@ -32,13 +32,13 @@ module.exports = class Archive {
return new NopCommand(
this.constructor.name,
this.repo,
this.github.repos.update.endpoint(this.settings),
this.github.rest.repos.update.endpoint(this.settings),
change,
'INFO'
)
}

const { data } = await this.github.repos.update({
const { data } = await this.github.rest.repos.update({
owner: this.repo.owner,
repo: this.repo.repo,
archived
Expand Down
10 changes: 5 additions & 5 deletions lib/plugins/autolinks.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ module.exports = class Autolinks extends Diffable {
// }

async find () {
const { data } = await this.github.repos.listAutolinks(this.repo)
const { data } = await this.github.rest.repos.listAutolinks(this.repo)
return data
}

Expand Down Expand Up @@ -43,13 +43,13 @@ module.exports = class Autolinks extends Diffable {
return new NopCommand(
this.constructor.name,
this.repo,
this.github.repos.createAutolink.endpoint(attrs),
this.github.rest.repos.createAutolink.endpoint(attrs),
'Add autolink'
)
}

try {
return this.github.repos.createAutolink(attrs)
return this.github.rest.repos.createAutolink(attrs)
} catch (e) {
if (e?.response?.data?.errors?.[0]?.code === 'already_exists') {
this.log.debug(`Did not update ${key_prefix}, as it already exists`)
Expand All @@ -68,10 +68,10 @@ module.exports = class Autolinks extends Diffable {
return new NopCommand(
this.constructor.name,
this.repo,
this.github.repos.deleteAutolink.endpoint(attrs),
this.github.rest.repos.deleteAutolink.endpoint(attrs),
'Remove autolink'
)
}
return this.github.repos.deleteAutolink(attrs)
return this.github.rest.repos.deleteAutolink(attrs)
}
}
18 changes: 9 additions & 9 deletions lib/plugins/branches.js
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ module.exports = class Branches extends ErrorStash {

sync () {
const resArray = []
return this.github.repos.get(this.repo).then((currentRepo) => {
return this.github.rest.repos.get(this.repo).then((currentRepo) => {
return Promise.all(
this.branches
.filter(branch => branch.protection !== undefined)
Expand All @@ -39,12 +39,12 @@ module.exports = class Branches extends ErrorStash {
const params = Object.assign({}, p)
if (this.nop) {
resArray.push(
new NopCommand(this.constructor.name, this.repo, this.github.repos.deleteBranchProtection.endpoint(params), 'Delete Branch Protection')
new NopCommand(this.constructor.name, this.repo, this.github.rest.repos.deleteBranchProtection.endpoint(params), 'Delete Branch Protection')
)
return Promise.resolve(resArray)
}

return this.github.repos.deleteBranchProtection(params).catch(e => { return [] })
return this.github.rest.repos.deleteBranchProtection(params).catch(e => { return [] })
} else {
// Branch protection is not empty
let p = Object.assign(this.repo, { branch: branch.name })
Expand All @@ -54,7 +54,7 @@ module.exports = class Branches extends ErrorStash {
}
// Hack to handle closures and keep params from changing
const params = Object.assign({}, p)
return this.github.repos.getBranchProtection(params).then((result) => {
return this.github.rest.repos.getBranchProtection(params).then((result) => {
const mergeDeep = new MergeDeep(this.log, this.github, ignorableFields)
const changes = mergeDeep.compareDeep({ branch: { protection: this.reformatAndReturnBranchProtection(result.data) } }, { branch: { protection: Overrides.removeOverrides(overrides, branch.protection, result.data) } })
const results = { msg: `Followings changes will be applied to the branch protection for ${params.branch.name} branch`, additions: changes.additions, modifications: changes.modifications, deletions: changes.deletions }
Expand All @@ -76,24 +76,24 @@ module.exports = class Branches extends ErrorStash {
Object.assign(params, branch.protection, { headers: previewHeaders })

if (this.nop) {
resArray.push(new NopCommand(this.constructor.name, this.repo, this.github.repos.updateBranchProtection.endpoint(params), 'Add Branch Protection'))
resArray.push(new NopCommand(this.constructor.name, this.repo, this.github.rest.repos.updateBranchProtection.endpoint(params), 'Add Branch Protection'))
return Promise.resolve(resArray)
}
this.log.debug(`Adding branch protection ${JSON.stringify(params)}`)
return this.github.repos.updateBranchProtection(params).then(res => this.log.debug(`Branch protection applied successfully ${JSON.stringify(res.url)}`)).catch(e => { this.logError(`Error applying branch protection ${JSON.stringify(e)}`); return [] })
return this.github.rest.repos.updateBranchProtection(params).then(res => this.log.debug(`Branch protection applied successfully ${JSON.stringify(res.url)}`)).catch(e => { this.logError(`Error applying branch protection ${JSON.stringify(e)}`); return [] })
}).catch((e) => {
if (e.status === 404) {
Object.assign(params, Overrides.removeOverrides(overrides, branch.protection, {}), { headers: previewHeaders })
if (this.nop) {
resArray.push(new NopCommand(this.constructor.name, this.repo, this.github.repos.updateBranchProtection.endpoint(params), 'Add Branch Protection'))
resArray.push(new NopCommand(this.constructor.name, this.repo, this.github.rest.repos.updateBranchProtection.endpoint(params), 'Add Branch Protection'))
return Promise.resolve(resArray)
}
this.log.debug(`Adding branch protection ${JSON.stringify(params)}`)
return this.github.repos.updateBranchProtection(params).then(res => this.log.debug(`Branch protection applied successfully ${JSON.stringify(res.url)}`)).catch(e => { this.logError(`Error applying branch protection ${JSON.stringify(e)}`); return [] })
return this.github.rest.repos.updateBranchProtection(params).then(res => this.log.debug(`Branch protection applied successfully ${JSON.stringify(res.url)}`)).catch(e => { this.logError(`Error applying branch protection ${JSON.stringify(e)}`); return [] })
} else {
this.logError(e)
if (this.nop) {
resArray.push(new NopCommand(this.constructor.name, this.repo, this.github.repos.updateBranchProtection.endpoint(params), `${e}`, 'ERROR'))
resArray.push(new NopCommand(this.constructor.name, this.repo, this.github.rest.repos.updateBranchProtection.endpoint(params), `${e}`, 'ERROR'))
return Promise.resolve(resArray)
}
}
Expand Down
20 changes: 10 additions & 10 deletions lib/plugins/collaborators.js
Original file line number Diff line number Diff line change
Expand Up @@ -20,8 +20,8 @@ module.exports = class Collaborators extends Diffable {
// 'direct' means all collaborators with permissions to an organization-owned repository, regardless of organization membership status. (includes outside collaborators)
// 'all' means all collaborators the authenticated user can see.
// We are using 'direct' to avoid double listing users outside collaborators and team members.
return Promise.all([this.github.repos.listCollaborators({ repo: this.repo.repo, owner: this.repo.owner, affiliation: 'direct' }),
this.github.repos.listInvitations({ repo: this.repo.repo, owner: this.repo.owner })])
return Promise.all([this.github.rest.repos.listCollaborators({ repo: this.repo.repo, owner: this.repo.owner, affiliation: 'direct' }),
this.github.rest.repos.listInvitations({ repo: this.repo.repo, owner: this.repo.owner })])
.then(res => {
const mapCollaborator = user => {
return {
Expand Down Expand Up @@ -74,10 +74,10 @@ module.exports = class Collaborators extends Diffable {
const data = Object.assign({}, attrs, this.repo)
if (this.nop) {
return Promise.resolve([
new NopCommand(this.constructor.name, this.repo, this.github.repos.addCollaborator.endpoint(data), 'Add Collaborators')
new NopCommand(this.constructor.name, this.repo, this.github.rest.repos.addCollaborator.endpoint(data), 'Add Collaborators')
])
}
return this.github.repos.addCollaborator(data)
return this.github.rest.repos.addCollaborator(data)
}

updateInvite (invitation_id, permissions) {
Expand All @@ -89,31 +89,31 @@ module.exports = class Collaborators extends Diffable {
}, this.repo)
if (this.nop) {
return Promise.resolve([
new NopCommand(this.constructor.name, this.repo, this.github.repos.updateInvitation.endpoint(data), 'Update Invitation')
new NopCommand(this.constructor.name, this.repo, this.github.rest.repos.updateInvitation.endpoint(data), 'Update Invitation')
])
}
return this.github.repos.updateInvitation(data)
return this.github.rest.repos.updateInvitation(data)
}

remove (existing) {
if (existing.pendinginvite) {
const data = Object.assign({ invitation_id: existing.invitation_id }, this.repo)
if (this.nop) {
return Promise.resolve([
new NopCommand(this.constructor.name, this.repo, this.github.repos.deleteInvitation.endpoint(data),
new NopCommand(this.constructor.name, this.repo, this.github.rest.repos.deleteInvitation.endpoint(data),
'Delete Invitation')
])
}
return this.github.repos.deleteInvitation(data)
return this.github.rest.repos.deleteInvitation(data)
} else {
const data = Object.assign({ username: existing.username }, this.repo)
if (this.nop) {
return Promise.resolve([
new NopCommand(this.constructor.name, this.repo, this.github.repos.removeCollaborator.endpoint(data),
new NopCommand(this.constructor.name, this.repo, this.github.rest.repos.removeCollaborator.endpoint(data),
'Remove Collaborator')
])
}
return this.github.repos.removeCollaborator(data)
return this.github.rest.repos.removeCollaborator(data)
}
}
}
6 changes: 3 additions & 3 deletions lib/plugins/custom_properties.js
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ module.exports = class CustomProperties extends Diffable {
this.log.debug(`Getting all custom properties for the repo ${repoFullName}`)

const customProperties = await this.github.paginate(
this.github.repos.getCustomPropertiesValues,
this.github.rest.repos.getCustomPropertiesValues,
{
owner,
repo,
Expand Down Expand Up @@ -82,14 +82,14 @@ module.exports = class CustomProperties extends Diffable {
return new NopCommand(
this.constructor.name,
this.repo,
this.github.repos.createOrUpdateCustomPropertiesValues.endpoint(params),
this.github.rest.repos.createOrUpdateCustomPropertiesValues.endpoint(params),
`${operation} Custom Property`
)
}

try {
this.log.debug(`${operation} Custom Property "${name}" for the repo ${repoFullName}`)
await this.github.repos.createOrUpdateCustomPropertiesValues(params)
await this.github.rest.repos.createOrUpdateCustomPropertiesValues(params)
this.log.debug(`Successfully ${operation.toLowerCase()}d Custom Property "${name}" for the repo ${repoFullName}`)
} catch (e) {
this.logError(`Error during ${operation} Custom Property "${name}" for the repo ${repoFullName}: ${e.message || e}`)
Expand Down
16 changes: 8 additions & 8 deletions lib/plugins/labels.js
Original file line number Diff line number Diff line change
Expand Up @@ -34,8 +34,8 @@ module.exports = class Labels extends Diffable {

find () {
this.log.debug(`Finding labels for ${JSON.stringify(this.wrapAttrs({ per_page: 100 }))}`)
const options = this.github.issues.listLabelsForRepo.endpoint.merge(this.wrapAttrs({ per_page: 100 }))
return this.github.repos.get(this.repo).then(() => {
const options = this.github.rest.issues.listLabelsForRepo.endpoint.merge(this.wrapAttrs({ per_page: 100 }))
return this.github.rest.repos.get(this.repo).then(() => {
return this.github.paginate(options)
})
.catch(e => {
Expand Down Expand Up @@ -63,20 +63,20 @@ module.exports = class Labels extends Diffable {
delete attrs.oldname
if (this.nop) {
return Promise.resolve([
new NopCommand(this.constructor.name, this.repo, this.github.issues.updateLabel.endpoint(this.wrapAttrs(attrs)), 'Update label')
new NopCommand(this.constructor.name, this.repo, this.github.rest.issues.updateLabel.endpoint(this.wrapAttrs(attrs)), 'Update label')
])
}
return this.github.issues.updateLabel(this.wrapAttrs(attrs))
return this.github.rest.issues.updateLabel(this.wrapAttrs(attrs))
}

add (attrs) {
if (this.nop) {
return Promise.resolve([
new NopCommand(this.constructor.name, this.repo, this.github.issues.createLabel.endpoint(this.wrapAttrs(attrs)), 'Create label')
new NopCommand(this.constructor.name, this.repo, this.github.rest.issues.createLabel.endpoint(this.wrapAttrs(attrs)), 'Create label')
])
}
this.log.debug(`Creating labels for ${JSON.stringify(attrs, null, 4)}`)
return this.github.issues.createLabel(this.wrapAttrs(attrs)).catch(e => this.logError(` ${JSON.stringify(e)}`))
return this.github.rest.issues.createLabel(this.wrapAttrs(attrs)).catch(e => this.logError(` ${JSON.stringify(e)}`))
}

remove (existing) {
Expand All @@ -85,10 +85,10 @@ module.exports = class Labels extends Diffable {
}
if (this.nop) {
return Promise.resolve([
new NopCommand(this.constructor.name, this.repo, this.github.issues.deleteLabel.endpoint(this.wrapAttrs({ name: existing.name })), 'Delete label')
new NopCommand(this.constructor.name, this.repo, this.github.rest.issues.deleteLabel.endpoint(this.wrapAttrs({ name: existing.name })), 'Delete label')
])
}
return this.github.issues.deleteLabel(this.wrapAttrs({ name: existing.name }))
return this.github.rest.issues.deleteLabel(this.wrapAttrs({ name: existing.name }))
}

wrapAttrs (attrs) {
Expand Down
8 changes: 4 additions & 4 deletions lib/plugins/milestones.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ module.exports = class Milestones extends Diffable {
}

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

Expand All @@ -29,18 +29,18 @@ module.exports = 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.rest.issues.updateMilestone(Object.assign({ 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.rest.issues.createMilestone(Object.assign({}, 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.rest.issues.deleteMilestone(Object.assign({ milestone_number: existing.number }, { owner, repo }))
}
}
Loading
Loading