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

Make it compatible with Probot 12 #23

Open
wants to merge 5 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
2 changes: 1 addition & 1 deletion index.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ const Configuration = require('./lib/configuration')
const HaltedError = require('./lib/errors/halted')

module.exports = robot => {
robot.on('*', async context => {
robot.webhooks.onAny(async context => {
const config = await Configuration.load(context, '.github/probot.js')
return config.execute().catch(err => {
if (err instanceof HaltedError) {
Expand Down
2 changes: 1 addition & 1 deletion lib/configuration.js
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ module.exports = class Configuration {
const options = path
? this.context.repo(url(path, this.source))
: this.source
return this.context.github.repos.getContent(options).then(res =>
return this.context.octokit.repos.getContent(options).then(res =>
Buffer.from(res.data.content, 'base64').toString()
)
}
Expand Down
2 changes: 1 addition & 1 deletion lib/plugins/filter.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ module.exports = class Filter extends Plugin {
on (context, ...events) {
const res = events.find(e => {
const [name, action] = e.split('.')
return name === context.event && (!action || action === context.payload.action)
return name === context.name && (!action || action === context.payload.action)
})

return res
Expand Down
22 changes: 11 additions & 11 deletions lib/plugins/issues.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,48 +4,48 @@ const Plugin = require('../plugin')
module.exports = class Issues extends Plugin {
comment (context, content) {
const template = handlebars.compile(content)(context.payload)
return context.github.issues.createComment(context.issue({body: template}))
return context.octokit.issues.createComment(context.issue({body: template}))
}

assign (context, ...assignees) {
return context.github.issues.addAssigneesToIssue(context.issue({assignees}))
return context.octokit.issues.addAssigneesToIssue(context.issue({assignees}))
}

unassign (context, ...assignees) {
return context.github.issues.removeAssigneesFromIssue(context.issue({body: {assignees}}))
return context.octokit.issues.removeAssigneesFromIssue(context.issue({body: {assignees}}))
}

label (context, ...labels) {
return context.github.issues.addLabels(context.issue({labels}))
return context.octokit.issues.addLabels(context.issue({labels}))
}

unlabel (context, ...labels) {
return labels.map(label => {
return context.github.issues.removeLabel(
return context.octokit.issues.removeLabel(
context.issue({name: label})
)
})
}

lock (context) {
return context.github.issues.lock(context.issue({}))
return context.octokit.issues.lock(context.issue({}))
}

unlock (context) {
return context.github.issues.unlock(context.issue({}))
return context.octokit.issues.unlock(context.issue({}))
}

open (context) {
return context.github.issues.edit(context.issue({state: 'open'}))
return context.octokit.issues.update(context.issue({state: 'open'}))
}

close (context) {
return context.github.issues.edit(context.issue({state: 'closed'}))
return context.octokit.issues.update(context.issue({state: 'closed'}))
}

deleteComment (context) {
const comment = context.payload.comment
const github = context.github
const github = context.octokit

const deleteFunction =
(comment.pull_request_review_id && github.pullRequests.deleteComment) ||
Expand All @@ -60,7 +60,7 @@ module.exports = class Issues extends Plugin {
const titleTemplate = handlebars.compile(content.title)(context.payload)
const bodyTemplate = handlebars.compile(body)(context.payload)

return context.github.issues.create(context.repo({
return context.octokit.issues.create(context.repo({
title: titleTemplate,
body: bodyTemplate,
assignees: content.assignees,
Expand Down
10 changes: 5 additions & 5 deletions lib/plugins/projects.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ module.exports = class Projects extends Plugin {
createCard (context, content) {
return Promise.resolve().then(() => {
// Get all projects for repo
Projects.getRepoProjects(context)
Projects.listForRepo(context)
// Then get the projectID for desired project
.then(response => Projects.getID(response, content.project))
// Then get the columns for that project
Expand All @@ -20,7 +20,7 @@ module.exports = class Projects extends Plugin {
.then(projectColumns => Projects.getID(projectColumns, content.column))
// Then create the card
.then(columnID => {
context.github.projects.createProjectCard({
context.octokit.projects.createProjectCard({
column_id: columnID,
content_id: context.payload.issue.id,
content_type: 'Issue'
Expand All @@ -35,8 +35,8 @@ module.exports = class Projects extends Plugin {
* @param context
* @returns {*}
*/
static getRepoProjects (context) {
return context.github.projects.getRepoProjects({
static listForRepo (context) {
return context.octokit.projects.listForRepo({
owner: context.payload.repository.owner.login,
repo: context.payload.repository.name
})
Expand Down Expand Up @@ -64,6 +64,6 @@ module.exports = class Projects extends Plugin {
* @returns {*}
*/
static getProjectColumns (context, projectId) {
return context.github.projects.getProjectColumns({projectId})
return context.octokit.projects.getProjectColumns({projectId})
}
}
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
},
"dependencies": {
"handlebars": "^4.0.6",
"probot": "^6.1.0"
"probot": "^12.1.0"
},
"engines": {
"node": ">= 7.7.0",
Expand Down
4 changes: 2 additions & 2 deletions test/configuration.js
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ describe('Configuration', () => {

it('includes from the repo', () => {
config.include('foo.js')
expect(context.github.repos.getContent).toHaveBeenCalledWith({
expect(context.octokit.repos.getContent).toHaveBeenCalledWith({
path: 'foo.js'
})
})
Expand All @@ -47,7 +47,7 @@ describe('Configuration', () => {

it('includes from another repository', () => {
config.include('atom/configs:foo.js#branch')
expect(context.github.repos.getContent).toHaveBeenCalledWith({
expect(context.octokit.repos.getContent).toHaveBeenCalledWith({
owner: 'atom',
repo: 'configs',
path: 'foo.js',
Expand Down
4 changes: 2 additions & 2 deletions test/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,7 @@ describe('app', () => {
.filter((e) => e.payload.label.name == "bug")
.close();
`, context)
expect(github.issues.edit).toHaveBeenCalled()
expect(github.issues.update).toHaveBeenCalled()
})

it('does not call action when conditions do not match', async () => {
Expand All @@ -77,7 +77,7 @@ describe('app', () => {
.filter((e) => e.payload.label.name == "foobar")
.close();
`, context)
expect(github.issues.edit).toHaveBeenCalledTimes(0)
expect(github.issues.update).toHaveBeenCalledTimes(0)
})
})

Expand Down
16 changes: 8 additions & 8 deletions test/plugins/filter.js
Original file line number Diff line number Diff line change
Expand Up @@ -56,15 +56,15 @@ describe('filter plugin', () => {
describe('on', () => {
describe('matching only the event name', () => {
it('matches on a single event', () => {
context.event = 'issues'
context.name = 'issues'

return filter.on(context, 'issues').then(result => {
expect(result).toEqual('issues')
})
})

it('fails to match on a single event', () => {
context.event = 'issues'
context.name = 'issues'

return filter.on(context, 'foo').catch(err => {
expect(err).toBeInstanceOf(HaltedError)
Expand All @@ -73,15 +73,15 @@ describe('filter plugin', () => {
})

it('matches any of the event names', () => {
context.event = 'foo'
context.name = 'foo'

return filter.on(context, 'issues', 'foo').then(result => {
expect(result).toEqual('foo')
})
})

it('fails to match if none of the event names match', () => {
context.event = 'bar'
context.name = 'bar'

return filter.on(context, 'issues', 'foo').catch(err => {
expect(err).toBeInstanceOf(HaltedError)
Expand All @@ -92,7 +92,7 @@ describe('filter plugin', () => {

describe('matching the event and action', () => {
it('matches on a single event', () => {
context.event = 'issues'
context.name = 'issues'
context.payload = {action: 'opened'}

return filter.on(context, 'issues.opened').then(result => {
Expand All @@ -101,7 +101,7 @@ describe('filter plugin', () => {
})

it('fails to match on a single event', () => {
context.event = 'issues'
context.name = 'issues'
context.payload = {action: 'foo'}

return filter.on(context, 'issues.opened').catch(err => {
Expand All @@ -111,7 +111,7 @@ describe('filter plugin', () => {
})

it('matches any of the event descriptors', () => {
context.event = 'issues'
context.name = 'issues'
context.payload = {action: 'closed'}

return filter.on(context, 'issues.opened', 'issues.closed').then(result => {
Expand All @@ -120,7 +120,7 @@ describe('filter plugin', () => {
})

it('fails to match if none of the event descriptors match', () => {
context.event = 'issues'
context.name = 'issues'
context.payload = {action: 'foo'}

return filter.on(context, 'issues.opened', 'issues.closed').catch(err => {
Expand Down
Loading