Skip to content

Commit

Permalink
feat(artifactory): add link to artifactory app for artifact (#439)
Browse files Browse the repository at this point in the history
  • Loading branch information
claymccoy authored and jkschneider committed May 15, 2019
1 parent 0aa3eab commit aeddd7f
Show file tree
Hide file tree
Showing 3 changed files with 28 additions and 11 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -152,6 +152,7 @@ protected ArtifactPollingDelta generateDelta(PollContext ctx) {
aqlResponse.parseBody(ArtifactoryQueryResults.class).getResults();
return new ArtifactPollingDelta(
search.getName(),
client.getUri(),
search.getPartitionName(),
Collections.singletonList(
new ArtifactDelta(
Expand All @@ -175,15 +176,16 @@ protected void commitDelta(ArtifactPollingDelta delta, boolean sendEvents) {
for (ArtifactDelta artifactDelta : delta.items) {
if (sendEvents) {
for (ArtifactoryItem artifact : artifactDelta.getArtifacts()) {
postEvent(artifactDelta.getType(), artifact, delta.getName());
Artifact matchableArtifact =
artifact.toMatchableArtifact(artifactDelta.getType(), delta.getBaseUrl());
postEvent(matchableArtifact, delta.getName());
log.debug("{} event posted", artifact);
}
}
}
}

private void postEvent(
ArtifactoryRepositoryType repoType, ArtifactoryItem artifact, String name) {
private void postEvent(Artifact artifact, String name) {
if (!echoService.isPresent()) {
log.warn("Cannot send build notification: Echo is not configured");
registry
Expand All @@ -192,21 +194,23 @@ private void postEvent(
"monitor", ArtifactoryBuildMonitor.class.getSimpleName()))
.increment();
} else {
Artifact matchableArtifact = artifact.toMatchableArtifact(repoType);
if (matchableArtifact != null) {
if (artifact != null) {
echoService
.get()
.postEvent(new ArtifactoryEvent(new ArtifactoryEvent.Content(name, matchableArtifact)));
.postEvent(new ArtifactoryEvent(new ArtifactoryEvent.Content(name, artifact)));
}
}
}

@Data
static class ArtifactPollingDelta implements PollingDelta<ArtifactDelta> {
public static ArtifactPollingDelta EMPTY = new ArtifactPollingDelta(null, null, emptyList());
public static ArtifactPollingDelta EMPTY =
new ArtifactPollingDelta(null, null, null, emptyList());

private final String name;

private final String baseUrl;

@Nullable private final String repo;

private final List<ArtifactDelta> items;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ public class ArtifactoryItem {
private List<ArtifactoryArtifact> artifacts;

@Nullable
public Artifact toMatchableArtifact(ArtifactoryRepositoryType repoType) {
public Artifact toMatchableArtifact(ArtifactoryRepositoryType repoType, String baseUrl) {
switch (repoType) {
case Maven:
String[] pathParts = path.split("/");
Expand All @@ -41,13 +41,20 @@ public Artifact toMatchableArtifact(ArtifactoryRepositoryType repoType) {
String[] groupParts = Arrays.copyOfRange(pathParts, 0, pathParts.length - 2);
String group = String.join(".", groupParts);

String location = null;
if (baseUrl != null) {
location =
baseUrl + "/artifactory/webapp/#/artifacts/browse/tree/General/" + repo + "/" + path;
}

final Artifact.ArtifactBuilder artifactBuilder =
Artifact.builder()
.type("maven/file")
.reference(group + ":" + artifactId + ":" + version)
.name(group + ":" + artifactId)
.version(version)
.provenance(repo);
.provenance(repo)
.location(location);

if (artifacts != null && !artifacts.isEmpty()) {
final ArtifactoryArtifact artifact = artifacts.get(0);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,13 +31,18 @@ void toMatchableArtifact() {
artifact.setPath("io/pivotal/spinnaker/demo/0.1.0-dev.20+d9a14fb");
artifact.setRepo("libs-demo-local");

Artifact matchableArtifact = artifact.toMatchableArtifact(ArtifactoryRepositoryType.Maven);
Artifact matchableArtifact =
artifact.toMatchableArtifact(ArtifactoryRepositoryType.Maven, "http://localhost:8080");
assertThat(matchableArtifact).isNotNull();
assertThat(matchableArtifact.getType()).isEqualTo("maven/file");
assertThat(matchableArtifact.getReference())
.isEqualTo("io.pivotal.spinnaker:demo:0.1.0-dev.20+d9a14fb");
assertThat(matchableArtifact.getVersion()).isEqualTo("0.1.0-dev.20+d9a14fb");
assertThat(matchableArtifact.getName()).isEqualTo("io.pivotal.spinnaker:demo");
assertThat(matchableArtifact.getLocation())
.isEqualTo(
"http://localhost:8080/artifactory/webapp/#/artifacts/browse/tree/General/libs-demo-local/io/pivotal"
+ "/spinnaker/demo/0.1.0-dev.20+d9a14fb");
}

@Test
Expand Down Expand Up @@ -73,7 +78,8 @@ void toMatchableArtifactWithBuild() {
artifacts.add(new ArtifactoryArtifact(modules));
artifact.setArtifacts(artifacts);

Artifact matchableArtifact = artifact.toMatchableArtifact(ArtifactoryRepositoryType.Maven);
Artifact matchableArtifact =
artifact.toMatchableArtifact(ArtifactoryRepositoryType.Maven, null);
assertThat(matchableArtifact.getMetadata().get("build")).isEqualTo(expectedBuild);
}
}

0 comments on commit aeddd7f

Please sign in to comment.