Skip to content

Commit

Permalink
add approvals via thumb-emoji
Browse files Browse the repository at this point in the history
  • Loading branch information
FlorianLudwig authored and lkm committed Apr 25, 2020
1 parent bfcafec commit 16ad028
Show file tree
Hide file tree
Showing 2 changed files with 39 additions and 1 deletion.
14 changes: 14 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -193,6 +193,20 @@ ssh-keygen -t ed25519 -C marge-bot@invalid -f marge-bot-ssh-key -P ''
Add the public key (`marge-bot-ssh-key.pub`) to the user's `SSH Keys` in GitLab
and keep the private one handy.
### Per project configuration
On GitLab enterprise the [merge request approvals](https://docs.gitlab.com/ee/user/project/merge_requests/merge_request_approvals.html)
provide the information how many approvals from whom are needed for
a merge request. On GitlLab CE this is done via a configuration file
called `.marge-bot.yml`. Currently Marge uses the config file from master
as config for all merge request.
The `.marge-bot.yml` config currently only supports `approver_count`:
```yaml
approver_count: 3 # number of "thumbs up" needed, defaults to 1
```
### Running marge-bot in docker (what we do)
Assuming you have already got docker installed, the quickest and most minimal
Expand Down
26 changes: 25 additions & 1 deletion marge/approvals.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
import yaml
import logging as log

from . import gitlab

GET, POST, PUT = gitlab.GET, gitlab.POST, gitlab.PUT
Expand All @@ -17,7 +20,28 @@ def refetch_info(self):
if gitlab_version.is_ee:
self._info = self._api.call(GET(approver_url))
else:
self._info = dict(self._info, approvals_left=0, approved_by=[])
self.get_approvers_ce()

def get_approvers_ce(self):
"""get approvers status using thumbs on merge request
"""

config_file = self._api.repo_file_get(self.project_id, ".marge-bot.yml", "master")
if config_file is None:
log.info('Project id %s missing .marge-bot.yaml', self.project_id)
config = {}
else:
config = yaml.load(config_file["content"])


emoji_url = '/projects/{0.project_id}/merge_requests/{0.iid}/award_emoji'
emoji_url = emoji_url.format(self)
emoji = self._api.call(GET(emoji_url))

up_votes = [e for e in emoji if e['name'] == 'thumbsup']
approver_count = config.get('approver_count', 1)
approvals_left = max(approver_count - len(up_votes), 0)
self._info = dict(self._info, approvals_left=approvals_left, approved_by=up_votes)

@property
def iid(self):
Expand Down

0 comments on commit 16ad028

Please sign in to comment.