Created
October 4, 2024 15:12
-
-
Save andynu/a096c3bdd8778c1f941575cd9b9eff74 to your computer and use it in GitHub Desktop.
linear-bulk-add - Just let me paste a bulleted list to create some issues.
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
#!/usr/bin/env python3 | |
import sys | |
import requests | |
import os | |
import json | |
LINEAR_API_KEY = os.environ.get('LINEAR_API_KEY') | |
TEAM_ID = os.environ.get('LINEAR_TEAM_ID') | |
if not LINEAR_API_KEY or not TEAM_ID: | |
print("Please set LINEAR_API_KEY and LINEAR_TEAM_ID environment variables.") | |
sys.exit(1) | |
url = "https://api.linear.app/graphql" | |
headers = { | |
"Authorization": LINEAR_API_KEY, | |
"Content-Type": "application/json" | |
} | |
for line in sys.stdin: | |
title = line.strip() | |
if not title: | |
continue | |
query = """ | |
mutation CreateIssue($title: String!, $teamId: String!) { | |
issueCreate(input: {title: $title, teamId: $teamId}) { | |
success | |
issue { | |
id | |
title | |
} | |
} | |
} | |
""" | |
variables = { | |
"title": title, | |
"teamId": TEAM_ID | |
} | |
response = requests.post(url, json={"query": query, "variables": variables}, headers=headers) | |
if response.status_code == 200: | |
data = response.json() | |
if data.get("data") and data["data"].get("issueCreate") and data["data"]["issueCreate"].get("success"): | |
print(f"Created issue: {title}") | |
else: | |
print(f"Failed to create issue: {title}") | |
print(f"Response: {json.dumps(data, indent=2)}") | |
else: | |
print(f"Error creating issue: {title}") | |
print(f"Status code: {response.status_code}") | |
print(f"Response: {response.text}") |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment