diff --git a/README.md b/README.md
index 6fd3752..d5a0704 100644
--- a/README.md
+++ b/README.md
@@ -200,7 +200,7 @@ This validator checks if the branch name of the pull request satisfies the regul
Filling the input with an empty string will disabled this validator.
-### Pull request refers to an issue
+### Pull request links to an issue
@@ -213,9 +213,9 @@ Filling the input with an empty string will disabled this validator.
-This validator checks if the pull request mentions one or more issues in the pull request body.
+This validator checks if the pull request is linked one or more issues.
-Do note that linking the issue directly on the pull request is currently unsupported and does not considered as issue mentions.
+Do note that linking the issue using [special keywords](https://docs.github.com/en/issues/tracking-your-work-with-issues/linking-a-pull-request-to-an-issue) only works when the target branch is the default branch.
### Pull request does not introduce too many changes
@@ -292,7 +292,6 @@ Ideally, Conventional PR workflow should only triggered when an event related to
## Caveats
-- If the issues are linked manually and are not mentioned in the pull request body, the pull request is still considered to be invalid. Currently, there is no way to avoid this issue.
- `edit` feature cannot be used with `github-actions` credentials as it [doesn't have the `user` scope](https://docs.github.com/en/actions/security-guides/automatic-token-authentication#permissions-for-the-github_token). If you want to use the `edit` feature, please generate a [personal access token](https://docs.github.com/en/free-pro-team@latest/github/authenticating-to-github/creating-a-personal-access-token) instead with `read:user` scope. `edit` **cannot** be combined with `report`.
- It is recommended to use a dedicated dummy account if you want to use the `edit` feature as it may lead to unintended edits.
diff --git a/internal/validator/issue.go b/internal/validator/issue.go
index 572e046..c652ad3 100644
--- a/internal/validator/issue.go
+++ b/internal/validator/issue.go
@@ -1,10 +1,6 @@
package validator
import (
- "context"
- "regexp"
- "strconv"
-
"github.com/Namchee/conventional-pr/internal"
"github.com/Namchee/conventional-pr/internal/constants"
"github.com/Namchee/conventional-pr/internal/entity"
@@ -41,21 +37,13 @@ func (v *issueValidator) IsValid(pullRequest *github.PullRequest) *entity.Valida
}
}
- ctx := context.Background()
- pattern := regexp.MustCompile(`#(\d+)`)
-
- mentions := pattern.FindAllStringSubmatch(pullRequest.GetBody(), -1)
-
- for _, mention := range mentions {
- num, _ := strconv.Atoi(mention[1])
- issue, err := v.client.GetIssue(ctx, v.meta.Owner, v.meta.Name, num)
+ issue := pullRequest.GetLinks().GetIssue()
- if err == nil && issue != nil {
- return &entity.ValidationResult{
- Name: v.Name,
- Active: true,
- Result: nil,
- }
+ if issue != nil {
+ return &entity.ValidationResult{
+ Name: v.Name,
+ Active: true,
+ Result: nil,
}
}
diff --git a/internal/validator/issue_test.go b/internal/validator/issue_test.go
index 1ceb3a8..e423a32 100644
--- a/internal/validator/issue_test.go
+++ b/internal/validator/issue_test.go
@@ -12,8 +12,8 @@ import (
func TestIssueValidator_IsValid(t *testing.T) {
type args struct {
- config bool
- body string
+ config bool
+ pullRequest *github.PullRequest
}
tests := []struct {
name string
@@ -23,7 +23,13 @@ func TestIssueValidator_IsValid(t *testing.T) {
{
name: "should allow issue references",
args: args{
- body: "Closes #123",
+ pullRequest: &github.PullRequest{
+ Links: &github.PRLinks{
+ Issue: &github.PRLink{
+ HRef: github.String("abc"),
+ },
+ },
+ },
config: true,
},
want: &entity.ValidationResult{
@@ -35,7 +41,7 @@ func TestIssueValidator_IsValid(t *testing.T) {
{
name: "should be skipped if disabled",
args: args{
- body: "Closes #123",
+ pullRequest: &github.PullRequest{},
},
want: &entity.ValidationResult{
Name: constants.IssueValidatorName,
@@ -46,20 +52,8 @@ func TestIssueValidator_IsValid(t *testing.T) {
{
name: "should reject if no issue at all",
args: args{
- body: "this is a fake body",
- config: true,
- },
- want: &entity.ValidationResult{
- Name: constants.IssueValidatorName,
- Active: true,
- Result: constants.ErrNoIssue,
- },
- },
- {
- name: "should distinguih false alarm",
- args: args{
- body: "This is a fake issue #69",
- config: true,
+ pullRequest: &github.PullRequest{},
+ config: true,
},
want: &entity.ValidationResult{
Name: constants.IssueValidatorName,
@@ -71,10 +65,6 @@ func TestIssueValidator_IsValid(t *testing.T) {
for _, tc := range tests {
t.Run(tc.name, func(t *testing.T) {
- pull := &github.PullRequest{
- Body: &tc.args.body,
- }
-
client := mocks.NewGithubClientMock()
config := &entity.Configuration{
Issue: tc.args.config,
@@ -82,7 +72,7 @@ func TestIssueValidator_IsValid(t *testing.T) {
validator := NewIssueValidator(client, config, &entity.Meta{})
- got := validator.IsValid(pull)
+ got := validator.IsValid(tc.args.pullRequest)
assert.Equal(t, got, tc.want)
})