bu_pr 0.3.0 → 0.4.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
  SHA1:
3
- metadata.gz: a378ce215962223f4579793c8f83f8e26240d49a
4
- data.tar.gz: dd89b9e076031789c9b8e347d6f5a9167217e440
3
+ metadata.gz: 8d6a26d015d99b0818e94691d0c9ac8f4ec3e024
4
+ data.tar.gz: 42188f7945e7571011501e85fd78fc597211c5f2
5
5
  SHA512:
6
- metadata.gz: e9a323893ebdf4506ddd47808aeb6e0b987a8a9695883d5db9b558cc14fbf712201cae200c2ce28e174a42f421f939a3a3c5ce4ed4ee72811dcd750569d0775d
7
- data.tar.gz: 908fb84ded4440352d1d98cfb9f1de5e3470cd64c25356ba007d1531965639218cb72e6ba065101ae35ccbafb45b60284585ce6c0fd3539af1beb834f2285052
6
+ metadata.gz: ff2ac1be3f65db5a20da3a878686ee416b45a435bf4a66db2bdd48e08582d51a92f43c82a82bfcaa4af6261ef54b1497abea2ddcf36b7ee2cdd2bbb53693e074
7
+ data.tar.gz: 6c28f0f2a9bc0fcf6849c047bb00a072a3a89f85b139c0802ae4764e384de79a8cc284c06c612cf31c90078d19f3aeb0ef132772272a6b77033fb18d63b13bc7
data/README.md CHANGED
@@ -24,28 +24,44 @@ Or install it yourself as:
24
24
 
