- Notifications
You must be signed in to change notification settings - Fork396
Fix create issue script#2876
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to ourterms of service andprivacy statement. We’ll occasionally send you account related emails.
Already on GitHub?Sign in to your account
Uh oh!
There was an error while loading.Please reload this page.
Changes from1 commit
6ca3596
099213c
d3baf33
6916e38
1915095
9461867
9938321
2783511
4a79e4e
File filter
Filter by extension
Conversations
Uh oh!
There was an error while loading.Please reload this page.
Jump to
Uh oh!
There was an error while loading.Please reload this page.
Diff view
Diff view
- Loading branch information
Uh oh!
There was an error while loading.Please reload this page.
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -13,10 +13,6 @@ | ||
from github import Github | ||
from potodo.potodo import PoFileStats | ||
PYTHON_VERSION = "3.13" | ||
ISSUE_LABELS = [PYTHON_VERSION, "good first issue"] | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others.Learn more. El "good first issue" yo lo aplicaría sólo para issues donde jay que traducir menos de N entradas (5, 10?) en vez de aplicarlo de forma indiscriminada a todos There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others.Learn more. Me gustó la idea, done acá:1915095 | ||
ISSUE_TITLE = 'Translate `{pofilename}`' | ||
@@ -45,74 +41,84 @@ class PoFileAlreadyTranslated(Exception): | ||
"""Given PO file is already 100% translated""" | ||
class GitHubIssueGenerator: | ||
def __init__(self): | ||
g = Github(os.environ.get('GITHUB_TOKEN')) | ||
self.repo = g.get_repo('python/python-docs-es') | ||
self._issues = None | ||
@property | ||
def issues(self): | ||
if self._issues is None: | ||
self._issues = self.repo.get_issues(state='open') | ||
return self._issues | ||
def check_issue_not_already_existing(self, pofilename): | ||
for issue in self.issues: | ||
if pofilename in issue.title: | ||
print(f'Skipping {pofilename}. There is a similar issue already created at {issue.html_url}') | ||
raise IssueAlreadyExistingError | ||
@staticmethod | ||
def check_translation_is_pending(pofile): | ||
if pofile.fuzzy == 0 and any([ | ||
pofile.translated == pofile.entries, | ||
pofile.untranslated == 0, | ||
]): | ||
print(f'Skipping {pofile.filename}. The file is 100% translated already.') | ||
raise PoFileAlreadyTranslated | ||
def issue_generator(self, pofilename): | ||
pofile = PoFileStats(Path(pofilename)) | ||
self.check_issue_not_already_existing(pofilename) | ||
self.check_translation_is_pending(pofile) | ||
urlfile = pofilename.replace('.po', '.html') | ||
title = ISSUE_TITLE.format(pofilename=pofilename) | ||
body = ISSUE_BODY.format( | ||
python_version=PYTHON_VERSION, | ||
urlfile=urlfile, | ||
pofilename=pofilename, | ||
pofile_fuzzy=pofile.fuzzy, | ||
pofile_percent_translated=pofile.percent_translated, | ||
pofile_entries=pofile.entries, | ||
pofile_untranslated=pofile.untranslated, | ||
) | ||
# https://pygithub.readthedocs.io/en/latest/github_objects/Repository.html#github.Repository.Repository.create_issue | ||
issue = self.repo.create_issue(title=title, body=body, labels=ISSUE_LABELS) | ||
return issue | ||
def create_issues(self, only_one=False): | ||
po_files = glob("**/*.po") | ||
existing_issue_counter = 0 | ||
already_translated_counter = 0 | ||
created_issues_counter = 0 | ||
print(f"TOTAL PO FILES: {len(po_files)}") | ||
for pofilename in po_files: | ||
try: | ||
issue = self.issue_generator(pofilename) | ||
created_issues_counter += 1 | ||
print(f'Issue "{issue.title}" created at {issue.html_url}') | ||
if only_one: | ||
break | ||
except IssueAlreadyExistingError: | ||
existing_issue_counter += 1 | ||
except PoFileAlreadyTranslated: | ||
already_translated_counter += 1 | ||
print("Stats:") | ||
print(f"- Existing issues: {existing_issue_counter}") | ||
print(f"- Already translated files: {already_translated_counter}") | ||
print(f"- Created issues: {created_issues_counter}") | ||
def main(): | ||
@@ -122,15 +128,17 @@ def main(): | ||
arg = sys.argv[1] | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others.Learn more. Una idea que tenía era agregar un modo "dry run", pero queda para el futuro, necesitaría más cambios de los que hay hasta el momento There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others.Learn more. de acuerdo con la idea, y con que se haga a futuro 😅 | ||
gh = GitHubIssueGenerator() | ||
if arg == "--all": | ||
gh.create_issues() | ||
elif arg == "--one": | ||
gh.create_issues(only_one=True) | ||
else: | ||
try: | ||
gh.issue_generator(arg) | ||
except FileNotFoundError: | ||
raise Exception(error_msg) | ||