Make `execDependencyGraph` labels configurable (#220)

Summary:
The `"PASS"` label only makes sense for tests. This commit makes the
labels configurable, so that the verbiage can make more sense in other
contexts, too.

Test Plan:
Apply a patch like
```diff
diff --git a/config/travis.js b/config/travis.js
index af0996b..b0ab3b6 100644
--- a/config/travis.js
+++ b/config/travis.js
@@ -10,7 +10,11 @@ function main() {
     process.argv.includes("--full")
       ? "FULL"
       : "BASIC";
-  execDependencyGraph(makeTasks(mode)).then(({success}) => {
+  execDependencyGraph(makeTasks(mode), {
+    taskLaunchLabel: " YO ",
+    taskPassLabel: "WHEE",
+    taskFailLabel: "UHOH",
+  }).then(({success}) => {
     process.exitCode = success ? 0 : 1;
   });
 }
```
and note that `GITHUB_TOKEN=none yarn travis --full` exhibits all
desired messages.

wchargin-branch: configurable-labels
This commit is contained in:
William Chargin 2018-05-07 14:39:59 -07:00 committed by GitHub
parent 2aeeca9a13
commit 4e8d5b574a
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
1 changed files with 36 additions and 6 deletions

View File

@ -26,11 +26,33 @@ type TaskResult = {|
type OverallResult = {|
+success: boolean,
|};
// For best-looking results, the task pass, fail, and launch labels
// should all be of the same width. The default options use a
// 4-character string for each. Shorter strings with length of the same
// parity can be extended by symmetrically adding spaces.
type RunOptions = {|
+taskPassLabel?: string,
+taskFailLabel?: string,
+taskLaunchLabel?: string,
+overallPassLabel?: string,
+overallFailLabel?: string,
|};
*/
const defaultOptions = {
taskPassLabel: "PASS",
taskFailLabel: "FAIL",
taskLaunchLabel: " GO ",
overallPassLabel: "SUCCESS",
overallFailLabel: "FAILURE",
};
exports.default = async function execDependencyGraph(
tasks /*: $ReadOnlyArray<Task> */
tasks /*: $ReadOnlyArray<Task> */,
options /*:: ?: RunOptions */
) /*: Promise<OverallResult> */ {
const fullOptions = {...defaultOptions, ...(options || {})};
const tasksById /*: {[TaskId]: Task} */ = {};
tasks.forEach((task) => {
if (tasksById[task.id] !== undefined) {
@ -43,6 +65,10 @@ exports.default = async function execDependencyGraph(
const tasksInProgress /*: Map<TaskId, Promise<TaskResult>> */ = new Map();
const remainingTasks /*: Set<TaskId> */ = new Set(Object.keys(tasksById));
function spacedLabel(rawLabel /*: string */) /*: string */ {
return ` ${rawLabel} `;
}
function spawnTasksWhoseDependenciesHaveCompleted() {
for (const task of tasks) {
if (!remainingTasks.has(task.id)) {
@ -53,7 +79,11 @@ exports.default = async function execDependencyGraph(
}
// Ready to spawn!
remainingTasks.delete(task.id);
console.log(chalk.bgBlue.bold.white(" GO ") + " " + task.id);
console.log(
chalk.bgBlue.bold.white(spacedLabel(fullOptions.taskLaunchLabel)) +
" " +
task.id
);
tasksInProgress.set(task.id, processTask(task));
}
}
@ -84,8 +114,8 @@ exports.default = async function execDependencyGraph(
) {
const success = result && result.success;
const badge = success
? chalk.bgGreen.bold.white(" PASS ")
: chalk.bgRed.bold.white(" FAIL ");
? chalk.bgGreen.bold.white(spacedLabel(fullOptions.taskPassLabel))
: chalk.bgRed.bold.white(spacedLabel(fullOptions.taskFailLabel));
console.log(`${badge} ${id}`);
if (mode === "OVERVIEW" && success) {
@ -168,8 +198,8 @@ exports.default = async function execDependencyGraph(
}
const overallSuccess /*: boolean */ = failedTasks.length === 0;
const overallBadge = overallSuccess
? chalk.bgGreen.bold.white(" SUCCESS ")
: chalk.bgRed.bold.white(" FAILURE ");
? chalk.bgGreen.bold.white(spacedLabel(fullOptions.overallPassLabel))
: chalk.bgRed.bold.white(spacedLabel(fullOptions.overallFailLabel));
console.log("Final result: " + overallBadge);
return Promise.resolve({success: overallSuccess});
};