How to use git-parse - 1 common examples

To help you get started, we’ve selected a few git-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 apollographql / apollo-tooling / packages / apollo / src / git.ts View on Github external
// Occasionally `branch` will be undefined depending on the environment, so
  // we need to fallback on `prBranch`. However in some cases, we are not able
  // to get to the branch at all. For more information, see
  // https://github.com/pvdlg/env-ci#caveats
  const { commit, branch: ciBranch, root, prBranch } = ci();
  const gitLoc = root ? root : findGitRoot();

  if (!commit) return;

  let committer, remoteUrl, message;
  let branch = ciBranch || prBranch;

  // In order to use git-parse and git-rev-sync, we must ensure that a git context is
  // accessible. Without this check, the commands would throw
  if (gitLoc) {
    const { authorName, authorEmail, ...commit } = await gitToJs(gitLoc)
      .then((commits: Commit[]) =>
        commits && commits.length > 0
          ? commits[0]
          : { authorName: null, authorEmail: null, message: null }
      )
      .catch(() => ({ authorEmail: null, authorName: null, message: null }));

    committer = `${authorName || ""} ${
      authorEmail ? `<${authorEmail}>` : ""
    }`.trim();

    message = commit.message;

    // The remoteUrl call can fail and throw an error
    // https://github.com/kurttheviking/git-rev-sync-js#gitremoteurl--string
    try {

git-parse

Turn a git repository into a javascript object.

BSD-2-Clause
Latest version published 2 years ago

Package Health Score

59 / 100
Full package analysis

Popular git-parse functions