rubocop-automata 0.0.2

Sign up to get free protection for your applications and to get access to all the features.
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA256:
3
+ metadata.gz: de53b2876c51c29bbe6635e77b8259efb6bcbe6a354d9e51efcf7ffb2dc28c8f
4
+ data.tar.gz: 8a6371f848488251caa9eb8e024bccea7d5cf525f142f94453552206f4e18416
5
+ SHA512:
6
+ metadata.gz: 6a53d6b6299b3b8f7856d9752827baa22298eca45b6e2ddf13453c4d8789aa479f78f1995cb3fbd37ff6978aa291edcc71b6b1395c4ad76cb53177489e94364e
7
+ data.tar.gz: '0861a1d457d04e3dd31e4034f69d30a40e82424a1a189f9a79be1b71a40b16acd58f932d9d943d0967ef26d31a4bae70ca9c48f7cb6e68628bcc9ce7a4f3a0e1'
@@ -0,0 +1,39 @@
1
+ version: 2
2
+
3
+ jobs:
4
+ rake_build:
5
+ working_directory: /usr/src/app
6
+ docker:
7
+ - image: ruby:2.4.2-alpine3.6
8
+ steps:
9
+ - checkout
10
+ - run: apk --update --upgrade add --no-cache git openssh
11
+ - run: rake build
12
+
13
+ deploy:
14
+ docker:
15
+ - image: circleci/ruby:2.4
16
+ steps:
17
+ - checkout
18
+ - run:
19
+ name: create rubygems credentials
20
+ command: |
21
+ mkdir ~/.gem
22
+ echo -e "---\n:rubygems_api_key: ${RUBYGEMS_API_KEY}" > ~/.gem/credentials
23
+ chmod 0600 ~/.gem/credentials
24
+ - run: bundle install -j4 --retry=3
25
+ - run: rake release
26
+
27
+ workflows:
28
+ version: 2
29
+
30
+ workflow:
31
+ jobs:
32
+ - rake_build
33
+ - deploy:
34
+ requires:
35
+ - rake_build
36
+ filters:
37
+ branches:
38
+ only:
39
+ - deploy/production
@@ -0,0 +1 @@
1
+ Makefile
@@ -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 TODO: Write your email address. 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,6 @@
1
+ source 'https://rubygems.org'
2
+
3
+ git_source(:github) { |repo_name| "https://github.com/#{repo_name}" }
4
+
5
+ # Specify your gem's dependencies in rubocop-automata.gemspec
6
+ gemspec
@@ -0,0 +1,36 @@
1
+ PATH
2
+ remote: .
3
+ specs:
4
+ rubocop-automata (0.0.2)
5
+ rubocop
6
+
7
+ GEM
8
+ remote: https://rubygems.org/
9
+ specs:
10
+ ast (2.3.0)
11
+ parallel (1.12.1)
12
+ parser (2.4.0.2)
13
+ ast (~> 2.3)
14
+ powerpack (0.1.1)
15
+ rainbow (3.0.0)
16
+ rake (12.3.0)
17
+ rubocop (0.52.0)
18
+ parallel (~> 1.10)
19
+ parser (>= 2.4.0.2, < 3.0)
20
+ powerpack (~> 0.1)
21
+ rainbow (>= 2.2.2, < 4.0)
22
+ ruby-progressbar (~> 1.7)
23
+ unicode-display_width (~> 1.0, >= 1.0.1)
24
+ ruby-progressbar (1.9.0)
25
+ unicode-display_width (1.3.0)
26
+
27
+ PLATFORMS
28
+ ruby
29
+
30
+ DEPENDENCIES
31
+ bundler
32
+ rake
33
+ rubocop-automata!
34
+
35
+ BUNDLED WITH
36
+ 1.16.0
@@ -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,4 @@
1
+ # make release_tag
2
+ release_tag:
3
+ git checkout master
4
+ docker-compose run --rm ruby sh -c 'apk --update --upgrade add --no-cache git openssh && rake release:source_control_push[https://<github_api_key>@github.com/rvillage/rubocop-automata]'
@@ -0,0 +1,123 @@
1
+ # rubocop-automata
2
+
3
+ `rubocop-automata` is automation script for `rubocop --auto-correct` and create pull request.
4
+
5
+ By requesting a nightly build to CircleCI to execute this script, `rubocop --auto-correct` 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 'rubocop-automata'
13
+ ```
14
+
15
+ And then execute:
16
+
17
+ ```
18
+ $ bundle
19
+ ```
20
+
21
+ Or install it yourself as:
22
+
23
+ ```
24
+ $ gem install rubocop-automata
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 `rubocop-automata`, for example:
40
+
41
+ ```yaml
42
+ version: 2
43
+
44
+ default: &default
45
+ working_directory: /usr/src/app
46
+ docker:
47
+ - image: ruby:2.4.2-alpine3.6
48
+
49
+ jobs:
50
+ checkout_code:
51
+ <<: *default
52
+ steps:
53
+ - checkout
54
+ - persist_to_workspace:
55
+ root: /usr/src/app
56
+ paths:
57
+ - ./*
58
+
59
+ bundle_dependencies:
60
+ <<: *default
61
+ steps:
62
+ - attach_workspace:
63
+ at: /usr/src/app
64
+ - restore_cache:
65
+ keys:
66
+ - v1-bundler-{{ .Branch }}-{{ checksum "Gemfile.lock" }}
67
+ - v1-bundler-
68
+ - run: apk --update --upgrade add --no-cache git openssh
69
+ - run: bundle install -j4 --retry=3
70
+ - save_cache:
71
+ key: v1-bundler-{{ .Branch }}-{{ checksum "Gemfile.lock" }}
72
+ paths:
73
+ - /usr/local/bundle
74
+
75
+ auto_correction:
76
+ <<: *default
77
+ steps:
78
+ - attach_workspace:
79
+ at: /usr/src/app
80
+ - restore_cache:
81
+ key: v1-bundler-{{ .Branch }}-{{ checksum "Gemfile.lock" }}
82
+ - run: apk --update --upgrade add --no-cache git openssh curl
83
+ - run: rubocop-automata [email] [username]
84
+
85
+ workflows:
86
+ version: 2
87
+
88
+ workflow:
89
+ jobs:
90
+ - checkout_code
91
+ - bundle_dependencies:
92
+ requires:
93
+ - checkout_code
94
+ - auto_correction:
95
+ requires:
96
+ - bundle_dependencies
97
+ filters:
98
+ branches:
99
+ ignore:
100
+ - /ci\/.*/
101
+ ```
102
+
103
+ NOTE: Please make sure you replace `[email]`and `[username]` with yours.
104
+
105
+ ### CLI command references
106
+
107
+ General usage:
108
+
109
+ ```ruby
110
+ $ rubocop-automata [github email] [github username]
111
+ ```
112
+
113
+ ## Contributing
114
+
115
+ Bug reports and pull requests are welcome on GitHub at https://github.com/rvillage/rubocop-automata. 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.
116
+
117
+ ## License
118
+
119
+ The gem is available as open source under the terms of the [MIT License](https://opensource.org/licenses/MIT).
120
+
121
+ ## Code of Conduct
122
+
123
+ Everyone interacting in the rubocop-automata project’s codebases, issue trackers, chat rooms and mailing lists is expected to follow the [code of conduct](https://github.com/rvillage/rubocop-automata/blob/master/CODE_OF_CONDUCT.md).
@@ -0,0 +1 @@
1
+ require 'bundler/gem_tasks'
@@ -0,0 +1,5 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ require 'rubocop_automata'
4
+
5
+ RubocopAutomata.boot(github_email: ARGV[0], github_username: ARGV[1])
@@ -0,0 +1,10 @@
1
+ version: '3'
2
+
3
+ services:
4
+ ruby:
5
+ image: ruby:2.4.2-alpine3.6
6
+ container_name: rubocop-automata_ruby
7
+ working_dir: /usr/src/app
8
+ command: ruby -v
9
+ volumes:
10
+ - .:/usr/src/app
@@ -0,0 +1,40 @@
1
+ require 'rubocop_automata/version'
2
+ require 'rubocop_automata/skill'
3
+
4
+ require 'rubocop_automata/ci'
5
+ require 'rubocop_automata/ci/local'
6
+ require 'rubocop_automata/ci/circleci'
7
+
8
+ module RubocopAutomata
9
+ module_function
10
+
11
+ @@backend_ci = CI::CircleCI
12
+
13
+ def boot(github_email:, github_username:)
14
+ if ENV['GITHUB_ACCESS_TOKEN'].nil?
15
+ raise 'Please input ENV of GITHUB_ACCESS_TOKEN'
16
+ end
17
+
18
+ if Skill.rubocop_autocorrect
19
+ Skill.create_branch(
20
+ @@backend_ci.repository_url,
21
+ github_email,
22
+ github_username,
23
+ @@backend_ci.topic_branch
24
+ )
25
+ Skill.create_pullrequest(
26
+ @@backend_ci.repository_name,
27
+ @@backend_ci.pullrequest_title,
28
+ @@backend_ci.pullrequest_description,
29
+ @@backend_ci.base_branch,
30
+ @@backend_ci.topic_branch
31
+ )
32
+ end
33
+
34
+ true
35
+ end
36
+
37
+ def backend_ci=(ci)
38
+ @@backend_ci = ci
39
+ end
40
+ end
@@ -0,0 +1,4 @@
1
+ module RubocopAutomata
2
+ module CI
3
+ end
4
+ end
@@ -0,0 +1,32 @@
1
+ module RubocopAutomata
2
+ module CI::CircleCI
3
+ module_function
4
+
5
+ def repository_url
6
+ "https://#{ENV['GITHUB_ACCESS_TOKEN']}@github.com/#{repository_name}"
7
+ end
8
+
9
+ def repository_name
10
+ "#{ENV['CIRCLE_PROJECT_USERNAME']}/#{ENV['CIRCLE_PROJECT_REPONAME']}"
11
+ end
12
+
13
+ def base_branch
14
+ ENV['CIRCLE_BRANCH']
15
+ end
16
+
17
+ def topic_branch
18
+ "ci/auto_correction-#{ENV['CIRCLE_BUILD_NUM']}"
19
+ end
20
+
21
+ def pullrequest_title
22
+ "rubocop --auto-correct at #{`echo -n $(date)`}"
23
+ end
24
+
25
+ def pullrequest_description
26
+ <<~DESCRIPTION
27
+ PR: #{ENV['CIRCLE_PULL_REQUEST']}
28
+ Auto generated by [CircleCI](#{ENV['CIRCLE_BUILD_URL']})
29
+ DESCRIPTION
30
+ end
31
+ end
32
+ end
@@ -0,0 +1,38 @@
1
+ module RubocopAutomata
2
+ module CI::Local
3
+ module_function
4
+
5
+ def repository_url
6
+ "https://#{ENV['GITHUB_ACCESS_TOKEN']}@github.com/#{repository_name}"
7
+ end
8
+
9
+ def repository_name
10
+ if ENV['AUTOMATA_REPOSITORY_NAME'].nil?
11
+ raise 'Please input ENV of AUTOMATA_REPOSITORY_NAME'
12
+ end
13
+ ENV['AUTOMATA_REPOSITORY_NAME']
14
+ end
15
+
16
+ def base_branch
17
+ if ENV['AUTOMATA_BASE_BRANCH'].nil?
18
+ raise 'Please input ENV of AUTOMATA_BASE_BRANCH'
19
+ end
20
+ ENV['AUTOMATA_BASE_BRANCH']
21
+ end
22
+
23
+ def topic_branch
24
+ @@topic_branch ||= "ci/auto_correction-#{Time.now.to_i}"
25
+ end
26
+
27
+ def pullrequest_title
28
+ "rubocop --auto-correct at #{`echo -n $(date)`}"
29
+ end
30
+
31
+ def pullrequest_description
32
+ <<~DESCRIPTION
33
+ PR: https://github.com/#{repository_name}/pull/:id
34
+ Auto generated by localhost
35
+ DESCRIPTION
36
+ end
37
+ end
38
+ end
@@ -0,0 +1,30 @@
1
+ require 'json'
2
+ require 'shellwords'
3
+
4
+ module RubocopAutomata
5
+ module Skill
6
+ module_function
7
+
8
+ def rubocop_autocorrect
9
+ `rubocop --auto-correct`
10
+ `git diff --numstat` != ''
11
+ end
12
+
13
+ def create_branch(repository_url, github_email, github_username, new_branch)
14
+ `git config --local user.email "#{github_email}"`
15
+ `git config --local user.name "#{github_username}"`
16
+ `git checkout -b #{new_branch}`
17
+ `git add .`
18
+ `git commit -m ":shirt: rubocop --auto-correct"`
19
+ `git push #{repository_url} #{new_branch}`
20
+ end
21
+
22
+ def create_pullrequest(repository_name, title, description, base_branch, topic_branch)
23
+ options = <<~OPTIONS.strip
24
+ -X POST -H "Authorization: token #{ENV['GITHUB_ACCESS_TOKEN']}" \
25
+ --data #{Shellwords.escape({title: title, body: description, head: topic_branch, base: base_branch}.to_json)}
26
+ OPTIONS
27
+ `curl #{options} https://api.github.com/repos/#{repository_name}/pulls`
28
+ end
29
+ end
30
+ end
@@ -0,0 +1,3 @@
1
+ module RubocopAutomata
2
+ VERSION = '0.0.2'.freeze
3
+ end
@@ -0,0 +1,27 @@
1
+ lib = File.expand_path('../lib', __FILE__)
2
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
3
+ require 'rubocop_automata/version'
4
+
5
+ Gem::Specification.new do |spec|
6
+ spec.name = 'rubocop-automata'
7
+ spec.version = RubocopAutomata::VERSION
8
+ spec.authors = ['rvillage']
9
+ spec.email = ['rvillage@gmail.com']
10
+
11
+ spec.summary = 'Create GitHub PullRequest of rubocop --autocorrect in CircleCI'
12
+ spec.description = 'For rubocop --autocorrect. Use in CircleCI'
13
+ spec.homepage = 'https://github.com/rvillage/rubocop-automata'
14
+ spec.license = 'MIT'
15
+
16
+ spec.files = `git ls-files -z`.split("\x0").reject do |f|
17
+ f.match(%r{^(test|spec|features)/})
18
+ end
19
+ spec.bindir = 'bin'
20
+ spec.executables = spec.files.grep(%r{^bin/}) { |f| File.basename(f) }
21
+ spec.require_paths = ['lib']
22
+
23
+ spec.add_runtime_dependency 'rubocop'
24
+
25
+ spec.add_development_dependency 'bundler'
26
+ spec.add_development_dependency 'rake'
27
+ end
metadata ADDED
@@ -0,0 +1,105 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: rubocop-automata
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.0.2
5
+ platform: ruby
6
+ authors:
7
+ - rvillage
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2017-12-24 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: rubocop
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: bundler
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - ">="
32
+ - !ruby/object:Gem::Version
33
+ version: '0'
34
+ type: :development
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: rake
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - ">="
46
+ - !ruby/object:Gem::Version
47
+ version: '0'
48
+ type: :development
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - ">="
53
+ - !ruby/object:Gem::Version
54
+ version: '0'
55
+ description: For rubocop --autocorrect. Use in CircleCI
56
+ email:
57
+ - rvillage@gmail.com
58
+ executables:
59
+ - rubocop-automata
60
+ extensions: []
61
+ extra_rdoc_files: []
62
+ files:
63
+ - ".circleci/config.yml"
64
+ - ".gitignore"
65
+ - CODE_OF_CONDUCT.md
66
+ - Gemfile
67
+ - Gemfile.lock
68
+ - LICENSE.txt
69
+ - Makefile.sample
70
+ - README.md
71
+ - Rakefile
72
+ - bin/rubocop-automata
73
+ - docker-compose.yml
74
+ - lib/rubocop_automata.rb
75
+ - lib/rubocop_automata/ci.rb
76
+ - lib/rubocop_automata/ci/circleci.rb
77
+ - lib/rubocop_automata/ci/local.rb
78
+ - lib/rubocop_automata/skill.rb
79
+ - lib/rubocop_automata/version.rb
80
+ - rubocop-automata.gemspec
81
+ homepage: https://github.com/rvillage/rubocop-automata
82
+ licenses:
83
+ - MIT
84
+ metadata: {}
85
+ post_install_message:
86
+ rdoc_options: []
87
+ require_paths:
88
+ - lib
89
+ required_ruby_version: !ruby/object:Gem::Requirement
90
+ requirements:
91
+ - - ">="
92
+ - !ruby/object:Gem::Version
93
+ version: '0'
94
+ required_rubygems_version: !ruby/object:Gem::Requirement
95
+ requirements:
96
+ - - ">="
97
+ - !ruby/object:Gem::Version
98
+ version: '0'
99
+ requirements: []
100
+ rubyforge_project:
101
+ rubygems_version: 2.7.3
102
+ signing_key:
103
+ specification_version: 4
104
+ summary: Create GitHub PullRequest of rubocop --autocorrect in CircleCI
105
+ test_files: []