Skip to content

Instantly share code, notes, and snippets.

@varsy
Created June 4, 2014 21:23
Show Gist options
  • Save varsy/4faf02a307ce6db3fb62 to your computer and use it in GitHub Desktop.
Save varsy/4faf02a307ce6db3fb62 to your computer and use it in GitHub Desktop.
dashing-youtrack

Description

Simple Dashing widget that shows YouTrack REST API data.

Dependencies

nokogiri gem is required so add gem 'nokogiri' to your Gemfile.

Usage

Please refer to Official YouTrack REST API Reference in order to get all that you need from YouTrack. In my case I'm getting the list of unresolved issues about upcoming employees. Just copy your filter to :filter parameter in response in youtrack.rb. Don't forget to change the fields that you want to obtain in this section:

summary = xmlfeed.xpath("//field[@name='summary']/value/text()")
issue_number = xmlfeed.xpath("//field[@name='numberInProject']/value/text()")

summary and numberInProject are the name of desired fields in REST XML, you should put there yours. Simple, eh?

Put youtrack.rb to jobs/ folder and youtrack.erb to your dashboard in dashboards.

And that is all.

<li data-row="1" data-col="4" data-sizex="2" data-sizey="1">
<div data-id="youtrack-widget" data-view="List" data-unordered="true" data-title="YouTrack"></div>
</li>
require 'nokogiri'
require 'open-uri'
require 'rest-client'
login='your-youtrack-login'
password='your-youtrack-password'
response = RestClient.post "https://youtrack.jetbrains.com/rest/user/login", :login => login, :password => password
@session_cookies = response.cookies
SCHEDULER.every '5m', :first_in => 0 do |job|
response = RestClient.get(
'http://youtrack.jetbrains.com/rest/issue/byproject/ADM',
:params => {:filter => 'type: {New employee} #Unresolved sort by: {Due Date} asc'},
:cookies => @session_cookies
)
xmlfeed = Nokogiri::XML(response, nil, 'UTF-8')
summary = xmlfeed.xpath("//field[@name='summary']/value/text()")
issue_number = xmlfeed.xpath("//field[@name='numberInProject']/value/text()")
issues = []
for i in 0..issue_number.length-1
label = summary[i].to_s
value = issue_number[i].to_s
issues.push({:label => label, :value => value })
end
send_event('youtrack-widget', { items: issues })
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment