From 79962c1cd0c58eda2d8e2c9a3397b0ef48b83596 Mon Sep 17 00:00:00 2001 From: arakaki_seina <87635517+anies1212@users.noreply.github.com> Date: Sat, 21 Dec 2024 12:25:35 +0900 Subject: [PATCH] feat: impl disable details --- README.md | 27 +++++++++++++++++++++++++++ cmd/comment.go | 4 ++-- cmd/root.go | 6 +++--- config/config.go | 3 +++ report/diff_report.go | 8 ++++++-- 5 files changed, 41 insertions(+), 7 deletions(-) diff --git a/README.md b/README.md index 4c2e2811..750e9fc0 100644 --- a/README.md +++ b/README.md @@ -575,6 +575,15 @@ comment: hideFooterLink: true ``` +### `comment.disableDetails:` + +Disable details tag for report. + +``` yaml +comment: + disableDetails: true +``` + ### `comment.deletePrevious:` Delete previous code metrics report comments instead of hiding them @@ -609,6 +618,15 @@ summary: hideFooterLink: true ``` +### `summary.disableDetails:` + +Disable details tag for report. + +``` yaml +comment: + disableDetails: true +``` + ### `summary.if:` Conditions for adding report to job summary page. @@ -634,6 +652,15 @@ body: hideFooterLink: true ``` +### `body.disableDetails:` + +Disable details tag for report. + +``` yaml +comment: + disableDetails: true +``` + ### `body.if:` Conditions for inserting report body of pull request. diff --git a/cmd/comment.go b/cmd/comment.go index 911ad0f8..30622b8a 100644 --- a/cmd/comment.go +++ b/cmd/comment.go @@ -36,7 +36,7 @@ func commentReport(ctx context.Context, c *config.Config, content, key string) e return nil } -func createReportContent(ctx context.Context, c *config.Config, r, rPrev *report.Report, hideFooterLink bool) (string, error) { +func createReportContent(ctx context.Context, c *config.Config, r, rPrev *report.Report, hideFooterLink bool, disableDetails bool) (string, error) { repo, err := gh.Parse(c.Repository) if err != nil { return "", err @@ -68,7 +68,7 @@ func createReportContent(ctx context.Context, c *config.Config, r, rPrev *report ) if rPrev != nil { d := r.Compare(rPrev) - table = d.Table() + table = d.Table(disableDetails) fileTable = d.FileCoveragesTable(files) for _, s := range d.CustomMetrics { customTables = append(customTables, s.Table(), s.MetadataTable()) diff --git a/cmd/root.go b/cmd/root.go index 730995f7..756359af 100644 --- a/cmd/root.go +++ b/cmd/root.go @@ -378,7 +378,7 @@ var rootCmd = &cobra.Command{ if err := c.DiffConfigReady(); err != nil { cmd.PrintErrf("Skip comparing reports: %v\n", err) } - content, err := createReportContent(ctx, c, r, rPrev, c.Comment.HideFooterLink) + content, err := createReportContent(ctx, c, r, rPrev, c.Comment.HideFooterLink, c.Comment.DisableDetails) if err != nil { return err } @@ -403,7 +403,7 @@ var rootCmd = &cobra.Command{ if err := c.DiffConfigReady(); err != nil { cmd.PrintErrf("Skip comparing reports: %v\n", err) } - content, err := createReportContent(ctx, c, r, rPrev, c.Summary.HideFooterLink) + content, err := createReportContent(ctx, c, r, rPrev, c.Summary.HideFooterLink, c.Summary.DisableDetails) if err != nil { return err } @@ -428,7 +428,7 @@ var rootCmd = &cobra.Command{ if err := c.DiffConfigReady(); err != nil { cmd.PrintErrf("Skip comparing reports: %v\n", err) } - content, err := createReportContent(ctx, c, r, rPrev, c.Body.HideFooterLink) + content, err := createReportContent(ctx, c, r, rPrev, c.Body.HideFooterLink, c.Body.DisableDetails) if err != nil { return err } diff --git a/config/config.go b/config/config.go index 2576fe1c..a1b38a98 100644 --- a/config/config.go +++ b/config/config.go @@ -118,17 +118,20 @@ type Push struct { type Comment struct { HideFooterLink bool `yaml:"hideFooterLink"` + DisableDetails bool `yaml:"disableDetails"` DeletePrevious bool `yaml:"deletePrevious"` If string `yaml:"if,omitempty"` } type Summary struct { HideFooterLink bool `yaml:"hideFooterLink"` + DisableDetails bool `yaml:"disableDetails"` If string `yaml:"if,omitempty"` } type Body struct { HideFooterLink bool `yaml:"hideFooterLink"` + DisableDetails bool `yaml:"disableDetails"` If string `yaml:"if,omitempty"` } diff --git a/report/diff_report.go b/report/diff_report.go index 83fb9ec9..915a553d 100644 --- a/report/diff_report.go +++ b/report/diff_report.go @@ -60,7 +60,7 @@ func (d *DiffReport) Out(w io.Writer) { var leftSepRe = regexp.MustCompile(`(?m)^\|`) -func (d *DiffReport) Table() string { +func (d *DiffReport) Table(disableDetails bool) string { var out []string // Markdown table @@ -120,7 +120,11 @@ func (d *DiffReport) Table() string { t2 = strings.Replace(t2, " | Test Execution", "+ | Test Execution", 1) } } - out = append(out, fmt.Sprintf("
\n\nDetails\n\n``` diff\n%s```\n\n
\n", t2)) + if disableDetails { + out = append(out, fmt.Sprintf("``` diff\n%s```\n", t2)) + } else { + out = append(out, fmt.Sprintf("
\n\nDetails\n\n``` diff\n%s```\n\n
\n", t2)) + } return strings.Join(out, "\n") }