-
-
Notifications
You must be signed in to change notification settings - Fork 5.4k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Auto merge pull requests when all checks succeeded
Signed-off-by: kolaente <k@knt.li>
- Loading branch information
Showing
15 changed files
with
556 additions
and
96 deletions.
There are no files selected for viewing
This file contains 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 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,20 @@ | ||
// Copyright 2020 The Gitea Authors. All rights reserved. | ||
// Use of this source code is governed by a MIT-style | ||
// license that can be found in the LICENSE file. | ||
|
||
package migrations | ||
|
||
import "xorm.io/xorm" | ||
|
||
func addAutoMergeTable(x *xorm.Engine) error { | ||
type MergeStyle string | ||
type ScheduledPullRequestMerge struct { | ||
ID int64 `xorm:"pk autoincr"` | ||
PullID int64 `xorm:"BIGINT"` | ||
UserID int64 `xorm:"BIGINT"` | ||
MergeStyle MergeStyle `xorm:"varchar(50)"` | ||
Message string `xorm:"TEXT"` | ||
} | ||
|
||
return x.Sync2(&ScheduledPullRequestMerge{}) | ||
} |
This file contains 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 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,55 @@ | ||
// Copyright 2019 Gitea. All rights reserved. | ||
// Use of this source code is governed by a MIT-style | ||
// license that can be found in the LICENSE file. | ||
|
||
package models | ||
|
||
import "code.gitea.io/gitea/modules/timeutil" | ||
|
||
// ScheduledPullRequestMerge represents a pull request scheduled for merging when checks succeed | ||
type ScheduledPullRequestMerge struct { | ||
ID int64 `xorm:"pk autoincr"` | ||
PullID int64 `xorm:"BIGINT"` | ||
UserID int64 `xorm:"BIGINT"` | ||
User *User `xorm:"-"` | ||
MergeStyle MergeStyle `xorm:"varchar(50)"` | ||
Message string `xorm:"TEXT"` | ||
CreatedUnix timeutil.TimeStamp `xorm:"created"` | ||
} | ||
|
||
// ScheduleAutoMerge schedules a pull request to be merged when all checks succeed | ||
func ScheduleAutoMerge(opts *ScheduledPullRequestMerge) (err error) { | ||
// Check if we already have a merge scheduled for that pull request | ||
exists, err := x.Exist(&ScheduledPullRequestMerge{PullID: opts.PullID}) | ||
if err != nil { | ||
return | ||
} | ||
if exists { | ||
// Maybe FIXME: Should we return a custom error here? | ||
return nil | ||
} | ||
|
||
_, err = x.Insert(opts) | ||
return err | ||
} | ||
|
||
// GetScheduledMergeRequestByPullID gets a scheduled pull request merge by pull request id | ||
func GetScheduledMergeRequestByPullID(pullID int64) (exists bool, scheduledPRM *ScheduledPullRequestMerge, err error) { | ||
scheduledPRM = &ScheduledPullRequestMerge{} | ||
exists, err = x.Where("pull_id = ?", pullID).Get(scheduledPRM) | ||
if err != nil || !exists { | ||
return | ||
} | ||
scheduledPRM.User, err = getUserByID(x, scheduledPRM.UserID) | ||
return | ||
} | ||
|
||
// RemoveScheduledMergeRequest cancels a previously scheduled pull request | ||
func RemoveScheduledMergeRequest(scheduledPR *ScheduledPullRequestMerge) (err error) { | ||
if scheduledPR.ID == 0 && scheduledPR.PullID != 0 { | ||
_, err = x.Where("pull_id = ?", scheduledPR.PullID).Delete(&ScheduledPullRequestMerge{}) | ||
return | ||
} | ||
_, err = x.Where("id = ? AND pull_id = ?", scheduledPR.ID, scheduledPR.PullID).Delete(&ScheduledPullRequestMerge{}) | ||
return | ||
} |
This file contains 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 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 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 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 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 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 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
Oops, something went wrong.