github_flow_cli 0.1.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/.gitignore +10 -0
- data/.rspec +3 -0
- data/CODE_OF_CONDUCT.md +74 -0
- data/Gemfile +6 -0
- data/Gemfile.lock +61 -0
- data/LICENSE.txt +21 -0
- data/README.md +35 -0
- data/Rakefile +2 -0
- data/bin/console +6 -0
- data/bin/rspec +21 -0
- data/bin/setup +8 -0
- data/exe/hubflow +12 -0
- data/github_flow_cli.gemspec +43 -0
- data/lib/commands/issue.rb +55 -0
- data/lib/commands/pr.rb +31 -0
- data/lib/github_flow_cli/api.rb +88 -0
- data/lib/github_flow_cli/cli.rb +47 -0
- data/lib/github_flow_cli/config.rb +62 -0
- data/lib/github_flow_cli/local.rb +25 -0
- data/lib/github_flow_cli/version.rb +3 -0
- data/lib/github_flow_cli.rb +5 -0
- metadata +194 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA1:
|
3
|
+
metadata.gz: 002c8c4e81bd601b09a96ccf31aa16f73044dded
|
4
|
+
data.tar.gz: 40f5e206e42458ae94cdc23bb386f574f319bdde
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: ead3a197702d2394a6207d0b5f7dfae139fea3efec589f44ecb4f99dea3b3be2d90efedd5c37d86145c016c1983433964a97388cdca7a78417f98c7a3ede8823
|
7
|
+
data.tar.gz: 34ed6b7f0e49e2e279266bd6e633d129015a61ce6414f5dc2a877cbf6accf7f6bb71d92598982823dd0254ef3a8b8f0d001f36b650a01510cd55ea5c4096baf3
|
data/.gitignore
ADDED
data/.rspec
ADDED
data/CODE_OF_CONDUCT.md
ADDED
@@ -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 jeremyrobturtle@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
data/Gemfile.lock
ADDED
@@ -0,0 +1,61 @@
|
|
1
|
+
PATH
|
2
|
+
remote: .
|
3
|
+
specs:
|
4
|
+
github_flow_cli (0.1.0)
|
5
|
+
facets
|
6
|
+
git
|
7
|
+
octokit
|
8
|
+
thor
|
9
|
+
|
10
|
+
GEM
|
11
|
+
remote: https://rubygems.org/
|
12
|
+
specs:
|
13
|
+
addressable (2.5.2)
|
14
|
+
public_suffix (>= 2.0.2, < 4.0)
|
15
|
+
byebug (10.0.2)
|
16
|
+
coderay (1.1.2)
|
17
|
+
diff-lcs (1.3)
|
18
|
+
facets (3.1.0)
|
19
|
+
faraday (0.15.2)
|
20
|
+
multipart-post (>= 1.2, < 3)
|
21
|
+
git (1.4.0)
|
22
|
+
method_source (0.9.0)
|
23
|
+
multipart-post (2.0.0)
|
24
|
+
octokit (4.9.0)
|
25
|
+
sawyer (~> 0.8.0, >= 0.5.3)
|
26
|
+
pry (0.11.3)
|
27
|
+
coderay (~> 1.1.0)
|
28
|
+
method_source (~> 0.9.0)
|
29
|
+
public_suffix (3.0.2)
|
30
|
+
rake (10.5.0)
|
31
|
+
rspec (3.7.0)
|
32
|
+
rspec-core (~> 3.7.0)
|
33
|
+
rspec-expectations (~> 3.7.0)
|
34
|
+
rspec-mocks (~> 3.7.0)
|
35
|
+
rspec-core (3.7.1)
|
36
|
+
rspec-support (~> 3.7.0)
|
37
|
+
rspec-expectations (3.7.0)
|
38
|
+
diff-lcs (>= 1.2.0, < 2.0)
|
39
|
+
rspec-support (~> 3.7.0)
|
40
|
+
rspec-mocks (3.7.0)
|
41
|
+
diff-lcs (>= 1.2.0, < 2.0)
|
42
|
+
rspec-support (~> 3.7.0)
|
43
|
+
rspec-support (3.7.1)
|
44
|
+
sawyer (0.8.1)
|
45
|
+
addressable (>= 2.3.5, < 2.6)
|
46
|
+
faraday (~> 0.8, < 1.0)
|
47
|
+
thor (0.20.0)
|
48
|
+
|
49
|
+
PLATFORMS
|
50
|
+
ruby
|
51
|
+
|
52
|
+
DEPENDENCIES
|
53
|
+
bundler (~> 1.16)
|
54
|
+
byebug
|
55
|
+
github_flow_cli!
|
56
|
+
pry
|
57
|
+
rake (~> 10.0)
|
58
|
+
rspec
|
59
|
+
|
60
|
+
BUNDLED WITH
|
61
|
+
1.16.0
|
data/LICENSE.txt
ADDED
@@ -0,0 +1,21 @@
|
|
1
|
+
The MIT License (MIT)
|
2
|
+
|
3
|
+
Copyright (c) 2018 Yang Liu
|
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,35 @@
|
|
1
|
+
# GithubFlowCli
|
2
|
+
|
3
|
+
This CLI tool is aiming to fasten the developing flow with Github by automating issue/PR creation according to the repo's convention.
|
4
|
+
|
5
|
+
## Installation
|
6
|
+
|
7
|
+
This gem is not published yet. For now please clone the repo and run the app via:
|
8
|
+
|
9
|
+
```
|
10
|
+
rake build
|
11
|
+
gem install pkg/*.gem
|
12
|
+
hubflow help
|
13
|
+
```
|
14
|
+
|
15
|
+
## Usage
|
16
|
+
|
17
|
+
TODO: Write usage instructions here
|
18
|
+
|
19
|
+
## Development
|
20
|
+
|
21
|
+
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.
|
22
|
+
|
23
|
+
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).
|
24
|
+
|
25
|
+
## Contributing
|
26
|
+
|
27
|
+
Bug reports and pull requests are welcome on GitHub at https://github.com/robturtle/github_flow_cli. 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.
|
28
|
+
|
29
|
+
## License
|
30
|
+
|
31
|
+
The gem is available as open source under the terms of the [MIT License](https://opensource.org/licenses/MIT).
|
32
|
+
|
33
|
+
## Code of Conduct
|
34
|
+
|
35
|
+
Everyone interacting in the GithubFlowCli project’s codebases, issue trackers, chat rooms and mailing lists is expected to follow the [code of conduct](https://github.com/robturtle/github_flow_cli/blob/master/CODE_OF_CONDUCT.md).
|
data/Rakefile
ADDED
data/bin/console
ADDED
data/bin/rspec
ADDED
@@ -0,0 +1,21 @@
|
|
1
|
+
#!/usr/bin/env ruby
|
2
|
+
# frozen_string_literal: true
|
3
|
+
|
4
|
+
#
|
5
|
+
# This file was generated by Bundler.
|
6
|
+
#
|
7
|
+
# The application 'rspec' is installed as part of a gem, and
|
8
|
+
# this file is here to facilitate running it.
|
9
|
+
#
|
10
|
+
|
11
|
+
bundle_binstub = File.expand_path("../bundle", __FILE__)
|
12
|
+
load(bundle_binstub) if File.file?(bundle_binstub)
|
13
|
+
|
14
|
+
require "pathname"
|
15
|
+
ENV["BUNDLE_GEMFILE"] ||= File.expand_path("../../Gemfile",
|
16
|
+
Pathname.new(__FILE__).realpath)
|
17
|
+
|
18
|
+
require "rubygems"
|
19
|
+
require "bundler/setup"
|
20
|
+
|
21
|
+
load Gem.bin_path("rspec-core", "rspec")
|
data/bin/setup
ADDED
data/exe/hubflow
ADDED
@@ -0,0 +1,12 @@
|
|
1
|
+
#!/usr/bin/env ruby
|
2
|
+
require 'github_flow_cli/cli'
|
3
|
+
begin
|
4
|
+
GithubFlowCli::Config.setup unless ARGV == ["login"]
|
5
|
+
GithubFlowCli::CLI.start
|
6
|
+
rescue Interrupt => e
|
7
|
+
puts "\nbye."
|
8
|
+
ensure
|
9
|
+
if GithubFlowCli::Config.valid?
|
10
|
+
GithubFlowCli::Config.save!
|
11
|
+
end
|
12
|
+
end
|
@@ -0,0 +1,43 @@
|
|
1
|
+
|
2
|
+
lib = File.expand_path("../lib", __FILE__)
|
3
|
+
$LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
|
4
|
+
require "github_flow_cli/version"
|
5
|
+
|
6
|
+
Gem::Specification.new do |spec|
|
7
|
+
spec.name = "github_flow_cli"
|
8
|
+
spec.version = GithubFlowCli::VERSION
|
9
|
+
spec.authors = ["Yang Liu"]
|
10
|
+
spec.email = ["jeremyrobturtle@gmail.com"]
|
11
|
+
|
12
|
+
spec.summary = "CLI of github-flow."
|
13
|
+
spec.description = "Github-flow provides you a CLI to interact with Github and automate the workflow."
|
14
|
+
spec.homepage = "https://github.com/robturtle/github_flow_cli"
|
15
|
+
spec.license = "MIT"
|
16
|
+
|
17
|
+
# Prevent pushing this gem to RubyGems.org. To allow pushes either set the 'allowed_push_host'
|
18
|
+
# to allow pushing to a single host or delete this section to allow pushing to any host.
|
19
|
+
if spec.respond_to?(:metadata)
|
20
|
+
spec.metadata["allowed_push_host"] = 'https://rubygems.org'
|
21
|
+
else
|
22
|
+
raise "RubyGems 2.0 or newer is required to protect against " \
|
23
|
+
"public gem pushes."
|
24
|
+
end
|
25
|
+
|
26
|
+
spec.files = `git ls-files -z`.split("\x0").reject do |f|
|
27
|
+
f.match(%r{^(test|spec|features)/})
|
28
|
+
end
|
29
|
+
spec.bindir = "exe"
|
30
|
+
spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
|
31
|
+
spec.require_paths = ["lib"]
|
32
|
+
|
33
|
+
spec.add_dependency "facets" # String#snakecase, common utils
|
34
|
+
spec.add_dependency "git"
|
35
|
+
spec.add_dependency "octokit" # Github API
|
36
|
+
spec.add_dependency "thor" # CLI
|
37
|
+
|
38
|
+
spec.add_development_dependency "bundler", "~> 1.16"
|
39
|
+
spec.add_development_dependency "byebug"
|
40
|
+
spec.add_development_dependency "pry"
|
41
|
+
spec.add_development_dependency "rake", "~> 10.0"
|
42
|
+
spec.add_development_dependency "rspec"
|
43
|
+
end
|
@@ -0,0 +1,55 @@
|
|
1
|
+
require 'facets/string/snakecase'
|
2
|
+
require 'thor'
|
3
|
+
require_relative '../github_flow_cli/api'
|
4
|
+
require_relative '../github_flow_cli/config'
|
5
|
+
|
6
|
+
module GithubFlowCli
|
7
|
+
class IssueCommands < Thor
|
8
|
+
desc "create TITLE", "create an issue"
|
9
|
+
def create(title)
|
10
|
+
puts API.create_issue(title).html_url
|
11
|
+
end
|
12
|
+
|
13
|
+
desc "all", "get all open tickets"
|
14
|
+
def all
|
15
|
+
list_issues(assignee: '*', show_assignee: true)
|
16
|
+
list_issues(assignee: 'none', show_assignee: true)
|
17
|
+
end
|
18
|
+
|
19
|
+
desc "mine", "get open tickets assigned to me"
|
20
|
+
def mine
|
21
|
+
list_issues(assignee: Config.username)
|
22
|
+
end
|
23
|
+
|
24
|
+
desc "unassigned", "get unassigned open tickets"
|
25
|
+
def unassigned
|
26
|
+
list_issues(assignee: 'none')
|
27
|
+
end
|
28
|
+
|
29
|
+
desc "start", "create a new branch named after the issue"
|
30
|
+
def start(number)
|
31
|
+
issue = API.issue(Local.repo, number)
|
32
|
+
# TODO: create branch based on RepoRules
|
33
|
+
# TODO: abstarct tag from issue title
|
34
|
+
branch_name = "i_#{number}_#{issue.title.gsub(/[^_\w\d ]/, '').snakecase}"
|
35
|
+
Local.git.branch(branch_name).checkout
|
36
|
+
Config.link_branch_to_issue(branch_name, issue)
|
37
|
+
rescue Octokit::NotFound
|
38
|
+
puts "issue not found!"
|
39
|
+
end
|
40
|
+
|
41
|
+
private
|
42
|
+
|
43
|
+
def list_issues(config)
|
44
|
+
show_assignee = config.delete(:show_assignee)
|
45
|
+
issues = API.list_issues(Local.repo, config)
|
46
|
+
unless issues.empty?
|
47
|
+
puts issues.sort_by(&:title).map { |i| "##{i.number}#{assignee_field(show_assignee, i)}: #{i.title}" }.join("\n")
|
48
|
+
end
|
49
|
+
end
|
50
|
+
|
51
|
+
def assignee_field(show_assignee, issue)
|
52
|
+
show_assignee ? " (#{issue.assignee&.login || 'NONE'})" : ''
|
53
|
+
end
|
54
|
+
end
|
55
|
+
end
|
data/lib/commands/pr.rb
ADDED
@@ -0,0 +1,31 @@
|
|
1
|
+
require 'thor'
|
2
|
+
require_relative '../github_flow_cli/api'
|
3
|
+
require_relative '../github_flow_cli/config'
|
4
|
+
|
5
|
+
module GithubFlowCli
|
6
|
+
class PrCommands < Thor
|
7
|
+
desc "all", "list all open PR"
|
8
|
+
def all
|
9
|
+
pull_requests = API.pull_requests(Local.repo)
|
10
|
+
unless pull_requests.empty?
|
11
|
+
puts pull_requests.map { |p| "##{p.number} (#{p.assignee&.login || "NONE"}): #{p.title}" }
|
12
|
+
end
|
13
|
+
end
|
14
|
+
|
15
|
+
desc "create TITLE", "create PR from current branch"
|
16
|
+
def create(title = nil)
|
17
|
+
puts API.create_pr(title: title).html_url
|
18
|
+
rescue Octokit::UnprocessableEntity => ex
|
19
|
+
case ex.message
|
20
|
+
when /no commits between .*? and/i
|
21
|
+
puts "No commits between base and head, stop creating PR..."
|
22
|
+
when /already exists/
|
23
|
+
puts "PR already exists."
|
24
|
+
pr_number = Config.pr_branch_map.find {|_, v| v == Local.git.current_branch }.first
|
25
|
+
puts API.pull_request(Local.repo, pr_number).html_url
|
26
|
+
else
|
27
|
+
raise
|
28
|
+
end
|
29
|
+
end
|
30
|
+
end
|
31
|
+
end
|
@@ -0,0 +1,88 @@
|
|
1
|
+
require 'octokit'
|
2
|
+
require_relative 'local'
|
3
|
+
|
4
|
+
module GithubFlowCli
|
5
|
+
class API
|
6
|
+
class << self
|
7
|
+
# @return [String] OAuth token
|
8
|
+
def authorize(username, password, two_factor_token: nil)
|
9
|
+
client = Octokit::Client.new(login: username, password: password)
|
10
|
+
auth_config = {
|
11
|
+
scopes: ['user', 'repo', 'admin:repo_hook'],
|
12
|
+
note: app_name,
|
13
|
+
}
|
14
|
+
if two_factor_token
|
15
|
+
auth_config.merge!(:headers => { "X-GitHub-OTP" => two_factor_token })
|
16
|
+
end
|
17
|
+
client.create_authorization(auth_config).token
|
18
|
+
rescue Octokit::UnprocessableEntity => ex
|
19
|
+
if ex.message =~ /already_exists/
|
20
|
+
id = client.authorizations.find { |auth| auth[:note] == app_name }.id
|
21
|
+
client.delete_authorization(id)
|
22
|
+
retry
|
23
|
+
else
|
24
|
+
raise
|
25
|
+
end
|
26
|
+
end
|
27
|
+
|
28
|
+
def use_oauth_token(token)
|
29
|
+
@client = Octokit::Client.new(access_token: token)
|
30
|
+
end
|
31
|
+
|
32
|
+
def valid?
|
33
|
+
!user[:login].nil?
|
34
|
+
rescue Octokit::Unauthorized
|
35
|
+
false
|
36
|
+
end
|
37
|
+
|
38
|
+
# delegate API calls to Octokit::Client
|
39
|
+
def method_missing(method, *args, &block)
|
40
|
+
if @client.respond_to?(method)
|
41
|
+
define_singleton_method(method) do |*args, &block|
|
42
|
+
@client.send(method, *args, &block)
|
43
|
+
end
|
44
|
+
return send(method, *args, &block)
|
45
|
+
end
|
46
|
+
super
|
47
|
+
end
|
48
|
+
|
49
|
+
# TODO: explicify options
|
50
|
+
# :assignee (String) — User login.
|
51
|
+
# :milestone (Integer) — Milestone number.
|
52
|
+
# :labels
|
53
|
+
# TODO: keywordify parameters
|
54
|
+
def create_issue(title, body = nil, options = {})
|
55
|
+
@client.create_issue(Local.repo, title, body, options)
|
56
|
+
end
|
57
|
+
|
58
|
+
# TODO: other options
|
59
|
+
def create_pr(base: "master", title: nil, body: nil)
|
60
|
+
branch_name = Local.git.current_branch
|
61
|
+
issue_number = Config.branch_issue_map[branch_name]
|
62
|
+
if issue_number
|
63
|
+
issue = API.issue(Local.repo, issue_number)
|
64
|
+
title ||= issue.title
|
65
|
+
body ||= issue.body
|
66
|
+
end
|
67
|
+
unless Local.git.branches.remote.find { |b| b.name == branch_name }
|
68
|
+
# TODO: custom default remote
|
69
|
+
puts "no remote branch found, creating remote branch..."
|
70
|
+
Local.git.config("branch.#{branch_name}.remote", 'origin')
|
71
|
+
Local.git.config("branch.#{branch_name}.merge", "refs/heads/#{branch_name}")
|
72
|
+
end
|
73
|
+
# TODO: custom default remote
|
74
|
+
puts "git push..."
|
75
|
+
Local.git.push('origin', branch_name)
|
76
|
+
@client.create_pull_request(Local.repo, base, branch_name, title, body).tap do |pr|
|
77
|
+
Config.link_pr_to_branch(pr, branch_name)
|
78
|
+
end
|
79
|
+
end
|
80
|
+
|
81
|
+
private
|
82
|
+
|
83
|
+
def app_name
|
84
|
+
"hubflow for #{`whoami`.strip}@#{`hostname`.strip}"
|
85
|
+
end
|
86
|
+
end
|
87
|
+
end
|
88
|
+
end
|
@@ -0,0 +1,47 @@
|
|
1
|
+
require 'thor'
|
2
|
+
require_relative 'api'
|
3
|
+
require_relative 'config'
|
4
|
+
require_relative 'local'
|
5
|
+
|
6
|
+
Dir[File.join(File.dirname(__FILE__), '../commands/*.rb')].each { |f| require f }
|
7
|
+
|
8
|
+
module GithubFlowCli
|
9
|
+
class CLI < Thor
|
10
|
+
desc "login", "login to Github with username and password"
|
11
|
+
def login
|
12
|
+
Config.username = ask("Github username:")
|
13
|
+
password = ask("password:", echo: false)
|
14
|
+
Config.oauth_token = authorize(Config.username, password)
|
15
|
+
Config.save!
|
16
|
+
puts "\nsuccessfully login!"
|
17
|
+
rescue Octokit::Unauthorized
|
18
|
+
puts "\nauthentication failed, please try again."
|
19
|
+
retry
|
20
|
+
end
|
21
|
+
|
22
|
+
desc "user", "display username"
|
23
|
+
def user
|
24
|
+
puts API.user[:login]
|
25
|
+
end
|
26
|
+
|
27
|
+
desc "repo", "display remote repo name"
|
28
|
+
def repo
|
29
|
+
puts(Local.repo&.slug || "remote repo not found!")
|
30
|
+
end
|
31
|
+
|
32
|
+
desc "issue COMMAND", "manipulate issues"
|
33
|
+
subcommand "issue", IssueCommands
|
34
|
+
|
35
|
+
desc "pr COMMAND", "manipulate PR"
|
36
|
+
subcommand "pr", PrCommands
|
37
|
+
|
38
|
+
private
|
39
|
+
|
40
|
+
def authorize(username, password)
|
41
|
+
API.authorize(username, password)
|
42
|
+
rescue Octokit::OneTimePasswordRequired
|
43
|
+
two_factor_token = ask("\nTwo Factor Authentication code:")
|
44
|
+
API.authorize(username, password, two_factor_token: two_factor_token)
|
45
|
+
end
|
46
|
+
end
|
47
|
+
end
|
@@ -0,0 +1,62 @@
|
|
1
|
+
require 'yaml'
|
2
|
+
require 'fileutils'
|
3
|
+
require_relative 'api'
|
4
|
+
require_relative 'local'
|
5
|
+
|
6
|
+
module GithubFlowCli
|
7
|
+
class Config
|
8
|
+
CONFIG_DIR = File.expand_path('~/.config')
|
9
|
+
CONFIG_FILE = 'hubflow'
|
10
|
+
KEYS = %w[username oauth_token branch_issue_map pr_branch_map]
|
11
|
+
|
12
|
+
class << self
|
13
|
+
attr_accessor *KEYS
|
14
|
+
|
15
|
+
def setup
|
16
|
+
self.branch_issue_map = {}
|
17
|
+
self.pr_branch_map = {}
|
18
|
+
if File.file?(config_path)
|
19
|
+
load
|
20
|
+
API.use_oauth_token(oauth_token)
|
21
|
+
unless API.valid?
|
22
|
+
puts "WARN: authentication failed, please retry login."
|
23
|
+
File.delete(config_path)
|
24
|
+
exit(1)
|
25
|
+
end
|
26
|
+
else
|
27
|
+
puts "please login first."
|
28
|
+
exit(2)
|
29
|
+
end
|
30
|
+
end
|
31
|
+
|
32
|
+
def link_branch_to_issue(branch_name, issue)
|
33
|
+
self.branch_issue_map[branch_name] = issue.number
|
34
|
+
end
|
35
|
+
|
36
|
+
def link_pr_to_branch(pr, branch_name)
|
37
|
+
self.pr_branch_map[pr.number] = branch_name
|
38
|
+
end
|
39
|
+
|
40
|
+
def load
|
41
|
+
YAML::load_file(config_path).each { |k, v| send("#{k}=", v) }
|
42
|
+
end
|
43
|
+
|
44
|
+
def save!
|
45
|
+
File.open(config_path, 'w') { |f| f.write(to_h.to_yaml) }
|
46
|
+
end
|
47
|
+
|
48
|
+
def to_h
|
49
|
+
KEYS.map{ |k| [k, send(k)] }.to_h
|
50
|
+
end
|
51
|
+
|
52
|
+
def valid?
|
53
|
+
KEYS.all? { |c| send(c) }
|
54
|
+
end
|
55
|
+
|
56
|
+
def config_path
|
57
|
+
FileUtils.mkdir_p(CONFIG_DIR) unless File.directory?(CONFIG_DIR)
|
58
|
+
File.join(CONFIG_DIR, CONFIG_FILE)
|
59
|
+
end
|
60
|
+
end
|
61
|
+
end
|
62
|
+
end
|
@@ -0,0 +1,25 @@
|
|
1
|
+
require 'git'
|
2
|
+
|
3
|
+
module GithubFlowCli
|
4
|
+
class Local
|
5
|
+
class << self
|
6
|
+
def repo
|
7
|
+
return @repo if @repo
|
8
|
+
url = git.remote.url
|
9
|
+
match = url&.match(%r{.*[:/](?<owner>.*?)/(?<name>.*?)\.git$})
|
10
|
+
return nil unless match[:owner] && match[:name]
|
11
|
+
@repo = Octokit::Repository.from_url("/#{match[:owner]}/#{match[:name]}")
|
12
|
+
rescue ArgumentError => ex
|
13
|
+
if ex.message =~ /path does not exist/
|
14
|
+
nil
|
15
|
+
else
|
16
|
+
raise
|
17
|
+
end
|
18
|
+
end
|
19
|
+
|
20
|
+
def git
|
21
|
+
@git ||= Git.open(File.expand_path('.'))
|
22
|
+
end
|
23
|
+
end
|
24
|
+
end
|
25
|
+
end
|
metadata
ADDED
@@ -0,0 +1,194 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: github_flow_cli
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.1.0
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- Yang Liu
|
8
|
+
autorequire:
|
9
|
+
bindir: exe
|
10
|
+
cert_chain: []
|
11
|
+
date: 2018-06-04 00:00:00.000000000 Z
|
12
|
+
dependencies:
|
13
|
+
- !ruby/object:Gem::Dependency
|
14
|
+
name: facets
|
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: git
|
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: octokit
|
43
|
+
requirement: !ruby/object:Gem::Requirement
|
44
|
+
requirements:
|
45
|
+
- - ">="
|
46
|
+
- !ruby/object:Gem::Version
|
47
|
+
version: '0'
|
48
|
+
type: :runtime
|
49
|
+
prerelease: false
|
50
|
+
version_requirements: !ruby/object:Gem::Requirement
|
51
|
+
requirements:
|
52
|
+
- - ">="
|
53
|
+
- !ruby/object:Gem::Version
|
54
|
+
version: '0'
|
55
|
+
- !ruby/object:Gem::Dependency
|
56
|
+
name: thor
|
57
|
+
requirement: !ruby/object:Gem::Requirement
|
58
|
+
requirements:
|
59
|
+
- - ">="
|
60
|
+
- !ruby/object:Gem::Version
|
61
|
+
version: '0'
|
62
|
+
type: :runtime
|
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: bundler
|
71
|
+
requirement: !ruby/object:Gem::Requirement
|
72
|
+
requirements:
|
73
|
+
- - "~>"
|
74
|
+
- !ruby/object:Gem::Version
|
75
|
+
version: '1.16'
|
76
|
+
type: :development
|
77
|
+
prerelease: false
|
78
|
+
version_requirements: !ruby/object:Gem::Requirement
|
79
|
+
requirements:
|
80
|
+
- - "~>"
|
81
|
+
- !ruby/object:Gem::Version
|
82
|
+
version: '1.16'
|
83
|
+
- !ruby/object:Gem::Dependency
|
84
|
+
name: byebug
|
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: pry
|
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: rake
|
113
|
+
requirement: !ruby/object:Gem::Requirement
|
114
|
+
requirements:
|
115
|
+
- - "~>"
|
116
|
+
- !ruby/object:Gem::Version
|
117
|
+
version: '10.0'
|
118
|
+
type: :development
|
119
|
+
prerelease: false
|
120
|
+
version_requirements: !ruby/object:Gem::Requirement
|
121
|
+
requirements:
|
122
|
+
- - "~>"
|
123
|
+
- !ruby/object:Gem::Version
|
124
|
+
version: '10.0'
|
125
|
+
- !ruby/object:Gem::Dependency
|
126
|
+
name: rspec
|
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
|
+
description: Github-flow provides you a CLI to interact with Github and automate the
|
140
|
+
workflow.
|
141
|
+
email:
|
142
|
+
- jeremyrobturtle@gmail.com
|
143
|
+
executables:
|
144
|
+
- hubflow
|
145
|
+
extensions: []
|
146
|
+
extra_rdoc_files: []
|
147
|
+
files:
|
148
|
+
- ".gitignore"
|
149
|
+
- ".rspec"
|
150
|
+
- CODE_OF_CONDUCT.md
|
151
|
+
- Gemfile
|
152
|
+
- Gemfile.lock
|
153
|
+
- LICENSE.txt
|
154
|
+
- README.md
|
155
|
+
- Rakefile
|
156
|
+
- bin/console
|
157
|
+
- bin/rspec
|
158
|
+
- bin/setup
|
159
|
+
- exe/hubflow
|
160
|
+
- github_flow_cli.gemspec
|
161
|
+
- lib/commands/issue.rb
|
162
|
+
- lib/commands/pr.rb
|
163
|
+
- lib/github_flow_cli.rb
|
164
|
+
- lib/github_flow_cli/api.rb
|
165
|
+
- lib/github_flow_cli/cli.rb
|
166
|
+
- lib/github_flow_cli/config.rb
|
167
|
+
- lib/github_flow_cli/local.rb
|
168
|
+
- lib/github_flow_cli/version.rb
|
169
|
+
homepage: https://github.com/robturtle/github_flow_cli
|
170
|
+
licenses:
|
171
|
+
- MIT
|
172
|
+
metadata:
|
173
|
+
allowed_push_host: https://rubygems.org
|
174
|
+
post_install_message:
|
175
|
+
rdoc_options: []
|
176
|
+
require_paths:
|
177
|
+
- lib
|
178
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
179
|
+
requirements:
|
180
|
+
- - ">="
|
181
|
+
- !ruby/object:Gem::Version
|
182
|
+
version: '0'
|
183
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
184
|
+
requirements:
|
185
|
+
- - ">="
|
186
|
+
- !ruby/object:Gem::Version
|
187
|
+
version: '0'
|
188
|
+
requirements: []
|
189
|
+
rubyforge_project:
|
190
|
+
rubygems_version: 2.6.14
|
191
|
+
signing_key:
|
192
|
+
specification_version: 4
|
193
|
+
summary: CLI of github-flow.
|
194
|
+
test_files: []
|