Created
March 4, 2016 09:03
-
-
Save unixunion/b0096502d834598e14bb to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package com.deblox.greatsnipe.git.impl; | |
import com.deblox.greatsnipe.git.GitServerProvider; | |
import io.vertx.core.Handler; | |
import io.vertx.core.Vertx; | |
import io.vertx.core.json.JsonObject; | |
import io.vertx.core.logging.Logger; | |
import io.vertx.core.logging.LoggerFactory; | |
import org.gitlab.api.GitlabAPI; | |
import org.gitlab.api.models.GitlabProject; | |
import java.io.IOException; | |
/** | |
* GitLab API client for Great Snipe Migration Service | |
* | |
* Created by keghol on 11/11/15. | |
*/ | |
public class GitLab implements GitServerProvider { | |
private static final Logger logger = LoggerFactory.getLogger(GitLab.class); | |
GitlabProject project; | |
GitlabAPI api; | |
public String apiUrl; | |
public String token; | |
public String repoUrl; | |
private Vertx vertx; | |
@Override | |
public GitServerProvider setVertx(Vertx vertx) { | |
this.vertx = vertx; | |
return this; | |
} | |
/** | |
* Set the api URL e.g. "http://gitlab.unibet.com" | |
* @param url | |
*/ | |
@Override | |
public GitServerProvider setApiUrl(String url) { | |
apiUrl = url; | |
return this; | |
} | |
/** | |
* Set the credentials e.g. "tTvgii6sht4XrEHdQW4K" | |
* @param credential | |
*/ | |
@Override | |
public GitServerProvider setToken(String credential) { | |
logger.info("Setting token: " + credential); | |
token = credential; | |
return this; | |
} | |
// @Override | |
// public void createRepo(Object name, Handler<Object> handler) throws IOException { | |
// | |
// } | |
/** | |
* Create the repo, async call handler with if of project | |
* | |
* @param name keys name, and key are in the name object which is a JsonObject | |
*/ | |
@Override | |
public void createProjectAndRepo(Object name, Handler handler) throws IOException { | |
logger.info("Creating repository " + name.toString() + " in " + apiUrl + " with token " + token); | |
api = GitlabAPI.connect(apiUrl, token); | |
JsonObject document = (JsonObject)name; | |
project = api.createProject(document.getString("repoName")); | |
logger.info("Created repository: " + name); | |
handler.handle(project.getHttpUrl()); | |
} | |
/** | |
* post hook | |
* | |
* @param name | |
* @throws IOException | |
*/ | |
// @Override | |
// public void postHook(Object name) throws IOException { | |
// api.unprotectBranch(project, name.toString()); | |
// } | |
@Override | |
public String getAuhRepoUrl(String username, String password) { | |
return null; | |
} | |
/** | |
* get the repo URL for use with "git remote ..." | |
* @return | |
*/ | |
// @Override | |
// public GitServerProvider getRepo(Object projectId) throws IOException { | |
// api = GitlabAPI.connect(apiUrl, token); | |
// project = api.getProject(Integer.valueOf(projectId.toString())); | |
// return this; | |
// } | |
@Override | |
public String getRepoUrl() { | |
return project.getHttpUrl(); | |
} | |
@Override | |
public void setRepoUrl(String s) { | |
repoUrl = s; | |
} | |
} | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment