-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathentrypoint.py
More file actions
49 lines (36 loc) · 1.49 KB
/
entrypoint.py
File metadata and controls
49 lines (36 loc) · 1.49 KB
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
#!/usr/bin/env python3
"""GitHub Action entrypoint for profile stats."""
import os
import sys
import logging
logging.basicConfig(level=logging.INFO)
logger = logging.getLogger(__name__)
# Add repo to path
sys.path.insert(0, os.path.dirname(__file__))
from app.stats import fetch_languages, fetch_activity, fetch_user_stats
from app.readme import generate_output, get_readme_content, push_readme, START_TAG, END_TAG, update_readme_content
def main():
username = os.environ.get("GITHUB_REPOSITORY_OWNER")
token = os.environ.get("GITHUB_TOKEN")
if not username or not token:
logger.error("GITHUB_REPOSITORY_OWNER and GITHUB_TOKEN env vars required")
sys.exit(1)
headers = {
"Authorization": f"token {token}",
"Accept": "application/vnd.github.v3+json",
}
logger.info(f"Fetching stats for {username}...")
lang_data = fetch_languages(username, headers)
activities = fetch_activity(username, headers)
stats = fetch_user_stats(username, headers)
stats_output = generate_output(lang_data, activities, stats)
logger.info("Updating README...")
content, sha = get_readme_content(username, headers)
if content is None:
new_content = f"# Hi there\n\n{START_TAG}\n{stats_output}\n{END_TAG}\n"
else:
new_content = update_readme_content(content, stats_output)
push_readme(username, headers, new_content, sha=sha)
logger.info(f"✓ Successfully updated profile stats for {username}")
if __name__ == "__main__":
main()