Uploaded image for project: 'Jenkins'
  1. Jenkins
  2. JENKINS-74647

[sofy-ai] Extract inline script block in sofy/jenkins/plugin/ViewMobileTestRunResults/index.jelly

XMLWordPrintable

    • Icon: Task Task
    • Resolution: Unresolved
    • Icon: Minor Minor
    • sofy-ai-plugin

      Problem

      == Inline Script Block
      Line: 9
      ----
      <script>
      
                      function getPercentage(num, total) {
                          return +(Math.round(num / total + "e+2") + "e-2") * 100 + "%";
                      }
      
                      let id = '${it.mobileTestRun.TestRunId}';
                      let token = '${it.apiToken}';
      
                      fetch("https://api.sofy.ai/v1/applications/testresults/summary?testrunid=" + id, {
                          headers: {
                              "SubscriptionKey": token
                          }
                      }).then(res => res.json())
                              .then(data => data[0] || data)
                              .then(summary => {
                                  if (summary) {
                                      document.getElementById('performance_td')
                                              .innerHTML = getPercentage(summary.Audit_Performance_Passed, summary.Audit_Performance_Total);
                                      document.getElementById('visualquality_td')
                                              .innerHTML = getPercentage(summary.Audit_VisualQuality_Passed, summary.Audit_VisualQuality_Total);
                                      document.getElementById('bestpractice_td')
                                              .innerHTML = getPercentage(summary.Audit_Bestpractices_Passed, summary.Audit_Bestpractices_Total);
                                      document.getElementById('security_td')
                                              .innerHTML = getPercentage(summary.Audit_Security_Passed, summary.Audit_Security_Total);
                                      document.getElementById('reliability_td')
                                              .innerHTML = getPercentage(summary.Audit_Reliability_Passed, summary.Audit_Reliability_Total);
                                  } else {
                                      document.getElementById('performance_td')
                                              .innerHTML = 'N/A';
                                      document.getElementById('visualquality_td')
                                              .innerHTML = 'N/A';
                                      document.getElementById('bestpractice_td')
                                              .innerHTML = 'N/A';
                                      document.getElementById('security_td')
                                              .innerHTML = 'N/A';
                                      document.getElementById('reliability_td')
                                              .innerHTML = 'N/A';
                                  }
      
                              })
                              .catch(e => console.log(e));
                  </script>
      ----
      

      Solution

      https://www.jenkins.io/doc/developer/security/csp/#inline-javascript-blocks

            Unassigned Unassigned
            basil Basil Crow
            Votes:
            0 Vote for this issue
            Watchers:
            1 Start watching this issue

              Created:
              Updated: