Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Bot comments when labels are set without permission #171

Merged
merged 8 commits into from
May 9, 2023
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions app.cfg.example
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,7 @@ submit_command = /usr/bin/sbatch
# if value is left/empty everyone can trigger the build
# value can be a space delimited list of GH accounts
build_permission = Hafsa-Naeem
no_build_permission_comment = Label `bot:build` has been set by user `{build_labeler}`, but only users `{build_permission_users}` have permission to trigger the action
bedroge marked this conversation as resolved.
Show resolved Hide resolved

[deploycfg]
# script for uploading built software packages
Expand Down Expand Up @@ -104,6 +105,7 @@ upload_policy = once
# if value is left/empty everyone can trigger the deployment
# value can be a space delimited list of GH accounts
deploy_permission = trz42
no_deploy_permission_comment = Label `bot:deploy` has been set by user `{deploy_labeler}`, but only users `{deploy_permission_users}` have permission to trigger the action


[architecturetargets]
Expand Down
11 changes: 10 additions & 1 deletion tasks/build.py
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@
SLURM_PARAMS = "slurm_params"
SUBMIT_COMMAND = "submit_command"
BUILD_PERMISSION = "build_permission"
NO_BUILD_PERMISSION_COMMENT = "no_build_permission_comment"
ARCHITECTURE_TARGETS = "architecturetargets"

Job = namedtuple('Job', ('working_dir', 'arch_target', 'slurm_opts'))
Expand Down Expand Up @@ -440,7 +441,15 @@ def check_build_permission(pr, event_info):
build_labeler = event_info['raw_request_body']['sender']['login']
if build_labeler not in build_permission.split():
log(f"{funcname}(): GH account '{build_labeler}' is not authorized to build")
# TODO update PR comments for this bot instance?
no_build_permission_comment = buildenv.get(NO_BUILD_PERMISSION_COMMENT)
gh = github.get_instance()
repo_name = event_info["raw_request_body"]["repository"]["full_name"]
repo = gh.get_repo(repo_name)
pull_request = repo.get_pull(pr.number)
pull_request.create_issue_comment(
no_build_permission_comment.format(build_labeler=build_labeler,
bedroge marked this conversation as resolved.
Show resolved Hide resolved
build_permission_users=", ".join(build_permission.split()))
)
return False
else:
log(f"{funcname}(): GH account '{build_labeler}' is authorized to build")
Expand Down
11 changes: 10 additions & 1 deletion tasks/deploy.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@
BUCKET_NAME = "bucket_name"
UPLOAD_POLICY = "upload_policy"
DEPLOY_PERMISSION = "deploy_permission"
NO_DEPLOY_PERMISSION_COMMENT = "no_deploy_permission_comment"


def determine_job_dirs(pr_number):
Expand Down Expand Up @@ -405,7 +406,15 @@ def deploy_built_artefacts(pr, event_info):
# permission to trigger the deployment
if labeler not in deploy_permission.split():
log(f"{funcname}(): GH account '{labeler}' is not authorized to deploy")
# TODO update PR comments for this bot instance?
no_deploy_permission_comment = deploy_cfg.get(NO_DEPLOY_PERMISSION_COMMENT)
gh = github.get_instance()
repo_name = event_info["raw_request_body"]["repository"]["full_name"]
repo = gh.get_repo(repo_name)
pull_request = repo.get_pull(pr.number)
pull_request.create_issue_comment(
no_deploy_permission_comment.format(deploy_labeler=labeler,
deploy_permission_users=", ".join(deploy_permission.split()))
)
return
else:
log(f"{funcname}(): GH account '{labeler}' is authorized to deploy")
Expand Down