Skip to content

Commit

Permalink
fix: fix the issue triage check fail problem when batch remove may-af…
Browse files Browse the repository at this point in the history
…fects label (#880)
  • Loading branch information
Mini256 authored Jan 25, 2022
1 parent b937a2d commit d12ccc4
Show file tree
Hide file tree
Showing 3 changed files with 39 additions and 3 deletions.
4 changes: 2 additions & 2 deletions docs/en/plugins/issue-triage.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ In the new process, before merging pull requests for fixing critical or major se

The ti-community-issue-triage plugin is designed to manage and automate this process.

## Design Ideas
## Design

### Issue side

Expand All @@ -22,7 +22,7 @@ For critical or major severity bug issues.

- When the `may-affects/x.y` label on an issue changes, it will rerun all pull requests opened on the **default branch** (e.g. `master` branch) associated with it

### Pull request aspects
### Pull request side

For pull requests that fix related bug issues and linked with them, we add a check named `check-issue-triage-complete` that will ensure that the bug issues are triaged before the pull request is merged.

Expand Down
10 changes: 9 additions & 1 deletion internal/pkg/externalplugins/issuetriage/issuetriage.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import (
"regexp"
"strings"
"sync"
"time"

githubql "github.com/shurcooL/githubv4"
"github.com/sirupsen/logrus"
Expand Down Expand Up @@ -345,9 +346,16 @@ func (s *Server) handleIssueEvent(ie *github.IssueEvent, log *logrus.Entry) erro
return err
}

// Notice: wait a few seconds to reduce API consumption in case of batched label operations.
time.Sleep(5 * time.Second)
issue, err := s.GitHubClient.GetIssue(org, repo, num)
if err != nil {
return err
}

issues := make(issueCache)
key := fmt.Sprintf("%s/%s#%d", org, repo, num)
issues[key] = &ie.Issue
issues[key] = issue

var errs []error
for _, pr := range prs {
Expand Down
28 changes: 28 additions & 0 deletions internal/pkg/externalplugins/issuetriage/issuetriage_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -174,6 +174,8 @@ func (f *fghc) Query(ctx context.Context, q interface{}, vars map[string]interfa
}

func TestHandleIssueEvent(t *testing.T) {
t.Parallel()

var testcases = []struct {
name string
config externalplugins.TiCommunityIssueTriage
Expand Down Expand Up @@ -277,6 +279,18 @@ func TestHandleIssueEvent(t *testing.T) {
"may-affects/5.1",
"may-affects/5.3",
},
issues: map[int]*github.Issue{
1: {
Number: 1,
Labels: []github.Label{
{Name: bugTypeLabel},
{Name: majorSeverityLabel},
{Name: "affects/5.2"},
{Name: "may-affects/5.1"},
{Name: "may-affects/5.3"},
},
},
},

expectAddedLabels: []string{
"org/repo#2:do-not-merge/needs-triage-completed",
Expand All @@ -293,6 +307,16 @@ func TestHandleIssueEvent(t *testing.T) {
majorSeverityLabel,
"affects/5.2",
},
issues: map[int]*github.Issue{
1: {
Number: 1,
Labels: []github.Label{
{Name: bugTypeLabel},
{Name: majorSeverityLabel},
{Name: "affects/5.2"},
},
},
},
statusState: github.StatusPending,

expectAddedLabels: []string{
Expand Down Expand Up @@ -505,6 +529,8 @@ func TestHandleIssueEvent(t *testing.T) {
}

func TestHandlePullRequestEvent(t *testing.T) {
t.Parallel()

var testcases = []struct {
name string
config externalplugins.TiCommunityIssueTriage
Expand Down Expand Up @@ -990,6 +1016,8 @@ func TestHandlePullRequestEvent(t *testing.T) {
}

func TestHandleIssueCommentEvent(t *testing.T) {
t.Parallel()

var testcases = []struct {
name string
config externalplugins.TiCommunityIssueTriage
Expand Down

0 comments on commit d12ccc4

Please sign in to comment.