Skip to content

Commit

Permalink
Merge pull request #241 from k1LoW/private-central
Browse files Browse the repository at this point in the history
Only display badges if the central mode repository is private
  • Loading branch information
k1LoW authored Aug 21, 2023
2 parents f14c9a2 + e21fc3c commit d5a2d87
Show file tree
Hide file tree
Showing 4 changed files with 31 additions and 2 deletions.
13 changes: 13 additions & 0 deletions .github/release.yml
Original file line number Diff line number Diff line change
Expand Up @@ -2,3 +2,16 @@ changelog:
exclude:
labels:
- tagpr
categories:
- title: Breaking Changes 🛠
labels:
- breaking-change
- title: New Features 🎉
labels:
- enhancement
- title: Fix bug 🐛
labels:
- bug
- title: Other Changes
labels:
- "*"
10 changes: 9 additions & 1 deletion central/central.go
Original file line number Diff line number Diff line change
Expand Up @@ -213,10 +213,17 @@ func (c *Central) renderIndex(wr io.Writer) error {
if err != nil {
return err
}
rawRootURL, err := g.GetRawRootURL(ctx, repo.Owner, repo.Repo)
isPrivate, err := g.IsPrivate(ctx, repo.Owner, repo.Repo)
if err != nil {
return err
}
var rawRootURL string
if !isPrivate {
rawRootURL, err = g.GetRawRootURL(ctx, repo.Owner, repo.Repo)
if err != nil {
return err
}
}

// Get project root dir
proot := c.config.Wd
Expand Down Expand Up @@ -250,6 +257,7 @@ func (c *Central) renderIndex(wr io.Writer) error {
"BadgesLinkRel": badgesLinkRel,
"BadgesURLRel": badgesURLRel,
"RawRootURL": rawRootURL,
"IsPrivate": isPrivate,
}
if err := tmpl.Execute(wr, d); err != nil {
return err
Expand Down
2 changes: 1 addition & 1 deletion central/index.md.tmpl
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
| Repository | Coverage | Code to Test Ratio | Time Execution Time | Badges |
| --- | --- | --- | --- | --- |
{{- range $r := .Reports }}
| [{{ $r.Repository }}]({{ $.Host }}/{{ $r.Repository }}) | {{ $r | coverage }} | {{ $r | ratio }} | {{ $r | time }} | ![{{ $r.Repository }}]({{ $.RawRootURL }}/{{ $.BadgesURLRel }}/{{ $r.Repository}}/coverage.svg){{ if $r.CodeToTestRatio }} ![{{ $r.Repository }}]({{ $.RawRootURL }}/{{ $.BadgesURLRel }}/{{ $r.Repository}}/ratio.svg){{ end }}{{ if $r.TestExecutionTime }} ![{{ $r.Repository }}]({{ $.RawRootURL }}/{{ $.BadgesURLRel }}/{{ $r.Repository}}/time.svg){{ end }} <details><summary>Copy status badge markdown</summary>```![Coverage]({{ $.RawRootURL }}/{{ $.BadgesURLRel }}/{{ $r.Repository}}/coverage.svg)```{{ if $r.CodeToTestRatio }}<br>```![Code to Test Ratio]({{ $.RawRootURL }}/{{ $.BadgesURLRel }}/{{ $r.Repository}}/ratio.svg)```{{ end }}{{ if $r.TestExecutionTime }}<br>```![Test Execution Time]({{ $.RawRootURL }}/{{ $.BadgesURLRel }}/{{ $r.Repository}}/time.svg)```{{ end }}</details> |
| [{{ $r.Repository }}]({{ $.Host }}/{{ $r.Repository }}) | {{ $r | coverage }} | {{ $r | ratio }} | {{ $r | time }} | ![{{ $r.Repository }}]({{ $.RawRootURL }}/{{ $.BadgesURLRel }}/{{ $r.Repository}}/coverage.svg){{ if $r.CodeToTestRatio }} ![{{ $r.Repository }}]({{ $.RawRootURL }}/{{ $.BadgesURLRel }}/{{ $r.Repository}}/ratio.svg){{ end }}{{ if $r.TestExecutionTime }} ![{{ $r.Repository }}]({{ $.RawRootURL }}/{{ $.BadgesURLRel }}/{{ $r.Repository}}/time.svg){{ end }} {{ if ne $.IsPrivate true }}<details><summary>Copy status badge markdown</summary>```![Coverage]({{ $.RawRootURL }}/{{ $.BadgesURLRel }}/{{ $r.Repository}}/coverage.svg)```{{ if $r.CodeToTestRatio }}<br>```![Code to Test Ratio]({{ $.RawRootURL }}/{{ $.BadgesURLRel }}/{{ $r.Repository}}/ratio.svg)```{{ end }}{{ if $r.TestExecutionTime }}<br>```![Test Execution Time]({{ $.RawRootURL }}/{{ $.BadgesURLRel }}/{{ $r.Repository}}/time.svg)```{{ end }}</details>{{ end }} |
{{- end }}

---
Expand Down
8 changes: 8 additions & 0 deletions gh/gh.go
Original file line number Diff line number Diff line change
Expand Up @@ -601,6 +601,14 @@ func (g *Gh) GetLatestArtifact(ctx context.Context, owner, repo, name, fp string
return nil, errors.New("artifact not found")
}

func (g *Gh) IsPrivate(ctx context.Context, owner, repo string) (bool, error) {
r, _, err := g.client.Repositories.Get(ctx, owner, repo)
if err != nil {
return false, err
}
return r.GetPrivate(), nil
}

type minimizeCommentMutation struct {
MinimizeComment struct {
MinimizedComment struct {
Expand Down

0 comments on commit d5a2d87

Please sign in to comment.