Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Should always be able to report to GitHub Actions Job Summaries #177

Merged
merged 2 commits into from
Oct 10, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion .octocov.yml
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ push:
comment:
if: is_pull_request
summary:
if: is_pull_request
if: true
# body:
# if: is_pull_request
report:
Expand Down
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -551,7 +551,7 @@ Conditions for adding report to job summary page.
``` yaml
# .octocov.yml
summary:
if: is_pull_request
if: true
```

The variables available in the `if` section are [here](https://github.com/k1LoW/octocov#if).
Expand Down
17 changes: 11 additions & 6 deletions cmd/comment.go
Original file line number Diff line number Diff line change
Expand Up @@ -45,13 +45,18 @@ func createReportContent(ctx context.Context, c *config.Config, r, rPrev *report
if err != nil {
return "", err
}
var files []*gh.PullRequestFile
n, err := g.DetectCurrentPullRequestNumber(ctx, repo.Owner, repo.Repo)
if err != nil {
return "", err
}
files, err := g.GetPullRequestFiles(ctx, repo.Owner, repo.Repo, n)
if err != nil {
return "", err
if err == nil {
files, err = g.GetPullRequestFiles(ctx, repo.Owner, repo.Repo, n)
if err != nil {
return "", err
}
} else {
files, err = g.GetChangedFiles(ctx, repo.Owner, repo.Repo)
if err != nil {
return "", err
}
}
footer := "Reported by [octocov](https://github.com/k1LoW/octocov)"
if hideFooterLink {
Expand Down
15 changes: 0 additions & 15 deletions config/ready.go
Original file line number Diff line number Diff line change
Expand Up @@ -98,21 +98,6 @@ func (c *Config) SummaryConfigReady() error {
if os.Getenv("GITHUB_STEP_SUMMARY") == "" {
return fmt.Errorf("env %s is not set", "GITHUB_STEP_SUMMARY")
}
ctx := context.Background()
repo, err := gh.Parse(c.Repository)
if err != nil {
return err
}
if c.gh == nil {
g, err := gh.New()
if err != nil {
return err
}
c.gh = g
}
if _, err := c.gh.DetectCurrentPullRequestNumber(ctx, repo.Owner, repo.Repo); err != nil {
return err
}
ok, err := c.CheckIf(c.Summary.If)
if err != nil {
return err
Expand Down
23 changes: 23 additions & 0 deletions gh/gh.go
Original file line number Diff line number Diff line change
Expand Up @@ -346,6 +346,29 @@ func (g *Gh) GetPullRequestFiles(ctx context.Context, owner, repo string, number
return files, nil
}

func (g *Gh) GetChangedFiles(ctx context.Context, owner, repo string) ([]*PullRequestFile, error) {
base, err := g.GetDefaultBranch(ctx, owner, repo)
if err != nil {
return nil, err
}
head, err := g.DetectCurrentBranch(ctx)
if err != nil {
return nil, err
}
compare, _, err := g.client.Repositories.CompareCommits(ctx, owner, repo, base, head, &github.ListOptions{})
if err != nil {
return nil, err
}
files := []*PullRequestFile{}
for _, f := range compare.Files {
files = append(files, &PullRequestFile{
Filename: f.GetFilename(),
BlobURL: f.GetBlobURL(),
})
}
return files, nil
}

func (g *Gh) GetStepExecutionTimeByTime(ctx context.Context, owner, repo string, jobID int64, t time.Time) (time.Duration, error) {
p := backoff.Exponential(
backoff.WithMinInterval(time.Second),
Expand Down