@jphutchins/code-review 0.1.0-alpha.25 → 0.1.0-alpha.26
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/index.js +16 -7
- package/dist/index.js.map +1 -1
- package/package.json +1 -1
package/dist/index.js
CHANGED
|
@@ -1055,18 +1055,27 @@ var runGhApi = (args, stdin, env) => new Promise((resolve3, reject) => {
|
|
|
1055
1055
|
});
|
|
1056
1056
|
|
|
1057
1057
|
// src/pr.ts
|
|
1058
|
+
var CANDIDATE_JQ = ".[] | {number: .number, state: .state, headRef: .head.ref, headSha: .head.sha}";
|
|
1059
|
+
var parseCandidates = (stdout) => parseJsonl(stdout);
|
|
1058
1060
|
var fetchPrCandidates = async (repo, headSha, ghApi) => {
|
|
1059
|
-
const
|
|
1060
|
-
`repos/${repo}/commits/${headSha}/pulls`,
|
|
1061
|
-
|
|
1062
|
-
|
|
1063
|
-
|
|
1064
|
-
|
|
1061
|
+
const direct = parseCandidates(
|
|
1062
|
+
await ghApi([`repos/${repo}/commits/${headSha}/pulls`, "--jq", CANDIDATE_JQ])
|
|
1063
|
+
);
|
|
1064
|
+
if (direct.length > 0) return direct;
|
|
1065
|
+
const open = parseCandidates(
|
|
1066
|
+
await ghApi([
|
|
1067
|
+
`repos/${repo}/pulls?state=open&per_page=100`,
|
|
1068
|
+
"--paginate",
|
|
1069
|
+
"--jq",
|
|
1070
|
+
CANDIDATE_JQ
|
|
1071
|
+
])
|
|
1072
|
+
);
|
|
1073
|
+
return open.filter((c) => c.headSha === headSha);
|
|
1065
1074
|
};
|
|
1066
1075
|
var resolvePr = (candidates, headBranch) => {
|
|
1067
1076
|
if (candidates.length === 0) return { kind: "none" };
|
|
1068
1077
|
const scoped = candidates.length > 1 && headBranch ? candidates.filter((c) => c.headRef === headBranch) : candidates;
|
|
1069
|
-
const chosen = scoped[0] ?? candidates[0];
|
|
1078
|
+
const chosen = scoped.find((c) => c.state === "open") ?? scoped[0] ?? candidates[0];
|
|
1070
1079
|
if (chosen === void 0) return { kind: "none" };
|
|
1071
1080
|
return chosen.state === "open" ? { kind: "open", prNumber: chosen.number } : { kind: "not-open", prNumber: chosen.number, state: chosen.state };
|
|
1072
1081
|
};
|