Skip to content

Instantly share code, notes, and snippets.

@jesusjavierdediego
Created December 20, 2018 13:30
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save jesusjavierdediego/c10d401bdd8970ffdbeb6a05c5e9c560 to your computer and use it in GitHub Desktop.
Save jesusjavierdediego/c10d401bdd8970ffdbeb6a05c5e9c560 to your computer and use it in GitHub Desktop.
@throws(classOf[JIRAException])
def getJIRARESTClient(): Option[JiraRestClient] = {
try {
val asyncClientFactory: AsynchronousJiraRestClientFactory = new AsynchronousJiraRestClientFactory()
result = Some(asyncClientFactory.createWithBasicHttpAuthentication(
new URI(baseUrl),
jiraUser,
jiraPwd
))
}catch{
case(e: Exception) => {
logger.error(s"The atlassian jira erest client could not be created. Reason: ${e}")
throw new JIRAException()
}
}
result
}
@throws(classOf[JIRAException])
def createNewJIRAItemAndWriteFeatureInto(rf: RequirementFeature): Unit ={
val defaultIssueType = configuration.envOrElseConfig("data.destination.jira.defaultIssueType")
try{
val issueTypes = client.getMetadataClient.getIssueTypes.claim().asScala
for(it <- issueTypes) yield {
if(it.getName.equals(defaultIssueType)){
val projectId: Long = client.getProjectClient.getProject(rf.projectKey).claim().getId
val newIssueInput: IssueInput = new IssueInputBuilder(rf.projectKey,it.getId, rf.jiraIssue.get.summary).build()
val newIssue: BasicIssue = client.getIssueClient.createIssue(newIssueInput).claim()
updateDescriptionIntoExistingJIRAIssue(updateJIRAItemInRF(newIssue, rf))
}
}
}catch{
case e: Exception => {
logger.error(s"Error trying to create a new JIRA issue. feature: '${rf.name}'. Reason: ${e}")
throw new JIRAException(s"Error trying to create a new JIRA issue. feature: '${rf.name}'. Reason: ${e}")
}
}
}
private def updateJIRAItemInRF(newIssue: BasicIssue, rf: RequirementFeature): RequirementFeature ={
val newJIRAItem: JIRAIssue = new JIRAIssue(newIssue.getId, newIssue.getKey, rf.name)
new RequirementFeature(rf.feature_id, rf.name, rf.projectKey, rf.component, rf.scenarios, Some(newJIRAItem), rf.lastUpdateTime)
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment