mirror of
https://git.vectorsigma.ru/public/atlantis.git
synced 2026-07-29 18:38:33 +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
36 lines
1.3 KiB
Go
36 lines
1.3 KiB
Go
package events
|
|
|
|
import (
|
|
"github.com/runatlantis/atlantis/server/events/command"
|
|
"github.com/runatlantis/atlantis/server/events/vcs"
|
|
)
|
|
|
|
type PullUpdater struct {
|
|
HidePrevPlanComments bool
|
|
VCSClient vcs.Client
|
|
MarkdownRenderer *MarkdownRenderer
|
|
}
|
|
|
|
func (c *PullUpdater) updatePull(ctx *command.Context, cmd PullCommand, res command.Result) {
|
|
// Log if we got any errors or failures.
|
|
if res.Error != nil {
|
|
ctx.Log.Err(res.Error.Error())
|
|
} else if res.Failure != "" {
|
|
ctx.Log.Warn(res.Failure)
|
|
}
|
|
|
|
// HidePrevCommandComments will hide old comments left from previous runs to reduce
|
|
// clutter in a pull/merge request. This will not delete the comment, since the
|
|
// comment trail may be useful in auditing or backtracing problems.
|
|
if c.HidePrevPlanComments {
|
|
if err := c.VCSClient.HidePrevCommandComments(ctx.Pull.BaseRepo, ctx.Pull.Num, cmd.CommandName().TitleString()); err != nil {
|
|
ctx.Log.Err("unable to hide old comments: %s", err)
|
|
}
|
|
}
|
|
|
|
comment := c.MarkdownRenderer.Render(res, cmd.CommandName(), ctx.Log.GetHistory(), cmd.IsVerbose(), ctx.Pull.BaseRepo.VCSHost.Type)
|
|
if err := c.VCSClient.CreateComment(ctx.Pull.BaseRepo, ctx.Pull.Num, comment, cmd.CommandName().String()); err != nil {
|
|
ctx.Log.Err("unable to comment: %s", err)
|
|
}
|
|
}
|