@@ -4,11 +4,9 @@ import (
44 "context"
55 "encoding/json"
66 "fmt"
7- "strconv"
87 "strings"
98
109 bbv1 "github.com/gfleury/go-bitbucket-v1"
11- "github.com/mitchellh/mapstructure"
1210 "github.com/openshift-pipelines/pipelines-as-code/pkg/acl"
1311 "github.com/openshift-pipelines/pipelines-as-code/pkg/params/info"
1412)
@@ -53,6 +51,8 @@ func (v *Provider) checkOkToTestCommentFromApprovedMember(ctx context.Context, e
5351 if nextPage > 0 {
5452 localVarOptionals ["start" ] = int (nextPage )
5553 }
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
5656 return v .Client .DefaultApi .GetActivities (v .projectKey , event .Repository , v .pullRequestNumber , localVarOptionals )
5757 })
5858 if err != nil {
@@ -94,66 +94,27 @@ func (v *Provider) checkOkToTestCommentFromApprovedMember(ctx context.Context, e
9494 return false , nil
9595}
9696
97- func (v * Provider ) checkMemberShipResults (results []any , event * info.Event ) (bool , error ) {
98- accountintid , err := strconv .Atoi (event .AccountID )
99- if err != nil {
100- return false , err
101- }
102- for _ , row := range results {
103- user := & bbv1.UserPermission {}
104- err := mapstructure .Decode (row , user )
105- if err != nil {
106- return false , err
107- }
108-
109- if user .User .ID == accountintid {
110- return true , nil
111- }
112- }
113- return false , nil
114- }
115-
11697func (v * Provider ) checkMemberShip (ctx context.Context , event * info.Event ) (bool , error ) {
11798 // Get permissions from project
118- allValues , err := paginate (func (nextPage int ) (* bbv1.APIResponse , error ) {
119- localVarOptionals := map [string ]any {}
120- if nextPage > 0 {
121- localVarOptionals ["start" ] = int (nextPage )
122- }
123- return v .Client .DefaultApi .GetUsersWithAnyPermission_23 (v .projectKey , localVarOptionals )
124- })
125- if err != nil {
126- return false , err
127- }
128- allowed , err := v .checkMemberShipResults (allValues , event )
99+ allowed , _ , err := v .ScmClient .Organizations .IsMember (ctx , event .Organization , event .Sender )
129100 if err != nil {
130101 return false , err
131102 }
132103 if allowed {
133104 return true , nil
134105 }
135106
107+ orgAndRepo := fmt .Sprintf ("%s/%s" , event .Organization , event .Repository )
136108 // Get permissions from repo
137- allValues , err = paginate (func (nextPage int ) (* bbv1.APIResponse , error ) {
138- localVarOptionals := map [string ]any {}
139- if nextPage > 0 {
140- localVarOptionals ["start" ] = int (nextPage )
141- }
142- return v .Client .DefaultApi .GetUsersWithAnyPermission_24 (v .projectKey , event .Repository , localVarOptionals )
143- })
144- if err != nil {
145- return false , err
146- }
147-
148- allowed , err = v .checkMemberShipResults (allValues , event )
109+ allowed , _ , err = v .ScmClient .Repositories .IsCollaborator (ctx , orgAndRepo , event .Sender )
149110 if err != nil {
150111 return false , err
151112 }
152113 if allowed {
153114 return true , nil
154115 }
155116
156- // Check if sender (which in bitbucket-datacenter mean the accountID) is inside the Owner file
117+ // Check if sender is inside the Owner file
157118 // in the 'main' branch Silently ignore error, which should be fine it
158119 // probably means the OWNERS file is not created. If we had another error
159120 // (ie: like API) we probably would have hit it already.
0 commit comments