pr_comet 0.1.1 → 0.2.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,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 1d89965b671d38838d9895fbeb87f2fa300d5837c3d67a58d1fee01beaedfe9c
4
- data.tar.gz: 72080a6c89fcdd4e922a3fccd78ee511855e96d096d3bf8887c237a9c723af58
3
+ metadata.gz: 26c2bf63b04addbcf8944b89f84b026baa7c0345d3888b977448ef5b1376f67c
4
+ data.tar.gz: ee125a1a0c3f34ba61f97908aeeab173daf06de06ac36a205832dffc37cedecf
5
5
  SHA512:
6
- metadata.gz: 57f958698936f599fbfdca4025062ff5b76996172714a0d5134d8a36bc7f87904511570e11d8302cdb450a30451b49388c359edc35ba085dd56ba42254164816
7
- data.tar.gz: 2cb178a32e7fb35bea01a71054ad7f795fae03a3a48ac860bc2ccc19e9211b11f89f64c84824709fe773713aaed94c52da38a2d3610827517bcf6c0a9cfe1859
6
+ metadata.gz: 9e26ed62ce34b767a376e7053e3b0abaf02f52fae8994db44f7c5c6d2a13374d98c30801a28c6444597677656ca8c512872688e704610af84b39a0a97ab4b7dc
7
+ data.tar.gz: cd38ef82bd6adbcaa623bec8f945c54c72012346861f96fc6eda0aaca5bad6a3dc201ba82cf0cf7643eda9c322f28474cd0f7e0f5e5493d5bdf44008dece2ec4
data/.rubocop_todo.yml CHANGED
@@ -1,6 +1,6 @@
1
1
  # This configuration was generated by
2
2
  # `rubocop --auto-gen-config`
3
- # on 2019-04-08 22:01:17 +0900 using RuboCop version 0.67.2.
3
+ # on 2019-05-30 23:31:16 +0000 using RuboCop version 0.71.0.
4
4
  # The point is for the user to remove these configuration records
5
5
  # one by one as the offenses are removed from the code base.
6
6
  # Note that changes in the inspected code, or installation of new
data/Gemfile.lock CHANGED
@@ -1,13 +1,14 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- pr_comet (0.1.1)
4
+ pr_comet (0.2.0)
5
5
  octokit
6
+ rainbow
6
7
 
7
8
  GEM
8
9
  remote: https://rubygems.org/
9
10
  specs:
10
- addressable (2.5.2)
11
+ addressable (2.6.0)
11
12
  public_suffix (>= 2.0.2, < 4.0)
12
13
  ast (2.4.0)
13
14
  byebug (11.0.1)
@@ -19,11 +20,11 @@ GEM
19
20
  jaro_winkler (1.5.2)
20
21
  json (2.2.0)
21
22
  method_source (0.9.2)
22
- multipart-post (2.0.0)
23
+ multipart-post (2.1.1)
23
24
  octokit (4.14.0)
24
25
  sawyer (~> 0.8.0, >= 0.5.3)
25
26
  parallel (1.17.0)
26
- parser (2.6.2.1)
27
+ parser (2.6.3.0)
27
28
  ast (~> 2.4.0)
28
29
  pry (0.12.2)
29
30
  coderay (~> 1.1.0)
@@ -31,8 +32,7 @@ GEM
31
32
  pry-byebug (3.7.0)
32
33
  byebug (~> 11.0)
33
34
  pry (~> 0.10)
34
- psych (3.1.0)
35
- public_suffix (3.0.3)
35
+ public_suffix (3.1.0)
36
36
  rainbow (3.0.0)
37
37
  rake (10.5.0)
38
38
  rspec (3.8.0)
@@ -41,7 +41,7 @@ GEM
41
41
  rspec-mocks (~> 3.8.0)
42
42
  rspec-core (3.8.0)
43
43
  rspec-support (~> 3.8.0)
44
- rspec-expectations (3.8.2)
44
+ rspec-expectations (3.8.3)
45
45
  diff-lcs (>= 1.2.0, < 2.0)
46
46
  rspec-support (~> 3.8.0)
47
47
  rspec-mocks (3.8.0)
@@ -50,28 +50,27 @@ GEM
50
50
  rspec-support (3.8.0)
