-
-
Notifications
You must be signed in to change notification settings - Fork 21
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 support for base URL #24
Conversation
lib/util/resolve-base-url.js
Outdated
var parsed = url.parse(repository) | ||
|
||
if (parsed.host) { | ||
return 'https://' + parsed.host + '/' |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I can't use parsed.protocol
as it resolves to original protocol (e.g. git://
), which is not what we need. But then if someone hosts GHE on http://
this will lead to errors :(
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Are they always https?
Does d = new URL(url || 'https://github.com'); d.protocol = 'https'; return d.hostname
work?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'm afraid it has to be hardcoded in this fashion.
The WHATWG URL Standard considers a handful of URL protocol schemes to be special in terms of how they are parsed and serialized. When a URL is parsed using one of these special protocols, the
url.protocol
property may be changed to another special protocol but cannot be changed to a non-special protocol, and vice versa.Likewise, changing from a non-special protocol to a special protocol is also not permitted:
const u = new URL('fish://example.org'); u.protocol = 'http'; console.log(u.href); // fish://example.org
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
lol. That’s...
Can we work around it by doing something like: new URL('http:' + url.href.slice(url.href.indexOf(':')))
?
I love url, but it’s a bit of a downside that it’s deprecated and the suggestion is to use URL
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Switched it back to concatenation. Alternatively I can use:
return new URL('/' + repo.user + '/' + repo.project, base) + '/'
which would be more foolproof, in case someone provide baseUrl with trailing slash /
, leading to https://github.com//such/urls
This comment has been minimized.
This comment has been minimized.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Nice, sorry for the wait!
Some suggestions inline, and could use docs!
@@ -39,23 +40,30 @@ var repositoryExpression = new RegExp( | |||
function github(options) { | |||
var settings = options || {} | |||
var repository = settings.repository | |||
var baseUrl = settings.baseUrl |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
how about just base
? (and githubBase
too?)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Personally I think "base" is too generic, when providing plugin options. But if you insist I'm happy to change it.
lib/util/resolve-base-url.js
Outdated
var parsed = url.parse(repository) | ||
|
||
if (parsed.host) { | ||
return 'https://' + parsed.host + '/' |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Are they always https?
Does d = new URL(url || 'https://github.com'); d.protocol = 'https'; return d.hostname
work?
Hey @wooorm! Sorry for wait, I was on holiday :). I switch to the modern API and removed unnecessary fixtures. Take a look, while I'll work on documentation. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Fancy! A couple code style suggestions.
And hope you had a lovely holiday!
@@ -2,18 +2,18 @@ | |||
|
|||
module.exports = gh | |||
|
|||
const {URL} = require('url') |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
drop this one, it isn’t really needed in this file
if (project) { | ||
repo = {user: repo, project: project} | ||
} | ||
|
||
if (repo) { | ||
base += repo.user + '/' + repo.project + '/' | ||
return new URL('/' + repo.user + '/' + repo.project, base) + '/' |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
return new URL('/' + repo.user + '/' + repo.project, base) + '/' | |
return base + '/' + repo.user + '/' + repo.project + '/ |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
You sure? Have you seen my comment about trailing slashes?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Sorry I missed this one!
I dunno, I feel that that’s a failure by users and should result in an error / that output?
Co-authored-by: Titus <tituswormer@gmail.com>
Oh gosh, I forgot about this WIP issue/PR when I rewrote the project. 😓 What do you think about my last comment? |
Oh snap! I forgot about this as well :D. I'll try to find some time and open the new PR. It would be easier than resolving conflicts here. |
The codebase is significantly easier now, and the changes here are roughly good to go, so applying them to the new code should be possible and easier than merge conflicts! I don’t have access to enterprise so I don‘t feel comfortable doing most of the work, but I can help you! |
Solves #23
I used 2
url
functions, both added in Node.js v0.1.25url.resolve
- safer way to resolve base + pathurl.parse
- see if hostname is present in whateverrepostiory
is set toI had to update all the test cases that mentioned
https://codeload.github.com/
, by the new rules they resolve tohttps://codeload.github.com/