Skip to content

Commit 0955ca7

Browse files
committed
Add GitlabAPI#getProjectPipelines()
1 parent 6dcc241 commit 0955ca7

File tree

2 files changed

+142
-0
lines changed

2 files changed

+142
-0
lines changed

src/main/java/org/gitlab/api/GitlabAPI.java

Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66
import org.gitlab.api.http.Query;
77
import org.gitlab.api.models.*;
88
import org.gitlab.api.query.PaginationQuery;
9+
import org.gitlab.api.query.PipelinesQuery;
910
import org.gitlab.api.query.ProjectsQuery;
1011
import org.slf4j.Logger;
1112
import org.slf4j.LoggerFactory;
@@ -1011,6 +1012,47 @@ public GitlabPipeline getProjectPipeline(Integer projectId, Integer pipelineId)
10111012
return retrieve().to(tailUrl, GitlabPipeline.class);
10121013
}
10131014

1015+
/**
1016+
* Get a list of a project's pipelines in Gitlab
1017+
*
1018+
* @param project the project
1019+
* @return A list of project pipelines
1020+
*/
1021+
public List<GitlabPipeline> getProjectPipelines(GitlabProject project) {
1022+
return getProjectPipelines(project.getId());
1023+
}
1024+
1025+
/**
1026+
* Get a list of a project's pipelines in Gitlab
1027+
*
1028+
* @param projectId the project id
1029+
* @return A list of project pipelines
1030+
*/
1031+
public List<GitlabPipeline> getProjectPipelines(Integer projectId) {
1032+
return getProjectPipelines(projectId, new PipelinesQuery().withPerPage(PaginationQuery.MAX_ITEMS_PER_PAGE));
1033+
}
1034+
1035+
/**
1036+
* Get a list of a project's pipelines in Gitlab
1037+
*
1038+
* @param project the project
1039+
* @return A list of project pipelines
1040+
*/
1041+
public List<GitlabPipeline> getProjectPipelines(GitlabProject project, PipelinesQuery pipelinesQuery) {
1042+
return getProjectPipelines(project.getId(), pipelinesQuery);
1043+
}
1044+
1045+
/**
1046+
* Get a list of a project's pipelines in Gitlab
1047+
*
1048+
* @param projectId the project id
1049+
* @return A list of project pipelines
1050+
*/
1051+
public List<GitlabPipeline> getProjectPipelines(Integer projectId, PipelinesQuery pipelinesQuery) {
1052+
String tailUrl = GitlabProject.URL + "/" + sanitizeProjectId(projectId) + GitlabPipeline.URL + pipelinesQuery;
1053+
return retrieve().getAll(tailUrl, GitlabPipeline[].class);
1054+
}
1055+
10141056
/**
10151057
* Gets a list of a project's jobs in Gitlab
10161058
*
Lines changed: 100 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,100 @@
1+
package org.gitlab.api.query;
2+
3+
import java.io.UnsupportedEncodingException;
4+
5+
public class PipelinesQuery extends PaginationQuery {
6+
7+
public void setScope(String scope) throws UnsupportedEncodingException {
8+
appendIf("scope", scope);
9+
}
10+
11+
public PipelinesQuery withScope(String scope) throws UnsupportedEncodingException {
12+
this.setScope(scope);
13+
return this;
14+
}
15+
16+
public void setStatus(String status) throws UnsupportedEncodingException {
17+
appendIf("status", status);
18+
}
19+
20+
public PipelinesQuery withStatus(String status) throws UnsupportedEncodingException {
21+
this.setStatus(status);
22+
return this;
23+
}
24+
25+
public void setRef(String ref) throws UnsupportedEncodingException {
26+
appendIf("ref", ref);
27+
}
28+
29+
public PipelinesQuery withRef(String ref) throws UnsupportedEncodingException {
30+
this.setRef(ref);
31+
return this;
32+
}
33+
34+
public void setSha(String sha) throws UnsupportedEncodingException {
35+
appendIf("sha", sha);
36+
}
37+
38+
public PipelinesQuery withSha(String sha) throws UnsupportedEncodingException {
39+
this.setSha(sha);
40+
return this;
41+
}
42+
43+
public void setYamlErrors(Boolean yamlErrors) throws UnsupportedEncodingException {
44+
appendIf("yaml_errors", yamlErrors);
45+
}
46+
47+
public PipelinesQuery withYamlErrors(Boolean yamlErrors) throws UnsupportedEncodingException {
48+
this.setYamlErrors(yamlErrors);
49+
return this;
50+
}
51+
52+
public void setName(String name) throws UnsupportedEncodingException {
53+
appendIf("name", name);
54+
}
55+
56+
public PipelinesQuery withName(String name) throws UnsupportedEncodingException {
57+
this.setName(name);
58+
return this;
59+
}
60+
61+
public void setUsername(String username) throws UnsupportedEncodingException {
62+
appendIf("username", username);
63+
}
64+
65+
public PipelinesQuery withUsername(String username) throws UnsupportedEncodingException {
66+
this.setUsername(username);
67+
return this;
68+
}
69+
70+
public void setOrderBy(String orderBy) throws UnsupportedEncodingException {
71+
appendIf("order_by", orderBy);
72+
}
73+
74+
public PipelinesQuery withOrderBy(String orderBy) throws UnsupportedEncodingException {
75+
this.setOrderBy(orderBy);
76+
return this;
77+
}
78+
79+
public void setSort(String sort) throws UnsupportedEncodingException {
80+
appendIf("sort", sort);
81+
}
82+
83+
public PipelinesQuery withSort(String sort) throws UnsupportedEncodingException {
84+
this.setSort(sort);
85+
return this;
86+
}
87+
88+
@Override
89+
public PipelinesQuery withPage(int page) {
90+
super.withPage(page);
91+
return this;
92+
}
93+
94+
@Override
95+
public PipelinesQuery withPerPage(int perPage) {
96+
super.withPerPage(perPage);
97+
return this;
98+
}
99+
100+
}

0 commit comments

Comments
 (0)