hubstats 1.0.0.beta3 → 1.0.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 8dd2a31cc4f6046f0d1bee94391a1f60378a76388d2d426ab6b8d51ee452f2dc
4
- data.tar.gz: 63999cfe6eb363c30ebc0acabe655dd2723e61a89397512221f4053cc6fe93b0
3
+ metadata.gz: 38c2e3ab11afad78ae1b32adb8c86347994f631dad92d1743fee058b274cb223
4
+ data.tar.gz: ac247c511194a97ca832cdb187deec8bcc455d471bcb7623084fb00d84cee981
5
5
  SHA512:
6
- metadata.gz: a0788fe29b54206591a28897cc24f8f58a2abb40a2974a0e919f7620bf09f242efd76f5add24a564f1a9b2891a821b5882bb62db396b401fb8538778caf49b35
7
- data.tar.gz: 119420b7746fe73dad252ed7954124ae2b9cd3bc9ef0dd9f48d3933edd7f1899dec38aeeba565bb1656fc248ee2d3559a426670e0835a190f37577875e69822f
6
+ metadata.gz: 9ce368ce4622af5d95f88df7a68cbadd98005a9e728778460393bcc5f0630b0277d1f8e8d86208787a5d83944058ff6d887358d50af70327d4d311ee39c481ec
7
+ data.tar.gz: 01e8a072cbaaf37de5210022cf528b666b6d2dec87e76215b44e1fcd42775114aced9174e044ba217ee019f1e62f71078b283a05b2155cbb577bfeea7c2759b6
@@ -1,3 +1,8 @@
1
+ #### v1.0.0
2
+ * Be able to load repositories and teams from webhooks
3
+
4
+ > Emma Sax, Carl Allen: production-status-check[bot]: https://github.com/sportngin/hubstats/pull/138
5
+
1
6
  #### v0.12.2
2
7
  * Fix bug that results in comments never being saved
3
8
 
@@ -1,6 +1,6 @@
1
1
  The MIT License (MIT)
2
2
 
3
- Copyright 2015 Sport Ngin
3
+ Copyright 2019 Sport Ngin
4
4
 
5
5
  Permission is hereby granted, free of charge, to any person obtaining
6
6
  a copy of this software and associated documentation files (the
@@ -10,24 +10,11 @@ module Hubstats
10
10
  #
11
11
  # Returns - nothing, but makes a new event
12
12
  def handler
13
- # verify_signature(request)
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
- # private def verify_signature(request)
43
- # request.body.rewind
44
- # payload_body = request.body.read
45
- # signature = 'sha1=' + OpenSSL::HMAC.hexdigest(OpenSSL::Digest.new('sha1'), Hubstats.config.webhook_endpoint, payload_body)
46
- # return 500, "Signatures didn't match!" unless Rack::Utils.secure_compare(signature, request.env['HTTP_X_HUB_SIGNATURE'])
47
- # end
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
@@ -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.
@@ -4,7 +4,7 @@
4
4
  <div class="col-lg-3 col-md-3 col-sm-3">
5
5
  <!-- Show the Sport Ngin copyright information, change if using a different copyright -->
6
6
  <div class="footer-text">
7
- © 2015 Sport Ngin
7
+ © 2019 Sport Ngin
8
8
  </div>
9
9
  </div>
10
10
  <div class="col-lg-6 col-md-6 col-sm-6">
@@ -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
- # Public - Gets the information for the PR, creates/updates the new PR, grabs the labels, and makes new labels;
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
- if payload[:github_action].include?('unlabeled') && payload[:label][:name].include?('qa-approved')
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
- repo_name = Hubstats::Repo.where(id: new_pull.repo_id).first.full_name
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
- # Public - Gets the information for the new comment and updates it
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
- # Public - Gets the information for the new team and updates it
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 = payload[:team]
72
-
73
- if payload[:scope] == "team" && payload[:github_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
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
- if payload[:github_action] == "edited" && Hubstats::Team.designed_for_hubstats?(team[:description])
83
- Hubstats::Team.create_or_update(team.with_indifferent_access)
84
- hubstats_team = Hubstats::Team.where(name: team[:name]).first
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
- def repository_processor(payload)
91
- repo = payload[:repository]
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(repo.with_indifferent_access)
95
- Hubstats::GithubAPI.create_repo_hook(repo.with_indifferent_access)
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
- # Public - Grabs the PR number off of any of the various places it can be
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
@@ -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
- repo.full_name,
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 #{repo.full_name} successfully created"
147
+ puts "Hook on #{repo_name} successfully created"
165
148
  rescue Octokit::UnprocessableEntity
166
- puts "Hook on #{repo.full_name} already existed"
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 #{repo.full_name}"
151
+ puts "You don't have sufficient privileges to add an event hook to #{repo_name}"
169
152
  end
170
153
  end
171
154
 
@@ -1,3 +1,3 @@
1
1
  module Hubstats
2
- VERSION = "1.0.0.beta3"
2
+ VERSION = "1.0.0"
3
3
  end
@@ -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
- update_teams_in_prs
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
@@ -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
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.0.0.beta3
4
+ version: 1.0.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Elliot Hursh
@@ -416,9 +416,9 @@ required_ruby_version: !ruby/object:Gem::Requirement
416
416
  version: '0'
417
417
  required_rubygems_version: !ruby/object:Gem::Requirement
418
418
  requirements:
419
- - - ">"
419
+ - - ">="
420
420
  - !ruby/object:Gem::Version
421
- version: 1.3.1
421
+ version: '0'
422
422
  requirements: []
423
423
  rubyforge_project:
424
424
  rubygems_version: 2.7.8