11///usr/bin/env jbang "$0" "$@" ; exit $?
22
33//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
55//JAVA 17
66
77import java .io .FileInputStream ;
@@ -47,14 +47,20 @@ public class EpicScript implements Callable<Integer> {
4747 @ Option (names = { "-t" , "--title" }, description = "epic title" )
4848 private String title ;
4949
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+
5056 @ Option (names = { "-c" , "--config" }, description = "configuration file location" )
5157 String configFile ;
5258
5359 @ Option (names = { "-v" , "--verbose" }, description = "log http trafic" )
5460 Boolean logHttp ;
5561
5662 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
5864 }
5965
6066 @ Override
@@ -79,10 +85,7 @@ public Integer call() throws Exception {
7985 System .out .println (epics );
8086 break ;
8187 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 );
8689 System .out .println (epic );
8790 break ;
8891 case CREATE_EPIC :
@@ -110,6 +113,34 @@ public Integer call() throws Exception {
110113 deleteEpic (gitLabApi , i .getIid ());
111114 }
112115 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 ;
113144 case CLOSE_EPIC :
114145 ensureExists (group , "group" );
115146 ensureExists (epicIid , "epic" );
@@ -141,6 +172,14 @@ private GitLabApi createGitLabApi(String gitLabUrl, String gitLabAuthValue) {
141172 return new GitLabApi (gitLabUrl , gitLabAuthValue );
142173 }
143174
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+
144183 private void deleteEpic (GitLabApi gitLabApi , Long iid ) throws GitLabApiException {
145184 gitLabApi .getEpicsApi ()
146185 .deleteEpic (idOrPath (group ), iid );
0 commit comments