Add comments to new & old message linking to where came from and where went

This commit is contained in:
benjamin melançon 2023-10-04 16:19:03 -04:00
parent 510d0d0261
commit 564fb23055

View file

@ -9,6 +9,8 @@ FORGEJO_INSTANCE = os.getenv("FORGEJO_INSTANCE", "https://codeberg.org")
FORGEJO_API_TOKEN = os.getenv("FORGEJO_API_TOKEN")
API_GET_ISSUE = "{instance}/api/v1/repos/{owner}/{repo}/issues/{index}"
API_GET_ISSUE = "{instance}/api/v1/repos/{owner}/{repo}/issues/{index}"
API_PATCH_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"
@ -23,6 +25,9 @@ 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 getting issue.")
else:
old_issue_url = json_response['html_url']
milestone = json_response.pop('milestone', {})
if milestone:
@ -42,7 +47,8 @@ def move_issue(source_owner, source_repo, issue_number, destination_owner, desti
print(message)
sys.exit("Error creating issue.")
else:
print(f"Issue created: {json_response['html_url']}")
new_issue_url = json_response['html_url']
print(f"Issue created: {new_issue_url}")
new_issue_number = json_response['number']
print(f"new_issue_number = {new_issue_number}")
new_issue_id = json_response['id']
@ -63,6 +69,18 @@ def move_issue(source_owner, source_repo, issue_number, destination_owner, desti
print(message)
sys.exit("Error creating comment.")
moved_to_message = {
'body': f"*Issue moved to:* {new_issue_url}"
}
moved_from_message = {
'body': f"*Issue moved here from:* {old_issue_url}"
}
new_comment = requests.post(create_comment_url, headers=headers, data=moved_from_message)
create_old_comment_url = API_CREATE_COMMENT.format(instance=FORGEJO_INSTANCE, owner=source_owner, repo=source_repo, index=issue_number)
new_old_comment = requests.post(create_old_comment_url, headers=headers, data=moved_to_message)
if __name__=="__main__":
# '0' comes in as move_issue.py when this is called as `python move_issue.py`
source_owner = sys.argv[1]