From b36eea5606dfcb7f9079ef234b22ca81e73f21fd Mon Sep 17 00:00:00 2001 From: Jony Jas J Date: Fri, 15 Aug 2025 14:58:42 +0530 Subject: [PATCH 1/2] feat: Add Pull mirror API (#1227) --- .../java/org/gitlab4j/api/ProjectApi.java | 36 +++++ .../org/gitlab4j/api/models/PullMirror.java | 124 ++++++++++++++++++ 2 files changed, 160 insertions(+) create mode 100644 gitlab4j-models/src/main/java/org/gitlab4j/api/models/PullMirror.java diff --git a/gitlab4j-api/src/main/java/org/gitlab4j/api/ProjectApi.java b/gitlab4j-api/src/main/java/org/gitlab4j/api/ProjectApi.java index c431dec5..1f89f34f 100644 --- a/gitlab4j-api/src/main/java/org/gitlab4j/api/ProjectApi.java +++ b/gitlab4j-api/src/main/java/org/gitlab4j/api/ProjectApi.java @@ -64,6 +64,7 @@ import org.gitlab4j.api.models.ProjectGroupsFilter; import org.gitlab4j.api.models.ProjectHook; import org.gitlab4j.api.models.ProjectUser; +import org.gitlab4j.api.models.PullMirror; import org.gitlab4j.api.models.PushRules; import org.gitlab4j.api.models.RemoteMirror; import org.gitlab4j.api.models.Snippet; @@ -4428,6 +4429,41 @@ public void deleteCustomAttribute(final Object projectIdOrPath, final String key delete(Response.Status.OK, null, "projects", getProjectIdOrPath(projectIdOrPath), "custom_attributes", key); } + /** + * Get all pull mirrors for the specified project. + * + *
GitLab Endpoint: GET /projects/:id/mirror/pull
+ * + * @param projectIdOrPath the project in the form of a Long(ID), String(path), or Project instance + * @return a list of project's pull mirrors + * @throws GitLabApiException if any exception occurs + */ + public List getPullMirrors(final Object projectIdOrPath) throws GitLabApiException { + return (getPullMirrors(projectIdOrPath, getDefaultPerPage()).all()); + } + + /** + * Get a Pager of pull mirrors for the specified project. + * + *
GitLab Endpoint: GET /projects/:id/mirror/pull
+ * + * @param projectIdOrPath the project in the form of an Long(ID), String(path), or Project instance + * @param itemsPerPage the number of items per page + * @return a Pager of project's pull mirrors + * @throws GitLabApiException if any exception occurs + */ + public Pager getPullMirrors(final Object projectIdOrPath, int itemsPerPage) throws GitLabApiException { + return new Pager( + this, + PullMirror.class, + itemsPerPage, + null, + "projects", + getProjectIdOrPath(projectIdOrPath), + "mirror", + "pull"); + } + /** * Get all remote mirrors and their statuses for the specified project. * diff --git a/gitlab4j-models/src/main/java/org/gitlab4j/api/models/PullMirror.java b/gitlab4j-models/src/main/java/org/gitlab4j/api/models/PullMirror.java new file mode 100644 index 00000000..5e84aa1b --- /dev/null +++ b/gitlab4j-models/src/main/java/org/gitlab4j/api/models/PullMirror.java @@ -0,0 +1,124 @@ +package org.gitlab4j.api.models; + +import java.io.Serializable; +import java.util.Date; + +import org.gitlab4j.models.utils.JacksonJson; + +public class PullMirror implements Serializable { + private static final long serialVersionUID = 1L; + + private Long id; + private String lastError; + private Date lastSuccessfulUpdateAt; + private Date lastUpdateAt; + private Date lastUpdateStartedAt; + private String updatedStatus; + private String url; + private Boolean enabled; + private Boolean mirrorTriggerBuilds; + private Boolean onlyMirrorProtectedBranches; + private Boolean mirrorOverwritesDivergedBranches; + private String mirrorBranchRegex; + + public Long getId() { + return id; + } + + public void setId(Long id) { + this.id = id; + } + + public String getLastError() { + return lastError; + } + + public void setLastError(String lastError) { + this.lastError = lastError; + } + + public Date getLastSuccessfulUpdateAt() { + return lastSuccessfulUpdateAt; + } + + public void setLastSuccessfulUpdateAt(Date lastSuccessfulUpdateAt) { + this.lastSuccessfulUpdateAt = lastSuccessfulUpdateAt; + } + + public Date getLastUpdateAt() { + return lastUpdateAt; + } + + public void setLastUpdateAt(Date lastUpdateAt) { + this.lastUpdateAt = lastUpdateAt; + } + + public Date getLastUpdateStartedAt() { + return lastUpdateStartedAt; + } + + public void setLastUpdateStartedAt(Date lastUpdateStartedAt) { + this.lastUpdateStartedAt = lastUpdateStartedAt; + } + + public String getUpdatedStatus() { + return updatedStatus; + } + + public void setUpdatedStatus(String updatedStatus) { + this.updatedStatus = updatedStatus; + } + + public String getUrl() { + return url; + } + + public void setUrl(String url) { + this.url = url; + } + + public Boolean getEnabled() { + return enabled; + } + + public void setEnabled(Boolean enabled) { + this.enabled = enabled; + } + + public Boolean getMirrorTriggerBuilds() { + return mirrorTriggerBuilds; + } + + public void setMirrorTriggerBuilds(Boolean mirrorTriggerBuilds) { + this.mirrorTriggerBuilds = mirrorTriggerBuilds; + } + + public Boolean getOnlyMirrorProtectedBranches() { + return onlyMirrorProtectedBranches; + } + + public void setOnlyMirrorProtectedBranches(Boolean onlyMirrorProtectedBranches) { + this.onlyMirrorProtectedBranches = onlyMirrorProtectedBranches; + } + + public Boolean getMirrorOverwritesDivergedBranches() { + return mirrorOverwritesDivergedBranches; + } + + public void setMirrorOverwritesDivergedBranches(Boolean mirrorOverwritesDivergedBranches) { + this.mirrorOverwritesDivergedBranches = mirrorOverwritesDivergedBranches; + } + + public String getMirrorBranchRegex() { + return mirrorBranchRegex; + } + + public void setMirrorBranchRegex(String mirrorBranchRegex) { + this.mirrorBranchRegex = mirrorBranchRegex; + } + + @Override + public String toString() { + return JacksonJson.toJsonString(this); + } +} From 4de4e0a1ab9aabe043febc9886a1a4d11322b883 Mon Sep 17 00:00:00 2001 From: Jeremie Bresson Date: Thu, 28 Aug 2025 08:01:33 +0200 Subject: [PATCH 2/2] Add a test and fix the attribute name --- .../java/org/gitlab4j/api/models/PullMirror.java | 10 +++++----- .../org/gitlab4j/models/TestGitLabApiBeans.java | 6 ++++++ .../resources/org/gitlab4j/models/pull-mirror.json | 14 ++++++++++++++ 3 files changed, 25 insertions(+), 5 deletions(-) create mode 100644 gitlab4j-models/src/test/resources/org/gitlab4j/models/pull-mirror.json diff --git a/gitlab4j-models/src/main/java/org/gitlab4j/api/models/PullMirror.java b/gitlab4j-models/src/main/java/org/gitlab4j/api/models/PullMirror.java index 5e84aa1b..e1b459ea 100644 --- a/gitlab4j-models/src/main/java/org/gitlab4j/api/models/PullMirror.java +++ b/gitlab4j-models/src/main/java/org/gitlab4j/api/models/PullMirror.java @@ -13,7 +13,7 @@ public class PullMirror implements Serializable { private Date lastSuccessfulUpdateAt; private Date lastUpdateAt; private Date lastUpdateStartedAt; - private String updatedStatus; + private String updateStatus; private String url; private Boolean enabled; private Boolean mirrorTriggerBuilds; @@ -61,12 +61,12 @@ public void setLastUpdateStartedAt(Date lastUpdateStartedAt) { this.lastUpdateStartedAt = lastUpdateStartedAt; } - public String getUpdatedStatus() { - return updatedStatus; + public String getUpdateStatus() { + return updateStatus; } - public void setUpdatedStatus(String updatedStatus) { - this.updatedStatus = updatedStatus; + public void setUpdateStatus(String updateStatus) { + this.updateStatus = updateStatus; } public String getUrl() { diff --git a/gitlab4j-models/src/test/java/org/gitlab4j/models/TestGitLabApiBeans.java b/gitlab4j-models/src/test/java/org/gitlab4j/models/TestGitLabApiBeans.java index 2ceb4fe2..a2b8720a 100644 --- a/gitlab4j-models/src/test/java/org/gitlab4j/models/TestGitLabApiBeans.java +++ b/gitlab4j-models/src/test/java/org/gitlab4j/models/TestGitLabApiBeans.java @@ -507,6 +507,12 @@ public void testPushRule() throws Exception { assertTrue(compareJson(pushRule, "push-rule.json")); } + @Test + public void testPullMirror() throws Exception { + PullMirror value = unmarshalResource(PullMirror.class, "pull-mirror.json"); + assertTrue(compareJson(value, "pull-mirror.json")); + } + @Test public void testRegistryRepositories() throws Exception { List repos = unmarshalResourceList(RegistryRepository.class, "registry-repositories.json"); diff --git a/gitlab4j-models/src/test/resources/org/gitlab4j/models/pull-mirror.json b/gitlab4j-models/src/test/resources/org/gitlab4j/models/pull-mirror.json new file mode 100644 index 00000000..66067db5 --- /dev/null +++ b/gitlab4j-models/src/test/resources/org/gitlab4j/models/pull-mirror.json @@ -0,0 +1,14 @@ +{ + "id": 101486, + "last_error": "FOO", + "last_successful_update_at": "2020-01-06T17:32:02.823Z", + "last_update_at": "2020-01-06T17:32:02.823Z", + "last_update_started_at": "2020-01-06T17:31:55.864Z", + "update_status": "finished", + "url": "https://*****:*****@gitlab.com/gitlab-org/security/gitlab.git", + "enabled": true, + "mirror_trigger_builds": true, + "only_mirror_protected_branches": true, + "mirror_overwrites_diverged_branches": false, + "mirror_branch_regex": "[a-z]+" +} \ No newline at end of file