mirror of
https://github.com/boostorg/website-v2.git
synced 2026-02-27 17:42:08 +00:00
- Add `verbose` flag to `import_versions` to allow user to silence the output - Removed some unused options from `import_versions` - Moved the exclusion logic in `import_versions` to its own function - Stop getting the `github_url` from the github API. Instead, generate it from the tag. (reason: in older tags, the best URL GitHub gives us is a less-useful one to a _commit_ and not a tag. We can generate the url, though.) - Move the retrieval of the `release_date` to its own task, so it can be loaded async. (reason: it's a separate API call per version to get the date) - Make `release_date` optional on the `Version` model (reason: make the field easier to load async) - Simplify logic to retrieve `release_date` and just always retrieve it from the commit - Stop loading the version `description` from GitHub. We don't use it on the frontend anyway, and in all but the most recent couple of versions, the `description` is the comment from the commit, which is usually not useful.
34 lines
912 B
Python
34 lines
912 B
Python
import structlog
|
|
|
|
from django.contrib.auth import get_user_model
|
|
|
|
from config.celery import app
|
|
from core.githubhelper import GithubAPIClient
|
|
|
|
logger = structlog.getLogger(__name__)
|
|
|
|
User = get_user_model()
|
|
|
|
|
|
class UserMissingGithubUsername(Exception):
|
|
pass
|
|
|
|
|
|
@app.task
|
|
def update_user_github_photo(user_pk):
|
|
try:
|
|
user = User.objects.get(pk=user_pk)
|
|
except User.DoesNotExist:
|
|
logger.exception("users_tasks_update_gh_photo_no_user_found", user_pk=user_pk)
|
|
raise
|
|
|
|
if not user.github_username:
|
|
logger.info("users_tasks_update_gh_photo_no_github_username", user_pk=user_pk)
|
|
raise UserMissingGithubUsername
|
|
|
|
client = GithubAPIClient()
|
|
response = client.get_user_by_username(user.github_username)
|
|
avatar_url = response["avatar_url"]
|
|
user.save_image_from_github(avatar_url)
|
|
logger.info("users_tasks_update_gh_photo_finished", user_pk=user_pk)
|