in src/main.ts [45:149]
async function handleSimilarIssuesScanning(issue: any, owner: string, repo: string, password: string, token: string, botUrl: string) {
const octokit = github.getOctokit(token);
const issueNumber = issue.number;
let owner_repo = `${owner}/${repo}`;
owner_repo = owner_repo.toLowerCase();
core.debug(`owner/repo: ${owner_repo}`);
const if_closed: boolean = issue.state === 'closed';
if (if_closed) {
await axios.post(botUrl + '/update_issue/', {
'raw': issue,
'password': password
})
core.info('This issue was closed. Update it to issue sentinel.');
return;
}
const if_replied: boolean = (await axios.post(botUrl + '/check_reply/', {
'repo': owner_repo,
'issue': issue.number,
'password': password
})).data.result;
core.info('Check if this issue was already replied by the sentinel: ' + if_replied.toString());
if (if_replied) {
await axios.post(botUrl + '/update_issue/', {
'raw': issue,
'password': password
})
core.info('This issue was already replied by the sentinel. Update the edited content to sentinel and skip this issue.');
return;
}
const response = (await axios.post(botUrl + '/search/', {
'raw': issue,
'password': password,
'verify': true,
'token': token //used for access issue comment to get possible solution
})).data;
const prediction: any[][] = response.predict;
core.info('Search by the issue sentinel successfully.');
core.debug(`Response: ${response}`);
if (!prediction || prediction.length === 0) {
core.info('No prediction found');
return;
}
let message = 'Here are some similar issues that might help you. Please check if they can solve your problem.\n'
for (const item of prediction) {
message += `- #${item[item.length - 1]}\n`
}
const solution: any[] = response.solution;
let isPossibleSolutionPresent: boolean = false;
if (!solution || solution.length === 0) {
core.info('No solution found');
}
else {
isPossibleSolutionPresent = true;
message += '------------\n\n**Possible solution (Extracted from existing issue, might be incorrect; please verify carefully)**\n\n';
let solutionIndex = 1;
for (const item of solution) {
if (solution.length > 1) {
message += `### Solution ${solutionIndex}:\n`;
}
message += item.solution + '\n\n'
solutionIndex++;
if (item.reference.length > 0) {
message += '**Reference**:\n';
}
for (const ref of item.reference) {
message += `- ${ref}\n`;
}
}
}
message += PoweredBy;
let labels = ["Similar-Issue"];
if (isPossibleSolutionPresent) {
labels.push("Possible-Solution");
}
await octokit.rest.issues.addLabels({
owner,
repo,
issue_number: issueNumber,
labels
});
core.info(`Labels added to issue #${issueNumber}`);
message = message.trimEnd();
await octokit.rest.issues.createComment({
owner,
repo,
issue_number: issueNumber,
body: message
});
core.info(`Comment sent to issue #${issueNumber}`);
await axios.post(botUrl + '/add_reply/', {
'repo': owner_repo,
'issue': issue.number,
'password': password
});
core.info('Save replied issue to issue sentinel.');
}