Skip to content

Commit cf3504c

Browse files
committed
Merge branch 'main' into xxx
# Conflicts: # README.md # gradle.properties
2 parents 0657ed6 + 2502147 commit cf3504c

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

53 files changed

+1804
-347
lines changed

build.gradle

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,12 @@
11
plugins {
22
id 'com.diffplug.spotless' version '6.25.0' apply false
3-
id 'io.github.gradle-nexus.publish-plugin' version '1.3.0'
4-
id 'net.researchgate.release' version '3.0.2'
3+
id 'org.kordamp.gradle.jandex' version '2.1.0' apply false
4+
id 'io.github.gradle-nexus.publish-plugin' version '2.0.0'
5+
id 'net.researchgate.release' version '3.1.0'
56
}
67

78
wrapper {
8-
gradleVersion = '7.6.2'
9+
gradleVersion = '8.10.1'
910
}
1011

1112
String groupId = 'org.gitlab4j'
@@ -15,6 +16,7 @@ subprojects {
1516
apply plugin: 'signing'
1617
apply plugin: 'com.diffplug.spotless'
1718
apply plugin: 'maven-publish'
19+
apply plugin: 'org.kordamp.gradle.jandex'
1820

1921
group = groupId
2022

@@ -55,6 +57,10 @@ subprojects {
5557
tasks.named('test') {
5658
useJUnitPlatform()
5759
}
60+
61+
tasks.named("javadoc") {
62+
inputs.files(tasks.getByPath("jandex").outputs.files)
63+
}
5864
}
5965

6066
nexusPublishing {

gitlab4j-api/src/main/java/org/gitlab4j/api/BoardsApi.java

Lines changed: 1041 additions & 96 deletions
Large diffs are not rendered by default.

gitlab4j-api/src/main/java/org/gitlab4j/api/GitLabApiForm.java

Lines changed: 48 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@
1111
import org.gitlab4j.api.models.AccessLevel;
1212
import org.gitlab4j.api.models.Variable;
1313
import org.gitlab4j.models.GitLabForm;
14+
import org.gitlab4j.models.GitLabFormValue;
1415
import org.gitlab4j.models.utils.ISO8601;
1516

1617
/**
@@ -35,13 +36,33 @@ public GitLabApiForm(MultivaluedHashMap<String, String> map) {
3536
public GitLabApiForm(int page, int perPage) {
3637
super();
3738
withParam(AbstractApi.PAGE_PARAM, page);
38-
withParam(AbstractApi.PER_PAGE_PARAM, (Integer) perPage);
39+
withParam(AbstractApi.PER_PAGE_PARAM, perPage);
3940
}
4041

4142
public GitLabApiForm(GitLabForm form) {
4243
super();
43-
for (Entry<String, String> e : form.getFormValues().entrySet()) {
44-
this.param(e.getKey(), e.getValue());
44+
for (Entry<String, GitLabFormValue> e : form.getFormValues().entrySet()) {
45+
GitLabFormValue value = e.getValue();
46+
switch (value.getType()) {
47+
case ACCESS_LEVEL:
48+
withParam(e.getKey(), (AccessLevel) value.getValue(), value.isRequired());
49+
break;
50+
case DATE:
51+
withParam(e.getKey(), (Date) value.getValue(), value.isRequired());
52+
break;
53+
case LIST:
54+
withParam(e.getKey(), (List<?>) value.getValue(), value.isRequired());
55+
break;
56+
case MAP:
57+
@SuppressWarnings("unchecked")
58+
Map<String, ?> mapValue = (Map<String, ?>) value.getValue();
59+
withParam(e.getKey(), mapValue, value.isRequired());
60+
break;
61+
case OBJECT:
62+
default:
63+
withParam(e.getKey(), value.getValue(), value.isRequired());
64+
break;
65+
}
4566
}
4667
}
4768

@@ -52,8 +73,8 @@ public GitLabApiForm(GitLabForm form) {
5273
* @param value the value of the field/attribute to add
5374
* @return this GitLabAPiForm instance
5475
*/
55-
public GitLabApiForm withParam(String name, Object value) throws IllegalArgumentException {
56-
return (withParam(name, value, false));
76+
public GitLabApiForm withParam(String name, Object value) {
77+
return withParam(name, value, false);
5778
}
5879

5980
/**
@@ -63,8 +84,8 @@ public GitLabApiForm withParam(String name, Object value) throws IllegalArgument
6384
* @param date the value of the field/attribute to add
6485
* @return this GitLabAPiForm instance
6586
*/
66-
public GitLabApiForm withParam(String name, Date date) throws IllegalArgumentException {
67-
return (withParam(name, date, false));
87+
public GitLabApiForm withParam(String name, Date date) {
88+
return withParam(name, date, false);
6889
}
6990

7091
/**
@@ -76,8 +97,8 @@ public GitLabApiForm withParam(String name, Date date) throws IllegalArgumentExc
7697
* @return this GitLabAPiForm instance
7798
* @throws IllegalArgumentException if a required parameter is null or empty
7899
*/
79-
public GitLabApiForm withParam(String name, Date date, boolean required) throws IllegalArgumentException {
80-
return (withParam(name, (date == null ? null : ISO8601.toString(date)), required));
100+
public GitLabApiForm withParam(String name, Date date, boolean required) {
101+
return withParam(name, date == null ? null : ISO8601.toString(date), required);
81102
}
82103

83104
/**
@@ -87,8 +108,8 @@ public GitLabApiForm withParam(String name, Date date, boolean required) throws
87108
* @param level the value of the field/attribute to add
88109
* @return this GitLabAPiForm instance
89110
*/
90-
public GitLabApiForm withParam(String name, AccessLevel level) throws IllegalArgumentException {
91-
return (withParam(name, level, false));
111+
public GitLabApiForm withParam(String name, AccessLevel level) {
112+
return withParam(name, level, false);
92113
}
93114

94115
/**
@@ -100,49 +121,47 @@ public GitLabApiForm withParam(String name, AccessLevel level) throws IllegalArg
100121
* @return this GitLabAPiForm instance
101122
* @throws IllegalArgumentException if a required parameter is null or empty
102123
*/
103-
public GitLabApiForm withParam(String name, AccessLevel level, boolean required) throws IllegalArgumentException {
104-
return (withParam(name, (level == null ? null : level.toValue()), required));
124+
public GitLabApiForm withParam(String name, AccessLevel level, boolean required) {
125+
return withParam(name, level == null ? null : level.toValue(), required);
105126
}
106127

107128
/**
108129
* Fluent method for adding a List type query and form parameters to a get() or post() call.
109130
*
110-
* @param <T> the type contained by the List
111131
* @param name the name of the field/attribute to add
112132
* @param values a List containing the values of the field/attribute to add
113133
* @return this GitLabAPiForm instance
114134
*/
115-
public <T> GitLabApiForm withParam(String name, List<T> values) {
116-
return (withParam(name, values, false));
135+
public GitLabApiForm withParam(String name, List<?> values) {
136+
return withParam(name, values, false);
117137
}
118138

119139
/**
120140
* Fluent method for adding a List type query and form parameters to a get() or post() call.
121141
*
122-
* @param <T> the type contained by the List
123142
* @param name the name of the field/attribute to add
124143
* @param values a List containing the values of the field/attribute to add
125144
* @param required the field is required flag
126145
* @return this GitLabAPiForm instance
127146
* @throws IllegalArgumentException if a required parameter is null or empty
128147
*/
129-
public <T> GitLabApiForm withParam(String name, List<T> values, boolean required) throws IllegalArgumentException {
148+
public GitLabApiForm withParam(String name, List<?> values, boolean required) {
130149

131150
if (values == null || values.isEmpty()) {
132151
if (required) {
133152
throw new IllegalArgumentException(name + " cannot be empty or null");
134153
}
135154

136-
return (this);
155+
return this;
137156
}
138157

139-
for (T value : values) {
158+
for (Object value : values) {
140159
if (value != null) {
141160
this.param(name + "[]", value.toString());
142161
}
143162
}
144163

145-
return (this);
164+
return this;
146165
}
147166

148167
/**
@@ -154,15 +173,14 @@ public <T> GitLabApiForm withParam(String name, List<T> values, boolean required
154173
* @return this GitLabAPiForm instance
155174
* @throws IllegalArgumentException if a required parameter is null or empty
156175
*/
157-
public GitLabApiForm withParam(String name, Map<String, ?> variables, boolean required)
158-
throws IllegalArgumentException {
176+
public GitLabApiForm withParam(String name, Map<String, ?> variables, boolean required) {
159177

160178
if (variables == null || variables.isEmpty()) {
161179
if (required) {
162180
throw new IllegalArgumentException(name + " cannot be empty or null");
163181
}
164182

165-
return (this);
183+
return this;
166184
}
167185

168186
for (Entry<String, ?> variable : variables.entrySet()) {
@@ -172,7 +190,7 @@ public GitLabApiForm withParam(String name, Map<String, ?> variables, boolean re
172190
}
173191
}
174192

175-
return (this);
193+
return this;
176194
}
177195

178196
/**
@@ -185,14 +203,14 @@ public GitLabApiForm withParam(String name, Map<String, ?> variables, boolean re
185203
* @return this GitLabAPiForm instance
186204
* @throws IllegalArgumentException if a required parameter is null or empty
187205
*/
188-
public GitLabApiForm withParam(String name, Object value, boolean required) throws IllegalArgumentException {
206+
public GitLabApiForm withParam(String name, Object value, boolean required) {
189207

190208
if (value == null) {
191209
if (required) {
192210
throw new IllegalArgumentException(name + " cannot be empty or null");
193211
}
194212

195-
return (this);
213+
return this;
196214
}
197215

198216
String stringValue = value.toString();
@@ -201,7 +219,7 @@ public GitLabApiForm withParam(String name, Object value, boolean required) thro
201219
}
202220

203221
this.param(name.trim(), stringValue);
204-
return (this);
222+
return this;
205223
}
206224

207225
/**
@@ -213,7 +231,7 @@ public GitLabApiForm withParam(String name, Object value, boolean required) thro
213231
public GitLabApiForm withParam(List<Variable> variables) {
214232

215233
if (variables == null || variables.isEmpty()) {
216-
return (this);
234+
return this;
217235
}
218236

219237
variables.forEach(v -> {
@@ -223,6 +241,6 @@ public GitLabApiForm withParam(List<Variable> variables) {
223241
}
224242
});
225243

226-
return (this);
244+
return this;
227245
}
228246
}

gitlab4j-api/src/main/java/org/gitlab4j/api/GroupApi.java

Lines changed: 37 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -636,7 +636,7 @@ public Optional<Group> getOptionalGroup(Object groupIdOrPath) {
636636
* @throws GitLabApiException if any exception occurs
637637
*/
638638
public Group createGroup(GroupParams params) throws GitLabApiException {
639-
Response response = post(Response.Status.CREATED, params.getForm(true), "groups");
639+
Response response = post(Response.Status.CREATED, new GitLabApiForm(params.getForm(true)), "groups");
640640
return (response.readEntity(Group.class));
641641
}
642642

@@ -651,8 +651,11 @@ public Group createGroup(GroupParams params) throws GitLabApiException {
651651
* @throws GitLabApiException at any exception
652652
*/
653653
public Group updateGroup(Object groupIdOrPath, GroupParams params) throws GitLabApiException {
654-
Response response =
655-
putWithFormData(Response.Status.OK, params.getForm(false), "groups", getGroupIdOrPath(groupIdOrPath));
654+
Response response = putWithFormData(
655+
Response.Status.OK,
656+
new GitLabApiForm(params.getForm(false)),
657+
"groups",
658+
getGroupIdOrPath(groupIdOrPath));
656659
return (response.readEntity(Group.class));
657660
}
658661

@@ -2372,16 +2375,42 @@ public GroupAccessToken getGroupAccessToken(Object groupIdOrPath, Long tokenId)
23722375
* @param accessLevel Access level. Valid values are {@link AccessLevel#GUEST}, {@link AccessLevel#REPORTER}, {@link AccessLevel#DEVELOPER}, {@link AccessLevel#MAINTAINER}, and {@link AccessLevel#OWNER}.
23732376
* @return the created GroupAccessToken instance
23742377
* @throws GitLabApiException if any exception occurs
2378+
* @deprecated use {@link #createGroupAccessToken(Object, String, String, Date, Scope[], AccessLevel)}
23752379
*/
2380+
@Deprecated
23762381
public GroupAccessToken createGroupAccessToken(
23772382
Object groupIdOrPath, String name, Date expiresAt, Scope[] scopes, AccessLevel accessLevel)
23782383
throws GitLabApiException {
2384+
return createGroupAccessToken(groupIdOrPath, name, null, expiresAt, scopes, accessLevel);
2385+
}
2386+
/**
2387+
* Create a group access token. You must have the Owner role for the group to create group access tokens.
2388+
*
2389+
* <pre><code>GitLab Endpoint: POST /groups/:id/access_tokens</code></pre>
2390+
*
2391+
* @param groupIdOrPath the group in the form of an Long(ID), String(path), or Group instance
2392+
* @param name the name of the group access token, required
2393+
* @param expiresAt the expiration date of the group access token, optional
2394+
* @param scopes an array of scopes of the group access token
2395+
* @param accessLevel Access level. Valid values are {@link AccessLevel#GUEST}, {@link AccessLevel#REPORTER}, {@link AccessLevel#DEVELOPER}, {@link AccessLevel#MAINTAINER}, and {@link AccessLevel#OWNER}.
2396+
* @return the created GroupAccessToken instance
2397+
* @throws GitLabApiException if any exception occurs
2398+
*/
2399+
public GroupAccessToken createGroupAccessToken(
2400+
Object groupIdOrPath,
2401+
String name,
2402+
String description,
2403+
Date expiresAt,
2404+
Scope[] scopes,
2405+
AccessLevel accessLevel)
2406+
throws GitLabApiException {
23792407
if (scopes == null || scopes.length == 0) {
23802408
throw new RuntimeException("scopes cannot be null or empty");
23812409
}
23822410

23832411
GitLabApiForm formData = new GitLabApiForm()
23842412
.withParam("name", name, true)
2413+
.withParam("description", description)
23852414
.withParam("scopes", Arrays.asList(scopes))
23862415
.withParam("expires_at", ISO8601.dateOnly(expiresAt))
23872416
.withParam("access_level", accessLevel);
@@ -2455,7 +2484,11 @@ public void revokeGroupAccessToken(Object groupIdOrPath, Long tokenId) throws Gi
24552484
*/
24562485
public GroupHook addWebhook(Object groupIdOrPath, GroupHookParams groupHookParams) throws GitLabApiException {
24572486
Response response = post(
2458-
Response.Status.CREATED, groupHookParams.getForm(), "groups", getGroupIdOrPath(groupIdOrPath), "hooks");
2487+
Response.Status.CREATED,
2488+
new GitLabApiForm(groupHookParams.getForm()),
2489+
"groups",
2490+
getGroupIdOrPath(groupIdOrPath),
2491+
"hooks");
24592492
return (response.readEntity(GroupHook.class));
24602493
}
24612494

gitlab4j-api/src/main/java/org/gitlab4j/api/JobApi.java

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -291,6 +291,19 @@ public Stream<Job> getJobsStream(Object projectIdOrPath, long pipelineId, Boolea
291291
return (getJobsForPipeline(projectIdOrPath, pipelineId, getDefaultPerPage(), includeRetried).stream());
292292
}
293293

294+
/**
295+
* Retrieve the job corresponding to the <code>$CI_JOB_TOKEN</code> environment variable (Using a {@link org.gitlab4j.models.Constants.TokenType#JOB_TOKEN} authentication).
296+
*
297+
* <pre><code>GitLab Endpoint: GET /job</code></pre>
298+
*
299+
* @return a single job
300+
* @throws GitLabApiException if any exception occurs during execution
301+
*/
302+
public Job getJob() throws GitLabApiException {
303+
Response response = get(Response.Status.OK, null, "job");
304+
return (response.readEntity(Job.class));
305+
}
306+
294307
/**
295308
* Get single job in a project.
296309
*

gitlab4j-api/src/main/java/org/gitlab4j/api/NotesApi.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -455,7 +455,7 @@ public Note getMergeRequestNote(Object projectIdOrPath, Long mergeRequestIid, Lo
455455
* @throws GitLabApiException if any exception occurs
456456
*/
457457
public Note createMergeRequestNote(
458-
Object projectIdOrPath, Long mergeRequestIid, String body, Date createdAt, boolean internal)
458+
Object projectIdOrPath, Long mergeRequestIid, String body, Date createdAt, Boolean internal)
459459
throws GitLabApiException {
460460
GitLabApiForm formData =
461461
new GitLabApiForm().withParam("body", body, true).withParam("internal", internal);

gitlab4j-api/src/main/java/org/gitlab4j/api/PersonalAccessTokenApi.java

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,9 @@
11
package org.gitlab4j.api;
22

33
import java.util.Date;
4+
import java.util.List;
45

6+
import jakarta.ws.rs.core.GenericType;
57
import jakarta.ws.rs.core.Response;
68

79
import org.gitlab4j.api.models.PersonalAccessToken;
@@ -66,6 +68,20 @@ public PersonalAccessToken rotatePersonalAccessToken(String id, Date expiresAt)
6668
return (response.readEntity(PersonalAccessToken.class));
6769
}
6870

71+
/**
72+
* Get information about the personal access token used in the request header.
73+
* Only working with GitLab 16.0 and above.
74+
*
75+
* <pre><code>GitLab Endpoint: GET /personal_access_tokens</code></pre>
76+
*
77+
* @return the specified PersonalAccessToken.
78+
* @throws GitLabApiException if any exception occurs
79+
*/
80+
public List<PersonalAccessToken> getPersonalAccessTokens() throws GitLabApiException {
81+
Response response = get(Response.Status.OK, null, "personal_access_tokens");
82+
return response.readEntity(new GenericType<List<PersonalAccessToken>>() {});
83+
}
84+
6985
/**
7086
* Get information about the personal access token used in the request header.
7187
* Only working with GitLab 16.0 and above.

0 commit comments

Comments
 (0)