@staff0rd/assist 0.355.0 → 0.356.1

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 CHANGED
@@ -6,7 +6,7 @@ import { Command } from "commander";
6
6
  // package.json
7
7
  var package_default = {
8
8
  name: "@staff0rd/assist",
9
- version: "0.355.0",
9
+ version: "0.356.1",
10
10
  type: "module",
11
11
  main: "dist/index.js",
12
12
  bin: {
@@ -6792,21 +6792,47 @@ async function prList(req, res) {
6792
6792
  }
6793
6793
 
6794
6794
  // src/commands/sessions/web/prStatus.ts
6795
- var getPr = createCachedGhJson(
6796
- ["pr", "view", "--json", "number,title,author,createdAt,url"],
6795
+ import { execFile as execFile4 } from "child_process";
6796
+ import { promisify as promisify5 } from "util";
6797
+ var execFileAsync4 = promisify5(execFile4);
6798
+ function toPrSummary(parsed) {
6799
+ if (typeof parsed.number !== "number") return null;
6800
+ return {
6801
+ number: parsed.number,
6802
+ title: parsed.title ?? "",
6803
+ author: parsed.author?.name || parsed.author?.login || "unknown",
6804
+ createdAt: parsed.createdAt ?? "",
6805
+ url: parsed.url ?? ""
6806
+ };
6807
+ }
6808
+ var prFields = "number,title,author,createdAt,url";
6809
+ var getPrByNumber = createCachedGhJson(
6810
+ ["pr", "view", "--json", prFields],
6811
+ (stdout) => toPrSummary(JSON.parse(stdout)),
6812
+ null
6813
+ );
6814
+ var getOpenPrForBranch = createCachedGhJson(
6815
+ ["pr", "list", "--state", "open", "--json", prFields],
6797
6816
  (stdout) => {
6798
6817
  const parsed = JSON.parse(stdout);
6799
- if (typeof parsed.number !== "number") return null;
6800
- return {
6801
- number: parsed.number,
6802
- title: parsed.title ?? "",
6803
- author: parsed.author?.name || parsed.author?.login || "unknown",
6804
- createdAt: parsed.createdAt ?? "",
6805
- url: parsed.url ?? ""
6806
- };
6818
+ if (!Array.isArray(parsed) || parsed.length === 0) return null;
6819
+ return toPrSummary(parsed[0]);
6807
6820
  },
6808
6821
  null
6809
6822
  );
6823
+ async function getCurrentBranch(cwd) {
6824
+ try {
6825
+ const { stdout } = await execFileAsync4(
6826
+ "git",
6827
+ ["rev-parse", "--abbrev-ref", "HEAD"],
6828
+ { encoding: "utf8", cwd: windowsCwdToWslPath(cwd) }
6829
+ );
6830
+ const branch2 = stdout.trim();
6831
+ return branch2 && branch2 !== "HEAD" ? branch2 : void 0;
6832
+ } catch {
6833
+ return void 0;
6834
+ }
6835
+ }
6810
6836
  function getNumberParam(req) {
6811
6837
  const raw = new URL(req.url ?? "/", "http://localhost").searchParams.get(
6812
6838
  "number"
@@ -6819,8 +6845,13 @@ async function prStatus(req, res) {
6819
6845
  const cwd = getCwdParam(req, res);
6820
6846
  if (!cwd) return;
6821
6847
  const number = getNumberParam(req);
6822
- const extraArgs = number !== void 0 ? [String(number)] : void 0;
6823
- respondJson(res, 200, { pr: await getPr(cwd, extraArgs) });
6848
+ if (number !== void 0) {
6849
+ respondJson(res, 200, { pr: await getPrByNumber(cwd, [String(number)]) });
6850
+ return;
6851
+ }
6852
+ const branch2 = await getCurrentBranch(cwd);
6853
+ const pr = branch2 ? await getOpenPrForBranch(cwd, ["--head", branch2]) : null;
6854
+ respondJson(res, 200, { pr });
6824
6855
  }
6825
6856
 
6826
6857
  // src/commands/sessions/daemon/stopDaemon.ts
@@ -14160,14 +14191,14 @@ function getRepoInfo() {
14160
14191
  );
14161
14192
  return { org: repoInfo.owner.login, repo: repoInfo.name };
14162
14193
  }
14163
- function getCurrentBranch() {
14194
+ function getCurrentBranch2() {
14164
14195
  return execSync33("git rev-parse --abbrev-ref HEAD", {
14165
14196
  encoding: "utf8"
14166
14197
  }).trim();
14167
14198
  }
14168
14199
  function viewCurrentPr(fields) {
14169
14200
  const { org, repo } = getRepoInfo();
14170
- const branch2 = getCurrentBranch();
14201
+ const branch2 = getCurrentBranch2();
14171
14202
  return JSON.parse(
14172
14203
  execSync33(`gh pr view ${branch2} --json ${fields} -R ${org}/${repo}`, {
14173
14204
  encoding: "utf8"
@@ -17336,37 +17367,36 @@ function fetchDiffViaGit(baseSha, headSha) {
17336
17367
 
17337
17368
  // src/commands/review/fetchPrDiffInfo.ts
17338
17369
  import { execSync as execSync48 } from "child_process";
17339
- function getCurrentBranch2() {
17370
+ function getCurrentBranch3() {
17340
17371
  return execSync48("git rev-parse --abbrev-ref HEAD", {
17341
17372
  encoding: "utf8"
17342
17373
  }).trim();
17343
17374
  }
17344
17375
  function fetchPrDiffInfo() {
17345
17376
  const { org, repo } = getRepoInfo();
17346
- const branch2 = getCurrentBranch2();
17377
+ const branch2 = getCurrentBranch3();
17347
17378
  const fields = "number,baseRefName,baseRefOid,headRefName,headRefOid";
17348
- let raw;
17349
- try {
17350
- raw = execSync48(`gh pr view ${branch2} --json ${fields} -R ${org}/${repo}`, {
17379
+ const raw = execSync48(
17380
+ `gh pr list --state open --head ${branch2} --json ${fields} -R ${org}/${repo}`,
17381
+ {
17351
17382
  encoding: "utf8",
17352
17383
  stdio: ["ignore", "pipe", "pipe"]
17353
- });
17354
- } catch (error) {
17355
- if (error instanceof Error && error.message.includes("no pull requests")) {
17356
- console.error(
17357
- `Error: No open pull request found for branch \`${branch2}\`. Open a PR for this branch before running \`assist review\`.`
17358
- );
17359
- process.exit(1);
17360
17384
  }
17361
- throw error;
17362
- }
17385
+ );
17363
17386
  const parsed = JSON.parse(raw);
17387
+ const pr = parsed[0];
17388
+ if (!pr) {
17389
+ console.error(
17390
+ `Error: No open pull request found for branch \`${branch2}\`. Open a PR for this branch before running \`assist review\`.`
17391
+ );
17392
+ process.exit(1);
17393
+ }
17364
17394
  return {
17365
- prNumber: parsed.number,
17366
- baseRef: parsed.baseRefName,
17367
- baseSha: parsed.baseRefOid,
17368
- headRef: parsed.headRefName,
17369
- headSha: parsed.headRefOid
17395
+ prNumber: pr.number,
17396
+ baseRef: pr.baseRefName,
17397
+ baseSha: pr.baseRefOid,
17398
+ headRef: pr.headRefName,
17399
+ headSha: pr.headRefOid
17370
17400
  };
17371
17401
  }
17372
17402
  function fetchPrChangedFiles(prNumber) {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@staff0rd/assist",
3
- "version": "0.355.0",
3
+ "version": "0.356.1",
4
4
  "type": "module",
5
5
  "main": "dist/index.js",
6
6
  "bin": {