Skip to content
Merged
Changes from 1 commit
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
83 changes: 43 additions & 40 deletions main.go
Original file line number Diff line number Diff line change
Expand Up @@ -53,8 +53,9 @@ var (
Repo: flag.String("repo", getEnv("INPUT_REPOSITORY", ""), "GitHub repo name"),
Verbose: flag.Bool("v", ignoreError(strconv.ParseBool(getEnv("INPUT_VERBOSE", "0"))), "Verbose output"),
}
WarningBuffer = bytes.NewBuffer([]byte{})
InfoBuffer = bytes.NewBuffer([]byte{})
WarningBuffer = bytes.NewBuffer([]byte{})
InfoBuffer = bytes.NewBuffer([]byte{})
QUIET_MODE_TEST = true
)

// initFlags initializes and parses command line flags
Expand Down Expand Up @@ -211,49 +212,51 @@ func (a *App) processApprovalsAndReviewers() (bool, string, error) {
}

// Add comments to the PR if necessary
if len(unapprovedOwners) > 0 {
// Comment on the PR with the codeowner teams that have not approved the PR
comment := allRequiredOwners.ToCommentString()
hasHighPriority, err := a.client.IsInLabels(a.conf.HighPriorityLabels)
if err != nil {
fmt.Fprintf(WarningBuffer, "WARNING: Error checking high priority labels: %v\n", err)
} else if hasHighPriority {
comment = "❗High Prio❗\n\n" + comment
}
if maxReviewsMet {
comment += "\n\n"
comment += "The PR has received the max number of required reviews. No further action is required."
}
fiveDaysAgo := time.Now().AddDate(0, 0, -5)
found, err := a.client.IsInComments(comment, &fiveDaysAgo)
if err != nil {
return false, message, fmt.Errorf("IsInComments Error: %v\n", err)
}
if !found {
err = a.client.AddComment(comment)
if !QUIET_MODE_TEST {
if len(unapprovedOwners) > 0 {
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Recommend && here to avoid additional layer of nesting

// Comment on the PR with the codeowner teams that have not approved the PR
comment := allRequiredOwners.ToCommentString()
hasHighPriority, err := a.client.IsInLabels(a.conf.HighPriorityLabels)
if err != nil {
return false, message, fmt.Errorf("AddComment Error: %v\n", err)
fmt.Fprintf(WarningBuffer, "WARNING: Error checking high priority labels: %v\n", err)
} else if hasHighPriority {
comment = "❗High Prio❗\n\n" + comment
}
}
}
if len(allOptionalReviewerNames) > 0 {
var isInCommentsError error = nil
// Add CC comment to the PR with the optional reviewers that have not already been mentioned in the PR comments
viewersToPing := f.Filtered(allOptionalReviewerNames, func(name string) bool {
found, err := a.client.IsSubstringInComments(name, nil)
if maxReviewsMet {
comment += "\n\n"
comment += "The PR has received the max number of required reviews. No further action is required."
}
fiveDaysAgo := time.Now().AddDate(0, 0, -5)
found, err := a.client.IsInComments(comment, &fiveDaysAgo)
if err != nil {
isInCommentsError = err
return false, message, fmt.Errorf("IsInComments Error: %v\n", err)
}
if !found {
err = a.client.AddComment(comment)
if err != nil {
return false, message, fmt.Errorf("AddComment Error: %v\n", err)
}
}
return !found
})
if isInCommentsError != nil {
return false, message, fmt.Errorf("IsInComments Error: %v\n", err)
}
if len(viewersToPing) > 0 {
comment := fmt.Sprintf("cc %s", strings.Join(viewersToPing, " "))
err = a.client.AddComment(comment)
if err != nil {
return false, message, fmt.Errorf("AddComment Error: %v\n", err)
if len(allOptionalReviewerNames) > 0 {
var isInCommentsError error = nil
// Add CC comment to the PR with the optional reviewers that have not already been mentioned in the PR comments
viewersToPing := f.Filtered(allOptionalReviewerNames, func(name string) bool {
found, err := a.client.IsSubstringInComments(name, nil)
if err != nil {
isInCommentsError = err
}
return !found
})
if isInCommentsError != nil {
return false, message, fmt.Errorf("IsInComments Error: %v\n", err)
}
if len(viewersToPing) > 0 {
comment := fmt.Sprintf("cc %s", strings.Join(viewersToPing, " "))
err = a.client.AddComment(comment)
if err != nil {
return false, message, fmt.Errorf("AddComment Error: %v\n", err)
}
}
}
}
Expand Down
Loading