@@ -109,6 +109,117 @@ class GithubApiTest :
109109 Version (" v2" ),
110110 ).right()
111111 }
112+ test(" scoped branches and tags starting with v" ) {
113+ // Given
114+ val tagsResponse =
115+ """
116+ [
117+ {
118+ "ref":"refs/tags/v1.0.0",
119+ "node_id":"MDM6UmVmMTk3ODE0NjI5OnJlZnMvdGFncy92MQ==",
120+ "url":"https://api.github.com/repos/some-owner/some-name/git/refs/tags/v1",
121+ "object": {
122+ "sha":"544eadc6bf3d226fd7a7a9f0dc5b5bf7ca0675b9",
123+ "type":"tag",
124+ "url":"https://api.github.com/repos/actions/some-name/git/tags/544eadc6bf3d226fd7a7a9f0dc5b5bf7ca0675b9"
125+ }
126+ },
127+ {
128+ "ref":"refs/tags/v1.0.1",
129+ "node_id":"MDM6UmVmMTk3ODE0NjI5OnJlZnMvdGFncy92MQ==",
130+ "url":"https://api.github.com/repos/some-owner/some-name/git/refs/tags/v1.0.1",
131+ "object": {
132+ "sha":"af513c7a016048ae468971c52ed77d9562c7c819",
133+ "type":"tag",
134+ "url":"https://api.github.com/repos/actions/some-name/git/tags/af513c7a016048ae468971c52ed77d9562c7c819"
135+ }
136+ },
137+ {
138+ "ref":"refs/tags/virtual/tag",
139+ "node_id":"MDM6UmVmMTk3ODE0NjI5OnJlZnMvdGFncy92MQ==",
140+ "url":"https://api.github.com/repos/some-owner/some-name/git/refs/tags/virtual/tag",
141+ "object": {
142+ "sha":"af513c7a016048ae468971c52ed77d9562c7c819",
143+ "type":"tag",
144+ "url":"https://api.github.com/repos/actions/some-name/git/tags/af513c7a016048ae468971c52ed77d9562c7c819"
145+ }
146+ }
147+ ]
148+ """ .trimIndent()
149+ val headsResponse =
150+ """
151+ [
152+ {
153+ "ref":"refs/heads/v1",
154+ "node_id":"MDM6UmVmMTk3ODE0NjI5OnJlZnMvaGVhZHMvdm1qb3NlcGgvc2lsZW50LXJldi1wYXJzZQ==",
155+ "url":"https://api.github.com/repos/some-owner/some-name/git/refs/heads/v1",
156+ "object": {
157+ "sha":"af5130cb8882054eda385840657dcbd1e19ab8f4",
158+ "type":"commit",
159+ "url":"https://api.github.com/repos/some-owner/some-name/git/commits/af5130cb8882054eda385840657dcbd1e19ab8f4"
160+ }
161+ },
162+ {
163+ "ref":"refs/heads/v2",
164+ "node_id":"MDM6UmVmMTk3ODE0NjI5OnJlZnMvaGVhZHMvdm1qb3NlcGgvdG9vbGtpdC13aW5kb3dzLWV4ZWM=",
165+ "url":"https://api.github.com/repos/some-owner/some-name/git/refs/heads/v2",
166+ "object": {
167+ "sha":"c22ccee38a13e34cb01a103c324adb1db665821e",
168+ "type":"commit",
169+ "url":"https://api.github.com/repos/some-owner/some-name/git/commits/c22ccee38a13e34cb01a103c324adb1db665821e"
170+ }
171+ },
172+ {
173+ "ref":"refs/heads/virtual/branch",
174+ "node_id":"MDM6UmVmMTk3ODE0NjI5OnJlZnMvaGVhZHMvdm1qb3NlcGgvdG9vbGtpdC13aW5kb3dzLWV4ZWM=",
175+ "url":"https://api.github.com/repos/some-owner/some-name/git/refs/heads/virtual/branch",
176+ "object": {
177+ "sha":"c22ccee38a13e34cb01a103c324adb1db665821e",
178+ "type":"commit",
179+ "url":"https://api.github.com/repos/some-owner/some-name/git/commits/c22ccee38a13e34cb01a103c324adb1db665821e"
180+ }
181+ }
182+ ]
183+ """ .trimIndent()
184+ mockServer
185+ .`when `(request().withPath(" /repos/$owner /$name /git/matching-refs/tags/v" ))
186+ .respond(
187+ response()
188+ .withStatusCode(200 )
189+ .withHeader(" Content-Type" , " application/json" )
190+ .withBody(tagsResponse),
191+ )
192+ mockServer
193+ .`when `(request().withPath(" /repos/$owner /$name /git/matching-refs/heads/v" ))
194+ .respond(
195+ response()
196+ .withStatusCode(200 )
197+ .withHeader(" Content-Type" , " application/json" )
198+ .withBody(headsResponse),
199+ )
200+
201+ // When
202+ val versionsOrError =
203+ fetchAvailableVersions(
204+ owner = owner,
205+ name = name,
206+ githubAuthToken = " token" ,
207+ githubEndpoint = " http://localhost:${mockServer.port} " ,
208+ )
209+
210+ // Then
211+ // This assertion shows current undesired behavior,
212+ // TODO fix in https://github.com/typesafegithub/github-workflows-kt/pull/2306
213+ versionsOrError shouldBe
214+ listOf (
215+ Version (" v1.0.0" ),
216+ Version (" v1.0.1" ),
217+ Version (" tag" ),
218+ Version (" v1" ),
219+ Version (" v2" ),
220+ Version (" branch" ),
221+ ).right()
222+ }
112223
113224 test(" error occurs when fetching branches and tags" ) {
114225 // Given
0 commit comments