mirror of
https://git.vectorsigma.ru/public/atlantis.git
synced 2026-07-29 12:58:20 +00:00
* Moved CommandContext and CommandResult to models (#193) * Moved CommandContext and CommandResult to models * move from models to command rename CommandContext -> Context rename CommandResult -> Result * moved command related helpers into command package * move ProjectCommandContext and ProjectResult to command/project package * move project command context and project result * revert unrelated code * move tests * fix left over * fix linting * fix tests * remove unused import * fix project context dependencies * fix depenedecies * fix typo
51 lines
1.4 KiB
Go
51 lines
1.4 KiB
Go
package events
|
|
|
|
import (
|
|
"github.com/runatlantis/atlantis/server/events/command"
|
|
"github.com/runatlantis/atlantis/server/events/vcs"
|
|
)
|
|
|
|
func NewUnlockCommandRunner(
|
|
deleteLockCommand DeleteLockCommand,
|
|
vcsClient vcs.Client,
|
|
SilenceNoProjects bool,
|
|
) *UnlockCommandRunner {
|
|
return &UnlockCommandRunner{
|
|
deleteLockCommand: deleteLockCommand,
|
|
vcsClient: vcsClient,
|
|
SilenceNoProjects: SilenceNoProjects,
|
|
}
|
|
}
|
|
|
|
type UnlockCommandRunner struct {
|
|
vcsClient vcs.Client
|
|
deleteLockCommand DeleteLockCommand
|
|
// SilenceNoProjects is whether Atlantis should respond to PRs if no projects
|
|
// are found
|
|
SilenceNoProjects bool
|
|
}
|
|
|
|
func (u *UnlockCommandRunner) Run(
|
|
ctx *command.Context,
|
|
cmd *CommentCommand,
|
|
) {
|
|
baseRepo := ctx.Pull.BaseRepo
|
|
pullNum := ctx.Pull.Num
|
|
|
|
vcsMessage := "All Atlantis locks for this PR have been unlocked and plans discarded"
|
|
numLocks, err := u.deleteLockCommand.DeleteLocksByPull(baseRepo.FullName, pullNum)
|
|
if err != nil {
|
|
vcsMessage = "Failed to delete PR locks"
|
|
ctx.Log.Err("failed to delete locks by pull %s", err.Error())
|
|
}
|
|
|
|
// if there are no locks to delete, no errors, and SilenceNoProjects is enabled, don't comment
|
|
if err == nil && numLocks == 0 && u.SilenceNoProjects {
|
|
return
|
|
}
|
|
|
|
if commentErr := u.vcsClient.CreateComment(baseRepo, pullNum, vcsMessage, command.Unlock.String()); commentErr != nil {
|
|
ctx.Log.Err("unable to comment: %s", commentErr)
|
|
}
|
|
}
|