-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathupdate_contributors.py
62 lines (48 loc) · 1.81 KB
/
update_contributors.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
import requests
import os
# 설정: 조직과 리포지토리 이름을 여기에 입력하세요
ORGANIZATION = 'Node-ko' # 예: 'facebook'
REPOSITORY = 'learn' # 예: 'react'
# GitHub API URL
API_URL = f'https://api.github.com/repos/{ORGANIZATION}/{REPOSITORY}/contributors'
# Contributors 섹션을 대체할 플레이스홀더
PLACEHOLDER = '<!-- CONTRIBUTOR PLACEHOLDER -->'
# README 파일 경로
README_PATH = './README.md'
NEW_README_PATH = './profile/README.md'
# GitHub Personal Access Token (필요 시)
GITHUB_TOKEN = os.getenv('GITHUB_TOKEN') # 환경 변수에서 토큰을 읽어옵니다.
def fetch_contributors():
headers = {
'Accept': 'application/vnd.github.v3+json',
}
if GITHUB_TOKEN:
headers['Authorization'] = f'token {GITHUB_TOKEN}'
response = requests.get(API_URL, headers=headers)
response.raise_for_status()
return response.json()
def update_readme(contributors_markdown):
with open(README_PATH, 'r', encoding='utf-8') as file:
readme_content = file.read()
new_readme = readme_content.replace(PLACEHOLDER, contributors_markdown)
with open(NEW_README_PATH, 'w', encoding='utf-8') as file:
file.write(new_readme)
def main():
try:
contributors = fetch_contributors()
except Exception as e:
print(f"Error fetching contributors: {e}")
return
if not contributors:
print("No contributors found.")
return
# 최대 100명, 한 줄에 12명씩 표시
contributors_markdown = '''
<a href="https://github.com/Node-ko/learn/graphs/contributors">
<img src="https://contrib.rocks/image?repo=Node-ko/learn" />
</a>
'''
update_readme(contributors_markdown)
print("README.md has been updated with the latest contributors.")
if __name__ == '__main__':
main()