Skip to content

Commit

Permalink
feat: add copy all audit permalinks button (#63)
Browse files Browse the repository at this point in the history
  • Loading branch information
fcasal authored Oct 28, 2024
1 parent 4386cea commit 6a66dcf
Show file tree
Hide file tree
Showing 2 changed files with 46 additions and 2 deletions.
20 changes: 18 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -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)"
Expand Down Expand Up @@ -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"
},
{
Expand Down Expand Up @@ -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)"
}
}
},
Expand Down Expand Up @@ -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",
Expand Down
28 changes: 28 additions & 0 deletions src/codeMarker.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1771,6 +1771,10 @@ export class CodeMarker implements vscode.TreeDataProvider<TreeEntry> {
this.copyEntryPermalink(entry);
});

vscode.commands.registerCommand("weAudit.copyEntryPermalinks", (entry: FullEntry) => {
this.copyEntryPermalinks(entry);
});

vscode.commands.registerTextEditorCommand("weAudit.copySelectedCodePermalink", () => {
this.copySelectedCodePermalink(Repository.Audit);
});
Expand Down Expand Up @@ -2558,6 +2562,30 @@ export class CodeMarker implements vscode.TreeDataProvider<TreeEntry> {
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<void> {
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
Expand Down

0 comments on commit 6a66dcf

Please sign in to comment.