Skip to content

Commit

Permalink
Add option preventing users from voting for two different options
Browse files Browse the repository at this point in the history
  • Loading branch information
tedivm committed Aug 23, 2017
1 parent ff38b50 commit 8e5ad54
Show file tree
Hide file tree
Showing 3 changed files with 31 additions and 4 deletions.
3 changes: 3 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,9 @@ will be skipped.
# Add extra labels for the vote counts and age when merging
extra_labels: false

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

# Minimum number of voters
quorum: 5

Expand Down
30 changes: 27 additions & 3 deletions gitconsensus/repository.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,9 +10,9 @@
## Vote Totals
| Yes | No | Abstain | Total |
| --- | -- | ------- | ----- |
| %s | %s | %s | %s |
| Yes | No | Abstain | Voters |
| --- | -- | ------- | ------ |
| %s | %s | %s | %s |
## Vote Breakdown
Expand Down Expand Up @@ -99,11 +99,15 @@ def __init__(self, repository, number):
self.no = []
self.abstain = []
self.users = []
self.doubles = []
for reaction in reactions:
content = reaction['content']
user = reaction['user']
username = user['login']

if username in self.doubles:
continue

if 'collaborators_only' in self.repository.rules and self.repository.rules['collaborators_only']:
if not isCollaborator(username):
continue
Expand All @@ -116,6 +120,19 @@ def __init__(self, repository, number):
if username not in self.repository.rules['whitelist']:
continue

if 'prevent_doubles' in self.repository.rules and self.repository.rules['prevent_doubles']:
# make sure user hasn't voted twice
if username in self.users:
self.doubles.append(username)
self.users.remove(username)
if username in self.yes:
self.yes.remove(username)
if username in self.no:
self.no.remove(username)
if username in self.abstain:
self.abstain.remove(username)
continue

if content == '+1':
self.yes.append(user['login'])
elif content == '-1':
Expand Down Expand Up @@ -199,6 +216,13 @@ def commentAction(self, action):
consensus.hasQuorum(self),
consensus.hasVotes(self)
)

if len(self.doubles) > 0:
duplist = ["[%s](https://github.com/%s)" % (username, username) for username in self.doubles]
dupuserstring = ', '.join(duplist)
dupstring = '\n\nThe following users voted for multiple options and were exlcuded: \n%s' % (dupuserstring)
message = "%s\n%s" % (message, dupstring)

self.addComment(message)

def buildVoteTable(self):
Expand Down
2 changes: 1 addition & 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.2.0'
version = '0.3.0'
setup(

name = 'gitconsensus',
Expand Down

0 comments on commit 8e5ad54

Please sign in to comment.