diff --git a/gitlab4j-test/FileUploadScript.java b/gitlab4j-test/FileUploadScript.java index 181cef5..a0b96bb 100755 --- a/gitlab4j-test/FileUploadScript.java +++ b/gitlab4j-test/FileUploadScript.java @@ -1,7 +1,7 @@ ///usr/bin/env jbang "$0" "$@" ; exit $? //DEPS info.picocli:picocli:4.6.3 -//DEPS org.gitlab4j:gitlab4j-api:5.4.0 +//DEPS https://github.com/gitlab4j/gitlab4j-api/commit/5805b41bae64b6c287abdbd51f63ce84d1ec8b90 //JAVA 17 import java.io.FileInputStream; @@ -31,6 +31,9 @@ class FileUploadScript implements Callable { @Option(names = { "-p", "--project" }, description = "project (id or path)") private String project; + @Option(names = { "-g", "--group" }, description = "group") + private String group; + @Option(names = { "-f", "--file" }, description = "Path to the file to uplaod") private String filePath; @@ -40,6 +43,9 @@ class FileUploadScript implements Callable { @Option(names = { "-c", "--config" }, description = "configuration file location") String configFile; + @Option(names = { "-v", "--verbose" }, description = "log http trafic") + Boolean logHttp; + @Override public Integer call() throws Exception { Path file; @@ -59,30 +65,40 @@ public Integer call() throws Exception { throw new IllegalStateException("Can not find file: " + fileToUpload.toAbsolutePath()); } - try (GitLabApi gitLabApi = new GitLabApi(gitLabUrl, gitLabAuthValue)) { - projectIdMandatory(); - // FileUpload uplaodedFile = gitLabApi.getProjectApi() - // .uploadFile(idOrPath(projectId), fileToUpload.toFile()); + try (GitLabApi gitLabApi = createGitLabApi(gitLabUrl, gitLabAuthValue)) { if (filename == null) { filename = fileToUpload.getFileName() .toString(); } - FileUpload uplaodedFile = gitLabApi.getProjectApi() - .uploadFile(idOrPath(project), Files.newInputStream(fileToUpload), filename, null); - System.out.println(uplaodedFile); + if(project == null && group == null) { + throw new IllegalStateException("Project or group is mandatory"); + } else if(project != null && group != null) { + throw new IllegalStateException("Project and group can't be set at the same time"); + } else if(project != null) { + FileUpload uplaodedFile = gitLabApi.getProjectApi() + .uploadFile(idOrPath(project), Files.newInputStream(fileToUpload), filename, null); + System.out.println(uplaodedFile); + } else if(group != null) { + FileUpload uplaodedFile = gitLabApi.getGroupApi() + .uploadFile(idOrPath(group), Files.newInputStream(fileToUpload), filename, null); + System.out.println(uplaodedFile); + } } return 0; } - private void filePathMandatory() { - if (filePath == null) { - throw new IllegalStateException("File is mandatory"); + private GitLabApi createGitLabApi(String gitLabUrl, String gitLabAuthValue) { + if (logHttp != null && logHttp) { + return new GitLabApi(gitLabUrl, gitLabAuthValue) + .withRequestResponseLogging(java.util.logging.Level.INFO) ; } + return new GitLabApi(gitLabUrl, gitLabAuthValue); } - private void projectIdMandatory() { - if (project == null) { - throw new IllegalStateException("Project is mandatory"); + + private void filePathMandatory() { + if (filePath == null) { + throw new IllegalStateException("File is mandatory"); } } diff --git a/gitlab4j-test/GitLabCiYamlScript.java b/gitlab4j-test/GitLabCiYamlScript.java index e6646bf..98a53f5 100755 --- a/gitlab4j-test/GitLabCiYamlScript.java +++ b/gitlab4j-test/GitLabCiYamlScript.java @@ -1,7 +1,7 @@ ///usr/bin/env jbang "$0" "$@" ; exit $? //DEPS info.picocli:picocli:4.6.3 -//DEPS org.gitlab4j:gitlab4j-api:5.4.0 +//DEPS org.gitlab4j:gitlab4j-api:5.6.0 //JAVA 17 import java.io.File; diff --git a/gitlab4j-test/GitLabScript.java b/gitlab4j-test/GitLabScript.java index c520dfc..f4c0c91 100755 --- a/gitlab4j-test/GitLabScript.java +++ b/gitlab4j-test/GitLabScript.java @@ -1,6 +1,6 @@ ///usr/bin/env jbang "$0" "$@" ; exit $? -//DEPS org.gitlab4j:gitlab4j-api:5.4.0 +//DEPS org.gitlab4j:gitlab4j-api:5.6.0 //JAVA 17 import java.util.logging.Level; diff --git a/gitlab4j-test/GroupScript.java b/gitlab4j-test/GroupScript.java index a5a645d..acf876d 100755 --- a/gitlab4j-test/GroupScript.java +++ b/gitlab4j-test/GroupScript.java @@ -1,7 +1,7 @@ ///usr/bin/env jbang "$0" "$@" ; exit $? //DEPS info.picocli:picocli:4.6.3 -//DEPS https://github.com/simon-weimann/gitlab4j-api/commit/7842c72bad980f2e582b649a91fce326c7dba7e1 +//DEPS https://github.com/gitlab4j/gitlab4j-api/commit/5805b41bae64b6c287abdbd51f63ce84d1ec8b90 //JAVA 17 import java.io.FileInputStream; @@ -39,8 +39,11 @@ public class GroupScript implements Callable { @Option(names = { "-c", "--config" }, description = "configuration file location") String configFile; + @Option(names = { "-v", "--verbose" }, description = "log http trafic") + Boolean logHttp; + private static enum Action { - GET_GROUP + GET_GROUP, GET_GROUP_LABELS, GET_GROUP_UPLOADS } @Override @@ -57,13 +60,25 @@ public Integer call() throws Exception { final String gitLabAuthValue = readProperty(prop, "GITLAB_AUTH_VALUE"); - try (GitLabApi gitLabApi = new GitLabApi(gitLabUrl, gitLabAuthValue)) { + try (GitLabApi gitLabApi = createGitLabApi(gitLabUrl, gitLabAuthValue)) { switch (action) { case GET_GROUP: ensureExists(group, "group"); - var result = gitLabApi.getGroupApi() + var groupResponse = gitLabApi.getGroupApi() .getGroup(idOrPath(group)); - System.out.println(result); + System.out.println(groupResponse); + break; + case GET_GROUP_LABELS: + ensureExists(group, "group"); + var labelsResponse = gitLabApi.getLabelsApi() + .getGroupLabels(idOrPath(group)); + System.out.println(labelsResponse); + break; + case GET_GROUP_UPLOADS: + ensureExists(group, "group"); + var uploadsResponse = gitLabApi.getGroupApi() + .getUploadFiles(idOrPath(group)); + System.out.println(uploadsResponse); break; default: throw new IllegalArgumentException("Unexpected value: " + action); @@ -72,6 +87,15 @@ public Integer call() throws Exception { return 0; } + private GitLabApi createGitLabApi(String gitLabUrl, String gitLabAuthValue) { + if (logHttp != null && logHttp) { + return new GitLabApi(gitLabUrl, gitLabAuthValue) + .withRequestResponseLogging(java.util.logging.Level.INFO) ; + } + return new GitLabApi(gitLabUrl, gitLabAuthValue); + } + + private void ensureExists(Object value, String optionName) { if (value == null) { throw new IllegalStateException("--" + optionName + " must be set"); diff --git a/gitlab4j-test/IssueScript.java b/gitlab4j-test/IssueScript.java index f7ba20f..e294016 100755 --- a/gitlab4j-test/IssueScript.java +++ b/gitlab4j-test/IssueScript.java @@ -1,7 +1,7 @@ ///usr/bin/env jbang "$0" "$@" ; exit $? //DEPS info.picocli:picocli:4.6.3 -//DEPS https://github.com/jmini/gitlab4j-api/commit/c3981f425828088f6d8f25d1435b5c2953fc1a35 +//DEPS https://github.com/jmini/gitlab4j-api/commit/436fb4edadb6b72641dbf836ee4fdb792ac0ab32 //JAVA 17 import java.io.FileInputStream; @@ -99,7 +99,7 @@ public Integer call() throws Exception { case GET_LINKED_ISSUES: ensureExists(project, "project"); ensureExists(issueIid, "issue"); - List linkedIssue = gitLabApi.getIssuesApi() + var linkedIssue = gitLabApi.getIssuesApi() .getIssueLinks(idOrPath(project), issueIid); System.out.println(linkedIssue); break; diff --git a/gitlab4j-test/IterationScript.java b/gitlab4j-test/IterationScript.java index 9d3c93e..5003d92 100755 --- a/gitlab4j-test/IterationScript.java +++ b/gitlab4j-test/IterationScript.java @@ -1,7 +1,7 @@ ///usr/bin/env jbang "$0" "$@" ; exit $? //DEPS info.picocli:picocli:4.6.3 -//DEPS org.gitlab4j:gitlab4j-api:5.4.0 +//DEPS org.gitlab4j:gitlab4j-api:5.6.0 //JAVA 17 import java.io.FileInputStream; diff --git a/gitlab4j-test/JobScript.java b/gitlab4j-test/JobScript.java index eee173a..3765cd7 100755 --- a/gitlab4j-test/JobScript.java +++ b/gitlab4j-test/JobScript.java @@ -1,7 +1,7 @@ ///usr/bin/env jbang "$0" "$@" ; exit $? //DEPS info.picocli:picocli:4.6.3 -//DEPS org.gitlab4j:gitlab4j-api:5.4.0 +//DEPS org.gitlab4j:gitlab4j-api:5.6.0 //JAVA 17 import java.io.*; diff --git a/gitlab4j-test/LabelScript.java b/gitlab4j-test/LabelScript.java index 65b499a..2262263 100755 --- a/gitlab4j-test/LabelScript.java +++ b/gitlab4j-test/LabelScript.java @@ -1,7 +1,7 @@ ///usr/bin/env jbang "$0" "$@" ; exit $? //DEPS info.picocli:picocli:4.6.3 -//DEPS org.gitlab4j:gitlab4j-api:5.4.0 +//DEPS org.gitlab4j:gitlab4j-api:5.6.0 //JAVA 17 import java.io.FileInputStream; diff --git a/gitlab4j-test/MetadataScript.java b/gitlab4j-test/MetadataScript.java index f0ee447..9bff942 100755 --- a/gitlab4j-test/MetadataScript.java +++ b/gitlab4j-test/MetadataScript.java @@ -1,7 +1,7 @@ ///usr/bin/env jbang "$0" "$@" ; exit $? //DEPS info.picocli:picocli:4.6.3 -//DEPS org.gitlab4j:gitlab4j-api:5.4.0 +//DEPS org.gitlab4j:gitlab4j-api:5.6.0 //JAVA 17 import java.io.File; diff --git a/gitlab4j-test/NoteScript.java b/gitlab4j-test/NoteScript.java index 1902db7..a1cf2fe 100755 --- a/gitlab4j-test/NoteScript.java +++ b/gitlab4j-test/NoteScript.java @@ -1,7 +1,7 @@ ///usr/bin/env jbang "$0" "$@" ; exit $? //DEPS info.picocli:picocli:4.6.3 -//DEPS org.gitlab4j:gitlab4j-api:5.4.0 +//DEPS org.gitlab4j:gitlab4j-api:5.6.0 //JAVA 17 import java.io.FileInputStream; diff --git a/gitlab4j-test/ProjectsScript.java b/gitlab4j-test/ProjectsScript.java index 71a18e4..fab9bd6 100755 --- a/gitlab4j-test/ProjectsScript.java +++ b/gitlab4j-test/ProjectsScript.java @@ -1,7 +1,7 @@ ///usr/bin/env jbang "$0" "$@" ; exit $? //DEPS info.picocli:picocli:4.6.3 -//DEPS org.gitlab4j:gitlab4j-api:5.4.0 +//DEPS org.gitlab4j:gitlab4j-api:5.6.0 //JAVA 17 import java.io.File; @@ -14,6 +14,7 @@ import java.util.List; import java.util.Properties; import java.util.concurrent.Callable; +import java.util.logging.Level; import org.gitlab4j.api.*; import org.gitlab4j.api.models.*; @@ -52,6 +53,9 @@ class ProjectsScript implements Callable { @Option(names = { "-c", "--config" }, description = "configuration file location") String configFile; + @Option(names = { "-v", "--verbose" }, description = "log http trafic") + Boolean logHttp; + private static enum Action { PRINT_PROJECT, PRINT_PROJECTS, CREATE_PROJECT, UPDATE_PROJECT, DELETE_PROJECT } @@ -69,7 +73,7 @@ public Integer call() throws Exception { String gitLabUrl = readProperty(prop, "GITLAB_URL", "https://gitlab.com"); String gitLabAuthValue = readProperty(prop, "GITLAB_AUTH_VALUE"); - try (GitLabApi gitLabApi = new GitLabApi(gitLabUrl, gitLabAuthValue)) { + try (GitLabApi gitLabApi = createGitLabApi(gitLabUrl, gitLabAuthValue)) { System.out.println("Action " + action + " ..."); Project project; @@ -120,6 +124,14 @@ public Integer call() throws Exception { return 0; } + private GitLabApi createGitLabApi(String gitLabUrl, String gitLabAuthValue) { + if (logHttp != null && logHttp) { + return new GitLabApi(gitLabUrl, gitLabAuthValue) + .withRequestResponseLogging(java.util.logging.Level.INFO); + } + return new GitLabApi(gitLabUrl, gitLabAuthValue); + } + private void projectIdMandatory() { if (projectId == null) { throw new IllegalStateException("Project id is mandatory"); diff --git a/gitlab4j-test/ReleaseScript.java b/gitlab4j-test/ReleaseScript.java index 7e33cc8..12521ed 100755 --- a/gitlab4j-test/ReleaseScript.java +++ b/gitlab4j-test/ReleaseScript.java @@ -1,7 +1,7 @@ ///usr/bin/env jbang "$0" "$@" ; exit $? //DEPS info.picocli:picocli:4.6.3 -//DEPS org.gitlab4j:gitlab4j-api:5.4.0 +//DEPS org.gitlab4j:gitlab4j-api:5.6.0 //JAVA 17 import java.io.FileInputStream; diff --git a/gitlab4j-test/SearchScript.java b/gitlab4j-test/SearchScript.java index 51e9766..34802dc 100755 --- a/gitlab4j-test/SearchScript.java +++ b/gitlab4j-test/SearchScript.java @@ -1,7 +1,7 @@ ///usr/bin/env jbang "$0" "$@" ; exit $? //DEPS info.picocli:picocli:4.6.3 -//DEPS org.gitlab4j:gitlab4j-api:5.4.0 +//DEPS org.gitlab4j:gitlab4j-api:5.6.0 //JAVA 17 import java.io.FileInputStream; diff --git a/gitlab4j-test/TopicsScript.java b/gitlab4j-test/TopicsScript.java index 0cc06f9..c606434 100755 --- a/gitlab4j-test/TopicsScript.java +++ b/gitlab4j-test/TopicsScript.java @@ -1,7 +1,7 @@ ///usr/bin/env jbang "$0" "$@" ; exit $? //DEPS info.picocli:picocli:4.6.3 -//DEPS org.gitlab4j:gitlab4j-api:5.4.0 +//DEPS org.gitlab4j:gitlab4j-api:5.6.0 //JAVA 17 import java.io.File; diff --git a/gitlab4j-test/command.txt b/gitlab4j-test/command.txt index 3c5ed90..a9d5950 100644 --- a/gitlab4j-test/command.txt +++ b/gitlab4j-test/command.txt @@ -54,6 +54,14 @@ With: File to include `*.java` +-------- + +Build all with jbang: + +``` +find . -name '*.java' -exec jbang build {} \; +``` + ========================================== Have a look at the PR https://github.com/gitlab4j/gitlab4j-api/pull/0000 (feel free to review it and give feedback)