API to get Lines of Code or Source Lines of code

Hello Team.
We frequently need Lines of code metrics data for our repositores. Is there any way to get that through Codacy API.

1 Like

There is one endpoint that might be useful: Codacy API v3 - listCommitAnalysisStats.

We can use it to obtain the number of lines of code for a repository like this:

curl -X GET https://app.codacy.com/api/v3/analysis/organizations/gh/mrfyda/repositories/imgur2pdf/commit-statistics
{
  "data": [
    {
      "repositoryId": 394242,
      "commitId": 543570636,
      "numberIssues": 17,
      "numberLoc": 139,
      "issuesPerCategory": [
        {
          "categoryId": 1,
          "numberOfIssues": 17
        }
      ],
      "issuePercentage": 20,
      "techDebt": 60,
      "totalFilesAdded": 3,
      "totalFilesRemoved": 0,
      "totalFilesChanged": 1,
      "commitTimestamp": "2021-02-24T11:02:09Z",
      "commitAuthorName": "Rafael Cortês",
      "commitShortUUID": "f92349c1b8",
      "totalComplexity": 12,
      "numberComplexFiles": 0,
      "complexFilesPercentage": 0,
      "filesChangedToIncreaseComplexity": 4,
      "numberDuplicatedLines": 0,
      "duplicationPercentage": 0,
      "numberFilesUncovered": 7
    },
    {
      "repositoryId": 394242,
      "commitId": 543570635,
      "numberIssues": 12,
      "numberLoc": 103,
      "issuesPerCategory": [
        {
          "categoryId": 1,
          "numberOfIssues": 12
        }
      ],
      "issuePercentage": 91,
      "techDebt": 35,
      "totalFilesAdded": 4,
      "totalFilesRemoved": 0,
      "totalFilesChanged": 0,
      "commitTimestamp": "2020-11-15T18:36:25Z",
      "commitAuthorName": "Rafael Cortês",
      "commitShortUUID": "2edf0a766e",
      "totalComplexity": 5,
      "numberComplexFiles": 0,
      "complexFilesPercentage": 0,
      "numberDuplicatedLines": 0,
      "duplicationPercentage": 0,
      "numberFilesUncovered": 4
    }
  ]
}

We get a list, but the first commit gives the current state of the repository. Don’t forget to specify a branch if it makes sense. (And don’t forget the authentication. The example uses a public repository.)

I’m curious about what you are building with this. Would you be kind enough to share what do you hope to achieve with this information? Where is it going to be used? What is it going to be used for?

3 Likes