Skip to content
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

Cleanup GitLabWebHook #207

Closed
Closed
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
19 changes: 12 additions & 7 deletions src/main/java/com/dabsquared/gitlabjenkins/GitLab.java
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,10 @@
import java.util.logging.Level;
import java.util.logging.Logger;

import com.dabsquared.gitlabjenkins.connection.GitLabConnection;
import com.dabsquared.gitlabjenkins.connection.GitLabConnectionConfig;
import hudson.model.Descriptor;
import jenkins.model.Jenkins;
import org.gitlab.api.GitlabAPI;

public class GitLab {
Expand All @@ -12,12 +16,13 @@ public class GitLab {

public GitlabAPI instance() {
if (api == null) {
String token = GitLabPushTrigger.getDesc().getGitlabApiToken();
String url = GitLabPushTrigger.getDesc().getGitlabHostUrl();
boolean ignoreCertificateErrors = GitLabPushTrigger.getDesc().getIgnoreCertificateErrors();
LOGGER.log(Level.FINE, "Connecting to Gitlab server ({0})", url);
api = GitlabAPI.connect(url, token);
api.ignoreCertificateErrors(ignoreCertificateErrors);
// Use the first configured connection as work around for the GitLabProjectBranchesService
GitLabConnectionConfig connectionConfig = (GitLabConnectionConfig) Jenkins.getInstance().getDescriptor(GitLabConnectionConfig.class);
if (connectionConfig != null && connectionConfig.getConnections().size() > 0) {
GitLabConnection connection = connectionConfig.getConnections().get(0);
api = GitlabAPI.connect(connection.getUrl(), connection.getApiToken());
api.ignoreCertificateErrors(connection.isIgnoreCertificateErrors());
}
}

return api;
Expand All @@ -29,4 +34,4 @@ public static boolean checkConnection (String token, String url, boolean ignoreC
testApi.getProjects();
return true;
}
}
}

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,7 @@
import org.apache.commons.lang.builder.ToStringBuilder;
import org.apache.commons.lang.builder.ToStringStyle;
import org.gitlab.api.GitlabAPI;
import org.gitlab.api.models.GitlabCommitStatus;
import org.gitlab.api.models.GitlabProject;
import org.gitlab.api.models.GitlabUser;

import java.io.IOException;

Expand Down Expand Up @@ -34,9 +32,9 @@ public GitLabMergeRequest() {
private ObjectAttributes objectAttributes;
private GitlabProject sourceProject = null;

public GitlabProject getSourceProject (GitLab api) throws IOException {
public GitlabProject getSourceProject(GitlabAPI gitlabAPI) throws IOException {
if (sourceProject == null) {
sourceProject = api.instance().getProject(objectAttributes.getSourceProjectId());
sourceProject = gitlabAPI.getProject(objectAttributes.getSourceProjectId());
}
return sourceProject;
}
Expand All @@ -62,17 +60,4 @@ public void setObjectAttribute(ObjectAttributes objectAttributes) {
public String toString() {
return ToStringBuilder.reflectionToString(this, ToStringStyle.MULTI_LINE_STYLE);
}

public GitlabCommitStatus createCommitStatus(GitlabAPI api, String status, String targetUrl) {
try {
if (objectAttributes.getLastCommit() != null) {
return api.createCommitStatus(sourceProject, objectAttributes.getLastCommit().getId(), status, objectAttributes.getLastCommit().getId(), "Jenkins", targetUrl, null);
}
} catch (IOException e) {
e.printStackTrace();
}

return null;
}

}
48 changes: 0 additions & 48 deletions src/main/java/com/dabsquared/gitlabjenkins/GitLabPushCause.java

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@
import org.apache.commons.lang.builder.ToStringBuilder;
import org.apache.commons.lang.builder.ToStringStyle;
import org.gitlab.api.GitlabAPI;
import org.gitlab.api.models.GitlabCommitStatus;
import org.gitlab.api.models.GitlabProject;

import java.io.IOException;
Expand All @@ -31,24 +30,13 @@ public GitLabPushRequest() {

private GitlabProject sourceProject = null;

public GitlabProject getSourceProject (GitLab api) throws IOException {
public GitlabProject getSourceProject(GitlabAPI gitlabAPI) throws IOException {
if (sourceProject == null) {
sourceProject = api.instance().getProject(project_id);
sourceProject = gitlabAPI.getProject(project_id);
}
return sourceProject;
}

public GitlabCommitStatus createCommitStatus(GitlabAPI api, String status, String targetUrl) {
try {
if(getLastCommit()!=null) {
return api.createCommitStatus(sourceProject, checkout_sha, status, checkout_sha, "Jenkins", targetUrl, null);
}
} catch (IOException e) {
e.printStackTrace();
}
return null;
}

private String before;
private String after;
private String checkout_sha;
Expand Down
Loading