octopolo 0.0.2 → 0.1.0

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,15 +1,15 @@
1
1
  ---
2
2
  !binary "U0hBMQ==":
3
3
  metadata.gz: !binary |-
4
- YjU0YzE4ZTQ4NzI1MjYwMDljM2MzNzgzYmJkZWM1Yjc3Y2Y5ZDVlYQ==
4
+ M2Q4NWI4ZGY4Y2M3NmNmNTc1MjU0YTcwYjM3YjkyMmU5ZmFjMmViNA==
5
5
  data.tar.gz: !binary |-
6
- YjViZWE1OGI2ZTUzNTVkMzI0NTcyOWJkZjMwOGQ3YjhiY2YxMTVmMg==
6
+ NjFiZjgyMmZiODM0M2ZlZDM4ODVlY2E2M2QxMzMyMmRjMzcwMjkwNg==
7
7
  SHA512:
8
8
  metadata.gz: !binary |-
9
- OGJjMmQ3ZTg2OGVkMDE4ODhiMTFhYjlmOGYzNmYwOGI4OTE0OGFmZDdjZWY2
10
- ZTc3N2U0ZTU2ZDg2Y2M4OTg3MDFmMTg5NmZlZDdmNDVmZGI5M2U5NmY4YWU4
11
- NDBjZDMxZWE5MGVmYzgzMDk3ZGMxYTVjMmYzMjJkNjQyYzI1NGI=
9
+ MGNmMTYzMmI5ZjM1YTk0M2Q3NTY3MGFmMTFlNmEzZDAwNTlhZDkxMDg1ZWU4
10
+ ODk0NDFjMDI4YmFiOThkMDU3NWYzOGQ3MDcyOTZiMDcyN2RhMzUxNzlkMTk1
11
+ YWQxYWY3OWM2NjlhZmJkMDMyN2ViYTIyYzUyMmUxYWQ1NzM3OWY=
12
12
  data.tar.gz: !binary |-
13
- OTRmMzUyMTg1MGZjOGE5NzBhZGJkYWFhNzUzY2IyODI1ZDM5OWM2MTU5YjRm
14
- ZDJiZmZkNGQzNDI2NjVjZDhmYzhjNjQyNDg0MTczNWY3OTI0MDM0MzY5ODc1
15
- YmY2YTY3NDNmMzA2ZTAyMzI1NzhmYTFmYWM4OWU3ZDJiNzRhMzE=
13
+ OWU3MzBjNWJlMTc4NjRmMjNiZmQ3ZmEwZmQ1NmQxZDE4Njk5YTc5NWQyY2Y1
14
+ ODVjODVlYmMxYWFjNDdhNDRiZGMxYjAzODdmZDRmNzM1ZGNkZTVmYTYzZGJi
15
+ ZGUwZGFiZjlmZWZhMzJhZjZkZjkwNzA1YTI5N2UxMWJiYTUwMzI=
data/.gitignore CHANGED
@@ -14,6 +14,7 @@ spec/reports
14
14
  test/tmp
15
15
  test/version_tmp
16
16
  tmp
17
+ log/
17
18
 
18
19
  # YARD artifacts
19
20
  .yardoc
@@ -0,0 +1,10 @@
1
+ #### v0.1.0
2
+
3
+ * Add Label for deployable
4
+
5
+ > Elliot Hursh: Nick LaMuro: https://github.com/sportngin/octopolo/pull/20
6
+
7
+ * upgraded rspec to 2.99.0, moved deprecation warning output to deprecations.log
8
+
9
+ > Elliot Hursh: Nick LaMuro: https://github.com/sportngin/octopolo/pull/18
10
+
@@ -36,6 +36,10 @@ module Octopolo
36
36
  @deploy_methods || []
37
37
  end
38
38
 
39
+ def deployable_label
40
+ @deployable_label.nil? ? true : @deployable_label
41
+ end
42
+
39
43
  def github_repo
40
44
  @github_repo || raise(MissingRequiredAttribute, "GitHub Repo is required")
