@@ -5,7 +5,7 @@ import fs from "fs/promises";
55import { colorize } from "./helpers/colorize.js" ;
66import { getReleaseInfo } from "./contributors.js" ;
77
8- const normalizeTag = ( tag ) => tag . replace ( / ^ v / , '' ) ;
8+ const normalizeTag = ( tag ) => tag ? 'v' + tag . replace ( / ^ v / , '' ) : '' ;
99
1010class RepoBot {
1111 constructor ( options ) {
@@ -29,7 +29,17 @@ class RepoBot {
2929 }
3030
3131 async notifyPRPublished ( id , tag ) {
32- const pr = await this . github . getPR ( id ) ;
32+ let pr ;
33+
34+ try {
35+ pr = await this . github . getPR ( id ) ;
36+ } catch ( err ) {
37+ if ( err . response ?. status === 404 ) {
38+ throw new Error ( `PR #${ id } not found (404)` ) ;
39+ }
40+
41+ throw err ;
42+ }
3343
3444 tag = normalizeTag ( tag ) ;
3545
@@ -41,7 +51,7 @@ class RepoBot {
4151 return false
4252 }
4353
44- await this . github . appendLabels ( id , [ 'v' + tag ] ) ;
54+ await this . github . appendLabels ( id , [ tag ] ) ;
4555
4656 if ( isBot || labels . find ( ( { name} ) => name === 'automated pr' ) || ( await this . github . isCollaborator ( login ) ) ) {
4757 return false ;
@@ -56,14 +66,16 @@ class RepoBot {
5666 author,
5767 release : {
5868 tag,
59- url : `https://github.com/${ this . owner } /${ this . repo } /releases/tag/v ${ tag } `
69+ url : `https://github.com/${ this . owner } /${ this . repo } /releases/tag/${ tag } `
6070 }
6171 } ) ;
6272
6373 return await this . addComment ( id , message ) ;
6474 }
6575
6676 async notifyPublishedPRs ( tag ) {
77+ tag = normalizeTag ( tag ) ;
78+
6779 const release = await getReleaseInfo ( tag ) ;
6880
6981 if ( ! release ) {
@@ -80,9 +92,9 @@ class RepoBot {
8092 try {
8193 console . log ( colorize ( ) `${ i ++ } ) Notify PR #${ pr . id } ` )
8294 const result = await this . notifyPRPublished ( pr . id , tag ) ;
83- console . log ( result ? 'OK ' : 'Skipped ' ) ;
95+ console . log ( '✔️' , result ? 'Label, comment ' : 'Label ' ) ;
8496 } catch ( err ) {
85- console . warn ( colorize ( 'green' , 'red' ) ` Failed notify PR ${ pr . id } : ${ err . message } ` ) ;
97+ console . warn ( colorize ( 'green' , 'red' ) `❌ Failed notify PR ${ pr . id } : ${ err . message } ` ) ;
8698 }
8799 }
88100 }
0 commit comments