Skip to content

Commit

Permalink
fix(nexus): deserialize nexus trigger (#3130)
Browse files Browse the repository at this point in the history
  • Loading branch information
claymccoy committed Sep 13, 2019
1 parent 3cae8de commit e4d4c2c
Show file tree
Hide file tree
Showing 4 changed files with 88 additions and 1 deletion.
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
/*
* Copyright 2019 Pivotal, Inc.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/

package com.netflix.spinnaker.orca.pipeline.model

import com.netflix.spinnaker.kork.artifacts.model.Artifact
import com.netflix.spinnaker.kork.artifacts.model.ExpectedArtifact

data class NexusTrigger
@JvmOverloads constructor(
override val type: String = "nexus",
override val correlationId: String? = null,
override val user: String? = "[anonymous]",
override val parameters: Map<String, Any> = mutableMapOf(),
override val artifacts: List<Artifact> = mutableListOf(),
override val notifications: List<Map<String, Any>> = mutableListOf(),
override var isRebake: Boolean = false,
override var isDryRun: Boolean = false,
override var isStrategy: Boolean = false,
val nexusSearchName: String
) : Trigger {
override var other: Map<String, Any> = mutableMapOf()
override var resolvedExpectedArtifacts: List<ExpectedArtifact> = mutableListOf()
}
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ import com.netflix.spinnaker.orca.pipeline.model.DockerTrigger
import com.netflix.spinnaker.orca.pipeline.model.Execution
import com.netflix.spinnaker.orca.pipeline.model.GitTrigger
import com.netflix.spinnaker.orca.pipeline.model.JenkinsTrigger
import com.netflix.spinnaker.orca.pipeline.model.NexusTrigger
import com.netflix.spinnaker.orca.pipeline.model.PipelineTrigger
import com.netflix.spinnaker.orca.pipeline.model.Trigger

Expand Down Expand Up @@ -111,6 +112,18 @@ internal class TriggerDeserializer :
get("strategy")?.booleanValue() == true,
get("artifactorySearchName").textValue()
)
looksLikeNexus() -> NexusTrigger(
get("type").textValue(),
get("correlationId")?.textValue(),
get("user")?.textValue() ?: "[anonymous]",
get("parameters")?.mapValue(parser) ?: mutableMapOf(),
get("artifacts")?.listValue(parser) ?: mutableListOf(),
get("notifications")?.listValue(parser) ?: mutableListOf(),
get("rebake")?.booleanValue() == true,
get("dryRun")?.booleanValue() == true,
get("strategy")?.booleanValue() == true,
get("nexusSearchName").textValue()
)
looksLikeGit() -> GitTrigger(
get("type").textValue(),
get("correlationId")?.textValue(),
Expand Down Expand Up @@ -166,6 +179,9 @@ internal class TriggerDeserializer :
private fun JsonNode.looksLikeArtifactory() =
hasNonNull("artifactorySearchName")

private fun JsonNode.looksLikeNexus() =
hasNonNull("nexusSearchName")

private fun JsonNode.looksLikeCustom() =
customTriggerSuppliers.any { it.predicate.invoke(this) }

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -494,6 +494,31 @@ class TriggerSpec extends Specification {
'''
}

def "can parse an nexus trigger"() {
given:
def trigger = mapper.readValue(triggerJson, Trigger)

expect:
trigger instanceof NexusTrigger
with(trigger) {
nexusSearchName == "search-name"
}

where:
triggerJson = '''
{
"account": "theaccount",
"enabled": true,
"job": "the-job",
"master": "master",
"organization": "org",
"nexusSearchName": "search-name",
"nexusRepository": "libs-demo-local",
"type": "nexus"
}
'''
}

def pubSubTrigger = '''
{
"attributeConstraints": {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -378,6 +378,9 @@ class TaskControllerSpec extends Specification {
],
[pipelineConfigId: "1", id: "test-4", startTime: clock.instant().minus(daysOfExecutionHistory, DAYS).minus(2, HOURS).toEpochMilli(),
trigger: new ArtifactoryTrigger("libs-demo-local")
],
[pipelineConfigId: "1", id: "test-5", startTime: clock.instant().minus(daysOfExecutionHistory, DAYS).minus(2, HOURS).toEpochMilli(),
trigger: new NexusTrigger("libs-nexus-local")
]
]

Expand Down Expand Up @@ -405,7 +408,7 @@ class TaskControllerSpec extends Specification {
List results = new ObjectMapper().readValue(response.contentAsString, List)

then:
results.id == ['test-1', 'test-2', 'test-3', 'test-4']
results.id == ['test-1', 'test-2', 'test-3', 'test-4', 'test-5']
}

void '/applications/{application}/pipelines/search should only return pipelines of given types'() {
Expand All @@ -426,6 +429,9 @@ class TaskControllerSpec extends Specification {
],
[pipelineConfigId: "1", id: "test-5", startTime: clock.instant().minus(daysOfExecutionHistory, DAYS).minus(2, HOURS).toEpochMilli(),
trigger: new ArtifactoryTrigger("libs-demo-local")
],
[pipelineConfigId: "1", id: "test-6", startTime: clock.instant().minus(daysOfExecutionHistory, DAYS).minus(2, HOURS).toEpochMilli(),
trigger: new NexusTrigger("libs-nexus-local")
]
]

Expand Down Expand Up @@ -475,6 +481,9 @@ class TaskControllerSpec extends Specification {
],
[pipelineConfigId: "1", id: "test-5", startTime: clock.instant().minus(daysOfExecutionHistory, DAYS).minus(2, HOURS).toEpochMilli(),
trigger: new ArtifactoryTrigger("libs-demo-local"), eventId: wrongEventId
],
[pipelineConfigId: "1", id: "test-6", startTime: clock.instant().minus(daysOfExecutionHistory, DAYS).minus(2, HOURS).toEpochMilli(),
trigger: new NexusTrigger("libs-nexus-local"), eventId: wrongEventId
]
]

Expand Down

0 comments on commit e4d4c2c

Please sign in to comment.