Skip to content

Commit 89a3632

Browse files
committed
Update jbang test scripts
1 parent a09c0b7 commit 89a3632

15 files changed

+93
-33
lines changed

gitlab4j-test/FileUploadScript.java

Lines changed: 30 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
///usr/bin/env jbang "$0" "$@" ; exit $?
22

33
//DEPS info.picocli:picocli:4.6.3
4-
//DEPS org.gitlab4j:gitlab4j-api:5.4.0
4+
//DEPS https://github.com/gitlab4j/gitlab4j-api/commit/5805b41bae64b6c287abdbd51f63ce84d1ec8b90
55
//JAVA 17
66

77
import java.io.FileInputStream;
@@ -31,6 +31,9 @@ class FileUploadScript implements Callable<Integer> {
3131
@Option(names = { "-p", "--project" }, description = "project (id or path)")
3232
private String project;
3333

34+
@Option(names = { "-g", "--group" }, description = "group")
35+
private String group;
36+
3437
@Option(names = { "-f", "--file" }, description = "Path to the file to uplaod")
3538
private String filePath;
3639

@@ -40,6 +43,9 @@ class FileUploadScript implements Callable<Integer> {
4043
@Option(names = { "-c", "--config" }, description = "configuration file location")
4144
String configFile;
4245

46+
@Option(names = { "-v", "--verbose" }, description = "log http trafic")
47+
Boolean logHttp;
48+
4349
@Override
4450
public Integer call() throws Exception {
4551
Path file;
@@ -59,30 +65,40 @@ public Integer call() throws Exception {
5965
throw new IllegalStateException("Can not find file: " + fileToUpload.toAbsolutePath());
6066
}
6167

62-
try (GitLabApi gitLabApi = new GitLabApi(gitLabUrl, gitLabAuthValue)) {
63-
projectIdMandatory();
64-
// FileUpload uplaodedFile = gitLabApi.getProjectApi()
65-
// .uploadFile(idOrPath(projectId), fileToUpload.toFile());
68+
try (GitLabApi gitLabApi = createGitLabApi(gitLabUrl, gitLabAuthValue)) {
6669
if (filename == null) {
6770
filename = fileToUpload.getFileName()
6871
.toString();
6972
}
70-
FileUpload uplaodedFile = gitLabApi.getProjectApi()
71-
.uploadFile(idOrPath(project), Files.newInputStream(fileToUpload), filename, null);
72-
System.out.println(uplaodedFile);
73+
if(project == null && group == null) {
74+
throw new IllegalStateException("Project or group is mandatory");
75+
} else if(project != null && group != null) {
76+
throw new IllegalStateException("Project and group can't be set at the same time");
77+
} else if(project != null) {
78+
FileUpload uplaodedFile = gitLabApi.getProjectApi()
79+
.uploadFile(idOrPath(project), Files.newInputStream(fileToUpload), filename, null);
80+
System.out.println(uplaodedFile);
81+
} else if(group != null) {
82+
FileUpload uplaodedFile = gitLabApi.getGroupApi()
83+
.uploadFile(idOrPath(group), Files.newInputStream(fileToUpload), filename, null);
84+
System.out.println(uplaodedFile);
85+
}
7386
}
7487
return 0;
7588
}
7689

77-
private void filePathMandatory() {
78-
if (filePath == null) {
79-
throw new IllegalStateException("File is mandatory");
90+
private GitLabApi createGitLabApi(String gitLabUrl, String gitLabAuthValue) {
91+
if (logHttp != null && logHttp) {
92+
return new GitLabApi(gitLabUrl, gitLabAuthValue)
93+
.withRequestResponseLogging(java.util.logging.Level.INFO) ;
8094
}
95+
return new GitLabApi(gitLabUrl, gitLabAuthValue);
8196
}
8297

83-
private void projectIdMandatory() {
84-
if (project == null) {
85-
throw new IllegalStateException("Project is mandatory");
98+
99+
private void filePathMandatory() {
100+
if (filePath == null) {
101+
throw new IllegalStateException("File is mandatory");
86102
}
87103
}
88104

gitlab4j-test/GitLabCiYamlScript.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
///usr/bin/env jbang "$0" "$@" ; exit $?
22

33
//DEPS info.picocli:picocli:4.6.3
4-
//DEPS org.gitlab4j:gitlab4j-api:5.4.0
4+
//DEPS org.gitlab4j:gitlab4j-api:5.6.0
55
//JAVA 17
66

77
import java.io.File;

gitlab4j-test/GitLabScript.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
///usr/bin/env jbang "$0" "$@" ; exit $?
22

3-
//DEPS org.gitlab4j:gitlab4j-api:5.4.0
3+
//DEPS org.gitlab4j:gitlab4j-api:5.6.0
44
//JAVA 17
55

66
import java.util.logging.Level;

gitlab4j-test/GroupScript.java

Lines changed: 29 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
///usr/bin/env jbang "$0" "$@" ; exit $?
22

33
//DEPS info.picocli:picocli:4.6.3
4-
//DEPS https://github.com/simon-weimann/gitlab4j-api/commit/7842c72bad980f2e582b649a91fce326c7dba7e1
4+
//DEPS https://github.com/gitlab4j/gitlab4j-api/commit/5805b41bae64b6c287abdbd51f63ce84d1ec8b90
55
//JAVA 17
66

77
import java.io.FileInputStream;
@@ -39,8 +39,11 @@ public class GroupScript implements Callable<Integer> {
3939
@Option(names = { "-c", "--config" }, description = "configuration file location")
4040
String configFile;
4141

42+
@Option(names = { "-v", "--verbose" }, description = "log http trafic")
43+
Boolean logHttp;
44+
4245
private static enum Action {
43-
GET_GROUP
46+
GET_GROUP, GET_GROUP_LABELS, GET_GROUP_UPLOADS
4447
}
4548

4649
@Override
@@ -57,13 +60,25 @@ public Integer call() throws Exception {
5760
final String gitLabAuthValue = readProperty(prop, "GITLAB_AUTH_VALUE");
5861

5962

60-
try (GitLabApi gitLabApi = new GitLabApi(gitLabUrl, gitLabAuthValue)) {
63+
try (GitLabApi gitLabApi = createGitLabApi(gitLabUrl, gitLabAuthValue)) {
6164
switch (action) {
6265
case GET_GROUP:
6366
ensureExists(group, "group");
64-
var result = gitLabApi.getGroupApi()
67+
var groupResponse = gitLabApi.getGroupApi()
6568
.getGroup(idOrPath(group));
66-
System.out.println(result);
69+
System.out.println(groupResponse);
70+
break;
71+
case GET_GROUP_LABELS:
72+
ensureExists(group, "group");
73+
var labelsResponse = gitLabApi.getLabelsApi()
74+
.getGroupLabels(idOrPath(group));
75+
System.out.println(labelsResponse);
76+
break;
77+
case GET_GROUP_UPLOADS:
78+
ensureExists(group, "group");
79+
var uploadsResponse = gitLabApi.getGroupApi()
80+
.getUploadFiles(idOrPath(group));
81+
System.out.println(uploadsResponse);
6782
break;
6883
default:
6984
throw new IllegalArgumentException("Unexpected value: " + action);
@@ -72,6 +87,15 @@ public Integer call() throws Exception {
7287
return 0;
7388
}
7489

90+
private GitLabApi createGitLabApi(String gitLabUrl, String gitLabAuthValue) {
91+
if (logHttp != null && logHttp) {
92+
return new GitLabApi(gitLabUrl, gitLabAuthValue)
93+
.withRequestResponseLogging(java.util.logging.Level.INFO) ;
94+
}
95+
return new GitLabApi(gitLabUrl, gitLabAuthValue);
96+
}
97+
98+
7599
private void ensureExists(Object value, String optionName) {
76100
if (value == null) {
77101
throw new IllegalStateException("--" + optionName + " must be set");

gitlab4j-test/IssueScript.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
///usr/bin/env jbang "$0" "$@" ; exit $?
22

33
//DEPS info.picocli:picocli:4.6.3
4-
//DEPS https://github.com/jmini/gitlab4j-api/commit/c3981f425828088f6d8f25d1435b5c2953fc1a35
4+
//DEPS https://github.com/jmini/gitlab4j-api/commit/436fb4edadb6b72641dbf836ee4fdb792ac0ab32
55
//JAVA 17
66

77
import java.io.FileInputStream;
@@ -99,7 +99,7 @@ public Integer call() throws Exception {
9999
case GET_LINKED_ISSUES:
100100
ensureExists(project, "project");
101101
ensureExists(issueIid, "issue");
102-
List<Issue> linkedIssue = gitLabApi.getIssuesApi()
102+
var linkedIssue = gitLabApi.getIssuesApi()
103103
.getIssueLinks(idOrPath(project), issueIid);
104104
System.out.println(linkedIssue);
105105
break;

gitlab4j-test/IterationScript.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
///usr/bin/env jbang "$0" "$@" ; exit $?
22

33
//DEPS info.picocli:picocli:4.6.3
4-
//DEPS org.gitlab4j:gitlab4j-api:5.4.0
4+
//DEPS org.gitlab4j:gitlab4j-api:5.6.0
55
//JAVA 17
66

77
import java.io.FileInputStream;

gitlab4j-test/JobScript.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
///usr/bin/env jbang "$0" "$@" ; exit $?
22

33
//DEPS info.picocli:picocli:4.6.3
4-
//DEPS org.gitlab4j:gitlab4j-api:5.4.0
4+
//DEPS org.gitlab4j:gitlab4j-api:5.6.0
55
//JAVA 17
66

77
import java.io.*;

gitlab4j-test/LabelScript.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
///usr/bin/env jbang "$0" "$@" ; exit $?
22

33
//DEPS info.picocli:picocli:4.6.3
4-
//DEPS org.gitlab4j:gitlab4j-api:5.4.0
4+
//DEPS org.gitlab4j:gitlab4j-api:5.6.0
55
//JAVA 17
66

77
import java.io.FileInputStream;

gitlab4j-test/MetadataScript.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
///usr/bin/env jbang "$0" "$@" ; exit $?
22

33
//DEPS info.picocli:picocli:4.6.3
4-
//DEPS org.gitlab4j:gitlab4j-api:5.4.0
4+
//DEPS org.gitlab4j:gitlab4j-api:5.6.0
55
//JAVA 17
66

77
import java.io.File;

gitlab4j-test/NoteScript.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
///usr/bin/env jbang "$0" "$@" ; exit $?
22

33
//DEPS info.picocli:picocli:4.6.3
4-
//DEPS org.gitlab4j:gitlab4j-api:5.4.0
4+
//DEPS org.gitlab4j:gitlab4j-api:5.6.0
55
//JAVA 17
66

77
import java.io.FileInputStream;

0 commit comments

Comments
 (0)