How to use git-url-parse - 9 common examples

To help you get started, we’ve selected a few git-url-parse examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github umijs / umi / packages / umi-build-dev / src / plugins / commands / block / download.js View on Github external
export async function parseGitUrl(url, closeFastGithub) {
  const args = GitUrlParse(url);
  const { ref, filepath, resource, full_name: fullName } = args;
  const fastGithub = await getFastGithub();

  // 如果是 github 并且 autoFastGithub =true 使用
  // 因为自动转化只支持 github 也可以需要关掉
  const repo =
    resource === 'github.com' && !closeFastGithub
      ? args.toString().replace(`${resource}`, fastGithub)
      : args.toString();

  return {
    repo: urlAddGit(repo),
    branch: ref || 'master',
    path: `/${filepath}`,
    id: `${resource}/${fullName}`, // 唯一标识一个 git 仓库
  };
github DXHeroes / dx-scanner / src / detectors / ScanningStrategyDetector.ts View on Github external
private determineRemoteAccessType = async (remoteService: RemoteService): Promise => {
    if (!remoteService.remoteUrl) {
      return undefined;
    }

    if (remoteService.serviceType === ServiceType.github) {
      const parsedUrl = gitUrlParse(remoteService.remoteUrl);

      // eslint-disable-next-line @typescript-eslint/no-explicit-any
      let response: any;
      try {
        response = await this.gitHubService.getRepo(parsedUrl.owner, parsedUrl.name);
      } catch (error) {
        this.detectorDebug(error.message);
        if (error.status === 401 || error.status === 404 || error.status === 403) {
          throw ErrorFactory.newAuthorizationError('You passed bad credentials or non existing repo.');
        }
        throw error;
      }

      if (response.status === 200) {
        if (response.data.private === true) {
          return AccessType.private;
github antvis / gatsby-theme-antv / @antv / gatsby-theme-antv / site / components / Header.tsx View on Github external
window.location.href = window.location.href.replace(
      'antv.vision',
      'antv.gitee.io',
    );
    return;
  }
  // g2plot.antv.vision => antv-g2plot.gitee.io
  const match = window.location.href.match(/(.*)\.antv\.vision/);
  if (match && match[1]) {
    window.location.href = window.location.href.replace(
      /(.*)\.antv\.vision/,
      `https://antv-${match[1]}.gitee.io`,
    );
    return;
  }
  const { name } = GitUrlParse(githubUrl);
  if (!name.includes('.') && !name.includes('-')) {
    window.location.href = window.location.href.replace(
      name,
      `https://antv-${name}.gitee.io`,
    );
  }
  message.info('镜像本地调试暂时无法跳转。');
};
github taichi / ci-yarn-upgrade / src / github.js View on Github external
function selectGetTagsPromise(LOG, github, c) {
    if (c.repo) {
        let url = giturl(c.repo);
        if (url.owner && url.name) {
            LOG(`BEGIN getTags from ${url.toString("https")}`);
            let request = { owner: url.owner, repo: url.name, namespace: "tags/" };
            return github.paginate("GET /repos/:owner/:repo/git/refs/:namespace",
                request, response => response.data.map(t => t.ref.split("/")[2]))
                .then(tags => {
                    LOG(`END   getTags ${tags}`);
                    c.tags = new Set(tags);
                    return c;
                }, err => {
                    LOG(`END   getTags ${request} ${err}`);
                    return c;
                });
        }
    }
    return Promise.resolve(c);
github arcanis / sherlock / sources / commands / entry.ts View on Github external
async execute() {
        const pkgPath = await pkgUp();
        if (pkgPath === null)
            throw new UsageError(`This command must be run from within a package`);

        let body: string;

        if (existsSync(this.issue)) {
            body = readFileSync(this.issue, `utf8`);
        } else {
            const packageJson = JSON.parse(readFileSync(pkgPath, `utf8`));
            if (!packageJson.repository || packageJson.repository.type !== `git` || !packageJson.repository.url)
                throw new UsageError(`This command must be run from within a package linked to a repository`);

            const {owner, name: repo} = gitUrlParse(packageJson.repository.url);
            if (!owner || !repo)
                throw new UsageError(`This command must be run from within a package linked to a GitHub repository`);

            const octokit = new Octokit({
                auth: process.env.GITHUB_TOKEN,
            });

            if (!process.env.GITHUB_TOKEN && process.env.GITHUB_ACTIONS)
                throw new UsageError(`Missing GitHub token in the environment`);

            let issue: number;

            const githubMatch = this.issue.match(GITHUB_REGEXP);
            if (githubMatch) {
                issue = parseInt(githubMatch[3], 10);
            } else {
github porchdotcom / up-to-code / src / index.js View on Github external
)).then(stdout => (
        parse(stdout).resource
    )).then(hostname => {
        const isGithubHosted = hostname === GITHUB_HOSTNAME;
github microsoft / beachball / packages / beachball / src / git.ts View on Github external
function normalizeRepoUrl(repositoryUrl: string) {
  try {
    const parsed = gitUrlParse(repositoryUrl);
    return parsed
      .toString('https')
      .replace(/\.git$/, '')
      .toLowerCase();
  } catch (e) {
    return '';
  }
}
github amazeeio / lagoon / services / ui / src / components / ProjectDetailsSidebar / index.js View on Github external
const Project = ({ project }) => {
  const [copied, setCopied] = useState(false);
  const gitUrlParsed = giturlparse(project.gitUrl);
  const gitLink = `${gitUrlParsed.resource}/${gitUrlParsed.full_name}`;
  const environmentCount = R.countBy(R.prop('environmentType'))(
    project.environments
  );
  const developEnvironmentCount = R.propOr(0, 'development', environmentCount);

  return (
    <div>
      <div>
        <div>
          <label>Created</label>
          <div>
            {moment
              .utc(project.created)
              .local()
              .format('DD MMM YYYY, HH:mm:ss (Z)')}</div></div></div></div>
github facade / ignition / resources / js / components / Tabs / ContextTab.vue View on Github external
repoUrl() {
            if (!this.git.remote) {
                return null;
            }

            const git = {
                ...this.repoInfo,
                git_suffix: false,
            };

            return gitUrlParse.stringify(git, 'https');
        },

git-url-parse

A high level git url parser for common git providers.

MIT
Latest version published 1 month ago

Package Health Score

85 / 100
Full package analysis

Popular git-url-parse functions