add log entries for rejected merges (#2604)

* add log entries for rejected merges
This commit is contained in:
Marko Gaćeša 2024-08-28 12:51:42 +00:00 committed by Harness
parent ffe585f8c4
commit 6b12b45950

View File

@ -130,7 +130,7 @@ func (c *Controller) Merge(
timeout+30*time.Second, // add 30s to the lock to give enough time for pre + post merge timeout+30*time.Second, // add 30s to the lock to give enough time for pre + post merge
) )
if err != nil { if err != nil {
return nil, nil, err return nil, nil, fmt.Errorf("failed to lock repository for pull request merge: %w", err)
} }
defer unlock() defer unlock()
@ -310,6 +310,24 @@ func (c *Controller) Merge(
} }
if protection.IsCritical(violations) { if protection.IsCritical(violations) {
sb := strings.Builder{}
for i, ruleViolation := range violations {
if i > 0 {
sb.WriteByte(',')
}
sb.WriteString(ruleViolation.Rule.Identifier)
sb.WriteString(":[")
for j, v := range ruleViolation.Violations {
if j > 0 {
sb.WriteByte(',')
}
sb.WriteString(v.Code)
}
sb.WriteString("]")
}
log.Ctx(ctx).Info().Msgf("aborting pull request merge because of rule violations: %s", sb.String())
return nil, &types.MergeViolations{RuleViolations: violations}, nil return nil, &types.MergeViolations{RuleViolations: violations}, nil
} }
@ -401,6 +419,8 @@ func (c *Controller) Merge(
} }
} }
log.Ctx(ctx).Info().Msg("aborting pull request merge because of conflicts")
return nil, &types.MergeViolations{ return nil, &types.MergeViolations{
ConflictFiles: mergeOutput.ConflictFiles, ConflictFiles: mergeOutput.ConflictFiles,
RuleViolations: violations, RuleViolations: violations,