Skip to content

Commit c6ccf90

Browse files
committed
Merge remote-tracking branch 'origin/main' into issue-1202
# Conflicts: # gitlab4j-api/src/main/java/org/gitlab4j/api/UserApi.java
2 parents 72fe9d0 + 6f2f878 commit c6ccf90

27 files changed

+2025
-70
lines changed

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

Lines changed: 22 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -292,18 +292,38 @@ public Stream<Job> getJobsStream(Object projectIdOrPath, long pipelineId, Boolea
292292
}
293293

294294
/**
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).
295+
* Retrieve the job corresponding to the <code>$CI_JOB_TOKEN</code> environment variable (Using a {@link TokenType#JOB_TOKEN} authentication).
296296
*
297297
* <pre><code>GitLab Endpoint: GET /job</code></pre>
298298
*
299-
* @return a single job
299+
* @return a single job corresponding to the token used for the authentication
300300
* @throws GitLabApiException if any exception occurs during execution
301301
*/
302302
public Job getJob() throws GitLabApiException {
303+
TokenType tokenType = getApiClient().getTokenType();
304+
if (tokenType != TokenType.JOB_TOKEN) {
305+
throw new IllegalStateException(
306+
"This method can only be called with a " + TokenType.JOB_TOKEN + " authentication");
307+
}
303308
Response response = get(Response.Status.OK, null, "job");
304309
return (response.readEntity(Job.class));
305310
}
306311

