-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #6 from Liftric/feature/issue-tracker
feat: support Jira issue parsing in commits from changelog
- Loading branch information
Showing
5 changed files
with
168 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
97 changes: 97 additions & 0 deletions
97
src/test/kotlin/com/liftric/octopusdeploy/task/CreateBuildInformationTaskTest.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,97 @@ | ||
package com.liftric.octopusdeploy.task | ||
|
||
import com.fasterxml.jackson.module.kotlin.jacksonObjectMapper | ||
import com.fasterxml.jackson.module.kotlin.readValue | ||
import com.liftric.octopusdeploy.api.BuildInformationCli | ||
import com.liftric.octopusdeploy.api.CommitCli | ||
import com.liftric.octopusdeploy.api.WorkItem | ||
import junit.framework.TestCase.* | ||
import org.gradle.api.Project | ||
import org.gradle.testfixtures.ProjectBuilder | ||
import org.junit.Rule | ||
import org.junit.Test | ||
import org.junit.rules.TemporaryFolder | ||
|
||
class CreateBuildInformationTaskTest { | ||
@get:Rule | ||
val outputDir = TemporaryFolder() | ||
|
||
@Test | ||
fun testParseJira() { | ||
val project: Project = ProjectBuilder.builder().build() | ||
project.pluginManager.apply("com.liftric.octopus-deploy-plugin") | ||
|
||
assertTrue(project.tasks.getByName("createBuildInformation") is CreateBuildInformationTask) | ||
|
||
val task = project.tasks.getByName("createBuildInformation") as CreateBuildInformationTask | ||
val baseJiraUrl = "https://testric.atlassian.net/browser/" | ||
task.apply { | ||
packageName.set("test-package") | ||
version.set("2.1.4") | ||
commits = createTestCommits() | ||
outputDir = this@CreateBuildInformationTaskTest.outputDir.root | ||
issueTrackerName.set("Jira") | ||
parseCommitsForJiraIssues.set(true) | ||
jiraBaseBrowseUrl.set(baseJiraUrl) | ||
} | ||
task.execute() | ||
assertTrue(task.outputFile?.exists() == true) | ||
val jsonText = task.outputFile!!.readText() | ||
val taskResult = jacksonObjectMapper().readValue<BuildInformationCli>(jsonText) | ||
assertNotNull(taskResult.WorkItems) | ||
taskResult.WorkItems?.let { workItems -> | ||
assertEquals(2, workItems.size) | ||
workItems.verify("LIF-71", baseJiraUrl) | ||
workItems.verify("LIF-72", baseJiraUrl) | ||
} | ||
} | ||
|
||
private fun createTestCommits(): List<CommitCli> { | ||
return listOf( | ||
testCommit1, | ||
testCommit2, | ||
testCommit3, | ||
testCommit4, | ||
testCommit5 | ||
) | ||
} | ||
|
||
companion object { | ||
val testCommit1 = CommitCli( | ||
"7119e5a28ef691cf95ec98cbf8b2e6bc4b1d84fc", | ||
"null/commit/7119e5a28ef691cf95ec98cbf8b2e6bc4b1d84fc", | ||
"[Gradle Release Plugin] - pre tag commit: '0.1.44'. " | ||
) | ||
val testCommit2 = CommitCli( | ||
"c6dc72fa67b5eb8fb134153ab240b169dea0d565", | ||
"null/commit/c6dc72fa67b5eb8fb134153ab240b169dea0d565", | ||
"Merge branch 'feature/test-octopus-integration' into 'master' " | ||
) | ||
val testCommit3 = CommitCli( | ||
"cb230f92c95ee1118d1348a9e96d6d45e7c611c9", | ||
"null/commit/cb230f92c95ee1118d1348a9e96d6d45e7c611c9", | ||
"feat(build): dummy commit for octopus - LIF-71 " | ||
) | ||
val testCommit4 = CommitCli( | ||
"cb230f92c95ee1118d1348a9e96d6d35e7c611c9", | ||
"null/commit/cb230f92c95ee1218d1348a9e96d6d45e7c611c9", | ||
"feat(build): dummy commit 2 for octopus - LIF-72" | ||
) | ||
val testCommit5 = CommitCli( | ||
"0f1352918b05338eba2275cbab8d33601a810251", | ||
"null/commit/0f1352918b05338eba2275cbab8d33601a810251", | ||
"[Gradle Release Plugin] [ci skip] - new version commit: '0.1.44-SNAPSHOT'" | ||
) | ||
} | ||
} | ||
|
||
private fun List<WorkItem>.verify( | ||
key: String, | ||
baseJiraUrl: String | ||
) { | ||
assertEquals(1, count { it.Id == key }) | ||
first { it.Id == key }.let { workItem -> | ||
assertEquals(workItem.Id, key) | ||
assertEquals(workItem.LinkUrl, "${baseJiraUrl}${key}") | ||
} | ||
} |