pivotalcli/api/projects.py

78 lines
2.0 KiB
Python
Raw Normal View History

2018-04-03 10:56:07 +00:00
from datetime import datetime
from typing import Any, Dict, List, Optional
import requests
from . import _BASE_URL, _headers, _with_token
2018-04-03 10:56:07 +00:00
@_with_token
2018-04-03 10:56:07 +00:00
def get(token: str) -> List[Dict[str, Any]]:
2019-09-04 14:42:23 +00:00
r = requests.get(f"{_BASE_URL}/projects", headers=_headers(token))
2018-04-03 10:56:07 +00:00
return r.json()
@_with_token
def get_project(project_id: int, token: str) -> Dict[str, Any]:
2019-09-04 14:42:23 +00:00
r = requests.get(f"{_BASE_URL}/projects/{project_id}", headers=_headers(token))
2018-04-03 10:56:07 +00:00
return r.json()
@_with_token
def get_stories(project_id: int, token: str) -> List[Dict[str, Any]]:
2019-09-04 14:42:23 +00:00
r = requests.get(
f"{_BASE_URL}/projects/{project_id}/stories", headers=_headers(token)
)
2018-04-03 10:56:07 +00:00
return r.json()
@_with_token
def get_memberships(project_id: int, token: str) -> List[Dict[str, Any]]:
2019-09-04 14:42:23 +00:00
r = requests.get(
f"{_BASE_URL}/projects/{project_id}/memberships", headers=_headers(token)
)
2018-04-03 10:56:07 +00:00
return r.json()
@_with_token
2019-09-04 14:42:23 +00:00
def get_iterations(project_id: int, scope: str, token: str) -> List[Dict[str, Any]]:
r = requests.get(
f"{_BASE_URL}/projects/{project_id}/iterations",
headers=_headers(token),
params={"scope": scope},
)
2018-04-03 10:56:07 +00:00
return r.json()
@_with_token
2019-09-04 14:42:23 +00:00
def get_story_transitions(
str,
project_id: int,
token: str,
after: Optional[datetime] = None,
before: Optional[datetime] = None,
) -> List[Dict[str, Any]]:
2019-02-05 13:29:33 +00:00
parameters = {}
if after:
2019-09-04 14:42:23 +00:00
parameters["occurred_after"] = after.isoformat()
2019-02-05 13:29:33 +00:00
if before:
2019-09-04 14:42:23 +00:00
parameters["occurred_before"] = before.isoformat()
2018-04-03 10:56:07 +00:00
2019-09-04 14:42:23 +00:00
r = requests.get(
f"{_BASE_URL}/projects/{project_id}/story_transitions",
headers=_headers(token),
params=parameters,
)
2018-04-03 10:56:07 +00:00
return r.json()
@_with_token
2019-09-04 14:42:23 +00:00
def get_history_days(project_id: int, start: datetime, token: str) -> Dict[str, Any]:
r = requests.get(
f"{_BASE_URL}/projects/{project_id}/history/days",
headers=_headers(token),
params={"start_date": start.isoformat()},
)
2018-04-03 10:56:07 +00:00
return r.json()