5
5
import java .util .List ;
6
6
import java .util .Objects ;
7
7
import java .util .Optional ;
8
+ import java .util .stream .Collectors ;
8
9
import java .util .stream .Stream ;
9
10
10
11
import javax .ws .rs .core .Form ;
@@ -1572,8 +1573,23 @@ public void denyAccessRequest(Object groupIdOrPath, Long userId) throws GitLabAp
1572
1573
* @throws GitLabApiException if any exception occurs
1573
1574
*/
1574
1575
public List <Badge > getBadges (Object groupIdOrPath ) throws GitLabApiException {
1575
- Response response = get (Response .Status .OK , null , "groups" , getGroupIdOrPath (groupIdOrPath ), "badges" );
1576
- return (response .readEntity (new GenericType <List <Badge >>() {}));
1576
+ return getBadges (groupIdOrPath , null );
1577
+ }
1578
+
1579
+ /**
1580
+ * Gets a list of a group’s badges, case-sensitively filtered on bagdeName if non-null.
1581
+ *
1582
+ * <pre><code>GitLab Endpoint: GET /groups/:id/badges?name=:name</code></pre>
1583
+ *
1584
+ * @param groupIdOrPath the group ID, path of the group, or a Group instance holding the group ID or path
1585
+ * @param badgeName The name to filter on (case-sensitive), ignored if null.
1586
+ * @return All badges of the GitLab item, case insensitively filtered on name.
1587
+ * @throws GitLabApiException If any problem is encountered
1588
+ */
1589
+ public List <Badge > getBadges (Object groupIdOrPath , String badgeName ) throws GitLabApiException {
1590
+ Form queryParam = new GitLabApiForm ().withParam ("name" , badgeName );
1591
+ Response response = get (Response .Status .OK , queryParam .asMap (), "groups" , getGroupIdOrPath (groupIdOrPath ), "badges" );
1592
+ return (response .readEntity (new GenericType <List <Badge >>() {}));
1577
1593
}
1578
1594
1579
1595
/**
@@ -1620,11 +1636,28 @@ public Optional<Badge> getOptionalBadge(Object groupIdOrPath, Long badgeId) {
1620
1636
* @throws GitLabApiException if any exception occurs
1621
1637
*/
1622
1638
public Badge addBadge (Object groupIdOrPath , String linkUrl , String imageUrl ) throws GitLabApiException {
1623
- GitLabApiForm formData = new GitLabApiForm ()
1624
- .withParam ("link_url" , linkUrl , true )
1625
- .withParam ("image_url" , imageUrl , true );
1626
- Response response = post (Response .Status .OK , formData , "groups" , getGroupIdOrPath (groupIdOrPath ), "badges" );
1627
- return (response .readEntity (Badge .class ));
1639
+ return addBadge (groupIdOrPath , null , linkUrl , imageUrl );
1640
+ }
1641
+
1642
+ /**
1643
+ * Add a badge to a group.
1644
+ *
1645
+ * <pre><code>GitLab Endpoint: POST /groups/:id/badges</code></pre>
1646
+ *
1647
+ * @param groupIdOrPath the group ID, path of the group, or a Group instance holding the group ID or path
1648
+ * @param name The name to give the badge (may be null)
1649
+ * @param linkUrl the URL of the badge link
1650
+ * @param imageUrl the URL of the image link
1651
+ * @return A Badge instance for the added badge
1652
+ * @throws GitLabApiException if any exception occurs
1653
+ */
1654
+ public Badge addBadge (Object groupIdOrPath , String name , String linkUrl , String imageUrl ) throws GitLabApiException {
1655
+ GitLabApiForm formData = new GitLabApiForm ()
1656
+ .withParam ("name" , name , false )
1657
+ .withParam ("link_url" , linkUrl , true )
1658
+ .withParam ("image_url" , imageUrl , true );
1659
+ Response response = post (Response .Status .OK , formData , "groups" , getGroupIdOrPath (groupIdOrPath ), "badges" );
1660
+ return (response .readEntity (Badge .class ));
1628
1661
}
1629
1662
1630
1663
/**
@@ -1640,11 +1673,29 @@ public Badge addBadge(Object groupIdOrPath, String linkUrl, String imageUrl) thr
1640
1673
* @throws GitLabApiException if any exception occurs
1641
1674
*/
1642
1675
public Badge editBadge (Object groupIdOrPath , Long badgeId , String linkUrl , String imageUrl ) throws GitLabApiException {
1643
- GitLabApiForm formData = new GitLabApiForm ()
1644
- .withParam ("link_url" , linkUrl , false )
1645
- .withParam ("image_url" , imageUrl , false );
1646
- Response response = putWithFormData (Response .Status .OK , formData , "groups" , getGroupIdOrPath (groupIdOrPath ), "badges" , badgeId );
1647
- return (response .readEntity (Badge .class ));
1676
+ return (editBadge (groupIdOrPath , badgeId , null , linkUrl , imageUrl ));
1677
+ }
1678
+
1679
+ /**
1680
+ * Edit a badge of a group.
1681
+ *
1682
+ * <pre><code>GitLab Endpoint: PUT /groups/:id/badges</code></pre>
1683
+ *
1684
+ * @param groupIdOrPath the group ID, path of the group, or a Group instance holding the group ID or path
1685
+ * @param badgeId the ID of the badge to edit
1686
+ * @param name The name of the badge to edit (may be null)
1687
+ * @param linkUrl the URL of the badge link
1688
+ * @param imageUrl the URL of the image link
1689
+ * @return a Badge instance for the edited badge
1690
+ * @throws GitLabApiException if any exception occurs
1691
+ */
1692
+ public Badge editBadge (Object groupIdOrPath , Long badgeId , String name , String linkUrl , String imageUrl ) throws GitLabApiException {
1693
+ GitLabApiForm formData = new GitLabApiForm ()
1694
+ .withParam ("name" , name , false )
1695
+ .withParam ("link_url" , linkUrl , false )
1696
+ .withParam ("image_url" , imageUrl , false );
1697
+ Response response = putWithFormData (Response .Status .OK , formData , "groups" , getGroupIdOrPath (groupIdOrPath ), "badges" , badgeId );
1698
+ return (response .readEntity (Badge .class ));
1648
1699
}
1649
1700
1650
1701
/**
0 commit comments