Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 0 additions & 1 deletion models/issues/pull.go
Original file line number Diff line number Diff line change
Expand Up @@ -138,7 +138,6 @@ type PullRequest struct {
BaseRepoID int64 `xorm:"INDEX"`
BaseRepo *repo_model.Repository `xorm:"-"`
HeadBranch string
HeadCommitID string `xorm:"-"`
BaseBranch string
MergeBase string `xorm:"VARCHAR(64)"`
AllowMaintainerEdit bool `xorm:"NOT NULL DEFAULT false"`
Expand Down
1 change: 0 additions & 1 deletion routers/web/repo/issue_comment.go
Original file line number Diff line number Diff line change
Expand Up @@ -98,7 +98,6 @@ func NewComment(ctx *context.Context) {

// Regenerate patch and test conflict.
if pr == nil {
issue.PullRequest.HeadCommitID = ""
pull_service.StartPullRequestCheckImmediately(ctx, issue.PullRequest)
}

Expand Down
9 changes: 7 additions & 2 deletions routers/web/repo/pull_review.go
Original file line number Diff line number Diff line change
Expand Up @@ -318,7 +318,12 @@ func UpdateViewedFiles(ctx *context.Context) {

// Expect the review to have been now if no head commit was supplied
if data.HeadCommitSHA == "" {
data.HeadCommitSHA = pull.HeadCommitID
data.HeadCommitSHA, err = ctx.Repo.GitRepo.GetRefCommitID(pull.GetGitHeadRefName())
if err != nil {
log.Warn("Attempted to update a review but could not get head commit SHA: %v", err)
ctx.Resp.WriteHeader(http.StatusBadRequest)
return
}
}

updatedFiles := make(map[string]pull_model.ViewedState, len(data.Files))
Expand All @@ -332,7 +337,7 @@ func UpdateViewedFiles(ctx *context.Context) {
}

if err := pull_model.UpdateReviewState(ctx, ctx.Doer.ID, pull.ID, data.HeadCommitSHA, updatedFiles); err != nil {
ctx.ServerError("UpdateReview", err)
ctx.ServerError("UpdateReviewState", err)
}
}

Expand Down
4 changes: 3 additions & 1 deletion routers/web/repo/pull_review_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,9 @@ func TestRenderConversation(t *testing.T) {

var preparedComment *issues_model.Comment
run("prepare", func(t *testing.T, ctx *context.Context, resp *httptest.ResponseRecorder) {
comment, err := pull.CreateCodeComment(ctx, pr.Issue.Poster, ctx.Repo.GitRepo, pr.Issue, 1, "content", "", false, 0, pr.HeadCommitID, nil)
headCommitID, err := ctx.Repo.GitRepo.GetBranchCommitID(pr.HeadBranch)
assert.NoError(t, err)
comment, err := pull.CreateCodeComment(ctx, pr.Issue.Poster, ctx.Repo.GitRepo, pr.Issue, 1, "content", "", false, 0, headCommitID, nil)
require.NoError(t, err)

comment.Invalidated = true
Expand Down
64 changes: 29 additions & 35 deletions services/agit/agit.go
Original file line number Diff line number Diff line change
Expand Up @@ -143,21 +143,21 @@ func ProcReceive(ctx context.Context, repo *repo_model.Repository, gitRepo *git.
}

pr := &issues_model.PullRequest{
HeadRepoID: repo.ID,
BaseRepoID: repo.ID,
HeadBranch: headBranch,
HeadCommitID: opts.NewCommitIDs[i],
BaseBranch: baseBranchName,
HeadRepo: repo,
BaseRepo: repo,
MergeBase: "",
Type: issues_model.PullRequestGitea,
Flow: issues_model.PullRequestFlowAGit,
HeadRepoID: repo.ID,
BaseRepoID: repo.ID,
HeadBranch: headBranch,
BaseBranch: baseBranchName,
HeadRepo: repo,
BaseRepo: repo,
MergeBase: "",
Type: issues_model.PullRequestGitea,
Flow: issues_model.PullRequestFlowAGit,
}
prOpts := &pull_service.NewPullRequestOptions{
Repo: repo,
Issue: prIssue,
PullRequest: pr,
Repo: repo,
Issue: prIssue,
PullRequest: pr,
HeadCommitID: opts.NewCommitIDs[i],
}
if err := pull_service.NewPullRequest(ctx, prOpts); err != nil {
return nil, err
Expand Down Expand Up @@ -215,35 +215,29 @@ func ProcReceive(ctx context.Context, repo *repo_model.Repository, gitRepo *git.
}
}

// Store old commit ID for review staleness checking
oldHeadCommitID := pr.HeadCommitID

pr.HeadCommitID = opts.NewCommitIDs[i]
if err = pull_service.UpdateRef(ctx, pr); err != nil {
if err = pull_service.UpdateRef(ctx, pr, opts.NewCommitIDs[i]); err != nil {
return nil, fmt.Errorf("failed to update pull ref. Error: %w", err)
}

// Mark existing reviews as stale when PR content changes (same as regular GitHub flow)
if oldHeadCommitID != opts.NewCommitIDs[i] {
if err := issues_model.MarkReviewsAsStale(ctx, pr.IssueID); err != nil {
log.Error("MarkReviewsAsStale: %v", err)
}
if err := issues_model.MarkReviewsAsStale(ctx, pr.IssueID); err != nil {
log.Error("MarkReviewsAsStale: %v", err)
}

// Dismiss all approval reviews if protected branch rule item enabled
pb, err := git_model.GetFirstMatchProtectedBranchRule(ctx, pr.BaseRepoID, pr.BaseBranch)
if err != nil {
log.Error("GetFirstMatchProtectedBranchRule: %v", err)
}
if pb != nil && pb.DismissStaleApprovals {
if err := pull_service.DismissApprovalReviews(ctx, pusher, pr); err != nil {
log.Error("DismissApprovalReviews: %v", err)
}
// Dismiss all approval reviews if protected branch rule item enabled
pb, err := git_model.GetFirstMatchProtectedBranchRule(ctx, pr.BaseRepoID, pr.BaseBranch)
if err != nil {
log.Error("GetFirstMatchProtectedBranchRule: %v", err)
}
if pb != nil && pb.DismissStaleApprovals {
if err := pull_service.DismissApprovalReviews(ctx, pusher, pr); err != nil {
log.Error("DismissApprovalReviews: %v", err)
}
}

// Mark reviews for the new commit as not stale
if err := issues_model.MarkReviewsAsNotStale(ctx, pr.IssueID, opts.NewCommitIDs[i]); err != nil {
log.Error("MarkReviewsAsNotStale: %v", err)
}
// Mark reviews for the new commit as not stale
if err := issues_model.MarkReviewsAsNotStale(ctx, pr.IssueID, opts.NewCommitIDs[i]); err != nil {
log.Error("MarkReviewsAsNotStale: %v", err)
}

pull_service.StartPullRequestCheckImmediately(ctx, pr)
Expand Down
Loading
Loading