Skip to content

Add method for "/user/runners" #1264

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 16 additions & 0 deletions gitlab4j-api/src/main/java/org/gitlab4j/api/UserApi.java
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,8 @@
import jakarta.ws.rs.core.Response;

import org.gitlab4j.api.models.Associations;
import org.gitlab4j.api.models.CreateRunnerParams;
import org.gitlab4j.api.models.CreateRunnerResponse;
import org.gitlab4j.api.models.CustomAttribute;
import org.gitlab4j.api.models.Email;
import org.gitlab4j.api.models.Exists;
Expand Down Expand Up @@ -1584,4 +1586,18 @@ public boolean exists(String username) throws GitLabApiException {
throw new GitLabApiException(e);
}
}

/**
* Create a runner linked to the current user.
*
* <pre><code>GitLab Endpoint: POST /user/runners</code></pre>
*
* @param params a CreateRunnerParams instance holding the parameters for the runner creation
* @return creation response, be sure to copy or save the token in the response, the value cannot be retrieved again.
* @throws GitLabApiException
*/
public CreateRunnerResponse createRunner(CreateRunnerParams params) throws GitLabApiException {
Response response = post(Response.Status.OK, new GitLabApiForm(params.getForm()).asMap(), "user", "runners");
return response.readEntity(CreateRunnerResponse.class);
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,100 @@
package org.gitlab4j.api.models;

import java.io.Serializable;
import java.util.List;

import org.gitlab4j.api.models.Runner.RunnerType;
import org.gitlab4j.models.GitLabForm;
import org.gitlab4j.models.utils.JacksonJson;

public class CreateRunnerParams implements Serializable {
private static final long serialVersionUID = 1L;

private RunnerType runnerType;
private Long groupId;
private Long projectId;
private String description;
private Boolean paused;
private Boolean locked;
private Boolean runUntagged;
private List<String> tagList;
private String accessLevel;
private Integer maximumTimeout;
private String maintenanceNote;

public GitLabForm getForm() {

return new GitLabForm()
.withParam("runner_type", runnerType, true)
.withParam("group_id", groupId)
.withParam("project_id", projectId)
.withParam("description", description)
.withParam("paused", paused)
.withParam("locked", locked)
.withParam("run_untagged", runUntagged)
.withParam("tag_list", tagList)
.withParam("access_level", accessLevel)
.withParam("maximum_timeout", maximumTimeout)
.withParam("maintenance_note", maintenanceNote);
}

public CreateRunnerParams withRunnerType(RunnerType runnerType) {
this.runnerType = runnerType;
return this;
}

public CreateRunnerParams withGroupId(Long groupId) {
this.groupId = groupId;
return this;
}

public CreateRunnerParams withProjectId(Long projectId) {
this.projectId = projectId;
return this;
}

public CreateRunnerParams withDescription(String description) {
this.description = description;
return this;
}

public CreateRunnerParams withPaused(Boolean paused) {
this.paused = paused;
return this;
}

public CreateRunnerParams withLocked(Boolean locked) {
this.locked = locked;
return this;
}

public CreateRunnerParams withRunUntagged(Boolean runUntagged) {
this.runUntagged = runUntagged;
return this;
}

public CreateRunnerParams withTagList(List<String> tagList) {
this.tagList = tagList;
return this;
}

public CreateRunnerParams withAccessLevel(String accessLevel) {
this.accessLevel = accessLevel;
return this;
}

public CreateRunnerParams withMaximumTimeout(Integer maximumTimeout) {
this.maximumTimeout = maximumTimeout;
return this;
}

public CreateRunnerParams withMaintenanceNote(String maintenanceNote) {
this.maintenanceNote = maintenanceNote;
return this;
}

@Override
public String toString() {
return (JacksonJson.toJsonString(this));
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
package org.gitlab4j.api.models;

import java.io.Serializable;
import java.util.Date;

import org.gitlab4j.models.utils.JacksonJson;

public class CreateRunnerResponse implements Serializable {
private static final long serialVersionUID = 1L;

private Long id;
private String token;
private Date tokenExpiresAt;

public Long getId() {
return id;
}

public void setId(Long id) {
this.id = id;
}

public String getToken() {
return token;
}

public void setToken(String token) {
this.token = token;
}

public Date getTokenExpiresAt() {
return tokenExpiresAt;
}

public void setTokenExpiresAt(Date tokenExpiresAt) {
this.tokenExpiresAt = tokenExpiresAt;
}

@Override
public String toString() {
return (JacksonJson.toJsonString(this));
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@

import java.io.Serializable;

import org.gitlab4j.models.utils.JacksonJson;

public class OauthTokenResponse implements Serializable {
private static final long serialVersionUID = 1L;

Expand Down Expand Up @@ -50,4 +52,9 @@ public Long getCreatedAt() {
public void setCreatedAt(Long createdAt) {
this.createdAt = createdAt;
}

@Override
public String toString() {
return (JacksonJson.toJsonString(this));
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -111,6 +111,12 @@ public void testBranch() throws Exception {
assertTrue(!Branch.isValid(branch));
}

@Test
public void testCreateRunnerResponse() throws Exception {
CreateRunnerResponse r = unmarshalResource(CreateRunnerResponse.class, "created-runner-response.json");
assertTrue(compareJson(r, "created-runner-response.json"));
}

@Test
public void testCreatedChildEpic() throws Exception {
CreatedChildEpic childEpic = unmarshalResource(CreatedChildEpic.class, "created-child-epic.json");
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
{
"id": 9171,
"token": "abcd1245"
}
Loading