Skip to content

Commit 77739dd

Browse files
committed
Rework "logHttp" option
1 parent 35364b5 commit 77739dd

20 files changed

+272
-210
lines changed

gitlab4j-test/AccessTokenScript.java

+3-4
Original file line numberDiff line numberDiff line change
@@ -55,6 +55,9 @@ public Integer call() throws Exception {
5555
final String gitLabAuthValue = readProperty(prop, "GITLAB_AUTH_VALUE");
5656

5757
try (GitLabApi gitLabApi = createGitLabApi(gitLabUrl, gitLabAuthValue)) {
58+
if (logHttp != null && logHttp) {
59+
gitLabApi.enableRequestResponseLogging(java.util.logging.Level.INFO, 2000000000);
60+
}
5861
switch (action) {
5962
case GET:
6063
var selfPersonalAccessToken = gitLabApi.getPersonalAccessTokenApi()
@@ -69,10 +72,6 @@ public Integer call() throws Exception {
6972
}
7073

7174
private GitLabApi createGitLabApi(String gitLabUrl, String gitLabAuthValue) {
72-
if (logHttp != null && logHttp) {
73-
return new GitLabApi(gitLabUrl, gitLabAuthValue)
74-
.withRequestResponseLogging(java.util.logging.Level.INFO) ;
75-
}
7675
return new GitLabApi(gitLabUrl, gitLabAuthValue);
7776
}
7877

gitlab4j-test/BoardScript.java

+3-4
Original file line numberDiff line numberDiff line change
@@ -103,6 +103,9 @@ public Integer call() throws Exception {
103103
}
104104

105105
try (GitLabApi gitLabApi = createGitLabApi(gitLabUrl, gitLabAuthValue)) {
106+
if (logHttp != null && logHttp) {
107+
gitLabApi.enableRequestResponseLogging(java.util.logging.Level.INFO, 2000000000);
108+
}
106109
switch (action) {
107110
case GET_BOARDS:
108111
List<Board> boards;
@@ -272,10 +275,6 @@ private Board updateBoard(GitLabApi gitLabApi) throws GitLabApiException {
272275
}
273276

274277
private GitLabApi createGitLabApi(String gitLabUrl, String gitLabAuthValue) {
275-
if (logHttp != null && logHttp) {
276-
return new GitLabApi(gitLabUrl, gitLabAuthValue)
277-
.withRequestResponseLogging(java.util.logging.Level.INFO);
278-
}
279278
return new GitLabApi(gitLabUrl, gitLabAuthValue);
280279
}
281280

gitlab4j-test/EpicScript.java

+3-4
Original file line numberDiff line numberDiff line change
@@ -77,6 +77,9 @@ public Integer call() throws Exception {
7777
final String gitLabAuthValue = readProperty(prop, "GITLAB_AUTH_VALUE");
7878

7979
try (GitLabApi gitLabApi = createGitLabApi(gitLabUrl, gitLabAuthValue)) {
80+
if (logHttp != null && logHttp) {
81+
gitLabApi.enableRequestResponseLogging(java.util.logging.Level.INFO, 2000000000);
82+
}
8083
switch (action) {
8184
case GROUP_EPICS:
8285
ensureExists(group, "group");
@@ -165,10 +168,6 @@ public Integer call() throws Exception {
165168
}
166169

167170
private GitLabApi createGitLabApi(String gitLabUrl, String gitLabAuthValue) {
168-
if (logHttp != null && logHttp) {
169-
return new GitLabApi(gitLabUrl, gitLabAuthValue)
170-
.withRequestResponseLogging(java.util.logging.Level.INFO);
171-
}
172171
return new GitLabApi(gitLabUrl, gitLabAuthValue);
173172
}
174173

gitlab4j-test/FileUploadScript.java

+3-4
Original file line numberDiff line numberDiff line change
@@ -66,6 +66,9 @@ public Integer call() throws Exception {
6666
}
6767

6868
try (GitLabApi gitLabApi = createGitLabApi(gitLabUrl, gitLabAuthValue)) {
69+
if (logHttp != null && logHttp) {
70+
gitLabApi.enableRequestResponseLogging(java.util.logging.Level.INFO, 2000000000);
71+
}
6972
if (filename == null) {
7073
filename = fileToUpload.getFileName()
7174
.toString();
@@ -86,10 +89,6 @@ public Integer call() throws Exception {
8689
}
8790

8891
private GitLabApi createGitLabApi(String gitLabUrl, String gitLabAuthValue) {
89-
if (logHttp != null && logHttp) {
90-
return new GitLabApi(gitLabUrl, gitLabAuthValue)
91-
.withRequestResponseLogging(java.util.logging.Level.INFO);
92-
}
9392
return new GitLabApi(gitLabUrl, gitLabAuthValue);
9493
}
9594

gitlab4j-test/GitLabCiYamlScript.java

+20-12
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,9 @@ public class GitLabCiYamlScript 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 {
4346
GET_ALL, GET_SINGLE
4447
}
@@ -57,18 +60,23 @@ public Integer call() throws Exception {
5760
String gitLabAuthValue = readProperty(prop, "GITLAB_AUTH_VALUE");
5861

5962
try (GitLabApi gitLabApi = new GitLabApi(gitLabUrl, gitLabAuthValue)) {
60-
switch(action) {
61-
case GET_ALL:
62-
List<GitLabCiTemplateElement> list = gitLabApi.getGitLabCiYamlApi().getAllGitLabCiYamlTemplates();
63-
System.out.println(list);
64-
break;
65-
case GET_SINGLE:
66-
if (key == null) {
67-
throw new IllegalStateException("Key (--key) id is mandatory");
68-
}
69-
GitLabCiTemplate template = gitLabApi.getGitLabCiYamlApi().getSingleGitLabCiYamlTemplate(key);
70-
System.out.println(template);
71-
break;
63+
if (logHttp != null && logHttp) {
64+
gitLabApi.enableRequestResponseLogging(java.util.logging.Level.INFO, 2000000000);
65+
}
66+
switch (action) {
67+
case GET_ALL:
68+
List<GitLabCiTemplateElement> list = gitLabApi.getGitLabCiYamlApi()
69+
.getAllGitLabCiYamlTemplates();
70+
System.out.println(list);
71+
break;
72+
case GET_SINGLE:
73+
if (key == null) {
74+
throw new IllegalStateException("Key (--key) id is mandatory");
75+
}
76+
GitLabCiTemplate template = gitLabApi.getGitLabCiYamlApi()
77+
.getSingleGitLabCiYamlTemplate(key);
78+
System.out.println(template);
79+
break;
7280
}
7381
}
7482
return 0;

gitlab4j-test/GroupAccessTokenScript.java

+3-4
Original file line numberDiff line numberDiff line change
@@ -78,6 +78,9 @@ public Integer call() throws Exception {
7878
ensureExists(group, "group");
7979

8080
try (GitLabApi gitLabApi = createGitLabApi(gitLabUrl, gitLabAuthValue)) {
81+
if (logHttp != null && logHttp) {
82+
gitLabApi.enableRequestResponseLogging(java.util.logging.Level.INFO, 2000000000);
83+
}
8184
switch (action) {
8285
case LIST_GROUP_ACCESS_TOKEN:
8386
var tokens = gitLabApi.getGroupApi()
@@ -112,10 +115,6 @@ public Integer call() throws Exception {
112115
}
113116

114117
private GitLabApi createGitLabApi(String gitLabUrl, String gitLabAuthValue) {
115-
if (logHttp != null && logHttp) {
116-
return new GitLabApi(gitLabUrl, gitLabAuthValue)
117-
.withRequestResponseLogging(java.util.logging.Level.INFO);
118-
}
119118
return new GitLabApi(gitLabUrl, gitLabAuthValue);
120119
}
121120

gitlab4j-test/GroupScript.java

+3-4
Original file line numberDiff line numberDiff line change
@@ -62,6 +62,9 @@ public Integer call() throws Exception {
6262
final String gitLabAuthValue = readProperty(prop, "GITLAB_AUTH_VALUE");
6363

6464
try (GitLabApi gitLabApi = createGitLabApi(gitLabUrl, gitLabAuthValue)) {
65+
if (logHttp != null && logHttp) {
66+
gitLabApi.enableRequestResponseLogging(java.util.logging.Level.INFO, 2000000000);
67+
}
6568
switch (action) {
6669
case GET_GROUP:
6770
ensureExists(group, "group");
@@ -119,10 +122,6 @@ public Integer call() throws Exception {
119122
}
120123

121124
private GitLabApi createGitLabApi(String gitLabUrl, String gitLabAuthValue) {
122-
if (logHttp != null && logHttp) {
123-
return new GitLabApi(gitLabUrl, gitLabAuthValue)
124-
.withRequestResponseLogging(java.util.logging.Level.INFO);
125-
}
126125
return new GitLabApi(gitLabUrl, gitLabAuthValue);
127126
}
128127

gitlab4j-test/IssueScript.java

+4-5
Original file line numberDiff line numberDiff line change
@@ -69,7 +69,10 @@ public Integer call() throws Exception {
6969
final String gitLabUrl = readProperty(prop, "GITLAB_URL", "https://gitlab.com");
7070
final String gitLabAuthValue = readProperty(prop, "GITLAB_AUTH_VALUE");
7171

72-
try (GitLabApi gitLabApi = new GitLabApi(gitLabUrl, gitLabAuthValue)) {
72+
try (GitLabApi gitLabApi = createGitLabApi(gitLabUrl, gitLabAuthValue)) {
73+
if (logHttp != null && logHttp) {
74+
gitLabApi.enableRequestResponseLogging(java.util.logging.Level.INFO, 2000000000);
75+
}
7376
switch (action) {
7477
case PROJECT_ISSUES:
7578
ensureExists(project, "project");
@@ -133,10 +136,6 @@ public Integer call() throws Exception {
133136
}
134137

135138
private GitLabApi createGitLabApi(String gitLabUrl, String gitLabAuthValue) {
136-
if (logHttp != null && logHttp) {
137-
return new GitLabApi(gitLabUrl, gitLabAuthValue)
138-
.withRequestResponseLogging(java.util.logging.Level.INFO);
139-
}
140139
return new GitLabApi(gitLabUrl, gitLabAuthValue);
141140
}
142141

gitlab4j-test/IterationScript.java

+20-12
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,7 @@ public class IterationScript implements Callable<Integer> {
3838

3939
@Option(names = { "-s", "--state" }, description = "state")
4040
private IterationFilter.IterationFilterState state;
41-
41+
4242
@Option(names = { "-q", "--query" }, description = "query")
4343
private String search;
4444

@@ -47,16 +47,19 @@ public class IterationScript implements Callable<Integer> {
4747

4848
@Option(names = { "-n", "--includeAncestors" }, description = "include ancestors")
4949
private Boolean includeAncestors;
50-
50+
5151
@Option(names = { "-a", "--after" }, description = "updated after")
5252
private Date updatedAfter;
53-
53+
5454
@Option(names = { "-b", "--before" }, description = "updated before")
5555
private Date updatedBefore;
5656

5757
@Option(names = { "-c", "--config" }, description = "configuration file location")
5858
String configFile;
5959

60+
@Option(names = { "-v", "--verbose" }, description = "log http trafic")
61+
Boolean logHttp;
62+
6063
@Override
6164
public Integer call() throws Exception {
6265
Path file;
@@ -73,44 +76,49 @@ public Integer call() throws Exception {
7376
if (project != null && group != null) {
7477
System.out.println("'--project' and '--group' can't be set at the same time");
7578
return 1;
76-
} else if (project == null && group == null) {
79+
} else if (project == null && group == null) {
7780
System.out.println("One of '--project' and '--group' must be set");
7881
return 1;
7982
}
8083
try (GitLabApi gitLabApi = new GitLabApi(gitLabUrl, gitLabAuthValue)) {
84+
if (logHttp != null && logHttp) {
85+
gitLabApi.enableRequestResponseLogging(java.util.logging.Level.INFO, 2000000000);
86+
}
8187
List<?> result;
8288
IterationFilter filter = null;
83-
if(state != null) {
89+
if (state != null) {
8490
filter = existingOrNew(filter);
8591
filter.setState(state);
8692
}
87-
if(search != null) {
93+
if (search != null) {
8894
filter = existingOrNew(filter);
8995
filter.setSearch(search);
9096
}
91-
if(in != null) {
97+
if (in != null) {
9298
filter = existingOrNew(filter);
9399
filter.setIn(in);
94100
}
95-
if(includeAncestors != null) {
101+
if (includeAncestors != null) {
96102
filter = existingOrNew(filter);
97103
filter.setIncludeAncestors(includeAncestors);
98104
}
99-
if(updatedAfter != null) {
105+
if (updatedAfter != null) {
100106
filter = existingOrNew(filter);
101107
filter.setUpdatedAfter(updatedAfter);
102108
}
103-
if(updatedBefore != null) {
109+
if (updatedBefore != null) {
104110
filter = existingOrNew(filter);
105111
filter.setUpdatedBefore(updatedBefore);
106112
}
107113

108114
if (project != null) {
109115
System.out.println("Project iteration...");
110-
result = gitLabApi.getProjectApi().listProjectIterations(idOrPath(project), filter);
116+
result = gitLabApi.getProjectApi()
117+
.listProjectIterations(idOrPath(project), filter);
111118
} else if (group != null) {
112119
System.out.println("Group iteration...");
113-
result = gitLabApi.getGroupApi().listGroupIterations(idOrPath(group), filter);
120+
result = gitLabApi.getGroupApi()
121+
.listGroupIterations(idOrPath(group), filter);
114122
} else {
115123
throw new IllegalArgumentException("Unexpected state (input parameters might be wrong)");
116124
}

gitlab4j-test/JobScript.java

+7-1
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,9 @@ public class JobScript implements Callable<Integer> {
4141
@Option(names = { "-c", "--config" }, description = "configuration file location")
4242
String configFile;
4343

44+
@Option(names = { "-v", "--verbose" }, description = "log http trafic")
45+
Boolean logHttp;
46+
4447
private static enum Action {
4548
PRINT_JOB, PRINT_LOG, PRINT_ARTIFACT
4649
}
@@ -59,6 +62,9 @@ public Integer call() throws Exception {
5962
final String gitLabAuthValue = readProperty(prop, "GITLAB_AUTH_VALUE");
6063

6164
try (GitLabApi gitLabApi = new GitLabApi(gitLabUrl, gitLabAuthValue)) {
65+
if (logHttp != null && logHttp) {
66+
gitLabApi.enableRequestResponseLogging(java.util.logging.Level.INFO, 2000000000);
67+
}
6268
switch (action) {
6369
case PRINT_JOB:
6470
ensureExists(project, "project");
@@ -79,7 +85,7 @@ public Integer call() throws Exception {
7985
ensureExists(jobId, "jobId");
8086
ensureExists(artifactPath, "artifactPath");
8187
ArtifactsFile f = new ArtifactsFile();
82-
f.setFilename(artifactPath);
88+
f.setFilename(artifactPath);
8389
InputStream inputisStream = gitLabApi.getJobApi()
8490
.downloadArtifactsFile(idOrPath(project), jobId, f);
8591
String text = new String(inputisStream.readAllBytes(), StandardCharsets.UTF_8);

gitlab4j-test/LabelScript.java

+6
Original file line numberDiff line numberDiff line change
@@ -72,6 +72,9 @@ public class LabelScript implements Callable<Integer> {
7272
@Option(names = { "-c", "--config" }, description = "configuration file location")
7373
String configFile;
7474

75+
@Option(names = { "-v", "--verbose" }, description = "log http trafic")
76+
Boolean logHttp;
77+
7578
private static enum Action {
7679
LIST_LABELS, GET_LABEL, CREATE_LABEL, UPDATE_LABEL, DELETE_LABEL
7780
}
@@ -96,6 +99,9 @@ public Integer call() throws Exception {
9699
throw new IllegalStateException("One of --project and --group must be set");
97100
}
98101
try (GitLabApi gitLabApi = new GitLabApi(gitLabUrl, gitLabAuthValue)) {
102+
if (logHttp != null && logHttp) {
103+
gitLabApi.enableRequestResponseLogging(java.util.logging.Level.INFO, 2000000000);
104+
}
99105
switch (action) {
100106
case LIST_LABELS:
101107
List<Label> labels;

gitlab4j-test/MetadataScript.java

+7-1
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,8 @@ class MetadataScript implements Callable<Integer> {
3131
@Option(names = { "-c", "--config" }, description = "configuration file location")
3232
String configFile;
3333

34+
@Option(names = { "-v", "--verbose" }, description = "log http trafic")
35+
Boolean logHttp;
3436

3537
@Override
3638
public Integer call() throws Exception {
@@ -46,7 +48,11 @@ public Integer call() throws Exception {
4648
String gitLabAuthValue = readProperty(prop, "GITLAB_AUTH_VALUE");
4749

4850
try (GitLabApi gitLabApi = new GitLabApi(gitLabUrl, gitLabAuthValue)) {
49-
Metadata m = gitLabApi.getMetadataApi().getMetadata();
51+
if (logHttp != null && logHttp) {
52+
gitLabApi.enableRequestResponseLogging(java.util.logging.Level.INFO, 2000000000);
53+
}
54+
Metadata m = gitLabApi.getMetadataApi()
55+
.getMetadata();
5056
System.out.println(m);
5157
}
5258
return 0;

gitlab4j-test/NoteScript.java

+6
Original file line numberDiff line numberDiff line change
@@ -53,6 +53,9 @@ public class NoteScript implements Callable<Integer> {
5353
@Option(names = { "-c", "--config" }, description = "configuration file location")
5454
String configFile;
5555

56+
@Option(names = { "-v", "--verbose" }, description = "log http trafic")
57+
Boolean logHttp;
58+
5659
private static enum Action {
5760
GET_ISSUE_NOTES, GET_ISSUE_NOTE, CREATE_ISSUE_NOTE, UPDATE_ISSUE_NOTE, DELETE_ISSUE_NOTE
5861
}
@@ -74,6 +77,9 @@ public Integer call() throws Exception {
7477
ensureExists(issueIid, "issue");
7578

7679
try (GitLabApi gitLabApi = new GitLabApi(gitLabUrl, gitLabAuthValue)) {
80+
if (logHttp != null && logHttp) {
81+
gitLabApi.enableRequestResponseLogging(java.util.logging.Level.INFO, 2000000000);
82+
}
7783
switch (action) {
7884
case GET_ISSUE_NOTES:
7985
var notes = gitLabApi.getNotesApi()

gitlab4j-test/ProjectAccessTokenScript.java

+3-4
Original file line numberDiff line numberDiff line change
@@ -83,6 +83,9 @@ public Integer call() throws Exception {
8383
ensureExists(project, "project");
8484

8585
try (GitLabApi gitLabApi = createGitLabApi(gitLabUrl, gitLabAuthValue)) {
86+
if (logHttp != null && logHttp) {
87+
gitLabApi.enableRequestResponseLogging(java.util.logging.Level.INFO, 2000000000);
88+
}
8689
switch (action) {
8790
case LIST_PROJECT_ACCESS_TOKEN:
8891
var tokens = gitLabApi.getProjectApi()
@@ -118,10 +121,6 @@ public Integer call() throws Exception {
118121
}
119122

120123
private GitLabApi createGitLabApi(String gitLabUrl, String gitLabAuthValue) {
121-
if (logHttp != null && logHttp) {
122-
return new GitLabApi(gitLabUrl, gitLabAuthValue)
123-
.withRequestResponseLogging(java.util.logging.Level.INFO);
124-
}
125124
return new GitLabApi(gitLabUrl, gitLabAuthValue);
126125
}
127126

0 commit comments

Comments
 (0)