88MASTER_BRANCH = "master"
99MASTER_REF = "refs/heads/master"
1010ORIGINAL_MARKDOWN_PATH = "Original.md"
11- ACCESS_TOKEN = os .environ ['ACCESS_TOKEN' ]
11+ ACCESS_TOKEN = os .environ ['ACCESS_TOKEN' ] if "ACCESS_TOKEN" in os . environ else ""
1212REPO_NAME = "Yosseulsin-JOB/Google-Python-Style-Guide-kor"
13- COMMIT_ID_CLASSNAME = ".text-small.text-mono.link-gray "
14- MARDOWN_URL = "https://github.com/google/styleguide/blob /gh-pages/pyguide.md"
13+ COMMIT_ID_CLASSNAME = ".BtnGroup a "
14+ MARDOWN_URL = "https://github.com/google/styleguide/commits /gh-pages/pyguide.md"
1515RAW_MARKDOWN_URL = "https://raw.githubusercontent.com/google/styleguide/gh-pages/pyguide.md"
1616
17+
1718def create_ref_name (commit ):
1819 return 'refs/heads/original/' + commit ['label' ]
1920
21+
2022def create_branch_name (commit ):
2123 return 'original/' + commit ['label' ]
2224
25+
2326def create_commit_title (commit ):
2427 return 'merge ' + commit ['label' ] + ' 🛰'
2528
29+
2630def create_pr_title (commit ):
2731 return '[' + commit ['label' ]+ '] 변역 요청 💬'
2832
33+
2934def create_pr_body ():
3035 return '''
3136새로운 번역이 왔습니다. 번역해주세요! 💤
3237'''
3338
3439# 항상 루트에서 python ./script/update_original.py 로 실행해야 루트에 있는 Original.md 파일로 대체됩니다.
40+
41+
3542def download_from_google_style_guide_original ():
3643 urllib .request .urlretrieve (RAW_MARKDOWN_URL , ORIGINAL_MARKDOWN_PATH )
37- print ("저장완료" )
3844
3945# commit 이름과 링크를 가져옵니다.
46+
47+
4048def get_commit_from_google_style_guide_original ():
4149 markdown = requests .get (MARDOWN_URL ).text
4250 soup = BeautifulSoup (markdown , 'html.parser' )
43- commit = soup .select (COMMIT_ID_CLASSNAME )[0 ]
51+ commits = soup .select (COMMIT_ID_CLASSNAME )
52+ if len (commits ) == 0 :
53+ raise Exception (
54+ "주소가 달라졌거나 selector 포맷이 변경되었습니다. 업데이트하세요. > ( https://github.com/Yosseulsin-JOB/Google-Python-Style-Guide-kor/blob/master/script/update_original.py )" )
55+ commit = commits [0 ]
4456 commit_label = commit .text
4557 commit_url = 'https://github.com' + commit .attrs ['href' ]
4658
47- print ( commit_label , commit_url )
59+ return { "label" : commit_label . strip (), 'url' : commit_url . strip ()}
4860
49- return { "label" :commit_label ,'url' : commit_url }
5061
5162def get_repo ():
63+ if ACCESS_TOKEN == "" :
64+ raise Exception (
65+ "'ACCESS_TOKEN'값을 지정해 주세요. 이 값이 없으면 PR 생성이 불가합니다. ( https://github.com/Yosseulsin-JOB/Google-Python-Style-Guide-kor/settings/secrets/actions )" )
5266 return Github (ACCESS_TOKEN ).get_repo (REPO_NAME )
5367
68+
5469def create_branch (repo , commit ):
5570 ref = create_ref_name (commit )
5671 branch = repo .get_branch (branch = MASTER_BRANCH )
5772
5873 try :
59- repo .create_git_ref (ref = ref , sha = branch .commit .sha )
74+ repo .create_git_ref (ref = ref , sha = branch .commit .sha )
6075 except :
61- return False
76+ return False
6277 return True
6378
79+
6480def create_commit (repo , commit ):
6581 branch = create_branch_name (commit )
6682 title = create_commit_title (commit )
@@ -69,6 +85,7 @@ def create_commit(repo, commit):
6985
7086 repo .update_file (contents .path , title , text , contents .sha , branch = branch )
7187
88+
7289def create_pull_request (repo , commit ):
7390 body = create_pr_body ()
7491 head = create_branch_name (commit )
@@ -79,27 +96,51 @@ def create_pull_request(repo, commit):
7996
8097if __name__ == "__main__" :
8198
99+ print ("원본 데이터 > 다운로드 시작" )
100+
82101 # 스타일 가이드를 최신 버전을 가져옵니다.
83102 download_from_google_style_guide_original ()
84103
104+ print ("원본 데이터 > 다운로드 완료" )
105+ print ("원본 데이터 > commit 정보 가져오기 시작" )
106+
85107 # 최신 버전의 commit id와 주소를 가져옵니다.
86108 commit = get_commit_from_google_style_guide_original ()
87109
110+ print ("원본 데이터 > commit 정보 가져오기 완료" )
111+ print ("\n ==================================" )
112+ print ("commit id : " + commit ['label' ])
113+ print ("url : " + commit ['url' ])
114+ print ("==================================\n " )
115+ print ("Github > 연동 작업 시작" )
116+
88117 # 스타일 가이드 한글판 레포를 가져옵니다.
89118 repo = get_repo ()
90119
120+ print ("Github > 연동 작업 완료" )
121+ print ("Github > branch 생성 작업 시작" )
122+
91123 # 브랜치를 생성합니다.
92124 branch = create_branch (repo , commit )
93125
94126 # 브랜치를 생성할 수 없는 상태라면 이미 생성된 것으로 더이상의 작업을 진행하지 않습니다.
95127 if branch is False :
96- print ('이미 생성된 작업 요청과 동일한 Commit 입니다. 🚨' )
128+ print ('Github > branch 생성 작업 실패' )
129+ print ("\n ==================================" )
130+ print ("이미 생성된 작업 요청과 동일한 Commit 입니다. 🚨" )
131+ print ("==================================\n " )
97132 sys .exit (0 )
98-
133+
134+ print ("Github > branch 생성 작업 완료" )
135+ print ("Github > add 및 commit 작업 시작" )
136+
99137 # 업데이트 된 파일을 commit합니다.
100138 create_commit (repo , commit )
101139
140+ print ("Github > add 및 commit 작업 완료" )
141+ print ("Github > PR 작업 시작" )
142+
102143 # Pull Request를 생성합니다.
103144 create_pull_request (repo , commit )
104145
105- print ("요청 완료했습니다. " )
146+ print ("Github > PR 작업 완료 " )
0 commit comments