Skip to content

Commit fa12a24

Browse files
committed
Remove unnecessary errlist
1 parent be5a5ea commit fa12a24

File tree

1 file changed

+8
-35
lines changed

1 file changed

+8
-35
lines changed

services/pull/pull.go

Lines changed: 8 additions & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ package pull
66
import (
77
"bytes"
88
"context"
9+
"errors"
910
"fmt"
1011
"io"
1112
"os"
@@ -635,24 +636,6 @@ func UpdateRef(ctx context.Context, pr *issues_model.PullRequest) (err error) {
635636
return err
636637
}
637638

638-
type errlist []error
639-
640-
func (errs errlist) Error() string {
641-
if len(errs) > 0 {
642-
var buf strings.Builder
643-
for i, err := range errs {
644-
if i > 0 {
645-
buf.WriteString(", ")
646-
}
647-
buf.WriteString(err.Error())
648-
}
649-
return buf.String()
650-
}
651-
return ""
652-
}
653-
654-
var _ error = &errlist{}
655-
656639
// retargetBranchPulls change target branch for all pull requests whose base branch is the branch
657640
// Both branch and targetBranch must be in the same repo (for security reasons)
658641
func retargetBranchPulls(ctx context.Context, doer *user_model.User, repoID int64, branch, targetBranch string) error {
@@ -665,7 +648,7 @@ func retargetBranchPulls(ctx context.Context, doer *user_model.User, repoID int6
665648
return err
666649
}
667650

668-
var errs errlist
651+
var errs []error
669652
for _, pr := range prs {
670653
if err = pr.Issue.LoadRepo(ctx); err != nil {
671654
errs = append(errs, err)
@@ -675,11 +658,7 @@ func retargetBranchPulls(ctx context.Context, doer *user_model.User, repoID int6
675658
errs = append(errs, err)
676659
}
677660
}
678-
679-
if len(errs) > 0 {
680-
return errs
681-
}
682-
return nil
661+
return errors.Join(errs...)
683662
}
684663

685664
// AdjustPullsCausedByBranchDeleted close all the pull requests who's head branch is the branch
@@ -700,7 +679,7 @@ func AdjustPullsCausedByBranchDeleted(ctx context.Context, doer *user_model.User
700679
return err
701680
}
702681

703-
var errs errlist
682+
var errs []error
704683
for _, pr := range prs {
705684
if err = issue_service.CloseIssue(ctx, pr.Issue, doer, ""); err != nil && !issues_model.IsErrPullWasClosed(err) && !issues_model.IsErrDependenciesLeft(err) {
706685
errs = append(errs, err)
@@ -718,7 +697,7 @@ func AdjustPullsCausedByBranchDeleted(ctx context.Context, doer *user_model.User
718697
log.Error("retargetBranchPulls failed: %v", err)
719698
errs = append(errs, err)
720699
}
721-
return errs
700+
return errors.Join(errs...)
722701
}
723702

724703
// branch as base branch
@@ -747,10 +726,7 @@ func AdjustPullsCausedByBranchDeleted(ctx context.Context, doer *user_model.User
747726
}
748727
}
749728
}
750-
if len(errs) > 0 {
751-
return errs
752-
}
753-
return nil
729+
return errors.Join(errs...)
754730
}
755731

756732
// CloseRepoBranchesPulls close all pull requests which head branches are in the given repository, but only whose base repo is not in the given repository
@@ -760,7 +736,7 @@ func CloseRepoBranchesPulls(ctx context.Context, doer *user_model.User, repo *re
760736
return err
761737
}
762738

763-
var errs errlist
739+
var errs []error
764740
for _, branch := range branches {
765741
prs, err := issues_model.GetUnmergedPullRequestsByHeadInfo(ctx, repo.ID, branch.Name)
766742
if err != nil {
@@ -783,10 +759,7 @@ func CloseRepoBranchesPulls(ctx context.Context, doer *user_model.User, repo *re
783759
}
784760
}
785761

786-
if len(errs) > 0 {
787-
return errs
788-
}
789-
return nil
762+
return errors.Join(errs...)
790763
}
791764

792765
var commitMessageTrailersPattern = regexp.MustCompile(`(?:^|\n\n)(?:[\w-]+[ \t]*:[^\n]+\n*(?:[ \t]+[^\n]+\n*)*)+$`)

0 commit comments

Comments
 (0)