Skip to content

Commit f82a4c0

Browse files
committed
WorkItemScript: add DELETE_WORKITEM
1 parent a20562e commit f82a4c0

File tree

1 file changed

+26
-6
lines changed

1 file changed

+26
-6
lines changed

gitlab4j-test/WorkItemScript.java

Lines changed: 26 additions & 6 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/42111c3e6f4fe6a3970695e578d70a2169e330ab
4+
//DEPS https://github.com/unblu/gitlab-workitem-graphql-client/commit/b098854092bba520dc6f770d39b11197244d3064
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
@@ -20,6 +20,9 @@
2020

2121
import graphql.gitlab.api.WorkitemClientApi;
2222
import graphql.gitlab.model.WorkItemConnection;
23+
import graphql.gitlab.model.WorkItemDeleteInput;
24+
import graphql.gitlab.model.WorkItemDeletePayload;
25+
import graphql.gitlab.model.WorkItemID;
2326
import io.smallrye.graphql.client.typesafe.api.TypesafeGraphQLClientBuilder;
2427
import picocli.CommandLine;
2528
import picocli.CommandLine.Command;
@@ -40,6 +43,9 @@ public class WorkItemScript implements Callable<Integer> {
4043
@Option(names = { "-n", "--namespace" }, description = "namespace path")
4144
private String namespace;
4245

46+
@Option(names = { "-i", "--id" }, description = "workitem id")
47+
private String id;
48+
4349
@Option(names = { "-r", "--ref", "--reference" }, description = "references in the namespace")
4450
private List<String> refs;
4551

@@ -50,7 +56,7 @@ public class WorkItemScript implements Callable<Integer> {
5056
Boolean logHttp;
5157

5258
private static enum Action {
53-
GET_WORKITEM
59+
GET_WORKITEM, DELETE_WORKITEM
5460
}
5561

5662
@Override
@@ -69,10 +75,10 @@ public Integer call() throws Exception {
6975
WorkitemClientApi api = createGraphQLWorkitemClientApi(gitLabUrl, gitLabAuthValue);
7076
switch (action) {
7177
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);
7682
break;
7783
default:
7884
throw new IllegalArgumentException("Unexpected value: " + action);
@@ -81,6 +87,20 @@ public Integer call() throws Exception {
8187
return 0;
8288
}
8389

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+
84104
static WorkitemClientApi createGraphQLWorkitemClientApi(String gitLabUrl, String gitlabToken) {
85105
WorkitemClientApi gqlApi = TypesafeGraphQLClientBuilder.newBuilder()
86106
.endpoint(gitLabUrl + "/api/graphql")

0 commit comments

Comments
 (0)