Skip to content

Commit

Permalink
✨ feat: Add partial update support.
Browse files Browse the repository at this point in the history
Signed-off-by: kokodev <[email protected]>
  • Loading branch information
kokofixcomputers committed Nov 30, 2024
1 parent 403c5a3 commit d509b84
Show file tree
Hide file tree
Showing 2 changed files with 46 additions and 3 deletions.
36 changes: 36 additions & 0 deletions commitify.py
Original file line number Diff line number Diff line change
@@ -1,8 +1,18 @@
import os
import sys
import argparse
import requests
from InquirerPy import prompt
from InquirerPy.base.control import Choice

# METADATA:
VERSION = '1.0.6'
PRE_RELEASE = False
# METADATA ENDS

def is_running_through_pyinstaller():
return hasattr(sys, '_MEIPASS')

parser = argparse.ArgumentParser(description="Argument parser", add_help=False)

# Add the -a flag as a boolean action
Expand All @@ -11,12 +21,36 @@
parser.add_argument("-h", action="store_true", help="Help.")
parser.add_argument("--help", action="store_true", help="Help.")

# Create a subparser for commands
commandparser = parser.add_subparsers(dest='command', required=False)
update = commandparser.add_parser('update', help='Update the script to latest version')


def download_script(url, filename):
response = requests.get(url)
with open(filename, 'wb') as f:
f.write(response.content)
print(f"Downloaded {filename}")



# Parse the arguments
args = parser.parse_args()

if args.command == 'update':
if is_running_through_pyinstaller():
print("WARNING: Update only works with the python script. Or else the python script will be downloaded. More versions will be added soon.")
print("Downloading Update Script. This won't take too long.")
download_script("https://raw.githubusercontent.com/kokofixcomputers/Commitify/refs/heads/main/update.py", "update.py")
import update
print("Checking for updates...")
updates, download_url, found = update.check_for_updates(VERSION)
if updates:
print("Updates available!")
print("Updating...")
update.update_script(download_url)
exit(0)

if args.h or args.help:
print("Commitify")
print("Style your commits.")
Expand All @@ -28,6 +62,8 @@
print("-a Automatically add files before commiting with `git add`")
print("-p Automatically push files after commiting with `git push`")
print("-h, --help Help (This Help)")
print("Available commands:")
print("update Automatically update the script with the latest version.")
exit(0)


Expand Down
13 changes: 10 additions & 3 deletions update.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,15 +23,22 @@ def check_for_updates(version):
latest_version = data['tag_name']
release_notes = data['body']
print(f"Latest Release: {latest_version}")
return latest_version == version
found_commitify = False
for asset in data['assets']:
if asset['name'] == 'commitify.py':
download_url = asset['browser_download_url']
print(f"Download link for commitify.py: {download_url}")
found_commitify = True
break
return latest_version == version, download_url, found_commitify
else:
print(f"Failed to fetch updates: {response.status_code} - {response.text}")
return "Failed to fetch updates"

except requests.exceptions.RequestException as e:
print(f"An error occurred: {e}")
def update_script():
download_script("https://raw.githubusercontent.com/kokofixcomputers/Commitify/refs/heads/main/commitify.py", "commitify.py")
def update_script(download_url):
download_script(download_url, "commitify.py")
print("Commitify script updated successfully!")
print("Please restart the script.")

Expand Down

0 comments on commit d509b84

Please sign in to comment.