exec method
Run command.
The contents of katana.yaml
and the arguments of the command are passed to context
.
コマンドを実行します。
context
にkatana.yaml
の内容やコマンドの引数が渡されます。
Implementation
@override
Future<void> exec(ExecContext context) async {
final bin = context.yaml.getAsMap("bin");
final gh = bin.get("gh", "gh");
final github = context.yaml.getAsMap("github");
final review = github.getAsMap("review");
final openAPIKey = review.get("openai_api_key", "");
if (openAPIKey.isEmpty) {
error(
"There is no [github]->[review]->[openai_api_key], please get OpenAI API key from [https://platform.openai.com/settings/profile?tab=api-keys].",
);
return;
}
await command(
"Set OpenAIApiKey in `secrets.OPENAI_API_KEY`.",
[
gh,
"secret",
"set",
"OPENAI_API_KEY",
"--body",
openAPIKey,
],
);
label("Create review.yaml");
final gitDir = await findGitDirectory(Directory.current);
final workingPath = Directory.current.difference(gitDir);
await const GitReviewCliCode().generateFile(
"${workingPath.isEmpty ? "." : workingPath}/.github/workflows/review.yaml",
);
}