Skip to content

Commit

Permalink
Treat future version consensus configs are untracked repositories
Browse files Browse the repository at this point in the history
  • Loading branch information
tedivm committed Apr 10, 2018
1 parent 47ccd46 commit 542926b
Show file tree
Hide file tree
Showing 4 changed files with 44 additions and 3 deletions.
25 changes: 25 additions & 0 deletions gitconsensus/repository.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,12 @@
import github3
import json
import requests
from semantic_version import Version
import yaml

# .gitconsensus.yaml files with versions higher than this will be ignored.
max_consensus_version = Version('3.0.0', partial=True)

message_template = """
This Pull Request has been %s by [GitConsensus](https://www.gitconsensus.com/).
Expand Down Expand Up @@ -80,6 +84,11 @@ def __init__(self, user, repository, client):
"timeout": self.rules.get('timeout')
}

# Treat higher version consensus rules are an unconfigured repository.
project_consensus_version = Version(str(self.rules['version']), partial=True)
if max_consensus_version < project_consensus_version:
self.rules = False

def getPullRequests(self):
prs = self.repository.iter_pulls(state="open")
retpr = []
Expand Down Expand Up @@ -251,6 +260,8 @@ def validate(self):
return self.consensus.validate(self)

def shouldClose(self):
if not self.repository.rules:
return False
if 'pull_requests' not in self.repository.rules:
return False
if 'timeout' in self.repository.rules['pull_requests']:
Expand All @@ -265,6 +276,8 @@ def close(self):
self.commentAction('closed')

def vote_merge(self):
if not self.repository.rules:
return False
self.pr.merge('GitConsensus Merge')
self.addLabels(['gc-merged'])
self.cleanInfoLabels()
Expand Down Expand Up @@ -393,6 +406,8 @@ def __init__(self, rules):
self.rules = rules

def validate(self, pr):
if not self.rules:
return False
if pr.isBlocked():
return False
if not self.isAllowed(pr):
Expand All @@ -408,6 +423,8 @@ def validate(self, pr):
return True

def isAllowed(self, pr):
if not self.rules:
return False
if pr.changesLicense():
if 'license_lock' in self.rules['pull_requests'] and self.rules['pull_requests']['license_lock']:
return False
Expand All @@ -417,17 +434,23 @@ def isAllowed(self, pr):
return True

def isMergeable(self, pr):
if not self.rules:
return False
if not pr.pr.mergeable:
return False
return True

def hasQuorum(self, pr):
if not self.rules:
return False
if 'quorum' in self.rules['pull_requests']:
if len(pr.users) < self.rules['pull_requests']['quorum']:
return False
return True

def hasVotes(self, pr):
if not self.rules:
return False
if 'threshold' in self.rules['pull_requests']:
total = (len(pr.yes) + len(pr.no))
if total <= 0:
Expand All @@ -438,6 +461,8 @@ def hasVotes(self, pr):
return True

def hasAged(self, pr):
if not self.rules:
return False
hours = pr.hoursSinceLastUpdate()
if pr.changesLicense():
if 'license_delay' in self.rules['pull_requests'] and self.rules['pull_requests']['license_delay']:
Expand Down
4 changes: 3 additions & 1 deletion makefile
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,12 @@
SHELL:=/bin/bash
ROOT_DIR:=$(shell dirname $(realpath $(lastword $(MAKEFILE_LIST))))

.PHONY: all fresh dependencies install fulluninstall uninstall removedeps
.PHONY: all fresh dependencies clean package

all: dependencies

fresh: clean dependencies

clean:
rm -rf $(ROOT_DIR)/gitconsensus/*.pyc
rm -rf $(ROOT_DIR)/env
Expand Down
15 changes: 14 additions & 1 deletion requirements.txt
Original file line number Diff line number Diff line change
@@ -1,4 +1,17 @@
click==5.0
certifi==2018.1.18
chardet==3.0.4
click==6.7
github3.py==1.0.2
idna==2.6
pkginfo==1.4.2
pypandoc==1.4
python-dateutil==2.7.2
PyYAML==3.12
requests==2.18.4
requests-toolbelt==0.8.0
semantic-version==2.6.0
six==1.11.0
tqdm==4.21.0
twine==1.11.0
uritemplate==3.0.0
urllib3==1.22
3 changes: 2 additions & 1 deletion setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
long_description = open('README.md').read()


version = '0.7.1'
version = '0.7.2'
setup(

name = 'gitconsensus',
Expand Down Expand Up @@ -48,6 +48,7 @@
'github3.py>=1,<2',
'PyYAML>=3.12,<3.13',
'requests>=2.18.0,<2.19',
'semantic_version>=2.6.0,<3'
],

extras_require={
Expand Down

0 comments on commit 542926b

Please sign in to comment.