-1

I am trying to run the github linguist ruby verision, It runs on my computer, I am using visual studio. If i run the github-linguist it does give me the stats of percentage and type of language my repository have that is on local system. ( using terminal commands )

OutPut running Linguist using terminal visual code

Goal: To write a scripts in ruby that takes provided repository and provide me with the stats (similar to above screenshot) as described by github-linguist functionality.

Based on some research so far, all i have is following code.

require 'rugged'
require 'linguist'
target=""
repo = Rugged::Repository.new('https://github.com/NameOfRepo')
project=Linguist::Repository.new(repo,repo.head.target)
project.language
project.languages

But having error, and I need a guidance related to the error and a better way to reach my goal. Error: Error from script, Visual Code I am new to ruby and I would like for some help ?

I am aware of how to change my path to local clone repository path in above code. I am looking for help with writing scripts that traverse through online github repository and provide me the stats.

1 Answers1

0

You need to pass the path to a directory to Rugged::Repository.new(), not a URL:

repo = Rugged::Repository.new('/home/ShaishavMaisuria/NameOfRepo')

FYI, the source code for the github-linguist executable is at https://github.com/github/linguist/blob/master/bin/github-linguist.

pchaigno
  • 11,313
  • 2
  • 29
  • 54
  • Yes I am aware about how to write the code for local clone repository. Based on my goal metioned. i want to traverse throughly my git repositories online. so I looking for help in regards of writing scripts that can traverse through online repositories and help me get languages. the source code, is helpfull but i am confused how to pursue my stated goal. would love to get some help. – shaishav maisuria Nov 01 '21 at 16:34
  • Are you saying you're question is basically a duplicate of https://stackoverflow.com/questions/24516394/how-to-clone-git-in-ruby-with-url? – pchaigno Nov 01 '21 at 16:45
  • Not actually, cloning of github repository to local system takes a lot of memory resources and does tolls on time if there are many github repository to traverse through. I am looking for something that allows to pursue my goal without cloning the project on local system rather the scripts travserses the repository online. – shaishav maisuria Nov 01 '21 at 18:07
  • I see. Then maybe you could query the GitHub API to retrieve statistics computed by Linguist for existing projects? – pchaigno Nov 01 '21 at 19:04
  • would be possible to query for user based accounts and check the stats using the above code. how can i do it in ruby though. I would request you to please guide – shaishav maisuria Nov 01 '21 at 19:11