From 1fbb0eba98d5746ba61e4f92ee65e648a133c23a Mon Sep 17 00:00:00 2001 From: Florian Beisel Date: Mon, 15 Jan 2024 09:19:21 +0100 Subject: [PATCH] fix: :bug: attempt to fix the Duplication of PRs in Rrelease Draft --- src/action.go | 30 ++++++++++++++++++------------ 1 file changed, 18 insertions(+), 12 deletions(-) diff --git a/src/action.go b/src/action.go index 2e13557..42b6cb0 100644 --- a/src/action.go +++ b/src/action.go @@ -53,13 +53,21 @@ func updateOrCreateDraftRelease(a *Action, cfg *config.RepoConfig) (*gitea.Relea categorizedPRs := make(map[string][]*gitea.PullRequest) for _, prs := range *changelog { - for _, category := range cfg.Categories { - if prHasLabel(prs, category.Labels) { - // Correctly append each PR in the slice - for _, pr := range prs { + for _, pr := range prs { + categorized := false + for _, category := range cfg.Categories { + if !categorized && prHasLabel(pr, category.Labels) { categorizedPRs[category.Title] = append(categorizedPRs[category.Title], pr) + categorized = true + break // Break out of the category loop } - break + } + if !categorized { + // Add to a default category if not categorized + categorizedPRs["Other Changes"] = append(categorizedPRs["Other Changes"], pr) + } + if categorized { + break // Break out of the PR loop once categorized } } } @@ -159,13 +167,11 @@ func (a *Action) Run() error { return nil } -func prHasLabel(prs []*gitea.PullRequest, labels []string) bool { - for _, pr := range prs { - for _, prLabel := range pr.Labels { - for _, label := range labels { - if prLabel.Name == label { - return true - } +func prHasLabel(pr *gitea.PullRequest, labels []string) bool { + for _, prLabel := range pr.Labels { + for _, label := range labels { + if prLabel.Name == label { + return true } } }