Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 4 additions & 1 deletion .eslintrc.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,10 @@ module.exports = {
"quotes": [2, "double"],
"comma-dangle": 0,
"global-require": 0,
"import/no-dynamic-require": 0,
"import/no-dynamic-require": 0, // activate all import rules later (issue with eslint 4.x)
"import/no-unresolved": 0,
"import/no-extraneous-dependencies": 0,
"import/no-absolute-path": 0,
"arrow-parens": [2, "always"],
indent: [ 2, 4, {
SwitchCase: 1
Expand Down
14 changes: 14 additions & 0 deletions .travis.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
language: node_js

node_js:
- "8"

sudo: false

branches:
only:
- master

script:
- "npm run lint"
- "npm test"
2 changes: 2 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
[![Build Status](https://travis-ci.org/gyandeeps/glados.svg?branch=master)](https://travis-ci.org/gyandeeps/glados)

GLaDOS
========

Expand Down
22 changes: 18 additions & 4 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,12 @@
"description": "Plugin based Github bot",
"main": "./src/app.js",
"scripts": {
"lint": "eslint src",
"lint:fix": "eslint src --fix",
"lint": "eslint src tests",
"lint:fix": "eslint src tests --fix",
"start": "node ./src/app.js",
"start:webhook": "node ./src/webhook.js",
"test": "echo \"Error: no test specified\" && exit 1"
"test": "jest --colors --verbose",
"test:cover": "jest --colors --coverage --verbose"
},
"author": "Gyandeep Singh <[email protected]>",
"license": "MIT",
Expand All @@ -29,13 +30,26 @@
"eslint": "^4.1.1",
"eslint-config-airbnb-base": "^11.2.0",
"eslint-plugin-import": "^2.6.1",
"localtunnel": "^1.8.3"
"jest": "^20.0.4",
"localtunnel": "^1.8.3",
"nock": "^9.0.13"
},
"keywords": [
"bot",
"github",
"events"
],
"jest": {
"testEnvironment": "node",
"testMatch": [
"<rootDir>/tests/**/*.js"
],
"testPathIgnorePatterns": [
"<rootDir>/tests/.eslintrc.js"
],
"coverageDirectory": "./coverage",
"collectCoverage": false
},
"engines": {
"node": ">=7.7"
}
Expand Down
5 changes: 5 additions & 0 deletions tests/.eslintrc.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
module.exports = {
env: {
jest: true
}
};
5 changes: 5 additions & 0 deletions tests/plugins/check-unit-test/index.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
describe("check unit test", () => {
test("sample", () => {
expect(1 + 2).toBe(3);
});
});
5 changes: 5 additions & 0 deletions tests/plugins/commit-message/index.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
describe("check commit message", () => {
test("sample", () => {
expect(1 + 2).toBe(3);
});
});
5 changes: 5 additions & 0 deletions tests/plugins/duplicate-comments/index.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
describe("Duplicate comments", () => {
test("sample", () => {
expect(1 + 2).toBe(3);
});
});
5 changes: 5 additions & 0 deletions tests/plugins/pr-ready-to-merge/index.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
describe("pr ready to merge", () => {
test("sample", () => {
expect(1 + 2).toBe(3);
});
});
95 changes: 95 additions & 0 deletions tests/plugins/triage/index.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,95 @@
const { triage } = require("../../../src/plugins/index");
const nock = require("nock");
const probot = require("probot");

/*
* We have to mock this dependecny as its not worth the effort to solve all the things
* related to private keys and request header cert.
*/
jest.mock("github-app", () => () => ({
createToken: () => Promise.resolve({
data: {
token: "test"
}
})
}));

describe("triage", () => {
let bot = null;

beforeAll(() => {
bot = probot({
id: "test",
cert: "test"
});
triage(bot.robot);
});

test("Adds the label if there are no labels present", (done) => {
const issueLabelReq = nock("https://api.github.com")
.post("/repos/test/repo-test/issues/1/labels", (body) => {
expect(body).toContain("triage");
return true;
})
.reply(200);

bot.receive({
event: "issues",
payload: {
action: "opened",
installation: {
id: 1
},
issue: {
labels: [],
number: 1
},
repository: {
name: "repo-test",
owner: {
login: "test"
}
}
}
});
setTimeout(() => {
expect(issueLabelReq.isDone()).toBeTruthy();
done();
}, 100);
});

test("Do not add the label if already present", (done) => {
const issueLabelReq = nock("https://api.github.com")
.post("/repos/test/repo-test/issues/1/labels", (body) => {
expect(body).toContain("triage");
return true;
})
.reply(200);

bot.receive({
event: "issues",
payload: {
action: "opened",
installation: {
id: 1
},
issue: {
labels: [
"label"
],
number: 1
},
repository: {
name: "repo-test",
owner: {
login: "test"
}
}
}
});
setTimeout(() => {
expect(issueLabelReq.isDone()).not.toBeTruthy();
done();
}, 100);
});
});