Skip to content

Commit 115c16f

Browse files
committed
add approvals via thumb-emoji
1 parent febeb96 commit 115c16f

File tree

2 files changed

+39
-1
lines changed

2 files changed

+39
-1
lines changed

README.md

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -193,6 +193,20 @@ ssh-keygen -t ed25519 -C marge-bot@invalid -f marge-bot-ssh-key -P ''
193193
Add the public key (`marge-bot-ssh-key.pub`) to the user's `SSH Keys` in GitLab
194194
and keep the private one handy.
195195
196+
### Per project configuration
197+
198+
On GitLab enterprise the [merge request approvals](https://docs.gitlab.com/ee/user/project/merge_requests/merge_request_approvals.html)
199+
provide the information how many approvals from whom are needed for
200+
a merge request. On GitlLab CE this is done via a configuration file
201+
called `.marge-bot.yml`. Currently Marge uses the config file from master
202+
as config for all merge request.
203+
204+
The `.marge-bot.yml` config currently only supports `approver_count`:
205+
```yaml
206+
207+
approver_count: 3 # number of "thumbs up" needed, defaults to 1
208+
```
209+
196210
### Running marge-bot in docker (what we do)
197211
198212
Assuming you have already got docker installed, the quickest and most minimal

marge/approvals.py

Lines changed: 25 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,6 @@
1+
import yaml
2+
import logging as log
3+
14
from . import gitlab
25

36
GET, POST, PUT = gitlab.GET, gitlab.POST, gitlab.PUT
@@ -17,7 +20,28 @@ def refetch_info(self):
1720
if gitlab_version.is_ee:
1821
self._info = self._api.call(GET(approver_url))
1922
else:
20-
self._info = dict(self._info, approvals_left=0, approved_by=[])
23+
self.get_approvers_ce()
24+
25+
def get_approvers_ce(self):
26+
"""get approvers status using thumbs on merge request
27+
"""
28+
29+
config_file = self._api.repo_file_get(self.project_id, ".marge-bot.yml", "master")
30+
if config_file is None:
31+
log.info('Project id %s missing .marge-bot.yaml', self.project_id)
32+
config = {}
33+
else:
34+
config = yaml.load(config_file["content"])
35+
36+
37+
emoji_url = '/projects/{0.project_id}/merge_requests/{0.iid}/award_emoji'
38+
emoji_url = emoji_url.format(self)
39+
emoji = self._api.call(GET(emoji_url))
40+
41+
up_votes = [e for e in emoji if e['name'] == 'thumbsup']
42+
approver_count = config.get('approver_count', 1)
43+
approvals_left = max(approver_count - len(up_votes), 0)
44+
self._info = dict(self._info, approvals_left=approvals_left, approved_by=up_votes)
2145

2246
@property
2347
def iid(self):

0 commit comments

Comments
 (0)