-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathindex.js
68 lines (53 loc) · 1.5 KB
/
index.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
"use strict";
const unirest = require('unirest');
const parser = require('xml2json');
const targetXml = 'example.xml';
const targetJson = 'data2.json';
function xmlFromFile(targetXml) {
// Read file for example
const fs = require('fs');
const path = require('path');
const xmlFile = fs.readFileSync(path.join(__dirname, targetXml));
return xmlFile.toString();
}
function xmlToJson(xmlContent) {
return parser.toJson(xmlContent, {
object: true,
});
}
function saveJson(fileName, jsonObj) {
const fs = require('fs');
const path = require('path');
const jsonContent = JSON.stringify(jsonObj, null, 2);
fs.writeFileSync(path.join(__dirname, fileName), jsonContent);
}
function transformData(data) {
const feed = data.feed;
/**
* @type {Array}
*/
const issues = feed.entry;
const transData = {
title: feed.title,
links: feed.link,
updated: feed.updated,
issues: issues.map((issue, index) => {
return {
id: '#' + issue.id.split('/').pop(),
title: issue.title,
updated: issue.updated,
author: issue.author.name,
description: issue.description,
assignee: issue.assignee && issue.assignee.name || '',
labels: issue.labels && issue.labels.label.join(', '),
serverity: '',
status: '',
};
}) || [],
};
return transData;
}
const xmlContent = xmlFromFile(targetXml);
const jsonObj = xmlToJson(xmlContent);
// saveJson(targetJson, jsonObj);
saveJson(targetJson, transformData(jsonObj));