You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@pulsar.apache.org by zi...@apache.org on 2022/09/08 15:17:33 UTC
[pulsar-test-infra] branch master updated: Fix remove labels (#70)
This is an automated email from the ASF dual-hosted git repository.
zixuan pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/pulsar-test-infra.git
The following commit(s) were added to refs/heads/master by this push:
new 19e15d1 Fix remove labels (#70)
19e15d1 is described below
commit 19e15d1ca3d5749dffb9beea3227476fb1427b30
Author: Zixuan Liu <no...@gmail.com>
AuthorDate: Thu Sep 8 23:17:26 2022 +0800
Fix remove labels (#70)
* Fix remove labels
* Fix style
---
docbot/action.go | 17 +++++++++------
docbot/action_test.go | 57 +++++++++++++++++++++++++++++++++++++++++++++------
2 files changed, 62 insertions(+), 12 deletions(-)
diff --git a/docbot/action.go b/docbot/action.go
index 026a9f7..f8deead 100644
--- a/docbot/action.go
+++ b/docbot/action.go
@@ -17,6 +17,11 @@ const (
Instructions see [Pulsar Documentation Label Guide](https://docs.google.com/document/d/1Qw7LHQdXWBW9t2-r-A7QdFDBwmZh6ytB4guwMoXHqc0).`
MessageLabelMultiple = `Please select only one documentation label for your PR.
Instructions see [Pulsar Documentation Label Guide](https://docs.google.com/document/d/1Qw7LHQdXWBW9t2-r-A7QdFDBwmZh6ytB4guwMoXHqc0).`
+
+ openedActionType = "opened"
+ editedActionType = "edited"
+ labeledActionType = "labeled"
+ unlabeledActionType = "unlabeled"
)
type Action struct {
@@ -51,7 +56,7 @@ func (a *Action) Run(prNumber int, actionType string) error {
a.prNumber = prNumber
switch actionType {
- case "opened", "edited", "labeled", "unlabeled":
+ case openedActionType, editedActionType, labeledActionType, unlabeledActionType:
return a.checkLabels()
}
return nil
@@ -68,6 +73,8 @@ func (a *Action) checkLabels() error {
bodyLabels = a.extractLabels(*pr.Body)
}
+ logger.Infof("PR description: %v\n", *pr.Body)
+
logger.Infoln("@List repo labels")
repoLabels, err := a.getRepoLabels()
if err != nil {
@@ -128,11 +135,9 @@ func (a *Action) checkLabels() error {
}
for label, checked := range expectedLabelsMap {
- _, found := prLabels[label]
- if found {
- continue
- }
- if checked {
+ if _, found := prLabels[label]; found && !checked {
+ labelsToRemove[label] = struct{}{}
+ } else if !found && checked {
labelsToAdd[label] = struct{}{}
}
}
diff --git a/docbot/action_test.go b/docbot/action_test.go
index a2af4f6..fccefe0 100644
--- a/docbot/action_test.go
+++ b/docbot/action_test.go
@@ -85,7 +85,7 @@ Need to update docs?
config := mustNewActionConfig()
action := NewActionWithClient(context.Background(), config, github.NewClient(mockedHTTPClient))
- err := action.Run(1, "opened")
+ err := action.Run(1, openedActionType)
if err != nil {
t.Fatal(err)
}
@@ -137,7 +137,7 @@ Need to update docs?
config := mustNewActionConfig()
action := NewActionWithClient(context.Background(), config, github.NewClient(mockedHTTPClient))
- err := action.Run(1, "opened")
+ err := action.Run(1, openedActionType)
if err != nil {
t.Fatal(err)
}
@@ -183,7 +183,7 @@ Need to update docs?
config := mustNewActionConfig()
action := NewActionWithClient(context.Background(), config, github.NewClient(mockedHTTPClient))
- err := action.Run(1, "opened")
+ err := action.Run(1, openedActionType)
assertMessageLabel(t, err, MessageLabelMissing)
}
@@ -227,7 +227,7 @@ Need to update docs?
config := mustNewActionConfig()
action := NewActionWithClient(context.Background(), config, github.NewClient(mockedHTTPClient))
- err := action.Run(1, "opened")
+ err := action.Run(1, openedActionType)
assertMessageLabel(t, err, MessageLabelMultiple)
}
@@ -271,7 +271,7 @@ Need to update docs?
config := mustNewActionConfig()
action := NewActionWithClient(context.Background(), config, github.NewClient(mockedHTTPClient))
- err := action.Run(1, "opened")
+ err := action.Run(1, openedActionType)
if err != nil {
t.Fatal(err)
}
@@ -315,6 +315,51 @@ Need to update docs?
config := mustNewActionConfig()
action := NewActionWithClient(context.Background(), config, github.NewClient(mockedHTTPClient))
- err := action.Run(1, "opened")
+ err := action.Run(1, openedActionType)
assertMessageLabel(t, err, MessageLabelMissing)
}
+
+func TestSingleChecked_WhenDocLabelExists(t *testing.T) {
+ id := int64(1)
+ body := fmt.Sprintf(`
+Check the box below or label this PR directly.
+
+Need to update docs?
+
+- [ ] %s
+(Your PR needs to update docs and you will update later)
+
+- [x] %s
+(Please explain why)
+
+- [ ] %s
+(Your PR contains doc changes)
+
+- [ ] %s
+(Docs have been already added)
+`, "`doc-required`", "`doc-not-needed`", "`doc`", "`doc-complete`")
+
+ docLabel := "doc"
+ mockedHTTPClient := mock.NewMockedHTTPClient(
+ mock.WithRequestMatch(
+ mock.GetReposPullsByOwnerByRepoByPullNumber,
+ github.PullRequest{
+ ID: &id,
+ Body: &body,
+ Labels: []*github.Label{{Name: &docLabel}},
+ },
+ ), mock.WithRequestMatch(
+ mock.GetReposLabelsByOwnerByRepo,
+ repoLabels(),
+ ),
+ mock.WithRequestMatch(mock.PostReposIssuesLabelsByOwnerByRepoByIssueNumber, nil),
+ mock.WithRequestMatch(mock.DeleteReposIssuesLabelsByOwnerByRepoByIssueNumberByName, nil),
+ )
+ config := mustNewActionConfig()
+ action := NewActionWithClient(context.Background(), config, github.NewClient(mockedHTTPClient))
+
+ err := action.Run(1, openedActionType)
+ if err != nil {
+ t.Fatal(err)
+ }
+}