Skip to content

Commit 0070008

Browse files
wkl3nkmnonnenmacher
authored andcommitted
feat(notifier): Add Jira notifier configuration
Providing a way to configure a Jira notifier to interact with a Jira server at the end of an ORT run, e.g. to create a comment to an existing Jira issue about the result of the ORT run. Signed-off-by: Wolfgang Klenk <[email protected]>
1 parent 7ab10aa commit 0070008

File tree

10 files changed

+202
-14
lines changed

10 files changed

+202
-14
lines changed

api/v1/mapping/src/commonMain/kotlin/Mappings.kt

Lines changed: 32 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,8 @@ import org.eclipse.apoapsis.ortserver.api.v1.model.EnvironmentVariableDeclaratio
3030
import org.eclipse.apoapsis.ortserver.api.v1.model.EvaluatorJob as ApiEvaluatorJob
3131
import org.eclipse.apoapsis.ortserver.api.v1.model.EvaluatorJobConfiguration as ApiEvaluatorJobConfiguration
3232
import org.eclipse.apoapsis.ortserver.api.v1.model.InfrastructureService as ApiInfrastructureService
33+
import org.eclipse.apoapsis.ortserver.api.v1.model.JiraNotificationConfiguration as ApiJiraNotificationConfiguration
34+
import org.eclipse.apoapsis.ortserver.api.v1.model.JiraRestClientConfiguration as ApiJiraRestClientConfiguration
3335
import org.eclipse.apoapsis.ortserver.api.v1.model.JobConfigurations as ApiJobConfigurations
3436
import org.eclipse.apoapsis.ortserver.api.v1.model.JobStatus as ApiJobStatus
3537
import org.eclipse.apoapsis.ortserver.api.v1.model.JobSummaries as ApiJobSummaries
@@ -70,6 +72,8 @@ import org.eclipse.apoapsis.ortserver.model.EvaluatorJob
7072
import org.eclipse.apoapsis.ortserver.model.EvaluatorJobConfiguration
7173
import org.eclipse.apoapsis.ortserver.model.InfrastructureService
7274
import org.eclipse.apoapsis.ortserver.model.InfrastructureServiceDeclaration
75+
import org.eclipse.apoapsis.ortserver.model.JiraNotificationConfiguration
76+
import org.eclipse.apoapsis.ortserver.model.JiraRestClientConfiguration
7377
import org.eclipse.apoapsis.ortserver.model.JobConfigurations
7478
import org.eclipse.apoapsis.ortserver.model.JobStatus
7579
import org.eclipse.apoapsis.ortserver.model.Jobs
@@ -351,14 +355,16 @@ fun NotifierJobConfiguration.mapToApi() =
351355
ApiNotifierJobConfiguration(
352356
notifierRules = notifierRules,
353357
resolutionsFile = resolutionsFile,
354-
mail = mail?.mapToApi()
358+
mail = mail?.mapToApi(),
359+
jira = jira?.mapToApi()
355360
)
356361

357362
fun ApiNotifierJobConfiguration.mapToModel() =
358363
NotifierJobConfiguration(
359364
notifierRules = notifierRules,
360365
resolutionsFile = resolutionsFile,
361-
mail = mail?.mapToModel()
366+
mail = mail?.mapToModel(),
367+
jira = jira?.mapToModel()
362368
)
363369

364370
fun ApiReporterJobConfiguration.mapToModel() =
@@ -491,6 +497,16 @@ fun ApiMailNotificationConfiguration.mapToModel() =
491497
mailServerConfiguration = mailServerConfiguration?.mapToModel()
492498
)
493499

500+
fun JiraNotificationConfiguration.mapToApi() =
501+
ApiJiraNotificationConfiguration(
502+
jiraRestClientConfiguration = jiraRestClientConfiguration?.mapToApi()
503+
)
504+
505+
fun ApiJiraNotificationConfiguration.mapToModel() =
506+
JiraNotificationConfiguration(
507+
jiraRestClientConfiguration = jiraRestClientConfiguration?.mapToModel()
508+
)
509+
494510
fun MailServerConfiguration.mapToApi() =
495511
ApiMailServerConfiguration(
496512
hostName = hostName,
@@ -511,6 +527,20 @@ fun ApiMailServerConfiguration.mapToModel() =
511527
fromAddress = fromAddress
512528
)
513529

