-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
refactor: introduce pull request class (#10)
By using an object it makes the code easier to read. It also moves the logic to create pull request proposals to its own class. Issue: #8
- Loading branch information
Joris Conijn
committed
Jan 24, 2022
1 parent
5b87e37
commit e15ccf9
Showing
5 changed files
with
110 additions
and
17 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
from pull_request_codecommit.git import Commits | ||
|
||
|
||
class PullRequest: | ||
""" | ||
Understands pull requests | ||
""" | ||
|
||
def __init__(self, commits: Commits) -> None: | ||
self.__commits = commits | ||
|
||
@property | ||
def has_changes(self) -> bool: | ||
return True if self.__commits.first else False | ||
|
||
@property | ||
def title(self) -> str: | ||
if not self.__commits.first: | ||
return "" | ||
|
||
title = self.__commits.first.message.subject | ||
|
||
if self.__commits.issues: | ||
title += f" ({', '.join(self.__commits.issues)})" | ||
|
||
return title | ||
|
||
@property | ||
def description(self) -> str: | ||
description = list(map(lambda commit: commit.message.subject, self.__commits)) | ||
|
||
if self.__commits.issues: | ||
description.append(f"\nIssues: " + ", ".join(self.__commits.issues)) | ||
|
||
return "\n".join(description) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,67 @@ | ||
import pytest | ||
|
||
from pull_request_codecommit.git import Commits | ||
from pull_request_codecommit.pull_request import PullRequest | ||
|
||
|
||
COMMIT_SIMPLE_MESSAGE = """commit my-hash-1 | ||
Author: John Doe <john@doe.nl> | ||
Date: Fri Jan 21 21:01:00 2022 +0100 | ||
feat: my first commit""" | ||
|
||
COMMIT_DETAILED_MESSAGE = """commit my-hash-1 | ||
Author: John Doe <john@doe.nl> | ||
Date: Fri Jan 21 21:01:00 2022 +0100 | ||
feat: my first commit | ||
Some additional information""" | ||
|
||
COMMIT_SIMPLE_MESSAGE_ISSUE = """commit my-hash-1 | ||
Author: John Doe <john@doe.nl> | ||
Date: Fri Jan 21 21:01:00 2022 +0100 | ||
feat: my first commit | ||
Issue: #1""" | ||
|
||
COMMIT_DETAILED_MESSAGE_ISSUE = """commit my-hash-1 | ||
Author: John Doe <john@doe.nl> | ||
Date: Fri Jan 21 21:01:00 2022 +0100 | ||
feat: my first commit | ||
Some additional information | ||
Issue: #1""" | ||
|
||
|
||
@pytest.mark.parametrize( | ||
"commits, expected_title, expected_description", | ||
[ | ||
(Commits(COMMIT_SIMPLE_MESSAGE), "feat: my first commit", ""), | ||
(Commits(COMMIT_DETAILED_MESSAGE), "feat: my first commit", ""), | ||
( | ||
Commits(COMMIT_SIMPLE_MESSAGE_ISSUE), | ||
"feat: my first commit (#1)", | ||
"\nIssues: #1", | ||
), | ||
( | ||
Commits(COMMIT_DETAILED_MESSAGE_ISSUE), | ||
"feat: my first commit (#1)", | ||
"\nIssues: #1", | ||
), | ||
( | ||
Commits(""), | ||
"", | ||
"", | ||
), | ||
], | ||
) | ||
def test_git_client( | ||
commits: Commits, expected_title: str, expected_description: str | ||
) -> None: | ||
pull_request = PullRequest(commits) | ||
assert pull_request.title == expected_title | ||
assert pull_request.description == expected_description |