From 22eeb00bbc7d50a7ceb2c79a4612d7770fe215a1 Mon Sep 17 00:00:00 2001 From: OlgaMaciaszek Date: Tue, 7 Nov 2017 11:22:46 +0100 Subject: [PATCH 1/4] Added possibility to get issues by projectId. --- src/main/java/org/gitlab/api/GitlabAPI.java | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/src/main/java/org/gitlab/api/GitlabAPI.java b/src/main/java/org/gitlab/api/GitlabAPI.java index 8e982757..5cd47353 100644 --- a/src/main/java/org/gitlab/api/GitlabAPI.java +++ b/src/main/java/org/gitlab/api/GitlabAPI.java @@ -1728,7 +1728,11 @@ public void deleteProjectHook(GitlabProject project, String hookId) throws IOExc } public List getIssues(GitlabProject project) throws IOException { - String tailUrl = GitlabProject.URL + "/" + sanitizeProjectId(project.getId()) + GitlabIssue.URL + PARAM_MAX_ITEMS_PER_PAGE; + return getIssues(project.getId()); + } + + public List getIssues(Serializable projectId) throws IOException { + String tailUrl = GitlabProject.URL + "/" + sanitizeProjectId(projectId) + GitlabIssue.URL + PARAM_MAX_ITEMS_PER_PAGE; return retrieve().getAll(tailUrl, GitlabIssue[].class); } From 4aa99cba210c308024514fa96b97ae81fbff1b93 Mon Sep 17 00:00:00 2001 From: OlgaMaciaszek Date: Wed, 8 Nov 2017 14:19:20 +0100 Subject: [PATCH 2/4] Added possibility to create subgroups. --- src/main/java/org/gitlab/api/GitlabAPI.java | 20 +++++++++++++++++++- 1 file changed, 19 insertions(+), 1 deletion(-) diff --git a/src/main/java/org/gitlab/api/GitlabAPI.java b/src/main/java/org/gitlab/api/GitlabAPI.java index 5cd47353..49780ea0 100644 --- a/src/main/java/org/gitlab/api/GitlabAPI.java +++ b/src/main/java/org/gitlab/api/GitlabAPI.java @@ -528,13 +528,31 @@ public GitlabGroup createGroup(CreateGroupRequest request, GitlabUser sudoUser) * @throws IOException on gitlab api call error */ public GitlabGroup createGroup(String name, String path, String ldapCn, GitlabAccessLevel ldapAccess, GitlabUser sudoUser) throws IOException { + return createGroup(name, path, ldapCn, ldapAccess, sudoUser, null); + } + + /** + * Creates a Group + * + * @param name The name of the group + * @param path The path for the group + * @param ldapCn LDAP Group Name to sync with, null otherwise + * @param ldapAccess Access level for LDAP group members, null otherwise + * @param sudoUser The user to create the group on behalf of + * @param parentId The id of a parent group; the new group will be its subgroup + * @return The GitLab Group + * + * @throws IOException on gitlab api call error + */ + public GitlabGroup createGroup(String name, String path, String ldapCn, GitlabAccessLevel ldapAccess, GitlabUser sudoUser, Integer parentId) throws IOException { Query query = new Query() .append("name", name) .append("path", path) .appendIf("ldap_cn", ldapCn) .appendIf("ldap_access", ldapAccess) - .appendIf(PARAM_SUDO, sudoUser != null ? sudoUser.getId() : null); + .appendIf(PARAM_SUDO, sudoUser != null ? sudoUser.getId() : null) + .appendIf("parent_id", parentId); String tailUrl = GitlabGroup.URL + query.toString(); From 93be5fbe9aaaeec371eb6d51ed4b1ca65edad4cf Mon Sep 17 00:00:00 2001 From: OlgaMaciaszek Date: Wed, 1 Aug 2018 15:05:09 +0200 Subject: [PATCH 3/4] Add support for project and group level badges. --- src/main/java/org/gitlab/api/GitlabAPI.java | 156 ++++++++++++++++++ .../org/gitlab/api/models/GitlabBadge.java | 70 ++++++++ 2 files changed, 226 insertions(+) create mode 100644 src/main/java/org/gitlab/api/models/GitlabBadge.java diff --git a/src/main/java/org/gitlab/api/GitlabAPI.java b/src/main/java/org/gitlab/api/GitlabAPI.java index 946475f3..e19e70b7 100644 --- a/src/main/java/org/gitlab/api/GitlabAPI.java +++ b/src/main/java/org/gitlab/api/GitlabAPI.java @@ -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 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); + } + + /** + * Create project badge + * + * @param projectId The id of the project for which the badge should be retrieved + * @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 createProjectBadge(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 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); + } + + /** + * Create group badge + * + * @param groupId The id of the group for which the badge should be retrieved + * @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 createGroupBadge(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. * diff --git a/src/main/java/org/gitlab/api/models/GitlabBadge.java b/src/main/java/org/gitlab/api/models/GitlabBadge.java new file mode 100644 index 00000000..7de3f1a6 --- /dev/null +++ b/src/main/java/org/gitlab/api/models/GitlabBadge.java @@ -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; + } +} From 18f0938b7202c043932c20cf6dd75c888d34ca43 Mon Sep 17 00:00:00 2001 From: OlgaMaciaszek Date: Thu, 2 Aug 2018 11:23:39 +0200 Subject: [PATCH 4/4] Adjust method naming to naming from GitLab GUI. --- src/main/java/org/gitlab/api/GitlabAPI.java | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/src/main/java/org/gitlab/api/GitlabAPI.java b/src/main/java/org/gitlab/api/GitlabAPI.java index e19e70b7..f2cd7888 100644 --- a/src/main/java/org/gitlab/api/GitlabAPI.java +++ b/src/main/java/org/gitlab/api/GitlabAPI.java @@ -2278,16 +2278,16 @@ public GitlabBadge getProjectBadge(Serializable projectId, Integer badgeId) thro } /** - * Create project badge + * Add project badge * - * @param projectId The id of the project for which the badge should be retrieved + * @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 createProjectBadge(Serializable projectId, String linkUrl, String imageUrl) throws IOException { + 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) @@ -2356,16 +2356,16 @@ public GitlabBadge getGroupBadge(Integer groupId, Integer badgeId) throws IOExce } /** - * Create group badge + * Add group badge * - * @param groupId The id of the group for which the badge should be retrieved + * @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 createGroupBadge(Integer groupId, String linkUrl, String imageUrl) throws IOException { + 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)