-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
10 changed files
with
163 additions
and
57 deletions.
There are no files selected for viewing
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
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
import { getCurrentsAPICommand } from "../../program"; | ||
|
||
export async function apiHandler( | ||
options: ReturnType<ReturnType<typeof getCurrentsAPICommand>["opts"]> | ||
) { | ||
console.log('api', { options }); | ||
} |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
import { getLastRunCommand } from "../../program"; | ||
|
||
export async function getLastRunHandler( | ||
options: ReturnType<ReturnType<typeof getLastRunCommand>["opts"]> | ||
) { | ||
console.log('get-last-run', { options }); | ||
} |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
export { uploadHandler } from "./upload"; | ||
export { apiHandler } from "./api/api"; | ||
export { getLastRunHandler } from "./api/get-last-run"; | ||
|
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,40 @@ | ||
import { CommanderError } from "@commander-js/extra-typings"; | ||
import { currentsReporter } from "../.."; | ||
import { getCurrentsConfig, setCurrentsConfig } from "../../config"; | ||
import { ValidationError } from "../../lib"; | ||
import { error, info, success } from "../../logger"; | ||
import { CLIManager } from "../cli-config"; | ||
import { getCurrentsUploadCommand } from "../program"; | ||
|
||
export async function uploadHandler( | ||
options: ReturnType<ReturnType<typeof getCurrentsUploadCommand>["opts"]> | ||
) { | ||
const cliManager = new CLIManager(options); | ||
setCurrentsConfig(cliManager.parsedConfig); | ||
const config = getCurrentsConfig(); | ||
|
||
info("Currents config: %o", { | ||
...config, | ||
recordKey: config?.recordKey ? "*****" : undefined, | ||
}); | ||
|
||
return currentsReporter() | ||
.then(() => { | ||
success("Script execution finished"); | ||
process.exit(0); | ||
}) | ||
.catch((e) => { | ||
if (e instanceof CommanderError) { | ||
error(e.message); | ||
process.exit(e.exitCode); | ||
} | ||
|
||
if (e instanceof ValidationError) { | ||
error(e.message); | ||
process.exit(1); | ||
} | ||
|
||
error("Script execution failed:", e); | ||
process.exit(1); | ||
}); | ||
} |
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
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
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,9 +1,11 @@ | ||
import { Command } from "@commander-js/extra-typings"; | ||
import chalk from "chalk"; | ||
|
||
import { reporterVersion } from "../env/versions"; | ||
import { dim } from "../logger"; | ||
import { apiHandler, getLastRunHandler, uploadHandler } from "./handlers"; | ||
import { | ||
apiKeyOption, | ||
branchOption, | ||
ciBuildIdOption, | ||
debugOption, | ||
disableTitleTagsOption, | ||
|
@@ -15,14 +17,12 @@ import { | |
tagOption, | ||
} from "./options"; | ||
|
||
type CurrentsReporterCommand = Partial< | ||
ReturnType<ReturnType<typeof getCurrentsReporterCommand>["opts"]> | ||
>; | ||
|
||
const NAME = "currents"; | ||
export const getProgram = ( | ||
command: Command<[], CurrentsReporterCommand> = getCurrentsReporterCommand() | ||
) => command.version(reporterVersion); | ||
export const getProgram = () => | ||
new Command(NAME) | ||
.version(reporterVersion) | ||
.addCommand(getCurrentsUploadCommand(), { isDefault: true }) | ||
.addCommand(getCurrentsAPICommand()); | ||
|
||
const currentsReporterExample = ` | ||
---------------------------------------------------- | ||
|
@@ -46,9 +46,9 @@ ${dim( | |
)} | ||
`; | ||
|
||
export const getCurrentsReporterCommand = () => { | ||
export const getCurrentsUploadCommand = () => { | ||
const command = new Command() | ||
.name(NAME) | ||
.name("upload") | ||
.command("upload") | ||
.showHelpAfterError("(add --help for additional information)") | ||
.allowUnknownOption() | ||
|
@@ -64,7 +64,51 @@ ${currentsReporterExample}` | |
.addOption(disableTitleTagsOption) | ||
.addOption(machineIdOption) | ||
.addOption(debugOption) | ||
.addOption(reportDirOption); | ||
.addOption(reportDirOption) | ||
.action((options) => uploadHandler(options)); | ||
|
||
return command; | ||
}; | ||
|
||
const currentsAPIExample = ` | ||
---------------------------------------------------- | ||
📖 Documentation: https://docs.currents.dev | ||
🤙 Support: [email protected] | ||
---------------------------------------------------- | ||
${chalk.bold("Examples")} | ||
Obtain last run data by --ci-build-id: | ||
${dim(`${NAME} api get-last-run --api-key <api-key> --ci-build-id --provider <provider>`)} | ||
Obtain last run data using filters: | ||
${dim(`${NAME} api get-last-run --api-key <api-key> --project-id <project-id> --branch <branch> --tag tagA --tag tagB`)} | ||
`; | ||
|
||
export const getLastRunCommand = () => { | ||
const command = new Command() | ||
.name("get-last-run") | ||
.allowUnknownOption() | ||
.addOption(ciBuildIdOption) | ||
.addOption(projectOption) | ||
.addOption(branchOption) | ||
.addOption(tagOption) | ||
.addOption(debugOption) | ||
.action(getLastRunHandler); | ||
|
||
return command; | ||
}; | ||
|
||
export const getCurrentsAPICommand = () => { | ||
const command = new Command() | ||
.command("api") | ||
.description(`Receive information from Currents API ${currentsAPIExample}`) | ||
.showHelpAfterError("(add --help for additional information)") | ||
.allowUnknownOption() | ||
.addCommand(getLastRunCommand()) | ||
.addOption(apiKeyOption) | ||
.addOption(debugOption) | ||
.action(apiHandler); | ||
|
||
return command; | ||
}; |
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
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