Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

create a Release & Branch #84

Merged
merged 1 commit into from
May 10, 2014
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
22 changes: 22 additions & 0 deletions src/main/java/org/kohsuke/github/GHRefBuilder.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
package org.kohsuke.github;


import java.io.IOException;

public class GHRefBuilder {

private final GHRepository repo;
private final Requester builder;

public GHRefBuilder(GHRepository ghRepository, String ref, String sha) {
this.repo = ghRepository;
this.builder = new Requester(repo.root);
builder.with("ref", "refs/heads/" +ref);
builder.with("sha", sha);
}

public void create() throws IOException {
builder.method("POST").to(repo.getApiTailUrl("git/refs"));
}

}
20 changes: 20 additions & 0 deletions src/main/java/org/kohsuke/github/GHRepository.java
Original file line number Diff line number Diff line change
Expand Up @@ -183,6 +183,11 @@ public List<GHRelease> getReleases() throws IOException {
GHRelease[].class), this));
}

public List<GHTag> getTags() throws IOException {
return Arrays.asList(GHTag.wrap(root.retrieve().to("/repos/" + owner.login + "/" + name + "/tags",
GHTag[].class), this));
}

protected String getOwnerName() {
return owner.login;
}
Expand Down Expand Up @@ -498,6 +503,21 @@ protected void wrapUp(GHCommit[] page) {
};
}

private String sha;
public PagedIterable<GHCommit> listCommitsSinceSha(String pSha) {
sha=pSha;
return new PagedIterable<GHCommit>() {
public PagedIterator<GHCommit> iterator() {
return new PagedIterator<GHCommit>(root.retrieve().asIterator(String.format("/repos/%s/%s/commits?sha=%s", owner.login, name, sha), GHCommit[].class)) {
protected void wrapUp(GHCommit[] page) {
for (GHCommit c : page)
c.wrapUp(GHRepository.this);
}
};
}
};
}

/**
* Lists up all the commit comments in this repository.
*/
Expand Down
56 changes: 56 additions & 0 deletions src/main/java/org/kohsuke/github/GHTag.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
package org.kohsuke.github;


public class GHTag {
private GHRepository owner;
private GitHub root;

private String name;
private GHCommit commit;

GHTag wrap(GHRepository owner) {
this.owner = owner;
this.root = owner.root;
return this;
}

static GHTag[] wrap(GHTag[] tags, GHRepository owner) {
for (GHTag tag : tags) {
tag.wrap(owner);
}
return tags;
}


public GHRepository getOwner() {
return owner;
}

public void setOwner(GHRepository owner) {
this.owner = owner;
}

public GitHub getRoot() {
return root;
}

public void setRoot(GitHub root) {
this.root = root;
}

public String getName() {
return name;
}

public void setName(String name) {
this.name = name;
}

public GHCommit getCommit() {
return commit;
}

public void setCommit(GHCommit commit) {
this.commit = commit;
}
}
37 changes: 37 additions & 0 deletions src/test/java/org/kohsuke/AppTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -6,12 +6,15 @@
import java.util.List;
import java.util.Map;
import java.util.Set;
import java.util.UUID;

import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertFalse;
import static org.junit.Assert.assertNotNull;
import static org.junit.Assert.assertSame;
import static org.junit.Assert.assertTrue;
import static org.junit.Assert.fail;

import org.junit.Assume;
import org.junit.Before;
import org.junit.Test;
Expand All @@ -34,7 +37,9 @@
import org.kohsuke.github.GHOrganization;
import org.kohsuke.github.GHOrganization.Permission;
import org.kohsuke.github.GHPullRequest;
import org.kohsuke.github.GHRefBuilder;
import org.kohsuke.github.GHRepository;
import org.kohsuke.github.GHTag;
import org.kohsuke.github.GHTeam;
import org.kohsuke.github.GHUser;
import org.kohsuke.github.GitHub;
Expand Down Expand Up @@ -489,6 +494,38 @@ public void testCheckMembership() throws Exception {
assertFalse(j.hasPublicMember(b));
}

@Test
public void testCreateRelease() throws Exception {

String tagName = UUID.randomUUID().toString();
String releaseName = "release-" + tagName;
String repo = "fanfansama/github-api-test-1";


gitHub.getRepository(repo)
.createRelease(tagName)
.name(releaseName)
.prerelease(false)
.create();

for(GHTag tag : gitHub.getRepository(repo).getTags()){
if(tagName.equals(tag.getName())){
String ash = tag.getCommit().getSHA1();
new GHRefBuilder(gitHub.getRepository(repo), releaseName, ash ).create(); // create a release branch

for (Map.Entry<String, GHBranch> entry : gitHub.getRepository(repo).getBranches().entrySet())
{
System.out.println(entry.getKey() + "/" + entry.getValue());
if(releaseName.equals(entry.getValue().getName())){
return;
}
}
fail("banch not found");
}
}
fail("release creation failed ! tag not found");
}

private void kohsuke() {
Assume.assumeTrue(getUser().getLogin().equals("kohsuke"));
}
Expand Down