Licenses count always 0 when landing on pipeline page

Summary

When landing on a pipeline page, the licenses count is always 0 even when licenses have been detected in the pipeline.

Steps to reproduce

In a project where License Scanning is configured, go to a pipeline page. The licenses count is 0 when you land on that page.

Example Project

Any project where License Scanning is configured.

Example: https://gitlab.com/gitlab-org/security-products/tests/php-composer/-/pipelines/742515529/builds

  • It shows Licenses 0 when landing on the Jobs tab of the pipeline.
  • If you select to the Licenses tab, then it shows Licenses 4.
  • If you select Jobs again, then it still shows Licenses 4.
  • But then if you refresh the page (Jobs tab), then it shows Licenses 0.

What is the current bug behavior?

The licenses count is 0 when landing on the pipeline, except when Licenses is the active tab.

What is the expected correct behavior?

The licenses count is correct when landing on the pipeline page, even if the active tab isn't Licenses.

Relevant logs and/or screenshots

First, land on the pipeline page:

Screenshot_2023-01-10_at_07.28.40

Then, select the Licenses tab:

Screenshot_2023-01-10_at_07.29.19

Output of checks

Results of GitLab environment info

Expand for output related to GitLab environment info

(For installations with omnibus-gitlab package run and paste the output of:
`sudo gitlab-rake gitlab:env:info`)

(For installations from source run and paste the output of:
`sudo -u git -H bundle exec rake gitlab:env:info RAILS_ENV=production`)

Results of GitLab application Check

Expand for output related to the GitLab application check

(For installations with omnibus-gitlab package run and paste the output of: sudo gitlab-rake gitlab:check SANITIZE=true)

(For installations from source run and paste the output of: sudo -u git -H bundle exec rake gitlab:check RAILS_ENV=production SANITIZE=true)

(we will only investigate if the tests are passing)

Implementation Plan

  1. In ee/app/helpers/ee/projects/pipeline_helper.rb add something like
      def js_pipeline_tabs_data(project, pipeline, user)
        super.merge(
          ...
          license_scan_count: license_scan_count(pipeline)
        )
      end

      def license_scan_count(pipeline)
        if project.licensed_feature_available?(:license_scanning)
          ::Gitlab::LicenseScanning.scanner_for_pipeline(pipeline).report.licenses.count
        end
      end
  1. In app/assets/javascripts/pipelines/pipeline_tabs.js
const {
  ...
  licenseScanCount
} = dataset

...
provide: {
 ...
 licenseScanCount
}
  1. In ee/app/assets/javascripts/pipelines/components/pipeline_tabs.vue
inject: {
 ...
 licenseScanCount
}

and set initial count to what we get from backend and rails template injection

  data() {
    return {
      licenseCount: this.licenseScanCount,
    };
  },
  1. Update unit tests

/cc @farias-gl

Edited by -