Skip to content

Commit 8d99fdd

Browse files
authored
PTFE-2196 authorize self bypass for admins (#230)
1 parent b533cae commit 8d99fdd

5 files changed

Lines changed: 39 additions & 7 deletions

File tree

CHANGELOG

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@ All notable changes to this project will be documented in this file.
1212
# Changed
1313
- Integration queue branches pattern is now `q/w/{pr.id}/{integration.branch}`
1414
instead of `q/{pr.id}/{integration.branch}`.
15+
- Allow admins to self-bypass their own PRs.
1516

1617
## [3.12.0] - 2024-02-26
1718
# Added

bert_e/docs/USER_DOC.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -480,7 +480,7 @@ to progress to the next step. message code
480480
| 120 | After pull request | The after_pull_request option has been activated, and the target pull request is not merged yet work on merging the pending pull request or remove the option
481481
| 121 | Integration data created | __Bert-E__ notifies the owner that he succesfully created the integration branches and the related pull requests, and provides a link to them. No action required
482482
| 122 | Unknown command | One of the participants asked __Bert-E__ to activate an option, or execute a command he doesn't know. Edit the corresponding message if it contains a typo. Delete it otherwise
483-
| 123 | Not authorized | One of the participants asked __Bert-E__ to activate a privileged option, or execute a privileged command, but doesn't have enough credentials to do so. Delete the corresponding command ask a __Bert-E__ administrator to run/set the desired command/option. Note that the even if the author of the pull request has administrator credentials, he cannot use privileged commands or options on his own pull requests.
483+
| 123 | Not authorized | One of the participants asked __Bert-E__ to activate a privileged option, or execute a privileged command, but doesn't have enough credentials to do so. Delete the corresponding command ask a __Bert-E__ administrator to run/set the desired command/option.
484484
| 134 | Not author | One of the participants asked __Bert-E__ to activate an authored option, but the participant is not the author of the pull request.
485485

486486
Queues

bert_e/templates/not_enough_credentials.md

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -9,11 +9,7 @@ I'm afraid I cannot do that, @{{ author }}:
99

1010
> {{ comment|replace('\n', '\n> ') }}
1111
12-
{% if self_pr %}
13-
You cannot use `{{ command }}` in your own pull request.
14-
{% else %}
1512
You don't have enough credentials to use `{{ command }}`.
16-
{% endif %}
1713

1814
Please **edit** or **delete** the corresponding comment so I can move on.
1915
{% endblock %}

bert_e/tests/test_bert_e.py

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4978,6 +4978,41 @@ def test_dev_major_lonely_stab(self):
49784978
with self.assertRaises(exns.DevBranchDoesNotExist):
49794979
self.handle(pr.id, options=self.bypass_all, backtrace=True)
49804980

4981+
def test_admin_self_bypass(self):
4982+
"""Test an admin can bypass its own PR."""
4983+
feature_branch = 'feature/TEST-00001'
4984+
from_branch = 'development/4.3'
4985+
create_branch(self.gitrepo, feature_branch,
4986+
from_branch=from_branch, file_=True)
4987+
pr = self.admin_bb.create_pull_request(
4988+
title="title",
4989+
name="name",
4990+
src_branch=feature_branch,
4991+
dst_branch=from_branch,
4992+
description="",
4993+
)
4994+
# Expect a jira check
4995+
with self.assertRaises(exns.IncorrectFixVersion):
4996+
self.handle(pr.id, backtrace=True)
4997+
# Ensure peers cannot bypass the jira check without admin credentials
4998+
peer = self.contributor_bb.get_pull_request(pull_request_id=pr.id)
4999+
comment = peer.add_comment('/bypass_jira_check')
5000+
# Expect a lack of credentials
5001+
with self.assertRaises(exns.NotEnoughCredentials):
5002+
self.handle(pr.id, backtrace=True)
5003+
comment.delete()
5004+
# Ensure the admin can bypass its own PR
5005+
pr.add_comment('/bypass_jira_check')
5006+
with self.assertRaises(exns.ApprovalRequired):
5007+
self.handle(pr.id, backtrace=True)
5008+
pr.add_comment('/bypass_peer_approval')
5009+
pr.approve()
5010+
with self.assertRaises(exns.BuildNotStarted):
5011+
self.handle(pr.id, backtrace=True)
5012+
pr.add_comment('/bypass_build_status')
5013+
with self.assertRaises(exns.SuccessMessage):
5014+
self.handle(pr.id, backtrace=True)
5015+
49815016

49825017
class TestQueueing(RepositoryTests):
49835018
"""Tests which validate all things related to the merge queue.

bert_e/workflow/gitwaterflow/__init__.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -305,7 +305,7 @@ def handle_comments(job):
305305
# Look for options in all of the pull request's comments.
306306
for comment in job.pull_request.comments:
307307
author = comment.author
308-
privileged = author in admins and author != pr_author
308+
privileged = author in admins
309309
authored = author == pr_author
310310
text = comment.text
311311
try:
@@ -318,7 +318,7 @@ def handle_comments(job):
318318
except NotPrivileged as err:
319319
raise messages.NotEnoughCredentials(
320320
active_options=job.active_options, command=err.keyword,
321-
author=author, self_pr=(author == pr_author), comment=text
321+
author=author, comment=text
322322
) from err
323323
except NotAuthored as err:
324324
raise messages.NotAuthor(

0 commit comments

Comments
 (0)