Skip to content

Commit

Permalink
AttachStagedCommit should only return an error.
Browse files Browse the repository at this point in the history
Returning a commitID is superfluous because it's attaching an existing commit, not making a new one.
  • Loading branch information
mitchell-as committed Oct 26, 2023
1 parent 0688b1c commit 4801d29
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 17 deletions.
15 changes: 7 additions & 8 deletions internal/runners/push/push.go
Original file line number Diff line number Diff line change
Expand Up @@ -149,7 +149,6 @@ func (r *Push) Run(params PushParams) (rerr error) {
}

bp := model.NewBuildPlannerModel(r.auth)
var newCommitID strfmt.UUID // the commit to update localcommit with
var branch *mono_models.Branch // the branch to write to as.yaml if it changed

// Create remote project
Expand Down Expand Up @@ -180,7 +179,7 @@ func (r *Push) Run(params PushParams) (rerr error) {
if err != nil {
return errs.Wrap(err, "Could not get buildexpression")
}
newCommitID, err = bp.CreateProject(&model.CreateProjectParams{
commitID, err = bp.CreateProject(&model.CreateProjectParams{
Owner: targetNamespace.Owner,
Project: targetNamespace.Project,
Private: r.project.Private(),
Expand All @@ -191,6 +190,11 @@ func (r *Push) Run(params PushParams) (rerr error) {
return locale.WrapError(err, "err_push_create_project", "Could not create new project")
}

// Update the project's commitID with the create project or push result.
if err := localcommit.Set(r.project.Dir(), commitID.String()); err != nil {
return errs.Wrap(err, "Unable to create local commit file")
}

// Fetch the newly created project's default branch (for updating activestate.yaml with).
targetPjm, err = model.LegacyFetchProjectByName(targetNamespace.Owner, targetNamespace.Project)
if err != nil {
Expand Down Expand Up @@ -246,7 +250,7 @@ func (r *Push) Run(params PushParams) (rerr error) {
}

// Perform the push.
newCommitID, err = bp.AttachStagedCommit(&model.AttachStagedCommitParams{
err = bp.AttachStagedCommit(&model.AttachStagedCommitParams{
Owner: targetNamespace.Owner,
Project: targetNamespace.Project,
ParentCommitID: *branch.CommitID,
Expand All @@ -258,11 +262,6 @@ func (r *Push) Run(params PushParams) (rerr error) {
}
}

// Update the project's commitID with the create project or push result.
if err := localcommit.Set(r.project.Dir(), newCommitID.String()); err != nil {
return errs.Wrap(err, "Unable to create local commit file")
}

// Write the project namespace to the as.yaml, if it changed
if r.project.Owner() != targetNamespace.Owner || r.project.Name() != targetNamespace.Project {
if err := r.project.Source().SetNamespace(targetNamespace.Owner, targetNamespace.Project); err != nil {
Expand Down
14 changes: 5 additions & 9 deletions pkg/platform/model/buildplanner.go
Original file line number Diff line number Diff line change
Expand Up @@ -305,28 +305,24 @@ type AttachStagedCommitParams struct {
Branch string
}

func (bp *BuildPlanner) AttachStagedCommit(params *AttachStagedCommitParams) (strfmt.UUID, error) {
func (bp *BuildPlanner) AttachStagedCommit(params *AttachStagedCommitParams) error {
logging.Debug("AttachStagedCommit, owner: %s, project: %s", params.Owner, params.Project)
request := request.AttachStagedCommit(params.Owner, params.Project, params.ParentCommitID.String(), params.StagedCommitID.String(), params.Branch)
resp := &bpModel.AttachStagedCommitResult{}
err := bp.client.Run(request, resp)
if err != nil {
return "", processBuildPlannerError(err, "Failed to attach staged commit")
return processBuildPlannerError(err, "Failed to attach staged commit")
}

if resp.Commit == nil {
return "", errs.New("Attached, staged commit is nil")
return errs.New("Attached, staged commit is nil")
}

if bpModel.IsErrorResponse(resp.Commit.Type) {
return "", bpModel.ProcessCommitError(resp.Commit, "Could not process error response from attach stage commit")
return bpModel.ProcessCommitError(resp.Commit, "Could not process error response from attach stage commit")
}

if resp.Commit.CommitID == "" {
return "", errs.New("Attach, staged commit does not contain commitID")
}

return resp.Commit.CommitID, nil
return nil
}

func (bp *BuildPlanner) GetBuildExpression(owner, project, commitID string) (*buildexpression.BuildExpression, error) {
Expand Down

0 comments on commit 4801d29

Please sign in to comment.