Skip to content

Commit

Permalink
Merge pull request #16 from takipi/develop
Browse files Browse the repository at this point in the history
Develop into Master v1.2.0
  • Loading branch information
ccaspanello authored Jul 8, 2020
2 parents 8245518 + 23a1177 commit 8d8a6e1
Show file tree
Hide file tree
Showing 12 changed files with 78 additions and 18 deletions.
8 changes: 8 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,10 @@ From Bamboo Administration, select "Settings" under "OverOps". Enter the API URL

The complete URL of the OverOps API, including port. For example, https://api.overops.com for SaaS or http://host.domain.com:8080 for on prem.

### APP URL

The complete URL of the OverOps APP, including port. For example, https://app.overops.com for SaaS or http://host.domain.com:8080 for on prem.

### API Token

The OverOps REST API token to use for authentication. [This can be obtained from the OverOps dashboard under Settings → Account](https://doc.overops.com/docs/api-token).
Expand Down Expand Up @@ -68,6 +72,10 @@ Prints the top X events (as provided by this parameter) with the highest volume

If checked the build will be marked ***failed*** if any quality gate did not pass.

#### Create a Report Link

If checked a link will be generated and displayed. The Quality Report can then be viewed by clicking the generated link. Note: If checked the Mark Unstable option is ignored.

#### Show All Events

If checked the quality report will list events for both passed and failed quality gates, otherwise only events for failed gates will be displayed.
Expand Down
11 changes: 9 additions & 2 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
<modelVersion>4.0.0</modelVersion>
<groupId>com.overops.plugins</groupId>
<artifactId>overops-bamboo-app</artifactId>
<version>1.1.0</version>
<version>1.2.0</version>

<organization>
<name>OverOps</name>
Expand Down Expand Up @@ -36,7 +36,7 @@
<maven.compiler.source>1.8</maven.compiler.source>
<maven.compiler.target>1.8</maven.compiler.target>
<!-- api-client local dev build with https://github.com/takipi/api-client/pull/147 -->
<takipi.version>2.33.0</takipi.version>
<takipi.version>2.34.1</takipi.version>
</properties>

<dependencies>
Expand Down Expand Up @@ -104,6 +104,12 @@
<groupId>com.takipi</groupId>
<artifactId>report-service</artifactId>
<version>${takipi.version}</version>
<exclusions>
<exclusion>
<groupId>org.slf4j</groupId>
<artifactId>slf4j-api</artifactId>
</exclusion>
</exclusions>
</dependency>


Expand Down Expand Up @@ -152,6 +158,7 @@
<!-- Add package to export here -->
<Export-Package>
com.overops.plugins,
org.apache.avalon.framework.logger
</Export-Package>

<!-- Add package import here -->
Expand Down
Binary file modified readme/config.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified readme/step.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
48 changes: 32 additions & 16 deletions src/main/java/com/overops/plugins/bamboo/TaskType.java
Original file line number Diff line number Diff line change
Expand Up @@ -3,15 +3,14 @@
import java.io.PrintWriter;
import java.io.PrintStream;
import java.io.StringWriter;
import java.util.HashMap;
import java.util.Map;
import java.util.Properties;


import com.overops.report.service.model.HtmlParts;
import org.apache.commons.lang3.StringUtils;
import org.apache.commons.lang3.math.NumberUtils;
import com.atlassian.bamboo.build.logger.BuildLogger;
import com.atlassian.bamboo.configuration.ConfigurationMap;
import com.atlassian.bamboo.process.ProcessService;
import com.atlassian.bamboo.task.TaskContext;
import com.atlassian.bamboo.task.TaskException;
import com.atlassian.bamboo.task.TaskResult;
Expand All @@ -24,7 +23,6 @@

import com.fasterxml.jackson.databind.ObjectMapper;

import com.overops.plugins.bamboo.configuration.Const;
import com.overops.plugins.bamboo.service.impl.BambooPrintWriter;
import com.overops.report.service.QualityReportParams;
import com.overops.report.service.ReportService;
Expand Down Expand Up @@ -73,24 +71,40 @@ public TaskResult execute(@NotNull TaskContext context) throws TaskException {
try {
logger.addBuildLogEntry("[" + Utils.getArtifactId() + " v" + Utils.getVersion() + "]");

boolean showAllEvents = Boolean.parseBoolean(context.getConfigurationMap().get(Const.SHOW_ALL_EVENTS));
boolean isDebug = Boolean.parseBoolean(context.getConfigurationMap().get(Const.DEBUG));
PrintStream printStream = isDebug ? new BambooPrintWriter(System.out, logger) : null;

QualityReport reportModel = overOpsService.runQualityReport(endPoint, apiKey, query, Requestor.BAMBOO, printStream, isDebug);
String appUrl = (String)globalSettings.get(Const.GLOBAL_APP_URL);

context.getBuildContext().getBuildResult().getCustomBuildData().put("overOpsReport", objectMapper.writeValueAsString(reportModel.getHtmlParts(showAllEvents)));
context.getBuildContext().getBuildResult().getCustomBuildData().put("isOverOpsStep", "true");
PrintStream printStream = isDebug ? new BambooPrintWriter(System.out, logger) : null;

if (reportModel.getStatusCode() == ReportStatus.FAILED) {
if ((reportModel.getExceptionDetails() != null) && Boolean.parseBoolean(context.getConfigurationMap().get(Const.PASS_BUILD_ON_QR_EXCEPTION))) {
Boolean displayLink = Boolean.parseBoolean(context.getConfigurationMap().get(Const.LINK));
if (displayLink)
{
HtmlParts htmlParts = new HtmlParts(overOpsService.generateReportLinkHtml(appUrl, query, printStream, isDebug), "");
context.getBuildContext().getBuildResult().getCustomBuildData().put("overOpsReport", objectMapper.writeValueAsString(htmlParts));
context.getBuildContext().getBuildResult().getCustomBuildData().put("isOverOpsStep", "true");
return resultBuilder.success().build();
} else
{
boolean showAllEvents = Boolean.parseBoolean(context.getConfigurationMap().get(Const.SHOW_ALL_EVENTS));
ReportService.pauseForTheCause();
QualityReport reportModel = overOpsService.runQualityReport(endPoint, apiKey, query, Requestor.BAMBOO, printStream, isDebug);

context.getBuildContext().getBuildResult().getCustomBuildData().put("overOpsReport", objectMapper.writeValueAsString(reportModel.getHtmlParts(showAllEvents)));
context.getBuildContext().getBuildResult().getCustomBuildData().put("isOverOpsStep", "true");

if (reportModel.getStatusCode() == ReportStatus.FAILED)
{
if ((reportModel.getExceptionDetails() != null) && Boolean.parseBoolean(context.getConfigurationMap().get(Const.PASS_BUILD_ON_QR_EXCEPTION)))
{
return resultBuilder.success().build();
}
return resultBuilder.failed().build();
}
else
{
return resultBuilder.success().build();
}
return resultBuilder.failed().build();
} else {
return resultBuilder.success().build();
}

} catch (Exception e) {
StringWriter sw = new StringWriter();
PrintWriter pw = new PrintWriter(sw);
Expand All @@ -107,13 +121,15 @@ public TaskResult execute(@NotNull TaskContext context) throws TaskException {
private QualityReportParams getQualityReportParams(ConfigurationMap params) {
QualityReportParams qrp = new QualityReportParams();


qrp.setServiceId((String)params.get(Const.ENV_ID));
qrp.setApplicationName(params.get(Const.APP_NAME));
qrp.setDeploymentName(params.get(Const.DEP_NAME));

qrp.setRegexFilter(params.get(Const.REGEX_FILTER));
qrp.setMarkUnstable(Boolean.parseBoolean(params.get(Const.MARK_UNSTABLE)));
qrp.setPrintTopIssues(NumberUtils.toInt(params.get(Const.TOP_ERROR_COUNT), 0));
qrp.setShowEventsForPassedGates(Boolean.parseBoolean(params.get(Const.SHOW_ALL_EVENTS)));

qrp.setNewEvents(Boolean.parseBoolean(params.get(Const.CHECK_NEW_ERRORS)));
qrp.setResurfacedErrors(Boolean.parseBoolean(params.get(Const.CHECK_RESURFACED_ERRORS)));
Expand Down
2 changes: 2 additions & 0 deletions src/main/java/com/overops/plugins/bamboo/Utils.java
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
package com.overops.plugins.bamboo;

import org.springframework.core.io.support.PropertiesLoaderUtils;

import java.io.*;
import java.util.*;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ public class Const {
// PluginSettingsFactory global settings
public static final String GLOBAL_ENV_ID = "com.overops.plugins.bamboo:global-api-env-id";
public static final String GLOBAL_API_URL = "com.overops.plugins.bamboo:global-api-url";
public static final String GLOBAL_APP_URL = "com.overops.plugins.bamboo:global-app-url";
public static final String GLOBAL_API_TOKEN = "com.overops.plugins.bamboo:global-api-token";


Expand All @@ -21,6 +22,7 @@ public class Const {
public static final String REGEX_FILTER = "regexFilter";
public static final String TOP_ERROR_COUNT = "topErrorCount";
public static final String MARK_UNSTABLE = "markUnstable";
public static final String LINK = "link";
public static final String SHOW_ALL_EVENTS = "showAllEvents";
public static final String PASS_BUILD_ON_QR_EXCEPTION = "passOnQRException";

Expand All @@ -41,7 +43,9 @@ public class Const {

// default values
public static final String DEFAULT_API_URL = "https://api.overops.com/";
public static final String DEFAULT_APP_URL = "https://app.overops.com/";

public static final String DEFAULT_TOP_ERROR_COUNT = "10";
public static final String DEFAULT_MARK_UNSTABLE = "true";
public static final String DEFAULT_LINK = "false";
}
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ public void populateContextForCreate(Map<String, Object> context) {
// set minimal defaults
context.put(Const.TOP_ERROR_COUNT, Const.DEFAULT_TOP_ERROR_COUNT);
context.put(Const.MARK_UNSTABLE, Const.DEFAULT_MARK_UNSTABLE);
context.put(Const.LINK, Const.DEFAULT_LINK);
}

/**
Expand All @@ -44,6 +45,7 @@ public void populateContextForEdit(Map<String, Object> context, TaskDefinition t
context.put(Const.REGEX_FILTER, config.get(Const.REGEX_FILTER));
context.put(Const.TOP_ERROR_COUNT, config.get(Const.TOP_ERROR_COUNT));
context.put(Const.MARK_UNSTABLE, config.get(Const.MARK_UNSTABLE));
context.put(Const.LINK, config.get(Const.LINK));
context.put(Const.SHOW_ALL_EVENTS, config.get(Const.SHOW_ALL_EVENTS));
context.put(Const.PASS_BUILD_ON_QR_EXCEPTION, config.get(Const.PASS_BUILD_ON_QR_EXCEPTION));

Expand Down Expand Up @@ -82,6 +84,7 @@ public Map<String, String> generateTaskConfigMap(ActionParametersMap params, Tas
config.put(Const.REGEX_FILTER, params.getString(Const.REGEX_FILTER));
config.put(Const.TOP_ERROR_COUNT, params.getString(Const.TOP_ERROR_COUNT));
config.put(Const.MARK_UNSTABLE, params.getString(Const.MARK_UNSTABLE));
config.put(Const.LINK, params.getString(Const.LINK));
config.put(Const.SHOW_ALL_EVENTS, params.getString(Const.SHOW_ALL_EVENTS));
config.put(Const.PASS_BUILD_ON_QR_EXCEPTION, params.getString(Const.PASS_BUILD_ON_QR_EXCEPTION));

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@ private enum VM {
template("default-settings.vm"),
envId("envId"),
apiUrl("apiUrl"),
appUrl("appUrl"),
apiToken("apiToken"),
save("save"),
testConnection("testConnection"),
Expand Down Expand Up @@ -77,6 +78,10 @@ protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws Se
String globalApiUrl = (String) pluginSettings.get(Const.GLOBAL_API_URL);
String url = StringUtils.isBlank(globalApiUrl) ? Const.DEFAULT_API_URL : globalApiUrl;

// APP URL: if blank, set default value
String globalAppUrl = (String) pluginSettings.get(Const.GLOBAL_APP_URL);
String appUrl = StringUtils.isBlank(globalAppUrl) ? Const.DEFAULT_APP_URL : globalAppUrl;

// ENV, TOKEN: blank is default value (replace null, whitespace with blank)
String globalEnvId = (String) pluginSettings.get(Const.GLOBAL_ENV_ID);
String env = StringUtils.isBlank(globalEnvId) ? "" : globalEnvId;
Expand All @@ -86,6 +91,7 @@ protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws Se

// set velocity context
context.put(VM.apiUrl.get(), url);
context.put(VM.appUrl.get(), appUrl);
context.put(VM.envId.get(), env);
context.put(VM.apiToken.get(), token);

Expand All @@ -103,6 +109,7 @@ protected void doPost(final HttpServletRequest req, HttpServletResponse resp) th
// populate values from form
String env = req.getParameter(VM.envId.get()).trim().toUpperCase();
String url = req.getParameter(VM.apiUrl.get()).trim();
String appUrl = req.getParameter(VM.appUrl.get()).trim();
String token = req.getParameter(VM.apiToken.get()).trim();

// check if 'save' or 'test connection' was submitted
Expand All @@ -115,6 +122,7 @@ protected void doPost(final HttpServletRequest req, HttpServletResponse resp) th
PluginSettings pluginSettings = pluginSettingsFactory.createGlobalSettings();
pluginSettings.put(Const.GLOBAL_ENV_ID, env);
pluginSettings.put(Const.GLOBAL_API_URL, url);
pluginSettings.put(Const.GLOBAL_APP_URL, appUrl);
pluginSettings.put(Const.GLOBAL_API_TOKEN, token);

context.put(VM.isSuccess.get(), "true");
Expand Down Expand Up @@ -161,6 +169,7 @@ protected void doPost(final HttpServletRequest req, HttpServletResponse resp) th

// set velocity context
context.put(VM.apiUrl.get(), url);
context.put(VM.appUrl.get(), appUrl);
context.put(VM.envId.get(), env);
context.put(VM.apiToken.get(), token);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,10 +10,13 @@ com.overops.plugins.bamboo.task.help.link=https://github.com/takipi/bamboo-overo
com.overops.plugins.bamboo.task.help.title=OverOps Quality Report Documentation &rarr;

com.overops.plugins.bamboo.task.config.applicationName=Application Name
com.overops.plugins.bamboo.task.config.apiUrl=API URL
com.overops.plugins.bamboo.task.config.appUrl=App URL
com.overops.plugins.bamboo.task.config.deploymentName=Deployment Name
com.overops.plugins.bamboo.task.config.envId=Environment ID
com.overops.plugins.bamboo.task.config.regexFilter=Regex Filter
com.overops.plugins.bamboo.task.config.markUnstable=Mark Build Unstable
com.overops.plugins.bamboo.task.config.link=Create a Report Link
com.overops.plugins.bamboo.task.config.showAllEvents=Show All Events
com.overops.plugins.bamboo.task.config.passOnQRException=Do not fail the build if OverOps reliability report fails to run.
com.overops.plugins.bamboo.task.config.topErrorCount=Number of total and unique errors to show
Expand Down
7 changes: 7 additions & 0 deletions src/main/resources/default-settings.vm
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,13 @@
The complete url including protocol and port of the OverOps API (e.g. https://api.overops.com or http://host.domain.com:8080)
</div>
</div>
<div class="field-group">
<label for="name">APP URL</label>
<input type="text" id="appUrl" name="appUrl" class="text" value="${appUrl}">
<div class="description">
The complete url including protocol and port of the OverOps APP (e.g. https://app.overops.com or http://host.domain.com:8080)
</div>
</div>
<div class="field-group">
<label for="name">API Token</label>
<input type="password" id="apiToken" name="apiToken" class="text" value="${apiToken}">
Expand Down
1 change: 1 addition & 0 deletions src/main/resources/templates/editTaskConfig.ftl
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,7 @@
[@ww.textfield labelKey="com.overops.plugins.bamboo.task.config.topErrorCount" name="topErrorCount" required="false" description="The number of total and unique errors to show in the quality report, sorted by volume." /]
<hr class="divider"/>
[@ww.checkbox labelKey="com.overops.plugins.bamboo.task.config.markUnstable" name="markUnstable" required="false" description="If checked the build will be marked unstable when any quality gates fail."/]
[@ww.checkbox labelKey="com.overops.plugins.bamboo.task.config.link" name="link" required="false" description="If checked a link will be generated and displayed. The Quality Report can then be viewed by clicking the generated link. Note: If checked the Mark Unstable option is ignored."/]
<hr class="divider"/>
[@ww.checkbox labelKey="com.overops.plugins.bamboo.task.config.showAllEvents" name="showAllEvents" required="false" description="If checked the quality report will list events for both passed and failed quality gates, otherwise only events for failed gates will be displayed."/]

Expand Down

0 comments on commit 8d8a6e1

Please sign in to comment.