forked from quarkiverse/quarkus-github-app
-
Notifications
You must be signed in to change notification settings - Fork 1
/
ArcSubclassesCli.java
111 lines (90 loc) · 3.98 KB
/
ArcSubclassesCli.java
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
package io.quarkiverse.githubapp.it.command.airline;
import static java.lang.annotation.ElementType.METHOD;
import static java.lang.annotation.ElementType.TYPE;
import static java.lang.annotation.RetentionPolicy.RUNTIME;
import java.io.IOException;
import java.lang.annotation.Documented;
import java.lang.annotation.Retention;
import java.lang.annotation.Target;
import javax.annotation.Priority;
import javax.enterprise.context.ApplicationScoped;
import javax.interceptor.AroundInvoke;
import javax.interceptor.Interceptor;
import javax.interceptor.InterceptorBinding;
import javax.interceptor.InvocationContext;
import org.kohsuke.github.GHEventPayload;
import org.kohsuke.github.GHEventPayload.IssueComment;
import com.github.rvesse.airline.annotations.Cli;
import com.github.rvesse.airline.annotations.Command;
import io.quarkiverse.githubapp.command.airline.CliOptions;
import io.quarkiverse.githubapp.command.airline.CommandOptions;
import io.quarkiverse.githubapp.command.airline.CommandOptions.CommandScope;
import io.quarkiverse.githubapp.it.command.airline.ArcSubclassesCli.TestApplicationScopedCommand1;
import io.quarkiverse.githubapp.it.command.airline.ArcSubclassesCli.TestApplicationScopedCommand2;
import io.quarkiverse.githubapp.it.command.airline.ArcSubclassesCli.TestSubclassCommand1;
import io.quarkiverse.githubapp.it.command.airline.ArcSubclassesCli.TestSubclassCommand2;
import io.quarkiverse.githubapp.it.command.airline.DefaultCommandOptionsCli.TestCommand;
@Cli(name = "@arc", commands = { TestApplicationScopedCommand1.class, TestApplicationScopedCommand2.class,
TestSubclassCommand1.class, TestSubclassCommand2.class })
@CliOptions(defaultCommandOptions = @CommandOptions(scope = CommandScope.ISSUES))
public class ArcSubclassesCli {
@Command(name = "application-scoped-command1")
@ApplicationScoped
static class TestApplicationScopedCommand1 implements TestCommand {
@Override
public void run(IssueComment issueCommentPayload) throws IOException {
issueCommentPayload.getIssue().comment("hello from @arc application-scoped-command1");
}
}
@Command(name = "application-scoped-command2")
@CommandOptions(scope = CommandScope.ISSUES_AND_PULL_REQUESTS)
@ApplicationScoped
static class TestApplicationScopedCommand2 implements TestCommand {
@Override
public void run(IssueComment issueCommentPayload) throws IOException {
issueCommentPayload.getIssue().comment("hello from @arc application-scoped-command2");
}
}
// we add an interceptor to generate a `_Subclass`
@Command(name = "subclass-command1")
@DoNothing
static class TestSubclassCommand1 implements TestCommand {
@Override
public void run(IssueComment issueCommentPayload) throws IOException {
issueCommentPayload.getIssue().comment("hello from @arc subclass-command1");
}
}
// we add an interceptor to generate a `_Subclass`
@Command(name = "subclass-command2")
@CommandOptions(scope = CommandScope.ISSUES_AND_PULL_REQUESTS)
@DoNothing
static class TestSubclassCommand2 implements TestCommand {
@Override
public void run(IssueComment issueCommentPayload) throws IOException {
issueCommentPayload.getIssue().comment("hello from @arc subclass-command2");
}
}
public interface DefaultCommand {
void run(GHEventPayload.IssueComment issueCommentPayload) throws IOException;
}
@Target({ TYPE, METHOD })
@Retention(RUNTIME)
@Documented
@InterceptorBinding
public @interface DoNothing {
}
@DoNothing
@Priority(2020)
@Interceptor
public static class LoggingInterceptor {
@AroundInvoke
Object logInvocation(InvocationContext context) {
// do nothing specific, we just want an interceptor
try {
return context.proceed();
} catch (Exception e) {
throw new RuntimeException(e);
}
}
}
}