Module: GhIssues
- Defined in:
- lib/gh_issues.rb,
lib/gh_issues/cli.rb,
lib/gh_issues/version.rb
Defined Under Namespace
Classes: CLI, GitHubAccessTokenError, GitHubBadCredentialsError, InvalidOwnerError, TextRenderer
Constant Summary collapse
- VERSION =
"0.4.10"
- @@client =
nil
Class Method Summary collapse
- .all_issues ⇒ Object
- .check_ghi_github_credentials ⇒ Object
- .check_ghi_token_defined ⇒ Object
- .get_issue(repo, issue_number) ⇒ Object
- .get_repo_name(url) ⇒ Object
- .ghi_access_available? ⇒ Boolean
- .in_github_repo?(url) ⇒ Boolean
- .list_owner_issues(requested_owner) ⇒ Object
- .show_repos_issues(repo) ⇒ Object
Class Method Details
.all_issues ⇒ Object
131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 |
# File 'lib/gh_issues.rb', line 131 def self.all_issues if ::GhIssues.ghi_access_available? open_issues = {} @@client.repos.each do |repo| if repo[:open_issues_count] > 0 owner = repo[:owner][:login] open_issues[owner] = [] unless open_issues[owner] data = { full_name: repo[:full_name], open_issues_count: repo[:open_issues_count], } open_issues[owner] << data end end open_issues end end |
.check_ghi_github_credentials ⇒ Object
14 15 16 17 18 19 20 21 |
# File 'lib/gh_issues.rb', line 14 def self.check_ghi_github_credentials begin @@client.user rescue Octokit::Unauthorized => puts raise ::GhIssues::GitHubBadCredentialsError, "Bad GitHub credentials." end end |
.check_ghi_token_defined ⇒ Object
10 11 12 |
# File 'lib/gh_issues.rb', line 10 def self.check_ghi_token_defined raise ::GhIssues::GitHubAccessTokenError, "Please define GH_ISSUES_TOKEN environment variable." unless ENV['GH_ISSUES_TOKEN'] end |
.get_issue(repo, issue_number) ⇒ Object
76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 |
# File 'lib/gh_issues.rb', line 76 def self.get_issue(repo, issue_number) if ::GhIssues.ghi_access_available? begin issue = @@client.issue(repo, issue_number) out = { number: issue[:number], title: issue[:title], user: issue[:user][:login], labels: issue[:labels].map{|i| i[:name]}, assignees: issue[:assignees].map{|i| i[:login]}, body: issue[:body], created_at: issue[:created_at], updated_at: issue[:updated_at], } rescue Octokit::NotFound => puts puts "Incorrect issue number (#{issue_number})" exit end out[:comments] = [] begin comments = @@client.issue_comments(repo, issue_number) comments.each do |comment| out[:comments] << { user: comment[:user][:login], body: comment[:body], created_at: comment[:created_at], updated_at: comment[:updated_at], } end rescue Octokit::NotFound => end out end end |
.get_repo_name(url) ⇒ Object
122 123 124 125 126 127 128 129 |
# File 'lib/gh_issues.rb', line 122 def self.get_repo_name(url) return nil unless ::GhIssues.in_github_repo?(url) https_matches = /https?\:\/\/github\.com\/(.[^\.]+)\/(.[^\.]+)/.match(url) return "#{https_matches[1]}/#{https_matches[2]}" if https_matches ssh_matches = /git\@github\.com\:(.[^\.]+)\/(.+).git/.match(url) return "#{ssh_matches[1]}/#{ssh_matches[2]}" if ssh_matches return nil end |
.ghi_access_available? ⇒ Boolean
23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 |
# File 'lib/gh_issues.rb', line 23 def self.ghi_access_available? begin ::GhIssues.check_ghi_token_defined rescue ::GhIssues::GitHubAccessTokenError => puts exit end @@client = Octokit::Client.new(:access_token => ENV['GH_ISSUES_TOKEN']) @@client.auto_paginate = true begin ::GhIssues.check_ghi_github_credentials rescue ::GhIssues::GitHubBadCredentialsError => puts exit end true end |
.in_github_repo?(url) ⇒ Boolean
115 116 117 118 119 120 |
# File 'lib/gh_issues.rb', line 115 def self.in_github_repo?(url) _rv = false _rv = true if url =~ /\/\/github.com\// _rv = true if url =~ /github\.com\:/ _rv end |
.list_owner_issues(requested_owner) ⇒ Object
43 44 45 46 47 48 49 50 51 52 53 |
# File 'lib/gh_issues.rb', line 43 def self.list_owner_issues(requested_owner) if ::GhIssues.ghi_access_available? all_issues = ::GhIssues.all_issues if all_issues[requested_owner] all_issues[requested_owner] else raise ::GhIssues::InvalidOwnerError, "Invalid owner requested" exit end end end |
.show_repos_issues(repo) ⇒ Object
55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 |
# File 'lib/gh_issues.rb', line 55 def self.show_repos_issues(repo) if ::GhIssues.ghi_access_available? begin issues = [] @@client.issues(repo).each do |issue| issues << { number: issue[:number], title: issue[:title], html_url: issue[:html_url], body: issue[:body], } end issues rescue Octokit::InvalidRepository => puts exit end end end |