51
51
  rspec_junit_formatter (0.4.1)
52
52
  rspec-core (>= 2, < 4, != 2.12.0)
53
- rubocop (0.67.2)
53
+ rubocop (0.71.0)
54
54
  jaro_winkler (~> 1.5.1)
55
55
  parallel (~> 1.10)
56
- parser (>= 2.5, != 2.5.1.1)
57
- psych (>= 3.1.0)
56
+ parser (>= 2.6)
58
57
  rainbow (>= 2.2.2, < 4.0)
59
58
  ruby-progressbar (~> 1.7)
60
- unicode-display_width (>= 1.4.0, < 1.6)
61
- rubocop-performance (1.1.0)
62
- rubocop (>= 0.67.0)
63
- rubocop-rspec (1.32.0)
59
+ unicode-display_width (>= 1.4.0, < 1.7)
60
+ rubocop-performance (1.3.0)
61
+ rubocop (>= 0.68.0)
62
+ rubocop-rspec (1.33.0)
64
63
  rubocop (>= 0.60.0)
65
- ruby-progressbar (1.10.0)
66
- sawyer (0.8.1)
67
- addressable (>= 2.3.5, < 2.6)
68
- faraday (~> 0.8, < 1.0)
64
+ ruby-progressbar (1.10.1)
65
+ sawyer (0.8.2)
66
+ addressable (>= 2.3.5)
67
+ faraday (> 0.8, < 2.0)
69
68
  simplecov (0.16.1)
70
69
  docile (~> 1.1)
71
70
  json (>= 1.8, < 3)
72
71
  simplecov-html (~> 0.10.0)
73
72
  simplecov-html (0.10.2)
74
- unicode-display_width (1.5.0)
73
+ unicode-display_width (1.6.0)
75
74
  yard (0.9.19)
76
75
 
77
76
  PLATFORMS
@@ -91,4 +90,4 @@ DEPENDENCIES
91
90
  yard
92
91
 
93
92
  BUNDLED WITH
94
- 1.16.6
93
+ 1.17.3
data/README.md CHANGED
@@ -1,6 +1,6 @@
1
1
  # PrComet
2
2
 
