code
stringlengths 73
34.1k
| label
stringclasses 1
value |
|---|---|
public Milestone updateMilestone(Object projectIdOrPath, Integer milestoneId, String title, String description,
Date dueDate, Date startDate, MilestoneState milestoneState) throws GitLabApiException {
if (milestoneId == null) {
throw new RuntimeException("milestoneId cannot be null");
}
GitLabApiForm formData = new GitLabApiForm()
.withParam("title", title, true)
.withParam("description", description)
.withParam("due_date", dueDate)
.withParam("start_date", startDate)
.withParam("state_event", milestoneState);
Response response = put(Response.Status.OK, formData.asMap(),
"projects", getProjectIdOrPath(projectIdOrPath), "milestones", milestoneId);
return (response.readEntity(Milestone.class));
}
|
java
|
public List<Issue> getIssues(int page, int perPage) throws GitLabApiException {
Response response = get(Response.Status.OK, getPageQueryParams(page, perPage), "issues");
return (response.readEntity(new GenericType<List<Issue>>() {}));
}
|
java
|
public Pager<Issue> getIssues(int itemsPerPage) throws GitLabApiException {
return (new Pager<Issue>(this, Issue.class, itemsPerPage, null, "issues"));
}
|
java
|
public Pager<Issue> getIssues(Object projectIdOrPath, int itemsPerPage) throws GitLabApiException {
return (new Pager<Issue>(this, Issue.class, itemsPerPage, null, "projects", getProjectIdOrPath(projectIdOrPath), "issues"));
}
|
java
|
public Pager<Issue> getIssues(IssueFilter filter, int itemsPerPage) throws GitLabApiException {
GitLabApiForm formData = filter.getQueryParams();
return (new Pager<Issue>(this, Issue.class, itemsPerPage, formData.asMap(), "issues"));
}
|
java
|
public Issue getIssue(Object projectIdOrPath, Integer issueIid) throws GitLabApiException {
Response response = get(Response.Status.OK, getDefaultPerPageParam(),
"projects", getProjectIdOrPath(projectIdOrPath), "issues", issueIid);
return (response.readEntity(Issue.class));
}
|
java
|
public Optional<Issue> getOptionalIssue(Object projectIdOrPath, Integer issueIid) {
try {
return (Optional.ofNullable(getIssue(projectIdOrPath, issueIid)));
} catch (GitLabApiException glae) {
return (GitLabApi.createOptionalFromException(glae));
}
}
|
java
|
public Issue closeIssue(Object projectIdOrPath, Integer issueIid) throws GitLabApiException {
if (issueIid == null) {
throw new RuntimeException("issue IID cannot be null");
}
GitLabApiForm formData = new GitLabApiForm().withParam("state_event", StateEvent.CLOSE);
Response response = put(Response.Status.OK, formData.asMap(), "projects", getProjectIdOrPath(projectIdOrPath), "issues", issueIid);
return (response.readEntity(Issue.class));
}
|
java
|
public Issue updateIssue(Object projectIdOrPath, Integer issueIid, String title, String description, Boolean confidential, List<Integer> assigneeIds,
Integer milestoneId, String labels, StateEvent stateEvent, Date updatedAt, Date dueDate) throws GitLabApiException {
if (issueIid == null) {
throw new RuntimeException("issue IID cannot be null");
}
GitLabApiForm formData = new GitLabApiForm()
.withParam("title", title)
.withParam("description", description)
.withParam("confidential", confidential)
.withParam("assignee_ids", assigneeIds)
.withParam("milestone_id", milestoneId)
.withParam("labels", labels)
.withParam("state_event", stateEvent)
.withParam("updated_at", updatedAt)
.withParam("due_date", dueDate);
Response response = put(Response.Status.OK, formData.asMap(), "projects", getProjectIdOrPath(projectIdOrPath), "issues", issueIid);
return (response.readEntity(Issue.class));
}
|
java
|
public void deleteIssue(Object projectIdOrPath, Integer issueIid) throws GitLabApiException {
if (issueIid == null) {
throw new RuntimeException("issue IID cannot be null");
}
Response.Status expectedStatus = (isApiVersion(ApiVersion.V3) ? Response.Status.OK : Response.Status.NO_CONTENT);
delete(expectedStatus, getDefaultPerPageParam(), "projects", getProjectIdOrPath(projectIdOrPath), "issues", issueIid);
}
|
java
|
public TimeStats resetSpentTime(Object projectIdOrPath, Integer issueIid) throws GitLabApiException {
if (issueIid == null) {
throw new RuntimeException("issue IID cannot be null");
}
Response response = post(Response.Status.OK, new GitLabApiForm().asMap(),
"projects", getProjectIdOrPath(projectIdOrPath), "issues", issueIid, "reset_spent_time");
return (response.readEntity(TimeStats.class));
}
|
java
|
public Optional<TimeStats> getOptionalTimeTrackingStats(Object projectIdOrPath, Integer issueIid) {
try {
return (Optional.ofNullable(getTimeTrackingStats(projectIdOrPath, issueIid)));
} catch (GitLabApiException glae) {
return (GitLabApi.createOptionalFromException(glae));
}
}
|
java
|
public Pager<MergeRequest> getClosedByMergeRequests(Object projectIdOrPath, Integer issueIid, int itemsPerPage) throws GitLabApiException {
return new Pager<MergeRequest>(this, MergeRequest.class, itemsPerPage, null,
"projects", getProjectIdOrPath(projectIdOrPath), "issues", issueIid, "closed_by");
}
|
java
|
public final GitLabApi duplicate() {
Integer sudoUserId = this.getSudoAsId();
GitLabApi gitLabApi = new GitLabApi(apiVersion, gitLabServerUrl,
getTokenType(), getAuthToken(), getSecretToken(), clientConfigProperties);
if (sudoUserId != null) {
gitLabApi.apiClient.setSudoAsId(sudoUserId);
}
if (getIgnoreCertificateErrors()) {
gitLabApi.setIgnoreCertificateErrors(true);
}
gitLabApi.defaultPerPage = this.defaultPerPage;
return (gitLabApi);
}
|
java
|
public void enableRequestResponseLogging(Logger logger, Level level, int maxEntitySize) {
enableRequestResponseLogging(logger, level, maxEntitySize, MaskingLoggingFilter.DEFAULT_MASKED_HEADER_NAMES);
}
|
java
|
public void enableRequestResponseLogging(Level level, int maxEntitySize, List<String> maskedHeaderNames) {
apiClient.enableRequestResponseLogging(LOGGER, level, maxEntitySize, maskedHeaderNames);
}
|
java
|
public void enableRequestResponseLogging(Logger logger, Level level, int maxEntitySize, List<String> maskedHeaderNames) {
apiClient.enableRequestResponseLogging(logger, level, maxEntitySize, maskedHeaderNames);
}
|
java
|
public Version getVersion() throws GitLabApiException {
class VersionApi extends AbstractApi {
VersionApi(GitLabApi gitlabApi) {
super(gitlabApi);
}
}
Response response = new VersionApi(this).get(Response.Status.OK, null, "version");
return (response.readEntity(Version.class));
}
|
java
|
protected static final <T> Optional<T> createOptionalFromException(GitLabApiException glae) {
Optional<T> optional = Optional.empty();
optionalExceptionMap.put(System.identityHashCode(optional), glae);
return (optional);
}
|
java
|
public static final <T> T orElseThrow(Optional<T> optional) throws GitLabApiException {
GitLabApiException glea = getOptionalException(optional);
if (glea != null) {
throw (glea);
}
return (optional.get());
}
|
java
|
public List<AwardEmoji> getNoteAwardEmojis(Object projectIdOrPath, Integer issueIid, Integer noteId) throws GitLabApiException {
Response response = get(Response.Status.OK, getPageQueryParams(1, getDefaultPerPage()),
"projects", getProjectIdOrPath(projectIdOrPath), "issues", issueIid, "notes", noteId, "award_emoji");
return response.readEntity(new GenericType<List<AwardEmoji>>() {});
}
|
java
|
public AwardEmoji getIssueAwardEmoji(Object projectIdOrPath, Integer issueIid, Integer awardId) throws GitLabApiException {
Response response = get(Response.Status.OK, getPageQueryParams(1, getDefaultPerPage()),
"projects", getProjectIdOrPath(projectIdOrPath), "issues", issueIid, "award_emoji", awardId);
return (response.readEntity(AwardEmoji.class));
}
|
java
|
public AwardEmoji getMergeRequestAwardEmoji(Object projectIdOrPath, Integer mergeRequestIid, Integer awardId) throws GitLabApiException {
Response response = get(Response.Status.OK, getPageQueryParams(1, getDefaultPerPage()),
"projects", getProjectIdOrPath(projectIdOrPath), "merge_requests", mergeRequestIid, "award_emoji", awardId);
return (response.readEntity(AwardEmoji.class));
}
|
java
|
public AwardEmoji getSnippetAwardEmoji(Object projectIdOrPath, Integer snippetId, Integer awardId) throws GitLabApiException {
Response response = get(Response.Status.OK, getPageQueryParams(1, getDefaultPerPage()),
"projects", getProjectIdOrPath(projectIdOrPath), "snippets", snippetId, "award_emoji", awardId);
return (response.readEntity(AwardEmoji.class));
}
|
java
|
public AwardEmoji addNoteAwardEmoji(Object projectIdOrPath, Integer issueIid, Integer noteId, String name) throws GitLabApiException {
GitLabApiForm form = new GitLabApiForm().withParam("name", name, true);
Response response = post(Response.Status.CREATED, form.asMap(),
"projects", getProjectIdOrPath(projectIdOrPath), "issues", issueIid, "notes", noteId, "award_emoji");
return (response.readEntity(AwardEmoji.class));
}
|
java
|
public void deleteIssueAwardEmoji(Object projectIdOrPath, Integer issueIid, Integer awardId) throws GitLabApiException {
delete(Response.Status.NO_CONTENT, null,
"projects", getProjectIdOrPath(projectIdOrPath), "issues", issueIid, "award_emoji", awardId);
}
|
java
|
public void deleteMergeRequestAwardEmoji(Object projectIdOrPath, Integer mergeRequestIid, Integer awardId) throws GitLabApiException {
delete(Response.Status.NO_CONTENT, null,
"projects", getProjectIdOrPath(projectIdOrPath), "merge_requests", mergeRequestIid, "award_emoji", awardId);
}
|
java
|
public void deleteSnippetAwardEmoji(Object projectIdOrPath, Integer snippetId, Integer awardId) throws GitLabApiException {
delete(Response.Status.NO_CONTENT, null,
"projects", getProjectIdOrPath(projectIdOrPath), "snippets", snippetId, "award_emoji", awardId);
}
|
java
|
public Pager<Branch> getBranches(Object projectIdOrPath, int itemsPerPage) throws GitLabApiException {
return (new Pager<Branch>(this, Branch.class, itemsPerPage, null, "projects",
getProjectIdOrPath(projectIdOrPath), "repository", "branches"));
}
|
java
|
public Stream<Branch> getBranchesStream(Object projectIdOrPath) throws GitLabApiException {
return (getBranches(projectIdOrPath, getDefaultPerPage()).stream());
}
|
java
|
public Branch getBranch(Object projectIdOrPath, String branchName) throws GitLabApiException {
Response response = get(Response.Status.OK, null, "projects",
getProjectIdOrPath(projectIdOrPath), "repository", "branches", urlEncode(branchName));
return (response.readEntity(Branch.class));
}
|
java
|
public Optional<Branch> getOptionalBranch(Object projectIdOrPath, String branchName) throws GitLabApiException {
try {
return (Optional.ofNullable(getBranch(projectIdOrPath, branchName)));
} catch (GitLabApiException glae) {
return (GitLabApi.createOptionalFromException(glae));
}
}
|
java
|
public Branch createBranch(Object projectIdOrPath, String branchName, String ref) throws GitLabApiException {
Form formData = new GitLabApiForm()
.withParam(isApiVersion(ApiVersion.V3) ? "branch_name" : "branch", branchName, true)
.withParam("ref", ref, true);
Response response = post(Response.Status.CREATED, formData.asMap(), "projects",
getProjectIdOrPath(projectIdOrPath), "repository", "branches");
return (response.readEntity(Branch.class));
}
|
java
|
public void deleteBranch(Object projectIdOrPath, String branchName) throws GitLabApiException {
Response.Status expectedStatus = (isApiVersion(ApiVersion.V3) ? Response.Status.OK : Response.Status.NO_CONTENT);
delete(expectedStatus, null, "projects",
getProjectIdOrPath(projectIdOrPath), "repository", "branches", urlEncode(branchName));
}
|
java
|
public Branch protectBranch(Object projectIdOrPath, String branchName) throws GitLabApiException {
Response response = put(Response.Status.OK, null, "projects",
getProjectIdOrPath(projectIdOrPath), "repository", "branches", urlEncode(branchName), "protect");
return (response.readEntity(Branch.class));
}
|
java
|
public Tag createTag(Object projectIdOrPath, String tagName, String ref, String message, String releaseNotes) throws GitLabApiException {
Form formData = new GitLabApiForm()
.withParam("tag_name", tagName, true)
.withParam("ref", ref, true)
.withParam("message", message, false)
.withParam("release_description", releaseNotes, false);
Response response = post(Response.Status.CREATED, formData.asMap(), "projects",
getProjectIdOrPath(projectIdOrPath), "repository", "tags");
return (response.readEntity(Tag.class));
}
|
java
|
public void deleteTag(Object projectIdOrPath, String tagName) throws GitLabApiException {
Response.Status expectedStatus = (isApiVersion(ApiVersion.V3) ? Response.Status.OK : Response.Status.NO_CONTENT);
delete(expectedStatus, null, "projects", getProjectIdOrPath(projectIdOrPath), "repository", "tags", tagName);
}
|
java
|
public List<Contributor> getContributors(Object projectIdOrPath, int page, int perPage) throws GitLabApiException {
Response response = get(Response.Status.OK, getPageQueryParams(page, perPage),
"projects", getProjectIdOrPath(projectIdOrPath), "repository", "contributors");
return (response.readEntity(new GenericType<List<Contributor>>() { }));
}
|
java
|
public Pager<Contributor> getContributors(Object projectIdOrPath, int itemsPerPage) throws GitLabApiException {
return new Pager<Contributor>(this, Contributor.class, itemsPerPage, null, "projects",
getProjectIdOrPath(projectIdOrPath), "repository", "contributors");
}
|
java
|
public Object getProjectIdOrPath(Object obj) throws GitLabApiException {
if (obj == null) {
throw (new RuntimeException("Cannot determine ID or path from null object"));
} else if (obj instanceof Integer) {
return (obj);
} else if (obj instanceof String) {
return (urlEncode(((String) obj).trim()));
} else if (obj instanceof Project) {
Integer id = ((Project) obj).getId();
if (id != null && id.intValue() > 0) {
return (id);
}
String path = ((Project) obj).getPathWithNamespace();
if (path != null && path.trim().length() > 0) {
return (urlEncode(path.trim()));
}
throw (new RuntimeException("Cannot determine ID or path from provided Project instance"));
} else {
throw (new RuntimeException("Cannot determine ID or path from provided " + obj.getClass().getSimpleName() +
" instance, must be Integer, String, or a Project instance"));
}
}
|
java
|
public Object getGroupIdOrPath(Object obj) throws GitLabApiException {
if (obj == null) {
throw (new RuntimeException("Cannot determine ID or path from null object"));
} else if (obj instanceof Integer) {
return (obj);
} else if (obj instanceof String) {
return (urlEncode(((String) obj).trim()));
} else if (obj instanceof Group) {
Integer id = ((Group) obj).getId();
if (id != null && id.intValue() > 0) {
return (id);
}
String path = ((Group) obj).getFullPath();
if (path != null && path.trim().length() > 0) {
return (urlEncode(path.trim()));
}
throw (new RuntimeException("Cannot determine ID or path from provided Group instance"));
} else {
throw (new RuntimeException("Cannot determine ID or path from provided " + obj.getClass().getSimpleName() +
" instance, must be Integer, String, or a Group instance"));
}
}
|
java
|
public Object getUserIdOrUsername(Object obj) throws GitLabApiException {
if (obj == null) {
throw (new RuntimeException("Cannot determine ID or username from null object"));
} else if (obj instanceof Integer) {
return (obj);
} else if (obj instanceof String) {
return (urlEncode(((String) obj).trim()));
} else if (obj instanceof User) {
Integer id = ((User) obj).getId();
if (id != null && id.intValue() > 0) {
return (id);
}
String username = ((User) obj).getUsername();
if (username != null && username.trim().length() > 0) {
return (urlEncode(username.trim()));
}
throw (new RuntimeException("Cannot determine ID or username from provided User instance"));
} else {
throw (new RuntimeException("Cannot determine ID or username from provided " + obj.getClass().getSimpleName() +
" instance, must be Integer, String, or a User instance"));
}
}
|
java
|
protected String urlEncode(String s) throws GitLabApiException {
try {
String encoded = URLEncoder.encode(s, "UTF-8");
// Since the encode method encodes plus signs as %2B,
// we can simply replace the encoded spaces with the correct encoding here
encoded = encoded.replace("+", "%20");
encoded = encoded.replace(".", "%2E");
encoded = encoded.replace("-", "%2D");
encoded = encoded.replace("_", "%5F");
return (encoded);
} catch (Exception e) {
throw new GitLabApiException(e);
}
}
|
java
|
protected Response post(Response.Status expectedStatus, StreamingOutput stream, String mediaType, Object... pathArgs) throws GitLabApiException {
try {
return validate(getApiClient().post(stream, mediaType, pathArgs), expectedStatus);
} catch (Exception e) {
throw handle(e);
}
}
|
java
|
protected Response upload(Response.Status expectedStatus, String name, File fileToUpload, String mediaType, URL url) throws GitLabApiException {
try {
return validate(getApiClient().upload(name, fileToUpload, mediaType, url), expectedStatus);
} catch (Exception e) {
throw handle(e);
}
}
|
java
|
protected Response put(Response.Status expectedStatus, MultivaluedMap<String, String> queryParams, Object... pathArgs) throws GitLabApiException {
try {
return validate(getApiClient().put(queryParams, pathArgs), expectedStatus);
} catch (Exception e) {
throw handle(e);
}
}
|
java
|
protected Response putUpload(Response.Status expectedStatus, String name, File fileToUpload, Object... pathArgs) throws GitLabApiException {
try {
return validate(getApiClient().putUpload(name, fileToUpload, pathArgs), expectedStatus);
} catch (Exception e) {
throw handle(e);
}
}
|
java
|
protected Response validate(Response response, Response.Status expected) throws GitLabApiException {
int responseCode = response.getStatus();
int expectedResponseCode = expected.getStatusCode();
if (responseCode != expectedResponseCode) {
// If the expected code is 200-204 and the response code is 200-204 it is OK. We do this because
// GitLab is constantly changing the expected code in the 200 to 204 range
if (expectedResponseCode > 204 || responseCode > 204 || expectedResponseCode < 200 || responseCode < 200)
throw new GitLabApiException(response);
}
if (!getApiClient().validateSecretToken(response)) {
throw new GitLabApiException(new NotAuthorizedException("Invalid secret token in response."));
}
return (response);
}
|
java
|
protected GitLabApiException handle(Exception thrown) {
if (thrown instanceof GitLabApiException) {
return ((GitLabApiException) thrown);
}
return (new GitLabApiException(thrown));
}
|
java
|
protected MultivaluedMap<String, String> getPerPageQueryParam(int perPage) {
return (new GitLabApiForm().withParam(PER_PAGE_PARAM, perPage).asMap());
}
|
java
|
protected MultivaluedMap<String, String> getDefaultPerPageParam(boolean customAttributesEnabled) {
GitLabApiForm form = new GitLabApiForm().withParam(PER_PAGE_PARAM, getDefaultPerPage());
if (customAttributesEnabled)
return (form.withParam("with_custom_attributes", true).asMap());
return (form.asMap());
}
|
java
|
void enableRequestResponseLogging(Logger logger, Level level, int maxEntityLength, List<String> maskedHeaderNames) {
MaskingLoggingFilter loggingFilter = new MaskingLoggingFilter(logger, level, maxEntityLength, maskedHeaderNames);
clientConfig.register(loggingFilter);
// Recreate the Client instance if already created.
if (apiClient != null) {
createApiClient();
}
}
|
java
|
protected URL getApiUrl(Object... pathArgs) throws IOException {
String url = appendPathArgs(this.hostUrl, pathArgs);
return (new URL(url));
}
|
java
|
protected URL getUrlWithBase(Object... pathArgs) throws IOException {
String url = appendPathArgs(this.baseUrl, pathArgs);
return (new URL(url));
}
|
java
|
protected Response getWithAccepts(MultivaluedMap<String, String> queryParams, String accepts, Object... pathArgs) throws IOException {
URL url = getApiUrl(pathArgs);
return (getWithAccepts(queryParams, url, accepts));
}
|
java
|
protected Response head(MultivaluedMap<String, String> queryParams, Object... pathArgs) throws IOException {
URL url = getApiUrl(pathArgs);
return (head(queryParams, url));
}
|
java
|
protected Response head(MultivaluedMap<String, String> queryParams, URL url) {
return (invocation(url, queryParams).head());
}
|
java
|
protected Response post(Object payload, Object... pathArgs) throws IOException {
URL url = getApiUrl(pathArgs);
Entity<?> entity = Entity.entity(payload, MediaType.APPLICATION_JSON);
return (invocation(url, null).post(entity));
}
|
java
|
protected Response post(StreamingOutput stream, String mediaType, Object... pathArgs) throws IOException {
URL url = getApiUrl(pathArgs);
return (invocation(url, null).post(Entity.entity(stream, mediaType)));
}
|
java
|
protected Response upload(String name, File fileToUpload, String mediaTypeString, Object... pathArgs) throws IOException {
URL url = getApiUrl(pathArgs);
return (upload(name, fileToUpload, mediaTypeString, null, url));
}
|
java
|
protected Response delete(MultivaluedMap<String, String> queryParams, Object... pathArgs) throws IOException {
return (delete(queryParams, getApiUrl(pathArgs)));
}
|
java
|
protected Response delete(MultivaluedMap<String, String> queryParams, URL url) {
return (invocation(url, queryParams).delete());
}
|
java
|
public void setIgnoreCertificateErrors(boolean ignoreCertificateErrors) {
if (this.ignoreCertificateErrors == ignoreCertificateErrors) {
return;
}
if (!ignoreCertificateErrors) {
this.ignoreCertificateErrors = false;
openSslContext = null;
openHostnameVerifier = null;
apiClient = null;
} else {
if (setupIgnoreCertificateErrors()) {
this.ignoreCertificateErrors = true;
apiClient = null;
} else {
this.ignoreCertificateErrors = false;
apiClient = null;
throw new RuntimeException("Unable to ignore certificate errors.");
}
}
}
|
java
|
private boolean setupIgnoreCertificateErrors() {
// Create a TrustManager that trusts all certificates
TrustManager[] trustAllCerts = new TrustManager[] { new X509ExtendedTrustManager() {
@Override
public X509Certificate[] getAcceptedIssuers() {
return null;
}
@Override
public void checkServerTrusted(X509Certificate[] chain, String authType) throws CertificateException {
}
@Override
public void checkClientTrusted(X509Certificate[] chain, String authType) throws CertificateException {
}
@Override
public void checkClientTrusted(X509Certificate[] chain, String authType, Socket socket) throws CertificateException {
}
@Override
public void checkClientTrusted(X509Certificate[] chain, String authType, SSLEngine engine) throws CertificateException {
}
@Override
public void checkServerTrusted(X509Certificate[] chain, String authType, Socket socket) throws CertificateException {
}
@Override
public void checkServerTrusted(X509Certificate[] chain, String authType, SSLEngine engine) throws CertificateException {
}
}};
// Ignore differences between given hostname and certificate hostname
HostnameVerifier hostnameVerifier = new HostnameVerifier() {
public boolean verify(String hostname, SSLSession session) {
return true;
}
};
try {
SSLContext sslContext = SSLContext.getInstance("TLS");
sslContext.init(null, trustAllCerts, new SecureRandom());
openSslContext = sslContext;
openHostnameVerifier = hostnameVerifier;
} catch (GeneralSecurityException ex) {
openSslContext = null;
openHostnameVerifier = null;
return (false);
}
return (true);
}
|
java
|
public List<Job> getJobs(Object projectIdOrPath, int page, int perPage) throws GitLabApiException {
Response response = get(Response.Status.OK, getPageQueryParams(page, perPage), "projects", getProjectIdOrPath(projectIdOrPath), "jobs");
return (response.readEntity(new GenericType<List<Job>>() {}));
}
|
java
|
public Pager<Job> getJobs(Object projectIdOrPath, int itemsPerPage) throws GitLabApiException {
return (new Pager<Job>(this, Job.class, itemsPerPage, null, "projects", getProjectIdOrPath(projectIdOrPath), "jobs"));
}
|
java
|
public Stream<Job> getJobsStream(Object projectIdOrPath) throws GitLabApiException {
return (getJobs(projectIdOrPath, getDefaultPerPage()).stream());
}
|
java
|
public Job getJob(Object projectIdOrPath, int jobId) throws GitLabApiException {
Response response = get(Response.Status.OK, null, "projects", getProjectIdOrPath(projectIdOrPath), "jobs", jobId);
return (response.readEntity(Job.class));
}
|
java
|
public Optional<Job> getOptionalJob(Object projectIdOrPath, int jobId) {
try {
return (Optional.ofNullable(getJob(projectIdOrPath, jobId)));
} catch (GitLabApiException glae) {
return (GitLabApi.createOptionalFromException(glae));
}
}
|
java
|
public InputStream downloadArtifactsFile(Object projectIdOrPath, String ref, String jobName) throws GitLabApiException {
Form formData = new GitLabApiForm().withParam("job", jobName, true);
Response response = getWithAccepts(Response.Status.OK, formData.asMap(), MediaType.MEDIA_TYPE_WILDCARD,
"projects", getProjectIdOrPath(projectIdOrPath), "jobs", "artifacts", ref, "download");
return (response.readEntity(InputStream.class));
}
|
java
|
public InputStream downloadArtifactsFile(Object projectIdOrPath, Integer jobId) throws GitLabApiException {
Response response = getWithAccepts(Response.Status.OK, null, MediaType.MEDIA_TYPE_WILDCARD,
"projects", getProjectIdOrPath(projectIdOrPath), "jobs", jobId, "artifacts");
return (response.readEntity(InputStream.class));
}
|
java
|
public String getTrace(Object projectIdOrPath, int jobId) throws GitLabApiException {
Response response = get(Response.Status.OK, getDefaultPerPageParam(),
"projects", getProjectIdOrPath(projectIdOrPath), "jobs", jobId, "trace");
return (response.readEntity(String.class));
}
|
java
|
public Job playJob(Object projectIdOrPath, int jobId) throws GitLabApiException {
GitLabApiForm formData = null;
Response response = post(Status.CREATED, formData, "projects", getProjectIdOrPath(projectIdOrPath), "jobs", jobId, "play");
return (response.readEntity(Job.class));
}
|
java
|
public JsonNode readTree(String postData) throws JsonParseException, JsonMappingException, IOException {
return (objectMapper.readTree(postData));
}
|
java
|
public JsonNode readTree(Reader reader) throws JsonParseException, JsonMappingException, IOException {
return (objectMapper.readTree(reader));
}
|
java
|
public <T> T unmarshal(Class<T> returnType, Reader reader) throws JsonParseException, JsonMappingException, IOException {
ObjectMapper objectMapper = getContext(returnType);
return (objectMapper.readValue(reader, returnType));
}
|
java
|
public <T> T unmarshal(Class<T> returnType, String postData) throws JsonParseException, JsonMappingException, IOException {
ObjectMapper objectMapper = getContext(returnType);
return (objectMapper.readValue(postData, returnType));
}
|
java
|
public <T> List<T> unmarshalList(Class<T> returnType, Reader reader) throws JsonParseException, JsonMappingException, IOException {
ObjectMapper objectMapper = getContext(null);
CollectionType javaType = objectMapper.getTypeFactory().constructCollectionType(List.class, returnType);
return (objectMapper.readValue(reader, javaType));
}
|
java
|
public <T> Map<String, T> unmarshalMap(Class<T> returnType, Reader reader) throws JsonParseException, JsonMappingException, IOException {
ObjectMapper objectMapper = getContext(null);
return (objectMapper.readValue(reader, new TypeReference<Map<String, T>>() {}));
}
|
java
|
public <T> String marshal(final T object) {
if (object == null) {
throw new IllegalArgumentException("object parameter is null");
}
ObjectWriter writer = objectMapper.writer().withDefaultPrettyPrinter();
String results = null;
try {
results = writer.writeValueAsString(object);
} catch (JsonGenerationException e) {
System.err.println("JsonGenerationException, message=" + e.getMessage());
} catch (JsonMappingException e) {
e.printStackTrace();
System.err.println("JsonMappingException, message=" + e.getMessage());
} catch (IOException e) {
System.err.println("IOException, message=" + e.getMessage());
}
return (results);
}
|
java
|
public static JsonNode toJsonNode(String jsonString) throws IOException {
return (JacksonJsonSingletonHelper.JACKSON_JSON.objectMapper.readTree(jsonString));
}
|
java
|
public List<LicenseTemplate> getAllLicenseTemplates() throws GitLabApiException {
Response response = get(Response.Status.OK, null, "licenses");
return (response.readEntity(new GenericType<List<LicenseTemplate>>() {}));
}
|
java
|
public List<LicenseTemplate> getPopularLicenseTemplates() throws GitLabApiException {
Form formData = new GitLabApiForm().withParam("popular", true, true);
Response response = get(Response.Status.OK, formData.asMap(), "licenses");
return (response.readEntity(new GenericType<List<LicenseTemplate>>() {}));
}
|
java
|
public LicenseTemplate getSingleLicenseTemplate(String key) throws GitLabApiException {
Response response = get(Response.Status.OK, null, "licenses", key);
return (response.readEntity(LicenseTemplate.class));
}
|
java
|
public HealthCheckInfo getLiveness(String token) throws GitLabApiException {
try {
URL livenessUrl = getApiClient().getUrlWithBase("-", "liveness");
GitLabApiForm formData = new GitLabApiForm().withParam("token", token, false);
Response response = get(Response.Status.OK, formData.asMap(), livenessUrl);
return (response.readEntity(HealthCheckInfo.class));
} catch (IOException ioe) {
throw (new GitLabApiException(ioe));
}
}
|
java
|
public void setGitLabCI(Object projectIdOrPath, String token, String projectCIUrl) throws GitLabApiException {
final Form formData = new Form();
formData.param("token", token);
formData.param("project_url", projectCIUrl);
put(Response.Status.OK, formData.asMap(), "projects", getProjectIdOrPath(projectIdOrPath), "services", "gitlab-ci");
}
|
java
|
public void deleteGitLabCI(Object projectIdOrPath) throws GitLabApiException {
Response.Status expectedStatus = (isApiVersion(ApiVersion.V3) ? Response.Status.OK : Response.Status.NO_CONTENT);
delete(expectedStatus, null, "projects", getProjectIdOrPath(projectIdOrPath), "services", "gitlab-ci");
}
|
java
|
public HipChatService getHipChatService(Object projectIdOrPath) throws GitLabApiException {
Response response = get(Response.Status.OK, null, "projects", getProjectIdOrPath(projectIdOrPath), "services", "hipchat");
return (response.readEntity(HipChatService.class));
}
|
java
|
public HipChatService updateHipChatService(Object projectIdOrPath, HipChatService hipChat) throws GitLabApiException {
GitLabApiForm formData = new GitLabApiForm()
.withParam("push_events", hipChat.getPushEvents())
.withParam("issues_events", hipChat.getIssuesEvents())
.withParam("confidential_issues_events", hipChat.getConfidentialIssuesEvents())
.withParam("merge_requests_events", hipChat.getMergeRequestsEvents())
.withParam("tag_push_events", hipChat.getTagPushEvents())
.withParam("note_events", hipChat.getNoteEvents())
.withParam("confidential_note_events", hipChat.getConfidentialNoteEvents())
.withParam("pipeline_events", hipChat.getPipelineEvents())
.withParam("token", hipChat.getToken(), true)
.withParam("color", hipChat.getColor())
.withParam("notify", hipChat.getNotify())
.withParam("room", hipChat.getRoom())
.withParam("api_version", hipChat.getApiVersion())
.withParam("server", hipChat.getServer())
.withParam("notify_only_broken_pipelines", hipChat.getNotifyOnlyBrokenPipelines());
Response response = put(Response.Status.OK, formData.asMap(), "projects", getProjectIdOrPath(projectIdOrPath), "services", "hipchat");
return (response.readEntity(HipChatService.class));
}
|
java
|
public void setHipChat(Object projectIdOrPath, String token, String room, String server) throws GitLabApiException {
GitLabApiForm formData = new GitLabApiForm()
.withParam("token", token)
.withParam("room", room)
.withParam("server", server);
put(Response.Status.OK, formData.asMap(), "projects", getProjectIdOrPath(projectIdOrPath), "services", "hipchat");
}
|
java
|
public SlackService getSlackService(Object projectIdOrPath) throws GitLabApiException {
Response response = get(Response.Status.OK, null, "projects", getProjectIdOrPath(projectIdOrPath), "services", "slack");
return (response.readEntity(SlackService.class));
}
|
java
|
public SlackService updateSlackService(Object projectIdOrPath, SlackService slackNotifications) throws GitLabApiException {
GitLabApiForm formData = new GitLabApiForm()
.withParam("webhook", slackNotifications.getWebhook(), true)
.withParam("username", slackNotifications.getUsername())
.withParam("channel", slackNotifications.getDefaultChannel())
.withParam("notify_only_broken_pipelines", slackNotifications.getNotifyOnlyBrokenPipelines())
.withParam("notify_only_default_branch", slackNotifications.getNotifyOnlyDefaultBranch())
.withParam("push_events", slackNotifications.getPushEvents())
.withParam("issues_events", slackNotifications.getIssuesEvents())
.withParam("confidential_issues_events", slackNotifications.getConfidentialIssuesEvents())
.withParam("merge_requests_events", slackNotifications.getMergeRequestsEvents())
.withParam("tag_push_events", slackNotifications.getTagPushEvents())
.withParam("note_events", slackNotifications.getNoteEvents())
.withParam("confidential_note_events", slackNotifications.getConfidentialNoteEvents())
.withParam("pipeline_events", slackNotifications.getPipelineEvents())
.withParam("wiki_page_events", slackNotifications.getWikiPageEvents())
.withParam("push_channel", slackNotifications.getPushChannel())
.withParam("issue_channel", slackNotifications.getIssueChannel())
.withParam("confidential_issue_channel", slackNotifications.getConfidentialIssueChannel())
.withParam("merge_request_channel", slackNotifications.getMergeRequestChannel())
.withParam("note_channel", slackNotifications.getNoteChannel())
.withParam("confidential_note_channel", slackNotifications.getConfidentialNoteChannel())
.withParam("tag_push_channel", slackNotifications.getTagPushChannel())
.withParam("pipeline_channel", slackNotifications.getPipelineChannel())
.withParam("wiki_page_channel", slackNotifications.getWikiPageChannel());
Response response = put(Response.Status.OK, formData.asMap(), "projects", getProjectIdOrPath(projectIdOrPath), "services", "slack");
return (response.readEntity(SlackService.class));
}
|
java
|
public JiraService updateJiraService(Object projectIdOrPath, JiraService jira) throws GitLabApiException {
GitLabApiForm formData = new GitLabApiForm()
.withParam("merge_requests_events", jira.getMergeRequestsEvents())
.withParam("commit_events", jira.getCommitEvents())
.withParam("url", jira.getUrl(), true)
.withParam("api_url", jira.getApiUrl())
.withParam("project_key", jira.getProjectKey())
.withParam("username", jira.getUsername(), true)
.withParam("password", jira.getPassword(), true)
.withParam("jira_issue_transition_id", jira.getJiraIssueTransitionId());
Response response = put(Response.Status.OK, formData.asMap(), "projects", getProjectIdOrPath(projectIdOrPath), "services", "jira");
return (response.readEntity(JiraService.class));
}
|
java
|
public ExternalWikiService updateExternalWikiService(Object projectIdOrPath, ExternalWikiService externalWiki) throws GitLabApiException {
GitLabApiForm formData = new GitLabApiForm()
.withParam("external_wiki_url", externalWiki.getExternalWikiUrl());
Response response = put(Response.Status.OK, formData.asMap(), "projects", getProjectIdOrPath(projectIdOrPath), "services", "external-wiki");
return (response.readEntity(ExternalWikiService.class));
}
|
java
|
public void handleEvent(HttpServletRequest request) throws GitLabApiException {
String eventName = request.getHeader("X-Gitlab-Event");
if (eventName == null || eventName.trim().isEmpty()) {
String message = "X-Gitlab-Event header is missing!";
LOGGER.warning(message);
return;
}
if (!isValidSecretToken(request)) {
String message = "X-Gitlab-Token mismatch!";
LOGGER.warning(message);
throw new GitLabApiException(message);
}
LOGGER.info("handleEvent: X-Gitlab-Event=" + eventName);
if (!SYSTEM_HOOK_EVENT.equals(eventName)) {
String message = "Unsupported X-Gitlab-Event, event Name=" + eventName;
LOGGER.warning(message);
throw new GitLabApiException(message);
}
// Get the JSON as a JsonNode tree. We do not directly unmarshal the input as special handling must
// be done for "merge_request" events.
JsonNode tree;
try {
if (LOGGER.isLoggable(Level.FINE)) {
LOGGER.fine(HttpRequestUtils.getShortRequestDump("System Hook", true, request));
String postData = HttpRequestUtils.getPostDataAsString(request);
LOGGER.fine("Raw POST data:\n" + postData);
tree = jacksonJson.readTree(postData);
} else {
InputStreamReader reader = new InputStreamReader(request.getInputStream());
tree = jacksonJson.readTree(reader);
}
} catch (Exception e) {
LOGGER.warning("Error reading JSON data, exception=" +
e.getClass().getSimpleName() + ", error=" + e.getMessage());
throw new GitLabApiException(e);
}
// NOTE: This is a hack based on the GitLab documentation and actual content of the "merge_request" event
// showing that the "event_name" property is missing from the merge_request system hook event. The hack is
// to inject the "event_name" node so that the polymorphic deserialization of a SystemHookEvent works correctly
// when the system hook event is a "merge_request" event.
if (!tree.has("event_name") && tree.has("object_kind")) {
String objectKind = tree.get("object_kind").asText();
if (MergeRequestSystemHookEvent.MERGE_REQUEST_EVENT.equals(objectKind)) {
ObjectNode node = (ObjectNode)tree;
node.put("event_name", MergeRequestSystemHookEvent.MERGE_REQUEST_EVENT);
} else {
String message = "Unsupported object_kind for system hook event, object_kind=" + objectKind;
LOGGER.warning(message);
throw new GitLabApiException(message);
}
}
// Unmarshal the tree to a concrete instance of a SystemHookEvent and fire the event to any listeners
try {
SystemHookEvent event = jacksonJson.unmarshal(SystemHookEvent.class, tree);
if (LOGGER.isLoggable(Level.FINE)) {
LOGGER.fine(event.getEventName() + "\n" + jacksonJson.marshal(event) + "\n");
}
StringBuffer requestUrl = request.getRequestURL();
event.setRequestUrl(requestUrl != null ? requestUrl.toString() : null);
event.setRequestQueryString(request.getQueryString());
fireEvent(event);
} catch (Exception e) {
LOGGER.warning("Error processing JSON data, exception=" +
e.getClass().getSimpleName() + ", error=" + e.getMessage());
throw new GitLabApiException(e);
}
}
|
java
|
public Stream<Runner> getRunnersStream(Runner.RunnerStatus scope) throws GitLabApiException {
return (getRunners(scope, getDefaultPerPage()).stream());
}
|
java
|
public Pager<Runner> getRunners(Runner.RunnerStatus scope, int itemsPerPage) throws GitLabApiException {
GitLabApiForm formData = new GitLabApiForm().withParam("scope", scope, false);
return (new Pager<>(this, Runner.class, itemsPerPage, formData.asMap(), "runners"));
}
|
java
|
public RunnerDetail getRunnerDetail(Integer runnerId) throws GitLabApiException {
if (runnerId == null) {
throw new RuntimeException("runnerId cannot be null");
}
Response response = get(Response.Status.OK, null, "runners", runnerId);
return (response.readEntity(RunnerDetail.class));
}
|
java
|
public RunnerDetail updateRunner(Integer runnerId, String description, Boolean active, List<String> tagList,
Boolean runUntagged, Boolean locked, RunnerDetail.RunnerAccessLevel accessLevel) throws GitLabApiException {
if (runnerId == null) {
throw new RuntimeException("runnerId cannot be null");
}
GitLabApiForm formData = new GitLabApiForm()
.withParam("description", description, false)
.withParam("active", active, false)
.withParam("tag_list", tagList, false)
.withParam("run_untagged", runUntagged, false)
.withParam("locked", locked, false)
.withParam("access_level", accessLevel, false);
Response response = put(Response.Status.OK, formData.asMap(), "runners", runnerId);
return (response.readEntity(RunnerDetail.class));
}
|
java
|
public void removeRunner(Integer runnerId) throws GitLabApiException {
if (runnerId == null) {
throw new RuntimeException("runnerId cannot be null");
}
delete(Response.Status.NO_CONTENT, null, "runners", runnerId);
}
|
java
|
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.