Skip to content

Instantly share code, notes, and snippets.

@matt-snider
Forked from christiangalsterer/README.md
Last active January 17, 2019 20:02
Show Gist options
  • Star 4 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save matt-snider/be38718bc9ff3ee26f9c to your computer and use it in GitHub Desktop.
Save matt-snider/be38718bc9ff3ee26f9c to your computer and use it in GitHub Desktop.
JIRA List Current Sprint Issues Dashing Widget

Preview

Description

A Dashing widget that lists JIRA issues in the current sprint for a specific team. For example open issues, in progress issues, etc.

Dependencies

Requires the following:

Add to Dashing's Gemfile:

gem 'jira-ruby', :require => 'jira'
gem 'json'

and run bundle install.

Usage

To use this widget, simply run:

dashing install be38718bc9ff3ee26f9c

For each widget you add to your dashboard, include the following snippet in the layout file:

<li data-row="1" data-col="1" data-sizex="1" data-sizey="1">
    <div data-id="jira-in-prog-issues" data-view="JiraListCurrentSprintIssues"></div>
</li>

Settings

Substitute the following placeholders in gitlab_merge_requests.rb with the appropriate values:

  • PROJECT: the project path/name
  • RAPID_VIEW_ID: id for the rapid view board
  • JIRA_CONFIG: credentials to access JIRA
  • ISSUE_LISTS: the lists to create (creates a widget per entry)
    • status codes: open (1), in progress (3), resolved (4), reopened (5), closed (6)

The job to update the merge requests is run every 5 minutes but you can adjust this as needed.

class Dashing.JiraListCurrentSprintIssues extends Dashing.Widget
ready: ->
# This is fired when the widget is done being rendered
onData: (data) ->
# Handle incoming data
# You can access the html node of this widget with `@node`
# Example: $(@node).fadeOut().fadeIn() will make the node flash each time data comes in.
<h1 class="header" data-bind="header"></h1>
<h2 class="status-title" data-bind="issue_type"></h2>
<div class="list">
<div data-foreach-issue="issues" class="wrapper">
<div class="left">
<img class="assignee-avatar" data-bind-src="issue.assigneeAvatarUrl" alt="Assignee Avatar" src="">
<div class="assignee-name" data-bind="issue.assigneeName"></div>
</div>
<div class="right">
<div class="issue-title" data-bind="issue.title"></div>
<div class="issue-id" data-bind="issue.id"></div>
</div>
<div style="clear: both; padding-bottom: 1vh;"></div>
</div>
</div>
<p class="updated-at" data-bind="updatedAtMessage"></p>
require 'jira'
require 'net/http'
require 'json'
# Settings to configure:
# PROJECT: the project path/name
# RAPID_VIEW_ID: id for the rapid view board
# JIRA_CONFIG: credentials to access JIRA
# ISSUE_LISTS: a widget per entry for different statuses (see JIRA_STATUSES)
PROJECT = "my-awesome-project"
RAPID_VIEW_ID = 0
JIRA_CONFIG = {
:username => 'username',
:password => 'password',
:site => "https://jira.atlassian.com",
:auth_type => :basic,
:context_path => ''
}
ISSUE_LISTS = [
{:widget_id => 'jira_open_issues', :status_id => 1}, # Lists all open issues
{:widget_id => 'jira_in_prog_issues', :status_id => 3} # Lists all issues in progress
]
# Constants (do not change)
JIRA_URI = URI.parse(JIRA_CONFIG[:site])
JIRA_ANON_AVATAR_ID = 10123
JIRA_STATUSES = {
1 => "Open",
3 => "In Progress",
4 => "Reopened",
5 => "Resolved",
6 => "Closed"
}
# gets the view for a given view id
def get_view_for_viewid(view_id)
http = create_http
request = create_request("/rest/greenhopper/1.0/rapidviews/list")
response = http.request(request)
views = JSON.parse(response.body)['views']
views.each do |view|
if view['id'] == view_id
return view
end
end
end
# gets the active sprint for the view
def get_active_sprint_for_view(view_id)
http = create_http
request = create_request("/rest/greenhopper/1.0/sprintquery/#{view_id}")
response = http.request(request)
sprints = JSON.parse(response.body)['sprints']
sprints.each do |sprint|
if sprint['state'] == 'ACTIVE'
return sprint
end
end
end
# create HTTP
def create_http
http = Net::HTTP.new(JIRA_URI.host, JIRA_URI.port)
if ('https' == JIRA_URI.scheme)
http.use_ssl = true
http.verify_mode = OpenSSL::SSL::VERIFY_NONE
end
return http
end
# create HTTP request for given path
def create_request(path)
request = Net::HTTP::Get.new(JIRA_URI.path + path)
if JIRA_CONFIG[:username]
request.basic_auth(JIRA_CONFIG[:username], JIRA_CONFIG[:password])
end
return request
end
ISSUE_LISTS.each do |list_config|
SCHEDULER.every '5m', :first_in => 0 do |job|
issues = []
status_id = list_config[:status_id]
client = JIRA::Client.new(JIRA_CONFIG)
client.Issue.jql("PROJECT = \"#{PROJECT}\" AND STATUS = \"#{status_id}\" AND SPRINT in openSprints()").each { |issue|
assigneeAvatarUrl = issue.assignee.nil? ? URI.join(JIRA_URI.to_s, "secure/useravatar?avatarId=#{JIRA_ANON_AVATAR_ID}") : issue.assignee.avatarUrls["48x48"]
assigneeName = issue.assignee.nil? ? "unassigned" : issue.assignee.name
issues.push({
id: issue.key,
title: issue.summary,
assigneeName: assigneeName,
assigneeAvatarUrl: assigneeAvatarUrl
})
}
issue_type = JIRA_STATUSES[status_id]
active_sprint = get_active_sprint_for_view(RAPID_VIEW_ID)
sprint_name = active_sprint['name']
send_event(list_config[:widget_id], { header: "#{sprint_name} Issues", issue_type: issue_type, issues: issues})
end
end
// ----------------------------------------------------------------------------
// Sass declarations
// ----------------------------------------------------------------------------
$background-color: teal;
$value-color: #fff;
$title-color: rgba(255, 255, 255, 0.7);
$label-color: rgba(255, 255, 255, 0.7);
$updated-at-color: rgba(212, 212, 212, 0.76);
// ----------------------------------------------------------------------------
// Widget-jira-list-current-sprint-issues styles
// ----------------------------------------------------------------------------
.widget-jira-list-current-sprint-issues {
background-color: $background-color;
vertical-align: top !important;
.header {
color: $label-color;
font-size: xx-large;
margin-bottom: 0;
}
.status-title {
font-size: x-large;
padding-bottom: 1vh;
color: $label-color;
}
.wrapper {
width: 100%;
height: auto;
}
.left {
display: inline;
float: left;
width: 4vw;
text-align: left;
overflow: hidden;
}
.right {
vertical-align: top;
overflow: hidden;
padding-left: 0.5vw;
}
.issue-title {
font-size: medium;
text-align: left;
}
.issue-id {
font-size: small;
}
.assignee-name {
font-size: small;
}
.list {
list-style: none;
}
.updated-at {
color: $updated-at-color;
}
}
@spudtheimpaler
Copy link

