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
d34694c8
Commit
d34694c8
authored
Apr 13, 2024
by
Jeremie Bresson
Browse files
Merge remote-tracking branch 'origin/main' into 6.x
parents
264884af
fcecb0b2
Changes
4
Hide whitespace changes
Inline
Side-by-side
src/main/java/org/gitlab4j/api/models/Group.java
View file @
d34694c8
...
@@ -66,6 +66,7 @@ public class Group extends AbstractGroup<Group> {
...
@@ -66,6 +66,7 @@ public class Group extends AbstractGroup<Group> {
private
List
<
Project
>
sharedProjects
;
private
List
<
Project
>
sharedProjects
;
private
Date
createdAt
;
private
Date
createdAt
;
private
List
<
SharedGroup
>
sharedWithGroups
;
private
List
<
SharedGroup
>
sharedWithGroups
;
private
List
<
CustomAttribute
>
customAttributes
;
private
String
runnersToken
;
private
String
runnersToken
;
private
Boolean
preventSharingGroupsOutsideHierarchy
;
private
Boolean
preventSharingGroupsOutsideHierarchy
;
private
Boolean
preventForkingOutsideGroup
;
private
Boolean
preventForkingOutsideGroup
;
...
@@ -228,6 +229,14 @@ public class Group extends AbstractGroup<Group> {
...
@@ -228,6 +229,14 @@ public class Group extends AbstractGroup<Group> {
this
.
defaultBranchProtection
=
defaultBranchProtection
;
this
.
defaultBranchProtection
=
defaultBranchProtection
;
}
}
public
List
<
CustomAttribute
>
getCustomAttributes
()
{
return
customAttributes
;
}
public
void
setCustomAttributes
(
List
<
CustomAttribute
>
customAttributes
)
{
this
.
customAttributes
=
customAttributes
;
}
public
Group
withPath
(
String
path
)
{
public
Group
withPath
(
String
path
)
{
this
.
path
=
path
;
this
.
path
=
path
;
return
this
;
return
this
;
...
@@ -303,6 +312,11 @@ public class Group extends AbstractGroup<Group> {
...
@@ -303,6 +312,11 @@ public class Group extends AbstractGroup<Group> {
return
this
;
return
this
;
}
}
public
Group
withCustomAttributes
(
List
<
CustomAttribute
>
customAttributes
)
{
this
.
customAttributes
=
customAttributes
;
return
this
;
}
@Override
@Override
public
String
toString
()
{
public
String
toString
()
{
return
(
JacksonJson
.
toJsonString
(
this
));
return
(
JacksonJson
.
toJsonString
(
this
));
...
...
src/main/java/org/gitlab4j/api/models/GroupFilter.java
View file @
d34694c8
...
@@ -6,6 +6,7 @@ import org.gitlab4j.api.GitLabApiForm;
...
@@ -6,6 +6,7 @@ import org.gitlab4j.api.GitLabApiForm;
import
org.gitlab4j.api.utils.JacksonJson
;
import
org.gitlab4j.api.utils.JacksonJson
;
import
java.io.Serializable
;
import
java.io.Serializable
;
import
java.util.ArrayList
;
import
java.util.List
;
import
java.util.List
;
/**
/**
...
@@ -24,6 +25,7 @@ public class GroupFilter implements Serializable {
...
@@ -24,6 +25,7 @@ public class GroupFilter implements Serializable {
private
Boolean
owned
;
private
Boolean
owned
;
private
AccessLevel
accessLevel
;
private
AccessLevel
accessLevel
;
private
Boolean
topLevelOnly
;
private
Boolean
topLevelOnly
;
private
List
<
CustomAttribute
>
customAttributesFilter
=
new
ArrayList
<>();
/**
/**
* Do not include the provided groups IDs.
* Do not include the provided groups IDs.
...
@@ -103,6 +105,18 @@ public class GroupFilter implements Serializable {
...
@@ -103,6 +105,18 @@ public class GroupFilter implements Serializable {
return
(
this
);
return
(
this
);
}
}
/**
* Results must have custom attribute (admins only). Can be chained to combine multiple attribute checks.
*
* @param key the assets returned must have the specified custom attribute key
* @param value the assets returned must have the specified value for the custom attribute key
* @return the reference to this GroupFilter instance
*/
public
GroupFilter
withCustomAttributeFilter
(
String
key
,
String
value
)
{
this
.
customAttributesFilter
.
add
(
new
CustomAttribute
().
withKey
(
key
).
withValue
(
value
));
return
(
this
);
}
/**
/**
* Limit by groups explicitly owned by the current user
* Limit by groups explicitly owned by the current user
*
*
...
@@ -142,18 +156,20 @@ public class GroupFilter implements Serializable {
...
@@ -142,18 +156,20 @@ public class GroupFilter implements Serializable {
* @return a GitLabApiForm instance holding the query parameters for this GroupFilter instance
* @return a GitLabApiForm instance holding the query parameters for this GroupFilter instance
*/
*/
public
GitLabApiForm
getQueryParams
()
{
public
GitLabApiForm
getQueryParams
()
{
return
(
new
GitLabApiForm
()
GitLabApiForm
form
=
new
GitLabApiForm
().
withParam
(
"skip_groups"
,
skipGroups
)
.
withParam
(
"skip_groups"
,
skipGroups
)
.
withParam
(
"all_available"
,
allAvailable
)
.
withParam
(
"all_available"
,
allAvailable
)
.
withParam
(
"search"
,
search
)
.
withParam
(
"search"
,
search
)
.
withParam
(
"order_by"
,
orderBy
)
.
withParam
(
"order_by"
,
orderBy
)
.
withParam
(
"sort"
,
sort
)
.
withParam
(
"sort"
,
sort
)
.
withParam
(
"statistics"
,
statistics
)
.
withParam
(
"statistics"
,
statistics
)
.
withParam
(
"with_custom_attributes"
,
withCustomAttributes
)
.
withParam
(
"with_custom_attributes"
,
withCustomAttributes
)
.
withParam
(
"owned"
,
owned
)
.
withParam
(
"owned"
,
owned
)
.
withParam
(
"min_access_level"
,
accessLevel
)
.
withParam
(
"min_access_level"
,
accessLevel
)
.
withParam
(
"top_level_only"
,
topLevelOnly
);
.
withParam
(
"top_level_only"
,
topLevelOnly
)
for
(
CustomAttribute
customAttribute
:
customAttributesFilter
)
{
);
form
.
withParam
(
String
.
format
(
"custom_attributes[%s]"
,
customAttribute
.
getKey
()),
customAttribute
.
getValue
());
}
return
form
;
}
}
@Override
@Override
...
...
src/test/java/org/gitlab4j/api/TestGroupApi.java
View file @
d34694c8
...
@@ -21,6 +21,7 @@ import jakarta.ws.rs.core.Response;
...
@@ -21,6 +21,7 @@ import jakarta.ws.rs.core.Response;
import
org.gitlab4j.api.models.AccessLevel
;
import
org.gitlab4j.api.models.AccessLevel
;
import
org.gitlab4j.api.models.AccessRequest
;
import
org.gitlab4j.api.models.AccessRequest
;
import
org.gitlab4j.api.models.Group
;
import
org.gitlab4j.api.models.Group
;
import
org.gitlab4j.api.models.GroupFilter
;
import
org.gitlab4j.api.models.GroupParams
;
import
org.gitlab4j.api.models.GroupParams
;
import
org.gitlab4j.api.models.Member
;
import
org.gitlab4j.api.models.Member
;
import
org.gitlab4j.api.models.User
;
import
org.gitlab4j.api.models.User
;
...
@@ -193,6 +194,21 @@ public class TestGroupApi extends AbstractIntegrationTest {
...
@@ -193,6 +194,21 @@ public class TestGroupApi extends AbstractIntegrationTest {
assertNotNull
(
group
);
assertNotNull
(
group
);
}
}
@Test
public
void
getGroupsWithCustomAttribute
()
throws
GitLabApiException
{
gitLabApi
.
getGroupApi
().
setCustomAttribute
(
TEST_GROUP
,
"test_key"
,
"test_value"
);
GroupFilter
wrongKeyFilter
=
new
GroupFilter
().
withCustomAttributeFilter
(
"other_key"
,
"test_value"
);
GroupFilter
multipleFilter
=
new
GroupFilter
().
withCustomAttributeFilter
(
"test_key"
,
"test_value"
).
withCustomAttributeFilter
(
"other_key"
,
"test_value"
);
GroupFilter
matchingFilter
=
new
GroupFilter
().
withCustomAttributeFilter
(
"test_key"
,
"test_value"
);
assertEquals
(
1
,
gitLabApi
.
getGroupApi
().
getGroups
(
matchingFilter
).
size
());
assertTrue
(
gitLabApi
.
getGroupApi
().
getGroups
(
wrongKeyFilter
).
isEmpty
());
assertTrue
(
gitLabApi
.
getGroupApi
().
getGroups
(
multipleFilter
).
isEmpty
());
gitLabApi
.
getGroupApi
().
deleteCustomAttribute
(
TEST_GROUP
,
"test_key"
);
}
@Test
@Test
public
void
getOptionalGroup
()
{
public
void
getOptionalGroup
()
{
Optional
<
Group
>
optional
=
gitLabApi
.
getGroupApi
().
getOptionalGroup
(
TEST_GROUP
);
Optional
<
Group
>
optional
=
gitLabApi
.
getGroupApi
().
getOptionalGroup
(
TEST_GROUP
);
...
...
src/test/resources/org/gitlab4j/api/group.json
View file @
d34694c8
...
@@ -22,6 +22,12 @@
...
@@ -22,6 +22,12 @@
"lfs_objects_size"
:
123
,
"lfs_objects_size"
:
123
,
"job_artifacts_size"
:
57
"job_artifacts_size"
:
57
},
},
"custom_attributes"
:
[
{
"key"
:
"flagged"
,
"value"
:
"YAY"
}
],
"shared_with_groups"
:
[
"shared_with_groups"
:
[
{
{
"group_id"
:
104
,
"group_id"
:
104
,
...
...
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