Skip to content

Commit 3cd820a

Browse files
committed
Several fixed after overtake of issue.
1 parent a0f94e5 commit 3cd820a

File tree

9 files changed

+44
-25
lines changed

9 files changed

+44
-25
lines changed

.gitignore

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -159,4 +159,4 @@ cython_debug/
159159
.idea/
160160

161161
default_output.txt
162-
run_localy.sh
162+
run_locally.sh

DEVELOPER.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -146,7 +146,7 @@ open htmlcov/index.html
146146
```
147147

148148
## Run Action Locally
149-
Create *.sh file and place it in the project root.
149+
Create run_locally.sh file and place it in the project root.
150150

151151
```bash
152152
#!/bin/bash

release_notes_generator/action_inputs.py

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -336,7 +336,12 @@ def validate_inputs() -> None:
336336
else:
337337
ActionInputs._owner = ActionInputs._repo_name = ""
338338

339-
if not isinstance(ActionInputs._owner, str) or not ActionInputs._owner.strip() or not isinstance(ActionInputs._repo_name, str) or not ActionInputs._repo_name.strip():
339+
if (
340+
not isinstance(ActionInputs._owner, str)
341+
or not ActionInputs._owner.strip()
342+
or not isinstance(ActionInputs._repo_name, str)
343+
or not ActionInputs._repo_name.strip()
344+
):
340345
errors.append("Owner and Repo must be a non-empty string.")
341346

342347
tag_name = ActionInputs.get_tag_name()

release_notes_generator/filter.py

Lines changed: 12 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@
2222

2323
logger = logging.getLogger(__name__)
2424

25+
2526
class Filter:
2627
"""
2728
Base class for filtering records.
@@ -44,16 +45,21 @@ class FilterByRelease(Filter):
4445

4546
def __init__(self, release_version: Optional[str] = None):
4647
self.release_version = release_version
48+
# TODO - check usage of release_version, as it is not used in the current implementation
49+
# it is also part of the MinedData class, so it might be redundant here
4750

48-
def filter(self, data: MinedData):
51+
def filter(self, data: MinedData) -> MinedData:
4952
"""
5053
Filters issues, pull requests, and commits based on the latest release date.
5154
If the release is not None, it filters out closed issues, merged pull requests, and commits
5255
that occurred before the release date.
53-
@param data: The mined data containing issues, pull requests, commits, and release information.
54-
@return: The filtered mined data.
55-
"""
5656
57+
@Parameters:
58+
- data (MinedData): The mined data containing issues, pull requests, commits, and release information.
59+
60+
@Returns:
61+
- MinedData: The filtered mined data with issues, pull requests, and commits reduced based on the release date.
62+
"""
5763
issues_list = data.issues
5864
pulls_list = data.pull_requests
5965
commits_list = data.commits
@@ -76,3 +82,5 @@ def filter(self, data: MinedData):
7682
data.commits = list(filter(lambda commit: commit.commit.author.date > data.since, commits_list))
7783
logger.debug("Count of commits reduced from %d to %d", len(commits_list), len(data.commits))
7884

85+
return data
86+

release_notes_generator/generator.py

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -69,25 +69,25 @@ def generate(self, filterer: Filter) -> Optional[str]:
6969
"""
7070
Generates the Release Notes for a given repository.
7171
72+
@Parameters:
73+
- filterer: An instance of Filter that will be used to filter the mined data.
74+
7275
@return: The generated release notes as a string, or None if the repository could not be found.
7376
"""
7477
miner = DataMiner(self._github_instance, self._rate_limiter)
7578
data = miner.mine_data()
7679
if data.is_empty():
7780
return None
7881

79-
filterer.filter(data=data)
82+
filtered_data = filterer.filter(data=data)
8083

8184
changelog_url: str = get_change_url(
82-
tag_name=ActionInputs.get_tag_name(), repository=data.repository, git_release=data.release
85+
tag_name=ActionInputs.get_tag_name(), repository=filtered_data.repository, git_release=filtered_data.release
8386
)
8487

85-
assert data.repository is not None, "Repository must not be None"
88+
assert filtered_data.repository is not None, "Repository must not be None"
8689

87-
rls_notes_records: dict[int, Record] = RecordFactory.generate(
88-
github=self._github_instance,
89-
data=data
90-
)
90+
rls_notes_records: dict[int, Record] = RecordFactory.generate(github=self._github_instance, data=filtered_data)
9191

