Skip to content

Commit cfb1409

Browse files
feat: add generatePullRequestBody function and corresponding tests
1 parent cfea6e2 commit cfb1409

File tree

4 files changed

+89
-2
lines changed

4 files changed

+89
-2
lines changed

docs/tasks.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -237,7 +237,7 @@ Use Context7 MCP for up to date documentation.
237237
Check existing ref before branch create. Document workflow `concurrency`.
238238
Verify: Parallel runs yield one PR.
239239

240-
39. [ ] **Rollback instructions generator**
240+
39. [x] **Rollback instructions generator**
241241
PR body includes exact git commands.
242242
Verify: Snapshot contains commands with placeholders.
243243

src/action-execution.ts

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@ import {
1212
type LatestPatchResult,
1313
} from './versioning';
1414
import { createOrUpdatePullRequest, findExistingPullRequest, type PullRequestResult } from './git';
15+
import { generatePullRequestBody } from './pr-body';
1516

1617
export type SkipReason =
1718
| 'no_matches_found'
@@ -231,13 +232,21 @@ export async function executeAction(
231232
}
232233

233234
try {
235+
const prBody = generatePullRequestBody({
236+
track,
237+
newVersion: latestVersion,
238+
filesChanged,
239+
branchName,
240+
defaultBranch,
241+
});
242+
234243
const pullRequest = await dependencies.createOrUpdatePullRequest({
235244
owner: repository.owner,
236245
repo: repository.repo,
237246
head: branchName,
238247
base: defaultBranch,
239248
title: `chore: bump python ${track} to ${latestVersion}`,
240-
body: `Update CPython ${track} pins to ${latestVersion}.`,
249+
body: prBody,
241250
authToken: githubToken,
242251
});
243252

src/pr-body.ts

Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,44 @@
1+
interface GeneratePullRequestBodyOptions {
2+
track: string;
3+
newVersion: string;
4+
filesChanged: string[];
5+
branchName: string;
6+
defaultBranch: string;
7+
}
8+
9+
export function generatePullRequestBody(options: GeneratePullRequestBodyOptions): string {
10+
const { track, newVersion, filesChanged, branchName, defaultBranch } = options;
11+
12+
const filesSection = filesChanged.length
13+
? filesChanged.map((file) => `- \`${file}\``).join('\n')
14+
: 'No files were modified in this bump.';
15+
16+
return [
17+
'## Summary',
18+
'',
19+
`- Bump CPython ${track} pins to \`${newVersion}\`.`,
20+
'',
21+
'## Files Updated',
22+
'',
23+
filesSection,
24+
'',
25+
'## Rollback',
26+
'',
27+
'Before merge, close this PR and delete the branch:',
28+
'',
29+
'```sh',
30+
`git push origin --delete ${branchName}`,
31+
'```',
32+
'',
33+
`After merge, revert the change on ${defaultBranch}:`,
34+
'',
35+
'```sh',
36+
`git checkout ${defaultBranch}`,
37+
`git pull --ff-only origin ${defaultBranch}`,
38+
'git revert --no-edit <merge_commit_sha>',
39+
`git push origin ${defaultBranch}`,
40+
'```',
41+
'',
42+
'Replace `<merge_commit_sha>` with the SHA of the merge commit if rollback is required.',
43+
].join('\n');
44+
}

tests/pr-body.test.ts

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
import { describe, expect, it } from 'vitest';
2+
3+
import { generatePullRequestBody } from '../src/pr-body';
4+
5+
describe('generatePullRequestBody', () => {
6+
it('includes summary, files, and rollback sections', () => {
7+
const body = generatePullRequestBody({
8+
track: '3.13',
9+
newVersion: '3.13.2',
10+
filesChanged: ['Dockerfile', '.github/workflows/ci.yml'],
11+
branchName: 'chore/bump-python-3.13',
12+
defaultBranch: 'main',
13+
});
14+
15+
expect(body).toContain('## Summary');
16+
expect(body).toContain('CPython 3.13 pins to `3.13.2`');
17+
expect(body).toContain('`Dockerfile`');
18+
expect(body).toContain('git push origin --delete chore/bump-python-3.13');
19+
expect(body).toContain('git checkout main');
20+
expect(body).toContain('git revert --no-edit <merge_commit_sha>');
21+
});
22+
23+
it('falls back to message when no files changed', () => {
24+
const body = generatePullRequestBody({
25+
track: '3.12',
26+
newVersion: '3.12.4',
27+
filesChanged: [],
28+
branchName: 'chore/bump-python-3.12',
29+
defaultBranch: 'main',
30+
});
31+
32+
expect(body).toContain('No files were modified in this bump.');
33+
});
34+
});

0 commit comments

Comments
 (0)