-
Notifications
You must be signed in to change notification settings - Fork 178
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Adding ability to manage tag protections via settings #795
Open
ctoestreich
wants to merge
2
commits into
repository-settings:master
Choose a base branch
from
ctoestreich:refactor/ctoestreich/tag-protection
base: master
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
2 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
const Diffable = require('./diffable') | ||
|
||
module.exports = class Tags extends Diffable { | ||
async find () { | ||
return this.github.repos.listTagProtection(this.repo).then(res => res.data) | ||
} | ||
|
||
comparator (existing, attrs) { | ||
return existing.pattern === attrs.pattern | ||
} | ||
|
||
changed (existing, attrs) { | ||
return existing.pattern !== attrs.pattern | ||
} | ||
|
||
async update (existing, attrs) { | ||
const { owner, repo } = this.repo | ||
|
||
this.github.issues.deleteTagProtection(Object.assign({ tag_protection_id: existing.id }, attrs, { owner, repo })) | ||
return this.github.repos.createTagProtection(Object.assign({ pattern: attrs.pattern }, attrs, { owner, repo })) | ||
} | ||
|
||
add (attrs) { | ||
const { owner, repo } = this.repo | ||
return this.github.repos.createTagProtection(Object.assign({ pattern: attrs.pattern }, attrs, { owner, repo })) | ||
} | ||
|
||
remove (existing) { | ||
const { owner, repo } = this.repo | ||
return this.github.repos.deleteTagProtection( | ||
Object.assign({ tag_protection_id: existing.id }, existing, { owner, repo }) | ||
) | ||
} | ||
} |
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 |
---|---|---|
@@ -0,0 +1,3 @@ | ||
tag_protection: | ||
- pattern: "v1" | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. i don think including |
||
- pattern: "duplicate" |
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,39 @@ | ||
const { | ||
initializeNock, | ||
loadInstance, | ||
teardownNock, | ||
repository, | ||
buildTriggerEvent, | ||
defineSettingsFileForScenario | ||
} = require('../common') | ||
const { OK, CREATED, NO_CONTENT } = require('http-status-codes') | ||
describe('tags plugin', function () { | ||
let probot, githubScope | ||
|
||
beforeEach(async () => { | ||
githubScope = initializeNock() | ||
probot = await loadInstance() | ||
}) | ||
|
||
afterEach(() => { | ||
teardownNock(githubScope) | ||
}) | ||
|
||
it('configures tags', async () => { | ||
await defineSettingsFileForScenario('tags-config.yml', githubScope) | ||
githubScope.get(`/repos/${repository.owner.name}/${repository.name}/tags/protection`).reply(OK, [ | ||
{ id: '1', pattern: '*' }, | ||
{ id: '2', pattern: 'duplicate' } | ||
]) | ||
|
||
githubScope | ||
.post(`/repos/${repository.owner.name}/${repository.name}/tags/protection`, body => { | ||
expect(body).toMatchObject({ pattern: 'v1' }) | ||
return true | ||
}) | ||
.reply(CREATED) | ||
githubScope.delete(`/repos/${repository.owner.name}/${repository.name}/tags/protection/1`).reply(NO_CONTENT) | ||
|
||
await probot.receive(buildTriggerEvent()) | ||
}) | ||
}) |
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
lets simplify this to
tags
to be more similar to the existingbranches
, for example