Skip to content

Commit fa55d9b

Browse files
committed
Add Dokka Documentation
1 parent 1cbb3e3 commit fa55d9b

File tree

7 files changed

+126
-4
lines changed

7 files changed

+126
-4
lines changed

.github/workflows/build.yml

+21
Original file line numberDiff line numberDiff line change
@@ -148,3 +148,24 @@ jobs:
148148
path: |
149149
build/libs/*.jar
150150
151+
dokka:
152+
runs-on: ubuntu-latest
153+
needs: [build, test]
154+
name: Deploy Dokka
155+
if: ${{ github.event_name != 'pull_request' && github.ref_name == 'master' }}
156+
timeout-minutes: 30
157+
158+
steps:
159+
- uses: actions/checkout@v4
160+
- name: Set up JDK 17
161+
uses: actions/setup-java@v4
162+
with:
163+
distribution: 'temurin'
164+
java-version: '17'
165+
cache: 'gradle'
166+
- name: Change Permissions
167+
run: chmod +x ./gradlew
168+
- name: Build Dokka
169+
run: ./gradlew clean dokkaHtml
170+
- name: Deploy Dokka
171+
run: bash dokka.sh ${GITHUB_SHA::7}

build.gradle.kts

+5
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ import org.jetbrains.kotlin.gradle.tasks.KotlinCompile
44

55
plugins {
66
kotlin("jvm") version "2.0.20"
7+
id("org.jetbrains.dokka") version "1.9.20"
78
id("io.github.goooler.shadow") version "8.1.8"
89

910
java
@@ -40,6 +41,10 @@ java {
4041
}
4142

4243
tasks {
44+
clean {
45+
delete("bin")
46+
}
47+
4348
withType<KotlinCompile> {
4449
compilerOptions {
4550
jvmTarget.set(JvmTarget.JVM_17)

dokka.sh

+27
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
git config --local user.email "[email protected]"
2+
git config --local user.name "GitHub Action"
3+
git fetch origin gh-pages
4+
5+
if [ ! -d "docs" ]; then
6+
mkdir docs
7+
fi;
8+
9+
cp -Rfv build/dokka/html/* ./docs/
10+
11+
git switch -f gh-pages
12+
13+
for dir in ./*
14+
do
15+
if [ "$dir" == "./docs" ]; then
16+
continue
17+
fi
18+
19+
rm -rf "$dir"
20+
done
21+
22+
cp -Rfv ./docs/* ./
23+
rm -rf ./docs
24+
25+
git add .
26+
git commit -m "Update Dokka ($1)"
27+
git push -f origin gh-pages

src/main/kotlin/io/codemc/api/database/database.kt

+46
Original file line numberDiff line numberDiff line change
@@ -10,17 +10,33 @@ private val config: DatabaseConfig = DatabaseConfig {
1010
defaultMaxAttempts = 5
1111
}
1212

13+
/**
14+
* The [DBConfig] instance.
15+
*/
1316
var dbConfig: DBConfig = DBConfig("", "", "")
1417

18+
/**
19+
* The MariaDB configuration.
20+
* @param url The URl to the database.
21+
* @param username The username into the database.
22+
* @param password The password into the database.
23+
*/
1524
data class DBConfig(
1625
val url: String,
1726
val username: String,
1827
val password: String
1928
)
2029

30+
/**
31+
* Represents the database connection.
32+
*/
2133
lateinit var database: Database
2234
private set
2335

