diff --git a/probot/presolver/app.yml b/probot/presolver/app.yml index 648d04f8b7..1aa6c44086 100644 --- a/probot/presolver/app.yml +++ b/probot/presolver/app.yml @@ -36,12 +36,12 @@ default_events: # - project_column # - public - pull_request -# - pull_request_review -# - pull_request_review_comment +- pull_request_review +- pull_request_review_comment # - push # - release -# - repository -# - repository_import +- repository +- repository_import # - status # - team # - team_add @@ -54,15 +54,15 @@ default_events: default_permissions: # Repository creation, deletion, settings, teams, and collaborators. # https://developer.github.com/v3/apps/permissions/#permission-on-administration - # administration: read + administration: read # Checks on code. # https://developer.github.com/v3/apps/permissions/#permission-on-checks - # checks: read + checks: read # Repository contents, commits, branches, downloads, releases, and merges. # https://developer.github.com/v3/apps/permissions/#permission-on-contents - # contents: read + contents: read # Deployments and deployment statuses. # https://developer.github.com/v3/apps/permissions/#permission-on-deployments @@ -70,11 +70,11 @@ default_permissions: # Issues and related comments, assignees, labels, and milestones. # https://developer.github.com/v3/apps/permissions/#permission-on-issues - issues: write + # issues: write # Search repositories, list collaborators, and access repository metadata. # https://developer.github.com/v3/apps/permissions/#metadata-permissions - # metadata: read + metadata: read # Retrieve Pages statuses, configuration, and builds, as well as create new builds. # https://developer.github.com/v3/apps/permissions/#permission-on-pages @@ -86,7 +86,7 @@ default_permissions: # Manage the post-receive hooks for a repository. # https://developer.github.com/v3/apps/permissions/#permission-on-repository-hooks - # repository_hooks: read + repository_hooks: read # Manage repository projects, columns, and cards. # https://developer.github.com/v3/apps/permissions/#permission-on-repository-projects @@ -98,7 +98,7 @@ default_permissions: # Commit statuses. # https://developer.github.com/v3/apps/permissions/#permission-on-statuses - # statuses: read + statuses: read # Organization members and teams. # https://developer.github.com/v3/apps/permissions/#permission-on-members @@ -118,7 +118,7 @@ default_permissions: # Manage the post-receive hooks for an organization. # https://developer.github.com/v3/apps/permissions/#permission-on-organization-hooks - # organization_hooks: read + organization_hooks: read # Get notified of, and update, content references. # https://developer.github.com/v3/apps/permissions/ diff --git a/probot/presolver/index.js b/probot/presolver/index.js index d0a7438ac3..a9494f5988 100644 --- a/probot/presolver/index.js +++ b/probot/presolver/index.js @@ -1,6 +1,28 @@ -/*const Presolver = require('./lib/presolver'); +const debug = require("debug")("probot: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 = {}; + //} -function probotPlugin(robot) { + /*static get STATE() { + return Object.freeze({ + CLASH: 'clashing' + }); + }*/ + + + + +//} + +async function probotPlugin(robot) { const events = [ "pull_request.opened", "pull_request.edited", @@ -10,14 +32,29 @@ function probotPlugin(robot) { robot.on(events, presolve); } +async function _getClashingRanges(context, pullRequest) { + const repo = pullRequest.base.repo; + //console.log(pullRequest) + const owner = repo.owner; + const number = pullRequest.number; -async function presolve(context) { - const presolverContext = getRepository(context); - const pullRequest = getPullRequest(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; -function getRepository(context) { - const config = Object.assign(context.repo()); + const state = await _getClashingRanges(context, pullRequest); + +} +function forRepository(context) { + const config = Object.assign({}, context.repo({ logger: debug })); return new Presolver(context.github, config); } @@ -25,20 +62,34 @@ function getPullRequest(context) { return context.payload.pull_request || context.payload.review.pull_request; } -module.exports = probotPlugin; -*/ -function getPullRequest(context) { - return context.payload.pull_request || context.payload.review.pull_request; + +async function presolve(context) { + //const presolved = //forRepository(context); + const pullRequest = getPullRequest(context); + //presolver.presolve(pullRequest); + console.log(context); + return presolver(context, pullRequest); } -module.exports = async app => { +module.exports = probotPlugin; +/*module.exports = async app => { // Your code here app.log('Yay, the app was loaded!') - app.on('pull_request.labeled', async context => { + 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 } = getPullRequest(context); - const owner = context.repo().owner; - const repo = context.repo().repo; + + 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 || []; @@ -72,7 +123,7 @@ module.exports = async app => { return Object.values(uniqueReviews); }*/ //const params = - const commit_id = head.sha; +/* const commit_id = head.sha; const body = 'probot comment test'; const filepath = './app.js' const pos = 4; @@ -88,7 +139,7 @@ module.exports = async app => { const position = //comments[].path = pos; - const reviewers = ['tbushman'] + const reviewers = ['tbushman']*/ /*return await context.github.pullRequests.createReview({ owner, repo, @@ -98,16 +149,16 @@ module.exports = async app => { event, comments - }) - /*const issueComment = context.issue({ body: 'probot label test' }) - return context.github.issues.createComment(issueComment)*/ - return await context.github.pullRequests.createReviewRequest({owner, repo, number, reviewers}) - }) + })*/ +/* 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/ -} +//} diff --git a/probot/presolver/lib/presolver.js b/probot/presolver/lib/presolver.js deleted file mode 100644 index c12283cf8b..0000000000 --- a/probot/presolver/lib/presolver.js +++ /dev/null @@ -1,41 +0,0 @@ -class Presolver { - 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 _getClashingRanges(pullRequest) { - Object.assign(this.pullRequest, pullRequest); - const { owner, repo } = this.config; - const number = this.pullRequest.number; - - const prs = (await this.github.pullRequests.get({ owner, repo })) - .data || []; - this.logger(prs) - prs.forEach(function(pr){ - const files = pr.files() - }) - } - - async presolve(pullRequest) { - Object.assign(this.pullRequest, pullRequest); - const { owner, repo } = this.config; - const number = this.pullRequest.number; - - const state = await this._getClashingRanges(pullRequest); - - } - -} - -module.exports = Presolver; \ No newline at end of file diff --git a/probot/presolver/test/index.test.js b/probot/presolver/test/index.test.js index 55d8f19135..f892d93791 100644 --- a/probot/presolver/test/index.test.js +++ b/probot/presolver/test/index.test.js @@ -4,26 +4,33 @@ const myProbotApp = require('..') const { Probot } = require('probot') // Requiring our fixtures const payload = require('./fixtures/pullRequests.labeled') -const issueCreatedBody = { body: 'Thanks for opening this issue!' } - +const issueCreatedBody = { body: 'Thanks for contributing!' } +// const url = (process.env.NODE_ENV === 'production' ? 'https://api.github.com' : 'https://smee.io/Vq0IH8tsXTuCp6kM') nock.disableNetConnect() describe('My Probot app', () => { - let probot + let probot, github beforeEach(() => { probot = new Probot({}) // Load our app into probot - const app = probot.load(myProbotApp) - + let app = probot.load(myProbotApp) + // This is an easy way to mock out the GitHub API + // https://probot.github.io/docs/testing/ + github = { + issues: { + createComment: jest.fn().mockReturnValue(Promise.resolve({})) + } + } + 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 () => { - nock('https://api.github.com') + /*nock(url) .post('/app/installations/421598/access_tokens') - .reply(200, { token: 'test' }) + .reply(200, { token: 'test' })*/ // Test that a comment is posted /*nock('https://api.github.com') @@ -34,7 +41,8 @@ describe('My Probot app', () => { .reply(200)*/ // Receive a webhook event - await probot.receive({name: 'pull_request', payload: payload}) + await probot.receive({name: 'pull_request.opened', payload: payload}) + expect(github.issues.createComment).toHaveBeenCalled() }) })