Skip to content

Commit eb9fc40

Browse files
authored
Merge pull request #688 from gsmet/codestarts
Add codestarts
2 parents 7ab20d5 + 66759c6 commit eb9fc40

File tree

23 files changed

+539
-14
lines changed

23 files changed

+539
-14
lines changed

.github/workflows/build.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -60,5 +60,5 @@ jobs:
6060
key: maven-repo-pr-${{ runner.os }}-${{ steps.get-date.outputs.date }}
6161

6262
- name: Build with Maven
63-
run: mvn -B formatter:validate verify --file pom.xml
63+
run: mvn -B formatter:validate install
6464

command-airline/runtime/pom.xml

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -60,6 +60,26 @@
6060
</annotationProcessorPaths>
6161
</configuration>
6262
</plugin>
63+
<plugin>
64+
<artifactId>maven-jar-plugin</artifactId>
65+
<executions>
66+
<execution>
67+
<id>generate-codestart-jar</id>
68+
<phase>generate-resources</phase>
69+
<goals>
70+
<goal>jar</goal>
71+
</goals>
72+
<configuration>
73+
<classesDirectory>${project.basedir}/src/main</classesDirectory>
74+
<includes>
75+
<include>codestarts/**</include>
76+
</includes>
77+
<classifier>codestarts</classifier>
78+
<skipIfEmpty>true</skipIfEmpty>
79+
</configuration>
80+
</execution>
81+
</executions>
82+
</plugin>
6383
</plugins>
6484
</build>
6585
</project>
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
name: quarkiverse-github-app-command-airline-codestart
2+
ref: quarkiverse-github-app-command-airline
3+
metadata:
4+
title: GitHub App Command Airline
5+
description: Start coding comment-based commands.
6+
related-guide-section: https://docs.quarkiverse.io/quarkus-github-app/dev/commands.html
7+
language:
8+
base:
9+
shared-data:
10+
readme:
11+
include-default-content: false
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
package org.acme;
2+
3+
import java.io.IOException;
4+
import java.util.List;
5+
6+
import org.kohsuke.github.GHEventPayload;
7+
8+
import com.github.rvesse.airline.annotations.Arguments;
9+
import com.github.rvesse.airline.annotations.Cli;
10+
import com.github.rvesse.airline.annotations.Command;
11+
12+
import io.quarkiverse.githubapp.command.airline.AbstractHelpCommand;
13+
14+
// TODO: make sure you adjust the name as @bot is an actual GitHub user
15+
@Cli(name = "@bot", commands = { MyGitHubBot.SayHello.class, MyGitHubBot.Help.class }, description = "A friendly bot")
16+
public class MyGitHubBot {
17+
18+
interface Commands {
19+
20+
void run(GHEventPayload.IssueComment issueCommentPayload) throws IOException;
21+
}
22+
23+
@Command(name = "say-hello", description = "Says hello")
24+
static class SayHello implements Commands {
25+
26+
@Arguments
27+
List<String> arguments;
28+
29+
@Override
30+
public void run(GHEventPayload.IssueComment issueCommentPayload) throws IOException {
31+
issueCommentPayload.getIssue()
32+
.comment(":wave: Hello " + (arguments != null ? String.join(" ", arguments) : "from Bot"));
33+
}
34+
}
35+
36+
@Command(name = "help", description = "Displays help")
37+
static class Help extends AbstractHelpCommand implements Commands {
38+
}
39+
}

command-airline/runtime/src/main/resources/META-INF/quarkus-extension.yaml

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,3 +15,8 @@ metadata:
1515
status: "stable"
1616
config:
1717
- "quarkus.github-app."
18+
codestart:
19+
name: "quarkiverse-github-app-command-airline"
20+
languages:
21+
- "java"
22+
artifact: "io.quarkiverse.githubapp:quarkus-github-app-command-airline:codestarts:jar:${project.version}"

docs/modules/ROOT/pages/commands.adoc

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,12 @@ First things first, add the `quarkus-github-app-command-airline` dependency to y
3131
</dependency>
3232
----
3333

34+
[NOTE]
35+
====
36+
If you requested the dependency when you generated the Quarkus project,
37+
Quarkus will generate a small example for you: `MyGitHubBot`.
38+
====
39+
3440
== Your first command
3541

3642
Let's say we want to implement a command to re-run a CI workflow.

docs/modules/ROOT/pages/create-github-app.adoc

Lines changed: 16 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -14,12 +14,10 @@ WARNING: Make sure you use the `📋` button to copy the command.
1414
----
1515
quarkus create app \
1616
-x quarkus-github-app \ <1>
17-
org.acme:my-github-app \ <2>
18-
--no-code <3>
17+
org.acme:my-github-app <2>
1918
----
2019
<1> The Quarkus GitHub App extension.
2120
<2> The GA of your Maven project.
22-
<3> Do not include unrelated generated code in the project.
2321

2422
[TIP]
2523
====
@@ -40,13 +38,11 @@ mvn io.quarkus:quarkus-maven-plugin:{quarkus-version}:create \
4038
-DplatformVersion={quarkus-version} \
4139
-DprojectGroupId=org.acme \ <1>
4240
-DprojectArtifactId=my-github-app \ <2>
43-
-Dextensions="io.quarkiverse.githubapp:quarkus-github-app:{quarkus-github-app-version}" \ <3>
44-
-DnoCode <4>
41+
-Dextensions="io.quarkiverse.githubapp:quarkus-github-app:{quarkus-github-app-version}" <3>
4542
----
4643
<1> The groupId of your Maven project.
4744
<2> The artifactId of your Maven project.
4845
<3> The Quarkus GitHub App extension.
49-
<4> Do not include unrelated generated code in the project.
5046
5147
[TIP]
5248
====
@@ -118,15 +114,23 @@ Check the instructions above carefully.
118114
That's it! You are done with the setup and you can code your GitHub App.
119115
Sky is the limit.
120116

121-
For instance, you can create the following class:
117+
Your newly created GitHub App comes with a small example:
122118

123119
[source, java]
124120
----
125-
class CreateComment {
121+
package org.acme;
126122
127-
void onOpen(@Issue.Opened GHEventPayload.Issue issuePayload) throws IOException {
128-
issuePayload.getIssue().comment("Hello from my GitHub App");
129-
}
123+
import java.io.IOException;
124+
125+
import org.kohsuke.github.GHEventPayload;
126+
127+
import io.quarkiverse.githubapp.event.Issue;
128+
129+
class MyGitHubApp {
130+
131+
void onOpen(@Issue.Opened GHEventPayload.Issue issuePayload) throws IOException {
132+
issuePayload.getIssue().comment(":wave: Hello from my GitHub App");
133+
}
130134
}
131135
----
132136

@@ -143,7 +147,7 @@ In details:
143147

144148
You are done developing your first Quarkus GitHub App.
145149

146-
Obviously the one we developed is not very useful, but it is a good start and by using this framework:
150+
Obviously, the code from `MyGitHubApp` is not very useful in real life, but it is a good start and by using this framework:
147151

148152
* You can listen to all the events currently supported by the https://github.com/hub4j/github-api[Hub4j GitHub API].
149153
* You have the full power of Quarkus with live coding, easy configuration, dependency injection, native executables and more.

docs/modules/ROOT/pages/includes/attributes.adoc

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
:quarkus-version: 3.16.0
1+
:quarkus-version: 3.17.0
22
:quarkus-github-app-version: 2.7.0
33

44
:github-api-javadoc-root-url: https://github-api.kohsuke.org/apidocs/org/kohsuke/github

integration-tests/app/pom.xml

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,11 @@
2323
<version>${project.version}</version>
2424
<scope>test</scope>
2525
</dependency>
26+
<dependency>
27+
<groupId>io.quarkus</groupId>
28+
<artifactId>quarkus-devtools-testing</artifactId>
29+
<scope>test</scope>
30+
</dependency>
2631
<dependency>
2732
<groupId>org.assertj</groupId>
2833
<artifactId>assertj-core</artifactId>
Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
package io.quarkiverse.githubapp.it.app;
2+
3+
import org.junit.jupiter.api.Test;
4+
import org.junit.jupiter.api.extension.RegisterExtension;
5+
6+
import io.quarkus.devtools.codestarts.quarkus.QuarkusCodestartCatalog;
7+
import io.quarkus.devtools.codestarts.quarkus.QuarkusCodestartCatalog.Language;
8+
import io.quarkus.devtools.commands.CreateProject.CreateProjectKey;
9+
import io.quarkus.devtools.testing.codestarts.QuarkusCodestartTest;
10+
11+
public class CodestartTest {
12+
@RegisterExtension
13+
public static QuarkusCodestartTest codestartTest = QuarkusCodestartTest.builder()
14+
.languages(QuarkusCodestartCatalog.Language.JAVA)
15+
.setupStandaloneExtensionTest("io.quarkiverse.githubapp:quarkus-github-app")
16+
.putData(CreateProjectKey.PROJECT_NAME, "My GitHub App")
17+
.putData(CreateProjectKey.PROJECT_DESCRIPTION, "My GitHub App description")
18+
.build();
19+
20+
@Test
21+
void testContent() throws Throwable {
22+
codestartTest.checkGeneratedSource("org.acme.MyGitHubApp");
23+
codestartTest.assertThatGeneratedFileMatchSnapshot(Language.JAVA, "pom.xml");
24+
codestartTest.assertThatGeneratedFileMatchSnapshot(Language.JAVA, "README.md");
25+
}
26+
27+
@Test
28+
void buildAllProjects() throws Throwable {
29+
codestartTest.buildAllProjects();
30+
}
31+
}

0 commit comments

Comments
 (0)