@@ -185,10 +185,8 @@ func (r *Repo) SetGitHubToken(tokenFile string) error {
185
185
if err != nil {
186
186
return err
187
187
}
188
-
189
188
r .Token = strings .Trim (string (token ), "\n \r " )
190
189
}
191
-
192
190
return nil
193
191
}
194
192
@@ -205,10 +203,7 @@ func (r *Repo) getProposalTemplate() ([]byte, error) {
205
203
}
206
204
207
205
func (r * Repo ) findLocalKEPMeta (sig string ) ([]string , error ) {
208
- sigPath := filepath .Join (
209
- r .ProposalPath ,
210
- sig ,
211
- )
206
+ sigPath := filepath .Join (r .ProposalPath , sig )
212
207
213
208
keps := []string {}
214
209
@@ -240,6 +235,10 @@ func (r *Repo) findLocalKEPMeta(sig string) ([]string, error) {
240
235
241
236
if info .Name () == ProposalMetadataFilename {
242
237
logrus .Debugf ("adding %s as KEP metadata" , info .Name ())
238
+ path , err = filepath .Rel (r .BasePath , path )
239
+ if err != nil {
240
+ return err
241
+ }
243
242
keps = append (keps , path )
244
243
return filepath .SkipDir
245
244
}
@@ -269,27 +268,41 @@ func (r *Repo) LoadLocalKEPs(sig string) ([]*api.Proposal, error) {
269
268
logrus .Debugf ("loading the following local KEPs: %v" , files )
270
269
271
270
var allKEPs []* api.Proposal
272
- for _ , k := range files {
273
- if filepath .Ext (k ) == ".yaml" {
274
- kep , err := r .loadKEPFromYaml (k )
275
- if err != nil {
276
- return nil , errors .Wrapf (
277
- err ,
278
- "reading KEP %s from yaml" ,
279
- k ,
280
- )
281
- }
282
-
283
- allKEPs = append (allKEPs , kep )
271
+ for _ , kepYamlPath := range files {
272
+ kep , err := r .loadKEPFromYaml (r .BasePath , kepYamlPath )
273
+ if err != nil {
274
+ return nil , errors .Wrapf (
275
+ err ,
276
+ "reading KEP %s from yaml" ,
277
+ kepYamlPath ,
278
+ )
284
279
}
280
+
281
+ allKEPs = append (allKEPs , kep )
285
282
}
286
283
287
284
logrus .Debugf ("returning %d local KEPs" , len (allKEPs ))
288
285
289
286
return allKEPs , nil
290
287
}
291
288
292
- func (r * Repo ) loadKEPPullRequests (sig string ) ([]* api.Proposal , error ) {
289
+ func (r * Repo ) LoadLocalKEP (sig , name string ) (* api.Proposal , error ) {
290
+ kepPath := filepath .Join (
291
+ ProposalPathStub ,
292
+ sig ,
293
+ name ,
294
+ ProposalMetadataFilename ,
295
+ )
296
+
297
+ _ , err := os .Stat (kepPath )
298
+ if err != nil {
299
+ return nil , errors .Wrapf (err , "getting file info for %s" , kepPath )
300
+ }
301
+
302
+ return r .loadKEPFromYaml (r .BasePath , kepPath )
303
+ }
304
+
305
+ func (r * Repo ) LoadPullRequestKEPs (sig string ) ([]* api.Proposal , error ) {
293
306
// Initialize github client
294
307
logrus .Debugf ("Initializing github client to load PRs for sig: %v" , sig )
295
308
var auth * http.Client
@@ -331,6 +344,7 @@ func (r *Repo) loadKEPPullRequests(sig string) ([]*api.Proposal, error) {
331
344
}
332
345
}
333
346
347
+ // Find KEP PRs for the given sig
334
348
kepPRs := []* github.PullRequest {}
335
349
sigLabel := strings .Replace (sig , "-" , "/" , 1 )
336
350
logrus .Debugf ("Searching list of %v PRs for %v/%v with labels: [%v, %v]" , len (r .allPRs ), remoteOrg , remoteRepo , sigLabel , proposalLabel )
@@ -422,7 +436,13 @@ func (r *Repo) loadKEPPullRequests(sig string) ([]*api.Proposal, error) {
422
436
423
437
// read all these KEPs
424
438
for k := range kepNames {
425
- kep , err := r .ReadKEP (sig , k )
439
+ kepPath := filepath .Join (
440
+ ProposalPathStub ,
441
+ sig ,
442
+ k ,
443
+ ProposalMetadataFilename ,
444
+ )
445
+ kep , err := r .loadKEPFromYaml (r .gitRepo .Directory (), kepPath )
426
446
if err != nil {
427
447
logrus .Warnf ("error reading KEP %v: %v" , k , err )
428
448
} else {
@@ -435,26 +455,13 @@ func (r *Repo) loadKEPPullRequests(sig string) ([]*api.Proposal, error) {
435
455
return allKEPs , nil
436
456
}
437
457
438
- func (r * Repo ) ReadKEP (sig , name string ) (* api.Proposal , error ) {
439
- kepPath := filepath .Join (
440
- r .ProposalPath ,
441
- sig ,
442
- name ,
443
- ProposalMetadataFilename ,
444
- )
445
-
446
- _ , err := os .Stat (kepPath )
447
- if err != nil {
448
- return nil , errors .Wrapf (err , "getting file info for %s" , kepPath )
449
- }
450
-
451
- return r .loadKEPFromYaml (kepPath )
452
- }
453
-
454
- func (r * Repo ) loadKEPFromYaml (kepPath string ) (* api.Proposal , error ) {
455
- b , err := ioutil .ReadFile (kepPath )
458
+ // loadKEPFromYaml will return a Proposal from a kep.yaml at the given kepPath
459
+ // within the given repoPath, or an error if the Proposal is invalid
460
+ func (r * Repo ) loadKEPFromYaml (repoPath , kepPath string ) (* api.Proposal , error ) {
461
+ fullKEPPath := filepath .Join (repoPath , kepPath )
462
+ b , err := ioutil .ReadFile (fullKEPPath )
456
463
if err != nil {
457
- return nil , fmt .Errorf ("unable to read KEP metadata: %s" , err )
464
+ return nil , fmt .Errorf ("unable to read KEP metadata for %s: %w" , fullKEPPath , err )
458
465
}
459
466
460
467
var p api.Proposal
@@ -464,24 +471,22 @@ func (r *Repo) loadKEPFromYaml(kepPath string) (*api.Proposal, error) {
464
471
}
465
472
466
473
p .Name = filepath .Base (filepath .Dir (kepPath ))
474
+ prrApprovalPath := filepath .Join (repoPath , ProposalPathStub , PRRApprovalPathStub )
467
475
468
476
// Read the PRR approval file and add any listed PRR approvers in there
469
477
// to the PRR approvers list in the KEP. this is a hack while we transition
470
478
// away from PRR approvers listed in kep.yaml
471
479
handler := r .PRRHandler
472
- err = kepval .ValidatePRR (& p , handler , r . PRRApprovalPath )
480
+ err = kepval .ValidatePRR (& p , handler , prrApprovalPath )
473
481
if err != nil {
474
482
logrus .Errorf (
475
483
"%v" ,
476
484
errors .Wrapf (err , "validating PRR for %s" , p .Name ),
477
485
)
478
486
} else {
479
- prrPath := filepath .Dir (kepPath )
480
- prrPath = filepath .Dir (prrPath )
481
- sig := filepath .Base (prrPath )
482
- prrPath = filepath .Join (
483
- filepath .Dir (prrPath ),
484
- PRRApprovalPathStub ,
487
+ sig := filepath .Base (filepath .Dir (filepath .Dir (kepPath )))
488
+ prrPath := filepath .Join (
489
+ prrApprovalPath ,
485
490
sig ,
486
491
p .Number + ".yaml" ,
487
492
)
0 commit comments