-
Notifications
You must be signed in to change notification settings - Fork 17
/
findIssues.js
96 lines (78 loc) · 2.54 KB
/
findIssues.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
88
89
90
91
92
93
94
95
96
const fs = require('fs')
path = require('path')
mariner = require('oss-mariner')
function getFromEnvOrThrow(configField) {
const value = process.env[configField];
if (!value) {
throw new Error(`${configField} is required`);
}
return value;
}
const token = getFromEnvOrThrow('MARINER_GITHUB_TOKEN');
const inputFilePath =
process.env.MARINER_INPUT_FILE_PATH ||
path.join(__dirname, 'InputFiles', 'inputData.json');
const outputFilePath =
process.env.MARINER_OUTPUT_FILE_PATH ||
path.join(__dirname, 'OutputFiles', 'outputData.json');
class FancyLogger {
info(message) {
console.log('***INFO: ' + message);
}
error(message) {
console.log('***ERROR: ' + message);
}
}
const logger = new FancyLogger();
logger.info(`Input: ${inputFilePath}`);
logger.info(`Output: ${outputFilePath}`);
const contents = fs.readFileSync(inputFilePath, {
encoding: 'utf8',
});
const countsByLibrary = JSON.parse(contents);
const repositoryIdentifiers = Object.keys(countsByLibrary);
const finder = new mariner.IssueFinder(logger);
function convertToRecord(issues) {
const record = {};
repositoryIdentifiers
.sort((a, b) => countsByLibrary[b] - countsByLibrary[a])
.map(a => record[a] = [])
issues.forEach((issuesForRepo, repo) => {
record[repo] = issuesForRepo;
});
const jsonFile = outputToJson(record);
return jsonFile;
}
function outputToJson(record) {
const noReplacer = undefined;
const indent = 2;
const jsonResults = JSON.stringify(record, noReplacer, indent);
const data = fs.writeFileSync(outputFilePath, jsonResults);
return data;
}
function formatLabels(labels) {
return labels.map((label) => label.replace(/\s/g, '+'));
}
const labelsFilePath =
process.env.MARINER_LABELS_FILE_PATH ||
path.join(__dirname, 'InputFiles', 'issueLabels.json');
logger.info(`Labels: ${labelsFilePath}`);
const labelsJSON = fs.readFileSync(labelsFilePath, {
encoding: 'utf8',
});
const formattedLabels = formatLabels(JSON.parse(labelsJSON));
finder
.findIssues(token, formattedLabels, repositoryIdentifiers)
.then((issues) => {
let issueCount = 0;
issues.forEach((issuesForRepo) => {
issueCount += issuesForRepo.length;
});
convertToRecord(issues);
logger.info(`Found ${issueCount} issues in ${issues.size} projects\n`);
logger.info(`Saved issue results to: ${outputFilePath}`);
})
.catch((err) => {
logger.error(err.message);
console.log(err);
});