Hi! Sorry to ask for "support" here but I don't know where else to put it.

When adding your widget I see a blank screen. I can't find any logs on the server and looking through the dashing support, I added the debugging flag so that I could see the information, and lo and behold the information is being sent, so it isn't a case of jira connection issues. They just aren't being displayed.

Unfortunately, this is where my know-how ends. I don't know Ruby or the framework dashing uses particularly well, but I understand there is a binding between the "jira_in_prog_issues" data-id, and it is this same id that seems to retrieve data. The console log shows:

Received data for jira_in_prog_issues Object > header: "My Project Name" id: "jira_in_prog_issues" issue_type: "In Progress" issues: Array[9] updatedAt: 1449220103 proto: Object {...}

Any guidance would be greatly appreciated, I would love to be able to add this to my dashboard!

Many thanks,
Mitch.

@Martin1001
Copy link

Hi Mitch,

there is a spelling mistake in dashboard snippet.

You must change the word separator in the data-id variable:

  • data-id="jira-in-prog-issues" > data-id="jira_in_prog_issues"
  • data-id="jira-open-issues" > data-id="jira_open_issues"

@shivpatel779
Copy link

Hi,

hey i have follow all you instruction and updated proper JIRA credential, why? I'm not able to see details from dashboard...

I fix the JIRA::HTTP error while updating valid JIRA credential..

@ScottBrenner
Copy link

require 'jira' from the first line of jira_list_current_sprint_issues.rb should be require 'jira-ruby'

My widget is displaying 10 issues, but the "last updated" text appears between the third/fourth issue - any way to move it to the bottom of the widget?

@guicattani
Copy link

Is the coffee script part outdated? It is empty.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment