Jira Python API 按列表中的值查询

问题描述 投票:0回答:1

我使用自定义字段值查询问题,例如

query = { 
   'jql': 'customfield_123 ~ "pattern"'
}
response_tickets = requests.request(
    "GET",
    url,
    headers=headers,
    params=query,
    auth=basic_auth,
    timeout=15
)

它有效。 在输出中我有这个自定义字段:

"customfield_456": [
     {
         "workspaceId": "35bc4381-e5bb-4e45-8ac3-6248aaea6b13",
         "id": "35bc4381-e5bb-4e45-8ac3-6248aaea6b13:4444",
         "objectId": "4444"
     }
 ],

我需要通过列表项的键进行查询,而不是上面的查询,在这种情况下,我需要以某种方式指定列表的第一项的 objectId 值(“4444”)来解决问题 下面的这个和几个变体(包括引用和编码)不起作用。也不报错。

value = "4444"
query = { 
    'jql': f"customfield_456[0].objectId ~ '{value}'"
}

此查询未找到问题。 jql 在查询中指定

customfield_456[0].objectId
的方法是什么? 附:我有输入的实际值
customfield_456[0].objectId
,所以我不介意使用等号而不是波形符,但它也不起作用。

python list api jira jql
1个回答
0
投票

以编程方式检索问题和过滤:

  1. 使用更广泛的 JQL 查询来检索具有 customfield_456 的问题 设置。

  2. 通过迭代以编程方式在脚本中过滤问题 问题并检查第一项的 objectId 自定义字段_456。

import requests

# Query to get all issues where customfield_456 is not empty
query = {
    'jql': '"customfield_456" is not EMPTY'
}

response_tickets = requests.request(
    "GET",
    url,
    headers=headers,
    params=query,
    auth=basic_auth,
    timeout=15
)

# Assuming response_tickets is a JSON response from JIRA
issues = response_tickets.json().get('issues', [])

# Filtering issues where the first item in customfield_456 has objectId 4444
filtered_issues = [issue for issue in issues if issue.get('fields', {}).get('customfield_456', [{}])[0].get('objectId') == "4444"]


# Now filtered_issues contains only the issues you need
© www.soinside.com 2019 - 2024. All rights reserved.