@@ -4,11 +4,9 @@ import (
4
4
"context"
5
5
"encoding/json"
6
6
"fmt"
7
- "strconv"
8
7
"strings"
9
8
10
9
bbv1 "github.com/gfleury/go-bitbucket-v1"
11
- "github.com/mitchellh/mapstructure"
12
10
"github.com/openshift-pipelines/pipelines-as-code/pkg/acl"
13
11
"github.com/openshift-pipelines/pipelines-as-code/pkg/params/info"
14
12
)
@@ -53,6 +51,8 @@ func (v *Provider) checkOkToTestCommentFromApprovedMember(ctx context.Context, e
53
51
if nextPage > 0 {
54
52
localVarOptionals ["start" ] = int (nextPage )
55
53
}
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
56
return v .Client .DefaultApi .GetActivities (v .projectKey , event .Repository , v .pullRequestNumber , localVarOptionals )
57
57
})
58
58
if err != nil {
@@ -94,66 +94,27 @@ func (v *Provider) checkOkToTestCommentFromApprovedMember(ctx context.Context, e
94
94
return false , nil
95
95
}
96
96
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
-
116
97
func (v * Provider ) checkMemberShip (ctx context.Context , event * info.Event ) (bool , error ) {
117
98
// 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 )
129
100
if err != nil {
130
101
return false , err
131
102
}
132
103
if allowed {
133
104
return true , nil
134
105
}
135
106
107
+ orgAndRepo := fmt .Sprintf ("%s/%s" , event .Organization , event .Repository )
136
108
// 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 )
149
110
if err != nil {
150
111
return false , err
151
112
}
152
113
if allowed {
153
114
return true , nil
154
115
}
155
116
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
157
118
// in the 'main' branch Silently ignore error, which should be fine it
158
119
// probably means the OWNERS file is not created. If we had another error
159
120
// (ie: like API) we probably would have hit it already.
0 commit comments