Skip to content

Commit af74d42

Browse files
committed
Add test
1 parent 8267f5e commit af74d42

File tree

3 files changed

+190
-2
lines changed

3 files changed

+190
-2
lines changed

repoman/src/main/kotlin/org/metaborg/repoman/meta/RepoMetadata.kt

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ package org.metaborg.repoman.meta
22

33
import kotlinx.serialization.Serializable
44
import org.metaborg.repoman.Markdown
5+
import java.time.Year
56

67
/** Default values. */
78
object Defaults {
@@ -34,7 +35,7 @@ data class RepoMetadata(
3435
/** The inception year of the repository (required). */
3536
val inceptionYear: String,
3637
/** The current year in which the repository is still maintained. */
37-
val currentYear: String = "2024",
38+
val currentYear: String = Year.now().toString(),
3839

3940
/** A list of Maven libraries published by the repo. */
4041
val libraries: List<MavenArtifact> = emptyList(),
@@ -199,6 +200,18 @@ data class GithubIssueTemplates(
199200
val assignDevelopers: Boolean = true,
200201
/** Whether to use the GitHub Discussions tab. */
201202
val useDiscussions: Boolean = true,
203+
/** The type label to apply to bugs; or `null` to not apply a label. */
204+
val bugTypeLabel: String? = "bug",
205+
/** The type label to apply to feature requests; or `null` to not apply a label. */
206+
val featureRequestTypeLabel: String? = "feature-request",
207+
/** The type label to apply to questions; or `null` to not apply a label. */
208+
val questionTypeLabel: String? = "question",
209+
/** The state label to apply to new bugs; or `null` to not apply a label. */
210+
val bugStateLabel: String? = "needs-triage",
211+
/** The state label to apply to new feature requests; or `null` to not apply a label. */
212+
val featureRequestStateLabel: String? = null,
213+
/** The state label to apply to new questions; or `null` to not apply a label. */
214+
val questionStateLabel: String? = null,
202215
)
203216

204217
/** A Maven artifact. */

repoman/src/main/resources/templates/github/ISSUE_TEMPLATE/20-report-a-bug.yml.kte

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,13 @@
1010
name: "🐞 Report a Bug"
1111
description: File a bug report or issue for any project in ${meta.title}.
1212
title: "[Bug]: "
13-
labels: ["bug", "triage"]
13+
labels:
14+
@if(meta.files.githubIssueTemplates.bugTypeLabel != null)
15+
- "${meta.files.githubIssueTemplates.bugTypeLabel}"
16+
@endif
17+
@if(meta.files.githubIssueTemplates.bugStateLabel != null)
18+
- "${meta.files.githubIssueTemplates.bugStateLabel}"
19+
@endif
1420
@if(meta.files.githubIssueTemplates.assignDevelopers)
1521
assignees:
1622
@for(person in meta.developers)
Lines changed: 169 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,169 @@
1+
package org.metaborg.repoman
2+
3+
import com.github.ajalt.clikt.testing.test
4+
import io.kotest.assertions.assertSoftly
5+
import io.kotest.assertions.withClue
6+
import io.kotest.core.spec.style.FunSpec
7+
import io.kotest.engine.spec.tempdir
8+
import io.kotest.matchers.file.shouldNotBeEmpty
9+
import io.kotest.matchers.shouldBe
10+
11+
/** Tests the [GenerateCommand]. */
12+
class GenerateCommandTests: FunSpec({
13+
14+
test("should generate the necessary files") {
15+
// Arrange
16+
val projectDir = tempdir()
17+
val metadataFile = projectDir.resolve("repo.yaml")
18+
// Try to exercise all the features
19+
metadataFile.writeText(
20+
"""
21+
---
22+
repoOwner: "metaborgcube"
23+
repoName: "queen"
24+
mainBranch: "master"
25+
releaseTagPrefix: "v"
26+
mavenGroup: "org.metaborgcube"
27+
28+
title: "Metaborgcube Queen"
29+
description: "Resistance is futile."
30+
documentationLink: "https://metaborgcube.dev/queen/"
31+
inceptionYear: "2000"
32+
currentYear: "2373"
33+
34+
libraries:
35+
- group: "org.metaborgcube"
36+
name: "picard"
37+
description: "Make it so."
38+
- group: "org.metaborgcube"
39+
name: "riker"
40+
description: "Engage."
41+
42+
languages:
43+
- group: "org.metaborgcube"
44+
name: "worf"
45+
description: "Today is a good day to die."
46+
- group: "org.metaborgcube"
47+
name: "data"
48+
description: "I am fully functional."
49+
50+
plugins:
51+
- id: "org.metaborgcube.enterprise"
52+
description: "NCC-1701-D"
53+
- id: "org.metaborgcube.voyager"
54+
description: "NCC-74656"
55+
56+
developers:
57+
- id: "picard"
58+
name: "Jean-Luc Picard"
59+
60+
- id: "riker"
61+
name: "William Riker"
62+
63+
64+
contributors:
65+
- id: "worf"
66+
name: "Worf"
67+
68+
- id: "data"
69+
name: "Data"
70+
71+
72+
files:
73+
readme:
74+
generate: true
75+
update: true
76+
body: |
77+
I am the beginning, the end, the one who is many. I am the Borg.
78+
license:
79+
generate: true
80+
update: true
81+
contributing:
82+
generate: true
83+
update: true
84+
codeOfConduct:
85+
generate: true
86+
update: true
87+
changelog:
88+
generate: true
89+
update: true
90+
gitignore:
91+
generate: true
92+
update: true
93+
extra: |
94+
.dna/
95+
gradleWrapper:
96+
generate: true
97+
update: true
98+
gradleVersion: "latest"
99+
gradleDistributionType: "all"
100+
gradleRootProject:
101+
generate: true
102+
update: true
103+
rootProjectName: "queen"
104+
includedBuilds:
105+
- name: "sevenofnine"
106+
path: "people/sevenofnine/"
107+
includedProjects:
108+
- name: ":core"
109+
path: "core/"
110+
- name: ":ui"
111+
path: "ui/"
112+
conventionVersion: "0.16.0"
113+
createPublishTasks: true
114+
githubWorkflows:
115+
generate: true
116+
update: true
117+
publishRelease: true
118+
publishSnapshot: true
119+
buildTask: ":core:build"
120+
publishTask: ":core:publish"
121+
printVersionTask: ":core:printVersion"
122+
buildDocs: true
123+
githubIssueTemplates:
124+
generate: true
125+
update: true
126+
assignDevelopers: true
127+
useDiscussions: true
128+
bugTypeLabel: "Type-Bug"
129+
featureRequestTypeLabel: "Type-Enhancement"
130+
questionTypeLabel: "Type-Question"
131+
bugStateLabel: "State-Triage"
132+
featureRequestStateLabel: "State-Triage"
133+
questionStateLabel: "State-Triage"
134+
""".trimIndent()
135+
)
136+
137+
// Act
138+
val result = CLI.test(arrayOf(
139+
"generate",
140+
"--meta", metadataFile.toString(),
141+
"--repo", projectDir.toString(),
142+
"--force-update"
143+
))
144+
145+
// Assert
146+
withClue(result.output) {
147+
result.statusCode shouldBe 0
148+
}
149+
assertSoftly {
150+
projectDir.resolve("README.md").shouldNotBeEmpty()
151+
projectDir.resolve("LICENSE.md").shouldNotBeEmpty()
152+
projectDir.resolve("CONTRIBUTING.md").shouldNotBeEmpty()
153+
projectDir.resolve("CODE_OF_CONDUCT.md").shouldNotBeEmpty()
154+
projectDir.resolve("CHANGELOG.md").shouldNotBeEmpty()
155+
projectDir.resolve(".gitignore").shouldNotBeEmpty()
156+
projectDir.resolve("gradlew").shouldNotBeEmpty()
157+
projectDir.resolve("gradlew.bat").shouldNotBeEmpty()
158+
projectDir.resolve("gradle/wrapper/gradle-wrapper.jar").shouldNotBeEmpty()
159+
projectDir.resolve("gradle/wrapper/gradle-wrapper.properties").shouldNotBeEmpty()
160+
projectDir.resolve("settings.gradle.kts").shouldNotBeEmpty()
161+
projectDir.resolve("build.gradle.kts").shouldNotBeEmpty()
162+
projectDir.resolve(".github/workflows/build.yaml").shouldNotBeEmpty()
163+
projectDir.resolve(".github/workflows/documentation.yaml").shouldNotBeEmpty()
164+
projectDir.resolve(".github/ISSUE_TEMPLATE/config.yml").shouldNotBeEmpty()
165+
projectDir.resolve(".github/ISSUE_TEMPLATE/20-report-a-bug.yml").shouldNotBeEmpty()
166+
}
167+
}
168+
169+
})

0 commit comments

Comments
 (0)