Skip to content
New issue

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

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

Already on GitHub? # to your account

Sync with mainline #488

Open
wants to merge 8 commits into
base: main
Choose a base branch
from
Open
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
Binary file added ui/assets/images/favicon.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
1 change: 1 addition & 0 deletions ui/assets/index.tpl.html
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
<meta charset="utf-8">
<meta http-equiv="X-UA-Compatible" content="IE=Edge" />
<title>{{ .Title }}</title>
<link rel="shortcut icon" type="image/png" href="images/favicon.png" />
<link rel="stylesheet" href="css/octicons/octicons.css">
<link rel="stylesheet" href="css/hound.css">
<link rel="search" href="//{{ .Host }}/open_search.xml"
Expand Down
70 changes: 52 additions & 18 deletions ui/assets/js/common.js
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ export function UrlParts(repo, path, line, rev) {
path = path || '',
port = '',
filename = path.substring(path.lastIndexOf('/') + 1),
anchor = line ? ExpandVars(pattern.anchor, { line : line, filename : filename }) : '';
anchor = line ? ExpandVars(pattern.anchor, { line : line, filename : filename, repo : repo }) : '';

// Determine if the URL passed is a GitHub wiki
var wikiUrl = /\.wiki$/.exec(url);
Expand All @@ -28,26 +28,32 @@ export function UrlParts(repo, path, line, rev) {
anchor = '' // wikis do not support direct line linking
}

// Hacky solution to fix _some more_ of the 404's when using SSH style URLs.
// This works for both github style URLs (git@github.com:username/Foo.git) and
// bitbucket style URLs (ssh://hg@bitbucket.org/username/Foo).
// Check for ssh:// and hg:// protocol URLs
// match the protocol, optionally a basic auth indicator, a
// hostname, optionally a port, and then a path
var ssh_protocol = /^(git|hg|ssh):\/\/([^@\/]+@)?([^:\/]+)(:[0-9]+)?\/(.*)/.exec(url);

// Regex explained: Match either `git` or `hg` followed by an `@`.
// Next, slurp up the hostname by reading until either a `:` or `/` is found.
// If a port is specified, slurp that up too. Finally, grab the project and
// repo names.
var sshParts = /(git|hg)@(.*?)(:[0-9]+)?(:|\/)(.*)(\/)(.*)/.exec(url);
if (sshParts) {
hostname = '//' + sshParts[2]
project = sshParts[5]
repoName = sshParts[7]
// Port is omitted in most cases. Bitbucket Server is special:
// ssh://git@bitbucket.atlassian.com:7999/ATLASSIAN/jira.git
if(sshParts[3]){
port = sshParts[3]
//// Begin EasyPost edit: support phab links
{
//
// Regex explained: Match either `git` or `hg` followed by an `@`.
// Next, slurp up the hostname by reading until either a `:` or `/` is found.
// If a port is specified, slurp that up too. Finally, grab the project and
// repo names.
var sshParts = /(git|hg)@(.*?)(:[0-9]+)?(:|\/)(.*)(\/)(.*)/.exec(url);
if (sshParts) {
hostname = '//' + sshParts[2]
project = sshParts[5]
repoName = sshParts[7]
// Port is omitted in most cases. Bitbucket Server is special:
// ssh://git@bitbucket.atlassian.com:7999/ATLASSIAN/jira.git
if (sshParts[3]) {
port = sshParts[3]
}
url = hostname + port + '/' + project + '/' + repoName;
}
url = hostname + port + '/' + project + '/' + repoName;
}
//// End EasyPost edit

return {
url : url,
Expand All @@ -61,10 +67,38 @@ export function UrlParts(repo, path, line, rev) {
};
}

//// Begin EasyPost edit: support phab links
function toPhabURL(parts) {
// https://phab.easypo.net/source/easy_post/browse/master/app/helpers/sessions_helper.rb
const rev = parts['rev'],
path = parts['path'],
project = parts['project'],
repo = parts['repo'],
anchor = parts['anchor'];
const linenum = anchor ? anchor.replace(/^#L/, '') : undefined;
const branch = 'master';
// Caveat: Assumes "master" branch is primary/exists.
const result = ('https://phab.easypo.net/' + project
+ '/' + repo + '/browse/' + branch + '/' + path
+ ';' + rev);
if (linenum) {
return result + '$' + linenum;
}
return result;
}
//// End EasyPost edit

export function UrlToRepo(repo, path, line, rev) {
var urlParts = UrlParts(repo, path, line, rev),
pattern = repo['url-pattern']

//// Begin EasyPost edit: support phab links
const hostname = urlParts['hostname'] || '';
if (hostname.endsWith('phab.easypo.net')) {
return toPhabURL(urlParts);
}
//// End EasyPost edit

// I'm sure there is a nicer React/jsx way to do this:
return ExpandVars(pattern['base-url'], urlParts);
}