Skip to content

Commit

Permalink
Keep only a release blog post feature
Browse files Browse the repository at this point in the history
  • Loading branch information
bilelmoussaoui committed Feb 4, 2024
1 parent ac68ef8 commit 5d2b580
Show file tree
Hide file tree
Showing 9 changed files with 412 additions and 1,014 deletions.
5 changes: 1 addition & 4 deletions requirements.txt
Original file line number Diff line number Diff line change
@@ -1,4 +1 @@
DateTime==4.3.0
requests==2.23.0
toml==0.10.2

requests==2.23.0
6 changes: 3 additions & 3 deletions src/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,8 @@
Script to release new gtk-rs crates version.
"""

__version__ = '0.0.1'
__author__ = 'Guillaume Gomez'
__version__ = "0.0.1"
__author__ = "Guillaume Gomez"


__all__ = ['consts', 'github', 'my_toml', 'release', 'utils', 'args', 'globals']
__all__ = ["consts", "github", "release", "utils", "args"]
159 changes: 7 additions & 152 deletions src/args.py
Original file line number Diff line number Diff line change
@@ -1,192 +1,47 @@
import getopt

# local imports
from utils import write_error, write_msg
import consts


class UpdateType:
MAJOR = 0
MEDIUM = 1
MINOR = 2

@staticmethod
def create_from_string(version_s):
version_s = version_s.lower()
if version_s == 'major':
return UpdateType.MAJOR
if version_s == 'medium':
return UpdateType.MEDIUM
if version_s == 'minor':
return UpdateType.MINOR
return None

@staticmethod
def to_str(update):
if update == UpdateType.MAJOR:
return "MAJOR"
if update == UpdateType.MEDIUM:
return "MEDIUM"
if update == UpdateType.MINOR:
return "MINOR"
return "UNKNOWN"


def get_answer(text):
while True:
text = input(f'{text} [Y/n] ').strip().lower()
if len(text) == 0 or text == 'y':
return True
if text == 'n':
return False
write_msg(f'-> Invalid answer "{text}": only "Y" and "n" are expected')


def is_sys_crate(crate):
return crate.endswith('-sys') or crate.endswith('-sys-rs')


def get_up_type(crate, mode, pick_update_type_for_crates, default_updates):
if mode is None and pick_update_type_for_crates is False:
return None
if is_sys_crate(crate) and default_updates['sys'] is not None:
return default_updates['sys']
if not is_sys_crate(crate) and default_updates['non-sys'] is not None:
return default_updates['non-sys']
while pick_update_type_for_crates is True:
text = input(f'Which kind of update do you want for "{crate}"? [MINOR/MEDIUM/MAJOR] ')
text = text.strip().lower()
mode = UpdateType.create_from_string(text)
if mode is not None:
if (is_sys_crate(crate) and
get_answer('Do you want to use this release for all other sys crates?')):
default_updates['sys'] = mode
elif (not is_sys_crate(crate) and
get_answer('Do you want to use this release for all other non-sys crates?')):
default_updates['non-sys'] = mode
break
write_msg(f'Invalid update type received: "{text}". Accepted values: (MINOR|MEDIUM|MAJOR)')
return mode


def ask_updates_confirmation(crates):
write_msg("Recap' of picked updates:")
for crate in crates:
crate_name = crate['crate']['crate']
update = UpdateType.to_str(crate['up-type'])
write_msg(f"[{crate_name}] => {update}")
return get_answer('Do you agree with this?')


def write_help():
write_msg("release.py accepts the following options:")
write_msg("")
write_msg(" * -h | --help : display this message")
write_msg(" * -t <token> | --token=<token> : give the github token")
write_msg(" * -m <mode> | --mode=<mode> : give the update type (MINOR|MEDIUM|MAJOR)")
write_msg(" * --no-push : performs all operations but doesn't push anything")
write_msg(" * -c <crate> | --crate=<crate> : only update the given crate (for test purpose"
" mainly)")
write_msg(" * --badges-only : only update the badges on the website")
write_msg(" * --tags-only : only create new tags")
write_msg(" * --blog-only : only create blog post")
write_msg(" * --pick-crates : add an interactive way to pick crates")
write_msg(" * --pick-update-type-for-crates: pick an update type for each crate")


class Arguments:
def __init__(self):
self.token = None
self.mode = None
self.no_push = False
self.specified_crate = None
self.tags_only = False
self.blog_only = False
self.crates = consts.CRATE_LIST

@staticmethod
def parse_arguments(argv):
# pylint: disable=too-many-branches,too-many-return-statements
try:
opts = getopt.getopt(argv,
"ht:m:c:",
["help", "token=", "mode=", "no-push", "crate",
"badges-only", "tags-only", "pick-update-type-for-crates",
"pick-crates", "blog-only"])[0] # second argument is "args"
opts = getopt.getopt(argv, "ht:m:c:", ["help", "token="])[
0
] # second argument is "args"
except getopt.GetoptError:
write_help()
return None

instance = Arguments()

pick_update_type_for_crates = False

for opt, arg in opts:
if opt in ('-h', '--help'):
if opt in ("-h", "--help"):
write_help()
return None
if opt in ("-t", "--token"):
instance.token = arg
elif opt in ("-m", "--mode"):
instance.mode = UpdateType.create_from_string(arg)
if instance.mode is None:
write_error(f'{opt}: Invalid update type received. Accepted values: '
'(MINOR|MEDIUM|MAJOR)')
return None
elif opt == "--no-push":
instance.no_push = True
elif opt in ('-c', '--crate'):
instance.specified_crate = arg
elif opt == '--tags-only':
instance.tags_only = True
elif opt == '--blog-only':
instance.blog_only = True
elif opt == '--pick-crates':
instance.crates = []
elif opt == '--pick-update-type-for-crates':
pick_update_type_for_crates = True
else:
write_msg(f'"{opt}": unknown option')
write_msg('Use "-h" or "--help" to see help')
return None
if instance.token is None and instance.no_push is False and instance.blog_only is False:
if instance.token is None:
# In this case, I guess it's not an issue to not have a github token...
write_error('Missing token argument.')
return None
# To make pylint happy.
not_only_checks = (instance.tags_only is False or
instance.blog_only is False)
if (instance.mode is None and
not_only_checks is False and
pick_update_type_for_crates is False):
write_error('Missing update type argument.')
write_error("Missing token argument.")
return None

default_updates = {"sys": None, "non-sys": None}
if len(instance.crates) == 0:
for crate in consts.CRATE_LIST:
if get_answer(f'Do you want to include "{crate}" in this release?') is True:
instance.crates.append(
{
'up-type': get_up_type(crate['crate'],
instance.mode,
pick_update_type_for_crates,
default_updates),
'crate': crate,
})
if ask_updates_confirmation(instance.crates) is False:
write_msg('OK! Aborting then!')
return None
else:
instance.crates = [
{
'up-type': get_up_type(crate['crate'],
instance.mode,
pick_update_type_for_crates,
default_updates),
'crate': crate,
} for crate in instance.crates]
if (pick_update_type_for_crates is True and
ask_updates_confirmation(instance.crates) is False):
write_msg('OK! Aborting then!')
return None
return instance
Loading

0 comments on commit 5d2b580

Please sign in to comment.