41
45
  end
@@ -86,6 +86,18 @@ module Octopolo
86
86
  ["tst-octopolo"]
87
87
  end
88
88
 
89
+ def self.labels *args
90
+ client.labels *args
91
+ end
92
+
93
+ def self.add_label *args
94
+ client.add_label *args
95
+ end
96
+
97
+ def self.add_labels_to_pull *args
98
+ client.add_labels_to_an_issue *args
99
+ end
100
+
89
101
  # now that you've set up your credentials, try again
90
102
  TryAgain = Class.new(StandardError)
91
103
  # the credentials you've entered are bad
@@ -0,0 +1,86 @@
1
+ require_relative "../github"
2
+ require "yaml"
3
+ require "octokit"
4
+
5
+ module Octopolo
6
+ module GitHub
7
+ class Label
8
+ extend ConfigWrapper
9
+
10
+ attr_accessor :name
11
+ attr_accessor :color
12
+
13
+ def initialize(name, color)
14
+ self.name = name
15
+ self.color = color
16
+ end
17
+
18
+ def == (obj)
19
+ (self.name == obj.name) ? true : false
20
+ end
21
+
22
+ # Public: Grabs all labels from either file or github
23
+ # This is the method to override for labels from files
24
+ def self.all_labels
25
+ from_github
26
+ end
27
+
28
+ # Public: Gets the names of labels
29
+ #
30
+ # label_array - an array of labels
31
+ #
32
+ # returns - an array of all names from label_array
33
+ def self.get_names(label_array)
34
+ label_array.map{ |label| label.name }
35
+ end
36
+
37
+ # Public: Checks to see if label exists on remote, if not makes one.
38
+ #
39
+ # label - a label object
40
+ def self.first_or_create(label)
41
+ unless all_labels.include?(label)
42
+ GitHub.add_label(config.github_repo, label.name, label.color)
43
+ end
44
+ end
45
+
46
+ # Public: Adds labels to a pull-request
47
+ #
48
+ # labels - an array of labels
49
+ # pull_number - number of the pull_request to add label to
50
+ def self.add_to_pull(pull_number, *labels)
51
+ built_labels = build_label_array(labels)
52
+ GitHub.add_labels_to_pull(config.github_repo, pull_number, get_names(built_labels) )
53
+ end
54
+
55
+ # Private: takes in a hash, out puts a label
56
+ #
57
+ # label_hash - a hashed label
58
+ #
59
+ # returns - a label
60
+ def self.to_label(label_hash)
61
+ Label.new(label_hash[:name], label_hash[:color])
62
+ end
63
+ private_class_method :to_label
64
+
65
+ # Private: Gets all the labels from given repository on github
66
+ #
67
+ # returns - an array of labels
68
+ def self.from_github
69
+ GitHub.labels(config.github_repo).map{ |label_hash| to_label(label_hash) }
70
+ end
71
+ private_class_method :from_github
72
+
73
+ # Private: Finds or creates each of the passed in labels
74
+ #
75
+ # labels - label objects, can be a single label, an array of labels,
76
+ # or a list of labels
77
+ #
78
+ # returns - an array of labels.
79
+ def self.build_label_array(*labels)
80
+ Array(labels).flatten.each {|label| first_or_create(label)}
81
+ end
82
+ private_class_method :build_label_array
83
+
84
+ end
85
+ end
86
+ end
@@ -1,5 +1,6 @@
1
1
  require_relative "../scripts"
2
2
  require_relative "../pull_request_merger"
3
+ require_relative "../github/label"
3
4
 
4
5
  module Octopolo
5
6
  module Scripts
@@ -13,6 +14,10 @@ module Octopolo
13
14
  new(pull_request_id).execute
14
15
  end
15
16
 
17
+ def self.deployable_label
18
+ Octopolo::GitHub::Label.new("deployable", "428BCA")
19
+ end
20
+
16
21
  def initialize(pull_request_id=nil)
17
22
  @pull_request_id = pull_request_id
18
23
  end
