问题
I am trying to use the JIRA SOAP API to elegantly determine the ID number that is the highest among all the ID numbers of JIRA issues in a certain project. An upper bound is fine; I do not need the exact answer.
I was thinking of doing this by finding the number of existing issues, but I did not find a nice way to do this. I also thought that perhaps I could create a new issue and use the ID number of the new issue as the number of issues. This is not a very good way of doing this as I then have an extra issue that is meaningless.
Any ideas?
回答1:
I've had this problem in the past and just used the approach that if 5 consecutive issues can't be retrived, then you've reached the newest issues. When an issue is moved to another project or deleted, there will be a hole in the sequence of issue keys.
I suppose a binary chop from 2^16 would cover most cases too.
回答2:
- Perform a search (http://example.com:8080/jira/rest/api/2/search) setting the
"maxResults"
value to whatever you want and startAt = 0 - Do whatever you want with those values while maintaining a count of what was returned for this query and the cumulative count.
- If queryCount == maxResults, search with maxResults and startAt = cumulativeCount.
- If queryCount != maxResults, you're done.
回答3:
I would have done this in a different way, I would have used the Jira Scripting Suite to create a post-function that writes the current issue key somewhere to the disk, and place the function in the transaction going into the Open
status. This way you could easily retrieve the latest issue number fast and efficiently.
Working code:
import os
f = open('/tmp/workfile', 'w+')
f.write(str(issue.getKey()))
f.close()
Please note - going trough the issues is not exacts and not efficient!
If you have many issues you'll have to go trough all of them to find the last one, unlike my solution that will let you know very fast what's the last issue key. as well, let's say that by mistake someone moved issues from one project to another, noticed his error, and move the issue back. if prior to the copy the highest issue key was 200, and 200 issues were copied and than removed, the current highest issue key is 400, even due the last issue is at index 200. how can you tell that there are no more issues? equivalent to the halting problem.
来源:https://stackoverflow.com/questions/11617376/efficient-ways-to-find-the-highest-jira-issue-id-in-a-project