-
-
Notifications
You must be signed in to change notification settings - Fork 22
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
Script to fetch changelog #295
Conversation
WalkthroughA new script, Changes
Poem
Thank you for using CodeRabbit. We offer it for free to the OSS community and would appreciate your support in helping us grow. If you find it useful, would you consider giving us a shout-out on your favorite social media? TipsChatThere are 3 ways to chat with CodeRabbit:
Note: Be mindful of the bot's finite context window. It's strongly recommended to break down tasks such as reading entire modules into smaller chunks. For a focused discussion, use review comments to chat about specific files and their changes, instead of using the PR comments. CodeRabbit Commands (invoked as PR comments)
Additionally, you can add CodeRabbit Configration File (
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Actionable comments posted: 10
Review details
Configuration used: CodeRabbit UI
Review profile: CHILL
Files selected for processing (2)
- README.md (1 hunks)
- scripts/changelog_harvest.py (1 hunks)
Additional context used
Ruff
scripts/changelog_harvest.py
2-2: UTF-8 encoding declaration is unnecessary
Remove unnecessary coding comment
(UP009)
65-65: Unnecessary open mode parameters
Remove open mode parameters
(UP015)
88-88:
re.sub
should passcount
andflags
as keyword arguments to avoid confusion due to unintuitive argument positions(B034)
100-100: Unnecessary open mode parameters
Remove open mode parameters
(UP015)
LanguageTool
README.md
[uncategorized] ~281-~281: Possible missing article found.
Context: ... >}} ``` ### LT/LTR release variables Script for parsing release schedule from the g...(AI_HYDRA_LEO_MISSING_THE)
[grammar] ~282-~282: “Google” is a proper noun and needs to be capitalized.
Context: ...t for parsing release schedule from the google spreadsheet is scripts/update-schedule....(A_GOOGLE)
Markdownlint
README.md
287-287: null
Fenced code blocks should be surrounded by blank lines(MD031, blanks-around-fences)
287-287: null
Fenced code blocks should have a language specified(MD040, fenced-code-language)
296-296: null
Fenced code blocks should have a language specified(MD040, fenced-code-language)
Additional comments not posted (4)
scripts/changelog_harvest.py (3)
104-106
: LGTM!The
format_release_date
function works correctly and follows best practices.
108-112
: LGTM!The
parse_arguments
function works correctly and follows best practices.
45-45
: Remove unnecessary open mode parameters.The open mode parameters are unnecessary.
- with open(zip_filename, 'wb') as file: + with open(zip_filename, 'w') as file:Likely invalid or redundant comment.
README.md (1)
293-293
: LGTM!The example usage in markdown is clear and follows best practices.
|
||
|
||
def load_config(config_path): | ||
with open(config_path, 'r') as file: |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Remove unnecessary open mode parameters.
The open mode parameters are unnecessary.
- with open(config_path, 'r') as file:
+ with open(config_path) as file:
Committable suggestion
‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.
with open(config_path, 'r') as file: | |
with open(config_path) as file: |
Tools
Ruff
100-100: Unnecessary open mode parameters
Remove open mode parameters
(UP015)
release_date = format_release_date(args.release) | ||
elif not args.version and not args.release: | ||
# Load configuration from JSON | ||
config_path = 'data/conf.json' |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Replace hardcoded configuration path with a configurable path.
The hardcoded configuration path should be replaced with a configurable path.
- config_path = 'data/conf.json'
+ config_path = args.config if args.config else 'data/conf.json'
Committable suggestion
‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.
config_path = 'data/conf.json' | |
config_path = args.config if args.config else 'data/conf.json' |
scripts/changelog_harvest.py
Outdated
# url = f'https://changelog.qgis.org/en/qgis/version/{version}/md/' | ||
url = f'http://localhost:61202/en/qgis/version/{version}/md/' |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Replace hardcoded URL with a configurable URL.
The URL is hardcoded to localhost for testing purposes. It should be replaced with a configurable URL.
- url = f'http://localhost:61202/en/qgis/version/{version}/md/'
+ config = load_config('data/conf.json')
+ url = config['changelog_url'].format(version=version)
Committable suggestion was skipped due to low confidence.
content = re.sub(r'^(# .+)', r'\1 {#changelog' + version_formatted + '}', content, flags=re.M) | ||
|
||
# Insert release date after the first image | ||
content = re.sub(r'(!\[.*?\]\(.*?\))', r'\1\n\nRelease date: ' + release_date, content, 1) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Pass count
and flags
as keyword arguments in re.sub
.
The re.sub
function should pass count
and flags
as keyword arguments to avoid confusion.
- content = re.sub(r'(!\[.*?\]\(.*?\))', r'\1\n\nRelease date: ' + release_date, 1)
+ content = re.sub(r'(!\[.*?\]\(.*?\))', r'\1\n\nRelease date: ' + release_date, count=1)
Committable suggestion
‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.
content = re.sub(r'(!\[.*?\]\(.*?\))', r'\1\n\nRelease date: ' + release_date, content, 1) | |
content = re.sub(r'(!\[.*?\]\(.*?\))', r'\1\n\nRelease date: ' + release_date, count=1) |
Tools
Ruff
88-88:
re.sub
should passcount
andflags
as keyword arguments to avoid confusion due to unintuitive argument positions(B034)
Script for harvesting the visualchangelog from changelog.qgis.org is scripts/changelog_harvest.py. It will create/update a visual-changelogs at content/project/visual-changelogs based on the data at data/conf.json. | ||
|
||
Usage: | ||
``` |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Specify language for fenced code blocks.
Fenced code blocks should have a language specified.
- ```
+ ```bash
Tools
Markdownlint
287-287: null
Fenced code blocks should be surrounded by blank lines(MD031, blanks-around-fences)
287-287: null
Fenced code blocks should have a language specified(MD040, fenced-code-language)
# For a specific version | ||
$ python3 scripts/changelog_harvest.py --version 3.34 --release 21.06.2024 | ||
``` | ||
|
||
Example usage in md: | ||
|
||
``` |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Specify language for fenced code blocks.
Fenced code blocks should have a language specified.
- ```
+ ```bash
Tools
Markdownlint
296-296: null
Fenced code blocks should have a language specified(MD040, fenced-code-language)
@@ -281,6 +281,16 @@ | |||
|
|||
Script for parsing release schedule from the google spreadsheet is scripts/update-schedule.py. It creates data/conf.json with variables that can be used later in md/html. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Capitalize "Google".
"Google" is a proper noun and needs to be capitalized.
- google spreadsheet
+ Google spreadsheet
Committable suggestion
‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.
Script for parsing release schedule from the google spreadsheet is scripts/update-schedule.py. It creates data/conf.json with variables that can be used later in md/html. | |
Script for parsing release schedule from the Google spreadsheet is scripts/update-schedule.py. It creates data/conf.json with variables that can be used later in md/html. |
Tools
LanguageTool
[grammar] ~282-~282: “Google” is a proper noun and needs to be capitalized.
Context: ...t for parsing release schedule from the google spreadsheet is scripts/update-schedule....(A_GOOGLE)
@@ -281,6 +281,16 @@ | |||
|
|||
Script for parsing release schedule from the google spreadsheet is scripts/update-schedule.py. It creates data/conf.json with variables that can be used later in md/html. | |||
|
|||
Script for harvesting the visualchangelog from changelog.qgis.org is scripts/changelog_harvest.py. It will create/update a visual-changelogs at content/project/visual-changelogs based on the data at data/conf.json. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Add missing article.
There is a missing article in the sentence.
- Script for harvesting the visualchangelog from changelog.qgis.org is scripts/changelog_harvest.py.
+ The script for harvesting the visualchangelog from changelog.qgis.org is scripts/changelog_harvest.py.
Committable suggestion
‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.
Script for harvesting the visualchangelog from changelog.qgis.org is scripts/changelog_harvest.py. It will create/update a visual-changelogs at content/project/visual-changelogs based on the data at data/conf.json. | |
The script for harvesting the visualchangelog from changelog.qgis.org is scripts/changelog_harvest.py. It will create/update a visual-changelogs at content/project/visual-changelogs based on the data at data/conf.json. |
@@ -281,6 +281,16 @@ | |||
|
|||
Script for parsing release schedule from the google spreadsheet is scripts/update-schedule.py. It creates data/conf.json with variables that can be used later in md/html. | |||
|
|||
Script for harvesting the visualchangelog from changelog.qgis.org is scripts/changelog_harvest.py. It will create/update a visual-changelogs at content/project/visual-changelogs based on the data at data/conf.json. | |||
|
|||
Usage: |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Add blank lines around fenced code blocks.
Fenced code blocks should be surrounded by blank lines.
- Usage:
+ Usage:
Committable suggestion was skipped due to low confidence.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Actionable comments posted: 5
Review details
Configuration used: CodeRabbit UI
Review profile: CHILL
Files selected for processing (1)
- scripts/changelog_harvest.py (1 hunks)
Additional context used
Ruff
scripts/changelog_harvest.py
2-2: UTF-8 encoding declaration is unnecessary
Remove unnecessary coding comment
(UP009)
64-64: Unnecessary open mode parameters
Remove open mode parameters
(UP015)
87-87:
re.sub
should passcount
andflags
as keyword arguments to avoid confusion due to unintuitive argument positions(B034)
99-99: Unnecessary open mode parameters
Remove open mode parameters
(UP015)
Additional comments not posted (3)
scripts/changelog_harvest.py (3)
103-105
: LGTM!The function is correctly implemented.
107-111
: LGTM!The function is correctly implemented.
113-130
: Replace hardcoded URL with a configurable URL.The URL is hardcoded to localhost for testing purposes. It should be replaced with a configurable URL.
- url = f'http://localhost:61202/en/qgis/version/{version}/md/' + config = load_config('data/conf.json') + url = config['changelog_url'].format(version=version)Likely invalid or redundant comment.
if __name__ == '__main__': | ||
# Parse command-line arguments | ||
args = parse_arguments() | ||
|
||
if args.version and args.release: | ||
version = args.version | ||
release_date = format_release_date(args.release) | ||
elif not args.version and not args.release: | ||
# Load configuration from JSON | ||
config_path = 'data/conf.json' | ||
config = load_config(config_path) | ||
version = config['version'] | ||
release_date = format_release_date(config['releasedate']) | ||
else: | ||
print("Error: You must specify both --version and --release, or neither.") | ||
sys.exit(1) | ||
|
||
download_and_extract_zip(version, release_date) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Replace hardcoded configuration path with a configurable path.
The hardcoded configuration path should be replaced with a configurable path.
- config_path = 'data/conf.json'
+ config_path = args.config if args.config else 'data/conf.json'
Committable suggestion
‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.
if __name__ == '__main__': | |
# Parse command-line arguments | |
args = parse_arguments() | |
if args.version and args.release: | |
version = args.version | |
release_date = format_release_date(args.release) | |
elif not args.version and not args.release: | |
# Load configuration from JSON | |
config_path = 'data/conf.json' | |
config = load_config(config_path) | |
version = config['version'] | |
release_date = format_release_date(config['releasedate']) | |
else: | |
print("Error: You must specify both --version and --release, or neither.") | |
sys.exit(1) | |
download_and_extract_zip(version, release_date) | |
if __name__ == '__main__': | |
# Parse command-line arguments | |
args = parse_arguments() | |
if args.version and args.release: | |
version = args.version | |
release_date = format_release_date(args.release) | |
elif not args.version and not args.release: | |
# Load configuration from JSON | |
config_path = args.config if args.config else 'data/conf.json' | |
config = load_config(config_path) | |
version = config['version'] | |
release_date = format_release_date(config['releasedate']) | |
else: | |
print("Error: You must specify both --version and --release, or neither.") | |
sys.exit(1) | |
download_and_extract_zip(version, release_date) |
scripts/changelog_harvest.py
Outdated
def modify_index_file(index_file_path, version, version_formatted, release_date): | ||
print(f'Modifying {index_file_path}') | ||
with open(index_file_path, 'r') as file: | ||
content = file.read() | ||
|
||
# Add front matter | ||
front_matter = f"""--- | ||
type: "page" | ||
title: "Changelog for QGIS {version}" | ||
draft: false | ||
HasBanner: false | ||
sidebar: true | ||
releaseDate: "{release_date}" | ||
|
||
--- | ||
|
||
{{{{< content-start >}}}} | ||
|
||
""" | ||
content = front_matter + content | ||
|
||
# Add id to the first heading | ||
content = re.sub(r'^(# .+)', r'\1 {#changelog' + version_formatted + '}', content, flags=re.M) | ||
|
||
# Insert release date after the first image | ||
content = re.sub(r'(!\[.*?\]\(.*?\))', r'\1\n\nRelease date: ' + release_date, content, 1) | ||
|
||
# Append content-end | ||
content += '\n\n{{< content-end >}}' | ||
|
||
# Write the modified content back to the file | ||
with open(index_file_path, 'w') as file: | ||
file.write(content) | ||
print(f'Modified {index_file_path}') |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Pass count
and flags
as keyword arguments in re.sub
.
The re.sub
function should pass count
and flags
as keyword arguments to avoid confusion.
- content = re.sub(r'(!\[.*?\]\(.*?\))', r'\1\n\nRelease date: ' + release_date, 1)
+ content = re.sub(r'(!\[.*?\]\(.*?\))', r'\1\n\nRelease date: ' + release_date, count=1)
Committable suggestion
‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.
def modify_index_file(index_file_path, version, version_formatted, release_date): | |
print(f'Modifying {index_file_path}') | |
with open(index_file_path, 'r') as file: | |
content = file.read() | |
# Add front matter | |
front_matter = f"""--- | |
type: "page" | |
title: "Changelog for QGIS {version}" | |
draft: false | |
HasBanner: false | |
sidebar: true | |
releaseDate: "{release_date}" | |
--- | |
{{{{< content-start >}}}} | |
""" | |
content = front_matter + content | |
# Add id to the first heading | |
content = re.sub(r'^(# .+)', r'\1 {#changelog' + version_formatted + '}', content, flags=re.M) | |
# Insert release date after the first image | |
content = re.sub(r'(!\[.*?\]\(.*?\))', r'\1\n\nRelease date: ' + release_date, content, 1) | |
# Append content-end | |
content += '\n\n{{< content-end >}}' | |
# Write the modified content back to the file | |
with open(index_file_path, 'w') as file: | |
file.write(content) | |
print(f'Modified {index_file_path}') | |
# Insert release date after the first image | |
content = re.sub(r'(!\[.*?\]\(.*?\))', r'\1\n\nRelease date: ' + release_date, count=1) |
Tools
Ruff
64-64: Unnecessary open mode parameters
Remove open mode parameters
(UP015)
87-87:
re.sub
should passcount
andflags
as keyword arguments to avoid confusion due to unintuitive argument positions(B034)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Actionable comments posted: 4
Review details
Configuration used: CodeRabbit UI
Review profile: CHILL
Files selected for processing (1)
- scripts/changelog_harvest.py (1 hunks)
Additional context used
Ruff
scripts/changelog_harvest.py
2-2: UTF-8 encoding declaration is unnecessary
Remove unnecessary coding comment
(UP009)
64-64: Unnecessary open mode parameters
Remove open mode parameters
(UP015)
88-88:
re.sub
should passcount
andflags
as keyword arguments to avoid confusion due to unintuitive argument positions(B034)
100-100: Unnecessary open mode parameters
Remove open mode parameters
(UP015)
Additional comments not posted (3)
scripts/changelog_harvest.py (3)
104-106
: LGTM!The function is correct and well-implemented.
108-113
: LGTM!The function is correct and well-implemented.
114-131
: Replace hardcoded configuration path with a configurable path.The hardcoded configuration path should be replaced with a configurable path.
- config_path = 'data/conf.json' + config_path = args.config if args.config else 'data/conf.json'Likely invalid or redundant comment.
def download_and_extract_zip(version, release_date): | ||
# Format version without special characters | ||
version_formatted = re.sub(r'\D', '', version) | ||
|
||
# URL of the zip file | ||
url = f'https://changelog.qgis.org/en/qgis/version/{version}/md/' | ||
|
||
# Define file paths | ||
zip_filename = f'qgis_changelog_{version_formatted}.zip' | ||
extract_path = f'content/project/visual-changelogs/visualchangelog{version_formatted}' | ||
|
||
# Download the zip file | ||
print(f'Downloading {url}') | ||
response = requests.get(url) | ||
if response.status_code != 200: | ||
print(f"Error: Could not download the file from {url}. HTTP status code: {response.status_code}") | ||
return | ||
|
||
with open(zip_filename, 'wb') as file: | ||
file.write(response.content) | ||
print(f'Downloaded {zip_filename}') | ||
|
||
# Extract the zip file | ||
print(f'Extracting {zip_filename} to {extract_path}') | ||
with ZipFile(zip_filename, 'r') as zip_ref: | ||
zip_ref.extractall(extract_path) | ||
print(f'Extracted to {extract_path}') | ||
|
||
# Remove the zip file after extraction | ||
os.remove(zip_filename) | ||
print(f'Removed {zip_filename}') | ||
|
||
# Modify the index.md file | ||
index_file_path = os.path.join(extract_path, 'index.md') | ||
modify_index_file(index_file_path, version, version_formatted, release_date) | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Improve error handling and logging.
Consider adding more detailed error handling and logging to provide better feedback in case of failures. Additionally, make the URL configurable.
import logging
logging.basicConfig(level=logging.INFO)
def download_and_extract_zip(version, release_date):
try:
version_formatted = re.sub(r'\D', '', version)
config = load_config('data/conf.json')
url = config['changelog_url'].format(version=version)
zip_filename = f'qgis_changelog_{version_formatted}.zip'
extract_path = f'content/project/visual-changelogs/visualchangelog{version_formatted}'
logging.info(f'Downloading {url}')
response = requests.get(url)
response.raise_for_status()
with open(zip_filename, 'wb') as file:
file.write(response.content)
logging.info(f'Downloaded {zip_filename}')
logging.info(f'Extracting {zip_filename} to {extract_path}')
with ZipFile(zip_filename, 'r') as zip_ref:
zip_ref.extractall(extract_path)
logging.info(f'Extracted to {extract_path}')
os.remove(zip_filename)
logging.info(f'Removed {zip_filename}')
index_file_path = os.path.join(extract_path, 'index.md')
modify_index_file(index_file_path, version, version_formatted, release_date)
except requests.RequestException as e:
logging.error(f"Error: Could not download the file from {url}. Exception: {e}")
except Exception as e:
logging.error(f"An unexpected error occurred: {e}")
@@ -0,0 +1,131 @@ | |||
#!/usr/bin/python | |||
# -*- coding: utf-8 -*- |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Remove unnecessary coding comment.
The UTF-8 encoding declaration is unnecessary since UTF-8 is the default encoding in Python 3.
- # -*- coding: utf-8 -*-
Committable suggestion
‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.
# -*- coding: utf-8 -*- |
Tools
Ruff
2-2: UTF-8 encoding declaration is unnecessary
Remove unnecessary coding comment
(UP009)
def load_config(config_path): | ||
with open(config_path, 'r') as file: | ||
config = json.load(file) | ||
return config |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Remove unnecessary open mode parameters.
The open mode parameters are unnecessary.
- with open(config_path, 'r') as file:
+ with open(config_path) as file:
Committable suggestion
‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.
def load_config(config_path): | |
with open(config_path, 'r') as file: | |
config = json.load(file) | |
return config | |
def load_config(config_path): | |
with open(config_path) as file: | |
config = json.load(file) | |
return config |
Tools
Ruff
100-100: Unnecessary open mode parameters
Remove open mode parameters
(UP015)
def modify_index_file(index_file_path, version, version_formatted, release_date): | ||
print(f'Modifying {index_file_path}') | ||
with open(index_file_path, 'r') as file: | ||
content = file.read() | ||
|
||
# Add front matter | ||
front_matter = f"""--- | ||
title: "Changelog for QGIS {version}" | ||
draft: false | ||
HasBanner: false | ||
sidebar: true | ||
releaseDate: "{release_date}" | ||
section: "project" | ||
type: "visual-changelog" | ||
|
||
--- | ||
|
||
{{{{< content-start >}}}} | ||
|
||
""" | ||
content = front_matter + content | ||
|
||
# Add id to the first heading | ||
content = re.sub(r'^(# .+)', r'\1 {#changelog' + version_formatted + '}', content, flags=re.M) | ||
|
||
# Insert release date after the first image | ||
content = re.sub(r'(!\[.*?\]\(.*?\))', r'\1\n\nRelease date: ' + release_date, content, 1) | ||
|
||
# Append content-end | ||
content += '\n\n{{< content-end >}}' | ||
|
||
# Write the modified content back to the file | ||
with open(index_file_path, 'w') as file: | ||
file.write(content) | ||
print(f'Modified {index_file_path}') |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Pass count
and flags
as keyword arguments in re.sub
.
The re.sub
function should pass count
and flags
as keyword arguments to avoid confusion.
- content = re.sub(r'(!\[.*?\]\(.*?\))', r'\1\n\nRelease date: ' + release_date, content, 1)
+ content = re.sub(r'(!\[.*?\]\(.*?\))', r'\1\n\nRelease date: ' + release_date, content, count=1)
Committable suggestion
‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.
def modify_index_file(index_file_path, version, version_formatted, release_date): | |
print(f'Modifying {index_file_path}') | |
with open(index_file_path, 'r') as file: | |
content = file.read() | |
# Add front matter | |
front_matter = f"""--- | |
title: "Changelog for QGIS {version}" | |
draft: false | |
HasBanner: false | |
sidebar: true | |
releaseDate: "{release_date}" | |
section: "project" | |
type: "visual-changelog" | |
--- | |
{{{{< content-start >}}}} | |
""" | |
content = front_matter + content | |
# Add id to the first heading | |
content = re.sub(r'^(# .+)', r'\1 {#changelog' + version_formatted + '}', content, flags=re.M) | |
# Insert release date after the first image | |
content = re.sub(r'(!\[.*?\]\(.*?\))', r'\1\n\nRelease date: ' + release_date, content, 1) | |
# Append content-end | |
content += '\n\n{{< content-end >}}' | |
# Write the modified content back to the file | |
with open(index_file_path, 'w') as file: | |
file.write(content) | |
print(f'Modified {index_file_path}') | |
# Insert release date after the first image | |
content = re.sub(r'(!\[.*?\]\(.*?\))', r'\1\n\nRelease date: ' + release_date, content, count=1) |
Tools
Ruff
64-64: Unnecessary open mode parameters
Remove open mode parameters
(UP015)
88-88:
re.sub
should passcount
andflags
as keyword arguments to avoid confusion due to unintuitive argument positions(B034)
This is the proposed fix for #286.
Please note that current PR depends on kartoza/prj.app#1466
Summary by CodeRabbit