pycontribs / jira

Python Jira library. Development chat available on https://matrix.to/#/#pycontribs:matrix.org
https://jira.readthedocs.io
BSD 2-Clause "Simplified" License
1.96k stars 870 forks source link

Implement rest/api/{ver}/project/{project-key}/statuses #1577

Open lhh opened 1 year ago

lhh commented 1 year ago

Problem trying to solve

On JIRA instances where hundreds of projects have defined their own workflow, they also end up defining their own status.

Whereas rest/{ver}/status returns all possible status values for all projects on a given JIRA instance, the above API tells you the statuses available to the given project key.

Possible solution(s)

I naïvely implemented this as a 'statuses()' object method for the Project class, something like:

def statuses():
    if not self._statuses_raw:
        # lazy load statuses for this project
        spath = os.path.join(self._resource, "statuses")
        url = self._get_url(spath.format(str(self)))
        r_json = json_loads(self._session.get(url))
        self._statuses_raw = r_json
    [do stuff with self._statuses_raw]

... however, there's probably a considerably prettier way. The [do stuff] - I've mostly used the raw json but also returned a list of Issue Types (which then has their individual status types hanging off in the JSON data).

Alternatives

It's possible there is already a call for this and I have missed it.

Additional Context

Implementing tools that don't rely on knowledge of each project's specific workflows requires something like this. I'm happy to submit a PR for what I have, if desired.