From 8ef854a7f793af5e53ca8910fc96fb1990d93da9 Mon Sep 17 00:00:00 2001 From: thepetk Date: Sun, 31 Mar 2024 15:01:36 +0100 Subject: [PATCH 1/5] Implement create_issues script --- scripts/create_issues.py | 156 +++++++++++++++++++++++++++++++++++++++ 1 file changed, 156 insertions(+) create mode 100644 scripts/create_issues.py diff --git a/scripts/create_issues.py b/scripts/create_issues.py new file mode 100644 index 00000000..d42bf2b5 --- /dev/null +++ b/scripts/create_issues.py @@ -0,0 +1,156 @@ +#!/usr/bin/env python3 +# +# This script aims to create all issues require to translate a +# specific Python version docs. The flow of the script is very simple. +# +# User input: +# +# (optional) GITHUB_ADDITIONAL_MILESTONE: the id of the milestone for additional +# files this version. Default value is 3 +# +# (optional) GITHUB_MVP_MILESTONE: +GITHUB_REPO = os.getenv("GITHUB_REPO", "pygreece/python-docs-gr") +GITHUB_SEVERITY_MAJOR_LABEL = "severity/major" +GITHUB_TOKEN = os.getenv("GITHUB_TOKEN") +PYTHON_VERSION = os.getenv("PYTHON_VERSION", "3.12") +REQUIRED_DIRS = ["tutorial/", "library/stdtypes", "library/functions"] + +# +# Env setup: +# The script creates all the temporary directories and exports +# the GNUPGHOME environment variable in order to avoid creating +# issues to the operating system which is hosting the process. +# It also updates the ownership and mode of these directories +# in order to be able to clean them afterwards +# +# Master-key/Sub-keys generation: +# Following the environment setup the script will try to +# create the pubring.kbx file and with this the master key +# of the user. After the master key generation inside the custom homedir +# we are going to create three (3) sub keys for the newly +# created key. Those keys have specific usage and this is +# sign (signing) | encr (encryption) | auth (authentication) +# +# Card (YubiKey Reset & Re-configure) +# With --card-edit command and the usage of pexpect we are reseting +# and reconfiguring the card with the created master and sub keys. +# Moreover, the script applies a factory-reset command and then +# It imports the keys and the given input to the card +# +# Revocation certificate/ssh key/public key export: +# As a last step it generates the revocation certificate, +# and exportd the ssh_key and public key for the user +import os +from pathlib import Path + +from github import Github +from github.Issue import Issue +import logging + +logging.basicConfig( + format="%(asctime)s - %(levelname)s - %(message)s", + datefmt="%d-%b-%y %H:%M:%S", + level=logging.INFO, +) + +GITHUB_ADDITIONAL_MILESTONE = int(os.getenv("GITHUB_ADDITIONAL_MILESTONE", 3)) +GITHUB_MVP_MILESTONE = int(os.getenv("GITHUB_ADDITIONAL_MILESTONE", 2)) +GITHUB_REPO = os.getenv("GITHUB_REPO", "pygreece/python-docs-gr") +GITHUB_SEVERITY_MAJOR_LABEL = "severity/major" +GITHUB_TOKEN = os.getenv("GITHUB_TOKEN") +PYTHON_VERSION = os.getenv("PYTHON_VERSION", "3.12") +REQUIRED_DIRS = ["tutorial/", "library/stdtypes", "library/functions"] + + +def get_filenames() -> list[str]: + filenames = [] + current_path = Path.cwd() + base_path = os.getcwd() + for path, _, files in os.walk(current_path): + for name in files: + if name.endswith(".po"): + filenames.append(os.path.join(path, name).replace(f"{base_path}/", "")) + + logging.info(f"found {len(filenames)} filenames ending with .po") + return filenames + + +def filter_already_parsed_filenames( + filenames: list[str], gh_issues: list[Issue] +) -> list[str]: + """ + filters filenames having an already created issue. Returns a + list having only filenames without an issue created in github + """ + filtered_filenames = [] + for filename in filenames: + issue_already_exists = False + + for issue in gh_issues: + # check if filename is in title AND that the issue is for the same python version + if filename in issue.title and PYTHON_VERSION in issue.title: + logging.info( + f"Skipping {filename}. There is a similar issue already created at {issue.html_url}" + ) + issue_already_exists = True + break + + if not issue_already_exists: + filtered_filenames.append(filename) + + logging.info(f"found {len(filtered_filenames)} filenames without issue") + return filtered_filenames + + +def main() -> None: + g = Github(GITHUB_TOKEN) + repo = g.get_repo(GITHUB_REPO) + # get all filenames of po files inside the repo + raw_filenames = get_filenames() + + # get all github issues + issues = repo.get_issues(state="all") + + # filter filenames that have already a github issue assigned + filenames = filter_already_parsed_filenames(raw_filenames, issues) + + # get milestones and labels to enrich new issues + gh_mvp_milestone = repo.get_milestone(GITHUB_MVP_MILESTONE) + gh_additional_milestone = repo.get_milestone(GITHUB_ADDITIONAL_MILESTONE) + gh_severity_major_label = repo.get_label(GITHUB_SEVERITY_MAJOR_LABEL) + + for filename in filenames: + title = f"[{PYTHON_VERSION}] Translate `{filename}`" + urlfile = filename.replace(".po", ".html") + + # if the filename is inside the required dirs for translation + # add the mvp milestone otherwise add the additional one + if any(req_dir in title for req_dir in REQUIRED_DIRS): + milestone = gh_mvp_milestone + else: + milestone = gh_additional_milestone + + # create github issue for this file + issue = repo.create_issue( + title=title, + body=f"""/type translation + +## Περιγραφή της εργασίας μετάφρασης + +Το αρχείο αυτό θα πρέπει να μεταφραστεί στο 100%. + +Η μετεφρασμένη έκδοση του αρχείου θα είναι διαθέσιμη στο https://docs.python.org/el/3.12/{urlfile}. +Μέχρι τότε, θα φαίνεται η Αγγλική έκδοσης της σελίδας. + +Παρακαλούμε, σχολιάστε μέσα στο issue εάν θέλετε αυτό το αρχείο να ανατεθεί σε σας. Ένα μέλος της διαχειριστικής ομάδας θα σας το αναθέσει το συντομότερο δυνατό, ώστε να μπορέσεται να το δουλέψετε. + +Θυμηθείτε να ακουληθείσεται τις οδηγίες στον [οδηγό συνεισφοράς](https://github.com/pygreece/python-docs-gr/blob/main/CONTRIBUTING.md) +""", + milestone=milestone, + labels=[gh_severity_major_label], + ) + logging.info(f'Issue "{title}" created at {issue.html_url}') + + +if __name__ == "__main__": + main() From 8b1937ec305c3e8956e892bb84f7d56b0086e8b5 Mon Sep 17 00:00:00 2001 From: thepetk Date: Sun, 31 Mar 2024 15:39:44 +0100 Subject: [PATCH 2/5] Update script --- scripts/create_issues.py | 57 ++++++++++++++++++---------------------- 1 file changed, 26 insertions(+), 31 deletions(-) diff --git a/scripts/create_issues.py b/scripts/create_issues.py index d42bf2b5..ec98fc00 100644 --- a/scripts/create_issues.py +++ b/scripts/create_issues.py @@ -1,45 +1,40 @@ #!/usr/bin/env python3 # # This script aims to create all issues require to translate a -# specific Python version docs. The flow of the script is very simple. +# specific Python version docs. The flow of the script is very simple: +# +# 1. A list with all the repo's filenames ending in ".po" will be created. +# 2. All already existing issues will be fetched from github. +# 3. If a filename has already an issue for this specific python version, +# will be excluded. +# 4. All required labels and milestones will be fetched from github. +# 5. If the filename is inside a required dir will get the mvp milestone. +# Otherwise it will get the additional one. +# 6. An issue will be created in github. # # User input: # +# (required) GITHUB_TOKEN: fine-grained token which is owned by the pygreece +# organization. # (optional) GITHUB_ADDITIONAL_MILESTONE: the id of the milestone for additional -# files this version. Default value is 3 +# files of this version. Default value is 3. +# (optional) GITHUB_MVP_MILESTONE: the id of the milestone for required translated +# files of this version. Default is 2. +# (optional) GITHUB_REPO: the github repo of the greek python translation. Default +# is pygreece/python-docs-gr. +# (optional) PYTHON_VERSION: the python version that all the issues created will +# scope. # -# (optional) GITHUB_MVP_MILESTONE: -GITHUB_REPO = os.getenv("GITHUB_REPO", "pygreece/python-docs-gr") -GITHUB_SEVERITY_MAJOR_LABEL = "severity/major" -GITHUB_TOKEN = os.getenv("GITHUB_TOKEN") -PYTHON_VERSION = os.getenv("PYTHON_VERSION", "3.12") -REQUIRED_DIRS = ["tutorial/", "library/stdtypes", "library/functions"] - +# Installation: # -# Env setup: -# The script creates all the temporary directories and exports -# the GNUPGHOME environment variable in order to avoid creating -# issues to the operating system which is hosting the process. -# It also updates the ownership and mode of these directories -# in order to be able to clean them afterwards +# In order to install all requirements.txt on the root folder run: +# pip install -r requirements.txt # -# Master-key/Sub-keys generation: -# Following the environment setup the script will try to -# create the pubring.kbx file and with this the master key -# of the user. After the master key generation inside the custom homedir -# we are going to create three (3) sub keys for the newly -# created key. Those keys have specific usage and this is -# sign (signing) | encr (encryption) | auth (authentication) +# Run: # -# Card (YubiKey Reset & Re-configure) -# With --card-edit command and the usage of pexpect we are reseting -# and reconfiguring the card with the created master and sub keys. -# Moreover, the script applies a factory-reset command and then -# It imports the keys and the given input to the card -# -# Revocation certificate/ssh key/public key export: -# As a last step it generates the revocation certificate, -# and exportd the ssh_key and public key for the user +# In order to run the script run: +# GITHUB_TOKEN= (all other inputs) python scripts/create_issues.py + import os from pathlib import Path From 128760556f5f59b32e8f5503990ec1c5c2e5a8e0 Mon Sep 17 00:00:00 2001 From: Theofanis Petkos Date: Tue, 2 Apr 2024 15:02:31 +0100 Subject: [PATCH 3/5] Update scripts/create_issues.py Co-authored-by: Lysandros Nikolaou --- scripts/create_issues.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/scripts/create_issues.py b/scripts/create_issues.py index ec98fc00..414fd6f1 100644 --- a/scripts/create_issues.py +++ b/scripts/create_issues.py @@ -49,7 +49,7 @@ ) GITHUB_ADDITIONAL_MILESTONE = int(os.getenv("GITHUB_ADDITIONAL_MILESTONE", 3)) -GITHUB_MVP_MILESTONE = int(os.getenv("GITHUB_ADDITIONAL_MILESTONE", 2)) +GITHUB_MVP_MILESTONE = int(os.getenv("GITHUB_MVP_MILESTONE", 2)) GITHUB_REPO = os.getenv("GITHUB_REPO", "pygreece/python-docs-gr") GITHUB_SEVERITY_MAJOR_LABEL = "severity/major" GITHUB_TOKEN = os.getenv("GITHUB_TOKEN") From e37507527a944ad1d60cfe9193029d6735a043e7 Mon Sep 17 00:00:00 2001 From: Theofanis Petkos Date: Tue, 2 Apr 2024 15:03:25 +0100 Subject: [PATCH 4/5] Update scripts/create_issues.py Co-authored-by: Lysandros Nikolaou --- scripts/create_issues.py | 6 +----- 1 file changed, 1 insertion(+), 5 deletions(-) diff --git a/scripts/create_issues.py b/scripts/create_issues.py index 414fd6f1..a3149b9e 100644 --- a/scripts/create_issues.py +++ b/scripts/create_issues.py @@ -79,18 +79,14 @@ def filter_already_parsed_filenames( """ filtered_filenames = [] for filename in filenames: - issue_already_exists = False - for issue in gh_issues: # check if filename is in title AND that the issue is for the same python version if filename in issue.title and PYTHON_VERSION in issue.title: logging.info( f"Skipping {filename}. There is a similar issue already created at {issue.html_url}" ) - issue_already_exists = True break - - if not issue_already_exists: + else: filtered_filenames.append(filename) logging.info(f"found {len(filtered_filenames)} filenames without issue") From 09f7810834bdf50d07b05d3f4802a4cc685cc927 Mon Sep 17 00:00:00 2001 From: thepetk Date: Tue, 2 Apr 2024 15:14:52 +0100 Subject: [PATCH 5/5] Update script --- scripts/create_issues.py | 44 ++++++++++++++++++---------------------- 1 file changed, 20 insertions(+), 24 deletions(-) diff --git a/scripts/create_issues.py b/scripts/create_issues.py index a3149b9e..ca6bee03 100644 --- a/scripts/create_issues.py +++ b/scripts/create_issues.py @@ -40,15 +40,21 @@ from github import Github from github.Issue import Issue -import logging - -logging.basicConfig( - format="%(asctime)s - %(levelname)s - %(message)s", - datefmt="%d-%b-%y %H:%M:%S", - level=logging.INFO, -) GITHUB_ADDITIONAL_MILESTONE = int(os.getenv("GITHUB_ADDITIONAL_MILESTONE", 3)) +GITHUB_ISSUE_BODY = """/type translation + +## Περιγραφή της εργασίας μετάφρασης + +Το αρχείο αυτό θα πρέπει να μεταφραστεί στο 100%. + +Η μετεφρασμένη έκδοση του αρχείου θα είναι διαθέσιμη στο https://docs.python.org/el/{python_version}/{urlfile}. +Μέχρι τότε, θα φαίνεται η Αγγλική έκδοσης της σελίδας. + +Παρακαλούμε, σχολιάστε μέσα στο issue εάν θέλετε αυτό το αρχείο να ανατεθεί σε σας. Ένα μέλος της διαχειριστικής ομάδας θα σας το αναθέσει το συντομότερο δυνατό, ώστε να μπορέσεται να το δουλέψετε. + +Θυμηθείτε να ακουληθείσεται τις οδηγίες στον [οδηγό συνεισφοράς](https://github.com/pygreece/python-docs-gr/blob/main/CONTRIBUTING.md) +""" GITHUB_MVP_MILESTONE = int(os.getenv("GITHUB_MVP_MILESTONE", 2)) GITHUB_REPO = os.getenv("GITHUB_REPO", "pygreece/python-docs-gr") GITHUB_SEVERITY_MAJOR_LABEL = "severity/major" @@ -66,7 +72,7 @@ def get_filenames() -> list[str]: if name.endswith(".po"): filenames.append(os.path.join(path, name).replace(f"{base_path}/", "")) - logging.info(f"found {len(filenames)} filenames ending with .po") + print(f"found {len(filenames)} filenames ending with .po") return filenames @@ -82,14 +88,14 @@ def filter_already_parsed_filenames( for issue in gh_issues: # check if filename is in title AND that the issue is for the same python version if filename in issue.title and PYTHON_VERSION in issue.title: - logging.info( + print( f"Skipping {filename}. There is a similar issue already created at {issue.html_url}" ) break else: filtered_filenames.append(filename) - logging.info(f"found {len(filtered_filenames)} filenames without issue") + print(f"found {len(filtered_filenames)} filenames without issue") return filtered_filenames @@ -124,23 +130,13 @@ def main() -> None: # create github issue for this file issue = repo.create_issue( title=title, - body=f"""/type translation - -## Περιγραφή της εργασίας μετάφρασης - -Το αρχείο αυτό θα πρέπει να μεταφραστεί στο 100%. - -Η μετεφρασμένη έκδοση του αρχείου θα είναι διαθέσιμη στο https://docs.python.org/el/3.12/{urlfile}. -Μέχρι τότε, θα φαίνεται η Αγγλική έκδοσης της σελίδας. - -Παρακαλούμε, σχολιάστε μέσα στο issue εάν θέλετε αυτό το αρχείο να ανατεθεί σε σας. Ένα μέλος της διαχειριστικής ομάδας θα σας το αναθέσει το συντομότερο δυνατό, ώστε να μπορέσεται να το δουλέψετε. - -Θυμηθείτε να ακουληθείσεται τις οδηγίες στον [οδηγό συνεισφοράς](https://github.com/pygreece/python-docs-gr/blob/main/CONTRIBUTING.md) -""", + body=GITHUB_ISSUE_BODY.format( + python_version=PYTHON_VERSION, urlfile=urlfile + ), milestone=milestone, labels=[gh_severity_major_label], ) - logging.info(f'Issue "{title}" created at {issue.html_url}') + print(f'Issue "{title}" created at {issue.html_url}') if __name__ == "__main__":