test on repo
This commit is contained in:
committed by
mrugesh mohapatra
parent
5c926dc2dd
commit
e2c57be829
@ -29,7 +29,8 @@ async function probotPlugin(robot) {
|
||||
"pull_request.opened",
|
||||
"pull_request.edited",
|
||||
"pull_request.synchronize",
|
||||
"pull_request.reopened"
|
||||
"pull_request.reopened",
|
||||
"pull_request.labeled"
|
||||
];
|
||||
|
||||
robot.on(events, presolve.bind(null, robot));
|
||||
|
@ -17,6 +17,9 @@ class Presolver {
|
||||
const number = this.pullRequest.number;
|
||||
await this._ensurePresolverLabelExists();
|
||||
const state = await this._getState();
|
||||
if (this.conflictingFiles.length) {
|
||||
await this._addLabel();
|
||||
}
|
||||
/*switch(state) {
|
||||
case Presolver.STATE.CONFLICT:
|
||||
case Presolver.STATE.NOCONFLICT:
|
||||
@ -53,11 +56,11 @@ class Presolver {
|
||||
async _getConflictingFiles(prs, files) {
|
||||
prs.forEach(function(pr){
|
||||
var prFiles = pr.getFiles();
|
||||
prFiles.forEach(function(file){
|
||||
files.forEach(function(f){
|
||||
prFiles.data.forEach(function(file){
|
||||
files.data.forEach(function(f){
|
||||
console.log(f, file)
|
||||
if (f === file) {
|
||||
this.conflictingFiles.push(file)
|
||||
if (f.filename === file.filename) {
|
||||
this.conflictingFiles.push(file.filename)
|
||||
}
|
||||
})
|
||||
})
|
||||
@ -84,6 +87,32 @@ class Presolver {
|
||||
});
|
||||
});
|
||||
}
|
||||
|
||||
_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"));
|
||||
});
|
||||
}
|
||||
async _addLabel() {
|
||||
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(() => {
|
||||
return this.github.issues.addLabels({
|
||||
owner,
|
||||
repo,
|
||||
number,
|
||||
labels: [labelObj.name]
|
||||
});
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
module.exports = Presolver
|
@ -1,5 +1,5 @@
|
||||
{
|
||||
"action": "reopened",
|
||||
"action": "opened",
|
||||
"number": 13,
|
||||
"pull_request": {
|
||||
"url": "https://api.github.com/repos/tbushman/pu/pulls/13",
|
||||
|
@ -47,7 +47,7 @@ describe('Presolver', () => {
|
||||
test('creates a comment when an issue is opened', async () => {
|
||||
// Receive a webhook event
|
||||
await probot.receive({name: 'pull_request.opened', payload: prSuccessEvent})
|
||||
expect(github.issues.createLabel).toHaveBeenCalled()
|
||||
expect(github.issues.addLabels).toHaveBeenCalled()
|
||||
})
|
||||
})
|
||||
|
||||
|
Reference in New Issue
Block a user