diff --git a/plugins/qodana/plugin.go b/plugins/qodana/plugin.go new file mode 100644 index 00000000..7db0aadc --- /dev/null +++ b/plugins/qodana/plugin.go @@ -0,0 +1,22 @@ +package qodana + +import ( + "github.com/1Password/shell-plugins/sdk" + "github.com/1Password/shell-plugins/sdk/schema" +) + +func New() schema.Plugin { + return schema.Plugin{ + Name: "qodana", + Platform: schema.PlatformInfo{ + Name: "Qodana", + Homepage: sdk.URL("https://qodana.cloud"), + }, + Credentials: []schema.CredentialType{ + ProjectToken(), + }, + Executables: []schema.Executable{ + QodanaCLI(), + }, + } +} diff --git a/plugins/qodana/project_token.go b/plugins/qodana/project_token.go new file mode 100644 index 00000000..220d3b1c --- /dev/null +++ b/plugins/qodana/project_token.go @@ -0,0 +1,33 @@ +package qodana + +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 ProjectToken() schema.CredentialType { + return schema.CredentialType{ + Name: credname.APIToken, + DocsURL: sdk.URL("https://www.jetbrains.com/help/qodana/cloud-projects.html#cloud-manage-projects"), + ManagementURL: sdk.URL("https://qodana.cloud/"), + Fields: []schema.CredentialField{ + { + Name: fieldname.Token, + MarkdownDescription: "Project token used to authenticate to Qodana Cloud.", + Secret: true, + }, + }, + DefaultProvisioner: provision.EnvVars(defaultEnvVarMapping), + Importer: importer.TryAll( + importer.TryEnvVarPair(defaultEnvVarMapping), + ), + } +} + +var defaultEnvVarMapping = map[string]sdk.FieldName{ + "QODANA_TOKEN": fieldname.Token, +} diff --git a/plugins/qodana/project_token_test.go b/plugins/qodana/project_token_test.go new file mode 100644 index 00000000..62b2d463 --- /dev/null +++ b/plugins/qodana/project_token_test.go @@ -0,0 +1,41 @@ +package qodana + +import ( + "testing" + + "github.com/1Password/shell-plugins/sdk" + "github.com/1Password/shell-plugins/sdk/plugintest" + "github.com/1Password/shell-plugins/sdk/schema/fieldname" +) + +func TestProjectTokenImporter(t *testing.T) { + plugintest.TestImporter(t, ProjectToken().Importer, map[string]plugintest.ImportCase{ + "QODANA_TOKEN environment variable": { + Environment: map[string]string{ + "QODANA_TOKEN": "eyJhbGciOiJSUzI1NiIsInR5cCI6IkpXVCJ9.EXAMPLE", + }, + ExpectedCandidates: []sdk.ImportCandidate{ + { + Fields: map[sdk.FieldName]string{ + fieldname.Token: "eyJhbGciOiJSUzI1NiIsInR5cCI6IkpXVCJ9.EXAMPLE", + }, + }, + }, + }, + }) +} + +func TestProjectTokenProvisioner(t *testing.T) { + plugintest.TestProvisioner(t, ProjectToken().DefaultProvisioner, map[string]plugintest.ProvisionCase{ + "default": { + ItemFields: map[sdk.FieldName]string{ + fieldname.Token: "eyJhbGciOiJSUzI1NiIsInR5cCI6IkpXVCJ9.EXAMPLE", + }, + ExpectedOutput: sdk.ProvisionOutput{ + Environment: map[string]string{ + "QODANA_TOKEN": "eyJhbGciOiJSUzI1NiIsInR5cCI6IkpXVCJ9.EXAMPLE", + }, + }, + }, + }) +} diff --git a/plugins/qodana/qodana.go b/plugins/qodana/qodana.go new file mode 100644 index 00000000..68cf9859 --- /dev/null +++ b/plugins/qodana/qodana.go @@ -0,0 +1,28 @@ +package qodana + +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 QodanaCLI() schema.Executable { + return schema.Executable{ + Name: "Qodana CLI", + Runs: []string{"qodana"}, + DocsURL: sdk.URL("https://www.jetbrains.com/help/qodana/quick-start.html#quickstart-prerequisites-qodana-cli"), + NeedsAuth: needsauth.IfAll( + needsauth.NotForHelpOrVersion(), + needsauth.NotWhenContainsArgs("cloc"), + needsauth.NotWhenContainsArgs("completion"), + needsauth.NotWhenContainsArgs("contributors"), + needsauth.NotWhenContainsArgs("pull"), + needsauth.NotWhenContainsArgs("show"), + needsauth.NotWhenContainsArgs("view"), + ), + Uses: []schema.CredentialUsage{ + {Name: credname.APIToken}, + }, + } +}