hubstats 0.7.4 → 0.7.5
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.soyuz.yml +1 -1
- data/CHANGELOG.markdown +5 -0
- data/app/models/hubstats/pull_request.rb +20 -6
- data/lib/hubstats/events_handler.rb +10 -5
- data/lib/hubstats/github_api.rb +1 -1
- data/lib/hubstats/version.rb +1 -1
- data/spec/factories/pull_requests.rb +1 -0
- data/spec/lib/hubstats/events_handler_spec.rb +22 -2
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: fd6afdc60bb321ead7ca1d88abf2ef0c7dc0b0f3
|
4
|
+
data.tar.gz: c8cdaa2df2c12b307931b5ebadcbe29270208747
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 82f465b50ec0e8e2ecbd5672fb055e4c87efc3f29eb8a5bbf2c6ad25a77b0d3c6a010728f150fc457de93469cafc874ff94e965a6181dddbdc1de7cf295c033f
|
7
|
+
data.tar.gz: 7f5c3e6b305282393fd98d690c701d2f40c7f87ad8f1c7daed57e25d9779194e6f4f8ca4a5577778f29542745a0eb57c481abac1c0ceec6b6737e8979b270ff2
|
data/.soyuz.yml
CHANGED
@@ -2,7 +2,7 @@ defaults:
|
|
2
2
|
deploy_cmd: gem push *.gem
|
3
3
|
before_deploy_cmds:
|
4
4
|
- /usr/local/bin/op tag-release
|
5
|
-
- sed -i "" -e "s/\".*/\"$(git tag| sort -n -t. -k1,1 -k2,2 -k3,3 | tail -1
|
5
|
+
- sed -i "" -e "s/\".*/\"$(git tag| sed s/v// | sort -n -t. -k1,1 -k2,2 -k3,3 | tail -1)\"/" lib/hubstats/version.rb
|
6
6
|
- git add lib/hubstats/version.rb
|
7
7
|
- git commit -m "Version Bump" && git push
|
8
8
|
- gem build hubstats.gemspec
|
data/CHANGELOG.markdown
CHANGED
@@ -27,7 +27,7 @@ module Hubstats
|
|
27
27
|
belongs_to :repo
|
28
28
|
belongs_to :deploy
|
29
29
|
belongs_to :team
|
30
|
-
has_and_belongs_to_many :labels, :join_table => "hubstats_labels_pull_requests"
|
30
|
+
has_and_belongs_to_many :labels, ->{ uniq }, :join_table => "hubstats_labels_pull_requests"
|
31
31
|
|
32
32
|
# Public - Makes a new pull request from a GitHub webhook. Finds user_id and repo_id based on users and repos
|
33
33
|
# that are already in the Hubstats database. Updates the user_id of a deploy if the pull request has been merged in a deploy.
|
@@ -54,10 +54,10 @@ module Hubstats
|
|
54
54
|
if github_pull[:merged_by] && github_pull[:merged_by][:id]
|
55
55
|
pull_data[:merged_by] = github_pull[:merged_by][:id]
|
56
56
|
deploy = Hubstats::Deploy.where(id: pull.deploy_id, user_id: nil).first
|
57
|
-
|
58
|
-
|
59
|
-
|
60
|
-
|
57
|
+
if deploy
|
58
|
+
deploy.user_id = pull_data[:merged_by]
|
59
|
+
deploy.save!
|
60
|
+
end
|
61
61
|
end
|
62
62
|
|
63
63
|
if user.team && user.team.id
|
@@ -155,8 +155,22 @@ module Hubstats
|
|
155
155
|
#
|
156
156
|
# Returns - the new labels
|
157
157
|
def add_labels(labels)
|
158
|
-
labels.map!{|label| Hubstats::Label.first_or_create(label) }
|
158
|
+
labels.map! { |label| Hubstats::Label.first_or_create(label) }
|
159
159
|
self.labels = labels
|
160
160
|
end
|
161
|
+
|
162
|
+
# Public - Adds/remove a label based on the the webhook action
|
163
|
+
# @param payload Webhook payload#
|
164
|
+
# @return The list of labels after the update
|
165
|
+
def update_label(payload)
|
166
|
+
return unless payload[:label]
|
167
|
+
label = Hubstats::Label.first_or_create(payload[:label])
|
168
|
+
if payload[:action] == 'labeled'
|
169
|
+
labels << label
|
170
|
+
elsif payload[:action] == 'unlabeled'
|
171
|
+
labels.delete(label)
|
172
|
+
end
|
173
|
+
labels
|
174
|
+
end
|
161
175
|
end
|
162
176
|
end
|
@@ -22,18 +22,23 @@ module Hubstats
|
|
22
22
|
end
|
23
23
|
end
|
24
24
|
|
25
|
-
# Public - Gets the information for the
|
25
|
+
# Public - Gets the information for the PR, creates/updates the new PR, grabs the labels, and makes new labels
|
26
26
|
#
|
27
27
|
# payload - the information that we will use to get data off of
|
28
28
|
#
|
29
|
-
# Returns - nothing, but
|
29
|
+
# Returns - nothing, but creates/updates the PR and adds appropriate labels
|
30
30
|
def pull_processor(payload)
|
31
31
|
pull_request = payload[:pull_request]
|
32
32
|
pull_request[:repository] = payload[:repository]
|
33
33
|
new_pull = Hubstats::PullRequest.create_or_update(pull_request.with_indifferent_access)
|
34
|
-
|
35
|
-
|
36
|
-
|
34
|
+
if payload[:action].include?('labeled')
|
35
|
+
new_pull.update_label(payload)
|
36
|
+
else
|
37
|
+
repo_name = Hubstats::Repo.where(id: new_pull.repo_id).first.full_name
|
38
|
+
labels = Hubstats::GithubAPI.get_labels_for_pull(repo_name, new_pull.number)
|
39
|
+
new_pull.add_labels(labels)
|
40
|
+
end
|
41
|
+
new_pull.save!
|
37
42
|
end
|
38
43
|
|
39
44
|
# Public - Gets the information for the new comment and updates it
|
data/lib/hubstats/github_api.rb
CHANGED
@@ -276,7 +276,7 @@ module Hubstats
|
|
276
276
|
end
|
277
277
|
end
|
278
278
|
|
279
|
-
# Public - Routes to the
|
279
|
+
# Public - Routes to the correct setup methods to be used to update or create comments or PRs
|
280
280
|
#
|
281
281
|
# object - the new thing to be updated or created
|
282
282
|
# kind - the type of thing (pull comment, issue comment, normal comment, pull, or issue)
|
data/lib/hubstats/version.rb
CHANGED
@@ -33,6 +33,7 @@ FactoryGirl.define do
|
|
33
33
|
factory :pull_request_payload_hash, class:Hash do
|
34
34
|
id {Faker::Number.number(6).to_i}
|
35
35
|
type "PullRequestEvent"
|
36
|
+
action 'opened'
|
36
37
|
association :repository, factory: :repo_hash, strategy: :build
|
37
38
|
association :pull_request, factory: :pull_request_hash, strategy: :build
|
38
39
|
merged_by(:id => 202020)
|
@@ -17,8 +17,28 @@ module Hubstats
|
|
17
17
|
it 'should add labels to pull request' do
|
18
18
|
allow(PullRequest).to receive(:create_or_update) {pull}
|
19
19
|
allow(Repo).to receive(:where) {[repo,repo]}
|
20
|
-
allow(GithubAPI).to receive(:get_labels_for_pull) {['low','high']}
|
21
|
-
expect(pull).to receive(:add_labels).with(['low','high'])
|
20
|
+
allow(GithubAPI).to receive(:get_labels_for_pull) {[{name: 'low'}, {name: 'high'}]}
|
21
|
+
expect(pull).to receive(:add_labels).with([{name: 'low'}, {name: 'high'}])
|
22
|
+
subject.route(payload, payload[:type])
|
23
|
+
end
|
24
|
+
|
25
|
+
it 'should add new labels to pull requests' do
|
26
|
+
payload[:action] = 'labeled'
|
27
|
+
payload[:label] = {name: 'new_label'}
|
28
|
+
allow(PullRequest).to receive(:create_or_update) {pull}
|
29
|
+
allow(Repo).to receive(:where) {[repo,repo]}
|
30
|
+
allow(GithubAPI).to receive(:get_labels_for_pull) {[{name: 'low'}, {name: 'high'}]}
|
31
|
+
expect(pull).to receive(:update_label).with(payload)
|
32
|
+
subject.route(payload, payload[:type])
|
33
|
+
end
|
34
|
+
|
35
|
+
it 'should remove old labels from pull requests' do
|
36
|
+
payload[:action] = 'unlabeled'
|
37
|
+
payload[:label] = {name: 'old_label'}
|
38
|
+
allow(PullRequest).to receive(:create_or_update) {pull}
|
39
|
+
allow(Repo).to receive(:where) {[repo,repo]}
|
40
|
+
allow(GithubAPI).to receive(:get_labels_for_pull) {[{name: 'low'}, {name: 'high'}, {name: 'old_label'}]}
|
41
|
+
expect(pull).to receive(:update_label).with(payload)
|
22
42
|
subject.route(payload, payload[:type])
|
23
43
|
end
|
24
44
|
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.7.
|
4
|
+
version: 0.7.5
|
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: 2016-
|
12
|
+
date: 2016-09-09 00:00:00.000000000 Z
|
13
13
|
dependencies:
|
14
14
|
- !ruby/object:Gem::Dependency
|
15
15
|
name: rails
|