Commit e2ee6fef authored by eutkin's avatar eutkin Committed by Greg Messner
Browse files

Added createRelease(), updateRelease() (#211)

parent 75698879
package org.gitlab4j.api; package org.gitlab4j.api;
import java.io.UnsupportedEncodingException;
import java.net.URLEncoder;
import java.util.Date;
import java.util.List;
import java.util.Optional;
import javax.ws.rs.core.Form;
import javax.ws.rs.core.GenericType;
import javax.ws.rs.core.Response;
import org.gitlab4j.api.models.Comment; import org.gitlab4j.api.models.Comment;
import org.gitlab4j.api.models.Commit; import org.gitlab4j.api.models.Commit;
import org.gitlab4j.api.models.CommitAction; import org.gitlab4j.api.models.CommitAction;
import org.gitlab4j.api.models.CommitPayload; import org.gitlab4j.api.models.CommitPayload;
import org.gitlab4j.api.models.CommitRef;
import org.gitlab4j.api.models.Diff; import org.gitlab4j.api.models.Diff;
import org.gitlab4j.api.utils.ISO8601; import org.gitlab4j.api.utils.ISO8601;
import javax.ws.rs.core.Form;
import javax.ws.rs.core.GenericType;
import javax.ws.rs.core.Response;
import java.io.UnsupportedEncodingException;
import java.net.URLEncoder;
import java.util.Date;
import java.util.List;
import java.util.Optional;
import static org.gitlab4j.api.models.CommitRef.RefType.all;
/** /**
* This class implements the client side API for the GitLab commits calls. * This class implements the client side API for the GitLab commits calls.
*/ */
...@@ -251,6 +253,41 @@ public class CommitsApi extends AbstractApi { ...@@ -251,6 +253,41 @@ public class CommitsApi extends AbstractApi {
} }
} }
/**
* Get a specific commit identified by the commit hash or name of a branch or tag as an Optional instance
*
* GET /projects/:id/repository/commits/:sha/refs
*
* @param projectId the project ID that the commit belongs to
* @param sha a commit hash or name of a branch or tag
* @return Get all references (from branches or tags) a commit is pushed to
* @throws GitLabApiException GitLabApiException if any exception occurs during execution
* @since Gitlab 10.6
*/
public List<CommitRef> getCommitRefs(int projectId, String sha) throws GitLabApiException {
return getCommitRefs(projectId, sha, all);
}
/**
* Get a specific commit identified by the commit hash or name of a branch or tag as an Optional instance
*
* GET /projects/:id/repository/commits/:sha/refs?type=:refType
*
* @param projectId the project ID that the commit belongs to
* @param sha a commit hash or name of a branch or tag
* @param refType the scope of commits. Possible values branch, tag, all. Default is all.
* @return Get all references (from branches or tags) a commit is pushed to
* @throws GitLabApiException GitLabApiException if any exception occurs during execution
* @since Gitlab 10.6
*/
public List<CommitRef> getCommitRefs(int projectId, String sha, CommitRef.RefType refType) throws GitLabApiException {
Form form = new GitLabApiForm()
.withParam("type", refType)
.withParam(PER_PAGE_PARAM, getDefaultPerPage());
Response response = get(Response.Status.OK, form.asMap(), "projects", projectId, "repository", "commits", sha, "refs");
return (response.readEntity(new GenericType<List<CommitRef>>(){}));
}
/** /**
* Get the list of diffs of a commit in a project. * Get the list of diffs of a commit in a project.
* *
...@@ -302,7 +339,7 @@ public class CommitsApi extends AbstractApi { ...@@ -302,7 +339,7 @@ public class CommitsApi extends AbstractApi {
Response response = get(Response.Status.OK, null, "projects", projectId, "repository", "commits", sha, "comments"); Response response = get(Response.Status.OK, null, "projects", projectId, "repository", "commits", sha, "comments");
return (response.readEntity(new GenericType<List<Comment>>() {})); return (response.readEntity(new GenericType<List<Comment>>() {}));
} }
/** /**
* Get a Pager of the comments of a commit in a project. * Get a Pager of the comments of a commit in a project.
* *
......
package org.gitlab4j.api; package org.gitlab4j.api;
import org.gitlab4j.api.GitLabApi.ApiVersion;
import org.gitlab4j.api.models.Branch;
import org.gitlab4j.api.models.CompareResults;
import org.gitlab4j.api.models.Contributor;
import org.gitlab4j.api.models.Release;
import org.gitlab4j.api.models.Tag;
import org.gitlab4j.api.models.TreeItem;
import org.gitlab4j.api.utils.FileUtils;
import javax.ws.rs.core.Form;
import javax.ws.rs.core.GenericType;
import javax.ws.rs.core.MediaType;
import javax.ws.rs.core.Response;
import java.io.File; import java.io.File;
import java.io.IOException; import java.io.IOException;
import java.io.InputStream; import java.io.InputStream;
...@@ -9,19 +22,6 @@ import java.nio.file.Files; ...@@ -9,19 +22,6 @@ import java.nio.file.Files;
import java.nio.file.StandardCopyOption; import java.nio.file.StandardCopyOption;
import java.util.List; import java.util.List;
import javax.ws.rs.core.Form;
import javax.ws.rs.core.GenericType;
import javax.ws.rs.core.MediaType;
import javax.ws.rs.core.Response;
import org.gitlab4j.api.GitLabApi.ApiVersion;
import org.gitlab4j.api.models.Branch;
import org.gitlab4j.api.models.CompareResults;
import org.gitlab4j.api.models.Contributor;
import org.gitlab4j.api.models.Tag;
import org.gitlab4j.api.models.TreeItem;
import org.gitlab4j.api.utils.FileUtils;
/** /**
* This class provides an entry point to all the GitLab API repository calls. * This class provides an entry point to all the GitLab API repository calls.
*/ */
...@@ -225,6 +225,42 @@ public class RepositoryApi extends AbstractApi { ...@@ -225,6 +225,42 @@ public class RepositoryApi extends AbstractApi {
return (response.readEntity(Tag.class)); return (response.readEntity(Tag.class));
} }
/**
* Add release notes to the existing git tag.
*
* POST /projects/:id/repository/tags/:tagName/release
*
* @param projectId the ID of the project
* @param tagName the name of a tag
* @param releaseNotes release notes with markdown support
* @return a Tag instance containing info on the newly created tag
* @throws GitLabApiException if any exception occurs
*/
public Release createRelease(Integer projectId, String tagName, String releaseNotes) throws GitLabApiException {
Form formData = new GitLabApiForm()
.withParam("description", releaseNotes, false);
Response response = post(Response.Status.CREATED, formData.asMap(), "projects", projectId, "repository", "tags", tagName, "release");
return (response.readEntity(Release.class));
}
/**
* Updates the release notes of a given release.
*
* PUT /projects/:id/repository/tags/:tagName/release
*
* @param projectId the ID of the project
* @param tagName the name of a tag
* @param releaseNotes release notes with markdown support
* @return a Tag instance containing info on the newly created tag
* @throws GitLabApiException if any exception occurs
*/
public Release updateRelease(Integer projectId, String tagName, String releaseNotes) throws GitLabApiException {
Form formData = new GitLabApiForm()
.withParam("description", releaseNotes, false);
Response response = put(Response.Status.CREATED, formData.asMap(), "projects", projectId, "repository", "tags", tagName, "release");
return (response.readEntity(Release.class));
}
/** /**
* Creates a tag on a particular ref of a given project. A message and a File instance containing the * Creates a tag on a particular ref of a given project. A message and a File instance containing the
* release notes are optional. This method is the same as {@link #createTag(Integer, String, String, String, String)}, * release notes are optional. This method is the same as {@link #createTag(Integer, String, String, String, String)},
......
package org.gitlab4j.api.models;
import com.fasterxml.jackson.annotation.JsonCreator;
import com.fasterxml.jackson.annotation.JsonValue;
import org.gitlab4j.api.utils.JacksonJsonEnumHelper;
import javax.xml.bind.annotation.XmlAccessType;
import javax.xml.bind.annotation.XmlAccessorType;
import javax.xml.bind.annotation.XmlRootElement;
/**
* @author Евгений Уткин (evgeny.utkin@mediascope.net)
*/
@XmlRootElement
@XmlAccessorType(XmlAccessType.FIELD)
public class CommitRef {
private RefType type;
private String name;
public enum RefType {
BRANCH, TAG, ALL;
private static JacksonJsonEnumHelper<RefType> enumHelper = new JacksonJsonEnumHelper<>(RefType.class);
@JsonCreator
public static RefType forValue(String value) {
return enumHelper.forValue(value);
}
@JsonValue
public String toValue() {
return (enumHelper.toString(this));
}
@Override
public String toString() {
return (enumHelper.toString(this));
}
}
public RefType getType() {
return type;
}
public void setType(RefType type) {
this.type = type;
}
public String getName() {
return name;
}
public void setName(String name) {
this.name = name;
}
}
package org.gitlab4j.api; package org.gitlab4j.api;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertNotNull;
import static org.junit.Assert.assertTrue;
import static org.junit.Assume.assumeTrue;
import java.util.Date;
import java.util.List;
import javax.ws.rs.core.Response;
import org.gitlab4j.api.GitLabApi.ApiVersion; import org.gitlab4j.api.GitLabApi.ApiVersion;
import org.gitlab4j.api.models.Comment; import org.gitlab4j.api.models.Comment;
import org.gitlab4j.api.models.Commit; import org.gitlab4j.api.models.Commit;
import org.gitlab4j.api.models.CommitRef;
import org.gitlab4j.api.models.Diff; import org.gitlab4j.api.models.Diff;
import org.gitlab4j.api.models.Project; import org.gitlab4j.api.models.Project;
import org.junit.Before; import org.junit.Before;
...@@ -21,6 +12,15 @@ import org.junit.FixMethodOrder; ...@@ -21,6 +12,15 @@ import org.junit.FixMethodOrder;
import org.junit.Test; import org.junit.Test;
import org.junit.runners.MethodSorters; import org.junit.runners.MethodSorters;
import javax.ws.rs.core.Response;
import java.util.Date;
import java.util.List;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertNotNull;
import static org.junit.Assert.assertTrue;
import static org.junit.Assume.assumeTrue;
/** /**
* In order for these tests to run you must set the following properties in test-gitlab4j.properties * In order for these tests to run you must set the following properties in test-gitlab4j.properties
* *
...@@ -156,6 +156,19 @@ public class TestCommitsApi { ...@@ -156,6 +156,19 @@ public class TestCommitsApi {
assertTrue(pager.getTotalItems() > 0); assertTrue(pager.getTotalItems() > 0);
} }
@Test
public void testCommitRefs() throws GitLabApiException {
assertNotNull(testProject);
List<Commit> commits = gitLabApi.getCommitsApi().getCommits(testProject.getId());
assertNotNull(commits);
assertTrue(commits.size() > 0);
List<CommitRef> commitRefs = gitLabApi.getCommitsApi().getCommitRefs(testProject.getId(), commits.get(0).getId());
assertNotNull(commits);
assertTrue(commits.size() > 0);
}
@Test @Test
public void testCommitsSinceWithPath() throws GitLabApiException { public void testCommitsSinceWithPath() throws GitLabApiException {
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment