@@ -28,6 +28,7 @@ async function run() {
2828 const master_branch = state . master_branch ;
2929 const repo_path = state . repo_path ;
3030 const sync_github = state . sync_github ;
31+ const labels = argv . label ?? [ ] ;
3132
3233 invariant ( branch_name , "branch_name must exist" ) ;
3334 invariant ( commit_map , "commit_map must exist" ) ;
@@ -140,17 +141,17 @@ async function run() {
140141 const pr_url_list = all_pr_groups . map ( ( g ) => pr_url_by_group_id [ g . id ] ) ;
141142
142143 // update PR body for all pr groups (not just push_group_list)
143- const update_pr_body_tasks = [ ] ;
144+ const update_pr_tasks = [ ] ;
144145 for ( let i = 0 ; i < all_pr_groups . length ; i ++ ) {
145146 const group = all_pr_groups [ i ] ;
146147
147148 const selected_url = pr_url_by_group_id [ group . id ] ;
148149
149- const task = update_pr_body ( { group, selected_url, pr_url_list } ) ;
150- update_pr_body_tasks . push ( task ) ;
150+ const task = update_pr ( { group, selected_url, pr_url_list, labels } ) ;
151+ update_pr_tasks . push ( task ) ;
151152 }
152153
153- await Promise . all ( update_pr_body_tasks ) ;
154+ await Promise . all ( update_pr_tasks ) ;
154155
155156 actions . unregister_abort_handler ( ) ;
156157
@@ -262,6 +263,7 @@ async function run() {
262263 title : group . title ,
263264 body : DEFAULT_PR_BODY ,
264265 draft : argv . draft ,
266+ labels,
265267 } ) ;
266268
267269 if ( ! pr_url ) {
@@ -273,10 +275,11 @@ async function run() {
273275 }
274276 }
275277
276- async function update_pr_body ( args : {
278+ async function update_pr ( args : {
277279 group : CommitMetadataGroup ;
278280 selected_url : string ;
279281 pr_url_list : Array < string > ;
282+ labels : Array < string > ;
280283 } ) {
281284 const { group, selected_url, pr_url_list } = args ;
282285
@@ -292,17 +295,30 @@ async function run() {
292295
293296 const debug_meta = `${ group . id } ${ selected_url } ` ;
294297
295- if ( update_body === body ) {
296- actions . debug ( `Skipping body update ${ debug_meta } ` ) ;
297- } else {
298- actions . debug ( `Update body ${ debug_meta } ` ) ;
298+ const body_changed = update_body !== body ;
299+ const needs_labels = args . labels . length > 0 ;
299300
300- await github . pr_edit ( {
301- branch : group . id ,
302- base : group . base ,
303- body : update_body ,
304- } ) ;
301+ if ( ! body_changed && ! needs_labels ) {
302+ actions . debug ( `Skipping update ${ debug_meta } ` ) ;
303+ return ;
305304 }
305+
306+ actions . debug ( `Update PR ${ debug_meta } ` ) ;
307+
308+ const edit_args : Parameters < typeof github . pr_edit > [ 0 ] = {
309+ branch : group . id ,
310+ base : group . base ,
311+ } ;
312+
313+ if ( body_changed ) {
314+ edit_args . body = update_body ;
315+ }
316+
317+ if ( needs_labels ) {
318+ edit_args . add_labels = args . labels ;
319+ }
320+
321+ await github . pr_edit ( edit_args ) ;
306322 }
307323
308324 function is_pr_master_base ( group : CommitMetadataGroup ) {
0 commit comments