3
3
import github3
4
4
import json
5
5
import requests
6
+ from semantic_version import Version
6
7
import yaml
7
8
9
+ # .gitconsensus.yaml files with versions higher than this will be ignored.
10
+ max_consensus_version = Version ('3.0.0' , partial = True )
11
+
8
12
message_template = """
9
13
This Pull Request has been %s by [GitConsensus](https://www.gitconsensus.com/).
10
14
@@ -80,6 +84,11 @@ def __init__(self, user, repository, client):
80
84
"timeout" : self .rules .get ('timeout' )
81
85
}
82
86
87
+ # Treat higher version consensus rules are an unconfigured repository.
88
+ project_consensus_version = Version (str (self .rules ['version' ]), partial = True )
89
+ if max_consensus_version < project_consensus_version :
90
+ self .rules = False
91
+
83
92
def getPullRequests (self ):
84
93
prs = self .repository .iter_pulls (state = "open" )
85
94
retpr = []
@@ -251,6 +260,8 @@ def validate(self):
251
260
return self .consensus .validate (self )
252
261
253
262
def shouldClose (self ):
263
+ if not self .repository .rules :
264
+ return False
254
265
if 'pull_requests' not in self .repository .rules :
255
266
return False
256
267
if 'timeout' in self .repository .rules ['pull_requests' ]:
@@ -265,6 +276,8 @@ def close(self):
265
276
self .commentAction ('closed' )
266
277
267
278
def vote_merge (self ):
279
+ if not self .repository .rules :
280
+ return False
268
281
self .pr .merge ('GitConsensus Merge' )
269
282
self .addLabels (['gc-merged' ])
270
283
self .cleanInfoLabels ()
@@ -393,6 +406,8 @@ def __init__(self, rules):
393
406
self .rules = rules
394
407
395
408
def validate (self , pr ):
409
+ if not self .rules :
410
+ return False
396
411
if pr .isBlocked ():
397
412
return False
398
413
if not self .isAllowed (pr ):
@@ -408,6 +423,8 @@ def validate(self, pr):
408
423
return True
409
424
410
425
def isAllowed (self , pr ):
426
+ if not self .rules :
427
+ return False
411
428
if pr .changesLicense ():
412
429
if 'license_lock' in self .rules ['pull_requests' ] and self .rules ['pull_requests' ]['license_lock' ]:
413
430
return False
@@ -417,17 +434,23 @@ def isAllowed(self, pr):
417
434
return True
418
435
419
436
def isMergeable (self , pr ):
437
+ if not self .rules :
438
+ return False
420
439
if not pr .pr .mergeable :
421
440
return False
422
441
return True
423
442
424
443
def hasQuorum (self , pr ):
444
+ if not self .rules :
445
+ return False
425
446
if 'quorum' in self .rules ['pull_requests' ]:
426
447
if len (pr .users ) < self .rules ['pull_requests' ]['quorum' ]:
427
448
return False
428
449
return True
429
450
430
451
def hasVotes (self , pr ):
452
+ if not self .rules :
453
+ return False
431
454
if 'threshold' in self .rules ['pull_requests' ]:
432
455
total = (len (pr .yes ) + len (pr .no ))
433
456
if total <= 0 :
@@ -438,6 +461,8 @@ def hasVotes(self, pr):
438
461
return True
439
462
440
463
def hasAged (self , pr ):
464
+ if not self .rules :
465
+ return False
441
466
hours = pr .hoursSinceLastUpdate ()
442
467
if pr .changesLicense ():
443
468
if 'license_delay' in self .rules ['pull_requests' ] and self .rules ['pull_requests' ]['license_delay' ]:
0 commit comments