mirror of
https://git.vectorsigma.ru/public/atlantis.git
synced 2026-08-01 14:48:46 +00:00
Automerging merges pull requests automatically if all plans have been successfully applied. * Save status of PR's to BoltDB so after each apply, we can check if there are pending plans. * Add new feature where we delete successful plans *unless* all plans have succeeded *if* automerge is enabled. This was requested by users because when automerge is enabled, they want to enforce that a pull request's changes have been fully applied. They asked that plans not be allowed to be applied "piecemeal" and instead, all plans must be generated successfully prior to allowing any plans to be applied.
44 lines
1.2 KiB
Go
44 lines
1.2 KiB
Go
// Package common is used to share common code between all VCS clients without
|
|
// running into circular dependency issues.
|
|
package common
|
|
|
|
import (
|
|
"math"
|
|
)
|
|
|
|
// AutomergeCommitMsg is the commit message Atlantis will use when automatically
|
|
// merging pull requests.
|
|
const AutomergeCommitMsg = "[Atlantis] Automatically merging after successful apply"
|
|
|
|
// SplitComment splits comment into a slice of comments that are under maxSize.
|
|
// It appends sepEnd to all comments that have a following comment.
|
|
// It prepends sepStart to all comments that have a preceding comment.
|
|
func SplitComment(comment string, maxSize int, sepEnd string, sepStart string) []string {
|
|
if len(comment) <= maxSize {
|
|
return []string{comment}
|
|
}
|
|
|
|
maxWithSep := maxSize - len(sepEnd) - len(sepStart)
|
|
var comments []string
|
|
numComments := int(math.Ceil(float64(len(comment)) / float64(maxWithSep)))
|
|
for i := 0; i < numComments; i++ {
|
|
upTo := min(len(comment), (i+1)*maxWithSep)
|
|
portion := comment[i*maxWithSep : upTo]
|
|
if i < numComments-1 {
|
|
portion += sepEnd
|
|
}
|
|
if i > 0 {
|
|
portion = sepStart + portion
|
|
}
|
|
comments = append(comments, portion)
|
|
}
|
|
return comments
|
|
}
|
|
|
|
func min(a, b int) int {
|
|
if a < b {
|
|
return a
|
|
}
|
|
return b
|
|
}
|