530+
fun JiraRestClientConfiguration.mapToApi() =
531+
ApiJiraRestClientConfiguration(
532+
serverUrl = serverUrl,
533+
username = username,
534+
password = password
535+
)
536+
537+
fun ApiJiraRestClientConfiguration.mapToModel() =
538+
JiraRestClientConfiguration(
539+
serverUrl = serverUrl,
540+
username = username,
541+
password = password
542+
)
543+
514544
fun ApiPagingOptions.mapToModel() =
515545
ListQueryParameters(
516546
sortFields = sortProperties?.map { it.mapToModel() }.orEmpty(),
Lines changed: 52 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,52 @@
1+
/*
2+
* Copyright (C) 2024 The ORT Server Authors (See <https://github.com/eclipse-apoapsis/ort-server/blob/main/NOTICE>)
3+
*
4+
* Licensed under the Apache License, Version 2.0 (the "License");
5+
* you may not use this file except in compliance with the License.
6+
* You may obtain a copy of the License at
7+
*
8+
* https://www.apache.org/licenses/LICENSE-2.0
9+
*
10+
* Unless required by applicable law or agreed to in writing, software
11+
* distributed under the License is distributed on an "AS IS" BASIS,
12+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
* See the License for the specific language governing permissions and
14+
* limitations under the License.
15+
*
16+
* SPDX-License-Identifier: Apache-2.0
17+
* License-Filename: LICENSE
18+
*/
19+
20+
package org.eclipse.apoapsis.ortserver.api.v1.model
21+
22+
import kotlinx.serialization.Serializable
23+
24+
/**
25+
* Configuration for Jira notifications.
26+
* Notifications are typically sent after an [OrtRun] using a built-in Jira REST client.
27+
*/
28+
@Serializable
29+
data class JiraNotificationConfiguration(
30+
val jiraRestClientConfiguration: JiraRestClientConfiguration? = null
31+
)
32+
33+
/**
34+
* Configuration for a Jira REST client interacting with a Jira server after an [OrtRun].
35+
*/
36+
@Serializable
37+
data class JiraRestClientConfiguration(
38+
/**
39+
* The URL of the Jira server, e.g. "https://jira.example.com".
40+
*/
41+
val serverUrl: String,
42+
43+
/**
44+
* The username to authenticate with the Jira server.
45+
*/
46+
val username: String,
47+
48+
/**
49+
* The password to authenticate with the Jira server.
50+
*/
51+
val password: String
52+
)

api/v1/model/src/commonMain/kotlin/JobConfigurations.kt

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -344,7 +344,12 @@ data class NotifierJobConfiguration(
344344
/**
345345
* The configuration for Email notifications. If this is null, no email notifications will be sent.
346346
*/
347-
val mail: MailNotificationConfiguration? = null
347+
val mail: MailNotificationConfiguration? = null,
348+
349+
/**
350+
* The configuration for Jira notifications. If this is null, no Jira notifications will be sent.
351+
*/
352+
val jira: JiraNotificationConfiguration? = null
348353
)
349354

350355
/**

core/src/main/kotlin/apiDocs/RepositoriesDocs.kt

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,8 @@ import org.eclipse.apoapsis.ortserver.api.v1.model.EnvironmentConfig
3838
import org.eclipse.apoapsis.ortserver.api.v1.model.EvaluatorJob
3939
import org.eclipse.apoapsis.ortserver.api.v1.model.EvaluatorJobConfiguration
4040
import org.eclipse.apoapsis.ortserver.api.v1.model.InfrastructureService
41+
import org.eclipse.apoapsis.ortserver.api.v1.model.JiraNotificationConfiguration
42+
import org.eclipse.apoapsis.ortserver.api.v1.model.JiraRestClientConfiguration
4143
import org.eclipse.apoapsis.ortserver.api.v1.model.JobConfigurations
4244
import org.eclipse.apoapsis.ortserver.api.v1.model.JobStatus
4345
import org.eclipse.apoapsis.ortserver.api.v1.model.JobSummaries
@@ -144,6 +146,13 @@ private val fullJobConfigurations = JobConfigurations(
144146
useSsl = true,
145147
fromAddress = "[email protected]"
146148
)
149+
),
150+
jira = JiraNotificationConfiguration(
151+
jiraRestClientConfiguration = JiraRestClientConfiguration(
152+
serverUrl = "https://jira.example.com",
153+
username = "user",
154+
password = "password"
155+
)
147156
)
148157
)
149158
)

dao/src/testFixtures/kotlin/Fixtures.kt

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,7 @@ import org.eclipse.apoapsis.ortserver.dao.tables.runs.shared.IdentifierDao
4444
import org.eclipse.apoapsis.ortserver.model.AdvisorJobConfiguration
4545
import org.eclipse.apoapsis.ortserver.model.AnalyzerJobConfiguration
4646
import org.eclipse.apoapsis.ortserver.model.EvaluatorJobConfiguration
47+
import org.eclipse.apoapsis.ortserver.model.JiraNotificationConfiguration
4748
import org.eclipse.apoapsis.ortserver.model.JobConfigurations
4849
import org.eclipse.apoapsis.ortserver.model.MailNotificationConfiguration
4950
import org.eclipse.apoapsis.ortserver.model.NotifierJobConfiguration
@@ -112,7 +113,8 @@ class Fixtures(private val db: Database) {
112113
notifier = NotifierJobConfiguration(
113114
mail = MailNotificationConfiguration(
114115
recipientAddresses = listOf("[email protected]")
115-
)
116+
),
117+
jira = JiraNotificationConfiguration()
116118
)
117119
)
118120

Lines changed: 52 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,52 @@
1+
/*
2+
* Copyright (C) 2024 The ORT Server Authors (See <https://github.com/eclipse-apoapsis/ort-server/blob/main/NOTICE>)
3+
*
4+
* Licensed under the Apache License, Version 2.0 (the "License");
5+
* you may not use this file except in compliance with the License.
6+
* You may obtain a copy of the License at
7+
*
8+
* https://www.apache.org/licenses/LICENSE-2.0
9+
*
10+
* Unless required by applicable law or agreed to in writing, software
11+
* distributed under the License is distributed on an "AS IS" BASIS,
12+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
* See the License for the specific language governing permissions and
14+
* limitations under the License.
15+
*
16+
* SPDX-License-Identifier: Apache-2.0
17+
* License-Filename: LICENSE
18+
*/
19+
20+
package org.eclipse.apoapsis.ortserver.model
21+
22+
import kotlinx.serialization.Serializable
23+
24+
/**
25+
* Configuration for Jira notifications.
26+
* Notifications are typically sent after an [OrtRun] using a built-in Jira REST client.
27+
*/
28+
@Serializable
29+
data class JiraNotificationConfiguration(
30+
val jiraRestClientConfiguration: JiraRestClientConfiguration? = null
31+
)
32+
33+
/**
34+
* Configuration for a Jira REST client interacting with a Jira server after an [OrtRun].
35+
*/
36+
@Serializable
37+
data class JiraRestClientConfiguration(
38+
/**
39+
* The URL of the Jira server, e.g. "https://jira.example.com".
40+
*/
41+
val serverUrl: String,
42+
43+
/**
44+
* The username to authenticate with the Jira server.
45+
*/
46+
val username: String,
47+
48+
/**
49+
* The password to authenticate with the Jira server.
50+
*/
51+
val password: String
52+
)

model/src/commonMain/kotlin/JobConfigurations.kt

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -357,7 +357,12 @@ data class NotifierJobConfiguration(
357357
/**
358358
* The configuration for Email notifications. Is this is null, no email notifications will be sent.
359359
*/
360-
val mail: MailNotificationConfiguration? = null
360+
val mail: MailNotificationConfiguration? = null,
361+
362+
/**
363+
* The configuration for Jira notifications. Is this is null, no Jira notifications will be sent.
364+
*/
365+
val jira: JiraNotificationConfiguration? = null
361366
)
362367

363368
/**

workers/common/src/main/kotlin/common/OrtServerMappings.kt

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@ import java.time.Instant
2727

2828
import kotlinx.datetime.toJavaInstant
2929

30+
import org.eclipse.apoapsis.ortserver.model.JiraRestClientConfiguration
3031
import org.eclipse.apoapsis.ortserver.model.MailServerConfiguration
3132
import org.eclipse.apoapsis.ortserver.model.OrtRun
3233
import org.eclipse.apoapsis.ortserver.model.PluginConfiguration
@@ -168,6 +169,7 @@ import org.ossreviewtoolkit.model.config.FileStorageConfiguration as OrtFileStor
168169
import org.ossreviewtoolkit.model.config.HttpFileStorageConfiguration as OrtHttpFileStorageConfiguration
169170
import org.ossreviewtoolkit.model.config.IssueResolution as OrtIssueResolution
170171
import org.ossreviewtoolkit.model.config.IssueResolutionReason as OrtIssueResolutionReason
172+
import org.ossreviewtoolkit.model.config.JiraConfiguration as OrtJiraConfiguration
171173
import org.ossreviewtoolkit.model.config.LicenseChoices as OrtLicenseChoices
172174
import org.ossreviewtoolkit.model.config.LicenseFindingCuration as OrtLicenseFindingCuration
173175
import org.ossreviewtoolkit.model.config.LicenseFindingCurationReason as OrtLicenseFindingCurationReason
@@ -782,3 +784,10 @@ fun MailServerConfiguration.mapToOrt() =
782784
useSsl = useSsl,
783785
fromAddress = fromAddress
784786
)
787+
788+
fun JiraRestClientConfiguration.mapToOrt() =
789+
OrtJiraConfiguration(
790+
host = serverUrl,
791+
username = username,
792+
password = password
793+
)

workers/notifier/src/main/kotlin/notifier/NotifierRunner.kt

Lines changed: 24 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -70,17 +70,32 @@ class NotifierRunner {
7070
workerContext.configManager.getSecret(Path(it))
7171
}
7272

73-
val notifierConfiguration = if (mailServerUser != null && mailServerPassword != null) {
74-
NotifierConfiguration(
75-
mail = config.mail?.mailServerConfiguration?.copy(
76-
username = mailServerUser,
77-
password = mailServerPassword
78-
)?.mapToOrt()
79-
)
80-
} else {
81-
NotifierConfiguration()
73+
val sendMailConfiguration = config.mail?.mailServerConfiguration?.takeIf {
74+
mailServerUser != null && mailServerPassword != null
75+
}?.copy(
76+
username = mailServerUser!!,
77+
password = mailServerPassword!!
78+
)?.mapToOrt()
79+
80+
val jiraRestClientUsername = config.jira?.jiraRestClientConfiguration?.username?.let {
81+
workerContext.configManager.getSecret(Path(it))
82+
}
83+
val jiraRestClientPassword = config.jira?.jiraRestClientConfiguration?.password?.let {
84+
workerContext.configManager.getSecret(Path(it))
8285
}
8386

87+
val jiraConfiguration = config.jira?.jiraRestClientConfiguration?.takeIf {
88+
jiraRestClientUsername != null && jiraRestClientPassword != null
89+
}?.copy(
90+
username = jiraRestClientUsername!!,
91+
password = jiraRestClientPassword!!
92+
)?.mapToOrt()
93+
94+
val notifierConfiguration = NotifierConfiguration(
95+
mail = sendMailConfiguration,
96+
jira = jiraConfiguration
97+
)
98+
8499
val resolutionsFromOrtResult = ortResult.repository.config.resolutions
85100

86101
val resolutionsFromFile = workerContext.configManager.readConfigFileWithDefault(

workers/notifier/src/test/kotlin/NotifierRunnerTest.kt

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,8 @@ import java.io.File
3232
import org.eclipse.apoapsis.ortserver.config.ConfigManager
3333
import org.eclipse.apoapsis.ortserver.config.Context
3434
import org.eclipse.apoapsis.ortserver.config.Path
35+
import org.eclipse.apoapsis.ortserver.model.JiraNotificationConfiguration
36+
import org.eclipse.apoapsis.ortserver.model.JiraRestClientConfiguration
3537
import org.eclipse.apoapsis.ortserver.model.MailNotificationConfiguration
3638
import org.eclipse.apoapsis.ortserver.model.MailServerConfiguration
3739
import org.eclipse.apoapsis.ortserver.model.NotifierJobConfiguration
@@ -62,6 +64,13 @@ class NotifierRunnerTest : WordSpec({
6264
useSsl = false,
6365
fromAddress = "[email protected]"
6466
)
67+
),
68+
jira = JiraNotificationConfiguration(
69+
jiraRestClientConfiguration = JiraRestClientConfiguration(
70+
serverUrl = "https://jira.example.com",
71+
username = "secret-username",
72+
password = "secret-password"
73+
)
6574
)
6675
)
6776
}

0 commit comments

Comments
 (0)