Skip to content

Instantly share code, notes, and snippets.

@vossim
Last active November 17, 2018 09:22
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 vossim/c0072296d3297d3ae6fd to your computer and use it in GitHub Desktop.
Save vossim/c0072296d3297d3ae6fd to your computer and use it in GitHub Desktop.
Dashing widget to display the total number of Jira issues for a JQL query

dashing-jira-issuecount

Jira issue count plugin for dashing

Description

Dashing widget to display the total number of Jira issues for a JQL query

Installation

Put the files jira_issuecount.rb in the /jobs directory and (optionally) jira_issuecount.yaml in the /conf directory

This can also be done by using the gist: https://gist.github.com/vossim/c0072296d3297d3ae6fd

dashing install c0072296d3297d3ae6fd

Job configuration

Required configuration:

  • jira_url: Url to your jira server, excluding the trailing slash (/)
  • username: Username for a user with sufficient rights on your jira server
  • password: Password for the user
  • issuecount_mapping: Mapping of the issue count name and jql query

Example of issuecount_mapping:

issuecount_mapping: 
    myFilter: filter=123
    myFilter2: filter=456

Option 1: jira_issuecount.yaml

Create a jira_issuecount.yaml file in the /conf directory and configure it (example file in this repo).

Option 2: jira_issuecount.rb

Configure the JIRA_ISSUECOUNT_CONFIG block in the ruby code.

Dashboard configuration

Put the following in your dashboard.erb file to show the count:

<li data-row="1" data-col="1" data-sizex="1" data-sizey="1">
  <div data-id="myFilter" data-view="Number" data-title="A nice title for this JQL query"></div>
</li>

License

Distributed under the MIT license

require 'net/http'
require 'json'
require 'time'
require 'open-uri'
require 'cgi'
yamlFile = "./conf/jira_issuecount.yaml"
if File.exist?(yamlFile)
JIRA_OPENISSUES_CONFIG = YAML.load(File.new(yamlFile, "r").read)
else
JIRA_OPENISSUES_CONFIG = {
jira_url: "",
username: "",
password: "",
issuecount_mapping: {
'filterX' => "filter=1234"
}
}
end
def getNumberOfIssues(url, username, password, jqlString)
jql = CGI.escape(jqlString)
uri = URI.parse("#{url}/rest/api/2/search?jql=#{jql}")
http = Net::HTTP.new(uri.host, uri.port)
http.use_ssl = uri.scheme == 'https'
request = Net::HTTP::Get.new(uri.request_uri)
if !username.nil? && !username.empty?
request.basic_auth(username, password)
end
JSON.parse(http.request(request).body)["total"]
end
JIRA_OPENISSUES_CONFIG[:issuecount_mapping].each do |mappingName, filter|
SCHEDULER.every '1m', :first_in => 0 do
total = getNumberOfIssues(JIRA_OPENISSUES_CONFIG[:jira_url], JIRA_OPENISSUES_CONFIG[:username], JIRA_OPENISSUES_CONFIG[:password], filter)
send_event(mappingName, {current: total})
end
end
---
:jira_url: http://my.jira.server
:username: myUserName
:password: myPassword
:issuecount_mapping:
filterX: filter=1234
The MIT License (MIT)
Copyright (c) 2015 Simon Vos
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in
all copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
THE SOFTWARE.
@mehdibennis
Copy link

At first it is realy a good plugin and it make me win a lot of time.
But I have found some issues, the first one was about a required module
You can add require 'yaml' at the the beginning of your jira_issuecount.rb script
the second one was about
send_event(mappingName, {current: total})
here rmappingName var contains "filterX" value but it must refer to the widget_id ? Right ?
so I modified it like bellow:
send_event('myFilter', current: total)`
It works fine now

@Jega90
Copy link

Jega90 commented Nov 29, 2017

Hello @vossim @mehdibennis,

I don't understand this step:

Example of issuecount_mapping:
issuecount_mapping:
myFilter: filter=123
myFilter2: filter=456

Do i have to change anything on this to make the jira_issuecount work ?

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