@@ -21,7 +26,9 @@ module Octopolo
21
26
  def execute
22
27
  self.pull_request_id ||= cli.prompt("Pull Request ID: ")
23
28
  PullRequestMerger.perform Git::DEPLOYABLE_PREFIX, Integer(@pull_request_id), :user_notifications => config.user_notifications
29
+ Octopolo::GitHub::Label.add_to_pull(Integer(@pull_request_id), Deployable.deployable_label) if config.deployable_label
24
30
  end
31
+
25
32
  end
26
33
  end
27
34
  end
@@ -1,3 +1,3 @@
1
1
  module Octopolo
2
- VERSION = "0.0.2"
2
+ VERSION = "0.1.0"
3
3
  end
data/octopolo.gemspec CHANGED
@@ -24,7 +24,7 @@ Gem::Specification.new do |gem|
24
24
  gem.add_dependency 'pivotal-tracker', '~> 0.5'
25
25
  gem.add_dependency 'jiralicious'
26
26
 
27
- gem.add_development_dependency 'rspec', '~> 2.11.0'
27
+ gem.add_development_dependency 'rspec', '~> 2.99.0'
28
28
  gem.add_development_dependency "guard"
29
29
  gem.add_development_dependency "guard-rspec"
30
30
  gem.add_development_dependency 'octopolo-plugin-example'
@@ -62,6 +62,16 @@ module Octopolo
62
62
  end
63
63
  end
64
64
 
65
+ context "#deployable_label" do
66
+ it "is true by default" do
67
+ expect(Config.new.deployable_label).to eq(true)
68
+ end
69
+
70
+ it "is can be configured as well" do
71
+ expect(Config.new(deployable_label: false).deployable_label).to eq(false)
72
+ end
73
+ end
74
+
65
75
  context "#github_repo" do
66
76
  it "raises an exception if not given" do
67
77
  expect { Config.new.github_repo }.to raise_error(Config::MissingRequiredAttribute)
