From 0ba69b4d5f4758ba4525f31c9a10c0f878313483 Mon Sep 17 00:00:00 2001 From: tbushman Date: Sat, 17 Nov 2018 23:20:30 -0700 Subject: [PATCH] tests passing --- probot/presolver/index.js | 175 +------ probot/presolver/lib/defaults.js | 6 +- probot/presolver/lib/presolver.js | 144 +++--- .../test/events/pullRequests.existing.json | 461 ++++++++++++++++++ .../test/events/pullRequests.opened.json | 101 ++-- probot/presolver/test/index.test.js | 11 +- 6 files changed, 600 insertions(+), 298 deletions(-) create mode 100644 probot/presolver/test/events/pullRequests.existing.json diff --git a/probot/presolver/index.js b/probot/presolver/index.js index 0bd71ad708..9ec9438e0c 100644 --- a/probot/presolver/index.js +++ b/probot/presolver/index.js @@ -1,166 +1,31 @@ -const debug = require("debug")("probot:presolver"); +const debug = require('debug')('probot:presolver') const Presolver = require('./lib/presolver') -/*const Presolver = { - (github, { owner, repo, logger = console, ...config }) { - //constructor(github, { owner, repo, logger = console, ...config }) { - this.github = github; - this.logger = logger; - this.config = Object.assign({}, { - owner, - repo - }); - this.pullRequest = {}; - //} - /*static get STATE() { - return Object.freeze({ - CLASH: 'clashing' - }); - }*/ - - - - -//} - - -async function probotPlugin(robot) { +async function probotPlugin (robot) { const events = [ - "pull_request.opened", - "pull_request.edited", - "pull_request.synchronize", - "pull_request.reopened", - "pull_request.labeled" - ]; + 'pull_request.opened', + 'pull_request.edited', + 'pull_request.synchronize', + 'pull_request.reopened', + 'pull_request.labeled' + ] - robot.on(events, presolve.bind(null, robot)); -} -/*async function _getClashingRanges(context, pullRequest) { - const repo = pullRequest.base.repo; - //console.log(pullRequest) - const owner = repo.owner; - const number = pullRequest.number; - console.log(context) - const prs = (await context.github.pullRequests.get({ owner, repo })) - .data || []; - prs.forEach(function(pr){ - const files = pr.files() - console.log(files) - }) -}*/ -/*async function presolver(context, pullRequest) { - //Object.assign(this.pullRequest, pullRequest); - //const { owner, repo } = this.config; - //const number = this.pullRequest.number; - - const state = await _getClashingRanges(context, pullRequest); - -}*/ -async function presolve(app, context) { - const presolver = forRepository(context); - const pullRequest = getPullRequest(context); - return presolver.presolve(pullRequest); + robot.on(events, presolve.bind(null, robot)) } -function forRepository(context) { - const config = Object.assign({}, context.repo({ logger: debug })); - return new Presolver(context, config); +async function presolve (app, context) { + const presolver = forRepository(context) + const pullRequest = getPullRequest(context) + return presolver.presolve(pullRequest) } -function getPullRequest(context) { - return context.payload.pull_request || context.payload.review.pull_request; +function forRepository (context) { + const config = Object.assign({}, context.repo({ logger: debug })) + return new Presolver(context, config) } +function getPullRequest (context) { + return context.payload.pull_request || context.payload.review.pull_request +} -module.exports = probotPlugin; -/*module.exports = async app => { - // Your code here - app.log('Yay, the app was loaded!') - - app.on('pull_request.opened', async githubcontext => { - //console.log(githubcontext) - const prContext = getPullRequest(githubcontext); - //console.log(prContext); - //const config = //Object.assign({}, githubcontext.repo({}) - //); - //const context = prContext.github; - //console.log(context) - //constructor(github, { owner, repo, logger = console, ...config }) { - - //const prNumber = context.payload.pull_request.number; - - const { title, head, number, id } = prContext;*/ - //const owner = context.owner; - //const repo = context.repo; - /*const reviews = - (await context.github.pullRequests.getReviews({ owner, repo, number })) - .data || []; - - const uniqueReviews = reviews - .filter(review => review.commit_id === sha) - .reduce((reviewObj, review) => { - if ( - reviewObj[review.user.id] === null || - reviewObj[review.user.id] === undefined - ) { - reviewObj[review.user.id] = { - state: review.state, - submitted_at: review.submitted_at - }; - } else { - const a = new Date( - reviewObj[review.user.id]["submitted_at"] - ).getTime(); - const b = new Date(review.submitted_at).getTime(); - if (a < b) { - reviewObj[review.user.id] = { - state: review.state, - submitted_at: review.submitted_at - }; - } - } - return reviewObj; - }, {}); - - return Object.values(uniqueReviews); - }*/ - //const params = -/* const commit_id = head.sha; - const body = 'probot comment test'; - const filepath = './app.js' - const pos = 4; - const event = 'COMMENT' - const comments = { - path: './app.js', - position: 4, - body: 'probot test' - } - const path = - //comments[].path = - filepath; - const position = - //comments[].path = - pos; - const reviewers = ['tbushman']*/ - /*return await context.github.pullRequests.createReview({ - owner, - repo, - number, - commit_id, - body, - event, - comments - - })*/ -/* const issueComment = githubcontext.issue({ body: 'probot label test' }) - return githubcontext.github.issues.createComment(issueComment) - //return await githubcontext.github.pullRequests.createReviewRequest({owner, repo, number, reviewers}) - })*/ - - // For more information on building apps: - // https://probot.github.io/docs/ - - // To get your app running against GitHub, see: - // https://probot.github.io/docs/development/ -//} - +module.exports = probotPlugin diff --git a/probot/presolver/lib/defaults.js b/probot/presolver/lib/defaults.js index c85712cf2b..527b6d7e56 100644 --- a/probot/presolver/lib/defaults.js +++ b/probot/presolver/lib/defaults.js @@ -1,6 +1,6 @@ module.exports = { labelPRConflict: { - name: "PR: potential-conflict", - color: "c2e0c6" + name: 'PR: potential-conflict', + color: 'c2e0c6' } -}; \ No newline at end of file +} diff --git a/probot/presolver/lib/presolver.js b/probot/presolver/lib/presolver.js index 85d6dc0855..eaaaeef5b7 100644 --- a/probot/presolver/lib/presolver.js +++ b/probot/presolver/lib/presolver.js @@ -1,107 +1,95 @@ class Presolver { - constructor(context, { owner, repo, logger = console, ...config }) { - this.context = context; - this.github = context.github; - this.logger = logger; - this.config = Object.assign({}, require("./defaults"), config || {}, { + constructor (context, { owner, repo, logger = console, ...config }) { + this.context = context + this.github = context.github + this.logger = logger + this.config = Object.assign({}, require('./defaults'), config || {}, { owner, repo - }); - this.pullRequest = {}; - this.conflictingFiles = []; + }) + this.pullRequest = {} + this.conflictingFiles = [] } - async presolve(pullRequest) { - Object.assign(this.pullRequest, pullRequest); - const { owner, repo } = this.config; - const number = this.pullRequest.number; - await this._ensurePresolverLabelExists(); - const state = await this._getState(); + async presolve (pullRequest) { + Object.assign(this.pullRequest, pullRequest) + await this._ensurePresolverLabelExists() + await this._getState() + const labelObj = this.config.labelPRConflict if (this.conflictingFiles.length) { - await this._addLabel(); + await this._addLabel(labelObj) } - /*switch(state) { - case Presolver.STATE.CONFLICT: - case Presolver.STATE.NOCONFLICT: - default: - throw new Error('Undefined state');*/ - } - async _getState() { - const files = await this.github.pullRequests.getFiles(this.context.issue()); - console.log(files) - const {owner, repo} = this.config; + + async _getState () { + // console.log(this.context.issue()) + const files = await this.github.pullRequests.getFiles(this.context.issue()) + // console.log(files) + const {owner, repo} = this.config const prs = await this.github.pullRequests.getAll({ owner, repo }) - .data || []; - //let state; - console.log(prs) - await this._getConflictingFiles(prs, files); - /*if (conflictingFiles.length) { - return Presolver.STATE.CONFLICT; - } else { - return Presolver.STATE.NOCONFLICT; - }*/ - return; - // ... this.pullRequest. - /* - const prs = (await context.github.pullRequests.get({ owner, repo })) - .data || []; - prs.forEach(function(pr){ - const files = pr.files() - console.log(files) - }) - */ + .data || [] + // console.log(prs) + await this._getConflictingFiles(prs, files) } - - async _getConflictingFiles(prs, files) { - prs.forEach(function(pr){ - var prFiles = pr.getFiles(); - prFiles.data.forEach(function(file){ - files.data.forEach(function(f){ - console.log(f, file) + + async _getConflictingFiles (prs, files) { + const {owner, repo} = this.config + const github = this.github + const conflictingFiles = this.conflictingFiles + // console.log(prs, files) + prs.forEach((pr) => { + const prIssue = { + number: pr.number, + owner: owner, + repo: repo + } + var prFiles = github.pullRequests.getFiles(prIssue) + prFiles.data.forEach((file) => { + files.data.forEach((f) => { + // console.log(f, file) if (f.filename === file.filename) { - this.conflictingFiles.push(file.filename) + conflictingFiles.push(file.filename) } }) }) }) } - - async _ensurePresolverLabelExists() { - const label = this.config.labelPRConflict; - await this._createLabel(label); + + async _ensurePresolverLabelExists () { + const label = this.config.labelPRConflict + await this._createLabel(label) } - async _createLabel(labelObj) { - const { owner, repo } = this.config; + async _createLabel (labelObj) { + const { owner, repo } = this.config return this.github.issues .getLabels({ owner, repo, name: labelObj.name }) .catch(() => { - console.log(labelObj) + // console.log(labelObj) return this.github.issues.createLabel({ owner, repo, name: labelObj.name, color: labelObj.color - }); - }); + }) + }) } - - _getLabel(labelObj) { - return new Promise((resolve, reject) => { - for (const label of this.pullRequest.labels) { - if (lableObj && lableObj.name && label.name === lableObj.name) { - resolve(lableObj); - } - } - reject(new Error("Not found")); - }); + + _getLabel (labelObj) { + return new Promise((resolve, reject) => { + for (const label of this.pullRequest.labels) { + if (labelObj && labelObj.name && label.name === labelObj.name) { + resolve(labelObj) + } + } + reject(new Error('Not found')) + }) } - async _addLabel() { - const { owner, repo } = this.config; - const number = this.pullRequest.number; - const label = this.config.labelPRConflict; + async _addLabel (labelObj) { + const { owner, repo } = this.config + const number = this.pullRequest.number + const label = this.config.labelPRConflict // Check if a label does not exist. If it does, it addes the label. return this._getLabel(label).catch(() => { @@ -110,9 +98,9 @@ class Presolver { repo, number, labels: [labelObj.name] - }); - }); + }) + }) } } -module.exports = Presolver \ No newline at end of file +module.exports = Presolver diff --git a/probot/presolver/test/events/pullRequests.existing.json b/probot/presolver/test/events/pullRequests.existing.json new file mode 100644 index 0000000000..11b403c697 --- /dev/null +++ b/probot/presolver/test/events/pullRequests.existing.json @@ -0,0 +1,461 @@ +{ + "action": "opened", + "number": 13, + "pull_request": { + "url": "https://api.github.com/repos/tbushman/pu/pulls/13", + "id": 227499746, + "node_id": "MDExOlB1bGxSZXF1ZXN0MjI3NDk5NzQ2", + "html_url": "https://github.com/tbushman/pu/pull/13", + "diff_url": "https://github.com/tbushman/pu/pull/13.diff", + "patch_url": "https://github.com/tbushman/pu/pull/13.patch", + "issue_url": "https://api.github.com/repos/tbushman/pu/issues/13", + "number": 13, + "state": "open", + "locked": false, + "title": "remove comments", + "user": { + "login": "tbushman", + "id": 7049294, + "node_id": "MDQ6VXNlcjcwNDkyOTQ=", + "avatar_url": "https://avatars2.githubusercontent.com/u/7049294?v=4", + "gravatar_id": "", + "url": "https://api.github.com/users/tbushman", + "html_url": "https://github.com/tbushman", + "followers_url": "https://api.github.com/users/tbushman/followers", + "following_url": "https://api.github.com/users/tbushman/following{/other_user}", + "gists_url": "https://api.github.com/users/tbushman/gists{/gist_id}", + "starred_url": "https://api.github.com/users/tbushman/starred{/owner}{/repo}", + "subscriptions_url": "https://api.github.com/users/tbushman/subscriptions", + "organizations_url": "https://api.github.com/users/tbushman/orgs", + "repos_url": "https://api.github.com/users/tbushman/repos", + "events_url": "https://api.github.com/users/tbushman/events{/privacy}", + "received_events_url": "https://api.github.com/users/tbushman/received_events", + "type": "User", + "site_admin": false + }, + "body": "", + "created_at": "2018-11-01T03:06:36Z", + "updated_at": "2018-11-11T09:11:01Z", + "closed_at": null, + "merged_at": null, + "merge_commit_sha": "fc696e1a288b07f66318e775fdd9ea619122d09e", + "assignee": null, + "assignees": [ + + ], + "requested_reviewers": [ + + ], + "requested_teams": [ + + ], + "labels": [ + { + "id": 511502933, + "node_id": "MDU6TGFiZWw1MTE1MDI5MzM=", + "url": "https://api.github.com/repos/tbushman/pu/labels/enhancement", + "name": "enhancement", + "color": "84b6eb", + "default": true + } + ], + "milestone": null, + "commits_url": "https://api.github.com/repos/tbushman/pu/pulls/13/commits", + "review_comments_url": "https://api.github.com/repos/tbushman/pu/pulls/13/comments", + "review_comment_url": "https://api.github.com/repos/tbushman/pu/pulls/comments{/number}", + "comments_url": "https://api.github.com/repos/tbushman/pu/issues/13/comments", + "statuses_url": "https://api.github.com/repos/tbushman/pu/statuses/bce20f1db1348bdc53ac339ff91007afe88518ea", + "head": { + "label": "tbushman:presolvertest", + "ref": "presolvertest", + "sha": "bce20f1db1348bdc53ac339ff91007afe88518ea", + "user": { + "login": "tbushman", + "id": 7049294, + "node_id": "MDQ6VXNlcjcwNDkyOTQ=", + "avatar_url": "https://avatars2.githubusercontent.com/u/7049294?v=4", + "gravatar_id": "", + "url": "https://api.github.com/users/tbushman", + "html_url": "https://github.com/tbushman", + "followers_url": "https://api.github.com/users/tbushman/followers", + "following_url": "https://api.github.com/users/tbushman/following{/other_user}", + "gists_url": "https://api.github.com/users/tbushman/gists{/gist_id}", + "starred_url": "https://api.github.com/users/tbushman/starred{/owner}{/repo}", + "subscriptions_url": "https://api.github.com/users/tbushman/subscriptions", + "organizations_url": "https://api.github.com/users/tbushman/orgs", + "repos_url": "https://api.github.com/users/tbushman/repos", + "events_url": "https://api.github.com/users/tbushman/events{/privacy}", + "received_events_url": "https://api.github.com/users/tbushman/received_events", + "type": "User", + "site_admin": false + }, + "repo": { + "id": 77999410, + "node_id": "MDEwOlJlcG9zaXRvcnk3Nzk5OTQxMA==", + "name": "pu", + "full_name": "tbushman/pu", + "private": false, + "owner": { + "login": "tbushman", + "id": 7049294, + "node_id": "MDQ6VXNlcjcwNDkyOTQ=", + "avatar_url": "https://avatars2.githubusercontent.com/u/7049294?v=4", + "gravatar_id": "", + "url": "https://api.github.com/users/tbushman", + "html_url": "https://github.com/tbushman", + "followers_url": "https://api.github.com/users/tbushman/followers", + "following_url": "https://api.github.com/users/tbushman/following{/other_user}", + "gists_url": "https://api.github.com/users/tbushman/gists{/gist_id}", + "starred_url": "https://api.github.com/users/tbushman/starred{/owner}{/repo}", + "subscriptions_url": "https://api.github.com/users/tbushman/subscriptions", + "organizations_url": "https://api.github.com/users/tbushman/orgs", + "repos_url": "https://api.github.com/users/tbushman/repos", + "events_url": "https://api.github.com/users/tbushman/events{/privacy}", + "received_events_url": "https://api.github.com/users/tbushman/received_events", + "type": "User", + "site_admin": false + }, + "html_url": "https://github.com/tbushman/pu", + "description": "Build a map-linked timeline. Currently CV / Portfolio-style. ", + "fork": false, + "url": "https://api.github.com/repos/tbushman/pu", + "forks_url": "https://api.github.com/repos/tbushman/pu/forks", + "keys_url": "https://api.github.com/repos/tbushman/pu/keys{/key_id}", + "collaborators_url": "https://api.github.com/repos/tbushman/pu/collaborators{/collaborator}", + "teams_url": "https://api.github.com/repos/tbushman/pu/teams", + "hooks_url": "https://api.github.com/repos/tbushman/pu/hooks", + "issue_events_url": "https://api.github.com/repos/tbushman/pu/issues/events{/number}", + "events_url": "https://api.github.com/repos/tbushman/pu/events", + "assignees_url": "https://api.github.com/repos/tbushman/pu/assignees{/user}", + "branches_url": "https://api.github.com/repos/tbushman/pu/branches{/branch}", + "tags_url": "https://api.github.com/repos/tbushman/pu/tags", + "blobs_url": "https://api.github.com/repos/tbushman/pu/git/blobs{/sha}", + "git_tags_url": "https://api.github.com/repos/tbushman/pu/git/tags{/sha}", + "git_refs_url": "https://api.github.com/repos/tbushman/pu/git/refs{/sha}", + "trees_url": "https://api.github.com/repos/tbushman/pu/git/trees{/sha}", + "statuses_url": "https://api.github.com/repos/tbushman/pu/statuses/{sha}", + "languages_url": "https://api.github.com/repos/tbushman/pu/languages", + "stargazers_url": "https://api.github.com/repos/tbushman/pu/stargazers", + "contributors_url": "https://api.github.com/repos/tbushman/pu/contributors", + "subscribers_url": "https://api.github.com/repos/tbushman/pu/subscribers", + "subscription_url": "https://api.github.com/repos/tbushman/pu/subscription", + "commits_url": "https://api.github.com/repos/tbushman/pu/commits{/sha}", + "git_commits_url": "https://api.github.com/repos/tbushman/pu/git/commits{/sha}", + "comments_url": "https://api.github.com/repos/tbushman/pu/comments{/number}", + "issue_comment_url": "https://api.github.com/repos/tbushman/pu/issues/comments{/number}", + "contents_url": "https://api.github.com/repos/tbushman/pu/contents/{+path}", + "compare_url": "https://api.github.com/repos/tbushman/pu/compare/{base}...{head}", + "merges_url": "https://api.github.com/repos/tbushman/pu/merges", + "archive_url": "https://api.github.com/repos/tbushman/pu/{archive_format}{/ref}", + "downloads_url": "https://api.github.com/repos/tbushman/pu/downloads", + "issues_url": "https://api.github.com/repos/tbushman/pu/issues{/number}", + "pulls_url": "https://api.github.com/repos/tbushman/pu/pulls{/number}", + "milestones_url": "https://api.github.com/repos/tbushman/pu/milestones{/number}", + "notifications_url": "https://api.github.com/repos/tbushman/pu/notifications{?since,all,participating}", + "labels_url": "https://api.github.com/repos/tbushman/pu/labels{/name}", + "releases_url": "https://api.github.com/repos/tbushman/pu/releases{/id}", + "deployments_url": "https://api.github.com/repos/tbushman/pu/deployments", + "created_at": "2017-01-04T09:05:47Z", + "updated_at": "2018-07-01T04:09:57Z", + "pushed_at": "2018-11-01T03:06:36Z", + "git_url": "git://github.com/tbushman/pu.git", + "ssh_url": "git@github.com:tbushman/pu.git", + "clone_url": "https://github.com/tbushman/pu.git", + "svn_url": "https://github.com/tbushman/pu", + "homepage": "https://pu.bli.sh", + "size": 2720, + "stargazers_count": 0, + "watchers_count": 0, + "language": "CSS", + "has_issues": true, + "has_projects": true, + "has_downloads": true, + "has_wiki": true, + "has_pages": false, + "forks_count": 0, + "mirror_url": null, + "archived": false, + "open_issues_count": 1, + "license": null, + "forks": 0, + "open_issues": 1, + "watchers": 0, + "default_branch": "master" + } + }, + "base": { + "label": "tbushman:master", + "ref": "master", + "sha": "0a92c66df823675e2a1a9a74132f2427d5bdd224", + "user": { + "login": "tbushman", + "id": 7049294, + "node_id": "MDQ6VXNlcjcwNDkyOTQ=", + "avatar_url": "https://avatars2.githubusercontent.com/u/7049294?v=4", + "gravatar_id": "", + "url": "https://api.github.com/users/tbushman", + "html_url": "https://github.com/tbushman", + "followers_url": "https://api.github.com/users/tbushman/followers", + "following_url": "https://api.github.com/users/tbushman/following{/other_user}", + "gists_url": "https://api.github.com/users/tbushman/gists{/gist_id}", + "starred_url": "https://api.github.com/users/tbushman/starred{/owner}{/repo}", + "subscriptions_url": "https://api.github.com/users/tbushman/subscriptions", + "organizations_url": "https://api.github.com/users/tbushman/orgs", + "repos_url": "https://api.github.com/users/tbushman/repos", + "events_url": "https://api.github.com/users/tbushman/events{/privacy}", + "received_events_url": "https://api.github.com/users/tbushman/received_events", + "type": "User", + "site_admin": false + }, + "repo": { + "id": 77999410, + "node_id": "MDEwOlJlcG9zaXRvcnk3Nzk5OTQxMA==", + "name": "pu", + "full_name": "tbushman/pu", + "private": false, + "owner": { + "login": "tbushman", + "id": 7049294, + "node_id": "MDQ6VXNlcjcwNDkyOTQ=", + "avatar_url": "https://avatars2.githubusercontent.com/u/7049294?v=4", + "gravatar_id": "", + "url": "https://api.github.com/users/tbushman", + "html_url": "https://github.com/tbushman", + "followers_url": "https://api.github.com/users/tbushman/followers", + "following_url": "https://api.github.com/users/tbushman/following{/other_user}", + "gists_url": "https://api.github.com/users/tbushman/gists{/gist_id}", + "starred_url": "https://api.github.com/users/tbushman/starred{/owner}{/repo}", + "subscriptions_url": "https://api.github.com/users/tbushman/subscriptions", + "organizations_url": "https://api.github.com/users/tbushman/orgs", + "repos_url": "https://api.github.com/users/tbushman/repos", + "events_url": "https://api.github.com/users/tbushman/events{/privacy}", + "received_events_url": "https://api.github.com/users/tbushman/received_events", + "type": "User", + "site_admin": false + }, + "html_url": "https://github.com/tbushman/pu", + "description": "Build a map-linked timeline. Currently CV / Portfolio-style. ", + "fork": false, + "url": "https://api.github.com/repos/tbushman/pu", + "forks_url": "https://api.github.com/repos/tbushman/pu/forks", + "keys_url": "https://api.github.com/repos/tbushman/pu/keys{/key_id}", + "collaborators_url": "https://api.github.com/repos/tbushman/pu/collaborators{/collaborator}", + "teams_url": "https://api.github.com/repos/tbushman/pu/teams", + "hooks_url": "https://api.github.com/repos/tbushman/pu/hooks", + "issue_events_url": "https://api.github.com/repos/tbushman/pu/issues/events{/number}", + "events_url": "https://api.github.com/repos/tbushman/pu/events", + "assignees_url": "https://api.github.com/repos/tbushman/pu/assignees{/user}", + "branches_url": "https://api.github.com/repos/tbushman/pu/branches{/branch}", + "tags_url": "https://api.github.com/repos/tbushman/pu/tags", + "blobs_url": "https://api.github.com/repos/tbushman/pu/git/blobs{/sha}", + "git_tags_url": "https://api.github.com/repos/tbushman/pu/git/tags{/sha}", + "git_refs_url": "https://api.github.com/repos/tbushman/pu/git/refs{/sha}", + "trees_url": "https://api.github.com/repos/tbushman/pu/git/trees{/sha}", + "statuses_url": "https://api.github.com/repos/tbushman/pu/statuses/{sha}", + "languages_url": "https://api.github.com/repos/tbushman/pu/languages", + "stargazers_url": "https://api.github.com/repos/tbushman/pu/stargazers", + "contributors_url": "https://api.github.com/repos/tbushman/pu/contributors", + "subscribers_url": "https://api.github.com/repos/tbushman/pu/subscribers", + "subscription_url": "https://api.github.com/repos/tbushman/pu/subscription", + "commits_url": "https://api.github.com/repos/tbushman/pu/commits{/sha}", + "git_commits_url": "https://api.github.com/repos/tbushman/pu/git/commits{/sha}", + "comments_url": "https://api.github.com/repos/tbushman/pu/comments{/number}", + "issue_comment_url": "https://api.github.com/repos/tbushman/pu/issues/comments{/number}", + "contents_url": "https://api.github.com/repos/tbushman/pu/contents/{+path}", + "compare_url": "https://api.github.com/repos/tbushman/pu/compare/{base}...{head}", + "merges_url": "https://api.github.com/repos/tbushman/pu/merges", + "archive_url": "https://api.github.com/repos/tbushman/pu/{archive_format}{/ref}", + "downloads_url": "https://api.github.com/repos/tbushman/pu/downloads", + "issues_url": "https://api.github.com/repos/tbushman/pu/issues{/number}", + "pulls_url": "https://api.github.com/repos/tbushman/pu/pulls{/number}", + "milestones_url": "https://api.github.com/repos/tbushman/pu/milestones{/number}", + "notifications_url": "https://api.github.com/repos/tbushman/pu/notifications{?since,all,participating}", + "labels_url": "https://api.github.com/repos/tbushman/pu/labels{/name}", + "releases_url": "https://api.github.com/repos/tbushman/pu/releases{/id}", + "deployments_url": "https://api.github.com/repos/tbushman/pu/deployments", + "created_at": "2017-01-04T09:05:47Z", + "updated_at": "2018-07-01T04:09:57Z", + "pushed_at": "2018-11-01T03:06:36Z", + "git_url": "git://github.com/tbushman/pu.git", + "ssh_url": "git@github.com:tbushman/pu.git", + "clone_url": "https://github.com/tbushman/pu.git", + "svn_url": "https://github.com/tbushman/pu", + "homepage": "https://pu.bli.sh", + "size": 2720, + "stargazers_count": 0, + "watchers_count": 0, + "language": "CSS", + "has_issues": true, + "has_projects": true, + "has_downloads": true, + "has_wiki": true, + "has_pages": false, + "forks_count": 0, + "mirror_url": null, + "archived": false, + "open_issues_count": 1, + "license": null, + "forks": 0, + "open_issues": 1, + "watchers": 0, + "default_branch": "master" + } + }, + "_links": { + "self": { + "href": "https://api.github.com/repos/tbushman/pu/pulls/13" + }, + "html": { + "href": "https://github.com/tbushman/pu/pull/13" + }, + "issue": { + "href": "https://api.github.com/repos/tbushman/pu/issues/13" + }, + "comments": { + "href": "https://api.github.com/repos/tbushman/pu/issues/13/comments" + }, + "review_comments": { + "href": "https://api.github.com/repos/tbushman/pu/pulls/13/comments" + }, + "review_comment": { + "href": "https://api.github.com/repos/tbushman/pu/pulls/comments{/number}" + }, + "commits": { + "href": "https://api.github.com/repos/tbushman/pu/pulls/13/commits" + }, + "statuses": { + "href": "https://api.github.com/repos/tbushman/pu/statuses/bce20f1db1348bdc53ac339ff91007afe88518ea" + } + }, + "author_association": "OWNER", + "merged": false, + "mergeable": null, + "rebaseable": null, + "mergeable_state": "unknown", + "merged_by": null, + "comments": 0, + "review_comments": 0, + "maintainer_can_modify": false, + "commits": 1, + "additions": 0, + "deletions": 6, + "changed_files": 1 + }, + "repository": { + "id": 77999410, + "node_id": "MDEwOlJlcG9zaXRvcnk3Nzk5OTQxMA==", + "name": "pu", + "full_name": "tbushman/pu", + "private": false, + "owner": { + "login": "tbushman", + "id": 7049294, + "node_id": "MDQ6VXNlcjcwNDkyOTQ=", + "avatar_url": "https://avatars2.githubusercontent.com/u/7049294?v=4", + "gravatar_id": "", + "url": "https://api.github.com/users/tbushman", + "html_url": "https://github.com/tbushman", + "followers_url": "https://api.github.com/users/tbushman/followers", + "following_url": "https://api.github.com/users/tbushman/following{/other_user}", + "gists_url": "https://api.github.com/users/tbushman/gists{/gist_id}", + "starred_url": "https://api.github.com/users/tbushman/starred{/owner}{/repo}", + "subscriptions_url": "https://api.github.com/users/tbushman/subscriptions", + "organizations_url": "https://api.github.com/users/tbushman/orgs", + "repos_url": "https://api.github.com/users/tbushman/repos", + "events_url": "https://api.github.com/users/tbushman/events{/privacy}", + "received_events_url": "https://api.github.com/users/tbushman/received_events", + "type": "User", + "site_admin": false + }, + "html_url": "https://github.com/tbushman/pu", + "description": "Build a map-linked timeline. Currently CV / Portfolio-style. ", + "fork": false, + "url": "https://api.github.com/repos/tbushman/pu", + "forks_url": "https://api.github.com/repos/tbushman/pu/forks", + "keys_url": "https://api.github.com/repos/tbushman/pu/keys{/key_id}", + "collaborators_url": "https://api.github.com/repos/tbushman/pu/collaborators{/collaborator}", + "teams_url": "https://api.github.com/repos/tbushman/pu/teams", + "hooks_url": "https://api.github.com/repos/tbushman/pu/hooks", + "issue_events_url": "https://api.github.com/repos/tbushman/pu/issues/events{/number}", + "events_url": "https://api.github.com/repos/tbushman/pu/events", + "assignees_url": "https://api.github.com/repos/tbushman/pu/assignees{/user}", + "branches_url": "https://api.github.com/repos/tbushman/pu/branches{/branch}", + "tags_url": "https://api.github.com/repos/tbushman/pu/tags", + "blobs_url": "https://api.github.com/repos/tbushman/pu/git/blobs{/sha}", + "git_tags_url": "https://api.github.com/repos/tbushman/pu/git/tags{/sha}", + "git_refs_url": "https://api.github.com/repos/tbushman/pu/git/refs{/sha}", + "trees_url": "https://api.github.com/repos/tbushman/pu/git/trees{/sha}", + "statuses_url": "https://api.github.com/repos/tbushman/pu/statuses/{sha}", + "languages_url": "https://api.github.com/repos/tbushman/pu/languages", + "stargazers_url": "https://api.github.com/repos/tbushman/pu/stargazers", + "contributors_url": "https://api.github.com/repos/tbushman/pu/contributors", + "subscribers_url": "https://api.github.com/repos/tbushman/pu/subscribers", + "subscription_url": "https://api.github.com/repos/tbushman/pu/subscription", + "commits_url": "https://api.github.com/repos/tbushman/pu/commits{/sha}", + "git_commits_url": "https://api.github.com/repos/tbushman/pu/git/commits{/sha}", + "comments_url": "https://api.github.com/repos/tbushman/pu/comments{/number}", + "issue_comment_url": "https://api.github.com/repos/tbushman/pu/issues/comments{/number}", + "contents_url": "https://api.github.com/repos/tbushman/pu/contents/{+path}", + "compare_url": "https://api.github.com/repos/tbushman/pu/compare/{base}...{head}", + "merges_url": "https://api.github.com/repos/tbushman/pu/merges", + "archive_url": "https://api.github.com/repos/tbushman/pu/{archive_format}{/ref}", + "downloads_url": "https://api.github.com/repos/tbushman/pu/downloads", + "issues_url": "https://api.github.com/repos/tbushman/pu/issues{/number}", + "pulls_url": "https://api.github.com/repos/tbushman/pu/pulls{/number}", + "milestones_url": "https://api.github.com/repos/tbushman/pu/milestones{/number}", + "notifications_url": "https://api.github.com/repos/tbushman/pu/notifications{?since,all,participating}", + "labels_url": "https://api.github.com/repos/tbushman/pu/labels{/name}", + "releases_url": "https://api.github.com/repos/tbushman/pu/releases{/id}", + "deployments_url": "https://api.github.com/repos/tbushman/pu/deployments", + "created_at": "2017-01-04T09:05:47Z", + "updated_at": "2018-07-01T04:09:57Z", + "pushed_at": "2018-11-01T03:06:36Z", + "git_url": "git://github.com/tbushman/pu.git", + "ssh_url": "git@github.com:tbushman/pu.git", + "clone_url": "https://github.com/tbushman/pu.git", + "svn_url": "https://github.com/tbushman/pu", + "homepage": "https://pu.bli.sh", + "size": 2720, + "stargazers_count": 0, + "watchers_count": 0, + "language": "CSS", + "has_issues": true, + "has_projects": true, + "has_downloads": true, + "has_wiki": true, + "has_pages": false, + "forks_count": 0, + "mirror_url": null, + "archived": false, + "open_issues_count": 1, + "license": null, + "forks": 0, + "open_issues": 1, + "watchers": 0, + "default_branch": "master" + }, + "sender": { + "login": "tbushman", + "id": 7049294, + "node_id": "MDQ6VXNlcjcwNDkyOTQ=", + "avatar_url": "https://avatars2.githubusercontent.com/u/7049294?v=4", + "gravatar_id": "", + "url": "https://api.github.com/users/tbushman", + "html_url": "https://github.com/tbushman", + "followers_url": "https://api.github.com/users/tbushman/followers", + "following_url": "https://api.github.com/users/tbushman/following{/other_user}", + "gists_url": "https://api.github.com/users/tbushman/gists{/gist_id}", + "starred_url": "https://api.github.com/users/tbushman/starred{/owner}{/repo}", + "subscriptions_url": "https://api.github.com/users/tbushman/subscriptions", + "organizations_url": "https://api.github.com/users/tbushman/orgs", + "repos_url": "https://api.github.com/users/tbushman/repos", + "events_url": "https://api.github.com/users/tbushman/events{/privacy}", + "received_events_url": "https://api.github.com/users/tbushman/received_events", + "type": "User", + "site_admin": false + }, + "installation": { + "id": 421598, + "node_id": "MDIzOkludGVncmF0aW9uSW5zdGFsbGF0aW9uNDIxNTk4" + } +} \ No newline at end of file diff --git a/probot/presolver/test/events/pullRequests.opened.json b/probot/presolver/test/events/pullRequests.opened.json index 11b403c697..946f60ef59 100644 --- a/probot/presolver/test/events/pullRequests.opened.json +++ b/probot/presolver/test/events/pullRequests.opened.json @@ -1,18 +1,18 @@ { "action": "opened", - "number": 13, + "number": 15, "pull_request": { - "url": "https://api.github.com/repos/tbushman/pu/pulls/13", - "id": 227499746, - "node_id": "MDExOlB1bGxSZXF1ZXN0MjI3NDk5NzQ2", - "html_url": "https://github.com/tbushman/pu/pull/13", - "diff_url": "https://github.com/tbushman/pu/pull/13.diff", - "patch_url": "https://github.com/tbushman/pu/pull/13.patch", - "issue_url": "https://api.github.com/repos/tbushman/pu/issues/13", - "number": 13, + "url": "https://api.github.com/repos/tbushman/pu/pulls/15", + "id": 231769233, + "node_id": "MDExOlB1bGxSZXF1ZXN0MjMxNzY5MjMz", + "html_url": "https://github.com/tbushman/pu/pull/15", + "diff_url": "https://github.com/tbushman/pu/pull/15.diff", + "patch_url": "https://github.com/tbushman/pu/pull/15.patch", + "issue_url": "https://api.github.com/repos/tbushman/pu/issues/15", + "number": 15, "state": "open", "locked": false, - "title": "remove comments", + "title": "remove comments 2", "user": { "login": "tbushman", "id": 7049294, @@ -34,11 +34,11 @@ "site_admin": false }, "body": "", - "created_at": "2018-11-01T03:06:36Z", - "updated_at": "2018-11-11T09:11:01Z", + "created_at": "2018-11-18T05:12:18Z", + "updated_at": "2018-11-18T05:12:18Z", "closed_at": null, "merged_at": null, - "merge_commit_sha": "fc696e1a288b07f66318e775fdd9ea619122d09e", + "merge_commit_sha": null, "assignee": null, "assignees": [ @@ -50,25 +50,18 @@ ], "labels": [ - { - "id": 511502933, - "node_id": "MDU6TGFiZWw1MTE1MDI5MzM=", - "url": "https://api.github.com/repos/tbushman/pu/labels/enhancement", - "name": "enhancement", - "color": "84b6eb", - "default": true - } + ], "milestone": null, - "commits_url": "https://api.github.com/repos/tbushman/pu/pulls/13/commits", - "review_comments_url": "https://api.github.com/repos/tbushman/pu/pulls/13/comments", + "commits_url": "https://api.github.com/repos/tbushman/pu/pulls/15/commits", + "review_comments_url": "https://api.github.com/repos/tbushman/pu/pulls/15/comments", "review_comment_url": "https://api.github.com/repos/tbushman/pu/pulls/comments{/number}", - "comments_url": "https://api.github.com/repos/tbushman/pu/issues/13/comments", - "statuses_url": "https://api.github.com/repos/tbushman/pu/statuses/bce20f1db1348bdc53ac339ff91007afe88518ea", + "comments_url": "https://api.github.com/repos/tbushman/pu/issues/15/comments", + "statuses_url": "https://api.github.com/repos/tbushman/pu/statuses/c9f2f27b01043673c8abad91500ac8197d75f8b0", "head": { - "label": "tbushman:presolvertest", - "ref": "presolvertest", - "sha": "bce20f1db1348bdc53ac339ff91007afe88518ea", + "label": "tbushman:presolvertest2", + "ref": "presolvertest2", + "sha": "c9f2f27b01043673c8abad91500ac8197d75f8b0", "user": { "login": "tbushman", "id": 7049294, @@ -156,14 +149,14 @@ "releases_url": "https://api.github.com/repos/tbushman/pu/releases{/id}", "deployments_url": "https://api.github.com/repos/tbushman/pu/deployments", "created_at": "2017-01-04T09:05:47Z", - "updated_at": "2018-07-01T04:09:57Z", - "pushed_at": "2018-11-01T03:06:36Z", + "updated_at": "2018-11-12T11:15:42Z", + "pushed_at": "2018-11-18T05:11:55Z", "git_url": "git://github.com/tbushman/pu.git", "ssh_url": "git@github.com:tbushman/pu.git", "clone_url": "https://github.com/tbushman/pu.git", "svn_url": "https://github.com/tbushman/pu", "homepage": "https://pu.bli.sh", - "size": 2720, + "size": 2758, "stargazers_count": 0, "watchers_count": 0, "language": "CSS", @@ -175,10 +168,10 @@ "forks_count": 0, "mirror_url": null, "archived": false, - "open_issues_count": 1, + "open_issues_count": 2, "license": null, "forks": 0, - "open_issues": 1, + "open_issues": 2, "watchers": 0, "default_branch": "master" } @@ -186,7 +179,7 @@ "base": { "label": "tbushman:master", "ref": "master", - "sha": "0a92c66df823675e2a1a9a74132f2427d5bdd224", + "sha": "d91cfc285ddb7fc13d370694617fb9d3fda7c9d6", "user": { "login": "tbushman", "id": 7049294, @@ -274,14 +267,14 @@ "releases_url": "https://api.github.com/repos/tbushman/pu/releases{/id}", "deployments_url": "https://api.github.com/repos/tbushman/pu/deployments", "created_at": "2017-01-04T09:05:47Z", - "updated_at": "2018-07-01T04:09:57Z", - "pushed_at": "2018-11-01T03:06:36Z", + "updated_at": "2018-11-12T11:15:42Z", + "pushed_at": "2018-11-18T05:11:55Z", "git_url": "git://github.com/tbushman/pu.git", "ssh_url": "git@github.com:tbushman/pu.git", "clone_url": "https://github.com/tbushman/pu.git", "svn_url": "https://github.com/tbushman/pu", "homepage": "https://pu.bli.sh", - "size": 2720, + "size": 2758, "stargazers_count": 0, "watchers_count": 0, "language": "CSS", @@ -293,38 +286,38 @@ "forks_count": 0, "mirror_url": null, "archived": false, - "open_issues_count": 1, + "open_issues_count": 2, "license": null, "forks": 0, - "open_issues": 1, + "open_issues": 2, "watchers": 0, "default_branch": "master" } }, "_links": { "self": { - "href": "https://api.github.com/repos/tbushman/pu/pulls/13" + "href": "https://api.github.com/repos/tbushman/pu/pulls/15" }, "html": { - "href": "https://github.com/tbushman/pu/pull/13" + "href": "https://github.com/tbushman/pu/pull/15" }, "issue": { - "href": "https://api.github.com/repos/tbushman/pu/issues/13" + "href": "https://api.github.com/repos/tbushman/pu/issues/15" }, "comments": { - "href": "https://api.github.com/repos/tbushman/pu/issues/13/comments" + "href": "https://api.github.com/repos/tbushman/pu/issues/15/comments" }, "review_comments": { - "href": "https://api.github.com/repos/tbushman/pu/pulls/13/comments" + "href": "https://api.github.com/repos/tbushman/pu/pulls/15/comments" }, "review_comment": { "href": "https://api.github.com/repos/tbushman/pu/pulls/comments{/number}" }, "commits": { - "href": "https://api.github.com/repos/tbushman/pu/pulls/13/commits" + "href": "https://api.github.com/repos/tbushman/pu/pulls/15/commits" }, "statuses": { - "href": "https://api.github.com/repos/tbushman/pu/statuses/bce20f1db1348bdc53ac339ff91007afe88518ea" + "href": "https://api.github.com/repos/tbushman/pu/statuses/c9f2f27b01043673c8abad91500ac8197d75f8b0" } }, "author_association": "OWNER", @@ -337,9 +330,9 @@ "review_comments": 0, "maintainer_can_modify": false, "commits": 1, - "additions": 0, - "deletions": 6, - "changed_files": 1 + "additions": 1, + "deletions": 3, + "changed_files": 2 }, "repository": { "id": 77999410, @@ -408,14 +401,14 @@ "releases_url": "https://api.github.com/repos/tbushman/pu/releases{/id}", "deployments_url": "https://api.github.com/repos/tbushman/pu/deployments", "created_at": "2017-01-04T09:05:47Z", - "updated_at": "2018-07-01T04:09:57Z", - "pushed_at": "2018-11-01T03:06:36Z", + "updated_at": "2018-11-12T11:15:42Z", + "pushed_at": "2018-11-18T05:11:55Z", "git_url": "git://github.com/tbushman/pu.git", "ssh_url": "git@github.com:tbushman/pu.git", "clone_url": "https://github.com/tbushman/pu.git", "svn_url": "https://github.com/tbushman/pu", "homepage": "https://pu.bli.sh", - "size": 2720, + "size": 2758, "stargazers_count": 0, "watchers_count": 0, "language": "CSS", @@ -427,10 +420,10 @@ "forks_count": 0, "mirror_url": null, "archived": false, - "open_issues_count": 1, + "open_issues_count": 2, "license": null, "forks": 0, - "open_issues": 1, + "open_issues": 2, "watchers": 0, "default_branch": "master" }, diff --git a/probot/presolver/test/index.test.js b/probot/presolver/test/index.test.js index 77d6b65d4a..3746eba4ed 100644 --- a/probot/presolver/test/index.test.js +++ b/probot/presolver/test/index.test.js @@ -1,12 +1,7 @@ -const expect = require('expect'); +const expect = require('expect') const { Probot } = require('probot') const prSuccessEvent = require('./events/pullRequests.opened') const probotPlugin = require('..') -// Requiring our fixtures -//const payload = require('./fixtures/pullRequests.labeled') -//const issueCreatedBody = { body: 'Thanks for contributing!' } -// const url = (process.env.NODE_ENV === 'production' ? 'https://api.github.com' : 'https://smee.io/Vq0IH8tsXTuCp6kM') -//nock.disableNetConnect() describe('Presolver', () => { let probot, github @@ -36,12 +31,12 @@ describe('Presolver', () => { {filename: 'test.txt'} ] })), - getAll: jest.fn().mockResolvedValue({ data: [prSuccessEvent] }) + getAll: jest.fn().mockImplementation(() => ({ data: [prSuccessEvent.pull_request] })) } } app.auth = () => Promise.resolve(github) // just return a test token - //app.app = () => 'test' + // app.app = () => 'test' }) test('creates a comment when an issue is opened', async () => {