Skip to content

Commit 3b8e1f5

Browse files
feat(MORG-45): update branch PR status in registry during morg status (#33)
When running `morg status`, if a branch has a PR and the PR state has changed since the last sync (different PR number, status, or merged state), update the branch entry in branches.json so the registry stays current without requiring an explicit `morg sync`.
1 parent 15fc51c commit 3b8e1f5

1 file changed

Lines changed: 20 additions & 0 deletions

File tree

src/commands/status.ts

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ import { findBranchCaseInsensitive } from '../utils/ticket';
99
import { renderStatus } from '../ui/output';
1010
import { theme, symbols } from '../ui/theme';
1111
import { registry } from '../services/registry';
12+
import { ghPrToPrStatus } from '../integrations/providers/github/github-client';
1213

1314
async function runStatusDetail(targetBranch: string, projectId: string): Promise<void> {
1415
const [branchesFile, projectConfig] = await Promise.all([
@@ -38,6 +39,25 @@ async function runStatusDetail(targetBranch: string, projectId: string): Promise
3839
execa('git', ['diff', '--stat', `${defaultBranch}...HEAD`], { reject: false }),
3940
]);
4041

42+
// Update registry with latest PR status while we have the data
43+
if (trackedBranch && prResult.status === 'fulfilled' && prResult.value) {
44+
const pr = prResult.value;
45+
const prStatus = ghPrToPrStatus(pr);
46+
const branchStatus = pr.mergedAt ? ('pr_merged' as const) : ('pr_open' as const);
47+
if (
48+
trackedBranch.prNumber !== pr.number ||
49+
trackedBranch.prStatus !== prStatus ||
50+
trackedBranch.status !== branchStatus
51+
) {
52+
trackedBranch.prNumber = pr.number;
53+
trackedBranch.prUrl = pr.url;
54+
trackedBranch.prStatus = prStatus;
55+
trackedBranch.status = branchStatus;
56+
trackedBranch.updatedAt = new Date().toISOString();
57+
await configManager.saveBranches(projectId, branchesFile);
58+
}
59+
}
60+
4161
const lines: string[] = [];
4262

4363
lines.push(`${theme.primaryBold('Branch:')} ${targetBranch}`);

0 commit comments

Comments
 (0)