Skip to content

Commit

Permalink
wiki
Browse files Browse the repository at this point in the history
[release:minor]
  • Loading branch information
heitorpolidoro committed Jan 23, 2024
1 parent 10f4653 commit b8c5caa
Show file tree
Hide file tree
Showing 7 changed files with 30 additions and 70 deletions.
36 changes: 15 additions & 21 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,19 +2,6 @@
<img src="static/bartholomew-logo.png" width="200" height="200">
</div>

# Bartholomew "The Butler" Smith

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 Management](pull-request)**: Automatically creates a pull request on the repository's default branch
when a branch is created among other things.
- Releaser WiP
- Issue Manager WiP

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:

[![Code Quality](https://github.com/heitorpolidoro/bartholomew-smith/actions/workflows/code_quality.yml/badge.svg)](https://github.com/heitorpolidoro/bartholomew-smith/actions/workflows/code_quality.yml)
<br>
[![Latest Version](https://img.shields.io/github/v/release/heitorpolidoro/bartholomew-smith?label=Latest%20Version)](https://github.com/heitorpolidoro/bartholomew-smith/releases/latest)
Expand All @@ -33,14 +20,21 @@ It’s like having a butler for your GitHub repository! :tophat:
[![Vulnerabilities](https://sonarcloud.io/api/project_badges/measure?project=heitorpolidoro_bartholomew-smith&metric=vulnerabilities)](https://sonarcloud.io/summary/new_code?id=heitorpolidoro_bartholomew-smith)
[![Bugs](https://sonarcloud.io/api/project_badges/measure?project=heitorpolidoro_bartholomew-smith&metric=bugs)](https://sonarcloud.io/summary/new_code?id=heitorpolidoro_bartholomew-smith)

# Bartholomew "The Butler" Smith

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.md)**: 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

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/Home.md) for more information

## Thanks to
[gabriellamas](https://github.com/gabriellamas) for helping me with logo ideas

## TODOs
- [ ] Self-Approver heitorpolidoro/bartholomew-smith#4
- [ ] Auto Release heitorpolidoro/bartholomew-smith#5
- [ ] Issue Manager heitorpolidoro/bartholomew-smith#6
- [ ] Auto-fix linter heitorpolidoro/bartholomew-smith#84
- [ ] Check for TODOs in repository (create issues?) heitorpolidoro/bartholomew-smith#83
- [ ] Dont Merge Yet if WiP or has a not checked item in the checklist heitorpolidoro/bartholomew-smith#86
- [ ] PR checklist heitorpolidoro/bartholomew-smith#87
15 changes: 2 additions & 13 deletions app.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@

import markdown
import sentry_sdk
from flask import Flask, abort, render_template
from flask import Flask, render_template
from githubapp import Config, webhook_handler
from githubapp.events import (
CheckSuiteRequestedEvent,
Expand Down Expand Up @@ -86,19 +86,8 @@ def handle_issue(event: IssuesEvent):
@app.route("/", methods=["GET"])
def index():
"""Return the index homepage"""
return file("README.md")


@app.route("/<path:filename>", methods=["GET"])
def file(filename):
"""Convert a md file into HTML and return it"""
allowed_files = {f: f for f in ["README.md", "pull-request.md"]}
if filename not in allowed_files:
abort(404)
with open(allowed_files[filename]) as f:
with open("README.md") as f:
md = f.read()
body = markdown.markdown(md)
title = "Bartholomew Smith"
if filename != "README.md":
title += f" - {filename.replace('-', ' ').replace('.md', '').title()}"
return render_template("index.html", title=title, body=body)
9 changes: 1 addition & 8 deletions src/helpers/pull_request.py
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ def create_pull_request(repository: Repository, branch: str) -> Optional[PullReq
repository.default_branch,
branch,
title=title or branch,
body=body or "PR automatically created",
body=body or "Pull Request automatically created",
draft=False,
)
return pr
Expand Down Expand Up @@ -102,10 +102,3 @@ def get_or_create_pull_request(
pr = create_pull_request(repository, branch)
return pr


def enable_auto_merge(pr: PullRequest) -> None:
"""
Enables auto merge for the given PR.
:param pr: The PR to enable auto merge for.
"""
pr.enable_automerge(merge_method="SQUASH")
5 changes: 3 additions & 2 deletions src/managers/pull_request.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,5 +10,6 @@
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:
pr = pull_request.get_or_create_pull_request(repository, branch)
pull_request.enable_auto_merge(pr)
pull_request.get_or_create_pull_request(repository, branch).enable_automerge(
merge_method="SQUASH"
)
18 changes: 8 additions & 10 deletions tests/helpers/test_pull_request.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,11 +5,12 @@

from src.helpers.pull_request import (
create_pull_request,
enable_auto_merge,
get_existing_pull_request,
get_or_create_pull_request,
)

OTHER_ERROR = "other error"


def test_get_existing_pull_request_when_there_is_none(repository):
repository.get_pulls.return_value = []
Expand All @@ -30,7 +31,7 @@ def test_create_pull_request(repository):
repository.default_branch,
"branch",
title="branch",
body="PR automatically created",
body="Pull Request automatically created",
draft=False,
)

Expand Down Expand Up @@ -65,20 +66,20 @@ def test_create_pull_request_when_there_is_no_commits(repository):

def test_create_pull_request_when_other_errors(repository):
repository.create_pull.side_effect = GithubException(
status=400, message="other error"
status=400, message=OTHER_ERROR
)
with pytest.raises(GithubException) as err:
create_pull_request(repository, "branch")
assert err.value.message == "other error"
assert err.value.message == OTHER_ERROR


def test_create_pull_request_when_other_errors2(repository):
repository.create_pull.side_effect = GithubException(
status=400, data={"errors": [{"message": "other error"}]}
status=400, data={"errors": [{"message": OTHER_ERROR}]}
)
with pytest.raises(GithubException) as err:
create_pull_request(repository, "branch")
assert err.value.data["errors"][0]["message"] == "other error"
assert err.value.data["errors"][0]["message"] == OTHER_ERROR


def test_get_or_create_pull_request_when_there_is_no_pull_request(repository):
Expand Down Expand Up @@ -116,7 +117,4 @@ def test_get_or_create_pull_request_when_there_is_a_pull_request(repository):
create_pull_request_mock.assert_not_called()


def test_enable_auto_merge():
pull_request = Mock()
enable_auto_merge(pull_request)
pull_request.enable_automerge.assert_called_once_with(merge_method="SQUASH")

2 changes: 1 addition & 1 deletion tests/managers/test_pull_request.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ def test_handle_create_pull_request(pull_request_helper):
repository, "branch"
)
pr = pull_request_helper.get_or_create_pull_request.return_value
pull_request_helper.enable_auto_merge.assert_called_once_with(pr)
pr.enable_automerge.assert_called_once_with(merge_method="SQUASH")


def test_handle_create_pull_request_ignore_when_head_branch_is_the_default_branch(
Expand Down
15 changes: 0 additions & 15 deletions tests/test_app.py
Original file line number Diff line number Diff line change
Expand Up @@ -99,21 +99,6 @@ def test_index(self):
"index.html", title="Bartholomew Smith", body=body
)

def test_file(self):
response = self.client.get("/pull-request.md")
assert response.status_code == 200
with open("pull-request.md") as f:
md = f.read()
body = markdown.markdown(md)
self.mock_render_template.assert_called_once_with(
"index.html", title="Bartholomew Smith - Pull Request", body=body
)

def test_file_security(self):
response = self.client.get("/other.txt")
assert response.status_code == 404
self.mock_render_template.assert_not_called()


def test_managers_disabled(
handle_create_pull_request_mock, handle_release_mock, handle_tasklist_mock
Expand Down

0 comments on commit b8c5caa

Please sign in to comment.