Skip to content

Instantly share code, notes, and snippets.

@fernandascovino
Last active January 9, 2023 17:53
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save fernandascovino/59255f4aaecce80c38323add5d4d07d6 to your computer and use it in GitHub Desktop.
Save fernandascovino/59255f4aaecce80c38323add5d4d07d6 to your computer and use it in GitHub Desktop.
Print issues and drafts by field columns (kanban)
# Get gh access token: https://docs.github.com/en/authentication/keeping-your-account-and-data-secure/creating-a-personal-access-token
# How to use the GraphQL API on gh: https://docs.github.com/en/issues/planning-and-tracking-with-projects/automating-your-project/using-the-api-to-manage-projects#finding-information-about-items-in-a-project
import requests
import json
# Set config
url = 'https://api.github.com/graphql'
# token = ...
headers = {'Authorization': 'token ' + token}
org = "prefeitura-rio"
project_number = 16
# Get project ID
q = f'''
query{{
organization(login: "{org}"){{
projectV2(number: {project_number}) {{
id
}}
}}
}}'''
project_id = (
requests.post(
url,
headers=headers, json={'query': q}
).json()["data"]["organization"]["projectV2"]["id"]
)
# Get tasks
q = f'''
query{{
node(id: "{project_id}") {{
... on ProjectV2 {{
items(first: 100) {{
nodes{{
id
fieldValues(first: 8) {{
nodes{{
... on ProjectV2ItemFieldSingleSelectValue {{
name
field {{
... on ProjectV2FieldCommon {{
name
}}
}}
}}
... on ProjectV2ItemFieldDateValue {{
date
field {{
... on ProjectV2FieldCommon {{
name
}}
}}
}}
}}
}}
content{{
... on DraftIssue {{
title
}}
...on Issue {{
title
assignees(first: 10) {{
nodes{{
login
}}
}}
}}
}}
}}
}}
}}
}}
}}
'''
r = requests.post(url, headers=headers, json={'query': q}).json()
# Print status
status = {
'📋 Backlog': [],
'✅ Entregas da última semana': [],
'⭐️ Prioridades atuais': [],
'🔄 Em revisão': [],
'🎯 Metas': []
}
for item in r["data"]["node"]["items"]["nodes"]:
if item["content"]:
field = [i["name"] for i in item["fieldValues"]["nodes"] if "name" in i.keys()][0]
task = item["content"]["title"]
status[field].append(task)
for k, v in status.items():
print(k)
for x in v:
print("- ", x)
print("\n")
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment