Skip to content

Commit

Permalink
Include local history when checking if a commit exists in a project.
Browse files Browse the repository at this point in the history
  • Loading branch information
mitchell-as committed Jul 31, 2024
1 parent 03c5e90 commit f4695e5
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 2 deletions.
6 changes: 5 additions & 1 deletion internal/runbits/buildplanner/buildplanner.go
Original file line number Diff line number Diff line change
Expand Up @@ -143,7 +143,11 @@ func GetCommit(
name = pj.Name()
nsString = pj.NamespaceString()
}
_, err = model.GetCommitWithinProjectHistory(commit.CommitID, owner, name, auth)
localCommitID, err := localcommit.Get(pj.Path())
if err != nil {
return nil, errs.Wrap(err, "Could not get local commit")
}
_, err = model.GetCommitWithinProjectHistory(commit.CommitID, owner, name, localCommitID, auth)
if err != nil {
if err == model.ErrCommitNotInHistory {
return nil, errs.Pack(err, &ErrCommitDoesNotExistInProject{nsString, commit.CommitID.String()})
Expand Down
8 changes: 7 additions & 1 deletion pkg/platform/model/vcs.go
Original file line number Diff line number Diff line change
Expand Up @@ -888,12 +888,18 @@ func GetCommitWithinCommitHistory(currentCommitID, targetCommitID strfmt.UUID, a
// This function exists primarily as an existence check because the buildplanner API currently
// accepts a query for a org/project#commitID even if commitID does not belong to org/project.
// See DS-1705 (yes, DS, not DX).
func GetCommitWithinProjectHistory(commitID strfmt.UUID, owner, name string, auth *authentication.Auth) (*mono_models.Commit, error) {
func GetCommitWithinProjectHistory(commitID strfmt.UUID, owner, name string, localCommitID strfmt.UUID, auth *authentication.Auth) (*mono_models.Commit, error) {
commit, err := GetCommit(commitID, auth)
if err != nil {
return nil, errs.Wrap(err, "Unable to get commit")
}

if ok, err := CommitWithinCommitHistory(localCommitID, commitID, auth); err == nil && ok {
return commit, nil
} else if err != nil {
return nil, errs.Wrap(err, "Unable to determine if commit exists in local history")
}

branches, err := BranchesForProject(owner, name)
if err != nil {
return nil, errs.Wrap(err, "Unable to get branches for project")
Expand Down

0 comments on commit f4695e5

Please sign in to comment.