Compare commits
2 commits
0af686e64c
...
24a99ee2d4
Author | SHA1 | Date | |
---|---|---|---|
24a99ee2d4 | |||
f1777d2c18 |
2 changed files with 58 additions and 1 deletions
|
@ -19,7 +19,7 @@ Currently this is the only script:
|
||||||
Use it by passing in the source owner, the source repository, the issue number, the destination owner, and the destination repository, like so:
|
Use it by passing in the source owner, the source repository, the issue number, the destination owner, and the destination repository, like so:
|
||||||
|
|
||||||
```bash
|
```bash
|
||||||
python move_issue old-example-org old-example-repo 123 new-example-org new-example-repo
|
python move_issue.py old-example-org old-example-repo 123 new-example-org new-example-repo
|
||||||
```
|
```
|
||||||
|
|
||||||
All five parameters are needed, even if it is within the same organization.
|
All five parameters are needed, even if it is within the same organization.
|
||||||
|
|
57
import_issues.py
Normal file
57
import_issues.py
Normal file
|
@ -0,0 +1,57 @@
|
||||||
|
import csv
|
||||||
|
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_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"
|
||||||
|
|
||||||
|
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…")
|
||||||
|
|
||||||
|
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)
|
||||||
|
|
||||||
|
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]
|
||||||
|
|
||||||
|
import_issues(owner, repo, csvfile)
|
Loading…
Reference in a new issue