36+
/**
37+
* Attempts to connect to the database.
38+
* @return The new [database] value
39+
*/
2440
fun connect(): Database {
2541
database = Database.connect(
2642
url = dbConfig.url,
@@ -32,6 +48,12 @@ fun connect(): Database {
3248
return database
3349
}
3450

51+
/**
52+
* Adds a user to the database.
53+
* @param username The username of the jenkins user
54+
* @param discord The Discord ID of the jenkins user
55+
* @return The result of the `INSERT` statement.
56+
*/
3557
fun addUser(
3658
username: String,
3759
discord: Long
@@ -44,6 +66,11 @@ fun addUser(
4466
}
4567
}
4668

69+
/**
70+
* Gets a [User] by its jenkins username.
71+
* @param username The username to lookup
72+
* @return The user mapped to the jenkins username, or `null` if not found
73+
*/
4774
fun getUser(
4875
username: String
4976
): User? = transaction(database) {
@@ -52,11 +79,21 @@ fun getUser(
5279
.firstOrNull()
5380
}
5481

82+
/**
83+
* Gets all users currently linked in the database.
84+
* @return All users in the database
85+
*/
5586
fun getAllUsers(): List<User> = transaction(database) {
5687
Users.selectAll()
5788
.map { row -> User(row[Users.username], row[Users.discord]) }
5889
}
5990

91+
/**
92+
* Updates the user linked in the database.
93+
* @param username The jenkins user to update
94+
* @param discord The new Discord ID mapped to the user
95+
* @return `1` if updated, else `0`
96+
*/
6097
fun updateUser(
6198
username: String,
6299
discord: Long
@@ -66,12 +103,21 @@ fun updateUser(
66103
}
67104
}
68105

106+
/**
107+
* Removes a user from the database.
108+
* @param username The jenkins user to remove
109+
* @return `1` if removed, else `0`
110+
*/
69111
fun removeUser(
70112
username: String
71113
) = transaction(database) {
72114
Users.deleteWhere { Users.username eq username }
73115
}
74116

117+
/**
118+
* Removes all users from the database.
119+
* @return The count of deleted members
120+
*/
75121
fun removeAllUsers() = transaction(database) {
76122
Users.deleteAll()
77123
}

src/main/kotlin/io/codemc/api/main.kt

+6
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,12 @@ import io.codemc.api.jenkins.jenkinsConfig
99
import io.codemc.api.nexus.NexusConfig
1010
import io.codemc.api.nexus.nexusConfig
1111

12+
/**
13+
* Initializes the CodeMC API.
14+
* @param jenkins The Jenkins configuration.
15+
* @param nexus The Nexus configuration.
16+
* @param db The database configuration.
17+
*/
1218
suspend fun initialize(
1319
jenkins: JenkinsConfig,
1420
nexus: NexusConfig,

src/main/kotlin/io/codemc/api/network.kt

+16-4
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ import java.net.http.HttpResponse
1212
import java.nio.file.Files
1313
import java.time.Duration
1414

15-
private const val USER_AGENT = "CodeMC Nexus API"
15+
private const val USER_AGENT = "CodeMC API"
1616

1717
internal val http = HttpClient.newBuilder()
1818
.connectTimeout(Duration.ofSeconds(10))
@@ -23,7 +23,13 @@ internal val json = Json {
2323
explicitNulls = true
2424
}
2525

26-
internal suspend fun req(url: String, request: HttpRequest.Builder.() -> Unit = { GET() }): HttpResponse<String>
26+
/**
27+
* Sends an HTTP request using the HTTP Client.
28+
* @param url The URL to send the request to.
29+
* @param request The builder modifier on the HTTP Request.
30+
* @return An HTTP Response.
31+
*/
32+
suspend fun req(url: String, request: HttpRequest.Builder.() -> Unit = { GET() }): HttpResponse<String>
2733
= withContext(Dispatchers.IO) {
2834
val req = HttpRequest.newBuilder()
2935
.uri(URI.create(url))
@@ -34,13 +40,19 @@ internal suspend fun req(url: String, request: HttpRequest.Builder.() -> Unit =
3440
http.send(req.build(), HttpResponse.BodyHandlers.ofString())
3541
}
3642

37-
suspend fun filesExists(url: String, files: Iterable<String>): Boolean = withContext(Dispatchers.IO) {
43+
/**
44+
* Checks if any file exist in a Git Repository.
45+
* @param git The URL to the git repository.
46+
* @param files The files to check if they exist, relative to the repository.
47+
* @return `true` if **any** file exists in the git repository, `false` if none exist.
48+
*/
49+
suspend fun filesExists(git: String, files: Iterable<String>): Boolean = withContext(Dispatchers.IO) {
3850
val dir = Files.createTempDirectory("codemc")
3951

4052
Runtime.getRuntime().exec(arrayOf(
4153
"git",
4254
"clone",
43-
url,
55+
git,
4456
dir.toString()
4557
)).waitFor()
4658

src/main/kotlin/io/codemc/api/nexus/endpoints.kt

+5
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,11 @@ import kotlinx.serialization.json.putJsonObject
88

99
// Fields
1010

11+
/**
12+
* The Root API URl for the Nexus instance.
13+
*
14+
* Usually `https://<nexus-url>/service/rest/v1`.
15+
*/
1116
val API_URL
1217
get() = "${nexusConfig.url}/service/rest/v1"
1318

0 commit comments

Comments
 (0)