Skip to content

Commit

Permalink
[PTFE-583] ✨ Prevent creation of integration branches
Browse files Browse the repository at this point in the history
  • Loading branch information
gaspardmoindrot committed Jul 21, 2023
1 parent a6c2d54 commit e06707c
Show file tree
Hide file tree
Showing 5 changed files with 120 additions and 7 deletions.
2 changes: 1 addition & 1 deletion CHANGELOG
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
# Change Log
All notable changes to this project will be documented in this file.

## [3.8.0] - 2023-06-13
## [3.9.0] - 2023-07-20
# Added
- Introducing new option `create_integration_branches`
to allow the creation of integration branches on demand.
Expand Down
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ $ tox -e run
A series of test scenario will be executed locally using mocks.

```shell
$ tox run -e tests
$ tox -e tests
```

### Run tests against githost
Expand Down
2 changes: 1 addition & 1 deletion bert_e/docs/USER_DOC.md
Original file line number Diff line number Diff line change
Expand Up @@ -182,7 +182,7 @@ parameter in the bot settings:
* *false*: users will be required to explicitly request the creation
of integration branches by adding a `/create_integration_branches`
comment in their pull request.
The above allow to temporize the creation of those branches as
The above allows to temporize the creation of those branches as
in the review process requested changes as expected.

On the Git project, the name of the integration branches follow the format:
Expand Down
114 changes: 114 additions & 0 deletions bert_e/tests/test_bert_e.py
Original file line number Diff line number Diff line change
Expand Up @@ -1210,6 +1210,120 @@ def test_request_integration_branch_creation(self):
self.handle(
pr.id, settings=settings, options=options, backtrace=True)

def test_creation_integration_branch_by_approve(self):
"""Test pr.approve() to request integration branches creation.
1. Create a PR and verify that the appropriate message is sent
regarding its creation
2. Ensure that author approval is required for the PR
3. Approve the PR from the author's perspective and check if
the integration branches are created.
4. Once the integration branches are created,
ensure the bot is able to merge the PR.
"""
settings = """
repository_owner: {owner}
repository_slug: {slug}
repository_host: {host}
robot: {robot}
robot_email: [email protected]
pull_request_base_url: https://bitbucket.org/{owner}/{slug}/bar/pull-requests/{{pr_id}}
commit_base_url: https://bitbucket.org/{owner}/{slug}/commits/{{commit_id}}
build_key: pre-merge
required_leader_approvals: 0
required_peer_approvals: 0
always_create_integration_branches: false
admins:
- {admin}
""" # noqa
options = self.bypass_all_but(['bypass_build_status', 'bypass_author_approval'])
pr = self.create_pr('feature/TEST-0069', 'development/4.3')

with self.assertRaises(exns.ApprovalRequired):
self.handle(pr.id, options=options, backtrace=True)

self.assertEqual(len(list(pr.get_comments())), 3)

self.assertIn(
'Integration data created', list(pr.get_comments())[-2].text)

self.assertIn(
'Waiting for approval', self.get_last_pr_comment(pr))
self.assertIn(
'The following approvals are needed', self.get_last_pr_comment(pr))

pr.approve()

with self.assertRaises(exns.BuildNotStarted):
self.handle(
pr.id, settings=settings, options=options, backtrace=True)

options = self.bypass_all
with self.assertRaises(exns.SuccessMessage):
self.handle(
pr.id, settings=settings, options=options, backtrace=True)

self.assertIn(
'I have successfully merged the changeset', self.get_last_pr_comment(pr))

def test_creation_integration_branch_by_approve_2(self):
"""Test /approve to request integration branches creation.
1. Create a PR and verify that the appropriate message is sent
regarding its creation
2. Ensure that author approval is required for the PR
3. Approve the PR from the author's perspective and check if
the integration branches are created.
4. Once the integration branches are created,
ensure the bot is able to merge the PR.
"""
settings = """
repository_owner: {owner}
repository_slug: {slug}
repository_host: {host}
robot: {robot}
robot_email: [email protected]
pull_request_base_url: https://bitbucket.org/{owner}/{slug}/bar/pull-requests/{{pr_id}}
commit_base_url: https://bitbucket.org/{owner}/{slug}/commits/{{commit_id}}
build_key: pre-merge
required_leader_approvals: 0
required_peer_approvals: 0
always_create_integration_branches: false
admins:
- {admin}
""" # noqa
options = self.bypass_all_but(['bypass_build_status', 'bypass_author_approval'])
pr = self.create_pr('feature/TEST-0069', 'development/4.3')

with self.assertRaises(exns.ApprovalRequired):
self.handle(pr.id, options=options, backtrace=True)

self.assertEqual(len(list(pr.get_comments())), 3)

self.assertIn(
'Integration data created', list(pr.get_comments())[-2].text)

self.assertIn(
'Waiting for approval', self.get_last_pr_comment(pr))
self.assertIn(
'The following approvals are needed', self.get_last_pr_comment(pr))

pr.add_comment('/approve')

with self.assertRaises(exns.BuildNotStarted):
self.handle(
pr.id, settings=settings, options=options, backtrace=True)

options = self.bypass_all
with self.assertRaises(exns.SuccessMessage):
self.handle(
pr.id, settings=settings, options=options, backtrace=True)

self.assertIn(
'I have successfully merged the changeset', self.get_last_pr_comment(pr))

def test_integration_branch_creation_latest_branch(self):
"""Test there is no comment to request integration branches creation.
Expand Down
7 changes: 3 additions & 4 deletions bert_e/workflow/gitwaterflow/integration.py
Original file line number Diff line number Diff line change
Expand Up @@ -140,10 +140,9 @@ def check_integration_branches(job):
"""Check if the integration branches can be created."""

approvals = set(job.pull_request.get_approvals())
approved_by_author |= job.pull_request.author in approvals
if (approved_by_author is True and
len(job.git.cascade.dst_branches) > 1):
create_integration_branches()
if job.settings.approve:
approvals.add(job.pull_request.author)
approved_by_author = job.pull_request.author in approvals

if (job.settings.always_create_integration_branches is False and
job.settings.create_integration_branches is False and
Expand Down

0 comments on commit e06707c

Please sign in to comment.