Class: Jira
Instance Method Summary collapse
- #add_issue_to_sprint(issue_id, sprint_id) ⇒ Object
- #auth ⇒ Object
- #components ⇒ Object
- #create_issue(issue_params) ⇒ Object
- #find_project_by_key(project_key) ⇒ Object
- #first_open_sprint(rapid_board_id) ⇒ Object
-
#initialize(username, password, endpoint_url) ⇒ Jira
constructor
A new instance of Jira.
- #projects ⇒ Object
- #sprints(rapid_board_id) ⇒ Object
Constructor Details
#initialize(username, password, endpoint_url) ⇒ Jira
Returns a new instance of Jira.
17 18 19 20 21 |
# File 'lib/jira.rb', line 17 def initialize( username, password, endpoint_url ) @url = endpoint_url @username = username @password = password end |
Instance Method Details
#add_issue_to_sprint(issue_id, sprint_id) ⇒ Object
52 53 54 55 56 57 58 |
# File 'lib/jira.rb', line 52 def add_issue_to_sprint( issue_id, sprint_id ) = auth.merge({:body => JSON.dump({ 'issueKeys' => [ issue_id ] }) }). merge({:headers => { "Content-Type" => "application/json", "Accept" => "application/json" }}) self.class.put "/greenhopper/1.0/sprint/#{sprint_id}/issues/add", end |
#auth ⇒ Object
75 76 77 78 79 80 |
# File 'lib/jira.rb', line 75 def auth { :basic_auth => {:username => @username, :password => @password} } end |
#components ⇒ Object
23 24 25 26 27 28 |
# File 'lib/jira.rb', line 23 def components response = self.class.get "/project/CNVS/components", auth response.map do |item| Component.new item['id'], item['name'] end end |
#create_issue(issue_params) ⇒ Object
69 70 71 72 73 |
# File 'lib/jira.rb', line 69 def create_issue( issue_params ) body = { :body => JSON.dump({'fields'=> issue_params }) } body = body.merge({:headers => {"Content-Type" => "application/json", "Accept" => "application/json"}}) Issue.new( self.class.post "/api/2/issue", body.merge(auth) ) end |
#find_project_by_key(project_key) ⇒ Object
64 65 66 67 |
# File 'lib/jira.rb', line 64 def find_project_by_key( project_key ) projects = self.class.get "/api/2/project", auth projects.detect { | project | project['key'] == project_key } end |
#first_open_sprint(rapid_board_id) ⇒ Object
43 44 45 46 47 48 49 50 |
# File 'lib/jira.rb', line 43 def first_open_sprint( rapid_board_id ) sprints = sprints(rapid_board_id).sort_by(&:end_date) sprint = sprints.detect{ |sprint| sprint.open? } if !sprint sprint = sprints.last end sprint end |
#projects ⇒ Object
60 61 62 |
# File 'lib/jira.rb', line 60 def projects self.class.get "/api/2/project", auth end |
#sprints(rapid_board_id) ⇒ Object
30 31 32 33 34 35 36 37 38 39 40 41 |
# File 'lib/jira.rb', line 30 def sprints( rapid_board_id ) response = self.class.get "/greenhopper/1.0/sprints/#{rapid_board_id}", auth response['sprints'].map{ |sprint| spr = { 'id' => sprint['id'], 'name' => sprint['name'], 'closed' => sprint[ 'closed' ], 'end_date' => sprint[ 'name' ].split( " " ).last.to_s } Sprint.new spr } end |