diff --git a/src/functions/format.ts b/src/functions/format.ts index b5e082b..f8e2854 100644 --- a/src/functions/format.ts +++ b/src/functions/format.ts @@ -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}` @@ -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 ""; @@ -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; +} diff --git a/src/index.ts b/src/index.ts index 52bf382..80cc838 100644 --- a/src/index.ts +++ b/src/index.ts @@ -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 diff --git a/src/types/index.d.ts b/src/types/index.d.ts index 79bffc1..62666f5 100644 --- a/src/types/index.d.ts +++ b/src/types/index.d.ts @@ -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[] };