Last active
June 29, 2024 09:36
-
-
Save cpyle0819/27758200253ac2480c13cfde1b887e53 to your computer and use it in GitHub Desktop.
Clone a GitHub Issue
This file contains 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 subprocess | |
import argparse | |
import json | |
# Must be executed from within a git repo. | |
def main(): | |
parser = argparse.ArgumentParser(description='Clone a GitHub issue.') | |
parser.add_argument('issue_number', type=int, help='The issue number to clone.') | |
args = parser.parse_args() | |
fields = ["title", "labels", "assignees", "body"] | |
# Run gh issue view and capture output | |
issue = subprocess.run( | |
["gh", "issue", "view", str(args.issue_number), "--json", ','.join(fields)], | |
capture_output=True, text=True | |
).stdout | |
issue_parsed = json.loads(issue); | |
print(issue_parsed); | |
# Create new issue | |
new_issue = ["gh", "issue", "create"] | |
for key, value in issue_parsed.items(): | |
if key == "assignees": | |
new_issue.append('--assignee') | |
new_issue.append(','.join([assignee['login'] for assignee in value])) | |
elif key == "labels": | |
new_issue.append('--label') | |
new_issue.append(','.join(value)) | |
elif key == "body": | |
new_issue.append('--body') | |
new_issue.append(value or ' ') | |
else: | |
new_issue.append(f'--{key}') | |
new_issue.append(value) | |
result = subprocess.run(new_issue, capture_output=True, text=True) | |
print(result.stdout); | |
print(result.stderr); | |
if __name__ == "__main__": | |
main() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
value
in the else like every other statement.