You signed in with another tab or window.Reload to refresh your session.You signed out in another tab or window.Reload to refresh your session.You switched accounts on another tab or window.Reload to refresh your session.Dismiss alert
This will let you identify and transform various git hosts URLs betweenprotocols. It also can tell you what the URL is for the raw path forparticular file for direct access without git.
If the URL can't be matched with a git host,null will be returned. Wecan match git, ssh and https urls. Additionally, we can match ssh connectstrings (git@github.com:npm/hosted-git-info) and shortcuts (eg,github:npm/hosted-git-info). Github specifically, is detected in the caseof a third, unprefixed, form:npm/hosted-git-info.
If it does match, the returned object has properties of:
info.type -- The short name of the service
info.domain -- The domain for git protocol use
info.user -- The name of the user/org on the git host
info.project -- The name of the project on the git host
Version Contract
The major version will be bumped any time…
The constructor stops accepting URLs that it previously accepted.
A method is removed.
A method can no longer accept the number and type of arguments it previously accepted.
A method can return a different type than it currently returns.
Implications:
I do not consider the specific format of the urls returned from, say.https() to be a part of the contract. The contract is that it willreturn a string that can be used to fetch the repo via HTTPS. But whatthat string looks like, specifically, can change.
Dropping support for a hosted git provider would constitute a breakingchange.
Usage
var info = hostedGitInfo.fromUrl(gitSpecifier[, options])
gitSpecifer is a URL of a git repository or a SCP-style specifier of one.
options is an optional object. It can have the following properties:
noCommittish — If true then committishes won't be included in generated URLs.
noGitPlus — If true thengit+ won't be prefixed on URLs.
Methods
All of the methods take the same options as thefromUrl factory. Optionsprovided to a method override those provided to the constructor.
info.file(path, opts)
Given the path of a file relative to the repository, returns a URL fordirectly fetching it from the githost. If no committish was set thenmaster will be used as the default.
For examplehostedGitInfo.fromUrl("git@github.com:npm/hosted-git-info.git#v1.0.0").file("package.json")would returnhttps://raw.githubusercontent.com/npm/hosted-git-info/v1.0.0/package.json
Returns the default output type. The default output type is based on thestring you passed in to be parsed
info.toString(opts)
Uses the getDefaultRepresentation to call one of the other methods to get a URL forthis resource. As suchhostedGitInfo.fromUrl(url).toString() will giveyou a normalized version of the URL that still uses the same protocol.
Shortcuts will still be returned as shortcuts, but the special case githubform oforg/project will be normalized togithub:org/project.
SSH connect strings will be normalized intogit+ssh URLs.
Supported hosts
Currently this supports Github, Bitbucket and Gitlab. Pull requests foradditional hosts welcome.
About
Provides metadata and conversions from repository urls for Github, Bitbucket and Gitlab