Skip to content

Commit 323754d

Browse files
committed
Minor adjustments to webhookUrlPath support
1 parent 0f54003 commit 323754d

File tree

5 files changed

+34
-23
lines changed

5 files changed

+34
-23
lines changed

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.9.2
1+
:quarkus-version: 3.11.2
22
:quarkus-github-app-version: 2.5.1
33

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

docs/modules/ROOT/pages/includes/quarkus-github-app.adoc

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -90,9 +90,9 @@ a| [[quarkus-github-app_quarkus-github-app-webhook-url-path]]`link:#quarkus-gith
9090

9191
[.description]
9292
--
93-
The webhook URL path that the GitHub App listens to, prefixed with the "/" character.
93+
The webhook URL path on which the GitHub App route is mounted.
9494

95-
This defaults to the root "/" but could be configured to a something else to enable deployment alongside other HTTP routes. such as "/github-event"
95+
It defaults to the root `/` but it can be configured to another path such as `/github-events` to enable deployment alongside other HTTP routes.
9696

9797
ifdef::add-copy-button-to-env-var[]
9898
Environment variable: env_var_with_copy_button:+++QUARKUS_GITHUB_APP_WEBHOOK_URL_PATH+++[]

runtime/src/main/java/io/quarkiverse/githubapp/runtime/Routes.java

Lines changed: 16 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,6 @@
77
import static io.quarkiverse.githubapp.runtime.Headers.X_REQUEST_ID;
88

99
import java.io.IOException;
10-
import java.io.UncheckedIOException;
1110
import java.nio.charset.StandardCharsets;
1211
import java.nio.file.Files;
1312
import java.nio.file.Path;
@@ -76,28 +75,24 @@ public void init(@Observes Router router) {
7675
router.post(checkedConfigProvider.webhookUrlPath())
7776
.handler(BodyHandler.create()) // this is required so that the body to be read by subsequent handlers
7877
.blockingHandler(routingContext -> {
79-
try {
80-
handleRequest(
81-
routingContext,
82-
new RoutingExchangeImpl(routingContext),
83-
routingContext.request().getHeader(X_REQUEST_ID),
84-
routingContext.request().getHeader(X_HUB_SIGNATURE_256),
85-
routingContext.request().getHeader(X_GITHUB_DELIVERY),
86-
routingContext.request().getHeader(X_GITHUB_EVENT),
87-
routingContext.request().getHeader(X_QUARKIVERSE_GITHUB_APP_REPLAYED));
88-
} catch (IOException e) {
89-
throw new UncheckedIOException(e);
90-
}
78+
handleRequest(
79+
routingContext,
80+
new RoutingExchangeImpl(routingContext),
81+
routingContext.request().getHeader(X_REQUEST_ID),
82+
routingContext.request().getHeader(X_HUB_SIGNATURE_256),
83+
routingContext.request().getHeader(X_GITHUB_DELIVERY),
84+
routingContext.request().getHeader(X_GITHUB_EVENT),
85+
routingContext.request().getHeader(X_QUARKIVERSE_GITHUB_APP_REPLAYED));
9186
});
9287
}
9388

94-
public void handleRequest(RoutingContext routingContext,
89+
private void handleRequest(RoutingContext routingContext,
9590
RoutingExchange routingExchange,
9691
String requestId,
9792
String hubSignature,
9893
String deliveryId,
9994
String event,
100-
String replayed) throws IOException {
95+
String replayed) {
10196

10297
if (!launchMode.isDevOrTest() && (isBlank(deliveryId) || isBlank(hubSignature))) {
10398
routingExchange.response().setStatusCode(400).end();
@@ -136,7 +131,12 @@ public void handleRequest(RoutingContext routingContext,
136131
if (!isBlank(deliveryId) && checkedConfigProvider.debug().payloadDirectory.isPresent()) {
137132
String fileName = DATE_TIME_FORMATTER.format(LocalDateTime.now()) + "-" + event + "-"
138133
+ (!isBlank(action) ? action + "-" : "") + deliveryId + ".json";
139-
Files.write(checkedConfigProvider.debug().payloadDirectory.get().resolve(fileName), bodyBytes);
134+
Path path = checkedConfigProvider.debug().payloadDirectory.get().resolve(fileName);
135+
try {
136+
Files.write(path, bodyBytes);
137+
} catch (Exception e) {
138+
LOG.warnf(e, "Unable to write debug payload: %s", path);
139+
}
140140
}
141141

142142
Long installationId = extractInstallationId(payloadObject);

runtime/src/main/java/io/quarkiverse/githubapp/runtime/config/CheckedConfigProvider.java

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,7 @@ public class CheckedConfigProvider {
3333

3434
private final Optional<PrivateKey> privateKey;
3535
private final Optional<String> webhookSecret;
36+
private final String webhookUrlPath;
3637

3738
private final Set<String> missingPropertyKeys = new TreeSet<>();
3839

@@ -54,6 +55,8 @@ public class CheckedConfigProvider {
5455
} else {
5556
this.webhookSecret = gitHubAppRuntimeConfig.webhookSecret;
5657
}
58+
this.webhookUrlPath = gitHubAppRuntimeConfig.webhookUrlPath.startsWith("/") ? gitHubAppRuntimeConfig.webhookUrlPath
59+
: "/" + gitHubAppRuntimeConfig.webhookUrlPath;
5760

5861
if (gitHubAppRuntimeConfig.appId.isEmpty()) {
5962
missingPropertyKeys.add("quarkus.github-app.app-id (.env: QUARKUS_GITHUB_APP_APP_ID)");
@@ -109,7 +112,7 @@ public String restApiEndpoint() {
109112
}
110113

111114
public String webhookUrlPath() {
112-
return gitHubAppRuntimeConfig.webhookUrlPath;
115+
return webhookUrlPath;
113116
}
114117

115118
public String graphqlApiEndpoint() {

runtime/src/main/java/io/quarkiverse/githubapp/runtime/config/GitHubAppRuntimeConfig.java

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@ public class GitHubAppRuntimeConfig {
2121
* Optional for tests, but mandatory in production and dev mode.
2222
*/
2323
@ConfigItem
24+
@ConvertWith(TrimmedStringConverter.class)
2425
Optional<String> appId;
2526

2627
/**
@@ -29,6 +30,7 @@ public class GitHubAppRuntimeConfig {
2930
* Optional, only used for improving the user experience.
3031
*/
3132
@ConfigItem
33+
@ConvertWith(TrimmedStringConverter.class)
3234
Optional<String> appName;
3335

3436
/**
@@ -47,12 +49,13 @@ public class GitHubAppRuntimeConfig {
4749
Optional<PrivateKey> privateKey;
4850

4951
/**
50-
* The webhook URL path that the GitHub App listens to, prefixed with the "/" character.
52+
* The webhook URL path on which the GitHub App route is mounted.
5153
* <p>
52-
* This defaults to the root "/" but could be configured to a something else to enable deployment alongside other HTTP
53-
* routes. such as "/github-event"
54+
* It defaults to the root {@code /} but it can be configured to another path such as {@code /github-events} to enable
55+
* deployment alongside other HTTP routes.
5456
*/
5557
@ConfigItem(defaultValue = "/")
58+
@ConvertWith(TrimmedStringConverter.class)
5659
String webhookUrlPath;
5760

5861
/**
@@ -89,6 +92,7 @@ public class GitHubAppRuntimeConfig {
8992
* The Smee.io proxy URL used when testing locally.
9093
*/
9194
@ConfigItem
95+
@ConvertWith(TrimmedStringConverter.class)
9296
Optional<String> webhookProxyUrl;
9397

9498
/**
@@ -97,6 +101,7 @@ public class GitHubAppRuntimeConfig {
97101
* Defaults to the public github.com instance.
98102
*/
99103
@ConfigItem(defaultValue = "https://api.github.com")
104+
@ConvertWith(TrimmedStringConverter.class)
100105
String instanceEndpoint;
101106

102107
/**
@@ -105,6 +110,7 @@ public class GitHubAppRuntimeConfig {
105110
* Defaults to the public github.com instance REST API endpoint.
106111
*/
107112
@ConfigItem(defaultValue = "${quarkus.github-app.instance-endpoint}")
113+
@ConvertWith(TrimmedStringConverter.class)
108114
String restApiEndpoint;
109115

110116
/**
@@ -113,6 +119,7 @@ public class GitHubAppRuntimeConfig {
113119
* Defaults to the public github.com instance GraphQL endpoint.
114120
*/
115121
@ConfigItem(defaultValue = "${quarkus.github-app.instance-endpoint}/graphql")
122+
@ConvertWith(TrimmedStringConverter.class)
116123
String graphqlApiEndpoint;
117124

118125
/**
@@ -128,6 +135,7 @@ public static class Debug {
128135
* A directory in which the payloads are saved.
129136
*/
130137
@ConfigItem
138+
@ConvertWith(TrimmedStringConverter.class)
131139
public Optional<Path> payloadDirectory;
132140
}
133141
}

0 commit comments

Comments
 (0)