Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

#105 - Fix problem in output of pylint #125

Merged
merged 1 commit into from
Dec 12, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 5 additions & 5 deletions release_notes_generator/model/record.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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 = {}
Expand Down Expand Up @@ -133,14 +130,17 @@ 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.

@param detection_pattern: The detection pattern (regex allowed) to use.
@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
Expand Down
15 changes: 7 additions & 8 deletions release_notes_generator/record/record_factory.py
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand All @@ -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)

Expand All @@ -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.",
Expand All @@ -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:
Expand Down
72 changes: 16 additions & 56 deletions tests/conftest.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -479,38 +450,31 @@ 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


@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


@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)
Expand All @@ -520,27 +484,23 @@ 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


@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


@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

Expand Down
Loading