9292
release_notes_builder = ReleaseNotesBuilder(
9393
records=rls_notes_records,

release_notes_generator/model/record.py

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -440,6 +440,7 @@ def is_pull_request_merged(pull: PullRequest) -> bool:
440440
"""
441441
return pull.state == PR_STATE_CLOSED and pull.merged_at is not None and pull.closed_at is not None
442442

443+
443444
class PullRequestRecord(Record):
444445
"""
445446
A class used to represent a pull request record in the release notes.
@@ -463,6 +464,7 @@ def __init__(self, issue: Issue, skip: bool = False):
463464
super().__init__(issue=issue, skip=skip)
464465
self.__is_release_note_detected = self.contains_release_notes
465466

467+
466468
class CommitRecord(Record):
467469
"""
468470
A class used to represent a direct commit record in the release notes.
@@ -472,4 +474,4 @@ class CommitRecord(Record):
472474
def __init__(self, commit: Commit, skip: bool = False):
473475
super().__init__(issue=None, skip=skip)
474476
self.register_commit(commit)
475-
self.__is_release_note_detected = self.contains_release_notes
477+
self.__is_release_note_detected = self.contains_release_notes

release_notes_generator/record/record_factory.py

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -44,9 +44,7 @@ class RecordFactory:
4444
"""
4545

4646
@staticmethod
47-
def generate(
48-
github: Github, data: MinedData
49-
) -> dict[int, Record]:
47+
def generate(github: Github, data: MinedData) -> dict[int, Record]:
5048
"""
5149
Generate records for release notes.
5250

release_notes_generator/utils/pull_request_utils.py

Lines changed: 12 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@
2727
from action_inputs import ActionInputs
2828
from release_notes_generator.utils.constants import ISSUES_FOR_PRS, LINKED_ISSUES_MAX
2929

30+
3031
## todo romove
3132
def extract_issue_numbers_from_body(pr: PullRequest) -> list[int]:
3233
"""
@@ -46,20 +47,25 @@ def extract_issue_numbers_from_body(pr: PullRequest) -> list[int]:
4647

4748
return issue_numbers
4849

50+
4951
@lru_cache(maxsize=None)
5052
def get_issues_for_pr(pull_number: int) -> list[int]:
5153
"""Update the placeholder values and formate the graphQL query"""
5254
github_api_url = "https://api.github.com/graphql"
53-
query = ISSUES_FOR_PRS.format(number=pull_number,
54-
owner=ActionInputs.get_github_owner(),
55-
name=ActionInputs.get_github_repo_name(),
56-
first=LINKED_ISSUES_MAX)
55+
query = ISSUES_FOR_PRS.format(
56+
number=pull_number,
57+
owner=ActionInputs.get_github_owner(),
58+
name=ActionInputs.get_github_repo_name(),
59+
first=LINKED_ISSUES_MAX,
60+
)
5761
headers = {
5862
"Authorization": f"Bearer {ActionInputs.get_github_token()}",
5963
"Content-Type": "application/json",
6064
}
6165
response = requests.post(github_api_url, json={"query": query}, headers=headers)
6266
response.raise_for_status() # Raise an error for HTTP issues
63-
numbers = [node['number'] for node in response.json()['data']['repository']['pullRequest']['closingIssuesReferences']['nodes']]
67+
numbers = [
68+
node["number"]
69+
for node in response.json()["data"]["repository"]["pullRequest"]["closingIssuesReferences"]["nodes"]
70+
]
6471
return numbers
65-

tests/test_filter.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -84,4 +84,4 @@ def test_filter_with_release(mocker):
8484
assert ('Starting issue, prs and commit reduction by the latest release since time.',) == mock_log_info.call_args_list[0][0]
8585
assert ('Count of issues reduced from %d to %d', 2, 1) == mock_log_debug.call_args_list[0][0]
8686
assert ('Count of pulls reduced from %d to %d', 2, 1) == mock_log_debug.call_args_list[1][0]
87-
assert ('Count of commits reduced from %d to %d', 2, 1) == mock_log_debug.call_args_list[2][0]
87+
assert ('Count of commits reduced from %d to %d', 2, 1) == mock_log_debug.call_args_list[2][0]

0 commit comments

Comments
 (0)