hosted-git-info
Provides metadata and conversions from repository urls for Github, Bitbucket and Gitlab
Last updated 5 years ago by darcyclarke .
ISC · Repository · Bugs · Original npm · Tarball · package.json
$ gnpm install hosted-git-info 
SYNC missed versions from official npm registry.

hosted-git-info

This will let you identify and transform various git hosts URLs between protocols. It also can tell you what the URL is for the raw path for particular file for direct access without git.

Example

const hostedGitInfo = require("hosted-git-info")
const info = hostedGitInfo.fromUrl("git@github.com:npm/hosted-git-info.git", opts)
/* info looks like:
{
  type: "github",
  domain: "github.com",
  user: "npm",
  project: "hosted-git-info"
}
*/

If the URL can't be matched with a git host, null will be returned. We can match git, ssh and https urls. Additionally, we can match ssh connect strings (git@github.com:npm/hosted-git-info) and shortcuts (eg, github:npm/hosted-git-info). GitHub specifically, is detected in the case of 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 will return a string that can be used to fetch the repo via HTTPS. But what that string looks like, specifically, can change.
  • Dropping support for a hosted git provider would constitute a breaking change.

Usage

const 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 then git+ won't be prefixed on URLs.

Methods

All of the methods take the same options as the fromUrl factory. Options provided 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 for directly fetching it from the githost. If no committish was set then HEAD will be used as the default.

For example hostedGitInfo.fromUrl("git@github.com:npm/hosted-git-info.git#v1.0.0").file("package.json") would return https://raw.githubusercontent.com/npm/hosted-git-info/v1.0.0/package.json

  • info.shortcut(opts)

eg, github:npm/hosted-git-info

  • info.browse(path, fragment, opts)

eg, https://github.com/npm/hosted-git-info/tree/v1.2.0, https://github.com/npm/hosted-git-info/tree/v1.2.0/package.json, https://github.com/npm/hosted-git-info/tree/v1.2.0/README.md#supported-hosts

  • info.bugs(opts)

eg, https://github.com/npm/hosted-git-info/issues

  • info.docs(opts)

eg, https://github.com/npm/hosted-git-info/tree/v1.2.0#readme

  • info.https(opts)

eg, git+https://github.com/npm/hosted-git-info.git

  • info.sshurl(opts)

eg, git+ssh://git@github.com/npm/hosted-git-info.git

  • info.ssh(opts)

eg, git@github.com:npm/hosted-git-info.git

  • info.path(opts)

eg, npm/hosted-git-info

  • info.tarball(opts)

eg, https://github.com/npm/hosted-git-info/archive/v1.2.0.tar.gz

  • info.getDefaultRepresentation()

Returns the default output type. The default output type is based on the string you passed in to be parsed

  • info.toString(opts)

Uses the getDefaultRepresentation to call one of the other methods to get a URL for this resource. As such hostedGitInfo.fromUrl(url).toString() will give you a normalized version of the URL that still uses the same protocol.

Shortcuts will still be returned as shortcuts, but the special case github form of org/project will be normalized to github:org/project.

SSH connect strings will be normalized into git+ssh URLs.

Supported hosts

Currently this supports GitHub (including Gists), Bitbucket, GitLab and Sourcehut. Pull requests for additional hosts welcome.

Current Tags

  • 2.8.9                                ...           ancient-legacy-fixes (4 years ago)
  • 7.0.1                                ...           latest (a year ago)

63 Versions

  • 7.0.1                                ...           a year ago
  • 7.0.0                                ...           a year ago
  • 6.1.1                                ...           2 years ago
  • 5.2.1                                ...           2 years ago
  • 5.2.0                                ...           2 years ago
  • 6.1.0                                ...           2 years ago
  • 6.0.0                                ...           2 years ago
  • 5.1.0                                ...           2 years ago
  • 5.0.0                                ...           3 years ago
  • 4.1.0                                ...           3 years ago
  • 2.8.9                                ...           4 years ago
  • 4.0.2                                ...           4 years ago
  • 4.0.1                                ...           4 years ago
  • 4.0.0                                ...           4 years ago
  • 3.0.8                                ...           4 years ago
  • 3.0.7                                ...           4 years ago
  • 3.0.6                                ...           4 years ago
  • 3.0.5                                ...           4 years ago
  • 2.8.8                                ...           5 years ago
  • 3.0.4                                ...           5 years ago
  • 2.8.7                                ...           5 years ago
  • 3.0.3                                ...           5 years ago
  • 2.8.6                                ...           5 years ago
  • 3.0.2                                ...           5 years ago
  • 3.0.1                                ...           5 years ago
  • 2.8.5                                ...           5 years ago
  • 2.8.4                                ...           5 years ago
  • 3.0.0                                ...           5 years ago
  • 2.8.3                                ...           5 years ago
  • 2.8.2                                ...           5 years ago
  • 2.8.1                                ...           5 years ago
  • 2.8.0                                ...           5 years ago
  • 2.7.1                                ...           6 years ago
  • 2.7.0                                ...           6 years ago
  • 2.6.1                                ...           6 years ago
  • 2.6.0                                ...           7 years ago
  • 2.5.0                                ...           7 years ago
  • 2.4.2                                ...           8 years ago
  • 2.4.1                                ...           8 years ago
  • 2.4.0                                ...           8 years ago
  • 2.3.1                                ...           8 years ago
  • 2.3.0                                ...           8 years ago
  • 2.2.0                                ...           8 years ago
  • 2.1.5                                ...           9 years ago
  • 2.1.4                                ...           10 years ago
  • 2.1.3                                ...           10 years ago
  • 2.1.2                                ...           10 years ago
  • 2.1.1                                ...           10 years ago
  • 2.1.0                                ...           10 years ago
  • 2.0.3                                ...           10 years ago
  • 2.0.2                                ...           10 years ago
  • 2.0.1                                ...           10 years ago
  • 2.0.0                                ...           10 years ago
  • 1.6.0                                ...           10 years ago
  • 1.5.3                                ...           10 years ago
  • 1.5.2                                ...           10 years ago
  • 1.5.1                                ...           10 years ago
  • 1.5.0                                ...           10 years ago
  • 1.4.0                                ...           10 years ago
  • 1.3.0                                ...           10 years ago
  • 1.2.0                                ...           10 years ago
  • 1.1.0                                ...           10 years ago
  • 1.0.0                                ...           10 years ago

Copyright 2013 - present © cnpmjs.org | Home |