@@ -0,0 +1,103 @@
1
+ require "spec_helper"
2
+ require_relative "../../../lib/octopolo/github/label"
3
+
4
+ module Octopolo
5
+ module GitHub
6
+ describe Label do
7
+
8
+ let(:label_hash_1) { {name: "low-risk", url: "github.com", color: "343434"} }
9
+ let(:label_hash_2) { {name: "high-risk", url: "github.com", color: "565656"} }
10
+ let(:labels_hash) { [label_hash_1,label_hash_2] }
11
+ let(:label1) { Label.new("low-risk", "343434") }
12
+ let(:label2) { Label.new("high-risk", '565656') }
13
+ let(:config) { stub(:config, github_repo: "foo") }
14
+
15
+ subject { Label }
16
+
17
+ before do
18
+ subject.config = config
19
+ end
20
+
21
+ context "#all_labels" do
22
+ it "gets and returns all labels belonging to a repository" do
23
+ allow(GitHub).to receive(:labels).and_return(labels_hash)
24
+ expect(Label.all_labels).to eq([label1,label2])
25
+ end
26
+ end
27
+
28
+ context "#first_or_create" do
29
+ it "finds the existing label and doesn't do anything" do
30
+ allow(Label).to receive(:all_labels).and_return([label1,label2])
31
+ expect(GitHub).not_to receive(:add_label)
32
+ Label.first_or_create(label1)
33
+ end
34
+
35
+ it "doesn't find a label and creates one" do
36
+ allow(Label).to receive(:all_labels).and_return([label1,label2])
37
+ expect(GitHub).to receive(:add_label).with(config.github_repo, "medium-risk", "454545")
38
+ Label.first_or_create(Label.new("medium-risk","454545"))
39
+ end
40
+ end
41
+
42
+ context "#to_label" do
43
+ it "returns a label object" do
44
+ expect(Label).to receive(:new)
45
+ Label.send(:to_label, label_hash_1)
46
+ end
47
+ end
48
+
49
+ context "#==" do
50
+ it "returns true if names are same ignoring color" do
51
+ expect(label1 == Label.new("low-risk","121212")).to eq(true)
52
+ end
53
+
54
+ it "returns true if names are same ignoring color" do
55
+ expect(label1 == label2).to eq(false)
56
+ end
57
+ end
58
+
59
+ context "#add_to_pull" do
60
+ let (:pull_number) {007}
61
+ it "sends the correct arguments to add_labels_to_pull for multiple labels" do
62
+ allow(Label).to receive(:first_or_create)
63
+ expect(GitHub).to receive(:add_labels_to_pull).with(config.github_repo, pull_number, ["low-risk","high-risk"])
64
+ Label.add_to_pull(pull_number,[label1, label2])
65
+ end
66
+
67
+ it "sends the correct arguments to add_labels_to_pull for a single label" do
68
+ allow(Label).to receive(:first_or_create)
69
+ expect(GitHub).to receive(:add_labels_to_pull).with(config.github_repo, pull_number, ["low-risk"])
70
+ Label.add_to_pull(pull_number,label1)
71
+ end
72
+ end
73
+
74
+ context "#build_labels" do
75
+ it "returns an array of label when given a label" do
76
+ allow(Label).to receive(:first_or_create)
77
+ expect(Label.send(:build_label_array,label1)).to eq([label1])
78
+ end
79
+
80
+ it "returns an array of labels when given a list of labels" do
81
+ allow(Label).to receive(:first_or_create)
82
+ expect(Label.send(:build_label_array,label1,label2)).to eq([label1,label2])
83
+ end
84
+
85
+ it "returns an array of labels when given an array of length 1" do
86
+ allow(Label).to receive(:first_or_create)
87
+ expect(Label.send(:build_label_array,[label1])).to eq([label1])
88
+ end
89
+
90
+ it "returns an array of labels when given an array of length 1" do
91
+ allow(Label).to receive(:first_or_create)
92
+ expect(Label.send(:build_label_array,[label1,label2])).to eq([label1,label2])
93
+ end
94
+ end
95
+
96
+ context "#get_names" do
97
+ it "returns a list of names when given an array of labels" do
98
+ expect(Label.get_names([label1,label2])).to eq(["low-risk","high-risk"])
99
+ end
100
+ end
101
+ end
102
+ end
103
+ end
@@ -5,7 +5,7 @@ module Octopolo
5
5
  module Scripts
6
6
  describe Deployable do
7
7
  let(:cli) { stub(:Cli) }
8
- let(:config) { stub(:user_notifications => ['NickLaMuro']) }
8
+ let(:config) { stub(:user_notifications => ['NickLaMuro'], :github_repo => 'foo', :deployable_label => true) }
9
9
  before { Deployable.any_instance.stub(:cli => cli, :config => config) }
10
10
 
11
11
  context "#execute" do
@@ -13,6 +13,7 @@ module Octopolo
13
13
  subject { Deployable.new 42 }
14
14
 
15
15
  it "delegates the work to PullRequestMerger" do
16
+ allow(Octopolo::GitHub::Label).to receive(:add_to_pull)
16
17
  PullRequestMerger.should_receive(:perform).with(Git::DEPLOYABLE_PREFIX, 42, :user_notifications => ["NickLaMuro"])
17
18
  subject.execute
18
19
  end
@@ -29,6 +30,7 @@ module Octopolo
29
30
  end
30
31
 
31
32
  it "delegates the work to PullRequestMerger" do
33
+ allow(Octopolo::GitHub::Label).to receive(:add_to_pull)
32
34
  PullRequestMerger.should_receive(:perform).with(Git::DEPLOYABLE_PREFIX, 42, :user_notifications => ["NickLaMuro"])
33
35
  subject.execute
34
36
  end
@@ -46,6 +48,27 @@ module Octopolo
46
48
  end
47
49
  end
48
50
  end
