Skip to content

Commit

Permalink
Merge pull request #56 from octodemo/use-luis-to-label-issues
Browse files Browse the repository at this point in the history
Use luis to label issues
  • Loading branch information
pierluigi authored Nov 14, 2018
2 parents 48da7b2 + acbc094 commit 47fae4a
Show file tree
Hide file tree
Showing 3 changed files with 26 additions and 20 deletions.
8 changes: 4 additions & 4 deletions ModerateIssue/get-luis-intent.js
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
const luisAppId = process.env.LUIS_APP_ID;
const endpointKey = process.env.LUIS_ENDPOINT_KEY;

const request = require('request');
const querystring = require('querystring');

module.exports = function getLuisIntent(utterance) {
module.exports = function (utterance) {
const request = require('request');
const querystring = require('querystring');
const luisEndpoint = "https://westus.api.cognitive.microsoft.com/luis/v2.0/apps/";

const queryParams = {
Expand Down
8 changes: 5 additions & 3 deletions ModerateIssue/index.js
Original file line number Diff line number Diff line change
@@ -1,10 +1,11 @@
const octokit = require("@octokit/rest")();
const authenticate = require('./authenticate');
const getLuisIntent = require('./get-luis-intent');

module.exports = async function (context, data) {
const { body } = data
const { action, repository, issue, installation } = body;
const { number } = issue;
const { number, title } = issue;
const repo = repository.name;
const owner = repository.owner.login;
const installationId = installation.id;
Expand All @@ -13,11 +14,12 @@ module.exports = async function (context, data) {
let response = "";
if (action === "opened") {
await authenticate(octokit, installationId)
response = await octokit.issues.createComment({
const label = await getLuisIntent(title);
response = await octokit.issues.addLabels({
owner,
repo,
number,
body: "Thanks for submitting this issue. We will take a look at it later!"
labels: [label]
})
}
context.res = {
Expand Down
30 changes: 17 additions & 13 deletions test/moderateIssueTest.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,32 +2,36 @@ var sinon = require("sinon");
var proxyquire = require("proxyquire");
var issueOpenedPayload = require("./fixtures/issue-opened.json");

describe("ModerateIssue", function() {
var moderateIssue;

before(function() {
createCommentStub = sinon.spy();
addLabelsStub = sinon.spy();
describe("ModerateIssue", () => {
var moderateIssue
var defaultLabel;

before(() => {
createCommentStub = sinon.spy()
addLabelsStub = sinon.spy()

octoKitStubs = {
issues: {
addLabelsStub: addLabelsStub,
addLabels: addLabelsStub,
createComment: createCommentStub
}
};

}

defaultLabel = 'question'
moderateIssue = proxyquire("../ModerateIssue/index", {
"@octokit/rest": () => octoKitStubs,
"./authenticate": () => true,
"./get-luis-intent": () => "question"
'@octokit/rest': () => octoKitStubs,
'./authenticate': () => true,
'./get-luis-intent': () => new Promise(resolve => resolve(defaultLabel))
});
});

it("should create comment when issue is opened", async () => {
await moderateIssue({}, { body: issueOpenedPayload });

sinon.assert.calledWith(createCommentStub, {
body:
"Thanks for submitting this issue. We will take a look at it later!",
sinon.assert.calledWith(addLabelsStub, {
labels: [defaultLabel],
number: issueOpenedPayload.issue.number,
owner: issueOpenedPayload.repository.owner.login,
repo: issueOpenedPayload.repository.name
Expand Down

0 comments on commit 47fae4a

Please sign in to comment.