UNPKG

2.73 kBMarkdownView Raw
1# hosted-git-info
2
3This will let you identify and transform various git hosts URLs between
4protocols. It also can tell you what the URL is for the raw path for
5particular file for direct access without git.
6
7## Usage
8
9```javascript
10var hostedGitInfo = require("hosted-git-info")
11var info = hostedGitInfo.fromUrl("git@github.com:npm/hosted-git-info.git")
12/* info looks like:
13{
14 type: "github",
15 domain: "github.com",
16 user: "npm",
17 project: "hosted-git-info"
18}
19*/
20```
21
22If the URL can't be matched with a git host, `null` will be returned. We
23can match git, ssh and https urls. Additionally, we can match ssh connect
24strings (`git@github.com:npm/hosted-git-info`) and shortcuts (eg,
25`github:npm/hosted-git-info`). Github specifically, is detected in the case
26of a third, unprefixed, form: `npm/hosted-git-info`.
27
28If it does match, the returned object has properties of:
29
30* info.type -- The short name of the service
31* info.domain -- The domain for git protocol use
32* info.user -- The name of the user/org on the git host
33* info.project -- The name of the project on the git host
34
35And methods of:
36
37* info.file(path)
38
39Given the path of a file relative to the repository, returns a URL for
40directly fetching it from the githost. If no committish was set then
41`master` will be used as the default.
42
43For example `hostedGitInfo.fromUrl("git@github.com:npm/hosted-git-info.git#v1.0.0").file("package.json")`
44would return `https://raw.githubusercontent.com/npm/hosted-git-info/v1.0.0/package.json`
45
46* info.shortcut()
47
48eg, `github:npm/hosted-git-info`
49
50* info.browse()
51
52eg, `https://github.com/npm/hosted-git-info/tree/v1.2.0`
53
54* info.bugs()
55
56eg, `https://github.com/npm/hosted-git-info/issues`
57
58* info.docs()
59
60eg, `https://github.com/npm/hosted-git-info/tree/v1.2.0#readme`
61
62* info.https()
63
64eg, `git+https://github.com/npm/hosted-git-info.git`
65
66* info.sshurl()
67
68eg, `git+ssh://git@github.com/npm/hosted-git-info.git`
69
70* info.ssh()
71
72eg, `git@github.com:npm/hosted-git-info.git`
73
74* info.path()
75
76eg, `npm/hosted-git-info`
77
78* info.getDefaultRepresentation()
79
80Returns the default output type. The default output type is based on the
81string you passed in to be parsed
82
83* info.toString()
84
85Uses the getDefaultRepresentation to call one of the other methods to get a URL for
86this resource. As such `hostedGitInfo.fromUrl(url).toString()` will give
87you a normalized version of the URL that still uses the same protocol.
88
89Shortcuts will still be returned as shortcuts, but the special case github
90form of `org/project` will be normalized to `github:org/project`.
91
92SSH connect strings will be normalized into `git+ssh` URLs.
93
94
95## Supported hosts
96
97Currently this supports Github, Bitbucket and Gitlab. Pull requests for
98additional hosts welcome.
99