azdo-cli 0.5.0 → 0.6.0-develop.160

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/README.md CHANGED
@@ -174,8 +174,11 @@ azdo pr comments
174
174
  `azdo pr status`
175
175
 
176
176
  - Lists pull requests for the current branch
177
+ - Includes Azure DevOps pull request checks under each returned pull request
178
+ - Prints `Checks: none reported by Azure DevOps` when a pull request has no returned checks
179
+ - Shows `Detail: ...` lines for failed or errored checks when Azure DevOps provides description text
177
180
  - Prints `No pull requests found for branch <branch>.` when no PRs exist
178
- - Supports `--json` for machine-readable output
181
+ - Supports `--json` for machine-readable output, including a `checks` array per pull request
179
182
 
180
183
  `azdo pr open`
181
184
 
package/dist/index.js CHANGED
@@ -1672,6 +1672,13 @@ function buildPullRequestsUrl(context, repo, sourceBranch, opts) {
1672
1672
  }
1673
1673
  return url;
1674
1674
  }
1675
+ function buildPullRequestStatusesUrl(context, repo, prId) {
1676
+ const url = new URL(
1677
+ `https://dev.azure.com/${encodeURIComponent(context.org)}/${encodeURIComponent(context.project)}/_apis/git/repositories/${encodeURIComponent(repo)}/pullRequests/${prId}/statuses`
1678
+ );
1679
+ url.searchParams.set("api-version", "7.1");
1680
+ return url;
1681
+ }
1675
1682
  function mapPullRequest(repo, pullRequest) {
1676
1683
  return {
1677
1684
  id: pullRequest.pullRequestId,
@@ -1684,6 +1691,35 @@ function mapPullRequest(repo, pullRequest) {
1684
1691
  url: pullRequest._links.web.href
1685
1692
  };
1686
1693
  }
1694
+ function mapPullRequestCheckName(status) {
1695
+ const genre = status.context?.genre?.trim();
1696
+ const name = status.context?.name?.trim();
1697
+ if (genre && name) {
1698
+ return `${genre}/${name}`;
1699
+ }
1700
+ if (name) {
1701
+ return name;
1702
+ }
1703
+ if (genre) {
1704
+ return genre;
1705
+ }
1706
+ return `Status #${status.id}`;
1707
+ }
1708
+ function mapPullRequestCheck(status) {
1709
+ if (status.state === "notApplicable" || status.state === "notSet") {
1710
+ return null;
1711
+ }
1712
+ return {
1713
+ id: status.id,
1714
+ state: status.state,
1715
+ name: mapPullRequestCheckName(status),
1716
+ description: status.description ?? null,
1717
+ targetUrl: status.targetUrl ?? null,
1718
+ createdBy: status.createdBy?.displayName ?? null,
1719
+ createdAt: status.creationDate ?? null,
1720
+ updatedAt: status.updatedDate ?? null
1721
+ };
1722
+ }
1687
1723
  function mapComment(comment) {
1688
1724
  const content = comment.content?.trim();
1689
1725
  if (comment.isDeleted || !content) {
@@ -1725,6 +1761,14 @@ async function listPullRequests(context, repo, pat, sourceBranch, opts) {
1725
1761
  const data = await readJsonResponse(response);
1726
1762
  return data.value.map((pullRequest) => mapPullRequest(repo, pullRequest));
1727
1763
  }
1764
+ async function getPullRequestChecks(context, repo, pat, prId) {
1765
+ const response = await fetchWithErrors(
1766
+ buildPullRequestStatusesUrl(context, repo, prId).toString(),
1767
+ { headers: authHeaders(pat) }
1768
+ );
1769
+ const data = await readJsonResponse(response);
1770
+ return data.value.map(mapPullRequestCheck).filter((check) => check !== null);
1771
+ }
1728
1772
  async function openPullRequest(context, repo, pat, sourceBranch, title, description) {
1729
1773
  const existing = await listPullRequests(context, repo, pat, sourceBranch, {
1730
1774
  status: "active",
@@ -1806,11 +1850,25 @@ function handlePrCommandError(err, context, mode = "read") {
1806
1850
  }
1807
1851
  writeError(error.message);
1808
1852
  }
1853
+ function formatPullRequestChecks(checks) {
1854
+ if (checks.length === 0) {
1855
+ return ["Checks: none reported by Azure DevOps"];
1856
+ }
1857
+ const lines = ["Checks:"];
1858
+ for (const check of checks) {
1859
+ lines.push(`- [${check.state}] ${check.name}`);
1860
+ if ((check.state === "failed" || check.state === "error") && check.description) {
1861
+ lines.push(` Detail: ${check.description}`);
1862
+ }
1863
+ }
1864
+ return lines;
1865
+ }
1809
1866
  function formatPullRequestBlock(pullRequest) {
1810
1867
  return [
1811
1868
  `#${pullRequest.id} [${pullRequest.status}] ${pullRequest.title}`,
1812
1869
  `${formatBranchName(pullRequest.sourceRefName)} -> ${formatBranchName(pullRequest.targetRefName)}`,
1813
- pullRequest.url
1870
+ pullRequest.url,
1871
+ ...formatPullRequestChecks(pullRequest.checks)
1814
1872
  ].join("\n");
1815
1873
  }
1816
1874
  function formatThreads(prId, title, threads) {
@@ -1844,19 +1902,25 @@ function createPrStatusCommand() {
1844
1902
  const resolved = await resolvePrCommandContext(options);
1845
1903
  context = resolved.context;
1846
1904
  const pullRequests = await listPullRequests(resolved.context, resolved.repo, resolved.pat, resolved.branch);
1905
+ const pullRequestsWithChecks = await Promise.all(
1906
+ pullRequests.map(async (pullRequest) => ({
1907
+ ...pullRequest,
1908
+ checks: await getPullRequestChecks(resolved.context, resolved.repo, resolved.pat, pullRequest.id)
1909
+ }))
1910
+ );
1847
1911
  const { branch, repo } = resolved;
1848
- const result = { branch, repository: repo, pullRequests };
1912
+ const result = { branch, repository: repo, pullRequests: pullRequestsWithChecks };
1849
1913
  if (options.json) {
1850
1914
  process.stdout.write(`${JSON.stringify(result, null, 2)}
1851
1915
  `);
1852
1916
  return;
1853
1917
  }
1854
- if (pullRequests.length === 0) {
1918
+ if (pullRequestsWithChecks.length === 0) {
1855
1919
  process.stdout.write(`No pull requests found for branch ${branch}.
1856
1920
  `);
1857
1921
  return;
1858
1922
  }
1859
- process.stdout.write(`${pullRequests.map(formatPullRequestBlock).join("\n\n")}
1923
+ process.stdout.write(`${pullRequestsWithChecks.map(formatPullRequestBlock).join("\n\n")}
1860
1924
  `);
1861
1925
  } catch (err) {
1862
1926
  handlePrCommandError(err, context, "read");
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "azdo-cli",
3
- "version": "0.5.0",
3
+ "version": "0.6.0-develop.160",
4
4
  "description": "Azure DevOps CLI tool",
5
5
  "type": "module",
6
6
  "bin": {