-
Notifications
You must be signed in to change notification settings - Fork 475
Add support for name in badges #898
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
Changes from 3 commits
baec151
c26988d
a4a0186
e04c971
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -5,6 +5,7 @@ | |
import java.util.List; | ||
import java.util.Objects; | ||
import java.util.Optional; | ||
import java.util.stream.Collectors; | ||
import java.util.stream.Stream; | ||
|
||
import javax.ws.rs.core.Form; | ||
|
@@ -1576,6 +1577,24 @@ public List<Badge> getBadges(Object groupIdOrPath) throws GitLabApiException { | |
return (response.readEntity(new GenericType<List<Badge>>() {})); | ||
} | ||
|
||
/** | ||
* Gets a list of a group’s badges, case insensitively filtered on name. | ||
* | ||
* <pre><code>GitLab Endpoint: GET /groups/:id/badges</code></pre> | ||
* | ||
* @param groupIdOrPath the group ID, path of the group, or a Group instance holding the group ID or path | ||
* @param name The name to filter on | ||
* @return All badges of the GitLab item, case insensitively filtered on name. | ||
* @throws GitLabApiException If any problem is encountered | ||
*/ | ||
public List<Badge> getBadges(Object groupIdOrPath, String name) throws GitLabApiException { | ||
List<Badge> result = getBadges(groupIdOrPath); | ||
if (name != null && name.length()>0) { | ||
return result.stream().filter(b -> b.getName().equalsIgnoreCase(name)).collect(Collectors.toList()); | ||
} | ||
return (result); | ||
} | ||
|
||
/** | ||
* Gets a badge of a group. | ||
* | ||
|
@@ -1620,11 +1639,28 @@ public Optional<Badge> getOptionalBadge(Object groupIdOrPath, Long badgeId) { | |
* @throws GitLabApiException if any exception occurs | ||
*/ | ||
public Badge addBadge(Object groupIdOrPath, String linkUrl, String imageUrl) throws GitLabApiException { | ||
GitLabApiForm formData = new GitLabApiForm() | ||
.withParam("link_url", linkUrl, true) | ||
.withParam("image_url", imageUrl, true); | ||
Response response = post(Response.Status.OK, formData, "groups", getGroupIdOrPath(groupIdOrPath), "badges"); | ||
return (response.readEntity(Badge.class)); | ||
return addBadge(groupIdOrPath, null, linkUrl, imageUrl); | ||
} | ||
|
||
/** | ||
* Add a badge to a group. | ||
* | ||
* <pre><code>GitLab Endpoint: POST /groups/:id/badges</code></pre> | ||
* | ||
* @param groupIdOrPath the group ID, path of the group, or a Group instance holding the group ID or path | ||
* @param name The name to give the badge (may be null) | ||
* @param linkUrl the URL of the badge link | ||
* @param imageUrl the URL of the image link | ||
* @return A Badge instance for the added badge | ||
* @throws GitLabApiException if any exception occurs | ||
*/ | ||
public Badge addBadge(Object groupIdOrPath, String name, String linkUrl, String imageUrl) throws GitLabApiException { | ||
GitLabApiForm formData = new GitLabApiForm() | ||
.withParam("name", name, false) | ||
.withParam("link_url", linkUrl, true) | ||
.withParam("image_url", imageUrl, true); | ||
Response response = post(Response.Status.OK, formData, "groups", getGroupIdOrPath(groupIdOrPath), "badges"); | ||
return (response.readEntity(Badge.class)); | ||
} | ||
|
||
/** | ||
|
@@ -1640,11 +1676,29 @@ public Badge addBadge(Object groupIdOrPath, String linkUrl, String imageUrl) thr | |
* @throws GitLabApiException if any exception occurs | ||
*/ | ||
public Badge editBadge(Object groupIdOrPath, Long badgeId, String linkUrl, String imageUrl) throws GitLabApiException { | ||
GitLabApiForm formData = new GitLabApiForm() | ||
.withParam("link_url", linkUrl, false) | ||
.withParam("image_url", imageUrl, false); | ||
Response response = putWithFormData(Response.Status.OK, formData, "groups", getGroupIdOrPath(groupIdOrPath), "badges", badgeId); | ||
return (response.readEntity(Badge.class)); | ||
return (editBadge(groupIdOrPath, badgeId, null, linkUrl, imageUrl)); | ||
} | ||
|
||
/** | ||
* Edit a badge of a group. | ||
* | ||
* <pre><code>GitLab Endpoint: PUT /groups/:id/badges</code></pre> | ||
* | ||
* @param groupIdOrPath the group ID, path of the group, or a Group instance holding the group ID or path | ||
* @param badgeId the ID of the badge to edit | ||
* @param name The name of the badge to edit (may be null) | ||
* @param linkUrl the URL of the badge link | ||
* @param imageUrl the URL of the image link | ||
* @return a Badge instance for the edited badge | ||
* @throws GitLabApiException if any exception occurs | ||
*/ | ||
public Badge editBadge(Object groupIdOrPath, Long badgeId, String name, String linkUrl, String imageUrl) throws GitLabApiException { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I check on the current documentation of group badges and I don't find the edit with name. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Yes, you cannot directly edit based on name and that is not what this code is doing. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Ah, I see what you mean now. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I have submitted a merge request to update the API documentation. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. @roadSurfer thanks. |
||
GitLabApiForm formData = new GitLabApiForm() | ||
.withParam("name", name, false) | ||
.withParam("link_url", linkUrl, false) | ||
.withParam("image_url", imageUrl, false); | ||
Response response = putWithFormData(Response.Status.OK, formData, "groups", getGroupIdOrPath(groupIdOrPath), "badges", badgeId); | ||
return (response.readEntity(Badge.class)); | ||
} | ||
|
||
/** | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
GitLab4j is mostly a wrapper around GitLab API. Actually it seems that there is no possibility to find badges by name. The best way to implement this is to add a filter directly on GitLab. You can create an issue here https://gitlab.com/gitlab-org/gitlab/-/issues
Then when implementing, I will be happy to add the support of this filter.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Have updated my branch to correctly use
?name=foo
as per listing project and group badges.