From d23aa3e85837577c2364bedef8f0c2082d9034aa Mon Sep 17 00:00:00 2001 From: miroslavpojer Date: Thu, 12 Dec 2024 14:51:59 +0100 Subject: [PATCH] #105 - Fix problem in output of pylint - Implemented several fixed of pylint warnings. --- release_notes_generator/model/record.py | 10 +-- .../record/record_factory.py | 15 ++-- tests/conftest.py | 72 +++++-------------- 3 files changed, 28 insertions(+), 69 deletions(-) diff --git a/release_notes_generator/model/record.py b/release_notes_generator/model/record.py index 7e5a1b4b..38a1a6da 100644 --- a/release_notes_generator/model/record.py +++ b/release_notes_generator/model/record.py @@ -25,7 +25,6 @@ from github.Issue import Issue from github.PullRequest import PullRequest -from github.Repository import Repository from github.Commit import Commit from release_notes_generator.action_inputs import ActionInputs @@ -40,15 +39,13 @@ logger = logging.getLogger(__name__) -# TODO - recheck the size of class, is there a way to reduce or split it? # pylint: disable=too-many-instance-attributes, too-many-public-methods class Record: """ A class used to represent a record in the release notes. """ - def __init__(self, repo: Repository, issue: Optional[Issue] = None, skip: bool = False): - self.__repo: Repository = repo + def __init__(self, issue: Optional[Issue] = None, skip: bool = False): self.__gh_issue: Issue = issue self.__pulls: list[PullRequest] = [] self.__pull_commits: dict = {} @@ -133,7 +130,7 @@ def labels(self) -> list[str]: return [label.name for label in self.__gh_issue.labels] - def get_rls_notes(self, detection_pattern: str, line_marks: str = RELEASE_NOTE_LINE_MARKS) -> str: + def get_rls_notes(self, detection_pattern: str, line_marks: str = None) -> str: """ Gets the release notes of the record. @@ -141,6 +138,9 @@ def get_rls_notes(self, detection_pattern: str, line_marks: str = RELEASE_NOTE_L @param line_marks: The line marks to use. @return: The release notes of the record as a string. """ + if line_marks is None: + line_marks = RELEASE_NOTE_LINE_MARKS + release_notes = "" # Compile the regex pattern for efficiency diff --git a/release_notes_generator/record/record_factory.py b/release_notes_generator/record/record_factory.py index ee9541a5..21faf13e 100644 --- a/release_notes_generator/record/record_factory.py +++ b/release_notes_generator/record/record_factory.py @@ -36,7 +36,7 @@ logger = logging.getLogger(__name__) -# pylint: disable=too-few-public-methods +# pylint: disable=too-few-public-methods, too-many-locals class RecordFactory: """ A class used to generate records for release notes. @@ -59,18 +59,17 @@ def generate( records = {} pull_numbers = [pull.number for pull in pulls] - def create_record_for_issue(r: Repository, i: Issue) -> None: + def create_record_for_issue(i: Issue) -> None: """ Create a record for an issue. - @param r: Repository instance. @param i: Issue instance. @return: None """ # check for skip labels presence and skip when detected issue_labels = [label.name for label in i.labels] skip_record = any(item in issue_labels for item in ActionInputs.get_skip_release_notes_labels()) - records[i.number] = Record(r, i, skip=skip_record) + records[i.number] = Record(i, skip=skip_record) logger.debug("Created record for issue %d: %s", i.number, i.title) @@ -85,13 +84,13 @@ def register_pull_request(pull: PullRequest, skip_record: bool) -> None: ) parent_issue = safe_call(repo.get_issue)(parent_issue_number) if parent_issue is not None: - create_record_for_issue(repo, parent_issue) + create_record_for_issue(parent_issue) if parent_issue_number in records: records[parent_issue_number].register_pull_request(pull) logger.debug("Registering PR %d: %s to Issue %d", pull.number, pull.title, parent_issue_number) else: - records[pull.number] = Record(repo, skip=skip_record) + records[pull.number] = Record(skip=skip_record) records[pull.number].register_pull_request(pull) logger.debug( "Registering stand-alone PR %d: %s as mentioned Issue %d not found.", @@ -118,14 +117,14 @@ def register_commit_to_record(commit: Commit) -> bool: for issue in issues: if issue.number not in pull_numbers: - create_record_for_issue(repo, issue) + create_record_for_issue(issue) for pull in pulls: pull_labels = [label.name for label in pull.labels] skip_record: bool = any(item in pull_labels for item in ActionInputs.get_skip_release_notes_labels()) if not extract_issue_numbers_from_body(pull): - records[pull.number] = Record(repo, skip=skip_record) + records[pull.number] = Record(skip=skip_record) records[pull.number].register_pull_request(pull) logger.debug("Created record for PR %d: %s", pull.number, pull.title) else: diff --git a/tests/conftest.py b/tests/conftest.py index 87777346..afe2f426 100644 --- a/tests/conftest.py +++ b/tests/conftest.py @@ -378,97 +378,68 @@ def mock_commit(mocker): # Fixtures for Record(s) @pytest.fixture def record_with_issue_open_no_pull(request): - mock_repo_fixture = request.getfixturevalue("mock_repo") - return Record(repo=mock_repo_fixture, issue=request.getfixturevalue("mock_issue_open")) + return Record(issue=request.getfixturevalue("mock_issue_open")) @pytest.fixture def record_with_issue_closed_no_pull(request): - rec = Record( - repo=(mock_repo_fixture := request.getfixturevalue("mock_repo")), - issue=request.getfixturevalue("mock_issue_closed"), - ) - mock_repo_fixture.full_name = "org/repo" - return rec + return Record(issue=request.getfixturevalue("mock_issue_closed")) @pytest.fixture def record_with_issue_closed_one_pull(request): - rec = Record( - repo=(mock_repo_fixture := request.getfixturevalue("mock_repo")), - issue=request.getfixturevalue("mock_issue_closed"), - ) + rec = Record(issue=request.getfixturevalue("mock_issue_closed")) rec.register_pull_request(request.getfixturevalue("mock_pull_closed")) - mock_repo_fixture.full_name = "org/repo" return rec @pytest.fixture def record_with_issue_closed_one_pull_merged(request): - rec = Record( - repo=(mock_repo_fixture := request.getfixturevalue("mock_repo")), - issue=request.getfixturevalue("mock_issue_closed_i1_bug"), - ) + rec = Record(issue=request.getfixturevalue("mock_issue_closed_i1_bug")) rec.register_pull_request(request.getfixturevalue("mock_pull_merged")) - mock_repo_fixture.full_name = "org/repo" return rec @pytest.fixture def record_with_issue_closed_one_pull_merged_skip(request): rec = Record( - repo=(mock_repo_fixture := request.getfixturevalue("mock_repo")), issue=request.getfixturevalue("mock_issue_closed_i1_bug_and_skip"), skip=True, ) rec.register_pull_request(request.getfixturevalue("mock_pull_merged")) - mock_repo_fixture.full_name = "org/repo" return rec @pytest.fixture def record_with_issue_closed_two_pulls(request): - rec = Record( - repo=(mock_repo_fixture := request.getfixturevalue("mock_repo")), - issue=request.getfixturevalue("mock_issue_closed_i1_bug"), - ) + rec = Record(issue=request.getfixturevalue("mock_issue_closed_i1_bug")) rec.register_pull_request(request.getfixturevalue("mock_pull_closed_with_rls_notes_101")) rec.register_pull_request(request.getfixturevalue("mock_pull_closed_with_rls_notes_102")) - mock_repo_fixture.full_name = "org/repo" return rec @pytest.fixture def record_with_issue_open_one_pull_closed(request): - rec = Record( - repo=(mock_repo_fixture := request.getfixturevalue("mock_repo")), - issue=request.getfixturevalue("mock_issue_open"), - ) + rec = Record(issue=request.getfixturevalue("mock_issue_open")) rec.register_pull_request(request.getfixturevalue("mock_pull_closed")) - mock_repo_fixture.full_name = "org/repo" return rec @pytest.fixture def record_with_issue_open_two_pulls_closed(request): - rec = Record( - repo=(mock_repo_fixture := request.getfixturevalue("mock_repo")), - issue=request.getfixturevalue("mock_issue_open"), - ) + rec = Record(issue=request.getfixturevalue("mock_issue_open")) rec.register_pull_request(request.getfixturevalue("mock_pull_closed_with_rls_notes_101")) rec.register_pull_request(request.getfixturevalue("mock_pull_closed_with_rls_notes_102")) - mock_repo_fixture.full_name = "org/repo" return rec @pytest.fixture def record_with_two_issue_open_two_pulls_closed(request): - rec1 = Record(repo=(mock_repo_fixture := request.getfixturevalue("mock_repo"))) + rec1 = Record() rec1.register_pull_request(request.getfixturevalue("mock_pull_merged_with_rls_notes_101")) - rec2 = Record(repo=mock_repo_fixture) + rec2 = Record() rec2.register_pull_request(request.getfixturevalue("mock_pull_merged_with_rls_notes_102")) - mock_repo_fixture.full_name = "org/repo" records = {} records[rec1.number] = rec1 @@ -479,20 +450,15 @@ def record_with_two_issue_open_two_pulls_closed(request): @pytest.fixture def record_with_issue_closed_one_pull_no_rls_notes(request): - rec = Record( - repo=(mock_repo_fixture := request.getfixturevalue("mock_repo")), - issue=request.getfixturevalue("mock_issue_closed"), - ) + rec = Record(issue=request.getfixturevalue("mock_issue_closed")) rec.register_pull_request(mock_pull_closed_fixture := request.getfixturevalue("mock_pull_no_rls_notes")) mock_pull_closed_fixture.body = "Fixed bug" - mock_repo_fixture.full_name = "org/repo" return rec @pytest.fixture def record_with_no_issue_one_pull_merged(request): - record = Record(repo=(mock_repo_fixture := request.getfixturevalue("mock_repo"))) - mock_repo_fixture.full_name = "org/repo" + record = Record() record.register_pull_request(request.getfixturevalue("mock_pull_merged")) record.register_commit(request.getfixturevalue("mock_commit")) return record @@ -500,8 +466,7 @@ def record_with_no_issue_one_pull_merged(request): @pytest.fixture def record_with_no_issue_one_pull_open(request): - record = Record(repo=(mock_repo_fixture := request.getfixturevalue("mock_repo"))) - mock_repo_fixture.full_name = "org/repo" + record = Record() record.register_pull_request(request.getfixturevalue("mock_pull_open")) record.register_commit(request.getfixturevalue("mock_commit")) return record @@ -509,8 +474,7 @@ def record_with_no_issue_one_pull_open(request): @pytest.fixture def record_with_no_issue_one_pull_merged_with_issue_mentioned(request): - record = Record(repo=(mock_repo_fixture := request.getfixturevalue("mock_repo"))) - mock_repo_fixture.full_name = "org/repo" + record = Record() mock_pull_merged_fixture = request.getfixturevalue("mock_pull_merged") mock_pull_merged_fixture.body = "Release Notes:\n- Fixed bug\n- Improved performance\n\nFixes #123" record.register_pull_request(mock_pull_merged_fixture) @@ -520,9 +484,7 @@ def record_with_no_issue_one_pull_merged_with_issue_mentioned(request): @pytest.fixture def record_with_no_issue_one_pull_closed(request): - record = Record(repo=(mock_repo_fixture := request.getfixturevalue("mock_repo"))) - mock_repo_fixture.full_name = "org/repo" - mock_repo_fixture.draft = False + record = Record() record.register_pull_request(request.getfixturevalue("mock_pull_closed")) record.register_commit(request.getfixturevalue("mock_commit")) return record @@ -530,9 +492,7 @@ def record_with_no_issue_one_pull_closed(request): @pytest.fixture def record_with_no_issue_one_pull_closed_with_skip_label(request): - record = Record(repo=(mock_repo_fixture := request.getfixturevalue("mock_repo")), skip=True) - mock_repo_fixture.full_name = "org/repo" - mock_repo_fixture.draft = False + record = Record(skip=True) record.register_pull_request(request.getfixturevalue("mock_pull_closed_with_skip_label")) record.register_commit(request.getfixturevalue("mock_commit")) return record @@ -540,7 +500,7 @@ def record_with_no_issue_one_pull_closed_with_skip_label(request): @pytest.fixture def record_with_no_issue_one_pull_closed_no_rls_notes(request): - record = Record(repo=request.getfixturevalue("mock_repo")) + record = Record() record.register_pull_request(request.getfixturevalue("mock_pull_no_rls_notes")) return record