Skip to content

Commit

Permalink
merge mode in configuration file (#92)
Browse files Browse the repository at this point in the history
* feat(PullRequestManager): merge method configuration

[release:minor]

* style: format code with Black and isort

This commit fixes the style issues introduced in 55f0de8 according to the output
from Black and isort.

Details: #92

---------

Co-authored-by: Heitor Polidoro <[email protected]>
Co-authored-by: deepsource-autofix[bot] <62050782+deepsource-autofix[bot]@users.noreply.github.com>
  • Loading branch information
3 people authored Jan 23, 2024
1 parent e2b5853 commit b1ec168
Show file tree
Hide file tree
Showing 5 changed files with 50 additions and 30 deletions.
11 changes: 6 additions & 5 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -25,15 +25,16 @@
Bartholomew "The Butler" Smith is your personal assistant for managing your GitHub repositories.
This app automates repetitive tasks, helping you save time and focus on what’s important.
Here’s what GitHub Butler can do for you:
- **[Pull Request Manager](../../wiki/Pull-Request-Manager)**: Automatically creates a pull request with the repository's default branch as base
when a branch is created among other things.
- Releaser WiP
- Issue Manager WiP
- **[Pull Request Manager](../../wiki/Pull-Request-Manager)**: Automatically creates a pull request with the
repository's default branch as base when a branch is created among other things.
- **[Release Manager](../../wiki/Release-Manager)**: Automatically create releases using commands in commits message.
- **[Issue Manager](../../wiki/Issue-Manager)**: Manager the issues, automatically create issues from tasklist,
closes the issue if all issues in the tasklist are done, among other things

With Bartholomew "The Butler" Smith, you can spend less time managing your repository and more time writing great code.
It’s like having a butler for your GitHub repository! :tophat:

See the [Wiki](../../wiki/) for more information
See the [Wiki](../../wiki) for more information

## Thanks to
[gabriellamas](https://github.com/gabriellamas) for helping me with logo ideas
Expand Down
31 changes: 20 additions & 11 deletions app.py
Original file line number Diff line number Diff line change
Expand Up @@ -46,8 +46,11 @@ def sentry_init():
app = Flask(__name__)
sentry_init()
webhook_handler.handle_with_flask(
app, use_default_index=False, config_file="bartholomew.yaml"
app, use_default_index=False, config_file=".bartholomew.yaml"
)
Config.create_config("pull_request_manager", enabled=True, merge_method="SQUASH")
Config.create_config("release_manager", enabled=True)
Config.create_config("issue_manager", enabled=True)


@webhook_handler.add_handler(CheckSuiteRequestedEvent)
Expand All @@ -58,31 +61,37 @@ def handle_check_suite_requested(event: CheckSuiteRequestedEvent):
- Creates a Pull Request, if not exists, and/or enable the auto merge flag
"""
repository = event.repository
if Config.is_pull_request_manager_enabled:
if Config.pull_request_manager.enabled:
handle_create_pull_request(repository, event.check_suite.head_branch)
if Config.is_release_manager_enabled:
if Config.release_manager.enabled:
handle_release(event)


@webhook_handler.add_handler(IssueOpenedEvent)
@webhook_handler.add_handler(IssueEditedEvent)
@webhook_handler.add_handler(IssueClosedEvent)
def handle_issue(event: IssuesEvent):
"""
TODO update
Handle the IssueOpened and IssueEdited events, handling the tasklist and add the issue to the main project if
Handle the Issues events, handling the tasklist and add the issue to the main project if
configured to
:param event:
:return:
"""
if Config.is_issue_manager_enabled and event.issue and event.issue.body:
if isinstance(event, IssueClosedEvent):
handle_close_tasklist(event)
else:
handle_tasklist(event)
if Config.issue_manager.enabled and event.issue and event.issue.body:
handle_tasklist(event)
# add_to_project(event)


@webhook_handler.add_handler(IssueClosedEvent)
def handle_issue_closed(event: IssueClosedEvent):
"""
Handle the Issue Closed events, closing the issues in the task list
:param event:
:return:
"""
if Config.issue_manager.enabled and event.issue and event.issue.body:
handle_close_tasklist(event)


@app.route("/", methods=["GET"])
def index():
"""Return the index homepage"""
Expand Down
2 changes: 1 addition & 1 deletion requirements.txt
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
github-app-handler==0.21
github-app-handler==0.22
sentry-sdk==1.39.2
flask==3.0.1
Polidoro-PyGithub==2.2.0
Expand Down
3 changes: 2 additions & 1 deletion src/managers/pull_request.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import logging

from github.Repository import Repository
from githubapp import Config

from src.helpers import pull_request

Expand All @@ -11,5 +12,5 @@ def handle_create_pull_request(repository: Repository, branch: str):
"""Creates a Pull Request, if not exists, and/or enable the auto merge flag"""
if repository.default_branch != branch:
pull_request.get_or_create_pull_request(repository, branch).enable_automerge(
merge_method="SQUASH"
merge_method=Config.pull_request_manager.merge_method
)
33 changes: 21 additions & 12 deletions tests/test_app.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,14 @@
import markdown
import pytest
from githubapp import Config
from githubapp.events.issues import IssueClosedEvent

from app import app, handle_check_suite_requested, handle_issue, sentry_init
from app import (
app,
handle_check_suite_requested,
handle_issue,
handle_issue_closed,
sentry_init,
)


def test_sentry_init(monkeypatch):
Expand Down Expand Up @@ -72,8 +77,7 @@ def test_handle_issue_when_issue_has_no_body(event, issue, handle_tasklist_mock)


def test_handle_close_issue(event, issue, handle_close_tasklist_mock):
event.__class__ = IssueClosedEvent
handle_issue(event)
handle_issue_closed(event)
handle_close_tasklist_mock.assert_called_once_with(event)


Expand Down Expand Up @@ -101,19 +105,24 @@ def test_index(self):


def test_managers_disabled(
handle_create_pull_request_mock, handle_release_mock, handle_tasklist_mock
handle_create_pull_request_mock,
handle_release_mock,
handle_tasklist_mock,
handle_close_tasklist_mock,
):
event = Mock()
with patch("app.Config.load_config_from_file"):
Config.set_values(
{
"pull_request_manager": False,
"release_manager": False,
"issue_manager": False,
}
)
Config.pull_request_manager.enabled = False
Config.release_manager.enabled = False
Config.issue_manager.enabled = False

handle_check_suite_requested(event)
handle_create_pull_request_mock.assert_not_called()
handle_release_mock.assert_not_called()
handle_issue(event)
handle_tasklist_mock.assert_not_called()
handle_issue_closed(event)
handle_close_tasklist_mock.assert_not_called()
Config.pull_request_manager.enabled = True
Config.release_manager.enabled = True
Config.issue_manager.enabled = True

0 comments on commit b1ec168

Please sign in to comment.