-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add new kde gitlab instance support, refacto
- Loading branch information
Showing
4 changed files
with
83 additions
and
49 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,2 +1,3 @@ | ||
GITHUB_TOKEN=GITHUB_TOKEN_HERE | ||
GITLAB_TOKEN=GITLAB_TOKEN_HERE # for gitlab.com instance | ||
GLTLAB_KDE_TOKEN=GITLAB_KDE_TOKEN_HERE # for invent.kde.org instance |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -3,3 +3,4 @@ | |
*.csv | ||
todo.txt | ||
.direnv/ | ||
__pycache__/ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,53 @@ | ||
import calendar | ||
import logging | ||
import requests | ||
import time | ||
from github import Github | ||
from gitlab import Gitlab | ||
from gitlab.exceptions import GitlabGetError | ||
from github.GithubException import UnknownObjectException | ||
from github.GithubException import RateLimitExceededException | ||
|
||
logger = logging.getLogger(__name__) | ||
|
||
|
||
def get_github_repository_data(g: Github, repository_name: str): | ||
try: | ||
repo = g.get_repo(repository_name) | ||
except UnknownObjectException: | ||
logger.warning(f"Repository {repository_name} was not found on Github.") | ||
return {} | ||
except RateLimitExceededException: | ||
core_rate_limit = g.get_rate_limit().core | ||
reset_timestamp = calendar.timegm(core_rate_limit.reset.timetuple()) | ||
sleep_time = reset_timestamp - calendar.timegm(time.gmtime()) + 10 | ||
logger.warning(f"Rate-limit detected, sleeping for {sleep_time} seconds.") | ||
time.sleep(sleep_time) | ||
repo = g.get_repo(repository_name) | ||
return { | ||
"repository_stars_count": repo.stargazers_count, | ||
"repository_forks_count": repo.forks_count, | ||
} | ||
|
||
|
||
def get_gitlab_repository_data(gl: Gitlab, repository_name: str): | ||
try: | ||
repo = gl.projects.get(repository_name) | ||
except GitlabGetError: | ||
logger.warning(f"Repository {repository_name} was not found on Gitlab.") | ||
return {} | ||
return { | ||
"repository_stars_count": repo.star_count, | ||
"repository_forks_count": repo.forks_count, | ||
} | ||
|
||
|
||
def get_codeberg_repository_data(repository_name: str): | ||
result = requests.get(f"https://codeberg.org/api/v1/repos/{repository_name}") | ||
if result.status_code == 200: | ||
json_result = result.json() | ||
return { | ||
"repository_stars_count": json_result.get("stars_count"), | ||
"repository_forks_count": json_result.get("forks_count"), | ||
} | ||
return {} |