Skip to content

Commit

Permalink
Fixes bug #76 Correct implementation of createAnnotatedTag(). (#77)
Browse files Browse the repository at this point in the history
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>
  • Loading branch information
solarhess committed Jan 2, 2024
1 parent 4a18372 commit 1602258
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 16 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -215,9 +215,10 @@ public CompletableFuture<Tag> 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));
}

/**
Expand Down
28 changes: 15 additions & 13 deletions src/test/java/com/spotify/github/v3/clients/GitDataClientTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -182,19 +182,6 @@ public void createTagReference() throws Exception {

@Test
public void createAnnotateTag() throws Exception {
final CompletableFuture<Reference> 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<String, Object> body =
of(
Expand All @@ -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> 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(
Expand Down

0 comments on commit 1602258

Please sign in to comment.