@zixt/host 0.0.57 → 0.0.58

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.
Files changed (2) hide show
  1. package/dist/index.js +43 -8
  2. package/package.json +1 -1
package/dist/index.js CHANGED
@@ -31,7 +31,7 @@ import { homedir } from "node:os";
31
31
  // package.json
32
32
  var package_default = {
33
33
  name: "@zixt/host",
34
- version: "0.0.57",
34
+ version: "0.0.58",
35
35
  type: "module",
36
36
  exports: {
37
37
  ".": "./src/client.ts",
@@ -34693,9 +34693,8 @@ async function pullRequestBaseRepositories(gitCommand, cwd, checkoutRepository,
34693
34693
  add(checkoutRepository);
34694
34694
  return repositories;
34695
34695
  }
34696
- function parsePullRequest(output, expectedBaseRepository, expectedHeadRepository, expectedHeadBranch) {
34696
+ function parsePullRequest(value, expectedBaseRepository, expectedHeadRepository, expectedHeadBranch) {
34697
34697
  try {
34698
- const value = JSON.parse(output);
34699
34698
  const state = typeof value["state"] === "string" ? value["state"].toLowerCase() : "";
34700
34699
  const number4 = Number(value["number"]);
34701
34700
  const location = canonicalPullRequestLocation(value["url"], number4);
@@ -34718,10 +34717,41 @@ function parsePullRequest(output, expectedBaseRepository, expectedHeadRepository
34718
34717
  return void 0;
34719
34718
  }
34720
34719
  }
34720
+ var PULL_REQUEST_LIST_LIMIT = 20;
34721
+ var PULL_REQUEST_STATE_RANK = {
34722
+ // A still-open pull request is the branch's current truth even when an
34723
+ // earlier one from the same branch already merged; a closed one is the
34724
+ // weakest evidence because it says only that somebody gave up on it.
34725
+ open: 3,
34726
+ merged: 2,
34727
+ closed: 1
34728
+ };
34729
+ function selectPullRequest(output, expectedBaseRepository, expectedHeadRepository, expectedHeadBranch) {
34730
+ let value;
34731
+ try {
34732
+ value = JSON.parse(output);
34733
+ } catch {
34734
+ return void 0;
34735
+ }
34736
+ if (!Array.isArray(value)) return void 0;
34737
+ let best;
34738
+ for (const entry of value.slice(0, PULL_REQUEST_LIST_LIMIT)) {
34739
+ if (!entry || typeof entry !== "object" || Array.isArray(entry)) continue;
34740
+ const parsed = parsePullRequest(
34741
+ entry,
34742
+ expectedBaseRepository,
34743
+ expectedHeadRepository,
34744
+ expectedHeadBranch
34745
+ );
34746
+ if (!parsed) continue;
34747
+ if (!best || PULL_REQUEST_STATE_RANK[parsed.state] > PULL_REQUEST_STATE_RANK[best.state] || PULL_REQUEST_STATE_RANK[parsed.state] === PULL_REQUEST_STATE_RANK[best.state] && parsed.number > best.number) {
34748
+ best = parsed;
34749
+ }
34750
+ }
34751
+ return best;
34752
+ }
34721
34753
  async function pullRequest(command, gitCommand, repositoryCwd, commandCwd, repository, branch, signal) {
34722
34754
  if (!command || !repository || !branch) return void 0;
34723
- const headOwner = repository.split("/")[0];
34724
- const selector = `${headOwner}:${branch}`;
34725
34755
  const baseRepositories = await pullRequestBaseRepositories(
34726
34756
  gitCommand,
34727
34757
  repositoryCwd,
@@ -34734,10 +34764,15 @@ async function pullRequest(command, gitCommand, repositoryCwd, commandCwd, repos
34734
34764
  [
34735
34765
  ...command.prefixArgs ?? [],
34736
34766
  "pr",
34737
- "view",
34738
- selector,
34767
+ "list",
34739
34768
  "--repo",
34740
34769
  baseRepository,
34770
+ "--head",
34771
+ branch,
34772
+ "--state",
34773
+ "all",
34774
+ "--limit",
34775
+ String(PULL_REQUEST_LIST_LIMIT),
34741
34776
  "--json",
34742
34777
  "number,title,url,state,isDraft,baseRefName,headRefName,headRepository,headRepositoryOwner"
34743
34778
  ],
@@ -34746,7 +34781,7 @@ async function pullRequest(command, gitCommand, repositoryCwd, commandCwd, repos
34746
34781
  signal
34747
34782
  );
34748
34783
  if (!output) continue;
34749
- const parsed = parsePullRequest(output, baseRepository, repository, branch);
34784
+ const parsed = selectPullRequest(output, baseRepository, repository, branch);
34750
34785
  if (parsed) return parsed;
34751
34786
  }
34752
34787
  return void 0;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@zixt/host",
3
- "version": "0.0.57",
3
+ "version": "0.0.58",
4
4
  "type": "module",
5
5
  "exports": {
6
6
  ".": "./src/client.ts",