Skip to content

Commit 1602258

Browse files
authored
Fixes bug #76 Correct implementation of createAnnotatedTag(). (#77)
This puts the calls to the github api in the correct order and sets the commitsha on tag and reference so that an annotated tag is created in the git repository. Co-authored-by: I857847 <I857847>
1 parent 4a18372 commit 1602258

File tree

2 files changed

+19
-16
lines changed

2 files changed

+19
-16
lines changed

src/main/java/com/spotify/github/v3/clients/GitDataClient.java

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -215,9 +215,10 @@ public CompletableFuture<Tag> createAnnotatedTag(
215215
"name", taggerName,
216216
"email", taggerEmail,
217217
"date", Instant.now().toString()));
218-
return createTagReference(tag, sha)
219-
.thenCompose(
220-
reference -> github.post(tagPath, github.json().toJsonUnchecked(body), Tag.class));
218+
return github.post(tagPath, github.json().toJsonUnchecked(body), Tag.class)
219+
.thenCompose(tagCreated ->
220+
createTagReference(tag, tagCreated.sha())
221+
.thenApply(reference -> tagCreated));
221222
}
222223

223224
/**

src/test/java/com/spotify/github/v3/clients/GitDataClientTest.java

Lines changed: 15 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -182,19 +182,6 @@ public void createTagReference() throws Exception {
182182

183183
@Test
184184
public void createAnnotateTag() throws Exception {
185-
final CompletableFuture<Reference> reference =
186-
completedFuture(json.fromJson(getFixture("tag.json"), Reference.class));
187-
when(github.post(
188-
"/repos/someowner/somerepo/git/refs",
189-
github
190-
.json()
191-
.toJsonUnchecked(
192-
of(
193-
"ref", "refs/tags/0.0.1",
194-
"sha", "5926dd300de5fee31d445c57be223f00e128a634")),
195-
Reference.class))
196-
.thenReturn(reference);
197-
198185
final String now = Instant.now().toString();
199186
final ImmutableMap<String, Object> body =
200187
of(
@@ -211,6 +198,21 @@ public void createAnnotateTag() throws Exception {
211198
completedFuture(json.fromJson(getFixture("release-tag.json"), Tag.class));
212199
when(github.post(eq("/repos/someowner/somerepo/git/tags"), any(), eq(Tag.class)))
213200
.thenReturn(fixture);
201+
202+
// Ref to the annotate tag should reference the SHA of the tag, not the SHA of the commit.
203+
final CompletableFuture<Reference> reference =
204+
completedFuture(json.fromJson(getFixture("tag.json"), Reference.class));
205+
when(github.post(
206+
"/repos/someowner/somerepo/git/refs",
207+
github
208+
.json()
209+
.toJsonUnchecked(
210+
of(
211+
"ref", "refs/tags/0.0.1",
212+
"sha", "827210625b551200e7d3dc608935b1454523eaa8")),
213+
Reference.class))
214+
.thenReturn(reference);
215+
214216
Tag tag =
215217
gitDataClient
216218
.createAnnotatedTag(

0 commit comments

Comments
 (0)