Skip to content

Commit 53bc136

Browse files
authored
Merge pull request github#292 from nicacioliveira/fix/repository-security-update
Does fix bug inside of the Repository plugin related to updateRepo function ambiguity
2 parents bb684c1 + d11e97c commit 53bc136

File tree

3 files changed

+20
-18
lines changed

3 files changed

+20
-18
lines changed

.gitignore

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,3 +5,5 @@ node_modules/
55
private-key.pem
66
.env
77
*.pem
8+
9+
.vscode

lib/plugins/repository.js

Lines changed: 17 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,7 @@ const ignorableFields = [
4343
]
4444

4545
module.exports = class Repository {
46-
constructor (nop, github, repo, settings, installationId, log) {
46+
constructor(nop, github, repo, settings, installationId, log) {
4747
this.installationId = installationId
4848
this.github = github
4949
this.settings = Object.assign({ mediaType: { previews: ['nebula-preview'] } }, settings, repo)
@@ -59,7 +59,7 @@ module.exports = class Repository {
5959
delete this.settings.template
6060
}
6161

62-
sync () {
62+
sync() {
6363
const resArray = []
6464
this.log.debug(`Syncing Repo ${this.settings.name}`)
6565
this.settings.name = this.settings.name || this.settings.repo
@@ -100,9 +100,18 @@ module.exports = class Repository {
100100
}
101101
// Remove topics as it would be handled seperately
102102
delete this.settings.topics
103-
promises.push(this.updaterepo(resArray).then((resp) => {
104-
return this.updateSecurity(resp.data, resArray)
105-
}))
103+
104+
promises.push(async () => {
105+
106+
this.log.debug(`Updating repo with settings ${JSON.stringify(this.topics)} ${JSON.stringify(this.settings)}`)
107+
108+
if (this.nop) {
109+
resArray.push(new NopCommand(this.constructor.name, this.repo, this.github.repos.update.endpoint(this.settings), 'Update Repo'))
110+
return this.updateSecurity(resp.data, resArray)
111+
}
112+
113+
return this.updateSecurity(await this.github.repos.update(this.settings), resArray)
114+
})
106115
}
107116
if (topicChanges.hasChanges) {
108117
promises.push(this.updatetopics(resp.data, resArray))
@@ -156,7 +165,7 @@ module.exports = class Repository {
156165
})
157166
}
158167

159-
renameBranch (oldname, newname) {
168+
renameBranch(oldname, newname) {
160169
const parms = {
161170
owner: this.settings.owner,
162171
repo: this.settings.repo,
@@ -172,16 +181,7 @@ module.exports = class Repository {
172181
return this.github.repos.renameBranch(parms)
173182
}
174183

175-
updaterepo (resArray) {
176-
this.log.debug(`Updating repo with settings ${JSON.stringify(this.topics)} ${JSON.stringify(this.settings)}`)
177-
if (this.nop) {
178-
resArray.push(new NopCommand(this.constructor.name, this.repo, this.github.repos.update.endpoint(this.settings), 'Update Repo'))
179-
return Promise.resolve(resArray)
180-
}
181-
return this.github.repos.update(this.settings)
182-
}
183-
184-
updatetopics (repoData, resArray) {
184+
updatetopics(repoData, resArray) {
185185
const parms = {
186186
owner: this.settings.owner,
187187
repo: this.settings.repo,
@@ -212,7 +212,7 @@ module.exports = class Repository {
212212
}
213213

214214
// Added support for Code Security and Analysis
215-
updateSecurity (repoData, resArray) {
215+
updateSecurity(repoData, resArray) {
216216
if (this.security) {
217217
this.log(`Found repo with security settings ${JSON.stringify(this.security)}`)
218218
if (this.security?.enableVulnerabilityAlerts === true || this.security?.enableVulnerabilityAlerts === false) {

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
"repository": "https://github.com/github/safe-settings.git",
66
"main": "index.js",
77
"scripts": {
8-
"dev": "nodemon",
8+
"dev": "nodemon --inspect",
99
"start": "probot run ./index.js",
1010
"test": "npm-run-all --print-label --parallel lint:* --parallel test:*",
1111
"lint:es": "eslint .",

0 commit comments

Comments
 (0)