Skip to content

Commit 754ff4d

Browse files
authored
Add method for "/user/runners" (#1264)
1 parent 39cbdc7 commit 754ff4d

File tree

6 files changed

+176
-0
lines changed

6 files changed

+176
-0
lines changed

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

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,8 @@
1313
import jakarta.ws.rs.core.Response;
1414

1515
import org.gitlab4j.api.models.Associations;
16+
import org.gitlab4j.api.models.CreateRunnerParams;
17+
import org.gitlab4j.api.models.CreateRunnerResponse;
1618
import org.gitlab4j.api.models.CustomAttribute;
1719
import org.gitlab4j.api.models.Email;
1820
import org.gitlab4j.api.models.Exists;
@@ -1584,4 +1586,18 @@ public boolean exists(String username) throws GitLabApiException {
15841586
throw new GitLabApiException(e);
15851587
}
15861588
}
1589+
1590+
/**
1591+
* Create a runner linked to the current user.
1592+
*
1593+
* <pre><code>GitLab Endpoint: POST /user/runners</code></pre>
1594+
*
1595+
* @param params a CreateRunnerParams instance holding the parameters for the runner creation
1596+
* @return creation response, be sure to copy or save the token in the response, the value cannot be retrieved again.
1597+
* @throws GitLabApiException
1598+
*/
1599+
public CreateRunnerResponse createRunner(CreateRunnerParams params) throws GitLabApiException {
1600+
Response response = post(Response.Status.OK, new GitLabApiForm(params.getForm()).asMap(), "user", "runners");
1601+
return response.readEntity(CreateRunnerResponse.class);
1602+
}
15871603
}
Lines changed: 100 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,100 @@
1+
package org.gitlab4j.api.models;
2+
3+
import java.io.Serializable;
4+
import java.util.List;
5+
6+
import org.gitlab4j.api.models.Runner.RunnerType;
7+
import org.gitlab4j.models.GitLabForm;
8+
import org.gitlab4j.models.utils.JacksonJson;
9+
10+
public class CreateRunnerParams implements Serializable {
11+
private static final long serialVersionUID = 1L;
12+
13+
private RunnerType runnerType;
14+
private Long groupId;
15+
private Long projectId;
16+
private String description;
17+
private Boolean paused;
18+
private Boolean locked;
19+
private Boolean runUntagged;
20+
private List<String> tagList;
21+
private String accessLevel;
22+
private Integer maximumTimeout;
23+
private String maintenanceNote;
24+
25+
public GitLabForm getForm() {
26+
27+
return new GitLabForm()
28+
.withParam("runner_type", runnerType, true)
29+
.withParam("group_id", groupId)
30+
.withParam("project_id", projectId)
31+
.withParam("description", description)
32+
.withParam("paused", paused)
33+
.withParam("locked", locked)
34+
.withParam("run_untagged", runUntagged)
35+
.withParam("tag_list", tagList)
36+
.withParam("access_level", accessLevel)
37+
.withParam("maximum_timeout", maximumTimeout)
38+
.withParam("maintenance_note", maintenanceNote);
39+
}
40+
41+
public CreateRunnerParams withRunnerType(RunnerType runnerType) {
42+
this.runnerType = runnerType;
43+
return this;
44+
}
45+
46+
public CreateRunnerParams withGroupId(Long groupId) {
47+
this.groupId = groupId;
48+
return this;
49+
}
50+
51+
public CreateRunnerParams withProjectId(Long projectId) {
52+
this.projectId = projectId;
53+
return this;
54+
}
55+
56+
public CreateRunnerParams withDescription(String description) {
57+
this.description = description;
58+
return this;
59+
}
60+
61+
public CreateRunnerParams withPaused(Boolean paused) {
62+
this.paused = paused;
63+
return this;
64+
}
65+
66+
public CreateRunnerParams withLocked(Boolean locked) {
67+
this.locked = locked;
68+
return this;
69+
}
70+
71+
public CreateRunnerParams withRunUntagged(Boolean runUntagged) {
72+
this.runUntagged = runUntagged;
73+
return this;
74+
}
75+
76+
public CreateRunnerParams withTagList(List<String> tagList) {
77+
this.tagList = tagList;
78+
return this;
79+
}
80+
81+
public CreateRunnerParams withAccessLevel(String accessLevel) {
82+
this.accessLevel = accessLevel;
83+
return this;
84+
}
85+
86+
public CreateRunnerParams withMaximumTimeout(Integer maximumTimeout) {
87+
this.maximumTimeout = maximumTimeout;
88+
return this;
89+
}
90+
91+
public CreateRunnerParams withMaintenanceNote(String maintenanceNote) {
92+
this.maintenanceNote = maintenanceNote;
93+
return this;
94+
}
95+
96+
@Override
97+
public String toString() {
98+
return (JacksonJson.toJsonString(this));
99+
}
100+
}
Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
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 CreateRunnerResponse implements Serializable {
9+
private static final long serialVersionUID = 1L;
10+
11+
private Long id;
12+
private String token;
13+
private Date tokenExpiresAt;
14+
15+
public Long getId() {
16+
return id;
17+
}
18+
19+
public void setId(Long id) {
20+
this.id = id;
21+
}
22+
23+
public String getToken() {
24+
return token;
25+
}
26+
27+
public void setToken(String token) {
28+
this.token = token;
29+
}
30+
31+
public Date getTokenExpiresAt() {
32+
return tokenExpiresAt;
33+
}
34+
35+
public void setTokenExpiresAt(Date tokenExpiresAt) {
36+
this.tokenExpiresAt = tokenExpiresAt;
37+
}
38+
39+
@Override
40+
public String toString() {
41+
return (JacksonJson.toJsonString(this));
42+
}
43+
}

gitlab4j-models/src/main/java/org/gitlab4j/api/models/OauthTokenResponse.java

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,8 @@
22

33
import java.io.Serializable;
44

5+
import org.gitlab4j.models.utils.JacksonJson;
6+
57
public class OauthTokenResponse implements Serializable {
68
private static final long serialVersionUID = 1L;
79

@@ -50,4 +52,9 @@ public Long getCreatedAt() {
5052
public void setCreatedAt(Long createdAt) {
5153
this.createdAt = createdAt;
5254
}
55+
56+
@Override
57+
public String toString() {
58+
return (JacksonJson.toJsonString(this));
59+
}
5360
}

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

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -111,6 +111,12 @@ public void testBranch() throws Exception {
111111
assertTrue(!Branch.isValid(branch));
112112
}
113113

114+
@Test
115+
public void testCreateRunnerResponse() throws Exception {
116+
CreateRunnerResponse r = unmarshalResource(CreateRunnerResponse.class, "created-runner-response.json");
117+
assertTrue(compareJson(r, "created-runner-response.json"));
118+
}
119+
114120
@Test
115121
public void testCreatedChildEpic() throws Exception {
116122
CreatedChildEpic childEpic = unmarshalResource(CreatedChildEpic.class, "created-child-epic.json");
Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
{
2+
"id": 9171,
3+
"token": "abcd1245"
4+
}

0 commit comments

Comments
 (0)