diff --git a/index.js b/index.js index 149fb25..3aac806 100644 --- a/index.js +++ b/index.js @@ -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) { diff --git a/lib/configuration.js b/lib/configuration.js index b4b8024..47b9190 100644 --- a/lib/configuration.js +++ b/lib/configuration.js @@ -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() ) } diff --git a/lib/plugins/filter.js b/lib/plugins/filter.js index 8619fc9..c315622 100644 --- a/lib/plugins/filter.js +++ b/lib/plugins/filter.js @@ -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 diff --git a/lib/plugins/issues.js b/lib/plugins/issues.js index 6dde2c9..e874348 100644 --- a/lib/plugins/issues.js +++ b/lib/plugins/issues.js @@ -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) || @@ -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, diff --git a/lib/plugins/projects.js b/lib/plugins/projects.js index e5c6d7d..952b7a4 100644 --- a/lib/plugins/projects.js +++ b/lib/plugins/projects.js @@ -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 @@ -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' @@ -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 }) @@ -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}) } } diff --git a/package.json b/package.json index f103b0e..60ebb96 100644 --- a/package.json +++ b/package.json @@ -11,7 +11,7 @@ }, "dependencies": { "handlebars": "^4.0.6", - "probot": "^6.1.0" + "probot": "^12.1.0" }, "engines": { "node": ">= 7.7.0", diff --git a/test/configuration.js b/test/configuration.js index 28b1af4..537d100 100644 --- a/test/configuration.js +++ b/test/configuration.js @@ -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' }) }) @@ -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', diff --git a/test/index.js b/test/index.js index 5d371dc..44909af 100644 --- a/test/index.js +++ b/test/index.js @@ -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 () => { @@ -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) }) }) diff --git a/test/plugins/filter.js b/test/plugins/filter.js index ca5ae5c..2e25d3d 100644 --- a/test/plugins/filter.js +++ b/test/plugins/filter.js @@ -56,7 +56,7 @@ 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') @@ -64,7 +64,7 @@ describe('filter plugin', () => { }) 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) @@ -73,7 +73,7 @@ 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') @@ -81,7 +81,7 @@ describe('filter plugin', () => { }) 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) @@ -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 => { @@ -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 => { @@ -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 => { @@ -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 => { diff --git a/test/plugins/issues.js b/test/plugins/issues.js index b0b7413..8197573 100644 --- a/test/plugins/issues.js +++ b/test/plugins/issues.js @@ -40,13 +40,13 @@ describe('issues plugin', () => { it('locks', () => { issues.lock(context) - expect(context.github.issues.lock).toHaveBeenCalledWith({}) + expect(context.octokit.issues.lock).toHaveBeenCalledWith({}) }) it('unlocks', () => { issues.unlock(context) - expect(context.github.issues.unlock).toHaveBeenCalledWith({}) + expect(context.octokit.issues.unlock).toHaveBeenCalledWith({}) }) }) @@ -54,7 +54,7 @@ describe('issues plugin', () => { it('opens an issue', () => { issues.open(context) - expect(context.github.issues.edit).toHaveBeenCalledWith({ + expect(context.octokit.issues.update).toHaveBeenCalledWith({ state: 'open' }) }) @@ -62,7 +62,7 @@ describe('issues plugin', () => { it('closes an issue', () => { issues.close(context) - expect(context.github.issues.edit).toHaveBeenCalledWith({ + expect(context.octokit.issues.update).toHaveBeenCalledWith({ state: 'closed' }) }) @@ -72,7 +72,7 @@ describe('issues plugin', () => { it('adds a label', () => { issues.label(context, 'hello') - expect(context.github.issues.addLabels).toHaveBeenCalledWith({ + expect(context.octokit.issues.addLabels).toHaveBeenCalledWith({ labels: ['hello'] }) }) @@ -80,7 +80,7 @@ describe('issues plugin', () => { it('adds multiple labels', () => { issues.label(context, 'hello', 'world') - expect(context.github.issues.addLabels).toHaveBeenCalledWith({ + expect(context.octokit.issues.addLabels).toHaveBeenCalledWith({ labels: ['hello', 'world'] }) }) @@ -88,7 +88,7 @@ describe('issues plugin', () => { it('removes a single label', () => { issues.unlabel(context, 'hello') - expect(context.github.issues.removeLabel).toHaveBeenCalledWith({ + expect(context.octokit.issues.removeLabel).toHaveBeenCalledWith({ name: 'hello' }) }) @@ -96,11 +96,11 @@ describe('issues plugin', () => { it('removes a multiple labels', () => { issues.unlabel(context, 'hello', 'goodbye') - expect(context.github.issues.removeLabel).toHaveBeenCalledWith({ + expect(context.octokit.issues.removeLabel).toHaveBeenCalledWith({ name: 'hello' }) - expect(context.github.issues.removeLabel).toHaveBeenCalledWith({ + expect(context.octokit.issues.removeLabel).toHaveBeenCalledWith({ name: 'goodbye' }) }) @@ -110,7 +110,7 @@ describe('issues plugin', () => { it('creates a comment', () => { issues.comment(context, 'Hello world!') - expect(context.github.issues.createComment).toHaveBeenCalledWith({ + expect(context.octokit.issues.createComment).toHaveBeenCalledWith({ body: 'Hello world!' }) }) @@ -118,7 +118,7 @@ describe('issues plugin', () => { it('evaluates templates with handlebars', () => { issues.comment(context, 'Hello @{{ sender.login }}!') - expect(context.github.issues.createComment).toHaveBeenCalledWith({ + expect(context.octokit.issues.createComment).toHaveBeenCalledWith({ body: 'Hello @bkeepers!' }) }) @@ -128,7 +128,7 @@ describe('issues plugin', () => { it('assigns a user', () => { issues.assign(context, 'bkeepers') - expect(context.github.issues.addAssigneesToIssue).toHaveBeenCalledWith({ + expect(context.octokit.issues.addAssigneesToIssue).toHaveBeenCalledWith({ assignees: ['bkeepers'] }) }) @@ -136,7 +136,7 @@ describe('issues plugin', () => { it('assigns multiple users', () => { issues.assign(context, 'hello', 'world') - expect(context.github.issues.addAssigneesToIssue).toHaveBeenCalledWith({ + expect(context.octokit.issues.addAssigneesToIssue).toHaveBeenCalledWith({ assignees: ['hello', 'world'] }) }) @@ -144,7 +144,7 @@ describe('issues plugin', () => { it('unassigns a user', () => { issues.unassign(context, 'bkeepers') - expect(context.github.issues.removeAssigneesFromIssue).toHaveBeenCalledWith({ + expect(context.octokit.issues.removeAssigneesFromIssue).toHaveBeenCalledWith({ body: {assignees: ['bkeepers']} }) }) @@ -152,7 +152,7 @@ describe('issues plugin', () => { it('unassigns multiple users', () => { issues.unassign(context, 'hello', 'world') - expect(context.github.issues.removeAssigneesFromIssue).toHaveBeenCalledWith({ + expect(context.octokit.issues.removeAssigneesFromIssue).toHaveBeenCalledWith({ body: {assignees: ['hello', 'world']} }) }) @@ -162,7 +162,7 @@ describe('issues plugin', () => { it('deletes an issue comment', () => { issues.deleteComment(context) - expect(context.github.issues.deleteComment).toHaveBeenCalledWith({ + expect(context.octokit.issues.deleteComment).toHaveBeenCalledWith({ id: 252508381 }) }) @@ -172,7 +172,7 @@ describe('issues plugin', () => { issues.deleteComment(context) - expect(context.github.repos.deleteCommitComment).toHaveBeenCalledWith({ + expect(context.octokit.repos.deleteCommitComment).toHaveBeenCalledWith({ id: 20067099 }) }) @@ -182,7 +182,7 @@ describe('issues plugin', () => { issues.deleteComment(context) - expect(context.github.pullRequests.deleteComment).toHaveBeenCalledWith({ + expect(context.octokit.pullRequests.deleteComment).toHaveBeenCalledWith({ id: 90805181 }) }) @@ -191,7 +191,7 @@ describe('issues plugin', () => { describe('createIssue', () => { it('creates an issue', () => { return issues.createIssue(context, {title: 'testing', body: 'body'}).then(() => { - expect(context.github.issues.create).toHaveBeenCalledWith({ + expect(context.octokit.issues.create).toHaveBeenCalledWith({ title: 'testing', body: 'body', assignees: undefined, @@ -202,7 +202,7 @@ describe('issues plugin', () => { it('resolves body content', () => { return issues.createIssue(context, {title: 'testing', body: Promise.resolve('body')}).then(() => { - expect(context.github.issues.create).toHaveBeenCalledWith({ + expect(context.octokit.issues.create).toHaveBeenCalledWith({ title: 'testing', body: 'body', assignees: undefined, @@ -213,7 +213,7 @@ describe('issues plugin', () => { it('sets optional parameters', () => { return issues.createIssue(context, {title: 'testing', body: 'body', assignees: ['bkeepers'], labels: ['hello']}).then(() => { - expect(context.github.issues.create).toHaveBeenCalledWith({ + expect(context.octokit.issues.create).toHaveBeenCalledWith({ title: 'testing', body: 'body', assignees: ['bkeepers'], diff --git a/test/plugins/projects.js b/test/plugins/projects.js index 6f3c9c3..51a39a9 100644 --- a/test/plugins/projects.js +++ b/test/plugins/projects.js @@ -24,7 +24,7 @@ describe('projects plugin', () => { describe('createCard', () => { it('creates a project card', () => { projects.createCard(context, {project: 'myProject', column: 'myProject'}).then(() => { - expect(context.github.projects.getRepoProjects).toHaveBeenCalledWith({ + expect(context.octokit.projects.getRepoProjects).toHaveBeenCalledWith({ owner: 'pholleran', repo: 'test' })