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

Script to fetch changelog #295

Merged
merged 3 commits into from
Jul 5, 2024
Merged

Conversation

Xpirix
Copy link
Collaborator

@Xpirix Xpirix commented Jul 2, 2024

This is the proposed fix for #286.

Please note that current PR depends on kartoza/prj.app#1466

Summary by CodeRabbit

  • New Features
    • Introduced a script to automate the creation and updating of visual changelogs for QGIS versions.
    • Users can now download and extract changelog data for specific versions and update visual changelogs using configuration files or specified version and release date.

Copy link
Contributor

coderabbitai bot commented Jul 2, 2024

Walkthrough

A new script, changelog_harvest.py, has been added to automate the process of updating visual changelogs from QGIS changelog data. This script downloads changelog data for specific QGIS versions, extracts the data, and updates visual changelogs based on configuration details provided in conf.json. It includes functions for managing the downloaded data, modifying index files, and handling command-line arguments.

Changes

File Change Summary
README.md Added a summary of the new changelog_harvest.py script function and usage.
scripts/changelog_harvest.py Introduced new script for downloading and updating visual changelogs. Included new functions like download_and_extract_zip, modify_index_file, load_config, format_release_date, and parse_arguments.

Poem

In code we trust, updates we must,
With scripts that dance, no task too grand,
Changelogs bloom, like flowers new,
For QGIS, in hues so true. 🌼
Data we glean, from a zip unseen,
Automate, elevate, a changelog dream.


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?

Share
Tips

Chat

There are 3 ways to chat with CodeRabbit:

  • Review comments: Directly reply to a review comment made by CodeRabbit. Example:
    • I pushed a fix in commit <commit_id>.
    • Generate unit testing code for this file.
    • Open a follow-up GitHub issue for this discussion.
  • Files and specific lines of code (under the "Files changed" tab): Tag @coderabbitai in a new review comment at the desired location with your query. Examples:
    • @coderabbitai generate unit testing code for this file.
    • @coderabbitai modularize this function.
  • PR comments: Tag @coderabbitai in a new PR comment to ask questions about the PR branch. For the best results, please provide a very specific query, as very limited context is provided in this mode. Examples:
    • @coderabbitai generate interesting stats about this repository and render them as a table.
    • @coderabbitai show all the console.log statements in this repository.
    • @coderabbitai read src/utils.ts and generate unit testing code.
    • @coderabbitai read the files in the src/scheduler package and generate a class diagram using mermaid and a README in the markdown format.
    • @coderabbitai help me debug CodeRabbit configuration file.

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)

  • @coderabbitai pause to pause the reviews on a PR.
  • @coderabbitai resume to resume the paused reviews.
  • @coderabbitai review to trigger an incremental review. This is useful when automatic reviews are disabled for the repository.
  • @coderabbitai full review to do a full review from scratch and review all the files again.
  • @coderabbitai summary to regenerate the summary of the PR.
  • @coderabbitai resolve resolve all the CodeRabbit review comments.
  • @coderabbitai configuration to show the current CodeRabbit configuration for the repository.
  • @coderabbitai help to get help.

Additionally, you can add @coderabbitai ignore anywhere in the PR description to prevent this PR from being reviewed.

CodeRabbit Configration File (.coderabbit.yaml)

  • You can programmatically configure CodeRabbit by adding a .coderabbit.yaml file to the root of your repository.
  • Please see the configuration documentation for more information.
  • If your editor has YAML language server enabled, you can add the path at the top of this file to enable auto-completion and validation: # yaml-language-server: $schema=https://coderabbit.ai/integrations/schema.v2.json

Documentation and Community

  • Visit our Documentation for detailed information on how to use CodeRabbit.
  • Join our Discord Community to get help, request features, and share feedback.
  • Follow us on X/Twitter for updates and announcements.

Copy link
Contributor

@coderabbitai coderabbitai bot left a 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

Commits

Files that changed from the base of the PR and between f3fea67 and 75536ab.

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 pass count and flags 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:
Copy link
Contributor

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.

Suggested change
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'
Copy link
Contributor

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.

Suggested change
config_path = 'data/conf.json'
config_path = args.config if args.config else 'data/conf.json'

Comment on lines 31 to 32
# url = f'https://changelog.qgis.org/en/qgis/version/{version}/md/'
url = f'http://localhost:61202/en/qgis/version/{version}/md/'
Copy link
Contributor

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)
Copy link
Contributor

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.

Suggested change
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 pass count and flags 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:
```
Copy link
Contributor

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:

```
Copy link
Contributor

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.
Copy link
Contributor

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.

Suggested change
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.
Copy link
Contributor

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.

Suggested change
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:
Copy link
Contributor

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.

Copy link
Contributor

@coderabbitai coderabbitai bot left a 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

Commits

Files that changed from the base of the PR and between 75536ab and fd6c64a.

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 pass count and flags 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.

Comment on lines +113 to +130
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)
Copy link
Contributor

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.

Suggested change
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)

Comment on lines 62 to 95
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}')
Copy link
Contributor

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.

Suggested change
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 pass count and flags as keyword arguments to avoid confusion due to unintuitive argument positions

(B034)

Copy link
Contributor

@coderabbitai coderabbitai bot left a 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

Commits

Files that changed from the base of the PR and between fd6c64a and 7589150.

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 pass count and flags 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.

Comment on lines +26 to +61
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)

Copy link
Contributor

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 -*-
Copy link
Contributor

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.

Suggested change
# -*- coding: utf-8 -*-
Tools
Ruff

2-2: UTF-8 encoding declaration is unnecessary

Remove unnecessary coding comment

(UP009)

Comment on lines +99 to +102
def load_config(config_path):
with open(config_path, 'r') as file:
config = json.load(file)
return config
Copy link
Contributor

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.

Suggested change
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)

Comment on lines +62 to +96
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}')
Copy link
Contributor

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.

Suggested change
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 pass count and flags as keyword arguments to avoid confusion due to unintuitive argument positions

(B034)

@timlinux timlinux merged commit ead6acf into qgis:main Jul 5, 2024
2 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants