Skip to content

Commit

Permalink
Add some details when printing errors
Browse files Browse the repository at this point in the history
  • Loading branch information
pmaslana committed May 13, 2024
1 parent 803d648 commit 4325eaf
Show file tree
Hide file tree
Showing 5 changed files with 20 additions and 13 deletions.
7 changes: 5 additions & 2 deletions cmd/notifyPendingCI.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,12 +24,15 @@ var notifyPendingCICmd = &cobra.Command{

loop := viper.GetBool("loop")
loopDuration := viper.GetDuration("loop-time")
var listPendingPRs []string
for {
log.Println("Checking for community PRs that are waiting for CI to run")
_, err = github2.CheckForPendingCI(client, cfg.InternalTeam, cfg.CheckStalePending)
listPendingPRs, err = github2.CheckForPendingCI(client, cfg.InternalTeam, cfg.CheckStalePending)
if err != nil {
log.Fatalln(err.Error())
log.Printf("The following error occurred while obtaining a list of pending PRs: %s", err)
continue
}
log.Printf("Pending PRs ready for CI: %v\n", listPendingPRs)

if !loop {
break
Expand Down
6 changes: 4 additions & 2 deletions cmd/notifyStale.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,13 +24,15 @@ var notifyStaleCmd = &cobra.Command{

loop := viper.GetBool("loop")
loopDuration := viper.GetDuration("loop-time")
var listPendingPRs []string
for {
log.Println("Checking for community PRs that have no update in the last 7 days")
_, err = github2.CheckStalePRs(client, cfg.InternalTeam, cfg.CheckStalePending)
if err != nil {
log.Fatalln(err.Error())
log.Printf("The following error occurred while obtaining a list of stale PRs: %s", err)
continue
}

log.Printf("Stale PRs: %v\n", listPendingPRs)
if !loop {
break
}
Expand Down
13 changes: 7 additions & 6 deletions internal/github/checkPendingCI.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,8 @@ func CheckForPendingCI(githubClient *github.Client, internalTeam string, cfg con
log.Println("Checking repository:", fullRepo.Name)
parts := strings.Split(fullRepo.Name, "/")
if len(parts) != 2 {
return nil, fmt.Errorf("invalid repository name - must contain owner and repository: %s", fullRepo.Name)
log.Printf("invalid repository name - must contain owner and repository: %s", fullRepo.Name)
continue
}
owner, repo := parts[0], parts[1]

Expand All @@ -36,29 +37,29 @@ func CheckForPendingCI(githubClient *github.Client, internalTeam string, cfg con
// Dynamic cutoff time based on the last commit to the PR
lastCommitTime, err := getLastCommitTime(githubClient, owner, repo, pr.GetNumber())
if err != nil {
log.Printf("Error retrieving last commit time for PR #%d: %v", pr.GetNumber(), err)
log.Printf("Error retrieving last commit time for PR #%d in %s %s: %v", pr.GetNumber(), owner, repo, err)
continue
}
cutoffTime := lastCommitTime.Add(2 * time.Hour) // 2 hours after the last commit

if time.Now().Before(cutoffTime) {
log.Printf("Skipping PR #%d as it's still within the 2-hour window from the last commit.", pr.GetNumber())
log.Printf("Skipping PR #%d from %s %s repo as it's still within the 2-hour window from the last commit.", pr.GetNumber(), owner, repo)
continue
}

hasCIRuns, err := checkCIStatus(githubClient, owner, repo, pr.GetNumber())
if err != nil {
log.Printf("Error checking CI status for PR #%d: %v", pr.GetNumber(), err)
log.Printf("Error checking CI status for PR #%d in %s %s: %v", pr.GetNumber(), owner, repo, err)
continue
}

teamMemberActivity, err := checkTeamMemberActivity(githubClient, owner, repo, pr.GetNumber(), teamMembers, lastCommitTime)
if err != nil {
log.Printf("Error checking team member activity for PR #%d: %v", pr.GetNumber(), err)
log.Printf("Error checking team member activity for PR #%d in %s %s: %v", pr.GetNumber(), owner, repo, err)
continue // or handle the error as needed
}
if !hasCIRuns || !teamMemberActivity {
log.Printf("PR #%d by %s is ready for CI since %v but no CI actions have started yet, or it requires re-approval.", pr.GetNumber(), pr.User.GetLogin(), pr.CreatedAt)
log.Printf("PR #%d in %s %s by %s is ready for CI since %v but no CI actions have started yet, or it requires re-approval.", owner, repo, pr.GetNumber(), pr.User.GetLogin(), pr.CreatedAt)
pendingPRs = append(pendingPRs, pr.GetHTMLURL())
}
}
Expand Down
5 changes: 3 additions & 2 deletions internal/github/checkStalePRs.go
Original file line number Diff line number Diff line change
Expand Up @@ -25,10 +25,11 @@ func CheckStalePRs(githubClient *github.Client, internalTeam string, cfg config.
}

for _, pr := range communityPRs {
repoName := pr.GetBase().GetRepo().GetFullName() // Get the full name of the repository
stale, err := isStale(githubClient, pr, teamMembers, cutoffDate) // Handle both returned values
if err != nil {
log.Printf("Error checking if PR is stale: %v", err) // Log or handle the error
continue // Skip this PR or handle the error appropriately
log.Printf("Error checking if PR in repo %s is stale: %v", repoName, err)
continue // Skip this PR or handle the error appropriately
}
if stale {
stalePRUrls = append(stalePRUrls, pr.GetHTMLURL()) // Append if PR is confirmed stale
Expand Down
2 changes: 1 addition & 1 deletion internal/label/pullrequests.go
Original file line number Diff line number Diff line change
Expand Up @@ -59,5 +59,5 @@ func PullRequests(githubClient *github.Client, internalTeam string, cfg config.L
}
}

return nil // Ensure that a nil is returned if the function completes without error
return nil
}

0 comments on commit 4325eaf

Please sign in to comment.