Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 17 additions & 0 deletions src/main/java/com/spotify/github/v3/clients/GitDataClient.java
Original file line number Diff line number Diff line change
Expand Up @@ -188,6 +188,23 @@ public CompletableFuture<Reference> createTagReference(final String tag, final S
return createReference(format("refs/tags/%s", tag), sha);
}

/**
* Update a git reference.
*
* @param ref reference name
* @param sha The SHA1 value to set the reference to
* @param force Indicates whether to force the update or to make sure the update is a fast-forward update. Setting
* this to false will make sure you're not overwriting work.
*/
public CompletableFuture<Reference> updateReference(final String ref, final String sha, final boolean force) {
final String path = format(REFERENCE_URI, owner, repo, ref);
final ImmutableMap<String, String> body =
of(
"sha", sha,
"force", Boolean.toString(force));
return github.patch(path, github.json().toJsonUnchecked(body), Reference.class);
}

/**
* Create an annotated tag. First it would create a tag reference and then create annotated tag
*
Expand Down
19 changes: 19 additions & 0 deletions src/test/java/com/spotify/github/v3/clients/GitDataClientTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -180,6 +180,25 @@ public void createTagReference() throws Exception {
assertThat(reference.object().sha(), is("5926dd300de5fee31d445c57be223f00e128a634"));
}

@Test
public void updateReference() throws Exception {
final CompletableFuture<Reference> fixture =
completedFuture(json.fromJson(getFixture("branch.json"), Reference.class));
final ImmutableMap<String, String> body =
of(
"sha", "aa218f56b14c9653891f9e74264a383fa43fefbd",
"force", "false");
when(github.patch(
"/repos/someowner/somerepo/git/refs/featureA",
github.json().toJsonUnchecked(body),
Reference.class))
.thenReturn(fixture);
final Reference reference =
gitDataClient.updateReference("featureA", "aa218f56b14c9653891f9e74264a383fa43fefbd", false).get();
assertThat(reference.ref(), is("refs/heads/featureA"));
assertThat(reference.object().sha(), is("aa218f56b14c9653891f9e74264a383fa43fefbd"));
}

@Test
public void createAnnotateTag() throws Exception {
final String now = Instant.now().toString();
Expand Down