-
Notifications
You must be signed in to change notification settings - Fork 14
feat: CP-1037 New MCP tool to create revision from dependency list #3706
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
Merged
Merged
Changes from all commits
Commits
Show all changes
4 commits
Select commit
Hold shift + click to select a range
07367b2
feat: CP-1037 New MCP tool to create revision from dependency list
samueld-activator 7630e2b
Add create ingredient version revision runner
samueld-activator 1fdbd19
Wrap errors appropriately and move CreateNewIngredientVersionRevision…
samueld-activator 7b88f5b
Error when option set is of unknown type during ingredient revision c…
samueld-activator 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
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 |
---|---|---|
@@ -0,0 +1,70 @@ | ||
package createrevision | ||
|
||
import ( | ||
"encoding/json" | ||
|
||
"github.com/ActiveState/cli/internal/errs" | ||
"github.com/ActiveState/cli/internal/output" | ||
"github.com/ActiveState/cli/internal/primer" | ||
"github.com/ActiveState/cli/pkg/platform/api/inventory/inventory_models" | ||
"github.com/ActiveState/cli/pkg/platform/authentication" | ||
"github.com/ActiveState/cli/pkg/platform/model" | ||
) | ||
|
||
type CreateRevisionRunner struct { | ||
auth *authentication.Auth | ||
output output.Outputer | ||
} | ||
|
||
func New(p *primer.Values) *CreateRevisionRunner { | ||
return &CreateRevisionRunner{ | ||
auth: p.Auth(), | ||
output: p.Output(), | ||
} | ||
} | ||
|
||
type Params struct { | ||
namespace string | ||
name string | ||
version string | ||
dependencies string | ||
comment string | ||
} | ||
|
||
func NewParams(namespace string, name string, version string, dependencies string, comment string) *Params { | ||
return &Params{ | ||
namespace: namespace, | ||
name: name, | ||
version: version, | ||
dependencies: dependencies, | ||
comment: comment, | ||
} | ||
} | ||
|
||
func (runner *CreateRevisionRunner) Run(params *Params) error { | ||
// Unmarshal JSON with the new dependency info | ||
var dependencies []inventory_models.Dependency | ||
err := json.Unmarshal([]byte(params.dependencies), &dependencies) | ||
if err != nil { | ||
return errs.Wrap(err, "error unmarshaling dependencies, dependency JSON is in wrong format") | ||
} | ||
|
||
// Retrieve ingredient version to access ingredient and version IDs | ||
ingredient, err := model.GetIngredientByNameAndVersion(params.namespace, params.name, params.version, nil, runner.auth) | ||
if err != nil { | ||
return errs.Wrap(err, "error fetching ingredient") | ||
} | ||
|
||
newRevision, err := model.CreateNewIngredientVersionRevision(ingredient, params.comment, dependencies, runner.auth) | ||
if err != nil { | ||
return errs.Wrap(err, "error creating ingredient version revision") | ||
} | ||
|
||
marshalledRevision, err := json.Marshal(newRevision) | ||
if err != nil { | ||
return errs.Wrap(err, "error marshalling revision response") | ||
} | ||
runner.output.Print(string(marshalledRevision)) | ||
|
||
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
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.
Suggest adding a default handler that errors out (eg. unrecognized type). Even if there are only 2, that should future proof us somewhat in the sense that if this change in the future it'll be immediately apparent that our code needs updating.
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.
Done!