@@ -19,18 +19,9 @@ package tide
19
19
import (
20
20
"encoding/json"
21
21
"errors"
22
- "fmt"
23
- "strconv"
24
- "sync"
25
22
"time"
26
23
27
24
"github.com/sirupsen/logrus"
28
- utilerrors "k8s.io/apimachinery/pkg/util/errors"
29
- prowapi "k8s.io/test-infra/prow/apis/prowjobs/v1"
30
- "k8s.io/test-infra/prow/config"
31
- "k8s.io/test-infra/prow/git/types"
32
- "k8s.io/test-infra/prow/git/v2"
33
- "k8s.io/test-infra/prow/tide/blockers"
34
25
)
35
26
36
27
// CodeReviewForDeck contains superset of data from CodeReviewCommon, it's meant
@@ -170,140 +161,3 @@ func CodeReviewCommonFromPullRequest(pr *PullRequest) *CodeReviewCommon {
170
161
171
162
return crc
172
163
}
173
-
174
- // provider is the interface implemented by each source code
175
- // providers, such as GitHub and Gerrit.
176
- type provider interface {
177
- Query () (map [string ]CodeReviewCommon , error )
178
- blockers () (blockers.Blockers , error )
179
- isAllowedToMerge (crc * CodeReviewCommon ) (string , error )
180
- GetRef (org , repo , ref string ) (string , error )
181
- // headContexts returns Contexts from all presubmit requirements.
182
- // Tide needs to know whether a PR passed all tests or not, this includes
183
- // prow jobs, but also any external tests that are required by GitHub branch
184
- // protection, for example GH actions. For GitHub these are all reflected on
185
- // status contexts, and more importantly each prowjob is a context. For
186
- // Gerrit we can transform every prow jobs into a context, and mark it
187
- // optional if the prowjob doesn't vote on label that's required for
188
- // merging. And also transform any other label that is not voted by prow
189
- // into a context.
190
- headContexts (pr * CodeReviewCommon ) ([]Context , error )
191
- mergePRs (sp subpool , prs []CodeReviewCommon , dontUpdateStatus * threadSafePRSet ) error
192
- GetTideContextPolicy (gitClient git.ClientFactory , org , repo , branch string , baseSHAGetter config.RefGetter , headSHA string ) (contextChecker , error )
193
- refsForJob (sp subpool , prs []CodeReviewCommon ) prowapi.Refs
194
- prMergeMethod (crc * CodeReviewCommon ) (types.PullRequestMergeType , error )
195
- }
196
-
197
- // GitHubProvider implements provider, used by tide Controller for
198
- // interacting directly with GitHub.
199
- //
200
- // Tide Controller should only use GitHubProvider for communicating with GitHub.
201
- type GitHubProvider struct {
202
- cfg config.Getter
203
- ghc githubClient
204
- usesGitHubAppsAuth bool
205
-
206
- * mergeChecker
207
- logger * logrus.Entry
208
- }
209
-
210
- func (gi * GitHubProvider ) blockers () (blockers.Blockers , error ) {
211
- label := gi .cfg ().Tide .BlockerLabel
212
- if label == "" {
213
- return blockers.Blockers {}, nil
214
- }
215
-
216
- gi .logger .WithField ("blocker_label" , label ).Debug ("Searching for blocker issues" )
217
- orgExcepts , repos := gi .cfg ().Tide .Queries .OrgExceptionsAndRepos ()
218
- orgs := make ([]string , 0 , len (orgExcepts ))
219
- for org := range orgExcepts {
220
- orgs = append (orgs , org )
221
- }
222
- orgRepoQuery := orgRepoQueryStrings (orgs , repos .UnsortedList (), orgExcepts )
223
- return blockers .FindAll (gi .ghc , gi .logger , label , orgRepoQuery , gi .usesGitHubAppsAuth )
224
- }
225
-
226
- // Query gets all open PRs based on tide configuration.
227
- func (gi * GitHubProvider ) Query () (map [string ]CodeReviewCommon , error ) {
228
- lock := sync.Mutex {}
229
- wg := sync.WaitGroup {}
230
- prs := make (map [string ]CodeReviewCommon )
231
- var errs []error
232
- for i , query := range gi .cfg ().Tide .Queries {
233
-
234
- // Use org-sharded queries only when GitHub apps auth is in use
235
- var queries map [string ]string
236
- if gi .usesGitHubAppsAuth {
237
- queries = query .OrgQueries ()
238
- } else {
239
- queries = map [string ]string {"" : query .Query ()}
240
- }
241
-
242
- for org , q := range queries {
243
- org , q , i := org , q , i
244
- wg .Add (1 )
245
- go func () {
246
- defer wg .Done ()
247
- results , err := gi .search (gi .ghc .QueryWithGitHubAppsSupport , gi .logger , q , time.Time {}, time .Now (), org )
248
-
249
- resultString := "success"
250
- if err != nil {
251
- resultString = "error"
252
- }
253
- tideMetrics .queryResults .WithLabelValues (strconv .Itoa (i ), org , resultString ).Inc ()
254
-
255
- lock .Lock ()
256
- defer lock .Unlock ()
257
- if err != nil && len (results ) == 0 {
258
- gi .logger .WithField ("query" , q ).WithError (err ).Warn ("Failed to execute query." )
259
- errs = append (errs , fmt .Errorf ("query %d, err: %w" , i , err ))
260
- return
261
- }
262
- if err != nil {
263
- gi .logger .WithError (err ).WithField ("query" , q ).Warning ("found partial results" )
264
- }
265
-
266
- for _ , pr := range results {
267
- crc := CodeReviewCommonFromPullRequest (& pr )
268
- prs [prKey (crc )] = * crc
269
- }
270
- }()
271
- }
272
- }
273
- wg .Wait ()
274
-
275
- return prs , utilerrors .NewAggregate (errs )
276
- }
277
-
278
- func (gi * GitHubProvider ) GetRef (org , repo , ref string ) (string , error ) {
279
- return gi .ghc .GetRef (org , repo , ref )
280
- }
281
-
282
- func (gi * GitHubProvider ) GetTideContextPolicy (gitClient git.ClientFactory , org , repo , branch string , baseSHAGetter config.RefGetter , headSHA string ) (contextChecker , error ) {
283
- return gi .cfg ().GetTideContextPolicy (gitClient , org , repo , branch , baseSHAGetter , headSHA )
284
- }
285
-
286
- func (gi * GitHubProvider ) refsForJob (sp subpool , prs []CodeReviewCommon ) prowapi.Refs {
287
- refs := prowapi.Refs {
288
- Org : sp .org ,
289
- Repo : sp .repo ,
290
- BaseRef : sp .branch ,
291
- BaseSHA : sp .sha ,
292
- }
293
- for _ , pr := range prs {
294
- refs .Pulls = append (
295
- refs .Pulls ,
296
- prowapi.Pull {
297
- Number : pr .Number ,
298
- Title : pr .Title ,
299
- Author : string (pr .AuthorLogin ),
300
- SHA : pr .HeadRefOID ,
301
- },
302
- )
303
- }
304
- return refs
305
- }
306
-
307
- func (gi * GitHubProvider ) prMergeMethod (crc * CodeReviewCommon ) (types.PullRequestMergeType , error ) {
308
- return gi .mergeChecker .prMergeMethod (gi .cfg ().Tide , crc )
309
- }
0 commit comments