hubstats 0.7.4 → 0.7.5

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 70362c13d5ef627afc7c23ac91372ce4b19a603b
4
- data.tar.gz: 419eb2b3f4efc1d53f1970f7d06e89a4ee32a680
3
+ metadata.gz: fd6afdc60bb321ead7ca1d88abf2ef0c7dc0b0f3
4
+ data.tar.gz: c8cdaa2df2c12b307931b5ebadcbe29270208747
5
5
  SHA512:
6
- metadata.gz: 924011691995ee7de31c6a0e096d649552a231c23dd61c1ebd70b50f5b9cbd052fbc774d339e863a0f0bc2aac9eec277f614da2b7b93c9951b62e7534fc29d10
7
- data.tar.gz: 76f5422f93f235543281a6c07c8cf53272d0edcf513f6e7a4dc48504d32e0dc8b029c920f58c8f69559124e8c961e9bd5535ba32046b8312aedf456daef720fd
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 | sed s/v//)\"/" lib/hubstats/version.rb
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
@@ -1,3 +1,8 @@
1
+ #### v0.7.5
2
+ * Improved handling of labeling/unlabeling a PR
3
+
4
+ > Arvind Menon: Andy Fleener: https://github.com/sportngin/hubstats/pull/106
5
+
1
6
  #### v0.7.4
2
7
  * Sort decorators for consistent behavior
3
8
 
@@ -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
- if deploy
58
- deploy.user_id = pull_data[:merged_by]
59
- deploy.save!
60
- end
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 new PR, makes the new PR, grabs the labels, and makes new labels
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 makes the new PR and adds appropriate labels
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
- repo_name = Hubstats::Repo.where(id: new_pull.repo_id).first.full_name
35
- labels = Hubstats::GithubAPI.get_labels_for_pull(repo_name, new_pull.number )
36
- new_pull.add_labels(labels)
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
@@ -276,7 +276,7 @@ module Hubstats
276
276
  end
277
277
  end
278
278
 
279
- # Public - Routes to the correst setup methods to be used to update or create comments or PRs
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)
@@ -1,3 +1,3 @@
1
1
  module Hubstats
2
- VERSION = "0.7.4"
2
+ VERSION = "0.7.5"
3
3
  end
@@ -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
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-05-18 00:00:00.000000000 Z
12
+ date: 2016-09-09 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: rails