Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Quality Dashboard Integrated #76

Merged
merged 6 commits into from
Jan 18, 2024
Merged
Show file tree
Hide file tree
Changes from 5 commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 14 additions & 6 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
</parent>

<artifactId>browserstack-integration</artifactId>
<version>1.2.12-SNAPSHOT</version>
<version>1.2.13-SNAPSHOT</version>
<packaging>hpi</packaging>

<name>BrowserStack</name>
Expand All @@ -37,8 +37,8 @@
<tag>HEAD</tag>
</scm>

<!-- Adding a distribution management section here to override the now
defunct mave.jenkins-ci.org. If we update the parent pom version to newer
<!-- Adding a distribution management section here to override the now
defunct mave.jenkins-ci.org. If we update the parent pom version to newer
than 2.5 then this section is not needed. -->
<distributionManagement>
<repository>
Expand All @@ -53,7 +53,7 @@


<properties>
<!-- Baseline Jenkins version you use to build the plugin. Users must
<!-- Baseline Jenkins version you use to build the plugin. Users must
have this version or newer to run. -->
<jenkins.version>2.334</jenkins.version>
<java.level>8</java.level>
Expand All @@ -62,8 +62,8 @@
<junit-quickcheck.version>0.8</junit-quickcheck.version>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>

<!-- This is the testing Tracking Id. If you want to build the project
for production, please use the production profile which replaces this with
<!-- This is the testing Tracking Id. If you want to build the project
for production, please use the production profile which replaces this with
the production tracking id. -->
<ga.tracking.id>UA-79358556-2</ga.tracking.id>
</properties>
Expand Down Expand Up @@ -177,6 +177,13 @@
<version>1.24</version>
</dependency>

<dependency>
<groupId>org.zeroturnaround</groupId>
<artifactId>zt-zip</artifactId>
<version>1.16</version>
<type>jar</type>
</dependency>

<!-- https://mvnrepository.com/artifact/com.google.code.gson/gson -->
<dependency>
<groupId>com.google.code.gson</groupId>
Expand Down Expand Up @@ -286,6 +293,7 @@
<artifactId>spring-beans</artifactId>
<version>5.3.18</version>
</dependency>

</dependencies>

<dependencyManagement>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -61,4 +61,28 @@ public static final class SessionStatus {
public static final String UNMARKED = "unmarked";
public static final String PASSED = "passed";
}

public static final class QualityDashboardAPI {
public static final String URL_BASE = "https://quality-dashboard.browserstack.com/api/v1/jenkins";

public static final String LOG_MESSAGE = URL_BASE + "/log-message";
public static final String IS_INIT_SETUP_REQUIRED = URL_BASE + "/init-setup-required";

public static final String HISTORY_FOR_DAYS = URL_BASE + "/history-for-days";

public static final String SAVE_PIPELINES = URL_BASE + "/save-pipelines";

public static final String SAVE_PIPELINE_RESULTS = URL_BASE + "/save-pipeline-results";

public static final String ITEM_CRUD = URL_BASE + "/item";
public static final String IS_QD_ENABLED = URL_BASE + "/qd-enabled";
public static final String IS_PIPELINE_ENABLED = URL_BASE + "/pipeline-enabled";
public static final String GET_RESULT_DIRECTORY = URL_BASE + "/get-result-directory";

public static final String UPLOAD_RESULT_ZIP = URL_BASE + "/upload-result";
public static final String STORE_PIPELINE_RESULTS = URL_BASE + "/save-results";

public static final String PROJECTS_PAGE_SIZE = URL_BASE + "/projects-page-size";
public static final String RESULTS_PAGE_SIZE = URL_BASE + "/results-page-size";
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
import com.browserstack.automate.ci.common.BrowserStackBuildWrapperOperations;
import com.browserstack.automate.ci.common.analytics.Analytics;
import com.browserstack.automate.ci.jenkins.local.LocalConfig;
import com.browserstack.automate.ci.jenkins.qualityDashboard.QualityDashboardInit;
import hudson.Extension;
import hudson.model.AbstractProject;
import hudson.model.Item;
Expand Down Expand Up @@ -51,8 +52,11 @@ public boolean configure(StaplerRequest req, JSONObject formData) throws FormExc
if (config.has("usageStatsEnabled")) {
setEnableUsageStats(config.getBoolean("usageStatsEnabled"));
}
if (config.has("credentialsId")){
QualityDashboardInit qdInit = new QualityDashboardInit();
qdInit.pluginConfiguredNotif();
}
}

return true;
}

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,92 @@
package com.browserstack.automate.ci.jenkins.qualityDashboard;

import com.browserstack.automate.ci.common.constants.Constants;
import com.browserstack.automate.ci.jenkins.BrowserStackCredentials;
import com.fasterxml.jackson.annotation.JsonProperty;
import com.fasterxml.jackson.core.JsonProcessingException;
import com.fasterxml.jackson.databind.ObjectMapper;
import okhttp3.*;
import java.io.IOException;
import java.io.Serializable;

public class QualityDashboardAPIUtil {

OkHttpClient client = new OkHttpClient();

public Response makeGetRequestToQd(String getUrl, BrowserStackCredentials browserStackCredentials) {
try {
Request request = new Request.Builder()
.url(getUrl)
.header("Authorization", Credentials.basic(browserStackCredentials.getUsername(), browserStackCredentials.getDecryptedAccesskey()))
.build();
Response response = client.newCall(request).execute();
return response;
} catch(IOException e) {
e.printStackTrace();
}
return null;
}

public Response makePostRequestToQd(String postUrl, BrowserStackCredentials browserStackCredentials, RequestBody requestBody) {
try {
Request request = new Request.Builder()
.url(postUrl)
.header("Authorization", Credentials.basic(browserStackCredentials.getUsername(), browserStackCredentials.getDecryptedAccesskey()))
.post(requestBody)
.build();
Response response = client.newCall(request).execute();
return response;
} catch(IOException e) {
e.printStackTrace();
}
return null;
}

public Response makePutRequestToQd(String postUrl, BrowserStackCredentials browserStackCredentials, RequestBody requestBody) {
try {
Request request = new Request.Builder()
.url(postUrl)
.header("Authorization", Credentials.basic(browserStackCredentials.getUsername(), browserStackCredentials.getDecryptedAccesskey()))
.put(requestBody)
.build();
Response response = client.newCall(request).execute();
return response;
} catch(IOException e) {
e.printStackTrace();
}
return null;
}

public Response makeDeleteRequestToQd(String postUrl, BrowserStackCredentials browserStackCredentials, RequestBody requestBody) {
try {
Request request = new Request.Builder()
.url(postUrl)
.header("Authorization", Credentials.basic(browserStackCredentials.getUsername(), browserStackCredentials.getDecryptedAccesskey()))
.delete(requestBody)
.build();
Response response = client.newCall(request).execute();
return response;
} catch(IOException e) {
e.printStackTrace();
}
return null;
}

public void logToQD(BrowserStackCredentials browserStackCredentials, String logMessage) throws JsonProcessingException {
LogMessage logMessageObj = new LogMessage(logMessage);
ObjectMapper objectMapper = new ObjectMapper();
String jsonBody = objectMapper.writeValueAsString(logMessageObj);
RequestBody requestBody = RequestBody.create(MediaType.parse("application/json"), jsonBody);
makePostRequestToQd(Constants.QualityDashboardAPI.LOG_MESSAGE, browserStackCredentials, requestBody);
}
}

class LogMessage implements Serializable {

@JsonProperty("message")
private String message;

public LogMessage(String message) {
this.message = message;
}
}
Loading
Loading