-
Notifications
You must be signed in to change notification settings - Fork 16
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
refactor: use huey task for github mirroring
- Loading branch information
Showing
4 changed files
with
59 additions
and
9 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
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,45 @@ | ||
from huey.contrib.djhuey import db_task | ||
from django.conf import settings | ||
|
||
from .models import Codebase | ||
from .github import GithubApi | ||
from .fs import CodebaseGitRepositoryApi | ||
|
||
import logging | ||
|
||
logger = logging.getLogger(__name__) | ||
|
||
|
||
@db_task(retries=3, retry_delay=30) | ||
def mirror_codebase(codebase_id: int, is_user_repo=False, code=None, debug=False): | ||
"""asynchronous task that mirrors a codebase to a remote Github repository""" | ||
codebase = Codebase.objects.get(id=codebase_id) | ||
mirror = codebase.git_mirror | ||
if not mirror: | ||
raise ValueError("Codebase does not have a git mirror") | ||
if is_user_repo: | ||
if not code: | ||
raise ValueError("User repo requires a code") | ||
else: | ||
mirror.organization_login = settings.GITHUB_MODEL_LIBRARY_ORG_NAME | ||
|
||
git_fs_api = CodebaseGitRepositoryApi(codebase) | ||
local_repo = git_fs_api.get_or_build() | ||
|
||
gh_api = GithubApi( | ||
codebase=codebase, | ||
local_repo=local_repo, | ||
repo_name=mirror.repository_name, | ||
is_user_repo=is_user_repo, | ||
organization_login=mirror.organization_login, | ||
user_access_token=( | ||
GithubApi.get_user_access_token(code) if is_user_repo else None | ||
), | ||
debug=debug, | ||
) | ||
repo = gh_api.get_or_create_repo() | ||
mirror.remote_url = repo.html_url | ||
gh_api.push(local_repo) | ||
gh_api.create_releases(local_repo) | ||
|
||
mirror.update_remote_releases() |
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