33import github3
44import json
55import requests
6+ from semantic_version import Version
67import yaml
78
9+ # .gitconsensus.yaml files with versions higher than this will be ignored.
10+ max_consensus_version = Version ('3.0.0' , partial = True )
11+
812message_template = """
913This Pull Request has been %s by [GitConsensus](https://www.gitconsensus.com/).
1014
@@ -80,6 +84,11 @@ def __init__(self, user, repository, client):
8084 "timeout" : self .rules .get ('timeout' )
8185 }
8286
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+
8392 def getPullRequests (self ):
8493 prs = self .repository .iter_pulls (state = "open" )
8594 retpr = []
@@ -251,6 +260,8 @@ def validate(self):
251260 return self .consensus .validate (self )
252261
253262 def shouldClose (self ):
263+ if not self .repository .rules :
264+ return False
254265 if 'pull_requests' not in self .repository .rules :
255266 return False
256267 if 'timeout' in self .repository .rules ['pull_requests' ]:
@@ -265,6 +276,8 @@ def close(self):
265276 self .commentAction ('closed' )
266277
267278 def vote_merge (self ):
279+ if not self .repository .rules :
280+ return False
268281 self .pr .merge ('GitConsensus Merge' )
269282 self .addLabels (['gc-merged' ])
270283 self .cleanInfoLabels ()
@@ -393,6 +406,8 @@ def __init__(self, rules):
393406 self .rules = rules
394407
395408 def validate (self , pr ):
409+ if not self .rules :
410+ return False
396411 if pr .isBlocked ():
397412 return False
398413 if not self .isAllowed (pr ):
@@ -408,6 +423,8 @@ def validate(self, pr):
408423 return True
409424
410425 def isAllowed (self , pr ):
426+ if not self .rules :
427+ return False
411428 if pr .changesLicense ():
412429 if 'license_lock' in self .rules ['pull_requests' ] and self .rules ['pull_requests' ]['license_lock' ]:
413430 return False
@@ -417,17 +434,23 @@ def isAllowed(self, pr):
417434 return True
418435
419436 def isMergeable (self , pr ):
437+ if not self .rules :
438+ return False
420439 if not pr .pr .mergeable :
421440 return False
422441 return True
423442
424443 def hasQuorum (self , pr ):
444+ if not self .rules :
445+ return False
425446 if 'quorum' in self .rules ['pull_requests' ]:
426447 if len (pr .users ) < self .rules ['pull_requests' ]['quorum' ]:
427448 return False
428449 return True
429450
430451 def hasVotes (self , pr ):
452+ if not self .rules :
453+ return False
431454 if 'threshold' in self .rules ['pull_requests' ]:
432455 total = (len (pr .yes ) + len (pr .no ))
433456 if total <= 0 :
@@ -438,6 +461,8 @@ def hasVotes(self, pr):
438461 return True
439462
440463 def hasAged (self , pr ):
464+ if not self .rules :
465+ return False
441466 hours = pr .hoursSinceLastUpdate ()
442467 if pr .changesLicense ():
443468 if 'license_delay' in self .rules ['pull_requests' ] and self .rules ['pull_requests' ]['license_delay' ]:
0 commit comments