mirror of
https://github.com/boostorg/website-v2.git
synced 2026-02-28 05:52:21 +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.
54 lines
1.5 KiB
Python
54 lines
1.5 KiB
Python
import structlog
|
|
|
|
from config.celery import app
|
|
from django.conf import settings
|
|
from core.githubhelper import GithubAPIClient, GithubDataParser
|
|
from versions.models import Version
|
|
|
|
|
|
logger = structlog.getLogger(__name__)
|
|
|
|
|
|
@app.task
|
|
def get_release_date_for_version(version_pk, commit_sha, token=None):
|
|
"""
|
|
Gets and stores the release date for a Boost version using the given commit SHA.
|
|
|
|
:param version_pk: The primary key of the version to get the release date for.
|
|
:param commit_sha: The SHA of the commit to get the release date for.
|
|
"""
|
|
try:
|
|
version = Version.objects.get(pk=version_pk)
|
|
except Version.DoesNotExist:
|
|
logger.error(
|
|
"get_release_date_for_version_no_version_found", version_pk=version_pk
|
|
)
|
|
return
|
|
|
|
if not token:
|
|
token = settings.GITHUB_TOKEN
|
|
|
|
parser = GithubDataParser()
|
|
client = GithubAPIClient(token=token)
|
|
|
|
try:
|
|
commit = client.get_commit_by_sha(commit_sha=commit_sha)
|
|
except Exception as e:
|
|
logger.error(
|
|
"get_release_date_for_version_failed",
|
|
version_pk=version_pk,
|
|
commit_sha=commit_sha,
|
|
e=str(e),
|
|
)
|
|
return
|
|
|
|
commit_data = parser.parse_commit(commit)
|
|
release_date = commit_data.get("release_date")
|
|
|
|
if release_date:
|
|
version.release_date = release_date
|
|
version.save()
|
|
logger.info("get_release_date_for_version_success", version_pk=version_pk)
|
|
else:
|
|
logger.error("get_release_date_for_version_error", version_pk=version_pk)
|