-
Notifications
You must be signed in to change notification settings - Fork 65
/
merge.go
44 lines (34 loc) · 956 Bytes
/
merge.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
package multigitter
import (
"context"
"github.com/lindell/multi-gitter/internal/scm"
log "github.com/sirupsen/logrus"
)
// Merger merges pull requests in an organization
type Merger struct {
VersionController VersionController
FeatureBranch string
}
// Merge merges pull requests in an organization
func (s Merger) Merge(ctx context.Context) error {
prs, err := s.VersionController.GetPullRequests(ctx, s.FeatureBranch)
if err != nil {
return err
}
successPrs := make([]scm.PullRequest, 0, len(prs))
for _, pr := range prs {
if pr.Status() == scm.PullRequestStatusSuccess {
successPrs = append(successPrs, pr)
}
}
log.Infof("Merging %d pull requests", len(successPrs))
for _, pr := range successPrs {
log := log.WithField("pr", pr.String())
log.Infof("Merging")
err := s.VersionController.MergePullRequest(ctx, pr)
if err != nil {
log.Errorf("Error occurred while merging: %s", err.Error())
}
}
return nil
}