pi-odd-worktree 3.9.2 → 3.11.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.
Files changed (42) hide show
  1. package/LICENSE +21 -0
  2. package/README.md +68 -40
  3. package/extensions/odd-worktree-tools.ts +1028 -17
  4. package/lib/gh-issues.js +65 -10
  5. package/lib/gh-prs.js +2011 -0
  6. package/lib/issue-preview.js +70 -4
  7. package/lib/issues-cache-store.js +4 -1
  8. package/lib/issues-section.js +346 -23
  9. package/lib/issues-view.js +116 -5
  10. package/lib/pr-preview.js +353 -0
  11. package/lib/prs-rail-store.js +317 -0
  12. package/lib/prs-view.js +2896 -0
  13. package/lib/user-prompt-card.js +477 -0
  14. package/package.json +1 -1
  15. package/tools/files-bridge.test.js +2 -2
  16. package/tools/files-command.test.js +1 -1
  17. package/tools/fixtures/gh-pr-connection-page.json +84 -0
  18. package/tools/fixtures/gh-pr-metadata.json +29 -0
  19. package/tools/fixtures/gh-pr-rail.json +61 -0
  20. package/tools/fixtures/gh-pr-search-page.json +82 -0
  21. package/tools/fixtures/gh-pr-view.json +159 -0
  22. package/tools/gh-issues.test.js +4 -2
  23. package/tools/gh-prs.test.js +1828 -0
  24. package/tools/issue-preview.test.js +119 -0
  25. package/tools/issues-cache-store.test.js +2 -2
  26. package/tools/issues-command.test.js +10 -3
  27. package/tools/issues-open-guard.test.js +15 -0
  28. package/tools/issues-section.test.js +618 -9
  29. package/tools/issues-view.test.js +297 -0
  30. package/tools/package-surface.test.js +21 -5
  31. package/tools/pr-preview.test.js +281 -0
  32. package/tools/prs-command.test.js +1280 -0
  33. package/tools/prs-rail-store.test.js +343 -0
  34. package/tools/prs-t10-safety.test.js +326 -0
  35. package/tools/prs-t12-safety.test.js +348 -0
  36. package/tools/prs-t13-independent.test.js +378 -0
  37. package/tools/prs-t14-safety.test.js +340 -0
  38. package/tools/prs-t15-independent.test.js +259 -0
  39. package/tools/prs-t18-safety.test.js +217 -0
  40. package/tools/prs-t7-safety.test.js +127 -0
  41. package/tools/prs-view.test.js +1462 -0
  42. package/tools/user-prompt-card.test.js +963 -0
