Add comments from old issue to new issue
This commit is contained in:
parent
d8cc600aa0
commit
be559a0812
1 changed files with 22 additions and 0 deletions
|
@ -10,6 +10,8 @@ FORGEJO_API_TOKEN = os.getenv("FORGEJO_API_TOKEN")
|
|||
|
||||
API_GET_ISSUE = "{instance}/api/v1/repos/{owner}/{repo}/issues/{index}"
|
||||
API_CREATE_ISSUE = "{instance}/api/v1/repos/{owner}/{repo}/issues"
|
||||
API_GET_COMMENTS = "{instance}/api/v1/repos/{owner}/{repo}/issues/{index}/comments"
|
||||
API_CREATE_COMMENT = "{instance}/api/v1/repos/{owner}/{repo}/issues/{index}/comments"
|
||||
|
||||
def move_issue(source_owner, source_repo, issue_number, destination_owner, destination_repo):
|
||||
get_issue_url = API_GET_ISSUE.format(instance=FORGEJO_INSTANCE, owner=source_owner, repo=source_repo, index=issue_number)
|
||||
|
@ -38,8 +40,28 @@ def move_issue(source_owner, source_repo, issue_number, destination_owner, desti
|
|||
message = json_response.pop('message', False)
|
||||
if message:
|
||||
print(message)
|
||||
sys.exit("Error creating issue.")
|
||||
else:
|
||||
print(f"Issue created: {json_response['html_url']}")
|
||||
new_issue_number = json_response['number']
|
||||
print(f"new_issue_number = {new_issue_number}")
|
||||
new_issue_id = json_response['id']
|
||||
print(f"new_issue_id = {new_issue_id}")
|
||||
|
||||
print(f"Moving issue comments.")
|
||||
get_comments_url = API_GET_COMMENTS.format(instance=FORGEJO_INSTANCE, owner=source_owner, repo=source_repo, index=issue_number)
|
||||
create_comment_url = API_CREATE_COMMENT.format(instance=FORGEJO_INSTANCE, owner=destination_owner, repo=destination_repo, index=new_issue_number)
|
||||
|
||||
comments = requests.get(get_comments_url, params={"access_token": FORGEJO_API_TOKEN})
|
||||
json_comments = comments.json()
|
||||
|
||||
for comment in json_comments:
|
||||
new_comment = requests.post(create_comment_url, headers=headers, data=comment)
|
||||
json_new_comment = new_comment.json()
|
||||
message = json_new_comment.pop('message', False)
|
||||
if message:
|
||||
print(message)
|
||||
sys.exit("Error creating comment.")
|
||||
|
||||
if __name__=="__main__":
|
||||
# '0' comes in as move_issue.py when this is called as `python move_issue.py`
|
||||
|
|
Loading…
Reference in a new issue