-
Notifications
You must be signed in to change notification settings - Fork 8
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #82 from Sanofi-IADC/add-jira-step
add jira step & display issues in gridjs table
- Loading branch information
Showing
6 changed files
with
188 additions
and
3 deletions.
There are no files selected for viewing
This file contains 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
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
import { HttpService, Injectable } from '@nestjs/common'; | ||
import { ConfigService } from '@nestjs/config'; | ||
|
||
@Injectable() | ||
export class JiraService { | ||
baseUrl = 'https://iadc.atlassian.net/rest/api/2'; | ||
|
||
headers = {}; | ||
|
||
constructor( | ||
private httpService: HttpService, | ||
private configService: ConfigService, | ||
) { | ||
const credentials = `${this.configService.get( | ||
'confluence.apiUsername', | ||
)}:${this.configService.get('confluence.apiToken')}`; | ||
|
||
this.headers = { | ||
Authorization: `Basic ${credentials}`, | ||
}; | ||
} | ||
|
||
findTickets(jqlSearch: string, fields: string, maxResult = 100) { | ||
const url = `${this.baseUrl}/search?jql=${jqlSearch}&fields=${fields}&maxResults=${maxResult}`; | ||
|
||
return this.httpService | ||
.get(url, { | ||
headers: this.headers, | ||
}) | ||
.toPromise() | ||
.then((res) => res.data); | ||
} | ||
} |
This file contains 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
This file contains 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
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,6 @@ | ||
import { JiraService } from 'src/http/jira.service'; | ||
import { ContextService } from '../context/context.service'; | ||
|
||
export interface Step { | ||
(context: ContextService): void | Promise<void>; | ||
(context: ContextService, jira?: JiraService): void | Promise<void>; | ||
} |
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,143 @@ | ||
import { ContextService } from '../../context/context.service'; | ||
import { Step } from '../proxy-page.step'; | ||
import cheerio from 'cheerio'; | ||
import { JiraService } from 'src/http/jira.service'; | ||
|
||
export default (): Step => { | ||
return async ( | ||
context: ContextService, | ||
jiraService: JiraService, | ||
): Promise<void> => { | ||
context.setPerfMark('addJira'); | ||
const $ = context.getCheerioBody(); | ||
|
||
if (!$('.refresh-wiki') || !$('.refresh-wiki').data()) { | ||
context.getPerfMeasure('addJira'); | ||
return; | ||
} | ||
|
||
const wikimarkup: string = $('.refresh-wiki').data().wikimarkup; | ||
const xmlWikimarkup = cheerio.load(wikimarkup, { xmlMode: true }); | ||
const filter = xmlWikimarkup('ac\\:parameter[ac\\:name="jqlQuery"]').text(); | ||
const columns = | ||
xmlWikimarkup('ac\\:parameter[ac\\:name="columns"]').text() + | ||
',issuetype'; | ||
const maximumIssues = xmlWikimarkup( | ||
'ac\\:parameter[ac\\:name="maximumIssues"]', | ||
).text(); | ||
const { issues } = await jiraService.findTickets( | ||
filter, | ||
columns, | ||
Number(maximumIssues), | ||
); | ||
|
||
const data = []; | ||
issues.forEach((issue) => { | ||
data.push({ | ||
key: { | ||
name: issue.key, | ||
link: `https://iadc.atlassian.net/browse/${issue.key}?src=confmacro`, | ||
}, | ||
t: issue.fields.issuetype?.iconUrl, | ||
summary: { | ||
name: issue.fields.summary, | ||
link: `https://iadc.atlassian.net/browse/${issue.key}?src=confmacro`, | ||
}, | ||
updated: `${new Date(issue.fields.updated).toLocaleString('en-EN', { | ||
year: 'numeric', | ||
month: 'short', | ||
day: '2-digit', | ||
hour: '2-digit', | ||
minute: '2-digit', | ||
})}`, | ||
assignee: issue.fields.assignee?.displayName, | ||
pr: issue.fields.priority.iconUrl, | ||
status: { | ||
name: issue.fields.status.name, | ||
color: issue.fields.status.statusCategory.colorName, | ||
}, | ||
resolution: issue.fields.resolution.name, | ||
}); | ||
}); | ||
|
||
// remove the header | ||
$('div[id^="jira-issues-"]').remove(); | ||
|
||
// remove the 'loading...' text | ||
$('div[id^="refresh-issues-loading-"]').remove(); | ||
|
||
// remove the actualize link | ||
$('.refresh-issues-bottom').remove(); | ||
|
||
// add the grid using http://gridjs.io library | ||
$('#Content').append( | ||
'<script src="https://unpkg.com/gridjs/dist/gridjs.production.min.js"></script>', | ||
'<link href="https://unpkg.com/gridjs/dist/theme/mermaid.min.css" rel="stylesheet" />', | ||
'<div id="gridjs"></div>', | ||
`<script> | ||
document.addEventListener('DOMContentLoaded', function () { | ||
new gridjs.Grid({ | ||
columns: [ | ||
{ | ||
name: 'Key', | ||
width: '5%', | ||
formatter: (cell) => gridjs.html(${'`<a href="${cell.link}" target="_blank">${cell.name}</a>`'}) | ||
}, | ||
{ | ||
name: 'Summary', | ||
width: '30%', | ||
formatter: (cell) => gridjs.html(${'`<a href="${cell.link}" target="_blank">${cell.name}</a>`'}) | ||
}, | ||
{ | ||
name: 'T', | ||
width: '2%', | ||
formatter: (cell) => gridjs.html(${'`<img src="${cell}" style="height:2.5rem"/>`'}), | ||
}, | ||
{ | ||
name: 'Updated', | ||
width: '7%', | ||
sort: { | ||
compare: (a, b) => (new Date(a) > new Date(b) ? 1 : -1), | ||
} | ||
}, | ||
{ | ||
name: 'Assignee', | ||
width: '10%', | ||
}, | ||
{ | ||
name: 'Pr', | ||
width: '3%', | ||
formatter: (cell) => gridjs.html(${'`<img src="${cell}" style="height:2.5rem"/>`'}), | ||
}, | ||
{ | ||
name: 'Status', | ||
width: '5%', | ||
formatter: (cell) => gridjs.html(${'`<div style="color:${cell.color}">${cell.name}</div>`'}) | ||
}, | ||
{ | ||
name: 'Resolution', | ||
width: '5%', | ||
}, | ||
], | ||
data: ${JSON.stringify(data)}, | ||
sort: true, | ||
search: { | ||
enabled: true, | ||
selector: (cell, rowIndex, cellIndex) => cell ? cell.name || cell : '' | ||
}, | ||
style: { | ||
td: { | ||
padding: '5px 5px' | ||
}, | ||
th: { | ||
padding: '5px 5px' | ||
} | ||
} | ||
}).render(document.getElementById("gridjs")); | ||
}) | ||
</script>`, | ||
); | ||
|
||
context.getPerfMeasure('addJira'); | ||
}; | ||
}; |