Skip to content

Commit df17d98

Browse files
committed
Add GitLabScript (very simple script using gitlab4j)
1 parent f264a41 commit df17d98

File tree

1 file changed

+37
-0
lines changed

1 file changed

+37
-0
lines changed

gitlab4j-test/GitLabScript.java

Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
///usr/bin/env jbang "$0" "$@" ; exit $?
2+
3+
//DEPS org.gitlab4j:gitlab4j-api:5.4.0
4+
//JAVA 17
5+
6+
import java.util.logging.Level;
7+
import java.util.logging.Logger;
8+
9+
import org.gitlab4j.api.*;
10+
import org.gitlab4j.api.models.*;
11+
12+
class GitlabScript {
13+
14+
public static void main(String... args) throws Exception {
15+
if(args.length != 1) {
16+
System.out.println("Project id parameter is missing");
17+
System.exit(1);
18+
}
19+
String projectId = args[0];
20+
21+
try (GitLabApi gitLabApi = new GitLabApi("https://gitlab.com", null)) {
22+
Logger one = Logger.getLogger(GitlabScript.class.getName());
23+
gitLabApi.enableRequestResponseLogging(one, Level.INFO, 4096);
24+
25+
Project project = gitLabApi.getProjectApi()
26+
.getProject(idOrPath(projectId));
27+
System.out.println(project);
28+
}
29+
}
30+
31+
private static Object idOrPath(String value) {
32+
if (value.matches("[0-9]+")) {
33+
return Long.valueOf(value);
34+
}
35+
return value;
36+
}
37+
}

0 commit comments

Comments
 (0)