From 6a66dcf1aa0d698979cb6f4da635933fab85e4c7 Mon Sep 17 00:00:00 2001 From: Filipe Casal Date: Mon, 28 Oct 2024 12:08:38 +0000 Subject: [PATCH] feat: add copy all audit permalinks button (#63) --- package.json | 20 ++++++++++++++++++-- src/codeMarker.ts | 28 ++++++++++++++++++++++++++++ 2 files changed, 46 insertions(+), 2 deletions(-) diff --git a/package.json b/package.json index 908f2c9..edef184 100644 --- a/package.json +++ b/package.json @@ -82,6 +82,11 @@ "title": "Copy Audit Permalink", "icon": "$(link)" }, + { + "command": "weAudit.copyEntryPermalinks", + "title": "Copy All Audit Permalinks", + "icon": "$(link)" + }, { "command": "weAudit.copySelectedCodePermalink", "title": "weAudit: Copy Permalink (Audit Repository)" @@ -369,7 +374,12 @@ }, { "command": "weAudit.copyEntryPermalink", - "when": "view == codeMarker && viewItem != pathOrganizer", + "when": "view == codeMarker && viewItem == additionalLocation", + "group": "inline@2" + }, + { + "command": "weAudit.copyEntryPermalinks", + "when": "view == codeMarker && viewItem != pathOrganizer && viewItem != additionalLocation", "group": "inline@2" }, { @@ -450,6 +460,11 @@ "type": "string", "default": "", "description": "The username to use as the finding's author. (Defaults to the system's username if left empty.)" + }, + "weAudit.general.permalinkSeparator": { + "type": "string", + "default": "\\n", + "description": "The separator to use in permalinks. (Note that \\n is interpreted as a newline)" } } }, @@ -491,7 +506,8 @@ "compile": "node ./esbuild.js", "package": "NODE_ENV=production node ./esbuild.js", "watch": "node ./esbuild.js --watch", - "lint": "eslint src --ext ts" + "lint": "eslint src --ext ts", + "prettier": "prettier --write ." }, "devDependencies": { "@microsoft/eslint-formatter-sarif": "^3.0.0", diff --git a/src/codeMarker.ts b/src/codeMarker.ts index 745f839..fc9a9f8 100644 --- a/src/codeMarker.ts +++ b/src/codeMarker.ts @@ -1771,6 +1771,10 @@ export class CodeMarker implements vscode.TreeDataProvider { this.copyEntryPermalink(entry); }); + vscode.commands.registerCommand("weAudit.copyEntryPermalinks", (entry: FullEntry) => { + this.copyEntryPermalinks(entry); + }); + vscode.commands.registerTextEditorCommand("weAudit.copySelectedCodePermalink", () => { this.copySelectedCodePermalink(Repository.Audit); }); @@ -2558,6 +2562,30 @@ export class CodeMarker implements vscode.TreeDataProvider { this.copyToClipboard(remoteAndPermalink.permalink); } + /** + * Copy all permalinks of the given entry to the clipboard + * @param entry The entry to copy the permalinks of + */ + async copyEntryPermalinks(entry: FullEntry): Promise { + const permalinkList = []; + for (const location of entry.locations) { + const remoteAndPermalink = await this.getEntryRemoteAndPermalink(location); + if (remoteAndPermalink === undefined) { + return; + } + permalinkList.push(remoteAndPermalink.permalink); + } + + // get separator from configuration + const separator: string = vscode.workspace.getConfiguration("weAudit").get("general.permalinkSeparator") || "\n"; + // interpret \n as newline + const interpretedSep = separator.replace(/\\n/g, "\n"); + // join the permalinks with the separator + const permalinksString = permalinkList.join(interpretedSep); + // copy the permalinks to the clipboard + this.copyToClipboard(permalinksString); + } + /** * Copy the given text to the clipboard * @param txt The text to copy to the clipboard