From 1602258bf8c349e7130bdf47d095440d63d380f4 Mon Sep 17 00:00:00 2001 From: solarhess Date: Tue, 2 Jan 2024 04:10:41 -0700 Subject: [PATCH] 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 --- .../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 760a474c..4953f47b 100644 --- a/src/main/java/com/spotify/github/v3/clients/GitDataClient.java +++ b/src/main/java/com/spotify/github/v3/clients/GitDataClient.java @@ -215,9 +215,10 @@ 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 cc0bdd55..4f87af26 100644 --- a/src/test/java/com/spotify/github/v3/clients/GitDataClientTest.java +++ b/src/test/java/com/spotify/github/v3/clients/GitDataClientTest.java @@ -182,19 +182,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( @@ -211,6 +198,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(