diff --git a/cmd/action/merge_guard.go b/cmd/action/merge_guard.go index f50aff4f..9a40b822 100644 --- a/cmd/action/merge_guard.go +++ b/cmd/action/merge_guard.go @@ -162,22 +162,36 @@ func (c *MergeGuard) Run(cc *cli.Context) (err error) { slices.SortFunc(vs, func(a spec.Violation, b spec.Violation) int { return a.Line - b.Line }) - vf := templates.ViolationFile{Path: path} + + var relPath string + relPath, err = filepath.Rel(headRoot, path) + if err != nil { + err = fmt.Errorf("the relative path could not be determined. Path: %s, Root: %s", path, headRoot) + return + } + + vf := templates.ViolationFile{Path: relPath} for _, v := range vs { vv := templates.Violation{} - vv.EntityName = matter.EntityName(v.Entity) - vv.EntityType = entityTypeName(v.Entity) - parent := v.Entity.Parent() - for { - if parent == nil { - break + if v.Entity != nil { + vv.EntityName = matter.EntityName(v.Entity) + vv.EntityType = entityTypeName(v.Entity) + + parent := v.Entity.Parent() + for { + if parent == nil { + break + } + vv.EntityName = matter.EntityName(parent) + "." + vv.EntityName + parent = parent.Parent() } - vv.EntityName = matter.EntityName(parent) + "." + vv.EntityName - parent = parent.Parent() + } else { + vv.EntityName = "-" + vv.EntityType = "-" } - pathHash := sha256.Sum256([]byte(path)) + pathHash := sha256.Sum256([]byte(relPath)) vv.SourceLink = fmt.Sprintf("https://github.com/%s/%s/pull/%d/files#diff-%sR%d", owner, repo, pr.GetNumber(), hex.EncodeToString(pathHash[:]), v.Line) vv.SourceLine = v.Line if v.Type.Has(spec.ViolationTypeNonProvisional) {