diff --git a/README.md b/README.md index 4801777..2b14fb3 100644 --- a/README.md +++ b/README.md @@ -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 diff --git a/app.py b/app.py index b4eeb69..e5456d1 100644 --- a/app.py +++ b/app.py @@ -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) @@ -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""" diff --git a/requirements.txt b/requirements.txt index b943768..b924756 100644 --- a/requirements.txt +++ b/requirements.txt @@ -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 diff --git a/src/managers/pull_request.py b/src/managers/pull_request.py index e398be8..5c9c4eb 100644 --- a/src/managers/pull_request.py +++ b/src/managers/pull_request.py @@ -1,6 +1,7 @@ import logging from github.Repository import Repository +from githubapp import Config from src.helpers import pull_request @@ -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 ) diff --git a/tests/test_app.py b/tests/test_app.py index 8c57bae..e87f586 100644 --- a/tests/test_app.py +++ b/tests/test_app.py @@ -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): @@ -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) @@ -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