Skip to content

Commit

Permalink
fix(pr): Address review feedback + allow querying multiple statuses
Browse files Browse the repository at this point in the history
  • Loading branch information
luispollo committed Jul 21, 2020
1 parent af347c1 commit aaa4e62
Show file tree
Hide file tree
Showing 4 changed files with 16 additions and 30 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -46,10 +46,10 @@ 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(type, name, releaseStatus);
return artifactService.getArtifactVersions(type, name, releaseStatuses);
}

@GetMapping("/{provider}/{name}/{version:.+}")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,25 +34,9 @@ public interface ArtifactService {
/** Used to populate the manual trigger dropdown with options */
@Nonnull
List<String> getArtifactVersions(
@Nonnull String type, @Nonnull String name, String releaseStatus);
@Nonnull String type, @Nonnull String name, List<String> releaseStatuses);

/** Used to fetch a specific artifact for decorating a trigger */
@Nonnull
Artifact getArtifact(@Nonnull String type, @Nonnull String name, @Nonnull String version);

/**
* Used to populate the manual trigger dropdown with options (backwards-compatibility for Debian)
*/
@Nonnull
default List<String> getArtifactVersions(@Nonnull String name, String releaseStatus) {
return getArtifactVersions("deb", name, releaseStatus);
}

/**
* Used to fetch a specific artifact for decorating a trigger (backwards-compatibility for Debian)
*/
@Nonnull
default Artifact getArtifact(@Nonnull String name, @Nonnull String version) {
return getArtifact("deb", name, 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,18 +31,20 @@ public ArtifactServiceProvider artifactServiceProvider() {
}

@Override
public List<String> getArtifactVersions(String type, 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;
Expand Down

0 comments on commit aaa4e62

Please sign in to comment.