Created
May 3, 2018 06:52
-
-
Save malys/b6c19b4de72f009dd3c6f0af76cabca7 to your computer and use it in GitHub Desktop.
[JiraPlantUMLGantt] Gantt generator for JIRA #javascript #jira
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| module.exports = { | |
| //Background/contour | |
| 'In Progress': {b:'#d9d9d9',c:'#d9d9d9'}, | |
| 'To Review': {b:'#cccccc',c:'#cccccc'}, | |
| 'To Validate': {b:'#bfbfbf',c:'#bfbfbf'}, | |
| 'Done': {b:'#999999',c:'#999999'}, | |
| 'Urgent': {b:'ff3333',c:'#ff3333'} | |
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| module.exports = (argv) => { | |
| return { | |
| protocol: 'https', | |
| host: argv.h , | |
| port: 443, | |
| user: argv.u, | |
| password: argv.p, | |
| apiVersion: '2', | |
| verbose: true, | |
| strictSSL: true | |
| } | |
| }; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| // Initialize | |
| //node src/gantt.js && java -jar "plantuml.jar" -o "h:/" -charset UTF-8 "gantt.puml" | |
| const debug = require('debug')('gantt') | |
| const argv = require('yargs').argv | |
| var sleep = require('thread-sleep'); | |
| var config = require('./config')(argv) | |
| var JiraApi = require('jira').JiraApi; | |
| var jira = new JiraApi(config.protocol, config.host, config.port, config.user, config.password, config.apiVersion, config.verbose, config.strictSSL); | |
| const fs = require('fs'); | |
| const IS_COLORED = ' is colored in ' | |
| const EQUI_COLOR = require('./color.js') | |
| var processDate = (value => { | |
| return value.split(' ').map(v => { | |
| let unit = v.substring(v.length - 1, v.length) | |
| let number = v.substring(0, v.length - 1) | |
| let result = 0 | |
| switch (unit) { | |
| case 'w': | |
| result = parseInt(number, 10) * 7 | |
| break; | |
| default: | |
| result = parseInt(number, 10) | |
| break; | |
| } | |
| return result; | |
| }).reduce((accumulator, currentValue) => accumulator + currentValue) | |
| }) | |
| let criteria='and (fixVersion in (unreleasedVersions()) or fixVersion is EMPTY)' | |
| if(argv.v){ | |
| console.log("Version: " + argv.v) | |
| criteria = 'and fixVersion = ' + argv.v | |
| } | |
| jira.searchJira('project=XXXX ' + criteria + ' and status ="NEW" ORDER BY fixVersion ASC,status ASC,RANK ASC', {}, function (error, result1) { | |
| //console.log(result1); | |
| if (error) { | |
| console.log(error) | |
| return | |
| } | |
| var puml = fs.createWriteStream('gantt.puml') | |
| puml.write('@startuml' + '\n') | |
| // puml.write('Project starts the 2th of october 2017' + '\n') | |
| var l = [] | |
| result1.issues.forEach(function (element, index, array) { | |
| l.push(new Promise((resolve, reject) => { | |
| jira.findIssue(element.key, function (error, result) { | |
| /*let versions | |
| if(result && result.fields){ | |
| versions = result.fields.fixVersions.map((f) => { | |
| return f.name | |
| }) | |
| }*/ | |
| //if (true || (argv.v && versions && result.fields.fixVersions && versions.includes(argv.v) ) || !argv.v) { | |
| let en = '[' + element.key + ':' + element.fields.summary + ']' | |
| let alias = '[' + element.key + ']' | |
| //Duration | |
| var d = '1' | |
| if (result && result.fields && result.fields.timetracking.originalEstimate) { | |
| d = processDate(result.fields.timetracking.originalEstimate) | |
| } | |
| var r = en + ' as ' + alias + ' lasts ' + d + ' days' + '\n' | |
| //Color | |
| let detected = -1 | |
| if (result && result.fields) { | |
| detected = result.fields.labels.findIndex(function (e) { | |
| return e.indexOf('-LYRA') > -1; | |
| }) | |
| } | |
| if (result && result.fields && detected > -1) { | |
| let colorEntry = EQUI_COLOR[result.fields.labels[detected]] | |
| let colorOver = undefined | |
| let colorUrgent = undefined | |
| let color = undefined | |
| if (result.fields.status && result.fields.status.name !== 'To Do') { | |
| colorOver = EQUI_COLOR[result.fields.status.name] | |
| } | |
| if (result.fields.status && result.fields.status.name == 'To Do' && result.fields.duedate) { | |
| //console.log(result.fields.duedate) | |
| var from = result.fields.duedate.split('-') | |
| var due = new Date(from[0], from[1] - 1, from[2]); | |
| //console.log(due.toISOString(),new Date().toISOString()) | |
| if (due.getTime() < new Date().getTime()) { | |
| colorUrgent = EQUI_COLOR['Urgent'] | |
| } | |
| } | |
| if (colorEntry && !colorOver) { | |
| color = colorEntry.b + '/' + colorEntry.c | |
| } else if (colorEntry && colorOver) { | |
| color = colorOver.b + '/' + colorEntry.c | |
| } else if (!colorEntry && colorOver) { | |
| color = colorOver.b + '/' + colorOver.c | |
| } | |
| if (colorUrgent) { | |
| color = colorUrgent.b + '/' + color.split('/')[1]; | |
| } | |
| if (color) { | |
| r = r + alias + IS_COLORED + color + "\n" | |
| } | |
| } | |
| //Ancester | |
| if (index > 0) r = parseIssueLinks(array, index, result, r, alias) | |
| resolve(r) | |
| /* }else{ | |
| resolve('') | |
| }*/ | |
| }); | |
| })) | |
| //sleep(1000); | |
| }); | |
| Promise.all(l).then(values => { | |
| puml.write(values.join('')); | |
| puml.write('@enduml' + '\n'); | |
| }); | |
| }); | |
| /** | |
| * Find ancester for a task | |
| * @param {*} array | |
| * @param {*} element | |
| */ | |
| var parseIssueLinks = (array, index, element, r, en) => { | |
| let result = undefined // | |
| if (element && element.fields.issuelinks) { | |
| for (var link of element.fields.issuelinks) { | |
| if (link.type && link.type.outward === 'blocks' && link.inwardIssue && link.inwardIssue.fields.status.name != 'Done') { | |
| let indexD=array.findIndex((a)=>{ | |
| return a.key === link.inwardIssue.key | |
| }) | |
| if(indexD>-1){ | |
| result = link.inwardIssue.key | |
| } | |
| //break | |
| } | |
| if (result) { | |
| //console.log(element,link) | |
| let dep = en + ' starts at [' + result + ']' + '\'s end' + '\n' | |
| if (r.indexOf(dep) == -1) { | |
| r = r + dep | |
| } | |
| result = undefined // array[index - 1].key | |
| } | |
| } | |
| } | |
| return r | |
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| { | |
| "name": "jira", | |
| "version": "0.0.1", | |
| "main": "gantt.js", | |
| "dependencies": { | |
| "debug": "*", | |
| "jira": "~0.9.2", | |
| "thread-sleep": "^2.0.0", | |
| "yargs": "^11.0.0" | |
| } | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment