Skip to content

Commit

Permalink
feat(externalplugins/issuetriage): support wont fix feature (#998)
Browse files Browse the repository at this point in the history
  • Loading branch information
wuhuizuo authored Aug 11, 2022
1 parent c16d52d commit 6927685
Show file tree
Hide file tree
Showing 5 changed files with 78 additions and 17 deletions.
5 changes: 4 additions & 1 deletion docs/en/plugins/issue-triage.md
Original file line number Diff line number Diff line change
Expand Up @@ -47,9 +47,10 @@ When the `check-issue-triage-complete` check passes, the bot removes the `do-not
## Parameter Configuration

| parameter name | type | description |
|---------------------------------|----------|-------------------------------------------------------------------------------------|
| ------------------------------- | -------- | ----------------------------------------------------------------------------------- |
| repos | []string | Configuration effective repository |
| maintain_versions | []string | The version number of the release branch being maintained by the repository |
| wontfix_versions | []string | The version number of the release branch won't be cherry pick to in the repository |
| affects_label_prefix | string | The label prefix that identifies the release branch affected by the issue |
| may_affects_label_prefix | string | The label prefix that identifies the release branch that the issue may affect |
| linked_issue_needs_triage_label | string | The label that identifies the PR's associated issue that requires triage completion |
Expand All @@ -66,6 +67,8 @@ ti-community-issue-triage:
- "5.1"
- "5.2"
- "5.3"
wontfix_versions:
- "5.1" # can label `affect-5.1` label to issue, but will not create `needs-cherry-pick-5.1` in pull request.
affects_label_prefix: "affects/"
may_affects_label_prefix: "may-affects/"
linked_issue_needs_triage_label: "do-not-merge/needs-triage_completed"
Expand Down
21 changes: 12 additions & 9 deletions docs/plugins/issue-triage.md
Original file line number Diff line number Diff line change
Expand Up @@ -46,15 +46,16 @@ ti-community-issue-triage 插件将被设计来对以上流程进行管控和自

## 参数配置

| 参数名 | 类型 | 说明 |
|---------------------------------|----------|--------------------------------------|
| repos | []string | 配置生效仓库 |
| maintain_versions | []string | 仓库正在维护的发行分支版本号 |
| affects_label_prefix | string | 标识 issue 影响的发行分支的 label 前缀 |
| may_affects_label_prefix | string | 标识 issue 可能影响的发行分支的 label 前缀 |
| linked_issue_needs_triage_label | string | 标识 PR 所关联 issue 需要 triage 完成的 label |
| need_cherry_pick_label_prefix | string | 标识 PR 需要 cherry-pick 到 release 分支的前缀 |
| status_target_url | string | Status check 的详情 URL |
| 参数名 | 类型 | 说明 |
| ------------------------------- | -------- | ------------------------------------------------------ |
| repos | []string | 配置生效仓库 |
| maintain_versions | []string | 仓库正在维护的发行分支版本号 |
| wontfix_versions | []string | 仓库不会再自动创建 cherry pick PR 的目标发行分支版本号 |
| affects_label_prefix | string | 标识 issue 影响的发行分支的 label 前缀 |
| may_affects_label_prefix | string | 标识 issue 可能影响的发行分支的 label 前缀 |
| linked_issue_needs_triage_label | string | 标识 PR 所关联 issue 需要 triage 完成的 label |
| need_cherry_pick_label_prefix | string | 标识 PR 需要 cherry-pick 到 release 分支的前缀 |
| status_target_url | string | Status check 的详情 URL |

例如:

Expand All @@ -66,6 +67,8 @@ ti-community-issue-triage:
- "5.1"
- "5.2"
- "5.3"
wontfix_versions:
- "5.1" # issue 会打上 `affect-5.1` 标签, 但 PR 不会自动打上 `needs-cherry-pick-5.1` 标签.
affects_label_prefix: "affects/"
may_affects_label_prefix: "may-affects/"
linked_issue_needs_triage_label: "do-not-merge/needs-triage-completed"
Expand Down
4 changes: 3 additions & 1 deletion internal/pkg/externalplugins/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -309,8 +309,10 @@ type RequiredMatchRule struct {
type TiCommunityIssueTriage struct {
// Repos are either of the form org/repo or just org.
Repos []string `json:"repos,omitempty"`
// MaintainVersions specifies the version number under maintenance, like 5.1.
// MaintainVersions specifies the version numbers under maintenance, like 5.1.
MaintainVersions []string `json:"maintain_versions"`
// WontfixVersions specifies the version numbers out of fix support, like 5.0.
WontfixVersions []string `json:"wontfix_versions"`
// AffectsLabelPrefix specifies the prefix for the affects label
AffectsLabelPrefix string `json:"affects_label_prefix"`
// MayAffectsLabelPrefix specifies the prefix for the may-affects label
Expand Down
17 changes: 16 additions & 1 deletion internal/pkg/externalplugins/issuetriage/issuetriage.go
Original file line number Diff line number Diff line change
Expand Up @@ -167,7 +167,7 @@ func HelpProvider(epa *tiexternalplugins.ConfigAgent) externalplugins.ExternalPl
)
}

if opts.MaintainVersions != nil && len(opts.MaintainVersions) != 0 {
if len(opts.MaintainVersions) != 0 {
var versionConfigStrings []string
versionConfigStrings = append(versionConfigStrings,
"The release branches that the current repository is maintaining: ")
Expand All @@ -179,13 +179,23 @@ func HelpProvider(epa *tiexternalplugins.ConfigAgent) externalplugins.ExternalPl
configInfoStrings = append(configInfoStrings, strings.Join(versionConfigStrings, "\n"))
}

if len(opts.WontfixVersions) != 0 {
wontFixStrings := []string{"The release branches won't fix in the current repository: ", "<ul>"}
for _, version := range opts.WontfixVersions {
wontFixStrings = append(wontFixStrings, fmt.Sprintf("<li>%s</li>", version))
}
wontFixStrings = append(wontFixStrings, "</ul>")
configInfoStrings = append(configInfoStrings, strings.Join(wontFixStrings, "\n"))
}

configInfo[repo.String()] = strings.Join(configInfoStrings, "\n")
}

yamlSnippet, err := plugins.CommentMap.GenYaml(&tiexternalplugins.Configuration{
TiCommunityIssueTriage: []tiexternalplugins.TiCommunityIssueTriage{
{
Repos: []string{"ti-community-infra/test-dev"},
WontfixVersions: []string{"5.0", "6.0"},
MaintainVersions: []string{"5.1", "5.2", "5.3"},
AffectsLabelPrefix: "affects/",
MayAffectsLabelPrefix: "may-affects/",
Expand Down Expand Up @@ -542,8 +552,13 @@ func (s *Server) handle(log *logrus.Entry, cfg *tiexternalplugins.TiCommunityIss

// Add needs-cherry-pick label.
labelsNeedToAdd := make([]string, 0)
wontfixVersionSets := sets.NewString(cfg.WontfixVersions...)
for _, affectsVersionLabel := range affectsVersionLabels.List() {
affectVersion := strings.TrimPrefix(affectsVersionLabel, cfg.AffectsLabelPrefix)
if wontfixVersionSets.Has(affectVersion) {
continue
}

cherryPickLabel := cfg.NeedCherryPickLabelPrefix + affectVersion
if !prLabels.Has(cherryPickLabel) {
labelsNeedToAdd = append(labelsNeedToAdd, cherryPickLabel)
Expand Down
48 changes: 43 additions & 5 deletions internal/pkg/externalplugins/issuetriage/issuetriage_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -840,6 +840,42 @@ func TestHandlePullRequestEvent(t *testing.T) {
expectCreatedStatusState: github.StatusSuccess,
expectCreatedStatusDesc: statusDescAllBugIssueTriaged,
},
{
name: "open a pull request linked to two triaged issue, but affect labels contain won't fix versions",
action: github.PullRequestActionOpened,
labels: []string{},
body: "Issue Number: close #2, ref #3",
state: "open",
targetBranch: "master",
issues: map[int]*github.Issue{
2: {
Number: 2,
Labels: []github.Label{
{Name: "type/bug"},
{Name: "severity/major"},
{Name: "affects/5.2"},
{Name: "affects/4.1"},
},
},
3: {
Number: 3,
Labels: []github.Label{
{Name: "type/bug"},
{Name: "severity/major"},
{Name: "affects/5.3"},
{Name: "affects/4.0"},
},
},
},

expectAddedLabels: []string{
"org/repo#1:needs-cherry-pick-release-5.2",
"org/repo#1:needs-cherry-pick-release-5.3",
},
expectRemovedLabels: []string{},
expectCreatedStatusState: github.StatusSuccess,
expectCreatedStatusDesc: statusDescAllBugIssueTriaged,
},
{
name: "open a pull request on release branch and link to a bug issue with may-affects/* labels",
action: github.PullRequestActionOpened,
Expand Down Expand Up @@ -933,7 +969,8 @@ func TestHandlePullRequestEvent(t *testing.T) {
cfg.TiCommunityIssueTriage = []externalplugins.TiCommunityIssueTriage{
{
Repos: []string{"org/repo"},
MaintainVersions: []string{"5.1", "5.2", "5.3"},
MaintainVersions: []string{"4.0", "4.1", "5.1", "5.2", "5.3"},
WontfixVersions: []string{"4.0", "4.1"},
AffectsLabelPrefix: "affects/",
MayAffectsLabelPrefix: "may-affects/",
NeedTriagedLabel: "do-not-merge/needs-triage-completed",
Expand Down Expand Up @@ -1831,10 +1868,9 @@ func TestHelpProvider(t *testing.T) {
config: &externalplugins.Configuration{
TiCommunityIssueTriage: []externalplugins.TiCommunityIssueTriage{
{
Repos: []string{"org2/repo"},
MaintainVersions: []string{
"5.1", "5.2", "5.3",
},
Repos: []string{"org2/repo"},
MaintainVersions: []string{"5.1", "5.2", "5.3"},
WontfixVersions: []string{"5.1", "5.2"},
NeedCherryPickLabelPrefix: "needs-cherry-pick-release-",
AffectsLabelPrefix: "affects/",
MayAffectsLabelPrefix: "may-affects/",
Expand All @@ -1850,6 +1886,8 @@ func TestHelpProvider(t *testing.T) {
"The need triaged label prefix is:",
"The need cherry-pick label prefix is:",
"The status details will be targeted to:",
"The release branches that the current repository is maintaining:",
"The release branches won't fix in the current repository:",
},
configInfoExcludes: []string{},
},
Expand Down

0 comments on commit 6927685

Please sign in to comment.