11package com .browserstack .automate .ci .jenkins ;
22
33import com .browserstack .automate .ci .common .constants .Constants ;
4+ import hudson .model .Action ;
45import hudson .model .Run ;
56import org .json .JSONObject ;
67import okhttp3 .*;
1213import static com .browserstack .automate .ci .common .logger .PluginLogger .log ;
1314import 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
0 commit comments