From af1949de0259b9dc68c17c243c211d415fbefde6 Mon Sep 17 00:00:00 2001 From: Lukas Date: Thu, 14 Sep 2023 11:47:40 +0200 Subject: [PATCH] fix: use notes endpoint to check for unresolved discussions (#68) --- .../checks/has_no_open_discussions.go | 18 ++++++++++++++++-- plugins/auto_merge/merge_checks.go | 2 +- 2 files changed, 17 insertions(+), 3 deletions(-) diff --git a/plugins/auto_merge/checks/has_no_open_discussions.go b/plugins/auto_merge/checks/has_no_open_discussions.go index 6f9fa6f..40072c0 100644 --- a/plugins/auto_merge/checks/has_no_open_discussions.go +++ b/plugins/auto_merge/checks/has_no_open_discussions.go @@ -2,14 +2,28 @@ package checks import ( "github.com/GEPROG/lassie-bot-dog/plugins/auto_merge/config" + "github.com/GEPROG/lassie-bot-dog/utils" "github.com/xanzy/go-gitlab" ) type HasNoOpenDiscussionsCheck struct { + Client *gitlab.Client } -func (check HasNoOpenDiscussionsCheck) Check(_ *config.AutoMergeConfig, _ *gitlab.Project, mergeRequest *gitlab.MergeRequest) bool { - return mergeRequest.BlockingDiscussionsResolved +func (check HasNoOpenDiscussionsCheck) Check(_ *config.AutoMergeConfig, project *gitlab.Project, mergeRequest *gitlab.MergeRequest) bool { + log := utils.Logger(project, mergeRequest) + notes, _, err := check.Client.Notes.ListMergeRequestNotes(mergeRequest.ProjectID, mergeRequest.IID, nil) + if err != nil { + log.Error("Can't load merge-request notes", err) + return false + } + for _, note := range notes { + if note.Resolvable && !note.Resolved { + log.Debug("Found unresolved discussion", note.ID) + return false + } + } + return true } func (check HasNoOpenDiscussionsCheck) Name() string { diff --git a/plugins/auto_merge/merge_checks.go b/plugins/auto_merge/merge_checks.go index af1a5b4..94c84ad 100644 --- a/plugins/auto_merge/merge_checks.go +++ b/plugins/auto_merge/merge_checks.go @@ -68,7 +68,7 @@ func (plugin AutoMergePlugin) setupMergeChecks() { }, checks.HasRequiredLabelsCheck{}, checks.HasNoConflictsCheck{}, - checks.HasNoOpenDiscussionsCheck{}, + checks.HasNoOpenDiscussionsCheck{Client: plugin.Client}, checks.IsNotWorkInProgressCheck{}, checks.PassesCICheck{ Client: plugin.Client,