Working simple import script - unless issue title is too long
Then it breaks with: Traceback (most recent call last): File '/home/mlncn/Projects/agaric/forgejo_helpers/import_issues.py', line 57, in <module> import_issues(owner, repo, csv_filename) File '/home/mlncn/Projects/agaric/forgejo_helpers/import_issues.py', line 47, in import_issues new_issue_url = json_response['html_url'] ~~~~~~~~~~~~~^^^^^^^^^^^^ KeyError: 'html_url'
This commit is contained in:
parent
24a99ee2d4
commit
a3b0596584
1 changed files with 16 additions and 16 deletions
|
@ -21,37 +21,37 @@ def import_issues(owner, repo, csv_filename):
|
|||
issues = []
|
||||
with open(csv_filename) as csvfile:
|
||||
rows = csv.reader(csvfile)
|
||||
rows.pop(0)
|
||||
for row in rows:
|
||||
issues.append(row[0])
|
||||
|
||||
|
||||
print(f"Creating issue {json_response['title']} now…")
|
||||
print(f"Creating issues now…")
|
||||
|
||||
issues.pop(0)
|
||||
for issue in issues:
|
||||
new_issue = {
|
||||
"title": issue
|
||||
}
|
||||
|
||||
create_issue_url = API_CREATE_ISSUE.format(instance=FORGEJO_INSTANCE, owner=owner, repo=repo)
|
||||
# print(create_issue_url)
|
||||
headers = {"Authorization": f"token {FORGEJO_API_TOKEN}"}
|
||||
created_response = requests.post(create_issue_url, headers=headers, json=new_issue)
|
||||
create_issue_url = API_CREATE_ISSUE.format(instance=FORGEJO_INSTANCE, owner=owner, repo=repo)
|
||||
# print(create_issue_url)
|
||||
headers = {"Authorization": f"token {FORGEJO_API_TOKEN}"}
|
||||
created_response = requests.post(create_issue_url, headers=headers, json=new_issue)
|
||||
|
||||
json_response = created_response.json()
|
||||
message = json_response.pop('message', False)
|
||||
if message:
|
||||
print(message)
|
||||
sys.exit("Error creating issue.")
|
||||
else:
|
||||
new_issue_url = json_response['html_url']
|
||||
print(f"Issue created: {new_issue_url}")
|
||||
json_response = created_response.json()
|
||||
message = json_response.pop('message', False)
|
||||
if message:
|
||||
print(message)
|
||||
sys.exit("Error creating issue.")
|
||||
else:
|
||||
new_issue_url = json_response['html_url']
|
||||
print(f"Issue created: {new_issue_url}")
|
||||
|
||||
|
||||
if __name__=="__main__":
|
||||
# '0' comes in as move_issue.py when this is called as `python move_issue.py`
|
||||
owner = sys.argv[1]
|
||||
repo = sys.argv[2]
|
||||
csv_filename = sys.argv[2]
|
||||
csv_filename = sys.argv[3]
|
||||
|
||||
import_issues(owner, repo, csvfile)
|
||||
import_issues(owner, repo, csv_filename)
|
||||
|
|
Loading…
Reference in a new issue