CI: check_mr_settings.py: fix check for same repo (!255)

Do not crash when a MR was made from the same repository, because the
"allow_maintainer_to_push" key does not exist in the GitLab API's
output. Check first if the "source_project_id" is the same as the
"target_project_id", and if it is, do not try to access
"allow_maintainer_to_push" at all.
This commit is contained in:
Oliver Smith 2019-03-05 08:56:47 +01:00
parent 81cee38610
commit 3030c00ba2
No known key found for this signature in database
GPG key ID: 5AE7F5513E0885CB

View file

@ -77,16 +77,27 @@ def get_mr_settings(path):
exit(1)
def check_allow_push(settings):
""" :returns: True when maintainers are allowed to push to the branch
(what we want!), False otherwise """
if "allow_maintainer_to_push" not in settings:
print("ERROR: missing 'allow_maintainer_to_push' key in settings!")
def settings_read(settings, key):
if key not in settings:
print("ERROR: missing '" + key + "' key in settings!")
print("Here are the whole settings for debugging:")
print("---")
print(settings)
exit(1)
return settings["allow_maintainer_to_push"]
return settings[key]
def check_allow_push(settings):
""" :returns: True when maintainers are allowed to push to the branch
(what we want!), False otherwise """
# Check if source branch is in same repository
source = settings_read(settings, "source_project_id")
target = settings_read(settings, "target_project_id")
if source == target:
return True
return settings_read(settings, "allow_maintainer_to_push")
def main():