This repository has been archived by the owner on Nov 17, 2022. It is now read-only.
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add footer with current Update Level
- Loading branch information
Showing
4 changed files
with
70 additions
and
0 deletions.
There are no files selected for viewing
48 changes: 48 additions & 0 deletions
48
src/main/java/io/jenkins/plugins/evergreen/EvergreenUpdateLevelPageDecorator.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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; | ||
} | ||
} |
4 changes: 4 additions & 0 deletions
4
...ain/resources/io/jenkins/plugins/evergreen/EvergreenUpdateLevelPageDecorator/footer.jelly
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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> |
17 changes: 17 additions & 0 deletions
17
src/test/java/io/jenkins/plugins/evergreen/EvergreenUpdateLevelPageDecoratorTest.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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"); | ||
} | ||
} |
Oops, something went wrong.