Skip to content

Commit 3c1df55

Browse files
committed
Minor fixes applied & package update
1 parent ad40d17 commit 3c1df55

File tree

5 files changed

+129
-36
lines changed

5 files changed

+129
-36
lines changed

.env.example

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -6,9 +6,6 @@ WEBHOOK_SECRET=development
66
# Use `trace` to get verbose logging or `info` to show less
77
LOG_LEVEL=debug
88

9-
# Go to https://smee.io/new set this to the URL that you are redirected to.
10-
WEBHOOK_PROXY_URL=
11-
129
LANGUAGE_API_ENDPOINT=
1310
LANGUAGE_API_KEY=
1411
APPLICATIONINSIGHTS_CONNECTION_STRING=

index.js

Lines changed: 25 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,9 @@ module.exports = (app) => {
2929
});
3030
let pr_number = context.payload.pull_request.number;
3131
let pr_body = context.payload.pull_request.body;
32-
let result = [{ primaryLanguage: { iso6391Name: "en" } }];
32+
let detectedLanguage = "en";
33+
let pr_author = context.payload.pull_request.user.login;
34+
let organization_name = context.payload.repository.owner.login
3335

3436
// check language for pr_body
3537
if (LANGUAGE_API_ENDPOINT && LANGUAGE_API_KEY) {
@@ -40,7 +42,7 @@ module.exports = (app) => {
4042
if (pr_body) {
4143
try {
4244
let startTime = Date.now();
43-
result = await TAclient.analyze("LanguageDetection", [pr_body]);
45+
let result = await TAclient.analyze("LanguageDetection", [pr_body]);
4446
let duration = Date.now() - startTime;
4547
appInsights.trackDependency({
4648
target: "API:Language Detection",
@@ -50,12 +52,10 @@ module.exports = (app) => {
5052
success: true,
5153
dependencyTypeName: "HTTP",
5254
});
53-
if (
54-
!["en", "es", "pt", "fr"].includes(
55-
result[0].primaryLanguage.iso6391Name
56-
)
57-
) {
58-
result[0].primaryLanguage.iso6391Name = "en";
55+
if (result.length > 0 && !result[0].error && ["en", "es", "pt", "fr"].includes(result[0].primaryLanguage.iso6391Name) ) {
56+
detectedLanguage = result[0].primaryLanguage.iso6391Name;
57+
}else {
58+
detectedLanguage = "en";
5959
}
6060
} catch (err) {
6161
app.log.error(err);
@@ -67,7 +67,7 @@ module.exports = (app) => {
6767
// read file that aligns with detected language
6868
const issue_body = fs.readFileSync(
6969
"./issue_template/copilot-usage-" +
70-
result[0].primaryLanguage.iso6391Name +
70+
detectedLanguage +
7171
".md",
7272
"utf-8"
7373
);
@@ -79,11 +79,11 @@ module.exports = (app) => {
7979

8080
// display the body for the issue
8181
app.log.info(fileContent);
82-
83-
// create an issue using fileContent as body
82+
83+
// create an issue using fileContent as body if pr_author is included in copilotSeats
8484
try {
8585
await context.octokit.issues.create({
86-
owner: context.payload.repository.owner.login,
86+
owner: organization_name,
8787
repo: context.payload.repository.name,
8888
title: "Copilot Usage - PR#" + pr_number.toString(),
8989
body: fileContent,
@@ -402,19 +402,19 @@ module.exports = (app) => {
402402
completed_at
403403
)
404404
VALUES (
405-
${enterprise_name},
406-
${organization_name},
407-
${context.payload.repository.name},
408-
${issue_id},
409-
${context.payload.issue.number},
410-
${pr_number},
411-
${assignee_name},
412-
${isCopilotUsed},
413-
${pctValue},
414-
${freqValue},
415-
${comment},
416-
${context.payload.issue.created_at},
417-
${context.payload.issue.updated_at}
405+
'${enterprise_name}',
406+
'${organization_name}',
407+
'${context.payload.repository.name}',
408+
${issue_id},
409+
${context.payload.issue.number},
410+
${pr_number},
411+
'${assignee_name}',
412+
'${isCopilotUsed}',
413+
'${pctValue}',
414+
'${freqValue}',
415+
'${comment}',
416+
'${context.payload.issue.created_at}',
417+
'${context.payload.issue.updated_at}'
418418
)`;
419419
let insert_result = await sql.query(insert_query);
420420
app.log.info(insert_result);

package-lock.json

Lines changed: 80 additions & 6 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,8 +17,11 @@
1717
},
1818
"dependencies": {
1919
"@azure/ai-language-text": "^1.1.0",
20+
"@azure/ai-text-analytics": "^5.1.0",
21+
"ai-text-analytics": "^0.0.1-security",
2022
"applicationinsights": "^2.7.3",
2123
"dedent": "^1.5.1",
24+
"dotenv": "^16.3.1",
2225
"mssql": "^9.2.0",
2326
"probot": "^12.3.1"
2427
},

test/index.test.js

Lines changed: 21 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ const payload_issues_edited = require("./fixtures/issues.edited.json");
88
const issue_comment_created = require("./fixtures/issue_comment.created.json");
99
const fs = require("fs");
1010
const path = require("path");
11+
const LANGUAGE_API_ENDPOINT = process.env.LANGUAGE_API_ENDPOINT;
1112

1213
const issue_body = fs.readFileSync(
1314
path.join(__dirname, "fixtures/issue_body.md"),
@@ -29,7 +30,25 @@ describe("My Probot app", () => {
2930

3031
beforeEach(() => {
3132
nock.disableNetConnect();
32-
nock.enableNetConnect('ghazlanguage.cognitiveservices.azure.com');
33+
nock.enableNetConnect(LANGUAGE_API_ENDPOINT);
34+
nock(LANGUAGE_API_ENDPOINT)
35+
.post('/language/:analyze-text?api-version=2023-04-01')
36+
.reply(200, {
37+
"kind": "LanguageDetectionResults",
38+
"results": {
39+
"documents": [{
40+
"id": "1",
41+
"detectedLanguage": {
42+
"name": "English",
43+
"iso6391Name": "en",
44+
"confidenceScore": 1.0
45+
},
46+
"warnings": []
47+
}],
48+
"errors": [],
49+
"modelVersion": "2022-10-01"
50+
}
51+
});
3352
probot = new Probot({
3453
appId: 123,
3554
privateKey,
@@ -53,7 +72,7 @@ describe("My Probot app", () => {
5372
issues: "write",
5473
},
5574
})
56-
75+
5776
// Test that a issue is created
5877
.post("/repos/mageroni/TestRepo/issues", (body) => {
5978
expect(body).toMatchObject(expected_issue);

0 commit comments

Comments
 (0)