-
Notifications
You must be signed in to change notification settings - Fork 29
feat: register custom code #1664
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
Draft
mfbx9da4
wants to merge
42
commits into
main
Choose a base branch
from
feat/register-custom-code
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.
Draft
Changes from all commits
Commits
Show all changes
42 commits
Select commit
Hold shift + click to select a range
49e33d6
add new register custom code command
idbentley 8df96f5
add commands for registercustomcode
idbentley 38fe3e5
pass sufficient context to support generation
idbentley f61a7d1
feat: implement register custom code functionality
2da7241
removed theirs
59f7396
implemented new workflow
cf13c9e
update registercustomcode to run generation in a manner more consiste…
idbentley e2eb25a
use object oriented interface to workflow file
idbentley 8d4aa57
remove pause command, and update generation so applying custom code i…
idbentley 59d93fd
don't fetch new build
idbentley dae01c8
added compilation and linting to registercustomcode
a3b2c27
iter
idbentley da30201
improved output
idbentley 484530b
back out commit upon fialure
idbentley 9382bcd
cleanup
idbentley 0a73cd8
disabled versioning
a583160
iter
idbentley 4b2be1a
remove unused resolve flag
idbentley be00abc
skip version
idbentley cc22172
introduce hash
idbentley 36bca50
support multi target workflows
idbentley 400b54e
fix command.go
idbentley af628fb
fix multi-build
idbentley b5bcaad
cleanup
idbentley db90d53
New conflict resolution flow
df3743a
fixes
a37fcaa
cleanup and prevent common issues
idbentley ccd4429
reintroduce accidental deletion
idbentley 6406863
Saving patches to .diff file instead of gen.lock
5177446
Integration test for perfect custom code scenario
ac8b44e
Fixed patch deletion when no custom code is found + integration tests…
5dd125c
test improvement
6180540
tests and added added git reset --hard HEAD after capturing patches b…
fa2fc1e
Catching conflict error from the generator
131c26c
tests
e907a2e
reverse strategy + multitarget tests
efeaeae
multitarget conflict resolution fix
bba77ba
use byprefix functions instead of bylinenumber
idbentley a57b83d
cleanup and tests passing
idbentley 24d0a3b
tests
idbentley 9f41acd
cleanup and fix tests
idbentley b639ee1
cleanup
idbentley 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,139 @@ | ||
| package cmd | ||
|
|
||
| import ( | ||
| "context" | ||
| "fmt" | ||
|
|
||
| "github.com/speakeasy-api/speakeasy/internal/charm/styles" | ||
| "github.com/speakeasy-api/speakeasy/internal/utils" | ||
| "github.com/speakeasy-api/speakeasy/internal/model" | ||
| "github.com/speakeasy-api/speakeasy/internal/model/flag" | ||
| "github.com/speakeasy-api/speakeasy/internal/registercustomcode" | ||
| "github.com/speakeasy-api/speakeasy/internal/log" | ||
| "github.com/speakeasy-api/speakeasy/internal/env" | ||
|
|
||
| "github.com/speakeasy-api/speakeasy/internal/run" | ||
| "go.uber.org/zap" | ||
| ) | ||
|
|
||
| type RegisterCustomCodeFlags struct { | ||
| Show bool `json:"show"` | ||
| Apply bool `json:"apply-only"` | ||
| ApplyReverse bool `json:"apply-reverse"` | ||
| InstallationURL string `json:"installationURL"` | ||
| InstallationURLs map[string]string `json:"installationURLs"` | ||
| Repo string `json:"repo"` | ||
| RepoSubdir string `json:"repo-subdir"` | ||
| RepoSubdirs map[string]string `json:"repo-subdirs"` | ||
| SkipVersioning bool `json:"skip-versioning"` | ||
| Output string `json:"output"` | ||
| SetVersion string `json:"set-version"` | ||
|
|
||
| } | ||
|
|
||
| var registerCustomCodeCmd = &model.ExecutableCommand[RegisterCustomCodeFlags]{ | ||
| Usage: "customcode", | ||
| Short: "Register custom code with the OpenAPI generation system.", | ||
| Long: `Register custom code with the OpenAPI generation system.`, | ||
| Run: registerCustomCode, | ||
| Flags: []flag.Flag{ | ||
| flag.BooleanFlag{ | ||
| Name: "show", | ||
| Shorthand: "s", | ||
| Description: "show custom code patches", | ||
| }, | ||
| flag.BooleanFlag{ | ||
| Name: "apply-only", | ||
| Shorthand: "a", | ||
| Description: "apply existing custom code patches without running generation", | ||
| }, | ||
| flag.EnumFlag{ | ||
| Name: "output", | ||
| Shorthand: "o", | ||
| Description: "What to output while running", | ||
| AllowedValues: []string{"summary", "mermaid", "console"}, | ||
| DefaultValue: "summary", | ||
| }, | ||
| }, | ||
| } | ||
|
|
||
| func registerCustomCode(ctx context.Context, flags RegisterCustomCodeFlags) error { | ||
| logger := log.From(ctx).With(zap.String("method", "RegisterCustomCode")) | ||
|
|
||
| // If --show flag is provided, show existing customcode | ||
| if flags.Show { | ||
| wf, _, err := utils.GetWorkflowAndDir() | ||
| if err != nil { | ||
| return fmt.Errorf("Could not find workflow file") | ||
| } | ||
| var allErrors []error | ||
| for targetName, target := range wf.Targets { | ||
| logger.Info("Showing target", zap.String("target_name", targetName)) | ||
| if err := registercustomcode.ShowCustomCodePatch(ctx, target); err != nil { | ||
| allErrors = append(allErrors, fmt.Errorf("target %s: %w", targetName, err)) | ||
| } | ||
| } | ||
| if len(allErrors) > 0 { | ||
| return fmt.Errorf("errors occurred: %v", allErrors) | ||
| } | ||
| return nil | ||
| } | ||
|
|
||
| // If --apply-only flag is provided, only apply existing patches | ||
| if flags.Apply { | ||
| wf, _, err := utils.GetWorkflowAndDir() | ||
| if err != nil { | ||
| return fmt.Errorf("Could not find workflow file") | ||
| } | ||
| for _, target := range wf.Targets { | ||
| registercustomcode.ApplyCustomCodePatch(ctx, target) | ||
| } | ||
| return nil | ||
| } | ||
|
|
||
| // Call the registercustomcode functionality | ||
| return registercustomcode.RegisterCustomCode(ctx, func(targetName string) error { | ||
| opts := []run.Opt{ | ||
| run.WithTarget(targetName), | ||
| run.WithRepo(flags.Repo), | ||
| run.WithRepoSubDirs(flags.RepoSubdirs), | ||
| run.WithInstallationURLs(flags.InstallationURLs), | ||
| run.WithSkipVersioning(true), | ||
| run.WithSkipApplyCustomCode(), | ||
| } | ||
| workflow, err := run.NewWorkflow( | ||
| ctx, | ||
| opts..., | ||
| ) | ||
| defer func() { | ||
| // we should leave temp directories for debugging if run fails | ||
| if env.IsGithubAction() { | ||
| workflow.Cleanup() | ||
| } | ||
| }() | ||
|
|
||
| switch flags.Output { | ||
| case "summary": | ||
| err = workflow.RunWithVisualization(ctx) | ||
| if err != nil { | ||
| return err | ||
| } | ||
| case "mermaid": | ||
| err = workflow.Run(ctx) | ||
| workflow.RootStep.Finalize(err == nil) | ||
| mermaid, err := workflow.RootStep.ToMermaidDiagram() | ||
| if err != nil { | ||
| return err | ||
| } | ||
| log.From(ctx).Println("\n" + styles.MakeSection("Mermaid diagram of workflow", mermaid, styles.Colors.Blue)) | ||
| case "console": | ||
| err = workflow.Run(ctx) | ||
| // workflow.RootStep.Finalize(err == nil) | ||
| if err != nil { | ||
| return err | ||
| } | ||
| } | ||
| return 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
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
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
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 |
|---|---|---|
|
|
@@ -6,6 +6,8 @@ replace github.com/pb33f/doctor => github.com/speakeasy-api/doctor v0.20.0-fixva | |
|
|
||
| replace github.com/pb33f/libopenapi => github.com/speakeasy-api/libopenapi v0.21.9-fixhiddencomps-fixed | ||
|
|
||
| replace github.com/speakeasy-api/openapi-generation/v2 => ../openapi-generation | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This should be removed before merging. |
||
|
|
||
| require ( | ||
| github.com/AlekSi/pointer v1.2.0 | ||
| github.com/KimMachineGun/automemlimit v0.7.1 | ||
|
|
||
Oops, something went wrong.
Oops, something went wrong.
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.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
this should be re-added before merging. Locally this raised an error for me.