From def010f1c18c6530d2a490fea14d2b40f2bae7f6 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Edd=C3=BA=20Mel=C3=A9ndez?= Date: Thu, 28 May 2026 22:11:47 -0600 Subject: [PATCH] Add GitHub Copilot CLI shell plugin MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: EddĂș MelĂ©ndez --- plugins/copilot/auth_token.go | 31 ++++++++++++++++++ plugins/copilot/auth_token_test.go | 50 ++++++++++++++++++++++++++++++ plugins/copilot/copilot.go | 22 +++++++++++++ plugins/copilot/plugin.go | 22 +++++++++++++ 4 files changed, 125 insertions(+) create mode 100644 plugins/copilot/auth_token.go create mode 100644 plugins/copilot/auth_token_test.go create mode 100644 plugins/copilot/copilot.go create mode 100644 plugins/copilot/plugin.go diff --git a/plugins/copilot/auth_token.go b/plugins/copilot/auth_token.go new file mode 100644 index 00000000..740345df --- /dev/null +++ b/plugins/copilot/auth_token.go @@ -0,0 +1,31 @@ +package copilot + +import ( + "github.com/1Password/shell-plugins/sdk" + "github.com/1Password/shell-plugins/sdk/importer" + "github.com/1Password/shell-plugins/sdk/provision" + "github.com/1Password/shell-plugins/sdk/schema" + "github.com/1Password/shell-plugins/sdk/schema/credname" + "github.com/1Password/shell-plugins/sdk/schema/fieldname" +) + +func AuthToken() schema.CredentialType { + return schema.CredentialType{ + Name: credname.AuthToken, + DocsURL: sdk.URL("https://docs.github.com/en/copilot/how-tos/copilot-cli/set-up-copilot-cli/authenticate-copilot-cli"), + ManagementURL: sdk.URL("https://github.com/settings/personal-access-tokens/new"), + Fields: []schema.CredentialField{ + { + Name: fieldname.Token, + MarkdownDescription: "Token used to authenticate to GitHub Copilot.", + Secret: true, + }, + }, + DefaultProvisioner: provision.EnvVars(defaultEnvVarMapping), + Importer: importer.TryEnvVarPair(defaultEnvVarMapping), + } +} + +var defaultEnvVarMapping = map[string]sdk.FieldName{ + "COPILOT_GITHUB_TOKEN": fieldname.Token, +} diff --git a/plugins/copilot/auth_token_test.go b/plugins/copilot/auth_token_test.go new file mode 100644 index 00000000..0afb75fe --- /dev/null +++ b/plugins/copilot/auth_token_test.go @@ -0,0 +1,50 @@ +package copilot + +import ( + "testing" + + "github.com/1Password/shell-plugins/sdk" + "github.com/1Password/shell-plugins/sdk/plugintest" + "github.com/1Password/shell-plugins/sdk/schema/fieldname" +) + +const exampleCopilotToken = "github_pat_OYXGsaLFxgNy9msXs44LFNzg3wh0VsXRGycViVc0iKPOqczc1QKlB3ZVVrm5ESukqKR8nE3jzPBEXAMPLE" + +func TestAuthTokenProvisioner(t *testing.T) { + plugintest.TestProvisioner(t, AuthToken().DefaultProvisioner, map[string]plugintest.ProvisionCase{ + "default": { + ItemFields: map[sdk.FieldName]string{ + fieldname.Token: exampleCopilotToken, + }, + ExpectedOutput: sdk.ProvisionOutput{ + Environment: map[string]string{ + "COPILOT_GITHUB_TOKEN": exampleCopilotToken, + }, + }, + }, + }) +} + +func TestAuthTokenImporter(t *testing.T) { + plugintest.TestImporter(t, AuthToken().Importer, map[string]plugintest.ImportCase{ + "COPILOT_GITHUB_TOKEN": { + Environment: map[string]string{ + "COPILOT_GITHUB_TOKEN": exampleCopilotToken, + }, + ExpectedCandidates: []sdk.ImportCandidate{ + { + Fields: map[sdk.FieldName]string{ + fieldname.Token: exampleCopilotToken, + }, + }, + }, + }, + "GITHUB_TOKEN ignored": { + Environment: map[string]string{ + "COPILOT_GITHUB_TOKEN": "", + "GITHUB_TOKEN": exampleCopilotToken, + }, + ExpectedCandidates: []sdk.ImportCandidate{}, + }, + }) +} diff --git a/plugins/copilot/copilot.go b/plugins/copilot/copilot.go new file mode 100644 index 00000000..07d13fe6 --- /dev/null +++ b/plugins/copilot/copilot.go @@ -0,0 +1,22 @@ +package copilot + +import ( + "github.com/1Password/shell-plugins/sdk" + "github.com/1Password/shell-plugins/sdk/needsauth" + "github.com/1Password/shell-plugins/sdk/schema" + "github.com/1Password/shell-plugins/sdk/schema/credname" +) + +func CopilotCLI() schema.Executable { + return schema.Executable{ + Name: "GitHub Copilot CLI", + Runs: []string{"copilot"}, + DocsURL: sdk.URL("https://docs.github.com/en/copilot/reference/copilot-cli-reference/cli-command-reference"), + NeedsAuth: needsauth.NotForHelpOrVersion(), + Uses: []schema.CredentialUsage{ + { + Name: credname.AuthToken, + }, + }, + } +} diff --git a/plugins/copilot/plugin.go b/plugins/copilot/plugin.go new file mode 100644 index 00000000..0d8bc28f --- /dev/null +++ b/plugins/copilot/plugin.go @@ -0,0 +1,22 @@ +package copilot + +import ( + "github.com/1Password/shell-plugins/sdk" + "github.com/1Password/shell-plugins/sdk/schema" +) + +func New() schema.Plugin { + return schema.Plugin{ + Name: "copilot", + Platform: schema.PlatformInfo{ + Name: "GitHub Copilot", + Homepage: sdk.URL("https://github.com/features/copilot/cli"), + }, + Credentials: []schema.CredentialType{ + AuthToken(), + }, + Executables: []schema.Executable{ + CopilotCLI(), + }, + } +}