mirror of
https://github.com/boostorg/website-v2.git
synced 2026-02-26 05:12:11 +00:00
🚧 Progress on PR import
This commit is contained in:
@@ -7,7 +7,9 @@ import structlog
|
||||
from dateutil.parser import ParserError, parse
|
||||
from ghapi.all import GhApi, paged
|
||||
|
||||
from .models import Category, Library
|
||||
|
||||
from .models import Category, Issue, Library, PullRequest
|
||||
from .utils import parse_date
|
||||
|
||||
logger = structlog.get_logger()
|
||||
|
||||
@@ -321,8 +323,109 @@ class GithubUpdater:
|
||||
|
||||
def update_issues(self):
|
||||
self.logger.info("updating_repo_issues")
|
||||
issues = repo_issues(self.owner, self.repo, state="all")
|
||||
|
||||
issues_data = repo_issues(
|
||||
self.owner, self.library.name, state="all", issues_only=True
|
||||
)
|
||||
|
||||
for issue_dict in issues_data:
|
||||
|
||||
# Get the date information
|
||||
closed_at = None
|
||||
created_at = None
|
||||
modified_at = None
|
||||
|
||||
if issue_dict.get("closed_at"):
|
||||
closed_at = parse_date(issue_dict["closed_at"])
|
||||
|
||||
if issue_dict.get("created_at"):
|
||||
created_at = parse_date(issue_dict["created_at"])
|
||||
|
||||
if issue_dict.get("updated_at"):
|
||||
modified_at = parse_date(issue_dict["updated_at"])
|
||||
|
||||
# Create or update the Issue object
|
||||
try:
|
||||
issue, created = Issue.objects.update_or_create(
|
||||
library=self.library,
|
||||
github_id=issue_dict["id"],
|
||||
defaults={
|
||||
"title": issue_dict["title"][:255],
|
||||
"number": issue_dict["number"],
|
||||
"is_open": issue_dict["state"] == "open",
|
||||
"closed": closed_at,
|
||||
"created": created_at,
|
||||
"modified": modified_at,
|
||||
"data": obj2dict(issue_dict),
|
||||
},
|
||||
)
|
||||
except Exception as e:
|
||||
logger.exception(
|
||||
"update_issues_error_skipped_issue",
|
||||
issue_github_id=issue_dict.get("id"),
|
||||
exc_msg=str(e),
|
||||
)
|
||||
continue
|
||||
logger.info(
|
||||
"issue_updated_successfully",
|
||||
issue_id=issue.id,
|
||||
created=created,
|
||||
issue_github_id=issue.github_id,
|
||||
)
|
||||
|
||||
def update_prs(self):
|
||||
"""Update all PRs for a library"""
|
||||
self.logger.info("updating_repo_prs")
|
||||
raise ValueError("testing!")
|
||||
|
||||
prs_data = repo_prs(self.owner, self.library.name)
|
||||
|
||||
for pr_dict in prs_data:
|
||||
# Get the date information
|
||||
closed_at = None
|
||||
merged_at = None
|
||||
created_at = None
|
||||
modified_at = None
|
||||
|
||||
if pr_dict.get("closed_at"):
|
||||
closed_at = parse_date(pr_dict["closed_at"])
|
||||
|
||||
if pr_dict.get("merged_at"):
|
||||
merged_at = parse_date(pr_dict["merged_at"])
|
||||
|
||||
if pr_dict.get("created_at"):
|
||||
created_at = parse_date(pr_dict["created_at"])
|
||||
|
||||
if pr_dict.get("modified_at"):
|
||||
modified_at = parse_date(pr_dict["modified_at"])
|
||||
|
||||
breakpoint()
|
||||
|
||||
try:
|
||||
pull_request, created = PullRequest.objects.update_or_create(
|
||||
library=self.library,
|
||||
github_id=pr_dict["id"],
|
||||
defaults={
|
||||
"title": pr_dict["title"][:255],
|
||||
"number": pr_dict["number"],
|
||||
"is_open": pr_dict["state"] == "open",
|
||||
"closed": closed_at,
|
||||
"merged": merged_at,
|
||||
"created": created_at,
|
||||
"modified": modified_at,
|
||||
"data": obj2dict(pr_dict),
|
||||
},
|
||||
)
|
||||
except Exception as e:
|
||||
logger.exception(
|
||||
"update_prs_error_skipped_pr",
|
||||
pr_github_id=pr_dict.get("id"),
|
||||
exc_msg=str(e),
|
||||
)
|
||||
continue
|
||||
|
||||
logger.info(
|
||||
"pr_updated_successfully",
|
||||
pull_request_id=pull_request.id,
|
||||
created=created,
|
||||
pull_request_github_id=pull_request.github_id,
|
||||
)
|
||||
|
||||
Reference in New Issue
Block a user