Skip to content

Commit

Permalink
feat(artifacts): Add type parameter to ArtifactService (#821)
Browse files Browse the repository at this point in the history
* feat(artifacts): Add type parameter to ArtifactService

* fix(pr): Address review feedback + allow querying multiple statuses
  • Loading branch information
luispollo authored Jul 22, 2020
1 parent 62c899a commit 49c9647
Show file tree
Hide file tree
Showing 4 changed files with 33 additions and 18 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -46,18 +46,20 @@ public ArtifactController(ArtifactServices artifactServices) {
public List<String> getVersions(
@PathVariable("provider") String provider,
@PathVariable("name") String name,
@RequestParam(value = "releaseStatus", required = false) String releaseStatus) {
@RequestParam(value = "releaseStatus", required = false) List<String> releaseStatuses,
@RequestParam(value = "type", required = false, defaultValue = "deb") String type) {
ArtifactService artifactService = getService(provider);
return artifactService.getArtifactVersions(name, releaseStatus);
return artifactService.getArtifactVersions(type, name, releaseStatuses);
}

@GetMapping("/{provider}/{name}/{version:.+}")
public Artifact getArtifact(
@PathVariable("provider") String provider,
@PathVariable("name") String name,
@PathVariable("version") String version) {
@PathVariable("version") String version,
@RequestParam(value = "type", required = false, defaultValue = "deb") String type) {
ArtifactService artifactService = getService(provider);
return artifactService.getArtifact(name, version);
return artifactService.getArtifact(type, name, version);
}

private ArtifactService getService(String serviceName) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@

import com.netflix.spinnaker.igor.model.ArtifactServiceProvider;
import com.netflix.spinnaker.kork.artifacts.model.Artifact;
import java.util.ArrayList;
import java.util.List;
import javax.annotation.Nonnull;

Expand All @@ -33,9 +34,19 @@ public interface ArtifactService {

/** Used to populate the manual trigger dropdown with options */
@Nonnull
List<String> getArtifactVersions(@Nonnull String name, String releaseStatus);
default List<String> getArtifactVersions(
@Nonnull String type, @Nonnull String name, String releaseStatus) {
List<String> releaseStatuses = new ArrayList<>();
releaseStatuses.add(releaseStatus);
return getArtifactVersions(type, name, releaseStatuses);
}

/** Used to populate the manual trigger dropdown with options */
@Nonnull
List<String> getArtifactVersions(
@Nonnull String type, @Nonnull String name, List<String> releaseStatuses);

/** Used to fetch a specific artifact for decorating a trigger */
@Nonnull
Artifact getArtifact(@Nonnull String name, @Nonnull String version);
Artifact getArtifact(@Nonnull String type, @Nonnull String name, @Nonnull String version);
}
Original file line number Diff line number Diff line change
Expand Up @@ -27,13 +27,13 @@ class ArtifactServiceSpec extends Specification {

@Subject
ArtifactServices artifactServices = new ArtifactServices()

void setup() {
Map<String, ArtifactService> services = new HashMap<>()
services.put("artifactory", new TestArtifactService())
artifactServices.addServices(services)
}

def "finds matching service"() {
when:
def service = artifactServices.getService("artifactory")
Expand All @@ -53,7 +53,7 @@ class ArtifactServiceSpec extends Specification {
def "service finds artifact versions"() {
when:
def service = artifactServices.getService("artifactory")
def versions = service.getArtifactVersions("test", null)
def versions = service.getArtifactVersions("deb","test", null)

then:
assertThat(versions).isNotNull()
Expand All @@ -64,7 +64,7 @@ class ArtifactServiceSpec extends Specification {
def "service finds only snapshot artifacts"() {
when:
def service = artifactServices.getService("artifactory")
def versions = service.getArtifactVersions("test", "snapshot")
def versions = service.getArtifactVersions("deb","test", "snapshot")

then:
assertThat(versions).isNotNull()
Expand All @@ -75,7 +75,7 @@ class ArtifactServiceSpec extends Specification {
def "service finds artifact"() {
when:
def service = artifactServices.getService("artifactory")
def artifact = service.getArtifact("test", "v0.4.0")
def artifact = service.getArtifact("deb","test", "v0.4.0")

then:
assertThat(artifact).isNotNull()
Expand All @@ -86,7 +86,7 @@ class ArtifactServiceSpec extends Specification {
def "versions list is empty when no versions found"() {
when:
def service = artifactServices.getService("artifactory")
def versions = service.getArtifactVersions("blah", "")
def versions = service.getArtifactVersions("deb","blah", "")

then:
assertThat(versions).isNotNull()
Expand All @@ -96,10 +96,10 @@ class ArtifactServiceSpec extends Specification {
def "404 is thrown when artifact not found"() {
when:
def service = artifactServices.getService("artifactory")
service.getArtifact("blah","v0.0.1")
service.getArtifact("deb","blah","v0.0.1")

then:
thrown(NotFoundException)
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -31,25 +31,27 @@ public ArtifactServiceProvider artifactServiceProvider() {
}

@Override
public List<String> getArtifactVersions(String name, String releaseStatus) {
public List<String> getArtifactVersions(String type, String name, List<String> releaseStatuses) {
if (!name.equals("test")) {
return Collections.emptyList();
}
List<String> versions = new ArrayList<>();
if (releaseStatus == null || releaseStatus.isEmpty() || releaseStatus.contains("final")) {
if (releaseStatuses == null || releaseStatuses.isEmpty() || releaseStatuses.contains("final")) {
versions.add("v0.1.0");
versions.add("v0.2.0");
versions.add("v0.3.0");
versions.add("v0.4.0");
}
if (releaseStatus == null || releaseStatus.isEmpty() || releaseStatus.contains("snapshot")) {
if (releaseStatuses == null
|| releaseStatuses.isEmpty()
|| releaseStatuses.contains("snapshot")) {
versions.add("v0.5.0~SNAPSHOT");
}
return versions;
}

@Override
public Artifact getArtifact(String name, String version) {
public Artifact getArtifact(String type, String name, String version) {
if (!name.equals("test") && !version.equals("v0.4.0")) {
throw new NotFoundException("Artifact not found");
}
Expand Down

0 comments on commit 49c9647

Please sign in to comment.