Class: TicketMaster::Provider::Github::Ticket
- Inherits:
-
Base::Ticket
- Object
- Base::Ticket
- TicketMaster::Provider::Github::Ticket
- Defined in:
- lib/provider/ticket.rb
Overview
Ticket class for ticketmaster-github
Constant Summary collapse
- API =
Octopi::Issue
- @@allowed_states =
%w{open close}
Instance Attribute Summary collapse
-
#prefix_options ⇒ Object
Returns the value of attribute prefix_options.
Class Method Summary collapse
- .build_attributes(repo, options) ⇒ Object
- .find_by_attributes(project_id, attributes = {}) ⇒ Object
- .find_by_id(project_id, ticket_id) ⇒ Object
- .open(project_id, *options) ⇒ Object
Instance Method Summary collapse
- #close ⇒ Object
- #comment!(comment) ⇒ Object
- #comments ⇒ Object
-
#initialize(*object) ⇒ Ticket
constructor
declare needed overloaded methods here.
- #reopen ⇒ Object
- #save ⇒ Object
Constructor Details
#initialize(*object) ⇒ Ticket
declare needed overloaded methods here
12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 |
# File 'lib/provider/ticket.rb', line 12 def initialize(*object) if object.first object = object.first @system_data = {:client => object} unless object.is_a? Hash hash = {:repository => object.repository.name, :user => object.user, :updated_at => object.updated_at, :votes => object.votes, :number => object.number, :title => object.title, :body => object.body, :closed_at => object.closed_at, :labels => object.labels, :state => object.state, :created_at => object.created_at, :id => object.number, :project_id => object.repository.name, :description => object.body, :status => object.state, :resolution => (object.state == 'closed' ? 'closed' : nil), :requestor => object.user } else hash = object end super hash end end |
Instance Attribute Details
#prefix_options ⇒ Object
Returns the value of attribute prefix_options.
8 9 10 |
# File 'lib/provider/ticket.rb', line 8 def @prefix_options end |
Class Method Details
.build_attributes(repo, options) ⇒ Object
65 66 67 68 |
# File 'lib/provider/ticket.rb', line 65 def self.build_attributes(repo, ) hash = {:repo => repo, :user => TicketMaster::Provider::Github.login} hash.merge!() end |
.find_by_attributes(project_id, attributes = {}) ⇒ Object
47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 |
# File 'lib/provider/ticket.rb', line 47 def self.find_by_attributes(project_id, attributes = {}) attributes ||= {} issues = [] if attributes[:state].nil? attributes[:state] = 'open' issues += self::API.find_all(build_attributes(project_id, attributes)) attributes[:state] = 'closed' begin issues += self::API.find_all(build_attributes(project_id, attributes)) rescue APICache::TimeoutError warn "Unable to fetch closed issues due to timeout" end else issues = self::API.find_all(build_attributes(project_id, attributes)) end issues.collect { |issue| self.new issue } end |
.find_by_id(project_id, ticket_id) ⇒ Object
43 44 45 |
# File 'lib/provider/ticket.rb', line 43 def self.find_by_id(project_id, ticket_id) self.new self::API.find(build_attributes(project_id, {:number => ticket_id})) end |
.open(project_id, *options) ⇒ Object
70 71 72 73 74 75 76 |
# File 'lib/provider/ticket.rb', line 70 def self.open(project_id, *) begin self.new self::API.open(build_attributes(project_id, .first)) rescue self.find(project_id, :all).last end end |
Instance Method Details
#close ⇒ Object
78 79 80 |
# File 'lib/provider/ticket.rb', line 78 def close Ticket.new API.find(Ticket.build_attributes(repository, {:number => number})).close! end |
#comment!(comment) ⇒ Object
102 103 104 |
# File 'lib/provider/ticket.rb', line 102 def comment!(comment) Comment.create(repository, number, comment) end |
#comments ⇒ Object
98 99 100 |
# File 'lib/provider/ticket.rb', line 98 def comments Comment.find(repository, number, :all) end |
#reopen ⇒ Object
82 83 84 |
# File 'lib/provider/ticket.rb', line 82 def reopen Ticket.new API.find(Ticket.build_attributes(repository, {:number => number})).reopen! end |
#save ⇒ Object
86 87 88 89 90 91 92 93 94 95 96 |
# File 'lib/provider/ticket.rb', line 86 def save t = API.find(Ticket.build_attributes(repository, {:number => number})) return false if t.title == title and t.body == body t.title = title t.body = body t.save true end |