@@ -2,16 +2,14 @@ package bitbucketdatacenter
2
2
3
3
import (
4
4
"context"
5
- "encoding/json"
6
5
"fmt"
7
6
"strings"
8
7
9
- bbv1 "github.com/gfleury/go-bitbucket-v1"
10
8
"github.com/openshift-pipelines/pipelines-as-code/pkg/acl"
11
9
"github.com/openshift-pipelines/pipelines-as-code/pkg/params/info"
12
- )
13
10
14
- type activitiesTypes struct { Values []* bbv1.Activity }
11
+ "github.com/jenkins-x/go-scm/scm"
12
+ )
15
13
16
14
func (v * Provider ) IsAllowed (ctx context.Context , event * info.Event ) (bool , error ) {
17
15
allowed , err := v .checkMemberShip (ctx , event )
@@ -44,50 +42,42 @@ func (v *Provider) IsAllowedOwnersFile(ctx context.Context, event *info.Event) (
44
42
}
45
43
46
44
func (v * Provider ) checkOkToTestCommentFromApprovedMember (ctx context.Context , event * info.Event ) (bool , error ) {
47
- allPages , err := paginate (func (nextPage int ) (* bbv1.APIResponse , error ) {
48
- localVarOptionals := map [string ]any {
49
- "fromType" : "COMMENT" ,
45
+ allComments := []* scm.Comment {}
46
+ OrgAndRepo := fmt .Sprintf ("%s/%s" , event .Organization , event .Repository )
47
+ opts := & scm.ListOptions {Page : 1 , Size : apiResponseLimit }
48
+ for {
49
+ comments , _ , err := v .ScmClient ().PullRequests .ListComments (ctx , OrgAndRepo , v .pullRequestNumber , opts )
50
+ if err != nil {
51
+ return false , err
50
52
}
51
- if nextPage > 0 {
52
- localVarOptionals ["start" ] = int (nextPage )
53
+
54
+ allComments = append (allComments , comments ... )
55
+
56
+ if len (comments ) < apiResponseLimit {
57
+ break
53
58
}
54
- // will replace this API call with jenkins-x/go-scm after my PR on go-scm is merged
55
- // https://github.com/jenkins-x/go-scm/pull/494
56
- return v .Client ().DefaultApi .GetActivities (v .projectKey , event .Repository , v .pullRequestNumber , localVarOptionals )
57
- })
58
- if err != nil {
59
- return false , err
59
+
60
+ opts .Page ++
60
61
}
61
62
62
- for _ , comment := range allPages {
63
- activities := & activitiesTypes {}
64
- cbyte , ok := comment .([]byte )
65
- if ! ok {
66
- return false , fmt .Errorf ("cannot convert comment to bytes" )
67
- }
68
- err := json .Unmarshal (cbyte , activities )
69
- if err != nil {
70
- return false , err
71
- }
72
- for _ , activity := range activities .Values {
73
- if acl .MatchRegexp (acl .OKToTestCommentRegexp , activity .Comment .Text ) {
74
- commenterEvent := info .NewEvent ()
75
- commenterEvent .Sender = activity .Comment .Author .Slug
76
- commenterEvent .AccountID = fmt .Sprintf ("%d" , activity .Comment .Author .ID )
77
- commenterEvent .Event = event .Event
78
- commenterEvent .BaseBranch = event .BaseBranch
79
- commenterEvent .HeadBranch = event .HeadBranch
80
- commenterEvent .Repository = event .Repository
81
- commenterEvent .Organization = v .projectKey
82
- commenterEvent .DefaultBranch = event .DefaultBranch
83
- allowed , err := v .checkMemberShip (ctx , commenterEvent )
84
- if err != nil {
85
- return false , err
86
- }
87
- if allowed {
88
- // TODO: show a log how come this has been allowed
89
- return true , nil
90
- }
63
+ for _ , comment := range allComments {
64
+ if acl .MatchRegexp (acl .OKToTestCommentRegexp , comment .Body ) {
65
+ commenterEvent := info .NewEvent ()
66
+ commenterEvent .Sender = comment .Author .Login
67
+ commenterEvent .AccountID = fmt .Sprintf ("%d" , comment .Author .ID )
68
+ commenterEvent .Event = event .Event
69
+ commenterEvent .BaseBranch = event .BaseBranch
70
+ commenterEvent .HeadBranch = event .HeadBranch
71
+ commenterEvent .Repository = event .Repository
72
+ commenterEvent .Organization = v .projectKey
73
+ commenterEvent .DefaultBranch = event .DefaultBranch
74
+ allowed , err := v .checkMemberShip (ctx , commenterEvent )
75
+ if err != nil {
76
+ return false , err
77
+ }
78
+ if allowed {
79
+ // TODO: show a log how come this has been allowed
80
+ return true , nil
91
81
}
92
82
}
93
83
}
0 commit comments