1 | "use strict";
|
2 | Object.defineProperty(exports, "__esModule", { value: true });
|
3 | const tslib_1 = require("tslib");
|
4 | const endent_1 = tslib_1.__importDefault(require("endent"));
|
5 |
|
6 |
|
7 |
|
8 |
|
9 | function buildSearchQuery(owner, project, commits) {
|
10 | const repo = `${owner}/${project}`;
|
11 | const query = commits.reduce((q, commit) => {
|
12 | const subQuery = `repo:${repo} ${commit}`;
|
13 | return endent_1.default `
|
14 | ${q}
|
15 |
|
16 | hash_${commit}: search(query: "${subQuery}", type: ISSUE, first: 10) {
|
17 | edges {
|
18 | node {
|
19 | ... on PullRequest {
|
20 | number
|
21 | state
|
22 | body
|
23 | headRefName
|
24 | headRepositoryOwner {
|
25 | login
|
26 | }
|
27 | labels(first: 10) {
|
28 | edges {
|
29 | node {
|
30 | name
|
31 | }
|
32 | }
|
33 | }
|
34 | }
|
35 | }
|
36 | }
|
37 | }
|
38 | `;
|
39 | }, "");
|
40 | if (!query) {
|
41 | return;
|
42 | }
|
43 | return `{
|
44 | ${query}
|
45 | rateLimit {
|
46 | limit
|
47 | cost
|
48 | remaining
|
49 | resetAt
|
50 | }
|
51 | }`;
|
52 | }
|
53 | exports.buildSearchQuery = buildSearchQuery;
|
54 |
|
55 | function processQueryResult({ owner, sha, result, commitsWithoutPR, prereleaseBranches, }) {
|
56 | const hash = sha.split("hash_")[1];
|
57 | const commit = commitsWithoutPR.find((commitWithoutPR) => commitWithoutPR.hash === hash);
|
58 | if (!commit) {
|
59 | return;
|
60 | }
|
61 |
|
62 |
|
63 | const prs = result.edges.filter((edge) => edge.node.state === "MERGED");
|
64 | const isInPrerelease = result.edges.filter((edge) => prereleaseBranches.includes(edge.node.headRefName) &&
|
65 | edge.node.headRepositoryOwner.login === owner);
|
66 | if (prs.length) {
|
67 | const pr = prs[0].node;
|
68 | const labels = pr.labels
|
69 | ? pr.labels.edges.map((edge) => edge.node)
|
70 | : [];
|
71 | commit.pullRequest = {
|
72 | number: pr.number,
|
73 | body: pr.body,
|
74 | };
|
75 | commit.labels = [...labels.map((label) => label.name), ...commit.labels];
|
76 | }
|
77 | else if (!result.edges.length || isInPrerelease.length) {
|
78 | commit.labels = ["pushToBaseBranch", ...commit.labels];
|
79 | }
|
80 | commit.subject = commit.subject.split("\n")[0];
|
81 | return commit;
|
82 | }
|
83 | exports.processQueryResult = processQueryResult;
|
84 |
|
\ | No newline at end of file |