mirror of
https://github.com/go-gitea/gitea.git
synced 2026-09-30 21:04:55 +00:00
fix: PR merge (#39442)
* Revert the behavior introduced by #30805 * Now the PR status is still managed in Gitea's code where the operation is triggerred but not in post-receive hook * Fix #39254 and many more related bugs. * Fix #39124 ``` // MarkAsMerged sets a pull request to merged and closes the corresponding issue // To make sure the pull request is marked as merged correctly, the caller uses multiple-stage operations: // 1. Create a temp repo from base, merge the head into the temp repo, and get the merged commit ID and timestamp, // 2. The merged commit ID and related information are stored into pull request // 3. Push the merged commit to the base repo // 4. Call MarkAsMerged to mark the pull request as merged and do post-processing (notification, close issues, etc) // // If failure occurs in step 1/2/3: the pull request is still open, the base repo is not changed, the doer can start a new merge. // If failure occurs in step 4: the pull request can be marked as merged by the merged commit ID stored in it later. ```
This commit is contained in:
@@ -216,16 +216,10 @@ func (pr *PullRequest) OptionalHeadUserName(ctx context.Context) string {
|
||||
// LoadAttributes loads pull request attributes from database
|
||||
// Note: don't try to get Issue because will end up recursive querying.
|
||||
func (pr *PullRequest) LoadAttributes(ctx context.Context) (err error) {
|
||||
if pr.HasMerged && pr.Merger == nil {
|
||||
pr.Merger, err = user_model.GetUserByID(ctx, pr.MergerID)
|
||||
if user_model.IsErrUserNotExist(err) {
|
||||
pr.MergerID = user_model.GhostUserID
|
||||
pr.Merger = user_model.NewGhostUser()
|
||||
} else if err != nil {
|
||||
return fmt.Errorf("getUserByID [%d]: %w", pr.MergerID, err)
|
||||
}
|
||||
if pr.Merger == nil && pr.MergerID != 0 {
|
||||
pr.MergerID, pr.Merger, err = user_model.GetPossibleUserByID(ctx, pr.MergerID)
|
||||
return err
|
||||
}
|
||||
|
||||
return nil
|
||||
}
|
||||
|
||||
|
||||
@@ -166,6 +166,14 @@ func GetPullRequestIDsByCheckStatus(ctx context.Context, status PullRequestStatu
|
||||
Find(&prs)
|
||||
}
|
||||
|
||||
func GetInterruptedPullRequestIDs(ctx context.Context) ([]int64, error) {
|
||||
prs := make([]int64, 0, 10)
|
||||
return prs, db.GetEngine(ctx).Table("pull_request").
|
||||
Where("merged_commit_id <> '' AND has_merged = ? AND merged_unix >= ?", false, timeutil.TimeStampNow()-24*3600).
|
||||
Cols("pull_request.id").
|
||||
Find(&prs)
|
||||
}
|
||||
|
||||
// PullRequests returns all pull requests for a base Repo by the given conditions
|
||||
func PullRequests(ctx context.Context, baseRepoID int64, opts *PullRequestsOptions) (PullRequestList, int64, error) {
|
||||
if opts.Page <= 0 {
|
||||
|
||||
Reference in New Issue
Block a user