-
Notifications
You must be signed in to change notification settings - Fork 130
Expand file tree
/
Copy pathGitlab.java
More file actions
41 lines (30 loc) · 1.44 KB
/
Gitlab.java
File metadata and controls
41 lines (30 loc) · 1.44 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
package org.jenkinsci.plugins.gitlab;
import java.io.IOException;
import org.gitlab.api.GitlabAPI;
import org.gitlab.api.models.GitlabCommitStatus;
import org.gitlab.api.models.GitlabProject;
/**
* GitlabAPI Wrapper Class
*/
public class Gitlab {
private GitlabAPI api;
private void connect() {
String privateToken = GitlabBuildTrigger.getDesc().getBotApiTokenSecret().getPlainText();
String apiUrl = GitlabBuildTrigger.getDesc().getGitlabHostUrl();
api = GitlabAPI.connect(apiUrl, privateToken);
api.ignoreCertificateErrors(GitlabBuildTrigger.getDesc().isIgnoreCertificateErrors());
}
public GitlabAPI get() {
if (api == null) {
connect();
}
return api;
}
public synchronized GitlabCommitStatus changeCommitStatus(Integer projectId, String branch, String commitHash, String commitStatus, String targetUrl) throws IOException {
return changeCommitStatus(projectId, branch, commitHash, "Jenkins", "Gitlab MR Builder", commitStatus, targetUrl);
}
public synchronized GitlabCommitStatus changeCommitStatus(Integer projectId, String branch, String commitHash, String name, String description, String commitStatus, String targetUrl) throws IOException {
GitlabProject project = get().getProject(projectId);
return get().createCommitStatus(project, commitHash, commitStatus, branch, name, targetUrl, description);
}
}