1
1
///usr/bin/env jbang "$0" "$@" ; exit $?
2
2
3
3
//DEPS info.picocli:picocli:4.6.3
4
- //DEPS org. gitlab4j:gitlab4j -api:6.0.0-rc.7
4
+ //DEPS https://github.com/jmini/ gitlab4j-api/commit/f24e3a1f250d0080e346a351a9c7d8f2a3c61ae3
5
5
//JAVA 17
6
6
7
7
import java .io .FileInputStream ;
@@ -47,14 +47,20 @@ public class EpicScript implements Callable<Integer> {
47
47
@ Option (names = { "-t" , "--title" }, description = "epic title" )
48
48
private String title ;
49
49
50
+ @ Option (names = { "-b" , "--body" }, description = "epic comment body" )
51
+ private String body ;
52
+
53
+ @ Option (names = { "-n" , "--note" }, description = "epic comment note id" )
54
+ private Long noteId ;
55
+
50
56
@ Option (names = { "-c" , "--config" }, description = "configuration file location" )
51
57
String configFile ;
52
58
53
59
@ Option (names = { "-v" , "--verbose" }, description = "log http trafic" )
54
60
Boolean logHttp ;
55
61
56
62
private static enum Action {
57
- GROUP_EPICS , GET_EPIC , CREATE_EPIC , DELETE_EPIC , DELETE_ALL_EPICS , CLOSE_EPIC , REOPEN_EPIC
63
+ GROUP_EPICS , GET_EPIC , CREATE_EPIC , DELETE_EPIC , DELETE_ALL_EPICS , CLOSE_EPIC , REOPEN_EPIC , GET_COMMENTS , CREATE_COMMENT , UPDATE_COMMENT , DELETE_COMMENT
58
64
}
59
65
60
66
@ Override
@@ -79,10 +85,7 @@ public Integer call() throws Exception {
79
85
System .out .println (epics );
80
86
break ;
81
87
case GET_EPIC :
82
- ensureExists (group , "group" );
83
- ensureExists (epicIid , "epic" );
84
- Epic epic = gitLabApi .getEpicsApi ()
85
- .getEpic (idOrPath (group ), epicIid );
88
+ Epic epic = readEpic (gitLabApi );
86
89
System .out .println (epic );
87
90
break ;
88
91
case CREATE_EPIC :
@@ -110,6 +113,34 @@ public Integer call() throws Exception {
110
113
deleteEpic (gitLabApi , i .getIid ());
111
114
}
112
115
break ;
116
+ case GET_COMMENTS :
117
+ Epic e1 = readEpic (gitLabApi );
118
+ List <Note > comments = gitLabApi .getNotesApi ()
119
+ .getEpicNotes (idOrPath (group ), e1 .getId ());
120
+ System .out .println (comments );
121
+ break ;
122
+ case CREATE_COMMENT :
123
+ Epic e2 = readEpic (gitLabApi );
124
+ ensureExists (body , "body" );
125
+ Note createdComment = gitLabApi .getNotesApi ()
126
+ .createEpicNote (idOrPath (group ), e2 .getId (), body );
127
+ System .out .println (createdComment );
128
+ break ;
129
+ case UPDATE_COMMENT :
130
+ Epic e3 = readEpic (gitLabApi );
131
+ ensureExists (noteId , "note" );
132
+ ensureExists (body , "body" );
133
+ Note updatedComment = gitLabApi .getNotesApi ()
134
+ .updateEpicNote (idOrPath (group ), e3 .getId (), noteId , body );
135
+ System .out .println (updatedComment );
136
+ break ;
137
+ case DELETE_COMMENT :
138
+ Epic e4 = readEpic (gitLabApi );
139
+ ensureExists (noteId , "note" );
140
+ gitLabApi .getNotesApi ()
141
+ .deleteEpicNote (idOrPath (group ), e4 .getId (), noteId );
142
+ System .out .println ("Note " + noteId + " deleted in " + e4 .getWebUrl ());
143
+ break ;
113
144
case CLOSE_EPIC :
114
145
ensureExists (group , "group" );
115
146
ensureExists (epicIid , "epic" );
@@ -141,6 +172,14 @@ private GitLabApi createGitLabApi(String gitLabUrl, String gitLabAuthValue) {
141
172
return new GitLabApi (gitLabUrl , gitLabAuthValue );
142
173
}
143
174
175
+ private Epic readEpic (GitLabApi gitLabApi ) throws GitLabApiException {
176
+ ensureExists (group , "group" );
177
+ ensureExists (epicIid , "epic" );
178
+ Epic epic = gitLabApi .getEpicsApi ()
179
+ .getEpic (idOrPath (group ), epicIid );
180
+ return epic ;
181
+ }
182
+
144
183
private void deleteEpic (GitLabApi gitLabApi , Long iid ) throws GitLabApiException {
145
184
gitLabApi .getEpicsApi ()
146
185
.deleteEpic (idOrPath (group ), iid );
0 commit comments