Class: Houston::Adapters::TicketTracker::GithubAdapter::Connection
- Inherits:
-
Object
- Object
- Houston::Adapters::TicketTracker::GithubAdapter::Connection
- Defined in:
- app/adapters/houston/adapters/ticket_tracker/github_adapter/connection.rb
Instance Attribute Summary collapse
-
#config ⇒ Object
readonly
Idiomatic API.
-
#repo_path ⇒ Object
readonly
Idiomatic API.
Instance Method Summary collapse
- #all_milestones ⇒ Object
- #all_tickets ⇒ Object
- #as_user(user, &block) ⇒ Object
- #build_ticket(attributes) ⇒ Object
- #client ⇒ Object
- #close_issue(number) ⇒ Object
- #create_ticket!(houston_ticket) ⇒ Object
-
#features ⇒ Object
Required API.
- #find_ticket_by_number(number) ⇒ Object
- #find_tickets_numbered(*numbers) ⇒ Object
-
#initialize(repo_path) ⇒ Connection
constructor
A new instance of Connection.
- #open_milestones ⇒ Object
- #open_tickets ⇒ Object
- #project_url ⇒ Object
- #reopen_issue(number) ⇒ Object
- #ticket_url(ticket_number) ⇒ Object
Constructor Details
#initialize(repo_path) ⇒ Connection
Returns a new instance of Connection.
7 8 9 10 |
# File 'app/adapters/houston/adapters/ticket_tracker/github_adapter/connection.rb', line 7 def initialize(repo_path) @repo_path = repo_path @config = Houston.config.ticket_tracker_configuration(:github) end |
Instance Attribute Details
#config ⇒ Object (readonly)
Idiomatic API
86 87 88 |
# File 'app/adapters/houston/adapters/ticket_tracker/github_adapter/connection.rb', line 86 def config @config end |
#repo_path ⇒ Object (readonly)
Idiomatic API
86 87 88 |
# File 'app/adapters/houston/adapters/ticket_tracker/github_adapter/connection.rb', line 86 def repo_path @repo_path end |
Instance Method Details
#all_milestones ⇒ Object
74 75 76 |
# File 'app/adapters/houston/adapters/ticket_tracker/github_adapter/connection.rb', line 74 def all_milestones [] end |
#all_tickets ⇒ Object
56 57 58 |
# File 'app/adapters/houston/adapters/ticket_tracker/github_adapter/connection.rb', line 56 def all_tickets open_tickets + closed_tickets end |
#as_user(user, &block) ⇒ Object
102 103 104 105 106 107 108 109 110 111 112 113 114 115 |
# File 'app/adapters/houston/adapters/ticket_tracker/github_adapter/connection.rb', line 102 def as_user(user, &block) current_client = @client begin token = user.consumer_tokens.first # !todo: use a more generic exception? raise Github:: unless token @client = Octokit::Client.new(access_token: token.token) yield rescue Octokit:: raise Github::, $!. ensure @client = current_client end end |
#build_ticket(attributes) ⇒ Object
20 21 22 23 24 |
# File 'app/adapters/houston/adapters/ticket_tracker/github_adapter/connection.rb', line 20 def build_ticket(attributes) attributes["user"] = {} unless attributes["user"] attributes["user"]["email"] = find_user_email(attributes["user"]["login"]) Houston::Adapters::TicketTracker::GithubAdapter::Issue.new(self, attributes) end |
#client ⇒ Object
88 89 90 |
# File 'app/adapters/houston/adapters/ticket_tracker/github_adapter/connection.rb', line 88 def client @client ||= Octokit::Client.new(Houston.config.github.pick(:access_token).merge(auto_paginate: true)) end |
#close_issue(number) ⇒ Object
92 93 94 |
# File 'app/adapters/houston/adapters/ticket_tracker/github_adapter/connection.rb', line 92 def close_issue(number) client.close_issue(repo_path, number) end |
#create_ticket!(houston_ticket) ⇒ Object
26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 |
# File 'app/adapters/houston/adapters/ticket_tracker/github_adapter/connection.rb', line 26 def create_ticket!(houston_ticket) as_user(houston_ticket.reporter) do attrs = get_attributes_from_type(houston_ticket.type) = {} [:labels] = attrs[:labels].join(",") if attrs[:labels] native_ticket = client.create_issue( repo_path, houston_ticket.summary, houston_ticket.description, ) build_ticket(native_ticket) end end |
#features ⇒ Object
Required API
16 17 18 |
# File 'app/adapters/houston/adapters/ticket_tracker/github_adapter/connection.rb', line 16 def features [:syncing_tickets, :syncing_milestones] end |
#find_ticket_by_number(number) ⇒ Object
42 43 44 45 46 47 |
# File 'app/adapters/houston/adapters/ticket_tracker/github_adapter/connection.rb', line 42 def find_ticket_by_number(number) attributes = client.issue(repo_path, number) unless number.blank? build_ticket(attributes) if attributes rescue Octokit::NotFound nil end |
#find_tickets_numbered(*numbers) ⇒ Object
49 50 51 52 53 54 |
# File 'app/adapters/houston/adapters/ticket_tracker/github_adapter/connection.rb', line 49 def find_tickets_numbered(*numbers) numbers = numbers.flatten return [] if numbers.empty? return numbers.map(&method(:find_ticket_by_number)).compact if numbers.length < 5 open_tickets.select { |ticket| numbers.member?(ticket.number) } end |
#open_milestones ⇒ Object
78 79 80 |
# File 'app/adapters/houston/adapters/ticket_tracker/github_adapter/connection.rb', line 78 def open_milestones [] end |
#open_tickets ⇒ Object
60 61 62 |
# File 'app/adapters/houston/adapters/ticket_tracker/github_adapter/connection.rb', line 60 def open_tickets build_issues client.list_issues(repo_path, state: "open") end |
#project_url ⇒ Object
64 65 66 |
# File 'app/adapters/houston/adapters/ticket_tracker/github_adapter/connection.rb', line 64 def project_url "https://github.com/#{repo_path}/issues" end |
#reopen_issue(number) ⇒ Object
96 97 98 |
# File 'app/adapters/houston/adapters/ticket_tracker/github_adapter/connection.rb', line 96 def reopen_issue(number) client.reopen_issue(repo_path, number) end |
#ticket_url(ticket_number) ⇒ Object
68 69 70 |
# File 'app/adapters/houston/adapters/ticket_tracker/github_adapter/connection.rb', line 68 def ticket_url(ticket_number) "#{project_url}/#{ticket_number}" end |