Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion application/config.json.template
Original file line number Diff line number Diff line change
Expand Up @@ -89,5 +89,5 @@
"logInfoChannelWebhook": "<put_your_webhook_here>",
"logErrorChannelWebhook": "<put_your_webhook_here>",
"openaiApiKey": "<check pins in #tjbot_discussion for the key>",
"sourceCodeBaseUrl": "<see explanation in https://github.com/Together-Java/TJ-Bot/pull/857>"
"sourceCodeBaseUrl": "<https://github.com/<your_account_here>/<your_repo_here>/blob/master/application/src/main/java/>"
}
Original file line number Diff line number Diff line change
Expand Up @@ -321,9 +321,11 @@ public String getOpenaiApiKey() {
}

/**
* The Base URL of the Source code to link tj-bot originated logs to the GitHub file.
* The base URL of the source code of this bot. E.g.
* {@code getSourceCodeBaseUrl() + "/org/togetherjava/tjbot/config/Config.java"} would point to
* this file.
*
* @return the base url of the source code
* @return the base url of the source code of this bot
*/
public String getSourceCodeBaseUrl() {
return sourceCodeBaseUrl;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,6 @@
import org.togetherjava.tjbot.features.utils.MessageUtils;
import org.togetherjava.tjbot.logging.LogMarkers;

import javax.annotation.Nullable;

import java.io.PrintWriter;
import java.io.StringWriter;
import java.net.URI;
Expand Down Expand Up @@ -168,7 +166,8 @@ private record LogMessage(WebhookEmbed embed,

private static LogMessage ofEvent(LogEvent event, String sourceCodeBaseUrl) {
String authorName = event.getLoggerName();
String authorUrl = linkToSource(event.getSource().getClassName(), sourceCodeBaseUrl);
String authorUrl =
linkToSource(event.getSource().getClassName(), sourceCodeBaseUrl).orElse(null);
String title = event.getLevel().name();
int colorDecimal = Objects.requireNonNull(LEVEL_TO_AMBIENT_COLOR.get(event.getLevel()));
String description =
Expand Down Expand Up @@ -199,12 +198,17 @@ private static String describeLogEvent(LogEvent event) {
return logMessage + "\n" + exceptionWriter.toString().replace("\t", "> ");
}

private static @Nullable String linkToSource(String source, String sourceCodeBaseUrl) {
private static Optional<String> linkToSource(String source, String sourceCodeBaseUrl) {
if (!source.startsWith(BASE_PACKAGE)) {
return null;
return Optional.empty();
}

if (!sourceCodeBaseUrl.endsWith("/")) {
sourceCodeBaseUrl += "/";
}

return sourceCodeBaseUrl + source.replace('.', '/') + ".java";
String link = sourceCodeBaseUrl + source.replace('.', '/') + ".java";
return Optional.of(link);
}

private LogMessage shortened() {
Expand Down