Class: TicketMaster::Provider::Github::Ticket

Inherits:
Base::Ticket
  • Object
show all
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

Class Method Summary collapse

Instance Method Summary collapse

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
# File 'lib/provider/ticket.rb', line 12

def initialize(*object)
  if object.first
    object = object.first
  	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
  	    }
  	else
  	  hash = object
  	end

  	super hash
	end
end

Instance Attribute Details

#prefix_optionsObject

Returns the value of attribute prefix_options.



8
9
10
# File 'lib/provider/ticket.rb', line 8

def prefix_options
  @prefix_options
end

Class Method Details

.build_attributes(repo, options) ⇒ Object



46
47
48
49
# File 'lib/provider/ticket.rb', line 46

def self.build_attributes(repo, options)
	hash = {:repo => repo, :user => Octopi::Api.api.}
	hash.merge!(options)
end

.find_by_attributes(project_id, attributes = {}) ⇒ Object



40
41
42
43
44
# File 'lib/provider/ticket.rb', line 40

def self.find_by_attributes(project_id, attributes = {})
	attributes ||= {}
	attributes[:state] ||= 'open'
	self::API.find_all(build_attributes(project_id, attributes)).collect{|issue| self.new issue}
end

.find_by_id(project_id, ticket_id) ⇒ Object



36
37
38
# File 'lib/provider/ticket.rb', line 36

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



51
52
53
54
55
56
57
# File 'lib/provider/ticket.rb', line 51

def self.open(project_id, *options)
  begin
   self.new self::API.open(build_attributes(project_id, options.first))
  rescue
    self.find(project_id, :all).last
  end
end

Instance Method Details

#closeObject



59
60
61
# File 'lib/provider/ticket.rb', line 59

def close
 Ticket.new API.find(Ticket.build_attributes(repository, {:number => number})).close!
end

#comment!(comment) ⇒ Object



83
84
85
# File 'lib/provider/ticket.rb', line 83

def comment!(comment)
 Comment.create(repository, number, comment)
end

#commentsObject



79
80
81
# File 'lib/provider/ticket.rb', line 79

def comments
 Comment.find(repository, number, :all)
end

#reopenObject



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

def reopen
 Ticket.new API.find(Ticket.build_attributes(repository, {:number => number})).reopen!
end

#saveObject



67
68
69
70
71
72
73
74
75
76
77
# File 'lib/provider/ticket.rb', line 67

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