Skip to content
This repository has been archived by the owner on Nov 17, 2022. It is now read-only.

Commit

Permalink
Add footer with current Update Level
Browse files Browse the repository at this point in the history
  • Loading branch information
batmat committed Oct 29, 2018
1 parent a9ecd20 commit cbb94c1
Show file tree
Hide file tree
Showing 4 changed files with 70 additions and 0 deletions.
@@ -0,0 +1,48 @@
package io.jenkins.plugins.evergreen;

import com.google.common.annotations.VisibleForTesting;
import hudson.Extension;
import hudson.model.PageDecorator;
import net.sf.json.JSONException;
import net.sf.json.JSONObject;
import net.sf.json.groovy.JsonSlurper;

import java.io.File;
import java.io.IOException;
import java.util.logging.Logger;


@Extension
public class EvergreenUpdateLevelPageDecorator extends PageDecorator {

private static final Logger LOGGER = Logger.getLogger(EvergreenUpdateLevelPageDecorator.class.getName());
private File manifest;

@VisibleForTesting
EvergreenUpdateLevelPageDecorator(File manifestFilePath) {
this.manifest = manifestFilePath;
}

public EvergreenUpdateLevelPageDecorator() {
final String evergreenData = System.getenv("EVERGREEN_DATA");
manifest = new File(evergreenData, "updates.json");
}

public String getUpdateLevel() {
String updateLevel = "N/A";

if (manifest.exists()) {
try {
final JSONObject parsedJson = (JSONObject) new JsonSlurper().parse(manifest);
updateLevel = "" + ((JSONObject) parsedJson.get("meta")).get("level");
} catch (IOException e) {
updateLevel = "Unable to parse: " + e.getMessage();
} catch (JSONException e) {
updateLevel = "Corrupted manifest: " + e.getMessage();
}
} else {
LOGGER.warning("No Evergreen manifest found!");
}
return updateLevel;
}
}
@@ -0,0 +1,4 @@
<?jelly escape-by-default='true'?>
<j:jelly xmlns:j="jelly:core">
<span class="updateLevel"><a href="https://evergreen.jenkins.io/">Evergreen <em><acronym title="Update Level">UL</acronym>-<j:out value="${it.getUpdateLevel()}"/></em></a></span>
</j:jelly>
@@ -0,0 +1,17 @@
package io.jenkins.plugins.evergreen;

import org.junit.Test;

import java.io.File;

import static org.assertj.core.api.Assertions.assertThat;

public class EvergreenUpdateLevelPageDecoratorTest {
@Test
public void getUpdateLevel() {

final File manifestFile = new File(getClass().getResource("manifest.json").getPath());
assertThat(manifestFile).exists();
assertThat(new EvergreenUpdateLevelPageDecorator(manifestFile).getUpdateLevel()).isEqualTo("2");
}
}

0 comments on commit cbb94c1

Please sign in to comment.