diff options
| author | JeromeJu <[email protected]> | 2025-07-31 18:14:22 -0400 |
|---|---|---|
| committer | GitHub <[email protected]> | 2025-07-31 22:14:22 +0000 |
| commit | 574015edd91a651b0a4770e595be7ff10d67e5ab (patch) | |
| tree | 8283bdc1e4f37ae3b034234752b7b51ca62f20f5 /packages/cli/src/ui/commands/setupGithubCommand.ts | |
| parent | f9a05401c1d2d93d1251d3ebf2c079ee1f4ba8df (diff) | |
feat: Implement /setup-github command (#5069)
Diffstat (limited to 'packages/cli/src/ui/commands/setupGithubCommand.ts')
| -rw-r--r-- | packages/cli/src/ui/commands/setupGithubCommand.ts | 60 |
1 files changed, 60 insertions, 0 deletions
diff --git a/packages/cli/src/ui/commands/setupGithubCommand.ts b/packages/cli/src/ui/commands/setupGithubCommand.ts new file mode 100644 index 00000000..14314423 --- /dev/null +++ b/packages/cli/src/ui/commands/setupGithubCommand.ts @@ -0,0 +1,60 @@ +/** + * @license + * Copyright 2025 Google LLC + * SPDX-License-Identifier: Apache-2.0 + */ + +import path from 'path'; +import { execSync } from 'child_process'; +import { isGitHubRepository } from '../../utils/gitUtils.js'; + +import { + CommandKind, + SlashCommand, + SlashCommandActionReturn, +} from './types.js'; + +export const setupGithubCommand: SlashCommand = { + name: 'setup-github', + description: 'Set up GitHub Actions', + kind: CommandKind.BUILT_IN, + action: (): SlashCommandActionReturn => { + const gitRootRepo = execSync('git rev-parse --show-toplevel', { + encoding: 'utf-8', + }).trim(); + + if (!isGitHubRepository()) { + throw new Error('Unable to determine the Git root directory.'); + } + + // TODO(#5198): pin workflow versions for release controls + const version = 'main'; + const workflowBaseUrl = `https://raw.githubusercontent.com/google-github-actions/run-gemini-cli/refs/heads/${version}/workflows/`; + + const workflows = [ + 'gemini-cli/gemini-cli.yml', + 'issue-triage/gemini-issue-automated-triage.yml', + 'issue-triage/gemini-issue-scheduled-triage.yml', + 'pr-review/gemini-pr-review.yml', + ]; + + const command = [ + 'set -e', + `mkdir -p "${gitRootRepo}/.github/workflows"`, + ...workflows.map((workflow) => { + const fileName = path.basename(workflow); + return `curl -fsSL -o "${gitRootRepo}/.github/workflows/${fileName}" "${workflowBaseUrl}/${workflow}"`; + }), + 'echo "Workflows downloaded successfully."', + ].join(' && '); + return { + type: 'tool', + toolName: 'run_shell_command', + toolArgs: { + description: + 'Setting up GitHub Actions to triage issues and review PRs with Gemini.', + command, + }, + }; + }, +}; |
