Skip to content

Commit 2b05716

Browse files
committed
WorkItemScript add parent mutation
1 parent 952f941 commit 2b05716

File tree

1 file changed

+37
-3
lines changed

1 file changed

+37
-3
lines changed

gitlab4j-test/WorkItemScript.java

Lines changed: 37 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
///usr/bin/env jbang "$0" "$@" ; exit $?
22

33
//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
55
//DEPS io.smallrye:smallrye-graphql-client-implementation-vertx:2.11.0
66
//DEPS org.jboss.logmanager:jboss-logmanager:3.1.1.Final
77
//JAVA 17
@@ -23,6 +23,9 @@
2323
import graphql.gitlab.model.WorkItemDeleteInput;
2424
import graphql.gitlab.model.WorkItemDeletePayload;
2525
import graphql.gitlab.model.WorkItemID;
26+
import graphql.gitlab.model.WorkItemUpdateInput;
27+
import graphql.gitlab.model.WorkItemUpdatePayload;
28+
import graphql.gitlab.model.WorkItemWidgetHierarchyUpdateInput;
2629
import io.smallrye.graphql.client.typesafe.api.TypesafeGraphQLClientBuilder;
2730
import picocli.CommandLine;
2831
import picocli.CommandLine.Command;
@@ -46,6 +49,9 @@ public class WorkItemScript implements Callable<Integer> {
4649
@Option(names = { "-i", "--id" }, description = "workitem id")
4750
private String id;
4851

52+
@Option(names = { "-p", "--parentId" }, description = "workitem parentId")
53+
private String parentId;
54+
4955
@Option(names = { "-r", "--ref", "--reference" }, description = "references in the namespace")
5056
private List<String> refs;
5157

@@ -56,7 +62,7 @@ public class WorkItemScript implements Callable<Integer> {
5662
Boolean logHttp;
5763

5864
private static enum Action {
59-
GET_WORKITEM, DELETE_WORKITEM
65+
GET_WORKITEM, DELETE_WORKITEM, ADD_PARENT, REMOVE_PARENT
6066
}
6167

6268
@Override
@@ -73,13 +79,20 @@ public Integer call() throws Exception {
7379
final String gitLabAuthValue = readProperty(prop, "GITLAB_AUTH_VALUE");
7480

7581
WorkitemClientApi api = createGraphQLWorkitemClientApi(gitLabUrl, gitLabAuthValue);
82+
7683
switch (action) {
7784
case GET_WORKITEM:
7885
getWorkItem(api);
7986
break;
8087
case DELETE_WORKITEM:
8188
deleteWorkItem(api);
8289
break;
90+
case ADD_PARENT:
91+
addParent(api);
92+
break;
93+
case REMOVE_PARENT:
94+
deleteParent(api);
95+
break;
8396
default:
8497
throw new IllegalArgumentException("Unexpected value: " + action);
8598
}
@@ -97,7 +110,28 @@ private void getWorkItem(WorkitemClientApi api) {
97110
private void deleteWorkItem(WorkitemClientApi api) {
98111
ensureExists(id, "id");
99112
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)));
101135
System.out.println(response);
102136
}
103137

0 commit comments

Comments
 (0)