@@ -123,13 +123,72 @@ export function* run(): Generator<any, any, any> {
123
123
} ) ;
124
124
125
125
if ( covectored ) {
126
- let packagesPublished = Object . keys ( covectored ) . reduce ( ( pub , pkg ) => {
127
- if ( ! covectored [ pkg ] . published ) {
128
- return pub ;
126
+ let packagesPublished = Object . entries ( covectored ) . reduce ( ( pub , pkg ) => {
127
+ //@ts -ignore
128
+ if ( pkg [ 1 ] . published ) {
129
+ //@ts -ignore
130
+ let { name : pkgName , version : pkgVersion } = pkg [ 1 ] . pkg . pkgFile . pkg
131
+ return pub . concat ( `${ pkgName } @${ pkgVersion } ` ) ;
132
+ }
133
+ } , [ ] ) ;
134
+
135
+ if ( token && github . context . payload . pull_request ) {
136
+ const octokit = github . getOctokit ( token ) ;
137
+ const {
138
+ pull_request : {
139
+ number : issue_number ,
140
+ } ,
141
+ repository : {
142
+ name : repo ,
143
+ owner : {
144
+ login : owner
145
+ }
146
+ } ,
147
+ after
148
+ } = github . context . payload ;
149
+
150
+ const { data } = yield octokit . rest . issues . listComments ( {
151
+ owner,
152
+ repo,
153
+ issue_number,
154
+ } ) ;
155
+
156
+ const covectorComments = data . filter ( comment => comment . body . includes ( '<!-- covector comment -->' ) ) ;
157
+
158
+ let prComment = ( ) => {
159
+ let commentHead = '' ;
160
+ let commentBody = '' ;
161
+ if ( packagesPublished . length ) {
162
+ commentHead = `The following preview packages have been published by Covector:`
163
+ commentBody = packagesPublished . reduce ( ( result , publishedPackage ) => {
164
+ return `${ result } - \`${ publishedPackage } \`\n` ;
165
+ } , '' )
166
+ } else {
167
+ commentHead = "Covector did not publish any preview packages."
168
+ }
169
+ const commentFoot = `<p align="right">${ after . slice ( 0 , 7 ) } </p>` ;
170
+ return `${ commentHead } \n${ commentBody } \n${ commentFoot } \n<!-- covector comment -->` ;
171
+ } ;
172
+
173
+ if ( covectorComments . length !== 1 ) {
174
+ yield octokit . rest . issues . createComment ( {
175
+ owner,
176
+ repo,
177
+ issue_number,
178
+ body : prComment ( ) ,
179
+ } ) ;
129
180
} else {
130
- return `${ pub } ${ pkg } ` ;
181
+ yield octokit . rest . issues . updateComment ( {
182
+ owner,
183
+ repo,
184
+ comment_id : covectorComments [ 0 ] . id ,
185
+ body : prComment ( ) ,
186
+ } ) ;
131
187
}
132
- } , "" ) ;
188
+ } else {
189
+ throw new Error ( `Github token argument in preview workflow is missing but it is required in order to generate comments on pull requests.` ) ;
190
+ }
191
+
133
192
core . setOutput ( "packagesPublished" , packagesPublished ) ;
134
193
for ( let pkg of Object . keys ( covectored ) ) {
135
194
if ( covectored [ pkg ] . command !== false ) successfulPublish = true ;
0 commit comments