Skip to content
Open
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
9 changes: 5 additions & 4 deletions index.js
Original file line number Diff line number Diff line change
Expand Up @@ -171,10 +171,10 @@ export default (app) => {
}

// find regex [0-9]\+ in issue_body and get first result
let pr_number = issue_body.match(/[0-9]+/)[0];
let pr_number = issue_body?.match(/#?\s*([0-9]+)/i)?.[1] || '';

// Get answers to first question and find if they contain affirmative answer
let firstQuestionResponse = await getQuestionResponse(1, 2, issue_body);
let firstQuestionResponse = (await getQuestionResponse(1, 2, issue_body)) || [];
let isCopilotUsed = firstQuestionResponse.some((response) => {
return (
response.includes("Sim") ||
Expand Down Expand Up @@ -345,7 +345,8 @@ export default (app) => {
let AnswerSelected = false;
let Answers = new Array();
let Expression = end ? new RegExp(start + "\\. (.*" + end + "\\." + ")?", "s") : new RegExp(start + "\\. (.*" + ")?", "s");
let QuestionOptions = issue_body.match(Expression)[0].match(/\[x\].*/g);
let question = issue_body?.match(Expression);
let QuestionOptions = question ? question[0].match(/\[x\].*/g) : null;
if(QuestionOptions){
AnswerSelected = true;
QuestionOptions.forEach((option) => {
Expand Down Expand Up @@ -383,4 +384,4 @@ class AppInsights {
this.appIClient.trackException(exception);
}
}
}
}
11 changes: 11 additions & 0 deletions test/index.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -156,6 +156,17 @@ describe("My Probot app", () => {
expect(mock.pendingMocks()).toStrictEqual([]);
});

test("handles edited survey bodies without PR numbers or question markers", async () => {
const payload = structuredClone(payload_issues_edited);
payload.issue.body = "This edited survey has no numbered question markers.";

sql.Request.mockClear();
await probot.receive({ name: "issues", payload });

const request = sql.Request.mock.results[0].value;
expect(request.input).toHaveBeenCalledWith("value5", "");
});

test("closes an issue if a comment is received", async () => {
const mock = nock("https://api.github.com")
// Test that we correctly return a test token
Expand Down
Loading