timols / java-gitlab-api Goto Github PK
View Code? Open in Web Editor NEWA wrapper for the Gitlab API written in Java
License: Apache License 2.0
A wrapper for the Gitlab API written in Java
License: Apache License 2.0
The method gitlabApi.addProjectHook is missing a flag for tagEvents.
Hi.
I search possibile how to edit privileges user into group.
I find solution but I don't see how to do work in your api
From api (there is PUT but in your URL is only POST):
Edit project team member
Updates a project team member to a specified access level.
PUT /projects/:id/members/:user_id
Parameters:
id (required) - The ID or NAMESPACE/PROJECT_NAME of a project
user_id (required) - The ID of a team member
access_level (required) - Project access level
best regards s.
Is this project alive? Could you publish a new version to maven central?
Is it any way to download build artifact?
Hey,
can you please update the package on maven central? Thank you!
Best regards
Matthias
I don't know if this is an issue. I was trying to create a MergeRequest using the API and i see that there is no method in GitlabAPI to create a new Merge request. Does this feature exist in the current API?
GET, PUT on this URL /projects/:id/repository/files are not supported.
Dear gurus,
I am currently trying to get project list and branches of a project, but my code failed at the beginning. The exception is
com.fasterxml.jackson.core.JsonParseException: Unexpected character ('<' (code 60)): expected a valid value (number, String, array, object, 'true', 'false' or 'null')
at [Source: <title>Request Rejected</title>The requested URL was rejected. Please consult with your administrator.
Here is my code:
final String URL = "https://example.com";
final String token = "myToken";
api = GitlabAPI.connect(URL, token);
System.out.println(api.getProjects().size());
Could you please take a look?
A basic tutorial in readme would be better, I tried gitlab python API it works but I prefer to use Java.
Thanks.
As the title says, the setNotificationLevel in the file linked below incorrectly sets accesslevel rather than setting notification level as it should. Just happened to come across this when searching for an answer to a question I had.
The API supports deleting notes but this feature does not seem to be implemented
http://docs.gitlab.com/ce/api/notes.html#delete-an-issue-note
http://docs.gitlab.com/ce/api/notes.html#delete-a-merge-request-note
The getAllCommits
method is using GitlabHTTPRequestor.to()
and as such is using the default values in the REST API (per_page=20
and page=1
), returning only the most recent 20 commits.
This method should be updated to use GitlabHTTPRequestor.getAll()
and actually retrieve all commits.
I've started working on this and will submit a pull request soon.
Something like Project#isBuildsEnabled()
, Project#isSharedRunnersEnabled()
, Project#getRunnersToken()
and Project#hasPublicBuilds()
is missing.
{
"builds_enabled": false,
"shared_runners_enabled": false,
"runners_token": "abcdef",
"public_builds": true
}
Hello,
I am trying to operate a Gitlab server with Java Application, this project is great.
However, I cannot find any documents for the project, anyone can help me?
I observed that my tomcat server with JSF web app loads a lot the CPU and I'm almost sure that it's because opened HttpURLConnection in the GitApi.
Can you provide disconnect() or close() method in the GitlabAPI class where the connect method is also placed ? I didn't find any disconnect of 'url.openConnection()'...
Or even if you can provide connect() method with some timeToClose parameter when connection gets automatically closed?
Thank you
Got the following Exception when invoking GitabAPI#getProject:
Can not construct instance of org.gitlab.api.models.GitlabAccessLevel from number value (50). index value outside legal index range [0..4]
Issue is that Jackson is not using GitlabAccessLevel#fromAccessValue to deserialize JSON.
This class is a major violation of single responsibility principle.
https://github.com/timols/java-gitlab-api/blob/master/src/main/java/org/gitlab/api/GitlabAPI.java
If you want some ideas on a better way to do it, you can view my current project which is in C#.
https://gitlab.com/tstivers/GitLab.NET
https://en.wikipedia.org/wiki/Single_responsibility_principle
Hello, I have a question regarding GitlabHTTPRequestor.java
.
When I tried to setup jenkins-gitlab-merge-request
for a jenkins behind proxy, I got the following error.
javax.servlet.ServletException: java.lang.Error: java.net.SocketException: Connection reset
at org.kohsuke.stapler.Stapler.tryInvoke(Stapler.java:796)
at org.kohsuke.stapler.Stapler.invoke(Stapler.java:876)
at org.kohsuke.stapler.MetaClass$6.doDispatch(MetaClass.java:249)
at org.kohsuke.stapler.NameBasedDispatcher.dispatch(NameBasedDispatcher.java:53)
at org.kohsuke.stapler.Stapler.tryInvoke(Stapler.java:746)
at org.kohsuke.stapler.Stapler.invoke(Stapler.java:876)
at org.kohsuke.stapler.Stapler.invoke(Stapler.java:649)
at org.kohsuke.stapler.Stapler.service(Stapler.java:238)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:848)
at org.eclipse.jetty.servlet.ServletHolder.handle(ServletHolder.java:686)
at org.eclipse.jetty.servlet.ServletHandler$CachedChain.doFilter(ServletHandler.java:1494)
at hudson.util.PluginServletFilter$1.doFilter(PluginServletFilter.java:132)
at hudson.util.PluginServletFilter.doFilter(PluginServletFilter.java:123)
at org.eclipse.jetty.servlet.ServletHandler$CachedChain.doFilter(ServletHandler.java:1482)
at hudson.security.csrf.CrumbFilter.doFilter(CrumbFilter.java:49)
at org.eclipse.jetty.servlet.ServletHandler$CachedChain.doFilter(ServletHandler.java:1482)
at hudson.security.ChainedServletFilter$1.doFilter(ChainedServletFilter.java:84)
at hudson.security.ChainedServletFilter.doFilter(ChainedServletFilter.java:76)
at hudson.security.HudsonFilter.doFilter(HudsonFilter.java:171)
at org.eclipse.jetty.servlet.ServletHandler$CachedChain.doFilter(ServletHandler.java:1482)
at org.kohsuke.stapler.compression.CompressionFilter.doFilter(CompressionFilter.java:49)
at org.eclipse.jetty.servlet.ServletHandler$CachedChain.doFilter(ServletHandler.java:1482)
at hudson.util.CharacterEncodingFilter.doFilter(CharacterEncodingFilter.java:81)
at org.eclipse.jetty.servlet.ServletHandler$CachedChain.doFilter(ServletHandler.java:1482)
at org.kohsuke.stapler.DiagnosticThreadNameFilter.doFilter(DiagnosticThreadNameFilter.java:30)
at org.eclipse.jetty.servlet.ServletHandler$CachedChain.doFilter(ServletHandler.java:1474)
at org.eclipse.jetty.servlet.ServletHandler.doHandle(ServletHandler.java:499)
at org.eclipse.jetty.server.handler.ScopedHandler.handle(ScopedHandler.java:137)
at org.eclipse.jetty.security.SecurityHandler.handle(SecurityHandler.java:533)
at org.eclipse.jetty.server.session.SessionHandler.doHandle(SessionHandler.java:231)
at org.eclipse.jetty.server.handler.ContextHandler.doHandle(ContextHandler.java:1086)
at org.eclipse.jetty.servlet.ServletHandler.doScope(ServletHandler.java:428)
at org.eclipse.jetty.server.session.SessionHandler.doScope(SessionHandler.java:193)
at org.eclipse.jetty.server.handler.ContextHandler.doScope(ContextHandler.java:1020)
at org.eclipse.jetty.server.handler.ScopedHandler.handle(ScopedHandler.java:135)
at org.eclipse.jetty.server.handler.HandlerWrapper.handle(HandlerWrapper.java:116)
at org.eclipse.jetty.server.Server.handle(Server.java:370)
at org.eclipse.jetty.server.AbstractHttpConnection.handleRequest(AbstractHttpConnection.java:489)
at org.eclipse.jetty.server.AbstractHttpConnection.content(AbstractHttpConnection.java:960)
at org.eclipse.jetty.server.AbstractHttpConnection$RequestHandler.content(AbstractHttpConnection.java:1021)
at org.eclipse.jetty.http.HttpParser.parseNext(HttpParser.java:865)
at org.eclipse.jetty.http.HttpParser.parseAvailable(HttpParser.java:240)
at org.eclipse.jetty.server.AsyncHttpConnection.handle(AsyncHttpConnection.java:82)
at org.eclipse.jetty.io.nio.SelectChannelEndPoint.handle(SelectChannelEndPoint.java:668)
at org.eclipse.jetty.io.nio.SelectChannelEndPoint$1.run(SelectChannelEndPoint.java:52)
at winstone.BoundedExecutorService$1.run(BoundedExecutorService.java:77)
at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1145)
at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:615)
at java.lang.Thread.run(Thread.java:745)
Caused by: java.lang.Error: java.net.SocketException: Connection reset
at org.gitlab.api.http.GitlabHTTPRequestor$1.fetch(GitlabHTTPRequestor.java:218)
at org.gitlab.api.http.GitlabHTTPRequestor$1.hasNext(GitlabHTTPRequestor.java:174)
at org.gitlab.api.http.GitlabHTTPRequestor.getAll(GitlabHTTPRequestor.java:143)
at org.gitlab.api.GitlabAPI.getProjects(GitlabAPI.java:168)
at org.jenkinsci.plugins.gitlab.GitlabRepository.getProjectForPath(GitlabRepository.java:98)
at org.jenkinsci.plugins.gitlab.GitlabRepository.checkState(GitlabRepository.java:39)
at org.jenkinsci.plugins.gitlab.GitlabRepository.init(GitlabRepository.java:30)
at org.jenkinsci.plugins.gitlab.GitlabMergeRequestBuilder.build(GitlabMergeRequestBuilder.java:56)
at org.jenkinsci.plugins.gitlab.GitlabBuildTrigger.start(GitlabBuildTrigger.java:57)
at org.jenkinsci.plugins.gitlab.GitlabBuildTrigger.start(GitlabBuildTrigger.java:28)
at hudson.model.AbstractProject.submit(AbstractProject.java:1879)
at hudson.model.Project.submit(Project.java:230)
at hudson.model.Job.doConfigSubmit(Job.java:1206)
at hudson.model.AbstractProject.doConfigSubmit(AbstractProject.java:798)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:57)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.lang.reflect.Method.invoke(Method.java:606)
at org.kohsuke.stapler.Function$InstanceFunction.invoke(Function.java:298)
at org.kohsuke.stapler.Function.bindAndInvoke(Function.java:161)
at org.kohsuke.stapler.Function.bindAndInvokeAndServeResponse(Function.java:96)
at org.kohsuke.stapler.MetaClass$1.doDispatch(MetaClass.java:121)
at org.kohsuke.stapler.NameBasedDispatcher.dispatch(NameBasedDispatcher.java:53)
at org.kohsuke.stapler.Stapler.tryInvoke(Stapler.java:746)
... 48 more
Caused by: java.net.SocketException: Connection reset
at java.net.SocketInputStream.read(SocketInputStream.java:196)
at java.net.SocketInputStream.read(SocketInputStream.java:122)
at sun.security.ssl.InputRecord.readFully(InputRecord.java:442)
at sun.security.ssl.InputRecord.read(InputRecord.java:480)
at sun.security.ssl.SSLSocketImpl.readRecord(SSLSocketImpl.java:946)
at sun.security.ssl.SSLSocketImpl.performInitialHandshake(SSLSocketImpl.java:1344)
at sun.security.ssl.SSLSocketImpl.startHandshake(SSLSocketImpl.java:1371)
at sun.security.ssl.SSLSocketImpl.startHandshake(SSLSocketImpl.java:1355)
at sun.net.www.protocol.https.HttpsClient.afterConnect(HttpsClient.java:559)
at sun.net.www.protocol.https.AbstractDelegateHttpsURLConnection.connect(AbstractDelegateHttpsURLConnection.java:185)
at sun.net.www.protocol.http.HttpURLConnection.getInputStream(HttpURLConnection.java:1301)
at sun.net.www.protocol.https.HttpsURLConnectionImpl.getInputStream(HttpsURLConnectionImpl.java:254)
at org.gitlab.api.http.GitlabHTTPRequestor.parse(GitlabHTTPRequestor.java:283)
at org.gitlab.api.http.GitlabHTTPRequestor.access$200(GitlabHTTPRequestor.java:39)
at org.gitlab.api.http.GitlabHTTPRequestor$1.fetch(GitlabHTTPRequestor.java:211)
... 71 more
Also when I tried to setup GitLab-Plugin
in same environment, similar error happened.
Both ends at the same function.
Caused by: java.net.SocketException: Connection reset
at java.net.SocketInputStream.read(SocketInputStream.java:196)
at java.net.SocketInputStream.read(SocketInputStream.java:122)
at sun.security.ssl.InputRecord.readFully(InputRecord.java:442)
at sun.security.ssl.InputRecord.read(InputRecord.java:480)
at sun.security.ssl.SSLSocketImpl.readRecord(SSLSocketImpl.java:946)
at sun.security.ssl.SSLSocketImpl.performInitialHandshake(SSLSocketImpl.java:1344)
at sun.security.ssl.SSLSocketImpl.startHandshake(SSLSocketImpl.java:1371)
at sun.security.ssl.SSLSocketImpl.startHandshake(SSLSocketImpl.java:1355)
at sun.net.www.protocol.https.HttpsClient.afterConnect(HttpsClient.java:559)
at sun.net.www.protocol.https.AbstractDelegateHttpsURLConnection.connect(AbstractDelegateHttpsURLConnection.java:185)
at sun.net.www.protocol.http.HttpURLConnection.getInputStream(HttpURLConnection.java:1301)
at sun.net.www.protocol.https.HttpsURLConnectionImpl.getInputStream(HttpsURLConnectionImpl.java:254)
at org.gitlab.api.http.GitlabHTTPRequestor.parse(GitlabHTTPRequestor.java:283)
at org.gitlab.api.http.GitlabHTTPRequestor.access$200(GitlabHTTPRequestor.java:39)
at org.gitlab.api.http.GitlabHTTPRequestor$1.fetch(GitlabHTTPRequestor.java:211)
... 63 more
My question is, can it be used behind proxy?
Thank you.
Can anyone else confirm that doing a PUT where the email address is specified for a user, does not take effect? All other fields seem to work for me, but I noticed that the 'email' field of a user does not ever seem to change after API calls.
I couldn't find 1.1.7 on Maven central.
Whats the plan to create a new 1.1.5 release? and push to Maven repo?
I'm currently developing a Jenkins integration. Would be super handy to have the avatar_url
to spice up the GUI.
Like the one mentioned here,
https://github.com/gitlabhq/gitlabhq/blob/master/doc/api/commits.md
Is there a way to do this besides gettings all notes and iterating over them? It should be possible by calling
GET /projects/:id/issues/:issue_id/notes/:note_id
right?
Thanks!
Is anyone else experiencing duplicate projects when getProjects() or getAllProjects() is called ?
I'm getting duplicate projects ( same ids, namespaces, etc ) in the response - is this a bug in the client / api / me ?
I'm using 1.1.4-SNAPSHOT (cloned and built locally)
Sorry if this is not a bug of this client, but didnt have anywhere else to ask.
Thanks.
This is a enhancement, not knew where to raise it
Scenario, app only know project name or HTTP URL of the project, have to check if the project exists or not before checking out
No API wrapper method exists to achieve this
Will be helpful if can be provided
I tried directly as below, which failed though
String myProjectName = "TestProject";
GitlabProject project = api.retrieve()
.with("per_page", "1")
.with("page", "1")
.to( (GitlabProject.URL + "/search/" + myProjectName), GitlabProject.class);
Not sure whats the reason
Would it be possible to move some model specific functions to their appropriate models, like moving getOpenMergeRequests to the GitlabProject model, this way you could get the open merge requests from the current project, instead of passing the project as a parameter.
List repository tree
Get a list of repository files and directories in a project.
GET /projects/:id/repository/tree
Is List repository tree
supported?
If I understand the code correctly, it expectes the project id to be part of the returned json data from gitlab. But this is not the case.
Instead, the project id is already part of the request.
Currently the merge request builder for jenkins fails because of it. It tries to get the merge request nodes, but tries to get them with an URL without a proper project id.
Any chance you can release an update soon? It looks like a lot of functionality has been added since 1.2.5 and it would be nice to get that from the release package.
Hi timols,
when you call the method GitlabApi.findUsers("") with an empty string, it returns strange results. I would expect that there will be returned no user or all users. In my case, we got more than 100 users, but it returns a list of about 10 users..
Best regards,
Stefan
If the hostname (or IP) being used does not match the hostname in the certificate, ignoreCertificateErrors will not do enough to avoid an SSL certificate exception.
Need to add this:
HostnameVerifier nullVerifier = new HostnameVerifier() {
@Override
public boolean verify(String hostname, SSLSession session) {
return true;
}
};
// ...
HttpsURLConnection.setDefaultHostnameVerifier(nullVerifier);
Support for downloading git file blobs:
http://doc.gitlab.com/ce/api/repositories.html#raw-file-content
http://doc.gitlab.com/ce/api/repositories.html#raw-blob-content
http://doc.gitlab.com/ce/api/repositories.html#get-file-archive
example call:
/api/v3/projects/74/repository/blobs/develop?filepath=filepath/file.txt
The icon exist on the user interface to remove a comment but the API does not provide this feature.
It is required when a tool automatically creates comments on a commit and we don't want comments being duplicated after each execution. The tool needs to remove (or update) previous comments.
I have a GitLab server running on, say, http://mygitlab.example.com
. I have a service account user (username=my_service_account
, password=changeme
)that has full read/write/API access to a cooldevs
group on that server. I am trying to write Java code that will create a new repo/project under cooldevs
.
I understand that I need to use the createProject(...)
endpoint, however it is not obvious to me how I can connect to the server in the first place. According to your unit tests, it looks like I will need a token in addition to my service account's username/password. So I believe the connection will look something like:
GitlabAPI api = GitlabAPI.connect("http://mygitlab.example.com", TEST_TOKEN);
api.dispatch().with("login", "my_service_account")
.with("password", "changeme").to("session", GitlabUser.class);
api.createProject(...) // etc.
Can someone confirm that I'm on the right path (or correct me where I'm wrong)? How do I get a valid token to pass into the connect(...)
method? Is there anything I need to do to politely close the connection when I'm done with it?
Once I get this working I'll happily contribute documentation and unit tests that show this for future comers! Thanks!
Hi timols,
please perform a release of 1.1.10 stable to mvn central.
Thanks a lot,
Grogdunn
I'm using the java-gitlab-api with the jenkins-gitlab-merge-request-builder-plugin and I setup the Jenkins comments to be:
OK --> "Build finished. Tests PASSED. ๐"
Falha --> "Build finished. Tests FAILED. ๐"
The messages in the merge request are OK, with the thumbs up or down, but the up vote or down vote counter does not change.
Thanks
Sigrist
According to the documentation in the 'List Repository Tree section' (http://doc.gitlab.com/ce/api/repositories.html) it is possible to define the 'path' attribute to List files/dirs in some directory. Because it's GET request the params must be appended to the url by ? and & chars the same way like 'private_token'. Currently the GET params seems to be ignored (I get only the file in the root dir) when building the request like:
String tailUrl = GitlabProject.URL + "/" + projectId + "/" + "repository" + "/" + "tree";
getConnection().dispatch()
.method("GET")
.with("id", projectId)
.with("path", path)
.with("ref_name", branchName)
.to(tailUrl, ListFilesResponse[].class);
I'm using the last 1.1.4 version from maven repo (http://mvnrepository.com/artifact/org.gitlab/java-gitlab-api).
Thank you
Hi @timols,
I started your great api client and just noticed there is a fix for the comments line_type
still not released.
When are you planning to release this? Would really appreciate if you could do this asap.
Hi,
I have a change which I would like to push into master regarding the for createMergeRequest operation. How can I get access to do that?
Hi, There is about 286 projects, I use GitlabAPI getAllProjects
method to get all projects, It spend 10 seconds about.
This is a feature request to support Authentication via Headers.
My use case:
I'm writing a Jenkins integration using this API wrapper. The current authentication with a GET parameter logs the token all over the place in Jenkins. I'd be happy to hide the token from the logs by moving the authentication data to the Headers.
We have groups which have ldap_access with value null, as these groups are not associated with ldap. When i try to get the list of groups from our gitlab using API, it blows up at setLdapAccess(GitlabAccessLevel ldapGitlabAccessLevel). When i add a condition to check if "ldapGitlabAccessLevel' is null, GitlabGroup object is created fine. Will this issue be fixed? or i can submit a fix.
I try to complie source with gradle and have problems.
Dependency failure:
diff --git a/build.gradle b/build.gradle
index 7614416..fcb4d0d 100644
--- a/build.gradle
+++ b/build.gradle
@@ -19,6 +19,8 @@ repositories {
}
dependencies {
+ compile "com.fasterxml.jackson.core:jackson-databind:2.6.1"
+
compile(group: 'org.codehaus.jackson', name: 'jackson-core-asl', version: '1.9.13')
compile(group: 'org.codehaus.jackson', name: 'jackson-mapper-asl', version: '1.9.13')
compile(group: 'commons-io', name: 'commons-io', version: '1.4')
And compilation failure:
:compileTestJava
warning: [options] bootstrap class path not set in conjunction with -source 1.7
/home/bozaro/github/java-gitlab-api/src/test/java/org/gitlab/api/GitlabAPIT.java:89: error: method updateUser in class GitlabAPI cannot be applied to given types;
api.updateUser(gitUser.getId(), gitUser.getEmail(), password, gitUser.getUsername(),
^
required: Integer,String,String,String,String,String,String,String,String,Integer,String,String,String,Boolean,Boolean
found: Integer,String,String,String,String,String,String,String,String,int,String,String,String,boolean,boolean,boolean
reason: actual and formal argument lists differ in length
1 error
1 warning
The Gitlab REST API supports the ability to set a default branch for a project. This allows Gitlab to display the README.md from the default branch when viewing the project. Please enhance the existing GitlabAPI.updateProject() method to include an additional argument for the default branch.
The Gitlab REST API documents the "default_branch" field here:
http://doc.gitlab.com/ce/api/projects.html#edit-project
Hi,
I have problem with user listing call.
If I do https://gitlab.com/api/v3/users?private_token=$TOKEN it takes 599ms
If I try to do the same with api.getUsers() it never finishes. I am using same token and https://gitlab.com
Any ideas?
Thanks.
Hi,
I don't see any method for adding members to groups. Gitlab API have appropriate query for this. Perhaps can you add this functionality?
See this ;)
https://github.com/gitlabhq/gitlabhq/blob/master/doc/api/groups.md#add-group-member
Hello guys,
I have the following problem:
Before the update gitlab I created a section with the default User's gitlab (root, 5iveL! Fe).
String username = "root";
String password = "5iveL!fe";
URI uri = new URI("http://10.100.100.119:8001");
GitlabSession sessionRoot = GitlabAPI.connect(uri.toString(), username, password);
String myToken = sessionRoot.getPrivateToken()
However after upgrading gitlab the default password (5iveL! Fe) has been disabled and the first access to gitlab is prompted to change the default password. That is, I can no longer create a section with the default User gitlab(root, 5iveL! Fe). Any solution?
8.9 introduced a new way of adding emojis to merge requests/issues/notes, http://docs.gitlab.com/ce/api/award_emoji.html.
A declarative, efficient, and flexible JavaScript library for building user interfaces.
๐ Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. ๐๐๐
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google โค๏ธ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.