Skip to content

Commit b99224a

Browse files
authored
Feat/draft prs lock unlock fixes (#2290)
* draft prs lock and unlock fixing * check explicitly for opened event * ensure that the digger unlock success message is posted
1 parent 860c1bc commit b99224a

File tree

2 files changed

+42
-12
lines changed

2 files changed

+42
-12
lines changed

backend/controllers/github_comment.go

Lines changed: 29 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -193,18 +193,6 @@ func handleIssueCommentEvent(gh utils.GithubClientProvider, payload *github.Issu
193193
slog.Debug("Added eyes reaction to comment", "commentId", commentIdStr)
194194
}
195195

196-
if !config.AllowDraftPRs && isDraft {
197-
slog.Info("Draft PRs are disabled, skipping",
198-
"issueNumber", issueNumber,
199-
"isDraft", isDraft,
200-
)
201-
if os.Getenv("DIGGER_REPORT_BEFORE_LOADING_CONFIG") == "1" {
202-
// This one is for aggregate reporting
203-
commentReporterManager.UpdateComment(":construction_worker: Ignoring event as it is a draft and draft PRs are configured to be ignored")
204-
}
205-
return nil
206-
}
207-
208196
commentReporter, err := commentReporterManager.UpdateComment(":construction_worker: Digger starting.... config loaded successfully")
209197
if err != nil {
210198
slog.Error("Error initializing comment reporter",
@@ -339,6 +327,35 @@ func handleIssueCommentEvent(gh utils.GithubClientProvider, payload *github.Issu
339327
return fmt.Errorf("error processing event")
340328
}
341329

330+
if !config.AllowDraftPRs && isDraft {
331+
slog.Info("Draft PRs are disabled, skipping",
332+
"issueNumber", issueNumber,
333+
"isDraft", isDraft,
334+
)
335+
336+
if os.Getenv("DIGGER_REPORT_BEFORE_LOADING_CONFIG") == "1" {
337+
// This one is for aggregate reporting
338+
commentReporterManager.UpdateComment(":construction_worker: Ignoring event as it is a draft and draft PRs are configured to be ignored")
339+
}
340+
341+
// special case to unlock all locks aquired by this PR
342+
if *diggerCommand == scheduler.DiggerCommandUnlock {
343+
err := models.DB.DeleteAllLocksAcquiredByPR(issueNumber, repoFullName, orgId)
344+
if err != nil {
345+
slog.Error("Failed to delete locks",
346+
"prNumber", issueNumber,
347+
"command", *diggerCommand,
348+
"error", err,
349+
)
350+
commentReporterManager.UpdateComment(fmt.Sprintf(":x: Failed to delete locks: %v", err))
351+
return fmt.Errorf("failed to delete locks: %v", err)
352+
}
353+
commentReporterManager.UpdateComment(fmt.Sprintf(":white_check_mark: Command %v completed successfully", *diggerCommand))
354+
}
355+
356+
return nil
357+
}
358+
342359
// perform unlocking in backend
343360
if config.PrLocks {
344361
slog.Info("Processing PR locks for impacted projects",

backend/controllers/github_pull_request.go

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -256,6 +256,19 @@ func handlePullRequestEvent(gh utils.GithubClientProvider, payload *github.PullR
256256
return nil
257257
}
258258

259+
// special case for when a draft pull request is opened and ignore PRs is set to true we DO NOT want to lock the projects
260+
if !config.AllowDraftPRs && isDraft && action == "opened" {
261+
slog.Info("Draft PRs are disabled, skipping PR",
262+
"prNumber", prNumber,
263+
"isDraft", isDraft,
264+
)
265+
if os.Getenv("DIGGER_REPORT_BEFORE_LOADING_CONFIG") == "1" {
266+
// This one is for aggregate reporting
267+
commentReporterManager.UpdateComment(":construction_worker: Ignoring event as it is a draft and draft PRs are configured to be ignored")
268+
}
269+
return nil
270+
}
271+
259272
// perform locking/unlocking in backend
260273
if config.PrLocks {
261274
slog.Info("Processing PR locks for impacted projects",

0 commit comments

Comments
 (0)