azdo-cli 0.2.0-008-pull-request-handling.99 → 0.2.0-008-pull-request-handling.101
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 +38 -23
- package/package.json +1 -1
package/dist/index.js
CHANGED
|
@@ -1613,25 +1613,35 @@ function formatPullRequestBlock(pullRequest) {
|
|
|
1613
1613
|
function formatThreads(prId, title, threads) {
|
|
1614
1614
|
const lines = [`Active comments for pull request #${prId}: ${title}`];
|
|
1615
1615
|
for (const thread of threads) {
|
|
1616
|
-
lines.push("");
|
|
1617
|
-
lines.push(`Thread #${thread.id} [${thread.status}] ${thread.threadContext ?? "(general)"}`);
|
|
1616
|
+
lines.push("", `Thread #${thread.id} [${thread.status}] ${thread.threadContext ?? "(general)"}`);
|
|
1618
1617
|
for (const comment of thread.comments) {
|
|
1619
1618
|
lines.push(` ${comment.author ?? "Unknown"}: ${comment.content}`);
|
|
1620
1619
|
}
|
|
1621
1620
|
}
|
|
1622
1621
|
return lines.join("\n");
|
|
1623
1622
|
}
|
|
1623
|
+
async function resolvePrCommandContext(options) {
|
|
1624
|
+
const context = resolveContext(options);
|
|
1625
|
+
const repo = detectRepoName();
|
|
1626
|
+
const branch = getCurrentBranch();
|
|
1627
|
+
const credential = await resolvePat();
|
|
1628
|
+
return {
|
|
1629
|
+
context,
|
|
1630
|
+
repo,
|
|
1631
|
+
branch,
|
|
1632
|
+
pat: credential.pat
|
|
1633
|
+
};
|
|
1634
|
+
}
|
|
1624
1635
|
function createPrStatusCommand() {
|
|
1625
1636
|
const command = new Command10("status");
|
|
1626
1637
|
command.description("Check pull requests for the current branch").option("--org <org>", "Azure DevOps organization").option("--project <project>", "Azure DevOps project").option("--json", "output JSON").action(async (options) => {
|
|
1627
1638
|
validateOrgProjectPair(options);
|
|
1628
1639
|
let context;
|
|
1629
1640
|
try {
|
|
1630
|
-
|
|
1631
|
-
|
|
1632
|
-
const
|
|
1633
|
-
const
|
|
1634
|
-
const pullRequests = await listPullRequests(context, repo, credential.pat, branch);
|
|
1641
|
+
const resolved = await resolvePrCommandContext(options);
|
|
1642
|
+
context = resolved.context;
|
|
1643
|
+
const pullRequests = await listPullRequests(resolved.context, resolved.repo, resolved.pat, resolved.branch);
|
|
1644
|
+
const { branch, repo } = resolved;
|
|
1635
1645
|
const result = { branch, repository: repo, pullRequests };
|
|
1636
1646
|
if (options.json) {
|
|
1637
1647
|
process.stdout.write(`${JSON.stringify(result, null, 2)}
|
|
@@ -1665,14 +1675,19 @@ function createPrOpenCommand() {
|
|
|
1665
1675
|
}
|
|
1666
1676
|
let context;
|
|
1667
1677
|
try {
|
|
1668
|
-
|
|
1669
|
-
|
|
1670
|
-
|
|
1671
|
-
if (branch === "develop") {
|
|
1678
|
+
const resolved = await resolvePrCommandContext(options);
|
|
1679
|
+
context = resolved.context;
|
|
1680
|
+
if (resolved.branch === "develop") {
|
|
1672
1681
|
writeError("Pull request creation requires a source branch other than develop.");
|
|
1673
1682
|
}
|
|
1674
|
-
const
|
|
1675
|
-
|
|
1683
|
+
const result = await openPullRequest(
|
|
1684
|
+
resolved.context,
|
|
1685
|
+
resolved.repo,
|
|
1686
|
+
resolved.pat,
|
|
1687
|
+
resolved.branch,
|
|
1688
|
+
title,
|
|
1689
|
+
description
|
|
1690
|
+
);
|
|
1676
1691
|
if (options.json) {
|
|
1677
1692
|
process.stdout.write(`${JSON.stringify(result, null, 2)}
|
|
1678
1693
|
`);
|
|
@@ -1685,7 +1700,7 @@ ${result.pullRequest.url}
|
|
|
1685
1700
|
return;
|
|
1686
1701
|
}
|
|
1687
1702
|
process.stdout.write(
|
|
1688
|
-
`Active pull request already exists for ${branch} -> develop: #${result.pullRequest.id}
|
|
1703
|
+
`Active pull request already exists for ${resolved.branch} -> develop: #${result.pullRequest.id}
|
|
1689
1704
|
${result.pullRequest.url}
|
|
1690
1705
|
`
|
|
1691
1706
|
);
|
|
@@ -1705,21 +1720,21 @@ function createPrCommentsCommand() {
|
|
|
1705
1720
|
validateOrgProjectPair(options);
|
|
1706
1721
|
let context;
|
|
1707
1722
|
try {
|
|
1708
|
-
|
|
1709
|
-
|
|
1710
|
-
const
|
|
1711
|
-
|
|
1712
|
-
|
|
1723
|
+
const resolved = await resolvePrCommandContext(options);
|
|
1724
|
+
context = resolved.context;
|
|
1725
|
+
const pullRequests = await listPullRequests(resolved.context, resolved.repo, resolved.pat, resolved.branch, {
|
|
1726
|
+
status: "active"
|
|
1727
|
+
});
|
|
1713
1728
|
if (pullRequests.length === 0) {
|
|
1714
|
-
writeError(`No active pull request found for branch ${branch}.`);
|
|
1729
|
+
writeError(`No active pull request found for branch ${resolved.branch}.`);
|
|
1715
1730
|
}
|
|
1716
1731
|
if (pullRequests.length > 1) {
|
|
1717
1732
|
const ids = pullRequests.map((pullRequest2) => `#${pullRequest2.id}`).join(", ");
|
|
1718
|
-
writeError(`Multiple active pull requests found for branch ${branch}: ${ids}. Use pr status to review them.`);
|
|
1733
|
+
writeError(`Multiple active pull requests found for branch ${resolved.branch}: ${ids}. Use pr status to review them.`);
|
|
1719
1734
|
}
|
|
1720
1735
|
const pullRequest = pullRequests[0];
|
|
1721
|
-
const threads = await getPullRequestThreads(context, repo,
|
|
1722
|
-
const result = { branch, pullRequest, threads };
|
|
1736
|
+
const threads = await getPullRequestThreads(resolved.context, resolved.repo, resolved.pat, pullRequest.id);
|
|
1737
|
+
const result = { branch: resolved.branch, pullRequest, threads };
|
|
1723
1738
|
if (options.json) {
|
|
1724
1739
|
process.stdout.write(`${JSON.stringify(result, null, 2)}
|
|
1725
1740
|
`);
|