pr-daikou 0.0.1

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.
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA256:
3
+ metadata.gz: b95b6e44f2b82266c1ed53d026ecf64556de31765455312d733a1c6dfa3514f5
4
+ data.tar.gz: 6260679fd435d1233952a10a77a3ea5a81e328d4f7d79361aea8198a4c238d3b
5
+ SHA512:
6
+ metadata.gz: c46c31874b6b9787d5c79fdedc8cc45159664b177fbff5ca0daf8a2c246831925e78e89b89617acd9528435320474eabcac8a4bcc9e4a47b636cf0fabb5dbf1d
7
+ data.tar.gz: 40e56e0914565a69690bdb5ab08d59e0ff5bbc84b19d4d3273156e49eb99eb085d713fc90fcdb343b1c81883e134e17a86d854357cb8903b27318806ef12a2de
@@ -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 rvillage@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/
@@ -0,0 +1,21 @@
1
+ The MIT License (MIT)
2
+
3
+ Copyright (c) 2017 rvillage
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.
@@ -0,0 +1,94 @@
1
+ # pr-daikou
2
+
3
+ `pr-daikou` is agency script for Create Pull Request.
4
+
5
+ By requesting a build to CI service (e.g. CircleCI) to execute this script, Automatic code correction (e.g. `rubocop --auto-correct`, `bundle update`) is invoked, then commit changes and create pull request to GitHub repository if there some changes exist.
6
+
7
+ ## Installation
8
+
9
+ Add this line to your application's Gemfile:
10
+
11
+ ```ruby
12
+ gem 'pr-daikou'
13
+ ```
14
+
15
+ And then execute:
16
+
17
+ ```
18
+ $ bundle
19
+ ```
20
+
21
+ Or install it yourself as:
22
+
23
+ ```
24
+ $ gem install pr-daikou
25
+ ```
26
+
27
+ ## Usage
28
+
29
+ ### Setting GitHub personal access token to CircleCI
30
+
31
+ GitHub personal access token is required for sending pull requests to your repository.
32
+
33
+ 1. Go to [your account's settings page](https://github.com/settings/tokens) and generate a personal access token with "repo" scope
34
+ 2. On CircleCI dashboard, go to your application's "Project Settings" -> "Environment Variables"
35
+ 3. Add an environment variable `GITHUB_ACCESS_TOKEN` with your GitHub personal access token
36
+
37
+ ### Configure circle.yml
38
+
39
+ Configure your `.circleci/config.yml` to run `pr-daikou`, for example:
40
+
41
+ #### CircleCI1.0
42
+
43
+ ```yaml
44
+ deployment:
45
+ code_correction:
46
+ branch: develop
47
+ commands:
48
+ - automatic code correction command (e.g. rubocop --auto-correct || true)
49
+ - pr-daikou
50
+ ```
51
+
52
+ #### CircleCI2.0
53
+
54
+ ```yaml
55
+ version: 2
56
+
57
+ jobs:
58
+ build:
59
+ docker:
60
+ - image: circleci/ruby:2.5
61
+ steps:
62
+ - checkout
63
+ - run: bundle install -j4 --retry=3
64
+ - run: automatic code correction command (e.g. rubocop --auto-correct || true)
65
+ - run: pr-daikou
66
+ ```
67
+
68
+ ### CLI command references
69
+
70
+ General usage:
71
+
72
+ ```ruby
73
+ $ pr-daikou --help
74
+ Usage: pr-daikou [options]
75
+ --email EMAIL git committed user email, default: pr_daikou@example.com
76
+ --name NAME git committed user name, default: pr_daikou
77
+ -T, --title TITLE pull request title, default: PR daikou [at Mon Jan 1 12:34:56 UTC 2017]
78
+ -m, --commit MESSAGE add git commit message, default: :robot: PR daikou
79
+ -b, --base BRANCH pull request base branch, default: master
80
+ -t, --topic BRANCH create new branch, default: ci/pr-daikou_[20170101123456.000]
81
+ -u, --pullrequest URL add new pull request description, default: nil
82
+ ```
83
+
84
+ ## Contributing
85
+
86
+ Bug reports and pull requests are welcome on GitHub at https://github.com/rvillage/pr-daikou. 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.
87
+
88
+ ## License
89
+
90
+ The gem is available as open source under the terms of the [MIT License](https://opensource.org/licenses/MIT).
91
+
92
+ ## Code of Conduct
93
+
94
+ Everyone interacting in the pr-daikou project’s codebases, issue trackers, chat rooms and mailing lists is expected to follow the [code of conduct](https://github.com/rvillage/pr-daikou/blob/master/CODE_OF_CONDUCT.md).
@@ -0,0 +1,5 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ require 'pr-daikou'
4
+
5
+ PRDaikou.exec(*PRDaikou::CLI.parse_options)
@@ -0,0 +1,55 @@
1
+ require 'pr-daikou/version'
2
+ require 'pr-daikou/cli'
3
+
4
+ require 'pr-daikou/host/github'
5
+
6
+ # Create pull request of CI Service
7
+ module PRDaikou
8
+ module_function
9
+
10
+ def exec(options, _args, current_time = Time.now)
11
+ if ENV['GITHUB_ACCESS_TOKEN'].nil?
12
+ raise 'Please input ENV of GITHUB_ACCESS_TOKEN'
13
+ end
14
+
15
+ return unless code_changed?
16
+
17
+ PRDaikou::Host::Github.create_branch(
18
+ options[:email],
19
+ options[:name],
20
+ topic_branch(options[:topic], current_time),
21
+ options[:commit]
22
+ )
23
+ PRDaikou::Host::Github.create_pullrequest(
24
+ pullrequest_title(options[:title]),
25
+ pullrequest_description(options[:url]),
26
+ options[:base],
27
+ topic_branch(options[:topic], current_time)
28
+ )
29
+
30
+ true
31
+ end
32
+
33
+ def code_changed?
34
+ `git diff --numstat` != ''
35
+ end
36
+
37
+ def topic_branch(topic_name, current_time)
38
+ if topic_name == 'ci/pr-daikou'
39
+ "#{topic_name}_#{current_time.strftime('%Y%m%d%H%M%S.%L')}"
40
+ else
41
+ topic_name
42
+ end
43
+ end
44
+
45
+ def pullrequest_title(title)
46
+ "#{title} at #{`echo -n $(date)`}"
47
+ end
48
+
49
+ def pullrequest_description(base_pullrequest_url)
50
+ <<~DESCRIPTION
51
+ PR: #{base_pullrequest_url}
52
+ Auto generated by [PR daikou](https://rubygems.org/gems/pr-daikou)
53
+ DESCRIPTION
54
+ end
55
+ end
@@ -0,0 +1,45 @@
1
+ require 'optparse'
2
+
3
+ module PRDaikou
4
+ # Command Line Interface
5
+ class CLI
6
+ class << self
7
+ def parse_options
8
+ new.parse
9
+ end
10
+ end
11
+
12
+ def initialize
13
+ @options = {
14
+ commit: ':robot: PR daikou',
15
+ title: 'PR daikou',
16
+ email: 'pr_daikou@example.com',
17
+ name: 'pr_daikou',
18
+ base: 'master',
19
+ topic: 'ci/pr-daikou',
20
+ url: nil
21
+ }
22
+ end
23
+
24
+ def parse(argv: ARGV)
25
+ args = parser.parse(argv)
26
+ [@options, args]
27
+ end
28
+
29
+ private
30
+
31
+ def parser
32
+ @parser ||= OptionParser.new do |opt|
33
+ opt.banner = 'Usage: pr-daikou [options]'
34
+
35
+ opt.on('--email EMAIL', "git committed user email, default: #{@options[:email]}") {|v| @options[:email] = v }
36
+ opt.on('--name NAME', "git committed user name, default: #{@options[:name]}") {|v| @options[:name] = v }
37
+ opt.on('-T', '--title TITLE', "pull request title, default: #{@options[:title]} [at Mon Jan 1 12:34:56 UTC 2017]") {|v| @options[:title] = v }
38
+ opt.on('-m', '--commit MESSAGE', "add git commit message, default: #{@options[:commit]}") {|v| @options[:commit] = v }
39
+ opt.on('-b', '--base BRANCH', "pull request base branch, default: #{@options[:base]}") {|v| @options[:base] = v }
40
+ opt.on('-t', '--topic BRANCH', "create new branch, default: #{@options[:topic]}_[20170101123456.000]") {|v| @options[:topic] = v }
41
+ opt.on('-u', '--pullrequest URL', 'add new pull request description, default: nil') {|v| @options[:url] = v }
42
+ end
43
+ end
44
+ end
45
+ end
@@ -0,0 +1,37 @@
1
+ require 'json'
2
+ require 'shellwords'
3
+
4
+ module PRDaikou
5
+ module Host
6
+ # For hosting GitHub
7
+ module Github
8
+ module_function
9
+
10
+ def create_branch(email, username, new_branch, commit_message)
11
+ `git config --local user.email "#{email}"`
12
+ `git config --local user.name "#{username}"`
13
+ `git checkout -b #{new_branch}`
14
+ `git add .`
15
+ `git commit -m "#{commit_message}"`
16
+ `git push #{repository_url} #{new_branch}`
17
+ end
18
+
19
+ def create_pullrequest(title, description, base_branch, new_branch)
20
+ options = <<~OPTIONS.strip
21
+ -X POST -H "Authorization: token #{ENV['GITHUB_ACCESS_TOKEN']}" \
22
+ --data #{Shellwords.escape({title: title, body: description, head: new_branch, base: base_branch}.to_json)}
23
+ OPTIONS
24
+
25
+ `curl #{options} https://api.github.com/repos/#{repository_name}/pulls`
26
+ end
27
+
28
+ def repository_url
29
+ "https://#{ENV['GITHUB_ACCESS_TOKEN']}@github.com/#{repository_name}"
30
+ end
31
+
32
+ def repository_name
33
+ /^.+?github.com[:\/](?<repository_name>.+?)\.git$/.match(`git config --get remote.origin.url`)[:repository_name]
34
+ end
35
+ end
36
+ end
37
+ end
@@ -0,0 +1,3 @@
1
+ module PRDaikou
2
+ VERSION = '0.0.1'.freeze
3
+ end
metadata ADDED
@@ -0,0 +1,67 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: pr-daikou
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.0.1
5
+ platform: ruby
6
+ authors:
7
+ - rvillage
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2017-12-31 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: bundler
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - "~>"
18
+ - !ruby/object:Gem::Version
19
+ version: '1.16'
20
+ type: :development
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - "~>"
25
+ - !ruby/object:Gem::Version
26
+ version: '1.16'
27
+ description: Create GitHub PullRequest of code changes in CI Service
28
+ email:
29
+ - rvillage@gmail.com
30
+ executables:
31
+ - pr-daikou
32
+ extensions: []
33
+ extra_rdoc_files: []
34
+ files:
35
+ - CODE_OF_CONDUCT.md
36
+ - LICENSE.txt
37
+ - README.md
38
+ - bin/pr-daikou
39
+ - lib/pr-daikou.rb
40
+ - lib/pr-daikou/cli.rb
41
+ - lib/pr-daikou/host/github.rb
42
+ - lib/pr-daikou/version.rb
43
+ homepage: https://github.com/rvillage/pr-daikou
44
+ licenses:
45
+ - MIT
46
+ metadata: {}
47
+ post_install_message:
48
+ rdoc_options: []
49
+ require_paths:
50
+ - lib
51
+ required_ruby_version: !ruby/object:Gem::Requirement
52
+ requirements:
53
+ - - ">="
54
+ - !ruby/object:Gem::Version
55
+ version: '2.1'
56
+ required_rubygems_version: !ruby/object:Gem::Requirement
57
+ requirements:
58
+ - - ">="
59
+ - !ruby/object:Gem::Version
60
+ version: '0'
61
+ requirements: []
62
+ rubyforge_project:
63
+ rubygems_version: 2.7.4
64
+ signing_key:
65
+ specification_version: 4
66
+ summary: Create GitHub PullRequest of code changes in CI Service
67
+ test_files: []