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
156 changes: 156 additions & 0 deletions src/main/java/org/gitlab/api/GitlabAPI.java
Original file line number Diff line number Diff line change
Expand Up @@ -2249,6 +2249,162 @@ public void deleteNote(GitlabIssue issue, GitlabNote noteToDelete) throws IOExce
deleteNote(String.valueOf(issue.getProjectId()), issue.getId(), noteToDelete);
}

/**
* Get project badges
*
* @param projectId The id of the project for which the badges should be retrieved
* @return The list of badges
*
* @throws IOException on GitLab API call error
*/
public List<GitlabBadge> getProjectBadges(Serializable projectId) throws IOException {
String tailUrl = GitlabProject.URL + "/" + sanitizeProjectId(projectId) + GitlabBadge.URL;
return Arrays.asList(retrieve().to(tailUrl, GitlabBadge[].class));
}

/**
* Get project badge
*
* @param projectId The id of the project for which the badge should be retrieved
* @param badgeId The id of the badge that should be retrieved
* @return The badge with a given id
*
* @throws IOException on GitLab API call error
*/
public GitlabBadge getProjectBadge(Serializable projectId, Integer badgeId) throws IOException {
String tailUrl = GitlabProject.URL + "/" + sanitizeProjectId(projectId) + GitlabBadge.URL
+ "/" + badgeId;
return retrieve().to(tailUrl, GitlabBadge.class);
}

/**
* Add project badge
*
* @param projectId The id of the project for which the badge should be added
* @param linkUrl The URL that the badge should link to
* @param imageUrl The URL to the badge image
* @return The created badge
*
* @throws IOException on GitLab API call error
*/
public GitlabBadge addProjectBadge(Serializable projectId, String linkUrl, String imageUrl) throws IOException {
String tailUrl = GitlabProject.URL + "/" + sanitizeProjectId(projectId) + GitlabBadge.URL;
return dispatch().with("link_url", linkUrl)
.with("image_url", imageUrl)
.to(tailUrl, GitlabBadge.class);
}

/**
* Edit project badge
*
* @param projectId The id of the project for which the badge should be edited
* @param badgeId The id of the badge that should be edited
* @param linkUrl The URL that the badge should link to
* @param imageUrl The URL to the badge image
* @return The updated badge
*
* @throws IOException on GitLab API call error
*/
public GitlabBadge editProjectBadge(Serializable projectId, Integer badgeId, String linkUrl, String imageUrl) throws IOException {
String tailUrl = GitlabProject.URL + "/" + sanitizeProjectId(projectId) + GitlabBadge.URL
+ "/" + badgeId;
GitlabHTTPRequestor requestor = retrieve().method(PUT);
requestor.with("link_url", linkUrl)
.with("image_url", imageUrl);
return requestor.to(tailUrl, GitlabBadge.class);
}

/**
* Delete project badge
*
* @param projectId The id of the project for which the badge should be deleted
* @param badgeId The id of the badge that should be deleted
* @throws IOException on GitLab API call error
*/
public void deleteProjectBadge(Serializable projectId, Integer badgeId) throws IOException {
String tailUrl = GitlabProject.URL + "/" + sanitizeProjectId(projectId) + GitlabBadge.URL
+ "/" + badgeId;
retrieve().method(DELETE).to(tailUrl, Void.class);
}

/**
* Get project badges
*
* @param groupId The id of the group for which the badges should be retrieved
* @return The list of badges
*
* @throws IOException on GitLab API call error
*/
public List<GitlabBadge> getGroupBadges(Integer groupId) throws IOException {
String tailUrl = GitlabGroup.URL + "/" + groupId + GitlabBadge.URL;
return Arrays.asList(retrieve().to(tailUrl, GitlabBadge[].class));
}

/**
* Get group badge
*
* @param groupId The id of the group for which the badge should be retrieved
* @param badgeId The id of the badge that should be retrieved
* @return The badge with a given id
*
* @throws IOException on GitLab API call error
*/
public GitlabBadge getGroupBadge(Integer groupId, Integer badgeId) throws IOException {
String tailUrl = GitlabGroup.URL + "/" + groupId + GitlabBadge.URL
+ "/" + badgeId;
return retrieve().to(tailUrl, GitlabBadge.class);
}

/**
* Add group badge
*
* @param groupId The id of the group for which the badge should be added
* @param linkUrl The URL that the badge should link to
* @param imageUrl The URL to the badge image
* @return The created badge
*
* @throws IOException on GitLab API call error
*/
public GitlabBadge addGroupBadge(Integer groupId, String linkUrl, String imageUrl) throws IOException {
String tailUrl = GitlabGroup.URL + "/" + groupId + GitlabBadge.URL;
return dispatch().with("link_url", linkUrl)
.with("image_url", imageUrl)
.to(tailUrl, GitlabBadge.class);
}

/**
* Edit group badge
*
* @param groupId The id of the group for which the badge should be edited
* @param badgeId The id of the badge that should be edited
* @param linkUrl The URL that the badge should link to
* @param imageUrl The URL to the badge image
* @return The updated badge
*
* @throws IOException on GitLab API call error
*/
public GitlabBadge editGroupBadge(Integer groupId, Integer badgeId, String linkUrl, String imageUrl) throws IOException {
String tailUrl = GitlabGroup.URL + "/" + groupId + GitlabBadge.URL
+ "/" + badgeId;
GitlabHTTPRequestor requestor = retrieve().method(PUT);
requestor.with("link_url", linkUrl)
.with("image_url", imageUrl);
return requestor.to(tailUrl, GitlabBadge.class);
}

/**
* Delete group badge
*
* @param groupId The id of the group for which the badge should be deleted
* @param badgeId The id of the badge that should be deleted
* @throws IOException on GitLab API call error
*/
public void deleteGroupBadge(Integer groupId, Integer badgeId) throws IOException {
String tailUrl = GitlabGroup.URL + "/" + groupId + GitlabBadge.URL
+ "/" + badgeId;
retrieve().method(DELETE).to(tailUrl, Void.class);
}

/**
* Gets labels associated with a project.
*
Expand Down
70 changes: 70 additions & 0 deletions src/main/java/org/gitlab/api/models/GitlabBadge.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,70 @@
package org.gitlab.api.models;

import com.fasterxml.jackson.annotation.JsonProperty;

/**
* @author Olga Maciaszek-Sharma
*/
public class GitlabBadge {

public static final String URL = "/badges";

private Integer id;
@JsonProperty("link_url")
private String linkUrl;
@JsonProperty("image_url")
private String imageUrl;
@JsonProperty("rendered_link_url")
private String renderedLinkUrl;
@JsonProperty("rendered_image_url")
private String renderedImageUrl;
private String kind;

public Integer getId() {
return id;
}

public void setId(Integer id) {
this.id = id;
}

public String getLinkUrl() {
return linkUrl;
}

public void setLinkUrl(String linkUrl) {
this.linkUrl = linkUrl;
}

public String getImageUrl() {
return imageUrl;
}

public void setImageUrl(String imageUrl) {
this.imageUrl = imageUrl;
}

public String getRenderedLinkUrl() {
return renderedLinkUrl;
}

public void setRenderedLinkUrl(String renderedLinkUrl) {
this.renderedLinkUrl = renderedLinkUrl;
}

public String getRenderedImageUrl() {
return renderedImageUrl;
}

public void setRenderedImageUrl(String renderedImageUrl) {
this.renderedImageUrl = renderedImageUrl;
}

public String getKind() {
return kind;
}

public void setKind(String kind) {
this.kind = kind;
}
}