Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #286 from aaricpittman/vulnerability-alerts
- Loading branch information
Showing
7 changed files
with
237 additions
and
21 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,24 +1,67 @@ | ||
const enableAutomatedSecurityFixes = ({ github, settings, enabled }) => { | ||
if (enabled === undefined) { | ||
return Promise.resolve() | ||
} | ||
|
||
const args = { | ||
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 = { | ||
owner: settings.owner, | ||
repo: settings.repo, | ||
mediaType: { | ||
previews: ['dorian'] | ||
} | ||
} | ||
const methodName = enabled ? 'enableVulnerabilityAlerts' : 'disableVulnerabilityAlerts' | ||
|
||
return github.repos[methodName](args) | ||
} | ||
|
||
module.exports = class Repository { | ||
constructor (github, repo, settings) { | ||
this.github = github | ||
this.settings = Object.assign({ mediaType: { previews: ['baptiste'] } }, settings, repo) | ||
this.topics = this.settings.topics | ||
delete this.settings.topics | ||
|
||
this.enableVulnerabilityAlerts = this.settings.enable_vulnerability_alerts | ||
delete this.settings.enable_vulnerability_alerts | ||
|
||
this.enableAutomatedSecurityFixes = this.settings.enable_automated_security_fixes | ||
delete this.settings.enable_automated_security_fixes | ||
} | ||
|
||
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.replaceTopics({ | ||
owner: this.settings.owner, | ||
repo: this.settings.repo, | ||
names: this.topics.split(/\s*,\s*/), | ||
mediaType: { | ||
previews: ['mercy'] | ||
} | ||
}) | ||
} | ||
}) | ||
return this.github.repos.update(this.settings) | ||
.then(() => { | ||
if (this.topics) { | ||
return this.github.repos.replaceTopics({ | ||
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 })) | ||
} | ||
} |
5 changes: 5 additions & 0 deletions
5
test/fixtures/repository/basic-config-with-security-fixes.yml
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
repository: | ||
name: bar | ||
delete_branch_on_merge: true | ||
is_template: true | ||
enable_automated_security_fixes: true |
5 changes: 5 additions & 0 deletions
5
test/fixtures/repository/basic-config-with-vulnerability-alerts.yml
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
repository: | ||
name: bar | ||
delete_branch_on_merge: true | ||
is_template: true | ||
enable_vulnerability_alerts: true |
File renamed without changes.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters