Skip to content

Commit 6d5edeb

Browse files
authored
Support for bridges in pipeline API (#1069)
--------- Co-authored-by: Salamon <[email protected]>
1 parent 793146e commit 6d5edeb

File tree

7 files changed

+374
-5
lines changed

7 files changed

+374
-5
lines changed

Diff for: src/main/java/org/gitlab4j/api/PipelineApi.java

+31
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@
99
import javax.ws.rs.core.GenericType;
1010
import javax.ws.rs.core.Response;
1111

12+
import org.gitlab4j.api.models.Bridge;
1213
import org.gitlab4j.api.models.Pipeline;
1314
import org.gitlab4j.api.models.PipelineFilter;
1415
import org.gitlab4j.api.models.PipelineSchedule;
@@ -856,4 +857,34 @@ public Pager<Variable> getPipelineVariables(Object projectIdOrPath, Long pipelin
856857
public Stream<Variable> getPipelineVariablesStream(Object projectIdOrPath, Long pipelineId) throws GitLabApiException {
857858
return (getPipelineVariables(projectIdOrPath, pipelineId, getDefaultPerPage()).stream());
858859
}
860+
861+
/**
862+
* Get a Pager of bridges in a pipeline.
863+
*
864+
* <pre><code>GitLab Endpoint: GET /projects/:id/pipelines/:pipeline_id/bridges </code></pre>
865+
*
866+
* @param projectIdOrPath id, path of the project, or a Project instance holding the project ID or path to get the pipelines for
867+
* @param pipelineId the pipeline ID to get the list of bridges for
868+
* @param itemsPerPage the number of Bridge instances that will be fetched per page
869+
* @return a list containing the bridges for the specified project ID and pipeline ID
870+
* @throws GitLabApiException if any exception occurs during execution
871+
*/
872+
public Pager<Bridge> getBridgesForPipeline(Object projectIdOrPath, long pipelineId, int itemsPerPage, JobScope scope) throws GitLabApiException {
873+
return (new Pager<>(this, Bridge.class, itemsPerPage, getDefaultPerPageParam(),
874+
"projects", getProjectIdOrPath(projectIdOrPath), "pipelines", pipelineId, "bridges", scope));
875+
}
876+
877+
/**
878+
* Get a Stream of bridges in a pipeline.
879+
* <pre><code>GitLab Endpoint: GET /projects/:id/pipelines/:pipeline_id/bridges</code></pre>
880+
*
881+
* @param projectIdOrPath id, path of the project, or a Project instance holding the project ID or path
882+
* @param pipelineId the pipeline ID to get the list of bridges for
883+
* @return a Stream containing the bridges for the specified project ID
884+
* @throws GitLabApiException if any exception occurs during execution
885+
*/
886+
public Stream<Bridge> getBridgesStream(Object projectIdOrPath, long pipelineId, JobScope scope) throws GitLabApiException {
887+
return (getBridgesForPipeline(projectIdOrPath, pipelineId, getDefaultPerPage(), scope).stream());
888+
}
889+
859890
}

Diff for: src/main/java/org/gitlab4j/api/models/Bridge.java

+185
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,185 @@
1+
package org.gitlab4j.api.models;
2+
3+
import org.gitlab4j.api.utils.JacksonJson;
4+
5+
import java.util.Date;
6+
7+
public class Bridge {
8+
private Commit commit;
9+
private boolean allowFailure;
10+
private Date createdAt;
11+
private Date startedAt;
12+
private Date finishedAt;
13+
private Date erasedAt;
14+
private Double duration;
15+
private Double queuedDuration;
16+
private int id;
17+
private String name;
18+
private String coverage;
19+
private Pipeline pipeline;
20+
private String ref;
21+
private String stage;
22+
private String status;
23+
private boolean tag;
24+
private String webUrl;
25+
private User user;
26+
private DownstreamPipeline downstreamPipeline;
27+
28+
public Commit getCommit() {
29+
return commit;
30+
}
31+
32+
public void setCommit(Commit commit) {
33+
this.commit = commit;
34+
}
35+
36+
public boolean isAllowFailure() {
37+
return allowFailure;
38+
}
39+
40+
public void setAllowFailure(boolean allowFailure) {
41+
this.allowFailure = allowFailure;
42+
}
43+
44+
public Date getCreatedAt() {
45+
return createdAt;
46+
}
47+
48+
public void setCreatedAt(Date createdAt) {
49+
this.createdAt = createdAt;
50+
}
51+
52+
public Date getStartedAt() {
53+
return startedAt;
54+
}
55+
56+
public void setStartedAt(Date startedAt) {
57+
this.startedAt = startedAt;
58+
}
59+
60+
public Date getFinishedAt() {
61+
return finishedAt;
62+
}
63+
64+
public void setFinishedAt(Date finishedAt) {
65+
this.finishedAt = finishedAt;
66+
}
67+
68+
public Date getErasedAt() {
69+
return erasedAt;
70+
}
71+
72+
public void setErasedAt(Date erasedAt) {
73+
this.erasedAt = erasedAt;
74+
}
75+
76+
public Double getDuration() {
77+
return duration;
78+
}
79+
80+
public void setDuration(Double duration) {
81+
this.duration = duration;
82+
}
83+
84+
public Double getQueuedDuration() {
85+
return queuedDuration;
86+
}
87+
88+
public void setQueuedDuration(Double queuedDuration) {
89+
this.queuedDuration = queuedDuration;
90+
}
91+
92+
public int getId() {
93+
return id;
94+
}
95+
96+
public void setId(int id) {
97+
this.id = id;
98+
}
99+
100+
public String getName() {
101+
return name;
102+
}
103+
104+
public void setName(String name) {
105+
this.name = name;
106+
}
107+
108+
public String getCoverage() {
109+
return coverage;
110+
}
111+
112+
public void setCoverage(String coverage) {
113+
this.coverage = coverage;
114+
}
115+
116+
public Pipeline getPipeline() {
117+
return pipeline;
118+
}
119+
120+
public void setPipeline(Pipeline pipeline) {
121+
this.pipeline = pipeline;
122+
}
123+
124+
public String getRef() {
125+
return ref;
126+
}
127+
128+
public void setRef(String ref) {
129+
this.ref = ref;
130+
}
131+
132+
public String getStage() {
133+
return stage;
134+
}
135+
136+
public void setStage(String stage) {
137+
this.stage = stage;
138+
}
139+
140+
public String getStatus() {
141+
return status;
142+
}
143+
144+
public void setStatus(String status) {
145+
this.status = status;
146+
}
147+
148+
public boolean isTag() {
149+
return tag;
150+
}
151+
152+
public void setTag(boolean tag) {
153+
this.tag = tag;
154+
}
155+
156+
public String getWebUrl() {
157+
return webUrl;
158+
}
159+
160+
public void setWebUrl(String webUrl) {
161+
this.webUrl = webUrl;
162+
}
163+
164+
public User getUser() {
165+
return user;
166+
}
167+
168+
public void setUser(User user) {
169+
this.user = user;
170+
}
171+
172+
public DownstreamPipeline getDownstreamPipeline() {
173+
return downstreamPipeline;
174+
}
175+
176+
public void setDownstreamPipeline(DownstreamPipeline downstreamPipeline) {
177+
this.downstreamPipeline = downstreamPipeline;
178+
}
179+
180+
@Override
181+
public String toString() {
182+
return (JacksonJson.toJsonString(this));
183+
}
184+
185+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,76 @@
1+
package org.gitlab4j.api.models;
2+
3+
import org.gitlab4j.api.utils.JacksonJson;
4+
5+
import java.util.Date;
6+
7+
public class DownstreamPipeline {
8+
private int id;
9+
private String sha;
10+
private String ref;
11+
private String status;
12+
private Date createdAt;
13+
private Date updatedAt;
14+
private String webUrl;
15+
16+
public int getId() {
17+
return id;
18+
}
19+
20+
public void setId(int id) {
21+
this.id = id;
22+
}
23+
24+
public String getSha() {
25+
return sha;
26+
}
27+
28+
public void setSha(String sha) {
29+
this.sha = sha;
30+
}
31+
32+
public String getRef() {
33+
return ref;
34+
}
35+
36+
public void setRef(String ref) {
37+
this.ref = ref;
38+
}
39+
40+
public String getStatus() {
41+
return status;
42+
}
43+
44+
public void setStatus(String status) {
45+
this.status = status;
46+
}
47+
48+
public Date getCreatedAt() {
49+
return createdAt;
50+
}
51+
52+
public void setCreatedAt(Date createdAt) {
53+
this.createdAt = createdAt;
54+
}
55+
56+
public Date getUpdatedAt() {
57+
return updatedAt;
58+
}
59+
60+
public void setUpdatedAt(Date updatedAt) {
61+
this.updatedAt = updatedAt;
62+
}
63+
64+
public String getWebUrl() {
65+
return webUrl;
66+
}
67+
68+
public void setWebUrl(String webUrl) {
69+
this.webUrl = webUrl;
70+
}
71+
72+
@Override
73+
public String toString() {
74+
return (JacksonJson.toJsonString(this));
75+
}
76+
}

Diff for: src/test/java/org/gitlab4j/api/TestGitLabApiBeans.java

+7
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,7 @@
4545
import org.gitlab4j.api.models.Blame;
4646
import org.gitlab4j.api.models.Board;
4747
import org.gitlab4j.api.models.Branch;
48+
import org.gitlab4j.api.models.Bridge;
4849
import org.gitlab4j.api.models.ChildEpic;
4950
import org.gitlab4j.api.models.GitLabCiTemplate;
5051
import org.gitlab4j.api.models.GitLabCiTemplateElement;
@@ -497,6 +498,12 @@ public void testJob() throws Exception {
497498
assertTrue(compareJson(job, "job.json"));
498499
}
499500

501+
@Test
502+
public void testBridge() throws Exception {
503+
Bridge bridge = unmarshalResource(Bridge.class, "bridge.json");
504+
assertTrue(compareJson(bridge, "bridge.json"));
505+
}
506+
500507
@Test
501508
public void testDeployKeys() throws Exception {
502509
List<DeployKey> deployKeys = unmarshalResourceList(DeployKey.class, "deploy-keys.json");

Diff for: src/test/java/org/gitlab4j/api/TestJobApi.java

+3
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,10 @@
2727
import static org.junit.jupiter.api.Assumptions.assumeTrue;
2828

2929
import java.util.List;
30+
import java.util.Set;
31+
import java.util.stream.Collectors;
3032

33+
import org.gitlab4j.api.models.Bridge;
3134
import org.gitlab4j.api.models.Job;
3235
import org.gitlab4j.api.models.Project;
3336
import org.junit.jupiter.api.AfterAll;

Diff for: src/test/java/org/gitlab4j/api/TestPipelineApi.java

+12-5
Original file line numberDiff line numberDiff line change
@@ -12,19 +12,18 @@
1212
import java.util.List;
1313
import java.util.Map;
1414
import java.util.Optional;
15+
import java.util.Set;
16+
import java.util.stream.Collectors;
1517
import java.util.stream.Stream;
1618

19+
import org.gitlab4j.api.models.Bridge;
1720
import org.gitlab4j.api.models.Pipeline;
1821
import org.gitlab4j.api.models.PipelineSchedule;
1922
import org.gitlab4j.api.models.Project;
2023
import org.gitlab4j.api.models.RepositoryFile;
2124
import org.gitlab4j.api.models.Trigger;
2225
import org.gitlab4j.api.models.Variable;
23-
import org.junit.jupiter.api.AfterAll;
24-
import org.junit.jupiter.api.BeforeAll;
25-
import org.junit.jupiter.api.BeforeEach;
26-
import org.junit.jupiter.api.Tag;
27-
import org.junit.jupiter.api.Test;
26+
import org.junit.jupiter.api.*;
2827
import org.junit.jupiter.api.extension.ExtendWith;
2928

3029
@Tag("integration")
@@ -350,4 +349,12 @@ public void testPipelineVariables() throws GitLabApiException {
350349
gitLabApi.getPipelineApi().deletePipeline(testProject, pipeline.getId());
351350
}
352351
}
352+
353+
@Test
354+
@Disabled("disable till 'Move the test infrastructure to Testcontainers #925'")
355+
public void testGetBridges() throws GitLabApiException {
356+
Set<Bridge> bridges = gitLabApi.getPipelineApi().getBridgesStream(testProject, 4L, Constants.JobScope.SUCCESS).collect(Collectors.toSet());
357+
assertNotNull(bridges);
358+
}
359+
353360
}

0 commit comments

Comments
 (0)