-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #7 from edward3h/configure
multiple webhooks, configuration for message sending
- Loading branch information
Showing
19 changed files
with
542 additions
and
103 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,37 @@ | ||
name: Publish Docker image | ||
|
||
on: | ||
pull_request: | ||
branches: | ||
- main | ||
|
||
env: | ||
REGISTRY: ghcr.io | ||
IMAGE_NAME: edward3h/mc-webhook | ||
|
||
jobs: | ||
build-and-push-image: | ||
runs-on: ubuntu-latest | ||
permissions: | ||
contents: read | ||
packages: write | ||
|
||
steps: | ||
- name: Checkout repository | ||
uses: actions/checkout@v2 | ||
|
||
- name: Log in to the Container registry | ||
uses: docker/login-action@f054a8b539a109f9f41c372932f1ae047eff08c9 | ||
with: | ||
registry: ${{ env.REGISTRY }} | ||
username: ${{ github.actor }} | ||
password: ${{ secrets.GITHUB_TOKEN }} | ||
- name: Set up JDK 11 | ||
uses: ayltai/setup-graalvm@v1 | ||
with: | ||
java-version: 11 | ||
graalvm-version: 21.3.0 | ||
- name: Grant execute permission for gradlew | ||
run: chmod +x gradlew | ||
- name: Build with Gradle | ||
run: ./gradlew dockerPush -Pgithub_ref=${GITHUB_SHA} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
31 changes: 31 additions & 0 deletions
31
app/src/main/java/org/ethelred/minecraft/webhook/BackCompatUrlSetup.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
/* (C) Edward Harman 2022 */ | ||
package org.ethelred.minecraft.webhook; | ||
|
||
import io.micronaut.context.BeanContext; | ||
import io.micronaut.context.annotation.Context; | ||
import io.micronaut.context.annotation.Property; | ||
import io.micronaut.context.annotation.Requires; | ||
import io.micronaut.core.convert.ConversionService; | ||
import java.net.URL; | ||
|
||
/** | ||
* this bean maps the original webhook property into the updated system for backwards compatibility | ||
*/ | ||
@Context | ||
@Requires(property = "mc-webhook.webhook-url") | ||
public class BackCompatUrlSetup extends MinecraftServerEventListener { | ||
|
||
public BackCompatUrlSetup( | ||
BeanContext context, | ||
ConversionService<?> conversionService, | ||
@Property(name = "mc-webhook.webhook-url") URL url | ||
) { | ||
super(context, conversionService, getConfiguration(url)); | ||
} | ||
|
||
private static SenderConfiguration getConfiguration(URL url) { | ||
var config = new SenderConfiguration(); | ||
config.setUrl(url); // defaults are ok for other properties | ||
return config; | ||
} | ||
} |
1 change: 1 addition & 0 deletions
1
app/src/main/java/org/ethelred/minecraft/webhook/ContainerId.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,4 @@ | ||
/* (C) Edward Harman 2022 */ | ||
package org.ethelred.minecraft.webhook; | ||
|
||
import jakarta.inject.Qualifier; | ||
|
1 change: 1 addition & 0 deletions
1
app/src/main/java/org/ethelred/minecraft/webhook/DefaultDocker.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
38 changes: 38 additions & 0 deletions
38
app/src/main/java/org/ethelred/minecraft/webhook/JsonSender.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,38 @@ | ||
/* (C) Edward Harman 2022 */ | ||
package org.ethelred.minecraft.webhook; | ||
|
||
import io.micronaut.context.annotation.Parameter; | ||
import io.micronaut.context.annotation.Prototype; | ||
import io.micronaut.http.HttpRequest; | ||
import io.micronaut.http.client.BlockingHttpClient; | ||
import io.micronaut.http.client.HttpClient; | ||
import jakarta.inject.Named; | ||
import java.net.URI; | ||
import java.net.URISyntaxException; | ||
import java.net.URL; | ||
import org.apache.logging.log4j.LogManager; | ||
import org.apache.logging.log4j.Logger; | ||
|
||
@Prototype | ||
@Named("json") | ||
public class JsonSender implements Sender { | ||
|
||
private static final Logger LOGGER = LogManager.getLogger(); | ||
|
||
private final BlockingHttpClient client; | ||
private final URI url; | ||
|
||
public JsonSender(HttpClient client, @Parameter URL url) | ||
throws URISyntaxException { | ||
this.client = client.toBlocking(); | ||
this.url = url.toURI(); | ||
} | ||
|
||
@Override | ||
public void sendMessage(MinecraftServerEvent event, String message) { | ||
LOGGER.debug("Send message {}", event); | ||
var request = HttpRequest.POST(url, event); | ||
var response = client.exchange(request); | ||
LOGGER.debug(response); | ||
} | ||
} |
Oops, something went wrong.