sakanax 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
+ SHA1:
3
+ metadata.gz: d166a1dab45a55ebbd464dddec5f4aac26d89236
4
+ data.tar.gz: 52648fc73bad16199fc63cbbb71b8c243444f017
5
+ SHA512:
6
+ metadata.gz: a01d8aa57f2464cf68b6a8bd31586ef1595603bdf83b28190173cf8d35fa536b15dce39e97657fb9f69b60a353ccf0961b20f59a19e0792659cd73e213b77a0b
7
+ data.tar.gz: 9d98dccef5ee793fc383667173d98b9397038b9f40f917a57b414181c74550daaa7ff5ccb38d7f7e67e28cf1141abb3813c0759a7165ac46cd50577bfd808df1
data/.gitignore ADDED
@@ -0,0 +1,9 @@
1
+ /.bundle/
2
+ /.yardoc
3
+ /_yardoc/
4
+ /coverage/
5
+ /doc/
6
+ /pkg/
7
+ /spec/reports/
8
+ /tmp/
9
+ vendor/
data/.sakanax.yml ADDED
@@ -0,0 +1,4 @@
1
+ # List of search target files
2
+ detect_files:
3
+ - lib/sakanax.rb
4
+ - lib/sakanax/cli.rb
@@ -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 daisuke.awaji@i.softbank.jp. 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,11 @@
1
+ source "https://rubygems.org"
2
+
3
+ gem 'thor', '~> 0.19.1'
4
+ gem "octokit", "~> 4.0"
5
+ gem 'tty-spinner'
6
+
7
+
8
+ git_source(:github) {|repo_name| "https://github.com/#{repo_name}" }
9
+
10
+ # Specify your gem's dependencies in sakanax.gemspec
11
+ gemspec
data/Gemfile.lock ADDED
@@ -0,0 +1,38 @@
1
+ PATH
2
+ remote: .
3
+ specs:
4
+ sakanax (0.1.0)
5
+
6
+ GEM
7
+ remote: https://rubygems.org/
8
+ specs:
9
+ addressable (2.5.2)
10
+ public_suffix (>= 2.0.2, < 4.0)
11
+ faraday (0.15.3)
12
+ multipart-post (>= 1.2, < 3)
13
+ multipart-post (2.0.0)
14
+ octokit (4.13.0)
15
+ sawyer (~> 0.8.0, >= 0.5.3)
16
+ public_suffix (3.0.3)
17
+ rake (10.5.0)
18
+ sawyer (0.8.1)
19
+ addressable (>= 2.3.5, < 2.6)
20
+ faraday (~> 0.8, < 1.0)
21
+ thor (0.19.4)
22
+ tty-cursor (0.6.0)
23
+ tty-spinner (0.8.0)
24
+ tty-cursor (>= 0.5.0)
25
+
26
+ PLATFORMS
27
+ ruby
28
+
29
+ DEPENDENCIES
30
+ bundler (~> 1.16)
31
+ octokit (~> 4.0)
32
+ rake (~> 10.0)
33
+ sakanax!
34
+ thor (~> 0.19.1)
35
+ tty-spinner
36
+
37
+ BUNDLED WITH
38
+ 1.16.2
data/LICENSE.txt ADDED
@@ -0,0 +1,21 @@
1
+ The MIT License (MIT)
2
+
3
+ Copyright (c) 2018 daisuke-awaji
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,112 @@
1
+ # Sakanax <img class="avatar" src="https://user-images.githubusercontent.com/20736455/48205670-effe4300-e3af-11e8-8cfd-7078f8965e1f.png" width="44" height="44">
2
+
3
+ Sakanax is a CLI tool for identifying files that are up in Github PullRequest. For example, specifying a commit ID specifies a PullRequest including the commit ID, and also acquires a list of files included in the PullRequest.
4
+
5
+
6
+ ## Usage
7
+
8
+ First, Specify Github's access token and repository name as an environment variable and put .sakanax.yml in your project root directory.
9
+
10
+ ##### Github token / repository
11
+
12
+ ```bash
13
+ $ export GITHUB_TOKEN=<personal access token>
14
+ $ export GITHUB_REPOSITORY=<your repository name>
15
+ ```
16
+
17
+ ##### .sakanax.yml
18
+
19
+ ```yaml
20
+ detect_files:
21
+ - "src/main/file.rb"
22
+ - "lib/etc.rb"
23
+ - ....
24
+ ```
25
+
26
+ ### help
27
+
28
+ ```bash
29
+ $ sakanax help
30
+ Commands:
31
+ sakanax diff_files --sha=SHA # Detect files included in the PullRequests containing the target commit ID (sha).
32
+ sakanax help [COMMAND] # Describe available commands or one specific command
33
+ sakanax pull_requests --sha=SHA # A list of PullRequests containing the target commit ID (sha).
34
+ ```
35
+
36
+ ### pull_requests
37
+ A list of PullRequests containing the target commit ID (sha).
38
+ ```bash
39
+ $ sakanax pull_requests --sha 536ad1c5c6e5a675122eb0fdcb4ac5da06def098
40
+ [3, 2, 1]
41
+ ```
42
+
43
+ ### diff_files
44
+ Detect files included in the PullRequests containing the target commit ID (sha).
45
+ ```bash
46
+ $ sakanax diff_files --sha c5c6e5a6756def0986ad1122eb0a0fdcb4ac5d53
47
+ "PullRequest: 32, diff files: ['diff file1', 'diff file2', ...]"
48
+ ```
49
+
50
+ ### detect_file
51
+ Put .sakanax.yml in your project root directory. Detect file in .sakanax.yml.
52
+
53
+ ```bash
54
+ $ sakanax detect_file --sha aed28c5aa60398fda946878978168890b0x0007a
55
+ "[INFO] detected [[\"lib/sakanax/cli.rb\"]]"
56
+
57
+ $ sakanax detect_file --sha 17ff60e38f98aed28c5aa60398fda94687897816
58
+ "[INFO] target commit ID (sha: 17ff60e38f98aed28c5aa60398fda94687897816) does not exist in the currently open PullRequests."
59
+ "[INFO] Anything detcted.
60
+ ```
61
+
62
+ ### Actual Usage
63
+ Based on the result of sakanax detect_files command, it judges whether to test the target file.
64
+
65
+ ```bash
66
+ #!/bin/bash
67
+
68
+ RESULT=$(sakanax detect_files --sha <COMMIT ID> --config .sakanax.yml)
69
+
70
+ if [ "${RESULT}" == false ]; then
71
+ echo "Could not find the file contained in .sakanax.yml."
72
+ else
73
+ echo "Test the detected file"
74
+ # ...
75
+ # ...
76
+ fi
77
+ ```
78
+
79
+ ## Installation
80
+
81
+ Add this line to your application's Gemfile:
82
+
83
+ ```ruby
84
+ gem 'sakanax'
85
+ ```
86
+
87
+ And then execute:
88
+
89
+ $ bundle
90
+
91
+ Or install it yourself as:
92
+
93
+ $ gem install sakanax
94
+
95
+
96
+ ## Development
97
+
98
+ After checking out the repo, run `bin/setup` to install dependencies. You can also run `bin/console` for an interactive prompt that will allow you to experiment.
99
+
100
+ 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).
101
+
102
+ ## Contributing
103
+
104
+ Bug reports and pull requests are welcome on GitHub at https://github.com/[USERNAME]/sakanax. 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.
105
+
106
+ ## License
107
+
108
+ The gem is available as open source under the terms of the [MIT License](https://opensource.org/licenses/MIT).
109
+
110
+ ## Code of Conduct
111
+
112
+ Everyone interacting in the Sakanax project’s codebases, issue trackers, chat rooms and mailing lists is expected to follow the [code of conduct](https://github.com/[USERNAME]/sakanax/blob/master/CODE_OF_CONDUCT.md).
data/Rakefile ADDED
@@ -0,0 +1,2 @@
1
+ require "bundler/gem_tasks"
2
+ task :default => :spec
data/bin/console ADDED
@@ -0,0 +1,14 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ require "bundler/setup"
4
+ require "sakanax"
5
+
6
+ # You can add fixtures and/or initialization code here to make experimenting
7
+ # with your gem easier. You can also use a different console, if you like.
8
+
9
+ # (If you use this, don't forget to add pry to your Gemfile!)
10
+ # require "pry"
11
+ # Pry.start
12
+
13
+ require "irb"
14
+ IRB.start(__FILE__)
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 --path vendor/bundle
7
+
8
+ # Do any other automated setup that you need to do here
data/exe/sakanax ADDED
@@ -0,0 +1,5 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ require "sakanax"
4
+
5
+ Sakanax::CLI.start
@@ -0,0 +1,58 @@
1
+ require 'sakanax'
2
+ require 'thor'
3
+ require 'octokit'
4
+ require 'tty-spinner'
5
+ require_relative 'github'
6
+
7
+ module Sakanax
8
+ # CLI Class
9
+ class CLI < Thor
10
+ class_option :help, type: :boolean, aliases: '-h', desc: 'help message.'
11
+ class_option 'config', type: :string, required: false
12
+
13
+ def initialize(*args)
14
+ super
15
+ config = File.join(Dir.pwd, '.sakanax.yml') if config.nil?
16
+ @github = Github.new(config)
17
+ @sha = options['sha']
18
+ spinner = TTY::Spinner.new(':spinner ', format: :dots_2)
19
+ spinner.auto_spin
20
+ end
21
+
22
+ desc 'version', 'version'
23
+ def version
24
+ puts "sakanax #{Sakanax::VERSION}"
25
+ end
26
+
27
+ option 'sha', type: :string, required: true
28
+ desc 'pull_requests', \
29
+ 'A list of PullRequests containing the target commit ID (sha).'
30
+ def pull_requests
31
+ puts @github.get_pr_including_target_commit(options['sha'])
32
+ end
33
+
34
+ option 'sha', type: :string, required: true
35
+ desc 'diff_files', \
36
+ 'Detect files included in the PullRequests ' \
37
+ 'containing the target commit ID (sha).'
38
+ def diff_files
39
+ pull_requests = @github.get_pr_including_target_commit(@sha)
40
+ pull_requests.each do |pr|
41
+ puts "PR: #{pr}, Diff files: #{@github.get_files_with_changes(pr)}"
42
+ end
43
+ end
44
+
45
+ desc 'detect_files', \
46
+ 'It judges whether there is a file to be searched in PullRequest. '
47
+ long_desc <<-LONGDESC
48
+ If the file exists, it will return the list of the specified file.
49
+
50
+ If the file can not be found, false is returned.
51
+ LONGDESC
52
+ option 'sha', type: :string, required: true
53
+ def detect_files
54
+ detect_files = @github.detect_files(@sha)
55
+ puts detect_files.empty? ? false : "Detected files: #{detect_files}"
56
+ end
57
+ end
58
+ end
@@ -0,0 +1,62 @@
1
+ require 'yaml'
2
+
3
+ # Github
4
+ class Github
5
+ def initialize(config)
6
+ @client = Octokit::Client.new(access_token: ENV['GITHUB_TOKEN'])
7
+ @repository = ENV['GITHUB_REPOSITORY']
8
+ @yaml = load_config(config)
9
+ end
10
+
11
+ # Get a list of PullRequests including commit ID (sha) as an array
12
+ def get_pr_including_target_commit(sha)
13
+ pr_including_target_commit = []
14
+ fetch_opened_pull_requests.each do |pr|
15
+ @client.pull_request_commits(@repository, pr).each do |commit|
16
+ pr_including_target_commit.push(pr) if sha == commit[:sha]
17
+ end
18
+ end
19
+ puts "[INFO] Target sha: #{sha} is not exist in open PullRequests" \
20
+ if pr_including_target_commit.empty?
21
+ pr_including_target_commit
22
+ end
23
+
24
+ # Extract the changed file from the number of PR to be tested
25
+ def get_files_with_changes(pull_request)
26
+ files = []
27
+ @client.pull_request_files(@repository, pull_request).each do |file|
28
+ files.push(file[:filename])
29
+ end
30
+ puts '[INFO] No file changed in the specified PullRequest' if files.empty?
31
+ files
32
+ end
33
+
34
+ # Checks whether the file to be searched exists
35
+ # in the pull request including the specified commit ID.
36
+ def detect_files(sha)
37
+ duplicated_files = []
38
+ get_pr_including_target_commit(sha).each do |pr|
39
+ duplicated_files.push(get_files_with_changes(pr) & @yaml['detect_files'])
40
+ duplicated_files.flatten!
41
+ end
42
+ duplicated_files
43
+ end
44
+
45
+ private
46
+
47
+ def load_config(config)
48
+ return YAML.load_file(config) if File.exist?(config)
49
+
50
+ puts "[INFO] Config file #{config} does not exist"
51
+ exit 0
52
+ end
53
+
54
+ # Get a list of open state PullRequests as an array
55
+ def fetch_opened_pull_requests
56
+ opened_pull_requests = []
57
+ @client.pull_requests(@repository).each do |pr|
58
+ opened_pull_requests.push(pr[:number])
59
+ end
60
+ opened_pull_requests
61
+ end
62
+ end
@@ -0,0 +1,3 @@
1
+ module Sakanax
2
+ VERSION = '0.1.0'
3
+ end
data/lib/sakanax.rb ADDED
@@ -0,0 +1,6 @@
1
+ require 'sakanax/version'
2
+ require 'sakanax/cli'
3
+
4
+ module Sakanax
5
+ # Your code goes here...
6
+ end
data/sakanax.gemspec ADDED
@@ -0,0 +1,36 @@
1
+ lib = File.expand_path('lib', __dir__)
2
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
3
+ require 'sakanax/version'
4
+
5
+ Gem::Specification.new do |spec|
6
+ spec.name = 'sakanax'
7
+ spec.version = Sakanax::VERSION
8
+ spec.authors = ['daisuke-awaji']
9
+ spec.email = ['gee.awa@gmail.com']
10
+
11
+ spec.summary = 'Sakanax is simple cli tool to detect github pull request files.'
12
+ spec.description = 'Sakanax is a CLI tool for identifying files that are up in Github PullRequest. For example, specifying a commit ID specifies a PullRequest including the commit ID, and also acquires a list of files included in the PullRequest.'
13
+ spec.homepage = 'https://github.com/sakanax/sakanax'
14
+ spec.license = 'MIT'
15
+
16
+ # Prevent pushing this gem to RubyGems.org. To allow pushes either set the 'allowed_push_host'
17
+ # to allow pushing to a single host or delete this section to allow pushing to any host.
18
+ # if spec.respond_to?(:metadata)
19
+ # spec.metadata['allowed_push_host'] = "Set to 'http://mygemserver.com'"
20
+ # else
21
+ # raise 'RubyGems 2.0 or newer is required to protect against ' \
22
+ # 'public gem pushes.'
23
+ # end
24
+
25
+ # Specify which files should be added to the gem when it is released.
26
+ # The `git ls-files -z` loads the files in the RubyGem that have been added into git.
27
+ spec.files = Dir.chdir(File.expand_path(__dir__)) do
28
+ `git ls-files -z`.split("\x0").reject { |f| f.match(%r{^(test|spec|features)/}) }
29
+ end
30
+ spec.bindir = 'exe'
31
+ spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
32
+ spec.require_paths = ['lib']
33
+
34
+ spec.add_development_dependency 'bundler', '~> 1.16'
35
+ spec.add_development_dependency 'rake', '~> 10.0'
36
+ end
metadata ADDED
@@ -0,0 +1,91 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: sakanax
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.1.0
5
+ platform: ruby
6
+ authors:
7
+ - daisuke-awaji
8
+ autorequire:
9
+ bindir: exe
10
+ cert_chain: []
11
+ date: 2018-11-10 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
+ - !ruby/object:Gem::Dependency
28
+ name: rake
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - "~>"
32
+ - !ruby/object:Gem::Version
33
+ version: '10.0'
34
+ type: :development
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - "~>"
39
+ - !ruby/object:Gem::Version
40
+ version: '10.0'
41
+ description: Sakanax is a CLI tool for identifying files that are up in Github PullRequest.
42
+ For example, specifying a commit ID specifies a PullRequest including the commit
43
+ ID, and also acquires a list of files included in the PullRequest.
44
+ email:
45
+ - gee.awa@gmail.com
46
+ executables:
47
+ - sakanax
48
+ extensions: []
49
+ extra_rdoc_files: []
50
+ files:
51
+ - ".gitignore"
52
+ - ".sakanax.yml"
53
+ - CODE_OF_CONDUCT.md
54
+ - Gemfile
55
+ - Gemfile.lock
56
+ - LICENSE.txt
57
+ - README.md
58
+ - Rakefile
59
+ - bin/console
60
+ - bin/setup
61
+ - exe/sakanax
62
+ - lib/sakanax.rb
63
+ - lib/sakanax/cli.rb
64
+ - lib/sakanax/github.rb
65
+ - lib/sakanax/version.rb
66
+ - sakanax.gemspec
67
+ homepage: https://github.com/sakanax/sakanax
68
+ licenses:
69
+ - MIT
70
+ metadata: {}
71
+ post_install_message:
72
+ rdoc_options: []
73
+ require_paths:
74
+ - lib
75
+ required_ruby_version: !ruby/object:Gem::Requirement
76
+ requirements:
77
+ - - ">="
78
+ - !ruby/object:Gem::Version
79
+ version: '0'
80
+ required_rubygems_version: !ruby/object:Gem::Requirement
81
+ requirements:
82
+ - - ">="
83
+ - !ruby/object:Gem::Version
84
+ version: '0'
85
+ requirements: []
86
+ rubyforge_project:
87
+ rubygems_version: 2.5.1
88
+ signing_key:
89
+ specification_version: 4
90
+ summary: Sakanax is simple cli tool to detect github pull request files.
91
+ test_files: []