312+
/**
313+
* Retrieve the job corresponding to the <code>$CI_JOB_TOKEN</code> environment variable. This works only when used without any authentication.
314+
*
315+
* <pre><code>GitLab Endpoint: GET /job?job_token=${ciJobToken}"</code></pre>
316+
*
317+
* @return a single job corresponding to the token passed as query parameter
318+
* @throws GitLabApiException if any exception occurs during execution
319+
*/
320+
public Job getJob(final String ciJobToken) throws GitLabApiException {
321+
GitLabApiForm formData = new GitLabApiForm().withParam("job_token", ciJobToken, true);
322+
323+
Response response = get(Response.Status.OK, formData.asMap(), "job");
324+
return (response.readEntity(Job.class));
325+
}
326+
307327
/**
308328
* Get single job in a project.
309329
*

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

Lines changed: 109 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,7 @@
2828
import java.io.UnsupportedEncodingException;
2929
import java.net.URLEncoder;
3030
import java.util.Date;
31+
import java.util.HashMap;
3132
import java.util.List;
3233
import java.util.Map;
3334
import java.util.Objects;
@@ -1127,7 +1128,60 @@ public Project createProject(Project project, String importUrl) throws GitLabApi
11271128
.withParam("suggestion_commit_message", project.getSuggestionCommitMessage())
11281129
.withParam("remove_source_branch_after_merge", project.getRemoveSourceBranchAfterMerge())
11291130
.withParam("auto_devops_enabled", project.getAutoDevopsEnabled())
1130-
.withParam("squash_option", project.getSquashOption());
1131+
.withParam("squash_option", project.getSquashOption())
1132+
.withParam("use_custom_template", project.getUseCustomTemplate())
1133+
.withParam(
1134+
"external_authorization_classification_label",
1135+
project.getExternalAuthorizationClassificationLabel())
1136+
.withParam("group_runners_enabled", project.getGroupRunnersEnabled())
1137+
.withParam("show_default_award_emojis", project.getShowDefaultAwardEmojis())
1138+
.withParam(
1139+
"warn_about_potentially_unwanted_characters",
1140+
project.getWarnAboutPotentiallyUnwantedCharacters())
1141+
.withParam("mirror_trigger_builds", project.getMirrorTriggerBuilds())
1142+
.withParam("auto_cancel_pending_pipelines", project.getAutoCancelPendingPipelines())
1143+
.withParam("repository_object_format", project.getRepositoryObjectFormat())
1144+
.withParam(
1145+
"only_allow_merge_if_all_status_checks_passed",
1146+
project.getOnlyAllowMergeIfAllStatusChecksPassed())
1147+
.withParam("group_with_project_templates_id", project.getGroupWithProjectTemplatesId())
1148+
.withParam("public_builds", project.getPublicBuilds())
1149+
.withParam("build_timeout", project.getBuildTimeout())
1150+
.withParam("template_name", project.getTemplateName())
1151+
.withParam("emails_enabled", project.getEmailsEnabled())
1152+
.withParam("mirror", project.getMirror())
1153+
.withParam("analytics_access_level", project.getAnalyticsAccessLevel())
1154+
.withParam("builds_access_level", project.getBuildsAccessLevel())
1155+
.withParam("container_registry_access_level", project.getContainerRegistryAccessLevel())
1156+
.withParam("environments_access_level", project.getEnvironmentsAccessLevel())
1157+
.withParam("feature_flags_access_level", project.getFeatureFlagsAccessLevel())
1158+
.withParam("forking_access_level", project.getForkingAccessLevel())
1159+
.withParam("infrastructure_access_level", project.getInfrastructureAccessLevel())
1160+
.withParam("issues_access_level", project.getIssuesAccessLevel())
1161+
.withParam("merge_requests_access_level", project.getMergeRequestsAccessLevel())
1162+
.withParam("model_experiments_access_level", project.getModelExperimentsAccessLevel())
1163+
.withParam("model_registry_access_level", project.getModelRegistryAccessLevel())
1164+
.withParam("monitor_access_level", project.getMonitorAccessLevel())
1165+
.withParam("pages_access_level", project.getPagesAccessLevel())
1166+
.withParam("releases_access_level", project.getReleasesAccessLevel())
1167+
.withParam("repository_access_level", project.getRepositoryAccessLevel())
1168+
.withParam("requirements_access_level", project.getRequirementsAccessLevel())
1169+
.withParam("security_and_compliance_access_level", project.getSecurityAndComplianceAccessLevel())
1170+
.withParam("snippets_access_level", project.getSnippetsAccessLevel())
1171+
.withParam("wiki_access_level", project.getWikiAccessLevel());
1172+
1173+
if (project.getContainerExpirationPolicy() != null) {
1174+
Map<String, Object> attributes = new HashMap<>();
1175+
attributes.put("cadence", project.getContainerExpirationPolicy().getCadence());
1176+
attributes.put("enabled", project.getContainerExpirationPolicy().getEnabled());
1177+
attributes.put("keep_n", project.getContainerExpirationPolicy().getKeepN());
1178+
attributes.put("older_than", project.getContainerExpirationPolicy().getOlderThan());
1179+
attributes.put("name_regex", project.getContainerExpirationPolicy().getNameRegex());
1180+
attributes.put(
1181+
"name_regex_keep", project.getContainerExpirationPolicy().getNameRegexKeep());
1182+
1183+
formData.withParam("container_expiration_policy_attributes", attributes, false);
1184+
}
11311185

11321186
Namespace namespace = project.getNamespace();
11331187
if (namespace != null && namespace.getId() != null) {
@@ -1443,7 +1497,60 @@ public Project updateProject(Project project) throws GitLabApiException {
14431497
.withParam("merge_method", project.getMergeMethod())
14441498
.withParam("suggestion_commit_message", project.getSuggestionCommitMessage())
14451499
.withParam("remove_source_branch_after_merge", project.getRemoveSourceBranchAfterMerge())
1446-
.withParam("squash_option", project.getSquashOption());
1500+
.withParam("squash_option", project.getSquashOption())
1501+
.withParam("use_custom_template", project.getUseCustomTemplate())
1502+
.withParam(
1503+
"external_authorization_classification_label",
1504+
project.getExternalAuthorizationClassificationLabel())
1505+
.withParam("group_runners_enabled", project.getGroupRunnersEnabled())
1506+
.withParam("show_default_award_emojis", project.getShowDefaultAwardEmojis())
1507+
.withParam(
1508+
"warn_about_potentially_unwanted_characters",
1509+
project.getWarnAboutPotentiallyUnwantedCharacters())
1510+
.withParam("mirror_trigger_builds", project.getMirrorTriggerBuilds())
1511+
.withParam("auto_cancel_pending_pipelines", project.getAutoCancelPendingPipelines())
1512+
.withParam("repository_object_format", project.getRepositoryObjectFormat())
1513+
.withParam(
1514+
"only_allow_merge_if_all_status_checks_passed",
1515+
project.getOnlyAllowMergeIfAllStatusChecksPassed())
1516+
.withParam("group_with_project_templates_id", project.getGroupWithProjectTemplatesId())
1517+
.withParam("public_builds", project.getPublicBuilds())
1518+
.withParam("build_timeout", project.getBuildTimeout())
1519+
.withParam("template_name", project.getTemplateName())
1520+
.withParam("emails_enabled", project.getEmailsEnabled())
1521+
.withParam("mirror", project.getMirror())
1522+
.withParam("analytics_access_level", project.getAnalyticsAccessLevel())
1523+
.withParam("builds_access_level", project.getBuildsAccessLevel())
1524+
.withParam("container_registry_access_level", project.getContainerRegistryAccessLevel())
1525+
.withParam("environments_access_level", project.getEnvironmentsAccessLevel())
1526+
.withParam("feature_flags_access_level", project.getFeatureFlagsAccessLevel())
1527+
.withParam("forking_access_level", project.getForkingAccessLevel())
1528+
.withParam("infrastructure_access_level", project.getInfrastructureAccessLevel())
1529+
.withParam("issues_access_level", project.getIssuesAccessLevel())
1530+
.withParam("merge_requests_access_level", project.getMergeRequestsAccessLevel())
1531+
.withParam("model_experiments_access_level", project.getModelExperimentsAccessLevel())
1532+
.withParam("model_registry_access_level", project.getModelRegistryAccessLevel())
1533+
.withParam("monitor_access_level", project.getMonitorAccessLevel())
1534+
.withParam("pages_access_level", project.getPagesAccessLevel())
1535+
.withParam("releases_access_level", project.getReleasesAccessLevel())
1536+
.withParam("repository_access_level", project.getRepositoryAccessLevel())
1537+
.withParam("requirements_access_level", project.getRequirementsAccessLevel())
1538+
.withParam("security_and_compliance_access_level", project.getSecurityAndComplianceAccessLevel())
1539+
.withParam("snippets_access_level", project.getSnippetsAccessLevel())
1540+
.withParam("wiki_access_level", project.getWikiAccessLevel());
1541+
1542+
if (project.getContainerExpirationPolicy() != null) {
1543+
Map<String, Object> attributes = new HashMap<>();
1544+
attributes.put("cadence", project.getContainerExpirationPolicy().getCadence());
1545+
attributes.put("enabled", project.getContainerExpirationPolicy().getEnabled());
1546+
attributes.put("keep_n", project.getContainerExpirationPolicy().getKeepN());
1547+
attributes.put("older_than", project.getContainerExpirationPolicy().getOlderThan());
1548+
attributes.put("name_regex", project.getContainerExpirationPolicy().getNameRegex());
1549+
attributes.put(
1550+
"name_regex_keep", project.getContainerExpirationPolicy().getNameRegexKeep());
1551+
1552+
formData.withParam("container_expiration_policy_attributes", attributes, false);
1553+
}
14471554

14481555
Visibility visibility = (project.getVisibility() != null
14491556
? project.getVisibility()

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

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@
1212
import jakarta.ws.rs.core.GenericType;
1313
import jakarta.ws.rs.core.Response;
1414

15+
import org.gitlab4j.api.models.Associations;
1516
import org.gitlab4j.api.models.CustomAttribute;
1617
import org.gitlab4j.api.models.Email;
1718
import org.gitlab4j.api.models.Exists;
@@ -1489,6 +1490,20 @@ public Pager<Membership> getMemberships(Long userId, int itemsPerPage) throws Gi
14891490
return (new Pager<>(this, Membership.class, itemsPerPage, formData.asMap(), "users", userId, "memberships"));
14901491
}
14911492

1493+
/**
1494+
* Get a count of a user’s projects, groups, issues, and merge requests
1495+
*
1496+
* <pre><code>GitLab Endpoint: GET /user/:id/associations_count</code></pre>
1497+
*
1498+
* @param userId the ID of the user to get the associations for
1499+
* @return the count of each type of association
1500+
* @throws GitLabApiException if any exception occurs
1501+
*/
1502+
public Associations getAssociationsCount(Long userId) throws GitLabApiException {
1503+
Response response = get(Response.Status.OK, null, "users", userId, "associations_count");
1504+
return (response.readEntity(Associations.class));
1505+
}
1506+
14921507
/**
14931508
* Activates the given user (admin only)
14941509
*
Lines changed: 51 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,51 @@
1+
package org.gitlab4j.api.models;
2+
3+
import java.io.Serializable;
4+
5+
import org.gitlab4j.models.utils.JacksonJson;
6+
7+
public class Associations implements Serializable {
8+
private static final long serialVersionUID = 1L;
9+
10+
private int groupsCount;
11+
private int projectsCount;
12+
private int issuesCount;
13+
private int mergeRequestsCount;
14+
15+
public int getGroupsCount() {
16+
return groupsCount;
17+
}
18+
19+
public void setGroupsCount(int groupsCount) {
20+
this.groupsCount = groupsCount;
21+
}
22+
23+
public int getProjectsCount() {
24+
return projectsCount;
25+
}
26+
27+
public void setProjectsCount(int projectsCount) {
28+
this.projectsCount = projectsCount;
29+
}
30+
31+
public int getIssuesCount() {
32+
return issuesCount;
33+
}
34+
35+
public void setIssuesCount(int issuesCount) {
36+
this.issuesCount = issuesCount;
37+
}
38+
39+
public int getMergeRequestsCount() {
40+
return mergeRequestsCount;
41+
}
42+
43+
public void setMergeRequestsCount(int mergeRequestsCount) {
44+
this.mergeRequestsCount = mergeRequestsCount;
45+
}
46+
47+
@Override
48+
public String toString() {
49+
return (JacksonJson.toJsonString(this));
50+
}
51+
}

0 commit comments

Comments
 (0)