Created
March 13, 2025 19:18
-
-
Save gwennlbh/c407c961687c62e836c4d7aee2643f18 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import requests | |
from subprocess import run | |
import json | |
def create_github_issue(iid: int, title: str, body: str, open = True): | |
# make sure the issue we will create will have the same number as the one in GitLab | |
github_last_issue = json.loads( run(["gh", "issue", "ls", "--state", "all", "--limit", "1", "--json", "number"], capture_output=True).stdout.decode('utf-8')) | |
previous_iid_from_github = github_last_issue[0]['number'] if len(github_last_issue) > 0 else 0 | |
if previous_iid_from_github != iid-1: | |
print(f"Previous issue in GitHub has number {previous_iid_from_github}, while the next one should be {iid}.") | |
print("Please create the issues manually.") | |
return | |
command = ["gh", "issue", "create", "--title",title, "--body", f"{body}\n\n_[Issue migrated from GitLab](https://git.inpt.fr/cigale/cigale.pages.inpt.fr/-/issues/{iid})_"] | |
print(command) | |
run(command) | |
if not open: | |
command = ["gh", "issue", "close", str(iid)] | |
print(command) | |
run(command) | |
issues = requests.get("https://git.inpt.fr/api/v4/projects/cigale%2Fapp/issues?state=all&per_page=100").json() | |
issues.sort(key=lambda x: x['iid']) | |
for issue in issues[30:]: | |
create_github_issue(issue['iid'], issue['title'], issue['description'], issue['state'] == 'opened') |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment