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/b098854092bba520dc6f770d39b11197244d3064
4
+ //DEPS https://github.com/unblu/gitlab-workitem-graphql-client/commit/b93a9f97e53e2647a0531c33b2dc67be940fd80c
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
23
23
import graphql .gitlab .model .WorkItemDeleteInput ;
24
24
import graphql .gitlab .model .WorkItemDeletePayload ;
25
25
import graphql .gitlab .model .WorkItemID ;
26
+ import graphql .gitlab .model .WorkItemUpdateInput ;
27
+ import graphql .gitlab .model .WorkItemUpdatePayload ;
28
+ import graphql .gitlab .model .WorkItemWidgetHierarchyUpdateInput ;
26
29
import io .smallrye .graphql .client .typesafe .api .TypesafeGraphQLClientBuilder ;
27
30
import picocli .CommandLine ;
28
31
import picocli .CommandLine .Command ;
@@ -46,6 +49,9 @@ public class WorkItemScript implements Callable<Integer> {
46
49
@ Option (names = { "-i" , "--id" }, description = "workitem id" )
47
50
private String id ;
48
51
52
+ @ Option (names = { "-p" , "--parentId" }, description = "workitem parentId" )
53
+ private String parentId ;
54
+
49
55
@ Option (names = { "-r" , "--ref" , "--reference" }, description = "references in the namespace" )
50
56
private List <String > refs ;
51
57
@@ -56,7 +62,7 @@ public class WorkItemScript implements Callable<Integer> {
56
62
Boolean logHttp ;
57
63
58
64
private static enum Action {
59
- GET_WORKITEM , DELETE_WORKITEM
65
+ GET_WORKITEM , DELETE_WORKITEM , ADD_PARENT , REMOVE_PARENT
60
66
}
61
67
62
68
@ Override
@@ -73,13 +79,20 @@ public Integer call() throws Exception {
73
79
final String gitLabAuthValue = readProperty (prop , "GITLAB_AUTH_VALUE" );
74
80
75
81
WorkitemClientApi api = createGraphQLWorkitemClientApi (gitLabUrl , gitLabAuthValue );
82
+
76
83
switch (action ) {
77
84
case GET_WORKITEM :
78
85
getWorkItem (api );
79
86
break ;
80
87
case DELETE_WORKITEM :
81
88
deleteWorkItem (api );
82
89
break ;
90
+ case ADD_PARENT :
91
+ addParent (api );
92
+ break ;
93
+ case REMOVE_PARENT :
94
+ deleteParent (api );
95
+ break ;
83
96
default :
84
97
throw new IllegalArgumentException ("Unexpected value: " + action );
85
98
}
@@ -97,7 +110,28 @@ private void getWorkItem(WorkitemClientApi api) {
97
110
private void deleteWorkItem (WorkitemClientApi api ) {
98
111
ensureExists (id , "id" );
99
112
WorkItemDeletePayload response = api .workItemDelete (new WorkItemDeleteInput ()
100
- .setId (new WorkItemID (id )));
113
+ .setId (new WorkItemID (id )) //
114
+ );
115
+ System .out .println (response );
116
+ }
117
+
118
+ private void addParent (WorkitemClientApi api ) {
119
+ ensureExists (id , "id" );
120
+ ensureExists (parentId , "parentId" );
121
+ WorkItemUpdatePayload response = api .workItemUpdate (new WorkItemUpdateInput ()
122
+ .setId (new WorkItemID (id ))
123
+ .setHierarchyWidget (new WorkItemWidgetHierarchyUpdateInput () //
124
+ .setParentId (new WorkItemID (parentId )) //
125
+ ) //
126
+ );
127
+ System .out .println (response );
128
+ }
129
+
130
+ private void deleteParent (WorkitemClientApi api ) {
131
+ ensureExists (id , "id" );
132
+ WorkItemUpdatePayload response = api .workItemUpdate (new WorkItemUpdateInput ()
133
+ .setId (new WorkItemID (id ))
134
+ .setHierarchyWidget (new WorkItemWidgetHierarchyUpdateInput ().setParentId (null )));
101
135
System .out .println (response );
102
136
}
103
137
0 commit comments