51
+
52
+ context "with various values for deployable_label" do
53
+ let(:deployable_label) {Octopolo::GitHub::Label.new("deployable", "428BCA")}
54
+ subject { Deployable.new 42 }
55
+ before do
56
+ allow(PullRequestMerger).to receive(:perform)
57
+ end
58
+
59
+ it "calls add_to_pull when deployable_label is true" do
60
+ expect(Octopolo::GitHub::Label).to receive(:add_to_pull).with(42,deployable_label)
61
+ subject.execute
62
+ end
63
+
64
+ context "deployable_label is set to false " do
65
+ let(:config) { stub(:user_notifications => ['NickLaMuro'], :github_repo => 'foo', :deployable_label => false) }
66
+ it "skips add_to_pull when deployable_label is false" do
67
+ expect(Octopolo::GitHub::Label).to_not receive(:add_to_pull).with(42,deployable_label)
68
+ subject.execute
69
+ end
70
+ end
71
+ end
49
72
  end
50
73
  end
51
74
  end
data/spec/spec_helper.rb CHANGED
@@ -8,6 +8,7 @@ require_relative "../lib/octopolo"
8
8
  Octopolo.instance_variable_set(:@config, Octopolo::Config.new({:deploy_branch => "master"}))
9
9
 
10
10
  RSpec.configure do |config|
11
+ config.deprecation_stream = 'log/deprecations.log'
11
12
  config.treat_symbols_as_metadata_keys_with_true_values = true
12
13
  config.run_all_when_everything_filtered = true
13
14
  config.filter_run :focus
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: octopolo
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.2
4
+ version: 0.1.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Patrick Byrne
@@ -9,7 +9,7 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2014-07-11 00:00:00.000000000 Z
12
+ date: 2014-07-23 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: rake
@@ -115,14 +115,14 @@ dependencies:
115
115
  requirements:
116
116
  - - ~>
117
117
  - !ruby/object:Gem::Version
118
- version: 2.11.0
118
+ version: 2.99.0
119
119
  type: :development
120
120
  prerelease: false
121
121
  version_requirements: !ruby/object:Gem::Requirement
122
122
  requirements:
123
123
  - - ~>
124
124
  - !ruby/object:Gem::Version
125
- version: 2.11.0
125
+ version: 2.99.0
126
126
  - !ruby/object:Gem::Dependency
127
127
  name: guard
128
128
  requirement: !ruby/object:Gem::Requirement
@@ -179,6 +179,7 @@ files:
179
179
  - .ruby-gemset
180
180
  - .ruby-version
181
181
  - .travis.yml
182
+ - CHANGELOG.markdown
182
183
  - Gemfile
183
184
  - Guardfile
184
185
  - MIT-LICENSE
@@ -211,6 +212,7 @@ files:
211
212
  - lib/octopolo/git.rb
212
213
  - lib/octopolo/github.rb
213
214
  - lib/octopolo/github/commit.rb
215
+ - lib/octopolo/github/label.rb
214
216
  - lib/octopolo/github/pull_request.rb
215
217
  - lib/octopolo/github/pull_request_creator.rb
216
218
  - lib/octopolo/github/user.rb
@@ -248,6 +250,7 @@ files:
248
250
  - spec/octopolo/dated_branch_creator_spec.rb
249
251
  - spec/octopolo/git_spec.rb
250
252
  - spec/octopolo/github/commit_spec.rb
253
+ - spec/octopolo/github/label_spec.rb
251
254
  - spec/octopolo/github/pull_request_creator_spec.rb
252
255
  - spec/octopolo/github/pull_request_spec.rb
253
256
  - spec/octopolo/github/user_spec.rb
@@ -312,6 +315,7 @@ test_files:
312
315
  - spec/octopolo/dated_branch_creator_spec.rb
313
316
  - spec/octopolo/git_spec.rb
314
317
  - spec/octopolo/github/commit_spec.rb
318
+ - spec/octopolo/github/label_spec.rb
315
319
  - spec/octopolo/github/pull_request_creator_spec.rb
316
320
  - spec/octopolo/github/pull_request_spec.rb
317
321
  - spec/octopolo/github/user_spec.rb