pax_global_header 0000666 0000000 0000000 00000000064 15071511065 0014513 g ustar 00root root 0000000 0000000 52 comment=0c285cefba9f5ec7f0f024a49a98ba4082ca9422
hosted-git-info-9.0.2/ 0000775 0000000 0000000 00000000000 15071511065 0014523 5 ustar 00root root 0000000 0000000 hosted-git-info-9.0.2/.commitlintrc.js 0000664 0000000 0000000 00000000566 15071511065 0017652 0 ustar 00root root 0000000 0000000 /* This file is automatically added by @npmcli/template-oss. Do not edit. */
module.exports = {
extends: ['@commitlint/config-conventional'],
rules: {
'type-enum': [2, 'always', ['feat', 'fix', 'docs', 'deps', 'chore']],
'header-max-length': [2, 'always', 80],
'subject-case': [0],
'body-max-line-length': [0],
'footer-max-line-length': [0],
},
}
hosted-git-info-9.0.2/.eslintrc.js 0000664 0000000 0000000 00000000623 15071511065 0016763 0 ustar 00root root 0000000 0000000 /* This file is automatically added by @npmcli/template-oss. Do not edit. */
'use strict'
const { readdirSync: readdir } = require('fs')
const localConfigs = readdir(__dirname)
.filter((file) => file.startsWith('.eslintrc.local.'))
.map((file) => `./${file}`)
module.exports = {
root: true,
ignorePatterns: [
'tap-testdir*/',
],
extends: [
'@npmcli',
...localConfigs,
],
}
hosted-git-info-9.0.2/.github/ 0000775 0000000 0000000 00000000000 15071511065 0016063 5 ustar 00root root 0000000 0000000 hosted-git-info-9.0.2/.github/CODEOWNERS 0000664 0000000 0000000 00000000132 15071511065 0017452 0 ustar 00root root 0000000 0000000 # This file is automatically added by @npmcli/template-oss. Do not edit.
* @npm/cli-team
hosted-git-info-9.0.2/.github/ISSUE_TEMPLATE/ 0000775 0000000 0000000 00000000000 15071511065 0020246 5 ustar 00root root 0000000 0000000 hosted-git-info-9.0.2/.github/ISSUE_TEMPLATE/bug.yml 0000664 0000000 0000000 00000002655 15071511065 0021556 0 ustar 00root root 0000000 0000000 # This file is automatically added by @npmcli/template-oss. Do not edit.
name: Bug
description: File a bug/issue
title: "[BUG]
"
labels: [ Bug, Needs Triage ]
body:
- type: checkboxes
attributes:
label: Is there an existing issue for this?
description: Please [search here](./issues) to see if an issue already exists for your problem.
options:
- label: I have searched the existing issues
required: true
- type: textarea
attributes:
label: Current Behavior
description: A clear & concise description of what you're experiencing.
validations:
required: false
- type: textarea
attributes:
label: Expected Behavior
description: A clear & concise description of what you expected to happen.
validations:
required: false
- type: textarea
attributes:
label: Steps To Reproduce
description: Steps to reproduce the behavior.
value: |
1. In this environment...
2. With this config...
3. Run '...'
4. See error...
validations:
required: false
- type: textarea
attributes:
label: Environment
description: |
examples:
- **npm**: 7.6.3
- **Node**: 13.14.0
- **OS**: Ubuntu 20.04
- **platform**: Macbook Pro
value: |
- npm:
- Node:
- OS:
- platform:
validations:
required: false
hosted-git-info-9.0.2/.github/ISSUE_TEMPLATE/config.yml 0000664 0000000 0000000 00000000145 15071511065 0022236 0 ustar 00root root 0000000 0000000 # This file is automatically added by @npmcli/template-oss. Do not edit.
blank_issues_enabled: true
hosted-git-info-9.0.2/.github/actions/ 0000775 0000000 0000000 00000000000 15071511065 0017523 5 ustar 00root root 0000000 0000000 hosted-git-info-9.0.2/.github/actions/create-check/ 0000775 0000000 0000000 00000000000 15071511065 0022041 5 ustar 00root root 0000000 0000000 hosted-git-info-9.0.2/.github/actions/create-check/action.yml 0000664 0000000 0000000 00000002720 15071511065 0024042 0 ustar 00root root 0000000 0000000 # This file is automatically added by @npmcli/template-oss. Do not edit.
name: 'Create Check'
inputs:
name:
required: true
token:
required: true
sha:
required: true
check-name:
default: ''
outputs:
check-id:
value: ${{ steps.create-check.outputs.check_id }}
runs:
using: "composite"
steps:
- name: Get Workflow Job
uses: actions/github-script@v7
id: workflow
env:
JOB_NAME: "${{ inputs.name }}"
SHA: "${{ inputs.sha }}"
with:
result-encoding: string
script: |
const { repo: { owner, repo}, runId, serverUrl } = context
const { JOB_NAME, SHA } = process.env
const job = await github.rest.actions.listJobsForWorkflowRun({
owner,
repo,
run_id: runId,
per_page: 100
}).then(r => r.data.jobs.find(j => j.name.endsWith(JOB_NAME)))
return [
`This check is assosciated with ${serverUrl}/${owner}/${repo}/commit/${SHA}.`,
'Run logs:',
job?.html_url || `could not be found for a job ending with: "${JOB_NAME}"`,
].join(' ')
- name: Create Check
uses: LouisBrunner/checks-action@v1.6.0
id: create-check
with:
token: ${{ inputs.token }}
sha: ${{ inputs.sha }}
status: in_progress
name: ${{ inputs.check-name || inputs.name }}
output: |
{"summary":"${{ steps.workflow.outputs.result }}"}
hosted-git-info-9.0.2/.github/actions/install-latest-npm/ 0000775 0000000 0000000 00000000000 15071511065 0023253 5 ustar 00root root 0000000 0000000 hosted-git-info-9.0.2/.github/actions/install-latest-npm/action.yml 0000664 0000000 0000000 00000003406 15071511065 0025256 0 ustar 00root root 0000000 0000000 # This file is automatically added by @npmcli/template-oss. Do not edit.
name: 'Install Latest npm'
description: 'Install the latest version of npm compatible with the Node version'
inputs:
node:
description: 'Current Node version'
required: true
runs:
using: "composite"
steps:
# node 10/12/14 ship with npm@6, which is known to fail when updating itself in windows
- name: Update Windows npm
if: |
runner.os == 'Windows' && (
startsWith(inputs.node, 'v10.') ||
startsWith(inputs.node, 'v12.') ||
startsWith(inputs.node, 'v14.')
)
shell: cmd
run: |
curl -sO https://registry.npmjs.org/npm/-/npm-7.5.4.tgz
tar xf npm-7.5.4.tgz
cd package
node lib/npm.js install --no-fund --no-audit -g ..\npm-7.5.4.tgz
cd ..
rmdir /s /q package
- name: Install Latest npm
shell: bash
env:
NODE_VERSION: ${{ inputs.node }}
working-directory: ${{ runner.temp }}
run: |
MATCH=""
SPECS=("latest" "next-10" "next-9" "next-8" "next-7" "next-6")
echo "node@$NODE_VERSION"
for SPEC in ${SPECS[@]}; do
ENGINES=$(npm view npm@$SPEC --json | jq -r '.engines.node')
echo "Checking if node@$NODE_VERSION satisfies npm@$SPEC ($ENGINES)"
if npx semver -r "$ENGINES" "$NODE_VERSION" > /dev/null; then
MATCH=$SPEC
echo "Found compatible version: npm@$MATCH"
break
fi
done
if [ -z $MATCH ]; then
echo "Could not find a compatible version of npm for node@$NODE_VERSION"
exit 1
fi
npm i --prefer-online --no-fund --no-audit -g npm@$MATCH
- name: npm Version
shell: bash
run: npm -v
hosted-git-info-9.0.2/.github/dependabot.yml 0000664 0000000 0000000 00000000656 15071511065 0020722 0 ustar 00root root 0000000 0000000 # This file is automatically added by @npmcli/template-oss. Do not edit.
version: 2
updates:
- package-ecosystem: npm
directory: /
schedule:
interval: daily
target-branch: "main"
allow:
- dependency-type: direct
versioning-strategy: increase-if-necessary
commit-message:
prefix: deps
prefix-development: chore
labels:
- "Dependencies"
open-pull-requests-limit: 10
hosted-git-info-9.0.2/.github/matchers/ 0000775 0000000 0000000 00000000000 15071511065 0017671 5 ustar 00root root 0000000 0000000 hosted-git-info-9.0.2/.github/matchers/tap.json 0000664 0000000 0000000 00000001204 15071511065 0021345 0 ustar 00root root 0000000 0000000 {
"//@npmcli/template-oss": "This file is automatically added by @npmcli/template-oss. Do not edit.",
"problemMatcher": [
{
"owner": "tap",
"pattern": [
{
"regexp": "^\\s*not ok \\d+ - (.*)",
"message": 1
},
{
"regexp": "^\\s*---"
},
{
"regexp": "^\\s*at:"
},
{
"regexp": "^\\s*line:\\s*(\\d+)",
"line": 1
},
{
"regexp": "^\\s*column:\\s*(\\d+)",
"column": 1
},
{
"regexp": "^\\s*file:\\s*(.*)",
"file": 1
}
]
}
]
}
hosted-git-info-9.0.2/.github/settings.yml 0000664 0000000 0000000 00000001377 15071511065 0020456 0 ustar 00root root 0000000 0000000 # This file is automatically added by @npmcli/template-oss. Do not edit.
repository:
allow_merge_commit: false
allow_rebase_merge: true
allow_squash_merge: true
squash_merge_commit_title: PR_TITLE
squash_merge_commit_message: PR_BODY
delete_branch_on_merge: true
enable_automated_security_fixes: true
enable_vulnerability_alerts: true
branches:
- name: main
protection:
required_status_checks: null
enforce_admins: true
block_creations: true
required_pull_request_reviews:
required_approving_review_count: 1
require_code_owner_reviews: true
require_last_push_approval: true
dismiss_stale_reviews: true
restrictions:
apps: []
users: []
teams: [ "cli-team" ]
hosted-git-info-9.0.2/.github/workflows/ 0000775 0000000 0000000 00000000000 15071511065 0020120 5 ustar 00root root 0000000 0000000 hosted-git-info-9.0.2/.github/workflows/audit.yml 0000664 0000000 0000000 00000002275 15071511065 0021757 0 ustar 00root root 0000000 0000000 # This file is automatically added by @npmcli/template-oss. Do not edit.
name: Audit
on:
workflow_dispatch:
schedule:
# "At 08:00 UTC (01:00 PT) on Monday" https://crontab.guru/#0_8_*_*_1
- cron: "0 8 * * 1"
permissions:
contents: read
jobs:
audit:
name: Audit Dependencies
if: github.repository_owner == 'npm'
runs-on: ubuntu-latest
defaults:
run:
shell: bash
steps:
- name: Checkout
uses: actions/checkout@v4
- name: Setup Git User
run: |
git config --global user.email "npm-cli+bot@github.com"
git config --global user.name "npm CLI robot"
- name: Setup Node
uses: actions/setup-node@v4
id: node
with:
node-version: 22.x
check-latest: contains('22.x', '.x')
- name: Install Latest npm
uses: ./.github/actions/install-latest-npm
with:
node: ${{ steps.node.outputs.node-version }}
- name: Install Dependencies
run: npm i --ignore-scripts --no-audit --no-fund --package-lock
- name: Run Production Audit
run: npm audit --omit=dev
- name: Run Full Audit
run: npm audit --audit-level=none
hosted-git-info-9.0.2/.github/workflows/ci-release.yml 0000664 0000000 0000000 00000010707 15071511065 0022661 0 ustar 00root root 0000000 0000000 # This file is automatically added by @npmcli/template-oss. Do not edit.
name: CI - Release
on:
workflow_dispatch:
inputs:
ref:
required: true
type: string
default: main
workflow_call:
inputs:
ref:
required: true
type: string
check-sha:
required: true
type: string
permissions:
contents: read
checks: write
jobs:
lint-all:
name: Lint All
if: github.repository_owner == 'npm'
runs-on: ubuntu-latest
defaults:
run:
shell: bash
steps:
- name: Checkout
uses: actions/checkout@v4
with:
ref: ${{ inputs.ref }}
- name: Setup Git User
run: |
git config --global user.email "npm-cli+bot@github.com"
git config --global user.name "npm CLI robot"
- name: Create Check
id: create-check
if: ${{ inputs.check-sha }}
uses: ./.github/actions/create-check
with:
name: "Lint All"
token: ${{ secrets.GITHUB_TOKEN }}
sha: ${{ inputs.check-sha }}
- name: Setup Node
uses: actions/setup-node@v4
id: node
with:
node-version: 22.x
check-latest: contains('22.x', '.x')
- name: Install Latest npm
uses: ./.github/actions/install-latest-npm
with:
node: ${{ steps.node.outputs.node-version }}
- name: Install Dependencies
run: npm i --ignore-scripts --no-audit --no-fund
- name: Lint
run: npm run lint --ignore-scripts
- name: Post Lint
run: npm run postlint --ignore-scripts
- name: Conclude Check
uses: LouisBrunner/checks-action@v1.6.0
if: steps.create-check.outputs.check-id && always()
with:
token: ${{ secrets.GITHUB_TOKEN }}
conclusion: ${{ job.status }}
check_id: ${{ steps.create-check.outputs.check-id }}
test-all:
name: Test All - ${{ matrix.platform.name }} - ${{ matrix.node-version }}
if: github.repository_owner == 'npm'
strategy:
fail-fast: false
matrix:
platform:
- name: Linux
os: ubuntu-latest
shell: bash
- name: macOS
os: macos-latest
shell: bash
- name: macOS
os: macos-13
shell: bash
- name: Windows
os: windows-latest
shell: cmd
node-version:
- 20.17.0
- 20.x
- 22.9.0
- 22.x
exclude:
- platform: { name: macOS, os: macos-13, shell: bash }
node-version: 20.17.0
- platform: { name: macOS, os: macos-13, shell: bash }
node-version: 20.x
- platform: { name: macOS, os: macos-13, shell: bash }
node-version: 22.9.0
- platform: { name: macOS, os: macos-13, shell: bash }
node-version: 22.x
runs-on: ${{ matrix.platform.os }}
defaults:
run:
shell: ${{ matrix.platform.shell }}
steps:
- name: Checkout
uses: actions/checkout@v4
with:
ref: ${{ inputs.ref }}
- name: Setup Git User
run: |
git config --global user.email "npm-cli+bot@github.com"
git config --global user.name "npm CLI robot"
- name: Create Check
id: create-check
if: ${{ inputs.check-sha }}
uses: ./.github/actions/create-check
with:
name: "Test All - ${{ matrix.platform.name }} - ${{ matrix.node-version }}"
token: ${{ secrets.GITHUB_TOKEN }}
sha: ${{ inputs.check-sha }}
- name: Setup Node
uses: actions/setup-node@v4
id: node
with:
node-version: ${{ matrix.node-version }}
check-latest: contains(matrix.node-version, '.x')
- name: Install Latest npm
uses: ./.github/actions/install-latest-npm
with:
node: ${{ steps.node.outputs.node-version }}
- name: Install Dependencies
run: npm i --ignore-scripts --no-audit --no-fund
- name: Add Problem Matcher
run: echo "::add-matcher::.github/matchers/tap.json"
- name: Test
run: npm test --ignore-scripts
- name: Conclude Check
uses: LouisBrunner/checks-action@v1.6.0
if: steps.create-check.outputs.check-id && always()
with:
token: ${{ secrets.GITHUB_TOKEN }}
conclusion: ${{ job.status }}
check_id: ${{ steps.create-check.outputs.check-id }}
hosted-git-info-9.0.2/.github/workflows/ci.yml 0000664 0000000 0000000 00000006141 15071511065 0021240 0 ustar 00root root 0000000 0000000 # This file is automatically added by @npmcli/template-oss. Do not edit.
name: CI
on:
workflow_dispatch:
pull_request:
push:
branches:
- main
schedule:
# "At 09:00 UTC (02:00 PT) on Monday" https://crontab.guru/#0_9_*_*_1
- cron: "0 9 * * 1"
permissions:
contents: read
jobs:
lint:
name: Lint
if: github.repository_owner == 'npm'
runs-on: ubuntu-latest
defaults:
run:
shell: bash
steps:
- name: Checkout
uses: actions/checkout@v4
- name: Setup Git User
run: |
git config --global user.email "npm-cli+bot@github.com"
git config --global user.name "npm CLI robot"
- name: Setup Node
uses: actions/setup-node@v4
id: node
with:
node-version: 22.x
check-latest: contains('22.x', '.x')
- name: Install Latest npm
uses: ./.github/actions/install-latest-npm
with:
node: ${{ steps.node.outputs.node-version }}
- name: Install Dependencies
run: npm i --ignore-scripts --no-audit --no-fund
- name: Lint
run: npm run lint --ignore-scripts
- name: Post Lint
run: npm run postlint --ignore-scripts
test:
name: Test - ${{ matrix.platform.name }} - ${{ matrix.node-version }}
if: github.repository_owner == 'npm'
strategy:
fail-fast: false
matrix:
platform:
- name: Linux
os: ubuntu-latest
shell: bash
- name: macOS
os: macos-latest
shell: bash
- name: macOS
os: macos-13
shell: bash
- name: Windows
os: windows-latest
shell: cmd
node-version:
- 20.17.0
- 20.x
- 22.9.0
- 22.x
exclude:
- platform: { name: macOS, os: macos-13, shell: bash }
node-version: 20.17.0
- platform: { name: macOS, os: macos-13, shell: bash }
node-version: 20.x
- platform: { name: macOS, os: macos-13, shell: bash }
node-version: 22.9.0
- platform: { name: macOS, os: macos-13, shell: bash }
node-version: 22.x
runs-on: ${{ matrix.platform.os }}
defaults:
run:
shell: ${{ matrix.platform.shell }}
steps:
- name: Checkout
uses: actions/checkout@v4
- name: Setup Git User
run: |
git config --global user.email "npm-cli+bot@github.com"
git config --global user.name "npm CLI robot"
- name: Setup Node
uses: actions/setup-node@v4
id: node
with:
node-version: ${{ matrix.node-version }}
check-latest: contains(matrix.node-version, '.x')
- name: Install Latest npm
uses: ./.github/actions/install-latest-npm
with:
node: ${{ steps.node.outputs.node-version }}
- name: Install Dependencies
run: npm i --ignore-scripts --no-audit --no-fund
- name: Add Problem Matcher
run: echo "::add-matcher::.github/matchers/tap.json"
- name: Test
run: npm test --ignore-scripts
hosted-git-info-9.0.2/.github/workflows/codeql-analysis.yml 0000664 0000000 0000000 00000001606 15071511065 0023736 0 ustar 00root root 0000000 0000000 # This file is automatically added by @npmcli/template-oss. Do not edit.
name: CodeQL
on:
push:
branches:
- main
pull_request:
branches:
- main
schedule:
# "At 10:00 UTC (03:00 PT) on Monday" https://crontab.guru/#0_10_*_*_1
- cron: "0 10 * * 1"
permissions:
contents: read
jobs:
analyze:
name: Analyze
runs-on: ubuntu-latest
permissions:
actions: read
contents: read
security-events: write
steps:
- name: Checkout
uses: actions/checkout@v4
- name: Setup Git User
run: |
git config --global user.email "npm-cli+bot@github.com"
git config --global user.name "npm CLI robot"
- name: Initialize CodeQL
uses: github/codeql-action/init@v3
with:
languages: javascript
- name: Perform CodeQL Analysis
uses: github/codeql-action/analyze@v3
hosted-git-info-9.0.2/.github/workflows/post-dependabot.yml 0000664 0000000 0000000 00000012004 15071511065 0023730 0 ustar 00root root 0000000 0000000 # This file is automatically added by @npmcli/template-oss. Do not edit.
name: Post Dependabot
on: pull_request
permissions:
contents: write
jobs:
template-oss:
name: template-oss
if: github.repository_owner == 'npm' && github.actor == 'dependabot[bot]'
runs-on: ubuntu-latest
defaults:
run:
shell: bash
steps:
- name: Checkout
uses: actions/checkout@v4
with:
ref: ${{ github.event.pull_request.head.ref }}
- name: Setup Git User
run: |
git config --global user.email "npm-cli+bot@github.com"
git config --global user.name "npm CLI robot"
- name: Setup Node
uses: actions/setup-node@v4
id: node
with:
node-version: 22.x
check-latest: contains('22.x', '.x')
- name: Install Latest npm
uses: ./.github/actions/install-latest-npm
with:
node: ${{ steps.node.outputs.node-version }}
- name: Install Dependencies
run: npm i --ignore-scripts --no-audit --no-fund
- name: Fetch Dependabot Metadata
id: metadata
uses: dependabot/fetch-metadata@v1
with:
github-token: ${{ secrets.GITHUB_TOKEN }}
# Dependabot can update multiple directories so we output which directory
# it is acting on so we can run the command for the correct root or workspace
- name: Get Dependabot Directory
if: contains(steps.metadata.outputs.dependency-names, '@npmcli/template-oss')
id: flags
run: |
dependabot_dir="${{ steps.metadata.outputs.directory }}"
if [[ "$dependabot_dir" == "/" || "$dependabot_dir" == "/main" ]]; then
echo "workspace=-iwr" >> $GITHUB_OUTPUT
else
# strip leading slash from directory so it works as a
# a path to the workspace flag
echo "workspace=--workspace ${dependabot_dir#/}" >> $GITHUB_OUTPUT
fi
- name: Apply Changes
if: steps.flags.outputs.workspace
id: apply
run: |
npm run template-oss-apply ${{ steps.flags.outputs.workspace }}
if [[ `git status --porcelain` ]]; then
echo "changes=true" >> $GITHUB_OUTPUT
fi
# This only sets the conventional commit prefix. This workflow can't reliably determine
# what the breaking change is though. If a BREAKING CHANGE message is required then
# this PR check will fail and the commit will be amended with stafftools
if [[ "${{ steps.metadata.outputs.update-type }}" == "version-update:semver-major" ]]; then
prefix='feat!'
else
prefix='chore'
fi
echo "message=$prefix: postinstall for dependabot template-oss PR" >> $GITHUB_OUTPUT
# This step will fail if template-oss has made any workflow updates. It is impossible
# for a workflow to update other workflows. In the case it does fail, we continue
# and then try to apply only a portion of the changes in the next step
- name: Push All Changes
if: steps.apply.outputs.changes
id: push
continue-on-error: true
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
run: |
git commit -am "${{ steps.apply.outputs.message }}"
git push
# If the previous step failed, then reset the commit and remove any workflow changes
# and attempt to commit and push again. This is helpful because we will have a commit
# with the correct prefix that we can then --amend with @npmcli/stafftools later.
- name: Push All Changes Except Workflows
if: steps.apply.outputs.changes && steps.push.outcome == 'failure'
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
run: |
git reset HEAD~
git checkout HEAD -- .github/workflows/
git clean -fd .github/workflows/
git commit -am "${{ steps.apply.outputs.message }}"
git push
# Check if all the necessary template-oss changes were applied. Since we continued
# on errors in one of the previous steps, this check will fail if our follow up
# only applied a portion of the changes and we need to followup manually.
#
# Note that this used to run `lint` and `postlint` but that will fail this action
# if we've also shipped any linting changes separate from template-oss. We do
# linting in another action, so we want to fail this one only if there are
# template-oss changes that could not be applied.
- name: Check Changes
if: steps.apply.outputs.changes
run: |
npm exec --offline ${{ steps.flags.outputs.workspace }} -- template-oss-check
- name: Fail on Breaking Change
if: steps.apply.outputs.changes && startsWith(steps.apply.outputs.message, 'feat!')
run: |
echo "This PR has a breaking change. Run 'npx -p @npmcli/stafftools gh template-oss-fix'"
echo "for more information on how to fix this with a BREAKING CHANGE footer."
exit 1
hosted-git-info-9.0.2/.github/workflows/pull-request.yml 0000664 0000000 0000000 00000002737 15071511065 0023316 0 ustar 00root root 0000000 0000000 # This file is automatically added by @npmcli/template-oss. Do not edit.
name: Pull Request
on:
pull_request:
types:
- opened
- reopened
- edited
- synchronize
permissions:
contents: read
jobs:
commitlint:
name: Lint Commits
if: github.repository_owner == 'npm'
runs-on: ubuntu-latest
defaults:
run:
shell: bash
steps:
- name: Checkout
uses: actions/checkout@v4
with:
fetch-depth: 0
- name: Setup Git User
run: |
git config --global user.email "npm-cli+bot@github.com"
git config --global user.name "npm CLI robot"
- name: Setup Node
uses: actions/setup-node@v4
id: node
with:
node-version: 22.x
check-latest: contains('22.x', '.x')
- name: Install Latest npm
uses: ./.github/actions/install-latest-npm
with:
node: ${{ steps.node.outputs.node-version }}
- name: Install Dependencies
run: npm i --ignore-scripts --no-audit --no-fund
- name: Run Commitlint on Commits
id: commit
continue-on-error: true
run: npx --offline commitlint -V --from 'origin/${{ github.base_ref }}' --to ${{ github.event.pull_request.head.sha }}
- name: Run Commitlint on PR Title
if: steps.commit.outcome == 'failure'
env:
PR_TITLE: ${{ github.event.pull_request.title }}
run: echo "$PR_TITLE" | npx --offline commitlint -V
hosted-git-info-9.0.2/.github/workflows/release-integration.yml 0000664 0000000 0000000 00000004163 15071511065 0024610 0 ustar 00root root 0000000 0000000 # This file is automatically added by @npmcli/template-oss. Do not edit.
name: Release Integration
on:
workflow_dispatch:
inputs:
releases:
required: true
type: string
description: 'A json array of releases. Required fields: publish: tagName, publishTag. publish check: pkgName, version'
workflow_call:
inputs:
releases:
required: true
type: string
description: 'A json array of releases. Required fields: publish: tagName, publishTag. publish check: pkgName, version'
secrets:
PUBLISH_TOKEN:
required: true
permissions:
contents: read
id-token: write
jobs:
publish:
name: Publish
runs-on: ubuntu-latest
defaults:
run:
shell: bash
permissions:
id-token: write
steps:
- name: Checkout
uses: actions/checkout@v4
with:
ref: ${{ fromJSON(inputs.releases)[0].tagName }}
- name: Setup Git User
run: |
git config --global user.email "npm-cli+bot@github.com"
git config --global user.name "npm CLI robot"
- name: Setup Node
uses: actions/setup-node@v4
id: node
with:
node-version: 22.x
check-latest: contains('22.x', '.x')
- name: Install Latest npm
uses: ./.github/actions/install-latest-npm
with:
node: ${{ steps.node.outputs.node-version }}
- name: Install Dependencies
run: npm i --ignore-scripts --no-audit --no-fund
- name: Set npm authToken
run: npm config set '//registry.npmjs.org/:_authToken'=\${PUBLISH_TOKEN}
- name: Publish
env:
PUBLISH_TOKEN: ${{ secrets.PUBLISH_TOKEN }}
RELEASES: ${{ inputs.releases }}
run: |
EXIT_CODE=0
for release in $(echo $RELEASES | jq -r '.[] | @base64'); do
PUBLISH_TAG=$(echo "$release" | base64 --decode | jq -r .publishTag)
npm publish --provenance --tag="$PUBLISH_TAG"
STATUS=$?
if [[ "$STATUS" -eq 1 ]]; then
EXIT_CODE=$STATUS
fi
done
exit $EXIT_CODE
hosted-git-info-9.0.2/.github/workflows/release.yml 0000664 0000000 0000000 00000026106 15071511065 0022270 0 ustar 00root root 0000000 0000000 # This file is automatically added by @npmcli/template-oss. Do not edit.
name: Release
on:
push:
branches:
- main
permissions:
contents: write
pull-requests: write
checks: write
jobs:
release:
outputs:
pr: ${{ steps.release.outputs.pr }}
pr-branch: ${{ steps.release.outputs.pr-branch }}
pr-number: ${{ steps.release.outputs.pr-number }}
pr-sha: ${{ steps.release.outputs.pr-sha }}
releases: ${{ steps.release.outputs.releases }}
comment-id: ${{ steps.create-comment.outputs.comment-id || steps.update-comment.outputs.comment-id }}
check-id: ${{ steps.create-check.outputs.check-id }}
name: Release
if: github.repository_owner == 'npm'
runs-on: ubuntu-latest
defaults:
run:
shell: bash
steps:
- name: Checkout
uses: actions/checkout@v4
- name: Setup Git User
run: |
git config --global user.email "npm-cli+bot@github.com"
git config --global user.name "npm CLI robot"
- name: Setup Node
uses: actions/setup-node@v4
id: node
with:
node-version: 22.x
check-latest: contains('22.x', '.x')
- name: Install Latest npm
uses: ./.github/actions/install-latest-npm
with:
node: ${{ steps.node.outputs.node-version }}
- name: Install Dependencies
run: npm i --ignore-scripts --no-audit --no-fund
- name: Release Please
id: release
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
run: npx --offline template-oss-release-please --branch="${{ github.ref_name }}" --backport="" --defaultTag="latest"
- name: Create Release Manager Comment Text
if: steps.release.outputs.pr-number
uses: actions/github-script@v7
id: comment-text
with:
result-encoding: string
script: |
const { runId, repo: { owner, repo } } = context
const { data: workflow } = await github.rest.actions.getWorkflowRun({ owner, repo, run_id: runId })
return['## Release Manager', `Release workflow run: ${workflow.html_url}`].join('\n\n')
- name: Find Release Manager Comment
uses: peter-evans/find-comment@v2
if: steps.release.outputs.pr-number
id: found-comment
with:
issue-number: ${{ steps.release.outputs.pr-number }}
comment-author: 'github-actions[bot]'
body-includes: '## Release Manager'
- name: Create Release Manager Comment
id: create-comment
if: steps.release.outputs.pr-number && !steps.found-comment.outputs.comment-id
uses: peter-evans/create-or-update-comment@v3
with:
issue-number: ${{ steps.release.outputs.pr-number }}
body: ${{ steps.comment-text.outputs.result }}
- name: Update Release Manager Comment
id: update-comment
if: steps.release.outputs.pr-number && steps.found-comment.outputs.comment-id
uses: peter-evans/create-or-update-comment@v3
with:
comment-id: ${{ steps.found-comment.outputs.comment-id }}
body: ${{ steps.comment-text.outputs.result }}
edit-mode: 'replace'
- name: Create Check
id: create-check
uses: ./.github/actions/create-check
if: steps.release.outputs.pr-sha
with:
name: "Release"
token: ${{ secrets.GITHUB_TOKEN }}
sha: ${{ steps.release.outputs.pr-sha }}
update:
needs: release
outputs:
sha: ${{ steps.commit.outputs.sha }}
check-id: ${{ steps.create-check.outputs.check-id }}
name: Update - Release
if: github.repository_owner == 'npm' && needs.release.outputs.pr
runs-on: ubuntu-latest
defaults:
run:
shell: bash
steps:
- name: Checkout
uses: actions/checkout@v4
with:
fetch-depth: 0
ref: ${{ needs.release.outputs.pr-branch }}
- name: Setup Git User
run: |
git config --global user.email "npm-cli+bot@github.com"
git config --global user.name "npm CLI robot"
- name: Setup Node
uses: actions/setup-node@v4
id: node
with:
node-version: 22.x
check-latest: contains('22.x', '.x')
- name: Install Latest npm
uses: ./.github/actions/install-latest-npm
with:
node: ${{ steps.node.outputs.node-version }}
- name: Install Dependencies
run: npm i --ignore-scripts --no-audit --no-fund
- name: Create Release Manager Checklist Text
id: comment-text
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
run: npm exec --offline -- template-oss-release-manager --pr="${{ needs.release.outputs.pr-number }}" --backport="" --defaultTag="latest" --publish
- name: Append Release Manager Comment
uses: peter-evans/create-or-update-comment@v3
with:
comment-id: ${{ needs.release.outputs.comment-id }}
body: ${{ steps.comment-text.outputs.result }}
edit-mode: 'append'
- name: Run Post Pull Request Actions
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
run: npm run rp-pull-request --ignore-scripts --if-present -- --pr="${{ needs.release.outputs.pr-number }}" --commentId="${{ needs.release.outputs.comment-id }}"
- name: Commit
id: commit
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
run: |
git commit --all --amend --no-edit || true
git push --force-with-lease
echo "sha=$(git rev-parse HEAD)" >> $GITHUB_OUTPUT
- name: Create Check
id: create-check
uses: ./.github/actions/create-check
with:
name: "Update - Release"
check-name: "Release"
token: ${{ secrets.GITHUB_TOKEN }}
sha: ${{ steps.commit.outputs.sha }}
- name: Conclude Check
uses: LouisBrunner/checks-action@v1.6.0
with:
token: ${{ secrets.GITHUB_TOKEN }}
conclusion: ${{ job.status }}
check_id: ${{ needs.release.outputs.check-id }}
ci:
name: CI - Release
needs: [ release, update ]
if: needs.release.outputs.pr
uses: ./.github/workflows/ci-release.yml
with:
ref: ${{ needs.release.outputs.pr-branch }}
check-sha: ${{ needs.update.outputs.sha }}
post-ci:
needs: [ release, update, ci ]
name: Post CI - Release
if: github.repository_owner == 'npm' && needs.release.outputs.pr && always()
runs-on: ubuntu-latest
defaults:
run:
shell: bash
steps:
- name: Get CI Conclusion
id: conclusion
run: |
result=""
if [[ "${{ contains(needs.*.result, 'failure') }}" == "true" ]]; then
result="failure"
elif [[ "${{ contains(needs.*.result, 'cancelled') }}" == "true" ]]; then
result="cancelled"
else
result="success"
fi
echo "result=$result" >> $GITHUB_OUTPUT
- name: Conclude Check
uses: LouisBrunner/checks-action@v1.6.0
with:
token: ${{ secrets.GITHUB_TOKEN }}
conclusion: ${{ steps.conclusion.outputs.result }}
check_id: ${{ needs.update.outputs.check-id }}
post-release:
needs: release
outputs:
comment-id: ${{ steps.create-comment.outputs.comment-id }}
name: Post Release - Release
if: github.repository_owner == 'npm' && needs.release.outputs.releases
runs-on: ubuntu-latest
defaults:
run:
shell: bash
steps:
- name: Create Release PR Comment Text
id: comment-text
uses: actions/github-script@v7
env:
RELEASES: ${{ needs.release.outputs.releases }}
with:
result-encoding: string
script: |
const releases = JSON.parse(process.env.RELEASES)
const { runId, repo: { owner, repo } } = context
const issue_number = releases[0].prNumber
const runUrl = `https://github.com/${owner}/${repo}/actions/runs/${runId}`
return [
'## Release Workflow\n',
...releases.map(r => `- \`${r.pkgName}@${r.version}\` ${r.url}`),
`- Workflow run: :arrows_counterclockwise: ${runUrl}`,
].join('\n')
- name: Create Release PR Comment
id: create-comment
uses: peter-evans/create-or-update-comment@v3
with:
issue-number: ${{ fromJSON(needs.release.outputs.releases)[0].prNumber }}
body: ${{ steps.comment-text.outputs.result }}
release-integration:
needs: release
name: Release Integration
if: needs.release.outputs.releases
uses: ./.github/workflows/release-integration.yml
permissions:
contents: read
id-token: write
secrets:
PUBLISH_TOKEN: ${{ secrets.PUBLISH_TOKEN }}
with:
releases: ${{ needs.release.outputs.releases }}
post-release-integration:
needs: [ release, release-integration, post-release ]
name: Post Release Integration - Release
if: github.repository_owner == 'npm' && needs.release.outputs.releases && always()
runs-on: ubuntu-latest
defaults:
run:
shell: bash
steps:
- name: Get Post Release Conclusion
id: conclusion
run: |
if [[ "${{ contains(needs.*.result, 'failure') }}" == "true" ]]; then
result="x"
elif [[ "${{ contains(needs.*.result, 'cancelled') }}" == "true" ]]; then
result="heavy_multiplication_x"
else
result="white_check_mark"
fi
echo "result=$result" >> $GITHUB_OUTPUT
- name: Find Release PR Comment
uses: peter-evans/find-comment@v2
id: found-comment
with:
issue-number: ${{ fromJSON(needs.release.outputs.releases)[0].prNumber }}
comment-author: 'github-actions[bot]'
body-includes: '## Release Workflow'
- name: Create Release PR Comment Text
id: comment-text
if: steps.found-comment.outputs.comment-id
uses: actions/github-script@v7
env:
RESULT: ${{ steps.conclusion.outputs.result }}
BODY: ${{ steps.found-comment.outputs.comment-body }}
with:
result-encoding: string
script: |
const { RESULT, BODY } = process.env
const body = [BODY.replace(/(Workflow run: :)[a-z_]+(:)/, `$1${RESULT}$2`)]
if (RESULT !== 'white_check_mark') {
body.push(':rotating_light::rotating_light::rotating_light:')
body.push([
'@npm/cli-team: The post-release workflow failed for this release.',
'Manual steps may need to be taken after examining the workflow output.'
].join(' '))
body.push(':rotating_light::rotating_light::rotating_light:')
}
return body.join('\n\n').trim()
- name: Update Release PR Comment
if: steps.comment-text.outputs.result
uses: peter-evans/create-or-update-comment@v3
with:
comment-id: ${{ steps.found-comment.outputs.comment-id }}
body: ${{ steps.comment-text.outputs.result }}
edit-mode: 'replace'
hosted-git-info-9.0.2/.gitignore 0000664 0000000 0000000 00000001050 15071511065 0016507 0 ustar 00root root 0000000 0000000 # This file is automatically added by @npmcli/template-oss. Do not edit.
# ignore everything in the root
/*
!**/.gitignore
!/.commitlintrc.js
!/.eslint.config.js
!/.eslintrc.js
!/.eslintrc.local.*
!/.git-blame-ignore-revs
!/.github/
!/.gitignore
!/.npmrc
!/.prettierignore
!/.prettierrc.js
!/.release-please-manifest.json
!/bin/
!/CHANGELOG*
!/CODE_OF_CONDUCT.md
!/CONTRIBUTING.md
!/docs/
!/lib/
!/LICENSE*
!/map.js
!/package.json
!/README*
!/release-please-config.json
!/scripts/
!/SECURITY.md
!/tap-snapshots/
!/test/
!/tsconfig.json
tap-testdir*/
hosted-git-info-9.0.2/.npmrc 0000664 0000000 0000000 00000000135 15071511065 0015642 0 ustar 00root root 0000000 0000000 ; This file is automatically added by @npmcli/template-oss. Do not edit.
package-lock=false
hosted-git-info-9.0.2/.release-please-manifest.json 0000664 0000000 0000000 00000000023 15071511065 0022162 0 ustar 00root root 0000000 0000000 {
".": "9.0.2"
}
hosted-git-info-9.0.2/CHANGELOG.md 0000664 0000000 0000000 00000042204 15071511065 0016336 0 ustar 00root root 0000000 0000000 # Changelog
## [9.0.2](https://github.com/npm/hosted-git-info/compare/v9.0.1...v9.0.2) (2025-10-08)
### Bug Fixes
* [`c91490e`](https://github.com/npm/hosted-git-info/commit/c91490e162b3226c09b7337b54649988f741fa9c) [#314](https://github.com/npm/hosted-git-info/pull/314) correctProtocol misparsing protocol (#314) (@markovejnovic)
## [9.0.1](https://github.com/npm/hosted-git-info/compare/v9.0.0...v9.0.1) (2025-10-07)
### Bug Fixes
* [`bf29151`](https://github.com/npm/hosted-git-info/commit/bf291511cdcefba273d16df4b4fdc22edec47139) [#312](https://github.com/npm/hosted-git-info/pull/312) remove redundant httpstemplate (#312) (@markovejnovic)
### Chores
* [`6525ea6`](https://github.com/npm/hosted-git-info/commit/6525ea64373032e840df77b9764b69f2d3682d19) [#311](https://github.com/npm/hosted-git-info/pull/311) stop backport branch updates (#311) (@owlstronaut)
* [`97fef20`](https://github.com/npm/hosted-git-info/commit/97fef208f7b6663f21d1069654f60abea695f368) [#308](https://github.com/npm/hosted-git-info/pull/308) bump @npmcli/template-oss from 4.25.0 to 4.25.1 (#308) (@dependabot[bot], @npm-cli-bot)
## [9.0.0](https://github.com/npm/hosted-git-info/compare/v8.1.0...v9.0.0) (2025-07-24)
### ⚠️ BREAKING CHANGES
* `hosted-git-info` now supports node `^20.17.0 || >=22.9.0`
### Bug Fixes
* [`f5d971c`](https://github.com/npm/hosted-git-info/commit/f5d971c6e21de4c7d533fbfe7c0f4db33c1c10a4) [#305](https://github.com/npm/hosted-git-info/pull/305) align to npm 11 node engine range (@owlstronaut)
### Dependencies
* [`7a9c71e`](https://github.com/npm/hosted-git-info/commit/7a9c71ec56c588ed938dcfbc700eb56bcd20d14d) [#305](https://github.com/npm/hosted-git-info/pull/305) `lru-cache@11.1.0`
### Chores
* [`a0e07cd`](https://github.com/npm/hosted-git-info/commit/a0e07cd0b8cfd51907acac8a13caf426f690a4f6) [#302](https://github.com/npm/hosted-git-info/pull/302) bump @npmcli/template-oss from 4.24.4 to 4.25.0 (#302) (@dependabot[bot], @owlstronaut)
## [8.1.0](https://github.com/npm/hosted-git-info/compare/v8.0.2...v8.1.0) (2025-04-14)
### Features
* [`ef0865c`](https://github.com/npm/hosted-git-info/commit/ef0865cc5c28700f990bf25d919e2520c944cf55) [#288](https://github.com/npm/hosted-git-info/pull/288) add `HostedGitInfo.fromManifest` (#288) (@ljharb)
### Chores
* [`ac08fe8`](https://github.com/npm/hosted-git-info/commit/ac08fe89153d19d1fecbd1e5ce5014fad833134c) [#296](https://github.com/npm/hosted-git-info/pull/296) bump @npmcli/template-oss from 4.23.6 to 4.24.3 (#296) (@dependabot[bot], @npm-cli-bot)
## [8.0.2](https://github.com/npm/hosted-git-info/compare/v8.0.1...v8.0.2) (2024-11-21)
### Bug Fixes
* [`cc004ba`](https://github.com/npm/hosted-git-info/commit/cc004bae62d17b90c2fc889fcde5afbcac2fc508) [#280](https://github.com/npm/hosted-git-info/pull/280) even better regex for host fragment (#280) (@wraithgar)
## [8.0.1](https://github.com/npm/hosted-git-info/compare/v8.0.0...v8.0.1) (2024-11-20)
### Bug Fixes
* [`e47b7e4`](https://github.com/npm/hosted-git-info/commit/e47b7e476199820446483aefa0525d4726e49450) [#274](https://github.com/npm/hosted-git-info/pull/274) break up greedy host fragment parsing regex (#274) (@wraithgar)
### Chores
* [`3d55d13`](https://github.com/npm/hosted-git-info/commit/3d55d1316d1b323b1402ad2c642c6d1f37249058) [#277](https://github.com/npm/hosted-git-info/pull/277) fix workflows for new backport branch (#277) (@wraithgar)
* [`b3e455f`](https://github.com/npm/hosted-git-info/commit/b3e455fd7d66c2c967dba0cc624db8ed142bb86f) [#273](https://github.com/npm/hosted-git-info/pull/273) bump @npmcli/template-oss from 4.23.3 to 4.23.4 (#273) (@dependabot[bot], @npm-cli-bot)
## [8.0.0](https://github.com/npm/hosted-git-info/compare/v7.0.2...v8.0.0) (2024-09-03)
### ⚠️ BREAKING CHANGES
* `hosted-git-info` now supports node `^18.17.0 || >=20.5.0`
### Bug Fixes
* [`967d930`](https://github.com/npm/hosted-git-info/commit/967d930a3a2adb8b0b55c9d8ddfa1eeb9470f3e1) [#268](https://github.com/npm/hosted-git-info/pull/268) align to npm 10 node engine range (@hashtagchris)
### Chores
* [`20551b0`](https://github.com/npm/hosted-git-info/commit/20551b02dffa5fdb56d9b89b3521c016c4924ace) [#268](https://github.com/npm/hosted-git-info/pull/268) run template-oss-apply (@hashtagchris)
* [`9a3c062`](https://github.com/npm/hosted-git-info/commit/9a3c062a74dba37c6958a00ee22eb9207d45aefc) [#265](https://github.com/npm/hosted-git-info/pull/265) bump @npmcli/eslint-config from 4.0.5 to 5.0.0 (@dependabot[bot])
* [`8f0fa04`](https://github.com/npm/hosted-git-info/commit/8f0fa04d0fba8d6a2467acc648a2f568f3baa7ed) [#266](https://github.com/npm/hosted-git-info/pull/266) postinstall for dependabot template-oss PR (@hashtagchris)
* [`e0fe523`](https://github.com/npm/hosted-git-info/commit/e0fe523d96dc023b8e6750aa458b0d816673cb49) [#266](https://github.com/npm/hosted-git-info/pull/266) bump @npmcli/template-oss from 4.23.1 to 4.23.3 (@dependabot[bot])
## [7.0.2](https://github.com/npm/hosted-git-info/compare/v7.0.1...v7.0.2) (2024-05-04)
### Bug Fixes
* [`682fa35`](https://github.com/npm/hosted-git-info/commit/682fa356278e342b93361bb61cfb0e598011b61f) [#249](https://github.com/npm/hosted-git-info/pull/249) linting: no-unused-vars (@lukekarrys)
### Chores
* [`f33287c`](https://github.com/npm/hosted-git-info/commit/f33287c39772f714b41c2d32a5cb9e98b0d00c6f) [#249](https://github.com/npm/hosted-git-info/pull/249) bump @npmcli/template-oss to 4.22.0 (@lukekarrys)
* [`7bbdfd8`](https://github.com/npm/hosted-git-info/commit/7bbdfd8a564ddd5952fd245c38193af17e6a8d2c) [#248](https://github.com/npm/hosted-git-info/pull/248) chore: postinstall for dependabot template-oss PR (@lukekarrys)
* [`0d4310e`](https://github.com/npm/hosted-git-info/commit/0d4310e90809efa2c7f5be586709c821d432a551) [#249](https://github.com/npm/hosted-git-info/pull/249) postinstall for dependabot template-oss PR (@lukekarrys)
* [`2efc69b`](https://github.com/npm/hosted-git-info/commit/2efc69beca342455f1113625c66157f3f5c53af4) [#248](https://github.com/npm/hosted-git-info/pull/248) bump @npmcli/template-oss from 4.21.3 to 4.21.4 (@dependabot[bot])
## [7.0.1](https://github.com/npm/hosted-git-info/compare/v7.0.0...v7.0.1) (2023-09-13)
### Bug Fixes
* [`d7bac33`](https://github.com/npm/hosted-git-info/commit/d7bac33726d6a65788d16e3314f52449f0da58c4) [#213](https://github.com/npm/hosted-git-info/pull/213) remove sourcehut bugstemplate (#213) (@vladh)
## [7.0.0](https://github.com/npm/hosted-git-info/compare/v6.1.1...v7.0.0) (2023-08-14)
### ⚠️ BREAKING CHANGES
* support for node 14 has been removed
### Bug Fixes
* [`f9f7fde`](https://github.com/npm/hosted-git-info/commit/f9f7fde1385d3f99ed7a52b9d4b079d8074fc99f) [#209](https://github.com/npm/hosted-git-info/pull/209) use lru-cache named export (@lukekarrys)
* [`c98e908`](https://github.com/npm/hosted-git-info/commit/c98e90807775bf5c306a30426d7f6c6ebe9842d5) [#209](https://github.com/npm/hosted-git-info/pull/209) drop node14 support (@lukekarrys)
### Dependencies
* [`ecdd7de`](https://github.com/npm/hosted-git-info/commit/ecdd7decf24f66297ca5f459b4f1f36d41352e23) [#209](https://github.com/npm/hosted-git-info/pull/209) bump lru-cache from 7.18.3 to 10.0.1
## [6.1.1](https://github.com/npm/hosted-git-info/compare/v6.1.0...v6.1.1) (2022-10-27)
### Bug Fixes
* [`f03bfbd`](https://github.com/npm/hosted-git-info/commit/f03bfbd3022c8f6283a991ff879ed97704ac35fa) [#176](https://github.com/npm/hosted-git-info/pull/176) only correct protocols when called from githost (@lukekarrys)
## [6.1.0](https://github.com/npm/hosted-git-info/compare/v6.0.0...v6.1.0) (2022-10-26)
### Features
* [`a44bd35`](https://github.com/npm/hosted-git-info/commit/a44bd35820eaa6878f13ee12eba5dca6425ea2bd) [#172](https://github.com/npm/hosted-git-info/pull/172) add separate static method for just parsing urls (@lukekarrys)
## [6.0.0](https://github.com/npm/hosted-git-info/compare/v5.1.0...v6.0.0) (2022-10-12)
### ⚠️ BREAKING CHANGES
* `GitHost` now has a static `addHost` method to use instead of manually editing the object from `lib/git-host-info.js`.
* set default git ref to HEAD
* `hosted-git-info` is now compatible with the following semver range for node: `^14.17.0 || ^16.13.0 || >=18.0.0`
### Features
* [`9e0ce62`](https://github.com/npm/hosted-git-info/commit/9e0ce62b9aadb2a9cfe8999e96b004a5de4edfdf) [#142](https://github.com/npm/hosted-git-info/pull/142) refactor (@lukekarrys)
* [`89155e8`](https://github.com/npm/hosted-git-info/commit/89155e8799369f20ae71713f64e3d0f664192a58) set default git ref to HEAD (@darcyclarke)
* [`9ed9c38`](https://github.com/npm/hosted-git-info/commit/9ed9c38002f899ad2628f96b27b2ec9fecb4662f) [#162](https://github.com/npm/hosted-git-info/pull/162) postinstall for dependabot template-oss PR (@lukekarrys)
### Bug Fixes
* [`61ca7fb`](https://github.com/npm/hosted-git-info/commit/61ca7fb8f003299693e23f351eea589c38a3602c) [#152](https://github.com/npm/hosted-git-info/pull/152) parse branch names containing @ (@lukekarrys)
* [`3cd4a98`](https://github.com/npm/hosted-git-info/commit/3cd4a9881e20d3a59bf3bb470661a29208824dd6) ignore colons after hash when correcting scp urls (@lukekarrys)
## [5.1.0](https://github.com/npm/hosted-git-info/compare/v5.0.0...v5.1.0) (2022-08-09)
### Features
* add method to get an edit link to a file ([ad02952](https://github.com/npm/hosted-git-info/commit/ad02952f89fbdc99e67ae0d5308029395bde3331))
### Bug Fixes
* add comments to empty catch blocks for linting ([70a770d](https://github.com/npm/hosted-git-info/commit/70a770d1202128e15887d69dfd5c930e4ff29a00))
## [5.0.0](https://www.github.com/npm/hosted-git-info/compare/v4.1.0...v5.0.0) (2022-03-14)
### ⚠ BREAKING CHANGES
* this drops support for node 10 and non-LTS versions of node 12 and node 14
### Bug Fixes
* move files to lib ([a3f4836](https://www.github.com/npm/hosted-git-info/commit/a3f4836ba0a75b355c004e1991e8dd1e6321a983))
* @npmcli/template-oss@2.9.2 ([c42e1f2](https://www.github.com/npm/hosted-git-info/commit/c42e1f216542ead9d0d328704c5db02204f15ce8))
### Dependencies
* bump lru-cache from 6.0.0 to 7.5.1 ([#128](https://www.github.com/npm/hosted-git-info/issues/128)) ([5b0b3b5](https://www.github.com/npm/hosted-git-info/commit/5b0b3b50bd36f659037e3b82a7ff47b0eff3b9f9))
## [4.0.0](https://github.com/npm/hosted-git-info/compare/v3.0.7...v4.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](https://github.com/npm/hosted-git-info/commit/c218b9ec90cf6a818341cd0f7b03ea65793b185b))
### BREAKING CHANGES
* extending with custom providers has changed ([c218b9](https://github.com/npm/hosted-git-info/commit/c218b9ec90cf6a818341cd0f7b03ea65793b185b))
## [3.0.8](https://github.com/npm/hosted-git-info/compare/v3.0.7...v3.0.8) (2021-01-28)
### Bug Fixes
* simplify the regular expression for shortcut matching ([bede0dc](https://github.com/npm/hosted-git-info/commit/bede0dc)), closes [#76](https://github.com/npm/hosted-git-info/issues/76)
## [3.0.7](https://github.com/npm/hosted-git-info/compare/v3.0.6...v3.0.7) (2020-10-15)
### Bug Fixes
* correctly filter out urls for tarballs in gitlab ([eb5bd5a](https://github.com/npm/hosted-git-info/commit/eb5bd5a)), closes [#69](https://github.com/npm/hosted-git-info/issues/69)
## [3.0.6](https://github.com/npm/hosted-git-info/compare/v3.0.5...v3.0.6) (2020-10-12)
### Bug Fixes
* support to github gist legacy hash length ([c067102](https://github.com/npm/hosted-git-info/commit/c067102)), closes [#68](https://github.com/npm/hosted-git-info/issues/68)
## [3.0.5](https://github.com/npm/hosted-git-info/compare/v3.0.4...v3.0.5) (2020-07-11)
## [3.0.4](https://github.com/npm/hosted-git-info/compare/v3.0.3...v3.0.4) (2020-02-26)
### Bug Fixes
* Do not pass scp-style URLs to the WhatWG url.URL ([0835306](https://github.com/npm/hosted-git-info/commit/0835306)), closes [#60](https://github.com/npm/hosted-git-info/issues/60) [#63](https://github.com/npm/hosted-git-info/issues/63)
## [3.0.3](https://github.com/npm/hosted-git-info/compare/v3.0.2...v3.0.3) (2020-02-25)
## [3.0.2](https://github.com/npm/hosted-git-info/compare/v3.0.1...v3.0.2) (2019-10-08)
### Bug Fixes
* do not encodeURIComponent the domain ([3e5fbec](https://github.com/npm/hosted-git-info/commit/3e5fbec)), closes [#53](https://github.com/npm/hosted-git-info/issues/53)
## [3.0.1](https://github.com/npm/hosted-git-info/compare/v3.0.0...v3.0.1) (2019-10-07)
### Bug Fixes
* update pathmatch for gitlab ([e3e3054](https://github.com/npm/hosted-git-info/commit/e3e3054)), closes [#52](https://github.com/npm/hosted-git-info/issues/52)
* updated pathmatch for gitlab ([fa87af7](https://github.com/npm/hosted-git-info/commit/fa87af7))
# [3.0.0](https://github.com/npm/hosted-git-info/compare/v2.8.3...v3.0.0) (2019-08-12)
### Bug Fixes
* **cache:** Switch to lru-cache to save ourselves from unlimited memory consumption ([37c2891](https://github.com/npm/hosted-git-info/commit/37c2891)), closes [#38](https://github.com/npm/hosted-git-info/issues/38)
### BREAKING CHANGES
* **cache:** Drop support for node 0.x
## [2.8.3](https://github.com/npm/hosted-git-info/compare/v2.8.2...v2.8.3) (2019-08-12)
## [2.8.2](https://github.com/npm/hosted-git-info/compare/v2.8.1...v2.8.2) (2019-08-05)
### Bug Fixes
* http protocol use sshurl by default ([3b1d629](https://github.com/npm/hosted-git-info/commit/3b1d629)), closes [#48](https://github.com/npm/hosted-git-info/issues/48)
## [2.8.1](https://github.com/npm/hosted-git-info/compare/v2.8.0...v2.8.1) (2019-08-05)
### Bug Fixes
* ignore noCommittish on tarball url generation ([5d4a8d7](https://github.com/npm/hosted-git-info/commit/5d4a8d7))
* use gist tarball url that works for anonymous gists ([1692435](https://github.com/npm/hosted-git-info/commit/1692435))
# [2.8.0](https://github.com/npm/hosted-git-info/compare/v2.7.1...v2.8.0) (2019-08-05)
### Bug Fixes
* Allow slashes in gitlab project section ([bbcf7b2](https://github.com/npm/hosted-git-info/commit/bbcf7b2)), closes [#46](https://github.com/npm/hosted-git-info/issues/46) [#43](https://github.com/npm/hosted-git-info/issues/43)
* **git-host:** disallow URI-encoded slash (%2F) in `path` ([3776fa5](https://github.com/npm/hosted-git-info/commit/3776fa5)), closes [#44](https://github.com/npm/hosted-git-info/issues/44)
* **gitlab:** Do not URL encode slashes in project name for GitLab https URL ([cbf04f9](https://github.com/npm/hosted-git-info/commit/cbf04f9)), closes [#47](https://github.com/npm/hosted-git-info/issues/47)
* do not allow invalid gist urls ([d5cf830](https://github.com/npm/hosted-git-info/commit/d5cf830))
* **cache:** Switch to lru-cache to save ourselves from unlimited memory consumption ([e518222](https://github.com/npm/hosted-git-info/commit/e518222)), closes [#38](https://github.com/npm/hosted-git-info/issues/38)
### Features
* give these objects a name ([60abaea](https://github.com/npm/hosted-git-info/commit/60abaea))
## [2.7.1](https://github.com/npm/hosted-git-info/compare/v2.7.0...v2.7.1) (2018-07-07)
### Bug Fixes
* **index:** Guard against non-string types ([5bc580d](https://github.com/npm/hosted-git-info/commit/5bc580d))
* **parse:** Crash on strings that parse to having no host ([c931482](https://github.com/npm/hosted-git-info/commit/c931482)), closes [#35](https://github.com/npm/hosted-git-info/issues/35)
# [2.7.0](https://github.com/npm/hosted-git-info/compare/v2.6.1...v2.7.0) (2018-07-06)
### Bug Fixes
* **github tarball:** update github tarballtemplate ([6efd582](https://github.com/npm/hosted-git-info/commit/6efd582)), closes [#34](https://github.com/npm/hosted-git-info/issues/34)
* **gitlab docs:** switched to lowercase anchors for readmes ([701bcd1](https://github.com/npm/hosted-git-info/commit/701bcd1))
### Features
* **all:** Support www. prefixes on hostnames ([3349575](https://github.com/npm/hosted-git-info/commit/3349575)), closes [#32](https://github.com/npm/hosted-git-info/issues/32)
## [2.6.1](https://github.com/npm/hosted-git-info/compare/v2.6.0...v2.6.1) (2018-06-25)
### Bug Fixes
* **Revert:** "compat: remove Object.assign fallback ([#25](https://github.com/npm/hosted-git-info/issues/25))" ([cce5a62](https://github.com/npm/hosted-git-info/commit/cce5a62))
* **Revert:** "git-host: fix forgotten extend()" ([a815ec9](https://github.com/npm/hosted-git-info/commit/a815ec9))
# [2.6.0](https://github.com/npm/hosted-git-info/compare/v2.5.0...v2.6.0) (2018-03-07)
### Bug Fixes
* **compat:** remove Object.assign fallback ([#25](https://github.com/npm/hosted-git-info/issues/25)) ([627ab55](https://github.com/npm/hosted-git-info/commit/627ab55))
* **git-host:** fix forgotten extend() ([eba1f7b](https://github.com/npm/hosted-git-info/commit/eba1f7b))
### Features
* **browse:** fragment support for browse() ([#28](https://github.com/npm/hosted-git-info/issues/28)) ([cd5e5bb](https://github.com/npm/hosted-git-info/commit/cd5e5bb))
hosted-git-info-9.0.2/CODE_OF_CONDUCT.md 0000664 0000000 0000000 00000000507 15071511065 0017324 0 ustar 00root root 0000000 0000000
All interactions in this repo are covered by the [npm Code of
Conduct](https://docs.npmjs.com/policies/conduct)
The npm cli team may, at its own discretion, moderate, remove, or edit
any interactions such as pull requests, issues, and comments.
hosted-git-info-9.0.2/CONTRIBUTING.md 0000664 0000000 0000000 00000005133 15071511065 0016756 0 ustar 00root root 0000000 0000000
# Contributing
## Code of Conduct
All interactions in the **npm** organization on GitHub are considered to be covered by our standard [Code of Conduct](https://docs.npmjs.com/policies/conduct).
## Reporting Bugs
Before submitting a new bug report please search for an existing or similar report.
Use one of our existing issue templates if you believe you've come across a unique problem.
Duplicate issues, or issues that don't use one of our templates may get closed without a response.
## Pull Request Conventions
### Commits
We use [Conventional Commits](https://www.conventionalcommits.org/en/v1.0.0/).
When opening a pull request please be sure that either the pull request title, or each commit in the pull request, has one of the following prefixes:
- `feat`: For when introducing a new feature. The result will be a new semver minor version of the package when it is next published.
- `fix`: For bug fixes. The result will be a new semver patch version of the package when it is next published.
- `docs`: For documentation updates. The result will be a new semver patch version of the package when it is next published.
- `chore`: For changes that do not affect the published module. Often these are changes to tests. The result will be *no* change to the version of the package when it is next published (as the commit does not affect the published version).
### Test Coverage
Pull requests made against this repo will run `npm test` automatically. Please make sure tests pass locally before submitting a PR.
Every new feature or bug fix should come with a corresponding test or tests that validate the solutions. Testing also reports on code coverage and will fail if code coverage drops.
### Linting
Linting is also done automatically once tests pass. `npm run lintfix` will fix most linting errors automatically.
Please make sure linting passes before submitting a PR.
## What _not_ to contribute?
### Dependencies
It should be noted that our team does not accept third-party dependency updates/PRs. If you submit a PR trying to update our dependencies we will close it with or without a reference to these contribution guidelines.
### Tools/Automation
Our core team is responsible for the maintenance of the tooling/automation in this project and we ask contributors to not make changes to these when contributing (e.g. `.github/*`, `.eslintrc.json`, `.licensee.json`). Most of those files also have a header at the top to remind folks they are automatically generated. Pull requests that alter these will not be accepted.
hosted-git-info-9.0.2/LICENSE 0000664 0000000 0000000 00000001335 15071511065 0015532 0 ustar 00root root 0000000 0000000 Copyright (c) 2015, Rebecca Turner
Permission to use, copy, modify, and/or distribute this software for any
purpose with or without fee is hereby granted, provided that the above
copyright notice and this permission notice appear in all copies.
THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES WITH
REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND
FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY SPECIAL, DIRECT,
INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM
LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR
OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
PERFORMANCE OF THIS SOFTWARE.
hosted-git-info-9.0.2/README.md 0000664 0000000 0000000 00000010664 15071511065 0016011 0 ustar 00root root 0000000 0000000 # 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
```javascript
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.
### const infoOrURL = hostedGitInfo.fromManifest(manifest[, options])
* *manifest* is a package manifest, such as that returned by [`pacote.manifest()`](https://npmjs.com/pacote)
* *options* is an optional object. It can have the same properties as `fromUrl` above.
## 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.
hosted-git-info-9.0.2/SECURITY.md 0000664 0000000 0000000 00000002320 15071511065 0016311 0 ustar 00root root 0000000 0000000
GitHub takes the security of our software products and services seriously, including the open source code repositories managed through our GitHub organizations, such as [GitHub](https://github.com/GitHub).
If you believe you have found a security vulnerability in this GitHub-owned open source repository, you can report it to us in one of two ways.
If the vulnerability you have found is *not* [in scope for the GitHub Bug Bounty Program](https://bounty.github.com/#scope) or if you do not wish to be considered for a bounty reward, please report the issue to us directly through [opensource-security@github.com](mailto:opensource-security@github.com).
If the vulnerability you have found is [in scope for the GitHub Bug Bounty Program](https://bounty.github.com/#scope) and you would like for your finding to be considered for a bounty reward, please submit the vulnerability to us through [HackerOne](https://hackerone.com/github) in order to be eligible to receive a bounty award.
**Please do not report security vulnerabilities through public GitHub issues, discussions, or pull requests.**
Thanks for helping make GitHub safe for everyone.
hosted-git-info-9.0.2/lib/ 0000775 0000000 0000000 00000000000 15071511065 0015271 5 ustar 00root root 0000000 0000000 hosted-git-info-9.0.2/lib/from-url.js 0000664 0000000 0000000 00000010173 15071511065 0017374 0 ustar 00root root 0000000 0000000 'use strict'
const parseUrl = require('./parse-url')
// look for github shorthand inputs, such as npm/cli
const isGitHubShorthand = (arg) => {
// it cannot contain whitespace before the first #
// it cannot start with a / because that's probably an absolute file path
// but it must include a slash since repos are username/repository
// it cannot start with a . because that's probably a relative file path
// it cannot start with an @ because that's a scoped package if it passes the other tests
// it cannot contain a : before a # because that tells us that there's a protocol
// a second / may not exist before a #
const firstHash = arg.indexOf('#')
const firstSlash = arg.indexOf('/')
const secondSlash = arg.indexOf('/', firstSlash + 1)
const firstColon = arg.indexOf(':')
const firstSpace = /\s/.exec(arg)
const firstAt = arg.indexOf('@')
const spaceOnlyAfterHash = !firstSpace || (firstHash > -1 && firstSpace.index > firstHash)
const atOnlyAfterHash = firstAt === -1 || (firstHash > -1 && firstAt > firstHash)
const colonOnlyAfterHash = firstColon === -1 || (firstHash > -1 && firstColon > firstHash)
const secondSlashOnlyAfterHash = secondSlash === -1 || (firstHash > -1 && secondSlash > firstHash)
const hasSlash = firstSlash > 0
// if a # is found, what we really want to know is that the character
// immediately before # is not a /
const doesNotEndWithSlash = firstHash > -1 ? arg[firstHash - 1] !== '/' : !arg.endsWith('/')
const doesNotStartWithDot = !arg.startsWith('.')
return spaceOnlyAfterHash && hasSlash && doesNotEndWithSlash &&
doesNotStartWithDot && atOnlyAfterHash && colonOnlyAfterHash &&
secondSlashOnlyAfterHash
}
module.exports = (giturl, opts, { gitHosts, protocols }) => {
if (!giturl) {
return
}
const correctedUrl = isGitHubShorthand(giturl) ? `github:${giturl}` : giturl
const parsed = parseUrl(correctedUrl, protocols)
if (!parsed) {
return
}
const gitHostShortcut = gitHosts.byShortcut[parsed.protocol]
const gitHostDomain = gitHosts.byDomain[parsed.hostname.startsWith('www.')
? parsed.hostname.slice(4)
: parsed.hostname]
const gitHostName = gitHostShortcut || gitHostDomain
if (!gitHostName) {
return
}
const gitHostInfo = gitHosts[gitHostShortcut || gitHostDomain]
let auth = null
if (protocols[parsed.protocol]?.auth && (parsed.username || parsed.password)) {
auth = `${parsed.username}${parsed.password ? ':' + parsed.password : ''}`
}
let committish = null
let user = null
let project = null
let defaultRepresentation = null
try {
if (gitHostShortcut) {
let pathname = parsed.pathname.startsWith('/') ? parsed.pathname.slice(1) : parsed.pathname
const firstAt = pathname.indexOf('@')
// we ignore auth for shortcuts, so just trim it out
if (firstAt > -1) {
pathname = pathname.slice(firstAt + 1)
}
const lastSlash = pathname.lastIndexOf('/')
if (lastSlash > -1) {
user = decodeURIComponent(pathname.slice(0, lastSlash))
// we want nulls only, never empty strings
if (!user) {
user = null
}
project = decodeURIComponent(pathname.slice(lastSlash + 1))
} else {
project = decodeURIComponent(pathname)
}
if (project.endsWith('.git')) {
project = project.slice(0, -4)
}
if (parsed.hash) {
committish = decodeURIComponent(parsed.hash.slice(1))
}
defaultRepresentation = 'shortcut'
} else {
if (!gitHostInfo.protocols.includes(parsed.protocol)) {
return
}
const segments = gitHostInfo.extract(parsed)
if (!segments) {
return
}
user = segments.user && decodeURIComponent(segments.user)
project = decodeURIComponent(segments.project)
committish = decodeURIComponent(segments.committish)
defaultRepresentation = protocols[parsed.protocol]?.name || parsed.protocol.slice(0, -1)
}
} catch (err) {
/* istanbul ignore else */
if (err instanceof URIError) {
return
} else {
throw err
}
}
return [gitHostName, user, auth, project, committish, defaultRepresentation, opts]
}
hosted-git-info-9.0.2/lib/hosts.js 0000664 0000000 0000000 00000021437 15071511065 0016776 0 ustar 00root root 0000000 0000000 /* eslint-disable max-len */
'use strict'
const maybeJoin = (...args) => args.every(arg => arg) ? args.join('') : ''
const maybeEncode = (arg) => arg ? encodeURIComponent(arg) : ''
const formatHashFragment = (f) => f.toLowerCase()
.replace(/^\W+/g, '') // strip leading non-characters
.replace(/(?
`git@${domain}:${user}/${project}.git${maybeJoin('#', committish)}`,
sshurltemplate: ({ domain, user, project, committish }) =>
`git+ssh://git@${domain}/${user}/${project}.git${maybeJoin('#', committish)}`,
edittemplate: ({ domain, user, project, committish, editpath, path }) =>
`https://${domain}/${user}/${project}${maybeJoin('/', editpath, '/', maybeEncode(committish || 'HEAD'), '/', path)}`,
browsetemplate: ({ domain, user, project, committish, treepath }) =>
`https://${domain}/${user}/${project}${maybeJoin('/', treepath, '/', maybeEncode(committish))}`,
browsetreetemplate: ({ domain, user, project, committish, treepath, path, fragment, hashformat }) =>
`https://${domain}/${user}/${project}/${treepath}/${maybeEncode(committish || 'HEAD')}/${path}${maybeJoin('#', hashformat(fragment || ''))}`,
browseblobtemplate: ({ domain, user, project, committish, blobpath, path, fragment, hashformat }) =>
`https://${domain}/${user}/${project}/${blobpath}/${maybeEncode(committish || 'HEAD')}/${path}${maybeJoin('#', hashformat(fragment || ''))}`,
docstemplate: ({ domain, user, project, treepath, committish }) =>
`https://${domain}/${user}/${project}${maybeJoin('/', treepath, '/', maybeEncode(committish))}#readme`,
httpstemplate: ({ auth, domain, user, project, committish }) =>
`git+https://${maybeJoin(auth, '@')}${domain}/${user}/${project}.git${maybeJoin('#', committish)}`,
filetemplate: ({ domain, user, project, committish, path }) =>
`https://${domain}/${user}/${project}/raw/${maybeEncode(committish || 'HEAD')}/${path}`,
shortcuttemplate: ({ type, user, project, committish }) =>
`${type}:${user}/${project}${maybeJoin('#', committish)}`,
pathtemplate: ({ user, project, committish }) =>
`${user}/${project}${maybeJoin('#', committish)}`,
bugstemplate: ({ domain, user, project }) =>
`https://${domain}/${user}/${project}/issues`,
hashformat: formatHashFragment,
}
const hosts = {}
hosts.github = {
// First two are insecure and generally shouldn't be used any more, but
// they are still supported.
protocols: ['git:', 'http:', 'git+ssh:', 'git+https:', 'ssh:', 'https:'],
domain: 'github.com',
treepath: 'tree',
blobpath: 'blob',
editpath: 'edit',
filetemplate: ({ auth, user, project, committish, path }) =>
`https://${maybeJoin(auth, '@')}raw.githubusercontent.com/${user}/${project}/${maybeEncode(committish || 'HEAD')}/${path}`,
gittemplate: ({ auth, domain, user, project, committish }) =>
`git://${maybeJoin(auth, '@')}${domain}/${user}/${project}.git${maybeJoin('#', committish)}`,
tarballtemplate: ({ domain, user, project, committish }) =>
`https://codeload.${domain}/${user}/${project}/tar.gz/${maybeEncode(committish || 'HEAD')}`,
extract: (url) => {
let [, user, project, type, committish] = url.pathname.split('/', 5)
if (type && type !== 'tree') {
return
}
if (!type) {
committish = url.hash.slice(1)
}
if (project && project.endsWith('.git')) {
project = project.slice(0, -4)
}
if (!user || !project) {
return
}
return { user, project, committish }
},
}
hosts.bitbucket = {
protocols: ['git+ssh:', 'git+https:', 'ssh:', 'https:'],
domain: 'bitbucket.org',
treepath: 'src',
blobpath: 'src',
editpath: '?mode=edit',
edittemplate: ({ domain, user, project, committish, treepath, path, editpath }) =>
`https://${domain}/${user}/${project}${maybeJoin('/', treepath, '/', maybeEncode(committish || 'HEAD'), '/', path, editpath)}`,
tarballtemplate: ({ domain, user, project, committish }) =>
`https://${domain}/${user}/${project}/get/${maybeEncode(committish || 'HEAD')}.tar.gz`,
extract: (url) => {
let [, user, project, aux] = url.pathname.split('/', 4)
if (['get'].includes(aux)) {
return
}
if (project && project.endsWith('.git')) {
project = project.slice(0, -4)
}
if (!user || !project) {
return
}
return { user, project, committish: url.hash.slice(1) }
},
}
hosts.gitlab = {
protocols: ['git+ssh:', 'git+https:', 'ssh:', 'https:'],
domain: 'gitlab.com',
treepath: 'tree',
blobpath: 'tree',
editpath: '-/edit',
tarballtemplate: ({ domain, user, project, committish }) =>
`https://${domain}/${user}/${project}/repository/archive.tar.gz?ref=${maybeEncode(committish || 'HEAD')}`,
extract: (url) => {
const path = url.pathname.slice(1)
if (path.includes('/-/') || path.includes('/archive.tar.gz')) {
return
}
const segments = path.split('/')
let project = segments.pop()
if (project.endsWith('.git')) {
project = project.slice(0, -4)
}
const user = segments.join('/')
if (!user || !project) {
return
}
return { user, project, committish: url.hash.slice(1) }
},
}
hosts.gist = {
protocols: ['git:', 'git+ssh:', 'git+https:', 'ssh:', 'https:'],
domain: 'gist.github.com',
editpath: 'edit',
sshtemplate: ({ domain, project, committish }) =>
`git@${domain}:${project}.git${maybeJoin('#', committish)}`,
sshurltemplate: ({ domain, project, committish }) =>
`git+ssh://git@${domain}/${project}.git${maybeJoin('#', committish)}`,
edittemplate: ({ domain, user, project, committish, editpath }) =>
`https://${domain}/${user}/${project}${maybeJoin('/', maybeEncode(committish))}/${editpath}`,
browsetemplate: ({ domain, project, committish }) =>
`https://${domain}/${project}${maybeJoin('/', maybeEncode(committish))}`,
browsetreetemplate: ({ domain, project, committish, path, hashformat }) =>
`https://${domain}/${project}${maybeJoin('/', maybeEncode(committish))}${maybeJoin('#', hashformat(path))}`,
browseblobtemplate: ({ domain, project, committish, path, hashformat }) =>
`https://${domain}/${project}${maybeJoin('/', maybeEncode(committish))}${maybeJoin('#', hashformat(path))}`,
docstemplate: ({ domain, project, committish }) =>
`https://${domain}/${project}${maybeJoin('/', maybeEncode(committish))}`,
httpstemplate: ({ domain, project, committish }) =>
`git+https://${domain}/${project}.git${maybeJoin('#', committish)}`,
filetemplate: ({ user, project, committish, path }) =>
`https://gist.githubusercontent.com/${user}/${project}/raw${maybeJoin('/', maybeEncode(committish))}/${path}`,
shortcuttemplate: ({ type, project, committish }) =>
`${type}:${project}${maybeJoin('#', committish)}`,
pathtemplate: ({ project, committish }) =>
`${project}${maybeJoin('#', committish)}`,
bugstemplate: ({ domain, project }) =>
`https://${domain}/${project}`,
gittemplate: ({ domain, project, committish }) =>
`git://${domain}/${project}.git${maybeJoin('#', committish)}`,
tarballtemplate: ({ project, committish }) =>
`https://codeload.github.com/gist/${project}/tar.gz/${maybeEncode(committish || 'HEAD')}`,
extract: (url) => {
let [, user, project, aux] = url.pathname.split('/', 4)
if (aux === 'raw') {
return
}
if (!project) {
if (!user) {
return
}
project = user
user = null
}
if (project.endsWith('.git')) {
project = project.slice(0, -4)
}
return { user, project, committish: url.hash.slice(1) }
},
hashformat: function (fragment) {
return fragment && 'file-' + formatHashFragment(fragment)
},
}
hosts.sourcehut = {
protocols: ['git+ssh:', 'https:'],
domain: 'git.sr.ht',
treepath: 'tree',
blobpath: 'tree',
filetemplate: ({ domain, user, project, committish, path }) =>
`https://${domain}/${user}/${project}/blob/${maybeEncode(committish) || 'HEAD'}/${path}`,
httpstemplate: ({ domain, user, project, committish }) =>
`https://${domain}/${user}/${project}.git${maybeJoin('#', committish)}`,
tarballtemplate: ({ domain, user, project, committish }) =>
`https://${domain}/${user}/${project}/archive/${maybeEncode(committish) || 'HEAD'}.tar.gz`,
bugstemplate: () => null,
extract: (url) => {
let [, user, project, aux] = url.pathname.split('/', 4)
// tarball url
if (['archive'].includes(aux)) {
return
}
if (project && project.endsWith('.git')) {
project = project.slice(0, -4)
}
if (!user || !project) {
return
}
return { user, project, committish: url.hash.slice(1) }
},
}
for (const [name, host] of Object.entries(hosts)) {
hosts[name] = Object.assign({}, defaults, host)
}
module.exports = hosts
hosted-git-info-9.0.2/lib/index.js 0000664 0000000 0000000 00000012505 15071511065 0016741 0 ustar 00root root 0000000 0000000 'use strict'
const { LRUCache } = require('lru-cache')
const hosts = require('./hosts.js')
const fromUrl = require('./from-url.js')
const parseUrl = require('./parse-url.js')
const cache = new LRUCache({ max: 1000 })
function unknownHostedUrl (url) {
try {
const {
protocol,
hostname,
pathname,
} = new URL(url)
if (!hostname) {
return null
}
const proto = /(?:git\+)http:$/.test(protocol) ? 'http:' : 'https:'
const path = pathname.replace(/\.git$/, '')
return `${proto}//${hostname}${path}`
} catch {
return null
}
}
class GitHost {
constructor (type, user, auth, project, committish, defaultRepresentation, opts = {}) {
Object.assign(this, GitHost.#gitHosts[type], {
type,
user,
auth,
project,
committish,
default: defaultRepresentation,
opts,
})
}
static #gitHosts = { byShortcut: {}, byDomain: {} }
static #protocols = {
'git+ssh:': { name: 'sshurl' },
'ssh:': { name: 'sshurl' },
'git+https:': { name: 'https', auth: true },
'git:': { auth: true },
'http:': { auth: true },
'https:': { auth: true },
'git+http:': { auth: true },
}
static addHost (name, host) {
GitHost.#gitHosts[name] = host
GitHost.#gitHosts.byDomain[host.domain] = name
GitHost.#gitHosts.byShortcut[`${name}:`] = name
GitHost.#protocols[`${name}:`] = { name }
}
static fromUrl (giturl, opts) {
if (typeof giturl !== 'string') {
return
}
const key = giturl + JSON.stringify(opts || {})
if (!cache.has(key)) {
const hostArgs = fromUrl(giturl, opts, {
gitHosts: GitHost.#gitHosts,
protocols: GitHost.#protocols,
})
cache.set(key, hostArgs ? new GitHost(...hostArgs) : undefined)
}
return cache.get(key)
}
static fromManifest (manifest, opts = {}) {
if (!manifest || typeof manifest !== 'object') {
return
}
const r = manifest.repository
// TODO: look into also checking the `bugs`/`homepage` URLs
const rurl = r && (
typeof r === 'string'
? r
: typeof r === 'object' && typeof r.url === 'string'
? r.url
: null
)
if (!rurl) {
throw new Error('no repository')
}
const info = (rurl && GitHost.fromUrl(rurl.replace(/^git\+/, ''), opts)) || null
if (info) {
return info
}
const unk = unknownHostedUrl(rurl)
return GitHost.fromUrl(unk, opts) || unk
}
static parseUrl (url) {
return parseUrl(url)
}
#fill (template, opts) {
if (typeof template !== 'function') {
return null
}
const options = { ...this, ...this.opts, ...opts }
// the path should always be set so we don't end up with 'undefined' in urls
if (!options.path) {
options.path = ''
}
// template functions will insert the leading slash themselves
if (options.path.startsWith('/')) {
options.path = options.path.slice(1)
}
if (options.noCommittish) {
options.committish = null
}
const result = template(options)
return options.noGitPlus && result.startsWith('git+') ? result.slice(4) : result
}
hash () {
return this.committish ? `#${this.committish}` : ''
}
ssh (opts) {
return this.#fill(this.sshtemplate, opts)
}
sshurl (opts) {
return this.#fill(this.sshurltemplate, opts)
}
browse (path, ...args) {
// not a string, treat path as opts
if (typeof path !== 'string') {
return this.#fill(this.browsetemplate, path)
}
if (typeof args[0] !== 'string') {
return this.#fill(this.browsetreetemplate, { ...args[0], path })
}
return this.#fill(this.browsetreetemplate, { ...args[1], fragment: args[0], path })
}
// If the path is known to be a file, then browseFile should be used. For some hosts
// the url is the same as browse, but for others like GitHub a file can use both `/tree/`
// and `/blob/` in the path. When using a default committish of `HEAD` then the `/tree/`
// path will redirect to a specific commit. Using the `/blob/` path avoids this and
// does not redirect to a different commit.
browseFile (path, ...args) {
if (typeof args[0] !== 'string') {
return this.#fill(this.browseblobtemplate, { ...args[0], path })
}
return this.#fill(this.browseblobtemplate, { ...args[1], fragment: args[0], path })
}
docs (opts) {
return this.#fill(this.docstemplate, opts)
}
bugs (opts) {
return this.#fill(this.bugstemplate, opts)
}
https (opts) {
return this.#fill(this.httpstemplate, opts)
}
git (opts) {
return this.#fill(this.gittemplate, opts)
}
shortcut (opts) {
return this.#fill(this.shortcuttemplate, opts)
}
path (opts) {
return this.#fill(this.pathtemplate, opts)
}
tarball (opts) {
return this.#fill(this.tarballtemplate, { ...opts, noCommittish: false })
}
file (path, opts) {
return this.#fill(this.filetemplate, { ...opts, path })
}
edit (path, opts) {
return this.#fill(this.edittemplate, { ...opts, path })
}
getDefaultRepresentation () {
return this.default
}
toString (opts) {
if (this.default && typeof this[this.default] === 'function') {
return this[this.default](opts)
}
return this.sshurl(opts)
}
}
for (const [name, host] of Object.entries(hosts)) {
GitHost.addHost(name, host)
}
module.exports = GitHost
hosted-git-info-9.0.2/lib/parse-url.js 0000664 0000000 0000000 00000005271 15071511065 0017546 0 ustar 00root root 0000000 0000000 const url = require('url')
const lastIndexOfBefore = (str, char, beforeChar) => {
const startPosition = str.indexOf(beforeChar)
return str.lastIndexOf(char, startPosition > -1 ? startPosition : Infinity)
}
const safeUrl = (u) => {
try {
return new url.URL(u)
} catch {
// this fn should never throw
}
}
// accepts input like git:github.com:user/repo and inserts the // after the first :
const correctProtocol = (arg, protocols) => {
const firstColon = arg.indexOf(':')
const proto = arg.slice(0, firstColon + 1)
if (Object.prototype.hasOwnProperty.call(protocols, proto)) {
return arg
}
if (arg.substr(firstColon, 3) === '://') {
// If arg is given as ://, then this is already a valid URL.
return arg
}
const firstAt = arg.indexOf('@')
if (firstAt > -1) {
if (firstAt > firstColon) {
// URL has the form of :@. Assume this is a git+ssh URL.
return `git+ssh://${arg}`
} else {
// URL has the form 'git@github.com:npm/hosted-git-info.git'.
return arg
}
}
// Correct : to ://
return `${arg.slice(0, firstColon + 1)}//${arg.slice(firstColon + 1)}`
}
// attempt to correct an scp style url so that it will parse with `new URL()`
const correctUrl = (giturl) => {
// ignore @ that come after the first hash since the denotes the start
// of a committish which can contain @ characters
const firstAt = lastIndexOfBefore(giturl, '@', '#')
// ignore colons that come after the hash since that could include colons such as:
// git@github.com:user/package-2#semver:^1.0.0
const lastColonBeforeHash = lastIndexOfBefore(giturl, ':', '#')
if (lastColonBeforeHash > firstAt) {
// the last : comes after the first @ (or there is no @)
// like it would in:
// proto://hostname.com:user/repo
// username@hostname.com:user/repo
// :password@hostname.com:user/repo
// username:password@hostname.com:user/repo
// proto://username@hostname.com:user/repo
// proto://:password@hostname.com:user/repo
// proto://username:password@hostname.com:user/repo
// then we replace the last : with a / to create a valid path
giturl = giturl.slice(0, lastColonBeforeHash) + '/' + giturl.slice(lastColonBeforeHash + 1)
}
if (lastIndexOfBefore(giturl, ':', '#') === -1 && giturl.indexOf('//') === -1) {
// we have no : at all
// as it would be in:
// username@hostname.com/user/repo
// then we prepend a protocol
giturl = `git+ssh://${giturl}`
}
return giturl
}
module.exports = (giturl, protocols) => {
const withProtocol = protocols ? correctProtocol(giturl, protocols) : giturl
return safeUrl(withProtocol) || safeUrl(correctUrl(withProtocol))
}
hosted-git-info-9.0.2/package.json 0000664 0000000 0000000 00000002723 15071511065 0017015 0 ustar 00root root 0000000 0000000 {
"name": "hosted-git-info",
"version": "9.0.2",
"description": "Provides metadata and conversions from repository urls for GitHub, Bitbucket and GitLab",
"main": "./lib/index.js",
"repository": {
"type": "git",
"url": "git+https://github.com/npm/hosted-git-info.git"
},
"keywords": [
"git",
"github",
"bitbucket",
"gitlab"
],
"author": "GitHub Inc.",
"license": "ISC",
"bugs": {
"url": "https://github.com/npm/hosted-git-info/issues"
},
"homepage": "https://github.com/npm/hosted-git-info",
"scripts": {
"posttest": "npm run lint",
"snap": "tap",
"test": "tap",
"test:coverage": "tap --coverage-report=html",
"lint": "npm run eslint",
"postlint": "template-oss-check",
"lintfix": "npm run eslint -- --fix",
"template-oss-apply": "template-oss-apply --force",
"eslint": "eslint \"**/*.{js,cjs,ts,mjs,jsx,tsx}\""
},
"dependencies": {
"lru-cache": "^11.1.0"
},
"devDependencies": {
"@npmcli/eslint-config": "^5.0.0",
"@npmcli/template-oss": "4.25.1",
"tap": "^16.0.1"
},
"files": [
"bin/",
"lib/"
],
"engines": {
"node": "^20.17.0 || >=22.9.0"
},
"tap": {
"color": 1,
"coverage": true,
"nyc-arg": [
"--exclude",
"tap-snapshots/**"
]
},
"templateOSS": {
"//@npmcli/template-oss": "This file is partially managed by @npmcli/template-oss. Edits may be overwritten.",
"version": "4.25.1",
"publish": "true"
}
}
hosted-git-info-9.0.2/release-please-config.json 0000664 0000000 0000000 00000001277 15071511065 0021557 0 ustar 00root root 0000000 0000000 {
"group-pull-request-title-pattern": "chore: release ${version}",
"pull-request-title-pattern": "chore: release${component} ${version}",
"changelog-sections": [
{
"type": "feat",
"section": "Features",
"hidden": false
},
{
"type": "fix",
"section": "Bug Fixes",
"hidden": false
},
{
"type": "docs",
"section": "Documentation",
"hidden": false
},
{
"type": "deps",
"section": "Dependencies",
"hidden": false
},
{
"type": "chore",
"section": "Chores",
"hidden": true
}
],
"packages": {
".": {
"package-name": ""
}
},
"prerelease-type": "pre.0"
}
hosted-git-info-9.0.2/test/ 0000775 0000000 0000000 00000000000 15071511065 0015502 5 ustar 00root root 0000000 0000000 hosted-git-info-9.0.2/test/bitbucket.js 0000664 0000000 0000000 00000034312 15071511065 0020017 0 ustar 00root root 0000000 0000000 /* eslint-disable max-len */
'use strict'
const HostedGit = require('..')
const t = require('tap')
const invalid = [
// invalid protocol
'git://bitbucket.org/foo/bar',
// url to get a tarball
'https://bitbucket.org/foo/bar/get/archive.tar.gz',
// missing project
'https://bitbucket.org/foo',
]
const defaults = { type: 'bitbucket', user: 'foo', project: 'bar' }
const valid = {
// shortucts
//
// NOTE auth is accepted but ignored
'bitbucket:foo/bar': { ...defaults, default: 'shortcut' },
'bitbucket:foo/bar#branch': { ...defaults, default: 'shortcut', committish: 'branch' },
'bitbucket:user@foo/bar': { ...defaults, default: 'shortcut', auth: null },
'bitbucket:user@foo/bar#branch': { ...defaults, default: 'shortcut', auth: null, committish: 'branch' },
'bitbucket:user:password@foo/bar': { ...defaults, default: 'shortcut', auth: null },
'bitbucket:user:password@foo/bar#branch': { ...defaults, default: 'shortcut', auth: null, committish: 'branch' },
'bitbucket::password@foo/bar': { ...defaults, default: 'shortcut', auth: null },
'bitbucket::password@foo/bar#branch': { ...defaults, default: 'shortcut', auth: null, committish: 'branch' },
'bitbucket:foo/bar.git': { ...defaults, default: 'shortcut' },
'bitbucket:foo/bar.git#branch': { ...defaults, default: 'shortcut', committish: 'branch' },
'bitbucket:user@foo/bar.git': { ...defaults, default: 'shortcut', auth: null },
'bitbucket:user@foo/bar.git#branch': { ...defaults, default: 'shortcut', auth: null, committish: 'branch' },
'bitbucket:user:password@foo/bar.git': { ...defaults, default: 'shortcut', auth: null },
'bitbucket:user:password@foo/bar.git#branch': { ...defaults, default: 'shortcut', auth: null, committish: 'branch' },
'bitbucket::password@foo/bar.git': { ...defaults, default: 'shortcut', auth: null },
'bitbucket::password@foo/bar.git#branch': { ...defaults, default: 'shortcut', auth: null, committish: 'branch' },
// no-protocol git+ssh
//
// NOTE auth is accepted but ignored
'git@bitbucket.org:foo/bar': { ...defaults, default: 'sshurl', auth: null },
'git@bitbucket.org:foo/bar#branch': { ...defaults, default: 'sshurl', auth: null, committish: 'branch' },
'user@bitbucket.org:foo/bar': { ...defaults, default: 'sshurl', auth: null },
'user@bitbucket.org:foo/bar#branch': { ...defaults, default: 'sshurl', auth: null, committish: 'branch' },
'user:password@bitbucket.org:foo/bar': { ...defaults, default: 'sshurl', auth: null },
'user:password@bitbucket.org:foo/bar#branch': { ...defaults, default: 'sshurl', auth: null, committish: 'branch' },
':password@bitbucket.org:foo/bar': { ...defaults, default: 'sshurl', auth: null },
':password@bitbucket.org:foo/bar#branch': { ...defaults, default: 'sshurl', auth: null, committish: 'branch' },
'git@bitbucket.org:foo/bar.git': { ...defaults, default: 'sshurl', auth: null },
'git@bitbucket.org:foo/bar.git#branch': { ...defaults, default: 'sshurl', auth: null, committish: 'branch' },
'user@bitbucket.org:foo/bar.git': { ...defaults, default: 'sshurl', auth: null },
'user@bitbucket.org:foo/bar.git#branch': { ...defaults, default: 'sshurl', auth: null, committish: 'branch' },
'user:password@bitbucket.org:foo/bar.git': { ...defaults, default: 'sshurl', auth: null },
'user:password@bitbucket.org:foo/bar.git#branch': { ...defaults, default: 'sshurl', auth: null, committish: 'branch' },
':password@bitbucket.org:foo/bar.git': { ...defaults, default: 'sshurl', auth: null },
':password@bitbucket.org:foo/bar.git#branch': { ...defaults, default: 'sshurl', auth: null, committish: 'branch' },
// git+ssh urls
//
// NOTE auth is accepted but ignored
'git+ssh://bitbucket.org:foo/bar': { ...defaults, default: 'sshurl' },
'git+ssh://bitbucket.org:foo/bar#branch': { ...defaults, default: 'sshurl', committish: 'branch' },
'git+ssh://user@bitbucket.org:foo/bar': { ...defaults, default: 'sshurl', auth: null },
'git+ssh://user@bitbucket.org:foo/bar#branch': { ...defaults, default: 'sshurl', auth: null, committish: 'branch' },
'git+ssh://user:password@bitbucket.org:foo/bar': { ...defaults, default: 'sshurl', auth: null },
'git+ssh://user:password@bitbucket.org:foo/bar#branch': { ...defaults, default: 'sshurl', auth: null, committish: 'branch' },
'git+ssh://:password@bitbucket.org:foo/bar': { ...defaults, default: 'sshurl', auth: null },
'git+ssh://:password@bitbucket.org:foo/bar#branch': { ...defaults, default: 'sshurl', auth: null, committish: 'branch' },
'git+ssh://bitbucket.org:foo/bar.git': { ...defaults, default: 'sshurl' },
'git+ssh://bitbucket.org:foo/bar.git#branch': { ...defaults, default: 'sshurl', committish: 'branch' },
'git+ssh://user@bitbucket.org:foo/bar.git': { ...defaults, default: 'sshurl', auth: null },
'git+ssh://user@bitbucket.org:foo/bar.git#branch': { ...defaults, default: 'sshurl', auth: null, committish: 'branch' },
'git+ssh://user:password@bitbucket.org:foo/bar.git': { ...defaults, default: 'sshurl', auth: null },
'git+ssh://user:password@bitbucket.org:foo/bar.git#branch': { ...defaults, default: 'sshurl', auth: null, committish: 'branch' },
'git+ssh://:password@bitbucket.org:foo/bar.git': { ...defaults, default: 'sshurl', auth: null },
'git+ssh://:password@bitbucket.org:foo/bar.git#branch': { ...defaults, default: 'sshurl', auth: null, committish: 'branch' },
// ssh urls
//
// NOTE auth is accepted but ignored
'ssh://bitbucket.org:foo/bar': { ...defaults, default: 'sshurl' },
'ssh://bitbucket.org:foo/bar#branch': { ...defaults, default: 'sshurl', committish: 'branch' },
'ssh://user@bitbucket.org:foo/bar': { ...defaults, default: 'sshurl', auth: null },
'ssh://user@bitbucket.org:foo/bar#branch': { ...defaults, default: 'sshurl', auth: null, committish: 'branch' },
'ssh://user:password@bitbucket.org:foo/bar': { ...defaults, default: 'sshurl', auth: null },
'ssh://user:password@bitbucket.org:foo/bar#branch': { ...defaults, default: 'sshurl', auth: null, committish: 'branch' },
'ssh://:password@bitbucket.org:foo/bar': { ...defaults, default: 'sshurl', auth: null },
'ssh://:password@bitbucket.org:foo/bar#branch': { ...defaults, default: 'sshurl', auth: null, committish: 'branch' },
'ssh://bitbucket.org:foo/bar.git': { ...defaults, default: 'sshurl' },
'ssh://bitbucket.org:foo/bar.git#branch': { ...defaults, default: 'sshurl', committish: 'branch' },
'ssh://user@bitbucket.org:foo/bar.git': { ...defaults, default: 'sshurl', auth: null },
'ssh://user@bitbucket.org:foo/bar.git#branch': { ...defaults, default: 'sshurl', auth: null, committish: 'branch' },
'ssh://user:password@bitbucket.org:foo/bar.git': { ...defaults, default: 'sshurl', auth: null },
'ssh://user:password@bitbucket.org:foo/bar.git#branch': { ...defaults, default: 'sshurl', auth: null, committish: 'branch' },
'ssh://:password@bitbucket.org:foo/bar.git': { ...defaults, default: 'sshurl', auth: null },
'ssh://:password@bitbucket.org:foo/bar.git#branch': { ...defaults, default: 'sshurl', auth: null, committish: 'branch' },
// git+https urls
//
// NOTE auth is accepted and respected
'git+https://bitbucket.org/foo/bar': { ...defaults, default: 'https' },
'git+https://bitbucket.org/foo/bar#branch': { ...defaults, default: 'https', committish: 'branch' },
'git+https://user@bitbucket.org/foo/bar': { ...defaults, default: 'https', auth: 'user' },
'git+https://user@bitbucket.org/foo/bar#branch': { ...defaults, default: 'https', auth: 'user', committish: 'branch' },
'git+https://user:password@bitbucket.org/foo/bar': { ...defaults, default: 'https', auth: 'user:password' },
'git+https://user:password@bitbucket.org/foo/bar#branch': { ...defaults, default: 'https', auth: 'user:password', committish: 'branch' },
'git+https://:password@bitbucket.org/foo/bar': { ...defaults, default: 'https', auth: ':password' },
'git+https://:password@bitbucket.org/foo/bar#branch': { ...defaults, default: 'https', auth: ':password', committish: 'branch' },
'git+https://bitbucket.org/foo/bar.git': { ...defaults, default: 'https' },
'git+https://bitbucket.org/foo/bar.git#branch': { ...defaults, default: 'https', committish: 'branch' },
'git+https://user@bitbucket.org/foo/bar.git': { ...defaults, default: 'https', auth: 'user' },
'git+https://user@bitbucket.org/foo/bar.git#branch': { ...defaults, default: 'https', auth: 'user', committish: 'branch' },
'git+https://user:password@bitbucket.org/foo/bar.git': { ...defaults, default: 'https', auth: 'user:password' },
'git+https://user:password@bitbucket.org/foo/bar.git#branch': { ...defaults, default: 'https', auth: 'user:password', committish: 'branch' },
'git+https://:password@bitbucket.org/foo/bar.git': { ...defaults, default: 'https', auth: ':password' },
'git+https://:password@bitbucket.org/foo/bar.git#branch': { ...defaults, default: 'https', auth: ':password', committish: 'branch' },
// https urls
//
// NOTE auth is accepted and respected
'https://bitbucket.org/foo/bar': { ...defaults, default: 'https' },
'https://bitbucket.org/foo/bar#branch': { ...defaults, default: 'https', committish: 'branch' },
'https://user@bitbucket.org/foo/bar': { ...defaults, default: 'https', auth: 'user' },
'https://user@bitbucket.org/foo/bar#branch': { ...defaults, default: 'https', auth: 'user', committish: 'branch' },
'https://user:password@bitbucket.org/foo/bar': { ...defaults, default: 'https', auth: 'user:password' },
'https://user:password@bitbucket.org/foo/bar#branch': { ...defaults, default: 'https', auth: 'user:password', committish: 'branch' },
'https://:password@bitbucket.org/foo/bar': { ...defaults, default: 'https', auth: ':password' },
'https://:password@bitbucket.org/foo/bar#branch': { ...defaults, default: 'https', auth: ':password', committish: 'branch' },
'https://bitbucket.org/foo/bar.git': { ...defaults, default: 'https' },
'https://bitbucket.org/foo/bar.git#branch': { ...defaults, default: 'https', committish: 'branch' },
'https://user@bitbucket.org/foo/bar.git': { ...defaults, default: 'https', auth: 'user' },
'https://user@bitbucket.org/foo/bar.git#branch': { ...defaults, default: 'https', auth: 'user', committish: 'branch' },
'https://user:password@bitbucket.org/foo/bar.git': { ...defaults, default: 'https', auth: 'user:password' },
'https://user:password@bitbucket.org/foo/bar.git#branch': { ...defaults, default: 'https', auth: 'user:password', committish: 'branch' },
'https://:password@bitbucket.org/foo/bar.git': { ...defaults, default: 'https', auth: ':password' },
'https://:password@bitbucket.org/foo/bar.git#branch': { ...defaults, default: 'https', auth: ':password', committish: 'branch' },
}
t.test('valid urls parse properly', t => {
t.plan(Object.keys(valid).length)
for (const [url, result] of Object.entries(valid)) {
t.hasStrict(HostedGit.fromUrl(url), result, `${url} parses`)
}
})
t.test('invalid urls return undefined', t => {
t.plan(invalid.length)
for (const url of invalid) {
t.equal(HostedGit.fromUrl(url), undefined, `${url} returns undefined`)
}
})
t.test('toString respects defaults', t => {
const sshurl = HostedGit.fromUrl('git+ssh://bitbucket.org/foo/bar')
t.equal(sshurl.default, 'sshurl', 'got the right default')
t.equal(sshurl.toString(), sshurl.sshurl(), 'toString calls sshurl')
const https = HostedGit.fromUrl('https://bitbucket.org/foo/bar')
t.equal(https.default, 'https', 'got the right default')
t.equal(https.toString(), https.https(), 'toString calls https')
const shortcut = HostedGit.fromUrl('bitbucket:foo/bar')
t.equal(shortcut.default, 'shortcut', 'got the right default')
t.equal(shortcut.toString(), shortcut.shortcut(), 'toString calls shortcut')
t.end()
})
t.test('string methods populate correctly', t => {
const parsed = HostedGit.fromUrl('git+ssh://bitbucket.org/foo/bar')
t.equal(parsed.getDefaultRepresentation(), parsed.default, 'getDefaultRepresentation()')
t.equal(parsed.hash(), '', 'hash() returns empty string when committish is unset')
t.equal(parsed.ssh(), 'git@bitbucket.org:foo/bar.git')
t.equal(parsed.sshurl(), 'git+ssh://git@bitbucket.org/foo/bar.git')
t.equal(parsed.edit(), 'https://bitbucket.org/foo/bar')
t.equal(parsed.edit('/lib/index.js'), 'https://bitbucket.org/foo/bar/src/HEAD/lib/index.js?mode=edit')
t.equal(parsed.browse(), 'https://bitbucket.org/foo/bar')
t.equal(parsed.browse('/lib/index.js'), 'https://bitbucket.org/foo/bar/src/HEAD/lib/index.js')
t.equal(parsed.browse('/lib/index.js', 'L100'), 'https://bitbucket.org/foo/bar/src/HEAD/lib/index.js#l100')
t.equal(parsed.docs(), 'https://bitbucket.org/foo/bar#readme')
t.equal(parsed.https(), 'git+https://bitbucket.org/foo/bar.git')
t.equal(parsed.shortcut(), 'bitbucket:foo/bar')
t.equal(parsed.path(), 'foo/bar')
t.equal(parsed.tarball(), 'https://bitbucket.org/foo/bar/get/HEAD.tar.gz')
t.equal(parsed.file(), 'https://bitbucket.org/foo/bar/raw/HEAD/')
t.equal(parsed.file('/lib/index.js'), 'https://bitbucket.org/foo/bar/raw/HEAD/lib/index.js')
t.equal(parsed.bugs(), 'https://bitbucket.org/foo/bar/issues')
t.equal(parsed.docs({ committish: 'fix/bug' }), 'https://bitbucket.org/foo/bar/src/fix%2Fbug#readme', 'allows overriding options')
t.same(parsed.git(), null, 'git() returns null')
const extra = HostedGit.fromUrl('https://user@bitbucket.org/foo/bar#fix/bug')
t.equal(extra.hash(), '#fix/bug')
t.equal(extra.https(), 'git+https://user@bitbucket.org/foo/bar.git#fix/bug')
t.equal(extra.shortcut(), 'bitbucket:foo/bar#fix/bug')
t.equal(extra.ssh(), 'git@bitbucket.org:foo/bar.git#fix/bug')
t.equal(extra.sshurl(), 'git+ssh://git@bitbucket.org/foo/bar.git#fix/bug')
t.equal(extra.browse(), 'https://bitbucket.org/foo/bar/src/fix%2Fbug')
t.equal(extra.browse('/lib/index.js'), 'https://bitbucket.org/foo/bar/src/fix%2Fbug/lib/index.js')
t.equal(extra.browse('/lib/index.js', 'L200'), 'https://bitbucket.org/foo/bar/src/fix%2Fbug/lib/index.js#l200')
t.equal(extra.docs(), 'https://bitbucket.org/foo/bar/src/fix%2Fbug#readme')
t.equal(extra.file(), 'https://bitbucket.org/foo/bar/raw/fix%2Fbug/')
t.equal(extra.file('/lib/index.js'), 'https://bitbucket.org/foo/bar/raw/fix%2Fbug/lib/index.js')
t.equal(extra.sshurl({ noCommittish: true }), 'git+ssh://git@bitbucket.org/foo/bar.git', 'noCommittish drops committish from urls')
t.equal(extra.sshurl({ noGitPlus: true }), 'ssh://git@bitbucket.org/foo/bar.git#fix/bug', 'noGitPlus drops git+ prefix from urls')
t.end()
})
hosted-git-info-9.0.2/test/file.js 0000664 0000000 0000000 00000000376 15071511065 0016765 0 ustar 00root root 0000000 0000000 const HostedGit = require('..')
const t = require('tap')
t.test('file:// URLs', t => {
const fileRepo = {
name: 'foo',
repository: {
url: 'file:///path/dot.git',
},
}
t.equal(HostedGit.fromManifest(fileRepo), null)
t.end()
})
hosted-git-info-9.0.2/test/gist.js 0000664 0000000 0000000 00000077004 15071511065 0017016 0 ustar 00root root 0000000 0000000 /* eslint-disable max-len */
'use strict'
const HostedGit = require('..')
const t = require('tap')
const invalid = [
// raw urls that are wrong anyway but for some reason are in the wild
'https://gist.github.com/foo/feedbeef/raw/fix%2Fbug/',
// missing both user and project
'https://gist.github.com/',
]
const defaults = { type: 'gist', user: null, project: 'feedbeef' }
const valid = {
// shortcuts
//
// NOTE auth is accepted but ignored
'gist:feedbeef': { ...defaults, default: 'shortcut' },
'gist:feedbeef#branch': { ...defaults, default: 'shortcut', committish: 'branch' },
'gist:user@feedbeef': { ...defaults, default: 'shortcut', auth: null },
'gist:user@feedbeef#branch': { ...defaults, default: 'shortcut', auth: null, committish: 'branch' },
'gist:user:password@feedbeef': { ...defaults, default: 'shortcut', auth: null },
'gist:user:password@feedbeef#branch': { ...defaults, default: 'shortcut', auth: null, committish: 'branch' },
'gist::password@feedbeef': { ...defaults, default: 'shortcut', auth: null },
'gist::password@feedbeef#branch': { ...defaults, default: 'shortcut', auth: null, committish: 'branch' },
'gist:feedbeef.git': { ...defaults, default: 'shortcut' },
'gist:feedbeef.git#branch': { ...defaults, default: 'shortcut', committish: 'branch' },
'gist:user@feedbeef.git': { ...defaults, default: 'shortcut', auth: null },
'gist:user@feedbeef.git#branch': { ...defaults, default: 'shortcut', auth: null, committish: 'branch' },
'gist:user:password@feedbeef.git': { ...defaults, default: 'shortcut', auth: null },
'gist:user:password@feedbeef.git#branch': { ...defaults, default: 'shortcut', auth: null, committish: 'branch' },
'gist::password@feedbeef.git': { ...defaults, default: 'shortcut', auth: null },
'gist::password@feedbeef.git#branch': { ...defaults, default: 'shortcut', auth: null, committish: 'branch' },
'gist:/feedbeef': { ...defaults, default: 'shortcut' },
'gist:/feedbeef#branch': { ...defaults, default: 'shortcut', committish: 'branch' },
'gist:user@/feedbeef': { ...defaults, default: 'shortcut', auth: null },
'gist:user@/feedbeef#branch': { ...defaults, default: 'shortcut', auth: null, committish: 'branch' },
'gist:user:password@/feedbeef': { ...defaults, default: 'shortcut', auth: null },
'gist:user:password@/feedbeef#branch': { ...defaults, default: 'shortcut', auth: null, committish: 'branch' },
'gist::password@/feedbeef': { ...defaults, default: 'shortcut', auth: null },
'gist::password@/feedbeef#branch': { ...defaults, default: 'shortcut', auth: null, committish: 'branch' },
'gist:/feedbeef.git': { ...defaults, default: 'shortcut' },
'gist:/feedbeef.git#branch': { ...defaults, default: 'shortcut', committish: 'branch' },
'gist:user@/feedbeef.git': { ...defaults, default: 'shortcut', auth: null },
'gist:user@/feedbeef.git#branch': { ...defaults, default: 'shortcut', auth: null, committish: 'branch' },
'gist:user:password@/feedbeef.git': { ...defaults, default: 'shortcut', auth: null },
'gist:user:password@/feedbeef.git#branch': { ...defaults, default: 'shortcut', auth: null, committish: 'branch' },
'gist::password@/feedbeef.git': { ...defaults, default: 'shortcut', auth: null },
'gist::password@/feedbeef.git#branch': { ...defaults, default: 'shortcut', auth: null, committish: 'branch' },
'gist:foo/feedbeef': { ...defaults, default: 'shortcut', user: 'foo' },
'gist:foo/feedbeef#branch': { ...defaults, default: 'shortcut', user: 'foo', committish: 'branch' },
'gist:user@foo/feedbeef': { ...defaults, default: 'shortcut', user: 'foo', auth: null },
'gist:user@foo/feedbeef#branch': { ...defaults, default: 'shortcut', user: 'foo', auth: null, committish: 'branch' },
'gist:user:password@foo/feedbeef': { ...defaults, default: 'shortcut', user: 'foo', auth: null },
'gist:user:password@foo/feedbeef#branch': { ...defaults, default: 'shortcut', user: 'foo', auth: null, committish: 'branch' },
'gist::password@foo/feedbeef': { ...defaults, default: 'shortcut', user: 'foo', auth: null },
'gist::password@foo/feedbeef#branch': { ...defaults, default: 'shortcut', user: 'foo', auth: null, committish: 'branch' },
'gist:foo/feedbeef.git': { ...defaults, default: 'shortcut', user: 'foo' },
'gist:foo/feedbeef.git#branch': { ...defaults, default: 'shortcut', user: 'foo', committish: 'branch' },
'gist:user@foo/feedbeef.git': { ...defaults, default: 'shortcut', user: 'foo', auth: null },
'gist:user@foo/feedbeef.git#branch': { ...defaults, default: 'shortcut', user: 'foo', auth: null, committish: 'branch' },
'gist:user:password@foo/feedbeef.git': { ...defaults, default: 'shortcut', user: 'foo', auth: null },
'gist:user:password@foo/feedbeef.git#branch': { ...defaults, default: 'shortcut', user: 'foo', auth: null, committish: 'branch' },
'gist::password@foo/feedbeef.git': { ...defaults, default: 'shortcut', user: 'foo', auth: null },
'gist::password@foo/feedbeef.git#branch': { ...defaults, default: 'shortcut', user: 'foo', auth: null, committish: 'branch' },
// git urls
//
// NOTE auth is accepted and respected
'git://gist.github.com/feedbeef': { ...defaults, default: 'git' },
'git://gist.github.com/feedbeef#branch': { ...defaults, default: 'git', committish: 'branch' },
'git://user@gist.github.com/feedbeef': { ...defaults, default: 'git', auth: 'user' },
'git://user@gist.github.com/feedbeef#branch': { ...defaults, default: 'git', auth: 'user', committish: 'branch' },
'git://user:password@gist.github.com/feedbeef': { ...defaults, default: 'git', auth: 'user:password' },
'git://user:password@gist.github.com/feedbeef#branch': { ...defaults, default: 'git', auth: 'user:password', committish: 'branch' },
'git://:password@gist.github.com/feedbeef': { ...defaults, default: 'git', auth: ':password' },
'git://:password@gist.github.com/feedbeef#branch': { ...defaults, default: 'git', auth: ':password', committish: 'branch' },
'git://gist.github.com/feedbeef.git': { ...defaults, default: 'git' },
'git://gist.github.com/feedbeef.git#branch': { ...defaults, default: 'git', committish: 'branch' },
'git://user@gist.github.com/feedbeef.git': { ...defaults, default: 'git', auth: 'user' },
'git://user@gist.github.com/feedbeef.git#branch': { ...defaults, default: 'git', auth: 'user', committish: 'branch' },
'git://user:password@gist.github.com/feedbeef.git': { ...defaults, default: 'git', auth: 'user:password' },
'git://user:password@gist.github.com/feedbeef.git#branch': { ...defaults, default: 'git', auth: 'user:password', committish: 'branch' },
'git://:password@gist.github.com/feedbeef.git': { ...defaults, default: 'git', auth: ':password' },
'git://:password@gist.github.com/feedbeef.git#branch': { ...defaults, default: 'git', auth: ':password', committish: 'branch' },
'git://gist.github.com/foo/feedbeef': { ...defaults, default: 'git', user: 'foo' },
'git://gist.github.com/foo/feedbeef#branch': { ...defaults, default: 'git', user: 'foo', committish: 'branch' },
'git://user@gist.github.com/foo/feedbeef': { ...defaults, default: 'git', user: 'foo', auth: 'user' },
'git://user@gist.github.com/foo/feedbeef#branch': { ...defaults, default: 'git', user: 'foo', auth: 'user', committish: 'branch' },
'git://user:password@gist.github.com/foo/feedbeef': { ...defaults, default: 'git', user: 'foo', auth: 'user:password' },
'git://user:password@gist.github.com/foo/feedbeef#branch': { ...defaults, default: 'git', user: 'foo', auth: 'user:password', committish: 'branch' },
'git://:password@gist.github.com/foo/feedbeef': { ...defaults, default: 'git', user: 'foo', auth: ':password' },
'git://:password@gist.github.com/foo/feedbeef#branch': { ...defaults, default: 'git', user: 'foo', auth: ':password', committish: 'branch' },
'git://gist.github.com/foo/feedbeef.git': { ...defaults, default: 'git', user: 'foo' },
'git://gist.github.com/foo/feedbeef.git#branch': { ...defaults, default: 'git', user: 'foo', committish: 'branch' },
'git://user@gist.github.com/foo/feedbeef.git': { ...defaults, default: 'git', user: 'foo', auth: 'user' },
'git://user@gist.github.com/foo/feedbeef.git#branch': { ...defaults, default: 'git', user: 'foo', auth: 'user', committish: 'branch' },
'git://user:password@gist.github.com/foo/feedbeef.git': { ...defaults, default: 'git', user: 'foo', auth: 'user:password' },
'git://user:password@gist.github.com/foo/feedbeef.git#branch': { ...defaults, default: 'git', user: 'foo', auth: 'user:password', committish: 'branch' },
'git://:password@gist.github.com/foo/feedbeef.git': { ...defaults, default: 'git', user: 'foo', auth: ':password' },
'git://:password@gist.github.com/foo/feedbeef.git#branch': { ...defaults, default: 'git', user: 'foo', auth: ':password', committish: 'branch' },
// no-protocol git+ssh
//
// NOTE auth is accepted and ignored
'git@gist.github.com:feedbeef': { ...defaults, default: 'sshurl', auth: null },
'git@gist.github.com:feedbeef#branch': { ...defaults, default: 'sshurl', auth: null, committish: 'branch' },
'user@gist.github.com:feedbeef': { ...defaults, default: 'sshurl', auth: null },
'user@gist.github.com:feedbeef#branch': { ...defaults, default: 'sshurl', auth: null, committish: 'branch' },
'user:password@gist.github.com:feedbeef': { ...defaults, default: 'sshurl', auth: null },
'user:password@gist.github.com:feedbeef#branch': { ...defaults, default: 'sshurl', auth: null, committish: 'branch' },
':password@gist.github.com:feedbeef': { ...defaults, default: 'sshurl', auth: null },
':password@gist.github.com:feedbeef#branch': { ...defaults, default: 'sshurl', auth: null, committish: 'branch' },
'git@gist.github.com:feedbeef.git': { ...defaults, default: 'sshurl', auth: null },
'git@gist.github.com:feedbeef.git#branch': { ...defaults, default: 'sshurl', committish: 'branch', auth: null },
'user@gist.github.com:feedbeef.git': { ...defaults, default: 'sshurl', auth: null },
'user@gist.github.com:feedbeef.git#branch': { ...defaults, default: 'sshurl', auth: null, committish: 'branch' },
'user:password@gist.github.com:feedbeef.git': { ...defaults, default: 'sshurl', auth: null },
'user:password@gist.github.com:feedbeef.git#branch': { ...defaults, default: 'sshurl', auth: null, committish: 'branch' },
':password@gist.github.com:feedbeef.git': { ...defaults, default: 'sshurl', auth: null },
':password@gist.github.com:feedbeef.git#branch': { ...defaults, default: 'sshurl', auth: null, committish: 'branch' },
'git@gist.github.com:foo/feedbeef': { ...defaults, default: 'sshurl', auth: null, user: 'foo' },
'git@gist.github.com:foo/feedbeef#branch': { ...defaults, default: 'sshurl', auth: null, user: 'foo', committish: 'branch' },
'user@gist.github.com:foo/feedbeef': { ...defaults, default: 'sshurl', auth: null, user: 'foo' },
'user@gist.github.com:foo/feedbeef#branch': { ...defaults, default: 'sshurl', auth: null, user: 'foo', committish: 'branch' },
'user:password@gist.github.com:foo/feedbeef': { ...defaults, default: 'sshurl', auth: null, user: 'foo' },
'user:password@gist.github.com:foo/feedbeef#branch': { ...defaults, default: 'sshurl', auth: null, user: 'foo', committish: 'branch' },
':password@gist.github.com:foo/feedbeef': { ...defaults, default: 'sshurl', auth: null, user: 'foo' },
':password@gist.github.com:foo/feedbeef#branch': { ...defaults, default: 'sshurl', auth: null, user: 'foo', committish: 'branch' },
'git@gist.github.com:foo/feedbeef.git': { ...defaults, default: 'sshurl', auth: null, user: 'foo' },
'git@gist.github.com:foo/feedbeef.git#branch': { ...defaults, default: 'sshurl', auth: null, user: 'foo', committish: 'branch' },
'user@gist.github.com:foo/feedbeef.git': { ...defaults, default: 'sshurl', auth: null, user: 'foo' },
'user@gist.github.com:foo/feedbeef.git#branch': { ...defaults, default: 'sshurl', auth: null, user: 'foo', committish: 'branch' },
'user:password@gist.github.com:foo/feedbeef.git': { ...defaults, default: 'sshurl', auth: null, user: 'foo' },
'user:password@gist.github.com:foo/feedbeef.git#branch': { ...defaults, default: 'sshurl', auth: null, user: 'foo', committish: 'branch' },
':password@gist.github.com:foo/feedbeef.git': { ...defaults, default: 'sshurl', auth: null, user: 'foo' },
':password@gist.github.com:foo/feedbeef.git#branch': { ...defaults, default: 'sshurl', auth: null, user: 'foo', committish: 'branch' },
// git+ssh urls
//
// NOTE auth is accepted but ignored
// NOTE see TODO at list of invalids, some inputs fail and shouldn't
'git+ssh://gist.github.com:feedbeef': { ...defaults, default: 'sshurl', auth: null },
'git+ssh://gist.github.com:feedbeef#branch': { ...defaults, default: 'sshurl', auth: null, committish: 'branch' },
'git+ssh://user@gist.github.com:feedbeef': { ...defaults, default: 'sshurl', auth: null },
'git+ssh://user@gist.github.com:feedbeef#branch': { ...defaults, default: 'sshurl', auth: null, committish: 'branch' },
'git+ssh://user:password@gist.github.com:feedbeef': { ...defaults, default: 'sshurl', auth: null },
'git+ssh://user:password@gist.github.com:feedbeef#branch': { ...defaults, default: 'sshurl', auth: null, committish: 'branch' },
'git+ssh://:password@gist.github.com:feedbeef': { ...defaults, default: 'sshurl', auth: null },
'git+ssh://:password@gist.github.com:feedbeef#branch': { ...defaults, default: 'sshurl', auth: null, committish: 'branch' },
'git+ssh://gist.github.com:feedbeef.git': { ...defaults, default: 'sshurl', auth: null },
'git+ssh://gist.github.com:feedbeef.git#branch': { ...defaults, default: 'sshurl', auth: null, committish: 'branch' },
'git+ssh://user@gist.github.com:feedbeef.git': { ...defaults, default: 'sshurl', auth: null },
'git+ssh://user@gist.github.com:feedbeef.git#branch': { ...defaults, default: 'sshurl', auth: null, committish: 'branch' },
'git+ssh://user:password@gist.github.com:feedbeef.git': { ...defaults, default: 'sshurl', auth: null },
'git+ssh://user:password@gist.github.com:feedbeef.git#branch': { ...defaults, default: 'sshurl', auth: null, committish: 'branch' },
'git+ssh://:password@gist.github.com:feedbeef.git': { ...defaults, default: 'sshurl', auth: null },
'git+ssh://:password@gist.github.com:feedbeef.git#branch': { ...defaults, default: 'sshurl', auth: null, committish: 'branch' },
'git+ssh://gist.github.com:foo/feedbeef': { ...defaults, default: 'sshurl', user: 'foo' },
'git+ssh://gist.github.com:foo/feedbeef#branch': { ...defaults, default: 'sshurl', user: 'foo', committish: 'branch' },
'git+ssh://user@gist.github.com:foo/feedbeef': { ...defaults, default: 'sshurl', auth: null, user: 'foo' },
'git+ssh://user@gist.github.com:foo/feedbeef#branch': { ...defaults, default: 'sshurl', auth: null, user: 'foo', committish: 'branch' },
'git+ssh://user:password@gist.github.com:foo/feedbeef': { ...defaults, default: 'sshurl', auth: null, user: 'foo' },
'git+ssh://user:password@gist.github.com:foo/feedbeef#branch': { ...defaults, default: 'sshurl', auth: null, user: 'foo', committish: 'branch' },
'git+ssh://:password@gist.github.com:foo/feedbeef': { ...defaults, default: 'sshurl', auth: null, user: 'foo' },
'git+ssh://:password@gist.github.com:foo/feedbeef#branch': { ...defaults, default: 'sshurl', auth: null, user: 'foo', committish: 'branch' },
'git+ssh://gist.github.com:foo/feedbeef.git': { ...defaults, default: 'sshurl', user: 'foo' },
'git+ssh://gist.github.com:foo/feedbeef.git#branch': { ...defaults, default: 'sshurl', user: 'foo', committish: 'branch' },
'git+ssh://user@gist.github.com:foo/feedbeef.git': { ...defaults, default: 'sshurl', auth: null, user: 'foo' },
'git+ssh://user@gist.github.com:foo/feedbeef.git#branch': { ...defaults, default: 'sshurl', auth: null, user: 'foo', committish: 'branch' },
'git+ssh://user:password@gist.github.com:foo/feedbeef.git': { ...defaults, default: 'sshurl', auth: null, user: 'foo' },
'git+ssh://user:password@gist.github.com:foo/feedbeef.git#branch': { ...defaults, default: 'sshurl', auth: null, user: 'foo', committish: 'branch' },
'git+ssh://:password@gist.github.com:foo/feedbeef.git': { ...defaults, default: 'sshurl', auth: null, user: 'foo' },
'git+ssh://:password@gist.github.com:foo/feedbeef.git#branch': { ...defaults, default: 'sshurl', auth: null, user: 'foo', committish: 'branch' },
// ssh urls
//
// NOTE auth is accepted but ignored
'ssh://gist.github.com:feedbeef': { ...defaults, default: 'sshurl', auth: null },
'ssh://gist.github.com:feedbeef#branch': { ...defaults, default: 'sshurl', auth: null, committish: 'branch' },
'ssh://user@gist.github.com:feedbeef': { ...defaults, default: 'sshurl', auth: null },
'ssh://user@gist.github.com:feedbeef#branch': { ...defaults, default: 'sshurl', auth: null, committish: 'branch' },
'ssh://user:password@gist.github.com:feedbeef': { ...defaults, default: 'sshurl', auth: null },
'ssh://user:password@gist.github.com:feedbeef#branch': { ...defaults, default: 'sshurl', auth: null, committish: 'branch' },
'ssh://:password@gist.github.com:feedbeef': { ...defaults, default: 'sshurl', auth: null },
'ssh://:password@gist.github.com:feedbeef#branch': { ...defaults, default: 'sshurl', auth: null, committish: 'branch' },
'ssh://gist.github.com:feedbeef.git': { ...defaults, default: 'sshurl', auth: null },
'ssh://gist.github.com:feedbeef.git#branch': { ...defaults, default: 'sshurl', auth: null, committish: 'branch' },
'ssh://user@gist.github.com:feedbeef.git': { ...defaults, default: 'sshurl', auth: null },
'ssh://user@gist.github.com:feedbeef.git#branch': { ...defaults, default: 'sshurl', auth: null, committish: 'branch' },
'ssh://user:password@gist.github.com:feedbeef.git': { ...defaults, default: 'sshurl', auth: null },
'ssh://user:password@gist.github.com:feedbeef.git#branch': { ...defaults, default: 'sshurl', auth: null, committish: 'branch' },
'ssh://:password@gist.github.com:feedbeef.git': { ...defaults, default: 'sshurl', auth: null },
'ssh://:password@gist.github.com:feedbeef.git#branch': { ...defaults, default: 'sshurl', auth: null, committish: 'branch' },
'ssh://gist.github.com:foo/feedbeef': { ...defaults, default: 'sshurl', user: 'foo' },
'ssh://gist.github.com:foo/feedbeef#branch': { ...defaults, default: 'sshurl', user: 'foo', committish: 'branch' },
'ssh://user@gist.github.com:foo/feedbeef': { ...defaults, default: 'sshurl', auth: null, user: 'foo' },
'ssh://user@gist.github.com:foo/feedbeef#branch': { ...defaults, default: 'sshurl', auth: null, user: 'foo', committish: 'branch' },
'ssh://user:password@gist.github.com:foo/feedbeef': { ...defaults, default: 'sshurl', auth: null, user: 'foo' },
'ssh://user:password@gist.github.com:foo/feedbeef#branch': { ...defaults, default: 'sshurl', auth: null, user: 'foo', committish: 'branch' },
'ssh://:password@gist.github.com:foo/feedbeef': { ...defaults, default: 'sshurl', auth: null, user: 'foo' },
'ssh://:password@gist.github.com:foo/feedbeef#branch': { ...defaults, default: 'sshurl', auth: null, user: 'foo', committish: 'branch' },
'ssh://gist.github.com:foo/feedbeef.git': { ...defaults, default: 'sshurl', user: 'foo' },
'ssh://gist.github.com:foo/feedbeef.git#branch': { ...defaults, default: 'sshurl', user: 'foo', committish: 'branch' },
'ssh://user@gist.github.com:foo/feedbeef.git': { ...defaults, default: 'sshurl', auth: null, user: 'foo' },
'ssh://user@gist.github.com:foo/feedbeef.git#branch': { ...defaults, default: 'sshurl', auth: null, user: 'foo', committish: 'branch' },
'ssh://user:password@gist.github.com:foo/feedbeef.git': { ...defaults, default: 'sshurl', auth: null, user: 'foo' },
'ssh://user:password@gist.github.com:foo/feedbeef.git#branch': { ...defaults, default: 'sshurl', auth: null, user: 'foo', committish: 'branch' },
'ssh://:password@gist.github.com:foo/feedbeef.git': { ...defaults, default: 'sshurl', auth: null, user: 'foo' },
'ssh://:password@gist.github.com:foo/feedbeef.git#branch': { ...defaults, default: 'sshurl', auth: null, user: 'foo', committish: 'branch' },
// git+https urls
//
// NOTE auth is accepted and respected
'git+https://gist.github.com/feedbeef': { ...defaults, default: 'https' },
'git+https://gist.github.com/feedbeef#branch': { ...defaults, default: 'https', committish: 'branch' },
'git+https://user@gist.github.com/feedbeef': { ...defaults, default: 'https', auth: 'user' },
'git+https://user@gist.github.com/feedbeef#branch': { ...defaults, default: 'https', auth: 'user', committish: 'branch' },
'git+https://user:password@gist.github.com/feedbeef': { ...defaults, default: 'https', auth: 'user:password' },
'git+https://user:password@gist.github.com/feedbeef#branch': { ...defaults, default: 'https', auth: 'user:password', committish: 'branch' },
'git+https://:password@gist.github.com/feedbeef': { ...defaults, default: 'https', auth: ':password' },
'git+https://:password@gist.github.com/feedbeef#branch': { ...defaults, default: 'https', auth: ':password', committish: 'branch' },
'git+https://gist.github.com/feedbeef.git': { ...defaults, default: 'https' },
'git+https://gist.github.com/feedbeef.git#branch': { ...defaults, default: 'https', committish: 'branch' },
'git+https://user@gist.github.com/feedbeef.git': { ...defaults, default: 'https', auth: 'user' },
'git+https://user@gist.github.com/feedbeef.git#branch': { ...defaults, default: 'https', auth: 'user', committish: 'branch' },
'git+https://user:password@gist.github.com/feedbeef.git': { ...defaults, default: 'https', auth: 'user:password' },
'git+https://user:password@gist.github.com/feedbeef.git#branch': { ...defaults, default: 'https', auth: 'user:password', committish: 'branch' },
'git+https://:password@gist.github.com/feedbeef.git': { ...defaults, default: 'https', auth: ':password' },
'git+https://:password@gist.github.com/feedbeef.git#branch': { ...defaults, default: 'https', auth: ':password', committish: 'branch' },
'git+https://gist.github.com/foo/feedbeef': { ...defaults, default: 'https', user: 'foo' },
'git+https://gist.github.com/foo/feedbeef#branch': { ...defaults, default: 'https', user: 'foo', committish: 'branch' },
'git+https://user@gist.github.com/foo/feedbeef': { ...defaults, default: 'https', auth: 'user', user: 'foo' },
'git+https://user@gist.github.com/foo/feedbeef#branch': { ...defaults, default: 'https', auth: 'user', user: 'foo', committish: 'branch' },
'git+https://user:password@gist.github.com/foo/feedbeef': { ...defaults, default: 'https', auth: 'user:password', user: 'foo' },
'git+https://user:password@gist.github.com/foo/feedbeef#branch': { ...defaults, default: 'https', auth: 'user:password', user: 'foo', committish: 'branch' },
'git+https://:password@gist.github.com/foo/feedbeef': { ...defaults, default: 'https', auth: ':password', user: 'foo' },
'git+https://:password@gist.github.com/foo/feedbeef#branch': { ...defaults, default: 'https', auth: ':password', user: 'foo', committish: 'branch' },
'git+https://gist.github.com/foo/feedbeef.git': { ...defaults, default: 'https', user: 'foo' },
'git+https://gist.github.com/foo/feedbeef.git#branch': { ...defaults, default: 'https', user: 'foo', committish: 'branch' },
'git+https://user@gist.github.com/foo/feedbeef.git': { ...defaults, default: 'https', auth: 'user', user: 'foo' },
'git+https://user@gist.github.com/foo/feedbeef.git#branch': { ...defaults, default: 'https', auth: 'user', user: 'foo', committish: 'branch' },
'git+https://user:password@gist.github.com/foo/feedbeef.git': { ...defaults, default: 'https', auth: 'user:password', user: 'foo' },
'git+https://user:password@gist.github.com/foo/feedbeef.git#branch': { ...defaults, default: 'https', auth: 'user:password', user: 'foo', committish: 'branch' },
'git+https://:password@gist.github.com/foo/feedbeef.git': { ...defaults, default: 'https', auth: ':password', user: 'foo' },
'git+https://:password@gist.github.com/foo/feedbeef.git#branch': { ...defaults, default: 'https', auth: ':password', user: 'foo', committish: 'branch' },
// https urls
//
// NOTE auth is accepted and respected
'https://gist.github.com/feedbeef': { ...defaults, default: 'https' },
'https://gist.github.com/feedbeef#branch': { ...defaults, default: 'https', committish: 'branch' },
'https://user@gist.github.com/feedbeef': { ...defaults, default: 'https', auth: 'user' },
'https://user@gist.github.com/feedbeef#branch': { ...defaults, default: 'https', auth: 'user', committish: 'branch' },
'https://user:password@gist.github.com/feedbeef': { ...defaults, default: 'https', auth: 'user:password' },
'https://user:password@gist.github.com/feedbeef#branch': { ...defaults, default: 'https', auth: 'user:password', committish: 'branch' },
'https://:password@gist.github.com/feedbeef': { ...defaults, default: 'https', auth: ':password' },
'https://:password@gist.github.com/feedbeef#branch': { ...defaults, default: 'https', auth: ':password', committish: 'branch' },
'https://gist.github.com/feedbeef.git': { ...defaults, default: 'https' },
'https://gist.github.com/feedbeef.git#branch': { ...defaults, default: 'https', committish: 'branch' },
'https://user@gist.github.com/feedbeef.git': { ...defaults, default: 'https', auth: 'user' },
'https://user@gist.github.com/feedbeef.git#branch': { ...defaults, default: 'https', auth: 'user', committish: 'branch' },
'https://user:password@gist.github.com/feedbeef.git': { ...defaults, default: 'https', auth: 'user:password' },
'https://user:password@gist.github.com/feedbeef.git#branch': { ...defaults, default: 'https', auth: 'user:password', committish: 'branch' },
'https://:password@gist.github.com/feedbeef.git': { ...defaults, default: 'https', auth: ':password' },
'https://:password@gist.github.com/feedbeef.git#branch': { ...defaults, default: 'https', auth: ':password', committish: 'branch' },
'https://gist.github.com/foo/feedbeef': { ...defaults, default: 'https', user: 'foo' },
'https://gist.github.com/foo/feedbeef#branch': { ...defaults, default: 'https', user: 'foo', committish: 'branch' },
'https://user@gist.github.com/foo/feedbeef': { ...defaults, default: 'https', auth: 'user', user: 'foo' },
'https://user@gist.github.com/foo/feedbeef#branch': { ...defaults, default: 'https', auth: 'user', user: 'foo', committish: 'branch' },
'https://user:password@gist.github.com/foo/feedbeef': { ...defaults, default: 'https', auth: 'user:password', user: 'foo' },
'https://user:password@gist.github.com/foo/feedbeef#branch': { ...defaults, default: 'https', auth: 'user:password', user: 'foo', committish: 'branch' },
'https://:password@gist.github.com/foo/feedbeef': { ...defaults, default: 'https', auth: ':password', user: 'foo' },
'https://:password@gist.github.com/foo/feedbeef#branch': { ...defaults, default: 'https', auth: ':password', user: 'foo', committish: 'branch' },
'https://gist.github.com/foo/feedbeef.git': { ...defaults, default: 'https', user: 'foo' },
'https://gist.github.com/foo/feedbeef.git#branch': { ...defaults, default: 'https', user: 'foo', committish: 'branch' },
'https://user@gist.github.com/foo/feedbeef.git': { ...defaults, default: 'https', auth: 'user', user: 'foo' },
'https://user@gist.github.com/foo/feedbeef.git#branch': { ...defaults, default: 'https', auth: 'user', user: 'foo', committish: 'branch' },
'https://user:password@gist.github.com/foo/feedbeef.git': { ...defaults, default: 'https', auth: 'user:password', user: 'foo' },
'https://user:password@gist.github.com/foo/feedbeef.git#branch': { ...defaults, default: 'https', auth: 'user:password', user: 'foo', committish: 'branch' },
'https://:password@gist.github.com/foo/feedbeef.git': { ...defaults, default: 'https', auth: ':password', user: 'foo' },
'https://:password@gist.github.com/foo/feedbeef.git#branch': { ...defaults, default: 'https', auth: ':password', user: 'foo', committish: 'branch' },
}
t.test('valid urls parse properly', t => {
t.plan(Object.keys(valid).length)
for (const [url, result] of Object.entries(valid)) {
t.hasStrict(HostedGit.fromUrl(url), result, `${url} parses`)
}
})
t.test('invalid urls return undefined', t => {
t.plan(invalid.length)
for (const url of invalid) {
t.equal(HostedGit.fromUrl(url), undefined, `${url} returns undefined`)
}
})
t.test('toString respects defaults', t => {
const sshurl = HostedGit.fromUrl('git+ssh://gist.github.com/foo/feedbeef')
t.equal(sshurl.default, 'sshurl', 'got the right default')
t.equal(sshurl.toString(), sshurl.sshurl(), 'toString calls sshurl')
const https = HostedGit.fromUrl('https://gist.github.com/foo/feedbeef')
t.equal(https.default, 'https', 'got the right default')
t.equal(https.toString(), https.https(), 'toString calls https')
const shortcut = HostedGit.fromUrl('gist:feedbeef')
t.equal(shortcut.default, 'shortcut', 'got the right default')
t.equal(shortcut.toString(), shortcut.shortcut(), 'toString calls shortcut')
t.end()
})
t.test('string methods populate correctly', t => {
const parsed = HostedGit.fromUrl('git+ssh://gist.github.com/foo/feedbeef')
t.equal(parsed.getDefaultRepresentation(), parsed.default)
t.equal(parsed.hash(), '', 'hash() returns empty string when committish is unset')
t.equal(parsed.ssh(), 'git@gist.github.com:feedbeef.git')
t.equal(parsed.sshurl(), 'git+ssh://git@gist.github.com/feedbeef.git')
t.equal(parsed.edit(), 'https://gist.github.com/foo/feedbeef/edit', 'gist link only redirects with a user')
t.equal(parsed.edit('/lib/index.js'), 'https://gist.github.com/foo/feedbeef/edit', 'gist link only redirects with a user')
t.equal(parsed.browse(), 'https://gist.github.com/feedbeef')
t.equal(parsed.browse('/lib/index.js'), 'https://gist.github.com/feedbeef#file-libindex-js')
t.equal(parsed.browse('/lib/index.js', 'L100'), 'https://gist.github.com/feedbeef#file-libindex-js')
t.equal(parsed.browseFile('/lib/index.js'), 'https://gist.github.com/feedbeef#file-libindex-js')
t.equal(parsed.browseFile('/lib/index.js', 'L100'), 'https://gist.github.com/feedbeef#file-libindex-js')
t.equal(parsed.docs(), 'https://gist.github.com/feedbeef')
t.equal(parsed.https(), 'git+https://gist.github.com/feedbeef.git')
t.equal(parsed.shortcut(), 'gist:feedbeef')
t.equal(parsed.path(), 'feedbeef')
t.equal(parsed.tarball(), 'https://codeload.github.com/gist/feedbeef/tar.gz/HEAD')
t.equal(parsed.file(), 'https://gist.githubusercontent.com/foo/feedbeef/raw/')
t.equal(parsed.file('/lib/index.js'), 'https://gist.githubusercontent.com/foo/feedbeef/raw/lib/index.js')
t.equal(parsed.git(), 'git://gist.github.com/feedbeef.git')
t.equal(parsed.bugs(), 'https://gist.github.com/feedbeef')
t.equal(parsed.ssh({ committish: 'fix/bug' }), 'git@gist.github.com:feedbeef.git#fix/bug', 'allows overriding options')
const extra = HostedGit.fromUrl('https://user@gist.github.com/foo/feedbeef#fix/bug')
t.equal(extra.hash(), '#fix/bug')
t.equal(extra.https(), 'git+https://gist.github.com/feedbeef.git#fix/bug')
t.equal(extra.shortcut(), 'gist:feedbeef#fix/bug')
t.equal(extra.ssh(), 'git@gist.github.com:feedbeef.git#fix/bug')
t.equal(extra.sshurl(), 'git+ssh://git@gist.github.com/feedbeef.git#fix/bug')
t.equal(extra.browse(), 'https://gist.github.com/feedbeef/fix%2Fbug')
t.equal(extra.browse('/lib/index.js'), 'https://gist.github.com/feedbeef/fix%2Fbug#file-libindex-js')
t.equal(extra.browse('/lib/index.js', 'L200'), 'https://gist.github.com/feedbeef/fix%2Fbug#file-libindex-js')
t.equal(extra.docs(), 'https://gist.github.com/feedbeef/fix%2Fbug')
t.equal(extra.file(), 'https://gist.githubusercontent.com/foo/feedbeef/raw/fix%2Fbug/')
t.equal(extra.file('/lib/index.js'), 'https://gist.githubusercontent.com/foo/feedbeef/raw/fix%2Fbug/lib/index.js')
t.equal(extra.tarball(), 'https://codeload.github.com/gist/feedbeef/tar.gz/fix%2Fbug')
t.equal(extra.sshurl({ noCommittish: true }), 'git+ssh://git@gist.github.com/feedbeef.git', 'noCommittish drops committish from urls')
t.equal(extra.sshurl({ noGitPlus: true }), 'ssh://git@gist.github.com/feedbeef.git#fix/bug', 'noGitPlus drops git+ prefix from urls')
t.end()
})
hosted-git-info-9.0.2/test/github.js 0000664 0000000 0000000 00000051721 15071511065 0017330 0 ustar 00root root 0000000 0000000 /* eslint-disable max-len */
const HostedGit = require('..')
const t = require('tap')
const invalid = [
// foo/bar shorthand but specifying auth
'user@foo/bar',
'user:password@foo/bar',
':password@foo/bar',
// foo/bar shorthand but with a space in it
'foo/ bar',
// string that ends with a slash, probably a directory
'foo/bar/',
// git@github.com style, but omitting the username
'github.com:foo/bar',
'github.com/foo/bar',
// invalid URI encoding
'github:foo%0N/bar',
// missing path
'git+ssh://git@github.com:',
// a deep url to something we don't know
'https://github.com/foo/bar/issues',
]
const defaults = { type: 'github', user: 'foo', project: 'bar' }
// This is a valid git branch name that contains other occurences of the characters we check
// for to determine the committish in order to test that we parse those correctly
const committishDefaults = { committish: 'lk/br@nch.t#st:^1.0.0-pre.4' }
const valid = {
// extreme shorthand
//
// NOTE these do not accept auth at all
'foo/bar': { ...defaults, default: 'shortcut' },
[`foo/bar#${committishDefaults.committish}`]: { ...defaults, default: 'shortcut', ...committishDefaults },
'foo/bar.git': { ...defaults, default: 'shortcut' },
[`foo/bar.git#${committishDefaults.committish}`]: { ...defaults, default: 'shortcut', ...committishDefaults },
// shortcuts
//
// NOTE auth is accepted but ignored
'github:foo/bar': { ...defaults, default: 'shortcut' },
[`github:foo/bar#${committishDefaults.committish}`]: { ...defaults, default: 'shortcut', ...committishDefaults },
'github:user@foo/bar': { ...defaults, default: 'shortcut', auth: null },
[`github:user@foo/bar#${committishDefaults.committish}`]: { ...defaults, default: 'shortcut', auth: null, ...committishDefaults },
'github:user:password@foo/bar': { ...defaults, default: 'shortcut', auth: null },
[`github:user:password@foo/bar#${committishDefaults.committish}`]: { ...defaults, default: 'shortcut', auth: null, ...committishDefaults },
'github::password@foo/bar': { ...defaults, default: 'shortcut', auth: null },
[`github::password@foo/bar#${committishDefaults.committish}`]: { ...defaults, default: 'shortcut', auth: null, ...committishDefaults },
'github:foo/bar.git': { ...defaults, default: 'shortcut' },
[`github:foo/bar.git#${committishDefaults.committish}`]: { ...defaults, default: 'shortcut', ...committishDefaults },
'github:user@foo/bar.git': { ...defaults, default: 'shortcut', auth: null },
[`github:user@foo/bar.git#${committishDefaults.committish}`]: { ...defaults, default: 'shortcut', auth: null, ...committishDefaults },
'github:user:password@foo/bar.git': { ...defaults, default: 'shortcut', auth: null },
[`github:user:password@foo/bar.git#${committishDefaults.committish}`]: { ...defaults, default: 'shortcut', auth: null, ...committishDefaults },
'github::password@foo/bar.git': { ...defaults, default: 'shortcut', auth: null },
[`github::password@foo/bar.git#${committishDefaults.committish}`]: { ...defaults, default: 'shortcut', auth: null, ...committishDefaults },
// git urls
//
// NOTE auth is accepted and respected
'git://github.com/foo/bar': { ...defaults, default: 'git' },
[`git://github.com/foo/bar#${committishDefaults.committish}`]: { ...defaults, default: 'git', ...committishDefaults },
'git://user@github.com/foo/bar': { ...defaults, default: 'git', auth: 'user' },
[`git://user@github.com/foo/bar#${committishDefaults.committish}`]: { ...defaults, default: 'git', auth: 'user', ...committishDefaults },
'git://user:password@github.com/foo/bar': { ...defaults, default: 'git', auth: 'user:password' },
[`git://user:password@github.com/foo/bar#${committishDefaults.committish}`]: { ...defaults, default: 'git', auth: 'user:password', ...committishDefaults },
'git://:password@github.com/foo/bar': { ...defaults, default: 'git', auth: ':password' },
[`git://:password@github.com/foo/bar#${committishDefaults.committish}`]: { ...defaults, default: 'git', auth: ':password', ...committishDefaults },
'git://github.com/foo/bar.git': { ...defaults, default: 'git' },
[`git://github.com/foo/bar.git#${committishDefaults.committish}`]: { ...defaults, default: 'git', ...committishDefaults },
'git://git@github.com/foo/bar.git': { ...defaults, default: 'git', auth: 'git' },
[`git://git@github.com/foo/bar.git#${committishDefaults.committish}`]: { ...defaults, default: 'git', auth: 'git', ...committishDefaults },
'git://user:password@github.com/foo/bar.git': { ...defaults, default: 'git', auth: 'user:password' },
[`git://user:password@github.com/foo/bar.git#${committishDefaults.committish}`]: { ...defaults, default: 'git', auth: 'user:password', ...committishDefaults },
'git://:password@github.com/foo/bar.git': { ...defaults, default: 'git', auth: ':password' },
[`git://:password@github.com/foo/bar.git#${committishDefaults.committish}`]: { ...defaults, default: 'git', auth: ':password', ...committishDefaults },
// no-protocol git+ssh
//
// NOTE auth is _required_ (see invalid list) but ignored
'user@github.com:foo/bar': { ...defaults, default: 'sshurl', auth: null },
[`user@github.com:foo/bar#${committishDefaults.committish}`]: { ...defaults, default: 'sshurl', auth: null, ...committishDefaults },
'user:password@github.com:foo/bar': { ...defaults, default: 'sshurl', auth: null },
[`user:password@github.com:foo/bar#${committishDefaults.committish}`]: { ...defaults, default: 'sshurl', auth: null, ...committishDefaults },
':password@github.com:foo/bar': { ...defaults, default: 'sshurl', auth: null },
[`:password@github.com:foo/bar#${committishDefaults.committish}`]: { ...defaults, default: 'sshurl', auth: null, ...committishDefaults },
'user@github.com:foo/bar.git': { ...defaults, default: 'sshurl', auth: null },
[`user@github.com:foo/bar.git#${committishDefaults.committish}`]: { ...defaults, default: 'sshurl', auth: null, ...committishDefaults },
'user:password@github.com:foo/bar.git': { ...defaults, default: 'sshurl', auth: null },
[`user:password@github.com:foo/bar.git#${committishDefaults.committish}`]: { ...defaults, default: 'sshurl', auth: null, ...committishDefaults },
':password@github.com:foo/bar.git': { ...defaults, default: 'sshurl', auth: null },
[`:password@github.com:foo/bar.git#${committishDefaults.committish}`]: { ...defaults, default: 'sshurl', auth: null, ...committishDefaults },
// git+ssh urls
//
// NOTE auth is accepted but ignored
'git+ssh://github.com:foo/bar': { ...defaults, default: 'sshurl' },
[`git+ssh://github.com:foo/bar#${committishDefaults.committish}`]: { ...defaults, default: 'sshurl', ...committishDefaults },
'git+ssh://user@github.com:foo/bar': { ...defaults, default: 'sshurl', auth: null },
[`git+ssh://user@github.com:foo/bar#${committishDefaults.committish}`]: { ...defaults, default: 'sshurl', auth: null, ...committishDefaults },
'git+ssh://user:password@github.com:foo/bar': { ...defaults, default: 'sshurl', auth: null },
[`git+ssh://user:password@github.com:foo/bar#${committishDefaults.committish}`]: { ...defaults, default: 'sshurl', auth: null, ...committishDefaults },
'git+ssh://:password@github.com:foo/bar': { ...defaults, default: 'sshurl', auth: null },
[`git+ssh://:password@github.com:foo/bar#${committishDefaults.committish}`]: { ...defaults, default: 'sshurl', auth: null, ...committishDefaults },
'git+ssh://github.com:foo/bar.git': { ...defaults, default: 'sshurl' },
[`git+ssh://github.com:foo/bar.git#${committishDefaults.committish}`]: { ...defaults, default: 'sshurl', ...committishDefaults },
'git+ssh://user@github.com:foo/bar.git': { ...defaults, default: 'sshurl', auth: null },
[`git+ssh://user@github.com:foo/bar.git#${committishDefaults.committish}`]: { ...defaults, default: 'sshurl', auth: null, ...committishDefaults },
'git+ssh://user:password@github.com:foo/bar.git': { ...defaults, default: 'sshurl', auth: null },
[`git+ssh://user:password@github.com:foo/bar.git#${committishDefaults.committish}`]: { ...defaults, default: 'sshurl', auth: null, ...committishDefaults },
'git+ssh://:password@github.com:foo/bar.git': { ...defaults, default: 'sshurl', auth: null },
[`git+ssh://:password@github.com:foo/bar.git#${committishDefaults.committish}`]: { ...defaults, default: 'sshurl', auth: null, ...committishDefaults },
// ssh urls
//
// NOTE auth is accepted but ignored
'ssh://github.com:foo/bar': { ...defaults, default: 'sshurl' },
[`ssh://github.com:foo/bar#${committishDefaults.committish}`]: { ...defaults, default: 'sshurl', ...committishDefaults },
'ssh://user@github.com:foo/bar': { ...defaults, default: 'sshurl', auth: null },
[`ssh://user@github.com:foo/bar#${committishDefaults.committish}`]: { ...defaults, default: 'sshurl', auth: null, ...committishDefaults },
'ssh://user:password@github.com:foo/bar': { ...defaults, default: 'sshurl', auth: null },
[`ssh://user:password@github.com:foo/bar#${committishDefaults.committish}`]: { ...defaults, default: 'sshurl', auth: null, ...committishDefaults },
'ssh://:password@github.com:foo/bar': { ...defaults, default: 'sshurl', auth: null },
[`ssh://:password@github.com:foo/bar#${committishDefaults.committish}`]: { ...defaults, default: 'sshurl', auth: null, ...committishDefaults },
'ssh://github.com:foo/bar.git': { ...defaults, default: 'sshurl' },
[`ssh://github.com:foo/bar.git#${committishDefaults.committish}`]: { ...defaults, default: 'sshurl', ...committishDefaults },
'ssh://user@github.com:foo/bar.git': { ...defaults, default: 'sshurl', auth: null },
[`ssh://user@github.com:foo/bar.git#${committishDefaults.committish}`]: { ...defaults, default: 'sshurl', auth: null, ...committishDefaults },
'ssh://user:password@github.com:foo/bar.git': { ...defaults, default: 'sshurl', auth: null },
[`ssh://user:password@github.com:foo/bar.git#${committishDefaults.committish}`]: { ...defaults, default: 'sshurl', auth: null, ...committishDefaults },
'ssh://:password@github.com:foo/bar.git': { ...defaults, default: 'sshurl', auth: null },
[`ssh://:password@github.com:foo/bar.git#${committishDefaults.committish}`]: { ...defaults, default: 'sshurl', auth: null, ...committishDefaults },
// git+https urls
//
// NOTE auth is accepted and respected
'git+https://github.com/foo/bar': { ...defaults, default: 'https' },
[`git+https://github.com/foo/bar#${committishDefaults.committish}`]: { ...defaults, default: 'https', ...committishDefaults },
'git+https://user@github.com/foo/bar': { ...defaults, default: 'https', auth: 'user' },
[`git+https://user@github.com/foo/bar#${committishDefaults.committish}`]: { ...defaults, default: 'https', auth: 'user', ...committishDefaults },
'git+https://user:password@github.com/foo/bar': { ...defaults, default: 'https', auth: 'user:password' },
[`git+https://user:password@github.com/foo/bar#${committishDefaults.committish}`]: { ...defaults, default: 'https', auth: 'user:password', ...committishDefaults },
'git+https://:password@github.com/foo/bar': { ...defaults, default: 'https', auth: ':password' },
[`git+https://:password@github.com/foo/bar#${committishDefaults.committish}`]: { ...defaults, default: 'https', auth: ':password', ...committishDefaults },
'git+https://github.com/foo/bar.git': { ...defaults, default: 'https' },
[`git+https://github.com/foo/bar.git#${committishDefaults.committish}`]: { ...defaults, default: 'https', ...committishDefaults },
'git+https://user@github.com/foo/bar.git': { ...defaults, default: 'https', auth: 'user' },
[`git+https://user@github.com/foo/bar.git#${committishDefaults.committish}`]: { ...defaults, default: 'https', auth: 'user', ...committishDefaults },
'git+https://user:password@github.com/foo/bar.git': { ...defaults, default: 'https', auth: 'user:password' },
[`git+https://user:password@github.com/foo/bar.git#${committishDefaults.committish}`]: { ...defaults, default: 'https', auth: 'user:password', ...committishDefaults },
'git+https://:password@github.com/foo/bar.git': { ...defaults, default: 'https', auth: ':password' },
[`git+https://:password@github.com/foo/bar.git#${committishDefaults.committish}`]: { ...defaults, default: 'https', auth: ':password', ...committishDefaults },
// https urls
//
// NOTE auth is accepted and respected
'https://github.com/foo/bar': { ...defaults, default: 'https' },
[`https://github.com/foo/bar#${committishDefaults.committish}`]: { ...defaults, default: 'https', ...committishDefaults },
'https://user@github.com/foo/bar': { ...defaults, default: 'https', auth: 'user' },
[`https://user@github.com/foo/bar#${committishDefaults.committish}`]: { ...defaults, default: 'https', auth: 'user', ...committishDefaults },
'https://user:password@github.com/foo/bar': { ...defaults, default: 'https', auth: 'user:password' },
[`https://user:password@github.com/foo/bar#${committishDefaults.committish}`]: { ...defaults, default: 'https', auth: 'user:password', ...committishDefaults },
'https://:password@github.com/foo/bar': { ...defaults, default: 'https', auth: ':password' },
[`https://:password@github.com/foo/bar#${committishDefaults.committish}`]: { ...defaults, default: 'https', auth: ':password', ...committishDefaults },
'https://github.com/foo/bar.git': { ...defaults, default: 'https' },
[`https://github.com/foo/bar.git#${committishDefaults.committish}`]: { ...defaults, default: 'https', ...committishDefaults },
'https://user@github.com/foo/bar.git': { ...defaults, default: 'https', auth: 'user' },
[`https://user@github.com/foo/bar.git#${committishDefaults.committish}`]: { ...defaults, default: 'https', auth: 'user', ...committishDefaults },
'https://user:password@github.com/foo/bar.git': { ...defaults, default: 'https', auth: 'user:password' },
[`https://user:password@github.com/foo/bar.git#${committishDefaults.committish}`]: { ...defaults, default: 'https', auth: 'user:password', ...committishDefaults },
'https://:password@github.com/foo/bar.git': { ...defaults, default: 'https', auth: ':password' },
[`https://:password@github.com/foo/bar.git#${committishDefaults.committish}`]: { ...defaults, default: 'https', auth: ':password', ...committishDefaults },
// inputs that are not quite proper but we accept anyway
'https://www.github.com/foo/bar': { ...defaults, default: 'https' },
'foo/bar#branch with space': { ...defaults, default: 'shortcut', committish: 'branch with space' },
'foo/bar#branch:with:colons': { ...defaults, default: 'shortcut', committish: 'branch:with:colons' },
'https://github.com/foo/bar/tree/branch': { ...defaults, default: 'https', committish: 'branch' },
'user..blerg--/..foo-js# . . . . . some . tags / / /': { ...defaults, default: 'shortcut', user: 'user..blerg--', project: '..foo-js', committish: ' . . . . . some . tags / / /' },
}
t.test('valid urls parse properly', t => {
t.plan(Object.keys(valid).length)
for (const [url, result] of Object.entries(valid)) {
t.hasStrict(HostedGit.fromUrl(url), result, `${url} parses`)
}
})
t.test('invalid urls return undefined', t => {
t.plan(invalid.length)
for (const url of invalid) {
t.equal(HostedGit.fromUrl(url), undefined, `${url} returns undefined`)
}
})
t.test('toString respects defaults', t => {
const sshurl = HostedGit.fromUrl('git+ssh://github.com/foo/bar')
t.equal(sshurl.default, 'sshurl', 'got the right default')
t.equal(sshurl.toString(), sshurl.sshurl(), 'toString calls sshurl')
const https = HostedGit.fromUrl('https://github.com/foo/bar')
t.equal(https.default, 'https', 'got the right default')
t.equal(https.toString(), https.https(), 'toString calls https')
const http = HostedGit.fromUrl('http://github.com/foo/bar')
t.equal(http.default, 'http', 'got the right default')
t.equal(http.toString(), http.sshurl(), 'automatically upgrades toString to sshurl')
const git = HostedGit.fromUrl('git://github.com/foo/bar')
t.equal(git.default, 'git', 'got the right default')
t.equal(git.toString(), git.git(), 'toString calls git')
const shortcut = HostedGit.fromUrl('github:foo/bar')
t.equal(shortcut.default, 'shortcut', 'got the right default')
t.equal(shortcut.toString(), shortcut.shortcut(), 'got the right default')
t.end()
})
t.test('string methods populate correctly', t => {
const parsed = HostedGit.fromUrl('git+ssh://github.com/foo/bar')
t.equal(parsed.getDefaultRepresentation(), parsed.default)
t.equal(parsed.hash(), '', 'hash() returns empty string when committish is unset')
t.equal(parsed.ssh(), 'git@github.com:foo/bar.git')
t.equal(parsed.sshurl(), 'git+ssh://git@github.com/foo/bar.git')
t.equal(parsed.edit(), 'https://github.com/foo/bar')
t.equal(parsed.edit('/lib/index.js'), 'https://github.com/foo/bar/edit/HEAD/lib/index.js')
t.equal(parsed.edit('/lib/index.js', { committish: 'docs' }), 'https://github.com/foo/bar/edit/docs/lib/index.js')
t.equal(parsed.browse(), 'https://github.com/foo/bar')
t.equal(parsed.browse('/lib/index.js'), 'https://github.com/foo/bar/tree/HEAD/lib/index.js')
t.equal(parsed.browse('/lib/index.js', 'L100'), 'https://github.com/foo/bar/tree/HEAD/lib/index.js#l100')
t.equal(parsed.browseFile('/lib/index.js'), 'https://github.com/foo/bar/blob/HEAD/lib/index.js')
t.equal(parsed.browseFile('/lib/index.js', 'L100'), 'https://github.com/foo/bar/blob/HEAD/lib/index.js#l100')
t.equal(parsed.docs(), 'https://github.com/foo/bar#readme')
t.equal(parsed.https(), 'git+https://github.com/foo/bar.git')
t.equal(parsed.shortcut(), 'github:foo/bar')
t.equal(parsed.path(), 'foo/bar')
t.equal(parsed.tarball(), 'https://codeload.github.com/foo/bar/tar.gz/HEAD')
t.equal(parsed.file(), 'https://raw.githubusercontent.com/foo/bar/HEAD/')
t.equal(parsed.file('/lib/index.js'), 'https://raw.githubusercontent.com/foo/bar/HEAD/lib/index.js')
t.equal(parsed.git(), 'git://github.com/foo/bar.git')
t.equal(parsed.bugs(), 'https://github.com/foo/bar/issues')
t.equal(parsed.docs({ committish: 'fix/bug' }), 'https://github.com/foo/bar/tree/fix%2Fbug#readme', 'allows overriding options')
const extra = HostedGit.fromUrl('https://user@github.com/foo/bar#fix/bug')
t.equal(extra.hash(), '#fix/bug')
t.equal(extra.https(), 'git+https://user@github.com/foo/bar.git#fix/bug')
t.equal(extra.shortcut(), 'github:foo/bar#fix/bug')
t.equal(extra.ssh(), 'git@github.com:foo/bar.git#fix/bug')
t.equal(extra.sshurl(), 'git+ssh://git@github.com/foo/bar.git#fix/bug')
t.equal(extra.browse(), 'https://github.com/foo/bar/tree/fix%2Fbug')
t.equal(extra.browse('/lib/index.js'), 'https://github.com/foo/bar/tree/fix%2Fbug/lib/index.js')
t.equal(extra.browse('/lib/index.js', 'L200'), 'https://github.com/foo/bar/tree/fix%2Fbug/lib/index.js#l200')
t.equal(extra.docs(), 'https://github.com/foo/bar/tree/fix%2Fbug#readme')
t.equal(extra.file(), 'https://user@raw.githubusercontent.com/foo/bar/fix%2Fbug/')
t.equal(extra.file('/lib/index.js'), 'https://user@raw.githubusercontent.com/foo/bar/fix%2Fbug/lib/index.js')
t.equal(extra.tarball(), 'https://codeload.github.com/foo/bar/tar.gz/fix%2Fbug')
t.equal(extra.sshurl({ noCommittish: true }), 'git+ssh://git@github.com/foo/bar.git', 'noCommittish drops committish from urls')
t.equal(extra.sshurl({ noGitPlus: true }), 'ssh://git@github.com/foo/bar.git#fix/bug', 'noGitPlus drops git+ prefix from urls')
t.end()
})
t.test('from manifest', t => {
t.equal(HostedGit.fromManifest(), undefined, 'no manifest returns undefined')
t.equal(HostedGit.fromManifest(), undefined, 'no manifest returns undefined')
t.equal(HostedGit.fromManifest(false), undefined, 'false manifest returns undefined')
t.equal(HostedGit.fromManifest(() => {}), undefined, 'function manifest returns undefined')
const unknownHostRepo = {
name: 'foo',
repository: {
url: 'https://nope.com',
},
}
t.same(HostedGit.fromManifest(unknownHostRepo), 'https://nope.com/')
const insecureUnknownHostRepo = {
name: 'foo',
repository: {
url: 'http://nope.com',
},
}
t.same(HostedGit.fromManifest(insecureUnknownHostRepo), 'https://nope.com/')
const insecureGitUnknownHostRepo = {
name: 'foo',
repository: {
url: 'git+http://nope.com',
},
}
t.same(HostedGit.fromManifest(insecureGitUnknownHostRepo), 'http://nope.com')
const badRepo = {
name: 'foo',
repository: {
url: '#',
},
}
t.equal(HostedGit.fromManifest(badRepo), null)
const manifest = {
name: 'foo',
repository: {
type: 'git',
url: 'git+ssh://github.com/foo/bar.git',
},
}
const parsed = HostedGit.fromManifest(manifest)
t.same(parsed.browse(), 'https://github.com/foo/bar')
const monorepo = {
name: 'clowncar',
repository: {
type: 'git',
url: 'git+ssh://github.com/foo/bar.git',
directory: 'packages/foo',
},
}
const honk = HostedGit.fromManifest(monorepo)
t.same(honk.browse(monorepo.repository.directory), 'https://github.com/foo/bar/tree/HEAD/packages/foo')
const stringRepo = {
name: 'foo',
repository: 'git+ssh://github.com/foo/bar.git',
}
const stringRepoParsed = HostedGit.fromManifest(stringRepo)
t.same(stringRepoParsed.browse(), 'https://github.com/foo/bar')
const nonStringRepo = {
name: 'foo',
repository: 42,
}
t.throws(() => HostedGit.fromManifest(nonStringRepo))
t.end()
})
hosted-git-info-9.0.2/test/gitlab.js 0000664 0000000 0000000 00000063413 15071511065 0017311 0 ustar 00root root 0000000 0000000 /* eslint-disable max-len */
'use strict'
const HostedGit = require('..')
const t = require('tap')
const invalid = [
// gitlab urls can contain a /-/ segment, make sure we ignore those
'https://gitlab.com/foo/-/something',
// missing project
'https://gitlab.com/foo',
// tarball, this should not parse so that it can be used for pacote's remote fetcher
'https://gitlab.com/foo/bar/repository/archive.tar.gz',
'https://gitlab.com/foo/bar/repository/archive.tar.gz?ref=49b393e2ded775f2df36ef2ffcb61b0359c194c9',
]
const defaults = { type: 'gitlab', user: 'foo', project: 'bar' }
const subgroup = { type: 'gitlab', user: 'foo/bar', project: 'baz' }
const valid = {
// shortcuts
//
// NOTE auth is accepted but ignored
// NOTE subgroups are respected, but the subgroup is treated as the project and the real project is lost
'gitlab:foo/bar': { ...defaults, default: 'shortcut' },
'gitlab:foo/bar#branch': { ...defaults, default: 'shortcut', committish: 'branch' },
'gitlab:user@foo/bar': { ...defaults, default: 'shortcut', auth: null },
'gitlab:user@foo/bar#branch': { ...defaults, default: 'shortcut', auth: null, committish: 'branch' },
'gitlab:user:password@foo/bar': { ...defaults, default: 'shortcut', auth: null },
'gitlab:user:password@foo/bar#branch': { ...defaults, default: 'shortcut', auth: null, committish: 'branch' },
'gitlab::password@foo/bar': { ...defaults, default: 'shortcut', auth: null },
'gitlab::password@foo/bar#branch': { ...defaults, default: 'shortcut', auth: null, committish: 'branch' },
'gitlab:foo/bar.git': { ...defaults, default: 'shortcut' },
'gitlab:foo/bar.git#branch': { ...defaults, default: 'shortcut', committish: 'branch' },
'gitlab:user@foo/bar.git': { ...defaults, default: 'shortcut', auth: null },
'gitlab:user@foo/bar.git#branch': { ...defaults, default: 'shortcut', auth: null, committish: 'branch' },
'gitlab:user:password@foo/bar.git': { ...defaults, default: 'shortcut', auth: null },
'gitlab:user:password@foo/bar.git#branch': { ...defaults, default: 'shortcut', auth: null, committish: 'branch' },
'gitlab::password@foo/bar.git': { ...defaults, default: 'shortcut', auth: null },
'gitlab::password@foo/bar.git#branch': { ...defaults, default: 'shortcut', auth: null, committish: 'branch' },
'gitlab:foo/bar/baz': { ...subgroup, default: 'shortcut' },
'gitlab:foo/bar/baz#branch': { ...subgroup, default: 'shortcut', committish: 'branch' },
'gitlab:user@foo/bar/baz': { ...subgroup, default: 'shortcut', auth: null },
'gitlab:user@foo/bar/baz#branch': { ...subgroup, default: 'shortcut', auth: null, committish: 'branch' },
'gitlab:user:password@foo/bar/baz': { ...subgroup, default: 'shortcut', auth: null },
'gitlab:user:password@foo/bar/baz#branch': { ...subgroup, default: 'shortcut', auth: null, committish: 'branch' },
'gitlab::password@foo/bar/baz': { ...subgroup, default: 'shortcut', auth: null },
'gitlab::password@foo/bar/baz#branch': { ...subgroup, default: 'shortcut', auth: null, committish: 'branch' },
'gitlab:foo/bar/baz.git': { ...subgroup, default: 'shortcut' },
'gitlab:foo/bar/baz.git#branch': { ...subgroup, default: 'shortcut', committish: 'branch' },
'gitlab:user@foo/bar/baz.git': { ...subgroup, default: 'shortcut', auth: null },
'gitlab:user@foo/bar/baz.git#branch': { ...subgroup, default: 'shortcut', auth: null, committish: 'branch' },
'gitlab:user:password@foo/bar/baz.git': { ...subgroup, default: 'shortcut', auth: null },
'gitlab:user:password@foo/bar/baz.git#branch': { ...subgroup, default: 'shortcut', auth: null, committish: 'branch' },
'gitlab::password@foo/bar/baz.git': { ...subgroup, default: 'shortcut', auth: null },
'gitlab::password@foo/bar/baz.git#branch': { ...subgroup, default: 'shortcut', auth: null, committish: 'branch' },
// no-protocol git+ssh
//
// NOTE auth is _required_ (see invalid list) but ignored
'user@gitlab.com:foo/bar': { ...defaults, default: 'sshurl', auth: null },
'user@gitlab.com:foo/bar#branch': { ...defaults, default: 'sshurl', auth: null, committish: 'branch' },
'user:password@gitlab.com:foo/bar': { ...defaults, default: 'sshurl', auth: null },
'user:password@gitlab.com:foo/bar#branch': { ...defaults, default: 'sshurl', auth: null, committish: 'branch' },
':password@gitlab.com:foo/bar': { ...defaults, default: 'sshurl', auth: null },
':password@gitlab.com:foo/bar#branch': { ...defaults, default: 'sshurl', auth: null, committish: 'branch' },
'user@gitlab.com:foo/bar.git': { ...defaults, default: 'sshurl', auth: null },
'user@gitlab.com:foo/bar.git#branch': { ...defaults, default: 'sshurl', auth: null, committish: 'branch' },
'user:password@gitlab.com:foo/bar.git': { ...defaults, default: 'sshurl', auth: null },
'user:password@gitlab.com:foo/bar.git#branch': { ...defaults, default: 'sshurl', auth: null, committish: 'branch' },
':password@gitlab.com:foo/bar.git': { ...defaults, default: 'sshurl', auth: null },
':password@gitlab.com:foo/bar.git#branch': { ...defaults, default: 'sshurl', auth: null, committish: 'branch' },
'user@gitlab.com:foo/bar/baz': { ...subgroup, default: 'sshurl', auth: null },
'user@gitlab.com:foo/bar/baz#branch': { ...subgroup, default: 'sshurl', auth: null, committish: 'branch' },
'user:password@gitlab.com:foo/bar/baz': { ...subgroup, default: 'sshurl', auth: null },
'user:password@gitlab.com:foo/bar/baz#branch': { ...subgroup, default: 'sshurl', auth: null, committish: 'branch' },
':password@gitlab.com:foo/bar/baz': { ...subgroup, default: 'sshurl', auth: null },
':password@gitlab.com:foo/bar/baz#branch': { ...subgroup, default: 'sshurl', auth: null, committish: 'branch' },
'user@gitlab.com:foo/bar/baz.git': { ...subgroup, default: 'sshurl', auth: null },
'user@gitlab.com:foo/bar/baz.git#branch': { ...subgroup, default: 'sshurl', auth: null, committish: 'branch' },
'user:password@gitlab.com:foo/bar/baz.git': { ...subgroup, default: 'sshurl', auth: null },
'user:password@gitlab.com:foo/bar/baz.git#branch': { ...subgroup, default: 'sshurl', auth: null, committish: 'branch' },
':password@gitlab.com:foo/bar/baz.git': { ...subgroup, default: 'sshurl', auth: null },
':password@gitlab.com:foo/bar/baz.git#branch': { ...subgroup, default: 'sshurl', auth: null, committish: 'branch' },
// git+ssh urls
//
// NOTE auth is accepted but ignored
// NOTE subprojects are accepted, but the subproject is treated as the project and the real project is lost
'git+ssh://gitlab.com:foo/bar': { ...defaults, default: 'sshurl' },
'git+ssh://gitlab.com:foo/bar#branch': { ...defaults, default: 'sshurl', committish: 'branch' },
'git+ssh://user@gitlab.com:foo/bar': { ...defaults, default: 'sshurl', auth: null },
'git+ssh://user@gitlab.com:foo/bar#branch': { ...defaults, default: 'sshurl', auth: null, committish: 'branch' },
'git+ssh://user:password@gitlab.com:foo/bar': { ...defaults, default: 'sshurl', auth: null },
'git+ssh://user:password@gitlab.com:foo/bar#branch': { ...defaults, default: 'sshurl', auth: null, committish: 'branch' },
'git+ssh://:password@gitlab.com:foo/bar': { ...defaults, default: 'sshurl', auth: null },
'git+ssh://:password@gitlab.com:foo/bar#branch': { ...defaults, default: 'sshurl', auth: null, committish: 'branch' },
'git+ssh://gitlab.com:foo/bar.git': { ...defaults, default: 'sshurl' },
'git+ssh://gitlab.com:foo/bar.git#branch': { ...defaults, default: 'sshurl', committish: 'branch' },
'git+ssh://user@gitlab.com:foo/bar.git': { ...defaults, default: 'sshurl', auth: null },
'git+ssh://user@gitlab.com:foo/bar.git#branch': { ...defaults, default: 'sshurl', auth: null, committish: 'branch' },
'git+ssh://user:password@gitlab.com:foo/bar.git': { ...defaults, default: 'sshurl', auth: null },
'git+ssh://user:password@gitlab.com:foo/bar.git#branch': { ...defaults, default: 'sshurl', auth: null, committish: 'branch' },
'git+ssh://:password@gitlab.com:foo/bar.git': { ...defaults, default: 'sshurl', auth: null },
'git+ssh://:password@gitlab.com:foo/bar.git#branch': { ...defaults, default: 'sshurl', auth: null, committish: 'branch' },
'git+ssh://gitlab.com:foo/bar/baz': { ...subgroup, default: 'sshurl' },
'git+ssh://gitlab.com:foo/bar/baz#branch': { ...subgroup, default: 'sshurl', committish: 'branch' },
'git+ssh://user@gitlab.com:foo/bar/baz': { ...subgroup, default: 'sshurl', auth: null },
'git+ssh://user@gitlab.com:foo/bar/baz#branch': { ...subgroup, default: 'sshurl', auth: null, committish: 'branch' },
'git+ssh://user:password@gitlab.com:foo/bar/baz': { ...subgroup, default: 'sshurl', auth: null },
'git+ssh://user:password@gitlab.com:foo/bar/baz#branch': { ...subgroup, default: 'sshurl', auth: null, committish: 'branch' },
'git+ssh://:password@gitlab.com:foo/bar/baz': { ...subgroup, default: 'sshurl', auth: null },
'git+ssh://:password@gitlab.com:foo/bar/baz#branch': { ...subgroup, default: 'sshurl', auth: null, committish: 'branch' },
'git+ssh://gitlab.com:foo/bar/baz.git': { ...subgroup, default: 'sshurl' },
'git+ssh://gitlab.com:foo/bar/baz.git#branch': { ...subgroup, default: 'sshurl', committish: 'branch' },
'git+ssh://user@gitlab.com:foo/bar/baz.git': { ...subgroup, default: 'sshurl', auth: null },
'git+ssh://user@gitlab.com:foo/bar/baz.git#branch': { ...subgroup, default: 'sshurl', auth: null, committish: 'branch' },
'git+ssh://user:password@gitlab.com:foo/bar/baz.git': { ...subgroup, default: 'sshurl', auth: null },
'git+ssh://user:password@gitlab.com:foo/bar/baz.git#branch': { ...subgroup, default: 'sshurl', auth: null, committish: 'branch' },
'git+ssh://:password@gitlab.com:foo/bar/baz.git': { ...subgroup, default: 'sshurl', auth: null },
'git+ssh://:password@gitlab.com:foo/bar/baz.git#branch': { ...subgroup, default: 'sshurl', auth: null, committish: 'branch' },
// ssh urls
//
// NOTE auth is accepted but ignored
// NOTE subprojects are accepted, but the subproject is treated as the project and the real project is lost
'ssh://gitlab.com:foo/bar': { ...defaults, default: 'sshurl' },
'ssh://gitlab.com:foo/bar#branch': { ...defaults, default: 'sshurl', committish: 'branch' },
'ssh://user@gitlab.com:foo/bar': { ...defaults, default: 'sshurl', auth: null },
'ssh://user@gitlab.com:foo/bar#branch': { ...defaults, default: 'sshurl', auth: null, committish: 'branch' },
'ssh://user:password@gitlab.com:foo/bar': { ...defaults, default: 'sshurl', auth: null },
'ssh://user:password@gitlab.com:foo/bar#branch': { ...defaults, default: 'sshurl', auth: null, committish: 'branch' },
'ssh://:password@gitlab.com:foo/bar': { ...defaults, default: 'sshurl', auth: null },
'ssh://:password@gitlab.com:foo/bar#branch': { ...defaults, default: 'sshurl', auth: null, committish: 'branch' },
'ssh://gitlab.com:foo/bar.git': { ...defaults, default: 'sshurl' },
'ssh://gitlab.com:foo/bar.git#branch': { ...defaults, default: 'sshurl', committish: 'branch' },
'ssh://user@gitlab.com:foo/bar.git': { ...defaults, default: 'sshurl', auth: null },
'ssh://user@gitlab.com:foo/bar.git#branch': { ...defaults, default: 'sshurl', auth: null, committish: 'branch' },
'ssh://user:password@gitlab.com:foo/bar.git': { ...defaults, default: 'sshurl', auth: null },
'ssh://user:password@gitlab.com:foo/bar.git#branch': { ...defaults, default: 'sshurl', auth: null, committish: 'branch' },
'ssh://:password@gitlab.com:foo/bar.git': { ...defaults, default: 'sshurl', auth: null },
'ssh://:password@gitlab.com:foo/bar.git#branch': { ...defaults, default: 'sshurl', auth: null, committish: 'branch' },
'ssh://gitlab.com:foo/bar/baz': { ...subgroup, default: 'sshurl' },
'ssh://gitlab.com:foo/bar/baz#branch': { ...subgroup, default: 'sshurl', committish: 'branch' },
'ssh://user@gitlab.com:foo/bar/baz': { ...subgroup, default: 'sshurl', auth: null },
'ssh://user@gitlab.com:foo/bar/baz#branch': { ...subgroup, default: 'sshurl', auth: null, committish: 'branch' },
'ssh://user:password@gitlab.com:foo/bar/baz': { ...subgroup, default: 'sshurl', auth: null },
'ssh://user:password@gitlab.com:foo/bar/baz#branch': { ...subgroup, default: 'sshurl', auth: null, committish: 'branch' },
'ssh://:password@gitlab.com:foo/bar/baz': { ...subgroup, default: 'sshurl', auth: null },
'ssh://:password@gitlab.com:foo/bar/baz#branch': { ...subgroup, default: 'sshurl', auth: null, committish: 'branch' },
'ssh://gitlab.com:foo/bar/baz.git': { ...subgroup, default: 'sshurl' },
'ssh://gitlab.com:foo/bar/baz.git#branch': { ...subgroup, default: 'sshurl', committish: 'branch' },
'ssh://user@gitlab.com:foo/bar/baz.git': { ...subgroup, default: 'sshurl', auth: null },
'ssh://user@gitlab.com:foo/bar/baz.git#branch': { ...subgroup, default: 'sshurl', auth: null, committish: 'branch' },
'ssh://user:password@gitlab.com:foo/bar/baz.git': { ...subgroup, default: 'sshurl', auth: null },
'ssh://user:password@gitlab.com:foo/bar/baz.git#branch': { ...subgroup, default: 'sshurl', auth: null, committish: 'branch' },
'ssh://:password@gitlab.com:foo/bar/baz.git': { ...subgroup, default: 'sshurl', auth: null },
'ssh://:password@gitlab.com:foo/bar/baz.git#branch': { ...subgroup, default: 'sshurl', auth: null, committish: 'branch' },
// git+https urls
//
// NOTE auth is accepted and respected
// NOTE subprojects are accepted, but the subproject is treated as the project and the real project is lost
'git+https://gitlab.com/foo/bar': { ...defaults, default: 'https' },
'git+https://gitlab.com/foo/bar#branch': { ...defaults, default: 'https', committish: 'branch' },
'git+https://user@gitlab.com/foo/bar': { ...defaults, default: 'https', auth: 'user' },
'git+https://user@gitlab.com/foo/bar#branch': { ...defaults, default: 'https', auth: 'user', committish: 'branch' },
'git+https://user:password@gitlab.com/foo/bar': { ...defaults, default: 'https', auth: 'user:password' },
'git+https://user:password@gitlab.com/foo/bar#branch': { ...defaults, default: 'https', auth: 'user:password', committish: 'branch' },
'git+https://:password@gitlab.com/foo/bar': { ...defaults, default: 'https', auth: ':password' },
'git+https://:password@gitlab.com/foo/bar#branch': { ...defaults, default: 'https', auth: ':password', committish: 'branch' },
'git+https://gitlab.com/foo/bar.git': { ...defaults, default: 'https' },
'git+https://gitlab.com/foo/bar.git#branch': { ...defaults, default: 'https', committish: 'branch' },
'git+https://user@gitlab.com/foo/bar.git': { ...defaults, default: 'https', auth: 'user' },
'git+https://user@gitlab.com/foo/bar.git#branch': { ...defaults, default: 'https', auth: 'user', committish: 'branch' },
'git+https://user:password@gitlab.com/foo/bar.git': { ...defaults, default: 'https', auth: 'user:password' },
'git+https://user:password@gitlab.com/foo/bar.git#branch': { ...defaults, default: 'https', auth: 'user:password', committish: 'branch' },
'git+https://:password@gitlab.com/foo/bar.git': { ...defaults, default: 'https', auth: ':password' },
'git+https://:password@gitlab.com/foo/bar.git#branch': { ...defaults, default: 'https', auth: ':password', committish: 'branch' },
'git+https://gitlab.com/foo/bar/baz': { ...subgroup, default: 'https' },
'git+https://gitlab.com/foo/bar/baz#branch': { ...subgroup, default: 'https', committish: 'branch' },
'git+https://user@gitlab.com/foo/bar/baz': { ...subgroup, default: 'https', auth: 'user' },
'git+https://user@gitlab.com/foo/bar/baz#branch': { ...subgroup, default: 'https', auth: 'user', committish: 'branch' },
'git+https://user:password@gitlab.com/foo/bar/baz': { ...subgroup, default: 'https', auth: 'user:password' },
'git+https://user:password@gitlab.com/foo/bar/baz#branch': { ...subgroup, default: 'https', auth: 'user:password', committish: 'branch' },
'git+https://:password@gitlab.com/foo/bar/baz': { ...subgroup, default: 'https', auth: ':password' },
'git+https://:password@gitlab.com/foo/bar/baz#branch': { ...subgroup, default: 'https', auth: ':password', committish: 'branch' },
'git+https://gitlab.com/foo/bar/baz.git': { ...subgroup, default: 'https' },
'git+https://gitlab.com/foo/bar/baz.git#branch': { ...subgroup, default: 'https', committish: 'branch' },
'git+https://user@gitlab.com/foo/bar/baz.git': { ...subgroup, default: 'https', auth: 'user' },
'git+https://user@gitlab.com/foo/bar/baz.git#branch': { ...subgroup, default: 'https', auth: 'user', committish: 'branch' },
'git+https://user:password@gitlab.com/foo/bar/baz.git': { ...subgroup, default: 'https', auth: 'user:password' },
'git+https://user:password@gitlab.com/foo/bar/baz.git#branch': { ...subgroup, default: 'https', auth: 'user:password', committish: 'branch' },
'git+https://:password@gitlab.com/foo/bar/baz.git': { ...subgroup, default: 'https', auth: ':password' },
'git+https://:password@gitlab.com/foo/bar/baz.git#branch': { ...subgroup, default: 'https', auth: ':password', committish: 'branch' },
// https urls
//
// NOTE auth is accepted and respected
// NOTE subprojects are accepted, but the subproject is treated as the project and the real project is lost
'https://gitlab.com/foo/bar': { ...defaults, default: 'https' },
'https://gitlab.com/foo/bar#branch': { ...defaults, default: 'https', committish: 'branch' },
'https://user@gitlab.com/foo/bar': { ...defaults, default: 'https', auth: 'user' },
'https://user@gitlab.com/foo/bar#branch': { ...defaults, default: 'https', auth: 'user', committish: 'branch' },
'https://user:password@gitlab.com/foo/bar': { ...defaults, default: 'https', auth: 'user:password' },
'https://user:password@gitlab.com/foo/bar#branch': { ...defaults, default: 'https', auth: 'user:password', committish: 'branch' },
'https://:password@gitlab.com/foo/bar': { ...defaults, default: 'https', auth: ':password' },
'https://:password@gitlab.com/foo/bar#branch': { ...defaults, default: 'https', auth: ':password', committish: 'branch' },
'https://gitlab.com/foo/bar.git': { ...defaults, default: 'https' },
'https://gitlab.com/foo/bar.git#branch': { ...defaults, default: 'https', committish: 'branch' },
'https://user@gitlab.com/foo/bar.git': { ...defaults, default: 'https', auth: 'user' },
'https://user@gitlab.com/foo/bar.git#branch': { ...defaults, default: 'https', auth: 'user', committish: 'branch' },
'https://user:password@gitlab.com/foo/bar.git': { ...defaults, default: 'https', auth: 'user:password' },
'https://user:password@gitlab.com/foo/bar.git#branch': { ...defaults, default: 'https', auth: 'user:password', committish: 'branch' },
'https://:password@gitlab.com/foo/bar.git': { ...defaults, default: 'https', auth: ':password' },
'https://:password@gitlab.com/foo/bar.git#branch': { ...defaults, default: 'https', auth: ':password', committish: 'branch' },
'https://gitlab.com/foo/bar/baz': { ...subgroup, default: 'https' },
'https://gitlab.com/foo/bar/baz#branch': { ...subgroup, default: 'https', committish: 'branch' },
'https://user@gitlab.com/foo/bar/baz': { ...subgroup, default: 'https', auth: 'user' },
'https://user@gitlab.com/foo/bar/baz#branch': { ...subgroup, default: 'https', auth: 'user', committish: 'branch' },
'https://user:password@gitlab.com/foo/bar/baz': { ...subgroup, default: 'https', auth: 'user:password' },
'https://user:password@gitlab.com/foo/bar/baz#branch': { ...subgroup, default: 'https', auth: 'user:password', committish: 'branch' },
'https://:password@gitlab.com/foo/bar/baz': { ...subgroup, default: 'https', auth: ':password' },
'https://:password@gitlab.com/foo/bar/baz#branch': { ...subgroup, default: 'https', auth: ':password', committish: 'branch' },
'https://gitlab.com/foo/bar/baz.git': { ...subgroup, default: 'https' },
'https://gitlab.com/foo/bar/baz.git#branch': { ...subgroup, default: 'https', committish: 'branch' },
'https://user@gitlab.com/foo/bar/baz.git': { ...subgroup, default: 'https', auth: 'user' },
'https://user@gitlab.com/foo/bar/baz.git#branch': { ...subgroup, default: 'https', auth: 'user', committish: 'branch' },
'https://user:password@gitlab.com/foo/bar/baz.git': { ...subgroup, default: 'https', auth: 'user:password' },
'https://user:password@gitlab.com/foo/bar/baz.git#branch': { ...subgroup, default: 'https', auth: 'user:password', committish: 'branch' },
'https://:password@gitlab.com/foo/bar/baz.git': { ...subgroup, default: 'https', auth: ':password' },
'https://:password@gitlab.com/foo/bar/baz.git#branch': { ...subgroup, default: 'https', auth: ':password', committish: 'branch' },
}
t.test('valid urls parse properly', t => {
t.plan(Object.keys(valid).length)
for (const [url, result] of Object.entries(valid)) {
t.hasStrict(HostedGit.fromUrl(url), result, `${url} parses`)
}
})
t.test('invalid urls return undefined', t => {
t.plan(invalid.length)
for (const url of invalid) {
t.equal(HostedGit.fromUrl(url), undefined, `${url} returns undefined`)
}
})
t.test('toString respects defaults', t => {
const sshurl = HostedGit.fromUrl('git+ssh://gitlab.com/foo/bar')
t.equal(sshurl.default, 'sshurl', 'got the right default')
t.equal(sshurl.toString(), sshurl.sshurl(), 'toString calls sshurl')
const https = HostedGit.fromUrl('https://gitlab.com/foo/bar')
t.equal(https.default, 'https', 'got the right default')
t.equal(https.toString(), https.https(), 'toString calls https')
const shortcut = HostedGit.fromUrl('gitlab:foo/bar')
t.equal(shortcut.default, 'shortcut', 'got the right default')
t.equal(shortcut.toString(), shortcut.shortcut(), 'toString calls shortcut')
t.end()
})
t.test('string methods populate correctly', t => {
const parsed = HostedGit.fromUrl('git+ssh://gitlab.com/foo/bar')
t.equal(parsed.getDefaultRepresentation(), parsed.default)
t.equal(parsed.hash(), '', 'hash() returns empty string when committish is unset')
t.equal(parsed.ssh(), 'git@gitlab.com:foo/bar.git')
t.equal(parsed.sshurl(), 'git+ssh://git@gitlab.com/foo/bar.git')
t.equal(parsed.edit(), 'https://gitlab.com/foo/bar')
t.equal(parsed.edit('/lib/index.js'), 'https://gitlab.com/foo/bar/-/edit/HEAD/lib/index.js')
t.equal(parsed.browse(), 'https://gitlab.com/foo/bar')
t.equal(parsed.browse('/lib/index.js'), 'https://gitlab.com/foo/bar/tree/HEAD/lib/index.js')
t.equal(parsed.browse('/lib/index.js', 'L100'), 'https://gitlab.com/foo/bar/tree/HEAD/lib/index.js#l100')
t.equal(parsed.docs(), 'https://gitlab.com/foo/bar#readme')
t.equal(parsed.https(), 'git+https://gitlab.com/foo/bar.git')
t.equal(parsed.shortcut(), 'gitlab:foo/bar')
t.equal(parsed.path(), 'foo/bar')
t.equal(parsed.tarball(), 'https://gitlab.com/foo/bar/repository/archive.tar.gz?ref=HEAD')
t.equal(parsed.file(), 'https://gitlab.com/foo/bar/raw/HEAD/')
t.equal(parsed.file('/lib/index.js'), 'https://gitlab.com/foo/bar/raw/HEAD/lib/index.js')
t.equal(parsed.bugs(), 'https://gitlab.com/foo/bar/issues')
t.same(parsed.git(), null, 'git() returns null')
t.equal(parsed.docs({ committish: 'fix/bug' }), 'https://gitlab.com/foo/bar/tree/fix%2Fbug#readme', 'allows overriding options')
const extra = HostedGit.fromUrl('https://user@gitlab.com/foo/bar#fix/bug')
t.equal(extra.hash(), '#fix/bug')
t.equal(extra.https(), 'git+https://user@gitlab.com/foo/bar.git#fix/bug')
t.equal(extra.shortcut(), 'gitlab:foo/bar#fix/bug')
t.equal(extra.ssh(), 'git@gitlab.com:foo/bar.git#fix/bug')
t.equal(extra.sshurl(), 'git+ssh://git@gitlab.com/foo/bar.git#fix/bug')
t.equal(extra.browse(), 'https://gitlab.com/foo/bar/tree/fix%2Fbug')
t.equal(extra.browse('/lib/index.js'), 'https://gitlab.com/foo/bar/tree/fix%2Fbug/lib/index.js')
t.equal(extra.browse('/lib/index.js', 'L200'), 'https://gitlab.com/foo/bar/tree/fix%2Fbug/lib/index.js#l200')
t.equal(extra.docs(), 'https://gitlab.com/foo/bar/tree/fix%2Fbug#readme')
t.equal(extra.file(), 'https://gitlab.com/foo/bar/raw/fix%2Fbug/')
t.equal(extra.file('/lib/index.js'), 'https://gitlab.com/foo/bar/raw/fix%2Fbug/lib/index.js')
t.equal(extra.tarball(), 'https://gitlab.com/foo/bar/repository/archive.tar.gz?ref=fix%2Fbug')
t.equal(extra.sshurl({ noCommittish: true }), 'git+ssh://git@gitlab.com/foo/bar.git', 'noCommittish drops committish from urls')
t.equal(extra.sshurl({ noGitPlus: true }), 'ssh://git@gitlab.com/foo/bar.git#fix/bug', 'noGitPlus drops git+ prefix from urls')
t.end()
})
t.test('from manifest', t => {
t.equal(HostedGit.fromManifest(), undefined, 'no manifest returns undefined')
t.equal(HostedGit.fromManifest(), undefined, 'no manifest returns undefined')
t.equal(HostedGit.fromManifest(false), undefined, 'false manifest returns undefined')
t.equal(HostedGit.fromManifest(() => {}), undefined, 'function manifest returns undefined')
const unknownHostRepo = {
name: 'foo',
repository: {
url: 'https://nope.com',
},
}
t.same(HostedGit.fromManifest(unknownHostRepo), 'https://nope.com/')
const insecureUnknownHostRepo = {
name: 'foo',
repository: {
url: 'http://nope.com',
},
}
t.same(HostedGit.fromManifest(insecureUnknownHostRepo), 'https://nope.com/')
const insecureGitUnknownHostRepo = {
name: 'foo',
repository: {
url: 'git+http://nope.com',
},
}
t.same(HostedGit.fromManifest(insecureGitUnknownHostRepo), 'http://nope.com')
const badRepo = {
name: 'foo',
repository: {
url: '#',
},
}
t.equal(HostedGit.fromManifest(badRepo), null)
const manifest = {
name: 'foo',
repository: {
type: 'git',
url: 'git+ssh://gitlab.com/foo/bar.git',
},
}
const parsed = HostedGit.fromManifest(manifest)
t.same(parsed.browse(), 'https://gitlab.com/foo/bar')
const monorepo = {
name: 'clowncar',
repository: {
type: 'git',
url: 'git+ssh://gitlab.com/foo/bar.git',
directory: 'packages/foo',
},
}
const honk = HostedGit.fromManifest(monorepo)
t.same(honk.browse(monorepo.repository.directory), 'https://gitlab.com/foo/bar/tree/HEAD/packages/foo')
const stringRepo = {
name: 'foo',
repository: 'git+ssh://gitlab.com/foo/bar.git',
}
const stringRepoParsed = HostedGit.fromManifest(stringRepo)
t.same(stringRepoParsed.browse(), 'https://gitlab.com/foo/bar')
const nonStringRepo = {
name: 'foo',
repository: 42,
}
t.throws(() => HostedGit.fromManifest(nonStringRepo))
t.end()
})
hosted-git-info-9.0.2/test/invalid.js 0000664 0000000 0000000 00000001045 15071511065 0017466 0 ustar 00root root 0000000 0000000 const HostedGit = require('..')
const t = require('tap')
// each of these urls should return `undefined`
// none should throw
const urls = [
'https://google.com',
'git+ssh://git@nothosted.com/abc/def',
'git://nothosted.com',
'git+file:///foo/bar',
'git+ssh://git@git.unlucky.com:RND/electron-tools/some-tool#2.0.1',
'::',
'',
null,
undefined,
]
t.test('invalid results parse to undefined', t => {
t.plan(urls.length)
for (const url of urls) {
t.equal(HostedGit.fromUrl(url), undefined, `${url} returns undefined`)
}
})
hosted-git-info-9.0.2/test/localhost.js 0000664 0000000 0000000 00000001532 15071511065 0020031 0 ustar 00root root 0000000 0000000 const HostedGit = require('..')
const t = require('tap')
t.test('supports extensions', t => {
// An example of a custom setup, useful when testing modules like pacote,
// which do various things with these git shortcuts.
HostedGit.addHost('localhost', {
protocols: ['git:'],
domain: 'localhost',
extract: (url) => {
const [, user, project] = url.pathname.split('/')
return { user, project, committish: url.hash.slice(1) }
},
})
const hosted = HostedGit.fromUrl('git://localhost:12345/foo/bar')
t.match(
hosted,
{ type: 'localhost', default: 'git', user: 'foo', project: 'bar' },
'parsed correctly'
)
const shortcut = HostedGit.fromUrl('localhost:foo/bar')
t.match(
shortcut,
{ type: 'localhost', default: 'shortcut', user: 'foo', project: 'bar' },
'parsed correctly'
)
t.end()
})
hosted-git-info-9.0.2/test/parse-url.js 0000664 0000000 0000000 00000001374 15071511065 0017757 0 ustar 00root root 0000000 0000000 const t = require('tap')
const HostedGit = require('..')
const parseUrl = require('../lib/parse-url.js')
t.test('can parse git+ssh urls', async t => {
// https://github.com/npm/cli/issues/5278
const u = 'git+ssh://git@abc:frontend/utils.git#6d45447e0c5eb6cd2e3edf05a8c5a9bb81950c79'
t.ok(parseUrl(u))
t.ok(HostedGit.parseUrl(u))
})
t.test('can parse file urls', async t => {
// https://github.com/npm/cli/pull/5758#issuecomment-1292753331
const u = 'file:../../../global-prefix/lib/node_modules/@myscope/bar'
t.ok(parseUrl(u))
t.ok(HostedGit.parseUrl(u))
})
t.test('can parse custom urls', async t => {
const u = 'foobar://user:host@path'
t.ok(parseUrl(u, {}))
t.equal(parseUrl(u, {}).protocol, 'foobar:')
t.ok(HostedGit.parseUrl(u))
})
hosted-git-info-9.0.2/test/sourcehut.js 0000664 0000000 0000000 00000013204 15071511065 0020061 0 ustar 00root root 0000000 0000000 'use strict'
const HostedGit = require('..')
const t = require('tap')
const invalid = [
// missing project
'https://git.sr.ht/~foo',
// invalid protocos
'git://git@git.sr.ht:~foo/bar',
'ssh://git.sr.ht:~foo/bar',
// tarball url
'https://git.sr.ht/~foo/bar/archive/HEAD.tar.gz',
]
const defaults = { type: 'sourcehut', user: '~foo', project: 'bar' }
const valid = {
// shortucts
'sourcehut:~foo/bar': { ...defaults, default: 'shortcut' },
'sourcehut:~foo/bar#branch': { ...defaults, default: 'shortcut', committish: 'branch' },
// shortcuts (.git)
'sourcehut:~foo/bar.git': { ...defaults, default: 'shortcut' },
'sourcehut:~foo/bar.git#branch': { ...defaults, default: 'shortcut', committish: 'branch' },
// no-protocol git+ssh
'git@git.sr.ht:~foo/bar': { ...defaults, default: 'sshurl', auth: null },
'git@git.sr.ht:~foo/bar#branch': {
...defaults, default: 'sshurl', auth: null, committish: 'branch',
},
// no-protocol git+ssh (.git)
'git@git.sr.ht:~foo/bar.git': { ...defaults, default: 'sshurl', auth: null },
'git@git.sr.ht:~foo/bar.git#branch': {
...defaults, default: 'sshurl', auth: null, committish: 'branch',
},
// git+ssh urls
'git+ssh://git@git.sr.ht:~foo/bar': { ...defaults, default: 'sshurl' },
'git+ssh://git@git.sr.ht:~foo/bar#branch': {
...defaults, default: 'sshurl', committish: 'branch',
},
// git+ssh urls (.git)
'git+ssh://git@git.sr.ht:~foo/bar.git': { ...defaults, default: 'sshurl' },
'git+ssh://git@git.sr.ht:~foo/bar.git#branch': {
...defaults, default: 'sshurl', committish: 'branch',
},
// https urls
'https://git.sr.ht/~foo/bar': { ...defaults, default: 'https' },
'https://git.sr.ht/~foo/bar#branch': { ...defaults, default: 'https', committish: 'branch' },
'https://git.sr.ht/~foo/bar.git': { ...defaults, default: 'https' },
'https://git.sr.ht/~foo/bar.git#branch': { ...defaults, default: 'https', committish: 'branch' },
}
t.test('valid urls parse properly', t => {
t.plan(Object.keys(valid).length)
for (const [url, result] of Object.entries(valid)) {
t.hasStrict(HostedGit.fromUrl(url), result, `${url} parses`)
}
})
t.test('invalid urls return undefined', t => {
t.plan(invalid.length)
for (const url of invalid) {
t.equal(HostedGit.fromUrl(url), undefined, `${url} returns undefined`)
}
})
t.test('toString respects defaults', t => {
const sshurl = HostedGit.fromUrl('git+ssh://git.sr.ht/~foo/bar')
t.equal(sshurl.default, 'sshurl', 'got the right default')
t.equal(sshurl.toString(), sshurl.sshurl(), 'toString calls sshurl')
const https = HostedGit.fromUrl('https://git.sr.ht/~foo/bar')
t.equal(https.default, 'https', 'got the right default')
t.equal(https.toString(), https.https(), 'toString calls https')
const shortcut = HostedGit.fromUrl('sourcehut:~foo/bar')
t.equal(shortcut.default, 'shortcut', 'got the right default')
t.equal(shortcut.toString(), shortcut.shortcut(), 'toString calls shortcut')
t.end()
})
t.test('string methods populate correctly', t => {
const parsed = HostedGit.fromUrl('git+ssh://git.sr.ht/~foo/bar')
t.equal(parsed.getDefaultRepresentation(), parsed.default, 'getDefaultRepresentation()')
t.equal(parsed.hash(), '', 'hash() returns empty string when committish is unset')
t.equal(parsed.ssh(), 'git@git.sr.ht:~foo/bar.git')
t.equal(parsed.sshurl(), 'git+ssh://git@git.sr.ht/~foo/bar.git')
t.equal(parsed.edit('/lib/index.js'), 'https://git.sr.ht/~foo/bar', 'no editing, link to browse')
t.equal(parsed.edit(), 'https://git.sr.ht/~foo/bar', 'no editing, link to browse')
t.equal(parsed.browse(), 'https://git.sr.ht/~foo/bar')
t.equal(parsed.browse('/lib/index.js'), 'https://git.sr.ht/~foo/bar/tree/HEAD/lib/index.js')
t.equal(
parsed.browse('/lib/index.js', 'L100'),
'https://git.sr.ht/~foo/bar/tree/HEAD/lib/index.js#l100'
)
t.equal(parsed.docs(), 'https://git.sr.ht/~foo/bar#readme')
t.equal(parsed.https(), 'https://git.sr.ht/~foo/bar.git')
t.equal(parsed.shortcut(), 'sourcehut:~foo/bar')
t.equal(parsed.path(), '~foo/bar')
t.equal(parsed.tarball(), 'https://git.sr.ht/~foo/bar/archive/HEAD.tar.gz')
t.equal(parsed.file(), 'https://git.sr.ht/~foo/bar/blob/HEAD/')
t.equal(parsed.file('/lib/index.js'), 'https://git.sr.ht/~foo/bar/blob/HEAD/lib/index.js')
t.equal(parsed.bugs(), null)
t.equal(
parsed.docs({ committish: 'fix/bug' }),
'https://git.sr.ht/~foo/bar/tree/fix%2Fbug#readme',
'allows overriding options'
)
t.same(parsed.git(), null, 'git() returns null')
const extra = HostedGit.fromUrl('https://@git.sr.ht/~foo/bar#fix/bug')
t.equal(extra.hash(), '#fix/bug')
t.equal(extra.https(), 'https://git.sr.ht/~foo/bar.git#fix/bug')
t.equal(extra.shortcut(), 'sourcehut:~foo/bar#fix/bug')
t.equal(extra.ssh(), 'git@git.sr.ht:~foo/bar.git#fix/bug')
t.equal(extra.sshurl(), 'git+ssh://git@git.sr.ht/~foo/bar.git#fix/bug')
t.equal(extra.browse(), 'https://git.sr.ht/~foo/bar/tree/fix%2Fbug')
t.equal(extra.browse('/lib/index.js'), 'https://git.sr.ht/~foo/bar/tree/fix%2Fbug/lib/index.js')
t.equal(
extra.browse('/lib/index.js', 'L200'),
'https://git.sr.ht/~foo/bar/tree/fix%2Fbug/lib/index.js#l200'
)
t.equal(extra.docs(), 'https://git.sr.ht/~foo/bar/tree/fix%2Fbug#readme')
t.equal(extra.file(), 'https://git.sr.ht/~foo/bar/blob/fix%2Fbug/')
t.equal(extra.file('/lib/index.js'), 'https://git.sr.ht/~foo/bar/blob/fix%2Fbug/lib/index.js')
t.equal(
extra.sshurl({ noCommittish: true }),
'git+ssh://git@git.sr.ht/~foo/bar.git',
'noCommittish drops committish from urls'
)
t.equal(
extra.sshurl({ noGitPlus: true }),
'ssh://git@git.sr.ht/~foo/bar.git#fix/bug',
'noGitPlus drops git+ prefix from urls'
)
t.end()
})