forked from opengaming/osgameclones
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathhacktoberfest.py
70 lines (61 loc) · 2.79 KB
/
hacktoberfest.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
63
64
65
66
67
68
69
70
"""
This script finds repos participating in hacktoberfest:
- Hosted on GitHub or gitlab
- Includes the "hacktoberfest" topic
To run, install from pip:
- pygithub
- python-gitlab
Add environment variables:
- GH_TOKEN (see https://docs.github.com/en/authentication/keeping-your-account-and-data-secure/creating-a-personal-access-token#creating-a-token)
- with public_repo permission
- GL_TOKEN (see https://docs.gitlab.com/ee/user/profile/personal_access_tokens.html#create-a-personal-access-token)
- with read_api scope
"""
import os
import re
from github import Github, GithubException
from gitlab import Gitlab
from pathlib import Path
import yaml
GH_REGEX = re.compile(r"https://github.com/([^/]+)/([^/]+)")
GL_REGEX = re.compile(r"https://gitlab.com/([^/]+/[^/]+)")
def main():
gh = Github(os.environ["GH_TOKEN"])
gl = Gitlab("https://gitlab.com", private_token=os.environ["GL_TOKEN"])
hacktober_games = {}
for p in Path('games').iterdir():
if p.is_file() and p.suffix == ".yaml":
games = yaml.safe_load(open(p, encoding="utf-8"))
for game in games:
repo_url = game.get("repo", "")
if not repo_url:
continue
match = re.match(GH_REGEX, repo_url)
if match:
owner, repo = match.groups()
try:
gh_repo = gh.get_repo(f"{owner}/{repo}")
except GithubException as e:
print(f"Error getting repo info for {owner}/{repo}: {e}")
continue
topics = gh_repo.get_topics()
if "hacktoberfest" in topics:
game["platform"] = "github"
game["stars"] = gh_repo.stargazers_count
hacktober_games[game["name"]] = game
else:
match = re.match(GL_REGEX, repo_url)
if match:
project_namespace = match.groups()[0]
project = gl.projects.get(project_namespace)
if "hacktoberfest" in project.topics:
game["platform"] = "gitlab"
game["stars"] = project.star_count
hacktober_games[game["name"]] = game
for name, game in hacktober_games.items():
stars_badge = f"![stars](https://img.shields.io/badge/{game['platform']}%20stars-{game['stars']}-blue)"
langs = ", ".join(f"`{lang}`" for lang in game.get('langs', []))
frameworks = ", ".join(f"`{fw}`" for fw in game.get('frameworks', []))
print(f"- [**{name}** {stars_badge}]({game['repo']}): ({game.get('development', '')} {game.get('status', '')} {langs} {frameworks})")
if __name__ == "__main__":
main()