Skip to content
This repository has been archived by the owner on May 30, 2024. It is now read-only.

Commit

Permalink
Merge pull request #30 from equichainfi/EQC-102
Browse files Browse the repository at this point in the history
EQC-102 feature: issue label ✅
  • Loading branch information
OlivierKobialka authored Jan 5, 2024
2 parents 7bb8462 + 65bf506 commit 0847d60
Show file tree
Hide file tree
Showing 3 changed files with 25 additions and 2 deletions.
16 changes: 15 additions & 1 deletion src/functions/format.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,8 @@ export default function format({
sender,
res,
fileBlobs,
repoName,
orgName,
}: IFormatInput): string {
const header: string = found
? `# ❗ Private Key found❗\n### ⚠️ You can proceed with caution ⚠️\n\n### 👤 Sender: @${sender}`
Expand All @@ -17,7 +19,14 @@ export default function format({
const lineAndKey = r.keysFound.map(
(key: string, index: number) => {
if (r.lineNumbers[index] === undefined) return "";
return `**[Line ${r.lineNumbers[index]}:](${fileBlobs[index]}#L${r.lineNumbers[index]})** \`${key}\``;
const commitHash: string | null = extractCommitHash(
fileBlobs[index],
);
if (!commitHash) return "";
const linkToLine: string = `${r.lineNumbers[index]}:](${fileBlobs[index]}#L${r.lineNumbers[index]}`;
const linkToBlob: string = `https://github.com/${orgName}/${repoName}/issues/new?permalink=https%3A%2F%2Fgithub.com%2F${orgName}%2F${repoName}%2Fblob%2F${commitHash}%2F${r.fileName}%23L${r.lineNumbers[index]}`;

return `**[Line ${linkToLine})** \`${key}\` [create an issue](${linkToBlob}) 🆘`;
},
);
if (lineAndKey.length === 1 && lineAndKey[0] === "") return "";
Expand All @@ -28,3 +37,8 @@ export default function format({
return `${header}\n\n## Keys Found:\n${keysFound}\n\n`;
} else return `${header}`;
}

function extractCommitHash(url: string): string | null {
const match = url.match(/\/blob\/([a-f0-9]+)\//);
return match ? match[1] : null;
}
9 changes: 8 additions & 1 deletion src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,14 @@ export = (app: Probot): void => {
found = foundPrivateKey(res);
let label: string = addLabel(found);
msg = context.issue({
body: `${format({ found, sender, res, fileBlobs })}`,
body: `${format({
found,
sender,
res,
fileBlobs,
repoName: context.payload.repository.name,
orgName: context.payload.repository.owner.login,
})}`,
});
await relabel(context, found);
await context.octokit.issues
Expand Down
2 changes: 2 additions & 0 deletions src/types/index.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,8 @@ declare module "probot" {
sender: string;
res: MainImplResponse[];
fileBlobs: string[];
repoName: string;
orgName: string;
}
interface IActionMap {
[key: string]: { add?: string[]; remove?: string[] };
Expand Down

0 comments on commit 0847d60

Please sign in to comment.