1
1
import * as core from '@actions/core'
2
2
import PromisePool from '@supercharge/promise-pool'
3
3
import { Octokit } from 'octokit'
4
- import { array , parse , string } from 'valibot'
4
+ import { array , InferOutput , object , parse , string } from 'valibot'
5
5
6
- const ReleaseTagsSchema = array ( string ( ) )
6
+ const ReleaseTags = array ( string ( ) )
7
+
8
+ const ReleaseIssuesBody = object ( {
9
+ projectId : string ( ) ,
10
+ apps : array (
11
+ object ( {
12
+ appName : string ( ) ,
13
+ issues : array (
14
+ object ( {
15
+ version : string ( ) ,
16
+ issueId : string ( ) ,
17
+ rawText : string ( )
18
+ } )
19
+ )
20
+ } )
21
+ )
22
+ } )
23
+ type ReleaseIssuesBody = InferOutput < typeof ReleaseIssuesBody >
7
24
8
25
function parseReleaseTags ( string : string ) {
9
26
try {
10
- return parse ( ReleaseTagsSchema , JSON . parse ( string ) )
27
+ return parse ( ReleaseTags , JSON . parse ( string ) )
11
28
} catch ( error ) {
12
29
core . setFailed ( `Failed to parse releases-tags` )
13
30
throw error
@@ -18,6 +35,7 @@ type ParsedIssue = {
18
35
workspace : string
19
36
issue : string
20
37
title : string
38
+ url : string
21
39
}
22
40
23
41
export function parseIssueFromReleaseBody (
@@ -31,7 +49,10 @@ export function parseIssueFromReleaseBody(
31
49
return matchedIssueUrls . map ( url => {
32
50
const IssueUrlPattern =
33
51
/ \( h t t p s : \/ \/ l i n e a r .a p p \/ (?< workspace > \w + ) \/ i s s u e \/ (?< issue > .* ) \/ (?< title > .* ) \) / g
34
- return IssueUrlPattern . exec ( url ) ?. groups
52
+ return {
53
+ ...IssueUrlPattern . exec ( url ) ?. groups ,
54
+ url
55
+ }
35
56
} ) as any
36
57
}
37
58
@@ -70,14 +91,34 @@ export async function releaseMode(): Promise<void> {
70
91
return
71
92
}
72
93
73
- const issues = new Set < string > ( )
94
+ const releaseIssues : ReleaseIssuesBody [ 'apps' ] = [ ]
95
+
74
96
for ( const {
75
- data : { body }
97
+ data : { body, tag_name }
76
98
} of results ) {
77
99
if ( ! body ) continue
100
+ // TODO: Add support for poly repos
101
+ const version = tag_name . split ( '@' ) . at ( - 1 ) !
102
+ const appName = tag_name . split ( '@' ) . slice ( 0 , - 1 ) . join ( '@' )
103
+ const issues = new Set < string > ( )
104
+ const issuesMap = new Map < string , ParsedIssue > ( )
105
+ const app : ReleaseIssuesBody [ 'apps' ] [ 0 ] = {
106
+ appName,
107
+ issues : [ ]
108
+ }
78
109
for ( const issue of parseIssueFromReleaseBody ( body ) ) {
79
110
issues . add ( issue . issue )
111
+ issuesMap . set ( issue . issue , issue )
80
112
}
113
+ app . issues = Array . from ( issues ) . map ( issueId => {
114
+ const { url } = issuesMap . get ( issueId ) !
115
+ return {
116
+ issueId,
117
+ version,
118
+ rawText : url
119
+ }
120
+ } )
121
+ releaseIssues . push ( app )
81
122
}
82
123
83
124
const releaseWebhookUrl = core . getInput ( 'release-webhook-url' )
@@ -89,12 +130,8 @@ export async function releaseMode(): Promise<void> {
89
130
'Content-Type' : 'application/json'
90
131
} ,
91
132
body : JSON . stringify ( {
92
- data : {
93
- version : core . getInput ( 'version' ) ,
94
- environment : core . getInput ( 'environment' ) ,
95
- projectName : core . getInput ( 'project-name' ) ,
96
- issues : Array . from ( issues ) . map ( issueId => ( { issueId } ) )
97
- }
133
+ projectId : core . getInput ( 'project-id' ) ,
134
+ apps : releaseIssues
98
135
} )
99
136
} )
100
137
0 commit comments