diff --git a/probot/presolver/index.js b/probot/presolver/index.js index f5f16cd1d6..f7ccc363f1 100644 --- a/probot/presolver/index.js +++ b/probot/presolver/index.js @@ -1,4 +1,33 @@ -module.exports = app => { +const Presolver = require('./lib/presolver'); + +function probotPlugin(robot) { + const events = [ + "pull_request.opened", + "pull_request.edited", + "pull_request.synchronize", + "pull_request.reopened" + ]; + + robot.on(events, presolve); +} + +async function presolve(context) { + const presolverContext = getRepository(context); + const pullRequest = getPullRequest(context); +} + +function getRepository(context) { + const config = Object.assign(context.repo()); + return new Presolver(context.github, 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!') @@ -12,4 +41,4 @@ module.exports = app => { // 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 new file mode 100644 index 0000000000..c12283cf8b --- /dev/null +++ b/probot/presolver/lib/presolver.js @@ -0,0 +1,41 @@ +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