1
1
///usr/bin/env jbang "$0" "$@" ; exit $?
2
2
3
3
//DEPS info.picocli:picocli:4.6.3
4
- //DEPS https://github.com/unblu/gitlab-workitem-graphql-client/commit/42111c3e6f4fe6a3970695e578d70a2169e330ab
4
+ //DEPS https://github.com/unblu/gitlab-workitem-graphql-client/commit/b098854092bba520dc6f770d39b11197244d3064
5
5
//DEPS io.smallrye:smallrye-graphql-client-implementation-vertx:2.11.0
6
6
//DEPS org.jboss.logmanager:jboss-logmanager:3.1.1.Final
7
7
//JAVA 17
20
20
21
21
import graphql .gitlab .api .WorkitemClientApi ;
22
22
import graphql .gitlab .model .WorkItemConnection ;
23
+ import graphql .gitlab .model .WorkItemDeleteInput ;
24
+ import graphql .gitlab .model .WorkItemDeletePayload ;
25
+ import graphql .gitlab .model .WorkItemID ;
23
26
import io .smallrye .graphql .client .typesafe .api .TypesafeGraphQLClientBuilder ;
24
27
import picocli .CommandLine ;
25
28
import picocli .CommandLine .Command ;
@@ -40,6 +43,9 @@ public class WorkItemScript implements Callable<Integer> {
40
43
@ Option (names = { "-n" , "--namespace" }, description = "namespace path" )
41
44
private String namespace ;
42
45
46
+ @ Option (names = { "-i" , "--id" }, description = "workitem id" )
47
+ private String id ;
48
+
43
49
@ Option (names = { "-r" , "--ref" , "--reference" }, description = "references in the namespace" )
44
50
private List <String > refs ;
45
51
@@ -50,7 +56,7 @@ public class WorkItemScript implements Callable<Integer> {
50
56
Boolean logHttp ;
51
57
52
58
private static enum Action {
53
- GET_WORKITEM
59
+ GET_WORKITEM , DELETE_WORKITEM
54
60
}
55
61
56
62
@ Override
@@ -69,10 +75,10 @@ public Integer call() throws Exception {
69
75
WorkitemClientApi api = createGraphQLWorkitemClientApi (gitLabUrl , gitLabAuthValue );
70
76
switch (action ) {
71
77
case GET_WORKITEM :
72
- ensureExists ( namespace , "namespace" );
73
- ensureExists ( refs , "reference" ) ;
74
- WorkItemConnection response = api . workItemsByReference ( namespace , refs , null );
75
- System . out . println ( response );
78
+ getWorkItem ( api );
79
+ break ;
80
+ case DELETE_WORKITEM :
81
+ deleteWorkItem ( api );
76
82
break ;
77
83
default :
78
84
throw new IllegalArgumentException ("Unexpected value: " + action );
@@ -81,6 +87,20 @@ public Integer call() throws Exception {
81
87
return 0 ;
82
88
}
83
89
90
+ private void getWorkItem (WorkitemClientApi api ) {
91
+ ensureExists (namespace , "namespace" );
92
+ ensureExists (refs , "reference" );
93
+ WorkItemConnection response = api .workItemsByReference (namespace , refs , null );
94
+ System .out .println (response );
95
+ }
96
+
97
+ private void deleteWorkItem (WorkitemClientApi api ) {
98
+ ensureExists (id , "id" );
99
+ WorkItemDeletePayload response = api .workItemDelete (new WorkItemDeleteInput ()
100
+ .setId (new WorkItemID (id )));
101
+ System .out .println (response );
102
+ }
103
+
84
104
static WorkitemClientApi createGraphQLWorkitemClientApi (String gitLabUrl , String gitlabToken ) {
85
105
WorkitemClientApi gqlApi = TypesafeGraphQLClientBuilder .newBuilder ()
86
106
.endpoint (gitLabUrl + "/api/graphql" )
0 commit comments