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

Commitd59ca7d

Browse files
Implement create_issues script (#18)
* Implement create_issues script* Update script* Update scripts/create_issues.pyCo-authored-by: Lysandros Nikolaou <lisandrosnik@gmail.com>* Update scripts/create_issues.pyCo-authored-by: Lysandros Nikolaou <lisandrosnik@gmail.com>* Update script---------Co-authored-by: Lysandros Nikolaou <lisandrosnik@gmail.com>
1 parent10a680c commitd59ca7d

File tree

1 file changed

+143
-0
lines changed

1 file changed

+143
-0
lines changed

‎scripts/create_issues.py

Lines changed: 143 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,143 @@
1+
#!/usr/bin/env python3
2+
#
3+
# This script aims to create all issues require to translate a
4+
# specific Python version docs. The flow of the script is very simple:
5+
#
6+
# 1. A list with all the repo's filenames ending in ".po" will be created.
7+
# 2. All already existing issues will be fetched from github.
8+
# 3. If a filename has already an issue for this specific python version,
9+
# will be excluded.
10+
# 4. All required labels and milestones will be fetched from github.
11+
# 5. If the filename is inside a required dir will get the mvp milestone.
12+
# Otherwise it will get the additional one.
13+
# 6. An issue will be created in github.
14+
#
15+
# User input:
16+
#
17+
# (required) GITHUB_TOKEN: fine-grained token which is owned by the pygreece
18+
# organization.
19+
# (optional) GITHUB_ADDITIONAL_MILESTONE: the id of the milestone for additional
20+
# files of this version. Default value is 3.
21+
# (optional) GITHUB_MVP_MILESTONE: the id of the milestone for required translated
22+
# files of this version. Default is 2.
23+
# (optional) GITHUB_REPO: the github repo of the greek python translation. Default
24+
# is pygreece/python-docs-gr.
25+
# (optional) PYTHON_VERSION: the python version that all the issues created will
26+
# scope.
27+
#
28+
# Installation:
29+
#
30+
# In order to install all requirements.txt on the root folder run:
31+
# pip install -r requirements.txt
32+
#
33+
# Run:
34+
#
35+
# In order to run the script run:
36+
# GITHUB_TOKEN=<your-token> (all other inputs) python scripts/create_issues.py
37+
38+
importos
39+
frompathlibimportPath
40+
41+
fromgithubimportGithub
42+
fromgithub.IssueimportIssue
43+
44+
GITHUB_ADDITIONAL_MILESTONE=int(os.getenv("GITHUB_ADDITIONAL_MILESTONE",3))
45+
GITHUB_ISSUE_BODY="""/type translation
46+
47+
## Περιγραφή της εργασίας μετάφρασης
48+
49+
Το αρχείο αυτό θα πρέπει να μεταφραστεί στο 100%.
50+
51+
Η μετεφρασμένη έκδοση του αρχείου θα είναι διαθέσιμη στο https://docs.python.org/el/{python_version}/{urlfile}.
52+
Μέχρι τότε, θα φαίνεται η Αγγλική έκδοσης της σελίδας.
53+
54+
Παρακαλούμε, σχολιάστε μέσα στο issue εάν θέλετε αυτό το αρχείο να ανατεθεί σε σας. Ένα μέλος της διαχειριστικής ομάδας θα σας το αναθέσει το συντομότερο δυνατό, ώστε να μπορέσεται να το δουλέψετε.
55+
56+
Θυμηθείτε να ακουληθείσεται τις οδηγίες στον [οδηγό συνεισφοράς](https://github.com/pygreece/python-docs-gr/blob/main/CONTRIBUTING.md)
57+
"""
58+
GITHUB_MVP_MILESTONE=int(os.getenv("GITHUB_MVP_MILESTONE",2))
59+
GITHUB_REPO=os.getenv("GITHUB_REPO","pygreece/python-docs-gr")
60+
GITHUB_SEVERITY_MAJOR_LABEL="severity/major"
61+
GITHUB_TOKEN=os.getenv("GITHUB_TOKEN")
62+
PYTHON_VERSION=os.getenv("PYTHON_VERSION","3.12")
63+
REQUIRED_DIRS= ["tutorial/","library/stdtypes","library/functions"]
64+
65+
66+
defget_filenames()->list[str]:
67+
filenames= []
68+
current_path=Path.cwd()
69+
base_path=os.getcwd()
70+
forpath,_,filesinos.walk(current_path):
71+
fornameinfiles:
72+
ifname.endswith(".po"):
73+
filenames.append(os.path.join(path,name).replace(f"{base_path}/",""))
74+
75+
print(f"found{len(filenames)} filenames ending with .po")
76+
returnfilenames
77+
78+
79+
deffilter_already_parsed_filenames(
80+
filenames:list[str],gh_issues:list[Issue]
81+
)->list[str]:
82+
"""
83+
filters filenames having an already created issue. Returns a
84+
list having only filenames without an issue created in github
85+
"""
86+
filtered_filenames= []
87+
forfilenameinfilenames:
88+
forissueingh_issues:
89+
# check if filename is in title AND that the issue is for the same python version
90+
iffilenameinissue.titleandPYTHON_VERSIONinissue.title:
91+
print(
92+
f"Skipping{filename}. There is a similar issue already created at{issue.html_url}"
93+
)
94+
break
95+
else:
96+
filtered_filenames.append(filename)
97+
98+
print(f"found{len(filtered_filenames)} filenames without issue")
99+
returnfiltered_filenames
100+
101+
102+
defmain()->None:
103+
g=Github(GITHUB_TOKEN)
104+
repo=g.get_repo(GITHUB_REPO)
105+
# get all filenames of po files inside the repo
106+
raw_filenames=get_filenames()
107+
108+
# get all github issues
109+
issues=repo.get_issues(state="all")
110+
111+
# filter filenames that have already a github issue assigned
112+
filenames=filter_already_parsed_filenames(raw_filenames,issues)
113+
114+
# get milestones and labels to enrich new issues
115+
gh_mvp_milestone=repo.get_milestone(GITHUB_MVP_MILESTONE)
116+
gh_additional_milestone=repo.get_milestone(GITHUB_ADDITIONAL_MILESTONE)
117+
gh_severity_major_label=repo.get_label(GITHUB_SEVERITY_MAJOR_LABEL)
118+
119+
forfilenameinfilenames:
120+
title=f"[{PYTHON_VERSION}] Translate `{filename}`"
121+
urlfile=filename.replace(".po",".html")
122+
123+
# if the filename is inside the required dirs for translation
124+
# add the mvp milestone otherwise add the additional one
125+
ifany(req_dirintitleforreq_dirinREQUIRED_DIRS):
126+
milestone=gh_mvp_milestone
127+
else:
128+
milestone=gh_additional_milestone
129+
130+
# create github issue for this file
131+
issue=repo.create_issue(
132+
title=title,
133+
body=GITHUB_ISSUE_BODY.format(
134+
python_version=PYTHON_VERSION,urlfile=urlfile
135+
),
136+
milestone=milestone,
137+
labels=[gh_severity_major_label],
138+
)
139+
print(f'Issue "{title}" created at{issue.html_url}')
140+
141+
142+
if__name__=="__main__":
143+
main()

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp