-
Notifications
You must be signed in to change notification settings - Fork 267
Add Exercism plugin #404
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
dethancosta
wants to merge
7
commits into
1Password:main
Choose a base branch
from
dethancosta:exercism
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Add Exercism plugin #404
Changes from all commits
Commits
Show all changes
7 commits
Select commit
Hold shift + click to select a range
005b2b1
Add Exercism plugin
dethancosta 917fdfe
run go fmt
dethancosta bda4e18
fixing token schema and test
scottisloud fdf82fa
updating outdated baseURL
scottisloud 7a049d6
adding additional commands to auth exclusion
scottisloud 92ff1e5
fixing example key in importer
scottisloud 716477e
fixing example key
scottisloud File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or 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,95 @@ | ||
| package exercism | ||
|
|
||
| import ( | ||
| "context" | ||
| "encoding/json" | ||
|
|
||
| "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 APIKey() schema.CredentialType { | ||
| return schema.CredentialType{ | ||
| Name: credname.APIKey, | ||
| DocsURL: sdk.URL("https://exercism.org/docs/using/solving-exercises/working-locally"), | ||
| ManagementURL: sdk.URL("https://exercism.org/settings/api_cli"), | ||
| Fields: []schema.CredentialField{ | ||
| { | ||
| Name: fieldname.URL, | ||
| MarkdownDescription: `The URL of the Exercism API.`, | ||
| Secret: false, | ||
| }, | ||
| { | ||
| Name: fieldname.APIKey, | ||
| MarkdownDescription: "API Key used to authenticate to Exercism.", | ||
| Secret: true, | ||
| Composition: &schema.ValueComposition{ | ||
| Length: 36, | ||
| Charset: schema.Charset{ | ||
| Lowercase: true, | ||
| Digits: true, | ||
| Specific: []rune{'-'}, | ||
| }, | ||
| }, | ||
| }, | ||
| { | ||
| Name: sdk.FieldName("Directory"), | ||
| MarkdownDescription: `The path to the workspace directory where the exercises are stored.`, | ||
| Secret: false, | ||
| }, | ||
| }, | ||
| DefaultProvisioner: provision.TempFile( | ||
| tempFileConfig, | ||
| provision.AtFixedPath("~/.config/exercism/user.json"), | ||
| ), | ||
| Importer: importer.TryAll( | ||
| TryExercismConfigFile(), | ||
| )} | ||
| } | ||
|
|
||
| func TryExercismConfigFile() sdk.Importer { | ||
| return importer.TryFile("~/.config/exercism/user.json", func(ctx context.Context, contents importer.FileContents, in sdk.ImportInput, out *sdk.ImportAttempt) { | ||
| var config Config | ||
| if err := contents.ToJSON(&config); err != nil { | ||
| out.AddError(err) | ||
| return | ||
| } | ||
|
|
||
| if config.URL == "" || config.APIKey == "" || config.Workspace == "" { | ||
| return | ||
| } | ||
|
|
||
| out.AddCandidate(sdk.ImportCandidate{ | ||
| Fields: map[sdk.FieldName]string{ | ||
| fieldname.APIKey: config.APIKey, | ||
| fieldname.URL: config.URL, | ||
| sdk.FieldName("Directory"): config.Workspace, | ||
| }, | ||
| }) | ||
| }) | ||
| } | ||
|
|
||
| type Config struct { | ||
| URL string `json:"apibaseurl"` | ||
| APIKey string `json:"token"` | ||
| Workspace string `json:"workspace"` | ||
| } | ||
|
|
||
| func tempFileConfig(in sdk.ProvisionInput) ([]byte, error) { | ||
| config := Config{ | ||
| URL: in.ItemFields[fieldname.URL], | ||
| APIKey: in.ItemFields[fieldname.APIKey], | ||
| Workspace: in.ItemFields[sdk.FieldName("Directory")], | ||
| } | ||
|
|
||
| contents, err := json.Marshal(&config) | ||
| if err != nil { | ||
| return nil, err | ||
| } | ||
|
|
||
| return []byte(contents), nil | ||
| } | ||
This file contains hidden or 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,48 @@ | ||
| package exercism | ||
|
|
||
| import ( | ||
| "strings" | ||
| "testing" | ||
|
|
||
| "github.com/1Password/shell-plugins/sdk" | ||
| "github.com/1Password/shell-plugins/sdk/plugintest" | ||
| "github.com/1Password/shell-plugins/sdk/schema/fieldname" | ||
| ) | ||
|
|
||
| func TestAPIKeyProvisioner(t *testing.T) { | ||
| plugintest.TestProvisioner(t, APIKey().DefaultProvisioner, map[string]plugintest.ProvisionCase{ | ||
| "default": { | ||
| ItemFields: map[sdk.FieldName]string{ | ||
| fieldname.URL: "https://api.exercism.org/v1", | ||
| fieldname.APIKey: "1ge7a536-9d1c-4a26-9ww3-3d423example", | ||
| sdk.FieldName("Directory"): "/Users/username/exercism", | ||
| }, | ||
| ExpectedOutput: sdk.ProvisionOutput{ | ||
| Files: map[string]sdk.OutputFile{ | ||
| "~/.config/exercism/user.json": { | ||
| Contents: []byte(strings.Join(strings.Fields(plugintest.LoadFixture(t, "user.json")), "")), | ||
| }, | ||
| }, | ||
| }, | ||
| }, | ||
| }) | ||
| } | ||
|
|
||
| func TestAPIKeyImporter(t *testing.T) { | ||
| plugintest.TestImporter(t, APIKey().Importer, map[string]plugintest.ImportCase{ | ||
| "config file": { | ||
| Files: map[string]string{ | ||
| "~/.config/exercism/user.json": plugintest.LoadFixture(t, "user.json"), | ||
| }, | ||
| ExpectedCandidates: []sdk.ImportCandidate{ | ||
| { | ||
| Fields: map[sdk.FieldName]string{ | ||
| fieldname.URL: "https://api.exercism.org/v1", | ||
| fieldname.APIKey: "1ge7a536-9d1c-4a26-9ww3-3d423example", | ||
| sdk.FieldName("Directory"): "/Users/username/exercism", | ||
| }, | ||
| }, | ||
| }, | ||
| }, | ||
| }) | ||
| } |
This file contains hidden or 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,26 @@ | ||
| package exercism | ||
|
|
||
| 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 ExercismCLI() schema.Executable { | ||
| return schema.Executable{ | ||
| Name: "Exercism CLI", | ||
| Runs: []string{"exercism"}, | ||
| DocsURL: sdk.URL("https://exercism.org/docs/using/solving-exercises/working-locally"), | ||
| NeedsAuth: needsauth.IfAll( | ||
|
scottisloud marked this conversation as resolved.
|
||
| needsauth.NotForHelpOrVersion(), | ||
| needsauth.NotWithoutArgs(), | ||
| needsauth.NotForExactArgs("completion", "upgrade", "workspace", "troubleshoot"), | ||
| ), | ||
| Uses: []schema.CredentialUsage{ | ||
| { | ||
| Name: credname.APIKey, | ||
| }, | ||
| }, | ||
| } | ||
| } | ||
This file contains hidden or 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,22 @@ | ||
| package exercism | ||
|
|
||
| import ( | ||
| "github.com/1Password/shell-plugins/sdk" | ||
| "github.com/1Password/shell-plugins/sdk/schema" | ||
| ) | ||
|
|
||
| func New() schema.Plugin { | ||
| return schema.Plugin{ | ||
| Name: "exercism", | ||
| Platform: schema.PlatformInfo{ | ||
| Name: "Exercism", | ||
| Homepage: sdk.URL("https://exercism.org"), | ||
| }, | ||
| Credentials: []schema.CredentialType{ | ||
| APIKey(), | ||
| }, | ||
| Executables: []schema.Executable{ | ||
| ExercismCLI(), | ||
| }, | ||
| } | ||
| } |
This file contains hidden or 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,5 @@ | ||
| { | ||
| "apibaseurl":"https://api.exercism.org/v1", | ||
| "token":"1ge7a536-9d1c-4a26-9ww3-3d423example", | ||
| "workspace":"/Users/username/exercism" | ||
| } |
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.