Skip to content

Commit

Permalink
Merge pull request #67 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
bas authored Nov 28, 2018
2 parents 95b7221 + e82fbb4 commit 8615061
Show file tree
Hide file tree
Showing 3 changed files with 21 additions and 17 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
6 changes: 4 additions & 2 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)
const label = await getLuisIntent(title);
response = await octokit.issues.addLabels({
owner,
repo,
number,
labels: ['enhancement', 'question', 'bug']
labels: [label]
})
}
context.res = {
Expand Down
24 changes: 13 additions & 11 deletions test/moderateIssueTest.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,29 +5,31 @@ var issueOpenedPayload = require("./fixtures/issue-opened.json");

describe("ModerateIssue", () => {
var moderateIssue

var defaultLabel;

before(() => {

createCommentStub = sinon.spy()
addLabelsStub = sinon.spy()

octoKitStubs = {
issues: {
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 assign the enhancement label', async () => {
await moderateIssue({}, { body: issueOpenedPayload })

sinon.assert.calledWith(addLabelsStub, {
labels: ['enhancement', 'question', 'bug'],
labels: [defaultLabel],
number: issueOpenedPayload.issue.number,
owner: issueOpenedPayload.repository.owner.login,
repo: issueOpenedPayload.repository.name
Expand Down

0 comments on commit 8615061

Please sign in to comment.