-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #1 from mauris/develop
Development updates for 1.1.0
- Loading branch information
Showing
7 changed files
with
285 additions
and
64 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -103,3 +103,5 @@ $RECYCLE.BIN/ | |
|
||
# Linux trash folder which might appear on any partition or disk | ||
.Trash-* | ||
|
||
testAuth.json |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,15 +1,33 @@ | ||
{ | ||
"name": "accuser", | ||
"version": "1.0.4", | ||
"version": "1.1.0", | ||
"description": "A Github Pull Request bot for assigning people to pull requests", | ||
"main": "index.js", | ||
"scripts": { | ||
"test": "echo \"Error: no test specified\" && exit 1" | ||
"test": "mocha" | ||
}, | ||
"author": "Sam Yong <mauris@hotmail.sg>", | ||
"contributors": [ | ||
{ | ||
"name": "Sam Yong", | ||
"email": "mauris@hotmail.sg" | ||
} | ||
], | ||
"homepage": "https://github.com/mauris/accuser", | ||
"repository": { | ||
"type": "git", | ||
"url": "https://github.com/mauris/accuser.git" | ||
}, | ||
"author": "Sam Yong", | ||
"license": "MIT", | ||
"engine": { | ||
"node": ">=0.4.0" | ||
}, | ||
"dependencies": { | ||
"bluebird": "^3.4.1", | ||
"github": "^2.5.1" | ||
}, | ||
"devDependencies": { | ||
"mocha": "^3.0.2", | ||
"sinon": "^1.17.5" | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
|
||
var Repository = function (user, repo) { | ||
this.user = user; | ||
this.repo = repo; | ||
this.workers = []; | ||
}; | ||
|
||
Repository.prototype.newWorker = function() { | ||
var self = this; | ||
var worker = { | ||
'filters': [], | ||
'do': [] | ||
}; | ||
self.workers.push(worker); | ||
var workerChainer = { | ||
"filter": function(filterCallback) { | ||
worker.filters.push(filterCallback); | ||
return workerChainer; | ||
}, | ||
"do": function(doCallback) { | ||
worker.do.push(doCallback); | ||
return workerChainer; | ||
} | ||
}; | ||
return workerChainer; | ||
}; | ||
|
||
module.exports = Repository; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,131 @@ | ||
var assert = require('assert'); | ||
var sinon = require('sinon'); | ||
var Promise = require('bluebird'); | ||
var Accuser = require('../'); | ||
|
||
describe("Accuser", function() { | ||
var accuser; | ||
var samplePR = { | ||
number: 20, | ||
base: { | ||
repo: { | ||
name: "accuser", | ||
owner: { | ||
login: "mauris" | ||
} | ||
} | ||
} | ||
}; | ||
|
||
beforeEach(function() { | ||
accuser = new Accuser(); | ||
}); | ||
|
||
it("should authenticate with Github", function(next) { | ||
var repository = accuser.addRepository("mauris", "accuser"); | ||
assert(repository); | ||
assert(accuser.repos[0] === repository); | ||
next(); | ||
}); | ||
|
||
it("should be able to add a new repository", function(next) { | ||
accuser.github = { | ||
authenticate: function(config){ | ||
assert(config.type === "oauth"); | ||
assert(config.token === "some token"); | ||
} | ||
}; | ||
var mock = sinon.mock(accuser.github); | ||
mock.expects("authenticate").once(); | ||
accuser.authenticate({ | ||
"type": "oauth", | ||
"token": "some token" | ||
}); | ||
mock.verify(); | ||
next(); | ||
}); | ||
|
||
it("should accuse someone based on a pull request object and username", function(next) { | ||
accuser.github = { | ||
issues: { | ||
addAssigneesToIssue: function(obj) { | ||
assert(obj.repo === samplePR.base.repo.name); | ||
assert(obj.user === samplePR.base.repo.owner.login); | ||
assert(obj.number === samplePR.number); | ||
assert(obj.assignees[0] === "mauris"); | ||
} | ||
} | ||
}; | ||
var mock = sinon.mock(accuser.github.issues); | ||
mock.expects("addAssigneesToIssue").once(); | ||
accuser.accuse(samplePR, ["mauris"]); | ||
mock.verify(); | ||
next(); | ||
}); | ||
|
||
it("should add a comment to a pull request", function(next) { | ||
accuser.github = { | ||
issues: { | ||
createComment: function(obj) { | ||
assert(obj.repo === samplePR.base.repo.name); | ||
assert(obj.user === samplePR.base.repo.owner.login); | ||
assert(obj.number === samplePR.number); | ||
assert(obj.body === "some comment"); | ||
} | ||
} | ||
}; | ||
var mock = sinon.mock(accuser.github.issues); | ||
mock.expects("createComment").once(); | ||
accuser.comment(samplePR, "some comment"); | ||
mock.verify(); | ||
next(); | ||
}); | ||
|
||
it("should fetch pull requests from an added repository", function(next) { | ||
var repository = accuser.addRepository("mauris", "accuser"); | ||
|
||
var filterSpy = sinon.spy(); | ||
var workerFilter = function(repo, pr) { | ||
assert(repository === repo); | ||
assert(pr == samplePR); | ||
filterSpy(); | ||
return true; | ||
}; | ||
|
||
var doSpy = sinon.spy(); | ||
var workerDo = function(repo, pr) { | ||
assert(repository === repo); | ||
assert(pr == samplePR); | ||
doSpy(); | ||
}; | ||
|
||
repository.newWorker() | ||
.filter(workerFilter) | ||
.do(workerDo); | ||
|
||
accuser.github = { | ||
pullRequests: { | ||
getAll: function(obj) { | ||
return new Promise(function(resolve, reject){ | ||
resolve([samplePR]); | ||
}) | ||
} | ||
}, | ||
hasNextPage: function() { | ||
return false | ||
} | ||
}; | ||
var mock = sinon.mock(accuser.github.pullRequests); | ||
mock.expects("getAll").once().returns(new Promise(function(resolve, reject){ | ||
resolve([samplePR]); | ||
})); | ||
|
||
accuser.tick() | ||
.then(function(){ | ||
assert(filterSpy.calledOnce); | ||
assert(doSpy.calledOnce); | ||
mock.verify(); | ||
next(); | ||
}); | ||
}); | ||
}); |
Oops, something went wrong.