@@ -40,15 +40,43 @@ test.serial('Publish a release', async t => {
40
40
const releaseUrl = `https://github.com/${ owner } /${ repo } /releases/${ nextRelease . version } ` ;
41
41
42
42
const github = authenticate ( { githubToken} )
43
+ . get ( `/repos/${ owner } /${ repo } /git/refs/tags/${ nextRelease . gitTag } ` )
44
+ . reply ( 404 )
45
+ . post ( `/repos/${ owner } /${ repo } /git/refs` , { ref : `refs/tags/${ nextRelease . gitTag } ` , sha : nextRelease . gitHead } )
46
+ . reply ( { } )
43
47
. post ( `/repos/${ owner } /${ repo } /releases` , {
44
48
tag_name : nextRelease . gitTag ,
45
49
target_commitish : options . branch ,
46
50
name : nextRelease . gitTag ,
47
51
body : nextRelease . notes ,
48
52
} )
49
- . reply ( 200 , { html_url : releaseUrl } )
50
- . post ( `/repos/${ owner } /${ repo } /git/refs` , { ref : `refs/tags/${ nextRelease . gitTag } ` , sha : nextRelease . gitHead } )
51
- . reply ( { } ) ;
53
+ . reply ( 200 , { html_url : releaseUrl } ) ;
54
+
55
+ await publish ( pluginConfig , options , nextRelease , t . context . logger ) ;
56
+
57
+ t . true ( t . context . log . calledWith ( match . string , releaseUrl ) ) ;
58
+ t . true ( github . isDone ( ) ) ;
59
+ } ) ;
60
+
61
+ test . serial ( 'Publish a release with an existing tag' , async t => {
62
+ const owner = 'test_user' ;
63
+ const repo = 'test_repo' ;
64
+ const githubToken = 'github_token' ;
65
+ const pluginConfig = { githubToken} ;
66
+ const nextRelease = { version : '1.0.0' , gitHead : '123' , gitTag : 'v1.0.0' , notes : 'Test release note body' } ;
67
+ const options = { branch : 'master' , repositoryUrl : `https://github.com/${ owner } /${ repo } .git` } ;
68
+ const releaseUrl = `https://github.com/${ owner } /${ repo } /releases/${ nextRelease . version } ` ;
69
+
70
+ const github = authenticate ( { githubToken} )
71
+ . get ( `/repos/${ owner } /${ repo } /git/refs/tags/${ nextRelease . gitTag } ` )
72
+ . reply ( { ref : `refs/tags/${ nextRelease . gitTag } ` , object : { sha : 'e23a1bd8d7240c1eb3287374956042ffbcadca84' } } )
73
+ . post ( `/repos/${ owner } /${ repo } /releases` , {
74
+ tag_name : nextRelease . gitTag ,
75
+ target_commitish : options . branch ,
76
+ name : nextRelease . gitTag ,
77
+ body : nextRelease . notes ,
78
+ } )
79
+ . reply ( 200 , { html_url : releaseUrl } ) ;
52
80
53
81
await publish ( pluginConfig , options , nextRelease , t . context . logger ) ;
54
82
@@ -74,15 +102,17 @@ test.serial('Publish a release with one asset', async t => {
74
102
githubToken : process . env . GH_TOKEN ,
75
103
githubApiPathPrefix : process . env . GH_PREFIX ,
76
104
} )
105
+ . get ( `/repos/${ owner } /${ repo } /git/refs/tags/${ nextRelease . gitTag } ` )
106
+ . reply ( 404 )
107
+ . post ( `/repos/${ owner } /${ repo } /git/refs` , { ref : `refs/tags/${ nextRelease . gitTag } ` , sha : nextRelease . gitHead } )
108
+ . reply ( { } )
77
109
. post ( `/repos/${ owner } /${ repo } /releases` , {
78
110
tag_name : nextRelease . gitTag ,
79
111
target_commitish : options . branch ,
80
112
name : nextRelease . gitTag ,
81
113
body : nextRelease . notes ,
82
114
} )
83
- . reply ( 200 , { html_url : releaseUrl , id : releaseId } )
84
- . post ( `/repos/${ owner } /${ repo } /git/refs` , { ref : `refs/tags/${ nextRelease . gitTag } ` , sha : nextRelease . gitHead } )
85
- . reply ( { } ) ;
115
+ . reply ( 200 , { html_url : releaseUrl , id : releaseId } ) ;
86
116
87
117
const githubUpload = upload ( { githubUrl : process . env . GH_URL , githubToken : process . env . GH_TOKEN } )
88
118
. post ( `/repos/${ owner } /${ repo } /releases/${ releaseId } /assets?name=${ escape ( 'upload.txt' ) } ` )
@@ -115,15 +145,17 @@ test.serial('Publish a release with one asset and custom github url', async t =>
115
145
githubUrl : process . env . GITHUB_URL ,
116
146
githubApiPathPrefix : process . env . GITHUB_PREFIX ,
117
147
} )
148
+ . get ( `/repos/${ owner } /${ repo } /git/refs/tags/${ nextRelease . gitTag } ` )
149
+ . reply ( 404 )
150
+ . post ( `/repos/${ owner } /${ repo } /git/refs` , { ref : `refs/tags/${ nextRelease . gitTag } ` , sha : nextRelease . gitHead } )
151
+ . reply ( { } )
118
152
. post ( `/repos/${ owner } /${ repo } /releases` , {
119
153
tag_name : nextRelease . gitTag ,
120
154
target_commitish : options . branch ,
121
155
name : nextRelease . gitTag ,
122
156
body : nextRelease . notes ,
123
157
} )
124
- . reply ( 200 , { html_url : releaseUrl , id : releaseId } )
125
- . post ( `/repos/${ owner } /${ repo } /git/refs` , { ref : `refs/tags/${ nextRelease . gitTag } ` , sha : nextRelease . gitHead } )
126
- . reply ( { } ) ;
158
+ . reply ( 200 , { html_url : releaseUrl , id : releaseId } ) ;
127
159
128
160
const githubUpload = upload ( { githubToken : process . env . GITHUB_TOKEN , githubUrl : process . env . GITHUB_URL } )
129
161
. post ( `/repos/${ owner } /${ repo } /releases/${ releaseId } /assets?name=${ escape ( 'upload.txt' ) } ` )
@@ -156,15 +188,17 @@ test.serial('Publish a release with an array of assets', async t => {
156
188
const releaseId = 1 ;
157
189
158
190
const github = authenticate ( { githubToken} )
191
+ . get ( `/repos/${ owner } /${ repo } /git/refs/tags/${ nextRelease . gitTag } ` )
192
+ . reply ( 404 )
193
+ . post ( `/repos/${ owner } /${ repo } /git/refs` , { ref : `refs/tags/${ nextRelease . gitTag } ` , sha : nextRelease . gitHead } )
194
+ . reply ( { } )
159
195
. post ( `/repos/${ owner } /${ repo } /releases` , {
160
196
tag_name : nextRelease . gitTag ,
161
197
target_commitish : options . branch ,
162
198
name : nextRelease . gitTag ,
163
199
body : nextRelease . notes ,
164
200
} )
165
- . reply ( 200 , { html_url : releaseUrl , id : releaseId } )
166
- . post ( `/repos/${ owner } /${ repo } /git/refs` , { ref : `refs/tags/${ nextRelease . gitTag } ` , sha : nextRelease . gitHead } )
167
- . reply ( { } ) ;
201
+ . reply ( 200 , { html_url : releaseUrl , id : releaseId } ) ;
168
202
169
203
const githubUpload = upload ( { githubToken} )
170
204
. post ( `/repos/${ owner } /${ repo } /releases/${ releaseId } /assets?name=${ escape ( 'upload.txt' ) } ` )
@@ -185,7 +219,7 @@ test.serial('Publish a release with an array of assets', async t => {
185
219
t . true ( githubUpload . isDone ( ) ) ;
186
220
} ) ;
187
221
188
- test . serial ( 'Publish a release with an array of misconfigured assets' , async t => {
222
+ test . serial ( 'Publish a release with an array of missing assets' , async t => {
189
223
const owner = 'test_user' ;
190
224
const repo = 'test_repo' ;
191
225
const githubToken = 'github_token' ;
@@ -199,15 +233,17 @@ test.serial('Publish a release with an array of misconfigured assets', async t =
199
233
const releaseId = 1 ;
200
234
201
235
const github = authenticate ( { githubToken} )
236
+ . get ( `/repos/${ owner } /${ repo } /git/refs/tags/${ nextRelease . gitTag } ` )
237
+ . reply ( 404 )
238
+ . post ( `/repos/${ owner } /${ repo } /git/refs` , { ref : `refs/tags/${ nextRelease . gitTag } ` , sha : nextRelease . gitHead } )
239
+ . reply ( { } )
202
240
. post ( `/repos/${ owner } /${ repo } /releases` , {
203
241
tag_name : nextRelease . gitTag ,
204
242
target_commitish : options . branch ,
205
243
name : nextRelease . gitTag ,
206
244
body : nextRelease . notes ,
207
245
} )
208
- . reply ( 200 , { html_url : releaseUrl , id : releaseId } )
209
- . post ( `/repos/${ owner } /${ repo } /git/refs` , { ref : `refs/tags/${ nextRelease . gitTag } ` , sha : nextRelease . gitHead } )
210
- . reply ( { } ) ;
246
+ . reply ( 200 , { html_url : releaseUrl , id : releaseId } ) ;
211
247
212
248
await publish ( pluginConfig , options , nextRelease , t . context . logger ) ;
213
249
@@ -216,3 +252,21 @@ test.serial('Publish a release with an array of misconfigured assets', async t =
216
252
t . true ( t . context . error . calledWith ( match . string , 'test/fixtures' ) ) ;
217
253
t . true ( github . isDone ( ) ) ;
218
254
} ) ;
255
+
256
+ test . serial ( 'Throw Error if get tag call return an error other than 404' , async t => {
257
+ const owner = 'test_user' ;
258
+ const repo = 'test_repo' ;
259
+ const githubToken = 'github_token' ;
260
+ const pluginConfig = { githubToken} ;
261
+ const nextRelease = { version : '1.0.0' , gitHead : '123' , gitTag : 'v1.0.0' , notes : 'Test release note body' } ;
262
+ const options = { branch : 'master' , repositoryUrl : `https://github.com/${ owner } /${ repo } .git` } ;
263
+
264
+ const github = authenticate ( { githubToken} )
265
+ . get ( `/repos/${ owner } /${ repo } /git/refs/tags/${ nextRelease . gitTag } ` )
266
+ . reply ( 500 ) ;
267
+
268
+ const error = await t . throws ( publish ( pluginConfig , options , nextRelease , t . context . logger ) , Error ) ;
269
+
270
+ t . is ( error . code , 500 ) ;
271
+ t . true ( github . isDone ( ) ) ;
272
+ } ) ;
0 commit comments