@staff0rd/assist 0.814.0 → 0.815.0

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.814.0",
9
+ version: "0.815.0",
10
10
  type: "module",
11
11
  main: "dist/index.js",
12
12
  bin: {
@@ -15827,7 +15827,61 @@ async function prStatus(req, res) {
15827
15827
  respondJson(res, 200, { pr });
15828
15828
  }
15829
15829
 
15830
+ // src/commands/sessions/web/releases/mainlineCommits.ts
15831
+ function mainlineCommits(commits2) {
15832
+ const bySha = new Map(commits2.map((commit3) => [commit3.sha, commit3]));
15833
+ const mainline = [];
15834
+ let commit2 = commits2.at(-1);
15835
+ while (commit2) {
15836
+ mainline.push(commit2);
15837
+ const parent = commit2.parents?.[0];
15838
+ commit2 = parent ? bySha.get(parent) : void 0;
15839
+ }
15840
+ return mainline;
15841
+ }
15842
+
15843
+ // src/commands/sessions/web/releases/pullRequestsQuery.ts
15844
+ function pullRequestsQuery(shas) {
15845
+ const lookups = shas.map(
15846
+ (sha, index2) => `c${index2}: object(oid:${JSON.stringify(sha)}){ ... on Commit { associatedPullRequests(first:5){ nodes{ number title url author{ login } mergeCommit{ oid } } } } }`
15847
+ );
15848
+ return `query($owner:String!,$name:String!){
15849
+ repository(owner:$owner,name:$name){ ${lookups.join(" ")} }
15850
+ }`;
15851
+ }
15852
+
15853
+ // src/commands/sessions/web/releases/mergedPullRequests.ts
15854
+ async function mergedPullRequests(cwd, repo, shas) {
15855
+ const merged = /* @__PURE__ */ new Map();
15856
+ const [owner, name] = repo.split("/");
15857
+ if (shas.length === 0 || !owner || !name) return merged;
15858
+ const response = await ghJson(cwd, [
15859
+ "api",
15860
+ "graphql",
15861
+ "-f",
15862
+ `query=${pullRequestsQuery(shas)}`,
15863
+ "-f",
15864
+ `owner=${owner}`,
15865
+ "-f",
15866
+ `name=${name}`
15867
+ ]);
15868
+ const repository = response.data?.repository;
15869
+ for (const [index2, sha] of shas.entries()) {
15870
+ const nodes = repository?.[`c${index2}`]?.associatedPullRequests?.nodes;
15871
+ const pr = nodes?.find((node) => node.mergeCommit?.oid === sha);
15872
+ if (pr)
15873
+ merged.set(sha, {
15874
+ number: pr.number,
15875
+ title: pr.title,
15876
+ url: pr.url,
15877
+ author: pr.author?.login ?? null
15878
+ });
15879
+ }
15880
+ return merged;
15881
+ }
15882
+
15830
15883
  // src/commands/sessions/web/releases/toReleaseCompareCommit.ts
15884
+ var API_COMMIT_JQ = "{sha, commit, parents: [.parents[].sha]}";
15831
15885
  function toReleaseCompareCommit({
15832
15886
  sha,
15833
15887
  commit: commit2
@@ -15841,47 +15895,64 @@ function toReleaseCompareCommit({
15841
15895
  }
15842
15896
 
15843
15897
  // src/commands/sessions/web/releases/newestCommits.ts
15844
- var PAGE_SIZE = 50;
15898
+ var PAGE_SIZE = 100;
15899
+ var MAX_PAGES2 = 3;
15845
15900
  function comparePage(cwd, repo, range, page) {
15846
15901
  return ghJson(cwd, [
15847
15902
  "api",
15848
15903
  `repos/${repo}/compare/${range}?per_page=${PAGE_SIZE}&page=${page}`,
15849
15904
  "--jq",
15850
- "{total_commits, commits: [.commits[] | {sha, commit}]}"
15905
+ `{total_commits, commits: [.commits[] | ${API_COMMIT_JQ}]}`
15851
15906
  ]);
15852
15907
  }
15853
15908
  async function newestCommits(cwd, repo, range) {
15854
15909
  const first = await comparePage(cwd, repo, range, 1);
15855
- const total = first.total_commits;
15856
- if (total <= PAGE_SIZE)
15857
- return { total, commits: first.commits.map(toReleaseCompareCommit) };
15858
- const last = Math.ceil(total / PAGE_SIZE);
15910
+ const last = Math.ceil(first.total_commits / PAGE_SIZE);
15911
+ if (last <= 1) return first.commits;
15912
+ const pages = Array.from(
15913
+ { length: Math.min(MAX_PAGES2, last) },
15914
+ (_, i) => last - i
15915
+ ).reverse();
15859
15916
  const tail = await Promise.all(
15860
- [last - 1, last].map(
15917
+ pages.map(
15861
15918
  (page) => page === 1 ? first : comparePage(cwd, repo, range, page)
15862
15919
  )
15863
15920
  );
15864
- const commits2 = tail.flatMap((page) => page.commits).slice(-PAGE_SIZE);
15865
- return { total, commits: commits2.map(toReleaseCompareCommit) };
15921
+ return tail.flatMap((page) => page.commits);
15866
15922
  }
15867
15923
 
15868
15924
  // src/commands/sessions/web/releases/compareCommits.ts
15925
+ var MAX_CHANGES = 50;
15926
+ async function rangeCommits(cwd, repo, base, head) {
15927
+ if (base) return newestCommits(cwd, repo, `${base}...${head}`);
15928
+ const commit2 = await ghJson(cwd, [
15929
+ "api",
15930
+ `repos/${repo}/commits/${head}`,
15931
+ "--jq",
15932
+ API_COMMIT_JQ
15933
+ ]);
15934
+ return [commit2];
15935
+ }
15869
15936
  async function compareCommits(cwd, repo, base, head) {
15870
- if (!base) {
15871
- const commit2 = await ghJson(cwd, [
15872
- "api",
15873
- `repos/${repo}/commits/${head}`,
15874
- "--jq",
15875
- "{sha, commit}"
15876
- ]);
15877
- return { total: 1, commits: [toReleaseCompareCommit(commit2)] };
15878
- }
15879
- const { total, commits: commits2 } = await newestCommits(
15937
+ const mainline = mainlineCommits(await rangeCommits(cwd, repo, base, head));
15938
+ const shown = mainline.slice(0, MAX_CHANGES);
15939
+ const prs2 = await mergedPullRequests(
15880
15940
  cwd,
15881
15941
  repo,
15882
- `${base}...${head}`
15942
+ shown.map((commit2) => commit2.sha)
15883
15943
  );
15884
- return { total, commits: commits2.reverse() };
15944
+ const changes = shown.map((commit2) => {
15945
+ const change = toReleaseCompareCommit(commit2);
15946
+ const pr = prs2.get(commit2.sha);
15947
+ if (!pr) return { ...change, pr: null };
15948
+ return {
15949
+ ...change,
15950
+ subject: pr.title,
15951
+ author: pr.author ?? change.author,
15952
+ pr: { number: pr.number, url: pr.url }
15953
+ };
15954
+ });
15955
+ return { total: mainline.length, changes };
15885
15956
  }
15886
15957
 
15887
15958
  // src/commands/sessions/web/releases/releasesCompare.ts
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@staff0rd/assist",
3
- "version": "0.814.0",
3
+ "version": "0.815.0",
4
4
  "type": "module",
5
5
  "main": "dist/index.js",
6
6
  "bin": {