|
53 | 53 | Repo: flag.String("repo", getEnv("INPUT_REPOSITORY", ""), "GitHub repo name"), |
54 | 54 | Verbose: flag.Bool("v", ignoreError(strconv.ParseBool(getEnv("INPUT_VERBOSE", "0"))), "Verbose output"), |
55 | 55 | } |
56 | | - WarningBuffer = bytes.NewBuffer([]byte{}) |
57 | | - InfoBuffer = bytes.NewBuffer([]byte{}) |
| 56 | + WarningBuffer = bytes.NewBuffer([]byte{}) |
| 57 | + InfoBuffer = bytes.NewBuffer([]byte{}) |
| 58 | + QUIET_MODE_TEST = true |
58 | 59 | ) |
59 | 60 |
|
60 | 61 | // initFlags initializes and parses command line flags |
@@ -211,49 +212,51 @@ func (a *App) processApprovalsAndReviewers() (bool, string, error) { |
211 | 212 | } |
212 | 213 |
|
213 | 214 | // Add comments to the PR if necessary |
214 | | - if len(unapprovedOwners) > 0 { |
215 | | - // Comment on the PR with the codeowner teams that have not approved the PR |
216 | | - comment := allRequiredOwners.ToCommentString() |
217 | | - hasHighPriority, err := a.client.IsInLabels(a.conf.HighPriorityLabels) |
218 | | - if err != nil { |
219 | | - fmt.Fprintf(WarningBuffer, "WARNING: Error checking high priority labels: %v\n", err) |
220 | | - } else if hasHighPriority { |
221 | | - comment = "❗High Prio❗\n\n" + comment |
222 | | - } |
223 | | - if maxReviewsMet { |
224 | | - comment += "\n\n" |
225 | | - comment += "The PR has received the max number of required reviews. No further action is required." |
226 | | - } |
227 | | - fiveDaysAgo := time.Now().AddDate(0, 0, -5) |
228 | | - found, err := a.client.IsInComments(comment, &fiveDaysAgo) |
229 | | - if err != nil { |
230 | | - return false, message, fmt.Errorf("IsInComments Error: %v\n", err) |
231 | | - } |
232 | | - if !found { |
233 | | - err = a.client.AddComment(comment) |
| 215 | + if !QUIET_MODE_TEST { |
| 216 | + if len(unapprovedOwners) > 0 { |
| 217 | + // Comment on the PR with the codeowner teams that have not approved the PR |
| 218 | + comment := allRequiredOwners.ToCommentString() |
| 219 | + hasHighPriority, err := a.client.IsInLabels(a.conf.HighPriorityLabels) |
234 | 220 | if err != nil { |
235 | | - return false, message, fmt.Errorf("AddComment Error: %v\n", err) |
| 221 | + fmt.Fprintf(WarningBuffer, "WARNING: Error checking high priority labels: %v\n", err) |
| 222 | + } else if hasHighPriority { |
| 223 | + comment = "❗High Prio❗\n\n" + comment |
236 | 224 | } |
237 | | - } |
238 | | - } |
239 | | - if len(allOptionalReviewerNames) > 0 { |
240 | | - var isInCommentsError error = nil |
241 | | - // Add CC comment to the PR with the optional reviewers that have not already been mentioned in the PR comments |
242 | | - viewersToPing := f.Filtered(allOptionalReviewerNames, func(name string) bool { |
243 | | - found, err := a.client.IsSubstringInComments(name, nil) |
| 225 | + if maxReviewsMet { |
| 226 | + comment += "\n\n" |
| 227 | + comment += "The PR has received the max number of required reviews. No further action is required." |
| 228 | + } |
| 229 | + fiveDaysAgo := time.Now().AddDate(0, 0, -5) |
| 230 | + found, err := a.client.IsInComments(comment, &fiveDaysAgo) |
244 | 231 | if err != nil { |
245 | | - isInCommentsError = err |
| 232 | + return false, message, fmt.Errorf("IsInComments Error: %v\n", err) |
| 233 | + } |
| 234 | + if !found { |
| 235 | + err = a.client.AddComment(comment) |
| 236 | + if err != nil { |
| 237 | + return false, message, fmt.Errorf("AddComment Error: %v\n", err) |
| 238 | + } |
246 | 239 | } |
247 | | - return !found |
248 | | - }) |
249 | | - if isInCommentsError != nil { |
250 | | - return false, message, fmt.Errorf("IsInComments Error: %v\n", err) |
251 | 240 | } |
252 | | - if len(viewersToPing) > 0 { |
253 | | - comment := fmt.Sprintf("cc %s", strings.Join(viewersToPing, " ")) |
254 | | - err = a.client.AddComment(comment) |
255 | | - if err != nil { |
256 | | - return false, message, fmt.Errorf("AddComment Error: %v\n", err) |
| 241 | + if len(allOptionalReviewerNames) > 0 { |
| 242 | + var isInCommentsError error = nil |
| 243 | + // Add CC comment to the PR with the optional reviewers that have not already been mentioned in the PR comments |
| 244 | + viewersToPing := f.Filtered(allOptionalReviewerNames, func(name string) bool { |
| 245 | + found, err := a.client.IsSubstringInComments(name, nil) |
| 246 | + if err != nil { |
| 247 | + isInCommentsError = err |
| 248 | + } |
| 249 | + return !found |
| 250 | + }) |
| 251 | + if isInCommentsError != nil { |
| 252 | + return false, message, fmt.Errorf("IsInComments Error: %v\n", err) |
| 253 | + } |
| 254 | + if len(viewersToPing) > 0 { |
| 255 | + comment := fmt.Sprintf("cc %s", strings.Join(viewersToPing, " ")) |
| 256 | + err = a.client.AddComment(comment) |
| 257 | + if err != nil { |
| 258 | + return false, message, fmt.Errorf("AddComment Error: %v\n", err) |
| 259 | + } |
257 | 260 | } |
258 | 261 | } |
259 | 262 | } |
|
0 commit comments