Skip to content

Commit c37a213

Browse files
committed
fix: Use pull request number from issue comment payload
this uses the pull request number from issue commnet payload instead of doing hack to getting the number from pull request URL. Signed-off-by: Zaki Shaikh <zashaikh@redhat.com>
1 parent baf49e3 commit c37a213

4 files changed

Lines changed: 10 additions & 18 deletions

File tree

pkg/provider/github/acl.go

Lines changed: 3 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -142,14 +142,14 @@ func (v *Provider) aclAllowedOkToTestFromAnOwner(ctx context.Context, event *inf
142142
if !v.pacInfo.RememberOKToTest {
143143
return v.aclAllowedOkToTestCurrentComment(ctx, revent, event.Comment.GetID())
144144
}
145-
revent.URL = event.Issue.GetPullRequestLinks().GetHTMLURL()
145+
revent.PullRequestNumber = event.GetIssue().GetNumber()
146146
case *github.PullRequestEvent:
147147
// if we don't need to check old comments, then on push event we don't need
148148
// to check anything for the non-allowed user
149149
if !v.pacInfo.RememberOKToTest {
150150
return false, nil
151151
}
152-
revent.URL = event.GetPullRequest().GetHTMLURL()
152+
revent.PullRequestNumber = event.GetPullRequest().GetNumber()
153153
default:
154154
return false, nil
155155
}
@@ -330,10 +330,6 @@ func (v *Provider) getFileFromDefaultBranch(ctx context.Context, path string, ru
330330
// the comments text of a pull request.
331331
func (v *Provider) GetStringPullRequestComment(ctx context.Context, runevent *info.Event) ([]*github.IssueComment, error) {
332332
var ret []*github.IssueComment
333-
prNumber, err := convertPullRequestURLtoNumber(runevent.URL)
334-
if err != nil {
335-
return nil, err
336-
}
337333

338334
opt := &github.IssueListCommentsOptions{
339335
ListOptions: github.ListOptions{PerPage: v.PaginedNumber},
@@ -344,7 +340,7 @@ func (v *Provider) GetStringPullRequestComment(ctx context.Context, runevent *in
344340
for page := 0; page < maxCommentPages; page++ {
345341
comments, resp, err := wrapAPI(v, "list_issue_comments", func() ([]*github.IssueComment, *github.Response, error) {
346342
return v.Client().Issues.ListComments(ctx, runevent.Organization, runevent.Repository,
347-
prNumber, opt)
343+
runevent.PullRequestNumber, opt)
348344
})
349345
if err != nil {
350346
return nil, err

pkg/provider/github/acl_test.go

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -125,6 +125,7 @@ func TestOkToTestComment(t *testing.T) {
125125
PullRequestLinks: &github.PullRequestLinks{
126126
HTMLURL: github.Ptr("http://url.com/owner/repo/1"),
127127
},
128+
Number: github.Ptr(1),
128129
},
129130
},
130131
},
@@ -142,6 +143,7 @@ func TestOkToTestComment(t *testing.T) {
142143
Event: &github.PullRequestEvent{
143144
PullRequest: &github.PullRequest{
144145
HTMLURL: github.Ptr("http://url.com/owner/repo/1"),
146+
Number: github.Ptr(1),
145147
},
146148
},
147149
},
@@ -178,6 +180,7 @@ func TestOkToTestComment(t *testing.T) {
178180
PullRequestLinks: &github.PullRequestLinks{
179181
HTMLURL: github.Ptr("http://url.com/owner/repo/1"),
180182
},
183+
Number: github.Ptr(1),
181184
},
182185
},
183186
},
@@ -197,6 +200,7 @@ func TestOkToTestComment(t *testing.T) {
197200
PullRequestLinks: &github.PullRequestLinks{
198201
HTMLURL: github.Ptr("http://url.com/owner/repo/1"),
199202
},
203+
Number: github.Ptr(1),
200204
},
201205
},
202206
},
@@ -308,6 +312,7 @@ func TestOkToTestComment(t *testing.T) {
308312
PullRequestLinks: &github.PullRequestLinks{
309313
HTMLURL: github.Ptr("http://url.com/owner/repo/1"),
310314
},
315+
Number: github.Ptr(1),
311316
},
312317
},
313318
},

pkg/provider/github/github_test.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -870,13 +870,13 @@ func TestGetStringPullRequestComment(t *testing.T) {
870870
}{
871871
{
872872
name: "Get String from comments",
873-
runevent: info.Event{URL: "http://1"},
873+
runevent: info.Event{URL: "http://1", PullRequestNumber: 1},
874874
apiReturn: `[{"body": "/ok-to-test"}]`,
875875
wantRet: true,
876876
},
877877
{
878878
name: "Not matching string in comments",
879-
runevent: info.Event{URL: "http://1"},
879+
runevent: info.Event{URL: "http://1", PullRequestNumber: 1},
880880
apiReturn: `[{"body": ""}]`,
881881
wantRet: false,
882882
},

pkg/provider/github/parse_payload.go

Lines changed: 0 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,6 @@ import (
88
"fmt"
99
"net/http"
1010
"os"
11-
"path"
1211
"strconv"
1312
"strings"
1413
"time"
@@ -593,14 +592,6 @@ func (v *Provider) handleCheckSuites(ctx context.Context, event *github.CheckSui
593592
return v.getPullRequest(ctx, runevent)
594593
}
595594

596-
func convertPullRequestURLtoNumber(pullRequest string) (int, error) {
597-
prNumber, err := strconv.Atoi(path.Base(pullRequest))
598-
if err != nil {
599-
return -1, fmt.Errorf("bad pull request number html_url number: %w", err)
600-
}
601-
return prNumber, nil
602-
}
603-
604595
const (
605596
errSHANotProvided = "a SHA is required in `/ok-to-test` comments, but none was provided"
606597
errSHANotProvidedComment = "The `/ok-to-test` needs to be followed by a SHA to verify which commit to test. Try again with:\n\n`/ok-to-test %s`"

0 commit comments

Comments
 (0)