Skip to content

Commit

Permalink
Merge pull request #688 from gsmet/codestarts
Browse files Browse the repository at this point in the history
Add codestarts
  • Loading branch information
gsmet authored Nov 28, 2024
2 parents 7ab20d5 + 66759c6 commit eb9fc40
Show file tree
Hide file tree
Showing 23 changed files with 539 additions and 14 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -60,5 +60,5 @@ jobs:
key: maven-repo-pr-${{ runner.os }}-${{ steps.get-date.outputs.date }}

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

20 changes: 20 additions & 0 deletions command-airline/runtime/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,26 @@
</annotationProcessorPaths>
</configuration>
</plugin>
<plugin>
<artifactId>maven-jar-plugin</artifactId>
<executions>
<execution>
<id>generate-codestart-jar</id>
<phase>generate-resources</phase>
<goals>
<goal>jar</goal>
</goals>
<configuration>
<classesDirectory>${project.basedir}/src/main</classesDirectory>
<includes>
<include>codestarts/**</include>
</includes>
<classifier>codestarts</classifier>
<skipIfEmpty>true</skipIfEmpty>
</configuration>
</execution>
</executions>
</plugin>
</plugins>
</build>
</project>
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
name: quarkiverse-github-app-command-airline-codestart
ref: quarkiverse-github-app-command-airline
metadata:
title: GitHub App Command Airline
description: Start coding comment-based commands.
related-guide-section: https://docs.quarkiverse.io/quarkus-github-app/dev/commands.html
language:
base:
shared-data:
readme:
include-default-content: false
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
package org.acme;

import java.io.IOException;
import java.util.List;

import org.kohsuke.github.GHEventPayload;

import com.github.rvesse.airline.annotations.Arguments;
import com.github.rvesse.airline.annotations.Cli;
import com.github.rvesse.airline.annotations.Command;

import io.quarkiverse.githubapp.command.airline.AbstractHelpCommand;

// TODO: make sure you adjust the name as @bot is an actual GitHub user
@Cli(name = "@bot", commands = { MyGitHubBot.SayHello.class, MyGitHubBot.Help.class }, description = "A friendly bot")
public class MyGitHubBot {

interface Commands {

void run(GHEventPayload.IssueComment issueCommentPayload) throws IOException;
}

@Command(name = "say-hello", description = "Says hello")
static class SayHello implements Commands {

@Arguments
List<String> arguments;

@Override
public void run(GHEventPayload.IssueComment issueCommentPayload) throws IOException {
issueCommentPayload.getIssue()
.comment(":wave: Hello " + (arguments != null ? String.join(" ", arguments) : "from Bot"));
}
}

@Command(name = "help", description = "Displays help")
static class Help extends AbstractHelpCommand implements Commands {
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -15,3 +15,8 @@ metadata:
status: "stable"
config:
- "quarkus.github-app."
codestart:
name: "quarkiverse-github-app-command-airline"
languages:
- "java"
artifact: "io.quarkiverse.githubapp:quarkus-github-app-command-airline:codestarts:jar:${project.version}"
6 changes: 6 additions & 0 deletions docs/modules/ROOT/pages/commands.adoc
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,12 @@ First things first, add the `quarkus-github-app-command-airline` dependency to y
</dependency>
----

[NOTE]
====
If you requested the dependency when you generated the Quarkus project,
Quarkus will generate a small example for you: `MyGitHubBot`.
====

== Your first command

Let's say we want to implement a command to re-run a CI workflow.
Expand Down
28 changes: 16 additions & 12 deletions docs/modules/ROOT/pages/create-github-app.adoc
Original file line number Diff line number Diff line change
Expand Up @@ -14,12 +14,10 @@ WARNING: Make sure you use the `📋` button to copy the command.
----
quarkus create app \
-x quarkus-github-app \ <1>
org.acme:my-github-app \ <2>
--no-code <3>
org.acme:my-github-app <2>
----
<1> The Quarkus GitHub App extension.
<2> The GA of your Maven project.
<3> Do not include unrelated generated code in the project.

[TIP]
====
Expand All @@ -40,13 +38,11 @@ mvn io.quarkus:quarkus-maven-plugin:{quarkus-version}:create \
-DplatformVersion={quarkus-version} \
-DprojectGroupId=org.acme \ <1>
-DprojectArtifactId=my-github-app \ <2>
-Dextensions="io.quarkiverse.githubapp:quarkus-github-app:{quarkus-github-app-version}" \ <3>
-DnoCode <4>
-Dextensions="io.quarkiverse.githubapp:quarkus-github-app:{quarkus-github-app-version}" <3>
----
<1> The groupId of your Maven project.
<2> The artifactId of your Maven project.
<3> The Quarkus GitHub App extension.
<4> Do not include unrelated generated code in the project.
[TIP]
====
Expand Down Expand Up @@ -118,15 +114,23 @@ Check the instructions above carefully.
That's it! You are done with the setup and you can code your GitHub App.
Sky is the limit.

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

[source, java]
----
class CreateComment {
package org.acme;
void onOpen(@Issue.Opened GHEventPayload.Issue issuePayload) throws IOException {
issuePayload.getIssue().comment("Hello from my GitHub App");
}
import java.io.IOException;
import org.kohsuke.github.GHEventPayload;
import io.quarkiverse.githubapp.event.Issue;
class MyGitHubApp {
void onOpen(@Issue.Opened GHEventPayload.Issue issuePayload) throws IOException {
issuePayload.getIssue().comment(":wave: Hello from my GitHub App");
}
}
----

Expand All @@ -143,7 +147,7 @@ In details:

You are done developing your first Quarkus GitHub App.

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

* You can listen to all the events currently supported by the https://github.com/hub4j/github-api[Hub4j GitHub API].
* You have the full power of Quarkus with live coding, easy configuration, dependency injection, native executables and more.
Expand Down
2 changes: 1 addition & 1 deletion docs/modules/ROOT/pages/includes/attributes.adoc
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
:quarkus-version: 3.16.0
:quarkus-version: 3.17.0
:quarkus-github-app-version: 2.7.0

:github-api-javadoc-root-url: https://github-api.kohsuke.org/apidocs/org/kohsuke/github
Expand Down
5 changes: 5 additions & 0 deletions integration-tests/app/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,11 @@
<version>${project.version}</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>io.quarkus</groupId>
<artifactId>quarkus-devtools-testing</artifactId>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.assertj</groupId>
<artifactId>assertj-core</artifactId>
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
package io.quarkiverse.githubapp.it.app;

import org.junit.jupiter.api.Test;
import org.junit.jupiter.api.extension.RegisterExtension;

import io.quarkus.devtools.codestarts.quarkus.QuarkusCodestartCatalog;
import io.quarkus.devtools.codestarts.quarkus.QuarkusCodestartCatalog.Language;
import io.quarkus.devtools.commands.CreateProject.CreateProjectKey;
import io.quarkus.devtools.testing.codestarts.QuarkusCodestartTest;

public class CodestartTest {
@RegisterExtension
public static QuarkusCodestartTest codestartTest = QuarkusCodestartTest.builder()
.languages(QuarkusCodestartCatalog.Language.JAVA)
.setupStandaloneExtensionTest("io.quarkiverse.githubapp:quarkus-github-app")
.putData(CreateProjectKey.PROJECT_NAME, "My GitHub App")
.putData(CreateProjectKey.PROJECT_DESCRIPTION, "My GitHub App description")
.build();

@Test
void testContent() throws Throwable {
codestartTest.checkGeneratedSource("org.acme.MyGitHubApp");
codestartTest.assertThatGeneratedFileMatchSnapshot(Language.JAVA, "pom.xml");
codestartTest.assertThatGeneratedFileMatchSnapshot(Language.JAVA, "README.md");
}

@Test
void buildAllProjects() throws Throwable {
codestartTest.buildAllProjects();
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@

# My GitHub App

> My GitHub App description
This repository contains a GitHub App powered by [Quarkus GitHub App](https://github.com/quarkiverse/quarkus-github-app).

Have a look at the [documentation](https://quarkiverse.github.io/quarkiverse-docs/quarkus-github-app/dev/index.html) to get started.
Original file line number Diff line number Diff line change
@@ -0,0 +1,122 @@
<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 https://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<groupId>org.test</groupId>
<artifactId>test-codestart</artifactId>
<version>1.0.0-codestart</version>
<name>My GitHub App</name>
<description>My GitHub App description</description>

<properties>
<compiler-plugin.version>3.8.1-MOCK</compiler-plugin.version>
<maven.compiler.release>17</maven.compiler.release>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
<project.reporting.outputEncoding>UTF-8</project.reporting.outputEncoding>
<quarkus.platform.artifact-id>quarkus-mock-bom</quarkus.platform.artifact-id>
<quarkus.platform.group-id>io.quarkus</quarkus.platform.group-id>
<quarkus.platform.version>999-MOCK</quarkus.platform.version>
<skipITs>true</skipITs>
<surefire-plugin.version>3.0.0-MOCK</surefire-plugin.version>
</properties>

<dependencyManagement>
<dependencies>
<dependency>
<groupId>${quarkus.platform.group-id}</groupId>
<artifactId>${quarkus.platform.artifact-id}</artifactId>
<version>${quarkus.platform.version}</version>
<type>pom</type>
<scope>import</scope>
</dependency>
</dependencies>
</dependencyManagement>

<dependencies>
<dependency>
<groupId>io.quarkiverse.githubapp</groupId>
<artifactId>quarkus-github-app</artifactId>
<version>999-SNAPSHOT</version>
</dependency>
<dependency>
<groupId>io.quarkus</groupId>
<artifactId>quarkus-arc</artifactId>
</dependency>
<dependency>
<groupId>io.quarkus</groupId>
<artifactId>quarkus-junit5</artifactId>
<scope>test</scope>
</dependency>
</dependencies>

<build>
<plugins>
<plugin>
<groupId>${quarkus.platform.group-id}</groupId>
<artifactId>quarkus-mock-maven-plugin</artifactId>
<version>${quarkus.platform.version}</version>
<extensions>true</extensions>
<executions>
<execution>
<goals>
<goal>build</goal>
<goal>generate-code</goal>
<goal>generate-code-tests</goal>
<goal>native-image-agent</goal>
</goals>
</execution>
</executions>
</plugin>
<plugin>
<artifactId>maven-compiler-plugin</artifactId>
<version>${compiler-plugin.version}</version>
<configuration>
<parameters>true</parameters>
</configuration>
</plugin>
<plugin>
<artifactId>maven-surefire-plugin</artifactId>
<version>${surefire-plugin.version}</version>
<configuration>
<systemPropertyVariables>
<java.util.logging.manager>org.jboss.logmanager.LogManager</java.util.logging.manager>
<maven.home>${maven.home}</maven.home>
</systemPropertyVariables>
</configuration>
</plugin>
<plugin>
<artifactId>maven-failsafe-plugin</artifactId>
<version>${surefire-plugin.version}</version>
<executions>
<execution>
<goals>
<goal>integration-test</goal>
<goal>verify</goal>
</goals>
</execution>
</executions>
<configuration>
<systemPropertyVariables>
<native.image.path>${project.build.directory}/${project.build.finalName}-runner</native.image.path>
<java.util.logging.manager>org.jboss.logmanager.LogManager</java.util.logging.manager>
<maven.home>${maven.home}</maven.home>
</systemPropertyVariables>
</configuration>
</plugin>
</plugins>
</build>

<profiles>
<profile>
<id>native</id>
<activation>
<property>
<name>native</name>
</property>
</activation>
<properties>
<skipITs>false</skipITs>
<quarkus.native.enabled>true</quarkus.native.enabled>
</properties>
</profile>
</profiles>
</project>
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
package ilove.quark.us;

import java.io.IOException;

import org.kohsuke.github.GHEventPayload;

import io.quarkiverse.githubapp.event.Issue;

class MyGitHubApp {

void onOpen(@Issue.Opened GHEventPayload.Issue issuePayload) throws IOException {
issuePayload.getIssue().comment(":wave: Hello from my GitHub App");
}
}
5 changes: 5 additions & 0 deletions integration-tests/command-airline/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,11 @@
<version>${project.version}</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>io.quarkus</groupId>
<artifactId>quarkus-devtools-testing</artifactId>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.assertj</groupId>
<artifactId>assertj-core</artifactId>
Expand Down
Loading

0 comments on commit eb9fc40

Please sign in to comment.