-
Notifications
You must be signed in to change notification settings - Fork 247
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
Finalize Codecov integration #5963
Comments
I did some investigation of the opened PRs.
Codepackage main
import (
"context"
"fmt"
"log"
"github.com/google/go-github/v48/github"
"golang.org/x/oauth2"
"strings"
"time"
"os"
)
func main() {
ctx := context.Background()
ghToken, ok := os.LookupEnv("GITHUB_TOKEN")
if !ok {
log.Fatalf("GITHUB_TOKEN not set")
}
ts := oauth2.StaticTokenSource(
&oauth2.Token{AccessToken: ghToken},
)
tc := oauth2.NewClient(ctx, ts)
client := github.NewClient(tc)
owner := "status-im" // Replace with your repository owner
repo := "status-go" // Replace with your repository name
thresholdDate, _ := time.Parse("02.01.2006", "03.10.2024")
// Get open pull requests
prs, _, err := client.PullRequests.List(ctx, owner, repo, &github.PullRequestListOptions{State: "open"})
if err != nil {
log.Fatalf("Error fetching pull requests: %v", err)
}
fmt.Printf("| PR | Created at | Last commit | Date OK | Commit checks | Comment |\n")
fmt.Printf("|-|-|-|-|-|-|\n")
//skip := true
for _, pr := range prs {
//if skip {
// if *pr.Number == 5943 {
// skip = false
// }
// continue
//}
prDate := pr.GetCreatedAt()
// Check the date of the latest commit in the PR
latestCommit, _, err := client.Repositories.GetCommit(ctx, owner, repo, pr.Head.GetSHA(), nil)
if err != nil {
log.Fatalf("Error fetching the latest commit: %v", err)
}
commitDate := latestCommit.Commit.Author.GetDate()
tooOld := commitDate.Before(thresholdDate) && prDate.Before(thresholdDate)
prComments, _, err := client.Issues.ListComments(ctx, owner, repo, *pr.Number, nil)
if err != nil {
log.Fatalf("Error fetching PR comments: %v", err)
}
var codecovComment *github.IssueComment
var codecovChecks []string
// Check for codecov comments
for _, comment := range prComments {
if comment.User != nil && comment.User.GetLogin() == "codecov[bot]" {
codecovComment = comment
break
}
}
checkRuns, _, err := client.Checks.ListCheckRunsForRef(ctx, owner, repo, *pr.Head.SHA, nil)
if err != nil {
log.Fatalf("Error fetching combined check runs: %v", err)
}
for _, run := range checkRuns.CheckRuns {
if run.Name == nil {
continue
}
if !strings.HasPrefix(*run.Name, "codecov") {
continue
}
codecovChecks = append(codecovChecks, strings.Replace(*run.Name, "codecov/", "", 1))
}
//if codecovStatusChecks < 6 {
// fmt.Printf("PR #%d: %s has %d codecov checks\n", *pr.Number, *pr.Title, codecovStatusChecks)
//}
fmt.Printf("| #%d | %s | %s | %v | %s | %s |\n",
*pr.Number,
prDate.Format("02.01.2006"),
commitDate.Format("02.01.2006"),
boolEmoji(!tooOld),
boolEmoji(len(codecovChecks) > 0),
firstLine(codecovComment),
)
}
}
func boolEmoji(b bool) string {
if b {
return "✅"
}
return "❌"
}
func checksString(checks []string) string {
if len(checks) == 0 {
return "❌"
}
return "✅"
}
func commentURL(comment *github.IssueComment) string {
if comment == nil {
return "---"
}
if comment.URL == nil {
return "???"
}
return fmt.Sprintf("[url](%s)", *comment.URL)
}
func firstLine(comment *github.IssueComment) string {
if comment == nil {
return "❌"
}
if comment.Body == nil {
return "🙈"
}
body := *comment.Body
if strings.HasPrefix(body, "## [Codecov](https://app.codecov.io/gh/status-im/status-go/pull") {
return "✅"
}
if strings.HasPrefix(body, "### :x:") {
numberOfTestsFailed := strings.Split(body, " ")[2]
flaky := strings.Contains(body, "flaky")
//return fmt.Sprintf("%s failed", numberOfTestsFailed)
return fmt.Sprintf("⚠️ (%s) (flaky: %v)", numberOfTestsFailed, flaky)
}
return strings.Split(*comment.Body, "\n")[0]
} |
Analyzing issues from above:
|
Checking #5955. tests log:
tests-rpc log:
Both reports are detected by the Codecov: Maybe it's because |
These are the PRs to consider as problems:
Problems description
|
Another thing that bothers me: For some reason the last commit for https://app.codecov.io/github/status-im/status-go/tree/develop UPD:Just noted that a new commit appeared for the Interesting:https://app.codecov.io/github/status-im/status-go/commits/develop |
Another issue I found in #5985: UPD: probably not an issue. Codecov is actually showing better results, because it counts the |
done 🎉 |
Ensure all PRs have codecov status checks
Looks like when 1 test failed, codecov doesn't report the status checks to the PR. Despite that we rerun the test.
It's not always like that though. Maybe because of the flaky test detection Codecov feature.
One of the ways to fix it could be remove test results report to Codecov, keep only the coverage.
Configure Codecov to satisfy our needs.
Remove codeclimate integration.
The text was updated successfully, but these errors were encountered: