Skip to content

Commit bcf0704

Browse files
committed
Clean up consensus rules format, auto convert from older versions
1 parent 9ea2b2e commit bcf0704

File tree

2 files changed

+73
-50
lines changed

2 files changed

+73
-50
lines changed

README.md

+36-33
Original file line numberDiff line numberDiff line change
@@ -10,59 +10,62 @@ will be skipped.
1010

1111
```yaml
1212
# Which version of the consensus rules to use
13-
version: 2
13+
version: 3
1414

1515
# Add extra labels for the vote counts and age when merging
1616
extra_labels: false
1717

1818
# Don't count any vote from a user who votes for multiple options
1919
prevent_doubles: true
2020

21-
# Minimum number of voters
22-
quorum: 5
21+
# The following only applies to pull requests
22+
pull_requests:
2323

24-
# Required percentage of "yes" votes (ignoring abstentions)
25-
threshold: 0.65
24+
# Minimum number of voters
25+
quorum: 5
2626

27-
# Only process votes by contributors
28-
contributors_only: false
27+
# Required percentage of "yes" votes (ignoring abstentions)
28+
threshold: 0.65
2929

30-
# Only process votes by collaborators
31-
collaborators_only: false
30+
# Only process votes by contributors
31+
contributors_only: false
3232

33-
# When defined only process votes from these github users
34-
whitelist:
35-
- alice
36-
- carol
33+
# Only process votes by collaborators
34+
collaborators_only: false
3735

38-
# When defined votes from these users will be ignored
39-
blacklist:
40-
- bob
41-
- dan
36+
# When defined only process votes from these github users
37+
whitelist:
38+
- alice
39+
- carol
4240

43-
# Number of hours after last action (commit or opening the pull request) before issue can be merged
44-
mergedelay: 24
41+
# When defined votes from these users will be ignored
42+
blacklist:
43+
- bob
44+
- dan
4545

46-
# Number of votes from contributors at which the mergedelay gets ignored, assuming no negative votes.
47-
delayoverride: 10
46+
# Number of hours after last action (commit or opening the pull request) before issue can be merged
47+
merge_delay: 24
4848

49-
# When `delayoverride` is set this value is the minimum hours without changes before the PR will be merged
50-
mergedelaymin: 1
49+
# Number of votes from contributors at which the mergedelay gets ignored, assuming no negative votes.
50+
delay_override: 10
5151

52-
# Require this amount of time in hours before a PR with a license change will be merged.
53-
licensedelay: 72
52+
# When `delayoverride` is set this value is the minimum hours without changes before the PR will be merged
53+
merge_delay_min: 1
5454

55-
# Require this amount of time in hours before a PR with a consensus change will be merged.
56-
consensusdelay: 72
55+
# Require this amount of time in hours before a PR with a license change will be merged.
56+
licensed_delay: 72
5757

58-
# Do not allow license changes to be merged.
59-
locklicense: true
58+
# Require this amount of time in hours before a PR with a consensus change will be merged.
59+
consensus_delay: 72
6060

61-
# Do not allow consensus changes to be merged.
62-
lockconsensus: true
61+
# Do not allow license changes to be merged.
62+
license_lock: true
6363

64-
# Number of hours after last action (commit or opening the pull request) before issue is autoclosed
65-
timeout: 720
64+
# Do not allow consensus changes to be merged.
65+
consensus_lock: true
66+
67+
# Number of hours after last action (commit or opening the pull request) before issue is autoclosed
68+
timeout: 720
6669
```
6770
6871
## Voting

gitconsensus/repository.py

+37-17
Original file line numberDiff line numberDiff line change
@@ -59,7 +59,27 @@ def __init__(self, user, repository, client):
5959
self.rules['mergedelay'] = self.rules['mergedelay'] * 24
6060
if 'timeout' in self.rules and self.rules['timeout']:
6161
self.rules['timeout'] = self.rules['timeout'] * 24
62-
62+
self.rules['version'] = 2
63+
64+
if self.rules['version'] < 3:
65+
self.rules['version'] = 3
66+
self.rules['pull_requests'] = {
67+
"quorum": self.rules.get('quorum', False),
68+
"threshold": self.rules.get('threshold', False),
69+
"contributors_only": self.rules.get('contributorsonly', False),
70+
"collaborators_only": self.rules.get('collaboratorsonly', False),
71+
"whitelist": self.rules.get('whitelist'),
72+
"blacklist": self.rules.get('blacklist'),
73+
"merge_delay": self.rules.get('mergedelay', False),
74+
"delay_override": self.rules.get('delayoverride', False),
75+
"merge_delay_min": self.rules.get('mergedelaymin', False),
76+
"license_delay": self.rules.get('licenseddelay', False),
77+
"license_lock": self.rules.get('locklicense', False),
78+
"consensus_delay": self.rules.get('consensusdelay', False),
79+
"consensus_lock": self.rules.get('lockconsensus', False),
80+
"timeout": self.rules.get('timeout')
81+
}
82+
print(self.rules)
6383