3
- [![CircleCI](https://circleci.com/gh/ryz310/pr_comet.svg?style=svg)](https://circleci.com/gh/ryz310/pr_comet) [![Maintainability](https://api.codeclimate.com/v1/badges/962618c106a548ed762b/maintainability)](https://codeclimate.com/github/ryz310/pr_comet/maintainability) [![Test Coverage](https://api.codeclimate.com/v1/badges/962618c106a548ed762b/test_coverage)](https://codeclimate.com/github/ryz310/pr_comet/test_coverage)
3
+ [![CircleCI](https://circleci.com/gh/ryz310/pr_comet.svg?style=svg)](https://circleci.com/gh/ryz310/pr_comet) [![Gem Version](https://badge.fury.io/rb/pr_comet.svg)](https://badge.fury.io/rb/pr_comet) [![Maintainability](https://api.codeclimate.com/v1/badges/962618c106a548ed762b/maintainability)](https://codeclimate.com/github/ryz310/pr_comet/maintainability) [![Test Coverage](https://api.codeclimate.com/v1/badges/962618c106a548ed762b/test_coverage)](https://codeclimate.com/github/ryz310/pr_comet/test_coverage)
4
4
 
5
5
  Welcome to your new gem! In this directory, you'll find the files you need to be able to package up your Ruby library into a gem. Put your Ruby code in the file `lib/pr_comet`. To experiment with that code, run `bin/console` for an interactive prompt.
6
6
 
data/lib/pr_comet.rb CHANGED
@@ -2,6 +2,7 @@
2
2
 
3
3
  require 'English'
4
4
  require 'octokit'
5
+ require 'rainbow'
5
6
  require 'pr_comet/version'
6
7
  require 'pr_comet/errors'
7
8
  require 'pr_comet/command_line'
@@ -46,9 +47,19 @@ class PrComet
46
47
  #
47
48
  # @param title [String] Title for the pull request
48
49
  # @param body [String] The body for the pull request
49
- # @param labels [Array<String>] An array of labels to apply to this PR
50
- # @return [Boolean] Return true if its successed
51
- def create!(title:, body:, labels: nil)
50
+ # @param labels [Array<String>]
51
+ # List of labels. It is a optional parameter. You can add labels to the
52
+ # created PR.
53
+ # @param project_column_name [String]
54
+ # A project column name. It is a optional parameter. You can add the created
55
+ # PR to the GitHub project.
56
+ # @param project_id [Integer]
57
+ # A target project ID. It is a optional parameter. If does not supplied,
58
+ # this method will find a project which associated the repository.
59
+ # When the repository has multiple projects, you should supply this.
60
+ # @return [Boolean] Return true if it is successed.
61
+ # rubocop:disable Metrics/AbcSize, Metrics/MethodLength, Metrics/LineLength
62
+ def create!(title:, body:, labels: nil, project_column_name: nil, project_id: nil)
52
63
  return false unless git_condition_valid?
53
64
 
54
65
  git.push(github_token_url, topic_branch)
@@ -56,8 +67,14 @@ class PrComet
56
67
  base: base_branch, head: topic_branch, title: title, body: body
57
68
  )
58
69
  github.add_labels(pr_number, *labels) unless labels.nil?
70
+ unless project_column_name.nil?
71
+ github.add_to_project(
72
+ pr_number, column_name: project_column_name, project_id: project_id
73
+ )
74
+ end
59
75
  true
60
76
  end
77
+ # rubocop:enable Metrics/AbcSize, Metrics/MethodLength, Metrics/LineLength
61
78
 
62
79
  private
63
80
 
@@ -12,19 +12,9 @@ class PrComet
12
12
  def execute(command)
13
13
  puts "$ #{command}"
14
14
  `#{command}`.chomp.tap do |result|
15
- color_code = $CHILD_STATUS.success? ? GREEN : RED
16
- color_puts(result, color_code)
15
+ color = $CHILD_STATUS.success? ? :green : :red
16
+ puts Rainbow(result).color(color)
17
17
  end
18
18
  end
19
-
20
- RED = 31
21
- GREEN = 32
22
- YELLOW = 33
23
- BLUE = 34
24
- PING = 35
25
-
26
- def color_puts(string, color_code)
27
- puts "\e[#{color_code}m#{string}\e[0m"
28
- end
29
19
  end
30
20
  end
@@ -2,6 +2,10 @@
2
2
 
3
3
  class PrComet
4
4
  module Errors
5
- class ExistUncommittedModify < StandardError; end
5
+ # Common error class
6
+ class Error < StandardError; end
7
+
8
+ # Un-commited modify was detected on the local
9
+ class ExistUncommittedModify < Error; end
6
10
  end
7
11
  end
@@ -18,25 +18,93 @@ class PrComet
18
18
  # @param title [String] Title for the pull request
19
19
  # @param body [String] The body for the pull request
20
20
  # @return [Integer] Created pull request number
21
+ # @see http://octokit.github.io/octokit.rb/Octokit/Client/PullRequests.html#create_pull_request-instance_method
21
22
  def create_pull_request(base:, head:, title:, body:)
22
23
  response =
23
24
  client.create_pull_request(repository, base, head, title, body)
24
25
  response.number
25
26
  end
26
27
 
27
- # Description of #add_labels
28
+ # Add labels to the issue.
28
29
  #
29
30
  # @param issue_number [Integer] Number ID of the issue (or pull request)
30
31
  # @param labels [Array<String>] An array of labels to apply to this Issue
32
+ # @see http://octokit.github.io/octokit.rb/Octokit/Client/Labels.html#add_labels_to_an_issue-instance_method
31
33
  def add_labels(issue_number, *labels)
32
34
  client.add_labels_to_an_issue(repository, issue_number, labels)
33
35
  end
34
36
 
37
+ # Adds supplied issue (or pull request) to the GitHub project
38
+ #
39
+ # @param issue_number [Integer] Number ID of the issue (or pull request)
40
+ # @param column_name [String] A target column name
41
+ # @param project_id [Integer]
42
+ # A target project ID. It is a optional parameter. If does not supplied,
43
+ # this method will find a project which associated the repository.
44
+ # When the repository has multiple projects, you should supply this.
45
+ # @see http://octokit.github.io/octokit.rb/Octokit/Client/Projects.html#create_project_card-instance_method
46
+ def add_to_project(issue_number, column_name:, project_id: nil)
47
+ project_id ||= default_project_id
48
+ column_id = get_project_column_id(project_id, column_name)
49
+ issue_id = get_issue_id(issue_number)
50
+ client.create_project_card(
51
+ column_id,
52
+ content_id: issue_id,
53
+ content_type: 'PullRequest'
54
+ )
55
+ rescue Octokit::Error => e
56
+ raise "Failed to add a pull request to the project: #{e.message}"
57
+ end
58
+
35
59
  private
36
60
 
37
61
  REPOSITORY_MATCHER = %r{github\.com[:/](?<repository>.+)\.git}.freeze
38
62
 
39
63
  attr_reader :client
64
+
65
+ # Returns a GitHub project column id which associated with supplied
66
+ # project ID and which matched with supplied column name. If does not
67
+ # found column, it returns nil.
68
+ #
69
+ # @param project_id [Integer] A target project ID
70
+ # @param column_name [String] A target column name
71
+ # @return [Integer, nil] Project column ID
72
+ def get_project_column_id(project_id, column_name)
73
+ find_project_columns(project_id).find { |c| c.name == column_name }.id
74
+ rescue StandardError
75
+ raise "Cannot find the GitHub project column with '#{column_name}'"
76
+ end
77
+
78
+ # Returns the issue (or pull request) ID
79
+ #
80
+ # @param issue_number [Integer] A target issue number
81
+ # @return [Integer] Issue ID
82
+ def get_issue_id(issue_number)
83
+ client.pull_request(repository, issue_number).id
84
+ end
85
+
86
+ # Finds a project id which associate with this repository.
87
+ # If found multiple projects it returns first one.
88
+ #
89
+ # @return [Integer] Project ID
90
+ # @raise [StandardError] Raises error when does not found a project.
91
+ # @see http://octokit.github.io/octokit.rb/Octokit/Client/Projects.html#projects-instance_method
92
+ def default_project_id
93
+ client.projects(repository).first.id
94
+ rescue Octokit::Error
95
+ raise 'Project does not found on this repository'
96
+ end
97
+
98
+ # Finds project columns with supplied project ID.
99
+ #
100
+ # @param project_id [Integer] A target project ID
101
+ # @return [Array<Sawyer::Resource>] List of project columns
102
+ # @see http://octokit.github.io/octokit.rb/Octokit/Client/Projects.html#project_columns-instance_method
103
+ def find_project_columns(project_id)
104
+ client.project_columns(project_id)
105
+ rescue Octokit::Error
106
+ raise "Project columns does not found at project_id:#{project_id}"
107
+ end
40
108
  end
41
109
  end
42
110
  end
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  class PrComet
4
- VERSION = '0.1.1'
4
+ VERSION = '0.2.0'
5
5
  end
data/pr_comet.gemspec CHANGED
@@ -23,6 +23,7 @@ Gem::Specification.new do |spec|
23
23
  spec.require_paths = ['lib']
24
24
 
25
25
  spec.add_runtime_dependency 'octokit'
26
+ spec.add_runtime_dependency 'rainbow'
26
27
 
27
28
  spec.add_development_dependency 'bundler', '~> 1.16'
28
29
  spec.add_development_dependency 'pry-byebug'
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: pr_comet
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.1
4
+ version: 0.2.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - ryz310
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2019-04-08 00:00:00.000000000 Z
11
+ date: 2019-06-09 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: octokit
@@ -24,6 +24,20 @@ dependencies:
24
24
  - - ">="
25
25
  - !ruby/object:Gem::Version
26
26
  version: '0'
27
+ - !ruby/object:Gem::Dependency
28
+ name: rainbow
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - ">="
32
+ - !ruby/object:Gem::Version
33
+ version: '0'
34
+ type: :runtime
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - ">="
39
+ - !ruby/object:Gem::Version
40
+ version: '0'
27
41
  - !ruby/object:Gem::Dependency
28
42
  name: bundler
29
43
  requirement: !ruby/object:Gem::Requirement