Skip to content

Commit 943c3ab

Browse files
committed
intg 1575 refactoring under integration service package
1 parent 6b0360c commit 943c3ab

File tree

5 files changed

+48
-59
lines changed

5 files changed

+48
-59
lines changed

src/main/java/com/browserstack/automate/ci/jenkins/AbstractBrowserStackTestReportForBuild.java

Lines changed: 0 additions & 29 deletions
This file was deleted.

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

Lines changed: 32 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
package com.browserstack.automate.ci.jenkins;
22

33
import com.browserstack.automate.ci.common.constants.Constants;
4+
import hudson.model.Action;
45
import hudson.model.Run;
56
import org.json.JSONObject;
67
import okhttp3.*;
@@ -12,9 +13,10 @@
1213
import static com.browserstack.automate.ci.common.logger.PluginLogger.log;
1314
import static com.browserstack.automate.ci.common.logger.PluginLogger.logError;
1415

15-
public class BrowserStackTestReportForBuild extends AbstractBrowserStackTestReportForBuild {
16+
public class BrowserStackTestReportAction implements Action {
1617

17-
private BrowserStackCredentials credentials;
18+
private Run<?, ?> run;
19+
private BrowserStackCredentials credentials;
1820
private String reportUrl;
1921
private final String UUID;
2022
private String reportHtml;
@@ -25,9 +27,9 @@ public class BrowserStackTestReportForBuild extends AbstractBrowserStackTestRepo
2527
private static final String REPORT_IN_PROGRESS = "REPORT_IN_PROGRESS";
2628
private static final String REPORT_FAILED = "REPORT_FAILED";
2729
private static final OkHttpClient client = new OkHttpClient();
28-
makeRequestsUtil requestsUtil;
30+
RequestsUtil requestsUtil;
2931

30-
public BrowserStackTestReportForBuild(Run<?, ?> run, BrowserStackCredentials credentials, String reportUrl, String UUID, String reportName, String tabUrl, final PrintStream logger) {
32+
public BrowserStackTestReportAction(Run<?, ?> run, BrowserStackCredentials credentials, String reportUrl, String UUID, String reportName, String tabUrl, final PrintStream logger) {
3133
super();
3234
setBuild(run);
3335
this.credentials = credentials;
@@ -38,45 +40,47 @@ public BrowserStackTestReportForBuild(Run<?, ?> run, BrowserStackCredentials cre
3840
this.logger = logger;
3941
this.reportName = reportName;
4042
this.urlName = tabUrl;
41-
requestsUtil = new makeRequestsUtil();
43+
requestsUtil = new RequestsUtil();
4244
}
4345

4446

4547
public String getReportHtml() {
4648
fetchReportConditions();
4749
return reportHtml;
4850
}
51+
4952
public String getReportStyle() {
5053
fetchReportConditions();
5154
return reportStyle;
5255
}
5356

5457
private void fetchReportConditions() {
55-
if ( reportHtml == null || reportHtml.equals(REPORT_IN_PROGRESS)) {
58+
if (reportHtml == null || reportHtml.equals(REPORT_IN_PROGRESS)) {
5659
fetchReport();
5760
}
5861
}
62+
5963
private void fetchReport() {
60-
if( UUID == null ) {
64+
if (UUID == null) {
6165
reportHtml = REPORT_FAILED;
6266
return;
6367
}
6468
Map<String, String> params = new HashMap<>();
6569
params.put("UUID", UUID);
66-
params.put("report_name",reportName);
70+
params.put("report_name", reportName);
6771
params.put("tool", Constants.INTEGRATIONS_TOOL_KEY);
6872

6973
try {
7074
String CIReportUrlWithParams = requestsUtil.buildQueryParams(reportUrl, params);
71-
log(logger, "Fetching browserstack report " + reportName );
75+
log(logger, "Fetching browserstack report " + reportName);
7276
Response response = requestsUtil.makeRequest(CIReportUrlWithParams, credentials);
7377
if (response.isSuccessful()) {
7478
JSONObject reportResponse = new JSONObject(response.body().string());
7579
String reportStatus = reportResponse.optString("report_status");
76-
if(reportStatus.equalsIgnoreCase(Constants.REPORT_COMPLETED_STATUS)) {
80+
if (reportStatus.equalsIgnoreCase(String.valueOf(Constants.REPORT_STATUS.COMPLETED))) {
7781
reportHtml = reportResponse.optString("report_html", null);
7882
reportStyle = reportResponse.optString("report_style", "");
79-
} else if(reportStatus.equalsIgnoreCase(Constants.REPORT_IN_PROGRESS_STATUS)){
83+
} else if (reportStatus.equalsIgnoreCase(String.valueOf(Constants.REPORT_STATUS.IN_PROGRESS))) {
8084
reportHtml = REPORT_IN_PROGRESS;
8185
} else {
8286
reportHtml = REPORT_FAILED;
@@ -93,24 +97,37 @@ public boolean isReportInProgress() {
9397
return reportHtml.equals(REPORT_IN_PROGRESS);
9498
}
9599

96-
public boolean isReportFailed() {
100+
public boolean isReportFailed() {
97101
return reportHtml.equals(REPORT_FAILED);
98102
}
99103

100104
public boolean isReportAvailable() {
101-
if(reportHtml!=null && !reportHtml.equals(REPORT_IN_PROGRESS) && !reportHtml.equals(REPORT_FAILED)){
105+
if (reportHtml != null && !reportHtml.equals(REPORT_IN_PROGRESS) && !reportHtml.equals(REPORT_FAILED)) {
102106
return true;
103107
}
104108
return false;
105109
}
106110

111+
public Run<?, ?> getBuild() {
112+
return run;
113+
}
114+
115+
public void setBuild(Run<?, ?> build) {
116+
this.run = build;
117+
}
118+
119+
@Override
120+
public String getIconFileName() {
121+
return Constants.BROWSERSTACK_LOGO;
122+
}
123+
107124
@Override
108-
public String getDisplayName() {
125+
public String getDisplayName() {
109126
return this.reportName;
110127
}
111128

112129
@Override
113-
public String getUrlName(){
130+
public String getUrlName() {
114131
return this.urlName;
115132
}
116133

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

Lines changed: 15 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -42,11 +42,12 @@ public class BrowserStackTestReportPublisher extends Recorder implements SimpleB
4242
private static final int RETRY_DELAY_SECONDS = 10;
4343
private final Map<String, String> customEnvVars;
4444

45-
makeRequestsUtil requestsUtil;
45+
RequestsUtil requestsUtil;
46+
4647
@DataBoundConstructor
4748
public BrowserStackTestReportPublisher(Map<String, String> customEnvVars) {
4849
this.customEnvVars = customEnvVars != null ? new HashMap<>(customEnvVars) : new HashMap<>();
49-
requestsUtil = new makeRequestsUtil();
50+
requestsUtil = new RequestsUtil();
5051
}
5152

5253
@Override
@@ -99,20 +100,20 @@ public void perform(Run<?, ?> build, @NonNull FilePath workspace, @NonNull Launc
99100
String reportUrl = config.getString("report_fetch_url");
100101
String reportName = config.getString("report_name");
101102
String reportTabUrl = config.getString("report_tab_url");
102-
log(logger, reportUrl+" "+ UUID );
103-
build.addAction(new BrowserStackTestReportForBuild(build, credentials, reportUrl, UUID, reportName, reportTabUrl, logger));
103+
log(logger, reportUrl + " " + UUID);
104+
build.addAction(new BrowserStackTestReportAction(build, credentials, reportUrl, UUID, reportName, reportTabUrl, logger));
104105
}
105106

106107
}
107108

108-
private String fetchUUID(PrintStream logger, String lookUpURL, BrowserStackCredentials credentials , String buildName, String projectName, String encodedTimestamp) throws InterruptedException {
109+
private String fetchUUID(PrintStream logger, String lookUpURL, BrowserStackCredentials credentials, String buildName, String projectName, String encodedTimestamp) throws InterruptedException {
109110

110111
Map<String, String> params = new HashMap<>();
111-
params.put("build_name",buildName);
112+
params.put("build_name", buildName);
112113
params.put("pipeline_timestamp", encodedTimestamp);
113114
params.put("tool", Constants.INTEGRATIONS_TOOL_KEY);
114-
if(projectName != null) {
115-
params.put("project_name",projectName);
115+
if (projectName != null) {
116+
params.put("project_name", projectName);
116117
}
117118

118119
log(logger, "Fetching build....");
@@ -135,8 +136,8 @@ private String fetchUUID(PrintStream logger, String lookUpURL, BrowserStackCrede
135136
JSONObject lookUpResponse = new JSONObject(response.body().string());
136137
String UUID = lookUpResponse.optString("UUID", null);
137138

138-
if(UUID !=null) {
139-
log(logger, "build found with "+ buildName + " and project name " + projectName);
139+
if (UUID != null) {
140+
log(logger, "build found with " + buildName + " and project name " + projectName);
140141
return UUID;
141142
}
142143

@@ -148,16 +149,16 @@ private String fetchUUID(PrintStream logger, String lookUpURL, BrowserStackCrede
148149
TimeUnit.SECONDS.sleep(RETRY_DELAY_SECONDS);
149150
}
150151

151-
LOGGER.info("build not found even after "+ MAX_ATTEMPTS + "attempts");
152+
LOGGER.info("build not found even after " + MAX_ATTEMPTS + "attempts");
152153
return null;
153154
}
154155

155156
private JSONObject fetchConfigDetails(PrintStream logger, String configDetailsURL, BrowserStackCredentials credentials) {
156157
log(logger, "Fetching config details for reports");
157158
Map<String, String> params = new HashMap<>();
158-
params.put("tool",Constants.INTEGRATIONS_TOOL_KEY);
159-
params.put("operation",Constants.REPORT_CONFIG_OPERATION_NAME);
160-
try {
159+
params.put("tool", Constants.INTEGRATIONS_TOOL_KEY);
160+
params.put("operation", Constants.REPORT_CONFIG_OPERATION_NAME);
161+
try {
161162
String configDetailsURLWithParams = requestsUtil.buildQueryParams(configDetailsURL, params);
162163
Response response = requestsUtil.makeRequest(configDetailsURLWithParams, credentials);
163164
if (response.isSuccessful()) {

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@
1010
import java.net.URISyntaxException;
1111
import java.util.Map;
1212

13-
public class makeRequestsUtil {
13+
public class RequestsUtil {
1414
OkHttpClient client = new OkHttpClient();
1515

1616
public Response makeRequest(String getUrl, BrowserStackCredentials browserStackCredentials) throws Exception {

0 commit comments

Comments
 (0)