package/lib/gh-issues.js CHANGED
@@ -1027,7 +1027,10 @@ async function reportedRepoName(opts = {}) {
1027
1027
  // `scope: null` explicitly; any other `opts` behaves exactly like every
1028
1028
  // other client call (the checkout scope is resolved first, so a resolution
1029
1029
  // failure still prevents this gh call).
1030
- const repo = await runGh(['repo', 'view', '--json', 'nameWithOwner'], opts);
1030
+ // S2/D28: the answer carries the repository's own URL too, so a consumer can
1031
+ // read the HOST gh resolved instead of assuming github.com (the pull request
1032
+ // client pins writes host-qualified from it).
1033
+ const repo = await runGh(['repo', 'view', '--json', 'nameWithOwner,url'], opts);
1031
1034
  if (repo.error) return { ok: false, error: repo.error };
1032
1035
  if (repo.status !== 0) {
1033
1036
  return {
@@ -1042,7 +1045,18 @@ async function reportedRepoName(opts = {}) {
1042
1045
  ? parsedRepo.doc.nameWithOwner
1043
1046
  : '';
1044
1047
  if (!reported) return { ok: false, error: 'gh repo view returned an unexpected shape' };
1045
- return { ok: true, nameWithOwner: reported };
1048
+ return { ok: true, nameWithOwner: reported, host: hostOfRepositoryUrl(parsedRepo.doc.url) };
1049
+ }
1050
+
1051
+ // The host a repository URL names, or '' when the answer carries none.
1052
+ function hostOfRepositoryUrl(raw) {
1053
+ if (typeof raw !== 'string' || raw.trim() === '') return '';
1054
+ try {
1055
+ const host = new URL(raw).host.toLowerCase().replace(/\/+$/, '');
1056
+ return host === 'www.github.com' ? 'github.com' : host;
1057
+ } catch {
1058
+ return '';
1059
+ }
1046
1060
  }
1047
1061
 
1048
1062
  // The repository in scope, in one call. Split out of `repoInfo` so a GraphQL
@@ -1529,7 +1543,7 @@ async function getIssueMetadata(number, opts = {}) {
1529
1543
  viewerPermission
1530
1544
  issue(number: $number) {
1531
1545
  assignees(first: 100) { nodes { login } pageInfo { hasNextPage } }
1532
- closedByPullRequestsReferences(first: 100, includeClosedPrs: true) { nodes { number } pageInfo { hasNextPage } }
1546
+ closedByPullRequestsReferences(first: 100, includeClosedPrs: true) { nodes { number repository { nameWithOwner } } pageInfo { hasNextPage } }
1533
1547
  }
1534
1548
  }
1535
1549
  }`;
@@ -1551,6 +1565,13 @@ async function getIssueMetadata(number, opts = {}) {
1551
1565
  // A page that is not a list of positive integers is a failed relation, and a
1552
1566
  // page the server says continues is marked truncated rather than passed off
1553
1567
  // as the whole list.
1568
+ //
1569
+ // S6/D29: a linked pull request is identified by REPOSITORY and number. Only a
1570
+ // reference this repository owns is a click target (and a rail route); one
1571
+ // that names ANOTHER repository is carried separately, as plain
1572
+ // `owner/repo#N` text, so the pane never opens this repository's lookalike. A
1573
+ // reference that names no repository is kept, because the read is
1574
+ // repository-scoped.
1554
1575
  const references = issue.closedByPullRequestsReferences;
1555
1576
  const referenceNodes = references?.nodes;
1556
1577
  const validReference = Array.isArray(referenceNodes)
@@ -1559,8 +1580,26 @@ async function getIssueMetadata(number, opts = {}) {
1559
1580
  // metadata is missing; `metadataError` stays reserved for a whole-read loss.
1560
1581
  const unavailable = [];
1561
1582
  if (validReference) {
1562
- const numbers = [...new Set(referenceNodes.map((node) => node.number))].sort((a, b) => a - b);
1583
+ const pinned = repo.fullName.toLowerCase();
1584
+ const numbers = [];
1585
+ const foreign = [];
1586
+ for (const node of referenceNodes) {
1587
+ const named = node.repository && typeof node.repository.nameWithOwner === 'string'
1588
+ ? node.repository.nameWithOwner
1589
+ : '';
1590
+ if (named !== '' && named.toLowerCase() !== pinned) {
1591
+ const seen = foreign.some((entry) => entry.number === node.number && entry.repository === named);
1592
+ if (!seen) foreign.push({ repository: named, number: node.number });
1593
+ continue;
1594
+ }
1595
+ if (!numbers.includes(node.number)) numbers.push(node.number);
1596
+ }
1597
+ numbers.sort((a, b) => a - b);
1598
+ foreign.sort((left, right) => (left.repository === right.repository
1599
+ ? left.number - right.number
1600
+ : left.repository.localeCompare(right.repository)));
1563
1601
  if (numbers.length > 0) metadata.linkedPullRequests = numbers;
1602
+ if (foreign.length > 0) metadata.linkedPullRequestsForeign = foreign;
1564
1603
  if (references.pageInfo?.hasNextPage === true) metadata.linkedPullRequestsTruncated = true;
1565
1604
  } else {
1566
1605
  unavailable.push('linked PRs');
@@ -1754,7 +1793,7 @@ function relatedIssuesQuery(owner, name, first) {
1754
1793
  ${PAGE_ISSUE_FIELDS}
1755
1794
  assignees(first: 10) { nodes { login } }
1756
1795
  timelineItems(last: ${PR_REFERENCE_WINDOW}, itemTypes: [${PR_REFERENCE_EVENT}]) {
1757
- nodes { ... on CrossReferencedEvent { source { __typename ... on PullRequest { number } } } }
1796
+ nodes { ... on CrossReferencedEvent { source { __typename ... on PullRequest { number repository { nameWithOwner } } } } }
1758
1797
  }
1759
1798
  }
1760
1799
  }
@@ -1765,11 +1804,26 @@ function relatedIssuesQuery(owner, name, first) {
1765
1804
 
1766
1805
  // The marker is a decoration: a missing or malformed timeline is simply "no
1767
1806
  // pull request", never a failed read that costs the caller its rows.
1768
- function pullRequestReferenced(node) {
1807
+ //
1808
+ // S6/D29: a linked pull request is identified by REPOSITORY and number. A source
1809
+ // that names another repository is not this repository's pull request, so it is
1810
+ // not the marker this rail may route to; a source that names no repository is
1811
+ // kept, because the whole timeline read is repository-scoped.
1812
+ function sameRepositorySource(source, repository) {
1813
+ if (!source || typeof source !== 'object') return false;
1814
+ const named = source.repository && typeof source.repository.nameWithOwner === 'string'
1815
+ ? source.repository.nameWithOwner.toLowerCase()
1816
+ : '';
1817
+ if (named === '' || typeof repository !== 'string' || repository === '') return true;
1818
+ return named === repository.toLowerCase();
1819
+ }
1820
+
1821
+ function pullRequestReferenced(node, repository) {
1769
1822
  const connection = node && typeof node === 'object' ? node.timelineItems : null;
1770
1823
  if (!connection || typeof connection !== 'object' || !Array.isArray(connection.nodes)) return false;
1771
1824
  return connection.nodes.some(
1772
- (item) => item && typeof item === 'object' && item.source && item.source.__typename === 'PullRequest',
1825
+ (item) => item && typeof item === 'object' && item.source && item.source.__typename === 'PullRequest'
1826
+ && sameRepositorySource(item.source, repository),
1773
1827
  );
1774
1828
  }
1775
1829
 
@@ -1781,13 +1835,14 @@ function pullRequestReferenced(node) {
1781
1835
  // answer malformed, are skipped — never read as a number and never a throw — and
1782
1836
  // a source whose number the answer did not carry is no number at all, so a `#0`
1783
1837
  // or a `#NaN` never reaches a row. No pull request at all is `null`.
1784
- function pullRequestNumber(node) {
1838
+ function pullRequestNumber(node, repository) {
1785
1839
  const connection = node && typeof node === 'object' ? node.timelineItems : null;
1786
1840
  if (!connection || typeof connection !== 'object' || !Array.isArray(connection.nodes)) return null;
1787
1841
  for (let index = connection.nodes.length - 1; index >= 0; index -= 1) {
1788
1842
  const item = connection.nodes[index];
1789
1843
  const source = item && typeof item === 'object' ? item.source : null;
1790
1844
  if (!source || typeof source !== 'object' || source.__typename !== 'PullRequest') continue;
1845
+ if (!sameRepositorySource(source, repository)) continue;
1791
1846
  const number = Number(source.number);
1792
1847
  if (Number.isInteger(number) && number > 0) return number;
1793
1848
  }
@@ -1823,8 +1878,8 @@ async function listRelatedIssues(params = {}, opts = {}) {
1823
1878
  }
1824
1879
  issues.push({
1825
1880
  ...normalizeIssue(graphqlIssueRow(node)),
1826
- hasPullRequest: pullRequestReferenced(node),
1827
- pullRequestNumber: pullRequestNumber(node),
1881
+ hasPullRequest: pullRequestReferenced(node, repo.fullName),
1882
+ pullRequestNumber: pullRequestNumber(node, repo.fullName),
1828
1883
  });
1829
1884
  }
1830
1885
  buckets[alias] = { issueCount: connection.issueCount, issues };