Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

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

Merged
cacrespo merged 9 commits intopython:3.12fromsofide:fix_create_issue_script
Nov 21, 2024
Merged
Changes from1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
PrevPrevious commit
NextNext commit
refactor to cache issues
  • Loading branch information
@sofide
sofide committedNov 21, 2024
commit6916e3821c4ace2dbba0d48274e79949b83f2b82
126 changes: 67 additions & 59 deletionsscripts/create_issue.py
View file
Open in desktop
Original file line numberDiff line numberDiff line change
Expand Up@@ -13,10 +13,6 @@
from github import Github
from potodo.potodo import PoFileStats


g = Github(os.environ.get('GITHUB_TOKEN'))
repo = g.get_repo('python/python-docs-es')

PYTHON_VERSION = "3.13"
ISSUE_LABELS = [PYTHON_VERSION, "good first issue"]
Copy link
Collaborator

Choose a reason for hiding this comment

The 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

Copy link
CollaboratorAuthor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others.Learn more.

Me gustó la idea, done acá:1915095

ISSUE_TITLE = 'Translate `{pofilename}`'
Expand DownExpand Up@@ -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

def check_issue_not_already_existing(pofilename):
issues = repo.get_issues(state='open')
for issue in issues:
if pofilename in issue.title:
@property
def issues(self):
if self._issues is None:
self._issues = self.repo.get_issues(state='open')

print(f'Skipping {pofilename}. There is a similar issue already created at {issue.html_url}')
raise IssueAlreadyExistingError()
return self._issues

def check_issue_not_already_existing(self, pofilename):
for issue in self.issues:
if pofilename in issue.title:

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()
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(pofilename):
pofile = PoFileStats(Path(pofilename))

check_issue_not_already_existing(pofilename)
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 = repo.create_issue(title=title, body=body, labels=ISSUE_LABELS)
def issue_generator(self, pofilename):
pofile = PoFileStats(Path(pofilename))

return issue
self.check_issue_not_already_existing(pofilename)
self.check_translation_is_pending(pofile)

def create_issues(only_one=False):
po_files = glob("**/*.po")
existing_issue_counter = 0
already_translated_counter = 0
created_issues_counter = 0
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)

print(f"TOTAL PO FILES: {len(po_files)}")
return issue

for pofilename in po_files:
try:
issue = 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
def create_issues(self, only_one=False):
po_files = glob("**/*.po")
existing_issue_counter = 0
already_translated_counter = 0
created_issues_counter = 0

print("Stats:")
print(f"- Existing issues: {existing_issue_counter}")
print(f"- Already translated files: {already_translated_counter}")
print(f"- Created issues: {created_issues_counter}")
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():
Expand All@@ -122,15 +128,17 @@ def main():

arg = sys.argv[1]
Copy link
Collaborator

Choose a reason for hiding this comment

The 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

Copy link
CollaboratorAuthor

Choose a reason for hiding this comment

The 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":
create_issues()
gh.create_issues()

elif arg == "--one":
create_issues(only_one=True)
gh.create_issues(only_one=True)

else:
try:
issue_generator(arg)
gh.issue_generator(arg)
except FileNotFoundError:
raise Exception(error_msg)

Expand Down

[8]ページ先頭

©2009-2025 Movatter.jp