Class: Gitmine::Issue

Inherits:
Object
  • Object
show all
Includes:
HTTParty
Defined in:
lib/gitmine/issue.rb

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Instance Attribute Details

#assigned_toObject (readonly)

Returns the value of attribute assigned_to.



3
4
5
# File 'lib/gitmine/issue.rb', line 3

def assigned_to
  @assigned_to
end

#idObject (readonly)

Returns the value of attribute id.



3
4
5
# File 'lib/gitmine/issue.rb', line 3

def id
  @id
end

#statusObject (readonly)

Returns the value of attribute status.



3
4
5
# File 'lib/gitmine/issue.rb', line 3

def status
  @status
end

#subjectObject (readonly)

Returns the value of attribute subject.



3
4
5
# File 'lib/gitmine/issue.rb', line 3

def subject
  @subject
end

Class Method Details

.find(issue_id) ⇒ Object

Get the issue from redmine



24
25
26
27
28
# File 'lib/gitmine/issue.rb', line 24

def self.find(issue_id)
  Issue.new.tap { |issue|
    issue.build_via_issue_id(issue_id)
  }
end

.get_for_commit(commit_message) ⇒ Object

Parse the commit_message and get the associated issue if any.



18
19
20
21
# File 'lib/gitmine/issue.rb', line 18

def self.get_for_commit(commit_message)
  issue_id = parse_for_issue_id(commit_message)
  issue_id ? Issue.find(issue_id) : nil
end

.parse_for_issue_id(msg) ⇒ Object

Extract the issue_id from a commit message. Examples:

CommitMsgToIssueId.parse("Message for Issue #123.")
  => 123
CommitMsgToIssueId.parse("#123.")
  => nil


12
13
14
15
# File 'lib/gitmine/issue.rb', line 12

def self.parse_for_issue_id(msg)
  match = msg.match(/Issue #(\d+)/)
  match ? match[1] : nil
end

Instance Method Details

#add_note(note) ⇒ Object

Add a note to the Issue



50
51
52
53
54
55
# File 'lib/gitmine/issue.rb', line 50

def add_note(note)
  response = self.class.put(url(self.id), :query => {:notes => note}, :body => "") # nginx reject requests without body
  raise response.response.to_s unless response.code == 200

  puts green("Note added to Issue ##{self.id}: #{note}")
end

#build_via_issue_id(issue_id) ⇒ Object

Get attributes from redmine and set them all



39
40
41
42
43
44
45
46
47
# File 'lib/gitmine/issue.rb', line 39

def build_via_issue_id(issue_id)
  @id = issue_id
  data = http_get(issue_id).parsed_response['issue']
  if data
    @subject = data['subject']
    @status = data['status']['name']
    @assigned_to = (data['assigned_to'] || {})['name']
  end
end

#local_branchObject



30
31
32
# File 'lib/gitmine/issue.rb', line 30

def local_branch
  LocalBranch.find(self.id)
end

#remote_branchObject



34
35
36
# File 'lib/gitmine/issue.rb', line 34

def remote_branch
  RemoteBranch.find(self.id)
end

#update_status(st) ⇒ Object



57
58
59
60
61
62
63
64
65
# File 'lib/gitmine/issue.rb', line 57

def update_status(st)
  status_id = Gitmine::Config.statuses[st]
  raise "Please specify status_id in .gitmine.yml for #{st}" unless status_id

  response = self.class.put(url(self.id), :query => {:issue => {:status_id => status_id }}, :body => "")
  raise response.response.to_s unless response.code == 200

  puts green("Issue ##{self.id} -> #{st}")
end