From def46776f03b2100ccc094eeeea915be03183f81 Mon Sep 17 00:00:00 2001 From: Onur Demirci Date: Tue, 25 Jan 2022 14:43:50 +0100 Subject: [PATCH] JiraNotifier: Add function to get an issue The new function returns an issue for the given issue key which can be used in the script to use specific attributes of it (e.g. reporter of the issue). Signed-off-by: Onur Demirci --- notifier/src/main/kotlin/modules/JiraNotifier.kt | 14 ++++++++++++++ 1 file changed, 14 insertions(+) diff --git a/notifier/src/main/kotlin/modules/JiraNotifier.kt b/notifier/src/main/kotlin/modules/JiraNotifier.kt index 4a632e9d58287..f56bc2f84b03e 100644 --- a/notifier/src/main/kotlin/modules/JiraNotifier.kt +++ b/notifier/src/main/kotlin/modules/JiraNotifier.kt @@ -22,6 +22,7 @@ package org.ossreviewtoolkit.notifier.modules import com.atlassian.jira.rest.client.api.JiraRestClient import com.atlassian.jira.rest.client.api.domain.BasicIssue import com.atlassian.jira.rest.client.api.domain.Comment +import com.atlassian.jira.rest.client.api.domain.Issue import com.atlassian.jira.rest.client.api.domain.input.IssueInputBuilder import com.atlassian.jira.rest.client.api.domain.input.TransitionInput import com.atlassian.jira.rest.client.internal.async.AsynchronousJiraRestClientFactory @@ -65,6 +66,19 @@ class JiraNotifier( }.isSuccess } + /** + * Return the issue for the given [issueKey]. + */ + fun getIssue(issueKey: String): Issue? { + return runCatching { + restClient.issueClient.getIssue(issueKey).claim() + }.onFailure { + log.error { + "Could not retrieve the issue with the key '$issueKey' due to: ${it.collectMessagesAsString()}" + } + }.getOrNull() + } + /** * Returns a [ProjectIssueBuilder] object, which can be used to do operations for the given [projectKey]. */