From f12ed97cf61c7c5c1745396e38098891a5f60de4 Mon Sep 17 00:00:00 2001 From: I857847 Date: Fri, 17 Sep 2021 11:01:45 -0600 Subject: [PATCH] Fixes bug #76 Correct implementation of createAnnotatedTag(). 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. --- .../github/v3/clients/GitDataClient.java | 7 +++-- .../github/v3/clients/GitDataClientTest.java | 28 ++++++++++--------- 2 files changed, 19 insertions(+), 16 deletions(-) diff --git a/src/main/java/com/spotify/github/v3/clients/GitDataClient.java b/src/main/java/com/spotify/github/v3/clients/GitDataClient.java index 40d33b6b..65785231 100644 --- a/src/main/java/com/spotify/github/v3/clients/GitDataClient.java +++ b/src/main/java/com/spotify/github/v3/clients/GitDataClient.java @@ -208,8 +208,9 @@ public CompletableFuture createAnnotatedTag( "name", taggerName, "email", taggerEmail, "date", Instant.now().toString())); - return createTagReference(tag, sha) - .thenCompose( - reference -> github.post(tagPath, github.json().toJsonUnchecked(body), Tag.class)); + return github.post(tagPath, github.json().toJsonUnchecked(body), Tag.class) + .thenCompose(tagCreated -> + createTagReference(tag, tagCreated.sha()) + .thenApply(reference -> tagCreated)); } } diff --git a/src/test/java/com/spotify/github/v3/clients/GitDataClientTest.java b/src/test/java/com/spotify/github/v3/clients/GitDataClientTest.java index 1afef55b..64e5afda 100644 --- a/src/test/java/com/spotify/github/v3/clients/GitDataClientTest.java +++ b/src/test/java/com/spotify/github/v3/clients/GitDataClientTest.java @@ -173,19 +173,6 @@ public void createTagReference() throws Exception { @Test public void createAnnotateTag() throws Exception { - final CompletableFuture reference = - completedFuture(json.fromJson(getFixture("tag.json"), Reference.class)); - when(github.post( - "/repos/someowner/somerepo/git/refs", - github - .json() - .toJsonUnchecked( - of( - "ref", "refs/tags/0.0.1", - "sha", "5926dd300de5fee31d445c57be223f00e128a634")), - Reference.class)) - .thenReturn(reference); - final String now = Instant.now().toString(); final ImmutableMap body = of( @@ -202,6 +189,21 @@ public void createAnnotateTag() throws Exception { completedFuture(json.fromJson(getFixture("release-tag.json"), Tag.class)); when(github.post(eq("/repos/someowner/somerepo/git/tags"), any(), eq(Tag.class))) .thenReturn(fixture); + + // Ref to the annotate tag should reference the SHA of the tag, not the SHA of the commit. + final CompletableFuture reference = + completedFuture(json.fromJson(getFixture("tag.json"), Reference.class)); + when(github.post( + "/repos/someowner/somerepo/git/refs", + github + .json() + .toJsonUnchecked( + of( + "ref", "refs/tags/0.0.1", + "sha", "827210625b551200e7d3dc608935b1454523eaa8")), + Reference.class)) + .thenReturn(reference); + Tag tag = gitDataClient .createAnnotatedTag(