Skip to content

Commit 273ef30

Browse files
committed
dev test fixes
1 parent f62cea1 commit 273ef30

File tree

5 files changed

+35
-22
lines changed

5 files changed

+35
-22
lines changed

src/main/java/com/browserstack/automate/ci/common/constants/Constants.java

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,13 +15,16 @@ public class Constants {
1515
public static final String BROWSERSTACK_REPORT_PATH_PATTERN = "**/browserstack-artifacts/*";
1616
public static final String JENKINS_CI_PLUGIN = "JenkinsCiPlugin";
1717

18-
public static final String CAD_BASE_URL = "https://api-observability.browserstack.com//api";
18+
public static final String CAD_BASE_URL = "http://localhost:3002/api";
1919
public static final String BROWSERSTACK_CONFIG_DETAILS_ENDPOINT = "/v1/builds/buildReport";
2020

2121
public static final String BROWSERSTACK_TEST_REPORT_DISPLAY_NAME = "BrowserStack Build Test Reports";
2222
public static final String INTEGRATIONS_TOOL_KEY = "jenkins";
2323
public static final String REPORT_FORMAT = "richHtml";
2424

25+
public static final String BROWSERSTACK_TEST_REPORT_URL = "testReportBrowserStack";
26+
public static final String BROWSERSTACK_CAD_REPORT_DISPLAY_NAME = "BrowserStack Test Reports";
27+
2528
// Product
2629
public static final String AUTOMATE = "automate";
2730
public static final String APP_AUTOMATE = "app-automate";

src/main/java/com/browserstack/automate/ci/jenkins/integrationService/BrowserStackTestReportAction.java

Lines changed: 18 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -2,12 +2,12 @@
22

33
import com.browserstack.automate.ci.common.constants.Constants;
44
import com.browserstack.automate.ci.jenkins.BrowserStackCredentials;
5+
import com.google.gson.Gson;
56
import hudson.model.Action;
67
import hudson.model.Run;
78
import org.json.JSONObject;
89
import okhttp3.*;
910

10-
import javax.xml.bind.annotation.XmlType;
1111
import java.io.PrintStream;
1212
import java.util.Arrays;
1313
import java.util.HashMap;
@@ -37,6 +37,8 @@ public class BrowserStackTestReportAction implements Action {
3737

3838
private static final String RETRY_REPORT = "RETRY_REPORT";
3939

40+
private static final String RATE_LIMIT = "RATE_LIMIT";
41+
4042
private static final int MAX_ATTEMPTS = 3;
4143
private RequestsUtil requestsUtil;
4244

@@ -66,7 +68,7 @@ public String getReportStyle() {
6668
}
6769

6870
private void fetchReportConditions() {
69-
if (reportHtml == null || reportHtml.equals(REPORT_IN_PROGRESS) || reportHtml.equals(RETRY_REPORT)) {
71+
if (reportHtml == null || reportHtml.equals(REPORT_IN_PROGRESS) || reportHtml.equals(RETRY_REPORT) || reportHtml.equals(RATE_LIMIT)) {
7072
fetchReport();
7173
}
7274
}
@@ -83,9 +85,11 @@ private void fetchReport() {
8385

8486
try {
8587
String reportUrl = Constants.CAD_BASE_URL + Constants.BROWSERSTACK_CONFIG_DETAILS_ENDPOINT;
86-
String ciReportUrlWithParams = requestsUtil.buildQueryParams(reportUrl, params);
88+
Gson gson = new Gson();
89+
String json = gson.toJson(params);
90+
RequestBody ciReportBody = RequestBody.create(MediaType.parse("application/json"), json);
8791
log(logger, "Fetching browserstack report " + reportName);
88-
Response response = requestsUtil.makeRequest(ciReportUrlWithParams, credentials);
92+
Response response = requestsUtil.makeRequest(reportUrl, credentials, ciReportBody);
8993
if (response.isSuccessful()) {
9094
assert response.body() != null;
9195
JSONObject reportResponse = new JSONObject(response.body().string());
@@ -96,8 +100,8 @@ private void fetchReport() {
96100

97101
String defaultHTML = "<h1>No Report Found</h1>";
98102
JSONObject report = reportResponse.optJSONObject("report");
99-
reportHtml = report != null ? report.optString("reportHtml", defaultHTML) : defaultHTML;
100-
reportStyle = report != null ? report.optString("reportCss", "") : "";
103+
reportHtml = report != null ? report.optString("richHtml", defaultHTML) : defaultHTML;
104+
reportStyle = report != null ? report.optString("richCss", "") : "";
101105

102106
} else if (reportStatus.equalsIgnoreCase(String.valueOf(BrowserStackReportStatus.IN_PROGRESS))) {
103107

@@ -106,6 +110,10 @@ private void fetchReport() {
106110
} else {
107111
reportHtml = REPORT_FAILED;
108112
}
113+
} else if (response.code() == 429) {
114+
reportHtml = RATE_LIMIT;
115+
} else {
116+
reportHtml = REPORT_FAILED;
109117
logError(logger, "Received Non success response while fetching report" + response.code());
110118
}
111119
} catch (Exception e) {
@@ -130,6 +138,8 @@ public boolean reportRetryRequired() {
130138
return reportHtml.equals(RETRY_REPORT);
131139
}
132140

141+
public boolean isUserRateLimited() { return reportHtml.equals(RATE_LIMIT); }
142+
133143
public boolean isReportAvailable() {
134144
if (reportHtml != null && !reportHtml.equals(REPORT_IN_PROGRESS) && !reportHtml.equals(REPORT_FAILED) && !reportHtml.equals(RETRY_REPORT)) {
135145
return true;
@@ -157,12 +167,12 @@ public String getIconFileName() {
157167

158168
@Override
159169
public String getDisplayName() {
160-
return this.reportName;
170+
return Constants.BROWSERSTACK_CAD_REPORT_DISPLAY_NAME;
161171
}
162172

163173
@Override
164174
public String getUrlName() {
165-
return this.urlName;
175+
return Constants.BROWSERSTACK_TEST_REPORT_URL;
166176
}
167177

168178
}

src/main/java/com/browserstack/automate/ci/jenkins/integrationService/BrowserStackTestReportPublisher.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -98,7 +98,7 @@ public boolean isApplicable(Class<? extends AbstractProject> aClass) {
9898

9999
@Override
100100
public String getDisplayName() {
101-
return Constants.BROWSERSTACK_TEST_REPORT_DISPLAY_NAME;
101+
return Constants.BROWSERSTACK_CAD_REPORT_DISPLAY_NAME;
102102
}
103103

104104
}

src/main/java/com/browserstack/automate/ci/jenkins/integrationService/RequestsUtil.java

Lines changed: 5 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,7 @@
11
package com.browserstack.automate.ci.jenkins.integrationService;
22

33
import com.browserstack.automate.ci.jenkins.BrowserStackCredentials;
4-
import okhttp3.Credentials;
5-
import okhttp3.OkHttpClient;
6-
import okhttp3.Request;
7-
import okhttp3.Response;
4+
import okhttp3.*;
85
import org.apache.http.client.utils.URIBuilder;
96

107
import java.io.IOException;
@@ -15,14 +12,14 @@ public class RequestsUtil {
1512
private transient OkHttpClient client;
1613

1714

18-
public Response makeRequest(String getUrl, BrowserStackCredentials browserStackCredentials) throws Exception {
15+
public Response makeRequest(String url, BrowserStackCredentials browserStackCredentials, RequestBody body) throws Exception {
1916
try {
2017
Request request = new Request.Builder()
21-
.url(getUrl)
18+
.url(url)
2219
.header("Authorization", Credentials.basic(browserStackCredentials.getUsername(), browserStackCredentials.getDecryptedAccesskey()))
20+
.post(body)
2321
.build();
24-
Response response = getClient().newCall(request).execute();
25-
return response;
22+
return getClient().newCall(request).execute();
2623
} catch (IOException e) {
2724
e.printStackTrace();
2825
throw e;

src/main/resources/com/browserstack/automate/ci/jenkins/integrationService/BrowserStackTestReportAction/index.jelly

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -75,20 +75,23 @@
7575
<div class="new-container">
7676
<div class="report-row">
7777
<j:if test="${(it.isReportInProgress())}">
78-
<p class="no-report-para"><strong class="strong-font-custom">BrowserStack ${it.reportName} Report In Progress, please refresh after sometime</strong></p>
78+
<p class="no-report-para"><strong class="strong-font-custom">BrowserStack Test Report generation In Progress, please refresh after sometime</strong></p>
7979
</j:if>
8080
<j:if test="${(it.isReportFailed())}">
81-
<p class="no-report-para"><strong class="strong-font-custom">No BrowserStack ${it.reportName} Report Available</strong></p>
81+
<p class="no-report-para"><strong class="strong-font-custom">BrowserStack Test Report Could Not Be Fetched</strong></p>
8282
<br/>
83-
<p class="no-report-para">BrowserStack test report could not be generated for this build. Please ensure that:</p>
83+
<p class="no-report-para">BrowserStack test report could not be fetched for this build since something went wrong. Please ensure that:</p>
8484
<br/>
8585
<ul class="bullet-points">
8686
<li class="bullet-item">You have set valid BrowserStack credentials via BrowserStack Plugin.</li>
8787
<li class="bullet-item">You have used BROWSERSTACK_BUILD_NAME as your build name</li>
8888
</ul>
8989
</j:if>
9090
<j:if test="${it.reportRetryRequired()}">
91-
<p class="no-report-para"><strong class="strong-font-custom">Unable to Fetch Report try refreshing...</strong></p>
91+
<p class="no-report-para"><strong class="strong-font-custom">Unable to Fetch Report something went wrong try refreshing...</strong></p>
92+
</j:if>
93+
<j:if test="${it.isUserRateLimited()}">
94+
<p class="no-report-para"><strong class="strong-font-custom"> You have been rate limited, please retry after sometime</strong></p>
9295
</j:if>
9396
</div>
9497
</div>

0 commit comments

Comments
 (0)