6484
def getPullRequests(self):
6585
prs = self.repository.iter_pulls(state="open")
@@ -380,10 +400,10 @@ def validate(self, pr):
380400

381401
def isAllowed(self, pr):
382402
if pr.changesLicense():
383-
if 'locklicense' in self.rules and self.rules['locklicense']:
403+
if 'license_lock' in self.rules['pull_requests'] and self.rules['pull_requests']['license_lock']:
384404
return False
385405
if pr.changesConsensus():
386-
if 'lockconsensus' in self.rules and self.rules['lockconsensus']:
406+
if 'consensus_lock' in self.rules['pull_requests'] and self.rules['pull_requests']['consensus_lock']:
387407
return False
388408
return True
389409

@@ -393,43 +413,43 @@ def isMergeable(self, pr):
393413
return True
394414

395415
def hasQuorum(self, pr):
396-
if 'quorum' in self.rules:
397-
if len(pr.users) < self.rules['quorum']:
416+
if 'quorum' in self.rules['pull_requests']:
417+
if len(pr.users) < self.rules['pull_requests']['quorum']:
398418
return False
399419
return True
400420

401421
def hasVotes(self, pr):
402-
if 'threshold' in self.rules:
422+
if 'threshold' in self.rules['pull_requests']:
403423
total = (len(pr.yes) + len(pr.no))
404424
if total <= 0:
405425
return False
406426
ratio = len(pr.yes) / total
407-
if ratio < self.rules['threshold']:
427+
if ratio < self.rules['pull_requests']['threshold']:
408428
return False
409429
return True
410430

411431
def hasAged(self, pr):
412432
hours = pr.hoursSinceLastUpdate()
413433
if pr.changesLicense():
414-
if 'licensedelay' in self.rules and self.rules['licensedelay']:
415-
if hours < self.rules['licensedelay']:
434+
if 'license_delay' in self.rules['pull_requests'] and self.rules['pull_requests']['license_delay']:
435+
if hours < self.rules['pull_requests']['license_delay']:
416436
return False
417437
if pr.changesConsensus():
418-
if 'consensusdelay' in self.rules and self.rules['consensusdelay']:
419-
if hours < self.rules['consensusdelay']:
438+
if 'consensus_delay' in self.rules['pull_requests'] and self.rules['pull_requests']['consensus_delay']:
439+
if hours < self.rules['pull_requests']['consensus_delay']:
420440
return False
421-
if 'mergedelay' not in self.rules:
441+
if 'merge_delay' not in self.rules['pull_requests'] or not self.rules['pull_requests']['merge_delay']:
422442
return True
423-
if hours >= self.rules['mergedelay']:
443+
if hours >= self.rules['pull_requests']['merge_delay']:
424444
return True
425-
if 'delayoverride' in self.rules and self.rules['delayoverride']:
445+
if 'delay_override' in self.rules['pull_requests'] and self.rules['pull_requests']['delay_override']:
426446
if pr.changesConsensus() or pr.changesLicense():
427447
return False
428-
if 'mergedelaymin' in self.rules and self.rules['mergedelaymin']:
429-
if hours < self.rules['mergedelaymin']:
448+
if 'merge_delay_min' in self.rules['pull_requests'] and self.rules['pull_requests']['merge_delay_min']:
449+
if hours < self.rules['pull_requests']['merge_delay_min']:
430450
return False
431451
if len(pr.no) > 0:
432452
return False
433-
if len(pr.contributors_yes) >= self.rules['delayoverride']:
453+
if len(pr.contributors_yes) >= self.rules['pull_requests']['delay_override']:
434454
return True
435455
return False

0 commit comments

Comments
 (0)