Skip to content
GitLab
Projects
Groups
Snippets
/
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Sign in / Register
Toggle navigation
Menu
Open sidebar
佳 邓
Gitlab4j Api
Commits
2be235b8
Unverified
Commit
2be235b8
authored
Feb 05, 2023
by
roadSurfer
Committed by
GitHub
Feb 05, 2023
Browse files
Add support for name in badges (#898)
--------- Co-authored-by:
jason
<
jason.irwin@idoxgroup.com
>
parent
608c4861
Changes
3
Hide whitespace changes
Inline
Side-by-side
src/main/java/org/gitlab4j/api/GroupApi.java
View file @
2be235b8
...
...
@@ -5,6 +5,7 @@ import java.util.Date;
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
;
...
...
@@ -1572,8 +1573,23 @@ public class GroupApi extends AbstractApi {
* @throws GitLabApiException if any exception occurs
*/
public
List
<
Badge
>
getBadges
(
Object
groupIdOrPath
)
throws
GitLabApiException
{
Response
response
=
get
(
Response
.
Status
.
OK
,
null
,
"groups"
,
getGroupIdOrPath
(
groupIdOrPath
),
"badges"
);
return
(
response
.
readEntity
(
new
GenericType
<
List
<
Badge
>>()
{}));
return
getBadges
(
groupIdOrPath
,
null
);
}
/**
* Gets a list of a group’s badges, case-sensitively filtered on bagdeName if non-null.
*
* <pre><code>GitLab Endpoint: GET /groups/:id/badges?name=:name</code></pre>
*
* @param groupIdOrPath the group ID, path of the group, or a Group instance holding the group ID or path
* @param badgeName The name to filter on (case-sensitive), ignored if null.
* @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
badgeName
)
throws
GitLabApiException
{
Form
queryParam
=
new
GitLabApiForm
().
withParam
(
"name"
,
badgeName
);
Response
response
=
get
(
Response
.
Status
.
OK
,
queryParam
.
asMap
(),
"groups"
,
getGroupIdOrPath
(
groupIdOrPath
),
"badges"
);
return
(
response
.
readEntity
(
new
GenericType
<
List
<
Badge
>>()
{}));
}
/**
...
...
@@ -1620,11 +1636,28 @@ public class GroupApi extends AbstractApi {
* @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 +1673,29 @@ public class GroupApi extends AbstractApi {
* @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
{
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
));
}
/**
...
...
src/main/java/org/gitlab4j/api/ProjectApi.java
View file @
2be235b8
...
...
@@ -3310,8 +3310,23 @@ public class ProjectApi extends AbstractApi implements Constants {
* @throws GitLabApiException if any exception occurs
*/
public
List
<
Badge
>
getBadges
(
Object
projectIdOrPath
)
throws
GitLabApiException
{
Response
response
=
get
(
Response
.
Status
.
OK
,
null
,
"projects"
,
getProjectIdOrPath
(
projectIdOrPath
),
"badges"
);
return
(
response
.
readEntity
(
new
GenericType
<
List
<
Badge
>>()
{}));
return
getBadges
(
projectIdOrPath
,
null
);
}
/**
* Gets a list of a project’s badges and its group badges, case-sensitively filtered on bagdeName if non-null.
*
* <pre><code>GitLab Endpoint: GET /projects/:id/badges?name=:name</code></pre>
*
* @param projectIdOrPath the project in the form of a Long(ID), String(path), or Project instance
* @param bagdeName The name to filter on (case-sensitive), ignored if null.
* @return All badges of the GitLab item, case insensitively filtered on name.
* @throws GitLabApiException If any problem is encountered
*/
public
List
<
Badge
>
getBadges
(
Object
projectIdOrPath
,
String
bagdeName
)
throws
GitLabApiException
{
Form
queryParam
=
new
GitLabApiForm
().
withParam
(
"name"
,
bagdeName
);
Response
response
=
get
(
Response
.
Status
.
OK
,
queryParam
.
asMap
(),
"projects"
,
getProjectIdOrPath
(
projectIdOrPath
),
"badges"
);
return
(
response
.
readEntity
(
new
GenericType
<
List
<
Badge
>>()
{}));
}
/**
...
...
@@ -3358,11 +3373,28 @@ public class ProjectApi extends AbstractApi implements Constants {
* @throws GitLabApiException if any exception occurs
*/
public
Badge
addBadge
(
Object
projectIdOrPath
,
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
,
"projects"
,
getProjectIdOrPath
(
projectIdOrPath
),
"badges"
);
return
(
response
.
readEntity
(
Badge
.
class
));
return
addBadge
(
projectIdOrPath
,
null
,
linkUrl
,
imageUrl
);
}
/**
* Add a badge to a project.
*
* <pre><code>GitLab Endpoint: POST /projects/:id/badges</code></pre>
*
* @param projectIdOrPath the project in the form of a Long(ID), String(path), or Project instance
* @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
projectIdOrPath
,
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
,
"projects"
,
getProjectIdOrPath
(
projectIdOrPath
),
"badges"
);
return
(
response
.
readEntity
(
Badge
.
class
));
}
/**
...
...
@@ -3378,11 +3410,29 @@ public class ProjectApi extends AbstractApi implements Constants {
* @throws GitLabApiException if any exception occurs
*/
public
Badge
editBadge
(
Object
projectIdOrPath
,
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
,
"projects"
,
getProjectIdOrPath
(
projectIdOrPath
),
"badges"
,
badgeId
);
return
(
response
.
readEntity
(
Badge
.
class
));
return
(
editBadge
(
projectIdOrPath
,
badgeId
,
null
,
linkUrl
,
imageUrl
));
}
/**
* Edit a badge of a project.
*
* <pre><code>GitLab Endpoint: PUT /projects/:id/badges</code></pre>
*
* @param projectIdOrPath the project in the form of a Long(ID), String(path), or Project instance
* @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 editted badge
* @throws GitLabApiException if any exception occurs
*/
public
Badge
editBadge
(
Object
projectIdOrPath
,
Long
badgeId
,
String
name
,
String
linkUrl
,
String
imageUrl
)
throws
GitLabApiException
{
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
,
"projects"
,
getProjectIdOrPath
(
projectIdOrPath
),
"badges"
,
badgeId
);
return
(
response
.
readEntity
(
Badge
.
class
));
}
/**
...
...
src/test/resources/org/gitlab4j/api/badges.json
View file @
2be235b8
[
{
"id"
:
1
,
"name"
:
"Badge 1"
,
"link_url"
:
"http://example.com/ci_status.svg?project=%{project_path}&ref=%{default_branch}"
,
"image_url"
:
"https://shields.io/my/badge"
,
"rendered_link_url"
:
"http://example.com/ci_status.svg?project=example-org/example-project&ref=master"
,
...
...
@@ -9,10 +10,11 @@
},
{
"id"
:
2
,
"name"
:
"Badge 2"
,
"link_url"
:
"http://example.com/ci_status.svg?project=%{project_path}&ref=%{default_branch}"
,
"image_url"
:
"https://shields.io/my/badge"
,
"rendered_link_url"
:
"http://example.com/ci_status.svg?project=example-org/example-project&ref=master"
,
"rendered_image_url"
:
"https://shields.io/my/badge"
,
"kind"
:
"group"
}
]
\ No newline at end of file
]
Write
Preview
Supports
Markdown
0%
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment