Changeset View
Changeset View
Standalone View
Standalone View
contrib/buildbot/server.py
Show First 20 Lines • Show All 444 Lines • ▼ Show 20 Lines | def triggerCI(): | ||||
"PHID-TOKN-coin-2": "PHID-TOKN-coin-3", | "PHID-TOKN-coin-2": "PHID-TOKN-coin-3", | ||||
"PHID-TOKN-coin-3": "PHID-TOKN-coin-4", | "PHID-TOKN-coin-3": "PHID-TOKN-coin-4", | ||||
"PHID-TOKN-coin-4": "PHID-TOKN-like-1", | "PHID-TOKN-coin-4": "PHID-TOKN-like-1", | ||||
"PHID-TOKN-like-1": "PHID-TOKN-heart-1", | "PHID-TOKN-like-1": "PHID-TOKN-heart-1", | ||||
"PHID-TOKN-heart-1": "PHID-TOKN-like-1", | "PHID-TOKN-heart-1": "PHID-TOKN-like-1", | ||||
} | } | ||||
return next_token[current_token] if current_token in next_token else "PHID-TOKN-like-1" | return next_token[current_token] if current_token in next_token else "PHID-TOKN-like-1" | ||||
def is_user_allowed_to_trigger_builds(user_PHID, current_token): | def is_user_allowed_to_trigger_builds( | ||||
user_PHID, current_token, comment_builds, build_configs): | |||||
if current_token not in [ | if current_token not in [ | ||||
"", "PHID-TOKN-coin-1", "PHID-TOKN-coin-2", "PHID-TOKN-coin-3"]: | "", "PHID-TOKN-coin-1", "PHID-TOKN-coin-2", "PHID-TOKN-coin-3"]: | ||||
return False | return False | ||||
return all(role in phab.get_user_roles(user_PHID) for role in [ | if not all(role in phab.get_user_roles(user_PHID) for role in [ | ||||
"verified", | "verified", | ||||
"approved", | "approved", | ||||
"activated", | "activated", | ||||
]) | ]): | ||||
return False | |||||
for build_name in comment_builds: | |||||
build_config = build_configs.get(build_name, None) | |||||
if build_config is None: | |||||
# If one of the build doesn't exist, reject them all. | |||||
return False | |||||
if "docker" in build_config: | |||||
# If one of the build contain a docker configuration, reject | |||||
# them all. | |||||
return False | |||||
return True | |||||
# Anti DoS filter | # Anti DoS filter | ||||
# | # | ||||
# Users are allowed to trigger builds if these conditions are met: | # Users are allowed to trigger builds if these conditions are met: | ||||
# - It is an ABC member | # - It is an ABC member | ||||
# OR | # OR | ||||
# | - It is a "verified", "approved" and "activated" user | # | - It is a "verified", "approved" and "activated" user | ||||
# | AND | # | AND | ||||
# | - The maximum number of requests for this revision has not been | # | - The maximum number of requests for this revision has not been | ||||
# | reached yet. | # | reached yet. | ||||
# | AND | |||||
# | - The build doesn't contain a `docker` configuration. | |||||
# | # | ||||
# The number of requests is tracked by awarding a coin token to the | # The number of requests is tracked by awarding a coin token to the | ||||
# revision each time a build request is submitted (the number of build | # revision each time a build request is submitted (the number of build | ||||
# in that request is not taken into account). | # in that request is not taken into account). | ||||
# The awarded coin token is graduated as follow: | # The awarded coin token is graduated as follow: | ||||
# "Haypence" => "Piece of Eight" => "Dubloon" => "Mountain of Wealth". | # "Haypence" => "Piece of Eight" => "Dubloon" => "Mountain of Wealth". | ||||
# If the "Mountain of Wealth" token is reached, the next request will be | # If the "Mountain of Wealth" token is reached, the next request will be | ||||
# refused by the bot. At this stage only ABC members will be able to | # refused by the bot. At this stage only ABC members will be able to | ||||
# trigger new builds. | # trigger new builds. | ||||
abc_members = phab.get_project_members(BITCOIN_ABC_PROJECT_PHID) | abc_members = phab.get_project_members(BITCOIN_ABC_PROJECT_PHID) | ||||
current_token = phab.get_object_token(revision_PHID) | current_token = phab.get_object_token(revision_PHID) | ||||
build_configs = get_master_build_configurations() | |||||
builds = [] | builds = [] | ||||
for comment in comments: | for comment in comments: | ||||
comment_builds = get_builds_from_comment(comment["content"]["raw"]) | comment_builds = get_builds_from_comment(comment["content"]["raw"]) | ||||
# Parsing the string is cheaper than phabricator requests, so check | # Parsing the string is cheaper than phabricator requests, so check | ||||
# if the comment is for us prior to filtering on the user. | # if the comment is for us prior to filtering on the user. | ||||
if not comment_builds: | if not comment_builds: | ||||
continue | continue | ||||
user = comment["authorPHID"] | user = comment["authorPHID"] | ||||
# ABC members can always trigger builds | # ABC members can always trigger builds | ||||
if user in abc_members: | if user in abc_members: | ||||
builds += comment_builds | builds += comment_builds | ||||
continue | continue | ||||
if is_user_allowed_to_trigger_builds(user, current_token): | if is_user_allowed_to_trigger_builds( | ||||
user, current_token, comment_builds, build_configs): | |||||
builds += comment_builds | builds += comment_builds | ||||
# If there is no build provided, this request is not what we are after, | # If there is no build provided, this request is not what we are after, | ||||
# just return. | # just return. | ||||
# TODO return an help command to explain how to use the bot. | # TODO return an help command to explain how to use the bot. | ||||
if not builds: | if not builds: | ||||
return SUCCESS, 200 | return SUCCESS, 200 | ||||
▲ Show 20 Lines • Show All 560 Lines • Show Last 20 Lines |