summaryrefslogtreecommitdiff
path: root/lib/github.rb
blob: 77d765e9977614e4391173d844d446c9d4b99359 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
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
39
40
41
42
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
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
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
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
require 'date'
require 'open-uri'
require 'json'

class Github

  def initialize(orgname)
    url='https://api.github.com/orgs/'+orgname
    @headers={'User-Agent' => 'LEAP Dashboard'}
    if ENV.has_key?('GITHUB_AUTH_TOKEN')
      @headers['Authorization'] = "token "+ENV['GITHUB_AUTH_TOKEN']
    end
    @org=JSON.parse(open(url,@headers).read)
    @repos=JSON.parse(open(@org['repos_url'],@headers).read)
  end

  def repocount
    @repos.count
  end

  def prcount
    count=0
    @repos.each do |r|
      count+=JSON.parse(open(r['url']+'/pulls',@headers).read).count
    end
    return count
  end

  def recent_open_issues
    count=0
    @repos.each do |r|
      url=r['url']+'/issues?state=open&since='+(Time.new().to_datetime << 1).to_time.strftime("%Y-%m-%dT%H:%M:%SZ")
      count+=JSON.parse(open(url,@headers).read).count
    end
    return count
  end
  def recent_issues
    count=0
    @repos.each do |r|
      url=r['url']+'/issues?state=all&since='+(Time.new().to_datetime << 1).to_time.strftime("%Y-%m-%dT%H:%M:%SZ")
      count+=JSON.parse(open(url,@headers).read).count
    end
    return count
  end
  def open_pull_requests
    count=0
    @repos.each do |r|
      url=r['url']+'/pulls?state=open'
      count+=JSON.parse(open(url,@headers).read).count
    end
    return count
  end
  def pull_requests
    count=0
    @repos.each do |r|
      url=r['url']+'/pulls?state=all'
      count+=JSON.parse(open(url,@headers).read).count
    end
    return count
  end
  def forks
    count=0
    @repos.each do |r|
      url=r['url']+'/forks'
      count+=JSON.parse(open(url,@headers).read).count
    end
    return count
  end
  def issues_in_development
    count=0
    @repos.each do |r|
      url=r['url']+'/issues?labels=2%20-%20Development'
      count+=JSON.parse(open(url,@headers).read).count
    end
    return count
  end
  def prlist
    prlist=[]
    @repos.each do |r|
      JSON.parse(open(r['url']+'/pulls',@headers).read).each do |pr|
        prlist<<{'label'=>pr['title'], 'pr_url'=>pr['html_url']}
      end
    end
    return prlist
  end

  def stargazers
    @repos.inject(0) {|sum,hash| sum + hash['stargazers_count']}
  end
  def epic_issues
    count=0
    @repos.each do |r|
        url=r['url']+'/issues?labels=UA%20multiuser'
        count+=JSON.parse(open(url,@headers).read).count
      end
    return count
  end
  def all_epic_issues
    count=0
    @repos.each do |r|
        url=r['url']+'/issues?labels=UA%20multiuser&state=all'
        count+=JSON.parse(open(url,@headers).read).count
      end
    return count
  end

  def action_items
    issues=[]
    @repos.each do |r|
      url=r['url']+'/issues?labels=Action+item'
      JSON.parse(open(url,@headers).read).each do |issue|
        title=issue['title']
        if issue.has_key?('assignee') and not issue['assignee'].nil?
          assignee=issue['assignee']['login']
        else
          assignee='None'
        end
        issues<<{'label' => title, 'value' => assignee}
      end
    end
    issues
  end
end