Skip to content

Commit

Permalink
Merge pull request #1 from trailofbits/ci_fixes
Browse files Browse the repository at this point in the history
CI update and fix URL too large
  • Loading branch information
fcasal authored Mar 15, 2024
2 parents 513e1d2 + 5347fe1 commit d9bc7c9
Show file tree
Hide file tree
Showing 5 changed files with 59 additions and 32 deletions.
7 changes: 2 additions & 5 deletions .github/workflows/lint_and_format.yml
Original file line number Diff line number Diff line change
Expand Up @@ -9,17 +9,14 @@ jobs:
permissions:
# required for all workflows
security-events: write
# only required for workflows in private repositories
actions: read
contents: read
steps:
- uses: actions/checkout@v4
- name: Install modules
run: npm install
- name: Run ESLint
run: npx eslint --color -c .eslintrc.json .
- name: Run prettier
run: npx prettier --check .
- name: Run ESLint
run: npx eslint --color -c .eslintrc.json .
- name: SARIF
run: npx eslint -c .eslintrc.json -f @microsoft/eslint-formatter-sarif -o eslint.sarif . || true
- name: Upload SARIF file
Expand Down
3 changes: 2 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -4,4 +4,5 @@ node_modules
.vscode-test/
.vscode/
*.mov
*.vsix
*.vsix
*.sarif*
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ The highlighted color can be customized in the [settings](#settings).

You can fill detailed information about a finding by clicking on it in the _List of Findings_ view in the sidebar. The respective _Finding Details_ panel will open, where you can fill the information.

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

### Github Issues

Expand Down
6 changes: 3 additions & 3 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -111,7 +111,7 @@
"icon": "$(pass)"
},
{
"command": "weAudit.editEntry",
"command": "weAudit.editEntryTitle",
"title": "Edit Finding Title",
"icon": "$(edit)"
},
Expand Down Expand Up @@ -230,7 +230,7 @@
"menus": {
"commandPalette": [
{
"command": "weAudit.editEntry",
"command": "weAudit.editEntryTitle",
"when": "false"
},
{
Expand Down Expand Up @@ -303,7 +303,7 @@
],
"view/item/context": [
{
"command": "weAudit.editEntry",
"command": "weAudit.editEntryTitle",
"when": "view == codeMarker && viewItem != pathOrganizer && viewItem != additionalLocation",
"group": "inline@1"
},
Expand Down
73 changes: 51 additions & 22 deletions src/codeMarker.ts
Original file line number Diff line number Diff line change
Expand Up @@ -93,7 +93,7 @@ export class CodeMarker implements vscode.TreeDataProvider<TreeEntry> {
this.markedFilesDayLog = new Map<string, string[]>();
this.loadDayLogFromFile();

this.treeViewMode = 1;
this.treeViewMode = TreeViewMode.List;
this.loadTreeViewModeConfiguration();

this.username = userInfo().username;
Expand Down Expand Up @@ -138,8 +138,8 @@ export class CodeMarker implements vscode.TreeDataProvider<TreeEntry> {
this.deleteFinding(node);
});

vscode.commands.registerCommand("weAudit.editEntry", (node: Entry) => {
this.editEntryDescription(node);
vscode.commands.registerCommand("weAudit.editEntryTitle", (node: Entry) => {
this.editEntryTitle(node);
});

vscode.commands.registerCommand("weAudit.editLocationEntry", (node: LocationEntry) => {
Expand All @@ -166,7 +166,7 @@ export class CodeMarker implements vscode.TreeDataProvider<TreeEntry> {
const entry = this.getLocationUnderCursor();
if (entry) {
const toEdit = isLocationEntry(entry) ? entry.parentEntry : entry;
this.editEntryDescription(toEdit);
this.editEntryTitle(toEdit);
}
});

Expand Down Expand Up @@ -206,17 +206,19 @@ export class CodeMarker implements vscode.TreeDataProvider<TreeEntry> {
this.setupRepositories();
});

vscode.commands.registerCommand("weAudit.openGithubIssue", (entry: Entry) => {
vscode.commands.registerCommand("weAudit.openGithubIssue", (entry: Entry | LocationEntry) => {
// transform absolute paths to relative paths to the workspace path
for (const location of entry.locations) {
const actualEntry: Entry = isLocationEntry(entry) ? entry.parentEntry : entry;

for (const location of actualEntry.locations) {
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}).`);
return;
}
}
this.openGithubIssue(entry);
this.openGithubIssue(actualEntry);
});

vscode.commands.registerCommand("weAudit.loadSavedFindings", (filename: string, username: string) => {
Expand Down Expand Up @@ -453,6 +455,7 @@ export class CodeMarker implements vscode.TreeDataProvider<TreeEntry> {
entry.label = value;
this.refreshTree();
this.refreshAndDecorateEntry(entry);
treeView.reveal(entry);
break;
}
}
Expand Down Expand Up @@ -717,7 +720,7 @@ export class CodeMarker implements vscode.TreeDataProvider<TreeEntry> {
* Edit the label of a marked code region
* @param entry The entry to edit
*/
async editEntryDescription(entry: Entry): Promise<void> {
async editEntryTitle(entry: Entry): Promise<void> {
const entryTypeLabel = entry.entryType === EntryType.Finding ? "finding" : "note";
const label = await vscode.window.showInputBox({
title: `Edit ${entryTypeLabel} title`,
Expand All @@ -728,7 +731,7 @@ export class CodeMarker implements vscode.TreeDataProvider<TreeEntry> {
return;
}
entry.label = label;

treeView.reveal(entry);
this.refreshTree();
this.decorate();
this.updateSavedData(entry.author);
Expand Down Expand Up @@ -849,7 +852,6 @@ export class CodeMarker implements vscode.TreeDataProvider<TreeEntry> {
}
this.clientRemote = clientRemote;
this.persistClientRemote();
vscode.commands.executeCommand("weAudit.setGitConfigView", this.clientRemote, this.gitRemote, this.gitSha);
}

/**
Expand All @@ -862,7 +864,6 @@ export class CodeMarker implements vscode.TreeDataProvider<TreeEntry> {
}
this.gitRemote = auditRemote;
this.persistAuditRemote();
vscode.commands.executeCommand("weAudit.setGitConfigView", this.clientRemote, this.gitRemote, this.gitSha);
}

/**
Expand All @@ -875,7 +876,6 @@ export class CodeMarker implements vscode.TreeDataProvider<TreeEntry> {
}
this.gitSha = gitSha;
this.persistGitHash();
vscode.commands.executeCommand("weAudit.setGitConfigView", this.clientRemote, this.gitRemote, this.gitSha);
}

/**
Expand Down Expand Up @@ -990,12 +990,30 @@ export class CodeMarker implements vscode.TreeDataProvider<TreeEntry> {

const issueUrl = this.gitRemote + "/issues/new?";
const issueUrlWithBody = `${issueUrl}title=${title}&body=${issueBody}`;
// hack to get around the double encoding of openExternal.
// We call it with a string even though it's expecting a Uri
// https://github.com/microsoft/vscode/issues/85930
// eslint-disable-next-line @typescript-eslint/ban-ts-comment
// @ts-ignore
vscode.env.openExternal(issueUrlWithBody);
// GitHub's URL max size is about 8000 characters
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
// https://github.com/microsoft/vscode/issues/85930
// eslint-disable-next-line @typescript-eslint/ban-ts-comment
// @ts-ignore
vscode.env.openExternal(issueUrlWithBody);
return;
}

// Prompt the user to copy the issue body and open the empty issue page
vscode.window
.showErrorMessage("The issue body is too long to open automatically in the URL", "Copy issue to clipboard and open browser window")
.then((action) => {
if (action === undefined) {
return;
}
vscode.env.clipboard.writeText(issueBodyText);
const pasteHere = 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}`);
});
}

/**
Expand Down Expand Up @@ -1320,8 +1338,8 @@ export class CodeMarker implements vscode.TreeDataProvider<TreeEntry> {
// if we found an entry, edit the description
if (intersectedIdx !== -1) {
const entry = this.treeEntries[intersectedIdx];
// editEntryDescription calls updateSavedData so we don't need to call it here
this.editEntryDescription(entry);
// editEntryTitle calls updateSavedData so we don't need to call it here
this.editEntryTitle(entry);
} else {
// otherwise, add it to the tree entries
// create title depending on the entry type
Expand Down Expand Up @@ -1567,6 +1585,7 @@ export class CodeMarker implements vscode.TreeDataProvider<TreeEntry> {
* Saves the client's remote repository to the current user's file
*/
persistClientRemote(): void {
vscode.commands.executeCommand("weAudit.setGitConfigView", this.clientRemote, this.gitRemote, this.gitSha);
const vscodeFolder = path.join(this.workspacePath, ".vscode");
// create .vscode folder if it doesn't exist
if (!fs.existsSync(vscodeFolder)) {
Expand All @@ -1592,6 +1611,7 @@ export class CodeMarker implements vscode.TreeDataProvider<TreeEntry> {
* Saves the audit remote repository to the current user's file
*/
persistAuditRemote(): void {
vscode.commands.executeCommand("weAudit.setGitConfigView", this.clientRemote, this.gitRemote, this.gitSha);
const vscodeFolder = path.join(this.workspacePath, ".vscode");
// create .vscode folder if it doesn't exist
if (!fs.existsSync(vscodeFolder)) {
Expand All @@ -1617,6 +1637,7 @@ export class CodeMarker implements vscode.TreeDataProvider<TreeEntry> {
* Saves the relevant git hash to the current user's file
*/
persistGitHash(): void {
vscode.commands.executeCommand("weAudit.setGitConfigView", this.clientRemote, this.gitRemote, this.gitSha);
const vscodeFolder = path.join(this.workspacePath, ".vscode");
// create .vscode folder if it doesn't exist
if (!fs.existsSync(vscodeFolder)) {
Expand Down Expand Up @@ -2191,10 +2212,18 @@ export class AuditMarker {
/**
* Reveal the entry under the cursor, in the treeView.
*/
private revealEntryUnderCursor(): void {
private async revealEntryUnderCursor(): Promise<void> {
const entry = treeDataProvider.getLocationUnderCursor();
if (entry !== undefined) {
treeView.reveal(entry);
try {
await treeView.reveal(entry);
} catch (error) {
const typedError = error as Error;
if (typedError.message.startsWith("TreeError")) {
return;
}
throw error;
}
}
}

Expand Down

0 comments on commit d9bc7c9

Please sign in to comment.