Skip to content

Commit

Permalink
Enters release link correctly into README.md
Browse files Browse the repository at this point in the history
  • Loading branch information
saertna committed Nov 27, 2023
1 parent dcb086c commit 2e9f352
Showing 1 changed file with 28 additions and 9 deletions.
37 changes: 28 additions & 9 deletions preprelease.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,24 +3,43 @@
import shutil
from urllib.parse import urlparse

def get_current_version_from_link(link):
parsed_url = urlparse(link)
path_parts = parsed_url.path.split('/')
current_version = path_parts[-1]
return current_version

def get_current_version_from_link(content):
link_start = content.find('https://github.com/saertna/obsidian-gamified-pkm/releases/tag/')
if link_start == -1:
return None

link_end = content.find(')', link_start)
if link_end == -1:
link_end = content.find(']', link_start)
if link_end == -1:
link_end = len(content)

link = content[link_start:link_end]
parsed_url = urlparse(link)
path_parts = parsed_url.path.split('/')
current_version = path_parts[-1]
return current_version


def update_readme_version(readme_path, new_version):
with open(readme_path, 'r') as readme_file:
with open(readme_path, 'r', encoding='utf-8') as readme_file:
readme_content = readme_file.read()

old_version_link = 'https://github.com/saertna/obsidian-gamified-pkm/releases/tag/' + get_current_version_from_link(readme_content)
old_version = get_current_version_from_link(readme_content)
if old_version is None:
print("Unable to extract the current version from the README.md file.")
return

old_version_link = f'https://github.com/saertna/obsidian-gamified-pkm/releases/tag/{old_version}'
new_version_link = f'https://github.com/saertna/obsidian-gamified-pkm/releases/tag/{new_version}'

updated_readme_content = readme_content.replace(old_version_link, new_version_link)

with open(readme_path, 'w') as readme_file:
with open(readme_path, 'w', encoding='utf-8') as readme_file:
readme_file.write(updated_readme_content)


def update_json_version(file_path, new_version):
with open(file_path, 'r') as json_file:
data = json.load(json_file)
Expand All @@ -39,7 +58,7 @@ def zip_files(source_folder, output_zip_path):
zip_file.write(file_path, arcname=arcname)

def main(new_version):
plugin_folder = 'obsidian-gamified-pkm'
plugin_folder = '.'
readme_path = os.path.join(plugin_folder, 'README.md')
manifest_path = os.path.join(plugin_folder, 'manifest.json')
package_path = os.path.join(plugin_folder, 'package.json')
Expand Down

0 comments on commit 2e9f352

Please sign in to comment.