pr_comet 0.1.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA256:
3
+ metadata.gz: 60300dd2cb0a84e663a618c931368363f7d95818853733d3d738bd02d2992c15
4
+ data.tar.gz: 96a266b2c0c451f030ce5eba0111ad641fec6db03c6ec8970d741b7c758c6272
5
+ SHA512:
6
+ metadata.gz: 01c5cb7b6a1666454b1a518c9b4f6590b3f2e570fa3d856a440929d3913cfbe901229bc1847934f1076874147410b38f45af180b7590fcae39d6e6ae4f5d3f35
7
+ data.tar.gz: 33e0617fa0ee733e02962549b3e25dfff9178be6bfc636330a7b97dab104707d8be2f11661a3d33feb37de1e074ed31f101fa3c6e27feeaefcc48702f3263450
@@ -0,0 +1,176 @@
1
+ # Ruby CircleCI 2.0 configuration file
2
+ #
3
+ # Check https://circleci.com/docs/2.0/language-ruby/ for more details
4
+ #
5
+ version: 2
6
+
7
+ references:
8
+ - &download_cc_test_reporter
9
+ run:
10
+ name: Download cc-test-reporter
11
+ command: |
12
+ mkdir -p tmp/
13
+ curl -L https://codeclimate.com/downloads/test-reporter/test-reporter-latest-linux-amd64 > ./tmp/cc-test-reporter
14
+ chmod +x ./tmp/cc-test-reporter
15
+ - &restore_bundle_install_cache
16
+ restore_cache:
17
+ keys:
18
+ - v1-dependencies-{{ checksum "Gemfile.lock" }}
19
+ - v1-dependencies-
20
+ - &bundle_install
21
+ run:
22
+ name: Bundle Install
23
+ command: |
24
+ bundle install --jobs=4 --retry=3 --path vendor/bundle
25
+ - &save_bundle_install_cache
26
+ save_cache:
27
+ paths:
28
+ - ./vendor/bundle
29
+ key: v1-dependencies-{{ checksum "Gemfile.lock" }}
30
+ - &run_rspec
31
+ run:
32
+ name: Run Rspec
33
+ command: |
34
+ mkdir /tmp/test-results
35
+ TEST_FILES="$(circleci tests glob "spec/**/*_spec.rb" | circleci tests split --split-by=timings)"
36
+ ./tmp/cc-test-reporter before-build
37
+ bundle exec rspec --format documentation \
38
+ --color \
39
+ --format RspecJunitFormatter \
40
+ --out /tmp/test-results/rspec.xml \
41
+ $TEST_FILES
42
+ ./tmp/cc-test-reporter after-build --coverage-input-type simplecov --exit-code $?
43
+
44
+ - &build
45
+ working_directory: ~/repo
46
+ steps:
47
+ - checkout
48
+ - *download_cc_test_reporter
49
+ - *restore_bundle_install_cache
50
+ - *bundle_install
51
+ - *save_bundle_install_cache
52
+ - *run_rspec
53
+ - store_test_results:
54
+ path: /tmp/test-results
55
+ - store_artifacts:
56
+ path: /tmp/test-results
57
+ destination: test-results
58
+ - run:
59
+ name: Rake Build
60
+ command: |
61
+ bundle exec rake build
62
+
63
+ - &rubocop
64
+ working_directory: ~/repo
65
+ steps:
66
+ - checkout
67
+ - *restore_bundle_install_cache
68
+ - *bundle_install
69
+ - *save_bundle_install_cache
70
+ - run: bundle exec rubocop
71
+
72
+ - &yardoc
73
+ working_directory: ~/repo
74
+ steps:
75
+ - checkout
76
+ - *restore_bundle_install_cache
77
+ - *bundle_install
78
+ - *save_bundle_install_cache
79
+ - run: bundle exec yardoc -o ./yardoc
80
+ - store_artifacts:
81
+ path: ./yardoc
82
+ destination: yardoc
83
+
84
+ jobs:
85
+ build_on_ruby_2.4:
86
+ docker:
87
+ - image: circleci/ruby:2.4-node-browsers
88
+ <<: *build
89
+ build_on_ruby_2.5:
90
+ docker:
91
+ - image: circleci/ruby:2.5-node-browsers
92
+ <<: *build
93
+ build_on_ruby_2.6:
94
+ docker:
95
+ - image: circleci/ruby:2.6-node-browsers
96
+ <<: *build
97
+ build_on_ruby_latest:
98
+ docker:
99
+ - image: circleci/ruby:latest-node-browsers-legacy
100
+ <<: *build
101
+ rubocop:
102
+ docker:
103
+ - image: circleci/ruby:2.4-node-browsers
104
+ <<: *rubocop
105
+ yardoc:
106
+ docker:
107
+ - image: circleci/ruby:2.4-node-browsers
108
+ <<: *yardoc
109
+
110
+ rubocop_challenge:
111
+ docker:
112
+ - image: circleci/ruby:2.4-node-browsers
113
+ working_directory: ~/repo
114
+ steps:
115
+ - checkout
116
+ - run:
117
+ name: Rubocop Challenge
118
+ command: |
119
+ gem install rubocop_challenger --pre
120
+ rubocop_challenger go --email=ryz310@gmail.com --name=ryz310
121
+
122
+ release:
123
+ docker:
124
+ - image: circleci/ruby:2.4-node-browsers
125
+ working_directory: ~/repo
126
+ steps:
127
+ - checkout
128
+ - *restore_bundle_install_cache
129
+ - *bundle_install
130
+ - *save_bundle_install_cache
131
+ - run:
132
+ name: Create Rubygems Credentials
133
+ command: |
134
+ mkdir ~/.gem
135
+ echo -e "---\n:rubygems_api_key: ${RUBYGEMS_API_KEY}" > ~/.gem/credentials
136
+ chmod 0600 ~/.gem/credentials
137
+ - run:
138
+ name: Release Gem
139
+ command: |
140
+ git push --set-upstream origin ${CIRCLE_BRANCH}
141
+ bundle exec rake release --trace
142
+
143
+ workflows:
144
+ version: 2
145
+
146
+ commit:
147
+ jobs:
148
+ - build_on_ruby_2.4
149
+ - build_on_ruby_2.5
150
+ - build_on_ruby_2.6
151
+ - build_on_ruby_latest
152
+ - rubocop
153
+ - yardoc
154
+ - release:
155
+ context: RubyGems API Key
156
+ requires:
157
+ - build_on_ruby_2.4
158
+ - build_on_ruby_2.5
159
+ - build_on_ruby_2.6
160
+ - build_on_ruby_latest
161
+ - rubocop
162
+ filters:
163
+ branches:
164
+ only:
165
+ - production
166
+
167
+ challenge:
168
+ triggers:
169
+ - schedule:
170
+ cron: "30 23 * * *" # 8:30am every day (JST)
171
+ filters:
172
+ branches:
173
+ only:
174
+ - master
175
+ jobs:
176
+ - rubocop_challenge
data/.envrc.skeleton ADDED
@@ -0,0 +1 @@
1
+ export GITHUB_ACCESS_TOKEN={GITHUB_ACCESS_TOKEN}
data/.gitignore ADDED
@@ -0,0 +1,11 @@
1
+ /.bundle/
2
+ /.yardoc
3
+ /_yardoc/
4
+ /coverage/
5
+ /doc/
6
+ /pkg/
7
+ /spec/reports/
8
+ /tmp/
9
+
10
+ # rspec failure tracking
11
+ .rspec_status
data/.rspec ADDED
@@ -0,0 +1,3 @@
1
+ --format documentation
2
+ --color
3
+ --require spec_helper
data/.rubocop.yml ADDED
@@ -0,0 +1,16 @@
1
+ require:
2
+ - rubocop-performance
3
+ - rubocop-rspec
4
+
5
+ inherit_from: .rubocop_todo.yml
6
+
7
+ AllCops:
8
+ TargetRubyVersion: 2.4
9
+
10
+ Metrics/BlockLength:
11
+ Exclude:
12
+ - 'pr_comet.gemspec'
13
+ - 'spec/**/*'
14
+
15
+ RSpec/NestedGroups:
16
+ Max: 4
data/.rubocop_todo.yml ADDED
@@ -0,0 +1,7 @@
1
+ # This configuration was generated by
2
+ # `rubocop --auto-gen-config`
3
+ # on 2019-04-08 22:01:17 +0900 using RuboCop version 0.67.2.
4
+ # The point is for the user to remove these configuration records
5
+ # one by one as the offenses are removed from the code base.
6
+ # Note that changes in the inspected code, or installation of new
7
+ # versions of RuboCop, may require this file to be generated again.
@@ -0,0 +1,74 @@
1
+ # Contributor Covenant Code of Conduct
2
+
3
+ ## Our Pledge
4
+
5
+ In the interest of fostering an open and welcoming environment, we as
6
+ contributors and maintainers pledge to making participation in our project and
7
+ our community a harassment-free experience for everyone, regardless of age, body
8
+ size, disability, ethnicity, gender identity and expression, level of experience,
9
+ nationality, personal appearance, race, religion, or sexual identity and
10
+ orientation.
11
+
12
+ ## Our Standards
13
+
14
+ Examples of behavior that contributes to creating a positive environment
15
+ include:
16
+
17
+ * Using welcoming and inclusive language
18
+ * Being respectful of differing viewpoints and experiences
19
+ * Gracefully accepting constructive criticism
20
+ * Focusing on what is best for the community
21
+ * Showing empathy towards other community members
22
+
23
+ Examples of unacceptable behavior by participants include:
24
+
25
+ * The use of sexualized language or imagery and unwelcome sexual attention or
26
+ advances
27
+ * Trolling, insulting/derogatory comments, and personal or political attacks
28
+ * Public or private harassment
29
+ * Publishing others' private information, such as a physical or electronic
30
+ address, without explicit permission
31
+ * Other conduct which could reasonably be considered inappropriate in a
32
+ professional setting
33
+
34
+ ## Our Responsibilities
35
+
36
+ Project maintainers are responsible for clarifying the standards of acceptable
37
+ behavior and are expected to take appropriate and fair corrective action in
38
+ response to any instances of unacceptable behavior.
39
+
40
+ Project maintainers have the right and responsibility to remove, edit, or
41
+ reject comments, commits, code, wiki edits, issues, and other contributions
42
+ that are not aligned to this Code of Conduct, or to ban temporarily or
43
+ permanently any contributor for other behaviors that they deem inappropriate,
44
+ threatening, offensive, or harmful.
45
+
46
+ ## Scope
47
+
48
+ This Code of Conduct applies both within project spaces and in public spaces
49
+ when an individual is representing the project or its community. Examples of
50
+ representing a project or community include using an official project e-mail
51
+ address, posting via an official social media account, or acting as an appointed
52
+ representative at an online or offline event. Representation of a project may be
53
+ further defined and clarified by project maintainers.
54
+
55
+ ## Enforcement
56
+
57
+ Instances of abusive, harassing, or otherwise unacceptable behavior may be
58
+ reported by contacting the project team at ryz310@gmail.com. All
59
+ complaints will be reviewed and investigated and will result in a response that
60
+ is deemed necessary and appropriate to the circumstances. The project team is
61
+ obligated to maintain confidentiality with regard to the reporter of an incident.
62
+ Further details of specific enforcement policies may be posted separately.
63
+
64
+ Project maintainers who do not follow or enforce the Code of Conduct in good
65
+ faith may face temporary or permanent repercussions as determined by other
66
+ members of the project's leadership.
67
+
68
+ ## Attribution
69
+
70
+ This Code of Conduct is adapted from the [Contributor Covenant][homepage], version 1.4,
71
+ available at [http://contributor-covenant.org/version/1/4][version]
72
+
73
+ [homepage]: http://contributor-covenant.org
74
+ [version]: http://contributor-covenant.org/version/1/4/
data/Gemfile ADDED
@@ -0,0 +1,8 @@
1
+ # frozen_string_literal: true
2
+
3
+ source 'https://rubygems.org'
4
+
5
+ git_source(:github) { |repo_name| "https://github.com/#{repo_name}" }
6
+
7
+ # Specify your gem's dependencies in pr_comet.gemspec
8
+ gemspec
data/Gemfile.lock ADDED
@@ -0,0 +1,96 @@
1
+ PATH
2
+ remote: .
3
+ specs:
4
+ pr_comet (0.1.0)
5
+ octokit
6
+ thor
7
+
8
+ GEM
9
+ remote: https://rubygems.org/
10
+ specs:
11
+ addressable (2.5.2)
12
+ public_suffix (>= 2.0.2, < 4.0)
13
+ ast (2.4.0)
14
+ byebug (11.0.1)
15
+ coderay (1.1.2)
16
+ diff-lcs (1.3)
17
+ docile (1.3.1)
18
+ faraday (0.15.4)
19
+ multipart-post (>= 1.2, < 3)
20
+ jaro_winkler (1.5.2)
21
+ json (2.2.0)
22
+ method_source (0.9.2)
23
+ multipart-post (2.0.0)
24
+ octokit (4.14.0)
25
+ sawyer (~> 0.8.0, >= 0.5.3)
26
+ parallel (1.17.0)
27
+ parser (2.6.2.1)
28
+ ast (~> 2.4.0)
29
+ pry (0.12.2)
30
+ coderay (~> 1.1.0)
31
+ method_source (~> 0.9.0)
32
+ pry-byebug (3.7.0)
33
+ byebug (~> 11.0)
34
+ pry (~> 0.10)
35
+ psych (3.1.0)
36
+ public_suffix (3.0.3)
37
+ rainbow (3.0.0)
38
+ rake (10.5.0)
39
+ rspec (3.8.0)
40
+ rspec-core (~> 3.8.0)
41
+ rspec-expectations (~> 3.8.0)
42
+ rspec-mocks (~> 3.8.0)
43
+ rspec-core (3.8.0)
44
+ rspec-support (~> 3.8.0)
45
+ rspec-expectations (3.8.2)
46
+ diff-lcs (>= 1.2.0, < 2.0)
47
+ rspec-support (~> 3.8.0)
48
+ rspec-mocks (3.8.0)
49
+ diff-lcs (>= 1.2.0, < 2.0)
50
+ rspec-support (~> 3.8.0)
51
+ rspec-support (3.8.0)
52
+ rspec_junit_formatter (0.4.1)
53
+ rspec-core (>= 2, < 4, != 2.12.0)
54
+ rubocop (0.67.2)
55
+ jaro_winkler (~> 1.5.1)
56
+ parallel (~> 1.10)
57
+ parser (>= 2.5, != 2.5.1.1)
58
+ psych (>= 3.1.0)
59
+ rainbow (>= 2.2.2, < 4.0)
60
+ ruby-progressbar (~> 1.7)
61
+ unicode-display_width (>= 1.4.0, < 1.6)
62
+ rubocop-performance (1.1.0)
63
+ rubocop (>= 0.67.0)
64
+ rubocop-rspec (1.32.0)
65
+ rubocop (>= 0.60.0)
66
+ ruby-progressbar (1.10.0)
67
+ sawyer (0.8.1)
68
+ addressable (>= 2.3.5, < 2.6)
69
+ faraday (~> 0.8, < 1.0)
70
+ simplecov (0.16.1)
71
+ docile (~> 1.1)
72
+ json (>= 1.8, < 3)
73
+ simplecov-html (~> 0.10.0)
74
+ simplecov-html (0.10.2)
75
+ thor (0.20.3)
76
+ unicode-display_width (1.5.0)
77
+ yard (0.9.19)
78
+
79
+ PLATFORMS
80
+ ruby
81
+
82
+ DEPENDENCIES
83
+ bundler (~> 1.16)
84
+ pr_comet!
85
+ pry-byebug
86
+ rake (~> 10.0)
87
+ rspec
88
+ rspec_junit_formatter
89
+ rubocop
90
+ rubocop-performance
91
+ rubocop-rspec
92
+ simplecov
93
+ yard
94
+
95
+ BUNDLED WITH
96
+ 1.16.6
data/LICENSE.txt ADDED
@@ -0,0 +1,21 @@
1
+ The MIT License (MIT)
2
+
3
+ Copyright (c) 2019 ryz310
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in
13
+ all copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
21
+ THE SOFTWARE.
data/README.md ADDED
@@ -0,0 +1,45 @@
1
+ # PrComet
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)
4
+
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
+
7
+ TODO: Delete this and the text above, and describe your gem
8
+
9
+ ## Installation
10
+
11
+ Add this line to your application's Gemfile:
12
+
13
+ ```ruby
14
+ gem 'pr_comet'
15
+ ```
16
+
17
+ And then execute:
18
+
19
+ $ bundle
20
+
21
+ Or install it yourself as:
22
+
23
+ $ gem install pr_comet
24
+
25
+ ## Usage
26
+
27
+ TODO: Write usage instructions here
28
+
29
+ ## Development
30
+
31
+ After checking out the repo, run `bin/setup` to install dependencies. Then, run `rake spec` to run the tests. You can also run `bin/console` for an interactive prompt that will allow you to experiment.
32
+
33
+ To install this gem onto your local machine, run `bundle exec rake install`. To release a new version, update the version number in `version.rb`, and then run `bundle exec rake release`, which will create a git tag for the version, push git commits and tags, and push the `.gem` file to [rubygems.org](https://rubygems.org).
34
+
35
+ ## Contributing
36
+
37
+ Bug reports and pull requests are welcome on GitHub at https://github.com/[USERNAME]/pr_comet. This project is intended to be a safe, welcoming space for collaboration, and contributors are expected to adhere to the [Contributor Covenant](http://contributor-covenant.org) code of conduct.
38
+
39
+ ## License
40
+
41
+ The gem is available as open source under the terms of the [MIT License](https://opensource.org/licenses/MIT).
42
+
43
+ ## Code of Conduct
44
+
45
+ Everyone interacting in the PrComet project’s codebases, issue trackers, chat rooms and mailing lists is expected to follow the [code of conduct](https://github.com/[USERNAME]/pr_comet/blob/master/CODE_OF_CONDUCT.md).
data/Rakefile ADDED
@@ -0,0 +1,8 @@
1
+ # frozen_string_literal: true
2
+
3
+ require 'bundler/gem_tasks'
4
+ require 'rspec/core/rake_task'
5
+
6
+ RSpec::Core::RakeTask.new(:spec)
7
+
8
+ task default: :spec
data/bin/console ADDED
@@ -0,0 +1,15 @@
1
+ #!/usr/bin/env ruby
2
+ # frozen_string_literal: true
3
+
4
+ require 'bundler/setup'
5
+ require 'pr_comet'
6
+
7
+ # You can add fixtures and/or initialization code here to make experimenting
8
+ # with your gem easier. You can also use a different console, if you like.
9
+
10
+ # (If you use this, don't forget to add pry to your Gemfile!)
11
+ # require "pry"
12
+ # Pry.start
13
+
14
+ require 'irb'
15
+ IRB.start(__FILE__)
data/bin/release ADDED
@@ -0,0 +1,34 @@
1
+ #!/usr/bin/env ruby
2
+ # frozen_string_literal: true
3
+
4
+ # usage: bin/release VERSION
5
+
6
+ require 'bundler/setup'
7
+ require 'pr_comet'
8
+
9
+ VERSION_FORMAT = /\A\d+\.\d+\.\d+(\.(pre|beta|rc)\d?)?\z/.freeze
10
+ version = ARGV[0]
11
+ pr_comet = PrComet.new(base: 'master', branch: "update/v#{version}")
12
+
13
+ # Verifying
14
+ abort 'usage: bin/release VERSION' if version.nil?
15
+ abort 'A version must be like a `1.2.3`' unless version =~ VERSION_FORMAT
16
+
17
+ # Modify a version file
18
+ pr_comet.commit ':comet: Update version' do
19
+ File.write('lib/pr_comet/version.rb', <<~VERSION)
20
+ # frozen_string_literal: true
21
+
22
+ class PrComet
23
+ VERSION = '#{version}'
24
+ end
25
+ VERSION
26
+ end
27
+
28
+ # Bundle Update
29
+ pr_comet.commit ':comet: Run $ bundle update' do
30
+ `bundle update`
31
+ end
32
+
33
+ # Create a pull request
34
+ pr_comet.create!(title: "Update v#{version}", body: '')
data/bin/setup ADDED
@@ -0,0 +1,8 @@
1
+ #!/usr/bin/env bash
2
+ set -euo pipefail
3
+ IFS=$'\n\t'
4
+ set -vx
5
+
6
+ bundle install
7
+
8
+ # Do any other automated setup that you need to do here
@@ -0,0 +1,30 @@
1
+ # frozen_string_literal: true
2
+
3
+ class PrComet
4
+ # To execute command line. You should inherit this class to use.
5
+ module CommandLine
6
+ private
7
+
8
+ # Execute a command
9
+ #
10
+ # @param command [String] The command you want to execute
11
+ # @return [String] The result in the execution
12
+ def execute(command)
13
+ puts "$ #{command}"
14
+ `#{command}`.chomp.tap do |result|
15
+ color_code = $CHILD_STATUS.success? ? GREEN : RED
16
+ color_puts(result, color_code)
17
+ end
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
+ end
30
+ end
@@ -0,0 +1,98 @@
1
+ # frozen_string_literal: true
2
+
3
+ class PrComet
4
+ module Git
5
+ # To execute git command
6
+ class Command
7
+ include CommandLine
8
+
9
+ def initialize(user_name: nil, user_email: nil)
10
+ @user_name = user_name
11
+ @user_email = user_email
12
+ end
13
+
14
+ def user_name
15
+ @user_name ||= config('user.name')
16
+ end
17
+
18
+ def user_email
19
+ @user_email ||= config('user.email')
20
+ end
21
+
22
+ def exist_uncommitted_modify?
23
+ execute('git add -n .; git diff --name-only') != ''
24
+ end
25
+
26
+ def checkout(branch)
27
+ run('checkout', branch)
28
+ end
29
+
30
+ def checkout_with(new_branch)
31
+ run('checkout', '-b', new_branch)
32
+ end
33
+
34
+ def add(*files)
35
+ run('add', *files)
36
+ end
37
+
38
+ def commit(message)
39
+ run_with_environments('commit', '-m', "\"#{message}\"")
40
+ end
41
+
42
+ # Execute git push command
43
+ #
44
+ # @note For security, this command add a quiet option automatically.
45
+ # @param remote [String] The remote repository name.
46
+ # @param branch [String] The target branch. default: `#current_branch`
47
+ # @return [String] The command's standard output.
48
+ def push(remote, branch = current_branch)
49
+ run('push', '-q', remote, branch)
50
+ end
51
+
52
+ def current_sha1
53
+ run('rev-parse', 'HEAD')
54
+ end
55
+
56
+ def current_sha1?(sha1)
57
+ current_sha1 == sha1.to_s
58
+ end
59
+
60
+ def current_branch
61
+ run('rev-parse', '--abbrev-ref', 'HEAD')
62
+ end
63
+
64
+ def current_branch?(branch)
65
+ current_branch == branch.to_s
66
+ end
67
+
68
+ def remote_url(remote)
69
+ config("--get remote.#{remote}.url")
70
+ end
71
+
72
+ private
73
+
74
+ def run(*subcommands)
75
+ command = "git #{subcommands.join(' ')}"
76
+ execute(command)
77
+ end
78
+
79
+ def run_with_environments(*subcommands)
80
+ command = "#{environments} git #{subcommands.join(' ')}"
81
+ execute(command)
82
+ end
83
+
84
+ def config(key)
85
+ run('config', key)
86
+ end
87
+
88
+ def environments
89
+ @environments ||= [
90
+ "GIT_AUTHOR_NAME=\"#{user_name}\"",
91
+ "GIT_AUTHOR_EMAIL=\"#{user_email}\"",
92
+ "GIT_COMMITTER_NAME=\"#{user_name}\"",
93
+ "GIT_COMMITTER_EMAIL=\"#{user_email}\""
94
+ ].join(' ')
95
+ end
96
+ end
97
+ end
98
+ end
@@ -0,0 +1,42 @@
1
+ # frozen_string_literal: true
2
+
3
+ class PrComet
4
+ module Github
5
+ # GitHub API Client
6
+ class Client
7
+ attr_reader :repository
8
+
9
+ def initialize(access_token, remote_url)
10
+ @client = Octokit::Client.new(access_token: access_token)
11
+ @repository = remote_url.match(REPOSITORY_MATCHER)[:repository]
12
+ end
13
+
14
+ # Create a pull request
15
+ #
16
+ # @param base [String] The branch you want your changes pulled into
17
+ # @param head [String] The branch where your changes are implemented
18
+ # @param title [String] Title for the pull request
19
+ # @param body [String] The body for the pull request
20
+ # @return [Integer] Created pull request number
21
+ def create_pull_request(base:, head:, title:, body:)
22
+ response =
23
+ client.create_pull_request(repository, base, head, title, body)
24
+ response.number
25
+ end
26
+
27
+ # Description of #add_labels
28
+ #
29
+ # @param issue_number [Integer] Number ID of the issue (or pull request)
30
+ # @param labels [Array<String>] An array of labels to apply to this Issue
31
+ def add_labels(issue_number, *labels)
32
+ client.add_labels_to_an_issue(repository, issue_number, labels)
33
+ end
34
+
35
+ private
36
+
37
+ REPOSITORY_MATCHER = %r{github\.com[:/](?<repository>.+)\.git}.freeze
38
+
39
+ attr_reader :client
40
+ end
41
+ end
42
+ end
@@ -0,0 +1,5 @@
1
+ # frozen_string_literal: true
2
+
3
+ class PrComet
4
+ VERSION = '0.1.0'
5
+ end
data/lib/pr_comet.rb ADDED
@@ -0,0 +1,84 @@
1
+ # frozen_string_literal: true
2
+
3
+ require 'English'
4
+ require 'octokit'
5
+ require 'pr_comet/version'
6
+ require 'pr_comet/command_line'
7
+ require 'pr_comet/git/command'
8
+ require 'pr_comet/github/client'
9
+
10
+ # Helps to create a pull request
11
+ class PrComet
12
+ # @note You have to set ENV['GITHUB_ACCESS_TOKEN']
13
+ # @param base [String] The branch you want your changes pulled into
14
+ # @param branch [String] The branch where your changes are going to
15
+ # implement.
16
+ # @param user_name [String] The username to use for committer and author
17
+ # @param user_email [String] The email to use for committer and author
18
+ def initialize(base:, branch:, user_name: nil, user_email: nil)
19
+ raise "You have to set ENV['GITHUB_ACCESS_TOKEN']" if access_token.nil?
20
+
21
+ @base_branch = base
22
+ @topic_branch = branch
23
+ @git = Git::Command.new(user_name: user_name, user_email: user_email)
24
+ @github = Github::Client.new(access_token, git.remote_url('origin'))
25
+ @initial_sha1 = git.current_sha1
26
+ end
27
+
28
+ # Add and commit local files to this branch
29
+ #
30
+ # @param message [String] The commit message
31
+ # @yield Some commands where modify local files
32
+ # @return [Object] Return result of yield if you use &block
33
+ # @raise [RubocopChallenger::Errors::ExistUncommittedModify]
34
+ # Raise error if you use &block and exists someuncommitted files
35
+ def commit(message, &block)
36
+ git.checkout_with(topic_branch) unless git.current_branch?(topic_branch)
37
+ result = modify_files(&block) if block_given?
38
+ git.add('.')
39
+ git.commit(message)
40
+ result
41
+ end
42
+
43
+ # Create a pull request
44
+ # You should call #commit before calling this method
45
+ #
46
+ # @param title [String] Title for the pull request
47
+ # @param body [String] The body for the pull request
48
+ # @param labels [Array<String>] An array of labels to apply to this PR
49
+ # @return [Boolean] Return true if its successed
50
+ def create!(title:, body:, labels: nil)
51
+ return false unless git_condition_valid?
52
+
53
+ git.push(github_token_url, topic_branch)
54
+ pr_number = github.create_pull_request(
55
+ base: base_branch, head: topic_branch, title: title, body: body
56
+ )
57
+ github.add_labels(pr_number, *labels) unless labels.nil?
58
+ true
59
+ end
60
+
61
+ private
62
+
63
+ attr_reader :git, :github, :base_branch, :topic_branch, :initial_sha1
64
+
65
+ def git_condition_valid?
66
+ !git.current_sha1?(initial_sha1) && git.current_branch?(topic_branch)
67
+ end
68
+
69
+ def modify_files
70
+ raise Errors::ExistUncommittedModify if git.exist_uncommitted_modify?
71
+
72
+ yield
73
+ end
74
+
75
+ def access_token
76
+ ENV['GITHUB_ACCESS_TOKEN']
77
+ end
78
+
79
+ # @note You *MUST NOT* use `#access_token` in the URL because this string
80
+ # will be output STDOUT via `RubocopChallenger::CommandLine` module.
81
+ def github_token_url
82
+ "https://${GITHUB_ACCESS_TOKEN}@github.com/#{github.repository}"
83
+ end
84
+ end
data/pr_comet.gemspec ADDED
@@ -0,0 +1,38 @@
1
+ # frozen_string_literal: true
2
+
3
+ lib = File.expand_path('lib', __dir__)
4
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
5
+ require 'pr_comet/version'
6
+
7
+ Gem::Specification.new do |spec|
8
+ spec.name = 'pr_comet'
9
+ spec.version = PrComet::VERSION
10
+ spec.authors = ['ryz310']
11
+ spec.email = ['ryz310@gmail.com']
12
+
13
+ spec.summary = 'Create a lots of pull request like comets'
14
+ spec.description = 'It helps to create a pull request on your script'
15
+ spec.homepage = 'https://github.com/ryz310/pr_comet'
16
+ spec.license = 'MIT'
17
+
18
+ spec.files = Dir.chdir(File.expand_path(__dir__)) do
19
+ `git ls-files -z`.split("\x0").reject { |f| f.match(%r{^spec/}) }
20
+ end
21
+ spec.bindir = 'exe'
22
+ spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
23
+ spec.require_paths = ['lib']
24
+
25
+ spec.add_runtime_dependency 'octokit'
26
+ spec.add_runtime_dependency 'thor'
27
+
28
+ spec.add_development_dependency 'bundler', '~> 1.16'
29
+ spec.add_development_dependency 'pry-byebug'
30
+ spec.add_development_dependency 'rake', '~> 10.0'
31
+ spec.add_development_dependency 'rspec'
32
+ spec.add_development_dependency 'rspec_junit_formatter'
33
+ spec.add_development_dependency 'rubocop'
34
+ spec.add_development_dependency 'rubocop-performance'
35
+ spec.add_development_dependency 'rubocop-rspec'
36
+ spec.add_development_dependency 'simplecov'
37
+ spec.add_development_dependency 'yard'
38
+ end
metadata ADDED
@@ -0,0 +1,232 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: pr_comet
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.1.0
5
+ platform: ruby
6
+ authors:
7
+ - ryz310
8
+ autorequire:
9
+ bindir: exe
10
+ cert_chain: []
11
+ date: 2019-04-08 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: octokit
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - ">="
18
+ - !ruby/object:Gem::Version
19
+ version: '0'
20
+ type: :runtime
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - ">="
25
+ - !ruby/object:Gem::Version
26
+ version: '0'
27
+ - !ruby/object:Gem::Dependency
28
+ name: thor
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'
41
+ - !ruby/object:Gem::Dependency
42
+ name: bundler
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - "~>"
46
+ - !ruby/object:Gem::Version
47
+ version: '1.16'
48
+ type: :development
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - "~>"
53
+ - !ruby/object:Gem::Version
54
+ version: '1.16'
55
+ - !ruby/object:Gem::Dependency
56
+ name: pry-byebug
57
+ requirement: !ruby/object:Gem::Requirement
58
+ requirements:
59
+ - - ">="
60
+ - !ruby/object:Gem::Version
61
+ version: '0'
62
+ type: :development
63
+ prerelease: false
64
+ version_requirements: !ruby/object:Gem::Requirement
65
+ requirements:
66
+ - - ">="
67
+ - !ruby/object:Gem::Version
68
+ version: '0'
69
+ - !ruby/object:Gem::Dependency
70
+ name: rake
71
+ requirement: !ruby/object:Gem::Requirement
72
+ requirements:
73
+ - - "~>"
74
+ - !ruby/object:Gem::Version
75
+ version: '10.0'
76
+ type: :development
77
+ prerelease: false
78
+ version_requirements: !ruby/object:Gem::Requirement
79
+ requirements:
80
+ - - "~>"
81
+ - !ruby/object:Gem::Version
82
+ version: '10.0'
83
+ - !ruby/object:Gem::Dependency
84
+ name: rspec
85
+ requirement: !ruby/object:Gem::Requirement
86
+ requirements:
87
+ - - ">="
88
+ - !ruby/object:Gem::Version
89
+ version: '0'
90
+ type: :development
91
+ prerelease: false
92
+ version_requirements: !ruby/object:Gem::Requirement
93
+ requirements:
94
+ - - ">="
95
+ - !ruby/object:Gem::Version
96
+ version: '0'
97
+ - !ruby/object:Gem::Dependency
98
+ name: rspec_junit_formatter
99
+ requirement: !ruby/object:Gem::Requirement
100
+ requirements:
101
+ - - ">="
102
+ - !ruby/object:Gem::Version
103
+ version: '0'
104
+ type: :development
105
+ prerelease: false
106
+ version_requirements: !ruby/object:Gem::Requirement
107
+ requirements:
108
+ - - ">="
109
+ - !ruby/object:Gem::Version
110
+ version: '0'
111
+ - !ruby/object:Gem::Dependency
112
+ name: rubocop
113
+ requirement: !ruby/object:Gem::Requirement
114
+ requirements:
115
+ - - ">="
116
+ - !ruby/object:Gem::Version
117
+ version: '0'
118
+ type: :development
119
+ prerelease: false
120
+ version_requirements: !ruby/object:Gem::Requirement
121
+ requirements:
122
+ - - ">="
123
+ - !ruby/object:Gem::Version
124
+ version: '0'
125
+ - !ruby/object:Gem::Dependency
126
+ name: rubocop-performance
127
+ requirement: !ruby/object:Gem::Requirement
128
+ requirements:
129
+ - - ">="
130
+ - !ruby/object:Gem::Version
131
+ version: '0'
132
+ type: :development
133
+ prerelease: false
134
+ version_requirements: !ruby/object:Gem::Requirement
135
+ requirements:
136
+ - - ">="
137
+ - !ruby/object:Gem::Version
138
+ version: '0'
139
+ - !ruby/object:Gem::Dependency
140
+ name: rubocop-rspec
141
+ requirement: !ruby/object:Gem::Requirement
142
+ requirements:
143
+ - - ">="
144
+ - !ruby/object:Gem::Version
145
+ version: '0'
146
+ type: :development
147
+ prerelease: false
148
+ version_requirements: !ruby/object:Gem::Requirement
149
+ requirements:
150
+ - - ">="
151
+ - !ruby/object:Gem::Version
152
+ version: '0'
153
+ - !ruby/object:Gem::Dependency
154
+ name: simplecov
155
+ requirement: !ruby/object:Gem::Requirement
156
+ requirements:
157
+ - - ">="
158
+ - !ruby/object:Gem::Version
159
+ version: '0'
160
+ type: :development
161
+ prerelease: false
162
+ version_requirements: !ruby/object:Gem::Requirement
163
+ requirements:
164
+ - - ">="
165
+ - !ruby/object:Gem::Version
166
+ version: '0'
167
+ - !ruby/object:Gem::Dependency
168
+ name: yard
169
+ requirement: !ruby/object:Gem::Requirement
170
+ requirements:
171
+ - - ">="
172
+ - !ruby/object:Gem::Version
173
+ version: '0'
174
+ type: :development
175
+ prerelease: false
176
+ version_requirements: !ruby/object:Gem::Requirement
177
+ requirements:
178
+ - - ">="
179
+ - !ruby/object:Gem::Version
180
+ version: '0'
181
+ description: It helps to create a pull request on your script
182
+ email:
183
+ - ryz310@gmail.com
184
+ executables: []
185
+ extensions: []
186
+ extra_rdoc_files: []
187
+ files:
188
+ - ".circleci/config.yml"
189
+ - ".envrc.skeleton"
190
+ - ".gitignore"
191
+ - ".rspec"
192
+ - ".rubocop.yml"
193
+ - ".rubocop_todo.yml"
194
+ - CODE_OF_CONDUCT.md
195
+ - Gemfile
196
+ - Gemfile.lock
197
+ - LICENSE.txt
198
+ - README.md
199
+ - Rakefile
200
+ - bin/console
201
+ - bin/release
202
+ - bin/setup
203
+ - lib/pr_comet.rb
204
+ - lib/pr_comet/command_line.rb
205
+ - lib/pr_comet/git/command.rb
206
+ - lib/pr_comet/github/client.rb
207
+ - lib/pr_comet/version.rb
208
+ - pr_comet.gemspec
209
+ homepage: https://github.com/ryz310/pr_comet
210
+ licenses:
211
+ - MIT
212
+ metadata: {}
213
+ post_install_message:
214
+ rdoc_options: []
215
+ require_paths:
216
+ - lib
217
+ required_ruby_version: !ruby/object:Gem::Requirement
218
+ requirements:
219
+ - - ">="
220
+ - !ruby/object:Gem::Version
221
+ version: '0'
222
+ required_rubygems_version: !ruby/object:Gem::Requirement
223
+ requirements:
224
+ - - ">="
225
+ - !ruby/object:Gem::Version
226
+ version: '0'
227
+ requirements: []
228
+ rubygems_version: 3.0.3
229
+ signing_key:
230
+ specification_version: 4
231
+ summary: Create a lots of pull request like comets
232
+ test_files: []