{"id":28496074,"url":"https://github.com/sonarsource/sonar-loc-count","last_synced_at":"2025-07-19T12:38:31.581Z","repository":{"id":44161233,"uuid":"449112748","full_name":"SonarSource/sonar-loc-count","owner":"SonarSource","description":null,"archived":false,"fork":false,"pushed_at":"2025-06-16T16:32:43.000Z","size":495,"stargazers_count":45,"open_issues_count":13,"forks_count":30,"subscribers_count":31,"default_branch":"main","last_synced_at":"2025-07-02T10:47:59.610Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":null,"language":"PowerShell","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"lgpl-3.0","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/SonarSource.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":".github/CODEOWNERS","security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null,"zenodo":null}},"created_at":"2022-01-18T02:22:01.000Z","updated_at":"2025-06-16T16:32:48.000Z","dependencies_parsed_at":"2023-10-03T00:54:31.256Z","dependency_job_id":"cfb37cdc-c749-4caf-83ca-a8710760befc","html_url":"https://github.com/SonarSource/sonar-loc-count","commit_stats":null,"previous_names":[],"tags_count":0,"template":false,"template_full_name":null,"purl":"pkg:github/SonarSource/sonar-loc-count","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/SonarSource%2Fsonar-loc-count","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/SonarSource%2Fsonar-loc-count/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/SonarSource%2Fsonar-loc-count/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/SonarSource%2Fsonar-loc-count/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/SonarSource","download_url":"https://codeload.github.com/SonarSource/sonar-loc-count/tar.gz/refs/heads/main","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/SonarSource%2Fsonar-loc-count/sbom","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":265934253,"owners_count":23852092,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":[],"created_at":"2025-06-08T11:38:41.146Z","updated_at":"2025-07-19T12:38:31.560Z","avatar_url":"https://github.com/SonarSource.png","language":"PowerShell","funding_links":[],"categories":[],"sub_categories":[],"readme":"![Shell Script](https://img.shields.io/badge/shell_script-%23121011.svg?style=for-the-badge\u0026logo=gnu-bash\u0026logoColor=white)\n\n\n## LoC Counting Scripts\nThis is a collection of shell scripts that demonstrate how to count lines of code from repositories and/or local directories.These scripts can be used to **estimate** LoC counts that would be produced by a Sonar analysis of these projects, without having to implement this analysis.\n\nThese scripts that connect to a DevOps platform must be run in a blank workspace (without data).\n\nTo exclude directories or files from the scan, you can insert the names of these exclusions into the **.clocignore** file in the environment where you run the scripts. Example :\n\n\u003e bootstrap\n\u003e \n\u003e test\n\n* [Installation](#installation)\n* [General usage](#general-usage)\n* [Contributions and Feedbacks](#Contributions-and-feedbacks)\n\n![architecture](cloc.png)\n\n## Installation\nRequirements:\n\n* bash version 4+\n* [Git](https://git-scm.com/)\n* [curl](https://curl.haxx.se)\n* [jq](https://stedolan.github.io/jq/)\n* [cloc](https://github.com/AlDanial/cloc/releases/tag/v1.96)  installed v1.96\n* For Mac OSX you need gnu-sed (brew install gnu-sed)\n\n## General usage\nMost scripts will produce two reports of LoC by language (.lang) and by repository (.file).\n\n### [github.com](https://github.com):\nCounts lines of code from a GitHub.com organization.  Requires to pass username, [personal access token](https://docs.github.com/en/authentication/keeping-your-account-and-data-secure/creating-a-personal-access-token) and the organization.  The token must have repo scope.The script generates a report per project(File : ***ProjectName.txt***) that indicates the number of lines of code per branch and indicates the branch that has the highest number of lines of code.As well as a ***Report_global.txt*** file that indicates the maximum line of code on the repository.\n\n```\n\u003cgithub_com.sh\u003e \u003cuser\u003e \u003ctoken\u003e \u003corganization\u003e\ngithub_com.sh myuser 1234567890abcdefgh myGitHubDotComOrg\n```\nor\n```\n\u003cgithub_com.sh\u003e \u003cuser\u003e \u003ctoken\u003e \u003corganization\u003e \u003cMyRepoName\u003e\ngithub_com.sh myuser 1234567890abcdefgh myGitHubDotComOrg MyRepoName\n```\n\n### [bitbucket.org](https://bitbucket.org):\nCounts lines of code from a Bitbucket.org organization. Requires to pass username, [App token password](https://support.atlassian.com/bitbucket-cloud/docs/app-passwords/) and the workspace slug.  The token must have Repositories Read permissions.The script generates a report per project(File : ***ProjectName.txt***) that indicates the number of lines of code per branch and indicates the branch that has the highest number of lines of code.As well as a ***Report_global.txt*** file that indicates the maximum line of code on the repository.\n\n```\n\u003cbitbucket_org.sh\u003e \u003cuser\u003e \u003cPassordToken\u003e \u003cmyWorkspace\u003e\nbitbucket_org.sh myuser 1234567890abcdefgh myBBWorkspace\n```\nor\n```\n\u003cbitbucket_org.sh\u003e \u003cuser\u003e \u003cassordToken\u003e \u003cmyWorkspace\u003e \u003cMyProjectName\u003e\n\u003cbitbucket_org.sh\u003e myuser 1234567890abcdefgh myBBWorkspace MyProjectName\n```\nIf you have more than 100 repos , you need to change Value of parameter page=Number_of_page on line 53\n\n       1 Page = 100 repos max\n       Example for 150 repos : GetAPI=\"repositories/$wks?pagelen=100\u0026page=2\"\n\n### [Azure DevOps Services](https://dev.azure.com):\nCounts lines of code from a Azure DevOps Services organization. Requires to pass [personal access token](https://docs.microsoft.com/en-us/azure/devops/organizations/accounts/use-personal-access-tokens-to-authenticate?view=azure-devops) and the organization.  The token must have Code \u003e Read permissions.\nThe script generates a report per project(File : ***ProjectName.txt***) that indicates the number of lines of code per branch and indicates the branch that has the highest number of lines of code.As well as a ***Report_global.txt*** file that indicates the maximum line of code on the repository.\n\n```\n\u003cazure_devops_services.sh\u003e \u003ctoken\u003e \u003corganization\u003e\nazure_devops_services.sh 1234567890abcdefgh myADOOrg \n```\nor\n```\n\u003cazure_devops_services.sh\u003e \u003ctoken\u003e \u003corganization\u003e \u003cMyProjectName\u003e\nazure_devops_services.sh 1234567890abcdefgh myADOOrg MyProjectName\n```\n\n### [Gitlab.com](https://gitlab.com):\nCounts lines of code from a GitLab.com Group or Project. Requires to pass [personal access token](https://docs.gitlab.com/ee/user/profile/personal_access_tokens.html) and the group.  The token must have read_api and read_repository scopes.The script generates a report per project(File : ***ProjectName.txt***) that indicates the number of lines of code per branch and indicates the branch that has the highest number of lines of code.As well as a ***Report_global.txt*** file that indicates the maximum line of code on the repository.\n\n\n```\n\u003cgitlab_com.sh\u003e \u003ctoken\u003e \u003cgroupName\u003e\ngitlab_com.sh 1234567890abcdefgh myGitLabGroupName\n```\nor\n```\n\u003cgitlab_com.sh\u003e \u003ctoken\u003e \u003cgroupName//MyProjectName\u003e \ngitlab_com.sh 1234567890abcdefgh myGitLabGroupName/MyProjectName\n```\nIf you have more than 100 repos , you need to change Value of parameter page=Number_of_page on line 58 or 61\n\n       1 Page = 100 repos max\n       Example for 150 repos :  GetAPI=\"/projects/$groupname1?per_page=100\u0026page=2\"\n       \n### Local Filesystem:\nCounts lines of code from a local directory or file. The script generates a report file : Report_***Name-of-Directory***.txt\n\n```\n\u003cfilesystem.sh\u003e PathToDirectory\n```\n\nContributions and feedbacks\n-------------\nContributions and feedbacks are welcome, as PRs or issues directly with this repository, or through your established Sonar communication channel.\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fsonarsource%2Fsonar-loc-count","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fsonarsource%2Fsonar-loc-count","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fsonarsource%2Fsonar-loc-count/lists"}