This commit is contained in:
darenhsu
2022-07-17 13:16:16 +08:00
parent 84759556ff
commit befd344ab0
28070 changed files with 4008428 additions and 1 deletions
+21
View File
@@ -0,0 +1,21 @@
The MIT License (MIT)
Copyright (c) 2015-19 Ionică Bizău <bizauionica@gmail.com> (https://ionicabizau.net)
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.
+275
View File
@@ -0,0 +1,275 @@
<!-- Please do not edit this file. Edit the `blah` field in the `package.json` instead. If in doubt, open an issue. -->
[![git-url-parse](http://i.imgur.com/HlfMsVf.png)](#)
# git-url-parse
[![Support me on Patreon][badge_patreon]][patreon] [![Buy me a book][badge_amazon]][amazon] [![PayPal][badge_paypal_donate]][paypal-donations] [![Ask me anything](https://img.shields.io/badge/ask%20me-anything-1abc9c.svg)](https://github.com/IonicaBizau/ama) [![Travis](https://img.shields.io/travis/IonicaBizau/git-url-parse.svg)](https://travis-ci.org/IonicaBizau/git-url-parse/) [![Version](https://img.shields.io/npm/v/git-url-parse.svg)](https://www.npmjs.com/package/git-url-parse) [![Downloads](https://img.shields.io/npm/dt/git-url-parse.svg)](https://www.npmjs.com/package/git-url-parse) [![Get help on Codementor](https://cdn.codementor.io/badges/get_help_github.svg)](https://www.codementor.io/johnnyb?utm_source=github&utm_medium=button&utm_term=johnnyb&utm_campaign=github)
<a href="https://www.buymeacoffee.com/H96WwChMy" target="_blank"><img src="https://www.buymeacoffee.com/assets/img/custom_images/yellow_img.png" alt="Buy Me A Coffee"></a>
> A high level git url parser for common git providers.
## :cloud: Installation
```sh
# Using npm
npm install --save git-url-parse
# Using yarn
yarn add git-url-parse
```
## :clipboard: Example
```js
// Dependencies
const GitUrlParse = require("git-url-parse");
console.log(GitUrlParse("git@github.com:IonicaBizau/node-git-url-parse.git"));
// => {
// protocols: []
// , port: null
// , resource: "github.com"
// , user: "git"
// , pathname: "/IonicaBizau/node-git-url-parse.git"
// , hash: ""
// , search: ""
// , href: "git@github.com:IonicaBizau/node-git-url-parse.git"
// , token: ""
// , protocol: "ssh"
// , toString: [Function]
// , source: "github.com"
// , name: "node-git-url-parse"
// , owner: "IonicaBizau"
// }
console.log(GitUrlParse("https://github.com/IonicaBizau/node-git-url-parse.git"));
// => {
// protocols: ["https"]
// , port: null
// , resource: "github.com"
// , user: ""
// , pathname: "/IonicaBizau/node-git-url-parse.git"
// , hash: ""
// , search: ""
// , href: "https://github.com/IonicaBizau/node-git-url-parse.git"
// , token: ""
// , protocol: "https"
// , toString: [Function]
// , source: "github.com"
// , name: "node-git-url-parse"
// , owner: "IonicaBizau"
// }
console.log(GitUrlParse("https://github.com/IonicaBizau/git-url-parse/blob/master/test/index.js"));
// { protocols: [ 'https' ],
// protocol: 'https',
// port: null,
// resource: 'github.com',
// user: '',
// pathname: '/IonicaBizau/git-url-parse/blob/master/test/index.js',
// hash: '',
// search: '',
// href: 'https://github.com/IonicaBizau/git-url-parse/blob/master/test/index.js',
// token: '',
// toString: [Function],
// source: 'github.com',
// name: 'git-url-parse',
// owner: 'IonicaBizau',
// organization: '',
// ref: 'master',
// filepathtype: 'blob',
// filepath: 'test/index.js',
// full_name: 'IonicaBizau/git-url-parse' }
console.log(GitUrlParse("https://github.com/IonicaBizau/node-git-url-parse.git").toString("ssh"));
// => "git@github.com:IonicaBizau/node-git-url-parse.git"
console.log(GitUrlParse("git@github.com:IonicaBizau/node-git-url-parse.git").toString("https"));
// => "https://github.com/IonicaBizau/node-git-url-parse.git"
```
## :question: Get Help
There are few ways to get help:
1. Please [post questions on Stack Overflow](https://stackoverflow.com/questions/ask). You can open issues with questions, as long you add a link to your Stack Overflow question.
2. For bug reports and feature requests, open issues. :bug:
3. For direct and quick help, you can [use Codementor](https://www.codementor.io/johnnyb). :rocket:
## :memo: Documentation
### `gitUrlParse(url)`
Parses a Git url.
#### Params
- **String** `url`: The Git url to parse.
#### Return
- **GitUrl** The `GitUrl` object containing:
- `protocols` (Array): An array with the url protocols (usually it has one element).
- `port` (null|Number): The domain port.
- `resource` (String): The url domain (including subdomains).
- `user` (String): The authentication user (usually for ssh urls).
- `pathname` (String): The url pathname.
- `hash` (String): The url hash.
- `search` (String): The url querystring value.
- `href` (String): The input url.
- `protocol` (String): The git url protocol.
- `token` (String): The oauth token (could appear in the https urls).
- `source` (String): The Git provider (e.g. `"github.com"`).
- `owner` (String): The repository owner.
- `name` (String): The repository name.
- `ref` (String): The repository ref (e.g., "master" or "dev").
- `filepath` (String): A filepath relative to the repository root.
- `filepathtype` (String): The type of filepath in the url ("blob" or "tree").
- `full_name` (String): The owner and name values in the `owner/name` format.
- `toString` (Function): A function to stringify the parsed url into another url type.
- `organization` (String): The organization the owner belongs to. This is CloudForge specific.
- `git_suffix` (Boolean): Whether to add the `.git` suffix or not.
### `stringify(obj, type)`
Stringifies a `GitUrl` object.
#### Params
- **GitUrl** `obj`: The parsed Git url object.
- **String** `type`: The type of the stringified url (default `obj.protocol`).
#### Return
- **String** The stringified url.
## :yum: How to contribute
Have an idea? Found a bug? See [how to contribute][contributing].
## :sparkling_heart: Support my projects
I open-source almost everything I can, and I try to reply to everyone needing help using these projects. Obviously,
this takes time. You can integrate and use these projects in your applications *for free*! You can even change the source code and redistribute (even resell it).
However, if you get some profit from this or just want to encourage me to continue creating stuff, there are few ways you can do it:
- Starring and sharing the projects you like :rocket:
- [![Buy me a book][badge_amazon]][amazon]—I love books! I will remember you after years if you buy me one. :grin: :book:
- [![PayPal][badge_paypal]][paypal-donations]—You can make one-time donations via PayPal. I'll probably buy a ~~coffee~~ tea. :tea:
- [![Support me on Patreon][badge_patreon]][patreon]—Set up a recurring monthly donation and you will get interesting news about what I'm doing (things that I don't share with everyone).
- **Bitcoin**—You can send me bitcoins at this address (or scanning the code below): `1P9BRsmazNQcuyTxEqveUsnf5CERdq35V6`
![](https://i.imgur.com/z6OQI95.png)
Thanks! :heart:
## :dizzy: Where is this library used?
If you are using this library in one of your projects, add it in this list. :sparkles:
- [`auto-changelog-vsts`](https://github.com/denisonluz/auto-changelog-vsts) (by Pete Cook)—Command line tool for generating a changelog from git tags and commit history
- [`autorelease-setup`](https://github.com/tyler-johnson/autorelease-setup#readme) (by Tyler Johnson)—A CLI tool for setting up a repository with autorelease.
- [`belt-repo`](https://npmjs.com/package/belt-repo) (by ewnd9)—repo module for belt
- [`bibi`](https://github.com/steelbrain/bibi#readme) (by steelbrain)—A repository management tool
- [`bitbucket-pullr`](https://github.com/julien-langlois/bitbucket-pr#readme) (by Julien Langlois)—CLI for creating Bitbucket pull request
- [`branch-release`](https://github.com/RomanGotsiy/branch-release#readme) (by Roman Hotsiy)—Build and tag package realease on a separate branch
- [`changelog.md`](https://github.com/egoist/changelog.md#readme) (by EGOIST)—Manage CHANGELOG.md so easy it hurts.
- [`ci-yarn-upgrade`](https://github.com/taichi/ci-yarn-upgrade) (by taichi)—Keep NPM dependencies up-to-date with CI, providing version-to-version diff for each library
- [`clipped`](https://github.com/clippedjs/clipped#readme) (by IniZio)—Reduce pain of configuration to once
- [`committing`](https://github.com/axetroy/committing#readme) (by Axetroy)—commit every days
- [`common-boilerplate`](https://github.com/node-modules/common-boilerplate#readme) (by TZ)—base class for boilerplate
- [`complan`](https://github.com/pranavparikh/complan#readme) (by Pranav Parikh)—COMPLexity ANalyzer Tool For Javascript
- [`create-apex-js-app`](https://github.com/dfrechdev/create-apex-js-app#readme) (by Daniel Frech)—Bootstrap a JavaScript app for Oracle APEX applications
- [`create-openapi-repo`](https://github.com/Rebilly/generator-openapi-repo#readme) (by Roman Hotsiy)—Generator of OpenAPI(fka Swagger) repository
- [`create-sourcegraph-extension`](https://github.com/sourcegraph/create-extension#readme)—CLI to generate the skeleton for a Sourcegraph extension
- [`cz-conventional-changelog-befe`](https://github.com/be-fe/cz-conventional-changelog-befe#readme) (by teeeemoji)—cz adaptor for baidu BEFE
- [`def-core`](https://npmjs.com/package/def-core) (by tbfed)—def core for deflite
- [`docula-ui`](https://npmjs.com/package/docula-ui)—Express.js bindings for Docula project
- [`docula-ui-express`](https://npmjs.com/package/docula-ui-express)—Express.js bindings for Docula project
- [`documentation`](https://github.com/documentationjs/documentation#readme) (by Tom MacWright)—a documentation generator
- [`documentation-custom-markdown`](https://npmjs.com/package/documentation-custom-markdown) (by Tom MacWright)—a documentation generator
- [`documentation-fork`](https://github.com/documentationjs/documentation#readme) (by Tom MacWright)—a documentation generator
- [`documentation-habitlab`](https://github.com/documentationjs/documentation#readme) (by Tom MacWright)—a documentation generator
- [`download-repo-cli`](https://github.com/egoist/download-repo-cli#readme) (by EGOIST)—CLI tool to download GitHub repo.
- [`gd-cli`](https://npmjs.com/package/gd-cli) (by Sylvain Baronnet)—GD Command Line Interface
- [`generate-preview`](https://github.com/citizensas/generate-preview#readme) (by Sassoun Derderian)—Get a preview from a git branch before publishing your npm package
- [`generator-ckeditor4`](https://github.com/mlewand/generator-ckeditor4#readme) (by Marek Lewandowski)—Yeoman generator for CKEditor 4
- [`generator-clearphp`](https://github.com/jkphl/generator-clearphp#readme) (by Joschi Kuphal)—Scaffold for Composer based PHP projects with a lot of integrations, advocating the use of The Clear Architecture (https://jkphl.is/articles/clear-architecture-php)
- [`generator-nm-bti`](https://gitlab.com/beneaththeink/generator-nm-bti#README) (by Tyler Johnson)—Scaffold out a node module, Beneath the Ink style.
- [`generator-openapi-repo`](https://github.com/Rebilly/generator-openapi-repo#readme) (by Roman Hotsiy)—Yeoman generator for OpenAPI(fka Swagger) repo to help you share spec for your API
- [`git-cherry-fix`](https://npmjs.com/package/git-cherry-fix)—> helps you get your fixes to another branch by cherry-picking them
- [`git-issues`](https://github.com/softwarescales/git-issues) (by Gabriel Petrovay)—Git issues extension to list issues of a Git project
- [`git-lab-cli`](https://npmjs.com/package/git-lab-cli)—gitlab-cli ==================
- [`git-signed`](https://github.com/Wizcorp/git-signed#readme) (by Marc Trudel)—git commit signing made easy (and enforceable)
- [`git-source`](https://github.com/IonicaBizau/git-source#readme)—Parse and stringify git urls in a friendly way.
- [`git-upstream`](https://github.com/Leko/git-upstream#readme) (by Leko)—Utility to set the remote "upstream" on forked repository
- [`git-url-promise`](https://github.com/joshuan/git-url#readme) (by Evgeniy Shershnev)—Git url promise
- [`gitbook-start-https-alex-moi`](https://github.com/ULL-ESIT-SYTW-1617/https-al-servidor-del-libro-alex-moi.git#readme) (by Moises Yanes Carballo)—Plugin deploy iaas https
- [`gitbook-start-iaas-bbdd-alex-moi`](https://github.com/ULL-ESIT-SYTW-1617/practica-localstrategy-y-base-de-datos-alex-moi.git#readme) (by Moises Yanes Carballo)—Plugin deploy iaas bbdd
- [`gitbook-start-iaas-ull-es-alex-moi`](https://github.com/ULL-ESIT-SYTW-1617/gitbook-start-iaas-ull-es-alex-moi.git#readme) (by Moises Yanes Carballo)—Plugin deploy maquina iaas-ull-es
- [`gitbook-start-iaas-ull-es-merquililycony`](https://github.com/ULL-ESIT-SYTW-1617/gitbook-start-iaas-ull-es-merquililycony#readme) (by Constanza León, Merquis Cruz, Liliana Galiano)—*El objetivo de esta práctica es extender el package NodeJS publicado en npm en una práctica anterior con una nueva*
*funcionalidad que permita que los usuarios realizar un despliegue automatico en el servidor de IAAS*
- [`gitbook-start-plugin-iaas-ull-es-noejaco2017`](http://creacion-de-paquetes-y-modulos-en-nodejs-noejaco2017/README.md) (by alu0100622492)—Despliegue plugin Iaas
- [`gitc`](https://github.com/cezarlz/gitc#readme) (by Cezar Luiz)—Manage your pull requests and issues from your command line.
- [`github-publish-npm`](https://github.com/ofersadgat/github-publish-npm) (by Ofer Sadgat)—This will upload publish npm assets to the GitHub Releases API.
- [`gitlab-ci-variables-cli`](https://github.com/temando/gitlab-ci-variables-cli#readme) (by Khoa Tran)—CLI tool to set/get pipeline variables on Gitlab CI.
- [`gitlab-tool-cli`](https://npmjs.com/package/gitlab-tool-cli)—gitlab-tool-cli ==================
- [`gitline`](https://github.com/cezarlz/gitline#readme) (by Cezar Luiz)—Manage your pull requests and issues from your command line.
- [`gtni`](https://nmrony.github.io/gtni) (by Nur Rony)—Install your all npm dependencies recursively with gtni while you are doing git clone, fetch or pull
- [`gub`](https://github.com/janryWang/gub#readme) (by janry)—> 接入成本极低,快速从原有项目(可运行项目)中clone出新项目,并重写package.json,安装依赖
- [`harry-reporter`](https://github.com/harry-reporter/harry-reporter#readme)—Reporter plugin for hermione
- [`just-dev-sdk`](https://github.com/just-group/just-dev-sdk#readme) (by zoujie.wzj)—just development sdk
- [`kef-core`](https://npmjs.com/package/kef-core) (by younth)—The awesome KEF
- [`konitor`](https://github.com/konnectors/konitor#readme) (by Simon Constans)—The command-line tool for monitoring konnectors
- [`lcov-server`](https://github.com/gabrielcsapo/lcov-server#readme) (by Gabriel J. Csapo)—🎯 A simple lcov server & cli parser
- [`miguelcostero-ng2-toasty`](https://github.com/akserg/ng2-toasty) (by Sergey Akopkokhyants)—Angular2 Toasty component shows growl-style alerts and messages for your web app
- [`moto-connector`](https://npmjs.com/package/moto-connector) (by limingv5)—JAN平台SDK
- [`node-norman`](https://github.com/zenwarr/norman#readme) (by zenwarr)—A tool to develop multi-package Node.js apps with ease.
- [`nodeschool-admin`](https://github.com/nodeschool/admin#readme) (by Martin Heidegger)—CLI tool for setting up and maintaining a nodeschool chapters and other things.
- [`ogh`](https://github.com/egoist/ogh#readme) (by EGOIST)—Open GitHub Page of your repo directly in Terminal.
- [`one-more-gitlab-cli`](https://github.com/chamerling/one-more-gitlab-cli) (by Christophe Hamerling)—One more Gitlab CLI
- [`pr-log`](https://github.com/lo1tuma/pr-log#readme) (by Mathias Schreck)—Changelog generator based on GitHub Pull Requests
- [`proyecto-sytw-alex-moi`](https://github.com/ULL-ESIT-SYTW-1617/proyecto-sytw-16-17-alex-moi#readme) (by Moises Yanes Carballo)—Module to build a book on GitBook
- [`semantic-release-gitmoji`](https://github.com/momocow/semantic-release-gitmoji#readme) (by MomoCow)—Different from conventional changelog, Gitmoji commits are used to determine a release type and generate release notes.
- [`sherry-utils`](https://github.com/sherry/sherry/packages/sherry-utils#readme) (by ULIVZ)—sherry-utils for Sherry
- [`ship-release`](https://github.com/IonicaBizau/ship-release#readme)—Publish new versions on GitHub and npm with ease.
- [`sinit`](https://npmjs.com/package/sinit) (by villadora)—Project initializer based on Scaffold
- [`smart-clone`](https://github.com/ethernetdan/smart-clone#readme)—Clone a directory into a Golang style directory structure
- [`snipx`](https://npmjs.com/package/snipx)—Best team snippets
- [`ssh-remote`](https://github.com/IonicaBizau/ssh-remote)—Automagically switch on the SSH remote url in a Git repository.
- [`strapper`](https://npmjs.com/package/strapper) (by Sam Newman)—Coming Soon
- [`testarmada-midway`](http://testarmada.io/documentation/Mocking/rWeb/JAVASCRIPT/Introduction) (by Himanshu Jain)—Mocking server to create reliable test data for test execution and development
- [`vscode-gpm`](https://github.com/axetroy/vscode-gpm#readme)—Git Project Manager
- [`yarn-upgrade-on-ci`](https://npmjs.com/package/yarn-upgrade-on-ci) (by htwroclau)—undefined
## :scroll: License
[MIT][license] © [Ionică Bizău][website]
[badge_patreon]: https://ionicabizau.github.io/badges/patreon.svg
[badge_amazon]: https://ionicabizau.github.io/badges/amazon.svg
[badge_paypal]: https://ionicabizau.github.io/badges/paypal.svg
[badge_paypal_donate]: https://ionicabizau.github.io/badges/paypal_donate.svg
[patreon]: https://www.patreon.com/ionicabizau
[amazon]: http://amzn.eu/hRo9sIZ
[paypal-donations]: https://www.paypal.com/cgi-bin/webscr?cmd=_s-xclick&hosted_button_id=RVXDDLKKLQRJW
[license]: http://showalicense.com/?fullname=Ionic%C4%83%20Biz%C4%83u%20%3Cbizauionica%40gmail.com%3E%20(https%3A%2F%2Fionicabizau.net)&year=2015#license-mit
[website]: https://ionicabizau.net
[contributing]: /CONTRIBUTING.md
+227
View File
@@ -0,0 +1,227 @@
"use strict";
var gitUp = require("git-up");
/**
* gitUrlParse
* Parses a Git url.
*
* @name gitUrlParse
* @function
* @param {String} url The Git url to parse.
* @return {GitUrl} The `GitUrl` object containing:
*
* - `protocols` (Array): An array with the url protocols (usually it has one element).
* - `port` (null|Number): The domain port.
* - `resource` (String): The url domain (including subdomains).
* - `user` (String): The authentication user (usually for ssh urls).
* - `pathname` (String): The url pathname.
* - `hash` (String): The url hash.
* - `search` (String): The url querystring value.
* - `href` (String): The input url.
* - `protocol` (String): The git url protocol.
* - `token` (String): The oauth token (could appear in the https urls).
* - `source` (String): The Git provider (e.g. `"github.com"`).
* - `owner` (String): The repository owner.
* - `name` (String): The repository name.
* - `ref` (String): The repository ref (e.g., "master" or "dev").
* - `filepath` (String): A filepath relative to the repository root.
* - `filepathtype` (String): The type of filepath in the url ("blob" or "tree").
* - `full_name` (String): The owner and name values in the `owner/name` format.
* - `toString` (Function): A function to stringify the parsed url into another url type.
* - `organization` (String): The organization the owner belongs to. This is CloudForge specific.
* - `git_suffix` (Boolean): Whether to add the `.git` suffix or not.
*
*/
function gitUrlParse(url) {
if (typeof url !== "string") {
throw new Error("The url must be a string.");
}
var urlInfo = gitUp(url),
sourceParts = urlInfo.resource.split("."),
splits = null;
urlInfo.toString = function (type) {
return gitUrlParse.stringify(this, type);
};
urlInfo.source = sourceParts.length > 2 ? sourceParts.slice(1 - sourceParts.length).join(".") : urlInfo.source = urlInfo.resource;
// Note: Some hosting services (e.g. Visual Studio Team Services) allow whitespace characters
// in the repository and owner names so we decode the URL pieces to get the correct result
urlInfo.git_suffix = /\.git$/.test(urlInfo.pathname);
urlInfo.name = decodeURIComponent(urlInfo.pathname.replace(/^\//, '').replace(/\.git$/, ""));
urlInfo.owner = decodeURIComponent(urlInfo.user);
switch (urlInfo.source) {
case "git.cloudforge.com":
urlInfo.owner = urlInfo.user;
urlInfo.organization = sourceParts[0];
urlInfo.source = "cloudforge.com";
break;
case "visualstudio.com":
// Handle VSTS SSH URLs
if (urlInfo.resource === 'vs-ssh.visualstudio.com') {
splits = urlInfo.name.split("/");
if (splits.length === 4) {
urlInfo.organization = splits[1];
urlInfo.owner = splits[2];
urlInfo.name = splits[3];
urlInfo.full_name = splits[2] + '/' + splits[3];
}
break;
} else {
splits = urlInfo.name.split("/");
if (splits.length === 2) {
urlInfo.owner = splits[1];
urlInfo.name = splits[1];
urlInfo.full_name = '_git/' + urlInfo.name;
} else if (splits.length === 3) {
urlInfo.name = splits[2];
if (splits[0] === 'DefaultCollection') {
urlInfo.owner = splits[2];
urlInfo.organization = splits[0];
urlInfo.full_name = urlInfo.organization + '/_git/' + urlInfo.name;
} else {
urlInfo.owner = splits[0];
urlInfo.full_name = urlInfo.owner + '/_git/' + urlInfo.name;
}
} else if (splits.length === 4) {
urlInfo.organization = splits[0];
urlInfo.owner = splits[1];
urlInfo.name = splits[3];
urlInfo.full_name = urlInfo.organization + '/' + urlInfo.owner + '/_git/' + urlInfo.name;
}
break;
}
// Azure DevOps (formerly Visual Studio Team Services)
case "dev.azure.com":
case "azure.com":
if (urlInfo.resource === 'ssh.dev.azure.com') {
splits = urlInfo.name.split("/");
if (splits.length === 4) {
urlInfo.organization = splits[1];
urlInfo.owner = splits[2];
urlInfo.name = splits[3];
}
break;
} else {
splits = urlInfo.name.split("/");
if (splits.length === 5) {
urlInfo.organization = splits[0];
urlInfo.owner = splits[1];
urlInfo.name = splits[4];
urlInfo.full_name = '_git/' + urlInfo.name;
} else if (splits.length === 3) {
urlInfo.name = splits[2];
if (splits[0] === 'DefaultCollection') {
urlInfo.owner = splits[2];
urlInfo.organization = splits[0];
urlInfo.full_name = urlInfo.organization + '/_git/' + urlInfo.name;
} else {
urlInfo.owner = splits[0];
urlInfo.full_name = urlInfo.owner + '/_git/' + urlInfo.name;
}
} else if (splits.length === 4) {
urlInfo.organization = splits[0];
urlInfo.owner = splits[1];
urlInfo.name = splits[3];
urlInfo.full_name = urlInfo.organization + '/' + urlInfo.owner + '/_git/' + urlInfo.name;
}
break;
}
default:
splits = urlInfo.name.split("/");
var nameIndex = splits.length - 1;
if (splits.length >= 2) {
var blobIndex = splits.indexOf("blob", 2);
var treeIndex = splits.indexOf("tree", 2);
var commitIndex = splits.indexOf("commit", 2);
nameIndex = blobIndex > 0 ? blobIndex - 1 : treeIndex > 0 ? treeIndex - 1 : commitIndex > 0 ? commitIndex - 1 : nameIndex;
urlInfo.owner = splits.slice(0, nameIndex).join('/');
urlInfo.name = splits[nameIndex];
if (commitIndex) {
urlInfo.commit = splits[nameIndex + 2];
}
}
urlInfo.ref = "";
urlInfo.filepathtype = "";
urlInfo.filepath = "";
if (splits.length > nameIndex + 2 && ["blob", "tree"].indexOf(splits[nameIndex + 1]) >= 0) {
urlInfo.filepathtype = splits[nameIndex + 1];
urlInfo.ref = splits[nameIndex + 2];
if (splits.length > nameIndex + 3) {
urlInfo.filepath = splits.slice(nameIndex + 3).join('/');
}
}
urlInfo.organization = urlInfo.owner;
break;
}
if (!urlInfo.full_name) {
urlInfo.full_name = urlInfo.owner;
if (urlInfo.name) {
urlInfo.full_name && (urlInfo.full_name += "/");
urlInfo.full_name += urlInfo.name;
}
}
return urlInfo;
}
/**
* stringify
* Stringifies a `GitUrl` object.
*
* @name stringify
* @function
* @param {GitUrl} obj The parsed Git url object.
* @param {String} type The type of the stringified url (default `obj.protocol`).
* @return {String} The stringified url.
*/
gitUrlParse.stringify = function (obj, type) {
type = type || (obj.protocols && obj.protocols.length ? obj.protocols.join('+') : obj.protocol);
var port = obj.port ? ":" + obj.port : '';
var user = obj.user || 'git';
var maybeGitSuffix = obj.git_suffix ? ".git" : "";
switch (type) {
case "ssh":
if (port) return "ssh://" + user + "@" + obj.resource + port + "/" + obj.full_name + maybeGitSuffix;else return user + "@" + obj.resource + ":" + obj.full_name + maybeGitSuffix;
case "git+ssh":
case "ssh+git":
case "ftp":
case "ftps":
return type + "://" + user + "@" + obj.resource + port + "/" + obj.full_name + maybeGitSuffix;
case "http":
case "https":
var auth = obj.token ? buildToken(obj) : obj.user && (obj.protocols.includes('http') || obj.protocols.includes('https')) ? obj.user + "@" : "";
return type + "://" + auth + obj.resource + port + "/" + obj.full_name + maybeGitSuffix;
default:
return obj.href;
}
};
/*!
* buildToken
* Builds OAuth token prefix (helper function)
*
* @name buildToken
* @function
* @param {GitUrl} obj The parsed Git url object.
* @return {String} token prefix
*/
function buildToken(obj) {
switch (obj.source) {
case "bitbucket.org":
return "x-token-auth:" + obj.token + "@";
default:
return obj.token + "@";
}
}
module.exports = gitUrlParse;
+84
View File
@@ -0,0 +1,84 @@
{
"_args": [
[
"git-url-parse@11.1.2",
"/mnt/Foxconn/Digitalent/Deverloper/liff-push_2series"
]
],
"_from": "git-url-parse@11.1.2",
"_id": "git-url-parse@11.1.2",
"_inBundle": false,
"_integrity": "sha512-gZeLVGY8QVKMIkckncX+iCq2/L8PlwncvDFKiWkBn9EtCfYDbliRTTp6qzyQ1VMdITUfq7293zDzfpjdiGASSQ==",
"_location": "/git-url-parse",
"_phantomChildren": {},
"_requested": {
"type": "version",
"registry": true,
"raw": "git-url-parse@11.1.2",
"name": "git-url-parse",
"escapedName": "git-url-parse",
"rawSpec": "11.1.2",
"saveSpec": null,
"fetchSpec": "11.1.2"
},
"_requiredBy": [
"/@nuxt/telemetry"
],
"_resolved": "https://registry.npmjs.org/git-url-parse/-/git-url-parse-11.1.2.tgz",
"_spec": "11.1.2",
"_where": "/mnt/Foxconn/Digitalent/Deverloper/liff-push_2series",
"author": {
"name": "Ionică Bizău",
"email": "bizauionica@gmail.com",
"url": "https://ionicabizau.net"
},
"blah": {
"h_img": "http://i.imgur.com/HlfMsVf.png"
},
"bugs": {
"url": "https://github.com/IonicaBizau/git-url-parse/issues"
},
"dependencies": {
"git-up": "^4.0.0"
},
"description": "A high level git url parser for common git providers.",
"devDependencies": {
"tester": "^1.3.1"
},
"directories": {
"example": "example",
"test": "test"
},
"files": [
"bin/",
"app/",
"lib/",
"dist/",
"src/",
"scripts/",
"resources/",
"menu/",
"cli.js",
"index.js",
"bloggify.js",
"bloggify.json",
"bloggify/"
],
"homepage": "https://github.com/IonicaBizau/git-url-parse",
"keywords": [
"parse",
"git",
"url"
],
"license": "MIT",
"main": "lib/index.js",
"name": "git-url-parse",
"repository": {
"type": "git",
"url": "git+ssh://git@github.com/IonicaBizau/git-url-parse.git"
},
"scripts": {
"test": "node test"
},
"version": "11.1.2"
}