Class: Ginatra::RepoStats
- Inherits:
-
Object
- Object
- Ginatra::RepoStats
- Defined in:
- lib/ginatra/repo_stats.rb
Instance Method Summary collapse
-
#commits_count ⇒ Integer
Commits count in defined branch.
-
#contributors ⇒ Array
Contributors to repository.
-
#created_at ⇒ Time
Repository created at time.
- #initialize(repo, branch_name) ⇒ Ginatra::RepoStats constructor
-
#license ⇒ String
Detect common OSS licenses.
Constructor Details
#initialize(repo, branch_name) ⇒ Ginatra::RepoStats
6 7 8 9 |
# File 'lib/ginatra/repo_stats.rb', line 6 def initialize(repo, branch_name) @repo = repo @branch = branch_name end |
Instance Method Details
#commits_count ⇒ Integer
Commits count in defined branch
85 86 87 88 89 90 91 |
# File 'lib/ginatra/repo_stats.rb', line 85 def commits_count ref = @repo.ref("refs/heads/#{@branch}") walker = Rugged::Walker.new(@repo.to_rugged) walker.push(ref.target) walker.count end |
#contributors ⇒ Array
Contributors to repository
14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 |
# File 'lib/ginatra/repo_stats.rb', line 14 def contributors contributors = {} ref = @repo.ref("refs/heads/#{@branch}") walker = Rugged::Walker.new(@repo.to_rugged) walker.push(ref.target) walker.each do |commit| = commit. email = [:email] if contributors[email] contributors[email] = { author: [:name], commits_count: contributors[email][:commits_count] + 1 } else contributors[email] = { author: [:name], commits_count: 1 } end end contributors.sort_by {|c| c.last[:commits_count] }.reverse end |
#created_at ⇒ Time
Repository created at time
72 73 74 75 76 77 78 79 80 |
# File 'lib/ginatra/repo_stats.rb', line 72 def created_at ref = @repo.ref("refs/heads/#{@branch}") walker = Rugged::Walker.new(@repo.to_rugged) walker.sorting(Rugged::SORT_TOPO) walker.push(ref.target) commit = walker.to_a.last Time.at(commit.time) end |
#license ⇒ String
Detect common OSS licenses
43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 |
# File 'lib/ginatra/repo_stats.rb', line 43 def license last_commit = @repo.ref("refs/heads/#{@branch}").target license = @repo.blob_at(last_commit.oid, 'LICENSE') || @repo.blob_at(last_commit.oid, 'LICENSE.txt') if license.nil? 'N/A' else license_text = license.text case license_text when /Apache License/ 'Apache' when /GNU GENERAL PUBLIC LICENSE/ 'GPL' when /GNU LESSER GENERAL PUBLIC LICENSE/ 'LGPL' when /Permission is hereby granted, free of charge,/ 'MIT' when /Redistribution and use in source and binary forms/ 'BSD' else 'N/A' end end end |