Detalhes do pacote

@zkochan/hosted-git-info

npm462ISC4.0.2

Provides metadata and conversions from repository urls for GitHub, Bitbucket and GitLab

git, github, bitbucket, gitlab

readme (leia-me)

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

var hostedGitInfo = require("hosted-git-info")
var 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

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 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 master 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/REAMDE.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, Bitbucket and GitLab. Pull requests for additional hosts welcome.

changelog (log de mudanças)

Change Log

All notable changes to this project will be documented in this file. See standard-version for commit guidelines.

4.0.0 (2021-03-09)

Features

  • rewrite the entire module: all internals have been rewritten to maintain a similar contract but to remove excessive use of regular expressions, unnecessary loops, the custom string templating engine, and various other bits of complexity (c218b9)

BREAKING CHANGES

  • extending with custom providers has changed (c218b9)

3.0.8 (2021-01-28)

Bug Fixes

  • simplify the regular expression for shortcut matching (bede0dc), closes #76

3.0.7 (2020-10-15)

Bug Fixes

  • correctly filter out urls for tarballs in gitlab (eb5bd5a), closes #69

3.0.6 (2020-10-12)

Bug Fixes

  • support to github gist legacy hash length (c067102), closes #68

3.0.5 (2020-07-11)

3.0.4 (2020-02-26)

Bug Fixes

  • Do not pass scp-style URLs to the WhatWG url.URL (0835306), closes #60 #63

3.0.3 (2020-02-25)

3.0.2 (2019-10-08)

Bug Fixes

  • do not encodeURIComponent the domain (3e5fbec), closes #53

3.0.1 (2019-10-07)

Bug Fixes

  • update pathmatch for gitlab (e3e3054), closes #52
  • updated pathmatch for gitlab (fa87af7)

3.0.0 (2019-08-12)

Bug Fixes

  • cache: Switch to lru-cache to save ourselves from unlimited memory consumption (37c2891), closes #38

BREAKING CHANGES

  • cache: Drop support for node 0.x

2.8.3 (2019-08-12)

2.8.2 (2019-08-05)

Bug Fixes

  • http protocol use sshurl by default (3b1d629), closes #48

2.8.1 (2019-08-05)

Bug Fixes

  • ignore noCommittish on tarball url generation (5d4a8d7)
  • use gist tarball url that works for anonymous gists (1692435)

2.8.0 (2019-08-05)

Bug Fixes

  • Allow slashes in gitlab project section (bbcf7b2), closes #46 #43
  • git-host: disallow URI-encoded slash (%2F) in path (3776fa5), closes #44
  • gitlab: Do not URL encode slashes in project name for GitLab https URL (cbf04f9), closes #47
  • do not allow invalid gist urls (d5cf830)
  • cache: Switch to lru-cache to save ourselves from unlimited memory consumption (e518222), closes #38

Features

  • give these objects a name (60abaea)

2.7.1 (2018-07-07)

Bug Fixes

  • index: Guard against non-string types (5bc580d)
  • parse: Crash on strings that parse to having no host (c931482), closes #35

2.7.0 (2018-07-06)

Bug Fixes

  • github tarball: update github tarballtemplate (6efd582), closes #34
  • gitlab docs: switched to lowercase anchors for readmes (701bcd1)

Features

  • all: Support www. prefixes on hostnames (3349575), closes #32

2.6.1 (2018-06-25)

Bug Fixes

  • Revert: "compat: remove Object.assign fallback (#25)" (cce5a62)
  • Revert: "git-host: fix forgotten extend()" (a815ec9)

2.6.0 (2018-03-07)

Bug Fixes

  • compat: remove Object.assign fallback (#25) (627ab55)
  • git-host: fix forgotten extend() (eba1f7b)

Features

  • browse: fragment support for browse() (#28) (cd5e5bb)