根据自定义搜索检索错误总数

Retrieving total count of bugs based on custom search

我正在尝试检索项目中的问题计数,这些问题是错误且其状态已关闭或已解决且解决方案已修复。除此之外,我正在尝试确保错误的受让人与报告者不同,或者受让人不是未分配的。

这是我目前拥有的:

https://issues.apache.org/jira/rest/api/2/search?jql=issuetype=Bug and resolution=Fixed and status= Resolved or status = Closed and project=AMQ and assignee!=reporter and assignee != ''

但是,返回的总数多于项目存储库中存在的实际错误数。请协助。

无法在您尝试 API 调用时使用 assignee!=reporter 进行过滤。此外,您必须使用 assignee is NOT EMPTY 而不是 assignee != '' 才能在没有受让人的情况下获得问题。最后,您需要在 (status=Resolved or status=Closed) 周围加上括号,以免陷入 OR 陷阱。

如果您将 python 与 python-jira 一起使用,获得所需结果的代码将如下所示:

# connect to your JIRA instance
jira = JIRA('https://issues.apache.org/')

# get the issues via API search
issues = jira.search_issues("issuetype=Bug AND resolution=Fixed AND (status=Resolved or status=Closed) AND project=AMQ AND assignee is NOT EMPTY")

filtered_issues = [] # this variable will hold the correct list of issues

# filter the tickets where assignee != reporter
for issue in issues:

    # to prevent AttributeError due to possible NoneType
    try:
        reporter = issue.fields.reporter.key
    except AttributeError:
        reporter = ""

    # to prevent AttributeError due to possible NoneType
    try:
        assignee = issue.fields.assignee.key
    except AttributeError:
        assignee = ""

    if reporter != assignee:
        filtered_issues.append(issue)

print(filtered_issues) # list of issues
print(len(filtered_issues)) # number of issues