Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
// 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 {