Skip to content

Instantly share code, notes, and snippets.

@lukestanley
Created January 5, 2024 13:32
Show Gist options
  • Save lukestanley/bf33f1f065a65460d67daf614ffae091 to your computer and use it in GitHub Desktop.
Save lukestanley/bf33f1f065a65460d67daf614ffae091 to your computer and use it in GitHub Desktop.
Archive all done Linear issues
# Set API_KEY!
import requests
headers = {
'Authorization': API_KEY,
'Content-Type': 'application/json'
}
query = """
{
issues {
nodes {
id
title
description
state {
name
}
}
}
}
"""
response = requests.post('https://api.linear.app/graphql', json={'query': query}, headers=headers)
issues = response.json().get("data", {}).get("issues", {}).get("nodes", [])
# If they are in the Done state, archive them:
may_archive= []
for issue in issues:
state = issue.get("state", {}).get("name")
if state == "Done":#
print(issue['id'], state, issue['title'], issue['description'])
may_archive.append(issue)
print(len(may_archive), 'issues were in the Done state and may be archived.')
def archive_issue(issueId):
"""Uses a GraphQL query request to archive a specific issue, prints the result and returns the status"""
query = """
mutation ArchiveIssue($issueId: String!) {
issueArchive(id: $issueId) {
success
}
}
"""
variables = {
"issueId": issueId
}
response = requests.post('https://api.linear.app/graphql', json={'query': query, 'variables': variables}, headers=headers)
print(response)
response_json = response.json()
was_archive_success = response_json.get("data", {}).get("issueArchive", {}).get("success", False)
print('Was archive a success?', was_archive_success, 'for issue', issueId, 'response', response_json)
return was_archive_success
# Archives all the identified done issues:
for issue in may_archive:
archive_issue(issue['id'])
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment