Skip to content

Commit ca935b6

Browse files
authored
feat: add update-branch support to safe-outputs update-pull-request (#27244)
1 parent fd9f34c commit ca935b6

18 files changed

+387
-21
lines changed

.github/workflows/changeset.lock.yml

Lines changed: 6 additions & 3 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

.github/workflows/smoke-claude.lock.yml

Lines changed: 6 additions & 3 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

actions/setup/js/safe_output_type_validator.cjs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -445,7 +445,7 @@ function executeCustomValidation(item, customValidation, lineNum, itemType) {
445445
// Parse custom validation rule
446446
if (customValidation.startsWith("requiresOneOf:")) {
447447
const fields = customValidation.slice("requiresOneOf:".length).split(",");
448-
const hasValidField = fields.some(field => item[field] !== undefined);
448+
const hasValidField = fields.some(field => item[field] !== undefined && item[field] !== false);
449449
if (!hasValidField) {
450450
return {
451451
isValid: false,

actions/setup/js/safe_output_type_validator.test.cjs

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,16 @@ const SAMPLE_VALIDATION_CONFIG = {
4646
issue_number: { issueOrPRNumber: true },
4747
},
4848
},
49+
update_pull_request: {
50+
defaultMax: 1,
51+
customValidation: "requiresOneOf:title,body,update_branch",
52+
fields: {
53+
title: { type: "string", sanitize: true, maxLength: 256 },
54+
body: { type: "string", sanitize: true, maxLength: 65000 },
55+
update_branch: { type: "boolean" },
56+
pull_request_number: { issueOrPRNumber: true },
57+
},
58+
},
4959
assign_to_agent: {
5060
defaultMax: 1,
5161
customValidation: "requiresOneOf:issue_number,pull_number",
@@ -399,6 +409,23 @@ describe("safe_output_type_validator", () => {
399409
expect(result.error).toContain("issue_number");
400410
expect(result.error).toContain("pull_number");
401411
});
412+
413+
it("should fail for update_pull_request when update_branch is false and no title/body is provided", async () => {
414+
const { validateItem } = await import("./safe_output_type_validator.cjs");
415+
416+
const result = validateItem({ type: "update_pull_request", update_branch: false }, "update_pull_request", 1);
417+
418+
expect(result.isValid).toBe(false);
419+
expect(result.error).toContain("requires at least one of");
420+
});
421+
422+
it("should pass for update_pull_request when update_branch is true", async () => {
423+
const { validateItem } = await import("./safe_output_type_validator.cjs");
424+
425+
const result = validateItem({ type: "update_pull_request", update_branch: true }, "update_pull_request", 1);
426+
427+
expect(result.isValid).toBe(true);
428+
});
402429
});
403430

404431
describe("custom validation: startLineLessOrEqualLine", () => {

actions/setup/js/safe_outputs_tools.json

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -783,6 +783,10 @@
783783
"enum": ["replace", "append", "prepend"],
784784
"description": "How to update the PR body: 'replace' (default - completely overwrite), 'append' (add to end with separator), or 'prepend' (add to start with separator). Title is always replaced."
785785
},
786+
"update_branch": {
787+
"type": "boolean",
788+
"description": "When true, update the pull request branch with the latest base branch changes before applying other updates. Defaults to false."
789+
},
786790
"pull_request_number": {
787791
"type": ["number", "string"],
788792
"description": "Pull request number to update. This is the numeric ID from the GitHub URL (e.g., 234 in github.com/owner/repo/pull/234). Required when the workflow target is '*' (any PR)."

actions/setup/js/types/safe-outputs.d.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -235,6 +235,8 @@ interface UpdatePullRequestItem extends BaseSafeOutputItem {
235235
body?: string;
236236
/** Update operation for body: 'replace' (default), 'append', or 'prepend' */
237237
operation?: "replace" | "append" | "prepend";
238+
/** When true, updates the pull request branch with the latest base branch changes before other updates */
239+
update_branch?: boolean;
238240
/** Optional pull request number for target "*" */
239241
pull_request_number?: number | string;
240242
/** Whether the PR should be a draft (true) or ready for review (false) */

0 commit comments

Comments
 (0)