You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@lucene.apache.org by to...@apache.org on 2022/07/06 12:12:08 UTC
[lucene-jira-archive] 01/01: check if the assignee account can be assigned on the repo
This is an automated email from the ASF dual-hosted git repository.
tomoko pushed a commit to branch check-assignee
in repository https://gitbox.apache.org/repos/asf/lucene-jira-archive.git
commit 6eb02d462a14d7d2d06318604fc1a4ad897218cb
Author: Tomoko Uchida <to...@gmail.com>
AuthorDate: Wed Jul 6 21:11:36 2022 +0900
check if the assignee account can be assigned on the repo
---
migration/src/github_issues_util.py | 11 +++++++++++
migration/src/import_github_issues.py | 5 +++++
2 files changed, 16 insertions(+)
diff --git a/migration/src/github_issues_util.py b/migration/src/github_issues_util.py
index 3bea2165..7cb17e6d 100644
--- a/migration/src/github_issues_util.py
+++ b/migration/src/github_issues_util.py
@@ -95,3 +95,14 @@ def get_import_status(token: str, url: str, logger: Logger) -> Optional[tuple[st
logger.error(f"Failed to get import status for {url}; status code={res.status_code}, message={res.text}")
return None
return (res.json().get("status"), res.json().get("issue_url", ""), res.json().get("errors", []))
+
+
+def check_if_can_be_assigned(token: str, repo: str, assignee: str, logger: Logger) -> bool:
+ url = GITHUB_API_BASE + f"/repos/{repo}/assignees/{assignee}"
+ headers = {"Authorization": f"token {token}", "Accept": "application/vnd.github.v3+json"}
+ res = requests.get(url, headers=headers)
+ if res.status_code == 204:
+ return True
+ else:
+ logger.warning(f"Assignee {assignee} cannot be assigned; status code={res.status_code}, message={res.text}")
+ return False
diff --git a/migration/src/import_github_issues.py b/migration/src/import_github_issues.py
index eddb1a1f..2ae41fbe 100644
--- a/migration/src/import_github_issues.py
+++ b/migration/src/import_github_issues.py
@@ -30,6 +30,11 @@ def import_issue_with_comments(num: int, data_dir: Path, token: str, repo: str)
return None
with open(data_file) as fp:
issue_data = json.load(fp)
+ assignee = issue_data["issue"].get("assignee")
+ if assignee:
+ if not check_if_can_be_assigned(token, repo, assignee, logger):
+ # this field should be removed; otherwise an error occurs.
+ del issue_data["issue"]["assignee"]
url = import_issue(token, repo, issue_data, logger)
(status, issue_url, errors) = ("pending", "", [])
while not status or status == "pending":