Skip to content

Commit

Permalink
Merge pull request #1428 from h0x0er/improve-kbanalysis
Browse files Browse the repository at this point in the history
Add improvements in kbanalysis
  • Loading branch information
varunsh-coder committed Nov 16, 2022
2 parents 226b3da + 44c730e commit 9d85dcc
Show file tree
Hide file tree
Showing 3 changed files with 59 additions and 30 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/kbanalysis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ jobs:
uses: peter-evans/create-pull-request@18f7dc018cc2cd597073088f7c7591b9d1c02672
with:
token: ${{secrets.PAT}} # need to use PAT since GITHUB_TOKEN does not initiate workflows
body: "This PR adds a YAML file to describe token permissions needed for Action: ${{steps.get-action.outputs.id}}.\n Fixes #${{github.event.issue.number}}"
body: "This PR adds a YAML file to describe token permissions needed for Action: ${{steps.get-action.outputs.id}}."
commit-message: "added KB for issue#${{github.event.issue.number}}"
title: "[KB] Add GitHub token permissions for ${{steps.get-action.outputs.id}} Action"
branch: "issue#${{github.event.issue.number}}"
42 changes: 28 additions & 14 deletions kbanalysis/dist/src/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -8541,6 +8541,12 @@ async function handleKBIssue(octokit, owner, repo, issue) {
});
if (resp.status == 200) {
let old_body = resp.data.body;
let action_name = getAction(issue.title);
if (old_body.indexOf(action_name) >= 0) {
_actions_core__WEBPACK_IMPORTED_MODULE_0__.info(`[!] Action ${action_name} is already being tracked`);
let ret = await closeIssue(octokit, owner, repo, issue);
return ret;
}
let new_body = old_body + comment;
let resp2 = await octokit.rest.issues.updateComment({
owner: owner,
Expand All @@ -8553,20 +8559,8 @@ async function handleKBIssue(octokit, owner, repo, issue) {
}
else {
_actions_core__WEBPACK_IMPORTED_MODULE_0__.info(`[!] Added ${issue.title} in tracking comment.`);
let resp3 = await octokit.rest.issues.update({
owner: owner,
repo: repo,
issue_number: issue.number,
state: "closed",
});
if (resp3.status === 200) {
_actions_core__WEBPACK_IMPORTED_MODULE_0__.info(`[!] Closed Issue ${issue.number}`);
return "success";
}
else {
_actions_core__WEBPACK_IMPORTED_MODULE_0__.info(`[X] Unable to close issue ${issue.number}`);
return "error: unable to close issue";
}
let ret = await closeIssue(octokit, owner, repo, issue);
return ret;
}
}
_actions_core__WEBPACK_IMPORTED_MODULE_0__.info(`[X] Unable to handle: ${issue.title} `);
Expand Down Expand Up @@ -8607,6 +8601,26 @@ async function prepareComment(client, owner, repo, issue) {
body: "unable to fetch analysis",
});
}
function getAction(x) {
x = x.split(" ");
return x[6];
}
async function closeIssue(octokit, owner, repo, issue) {
let resp3 = await octokit.rest.issues.update({
owner: owner,
repo: repo,
issue_number: issue.number,
state: "closed",
});
if (resp3.status === 200) {
_actions_core__WEBPACK_IMPORTED_MODULE_0__.info(`[!] Closed Issue ${issue.number}`);
return "success";
}
else {
_actions_core__WEBPACK_IMPORTED_MODULE_0__.info(`[X] Unable to close issue ${issue.number}`);
return "error: unable to close issue";
}
}


/***/ }),
Expand Down
45 changes: 30 additions & 15 deletions kbanalysis/src/issues-util.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
import { Octokit } from "@octokit/core";
import { Api } from "@octokit/plugin-rest-endpoint-methods/dist-types/types";
import * as core from "@actions/core";
import { exit } from "process";

export async function handleKBIssue(
octokit: Octokit & Api,
Expand All @@ -22,8 +21,14 @@ export async function handleKBIssue(

if (resp.status == 200) {
let old_body = resp.data.body;
let new_body = old_body + comment;
let action_name = getAction(issue.title);
if (old_body.indexOf(action_name) >= 0) {
core.info(`[!] Action ${action_name} is already being tracked`);
let ret = await closeIssue(octokit, owner, repo, issue)
return ret;
}

let new_body = old_body + comment;
let resp2 = await octokit.rest.issues.updateComment({
owner: owner,
repo: repo,
Expand All @@ -34,19 +39,8 @@ export async function handleKBIssue(
core.info(`[X] Unable to add: ${issue.number} in the tracking comment`);
} else {
core.info(`[!] Added ${issue.title} in tracking comment.`);
let resp3 = await octokit.rest.issues.update({
owner: owner,
repo: repo,
issue_number: issue.number,
state: "closed",
});
if (resp3.status === 200) {
core.info(`[!] Closed Issue ${issue.number}`);
return "success";
} else {
core.info(`[X] Unable to close issue ${issue.number}`);
return "error: unable to close issue";
}
let ret = await closeIssue(octokit, owner, repo, issue)
return ret;
}
}
core.info(`[X] Unable to handle: ${issue.title} `);
Expand Down Expand Up @@ -95,3 +89,24 @@ async function prepareComment(
body: "unable to fetch analysis",
});
}

function getAction(x) {
x = x.split(" ");
return x[6];
}

async function closeIssue(octokit, owner, repo, issue) {
let resp3 = await octokit.rest.issues.update({
owner: owner,
repo: repo,
issue_number: issue.number,
state: "closed",
});
if (resp3.status === 200) {
core.info(`[!] Closed Issue ${issue.number}`);
return "success";
} else {
core.info(`[X] Unable to close issue ${issue.number}`);
return "error: unable to close issue";
}
}

0 comments on commit 9d85dcc

Please sign in to comment.