Skip to content

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

Merged
merged 4 commits into from
Feb 5, 2023
Merged

Conversation

roadSurfer
Copy link
Contributor

For a recent project I wanted to be able to set badge names and find them again based on that name, as this was simply more convenient than UUID.

To facilitate this, I have added a few methods to ProjectAPI and GroupAPI and ensured the interface remains backwards compatible.

Copy link
Collaborator

@jabby jabby left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for your contribution.

* @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 {
Copy link
Collaborator

Choose a reason for hiding this comment

The 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.
I did not try against latest versions of GitLab. Did you tried?

Copy link
Contributor Author

@roadSurfer roadSurfer Jan 19, 2023

Choose a reason for hiding this comment

The 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.
It is still using badgeId to find the badge, and then setting name and other values to that requested.
The name only really matters on creation.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ah, I see what you mean now.
I will go and check.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Testing in Gitlab shows that name does form part of the group badge put request, but this is not reflected in their documentation.
I will also log a bug with them about that, must be just an oversight as it is documented for projects.

edit_group_badge

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I have submitted a merge request to update the API documentation.

Copy link
Contributor Author

@roadSurfer roadSurfer Jan 30, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

109473 has now been merged and you can see the updated name information in the Group and Project API docs.

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@roadSurfer thanks.

* @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 {
Copy link
Collaborator

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.

Copy link
Contributor Author

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.

@roadSurfer
Copy link
Contributor Author

roadSurfer commented Jan 30, 2023

Whoops! Accidentally hit "Resolve conversation". Sorry.

Information on adding/editing badges with names can now be found in the Group and Project API docs after 109473 was merged.

Also modified my code to use the documented ?name= query param when appropriate.

I think that's all the required changes.

@roadSurfer roadSurfer requested a review from jabby February 3, 2023 16:47
@jabby jabby changed the title Adding support for working with badges by name where possible Add support for name in badges Feb 5, 2023
@jabby jabby merged commit 2be235b into gitlab4j:master Feb 5, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants