hubstats 1.0.0.beta2 → 1.2.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.ruby-version +1 -1
- data/.travis.yml +7 -2
- data/CHANGELOG.markdown +4 -17
- data/MIT-LICENSE +1 -1
- data/app/controllers/hubstats/events_controller.rb +7 -20
- data/app/controllers/hubstats/teams_controller.rb +2 -2
- data/app/models/hubstats/team.rb +8 -0
- data/app/views/hubstats/partials/_footer.html.erb +1 -1
- data/hubstats.gemspec +6 -2
- data/lib/hubstats/events_handler.rb +73 -46
- data/lib/hubstats/github_api.rb +6 -23
- data/lib/hubstats/version.rb +1 -1
- data/lib/tasks/hubstats_tasks.rake +6 -12
- data/lib/tasks/populate_task.rake +9 -26
- data/spec/factories/repo.rb +9 -1
- data/spec/lib/hubstats/events_handler_spec.rb +72 -0
- data/spec/lib/hubstats/github_api_spec.rb +1 -24
- data/spec/spec_helper.rb +3 -1
- data/spec/test_response_patch.rb +14 -0
- metadata +69 -12
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 9e5143e6456771677de3cc90bbe833374cf25fbf5ebb682e39e97ce7118c397e
|
4
|
+
data.tar.gz: a8af23b964e8455c73e9ab2459c8f60741fcc593e9982e399bf386d955febf68
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 1d5fb94663467fd706e1d6c74afa91c61efb097607ad47e8bfe07d6789997dd1a5aa263fe49a3df6ac4c16eca9fa9eb738e3b812f4582f37a9407df0590fc41d
|
7
|
+
data.tar.gz: 89c01859c31a42c1caa47f820475cf83af7335d609ae9734eec9240a07cbc7cc8d027d120485db36320041816dc0186cae945ae03957db6936a2cc642fdcd07b
|
data/.ruby-version
CHANGED
@@ -1 +1 @@
|
|
1
|
-
|
1
|
+
2.6.1
|
data/.travis.yml
CHANGED
@@ -1,19 +1,24 @@
|
|
1
|
-
|
1
|
+
os: linux
|
2
2
|
dist: trusty
|
3
3
|
language: ruby
|
4
4
|
cache: bundler
|
5
|
+
install:
|
6
|
+
- gem install bundler -v 1.17.3
|
7
|
+
- bundle _1.17.3_ install --jobs=3 --retry=3
|
5
8
|
|
6
9
|
branches:
|
7
10
|
only:
|
8
11
|
- master
|
12
|
+
|
9
13
|
rvm:
|
10
14
|
- 2.1
|
11
15
|
- 2.2
|
12
16
|
- 2.3.0
|
17
|
+
- 2.3.3
|
18
|
+
- 2.6.1
|
13
19
|
|
14
20
|
script: bundle exec rspec
|
15
21
|
before_script:
|
16
22
|
- bundle exec rake app:db:create
|
17
23
|
- bundle exec rake app:db:migrate
|
18
24
|
- bundle exec rake app:db:test:prepare
|
19
|
-
|
data/CHANGELOG.markdown
CHANGED
@@ -1,19 +1,6 @@
|
|
1
|
-
####
|
2
|
-
*
|
1
|
+
#### v1.2.1
|
2
|
+
* IS-12226 Update octokit
|
3
3
|
|
4
|
-
> Emma Sax: production-status-check[bot]: https://github.com/sportngin/hubstats/pull/
|
4
|
+
> Emma Sax: production-status-check[bot]: https://github.com/sportngin/hubstats/pull/143
|
5
5
|
|
6
|
-
####
|
7
|
-
* Show 50 items in detailed show pages
|
8
|
-
|
9
|
-
> Emma Sax: Unknown User: https://github.com/sportngin/hubstats/pull/133
|
10
|
-
|
11
|
-
#### v0.12.0
|
12
|
-
#### v0.11.5
|
13
|
-
* Fix bug where adding repositories will break if there are no commits
|
14
|
-
|
15
|
-
> Emma Sax: AJ Stuyvenberg, Unknown User: https://github.com/sportngin/hubstats/pull/131
|
16
|
-
|
17
|
-
#### v0.11.4
|
18
|
-
#### v0.11.3
|
19
|
-
#### v0.11.2
|
6
|
+
#### v1.2.0
|
data/MIT-LICENSE
CHANGED
@@ -10,24 +10,11 @@ module Hubstats
|
|
10
10
|
#
|
11
11
|
# Returns - nothing, but makes a new event
|
12
12
|
def handler
|
13
|
-
|
14
|
-
|
15
|
-
Rails.logger.warn("Webhook received from Github.")
|
16
|
-
puts "Webhook received from Github."
|
17
|
-
|
13
|
+
verify_signature(request)
|
18
14
|
kind = request.headers['X-Github-Event']
|
19
|
-
Rails.logger.warn("Kind of webhook: #{kind}")
|
20
|
-
puts "Kind of webhook: #{kind}"
|
21
|
-
|
22
15
|
event = event_params.with_indifferent_access
|
23
|
-
Rails.logger.warn("Event: #{event}")
|
24
|
-
puts "Event: #{event}"
|
25
|
-
|
26
16
|
raw_parameters = request.request_parameters
|
27
17
|
event[:github_action] = raw_parameters["action"]
|
28
|
-
Rails.logger.warn("Github action: #{event[:github_action]}")
|
29
|
-
puts "Github action: #{event[:github_action]}"
|
30
|
-
|
31
18
|
eventsHandler = Hubstats::EventsHandler.new()
|
32
19
|
eventsHandler.route(event, kind)
|
33
20
|
|
@@ -39,12 +26,12 @@ module Hubstats
|
|
39
26
|
# request - the signature to be checked
|
40
27
|
#
|
41
28
|
# Returns - an error if the signatures don't match
|
42
|
-
|
43
|
-
|
44
|
-
|
45
|
-
|
46
|
-
|
47
|
-
|
29
|
+
private def verify_signature(request)
|
30
|
+
request.body.rewind
|
31
|
+
payload_body = request.body.read
|
32
|
+
signature = 'sha1=' + OpenSSL::HMAC.hexdigest(OpenSSL::Digest.new('sha1'), Hubstats.config.webhook_endpoint, payload_body)
|
33
|
+
return 500, "Signatures didn't match!" unless Rack::Utils.secure_compare(signature, request.env['HTTP_X_HUB_SIGNATURE'])
|
34
|
+
end
|
48
35
|
|
49
36
|
# Private - Allows only these parameters to be added when creating an event
|
50
37
|
#
|
@@ -9,7 +9,7 @@ module Hubstats
|
|
9
9
|
# Returns - the team data
|
10
10
|
def index
|
11
11
|
if params[:query] ## For select 2
|
12
|
-
@teams = Hubstats::Team.where("name LIKE ?", "%#{params[:query]}%").order("name ASC")
|
12
|
+
@teams = Hubstats::Team.where(hubstats: true).where("name LIKE ?", "%#{params[:query]}%").order("name ASC")
|
13
13
|
elsif params[:id]
|
14
14
|
@teams = Hubstats::Team.where(id: params[:id].split(",")).order("name ASC")
|
15
15
|
else
|
@@ -42,7 +42,7 @@ module Hubstats
|
|
42
42
|
@net_additions = Hubstats::PullRequest.merged_in_date_range(@start_date, @end_date).belonging_to_team(@team.id).sum(:additions).to_i -
|
43
43
|
Hubstats::PullRequest.merged_in_date_range(@start_date, @end_date).belonging_to_team(@team.id).sum(:deletions).to_i
|
44
44
|
@additions = Hubstats::PullRequest.merged_in_date_range(@start_date, @end_date).belonging_to_team(@team.id).average(:additions)
|
45
|
-
@deletions = Hubstats::PullRequest.merged_in_date_range(@start_date, @end_date).belonging_to_team(@team.id).average(:deletions)
|
45
|
+
@deletions = Hubstats::PullRequest.merged_in_date_range(@start_date, @end_date).belonging_to_team(@team.id).average(:deletions)
|
46
46
|
|
47
47
|
stats
|
48
48
|
end
|
data/app/models/hubstats/team.rb
CHANGED
@@ -47,6 +47,14 @@ module Hubstats
|
|
47
47
|
|
48
48
|
has_and_belongs_to_many :users, :join_table => 'hubstats_teams_users', :uniq => true
|
49
49
|
|
50
|
+
# Public - Will change the team's hubstats column to false
|
51
|
+
#
|
52
|
+
# Returns - the team
|
53
|
+
def deprecate_team
|
54
|
+
self.update_column(:hubstats, false)
|
55
|
+
self.save!
|
56
|
+
end
|
57
|
+
|
50
58
|
# Public - Checks if the team is currently existing, and if it isn't, then makes a new team with
|
51
59
|
# the specifications that are passed in. We are assuming that if it is not already existent,
|
52
60
|
# then we probably don't really care about the team, so our hubstats boolean will be set to false.
|
data/hubstats.gemspec
CHANGED
@@ -17,11 +17,15 @@ Gem::Specification.new do |s|
|
|
17
17
|
s.test_files = s.files.grep(%r{^(test|spec|features)/})
|
18
18
|
|
19
19
|
s.add_dependency "rails", "~> 4.2.10"
|
20
|
-
s.add_dependency "rake", "
|
21
|
-
s.add_dependency "octokit", "~> 4.
|
20
|
+
s.add_dependency "rake", ">= 12.3.3"
|
21
|
+
s.add_dependency "octokit", "~> 4.18"
|
22
22
|
s.add_dependency "will_paginate-bootstrap", "~> 1.0"
|
23
23
|
s.add_dependency "select2-rails", "~> 3.0"
|
24
24
|
s.add_dependency "sass-rails"
|
25
|
+
s.add_dependency "railties", "~> 4.2.11.1"
|
26
|
+
s.add_dependency "jquery-rails", "= 4.3.3"
|
27
|
+
s.add_dependency "sprockets", "~> 3.7.2"
|
28
|
+
s.add_dependency "sprockets-rails", "~> 2.3.3"
|
25
29
|
s.add_dependency "bootstrap-datepicker-rails", "~> 1.5"
|
26
30
|
|
27
31
|
s.add_development_dependency "mysql2",'~> 0.3.2'
|
@@ -1,6 +1,5 @@
|
|
1
1
|
module Hubstats
|
2
2
|
class EventsHandler
|
3
|
-
|
4
3
|
# Public - Processes comments and PRs
|
5
4
|
#
|
6
5
|
# payload - the data that we will be processing
|
@@ -10,51 +9,46 @@ module Hubstats
|
|
10
9
|
def route(payload, type)
|
11
10
|
case type
|
12
11
|
when "issue_comment", "IssueCommentEvent"
|
13
|
-
comment_processor(payload, "Issue")
|
12
|
+
comment_processor(payload, "Issue") # comment on a pull request
|
14
13
|
when "commit_comment", "CommitCommentEvent"
|
15
|
-
comment_processor(payload, "Commit")
|
16
|
-
when "pull_request", "PullRequestEvent"
|
17
|
-
pull_processor(payload)
|
14
|
+
comment_processor(payload, "Commit") # comment on a pull request commit
|
18
15
|
when "pull_request_review_comment", "PullRequestReviewCommentEvent"
|
19
|
-
comment_processor(payload, "PullRequest")
|
16
|
+
comment_processor(payload, "PullRequest") # comment on a pull request review
|
17
|
+
when "pull_request", "PullRequestEvent"
|
18
|
+
pull_processor(payload) # new pull request
|
20
19
|
when "membership", "MembershipEvent", "team", "TeamEvent"
|
21
|
-
team_processor(payload)
|
20
|
+
team_processor(payload) # adding/editing/deleting/modifying teams
|
22
21
|
when "repository", "RepositoryEvent"
|
23
|
-
repository_processor(payload)
|
22
|
+
repository_processor(payload) # adding repositories
|
24
23
|
end
|
25
24
|
end
|
26
25
|
|
27
|
-
#
|
26
|
+
# Private - Gets the information for the PR, creates/updates the new PR, grabs the labels, and makes new labels;
|
28
27
|
# if the label qa-approved is added or removed, a new QA Signoff record will be made
|
29
28
|
#
|
30
29
|
# payload - the information that we will use to get data off of
|
31
30
|
#
|
32
31
|
# Returns - nothing, but creates/updates the PR and adds appropriate labels
|
33
|
-
def pull_processor(payload)
|
32
|
+
private def pull_processor(payload)
|
34
33
|
pull_request = payload[:pull_request]
|
35
34
|
pull_request[:repository] = payload[:repository]
|
36
35
|
new_pull = Hubstats::PullRequest.create_or_update(pull_request.with_indifferent_access)
|
36
|
+
|
37
37
|
if payload[:github_action].include?('labeled')
|
38
|
-
|
39
|
-
Hubstats::QaSignoff.remove_signoff(payload[:repository][:id], payload[:pull_request][:id])
|
40
|
-
elsif payload[:label][:name].include?('qa-approved')
|
41
|
-
Hubstats::QaSignoff.first_or_create(payload[:repository][:id], payload[:pull_request][:id], payload[:sender][:id])
|
42
|
-
end
|
43
|
-
new_pull.update_label(payload)
|
38
|
+
organize_qa_signoffs(payload, new_pull)
|
44
39
|
else
|
45
|
-
|
46
|
-
labels = Hubstats::GithubAPI.get_labels_for_pull(repo_name, new_pull.number)
|
47
|
-
new_pull.add_labels(labels)
|
40
|
+
add_labels_to_pull(new_pull)
|
48
41
|
end
|
42
|
+
|
49
43
|
new_pull.save!
|
50
44
|
end
|
51
45
|
|
52
|
-
#
|
46
|
+
# Private - Gets the information for the new comment and updates it
|
53
47
|
#
|
54
48
|
# payload - the information that we will use to get data off of
|
55
49
|
#
|
56
50
|
# Returns - nothing, but updates the comment
|
57
|
-
def comment_processor(payload, kind)
|
51
|
+
private def comment_processor(payload, kind)
|
58
52
|
comment = payload[:comment]
|
59
53
|
comment[:kind] = kind
|
60
54
|
comment[:repo_id] = payload[:repository][:id]
|
@@ -62,48 +56,45 @@ module Hubstats
|
|
62
56
|
Hubstats::Comment.create_or_update(comment.with_indifferent_access)
|
63
57
|
end
|
64
58
|
|
65
|
-
#
|
59
|
+
# Private - Gets the information for the team in the payload and updates it appropriately
|
66
60
|
#
|
67
61
|
# payload - the information that we will use to get the data off of
|
68
62
|
#
|
69
63
|
# Returns - nothing, but updates or makes the team
|
70
|
-
def team_processor(payload)
|
71
|
-
team
|
72
|
-
|
73
|
-
|
74
|
-
|
75
|
-
|
76
|
-
|
77
|
-
|
78
|
-
Hubstats::Team.update_users_in_team(hubstats_team, hubstats_user, payload[:github_action])
|
79
|
-
end
|
64
|
+
private def team_processor(payload)
|
65
|
+
# Adding a new hubstats team, adding/removing a person to/from a team, or renaming a team
|
66
|
+
if (payload[:scope] == "team" || payload[:github_action] == "edited") &&
|
67
|
+
Hubstats::Team.designed_for_hubstats?(payload[:team][:description])
|
68
|
+
Hubstats::Team.create_or_update(payload[:team].with_indifferent_access)
|
69
|
+
hubstats_team = Hubstats::Team.where(name: payload[:team][:name]).first
|
70
|
+
hubstats_user = payload[:member] ? Hubstats::User.create_or_update(payload[:member]) : Hubstats::User.create_or_update(payload[:sender])
|
71
|
+
Hubstats::Team.update_users_in_team(hubstats_team, hubstats_user, payload[:github_action])
|
80
72
|
end
|
81
73
|
|
82
|
-
|
83
|
-
|
84
|
-
|
85
|
-
hubstats_user = Hubstats::User.create_or_update(payload[:member])
|
86
|
-
Hubstats::Team.update_users_in_team(hubstats_team, hubstats_user, payload[:github_action])
|
74
|
+
# Deleting a hubstats team
|
75
|
+
if payload[:scope] == "organization" && payload[:github_action] == "removed"
|
76
|
+
deprecate_team(payload)
|
87
77
|
end
|
88
78
|
end
|
89
79
|
|
90
|
-
|
91
|
-
|
92
|
-
|
80
|
+
# Private - Gets the information for the repository in the payload and creates/updates it
|
81
|
+
#
|
82
|
+
# payload - the information that we will use to get the data off of
|
83
|
+
#
|
84
|
+
# Returns - nothing, but updates or makes the repository
|
85
|
+
private def repository_processor(payload)
|
93
86
|
if payload[:github_action] == "created" # it's a new repository
|
94
|
-
Hubstats::Repo.create_or_update
|
95
|
-
Hubstats::GithubAPI.create_repo_hook(
|
96
|
-
# The hook was probably already made when we made the repository,
|
97
|
-
# but we'll put this here just in case
|
87
|
+
Hubstats::Repo.create_or_update(payload[:repository].with_indifferent_access)
|
88
|
+
Hubstats::GithubAPI.create_repo_hook(payload[:repository].with_indifferent_access)
|
98
89
|
end
|
99
90
|
end
|
100
91
|
|
101
|
-
#
|
92
|
+
# Private - Grabs the PR number off of any of the various places it can be
|
102
93
|
#
|
103
94
|
# payload - the thing that we will use to try to attain the PR number
|
104
95
|
#
|
105
96
|
# Returns - the PR number
|
106
|
-
def get_pull_number(payload)
|
97
|
+
private def get_pull_number(payload)
|
107
98
|
if payload[:pull_request]
|
108
99
|
return payload[:pull_request][:number]
|
109
100
|
elsif payload[:issue]
|
@@ -114,5 +105,41 @@ module Hubstats
|
|
114
105
|
return nil
|
115
106
|
end
|
116
107
|
end
|
108
|
+
|
109
|
+
# Private - Will add QA signoffs to a pull request if they're present
|
110
|
+
#
|
111
|
+
# payload - data that we can add signoffs to
|
112
|
+
# new_pull - the pull request we just made or updated
|
113
|
+
#
|
114
|
+
# Returns - nothing
|
115
|
+
private def organize_qa_signoffs(payload, new_pull)
|
116
|
+
if payload[:github_action].include?('unlabeled') && payload[:label][:name].include?('qa-approved')
|
117
|
+
Hubstats::QaSignoff.remove_signoff(payload[:repository][:id], payload[:pull_request][:id])
|
118
|
+
elsif payload[:label][:name].include?('qa-approved')
|
119
|
+
Hubstats::QaSignoff.first_or_create(payload[:repository][:id], payload[:pull_request][:id], payload[:sender][:id])
|
120
|
+
end
|
121
|
+
new_pull.update_label(payload)
|
122
|
+
end
|
123
|
+
|
124
|
+
# Private - Will add labels to pull requests
|
125
|
+
#
|
126
|
+
# new_pull - the pull request we just made or updated
|
127
|
+
#
|
128
|
+
# Returns - nothing
|
129
|
+
private def add_labels_to_pull(new_pull)
|
130
|
+
repo_name = Hubstats::Repo.where(id: new_pull.repo_id).first.full_name
|
131
|
+
labels = Hubstats::GithubAPI.get_labels_for_pull(repo_name, new_pull.number)
|
132
|
+
new_pull.add_labels(labels)
|
133
|
+
end
|
134
|
+
|
135
|
+
# Private - Will deprecate the team if it is in the DB and needs to be deprecated
|
136
|
+
#
|
137
|
+
# payload - data that we can add signoffs to
|
138
|
+
#
|
139
|
+
# Returns - nothing
|
140
|
+
private def deprecate_team(payload)
|
141
|
+
hubstats_team = Hubstats::Team.where(name: payload[:team][:name]).first
|
142
|
+
hubstats_team.deprecate_team if (hubstats_team && hubstats_team[:hubstats])
|
143
|
+
end
|
117
144
|
end
|
118
145
|
end
|
data/lib/hubstats/github_api.rb
CHANGED
@@ -122,34 +122,17 @@ module Hubstats
|
|
122
122
|
end
|
123
123
|
end
|
124
124
|
|
125
|
-
# Public - Goes through entire team database and updates the hubstats boolean based on the octokit.yml file
|
126
|
-
#
|
127
|
-
# Returns - nothing
|
128
|
-
def self.deprecate_teams
|
129
|
-
teams = Hubstats::Team.all
|
130
|
-
|
131
|
-
teams.each do |team|
|
132
|
-
desc = client.team(team.id)[:description]
|
133
|
-
if Hubstats::Team.designed_for_hubstats?(desc) && (team[:hubstats] == true)
|
134
|
-
team.update_column(:hubstats, false)
|
135
|
-
team.save!
|
136
|
-
puts "Changed #{team[:name]} from true to false"
|
137
|
-
end
|
138
|
-
end
|
139
|
-
|
140
|
-
puts "All teams are up to date"
|
141
|
-
puts "Run 'rake hubstats:update_teams' or 'rake hubstats:update_teams_in_pulls' to grab more teams from GitHub"
|
142
|
-
end
|
143
|
-
|
144
125
|
# Public - Makes a new webhook from a repository
|
145
126
|
#
|
146
127
|
# repo - the repository that is attempting to have a hook made with
|
147
128
|
#
|
148
129
|
# Returns - the hook and a message (or just a message and no hook)
|
149
130
|
def self.create_repo_hook(repo)
|
131
|
+
repo_name = repo[:full_name] ? repo[:full_name] : repo.full_name
|
132
|
+
puts "Repo that we're going to make a hook on: #{repo_name}"
|
150
133
|
begin
|
151
134
|
client.create_hook(
|
152
|
-
|
135
|
+
repo_name,
|
153
136
|
'web',
|
154
137
|
{
|
155
138
|
:url => Hubstats.config.webhook_endpoint,
|
@@ -161,11 +144,11 @@ module Hubstats
|
|
161
144
|
:active => true
|
162
145
|
}
|
163
146
|
)
|
164
|
-
puts "Hook on #{
|
147
|
+
puts "Hook on #{repo_name} successfully created"
|
165
148
|
rescue Octokit::UnprocessableEntity
|
166
|
-
puts "Hook on #{
|
149
|
+
puts "Hook on #{repo_name} already existed"
|
167
150
|
rescue Octokit::NotFound
|
168
|
-
puts "You don't have sufficient privileges to add an event hook to #{
|
151
|
+
puts "You don't have sufficient privileges to add an event hook to #{repo_name}"
|
169
152
|
end
|
170
153
|
end
|
171
154
|
|
data/lib/hubstats/version.rb
CHANGED
@@ -18,18 +18,18 @@ namespace :hubstats do
|
|
18
18
|
Rake::Task['hubstats:setup'].invoke
|
19
19
|
end
|
20
20
|
|
21
|
-
desc "Updates changes to the config file"
|
22
|
-
task :update => :environment do
|
23
|
-
puts "Updating repos and teams"
|
24
|
-
Rake::Task['hubstats:populate:update'].invoke
|
25
|
-
end
|
26
|
-
|
27
21
|
desc "Updates the seed"
|
28
22
|
task :seed => :environment do
|
29
23
|
puts "Updating seed"
|
30
24
|
Rake::Task['db:seed'].invoke
|
31
25
|
end
|
32
26
|
|
27
|
+
desc "Updates changes to the config file"
|
28
|
+
task :update => :environment do
|
29
|
+
puts "Updating repos and teams"
|
30
|
+
Rake::Task['hubstats:populate:update'].invoke
|
31
|
+
end
|
32
|
+
|
33
33
|
desc "Updates the teams for past pull requests"
|
34
34
|
task :update_teams_in_pulls => :environment do
|
35
35
|
puts "Updating teams for past pull requests"
|
@@ -42,12 +42,6 @@ namespace :hubstats do
|
|
42
42
|
Rake::Task['hubstats:populate:update_teams'].invoke
|
43
43
|
end
|
44
44
|
|
45
|
-
desc "Deprecates teams"
|
46
|
-
task :deprecate_teams => :environment do
|
47
|
-
puts "Deprecating teams"
|
48
|
-
Rake::Task['hubstats:populate:deprecate_teams'].invoke
|
49
|
-
end
|
50
|
-
|
51
45
|
desc "Creates webhook from github for organization"
|
52
46
|
task :make_org_webhook => :environment do
|
53
47
|
puts "Making a webhook for an organization in octokit.yml"
|
@@ -33,7 +33,7 @@ namespace :hubstats do
|
|
33
33
|
|
34
34
|
desc "Updates teams for past pull requests"
|
35
35
|
task :update_teams_in_pulls => :environment do
|
36
|
-
|
36
|
+
Hubstats::PullRequest.update_teams_in_pulls(365)
|
37
37
|
end
|
38
38
|
|
39
39
|
desc "Updates the teams"
|
@@ -41,21 +41,8 @@ namespace :hubstats do
|
|
41
41
|
update_teams
|
42
42
|
end
|
43
43
|
|
44
|
-
desc "Deprecates teams"
|
45
|
-
task :deprecate_teams => :environment do
|
46
|
-
Hubstats::GithubAPI.deprecate_teams
|
47
|
-
end
|
48
|
-
|
49
44
|
desc "Creates the webhook for the current org"
|
50
45
|
task :create_organization_hook => :environment do
|
51
|
-
create_org_hook
|
52
|
-
end
|
53
|
-
|
54
|
-
task :create_org_hook => :environment do
|
55
|
-
create_org_hook
|
56
|
-
end
|
57
|
-
|
58
|
-
private def create_org_hook
|
59
46
|
Hubstats::GithubAPI.create_org_hook(Hubstats.config.github_config["org_name"])
|
60
47
|
end
|
61
48
|
|
@@ -70,6 +57,14 @@ namespace :hubstats do
|
|
70
57
|
# populate_labels(repo)
|
71
58
|
end
|
72
59
|
|
60
|
+
private def update_pulls
|
61
|
+
Hubstats::GithubAPI.update_pulls
|
62
|
+
end
|
63
|
+
|
64
|
+
private def update_teams
|
65
|
+
Hubstats::GithubAPI.update_teams
|
66
|
+
end
|
67
|
+
|
73
68
|
private def populate_users(repo)
|
74
69
|
repo = repo_checker(repo)
|
75
70
|
puts "Adding contributors to " + repo.full_name
|
@@ -102,18 +97,6 @@ namespace :hubstats do
|
|
102
97
|
Hubstats::GithubAPI.add_labels(repo)
|
103
98
|
end
|
104
99
|
|
105
|
-
private def update_pulls
|
106
|
-
Hubstats::GithubAPI.update_pulls
|
107
|
-
end
|
108
|
-
|
109
|
-
private def update_teams
|
110
|
-
Hubstats::GithubAPI.update_teams
|
111
|
-
end
|
112
|
-
|
113
|
-
private def update_teams_in_prs
|
114
|
-
Hubstats::PullRequest.update_teams_in_pulls(365)
|
115
|
-
end
|
116
|
-
|
117
100
|
private def repo_checker(args)
|
118
101
|
raise ArgumentError, "Must be called with repo argument. [:org/:repo]" if args.nil?
|
119
102
|
if args.is_a? String
|
data/spec/factories/repo.rb
CHANGED
@@ -11,6 +11,14 @@ FactoryGirl.define do
|
|
11
11
|
id 101010
|
12
12
|
name "Hubstats"
|
13
13
|
full_name "hub/hubstats"
|
14
|
-
initialize_with { attributes }
|
14
|
+
initialize_with { attributes }
|
15
|
+
end
|
16
|
+
|
17
|
+
factory :repo_payload_hash, class:Hash do
|
18
|
+
id {Faker::Number.number(6).to_i}
|
19
|
+
type "RepositoryEvent"
|
20
|
+
association :user, factory: :user_hash, strategy: :build
|
21
|
+
association :repo, factory: :repo_hash, strategy: :build
|
22
|
+
initialize_with { attributes }
|
15
23
|
end
|
16
24
|
end
|
@@ -136,7 +136,79 @@ module Hubstats
|
|
136
136
|
expect(Hubstats::Team).to receive(:create_or_update).and_return(team)
|
137
137
|
ehandler.route(payload, "MembershipEvent")
|
138
138
|
end
|
139
|
+
|
140
|
+
it 'should successfully remove a member from a team' do
|
141
|
+
ehandler = Hubstats::EventsHandler.new()
|
142
|
+
payload = build(:team_payload_hash)
|
143
|
+
team = build(:team)
|
144
|
+
user = build(:user)
|
145
|
+
allow(Hubstats::User).to receive(:create_or_update).and_return(user)
|
146
|
+
allow(payload).to receive(:[]).with(:event).and_return(payload)
|
147
|
+
allow(payload).to receive(:[]).with(:team).and_return({:name => "Team One", :description => "Hubstats"})
|
148
|
+
allow(payload).to receive(:[]).with(:member).and_return(user)
|
149
|
+
allow(payload).to receive(:[]).with(:github_action).and_return("removed")
|
150
|
+
allow(payload).to receive(:[]).with(:scope).and_return("team")
|
151
|
+
allow(payload).to receive(:[]).with(:action).and_return("removed")
|
152
|
+
expect(Hubstats::Team).to receive(:update_users_in_team)
|
153
|
+
expect(Hubstats::Team).to receive(:create_or_update).and_return(team)
|
154
|
+
ehandler.route(payload, "MembershipEvent")
|
155
|
+
end
|
156
|
+
|
157
|
+
it 'should successfully delete a team' do
|
158
|
+
ehandler = Hubstats::EventsHandler.new()
|
159
|
+
payload = build(:team_payload_hash)
|
160
|
+
team = build(:team)
|
161
|
+
user = build(:user)
|
162
|
+
allow(Hubstats::User).to receive(:create_or_update).and_return(user)
|
163
|
+
allow(payload).to receive(:[]).with(:event).and_return(payload)
|
164
|
+
allow(payload).to receive(:[]).with(:team).and_return({:name => "Team One", :description => "Hubstats"})
|
165
|
+
allow(payload).to receive(:[]).with(:member).and_return(user)
|
166
|
+
allow(payload).to receive(:[]).with(:github_action).and_return("removed")
|
167
|
+
allow(payload).to receive(:[]).with(:scope).and_return("organization")
|
168
|
+
allow(payload).to receive(:[]).with(:action).and_return("removed")
|
169
|
+
expect(Hubstats::Team).not_to receive(:update_users_in_team)
|
170
|
+
expect(Hubstats::Team).not_to receive(:create_or_update)
|
171
|
+
ehandler.route(payload, "MembershipEvent")
|
172
|
+
end
|
173
|
+
|
174
|
+
it 'should successfully rename a team' do
|
175
|
+
ehandler = Hubstats::EventsHandler.new()
|
176
|
+
payload = build(:team_payload_hash)
|
177
|
+
team = build(:team)
|
178
|
+
user = build(:user)
|
179
|
+
allow(Hubstats::User).to receive(:create_or_update).and_return(user)
|
180
|
+
allow(payload).to receive(:[]).with(:event).and_return(payload)
|
181
|
+
allow(payload).to receive(:[]).with(:team).and_return({:name => "Team One", :description => "Hubstats"})
|
182
|
+
allow(payload).to receive(:[]).with(:sender).and_return(user)
|
183
|
+
allow(payload).to receive(:[]).with(:member).and_return(nil)
|
184
|
+
allow(payload).to receive(:[]).with(:scope).and_return(nil)
|
185
|
+
allow(payload).to receive(:[]).with(:github_action).and_return("edited")
|
186
|
+
allow(payload).to receive(:[]).with(:action).and_return("edited")
|
187
|
+
expect(Hubstats::Team).to receive(:update_users_in_team)
|
188
|
+
expect(Hubstats::Team).to receive(:create_or_update).and_return(team)
|
189
|
+
ehandler.route(payload, "MembershipEvent")
|
190
|
+
end
|
139
191
|
end
|
140
192
|
|
193
|
+
context "RepositoryEvent" do
|
194
|
+
it 'should successfully route the repository' do
|
195
|
+
ehandler = EventsHandler.new()
|
196
|
+
payload = build(:repo_payload_hash)
|
197
|
+
expect(ehandler).to receive(:repository_processor)
|
198
|
+
ehandler.route(payload, payload[:type])
|
199
|
+
end
|
200
|
+
|
201
|
+
it 'should successfully process the repository' do
|
202
|
+
ehandler = Hubstats::EventsHandler.new()
|
203
|
+
payload = build(:repo_payload_hash)
|
204
|
+
allow(payload).to receive(:[]).with(:event).and_return(payload)
|
205
|
+
allow(payload).to receive(:[]).with(:repository).and_return({:full_name => "sportngin/test"})
|
206
|
+
allow(payload).to receive(:[]).with(:github_action).and_return("created")
|
207
|
+
allow(payload).to receive(:[]).with(:action).and_return("created")
|
208
|
+
expect(Hubstats::Repo).to receive(:create_or_update)
|
209
|
+
expect(Hubstats::GithubAPI).to receive(:create_repo_hook).and_return(true)
|
210
|
+
ehandler.route(payload, "RepositoryEvent")
|
211
|
+
end
|
212
|
+
end
|
141
213
|
end
|
142
214
|
end
|
@@ -103,29 +103,6 @@ module Hubstats
|
|
103
103
|
end
|
104
104
|
end
|
105
105
|
|
106
|
-
context '.deprecate_teams' do
|
107
|
-
subject {Hubstats::GithubAPI}
|
108
|
-
let(:team1) {create(:team, :name => "Team One")}
|
109
|
-
let(:team2) {create(:team, :name => "Team Two")}
|
110
|
-
let(:team3) {create(:team, :name => "Team Three")}
|
111
|
-
let(:team4) {create(:team, :name => "Team Four")}
|
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
|
119
|
-
|
120
|
-
it 'should update the teams in the database based on a given whitelist' do
|
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)
|
124
|
-
expect(team5).to receive(:update_column).with(:hubstats, false)
|
125
|
-
subject.deprecate_teams
|
126
|
-
end
|
127
|
-
end
|
128
|
-
|
129
106
|
context ".create_repo_hook" do
|
130
107
|
subject {Hubstats::GithubAPI}
|
131
108
|
let(:config) {double(:webhook_secret => 'a1b2c3d4', :webhook_endpoint => "hubstats.com")}
|
@@ -134,6 +111,7 @@ module Hubstats
|
|
134
111
|
before do
|
135
112
|
allow(Hubstats).to receive(:config) {config}
|
136
113
|
allow(subject).to receive(:client) {client}
|
114
|
+
allow(repo).to receive(:[]).with(:full_name)
|
137
115
|
end
|
138
116
|
|
139
117
|
it "should call octokit create_hook for repositories" do
|
@@ -167,6 +145,5 @@ module Hubstats
|
|
167
145
|
subject.create_org_hook(org)
|
168
146
|
end
|
169
147
|
end
|
170
|
-
|
171
148
|
end
|
172
149
|
end
|
data/spec/spec_helper.rb
CHANGED
@@ -4,6 +4,8 @@ require File.expand_path("../../test/dummy/config/environment", __FILE__)
|
|
4
4
|
require 'rspec/rails'
|
5
5
|
require 'factory_girl_rails'
|
6
6
|
require 'faker'
|
7
|
+
require 'test_response_patch'
|
8
|
+
|
7
9
|
# Requires supporting ruby files with custom matchers and macros, etc, in
|
8
10
|
# spec/support/ and its subdirectories. Files matching `spec/**/*_spec.rb` are
|
9
11
|
# run as spec files by default. This means that files in spec/support that end
|
@@ -23,7 +25,7 @@ RSpec.configure do |config|
|
|
23
25
|
# config.mock_with :rr
|
24
26
|
|
25
27
|
config.include FactoryGirl::Syntax::Methods
|
26
|
-
|
28
|
+
|
27
29
|
# Remove this line if you're not using ActiveRecord or ActiveRecord fixtures
|
28
30
|
# config.fixture_path = "#{::Rails.root}/spec/fixtures"
|
29
31
|
|
@@ -0,0 +1,14 @@
|
|
1
|
+
# The suggestion for this file is from: https://github.com/rails/rails/issues/34790
|
2
|
+
if RUBY_VERSION >= '2.6.0'
|
3
|
+
if Rails.version < '5'
|
4
|
+
class ActionController::TestResponse < ActionDispatch::TestResponse
|
5
|
+
def recycle!
|
6
|
+
@mon_mutex_owner_object_id = nil
|
7
|
+
@mon_mutex = nil
|
8
|
+
initialize
|
9
|
+
end
|
10
|
+
end
|
11
|
+
else
|
12
|
+
raise 'This monkey patch is no longer needed. Please remove this.'
|
13
|
+
end
|
14
|
+
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: 1.
|
4
|
+
version: 1.2.1
|
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: 2020-06-12 00:00:00.000000000 Z
|
13
13
|
dependencies:
|
14
14
|
- !ruby/object:Gem::Dependency
|
15
15
|
name: rails
|
@@ -29,30 +29,30 @@ dependencies:
|
|
29
29
|
name: rake
|
30
30
|
requirement: !ruby/object:Gem::Requirement
|
31
31
|
requirements:
|
32
|
-
- -
|
32
|
+
- - ">="
|
33
33
|
- !ruby/object:Gem::Version
|
34
|
-
version: 12.3.
|
34
|
+
version: 12.3.3
|
35
35
|
type: :runtime
|
36
36
|
prerelease: false
|
37
37
|
version_requirements: !ruby/object:Gem::Requirement
|
38
38
|
requirements:
|
39
|
-
- -
|
39
|
+
- - ">="
|
40
40
|
- !ruby/object:Gem::Version
|
41
|
-
version: 12.3.
|
41
|
+
version: 12.3.3
|
42
42
|
- !ruby/object:Gem::Dependency
|
43
43
|
name: octokit
|
44
44
|
requirement: !ruby/object:Gem::Requirement
|
45
45
|
requirements:
|
46
46
|
- - "~>"
|
47
47
|
- !ruby/object:Gem::Version
|
48
|
-
version: '4.
|
48
|
+
version: '4.18'
|
49
49
|
type: :runtime
|
50
50
|
prerelease: false
|
51
51
|
version_requirements: !ruby/object:Gem::Requirement
|
52
52
|
requirements:
|
53
53
|
- - "~>"
|
54
54
|
- !ruby/object:Gem::Version
|
55
|
-
version: '4.
|
55
|
+
version: '4.18'
|
56
56
|
- !ruby/object:Gem::Dependency
|
57
57
|
name: will_paginate-bootstrap
|
58
58
|
requirement: !ruby/object:Gem::Requirement
|
@@ -95,6 +95,62 @@ dependencies:
|
|
95
95
|
- - ">="
|
96
96
|
- !ruby/object:Gem::Version
|
97
97
|
version: '0'
|
98
|
+
- !ruby/object:Gem::Dependency
|
99
|
+
name: railties
|
100
|
+
requirement: !ruby/object:Gem::Requirement
|
101
|
+
requirements:
|
102
|
+
- - "~>"
|
103
|
+
- !ruby/object:Gem::Version
|
104
|
+
version: 4.2.11.1
|
105
|
+
type: :runtime
|
106
|
+
prerelease: false
|
107
|
+
version_requirements: !ruby/object:Gem::Requirement
|
108
|
+
requirements:
|
109
|
+
- - "~>"
|
110
|
+
- !ruby/object:Gem::Version
|
111
|
+
version: 4.2.11.1
|
112
|
+
- !ruby/object:Gem::Dependency
|
113
|
+
name: jquery-rails
|
114
|
+
requirement: !ruby/object:Gem::Requirement
|
115
|
+
requirements:
|
116
|
+
- - '='
|
117
|
+
- !ruby/object:Gem::Version
|
118
|
+
version: 4.3.3
|
119
|
+
type: :runtime
|
120
|
+
prerelease: false
|
121
|
+
version_requirements: !ruby/object:Gem::Requirement
|
122
|
+
requirements:
|
123
|
+
- - '='
|
124
|
+
- !ruby/object:Gem::Version
|
125
|
+
version: 4.3.3
|
126
|
+
- !ruby/object:Gem::Dependency
|
127
|
+
name: sprockets
|
128
|
+
requirement: !ruby/object:Gem::Requirement
|
129
|
+
requirements:
|
130
|
+
- - "~>"
|
131
|
+
- !ruby/object:Gem::Version
|
132
|
+
version: 3.7.2
|
133
|
+
type: :runtime
|
134
|
+
prerelease: false
|
135
|
+
version_requirements: !ruby/object:Gem::Requirement
|
136
|
+
requirements:
|
137
|
+
- - "~>"
|
138
|
+
- !ruby/object:Gem::Version
|
139
|
+
version: 3.7.2
|
140
|
+
- !ruby/object:Gem::Dependency
|
141
|
+
name: sprockets-rails
|
142
|
+
requirement: !ruby/object:Gem::Requirement
|
143
|
+
requirements:
|
144
|
+
- - "~>"
|
145
|
+
- !ruby/object:Gem::Version
|
146
|
+
version: 2.3.3
|
147
|
+
type: :runtime
|
148
|
+
prerelease: false
|
149
|
+
version_requirements: !ruby/object:Gem::Requirement
|
150
|
+
requirements:
|
151
|
+
- - "~>"
|
152
|
+
- !ruby/object:Gem::Version
|
153
|
+
version: 2.3.3
|
98
154
|
- !ruby/object:Gem::Dependency
|
99
155
|
name: bootstrap-datepicker-rails
|
100
156
|
requirement: !ruby/object:Gem::Requirement
|
@@ -365,6 +421,7 @@ files:
|
|
365
421
|
- spec/models/hubstats/team_spec.rb
|
366
422
|
- spec/models/hubstats/user_spec.rb
|
367
423
|
- spec/spec_helper.rb
|
424
|
+
- spec/test_response_patch.rb
|
368
425
|
- test/dummy/README.rdoc
|
369
426
|
- test/dummy/Rakefile
|
370
427
|
- test/dummy/app/assets/javascripts/application.js
|
@@ -416,12 +473,11 @@ required_ruby_version: !ruby/object:Gem::Requirement
|
|
416
473
|
version: '0'
|
417
474
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
418
475
|
requirements:
|
419
|
-
- - "
|
476
|
+
- - ">="
|
420
477
|
- !ruby/object:Gem::Version
|
421
|
-
version:
|
478
|
+
version: '0'
|
422
479
|
requirements: []
|
423
|
-
|
424
|
-
rubygems_version: 2.7.8
|
480
|
+
rubygems_version: 3.0.1
|
425
481
|
signing_key:
|
426
482
|
specification_version: 4
|
427
483
|
summary: Github Statistics
|
@@ -454,6 +510,7 @@ test_files:
|
|
454
510
|
- spec/models/hubstats/team_spec.rb
|
455
511
|
- spec/models/hubstats/user_spec.rb
|
456
512
|
- spec/spec_helper.rb
|
513
|
+
- spec/test_response_patch.rb
|
457
514
|
- test/dummy/README.rdoc
|
458
515
|
- test/dummy/Rakefile
|
459
516
|
- test/dummy/app/assets/javascripts/application.js
|