Skip to content

Instantly share code, notes, and snippets.

@raulcd
Last active May 9, 2022 10:35
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 raulcd/a033f5761f290ee4ab6fb349640e0d5b to your computer and use it in GitHub Desktop.
Save raulcd/a033f5761f290ee4ab6fb349640e0d5b to your computer and use it in GitHub Desktop.
Jira API to query for tickets with Nightly label
import requests
url = "https://issues.apache.org/jira/rest/api/2/search"
headers = {
"Accept": "application/json"
}
query = {
'jql': 'project = ARROW AND labels = Nightly and status in (Open, "In Progress")'
}
response = requests.request(
"GET",
url,
headers=headers,
params=query,
)
print({issue["id"]: issue["fields"]["summary"] for issue in response.json()["issues"]})
####
# OUTPUT:
# $ python jira_query.py
# {'13441785': '[Release][Archery][CI] Change the links on the email to point to the job run instead of the branch'}
###
<!DOCTYPE html>
<html lang="en">
<head>
<link rel="stylesheet" href="https://pyscript.net/alpha/pyscript.css" />
<link href="https://cdn.jsdelivr.net/npm/bootstrap@5.1.3/dist/css/bootstrap.min.css" rel="stylesheet" integrity="sha384-1BmE4kWBq78iYhFldvKuhfTAU6auU8tT94WrHftjDbrCEXSU1oBoqyl2QvZ6jIW3" crossorigin="anonymous">
<script defer src="https://pyscript.net/alpha/pyscript.js"></script>
<script src="https://cdn.jsdelivr.net/npm/bootstrap@5.1.3/dist/js/bootstrap.bundle.min.js" integrity="sha384-ka7Sk0Gln4gmtz2MlQnikT1wXgYsOg+OMhuP+IlRH9sENBO0LRn5q+8nbTov4+1p" crossorigin="anonymous"></script>
</head>
<py-env>
</py-env>
<body>
<div class="container">
<div id="jira-info">
<table id="jira-table">
<tr>
<th>
JIRA ID
</th>
<th>
Description
</th>
</tr>
</table>
</div>
</div>
<py-script>
import asyncio
from urllib import parse
from js import console, fetch, document
async def post_data():
url = "https://cors-anywhere.herokuapp.com/issues.apache.org/jira/rest/api/2/search?jql={query}"
headers = {
"Accept": "application/json",
"Access-Control-Allow-Origin": "*"
}
query = {
'jql': 'project = ARROW AND labels = pull-request-available and status in (Open, "In Progress")'
}
response = await fetch(
url.format(query=parse.quote(query.get("jql"))),
{'method':'GET', 'headers': headers}
)
json = await response.json()
return json
result = await post_data()
console.log('issues', result.issues)
tbody = document.createElement('tbody')
document.getElementById('jira-table').appendChild(tbody);
for issue in result.issues:
row = document.createElement('tr')
table_data_1 = document.createElement('td')
table_data_1.innerHTML = issue.id
table_data_2 = document.createElement('td')
table_data_2.innerHTML = issue.fields.summary
row.appendChild(table_data_1)
row.appendChild(table_data_2)
tbody.appendChild(row)
</py-script>
</body>
</html>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment