1+ /**
2+ * Copyright 2025 NVIDIA CORPORATION
3+ *
4+ * Licensed under the Apache License, Version 2.0 (the "License");
5+ * you may not use this file except in compliance with the License.
6+ * You may obtain a copy of the License at
7+ *
8+ * http://www.apache.org/licenses/LICENSE-2.0
9+ *
10+ * Unless required by applicable law or agreed to in writing, software
11+ * distributed under the License is distributed on an "AS IS" BASIS,
12+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+ * See the License for the specific language governing permissions and
14+ * limitations under the License.
15+ */
16+
117module . exports = async ( { github, context, core } ) => {
218const branches = JSON . parse ( process . env . BRANCHES_JSON || '[]' ) ;
319
@@ -70,7 +86,7 @@ for (const targetBranch of branches) {
7086 // Create backport branch from target release branch
7187 core . info ( `Creating branch ${ backportBranch } from ${ targetBranch } ` ) ;
7288 execSync ( `git fetch origin ${ targetBranch } :${ targetBranch } ` , { stdio : 'inherit' } ) ;
73- execSync ( `git checkout -b ${ backportBranch } ${ targetBranch } ` , { stdio : 'inherit' } ) ;
89+ execSync ( `git checkout ${ backportBranch } || git checkout -b ${ backportBranch } ${ targetBranch } ` , { stdio : 'inherit' } ) ;
7490 // Cherry-pick each commit from the PR
7591 let hasConflicts = false ;
7692 for ( let i = 0 ; i < commits . length ; i ++ ) {
@@ -107,10 +123,12 @@ for (const targetBranch of branches) {
107123 execSync ( `git push origin ${ backportBranch } ` , { stdio : 'inherit' } ) ;
108124 // Create pull request
109125 const commitList = commits . map ( c => `- \`${ c . sha . substring ( 0 , 7 ) } \` ${ c . commit . message . split ( '\n' ) [ 0 ] } ` ) . join ( '\n' ) ;
110- const prBody = hasConflicts
111- ? `🤖 **Automated backport of #${ prNumber } to \`${ targetBranch } \`**
112-
113- ⚠️ **This PR has merge conflicts that need manual resolution.**
126+
127+ // Build PR body based on conflict status
128+ let prBody = `🤖 **Automated backport of #${ prNumber } to \`${ targetBranch } \`**\n\n` ;
129+
130+ if ( hasConflicts ) {
131+ prBody += `⚠️ **This PR has merge conflicts that need manual resolution.**
114132
115133Original PR: #${ prNumber }
116134Original Author: @${ prAuthor }
@@ -122,7 +140,7 @@ ${commitList}
1221401. Review the conflicts in the "Files changed" tab
1231412. Check out this branch locally: \`git fetch origin ${ backportBranch } && git checkout ${ backportBranch } \`
1241423. Resolve conflicts manually
125- 4. Push the resolution: \`git push origin ${ backportBranch } \`
143+ 4. Push the resolution: \`git push --force-with-lease origin ${ backportBranch } \`
126144
127145---
128146<details>
@@ -134,12 +152,11 @@ git checkout ${backportBranch}
134152# Resolve conflicts in your editor
135153git add .
136154git commit
137- git push origin ${ backportBranch }
155+ git push --force-with-lease origin ${ backportBranch }
138156\`\`\`
139- </details>`
140- : `🤖 **Automated backport of #${ prNumber } to \`${ targetBranch } \`**
141-
142- ✅ Cherry-pick completed successfully with no conflicts.
157+ </details>` ;
158+ } else {
159+ prBody += `✅ Cherry-pick completed successfully with no conflicts.
143160
144161Original PR: #${ prNumber }
145162Original Author: @${ prAuthor }
@@ -148,6 +165,7 @@ Original Author: @${prAuthor}
148165${ commitList }
149166
150167This backport was automatically created by the backport bot.` ;
168+ }
151169
152170 const newPR = await github . rest . pulls . create ( {
153171 owner : context . repo . owner ,
@@ -218,5 +236,3 @@ for (const result of results) {
218236}
219237return results ;
220238} ;
221-
222-
0 commit comments