Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix #4369: Include pull requests in git ref search #4411

Merged
merged 2 commits into from
Sep 12, 2017
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions __tests__/util/git/git-ref-resolver.js
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ test('resolveVersion', async () => {
refs.set('refs/tags/v1.1.0', '37d5ed001dc4402d5446911c4e1cb589449e7d8d');
refs.set('refs/tags/v2.2.0', 'e88209b9513544a22fc3f8660e3d829281dc2c9f');
refs.set('refs/tags/both', 'f0dbab0a4345a64f544af37e24fc8187176936a4');
refs.set('refs/pull/100/head', '6e97e0159f10c275f227d0f067d99f2a97331cef');
const emptyRefs: GitRefs = new Map();
const git = new GitMock();

Expand Down Expand Up @@ -69,6 +70,10 @@ test('resolveVersion', async () => {
sha: '37d5ed001dc4402d5446911c4e1cb589449e7d8d',
ref: 'refs/tags/v1.1.0',
});
expect(await resolve('100/head')).toEqual({
sha: '6e97e0159f10c275f227d0f067d99f2a97331cef',
ref: 'refs/pull/100/head',
});
// not-existing sha
expect(await resolve('0123456')).toEqual(null);

Expand Down
7 changes: 6 additions & 1 deletion src/util/git/git-ref-resolver.js
Original file line number Diff line number Diff line change
Expand Up @@ -21,11 +21,12 @@ type Names = {tags: Array<string>, heads: Array<string>};

const REF_TAG_PREFIX = 'refs/tags/';
const REF_BRANCH_PREFIX = 'refs/heads/';
const REF_PR_PREFIX = 'refs/pull/';

// This regex is designed to match output from git of the style:
// ebeb6eafceb61dd08441ffe086c77eb472842494 refs/tags/v0.21.0
// and extract the hash and ref name as capture groups
const GIT_REF_LINE_REGEXP = /^([a-fA-F0-9]+)\s+(refs\/(?:tags|heads)\/.*)$/;
const GIT_REF_LINE_REGEXP = /^([a-fA-F0-9]+)\s+(refs\/(?:tags|heads|pull)\/.*)$/;

const COMMIT_SHA_REGEXP = /^[a-f0-9]{5,40}$/;
const REF_NAME_REGEXP = /^refs\/(tags|heads)\/(.+)$/;
Expand Down Expand Up @@ -62,6 +63,9 @@ const tryVersionAsFullRef = ({version, refs}: ResolveVersionOptions): ?ResolvedS
const tryVersionAsTagName = ({version, refs}: ResolveVersionOptions): ?ResolvedSha =>
tryRef(refs, `${REF_TAG_PREFIX}${version}`);

const tryVersionAsPullRequestNo = ({version, refs}: ResolveVersionOptions): ?ResolvedSha =>
tryRef(refs, `${REF_PR_PREFIX}${version}`);

const tryVersionAsBranchName = ({version, refs}: ResolveVersionOptions): ?ResolvedSha =>
tryRef(refs, `${REF_BRANCH_PREFIX}${version}`);

Expand Down Expand Up @@ -112,6 +116,7 @@ const VERSION_RESOLUTION_STEPS: Array<(ResolveVersionOptions) => ?ResolvedSha |
tryVersionAsGitCommit,
tryVersionAsFullRef,
tryVersionAsTagName,
tryVersionAsPullRequestNo,
tryVersionAsBranchName,
tryVersionAsSemverRange,
tryWildcardVersionAsDefaultBranch,
Expand Down