hubstats 0.12.2 → 1.0.0.beta
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +5 -5
- data/.travis.yml +4 -2
- data/app/controllers/hubstats/application_controller.rb +3 -4
- data/app/controllers/hubstats/deploys_controller.rb +2 -3
- data/app/controllers/hubstats/events_controller.rb +4 -6
- data/app/models/hubstats/team.rb +16 -9
- data/lib/generators/hubstats/octokit.example.yml +2 -3
- data/lib/hubstats/events_handler.rb +25 -3
- data/lib/hubstats/github_api.rb +6 -37
- data/lib/hubstats/version.rb +1 -1
- data/lib/tasks/hubstats_tasks.rake +8 -10
- data/lib/tasks/populate_task.rake +43 -61
- data/spec/factories/teams.rb +5 -4
- data/spec/lib/hubstats/events_handler_spec.rb +10 -8
- data/spec/lib/hubstats/github_api_spec.rb +22 -34
- data/test/dummy/db/schema.rb +22 -21
- metadata +5 -5
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
|
-
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
2
|
+
SHA256:
|
3
|
+
metadata.gz: ed7d93b16a3876de97581f4dc7c76be14e2cf40bee2ead1883231283cdd264e3
|
4
|
+
data.tar.gz: a59a5cde37267a9595f763d55916d7ef05412f6126c0578c5ba7a92de8b37e98
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: e7666522d273e5ec4c581ab965631669685d952b478c374849593fc862a9a69fc26b4100ebe47c92b6a497076dcafc7429cdfc0e05ebb4ce972ba3aa0d767ba7
|
7
|
+
data.tar.gz: 2e1536857df35eb959f0011ba1c5dedea3fd93bfe001280ca72150db505051e76065619bc1c5d45e96dc65f68fa923c7e035fb9e6b385cd09017a669c4e5d697
|
data/.travis.yml
CHANGED
@@ -4,10 +4,9 @@ module Hubstats
|
|
4
4
|
|
5
5
|
# Private - Reads the cookie, and then either sets @start_date and @end_date to be the cookie's values
|
6
6
|
# or sets them to be today + 1 and two weeks ago.
|
7
|
-
#
|
8
|
-
# Returns - nothing
|
9
|
-
private
|
10
|
-
def set_time
|
7
|
+
#
|
8
|
+
# Returns - nothing
|
9
|
+
private def set_time
|
11
10
|
cookie = cookies[:hubstats_dates]
|
12
11
|
if cookie == nil || cookie.include?("null")
|
13
12
|
@start_date = Date.today - 14
|
@@ -78,7 +78,7 @@ module Hubstats
|
|
78
78
|
#
|
79
79
|
# repo - the repository
|
80
80
|
#
|
81
|
-
# Returns - true if the repo is valid
|
81
|
+
# Returns - true if the repo is valid
|
82
82
|
def valid_repo(repo)
|
83
83
|
return !repo.empty?
|
84
84
|
end
|
@@ -106,8 +106,7 @@ module Hubstats
|
|
106
106
|
# Private - Allows only these parameters to be added when creating a deploy
|
107
107
|
#
|
108
108
|
# Returns - hash of parameters
|
109
|
-
private
|
110
|
-
def deploy_params
|
109
|
+
private def deploy_params
|
111
110
|
params.permit(:git_revision, :repo_name, :deployed_at, :user_id, :pull_request_ids)
|
112
111
|
end
|
113
112
|
end
|
@@ -11,7 +11,7 @@ module Hubstats
|
|
11
11
|
# Returns - nothing, but makes a new event
|
12
12
|
def handler
|
13
13
|
verify_signature(request)
|
14
|
-
|
14
|
+
|
15
15
|
kind = request.headers['X-Github-Event']
|
16
16
|
event = event_params.with_indifferent_access
|
17
17
|
|
@@ -25,12 +25,11 @@ module Hubstats
|
|
25
25
|
end
|
26
26
|
|
27
27
|
# Public - Will check that the request passed is a valid signature.
|
28
|
-
#
|
28
|
+
#
|
29
29
|
# request - the signature to be checked
|
30
30
|
#
|
31
31
|
# Returns - an error if the signatures don't match
|
32
|
-
private
|
33
|
-
def verify_signature(request)
|
32
|
+
private def verify_signature(request)
|
34
33
|
request.body.rewind
|
35
34
|
payload_body = request.body.read
|
36
35
|
signature = 'sha1=' + OpenSSL::HMAC.hexdigest(OpenSSL::Digest.new('sha1'), Hubstats.config.webhook_endpoint, payload_body)
|
@@ -40,8 +39,7 @@ module Hubstats
|
|
40
39
|
# Private - Allows only these parameters to be added when creating an event
|
41
40
|
#
|
42
41
|
# Returns - hash of parameters
|
43
|
-
private
|
44
|
-
def event_params
|
42
|
+
private def event_params
|
45
43
|
params.permit!
|
46
44
|
end
|
47
45
|
end
|
data/app/models/hubstats/team.rb
CHANGED
@@ -6,11 +6,11 @@ module Hubstats
|
|
6
6
|
scope :with_id, lambda {|team_id| where(id: team_id.split(',')) if team_id}
|
7
7
|
|
8
8
|
# Public - Counts all of the comments a selected team's members have written that occurred between the start_date and end_date.
|
9
|
-
#
|
9
|
+
#
|
10
10
|
# start_date - the start of the date range
|
11
11
|
# end_date - the end of the data range
|
12
12
|
# user_id_array - an array of all of the user ids in selected team
|
13
|
-
#
|
13
|
+
#
|
14
14
|
# Returns - count of comments
|
15
15
|
scope :comments_count, lambda {|start_date, end_date|
|
16
16
|
select("IFNULL(COUNT(DISTINCT hubstats_comments.id),0) AS comment_count, hubstats_teams.id as team_id")
|
@@ -20,10 +20,10 @@ module Hubstats
|
|
20
20
|
}
|
21
21
|
|
22
22
|
# Public - Counts all of the merged pull requests for selected team's users that occurred between the start_date and end_date.
|
23
|
-
#
|
23
|
+
#
|
24
24
|
# start_date - the start of the date range
|
25
25
|
# end_date - the end of the data range
|
26
|
-
#
|
26
|
+
#
|
27
27
|
# Returns - count of pull requests
|
28
28
|
scope :pull_requests_count, lambda {|start_date, end_date|
|
29
29
|
select("hubstats_teams.id as team_id")
|
@@ -33,10 +33,10 @@ module Hubstats
|
|
33
33
|
}
|
34
34
|
|
35
35
|
# Public - Joins all of the metrics together for selected team: net additions, comments, repos, and pull requests.
|
36
|
-
#
|
36
|
+
#
|
37
37
|
# start_date - the start of the date range
|
38
38
|
# end_date - the end of the data range
|
39
|
-
#
|
39
|
+
#
|
40
40
|
# Returns - all of the stats about the team
|
41
41
|
scope :with_all_metrics, lambda {|start_date, end_date|
|
42
42
|
select("hubstats_teams.*, pull_request_count, comment_count")
|
@@ -46,14 +46,14 @@ module Hubstats
|
|
46
46
|
}
|
47
47
|
|
48
48
|
has_and_belongs_to_many :users, :join_table => 'hubstats_teams_users', :uniq => true
|
49
|
-
|
50
|
-
# Public - Checks if the team is currently existing, and if it isn't, then makes a new team with
|
49
|
+
|
50
|
+
# Public - Checks if the team is currently existing, and if it isn't, then makes a new team with
|
51
51
|
# the specifications that are passed in. We are assuming that if it is not already existent,
|
52
52
|
# then we probably don't really care about the team, so our hubstats boolean will be set to false.
|
53
53
|
#
|
54
54
|
# github_team - the info that's passed in about the new or updated team
|
55
55
|
#
|
56
|
-
# Returns - the team
|
56
|
+
# Returns - the team
|
57
57
|
def self.create_or_update(github_team)
|
58
58
|
github_team = github_team.to_h.with_indifferent_access if github_team.respond_to? :to_h
|
59
59
|
|
@@ -88,5 +88,12 @@ module Hubstats
|
|
88
88
|
def self.order_by_name
|
89
89
|
order("name ASC")
|
90
90
|
end
|
91
|
+
|
92
|
+
def self.designed_for_hubstats?(description)
|
93
|
+
description.include?("hubstats") ||
|
94
|
+
description.include?("Hubstats") ||
|
95
|
+
description.include?("hub") ||
|
96
|
+
description.include?("Hub")
|
97
|
+
end
|
91
98
|
end
|
92
99
|
end
|
@@ -3,9 +3,8 @@ github_auth: # Must include access_token
|
|
3
3
|
|
4
4
|
github_config: # Must include org_name. The repo_list, team_list, and ignore_users_list are optional.
|
5
5
|
# org_name: <ORGANIZATION NAME>
|
6
|
-
#
|
7
|
-
#
|
8
|
-
# ignore_users_list: [<ARRAY OF USERS' LOGINS TO IGNORE>]
|
6
|
+
# repo_list: [<ARRAY OF OPTIONAL REPOS>]
|
7
|
+
# ignore_users_list: [<ARRAY OF OPTIONAL USERS' LOGINS TO IGNORE>]
|
9
8
|
|
10
9
|
webhook_secret: #<40 CHARACTER ACCESS TOKEN >
|
11
10
|
webhook_endpoint: #<url of webhook endpoint>
|
@@ -17,8 +17,10 @@ module Hubstats
|
|
17
17
|
pull_processor(payload)
|
18
18
|
when "pull_request_review_comment", "PullRequestReviewCommentEvent"
|
19
19
|
comment_processor(payload, "PullRequest")
|
20
|
-
when "membership", "MembershipEvent"
|
20
|
+
when "membership", "MembershipEvent", "team", "TeamEvent"
|
21
21
|
team_processor(payload)
|
22
|
+
when "repository", "RepositoryEvent"
|
23
|
+
repository_processor(payload)
|
22
24
|
end
|
23
25
|
end
|
24
26
|
|
@@ -67,8 +69,17 @@ module Hubstats
|
|
67
69
|
# Returns - nothing, but updates or makes the team
|
68
70
|
def team_processor(payload)
|
69
71
|
team = payload[:team]
|
70
|
-
|
71
|
-
if
|
72
|
+
|
73
|
+
if payload[:scope] == "team" && payload[:action] == "added"
|
74
|
+
if Hubstats::Team.designed_for_hubstats?(team[:description])
|
75
|
+
Hubstats::Team.create_or_update(team.with_indifferent_access)
|
76
|
+
hubstats_team = Hubstats::Team.where(name: team[:name]).first
|
77
|
+
hubstats_user = Hubstats::User.create_or_update(payload[:member])
|
78
|
+
Hubstats::Team.update_users_in_team(hubstats_team, hubstats_user, payload[:github_action])
|
79
|
+
end
|
80
|
+
end
|
81
|
+
|
82
|
+
if payload[:action] == "edited" && Hubstats::Team.designed_for_hubstats?(team[:description])
|
72
83
|
Hubstats::Team.create_or_update(team.with_indifferent_access)
|
73
84
|
hubstats_team = Hubstats::Team.where(name: team[:name]).first
|
74
85
|
hubstats_user = Hubstats::User.create_or_update(payload[:member])
|
@@ -76,6 +87,17 @@ module Hubstats
|
|
76
87
|
end
|
77
88
|
end
|
78
89
|
|
90
|
+
def repository_processor(payload)
|
91
|
+
repo = payload[:repository]
|
92
|
+
|
93
|
+
if payload[:action] == "created" # it's a new repository
|
94
|
+
Hubstats::Repo.create_or_update
|
95
|
+
Hubstats::GithubAPI.create_repo_hook(repo)
|
96
|
+
# The hook was probably already made when we made the repository,
|
97
|
+
# but we'll put this here just in case
|
98
|
+
end
|
99
|
+
end
|
100
|
+
|
79
101
|
# Public - Grabs the PR number off of any of the various places it can be
|
80
102
|
#
|
81
103
|
# payload - the thing that we will use to try to attain the PR number
|
data/lib/hubstats/github_api.rb
CHANGED
@@ -100,10 +100,9 @@ module Hubstats
|
|
100
100
|
Octokit.auto_paginate = true
|
101
101
|
client = Hubstats::GithubAPI.client
|
102
102
|
all_teams_in_org = client.organization_teams(Hubstats.config.github_config["org_name"])
|
103
|
-
team_list = Hubstats.config.github_config["team_list"] || []
|
104
103
|
|
105
104
|
all_teams_in_org.each do |team|
|
106
|
-
if
|
105
|
+
if Hubstats::Team.designed_for_hubstats?(team[:description])
|
107
106
|
puts "Making a team"
|
108
107
|
Hubstats::Team.create_or_update(team)
|
109
108
|
users = client.team_members(team[:id])
|
@@ -126,12 +125,12 @@ module Hubstats
|
|
126
125
|
# Public - Goes through entire team database and updates the hubstats boolean based on the octokit.yml file
|
127
126
|
#
|
128
127
|
# Returns - nothing
|
129
|
-
def self.
|
130
|
-
team_list = Hubstats.config.github_config["team_list"] || []
|
128
|
+
def self.deprecate_teams
|
131
129
|
teams = Hubstats::Team.all
|
132
130
|
|
133
131
|
teams.each do |team|
|
134
|
-
|
132
|
+
desc = client.team(team.id)[:description]
|
133
|
+
if Hubstats::Team.designed_for_hubstats?(desc) && (team[:hubstats] == true)
|
135
134
|
team.update_column(:hubstats, false)
|
136
135
|
team.save!
|
137
136
|
puts "Changed #{team[:name]} from true to false"
|
@@ -147,7 +146,7 @@ module Hubstats
|
|
147
146
|
# repo - the repository that is attempting to have a hook made with
|
148
147
|
#
|
149
148
|
# Returns - the hook and a message (or just a message and no hook)
|
150
|
-
def self.
|
149
|
+
def self.create_repo_hook(repo)
|
151
150
|
begin
|
152
151
|
client.create_hook(
|
153
152
|
repo.full_name,
|
@@ -185,7 +184,7 @@ module Hubstats
|
|
185
184
|
:secret => Hubstats.config.webhook_secret
|
186
185
|
},
|
187
186
|
{
|
188
|
-
:events => ['membership'],
|
187
|
+
:events => ['membership', 'repository', 'team'],
|
189
188
|
:active => true
|
190
189
|
}
|
191
190
|
)
|
@@ -197,36 +196,6 @@ module Hubstats
|
|
197
196
|
end
|
198
197
|
end
|
199
198
|
|
200
|
-
# Public - Delete webhook from github repository
|
201
|
-
#
|
202
|
-
# repo - a repo github object
|
203
|
-
# old_endpoint - A string of the previous endpoint
|
204
|
-
#
|
205
|
-
# Return - nothing
|
206
|
-
def self.delete_hook(repo, old_endpoint)
|
207
|
-
begin
|
208
|
-
client.hooks(repo.full_name).each do |hook|
|
209
|
-
if hook[:config][:url] == old_endpoint
|
210
|
-
Hubstats::GithubAPI.client.remove_hook(repo.full_name, hook[:id])
|
211
|
-
puts "Successfully deleted hook with id #{hook[:id]} and url #{hook[:config][:url]} from #{repo.full_name}"
|
212
|
-
end
|
213
|
-
end
|
214
|
-
rescue Octokit::NotFound
|
215
|
-
puts "You don't have sufficient privileges to remove an event hook to #{repo.full_name}"
|
216
|
-
end
|
217
|
-
end
|
218
|
-
|
219
|
-
# Public - updates a hook if it exists, otherwise creates one
|
220
|
-
#
|
221
|
-
# repo - a repo github object
|
222
|
-
# old_endpoint - A string of the previous endpoint
|
223
|
-
#
|
224
|
-
# Returns - the new hook
|
225
|
-
def self.update_hook(repo, old_endpoint = nil)
|
226
|
-
delete_hook(repo, old_endpoint) unless old_endpoint == nil
|
227
|
-
create_hook(repo)
|
228
|
-
end
|
229
|
-
|
230
199
|
# Public - gets labels for a particular label
|
231
200
|
#
|
232
201
|
# repo - a repo github object
|
data/lib/hubstats/version.rb
CHANGED
@@ -8,8 +8,7 @@ namespace :hubstats do
|
|
8
8
|
puts "Running rake db:migrate"
|
9
9
|
Rake::Task['db:migrate'].invoke
|
10
10
|
puts "Pulling data from Github. This may take a while..."
|
11
|
-
Rake::Task['hubstats:populate:
|
12
|
-
Rake::Task['hubstats:populate:setup_teams'].invoke
|
11
|
+
Rake::Task['hubstats:populate:setup'].invoke
|
13
12
|
end
|
14
13
|
|
15
14
|
desc "Drops the database, then runs rake hubstats:setup"
|
@@ -21,8 +20,8 @@ namespace :hubstats do
|
|
21
20
|
|
22
21
|
desc "Updates changes to the config file"
|
23
22
|
task :update => :environment do
|
24
|
-
puts "Updating repos"
|
25
|
-
Rake::Task['hubstats:populate:
|
23
|
+
puts "Updating repos and teams"
|
24
|
+
Rake::Task['hubstats:populate:update'].invoke
|
26
25
|
end
|
27
26
|
|
28
27
|
desc "Updates the seed"
|
@@ -43,16 +42,15 @@ namespace :hubstats do
|
|
43
42
|
Rake::Task['hubstats:populate:update_teams'].invoke
|
44
43
|
end
|
45
44
|
|
46
|
-
desc "Deprecates teams
|
47
|
-
task :
|
48
|
-
puts "Deprecating teams
|
49
|
-
Rake::Task['hubstats:populate:
|
45
|
+
desc "Deprecates teams"
|
46
|
+
task :deprecate_teams => :environment do
|
47
|
+
puts "Deprecating teams"
|
48
|
+
Rake::Task['hubstats:populate:deprecate_teams'].invoke
|
50
49
|
end
|
51
50
|
|
52
51
|
desc "Creates webhook from github for organization"
|
53
52
|
task :make_org_webhook => :environment do
|
54
53
|
puts "Making a webhook for an organization in octokit.yml"
|
55
|
-
Rake::Task['hubstats:populate:
|
54
|
+
Rake::Task['hubstats:populate:create_organization_hook'].invoke
|
56
55
|
end
|
57
|
-
|
58
56
|
end
|
@@ -1,23 +1,23 @@
|
|
1
1
|
# A variety of commands that can be used to populate the database information
|
2
|
-
namespace :hubstats do
|
2
|
+
namespace :hubstats do
|
3
3
|
namespace :populate do
|
4
4
|
|
5
5
|
desc "Pull repos from Github saves in database"
|
6
|
-
task :
|
6
|
+
task :setup => :environment do
|
7
7
|
Hubstats::GithubAPI.get_repos.each do |repo|
|
8
|
-
|
8
|
+
setup_repo(repo)
|
9
9
|
end
|
10
10
|
puts "Finished with initial population, grabbing extra info about pull requests"
|
11
|
-
|
11
|
+
update_pulls
|
12
12
|
puts "Finished grabbing info about pull requests, populating teams"
|
13
|
-
|
13
|
+
update_teams
|
14
14
|
end
|
15
15
|
|
16
|
-
desc "Updates which repos hubstats tracks"
|
17
|
-
task :
|
16
|
+
desc "Updates which repos hubstats tracks"
|
17
|
+
task :update => :environment do
|
18
18
|
Hubstats::GithubAPI.get_repos.each_with_index do |repo, index|
|
19
19
|
unless Hubstats::Repo.where(full_name: repo.full_name).first
|
20
|
-
|
20
|
+
setup_repo(repo)
|
21
21
|
end
|
22
22
|
|
23
23
|
if index % 10 == 0
|
@@ -26,49 +26,52 @@ namespace :hubstats do
|
|
26
26
|
end
|
27
27
|
|
28
28
|
puts "Finished with initial updating, grabbing extra info about pull requests"
|
29
|
-
|
29
|
+
update_pulls
|
30
30
|
puts "Finished grabbing info about pull requests, populating teams"
|
31
|
-
|
31
|
+
update_teams
|
32
32
|
end
|
33
33
|
|
34
34
|
desc "Updates teams for past pull requests"
|
35
35
|
task :update_teams_in_pulls => :environment do
|
36
|
-
|
36
|
+
update_teams_in_prs
|
37
37
|
end
|
38
38
|
|
39
39
|
desc "Updates the teams"
|
40
40
|
task :update_teams => :environment do
|
41
|
-
|
41
|
+
update_teams
|
42
42
|
end
|
43
43
|
|
44
|
-
desc "Deprecates teams
|
45
|
-
task :
|
46
|
-
Hubstats::GithubAPI.
|
44
|
+
desc "Deprecates teams"
|
45
|
+
task :deprecate_teams => :environment do
|
46
|
+
Hubstats::GithubAPI.deprecate_teams
|
47
47
|
end
|
48
48
|
|
49
49
|
desc "Creates the webhook for the current org"
|
50
|
-
task :
|
51
|
-
|
50
|
+
task :create_organization_hook => :environment do
|
51
|
+
create_org_hook
|
52
52
|
end
|
53
53
|
|
54
54
|
task :create_org_hook => :environment do
|
55
|
+
create_org_hook
|
56
|
+
end
|
57
|
+
|
58
|
+
private def create_org_hook
|
55
59
|
Hubstats::GithubAPI.create_org_hook(Hubstats.config.github_config["org_name"])
|
56
60
|
end
|
57
61
|
|
58
|
-
|
59
|
-
task :setup_repo, [:repo] => :environment do |t, args|
|
60
|
-
repo = args[:repo]
|
62
|
+
private def setup_repo(repo)
|
61
63
|
Hubstats::Repo.create_or_update(repo)
|
62
|
-
Hubstats::GithubAPI.
|
63
|
-
|
64
|
-
|
65
|
-
|
66
|
-
|
64
|
+
Hubstats::GithubAPI.create_repo_hook(repo)
|
65
|
+
# These are the pieces that take forever when we run the command. Let's not do this, and just make
|
66
|
+
# hubstats accurate from this time on out.
|
67
|
+
# populate_users(repo)
|
68
|
+
# populate_pulls(repo)
|
69
|
+
# populate_comments(repo)
|
70
|
+
# populate_labels(repo)
|
67
71
|
end
|
68
72
|
|
69
|
-
|
70
|
-
|
71
|
-
repo = repo_checker(args[:repo])
|
73
|
+
private def populate_users(repo)
|
74
|
+
repo = repo_checker(repo)
|
72
75
|
puts "Adding contributors to " + repo.full_name
|
73
76
|
|
74
77
|
users = Hubstats::GithubAPI.client({:auto_paginate => true}).contribs(repo.full_name)
|
@@ -77,9 +80,8 @@ namespace :hubstats do
|
|
77
80
|
end unless users == "" # there are no contributors because there are no commits yet
|
78
81
|
end
|
79
82
|
|
80
|
-
|
81
|
-
|
82
|
-
repo = repo_checker(args[:repo])
|
83
|
+
private def populate_comments(repo)
|
84
|
+
repo = repo_checker(repo)
|
83
85
|
puts "Adding comments to " + repo.full_name
|
84
86
|
|
85
87
|
pull_comments = Hubstats::GithubAPI.inline(repo.full_name,'pulls/comments')
|
@@ -87,58 +89,38 @@ namespace :hubstats do
|
|
87
89
|
commit_comments = Hubstats::GithubAPI.inline(repo.full_name,'comments')
|
88
90
|
end
|
89
91
|
|
90
|
-
|
91
|
-
|
92
|
-
repo = repo_checker(args[:repo])
|
92
|
+
private def populate_pulls(repo)
|
93
|
+
repo = repo_checker(repo)
|
93
94
|
puts "Adding pulls to " + repo.full_name
|
94
|
-
|
95
|
+
|
95
96
|
pull_requests = Hubstats::GithubAPI.inline(repo.full_name,'pulls', :state => "all")
|
96
97
|
end
|
97
98
|
|
98
|
-
|
99
|
-
|
100
|
-
repo = repo_checker(args[:repo])
|
99
|
+
private def populate_labels(repo)
|
100
|
+
repo = repo_checker(repo)
|
101
101
|
puts "Getting labels for " + repo.full_name
|
102
102
|
Hubstats::GithubAPI.add_labels(repo)
|
103
103
|
end
|
104
104
|
|
105
|
-
|
106
|
-
task :update_pulls => :environment do
|
105
|
+
private def update_pulls
|
107
106
|
Hubstats::GithubAPI.update_pulls
|
108
107
|
end
|
109
108
|
|
110
|
-
|
111
|
-
task :update_labels => :environment do
|
112
|
-
Hubstats::Repo.all.each do |repo|
|
113
|
-
Hubstats::GithubAPI.add_labels(repo)
|
114
|
-
end
|
115
|
-
end
|
116
|
-
|
117
|
-
desc "indivdually gets and updates all of the teams"
|
118
|
-
task :teams => :environment do
|
109
|
+
private def update_teams
|
119
110
|
Hubstats::GithubAPI.update_teams
|
120
111
|
end
|
121
112
|
|
122
|
-
|
123
|
-
task :update_teams_in_prs => :environment do
|
113
|
+
private def update_teams_in_prs
|
124
114
|
Hubstats::PullRequest.update_teams_in_pulls(365)
|
125
115
|
end
|
126
116
|
|
127
|
-
|
128
|
-
task :update_hooks, [:old_endpoint] => :environment do |t, args|
|
129
|
-
Hubstats::Repo.all.each do |repo|
|
130
|
-
Hubstats::GithubAPI.update_hook(repo, args[:old_endpoint])
|
131
|
-
end
|
132
|
-
end
|
133
|
-
|
134
|
-
def repo_checker(args)
|
117
|
+
private def repo_checker(args)
|
135
118
|
raise ArgumentError, "Must be called with repo argument. [:org/:repo]" if args.nil?
|
136
119
|
if args.is_a? String
|
137
120
|
return Hubstats::Repo.where(full_name: args).first
|
138
|
-
else
|
121
|
+
else
|
139
122
|
return args
|
140
123
|
end
|
141
124
|
end
|
142
|
-
|
143
125
|
end
|
144
126
|
end
|
data/spec/factories/teams.rb
CHANGED
@@ -16,14 +16,15 @@ FactoryGirl.define do
|
|
16
16
|
name "Team One"
|
17
17
|
hubstats true
|
18
18
|
action "added"
|
19
|
-
|
19
|
+
description "description"
|
20
|
+
initialize_with { attributes }
|
20
21
|
end
|
21
22
|
|
22
|
-
factory :team_payload_hash, class:Hash do
|
23
|
+
factory :team_payload_hash, class:Hash do
|
23
24
|
id {Faker::Number.number(6).to_i}
|
24
25
|
type "MembershipEvent"
|
25
26
|
association :user, factory: :user_hash, strategy: :build
|
26
27
|
association :team, factory: :team_hash, strategy: :build
|
27
|
-
initialize_with { attributes }
|
28
|
-
end
|
28
|
+
initialize_with { attributes }
|
29
|
+
end
|
29
30
|
end
|
@@ -66,7 +66,7 @@ module Hubstats
|
|
66
66
|
payload = build(:comment_payload_hash,
|
67
67
|
:user => {:login=>"hermina", :id=>0, :role=>"User"},
|
68
68
|
:comment => {
|
69
|
-
"id"=>194761,
|
69
|
+
"id"=>194761,
|
70
70
|
"body"=>"Quidem ea minus ut odio optio.",
|
71
71
|
"kind"=>"Issue",
|
72
72
|
"user"=>{},
|
@@ -83,11 +83,11 @@ module Hubstats
|
|
83
83
|
payload = build(:comment_payload_hash,
|
84
84
|
:user => {:login=>"hermina", :id=>0, :role=>"User"},
|
85
85
|
:comment => {
|
86
|
-
"id"=>194761,
|
86
|
+
"id"=>194761,
|
87
87
|
"body"=>"Quidem ea minus ut odio optio.",
|
88
|
-
"kind"=>"Issue",
|
88
|
+
"kind"=>"Issue",
|
89
89
|
"user"=>nil,
|
90
|
-
"created_at" => Date.today,
|
90
|
+
"created_at" => Date.today,
|
91
91
|
"updated_at" => Date.today
|
92
92
|
}
|
93
93
|
)
|
@@ -108,11 +108,12 @@ module Hubstats
|
|
108
108
|
ehandler = Hubstats::EventsHandler.new()
|
109
109
|
payload = build(:team_payload_hash)
|
110
110
|
user = build(:user)
|
111
|
-
allow(Hubstats).to receive_message_chain(:config, :github_config, :[]).with("team_list") { ["Team One", "Team Two", "Team Three"] }
|
112
111
|
allow(payload).to receive(:[]).with(:event).and_return(payload)
|
113
|
-
allow(payload).to receive(:[]).with(:team).and_return({:name => "Team One"})
|
112
|
+
allow(payload).to receive(:[]).with(:team).and_return({:name => "Team One", :description => "Hubstats"})
|
114
113
|
allow(payload).to receive(:[]).with(:member).and_return(user)
|
115
114
|
allow(payload).to receive(:[]).with(:github_action).and_return("added")
|
115
|
+
allow(payload).to receive(:[]).with(:scope).and_return("team")
|
116
|
+
allow(payload).to receive(:[]).with(:action).and_return("added")
|
116
117
|
allow(Hubstats::User).to receive(:create_or_update).and_return(user)
|
117
118
|
expect(Hubstats::Team).to receive(:create_or_update)
|
118
119
|
expect(Hubstats::Team).to receive(:update_users_in_team)
|
@@ -124,12 +125,13 @@ module Hubstats
|
|
124
125
|
payload = build(:team_payload_hash)
|
125
126
|
team = build(:team)
|
126
127
|
user = build(:user)
|
127
|
-
allow(Hubstats).to receive_message_chain(:config, :github_config, :[]).with("team_list") { ["Team One", "Team Two", "Team Three"] }
|
128
128
|
allow(Hubstats::User).to receive(:create_or_update).and_return(user)
|
129
129
|
allow(payload).to receive(:[]).with(:event).and_return(payload)
|
130
|
-
allow(payload).to receive(:[]).with(:team).and_return({:name => "Team One"})
|
130
|
+
allow(payload).to receive(:[]).with(:team).and_return({:name => "Team One", :description => "Hubstats"})
|
131
131
|
allow(payload).to receive(:[]).with(:member).and_return(user)
|
132
132
|
allow(payload).to receive(:[]).with(:github_action).and_return("added")
|
133
|
+
allow(payload).to receive(:[]).with(:scope).and_return("team")
|
134
|
+
allow(payload).to receive(:[]).with(:action).and_return("added")
|
133
135
|
expect(Hubstats::Team).to receive(:update_users_in_team)
|
134
136
|
expect(Hubstats::Team).to receive(:create_or_update).and_return(team)
|
135
137
|
ehandler.route(payload, "MembershipEvent")
|
@@ -70,7 +70,7 @@ module Hubstats
|
|
70
70
|
context '.update_teams' do
|
71
71
|
subject {Hubstats::GithubAPI}
|
72
72
|
let(:org) {'sportngin'}
|
73
|
-
let(:team1) {build(:team_hash, :name => "Team One")}
|
73
|
+
let(:team1) {build(:team_hash, :name => "Team One", description: "hubstats")}
|
74
74
|
let(:team2) {build(:team_hash, :name => "Team Four")}
|
75
75
|
let(:team3) {build(:team_hash, :name => "Team Five")}
|
76
76
|
let(:team4) {build(:team_hash, :name => "Team Six")}
|
@@ -82,12 +82,14 @@ module Hubstats
|
|
82
82
|
let(:hubstats_user) {build(:user)}
|
83
83
|
let(:access_token) { "access_token" }
|
84
84
|
let(:user) { double }
|
85
|
-
let(:
|
85
|
+
let(:octokit_team) {double(:octokit_team)}
|
86
|
+
let(:client) {double(:octokit_client, team: octokit_team, user: user)}
|
86
87
|
|
87
88
|
it 'should successfully update all teams' do
|
88
89
|
allow_message_expectations_on_nil
|
89
90
|
allow(client).to receive(:organization_teams).with("sportngin").and_return([team1, team2, team3, team4])
|
90
91
|
allow(client).to receive(:team_members).with(team1[:id]).and_return([user1, user2, user3])
|
92
|
+
allow(client).to receive(:team).and_return(octokit_team)
|
91
93
|
allow(Hubstats).to receive_message_chain(:config, :github_config, :[]).with("team_list") { ["Team One", "Team Two", "Team Three"] }
|
92
94
|
allow(Hubstats).to receive_message_chain(:config, :github_config, :[]).with("org_name") {"sportngin"}
|
93
95
|
allow(Hubstats::GithubAPI).to receive(:client).and_return(client)
|
@@ -101,44 +103,30 @@ module Hubstats
|
|
101
103
|
end
|
102
104
|
end
|
103
105
|
|
104
|
-
context '.
|
106
|
+
context '.deprecate_teams' do
|
105
107
|
subject {Hubstats::GithubAPI}
|
106
108
|
let(:team1) {create(:team, :name => "Team One")}
|
107
109
|
let(:team2) {create(:team, :name => "Team Two")}
|
108
110
|
let(:team3) {create(:team, :name => "Team Three")}
|
109
111
|
let(:team4) {create(:team, :name => "Team Four")}
|
110
112
|
let(:team5) {create(:team, :name => "Team Five")}
|
113
|
+
let(:octokit_team) {double(:octokit_team, description: "Description for Hubstats")}
|
114
|
+
let(:client) {double(:octokit_client, team: octokit_team)}
|
115
|
+
|
116
|
+
before do
|
117
|
+
allow(octokit_team).to receive(:[]).with(:description).and_return("Description for Hubstats")
|
118
|
+
end
|
111
119
|
|
112
120
|
it 'should update the teams in the database based on a given whitelist' do
|
113
|
-
allow(Hubstats).to receive_message_chain(:config, :github_config, :[]).with("team_list") { ["Team One", "Team Two", "Team Three", "Team Four"] }
|
114
121
|
allow(Hubstats::Team).to receive(:all).and_return( [team1, team2, team3, team4, team5] )
|
122
|
+
allow(client).to receive(:team).and_return(octokit_team)
|
123
|
+
allow(subject).to receive(:client).and_return(client)
|
115
124
|
expect(team5).to receive(:update_column).with(:hubstats, false)
|
116
|
-
subject.
|
117
|
-
end
|
118
|
-
end
|
119
|
-
|
120
|
-
context ".update_hook" do
|
121
|
-
subject {Hubstats::GithubAPI}
|
122
|
-
let(:repo) {'hubstats'}
|
123
|
-
context "with old_endpoint" do
|
124
|
-
let(:old_endpoint) {'www.hubstats.com'}
|
125
|
-
it 'should call delete_hook' do
|
126
|
-
allow(subject).to receive(:create_hook)
|
127
|
-
expect(subject).to receive(:delete_hook).with(repo,old_endpoint)
|
128
|
-
subject.update_hook('hubstats','www.hubstats.com')
|
129
|
-
end
|
130
|
-
end
|
131
|
-
|
132
|
-
context "without old_point" do
|
133
|
-
it 'should not call delete_hook' do
|
134
|
-
allow(subject).to receive(:create_hook)
|
135
|
-
expect(subject).to_not receive(:delete_hook).with(repo)
|
136
|
-
subject.update_hook('hubstats')
|
137
|
-
end
|
125
|
+
subject.deprecate_teams
|
138
126
|
end
|
139
127
|
end
|
140
128
|
|
141
|
-
context ".
|
129
|
+
context ".create_repo_hook" do
|
142
130
|
subject {Hubstats::GithubAPI}
|
143
131
|
let(:config) {double(:webhook_secret => 'a1b2c3d4', :webhook_endpoint => "hubstats.com")}
|
144
132
|
let(:client) {double}
|
@@ -150,12 +138,12 @@ module Hubstats
|
|
150
138
|
|
151
139
|
it "should call octokit create_hook for repositories" do
|
152
140
|
expect(client).to receive(:create_hook)
|
153
|
-
subject.
|
141
|
+
subject.create_repo_hook(repo)
|
154
142
|
end
|
155
143
|
|
156
144
|
it "should rescue unprocessable entity from repo hook" do
|
157
145
|
allow(client).to receive(:create_hook) { raise Octokit::UnprocessableEntity }
|
158
|
-
subject.
|
146
|
+
subject.create_repo_hook(repo)
|
159
147
|
end
|
160
148
|
end
|
161
149
|
|
@@ -169,14 +157,14 @@ module Hubstats
|
|
169
157
|
allow(subject).to receive(:client) {client}
|
170
158
|
end
|
171
159
|
|
172
|
-
it "should call octokit
|
173
|
-
expect(client).to receive(:
|
174
|
-
subject.
|
160
|
+
it "should call octokit create_org_hook for organizations" do
|
161
|
+
expect(client).to receive(:create_org_hook)
|
162
|
+
subject.create_org_hook(org)
|
175
163
|
end
|
176
164
|
|
177
165
|
it "should rescue unprocessable entity from organization hook" do
|
178
|
-
allow(client).to receive(:
|
179
|
-
subject.
|
166
|
+
allow(client).to receive(:create_org_hook) { raise Octokit::UnprocessableEntity }
|
167
|
+
subject.create_org_hook(org)
|
180
168
|
end
|
181
169
|
end
|
182
170
|
|
data/test/dummy/db/schema.rb
CHANGED
@@ -11,19 +11,20 @@
|
|
11
11
|
#
|
12
12
|
# It's strongly recommended that you check this file into your version control system.
|
13
13
|
|
14
|
-
ActiveRecord::Schema.define(version:
|
14
|
+
ActiveRecord::Schema.define(version: 20161222173310) do
|
15
15
|
|
16
16
|
create_table "hubstats_comments", force: :cascade do |t|
|
17
|
-
t.string "html_url", limit: 255
|
18
|
-
t.string "url", limit: 255
|
19
|
-
t.string "pull_request_url", limit: 255
|
20
|
-
t.integer "path", limit: 4
|
21
17
|
t.string "kind", limit: 255
|
22
18
|
t.integer "user_id", limit: 4
|
23
19
|
t.integer "pull_request_id", limit: 4
|
24
20
|
t.integer "repo_id", limit: 4
|
25
21
|
t.datetime "created_at"
|
26
22
|
t.datetime "updated_at"
|
23
|
+
t.string "body_string", limit: 255
|
24
|
+
t.integer "path", limit: 4
|
25
|
+
t.string "html_url", limit: 255
|
26
|
+
t.string "url", limit: 255
|
27
|
+
t.string "pull_request_url", limit: 255
|
27
28
|
t.text "body", limit: 65535
|
28
29
|
end
|
29
30
|
|
@@ -55,21 +56,21 @@ ActiveRecord::Schema.define(version: 20161222173633) do
|
|
55
56
|
add_index "hubstats_labels_pull_requests", ["pull_request_id"], name: "index_hubstats_labels_pull_requests_on_pull_request_id", using: :btree
|
56
57
|
|
57
58
|
create_table "hubstats_pull_requests", force: :cascade do |t|
|
59
|
+
t.integer "number", limit: 4
|
60
|
+
t.integer "user_id", limit: 4
|
61
|
+
t.integer "repo_id", limit: 4
|
62
|
+
t.datetime "created_at"
|
63
|
+
t.datetime "updated_at"
|
64
|
+
t.datetime "closed_at"
|
65
|
+
t.integer "additions", limit: 4
|
66
|
+
t.integer "deletions", limit: 4
|
67
|
+
t.integer "comments", limit: 4
|
58
68
|
t.string "url", limit: 255
|
59
69
|
t.string "html_url", limit: 255
|
60
70
|
t.string "issue_url", limit: 255
|
61
|
-
t.integer "number", limit: 4
|
62
71
|
t.string "state", limit: 255
|
63
72
|
t.string "title", limit: 255
|
64
|
-
t.datetime "created_at", null: false
|
65
|
-
t.datetime "updated_at", null: false
|
66
|
-
t.datetime "closed_at"
|
67
73
|
t.string "merged", limit: 255
|
68
|
-
t.integer "comments", limit: 4
|
69
|
-
t.integer "additions", limit: 4
|
70
|
-
t.integer "deletions", limit: 4
|
71
|
-
t.integer "user_id", limit: 4
|
72
|
-
t.integer "repo_id", limit: 4
|
73
74
|
t.integer "deploy_id", limit: 4
|
74
75
|
t.integer "merged_by", limit: 4
|
75
76
|
t.datetime "merged_at"
|
@@ -94,15 +95,15 @@ ActiveRecord::Schema.define(version: 20161222173633) do
|
|
94
95
|
add_index "hubstats_qa_signoffs", ["user_id"], name: "index_hubstats_qa_signoffs_on_user_id", using: :btree
|
95
96
|
|
96
97
|
create_table "hubstats_repos", force: :cascade do |t|
|
98
|
+
t.integer "owner_id", limit: 4
|
97
99
|
t.string "name", limit: 255
|
98
100
|
t.string "full_name", limit: 255
|
101
|
+
t.datetime "pushed_at"
|
102
|
+
t.datetime "created_at"
|
103
|
+
t.datetime "updated_at"
|
99
104
|
t.string "url", limit: 255
|
100
105
|
t.string "html_url", limit: 255
|
101
106
|
t.string "labels_url", limit: 255
|
102
|
-
t.datetime "pushed_at"
|
103
|
-
t.datetime "created_at", null: false
|
104
|
-
t.datetime "updated_at", null: false
|
105
|
-
t.integer "owner_id", limit: 4
|
106
107
|
end
|
107
108
|
|
108
109
|
add_index "hubstats_repos", ["owner_id"], name: "index_hubstats_repos_on_owner_id", using: :btree
|
@@ -122,12 +123,12 @@ ActiveRecord::Schema.define(version: 20161222173633) do
|
|
122
123
|
|
123
124
|
create_table "hubstats_users", force: :cascade do |t|
|
124
125
|
t.string "login", limit: 255
|
126
|
+
t.string "role", limit: 255
|
127
|
+
t.datetime "created_at"
|
128
|
+
t.datetime "updated_at"
|
125
129
|
t.string "avatar_url", limit: 255
|
126
130
|
t.string "url", limit: 255
|
127
131
|
t.string "html_url", limit: 255
|
128
|
-
t.string "role", limit: 255
|
129
|
-
t.datetime "created_at", null: false
|
130
|
-
t.datetime "updated_at", null: false
|
131
132
|
end
|
132
133
|
|
133
134
|
end
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: hubstats
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 1.0.0.beta
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Elliot Hursh
|
@@ -9,7 +9,7 @@ authors:
|
|
9
9
|
autorequire:
|
10
10
|
bindir: bin
|
11
11
|
cert_chain: []
|
12
|
-
date:
|
12
|
+
date: 2019-01-17 00:00:00.000000000 Z
|
13
13
|
dependencies:
|
14
14
|
- !ruby/object:Gem::Dependency
|
15
15
|
name: rails
|
@@ -402,12 +402,12 @@ required_ruby_version: !ruby/object:Gem::Requirement
|
|
402
402
|
version: '0'
|
403
403
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
404
404
|
requirements:
|
405
|
-
- - "
|
405
|
+
- - ">"
|
406
406
|
- !ruby/object:Gem::Version
|
407
|
-
version:
|
407
|
+
version: 1.3.1
|
408
408
|
requirements: []
|
409
409
|
rubyforge_project:
|
410
|
-
rubygems_version: 2.
|
410
|
+
rubygems_version: 2.7.8
|
411
411
|
signing_key:
|
412
412
|
specification_version: 4
|
413
413
|
summary: Github Statistics
|