MCPcopy Create free account
hub / github.com/github/gh-aw / executePRUpdate

Function executePRUpdate

actions/setup/js/update_pull_request.cjs:66–169  ·  view source on GitHub ↗

* Execute the pull request update API call * @param {any} github - GitHub API client * @param {any} context - GitHub Actions context * @param {number} prNumber - PR number to update * @param {any} updateData - Data to update * @returns {Promise } Updated pull request

(github, context, prNumber, updateData)

Source from the content-addressed store, hash-verified

64 * @returns {Promise<any>} Updated pull request
65 */
66async function executePRUpdate(github, context, prNumber, updateData) {
67 // Handle body operation (append/prepend/replace/replace-island)
68 const operation = updateData._operation || "replace";
69 const rawBody = updateData._rawBody;
70 const includeFooter = updateData._includeFooter !== false; // Default to true
71
72 // Remove internal fields (including update_branch which is handled separately below)
73 const { _operation, _rawBody, _includeFooter, _workflowRepo, update_branch, ...apiData } = updateData;
74 const updateBranch = update_branch === true;
75
76 if (updateBranch) {
77 core.info(`Updating pull request #${prNumber} branch with base branch changes`);
78 try {
79 await withRetry(
80 () =>
81 github.rest.pulls.updateBranch({
82 owner: context.repo.owner,
83 repo: context.repo.repo,
84 pull_number: prNumber,
85 }),
86 {
87 maxRetries: 1,
88 initialDelayMs: 0,
89 jitterMs: 0,
90 shouldRetry: isTransientError,
91 },
92 `update pull request #${prNumber} branch from base`
93 );
94 } catch (error) {
95 const errorMessage = getErrorMessage(error);
96 if (isNonFatalUpdateBranchError(error)) {
97 core.warning(`Failed to update pull request #${prNumber} branch from base (non-fatal): ${errorMessage}`);
98 } else {
99 core.warning(`Failed to update pull request #${prNumber} branch from base: ${errorMessage}`);
100 throw error;
101 }
102 }
103 }
104
105 // If we have a body, process it with the appropriate operation
106 if (rawBody !== undefined) {
107 // Fetch current PR body for all operations (needed for append/prepend/replace-island/replace)
108 const { data: currentPR } = await github.rest.pulls.get({
109 owner: context.repo.owner,
110 repo: context.repo.repo,
111 pull_number: prNumber,
112 });
113 const currentBody = currentPR.body || "";
114
115 // Get workflow run URL for AI attribution.
116 // Use the original workflow repo (_workflowRepo) rather than context.repo, because
117 // context may be effectiveContext with repo overridden to a cross-repo target.
118 const workflowName = process.env.GH_AW_WORKFLOW_NAME || "GitHub Agentic Workflow";
119 const workflowId = process.env.GH_AW_WORKFLOW_ID || "";
120 const callerWorkflowId = process.env.GH_AW_CALLER_WORKFLOW_ID || "";
121 const workflowRepo = _workflowRepo || context.repo;
122 const runUrl = buildWorkflowRunUrl(context, workflowRepo);
123

Callers

nothing calls this directly

Calls 7

withRetryFunction · 0.85
buildWorkflowRunUrlFunction · 0.85
generateHistoryUrlFunction · 0.85
updateBodyFunction · 0.85
getMethod · 0.80
getErrorMessageFunction · 0.70

Tested by

no test coverage detected