-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathtest.html
111 lines (84 loc) · 2.64 KB
/
test.html
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
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
<!DOCTYPE html>
<body>
<p>Click the button to display a String version of the array.</p>
<button onclick="myFunction()">Try it</button>
<input type="file" id="fileInput" accept=".txt" onchange="validateFile()">
<p id="demo"></p>
<script>
let tags = {T:'Feature', B:'Bugfixes', CB:'Client Bugfixes'}; //default commit tags
var chageLogTags = new Array();
var changeLogMessage = "## What’s New\n";
var logs = "";
function validateFile() {
var fileInput = document.getElementById("fileInput");
var file = fileInput.files[0]; // Get the selected file
if (!file) {
alert('Please select a file.');
return;
}
var allowedExtensions = /(\.txt)$/i;
var filename = file.name;
if (!allowedExtensions.exec(filename)) {
alert('Please upload only .txt files.');
return;
}
var reader = new FileReader();
reader.onload = function(event) {
var fileContent = event.target.result;
logs = (fileContent);
myFunction();
};
reader.readAsText(file); // Read the file as text
}
function escapeSpecialChars(jsonString) {
return jsonString.replace('\\', '\\\\')
.replace('"', '\\"')
.replace('\n', '\\n')
.replace('\t', '\\t');
}
function myFunction() {
console.log(tags);
tags = JSON.parse('{"T":"Feature", "B":"Bugfixes", "CB":"Client Bugfixes"}');
console.log(tags);
//var tags = {t:'Feature', B:'Bugfixes'};
//var chageLogTags = new Array();
for (let key in tags){
//set data to lower case to avoid issue regarding data
chageLogTags[key.toLowerCase()] = new Array();
tags[key.toLowerCase()] = tags[key];
};
console.log(chageLogTags);
parseData(logs);
}
function parseData(logs){
var myArray = [];
var parsedJSON = JSON.parse((logs));
for( let num in parsedJSON ){
var log = parsedJSON[num];
var message = log.message;
var splitMessage = message.split("-");
var type = splitMessage[0];
var id = splitMessage[1];
if(chageLogTags[type.toLowerCase()] !== undefined){
if(myArray.includes(id)){
continue;
}
myArray.push(id);
chageLogTags[type.toLowerCase()].push(new Array(type, id, message, log.author, log.original_message ));
}
}
var changeLogMessage = "## What’s New\n";
for (let key in chageLogTags){
var data = chageLogTags[key];
for (let i = 0; i < data.length; i++) {
if(i ==0){
changeLogMessage += "\n\n" + tags[key];
}
changeLogMessage += "\n* " + data[i][4] + " (@" + data[i][3] + ")"
}
};
console.log(changeLogMessage);
}
</script>
</body>
</html>