Class: Repos::GithubData
- Inherits:
-
Object
- Object
- Repos::GithubData
- Defined in:
- lib/repocrawler/crawler.rb
Instance Method Summary collapse
-
#get_commits_history ⇒ Object
get commits history.
-
#get_contributors ⇒ Object
Get the contributors.
-
#get_forks ⇒ Object
get numbers of forks, stars and issues.
- #get_issues ⇒ Object
-
#get_issues_info ⇒ Object
get information of the closed issues.
-
#get_last_commits_days ⇒ Object
get the date of the last commit.
-
#get_last_year_commit_activity ⇒ Object
get the commit activity in last year.
-
#get_readme_word_count ⇒ Object
get the readme file.
- #get_stars ⇒ Object
-
#get_total_commits ⇒ Object
get the total commits.
-
#initialize(repo_user, repo_name, github_token, github_password, github_account, user_agent) ⇒ GithubData
constructor
A new instance of GithubData.
Constructor Details
#initialize(repo_user, repo_name, github_token, github_password, github_account, user_agent) ⇒ GithubData
Returns a new instance of GithubData.
11 12 13 14 15 16 17 18 19 20 |
# File 'lib/repocrawler/crawler.rb', line 11 def initialize(repo_user, repo_name, github_token, github_password, github_account, user_agent) @GITHUB_README_URL = "https://raw.githubusercontent.com/#{repo_user}/#{repo_name}/master" @GITHUB_API_BASE_URL = "https://api.github.com/repos/#{repo_user}/#{repo_name}" @access_token = github_token @github_password = github_password @github_account = github_account @user_agent = user_agent @repo_user = repo_user @repo_name = repo_name end |
Instance Method Details
#get_commits_history ⇒ Object
get commits history
84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 |
# File 'lib/repocrawler/crawler.rb', line 84 def get_commits_history commits_info = [] stop = false page = 1 until stop commits_fetch = HTTParty.get(@GITHUB_API_BASE_URL + "/commits?page=#{page}&access_token=#{@access_token}", headers: { "User-Agent" => @user_agent }) if commits_fetch.count === 0 stop = true end commits_fetch.each do |commit| commits_info << { "committer" => commit['commit']['committer']['name'], "created_at" => commit['commit']['committer']['date'] } end page += 1 end commits_info.reverse! end |
#get_contributors ⇒ Object
Get the contributors
32 33 34 35 36 37 38 39 40 41 42 43 |
# File 'lib/repocrawler/crawler.rb', line 32 def get_contributors contributors = HTTParty.get(@GITHUB_API_BASE_URL + "/contributors?access_token=#{@access_token}", headers: { "User-Agent" => @user_agent }).map do |contributor| { 'name' => contributor['login'], 'contributions' => contributor['contributions'] } end contributors end |
#get_forks ⇒ Object
get numbers of forks, stars and issues
56 57 58 59 60 61 62 63 |
# File 'lib/repocrawler/crawler.rb', line 56 def get_forks = HTTParty.get(@GITHUB_API_BASE_URL + "?access_token=#{@access_token}", headers: { "User-Agent" => @user_agent }) forks = ['forks_count'] forks end |
#get_issues ⇒ Object
74 75 76 77 78 79 80 81 |
# File 'lib/repocrawler/crawler.rb', line 74 def get_issues = HTTParty.get(@GITHUB_API_BASE_URL + "?access_token=#{@access_token}", headers: { "User-Agent" => @user_agent }) issues = ['open_issues_count'] issues end |
#get_issues_info ⇒ Object
get information of the closed issues
111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 |
# File 'lib/repocrawler/crawler.rb', line 111 def get_issues_info closed_issues = [] stop = false page = 1 until stop issue_fetch = HTTParty.get(@GITHUB_API_BASE_URL + "/issues?state=closed&page=#{page}&access_token=#{@access_token}", headers: { "User-Agent" => @user_agent }) if issue_fetch.count === 0 stop = true end issue_fetch.each do |issue| closed_issues << { 'number' => issue['number'], 'created_at' => issue['created_at'], 'closed_at' => issue['closed_at'], 'duration' => (Date.parse(issue['closed_at']) - Date.parse(issue['created_at'])).to_i } end page += 1 end closed_issues.reverse! end |
#get_last_commits_days ⇒ Object
get the date of the last commit
141 142 143 144 145 146 147 148 149 |
# File 'lib/repocrawler/crawler.rb', line 141 def get_last_commits_days commits_fetch = HTTParty.get(@GITHUB_API_BASE_URL + "/commits?access_token=#{@access_token}", headers: { "User-Agent" => @user_agent }) last_commit_date = commits_fetch.first['commit']['comitter']['date'] last_commit = (Date.today - Date.parse(last_commit_date)).to_i last_commit end |
#get_last_year_commit_activity ⇒ Object
get the commit activity in last year
23 24 25 26 27 28 29 |
# File 'lib/repocrawler/crawler.rb', line 23 def get_last_year_commit_activity last_year_commit_activity = HTTParty.get(@GITHUB_API_BASE_URL + "/stats/commit_activity?access_token=#{@access_token}", headers: { "User-Agent" => @user_agent }) last_year_commit_activity.delete_if {|record| record['total'] == 0} end |
#get_readme_word_count ⇒ Object
get the readme file
152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 |
# File 'lib/repocrawler/crawler.rb', line 152 def get_readme_word_count github_contents = HTTParty.get(@GITHUB_API_BASE_URL + "/contents?access_token=#{@access_token}", headers: { "User-Agent" => @user_agent }) readme_file = '' github_contents.each do |content| readme_file = content['name'] if content['name'] =~ /^README/ end stop_words = [] File.open(File.("../../public/stop_words.txt", File.dirname(__FILE__)), "r") do |f| f.each_line do |line| stop_words << line.gsub(/\n/,"") end end readme = HTTParty.get(@GITHUB_README_URL + "/#{readme_file}") words = readme.split(' ') freqs = Hash.new(0) words.each do |word| if word =~ /^\w+$/ && !stop_words.include?(word.downcase) freqs[word] += 1 end end freqs = freqs.sort_by { |word, freq| freq }.reverse! freqs end |
#get_stars ⇒ Object
65 66 67 68 69 70 71 72 |
# File 'lib/repocrawler/crawler.rb', line 65 def get_stars = HTTParty.get(@GITHUB_API_BASE_URL + "?access_token=#{@access_token}", headers: { "User-Agent" => @user_agent }) stars = ['stargazers_count'] stars end |
#get_total_commits ⇒ Object
get the total commits
46 47 48 49 50 51 52 53 |
# File 'lib/repocrawler/crawler.rb', line 46 def get_total_commits contributors = get_contributors commits = contributors.reduce(0) do |sum, num| sum + num['contributions'] end commits end |