25
25
  Get Github access token from [this page](https://github.com/settings/tokens/new) with `repo` scope.
26
26
 
27
+
28
+ ### Set configuration values as Environment variables.
29
+
30
+ ```sh
31
+ # .bash_profile / .profile / .zshrc / etc.
32
+
33
+ export BUPR_TOKEN="xxx"
34
+ export BUPR_REPO="mmyoji/bu_pr"
35
+ # export BUPR_BRANCH="develop"
36
+ # export BUPR_TITLE="My bundle update"
37
+ ```
38
+
39
+
40
+ ### Set configuration values in config file.
41
+
27
42
  ```rb
28
43
  require 'bu_pr'
29
44
 
30
45
  # Setup
31
46
  BuPr.configure do |config|
32
- config.access_token = "xxx" # Required: or check ENV["BUPR_TOKEN"]
33
- config.repo_name = "mmyoji/bu_pr" # Required: or check ENV["BUPR_REPO"]
47
+ config.token = "xxx" # Required
48
+ config.repo = "mmyoji/bu_pr" # Required
34
49
 
35
- config.base_branch = "develop" # Optional: default is 'master'
36
- config.pr_title = "My bundle update" # Optional: default is like 'Bundle update 2016-11-13'
50
+ config.branch = "develop" # Optional :: default is 'master'
51
+ config.title = "My bundle update" # Optional :: default is like 'Bundle update 2016-11-13'
37
52
  end
38
53
 
39
54
  BuPr::Runner.call
40
55
  ```
41
56
 
42
- or if you're using Rails,
57
+ ### Rails
43
58
 
44
59
  ```rb
45
60
  # config/initializers/bu_pr.rb
61
+
46
62
  BuPr.configure do |config|
47
- config.access_token = "xxx"
48
- config.repo_name = "mmyoji/bu_pr"
63
+ config.token = "xxx"
64
+ config.repo = "mmyoji/bu_pr"
49
65
  end
50
66
  ```
51
67
 
@@ -5,27 +5,51 @@ module BuPr
5
5
  class Configuration
6
6
  include Singleton
7
7
 
8
- ACCESSORS = %i(
9
- access_token base_branch
10
- pr_title repo_name
8
+ attr_accessor(
9
+ :branch,
10
+ :title,
11
+ :token,
12
+ :repo,
11
13
  )
12
14
 
13
- attr_accessor(*ACCESSORS)
15
+ # DEPRECATED
16
+ alias access_token token
17
+ alias access_token= token=
18
+ alias base_branch branch
19
+ alias base_branch= branch=
20
+ alias pr_title title
21
+ alias pr_title= title=
22
+ alias repo_name repo
23
+ alias repo_name= repo=
14
24
 
15
25
  def initialize
16
- @base_branch = "master"
17
- @pr_title = "Bundle update #{Time.now.strftime('%F')}"
26
+ @branch = ENV.fetch("BUPR_BRANCH") { "master" }
27
+ @title = ENV.fetch("BUPR_TITLE") { "Bundle update #{Time.now.strftime('%F')}" }
18
28
 
19
- @access_token = ENV["BUPR_TOKEN"]
20
- @repo_name = ENV["BUPR_REPO"]
29
+ @token = ENV["BUPR_TOKEN"]
30
+ @repo = ENV["BUPR_REPO"]
21
31
  end
22
32
 
23
33
  def valid?
24
- ACCESSORS.all? do |accr|
25
- val = public_send(accr)
34
+ token? && branch? && title? && repo?
35
+ end
36
+
37
+ private
38
+
39
+ def token?
40
+ token && token != ""
41
+ end
42
+
43
+ def branch?
44
+ branch && branch != ""
45
+ end
46
+
47
+ def title?
48
+ title && title != ""
49
+ end
26
50
 
27
- val && val != ""
28
- end
51
+ def repo?
52
+ repo && repo != ""
29
53
  end
30
54
  end
31
55
  end
@@ -6,18 +6,22 @@ require "compare_linker"
6
6
  module BuPr
7
7
  module Handlers
8
8
  class Github
9
- attr_reader :base, :current_branch, :repo, :title, :token
9
+ attr_reader :base
10
+ attr_reader :current_branch
11
+ attr_reader :repo
12
+ attr_reader :title
13
+ attr_reader :token
10
14
  attr_reader :linker
11
15
 
12
- def initialize(attrs = {})
16
+ def initialize attrs = {}
13
17
  config = attrs[:config]
14
18
 
15
19
  @current_branch = attrs[:current_branch]
16
20
 
17
- @base = config.base_branch
18
- @repo = config.repo_name
19
- @title = config.pr_title
20
- @token = config.access_token
21
+ @base = config.branch
22
+ @repo = config.repo
23
+ @title = config.title
24
+ @token = config.token
21
25
  end
22
26
 
23
27
  def call
@@ -27,15 +31,15 @@ module BuPr
27
31
 
28
32
  def create_pull_request
29
33
  res = client.create_pull_request \
30
- repo,
31
- base,
32
- current_branch,
33
- title
34
+ repo,
35
+ base,
36
+ current_branch,
37
+ title
34
38
 
35
39
  res[:number]
36
40
  end
37
41
 
38
- def diff_comment(pr_number)
42
+ def diff_comment pr_number
39
43
  load_linker(pr_number)
40
44
  linker.add_comment repo, pr_number, comment_content
41
45
  end
@@ -52,7 +56,7 @@ module BuPr
52
56
  "#{linker.make_compare_links.to_a.join("\n")}"
53
57
  end
54
58
 
55
- def load_linker(pr_number)
59
+ def load_linker pr_number
56
60
  ENV['OCTOKIT_ACCESS_TOKEN'] = token
57
61
 
58
62
  @linker = ::CompareLinker.new repo, pr_number
data/lib/bu_pr/railtie.rb CHANGED
@@ -1,11 +1,9 @@
1
1
  # frozen_string_literal: true
2
2
 
3
- if defined?(Rails::Railtie)
4
- module BuPr
5
- class Railtie < ::Rails::Railtie
6
- rake_tasks do
7
- load "bu_pr/tasks/bu_pr.rake"
8
- end
3
+ module BuPr
4
+ class Railtie < ::Rails::Railtie
5
+ rake_tasks do
6
+ load "bu_pr/tasks/bu_pr.rake"
9
7
  end
10
8
  end
11
9
  end
data/lib/bu_pr/version.rb CHANGED
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  module BuPr
2
- VERSION = "0.3.0"
4
+ VERSION = "0.4.0"
3
5
  end
data/lib/bu_pr.rb CHANGED
@@ -2,12 +2,9 @@
2
2
  require "bu_pr/version"
3
3
  require "bu_pr/configuration"
4
4
  require "bu_pr/git"
5
-
6
5
  require "bu_pr/handlers/github"
7
-
8
6
  require "bu_pr/runner"
9
-
10
- require "bu_pr/railtie"
7
+ require "bu_pr/railtie" if defined?(Rails::Railtie)
11
8
 
12
9
  module BuPr
13
10
  def configure
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: bu_pr
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.3.0
4
+ version: 0.4.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Masaya Myojin
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2016-11-30 00:00:00.000000000 Z
11
+ date: 2017-02-14 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: compare_linker