-
Notifications
You must be signed in to change notification settings - Fork 14
feat: CP-1068 Create MCP tool to bump timestamp of a project #3713
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
3 commits
Select commit
Hold shift + click to select a range
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,90 @@ | ||
| package rebuildproject | ||
|
|
||
| import ( | ||
| "fmt" | ||
|
|
||
| "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/buildplanner/types" | ||
| "github.com/ActiveState/cli/pkg/platform/authentication" | ||
| "github.com/ActiveState/cli/pkg/platform/model" | ||
| "github.com/ActiveState/cli/pkg/platform/model/buildplanner" | ||
| bpModel "github.com/ActiveState/cli/pkg/platform/model/buildplanner" | ||
| "github.com/ActiveState/cli/pkg/project" | ||
| ) | ||
|
|
||
| type RebuildProjectRunner struct { | ||
| auth *authentication.Auth | ||
| output output.Outputer | ||
| svcModel *model.SvcModel | ||
| } | ||
|
|
||
| func New(p *primer.Values) *RebuildProjectRunner { | ||
| return &RebuildProjectRunner{ | ||
| auth: p.Auth(), | ||
| output: p.Output(), | ||
| svcModel: p.SvcModel(), | ||
| } | ||
| } | ||
|
|
||
| type Params struct { | ||
| Namespace *project.Namespaced | ||
| } | ||
|
|
||
| func NewParams() *Params { | ||
| return &Params{} | ||
| } | ||
|
|
||
| func (runner *RebuildProjectRunner) Run(params *Params) error { | ||
| branch, err := model.DefaultBranchForProjectName(params.Namespace.Owner, params.Namespace.Project) | ||
| if err != nil { | ||
| return fmt.Errorf("error fetching default branch: %w", err) | ||
| } | ||
|
|
||
| // Collect "before" buildscript | ||
| bpm := bpModel.NewBuildPlannerModel(runner.auth, runner.svcModel) | ||
| localCommit, err := bpm.FetchCommitNoPoll(*branch.CommitID, params.Namespace.Owner, params.Namespace.Project, nil) | ||
| if err != nil { | ||
| return errs.Wrap(err, "Failed to fetch build result") | ||
| } | ||
|
|
||
| // Collect "after" buildscript | ||
| bumpedBS, err := localCommit.BuildScript().Clone() | ||
| if err != nil { | ||
| return errs.Wrap(err, "Failed to clone build script") | ||
| } | ||
|
|
||
| latest, err := model.FetchLatestRevisionTimeStamp(runner.auth) | ||
| if err != nil { | ||
| return errs.Wrap(err, "Failed to fetch latest timestamp") | ||
| } | ||
| bumpedBS.SetAtTime(latest, true) | ||
|
|
||
| // Since our platform is commit based we need to create a commit for the "after" buildscript | ||
| bumpedCommit, err := bpm.StageCommitAndPoll(bpModel.StageCommitParams{ | ||
| Owner: params.Namespace.Owner, | ||
| Project: params.Namespace.Project, | ||
| ParentCommit: branch.CommitID.String(), | ||
| Script: bumpedBS, | ||
| }) | ||
| if err != nil { | ||
| return errs.Wrap(err, "Failed to stage bumped commit") | ||
| } | ||
|
|
||
| // Now, merge the new commit using the branch name to fast-forward | ||
| _, err = bpm.MergeCommit(&buildplanner.MergeCommitParams{ | ||
| Owner: params.Namespace.Owner, | ||
| Project: params.Namespace.Project, | ||
| TargetRef: branch.Label, | ||
| OtherRef: bumpedCommit.CommitID.String(), | ||
| Strategy: types.MergeCommitStrategyFastForward, | ||
| }) | ||
| if err != nil { | ||
| return fmt.Errorf("error merging commit: %w", err) | ||
| } | ||
|
|
||
| runner.output.Print("Project is now rebuilding with commit ID " + bumpedCommit.CommitID.String()) | ||
|
|
||
| return nil | ||
| } | ||
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.
When it does not solve, it errors here.
e.g.:
`Failed to stage bumped commit:
failed to poll build plan:
Request failed: Could not plan build. Platform responded with:
These are the last lines of the error message:
….2.36) requires Ingredient|language/python|fast-agent-mcp (0.2.36) which depends on Feature|language/python|opentelemetry-instrumentation-google-genai (>=0.2b0), Feature|language/python|fast-agent-mcp (0.2.36) requires Feature|language/python|opentelemetry-instrumentation-google-genai (>=0.2b0).