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
59 changes: 48 additions & 11 deletions src/main/java/org/gitlab4j/api/CommitsApi.java
Original file line number Diff line number Diff line change
@@ -1,22 +1,24 @@
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.Commit;
import org.gitlab4j.api.models.CommitAction;
import org.gitlab4j.api.models.CommitPayload;
import org.gitlab4j.api.models.CommitRef;
import org.gitlab4j.api.models.Diff;
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.
*/
Expand Down Expand Up @@ -251,6 +253,41 @@ public Optional<Commit> getOptionalCommit(int projectId, String sha) {
}
}

/**
* 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.
*
Expand Down Expand Up @@ -302,7 +339,7 @@ public List<Comment> getComments(int projectId, String sha) throws GitLabApiExce
Response response = get(Response.Status.OK, null, "projects", projectId, "repository", "commits", sha, "comments");
return (response.readEntity(new GenericType<List<Comment>>() {}));
}

/**
* Get a Pager of the comments of a commit in a project.
*
Expand Down
62 changes: 49 additions & 13 deletions src/main/java/org/gitlab4j/api/RepositoryApi.java
Original file line number Diff line number Diff line change
@@ -1,5 +1,18 @@
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.IOException;
import java.io.InputStream;
Expand All @@ -9,19 +22,6 @@
import java.nio.file.StandardCopyOption;
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.
*/
Expand Down Expand Up @@ -225,6 +225,42 @@ public Tag createTag(Integer projectId, String tagName, String ref, String messa
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
* release notes are optional. This method is the same as {@link #createTag(Integer, String, String, String, String)},
Expand Down
57 changes: 57 additions & 0 deletions src/main/java/org/gitlab4j/api/models/CommitRef.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,57 @@
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 Евгений Уткин ([email protected])
*/
@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;
}
}
33 changes: 23 additions & 10 deletions src/test/java/org/gitlab4j/api/TestCommitsApi.java
Original file line number Diff line number Diff line change
@@ -1,18 +1,9 @@
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.models.Comment;
import org.gitlab4j.api.models.Commit;
import org.gitlab4j.api.models.CommitRef;
import org.gitlab4j.api.models.Diff;
import org.gitlab4j.api.models.Project;
import org.junit.Before;
Expand All @@ -21,6 +12,15 @@
import org.junit.Test;
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
*
Expand Down Expand Up @@ -156,6 +156,19 @@ public void testCommitsSince() throws GitLabApiException {
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
public void testCommitsSinceWithPath() throws GitLabApiException {

Expand Down