Repository: srvaroa/labeler (go)

Issue:
author-can-merge: false does not seem to work
Hiya,

As one of the criteria in a `labeler.yml` file, I have the following:
``` yml
 labels:
   - label: "Status: triage"
     draft: false
     author-can-merge: false
```

### I'd expect

The `Status: triage` label to be added to all non-draft PRs where the author doesn't have commit rights in the repo.

### What actually happened

The `Status: triage` label does not get added to PRs from outside contributors (who don't have commit rights to the repo).

### Other info

I haven't tested yet if it works when I set it as follows, but if it does, I'd still find that counter-intuitive, as I'd expect `author-can-merge: false` to be respected.

```yml
labels:
  - label: "Status: triage"
    negate: true
    draft: false
    author-can-merge: true
```


Pull request description:
Fix bug in author_can_merge
Fixes #123


Patch:
diff --git a/pkg/condition_author_can_merge.go b/pkg/condition_author_can_merge.go
index 995cee5..0364285 100644
--- a/pkg/condition_author_can_merge.go
+++ b/pkg/condition_author_can_merge.go
@@ -2,6 +2,7 @@ package labeler
 
 import (
 	"fmt"
+	"strconv"
 )
 
 func AuthorCanMergeCondition() Condition {
@@ -10,16 +11,31 @@ func AuthorCanMergeCondition() Condition {
 			return "Author can merge"
 		},
 		CanEvaluate: func(target *Target) bool {
-			return true
+			return target.ghPR != nil
 		},
 		Evaluate: func(target *Target, matcher LabelMatcher) (bool, error) {
-			if len(matcher.AuthorCanMerge) <= 0 {
-				return false, fmt.Errorf("AuthorCanMerge not set in repository")
+			expected, err := strconv.ParseBool(matcher.AuthorCanMerge)
+			if err != nil {
+				return false, fmt.Errorf("author-can-merge doesn't have a valid value in config")
 			}
+
 			ghRepo := target.ghPR.GetAuthorAssociation()
 			canMerge := ghRepo == "OWNER"
-			fmt.Printf("User: %s can merge? %t\n", target.Author, canMerge)
-			return canMerge, nil
+
+			if expected && canMerge {
+				fmt.Printf("User: %s can merge %t, condition matched\n",
+					target.Author, canMerge)
+				return true, nil
+			}
+
+			if !expected && !canMerge {
+				fmt.Printf("User: %s can not merge %t, condition matched\n",
+					target.Author, canMerge)
+				return true, nil
+			}
+
+			fmt.Printf("Condition not matched")
+			return false, nil
 		},
 	}
 }


Test patch:
diff --git a/pkg/labeler_test.go b/pkg/labeler_test.go
index 04296a7..a65edca 100644
--- a/pkg/labeler_test.go
+++ b/pkg/labeler_test.go
@@ -592,7 +592,7 @@ func TestHandleEvent(t *testing.T) {
 		{
 			event:    "pull_request",
 			payloads: []string{"create_pr_non_owner"},
-			name:     "Add a label when the author cannot merge",
+			name:     "Remove a label when the author cannot merge",
 			config: LabelerConfigV1{
 				Version: 1,
 				Labels: []LabelMatcher{
@@ -605,6 +605,56 @@ func TestHandleEvent(t *testing.T) {
 			initialLabels:  []string{"Test"},
 			expectedLabels: []string{},
 		},
+		{
+			event:    "pull_request",
+			payloads: []string{"create_pr_non_owner"},
+			name:     "Add a label when the author cannot merge",
+			config: LabelerConfigV1{
+				Version: 1,
+				Labels: []LabelMatcher{
+					{
+						Label:          "Test",
+						AuthorCanMerge: "False",
+					},
+				},
+			},
+			initialLabels:  []string{},
+			expectedLabels: []string{"Test"},
+		},
+		{
+			event:    "pull_request",
+			payloads: []string{"create_pr"},
+			name:     "Remove label when the author can merge",
+			config: LabelerConfigV1{
+				Version: 1,
+				Labels: []LabelMatcher{
+					{
+						Label:          "Test",
+						AuthorCanMerge: "False",
+					},
+				},
+			},
+			initialLabels:  []string{"Test"},
+			expectedLabels: []string{},
+		},
+		{
+			event:    "pull_request",
+			payloads: []string{"create_pr"},
+			name:     "Negate when the author can merge",
+			config: LabelerConfigV1{
+				Version: 1,
+				Labels: []LabelMatcher{
+					{
+						Label:          "Test",
+						Draft:          "False", // payload is not a draft
+						AuthorCanMerge: "True",  // payload author is the owner
+						Negate:         true,    // both matchers are true, result should be false
+					},
+				},
+			},
+			initialLabels:  []string{"Test"},
+			expectedLabels: []string{},
+		},
 
 		// Issues