-
Notifications
You must be signed in to change notification settings - Fork 0
/
reportDetails.js
87 lines (70 loc) · 3.31 KB
/
reportDetails.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
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
const { execSync } = require('child_process');
const Utilities = require('./utilities');
const path = require("path");
function getProjectDetails(project){
const projectName = project.items[0].Project;
const projectUrl = project.items[0]['Project URL'];
const lastCheckedCommit = project.items[0]['SHA Detected'];
return { projectUrl, lastCheckedCommit, projectName };
}
function startup(){
if (Utilities.fileExists('reportDetails.csv'))
execSync('rm reportDetails.csv');
execSync('rm -rf projects/*');
}
function setup(projectUrl) {
console.log(`Cloning ${projectUrl}`);
execSync(`cd projects && git clone ${projectUrl}`);
}
function cleanup(){
execSync('rm -rf projects/*');
}
function getFileInfo(projectName, testFilePath){
const result = {};
let log; let rePattern;
const commitPattern = new RegExp(/commit (.*)\n/g);
const datePattern = new RegExp(/Date: (.*)\n/g);
try{
log = execSync(`cd projects/${projectName} && git log --diff-filter=D -- ${testFilePath}`).toString();
result.deletedCommit = log.match(commitPattern)[0].replace('commit ','').replace('\n','');
result.deletedDate = log.match(datePattern)[0].replace('Date: ','').replace('\n','');
}catch(e){}
try{
log = execSync(`cd projects/${projectName} && git log --diff-filter=M -- ${testFilePath}`).toString();
result.modifiedCommit = log.match(commitPattern)[0].replace('commit ','').replace('\n','');
result.modifiedDate = log.match(datePattern)[0].replace('Date: ','').replace('\n','');
}catch(e){}
try{
log = execSync(`cd projects/${projectName} && git log --diff-filter=A -- ${testFilePath}`).toString();
result.createdCommit = log.match(commitPattern)[0].replace('commit ','').replace('\n','');
result.createdDate = log.match(datePattern)[0].replace('Date: ','').replace('\n','');
}catch(e){}
return result;
}
async function main(){
const reportFilePath = 'report.csv';
const projects = Utilities.groupBy('Project', (await Utilities.readCSV(reportFilePath)).filter(x=>x.URL !== ''));
startup();
for (const project of projects) {
const {projectUrl, lastCheckedCommit, projectName} = getProjectDetails(project);
console.log('*****************************************************************');
console.log(` Fetching details for ${projectName} project`);
console.log(` Project URL: ${projectUrl}`);
console.log('*****************************************************************');
const deletedTests = project.items.filter(x=>x.Confirmation==='deleted');
if (deletedTests.length > 0) {
setup(projectUrl);
const result = [];
const testFilePaths = deletedTests.map(x=>`${path.dirname(path.join(x['Module Path'],'src/test/java', x['Fully-Qualified Test Name (packageName.ClassName.methodName)'].split('.').join('/')))}.java`);
for (const testFilePath of testFilePaths) {
const fileDetails = getFileInfo(projectName, testFilePath);
fileDetails.testFilePath = testFilePath;
result.push(fileDetails);
}
await Utilities.writeDetailsCSV('reportDetails.csv', result);
cleanup();
}
}
console.log();
}
main();