Skip to content

Commit 7bd1d19

Browse files
Jony-Jasjmini
andauthored
Add Pull mirror API (#1271)
Fixes #1227 --------- Co-authored-by: Jeremie Bresson <[email protected]>
1 parent 952ce31 commit 7bd1d19

File tree

4 files changed

+180
-0
lines changed

4 files changed

+180
-0
lines changed

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

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -64,6 +64,7 @@
6464
import org.gitlab4j.api.models.ProjectGroupsFilter;
6565
import org.gitlab4j.api.models.ProjectHook;
6666
import org.gitlab4j.api.models.ProjectUser;
67+
import org.gitlab4j.api.models.PullMirror;
6768
import org.gitlab4j.api.models.PushRules;
6869
import org.gitlab4j.api.models.RemoteMirror;
6970
import org.gitlab4j.api.models.Snippet;
@@ -4470,6 +4471,41 @@ public void deleteCustomAttribute(final Object projectIdOrPath, final String key
44704471
delete(Response.Status.OK, null, "projects", getProjectIdOrPath(projectIdOrPath), "custom_attributes", key);
44714472
}
44724473

4474+
/**
4475+
* Get all pull mirrors for the specified project.
4476+
*
4477+
* <pre><code>GitLab Endpoint: GET /projects/:id/mirror/pull</code></pre>
4478+
*
4479+
* @param projectIdOrPath the project in the form of a Long(ID), String(path), or Project instance
4480+
* @return a list of project's pull mirrors
4481+
* @throws GitLabApiException if any exception occurs
4482+
*/
4483+
public List<PullMirror> getPullMirrors(final Object projectIdOrPath) throws GitLabApiException {
4484+
return (getPullMirrors(projectIdOrPath, getDefaultPerPage()).all());
4485+
}
4486+
4487+
/**
4488+
* Get a Pager of pull mirrors for the specified project.
4489+
*
4490+
* <pre><code>GitLab Endpoint: GET /projects/:id/mirror/pull</code></pre>
4491+
*
4492+
* @param projectIdOrPath the project in the form of an Long(ID), String(path), or Project instance
4493+
* @param itemsPerPage the number of items per page
4494+
* @return a Pager of project's pull mirrors
4495+
* @throws GitLabApiException if any exception occurs
4496+
*/
4497+
public Pager<PullMirror> getPullMirrors(final Object projectIdOrPath, int itemsPerPage) throws GitLabApiException {
4498+
return new Pager<PullMirror>(
4499+
this,
4500+
PullMirror.class,
4501+
itemsPerPage,
4502+
null,
4503+
"projects",
4504+
getProjectIdOrPath(projectIdOrPath),
4505+
"mirror",
4506+
"pull");
4507+
}
4508+
44734509
/**
44744510
* Get all remote mirrors and their statuses for the specified project.
44754511
*
Lines changed: 124 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,124 @@
1+
package org.gitlab4j.api.models;
2+
3+
import java.io.Serializable;
4+
import java.util.Date;
5+
6+
import org.gitlab4j.models.utils.JacksonJson;
7+
8+
public class PullMirror implements Serializable {
9+
private static final long serialVersionUID = 1L;
10+
11+
private Long id;
12+
private String lastError;
13+
private Date lastSuccessfulUpdateAt;
14+
private Date lastUpdateAt;
15+
private Date lastUpdateStartedAt;
16+
private String updateStatus;
17+
private String url;
18+
private Boolean enabled;
19+
private Boolean mirrorTriggerBuilds;
20+
private Boolean onlyMirrorProtectedBranches;
21+
private Boolean mirrorOverwritesDivergedBranches;
22+
private String mirrorBranchRegex;
23+
24+
public Long getId() {
25+
return id;
26+
}
27+
28+
public void setId(Long id) {
29+
this.id = id;
30+
}
31+
32+
public String getLastError() {
33+
return lastError;
34+
}
35+
36+
public void setLastError(String lastError) {
37+
this.lastError = lastError;
38+
}
39+
40+
public Date getLastSuccessfulUpdateAt() {
41+
return lastSuccessfulUpdateAt;
42+
}
43+
44+
public void setLastSuccessfulUpdateAt(Date lastSuccessfulUpdateAt) {
45+
this.lastSuccessfulUpdateAt = lastSuccessfulUpdateAt;
46+
}
47+
48+
public Date getLastUpdateAt() {
49+
return lastUpdateAt;
50+
}
51+
52+
public void setLastUpdateAt(Date lastUpdateAt) {
53+
this.lastUpdateAt = lastUpdateAt;
54+
}
55+
56+
public Date getLastUpdateStartedAt() {
57+
return lastUpdateStartedAt;
58+
}
59+
60+
public void setLastUpdateStartedAt(Date lastUpdateStartedAt) {
61+
this.lastUpdateStartedAt = lastUpdateStartedAt;
62+
}
63+
64+
public String getUpdateStatus() {
65+
return updateStatus;
66+
}
67+
68+
public void setUpdateStatus(String updateStatus) {
69+
this.updateStatus = updateStatus;
70+
}
71+
72+
public String getUrl() {
73+
return url;
74+
}
75+
76+
public void setUrl(String url) {
77+
this.url = url;
78+
}
79+
80+
public Boolean getEnabled() {
81+
return enabled;
82+
}
83+
84+
public void setEnabled(Boolean enabled) {
85+
this.enabled = enabled;
86+
}
87+
88+
public Boolean getMirrorTriggerBuilds() {
89+
return mirrorTriggerBuilds;
90+
}
91+
92+
public void setMirrorTriggerBuilds(Boolean mirrorTriggerBuilds) {
93+
this.mirrorTriggerBuilds = mirrorTriggerBuilds;
94+
}
95+
96+
public Boolean getOnlyMirrorProtectedBranches() {
97+
return onlyMirrorProtectedBranches;
98+
}
99+
100+
public void setOnlyMirrorProtectedBranches(Boolean onlyMirrorProtectedBranches) {
101+
this.onlyMirrorProtectedBranches = onlyMirrorProtectedBranches;
102+
}
103+
104+
public Boolean getMirrorOverwritesDivergedBranches() {
105+
return mirrorOverwritesDivergedBranches;
106+
}
107+
108+
public void setMirrorOverwritesDivergedBranches(Boolean mirrorOverwritesDivergedBranches) {
109+
this.mirrorOverwritesDivergedBranches = mirrorOverwritesDivergedBranches;
110+
}
111+
112+
public String getMirrorBranchRegex() {
113+
return mirrorBranchRegex;
114+
}
115+
116+
public void setMirrorBranchRegex(String mirrorBranchRegex) {
117+
this.mirrorBranchRegex = mirrorBranchRegex;
118+
}
119+
120+
@Override
121+
public String toString() {
122+
return JacksonJson.toJsonString(this);
123+
}
124+
}

gitlab4j-models/src/test/java/org/gitlab4j/models/TestGitLabApiBeans.java

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -507,6 +507,12 @@ public void testPushRule() throws Exception {
507507
assertTrue(compareJson(pushRule, "push-rule.json"));
508508
}
509509

510+
@Test
511+
public void testPullMirror() throws Exception {
512+
PullMirror value = unmarshalResource(PullMirror.class, "pull-mirror.json");
513+
assertTrue(compareJson(value, "pull-mirror.json"));
514+
}
515+
510516
@Test
511517
public void testRegistryRepositories() throws Exception {
512518
List<RegistryRepository> repos = unmarshalResourceList(RegistryRepository.class, "registry-repositories.json");
Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
{
2+
"id": 101486,
3+
"last_error": "FOO",
4+
"last_successful_update_at": "2020-01-06T17:32:02.823Z",
5+
"last_update_at": "2020-01-06T17:32:02.823Z",
6+
"last_update_started_at": "2020-01-06T17:31:55.864Z",
7+
"update_status": "finished",
8+
"url": "https://*****:*****@gitlab.com/gitlab-org/security/gitlab.git",
9+
"enabled": true,
10+
"mirror_trigger_builds": true,
11+
"only_mirror_protected_branches": true,
12+
"mirror_overwrites_diverged_branches": false,
13+
"mirror_branch_regex": "[a-z]+"
14+
}

0 commit comments

Comments
 (0)