Created
June 2, 2020 02:25
-
-
Save makotom/b4765ee3799484d6dcbdffb8518bd793 to your computer and use it in GitHub Desktop.
CircleCI Server: Process list of jobs and users, and extract a list of unseen users
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// Modules to use | |
const fs = require('fs'); | |
{ | |
// Output: Array of users unseen in the job list | |
const unseenUsers = []; | |
// Output: Tab-separated list of jobs | |
const jobsTSV = []; | |
// Source data | |
const jobs = JSON.parse(fs.readFileSync('jobs.json')); | |
const users = JSON.parse(fs.readFileSync('users.json')); | |
// Internal data: a "user -> last job trigger date" map | |
const lastJobByUser = new Map(); | |
// Iterate through the list of jobs | |
jobs.forEach((job) => { | |
// Put the job into the TSV | |
jobsTSV.push([job.at, job.by, job.for].join('\t')); | |
// Update "user -> last job trigger date" map | |
lastJobByUser.set(job.by, job.at); | |
}); | |
// Iterate through the list of users | |
users.forEach((user) => { | |
if (lastJobByUser.get(user) === void 0) { | |
// The user did not trigger a job for a while | |
// Add the user to unseenUsers | |
unseenUsers.push(user); | |
} | |
}); | |
// Dump output to files | |
// Files are created in the current directory | |
fs.writeFileSync('jobs.tsv', jobsTSV.reverse().join('\n')); // jobs.tsv: List of all jobs, ordered by job date in descending order (newest comes first) | |
fs.writeFileSync('allUsers.txt', users.join('\n')); // allUsers.txt: List of all users registered in CircleCI | |
fs.writeFileSync('unseenUsers.txt', unseenUsers.join('\n')); // unseenUsers.txt: List of unseen users | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment