Thanks to visit codestin.com
Credit goes to github.com

Skip to content
Merged
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
13 changes: 11 additions & 2 deletions src/issues/util.ts
Original file line number Diff line number Diff line change
Expand Up @@ -492,10 +492,19 @@ export async function createGithubPermalink(
}
}
const pathSegment = uri.path.substring(repository.rootUri.path.length);
const rangeString = range ? `#L${range.start.line + 1}-L${range.end.line + 1}` : '';
const rangeString = () => {

@lgarron lgarron Sep 1, 2021

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This could theoretically be kept one one line, or shortened by conditionally updating a variable in the main block for createGithubPermalink(). However, I thought this would be the easiest to read, since it contains the calculation entirely inside a separate block without side effects.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

One line would look something like this:

const rangeString = range ? `#L${range.start.line + 1}${range.start.line === range.end.line ? '' : `-L${range.end.line + 1}`}` : '';

@lgarron lgarron Sep 1, 2021

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Putting it in the same in the main block for createGithubPermalink() could look like this:

let rangeString = '';
if (range) {
  rangeString = `#L${range.start.line + 1}`;
  if (range.start.line !== range.end.line) {
    rangeString += `-L${range.end.line + 1}`;
  }
}

if (!range) {
return '';
}
let hash = `#L${range.start.line + 1}`;
if (range.start.line !== range.end.line) {
hash += `-L${range.end.line + 1}`;
}
return hash;
};
return {
permalink: `https://github.com/${new Protocol(upstream.fetchUrl).nameWithOwner}/blob/${commitHash
}${pathSegment}${rangeString}`,
}${pathSegment}${rangeString()}`,
error: undefined,
originalFile: uri
};
Expand Down