зеркало из https://github.com/mozilla/tsci.git
Use a config.json file for all configurable constants
This commit is contained in:
Родитель
8ba5bf30d7
Коммит
3c8fb8a2be
|
@ -1,5 +1,5 @@
|
|||
node_modules
|
||||
data
|
||||
config.json
|
||||
credentials.json
|
||||
api-key.ini
|
||||
.vscode/
|
||||
|
|
27
README.md
27
README.md
|
@ -7,12 +7,29 @@ Requires [Node](https://nodejs.org/) 8+ and a [Google Cloud Platform](https://cl
|
|||
You need to [create](https://cloud.google.com/docs/authentication/getting-started) a service account and download
|
||||
the JSON file containing the authentication credentials. Put that file in the project workspace as `credentials.json`.
|
||||
|
||||
Create another file in the project workspace named `api-key.ini` containing API keys for
|
||||
[Bugzilla](https://bugzilla.mozilla.org/userprefs.cgi?tab=apikey) and
|
||||
[GitHub](https://help.github.com/en/articles/creating-a-personal-access-token-for-the-command-line), like this:
|
||||
Create another file in the project workspace named `config.json` containing configuration overrides for your needs,
|
||||
like API keys for [Bugzilla](https://bugzilla.mozilla.org/userprefs.cgi?tab=apikey) and
|
||||
[GitHub](https://help.github.com/en/articles/creating-a-personal-access-token-for-the-command-line).
|
||||
Omit any keys where the defaults would suffice. Here is what the a `config.json` with the defaults would look like
|
||||
(modulo the comments):
|
||||
```
|
||||
bugzillaKey=xxxxxxxxxx
|
||||
githubKey=zzzzzzzzzzzz
|
||||
{
|
||||
// The size of the Tranco list to download, up to 1 million sites.
|
||||
"listSize": 500,
|
||||
// The directory that will be used to store the downloaded list.
|
||||
"listDir": "data/",
|
||||
// The Bugzilla API authentication key.
|
||||
"bugzillaKey": "",
|
||||
// The GitHub API authentication key.
|
||||
"githubKey": "",
|
||||
// A cutoff date for calculating the TSCI (if not a Sunday, will be rounded to the next Sunday).
|
||||
// E.g. a value of "2019-03-01" would lead to using "2019-03-03" (March 1st was a Friday).
|
||||
"maxDate": null,
|
||||
// A list of Google accounts with whom the final spreadsheet should be shared.
|
||||
"writers": [
|
||||
"user@example.com"
|
||||
]
|
||||
}
|
||||
```
|
||||
|
||||
Then run:
|
||||
|
|
26
bugs.js
26
bugs.js
|
@ -13,7 +13,7 @@ const Octokit = require('@octokit/rest')
|
|||
* @returns a Map of String keys to arrays of Strings that represent spreadsheet
|
||||
* column data
|
||||
*/
|
||||
const fetchBugs = async (listFile = 'data/list.csv', keyFile = 'api-key.ini', minDate, maxDate) => {
|
||||
const fetchBugs = async (listFile = 'data/list.csv', bugzillaKey, githubKey, minDate, maxDate) => {
|
||||
const bugzilla = [];
|
||||
const webcompat = [];
|
||||
const criticals = [];
|
||||
|
@ -25,11 +25,6 @@ const fetchBugs = async (listFile = 'data/list.csv', keyFile = 'api-key.ini', mi
|
|||
bugTable.set("criticals", criticals);
|
||||
bugTable.set("duplicates", duplicates);
|
||||
|
||||
// Load service API keys.
|
||||
const apiKeys = await getKeys(keyFile);
|
||||
const bugzillaKey = apiKeys.get("bugzillaKey");
|
||||
const githubKey = apiKeys.get("githubKey");
|
||||
|
||||
// Load the website list.
|
||||
const fileStream = fs.createReadStream(listFile);
|
||||
const rl = readline.createInterface({
|
||||
|
@ -49,25 +44,6 @@ const fetchBugs = async (listFile = 'data/list.csv', keyFile = 'api-key.ini', mi
|
|||
return bugTable;
|
||||
}
|
||||
|
||||
/**
|
||||
* Load the service API keys from the provided file.
|
||||
* @param {*} keyFile
|
||||
*/
|
||||
const getKeys = async (keyFile) => {
|
||||
const apiKeys = new Map();
|
||||
const fileStream = fs.createReadStream(keyFile);
|
||||
const rl = readline.createInterface({
|
||||
input: fileStream,
|
||||
crlfDelay: Infinity
|
||||
});
|
||||
for await (const line of rl) {
|
||||
const [service, key] = line.split('=');
|
||||
apiKeys.set(service, key);
|
||||
console.log(`Loaded key ${key} for service ${service}`);
|
||||
}
|
||||
return apiKeys;
|
||||
}
|
||||
|
||||
function formatDateForAPIQueries(date) {
|
||||
const yyyy = date.getFullYear();
|
||||
const mm = String(date.getMonth() + 1).padStart(2, "0");
|
||||
|
|
18
index.js
18
index.js
|
@ -3,14 +3,16 @@ const tranco = require('./tranco');
|
|||
const spreadsheet = require('./spreadsheet');
|
||||
const bugs = require('./bugs');
|
||||
|
||||
const LIST_SIZE = 500;
|
||||
const LIST_DIR = 'data/';
|
||||
const API_KEY_FILE = 'api-key.ini';
|
||||
const writers = ['pastith@gmail.com'];
|
||||
|
||||
const main = async () => {
|
||||
let maxDate;
|
||||
const week = process.argv[2];
|
||||
const config = require('./config.json');
|
||||
const LIST_SIZE = config.listSize || 500;
|
||||
const LIST_DIR = config.listDir || 'data/';
|
||||
const bugzillaKey = config.bugzillaKey || '';
|
||||
const githubKey = config.githubKey || '';
|
||||
const writers = config.writers || ['user@example.com'];
|
||||
let maxDate = config.maxDate || null;
|
||||
|
||||
const week = process.argv[2] || maxDate;
|
||||
if (week) {
|
||||
// We want to consider open bugs only until the end of the given week.
|
||||
const parsed = new Date(week);
|
||||
|
@ -23,7 +25,7 @@ const main = async () => {
|
|||
}
|
||||
|
||||
const LIST_FILE = await tranco.fetchList(LIST_SIZE, LIST_DIR, maxDate);
|
||||
const bugTable = await bugs.fetchBugs(LIST_FILE, API_KEY_FILE, undefined, maxDate);
|
||||
const bugTable = await bugs.fetchBugs(LIST_FILE, bugzillaKey, githubKey, undefined, maxDate);
|
||||
|
||||
const SCOPES = ['https://www.googleapis.com/auth/drive.file'];
|
||||
const auth = await google.auth.getClient({ scopes: SCOPES });
|
||||
|
|
|
@ -18,7 +18,6 @@ async function createSpreadsheet(drive, title, file) {
|
|||
if (err) {
|
||||
reject(err);
|
||||
} else {
|
||||
// console.log(file);
|
||||
resolve(file.data.id);
|
||||
}
|
||||
});
|
||||
|
|
Загрузка…
Ссылка в новой задаче