Skip to content

Commit b8d4960

Browse files
committed
feature(common): Add shorthand for codeberg & forgejo instances
1 parent 45035f5 commit b8d4960

File tree

3 files changed

+77
-3
lines changed

3 files changed

+77
-3
lines changed

indra-common/src/main/java/net/kyori/indra/IndraExtension.java

Lines changed: 18 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
/*
22
* This file is part of indra, licensed under the MIT License.
33
*
4-
* Copyright (c) 2020-2022 KyoriPowered
4+
* Copyright (c) 2020-2025 KyoriPowered
55
*
66
* Permission is hereby granted, free of charge, to any person obtaining a copy
77
* of this software and associated documentation files (the "Software"), to deal
@@ -23,6 +23,7 @@
2323
*/
2424
package net.kyori.indra;
2525

26+
import java.net.URI;
2627
import net.kyori.indra.api.model.ApplyTo;
2728
import net.kyori.indra.api.model.ContinuousIntegration;
2829
import net.kyori.indra.api.model.Issues;
@@ -43,6 +44,8 @@
4344
* @since 2.0.0
4445
*/
4546
public interface IndraExtension {
47+
URI CODEBERG_BASE_URL = URI.create("https://codeberg.org");
48+
4649
/**
4750
* Options controlling JVM toolchain versions.
4851
*
@@ -148,6 +151,20 @@ default void gitlab(final @NotNull String user, final @NotNull String repo) {
148151

149152
void gitlab(final @NotNull String user, final @NotNull String repo, final @Nullable Action<ApplyTo> applicable);
150153

154+
default void codeberg(final @NotNull String user, final @NotNull String repo) {
155+
this.codeberg(user, repo, null);
156+
}
157+
158+
default void codeberg(final @NotNull String user, final @NotNull String repo, final @Nullable Action<ApplyTo> applicable) {
159+
this.forgejo(CODEBERG_BASE_URL, user, repo, applicable);
160+
}
161+
162+
default void forgejo(final URI instanceBase, final @NotNull String user, final @NotNull String repo) {
163+
this.forgejo(instanceBase, user, repo, null);
164+
}
165+
166+
void forgejo(final URI instanceBase, final @NotNull String user, final @NotNull String repo, final @Nullable Action<ApplyTo> applicable);
167+
151168
// Publishing repositories
152169

153170
void publishAllTo(final @NotNull String id, final @NotNull String url);

indra-common/src/main/java/net/kyori/indra/internal/IndraExtensionImpl.java

Lines changed: 31 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
/*
22
* This file is part of indra, licensed under the MIT License.
33
*
4-
* Copyright (c) 2020-2023 KyoriPowered
4+
* Copyright (c) 2020-2025 KyoriPowered
55
*
66
* Permission is hereby granted, free of charge, to any person obtaining a copy
77
* of this software and associated documentation files (the "Software"), to deal
@@ -26,6 +26,7 @@
2626
import java.io.BufferedReader;
2727
import java.io.File;
2828
import java.io.IOException;
29+
import java.net.URI;
2930
import java.nio.charset.StandardCharsets;
3031
import java.nio.file.Files;
3132
import java.util.Collections;
@@ -184,6 +185,35 @@ public void gitlab(final @NotNull String user, final @NotNull String repo, final
184185
}
185186
}
186187

188+
@Override
189+
public void forgejo(final URI baseUrl, final @NotNull String user, final @NotNull String repo, final @Nullable Action<ApplyTo> applicable) {
190+
final ApplyTo options = Configurable.configureIfNonNull(ApplyTo.defaults(), applicable);
191+
192+
193+
if (options.ci()) {
194+
this.ci(ci -> ci
195+
.system("Forgejo Actions")
196+
.url(baseUrl.resolve("%s/%s/actions".formatted(user, repo)).toString())
197+
);
198+
}
199+
if (options.issues()) {
200+
this.issues(issues -> issues
201+
.system("Forgejo")
202+
.url(baseUrl.resolve("%s/%s/issues".formatted(user, repo)).toString())
203+
);
204+
}
205+
if (options.scm()) {
206+
this.scm(scm -> scm
207+
.connection("scm:git:" + baseUrl.resolve("/%s/%s.git".formatted(user, repo)))
208+
.developerConnection("scm:git:ssh://git@%s/%s/%s.git".formatted(baseUrl.getHost(), user, repo))
209+
.url(baseUrl.resolve("%s/%s".formatted(user, repo)).toString())
210+
);
211+
}
212+
if (options.publishing()) {
213+
this.publishReleasesTo("forgejoPackages", baseUrl.resolve("/api/packages/%s/maven".formatted(user)).toString());
214+
}
215+
}
216+
187217
// Publishing
188218

189219
final Set<Action<MavenPublication>> publishingActions = new HashSet<>();

indra-common/src/test/java/net/kyori/indra/IndraPluginTest.java

Lines changed: 28 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
/*
22
* This file is part of indra, licensed under the MIT License.
33
*
4-
* Copyright (c) 2020-2022 KyoriPowered
4+
* Copyright (c) 2020-2025 KyoriPowered
55
*
66
* Permission is hereby granted, free of charge, to any person obtaining a copy
77
* of this software and associated documentation files (the "Software"), to deal
@@ -41,6 +41,33 @@ void testPluginSimplyApplies() {
4141
project.getPluginManager().apply(PLUGIN);
4242
}
4343

44+
@Test
45+
void testCodebergRepository() {
46+
final Project project = IndraTesting.project();
47+
project.getPluginManager().apply(PLUGIN);
48+
final IndraExtension extension = Indra.extension(project.getExtensions());
49+
extension.codeberg("kyori", "indra", to -> {
50+
to.ci(true);
51+
to.scm(true);
52+
to.issues(true);
53+
to.publishing(true);
54+
});
55+
56+
// CI
57+
assertEquals("Forgejo Actions", extension.ci().get().system());
58+
assertEquals("https://codeberg.org/kyori/indra/actions", extension.ci().get().url());
59+
60+
// SCM
61+
assertEquals("scm:git:https://codeberg.org/kyori/indra.git", extension.scm().get().connection());
62+
assertEquals("scm:git:ssh://[email protected]/kyori/indra.git", extension.scm().get().developerConnection());
63+
assertEquals("https://codeberg.org/kyori/indra", extension.scm().get().url());
64+
65+
// Issues
66+
assertEquals("Forgejo", extension.issues().get().system());
67+
assertEquals("https://codeberg.org/kyori/indra/issues", extension.issues().get().url());
68+
69+
}
70+
4471
@Test
4572
void testExtensionLicense() {
4673
final Project project = IndraTesting.project();

0 commit comments

Comments
 (0)