/
gitInfo.js
54 lines (45 loc) · 1.62 KB
/
gitInfo.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
import picomatch from 'picomatch';
import { getCommitAndBranch } from '../git/getCommitAndBranch';
import { getBaselineCommits, getSlug, getVersion } from '../git/git';
import { createTask, transitionTo } from '../lib/tasks';
import {
initial,
pending,
skipFailed,
skippedForCommit,
skippingBuild,
success,
} from '../ui/tasks/gitInfo';
const TesterSkipBuildMutation = `
mutation TesterSkipBuildMutation($commit: String!) {
skipBuild(commit: $commit)
}
`;
export const setGitInfo = async (ctx, task) => {
const { patchBaseRef, fromCI, ignoreLastBuildOnBranch, skip } = ctx.options;
ctx.git = await getCommitAndBranch({ patchBaseRef, inputFromCI: fromCI, log: ctx.log });
ctx.git.slug = ctx.git.slug || (await getSlug());
ctx.git.version = await getVersion();
const { branch, commit } = ctx.git;
const matchesBranch = (glob) => (glob && glob.length ? picomatch(glob)(branch) : !!glob);
ctx.git.matchesBranch = matchesBranch;
if (matchesBranch(skip)) {
transitionTo(skippingBuild)(ctx, task);
if (await ctx.client.runQuery(TesterSkipBuildMutation, { commit })) {
ctx.skip = true;
return transitionTo(skippedForCommit, true)(ctx, task);
}
throw new Error(skipFailed(ctx).output);
}
const baselineCommits = await getBaselineCommits(ctx, {
branch,
ignoreLastBuildOnBranch: matchesBranch(ignoreLastBuildOnBranch),
});
ctx.git.baselineCommits = baselineCommits;
ctx.log.debug(`Found baselineCommits: ${baselineCommits}`);
return transitionTo(success, true)(ctx, task);
};
export default createTask({
title: initial.title,
steps: [transitionTo(pending), setGitInfo],
});