Skip to content
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
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
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
34 changes: 34 additions & 0 deletions lib/plugins/tags.js
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 })
)
}
}
3 changes: 2 additions & 1 deletion lib/settings.js
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,8 @@ Settings.PLUGINS = {
environments: require('./plugins/environments'),
teams: require('./plugins/teams'),
milestones: require('./plugins/milestones'),
branches: require('./plugins/branches')
branches: require('./plugins/branches'),
tags: require('./plugins/tags')
}

module.exports = Settings
3 changes: 3 additions & 0 deletions test/fixtures/tags-config.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
tag_protection:
Copy link
Member

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 existing branches, for example

- pattern: "v1"
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

i don think including pattern here is helpful since it is the only property. lets simplify to just be the pattern

- pattern: "duplicate"
39 changes: 39 additions & 0 deletions test/integration/plugins/tags.test.js
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())
})
})