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 0a64fe6
Show file tree
Hide file tree
Showing 9 changed files with 57 additions and 865 deletions.
4 changes: 0 additions & 4 deletions requirements.txt

This file was deleted.

2 changes: 1 addition & 1 deletion src/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,4 +6,4 @@
__author__ = 'Guillaume Gomez'


__all__ = ['consts', 'github', 'my_toml', 'release', 'utils', 'args', 'globals']
__all__ = ['consts', 'github', 'release', 'utils', 'args']
152 changes: 3 additions & 149 deletions src/args.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,190 +3,44 @@
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"
"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'):
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.')
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
77 changes: 32 additions & 45 deletions src/consts.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,57 +3,44 @@
GIT_URL = "[email protected]:"

ORGANIZATION = "gtk-rs"
MASTER_TMP_BRANCH = "master-release-update"

BLOG_REPO = "gtk-rs.github.io"

CORE_PREVIOUS_RELEASE = "0.18"
CORE_CURRENT_RELEASE = "0.19"
GTK4_PREVIOUS_RELEASE = "0.7"
GTK4_CURRENT_RELEASE = "0.8"

CRATE_LIST = [
# Sys crates
{"crate": "glib-sys", "repository": "gtk-rs-core", "path": "glib/sys"},
{"crate": "gobject-sys", "repository": "gtk-rs-core", "path": "glib/gobject-sys"},
{"crate": "graphene-sys", "repository": "gtk-rs-core", "path": "graphene/sys"},
{"crate": "gio-sys", "repository": "gtk-rs-core", "path": "gio/sys"},
{"crate": "pango-sys", "repository": "gtk-rs-core", "path": "pango/sys"},
{"crate": "gdk-pixbuf-sys", "repository": "gtk-rs-core", "path": "gdk-pixbuf/sys"},
{"crate": "glib-macros", "repository": "gtk-rs-core", "path": "glib-macros"},
{"crate": "glib-sys", "repository": "gtk-rs-core", "current": CORE_CURRENT_RELEASE, "previous": CORE_PREVIOUS_RELEASE},
{"crate": "gobject-sys", "repository": "gtk-rs-core", "current": CORE_CURRENT_RELEASE, "previous": CORE_PREVIOUS_RELEASE},
{"crate": "graphene-sys", "repository": "gtk-rs-core", "current": CORE_CURRENT_RELEASE, "previous": CORE_PREVIOUS_RELEASE},
{"crate": "gio-sys", "repository": "gtk-rs-core", "current": CORE_CURRENT_RELEASE, "previous": CORE_PREVIOUS_RELEASE},
{"crate": "pango-sys", "repository": "gtk-rs-core", "current": CORE_CURRENT_RELEASE, "previous": CORE_PREVIOUS_RELEASE},
{"crate": "gdk-pixbuf-sys", "repository": "gtk-rs-core", "current": CORE_CURRENT_RELEASE, "previous": CORE_PREVIOUS_RELEASE},
{"crate": "glib-macros", "repository": "gtk-rs-core", "current": CORE_CURRENT_RELEASE, "previous": CORE_PREVIOUS_RELEASE},
# glib must be published before cairo-sys (because of macros)
{"crate": "glib", "repository": "gtk-rs-core", "path": "glib"},
{"crate": "cairo-sys-rs", "repository": "gtk-rs-core", "path": "cairo/sys"},
{"crate": "pangocairo-sys", "repository": "gtk-rs-core", "path": "pangocairo/sys"},
{"crate": "atk-sys", "repository": "gtk3-rs", "path": "atk/sys"},
{"crate": "gdkx11-sys", "repository": "gtk3-rs", "path": "gdkx11/sys"},
{"crate": "gdk-sys", "repository": "gtk3-rs", "path": "gdk/sys"},
{"crate": "gdkwayland-sys", "repository": "gtk3-rs", "path": "gdkwayland/sys"},
{"crate": "gtk-sys", "repository": "gtk3-rs", "path": "gtk/sys"},
{"crate": "gdk4-sys", "repository": "gtk4-rs", "path": "gdk4/sys"},
{"crate": "gdk4-wayland-sys", "repository": "gtk4-rs", "path": "gdk4-wayland/sys"},
{"crate": "gdk4-x11-sys", "repository": "gtk4-rs", "path": "gdk4-x11/sys"},
{"crate": "gsk4-sys", "repository": "gtk4-rs", "path": "gsk4/sys"},
{"crate": "gtk4-sys", "repository": "gtk4-rs", "path": "gtk4/sys"},
{"crate": "glib", "repository": "gtk-rs-core", "current": CORE_CURRENT_RELEASE, "previous": CORE_PREVIOUS_RELEASE},
{"crate": "cairo-sys-rs", "repository": "gtk-rs-core", "current": CORE_CURRENT_RELEASE, "previous": CORE_PREVIOUS_RELEASE},
{"crate": "pangocairo-sys", "repository": "gtk-rs-core", "current": CORE_CURRENT_RELEASE, "previous": CORE_PREVIOUS_RELEASE},
{"crate": "gdk4-sys", "repository": "gtk4-rs", "current": GTK4_CURRENT_RELEASE, "previous": GTK4_PREVIOUS_RELEASE},
{"crate": "gdk4-wayland-sys", "repository": "gtk4-rs", "current": GTK4_CURRENT_RELEASE, "previous": GTK4_PREVIOUS_RELEASE},
{"crate": "gdk4-x11-sys", "repository": "gtk4-rs", "current": GTK4_CURRENT_RELEASE, "previous": GTK4_PREVIOUS_RELEASE},
{"crate": "gsk4-sys", "repository": "gtk4-rs", "current": GTK4_CURRENT_RELEASE, "previous": GTK4_PREVIOUS_RELEASE},
{"crate": "gtk4-sys", "repository": "gtk4-rs", "current": GTK4_CURRENT_RELEASE, "previous": GTK4_PREVIOUS_RELEASE},

# Non-sys crates
{"crate": "gtk3-macros", "repository": "gtk3-rs", "path": "gtk3-macros"},
{"crate": "gtk4-macros", "repository": "gtk4-rs", "path": "gtk4-macros"},
{"crate": "graphene", "repository": "gtk-rs-core", "path": "graphene"},
{"crate": "atk", "repository": "gtk3-rs", "path": "atk"},
{"crate": "gio", "repository": "gtk-rs-core", "path": "gio"},
{"crate": "pango", "repository": "gtk-rs-core", "path": "pango"},
{"crate": "cairo-rs", "repository": "gtk-rs-core", "path": "cairo"},
{"crate": "gdk-pixbuf", "repository": "gtk-rs-core", "path": "gdk-pixbuf"},
{"crate": "gdk", "repository": "gtk3-rs", "path": "gdk"},
{"crate": "gdkwayland", "repository": "gtk3-rs", "path": "gdkwayland"},
{"crate": "gtk", "repository": "gtk3-rs", "path": "gtk"},
{"crate": "gdkx11", "repository": "gtk3-rs", "path": "gdkx11"},
{"crate": "pangocairo", "repository": "gtk-rs-core", "path": "pangocairo"},
{"crate": "gdk4", "repository": "gtk4-rs", "path": "gdk4"},
{"crate": "gdk4-wayland", "repository": "gtk4-rs", "path": "gdk4-wayland"},
{"crate": "gdk4-x11", "repository": "gtk4-rs", "path": "gdk4-x11"},
{"crate": "gsk4", "repository": "gtk4-rs", "path": "gsk4"},
{"crate": "gtk4", "repository": "gtk4-rs", "path": "gtk4"},
# {"crate": "gtk-test", "repository": "gtk-test", "path": ""},
]

