diff --git a/.github/workflows/robot/internal/bot/assign.go b/.github/workflows/robot/internal/bot/assign.go index abc86d9bda42d..35fe61ac3a243 100644 --- a/.github/workflows/robot/internal/bot/assign.go +++ b/.github/workflows/robot/internal/bot/assign.go @@ -104,7 +104,7 @@ func (b *Bot) backportReviewers(ctx context.Context) ([]string, error) { originalReviewers = append(originalReviewers, review.Author) } - return originalReviewers, nil + return dedup(b.c.Environment.Author, originalReviewers), nil } func (b *Bot) findOriginal(ctx context.Context, organization string, repository string, number int) (int, error) { @@ -155,8 +155,26 @@ func (b *Bot) findOriginal(ctx context.Context, organization string, repository return n, nil } +func dedup(author string, reviewers []string) []string { + m := map[string]bool{} + + for _, reviewer := range reviewers { + if reviewer == author { + continue + } + m[reviewer] = true + } + + var filtered []string + for k := range m { + filtered = append(filtered, k) + } + + return filtered +} + func isBackport(unsafeBase string) bool { return strings.HasPrefix(unsafeBase, "branch/v") } -var pattern = regexp.MustCompile(`#([0-9]+)`) +var pattern = regexp.MustCompile(`(?:https:\/\/github\.com\/gravitational\/teleport\/pull\/|#)([0-9]+)`) diff --git a/.github/workflows/robot/internal/bot/assign_test.go b/.github/workflows/robot/internal/bot/assign_test.go index a3186b8fccb87..b065a6023de36 100644 --- a/.github/workflows/robot/internal/bot/assign_test.go +++ b/.github/workflows/robot/internal/bot/assign_test.go @@ -47,7 +47,7 @@ func TestBackportReviewers(t *testing.T) { expected []string }{ { - desc: "backport-original-approved", + desc: "backport-original-pr-number-approved", pull: github.PullRequest{ Author: "baz", Repository: "bar", @@ -63,6 +63,43 @@ func TestBackportReviewers(t *testing.T) { err: false, expected: []string{"3", "4"}, }, + { + desc: "backport-original-url-approved", + pull: github.PullRequest{ + Author: "baz", + Repository: "bar", + UnsafeHead: "baz/fix", + UnsafeTitle: "Fixed an issue", + UnsafeBody: "https://github.com/gravitational/teleport/pull/0", + Fork: false, + }, + reviewers: []string{"3"}, + reviews: []github.Review{ + {Author: "4", State: "APPROVED"}, + }, + err: false, + expected: []string{"3", "4"}, + }, + { + desc: "backport-multiple-reviews", + pull: github.PullRequest{ + Author: "baz", + Repository: "bar", + UnsafeHead: "baz/fix", + UnsafeTitle: "Fixed feature", + UnsafeBody: "", + Fork: false, + }, + reviewers: []string{"3"}, + reviews: []github.Review{ + {Author: "4", State: "COMMENTED"}, + {Author: "4", State: "CHANGES_REQUESTED"}, + {Author: "4", State: "APPROVED"}, + {Author: "9", State: "APPROVED"}, + }, + err: true, + expected: []string{}, + }, { desc: "backport-original-not-found", pull: github.PullRequest{ @@ -87,6 +124,7 @@ func TestBackportReviewers(t *testing.T) { c: &Config{ Environment: &env.Environment{ Organization: "foo", + Author: "9", Repository: "bar", Number: 0, UnsafeBase: "branch/v8",