github_issue_branch 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.
- checksums.yaml +7 -0
- data/bin/github_issue_branch +6 -0
- data/lib/git_utils.rb~ +3 -0
- data/lib/github_issue_branch.rb +101 -0
- data/lib/github_issue_branch.rb~ +0 -0
- data/lib/string_utils.rb~ +2 -0
- data/lib/utils/git_utils.rb +28 -0
- data/lib/utils/string_utils.rb +13 -0
- data/lib/version.rb +3 -0
- data/lib/version.rb~ +1 -0
- metadata +82 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA1:
|
3
|
+
metadata.gz: 4db2e3794d9e0fff0a55bffe47317cd4b48ec362
|
4
|
+
data.tar.gz: 564da3dcfac09fa7f8185c5ad5c34897c28e4da5
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: 35e457edac6a648c62c657232a3b62912cdeefbe994e95e19d76b433898d602a0366c178660ce3e2233cb6abf36b3258ee3aed3fe7b723009eff0ebd71ff65d8
|
7
|
+
data.tar.gz: 32d3845d31326bc61c08ba19419e717701a7ff20fe9513d5c221c803f949a45fb8fb297067ad06078f8bdc7a8d9a0d0725eb0dcfeab80f59827082356e0fcbda
|
data/lib/git_utils.rb~
ADDED
@@ -0,0 +1,101 @@
|
|
1
|
+
require 'github_api'
|
2
|
+
require 'yaml'
|
3
|
+
require 'utils/git_utils'
|
4
|
+
require 'utils/string_utils'
|
5
|
+
require 'readline'
|
6
|
+
|
7
|
+
class GithubIssueBranch
|
8
|
+
|
9
|
+
module Error
|
10
|
+
|
11
|
+
class ConfNotFound < StandardError
|
12
|
+
def message
|
13
|
+
"Required configuration was not found in config files nor environment variables"
|
14
|
+
end
|
15
|
+
end
|
16
|
+
|
17
|
+
class NoIssuesAvailable < StandardError
|
18
|
+
def message
|
19
|
+
"No open issues were found in #{@github_repo}"
|
20
|
+
end
|
21
|
+
end
|
22
|
+
|
23
|
+
class IssueNotFound < StandardError
|
24
|
+
def message
|
25
|
+
"The chosen issue was not found"
|
26
|
+
end
|
27
|
+
end
|
28
|
+
|
29
|
+
end
|
30
|
+
|
31
|
+
GITHUB_CONF_FILE = ['.github_issue_branch_conf', "#{ENV['HOME']}/.github_issue_branch_conf"]
|
32
|
+
|
33
|
+
def initialize
|
34
|
+
load_configs
|
35
|
+
@github = Github.new(oauth_token: @github_token)
|
36
|
+
end
|
37
|
+
|
38
|
+
def get_issue_list
|
39
|
+
# TODO: read this from either config file or from git remotes
|
40
|
+
list = @github.issues.list user: @github_repo_owner, repo: @github_repo
|
41
|
+
list.select { |issue| issue['pull_request'].nil? }
|
42
|
+
end
|
43
|
+
|
44
|
+
def select_issue
|
45
|
+
issue_list = get_issue_list
|
46
|
+
raise Error::NoIssuesAvailable unless issue_list.length > 0
|
47
|
+
print_list issue_list
|
48
|
+
issue = choose_issue issue_list
|
49
|
+
# TODO: Fix the assignee as if owner is an organization it is wrong
|
50
|
+
@github.issues.edit @github_repo_owner, @github_repo, issue.number, assignee: @github_repo_owner
|
51
|
+
GitUtils.create_branch(StringUtils.branch_sanitize issue.title, issue.number)
|
52
|
+
end
|
53
|
+
|
54
|
+
def choose_issue issue_list
|
55
|
+
# TODO: Add history and autocomplete with tab
|
56
|
+
issue_selection = Readline.readline('> ', true)
|
57
|
+
return nil if issue_selection == '' or issue_selection.nil?
|
58
|
+
issue = issue_list.select{|s| issue_matcher s, issue_selection }.first
|
59
|
+
raise Error::IssueNotFound if issue.nil?
|
60
|
+
return issue
|
61
|
+
end
|
62
|
+
|
63
|
+
def print_list issue_list
|
64
|
+
issue_list.each { |issue| puts "#{issue.number} - #{issue.title}" }
|
65
|
+
end
|
66
|
+
|
67
|
+
private
|
68
|
+
|
69
|
+
def load_configs
|
70
|
+
@github_token = read_conf 'github_auth_token', 'GITHUB_AUTH_TOKEN'
|
71
|
+
owner, repo = GitUtils.get_remote_user_repo('origin')
|
72
|
+
@github_repo_owner = read_conf('github_owner') || owner
|
73
|
+
@github_repo = read_conf('github_repo') || repo
|
74
|
+
end
|
75
|
+
|
76
|
+
def read_conf(conf_name, environment_key=nil)
|
77
|
+
GITHUB_CONF_FILE.each do |config_file|
|
78
|
+
if File.exists? config_file
|
79
|
+
configurations = YAML.load_file config_file
|
80
|
+
return configurations[conf_name] if configurations[conf_name]
|
81
|
+
end
|
82
|
+
end
|
83
|
+
|
84
|
+
if environment_key
|
85
|
+
value ||= env_required environment_key
|
86
|
+
value
|
87
|
+
end
|
88
|
+
end
|
89
|
+
|
90
|
+
def env_required var_name
|
91
|
+
raise Error::ConfNotFound if ENV[var_name].nil?
|
92
|
+
ENV[var_name]
|
93
|
+
end
|
94
|
+
|
95
|
+
def issue_matcher issue, selection
|
96
|
+
m = selection.match(/^(\d*) /)
|
97
|
+
return false unless m
|
98
|
+
id = m.captures.first
|
99
|
+
return issue.number.to_s == id
|
100
|
+
end
|
101
|
+
end
|
File without changes
|
@@ -0,0 +1,28 @@
|
|
1
|
+
require 'git'
|
2
|
+
|
3
|
+
class GitUtils
|
4
|
+
def self.g
|
5
|
+
Git.open '.'
|
6
|
+
end
|
7
|
+
|
8
|
+
def self.get_remote name
|
9
|
+
g.remotes.select {|remote| remote.name == name}.first
|
10
|
+
end
|
11
|
+
|
12
|
+
def self.get_remote_url name
|
13
|
+
get_remote(name).url
|
14
|
+
end
|
15
|
+
|
16
|
+
# TODO: Use regex to extract values instead?
|
17
|
+
def self.get_remote_user_repo name
|
18
|
+
url = get_remote_url(name)
|
19
|
+
username_repository = url.split(':')[1]
|
20
|
+
username_repository.slice! '.git'
|
21
|
+
username_repository.split '/'
|
22
|
+
end
|
23
|
+
|
24
|
+
def self.create_branch name
|
25
|
+
# TODO: Throw error if branch already exists either locally or remotely
|
26
|
+
g.branch(name).checkout
|
27
|
+
end
|
28
|
+
end
|
@@ -0,0 +1,13 @@
|
|
1
|
+
class StringUtils
|
2
|
+
def self.branch_sanitize issue_title, issue_id
|
3
|
+
sane_branch = "#{sanitize issue_title}-#{issue_id}"
|
4
|
+
end
|
5
|
+
|
6
|
+
def self.sanitize string
|
7
|
+
string.strip!
|
8
|
+
string.gsub!(/^.*(\\|\/)/, '')
|
9
|
+
string.gsub!(/[^0-9A-Za-z.\-]/, '-')
|
10
|
+
string.gsub!(' ', '-')
|
11
|
+
string
|
12
|
+
end
|
13
|
+
end
|
data/lib/version.rb
ADDED
data/lib/version.rb~
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
module GitHubIssueBranch
|
metadata
ADDED
@@ -0,0 +1,82 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: github_issue_branch
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.0.1
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- Rui Baltazar
|
8
|
+
autorequire:
|
9
|
+
bindir: bin
|
10
|
+
cert_chain: []
|
11
|
+
date: 2016-03-11 00:00:00.000000000 Z
|
12
|
+
dependencies:
|
13
|
+
- !ruby/object:Gem::Dependency
|
14
|
+
name: github_api
|
15
|
+
requirement: !ruby/object:Gem::Requirement
|
16
|
+
requirements:
|
17
|
+
- - "~>"
|
18
|
+
- !ruby/object:Gem::Version
|
19
|
+
version: '0.13'
|
20
|
+
type: :runtime
|
21
|
+
prerelease: false
|
22
|
+
version_requirements: !ruby/object:Gem::Requirement
|
23
|
+
requirements:
|
24
|
+
- - "~>"
|
25
|
+
- !ruby/object:Gem::Version
|
26
|
+
version: '0.13'
|
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.3'
|
34
|
+
type: :runtime
|
35
|
+
prerelease: false
|
36
|
+
version_requirements: !ruby/object:Gem::Requirement
|
37
|
+
requirements:
|
38
|
+
- - "~>"
|
39
|
+
- !ruby/object:Gem::Version
|
40
|
+
version: '1.3'
|
41
|
+
description: Check a list of open issues in a specific repository, assign it to you
|
42
|
+
and get your branch created
|
43
|
+
email: rui.p.baltazar@gmail.com
|
44
|
+
executables:
|
45
|
+
- github_issue_branch
|
46
|
+
extensions: []
|
47
|
+
extra_rdoc_files: []
|
48
|
+
files:
|
49
|
+
- bin/github_issue_branch
|
50
|
+
- lib/git_utils.rb~
|
51
|
+
- lib/github_issue_branch.rb
|
52
|
+
- lib/github_issue_branch.rb~
|
53
|
+
- lib/string_utils.rb~
|
54
|
+
- lib/utils/git_utils.rb
|
55
|
+
- lib/utils/string_utils.rb
|
56
|
+
- lib/version.rb
|
57
|
+
- lib/version.rb~
|
58
|
+
homepage: http://github.com/rpbaltazar/github-issue-branch
|
59
|
+
licenses:
|
60
|
+
- MIT
|
61
|
+
metadata: {}
|
62
|
+
post_install_message:
|
63
|
+
rdoc_options: []
|
64
|
+
require_paths:
|
65
|
+
- lib
|
66
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
67
|
+
requirements:
|
68
|
+
- - ">="
|
69
|
+
- !ruby/object:Gem::Version
|
70
|
+
version: '0'
|
71
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
72
|
+
requirements:
|
73
|
+
- - ">="
|
74
|
+
- !ruby/object:Gem::Version
|
75
|
+
version: '0'
|
76
|
+
requirements: []
|
77
|
+
rubyforge_project:
|
78
|
+
rubygems_version: 2.4.6
|
79
|
+
signing_key:
|
80
|
+
specification_version: 4
|
81
|
+
summary: Create branches from open issues
|
82
|
+
test_files: []
|