Emerges fully-formed and working thanks to lots of help from Louis and Chris
This commit is contained in:
commit
453f7910ae
2 changed files with 53 additions and 0 deletions
2
.env.example
Normal file
2
.env.example
Normal file
|
@ -0,0 +1,2 @@
|
||||||
|
FORGEJO_INSTANCE=https://git.example.com
|
||||||
|
FORGEJO_API_TOKEN=create-at-/user/settings/applications
|
51
move_issue.py
Normal file
51
move_issue.py
Normal file
|
@ -0,0 +1,51 @@
|
||||||
|
import os
|
||||||
|
import sys
|
||||||
|
from dotenv import load_dotenv
|
||||||
|
import requests
|
||||||
|
|
||||||
|
load_dotenv()
|
||||||
|
|
||||||
|
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_CREATE_ISSUE = "{instance}/api/v1/repos/{owner}/{repo}/issues"
|
||||||
|
|
||||||
|
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)
|
||||||
|
# print(get_issue_url)
|
||||||
|
response = requests.get(get_issue_url, params={"access_token": FORGEJO_API_TOKEN})
|
||||||
|
json_response = response.json()
|
||||||
|
|
||||||
|
# Not 100% certain this can ever give a message, but create below does on error
|
||||||
|
message = json_response.pop('message', False)
|
||||||
|
if message:
|
||||||
|
print(message)
|
||||||
|
|
||||||
|
if json_response and 'milestone' in json_response:
|
||||||
|
print(f"We have removed the milestone {json_response['milestone']['title']} from this issue (milestones are specific to repositories).")
|
||||||
|
del json_response['milestone']
|
||||||
|
|
||||||
|
print(f"Creating issue {json_response['title']} now…")
|
||||||
|
|
||||||
|
create_issue_url = API_CREATE_ISSUE.format(instance=FORGEJO_INSTANCE, owner=destination_owner, repo=destination_repo)
|
||||||
|
# print(create_issue_url)
|
||||||
|
headers = {"Authorization": f"token {FORGEJO_API_TOKEN}"}
|
||||||
|
created_response = requests.post(create_issue_url, headers=headers, data=json_response)
|
||||||
|
|
||||||
|
json_response = created_response.json()
|
||||||
|
message = json_response.pop('message', False)
|
||||||
|
if message:
|
||||||
|
print(message)
|
||||||
|
else:
|
||||||
|
print(f"Issue created: {json_response['html_url']}")
|
||||||
|
|
||||||
|
if __name__=="__main__":
|
||||||
|
# '0' comes in as move_issue.py when this is called as `python move_issue.py`
|
||||||
|
source_owner = sys.argv[1]
|
||||||
|
source_repo = sys.argv[2]
|
||||||
|
issue_number = sys.argv[3]
|
||||||
|
destination_owner = sys.argv[4]
|
||||||
|
destination_repo = sys.argv[5]
|
||||||
|
|
||||||
|
move_issue(source_owner, source_repo, issue_number, destination_owner, destination_repo)
|
Loading…
Reference in a new issue