Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add button to copy all audit permalinks #63

Merged
merged 1 commit into from
Oct 28, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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