Skip to content

Commit

Permalink
Support gitlab remotes when opening issues (#35)
Browse files Browse the repository at this point in the history
* feat: support opening gitlab issues

* better: deduplicate target paths on remote issue template
  • Loading branch information
fcasal authored May 13, 2024
1 parent c7f0ea8 commit 892fdbd
Show file tree
Hide file tree
Showing 3 changed files with 34 additions and 13 deletions.
12 changes: 6 additions & 6 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@

WeAudit is an essential extension in the arsenal of any code auditor.

With weAudit, you can bookmark regions of code to highlight issues, add notes, mark files as reviewed, and collaborate with your fellow auditors. Enhance your reporting workflow by writing the findings directly in VSCode, creating prefilled Github issues, and copying links. For the stats lovers, analyze your audit progress with the daily log, showing the number of files and LOC audited per day.
With weAudit, you can bookmark regions of code to highlight issues, add notes, mark files as reviewed, and collaborate with your fellow auditors. Enhance your reporting workflow by writing the findings directly in VSCode, creating prefilled GitHub issues, and copying links. For the stats lovers, analyze your audit progress with the daily log, showing the number of files and LOC audited per day.

![Screenshot](media/readme/screenshot.png)

Expand All @@ -22,10 +22,10 @@ See the [Build and install](#build-and-install) section below for how to build a
- [**Audited Files**](#audited-files) - Mark an entire file as reviewed.
- [**Partially Audited Files**](#partially-audited-files) - Mark a region of code as reviewed.
- [**Detailed Findings**](#detailed-findings) - Fill detailed information about a finding.
- [**Github Issues**](#github-issues) - Create formatted Github issues with the Detailed Findings information.
- [**GitHub/Gitlab Issues**](#github-issues) - Create formatted GitHub or Gitlab issues with the Detailed Findings information.
- [**Multi-region Findings**](#multi-region-findings) - Group multiple locations under a single finding.
- [**Resolve and Restore**](#resolve-and-restore) - Resolved findings will not be highlighted in the editor but are still visible in the sidebar.
- [**Copy Permalinks**](#copy-permalinks) - Copy Github permalinks to findings, or to a selected code region.
- [**Copy Permalinks**](#copy-permalinks) - Copy GitHub permalinks to findings, or to a selected code region.
- [**Daily Log**](#daily-log) - View a daily log of all the marked files and LOC per day.
- [**View Mode**](#view-mode) - View findings in a list, or grouped by filename.
- [**Multiple Users**](#multiple-users) - Findings can be viewed from multiple different users.
Expand Down Expand Up @@ -79,11 +79,11 @@ You can fill detailed information about a finding by clicking on it in the _List

![Finding Details](media/readme/finding_details.png)

### Github Issues
### GitHub/Gitlab Issues

You can create a Github issue with the detailed findings information by clicking on the corresponding `Open Github Issue` button in the _List of Findings_ panel. A browser window in will open prompting you to open the issue with the prefilled information from the _Finding Details_ panel.
You can create a GitHub/Gitlab issue with the detailed findings information by clicking on the corresponding `Open Remote Issue` button in the _List of Findings_ panel. A browser window in will open prompting you to open the issue with the prefilled information from the _Finding Details_ panel.

![Open Github Issue](media/readme/gifs/create_gh_issue.gif)
![Open Remote Issue](media/readme/gifs/create_gh_issue.gif)

### Multi-region Findings

Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,7 @@
"commands": [
{
"command": "weAudit.openGithubIssue",
"title": "Open Github Issue",
"title": "Open Remote Issue",
"icon": "$(github)"
},
{
Expand Down
33 changes: 27 additions & 6 deletions src/codeMarker.ts
Original file line number Diff line number Diff line change
Expand Up @@ -222,7 +222,7 @@ export class CodeMarker implements vscode.TreeDataProvider<TreeEntry> {
try {
location.path = this.relativizePath(location.path);
} catch (error) {
vscode.window.showErrorMessage(`Failed to open GitHub issue. The file ${location.path} is not in the workspace (${this.workspacePath}).`);
vscode.window.showErrorMessage(`Failed to open remote issue. The file ${location.path} is not in the workspace (${this.workspacePath}).`);
return;
}
}
Expand Down Expand Up @@ -1097,9 +1097,24 @@ export class CodeMarker implements vscode.TreeDataProvider<TreeEntry> {

const encodedIssueBody = encodeURIComponent(issueBodyText);

const issueUrl = this.gitRemote + "/issues/new?";
const issueUrlWithBody = `${issueUrl}title=${title}&body=${encodedIssueBody}`;
const isGitHubRemote = this.gitRemote.startsWith("https://github.com/") || this.gitRemote.startsWith("github.com/");

let issueUrl: string;
let issueUrlWithBody: string;

if (isGitHubRemote) {
issueUrl = this.gitRemote + "/issues/new?";
issueUrlWithBody = `${issueUrl}title=${title}&body=${encodedIssueBody}`;
} else {
// If the remote is not GitHub, we assume it is GitLab
// gitlab url arguments spec
// https://docs.gitlab.com/ee/user/project/issues/create_issues.html#using-a-url-with-prefilled-values
issueUrl = this.gitRemote + "/-/issues/new?";
issueUrlWithBody = `${issueUrl}issue[title]=${title}&issue[description]=${encodedIssueBody}`;
}

// GitHub's URL max size is about 8000 characters
// Gitlab seems to allow more but we'll use the same limit for now
if (issueUrlWithBody.length < 8000) {
// hack to get around the double encoding of openExternal.
// We call it with a string even though it's expecting a Uri
Expand All @@ -1118,10 +1133,10 @@ export class CodeMarker implements vscode.TreeDataProvider<TreeEntry> {
return;
}
vscode.env.clipboard.writeText(issueBodyText);
const pasteHere = encodeURIComponent("[Paste the issue body here]");
const pasteHereMessage = encodeURIComponent("[Paste the issue body here]");
// eslint-disable-next-line @typescript-eslint/ban-ts-comment
// @ts-ignore
vscode.env.openExternal(`${issueUrl}title=${title}&body=${pasteHere}`);
vscode.env.openExternal(`${issueUrl}title=${title}&body=${pasteHereMessage}`);
});
}

Expand Down Expand Up @@ -1149,7 +1164,13 @@ export class CodeMarker implements vscode.TreeDataProvider<TreeEntry> {
}
}

const target = entry.locations.map((location) => location.path).join(", ");
// deduplicate the target paths
const locationSet: Set<string> = new Set();
for (const location of entry.locations) {
locationSet.add(location.path);
}

const target = Array.from(locationSet).join(", ");
const permalinks = auditPermalinks.join("\n");
const clientPermalinkString = clientPermalinks.join("\n");

Expand Down

0 comments on commit 892fdbd

Please sign in to comment.