github_issues_cli 0.2.2
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.
- checksums.yaml +7 -0
- data/bin/gi +6 -0
- data/lib/github_issues_cli.rb +17 -0
- data/lib/github_issues_cli/command.rb +105 -0
- data/lib/github_issues_cli/command/browse.rb +10 -0
- data/lib/github_issues_cli/command/checkout.rb +26 -0
- data/lib/github_issues_cli/command/list.rb +25 -0
- data/lib/github_issues_cli/command/open.rb +20 -0
- data/lib/github_issues_cli/command/pull_request.rb +21 -0
- data/lib/github_issues_cli/command/push.rb +16 -0
- data/lib/github_issues_cli/command/show.rb +32 -0
- data/lib/github_issues_cli/command_manager.rb +12 -0
- metadata +111 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA1:
|
3
|
+
metadata.gz: f3672afbc8205c0742de2b4d9d34b01c02a291a0
|
4
|
+
data.tar.gz: 2974bcf3df15e6fed060b3a80e5144ce17de9b94
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: 226d54775ed24548111425e7add4cea6cfe51c4fcf5b5870f7d14a6e7b130346bfa1cbf0258eadd25d180e2f424a0df47e217de1c1016f1bfe33035d609b3d74
|
7
|
+
data.tar.gz: dbc7736f5bbbd548eb836aa052fd06ca2cfb3c6d8bb72d8d9f7101d448bc9e7bb107d19132032f87d6f8d06df8c5e1f0711464c860c5d9c7c97cc7330f3077d9
|
data/bin/gi
ADDED
@@ -0,0 +1,17 @@
|
|
1
|
+
module GithubIssuesCli
|
2
|
+
require 'clamp'
|
3
|
+
require 'git'
|
4
|
+
require 'term/ansicolor'
|
5
|
+
require 'github_api'
|
6
|
+
require 'io/console'
|
7
|
+
require 'json'
|
8
|
+
require 'github_issues_cli/command'
|
9
|
+
require 'github_issues_cli/command/list'
|
10
|
+
require 'github_issues_cli/command/checkout'
|
11
|
+
require 'github_issues_cli/command/browse'
|
12
|
+
require 'github_issues_cli/command/show'
|
13
|
+
require 'github_issues_cli/command/open'
|
14
|
+
require 'github_issues_cli/command/push'
|
15
|
+
require 'github_issues_cli/command/pull_request'
|
16
|
+
require 'github_issues_cli/command_manager'
|
17
|
+
end
|
@@ -0,0 +1,105 @@
|
|
1
|
+
module GithubIssuesCli
|
2
|
+
class Command < Clamp::Command
|
3
|
+
|
4
|
+
include Term::ANSIColor
|
5
|
+
|
6
|
+
attr_accessor :git_repo, :username
|
7
|
+
|
8
|
+
def initialize(invocation_path, context = {}, parent_attribute_values = {})
|
9
|
+
super
|
10
|
+
authenticate
|
11
|
+
end
|
12
|
+
|
13
|
+
def authenticate
|
14
|
+
config_dirname = ENV['HOME'] + '/.github-issues/'
|
15
|
+
Dir.mkdir config_dirname unless Dir.exists? config_dirname
|
16
|
+
|
17
|
+
config_path = config_dirname + 'token'
|
18
|
+
if File.exists? config_path
|
19
|
+
config = JSON.parse File.new(config_path, 'r').gets
|
20
|
+
@username, token = config.values_at 'username', 'token'
|
21
|
+
else
|
22
|
+
print 'Please provide GitHub token: '
|
23
|
+
token = $stdin.gets.chomp
|
24
|
+
@username = Github::Users.new.get(:oauth_token => token).login
|
25
|
+
config = {:username => @username, :token => token}
|
26
|
+
File.new(config_path, 'w').puts config.to_json
|
27
|
+
end
|
28
|
+
|
29
|
+
Github.configure do |c|
|
30
|
+
c.oauth_token = token
|
31
|
+
end
|
32
|
+
end
|
33
|
+
|
34
|
+
# @return [Git::Base]
|
35
|
+
def get_git_repo
|
36
|
+
unless @git_repo
|
37
|
+
dir = Dir.getwd + '/'
|
38
|
+
until Dir.exists? dir + '.git' do
|
39
|
+
if dir == '/'
|
40
|
+
raise StandardError, 'Git not found'
|
41
|
+
end
|
42
|
+
dir = File.dirname(dir)
|
43
|
+
end
|
44
|
+
@git_repo = Git.open dir
|
45
|
+
end
|
46
|
+
@git_repo
|
47
|
+
end
|
48
|
+
|
49
|
+
def get_issue_number
|
50
|
+
if get_git_repo.current_branch.match(/issue-([0-9]+)/).nil?
|
51
|
+
raise 'Is not branch issue. Issue branches match `issue-XXX` pattern'
|
52
|
+
end
|
53
|
+
$1
|
54
|
+
end
|
55
|
+
|
56
|
+
def get_github_repo
|
57
|
+
url = get_git_repo.remote(:upstream).url
|
58
|
+
if url.nil?
|
59
|
+
raise 'No `upstream` remote found, please configure it first'
|
60
|
+
end
|
61
|
+
unless url.start_with?('git@github.com:', 'https://github.com/')
|
62
|
+
raise 'Remote upstream points to non-github url: ' + url
|
63
|
+
end
|
64
|
+
if url.match(/github.com[:\/]([^\/]+)\/([^\/]+)\.git$/).nil?
|
65
|
+
raise 'Can\'t extract `user/repo` data from upstream remote'
|
66
|
+
end
|
67
|
+
{:user => $1, :name => $2}
|
68
|
+
end
|
69
|
+
|
70
|
+
def get_source issue_number
|
71
|
+
github_repo = get_github_repo
|
72
|
+
pull_requests_client = Github::PullRequests.new
|
73
|
+
pull_request = pull_requests_client.get :user => github_repo[:user], :repo => github_repo[:name], :number => issue_number rescue return nil
|
74
|
+
user = pull_request.head.repo.owner.login
|
75
|
+
url = pull_request.head.repo.ssh_url
|
76
|
+
ref = pull_request.head.ref
|
77
|
+
remote_name = 'gi-' + user
|
78
|
+
repo = get_git_repo
|
79
|
+
remote = repo.remote remote_name
|
80
|
+
if remote.url.nil?
|
81
|
+
print 'Setting up remote `' + remote_name + '`...'
|
82
|
+
remote = repo.add_remote remote_name, url
|
83
|
+
puts ' Done'
|
84
|
+
end
|
85
|
+
if remote.url != url
|
86
|
+
raise '`' + remote_name + '` remote\'s url differs from expected: `' + remote.url + ' != ' + url + '`'
|
87
|
+
end
|
88
|
+
remote.fetch
|
89
|
+
remote.name + '/' + ref
|
90
|
+
end
|
91
|
+
|
92
|
+
def run(arguments)
|
93
|
+
begin
|
94
|
+
super
|
95
|
+
rescue Exception => e
|
96
|
+
print on_red ' '
|
97
|
+
print bold ' Error: '
|
98
|
+
puts e.message
|
99
|
+
exit 1
|
100
|
+
end
|
101
|
+
end
|
102
|
+
|
103
|
+
|
104
|
+
end
|
105
|
+
end
|
@@ -0,0 +1,26 @@
|
|
1
|
+
module GithubIssuesCli
|
2
|
+
class Command::Checkout < Command
|
3
|
+
|
4
|
+
parameter "issue-number", "number of issue to be worked on", :attribute_name => :issue_number
|
5
|
+
|
6
|
+
def execute
|
7
|
+
branch_name = 'issue-' + issue_number
|
8
|
+
repo = get_git_repo
|
9
|
+
source = nil
|
10
|
+
if repo.lib.branches_all.map(&:first).include? branch_name
|
11
|
+
repo.checkout branch_name
|
12
|
+
else
|
13
|
+
source = get_source issue_number
|
14
|
+
if source.nil?
|
15
|
+
repo.remote('upstream').fetch
|
16
|
+
source = 'upstream/master'
|
17
|
+
end
|
18
|
+
repo.lib.checkout source, :new_branch => branch_name
|
19
|
+
end
|
20
|
+
print on_green ' '
|
21
|
+
print ' Checked out #' + issue_number
|
22
|
+
print ' (' + source.split('/').first.sub(/^gi-/, '') + ')' if source
|
23
|
+
puts
|
24
|
+
end
|
25
|
+
end
|
26
|
+
end
|
@@ -0,0 +1,25 @@
|
|
1
|
+
module GithubIssuesCli
|
2
|
+
class Command::List < Command
|
3
|
+
|
4
|
+
option "--mine", :flag, "show only mine issues"
|
5
|
+
|
6
|
+
def execute
|
7
|
+
github_repo = get_github_repo
|
8
|
+
issues_client = Github::Issues.new
|
9
|
+
request = {:user => github_repo[:user], :repo => github_repo[:name]}
|
10
|
+
request.store(:assignee, @username) if mine?
|
11
|
+
issues = issues_client.list request
|
12
|
+
|
13
|
+
issues.each do |issue|
|
14
|
+
if not issue.assignee.nil? and issue.assignee.login == @username
|
15
|
+
print on_yellow ' '
|
16
|
+
else
|
17
|
+
print ' '
|
18
|
+
end
|
19
|
+
print bold ' ' + ('#' + issue.number.to_s).rjust(6)
|
20
|
+
print ' ' + issue.title
|
21
|
+
puts
|
22
|
+
end
|
23
|
+
end
|
24
|
+
end
|
25
|
+
end
|
@@ -0,0 +1,20 @@
|
|
1
|
+
module GithubIssuesCli
|
2
|
+
class Command::Open < Command
|
3
|
+
|
4
|
+
parameter "summary", "summary of the paramter", :attribute_name => :summary
|
5
|
+
|
6
|
+
def execute
|
7
|
+
github_repo = get_github_repo
|
8
|
+
issue = Github::Issues.new.create :user => github_repo[:user], :repo => github_repo[:name], :title => summary
|
9
|
+
issue_number = issue[:number].to_s
|
10
|
+
|
11
|
+
get_github_repo
|
12
|
+
git_repo = get_git_repo
|
13
|
+
git_repo.remote('upstream').fetch
|
14
|
+
git_repo.lib.checkout 'upstream/master', :new_branch => 'issue-' + issue_number
|
15
|
+
print on_green ' '
|
16
|
+
print ' Checked out '
|
17
|
+
puts bold '#' + issue_number
|
18
|
+
end
|
19
|
+
end
|
20
|
+
end
|
@@ -0,0 +1,21 @@
|
|
1
|
+
module GithubIssuesCli
|
2
|
+
class Command::Pull_request < Command
|
3
|
+
|
4
|
+
def execute
|
5
|
+
github_repo = get_github_repo
|
6
|
+
issue_number = get_issue_number
|
7
|
+
source = @username + ':issue-' + issue_number
|
8
|
+
begin
|
9
|
+
Github::PullRequests.new.create :user => github_repo[:user], :repo => github_repo[:name], :head => source, :base => github_repo[:user] + ':master', :issue => issue_number
|
10
|
+
rescue
|
11
|
+
unless get_source(issue_number).nil?
|
12
|
+
raise 'Pull-request for issue #' + issue_number + ' already exists'
|
13
|
+
end
|
14
|
+
raise 'Internal error: Cannot create pull-request'
|
15
|
+
end
|
16
|
+
print 'Pull request for issue '
|
17
|
+
print bold '#' + issue_number
|
18
|
+
puts ' created'
|
19
|
+
end
|
20
|
+
end
|
21
|
+
end
|
@@ -0,0 +1,16 @@
|
|
1
|
+
module GithubIssuesCli
|
2
|
+
class Command::Push < Command
|
3
|
+
|
4
|
+
def execute
|
5
|
+
issue_number = get_issue_number
|
6
|
+
source = get_source issue_number
|
7
|
+
if source.nil?
|
8
|
+
source = 'origin/issue-' + issue_number
|
9
|
+
end
|
10
|
+
print 'Pushing code to '
|
11
|
+
puts bold source
|
12
|
+
remote, branch = source.split('/')
|
13
|
+
get_git_repo.push(remote, branch)
|
14
|
+
end
|
15
|
+
end
|
16
|
+
end
|
@@ -0,0 +1,32 @@
|
|
1
|
+
module GithubIssuesCli
|
2
|
+
class Command::Show < Command
|
3
|
+
|
4
|
+
def execute
|
5
|
+
issue_number = get_issue_number
|
6
|
+
issues_client = Github::Issues.new
|
7
|
+
issue = issues_client.get :number => issue_number
|
8
|
+
comments = issues_client.comments.all :issue_id => issue_number
|
9
|
+
|
10
|
+
puts
|
11
|
+
print bold issue_number + ': ' + issue[:title] + ' '
|
12
|
+
if issue[:state] == :open
|
13
|
+
print white on_green [:state]
|
14
|
+
else
|
15
|
+
print white on_red issue[:state]
|
16
|
+
end
|
17
|
+
puts
|
18
|
+
if issue[:body]
|
19
|
+
puts issue[:body]
|
20
|
+
puts
|
21
|
+
end
|
22
|
+
puts
|
23
|
+
|
24
|
+
comments.each do |c|
|
25
|
+
print yellow '@' + c.user.login
|
26
|
+
puts ':'
|
27
|
+
puts c[:body]
|
28
|
+
puts
|
29
|
+
end
|
30
|
+
end
|
31
|
+
end
|
32
|
+
end
|
@@ -0,0 +1,12 @@
|
|
1
|
+
module GithubIssuesCli
|
2
|
+
class CommandManager < Clamp::Command
|
3
|
+
|
4
|
+
subcommand 'list', 'Lists issues', Command::List
|
5
|
+
subcommand 'checkout', 'Checkouts specifc issue', Command::Checkout
|
6
|
+
subcommand 'show', 'Show current issue details', Command::Show
|
7
|
+
subcommand 'browse', 'Navigate to issue HTML url', Command::Browse
|
8
|
+
subcommand 'open', 'Open new issue', Command::Open
|
9
|
+
subcommand 'push', 'Push current state to repo', Command::Push
|
10
|
+
subcommand 'pull-request', 'Creates pull-request out of current issue', Command::Pull_request
|
11
|
+
end
|
12
|
+
end
|
metadata
ADDED
@@ -0,0 +1,111 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: github_issues_cli
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.2.2
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- Tomasz Durka
|
8
|
+
autorequire:
|
9
|
+
bindir: bin
|
10
|
+
cert_chain: []
|
11
|
+
date: 2013-10-19 00:00:00.000000000 Z
|
12
|
+
dependencies:
|
13
|
+
- !ruby/object:Gem::Dependency
|
14
|
+
name: clamp
|
15
|
+
requirement: !ruby/object:Gem::Requirement
|
16
|
+
requirements:
|
17
|
+
- - ">="
|
18
|
+
- !ruby/object:Gem::Version
|
19
|
+
version: '0.5'
|
20
|
+
type: :runtime
|
21
|
+
prerelease: false
|
22
|
+
version_requirements: !ruby/object:Gem::Requirement
|
23
|
+
requirements:
|
24
|
+
- - ">="
|
25
|
+
- !ruby/object:Gem::Version
|
26
|
+
version: '0.5'
|
27
|
+
- !ruby/object:Gem::Dependency
|
28
|
+
name: git
|
29
|
+
requirement: !ruby/object:Gem::Requirement
|
30
|
+
requirements:
|
31
|
+
- - ">="
|
32
|
+
- !ruby/object:Gem::Version
|
33
|
+
version: 1.2.5
|
34
|
+
type: :runtime
|
35
|
+
prerelease: false
|
36
|
+
version_requirements: !ruby/object:Gem::Requirement
|
37
|
+
requirements:
|
38
|
+
- - ">="
|
39
|
+
- !ruby/object:Gem::Version
|
40
|
+
version: 1.2.5
|
41
|
+
- !ruby/object:Gem::Dependency
|
42
|
+
name: github_api
|
43
|
+
requirement: !ruby/object:Gem::Requirement
|
44
|
+
requirements:
|
45
|
+
- - ">="
|
46
|
+
- !ruby/object:Gem::Version
|
47
|
+
version: 0.10.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.10.0
|
55
|
+
- !ruby/object:Gem::Dependency
|
56
|
+
name: term-ansicolor
|
57
|
+
requirement: !ruby/object:Gem::Requirement
|
58
|
+
requirements:
|
59
|
+
- - ">="
|
60
|
+
- !ruby/object:Gem::Version
|
61
|
+
version: 1.2.0
|
62
|
+
type: :runtime
|
63
|
+
prerelease: false
|
64
|
+
version_requirements: !ruby/object:Gem::Requirement
|
65
|
+
requirements:
|
66
|
+
- - ">="
|
67
|
+
- !ruby/object:Gem::Version
|
68
|
+
version: 1.2.0
|
69
|
+
description:
|
70
|
+
email: tomasz@durka.pl
|
71
|
+
executables:
|
72
|
+
- gi
|
73
|
+
extensions: []
|
74
|
+
extra_rdoc_files: []
|
75
|
+
files:
|
76
|
+
- lib/github_issues_cli/command/browse.rb
|
77
|
+
- lib/github_issues_cli/command/checkout.rb
|
78
|
+
- lib/github_issues_cli/command/list.rb
|
79
|
+
- lib/github_issues_cli/command/open.rb
|
80
|
+
- lib/github_issues_cli/command/pull_request.rb
|
81
|
+
- lib/github_issues_cli/command/push.rb
|
82
|
+
- lib/github_issues_cli/command/show.rb
|
83
|
+
- lib/github_issues_cli/command.rb
|
84
|
+
- lib/github_issues_cli/command_manager.rb
|
85
|
+
- lib/github_issues_cli.rb
|
86
|
+
- bin/gi
|
87
|
+
homepage: https://github.com/tomaszdurka/github_issues_cli.git
|
88
|
+
licenses:
|
89
|
+
- MIT
|
90
|
+
metadata: {}
|
91
|
+
post_install_message:
|
92
|
+
rdoc_options: []
|
93
|
+
require_paths:
|
94
|
+
- lib
|
95
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
96
|
+
requirements:
|
97
|
+
- - ">="
|
98
|
+
- !ruby/object:Gem::Version
|
99
|
+
version: '0'
|
100
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
101
|
+
requirements:
|
102
|
+
- - ">="
|
103
|
+
- !ruby/object:Gem::Version
|
104
|
+
version: '0'
|
105
|
+
requirements: []
|
106
|
+
rubyforge_project:
|
107
|
+
rubygems_version: 2.1.9
|
108
|
+
signing_key:
|
109
|
+
specification_version: 4
|
110
|
+
summary: Command line tool for managing issues, pull-requests on GitHub platform
|
111
|
+
test_files: []
|