EXAMPLES = [
{"repository": "gtk3-rs", "path": "examples"},
{"repository": "gtk4-rs", "path": "examples"},
{"crate": "gtk4-macros", "repository": "gtk4-rs", "current": GTK4_CURRENT_RELEASE, "previous": GTK4_PREVIOUS_RELEASE},
{"crate": "graphene", "repository": "gtk-rs-core", "current": CORE_CURRENT_RELEASE, "previous": CORE_PREVIOUS_RELEASE},
{"crate": "gio", "repository": "gtk-rs-core", "current": CORE_CURRENT_RELEASE, "previous": CORE_PREVIOUS_RELEASE},
{"crate": "pango", "repository": "gtk-rs-core", "current": CORE_CURRENT_RELEASE, "previous": CORE_PREVIOUS_RELEASE},
{"crate": "cairo-rs", "repository": "gtk-rs-core", "current": CORE_CURRENT_RELEASE, "previous": CORE_PREVIOUS_RELEASE},
{"crate": "gdk-pixbuf", "repository": "gtk-rs-core", "current": CORE_CURRENT_RELEASE, "previous": CORE_PREVIOUS_RELEASE},
{"crate": "pangocairo", "repository": "gtk-rs-core", "current": CORE_CURRENT_RELEASE, "previous": CORE_PREVIOUS_RELEASE},
{"crate": "gdk4", "repository": "gtk4-rs", "current": GTK4_CURRENT_RELEASE, "previous": GTK4_PREVIOUS_RELEASE},
{"crate": "gdk4-wayland", "repository": "gtk4-rs", "current": GTK4_CURRENT_RELEASE, "previous": GTK4_PREVIOUS_RELEASE},
{"crate": "gdk4-x11", "repository": "gtk4-rs", "current": GTK4_CURRENT_RELEASE, "previous": GTK4_PREVIOUS_RELEASE},
{"crate": "gsk4", "repository": "gtk4-rs", "current": GTK4_CURRENT_RELEASE, "previous": GTK4_PREVIOUS_RELEASE},
{"crate": "gtk4", "repository": "gtk4-rs", "current": GTK4_CURRENT_RELEASE, "previous": GTK4_PREVIOUS_RELEASE},
]
5 changes: 4 additions & 1 deletion src/github.py
Original file line number Diff line number Diff line change
Expand Up @@ -177,7 +177,10 @@ def __init__(self, gh_obj, name, owner):
def get_pulls(self, state, max_date, only_merged=False):
prs = get_all_contents(f'https://api.github.com/repos/{self.owner}/{self.name}/pulls',
state, max_date,
token=self.gh_obj.token)
token=self.gh_obj.token,
params= {
'per_page': 100,
})
if prs is None:
return []
return [self.create_pr_obj(pull_request) for pull_request in prs
Expand Down
3 changes: 0 additions & 3 deletions src/globals.py

This file was deleted.

77 changes: 0 additions & 77 deletions src/my_toml.py

This file was deleted.

Loading

0 comments on commit 0a64fe6

Please sign in to comment.