github-linguist / linguist

Language Savant. If your repository's language is being reported incorrectly, send us a pull request!
MIT License
11.99k stars 4.15k forks source link

Can we use this against a VSTS organisation which is a SaaS solution. #4316

Closed Chaits358 closed 5 years ago

Chaits358 commented 5 years ago

I'm wondering if there is a way to use this to run against an entire VSTS organisation containing git Repo's. This needs to be run on a seperate server which we have access to(Any machine is fine) and reach out to vsts git repo's url's and determine the programming languages percentage across vsts organisation.

pchaigno commented 5 years ago

Linguist can run on any repository so you should be able to clone the repositories you want to analyze and run Linguist on them.

lildude commented 5 years ago

No, it can't be in the form you've described on its own as Linguist needs access to the repo content itself so you'd need to clone each repo to the machine on which you plan to run Linguist first.

You'd also need to perform the summing of all repo totals yourself.

Chaits358 commented 5 years ago

Linguist can run on any repository so you should be able to clone the repositories you want to analyze and run Linguist on them.

Thanks for your quick response. but we have more than 1460 repo's hosted on out VSTS and its not an ideal solution. I was thinking if I could write a scritp to clone, scan and delete each repo in a loop on a linux machine.

Chaits358 commented 5 years ago

No, it can't be in the form you've described on its own as Linguist needs access to the repo content itself so you'd need to clone each repo to the machine on which you plan to run Linguist first.

You'd also need to perform the summing of all repo totals yourself.

Thanks for your quick response. but we have more than 1460 repo's hosted on out VSTS and its not an ideal solution. I was thinking if I could write a scritp to clone, scan and delete each repo in a loop on a linux machine. Also wondering if there are any specific steps to install linguist on Linux? there seems to be few dependencies.

lildude commented 5 years ago

I was thinking if I could write a scritp to clone, scan and delete each repo in a loop on a linux machine.

You most certainly can. Something like this (completely untested pseudo Bash code):

for url in $list_of_repo_urls; do
  git clone $url
  [run code here to determine path repo was cloned into to get a $repo path to the repo]
  echo $repo >> file_with_all_analyses.txt
  github-linguist ./$repo >> file_with_all_analyses.txt
done

You can then post-process the file_with_all_analyses.txt file as you please.

Also wondering if there are any specific steps to install linguist on Linux? there seems to be few dependencies.

https://github.com/github/linguist#installation should cover it for macOS and Ubuntu. You may need to adjust the pkg names and installation method for other distros.

Chaits358 commented 5 years ago

I was thinking if I could write a scritp to clone, scan and delete each repo in a loop on a linux machine.

You most certainly can. Something like this (completely untested pseudo Bash code):

for url in $list_of_repo_urls; do
  git clone $url
  [run code here to determine path repo was cloned into to get a $repo path to the repo]
  echo $repo >> file_with_all_analyses.txt
  github-linguist ./$repo >> file_with_all_analyses.txt
done

You can then post-process the file_with_all_analyses.txt file as you please.

Also wondering if there are any specific steps to install linguist on Linux? there seems to be few dependencies.

https://github.com/github/linguist#installation should cover it for macOS and Ubuntu. You may need to adjust the pkg names and installation method for other distros.

Thanks for the input. There is an REST API within Azure Devops that gives the breakdown for each repository, for each project and then I used a powershell script to fetch the data.

You can use this API: https://dev.azure.com/{acct}/{project}/_apis/projectanalysis/languagemetrics

Powershellscript if anyone needs $Account="XXXX" $VSTSUser="XXXXX@yz.com" $VSTSPAT="XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX" $global:vstsbase64AuthInfo = [Convert]::ToBase64String([Text.Encoding]::ASCII.GetBytes(("{0}:{1}" -f $VSTSUser, $VSTSPAT)))

$url="https://dev.azure.com/$Account/_apis/projects?api-version=4.1-preview" $url2= "https://dev.azure.com/$Account/$project/_apis/projectanalysis/languagemetrics" $Projects=Invoke-Webrequest -Uri $url -Headers @{Authorization=("Basic {0}" -f $global:vstsbase64AuthInfo)} -Method GET | ConvertFrom-Json

foreach ($project in $Projects.value) { $ProjName=$project.name $url2= "https://dev.azure.com/$Account/$ProjName/_apis/projectanalysis/languagemetrics" Invoke-Webrequest -Uri $url2 -Headers @{Authorization=("Basic {0}" -f $global:vstsbase64AuthInfo)} -Method GET | ConvertFrom-Json | select -expand languageBreakdown

}