Class: GithubIssueBranch

Inherits:
Object
  • Object
show all
Defined in:
lib/github_issue_branch.rb

Defined Under Namespace

Modules: Error

Constant Summary collapse

GITHUB_CONF_FILE =
['.github_issue_branch_conf', "#{ENV['HOME']}/.github_issue_branch_conf"]

Instance Method Summary collapse

Constructor Details

#initializeGithubIssueBranch

Returns a new instance of GithubIssueBranch.



33
34
35
36
37
# File 'lib/github_issue_branch.rb', line 33

def initialize
  load_configs
  @github = Github.new(oauth_token: @github_token)
  @github_username = @github.users.get.
end

Instance Method Details

#choose_issue(issue_list) ⇒ Object



54
55
56
57
58
59
60
61
# File 'lib/github_issue_branch.rb', line 54

def choose_issue issue_list
  # TODO: Add history and autocomplete with tab
  issue_selection = Readline.readline('> ', true)
  return nil if issue_selection == '' or issue_selection.nil?
  issue = issue_list.select{|s| issue_matcher s, issue_selection }.first
  raise Error::IssueNotFound if issue.nil?
  return issue
end

#get_issue_listObject



39
40
41
42
# File 'lib/github_issue_branch.rb', line 39

def get_issue_list
  list = @github.issues.list user: @github_repo_owner, repo: @github_repo
  list.select { |issue| issue['pull_request'].nil? }
end


63
64
65
# File 'lib/github_issue_branch.rb', line 63

def print_list issue_list
  issue_list.each { |issue| puts "#{issue.number} - #{issue.title}" }
end

#select_issueObject



44
45
46
47
48
49
50
51
52
# File 'lib/github_issue_branch.rb', line 44

def select_issue
  issue_list = get_issue_list
  raise Error::NoIssuesAvailable unless issue_list.length > 0
  print_list issue_list
  issue = choose_issue issue_list
  # TODO: Fix the assignee as if owner is an organization it is wrong
  @github.issues.edit @github_repo_owner, @github_repo, issue.number, assignee: @github_username
  GitUtils.create_branch(StringUtils.branch_sanitize issue.title, issue.number)
end