Uploaded image for project: 'SonarQube'
  1. SonarQube
  2. SONAR-11604

Clean response of api/measures/component

    XMLWordPrintable

    Details

    • Edition:
      Community
    • Production Notes:
      None

      Description

      Here is an example of a response of the webservice api/measures/component:

      {
        "component": {
          "id": "AV8WJCz7leTHsONfkGE1",
          "key": "org.sonarsource.sonarqube:sonarqube",
          "name": "SonarQube",
          "description": "Open source platform for continuous inspection of code quality",
          "qualifier": "TRK",
          "measures": [
            {
              "metric": "new_lines",
              "periods": [
                {
                  "index": 1,
                  "value": "17526"
                }
              ]
            }
          ]
        },
        "periods": [
          {
            "index": 1,
            "mode": "previous_version",
            "date": "2018-12-18T11:22:48+0100",
            "parameter": "7.5"
          }
        ]
      }
      

      For backward compatibility reasons, we still structure the data as if there could be values for multiple periods. That's no longer the case since 6.3 (before LTS).
      Currently, for metrics related to differential metrics (new_*), we only have one period which is the leak period configured for the project.
      The response could therefore be simplified:

      {
        "component": {
          "id": "AV8WJCz7leTHsONfkGE1",
          "key": "org.sonarsource.sonarqube:sonarqube",
          "name": "SonarQube",
          "description": "Open source platform for continuous inspection of code quality",
          "qualifier": "TRK",
          "measures": [
            {
              "metric": "new_lines",
              "value": "17526"
            }
          ]
        },
        "period": [
          {
            "mode": "previous_version",
            "date": "2018-12-18T11:22:48+0100",
            "parameter": "7.5"
          }
        ]
      }
      

      Pull Requests and Short Lived Branches

      In PRs and SLBs, the differential metrics (new_*) have a different meaning: the measurements apply on lines detected as new when comparing the branch with its target.

      For example, new_lines in master means the number of lines changed since the version changed while in a PR means the number of lines detected as changed in that PR.

      The WebService wasn't updated to reflect this difference. The exact same response is used in both cases, and as a consequence some fields are very misleading and make no sense in PRs and SLBs:

      {
        "component": {
          "id": "AWfgviWPUxLgSL7msVfx",
          "key": "org.sonarsource.sonarqube:sonarqube",
          "name": "SonarQube",
          "description": "Open source platform for continuous inspection of code quality",
          "qualifier": "TRK",
          "measures": [
            {
              "metric": "new_lines",
              "periods": [
                {
                  "index": 1,
                  "value": "488"
                }
              ]
            }
          ],
          "pullRequest": "1113"
        },
        "periods": [
          {
            "index": 1,
            "mode": "previous_version",
            "date": "2018-12-24T19:18:33+0100"
          }
        ]
      }
      

      Note that in this example there are 488 lines modified in the PR. The period's mode and date make no sense.

        Attachments

          Issue Links

            Activity

              People

              Assignee:
              jacek.poreda Jacek Poreda
              Reporter:
              duarte.meneses Duarte Meneses
              Votes:
              0 Vote for this issue
              Watchers:
              1 Start watching this issue

                Dates

                Due:
                Created:
                Updated:
                Resolved: