fix: add comment creation for pre-workflow hook failures

- Remove unused formatPreWorkflowHookError helper function
- Use inline markdown code blocks for error formatting
- Add comment creation in both RunAutoplanCommand and RunCommentCommand
- Fixes compilation error in PR #5659
This commit is contained in:
Test User
2025-07-30 15:22:18 -07:00
parent aca08b9db9
commit 79c0db8ead

View File

@@ -214,6 +214,12 @@ func (c *DefaultCommandRunner) RunAutoplanCommand(baseRepo models.Repo, headRepo
if c.FailOnPreWorkflowHookError {
ctx.Log.Err("'fail-on-pre-workflow-hook-error' set, so not running %s command.", command.Plan)
// Create comment on pull request about the pre-workflow hook failure
errMsg := fmt.Sprintf("```\nError: Pre-workflow hook failed: %s\n```", err.Error())
if err := c.VCSClient.CreateComment(ctx.Log, ctx.Pull.BaseRepo, ctx.Pull.Num, errMsg, ""); err != nil {
ctx.Log.Warn("Unable to create comment about pre-workflow hook failure: %s", err)
}
// Update the plan or apply commit status to failed
switch cmd.Name {
case command.Plan:
@@ -378,6 +384,12 @@ func (c *DefaultCommandRunner) RunCommentCommand(baseRepo models.Repo, maybeHead
if c.FailOnPreWorkflowHookError {
ctx.Log.Err("'fail-on-pre-workflow-hook-error' set, so not running %s command.", cmd.Name.String())
// Create comment on pull request about the pre-workflow hook failure
errMsg := fmt.Sprintf("```\nError: Pre-workflow hook failed: %s\n```", err.Error())
if err := c.VCSClient.CreateComment(ctx.Log, ctx.Pull.BaseRepo, ctx.Pull.Num, errMsg, ""); err != nil {
ctx.Log.Warn("Unable to create comment about pre-workflow hook failure: %s", err)
}
// Update the plan or apply commit status to failed
switch cmd.Name {
case command.Plan:
@@ -566,3 +578,6 @@ func (c *DefaultCommandRunner) logPanics(baseRepo models.Repo, pullNum int, logg
}
var automergeComment = `Automatically merging because all plans have been successfully applied.`
// formatPreWorkflowHookError formats the pre-workflow hook error for display in a comment