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
+
1
17
module . exports = async ( { github, context, core } ) => {
2
18
const branches = JSON . parse ( process . env . BRANCHES_JSON || '[]' ) ;
3
19
@@ -70,7 +86,7 @@ for (const targetBranch of branches) {
70
86
// Create backport branch from target release branch
71
87
core . info ( `Creating branch ${ backportBranch } from ${ targetBranch } ` ) ;
72
88
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' } ) ;
74
90
// Cherry-pick each commit from the PR
75
91
let hasConflicts = false ;
76
92
for ( let i = 0 ; i < commits . length ; i ++ ) {
@@ -107,10 +123,12 @@ for (const targetBranch of branches) {
107
123
execSync ( `git push origin ${ backportBranch } ` , { stdio : 'inherit' } ) ;
108
124
// Create pull request
109
125
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.**
114
132
115
133
Original PR: #${ prNumber }
116
134
Original Author: @${ prAuthor }
@@ -122,7 +140,7 @@ ${commitList}
122
140
1. Review the conflicts in the "Files changed" tab
123
141
2. Check out this branch locally: \`git fetch origin ${ backportBranch } && git checkout ${ backportBranch } \`
124
142
3. Resolve conflicts manually
125
- 4. Push the resolution: \`git push origin ${ backportBranch } \`
143
+ 4. Push the resolution: \`git push -f origin ${ backportBranch } \`
126
144
127
145
---
128
146
<details>
@@ -134,12 +152,11 @@ git checkout ${backportBranch}
134
152
# Resolve conflicts in your editor
135
153
git add .
136
154
git commit
137
- git push origin ${ backportBranch }
155
+ git push -f origin ${ backportBranch }
138
156
\`\`\`
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.
143
160
144
161
Original PR: #${ prNumber }
145
162
Original Author: @${ prAuthor }
@@ -148,6 +165,7 @@ Original Author: @${prAuthor}
148
165
${ commitList }
149
166
150
167
This backport was automatically created by the backport bot.` ;
168
+ }
151
169
152
170
const newPR = await github . rest . pulls . create ( {
153
171
owner : context . repo . owner ,
@@ -218,5 +236,3 @@ for (const result of results) {
218
236
}
219
237
return results ;
220
238
} ;
221
-
222
-
0 commit comments