Improve comment messages (#71)
diff --git a/docbot/action.go b/docbot/action.go
index f8deead..407bc70 100644
--- a/docbot/action.go
+++ b/docbot/action.go
@@ -13,10 +13,7 @@
)
const (
- MessageLabelMissing = `Please provide a correct documentation label for your PR.
-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).`
+ MessageLabelMultiple = "Please select only one documentation label in your PR description."
openedActionType = "opened"
editedActionType = "edited"
@@ -24,6 +21,15 @@
unlabeledActionType = "unlabeled"
)
+var builtInDescriptions = make(map[string]string)
+
+func init() {
+ builtInDescriptions["doc-required"] = "Your PR changes impact docs and you will update later"
+ builtInDescriptions["doc-not-needed"] = "Your PR changes do not impact docs"
+ builtInDescriptions["doc"] = "Your PR contains doc changes"
+ builtInDescriptions["doc-complete"] = "Docs have been already added"
+}
+
type Action struct {
config *ActionConfig
@@ -117,7 +123,7 @@
labelsToAdd[a.config.GetLabelMissing()] = struct{}{}
} else {
logger.Infoln("Already added missing label.")
- return errors.New(MessageLabelMissing)
+ return errors.New(a.getLabelMissingMessage())
}
} else {
if !a.config.GetEnableLabelMultiple() && checkedCount > 1 {
@@ -170,11 +176,11 @@
}
if checkedCount == 0 {
- err := a.addAndCleanupHelpComment(pr.User.GetLogin(), MessageLabelMissing)
+ err := a.addAndCleanupHelpComment(pr.User.GetLogin(), a.getLabelMissingMessage())
if err != nil {
return err
}
- return errors.New(MessageLabelMissing)
+ return errors.New(a.getLabelMissingMessage())
}
return nil
@@ -319,3 +325,19 @@
return nil
}
+
+func (a *Action) getLabelMissingMessage() string {
+ msg := "Please add the following content to your PR description and select a checkbox:\n```\n"
+
+ for _, label := range a.config.labelWatchList {
+ desc := ""
+ if value, found := builtInDescriptions[label]; found {
+ desc = fmt.Sprintf("<!-- %s -->", value)
+ }
+ msg += fmt.Sprintf("- [ ] `%s` %s\n", label, desc)
+ }
+
+ msg += "```"
+
+ return msg
+}
diff --git a/docbot/action_config.go b/docbot/action_config.go
index 34a810e..e39ea72 100644
--- a/docbot/action_config.go
+++ b/docbot/action_config.go
@@ -13,6 +13,7 @@
labelPattern *string
labelWatchSet map[string]struct{}
+ labelWatchList []string
labelMissing *string
enableLabelMissing *bool
enableLabelMultiple *bool
@@ -34,14 +35,18 @@
}
labelWatchListSlug := os.Getenv("LABEL_WATCH_LIST")
- labelWatchList := strings.Split(labelWatchListSlug, ",")
labelWatchSet := make(map[string]struct{})
- for _, l := range labelWatchList {
+ labelWatchList := make([]string, 0)
+ for _, l := range strings.Split(labelWatchListSlug, ",") {
key := strings.TrimSpace(l)
if key == "" {
continue
}
- labelWatchSet[key] = struct{}{}
+ _, found := labelWatchSet[key]
+ if !found {
+ labelWatchSet[key] = struct{}{}
+ labelWatchList = append(labelWatchList, key)
+ }
}
enableLabelMissingSlug := os.Getenv("ENABLE_LABEL_MISSING")
@@ -67,6 +72,7 @@
owner: &owner,
labelPattern: &labelPattern,
labelWatchSet: labelWatchSet,
+ labelWatchList: labelWatchList,
labelMissing: &labelMissing,
enableLabelMissing: &enableLabelMissing,
enableLabelMultiple: &enableLabelMultiple,
diff --git a/docbot/action_test.go b/docbot/action_test.go
index fccefe0..b31d790 100644
--- a/docbot/action_test.go
+++ b/docbot/action_test.go
@@ -184,7 +184,7 @@
action := NewActionWithClient(context.Background(), config, github.NewClient(mockedHTTPClient))
err := action.Run(1, openedActionType)
- assertMessageLabel(t, err, MessageLabelMissing)
+ assertMessageLabel(t, err, action.getLabelMissingMessage())
}
func TestMultipleChecked_WhenMultipleLabelsNotEnabled(t *testing.T) {
@@ -316,7 +316,7 @@
action := NewActionWithClient(context.Background(), config, github.NewClient(mockedHTTPClient))
err := action.Run(1, openedActionType)
- assertMessageLabel(t, err, MessageLabelMissing)
+ assertMessageLabel(t, err, action.getLabelMissingMessage())
}
func TestSingleChecked_WhenDocLabelExists(t *testing.T) {