Fix incorrect API abstraction calls
This commit is contained in:
parent
d2c855922b
commit
5cd27be798
3 changed files with 39 additions and 32 deletions
|
@ -75,3 +75,8 @@ def get_history_days(project_id: int, start: datetime, token: str) -> Dict[str,
|
|||
)
|
||||
|
||||
return r.json()
|
||||
|
||||
|
||||
@_with_token
|
||||
def get_labels(project_id: int, start: datetime, token: str) -> List[Dict[str, Any]]:
|
||||
pass
|
||||
|
|
|
@ -10,6 +10,17 @@ def get(story_id: int = None, token: str = None) -> Dict[str, Any]:
|
|||
return r.json()
|
||||
|
||||
|
||||
@_with_token
|
||||
def post(project_id: int, token: str, **kwargs: Any) -> Dict[str, Any]:
|
||||
r = requests.post(
|
||||
f"{_BASE_URL}/projects/{project_id}/stories",
|
||||
headers={"X-TrackerToken": token},
|
||||
json=kwargs,
|
||||
)
|
||||
r.raise_for_status()
|
||||
return r.json()
|
||||
|
||||
|
||||
@_with_token
|
||||
def put_story(story_id: int, token: str, **kwargs: Any) -> Dict[str, Any]:
|
||||
r = requests.put(
|
||||
|
@ -33,20 +44,19 @@ def get_comments(project_id: int, story_id: int, token: str) -> List[Dict[str, A
|
|||
|
||||
|
||||
@_with_token
|
||||
def get_blockers(project_id: int, story_id: int, token: str) -> List[Dict[str, Any]]:
|
||||
url = f"{_BASE_URL}/projects/{project_id}/stories/{story_id}/blockers"
|
||||
r = requests.get(url, headers=_headers(token))
|
||||
def post_comment(
|
||||
project_id: int, story_id: int, token: str, **kwargs
|
||||
) -> Dict[str, Any]:
|
||||
url = f"{_BASE_URL}/projects/{project_id}/stories/{story_id}/comments"
|
||||
r = requests.post(url, headers=_headers(token), json=kwargs)
|
||||
r.raise_for_status()
|
||||
return r.json()
|
||||
|
||||
|
||||
@_with_token
|
||||
def post(project_id: int, token: str, **kwargs: Any) -> Dict[str, Any]:
|
||||
r = requests.post(
|
||||
f"{_BASE_URL}/projects/{project_id}/stories",
|
||||
headers={"X-TrackerToken": token},
|
||||
json=kwargs,
|
||||
)
|
||||
def get_blockers(project_id: int, story_id: int, token: str) -> List[Dict[str, Any]]:
|
||||
url = f"{_BASE_URL}/projects/{project_id}/stories/{story_id}/blockers"
|
||||
r = requests.get(url, headers=_headers(token))
|
||||
r.raise_for_status()
|
||||
return r.json()
|
||||
|
||||
|
|
|
@ -202,11 +202,6 @@ def _stories_current(project: str, scope: str, show_accepted: bool) -> None:
|
|||
__print_burndown(iteration, show_accepted)
|
||||
|
||||
|
||||
def _set_story_state(story: str, state: str) -> None:
|
||||
story_id = base32.decode(story)
|
||||
api.stories.put_story(story_id, current_state=state)
|
||||
|
||||
|
||||
def _complete_projects(
|
||||
ctx: click.Context, args: List[str], incomplete: str
|
||||
) -> List[str]:
|
||||
|
@ -221,7 +216,6 @@ def _complete_projects(
|
|||
@click.argument("action", required=False)
|
||||
@click.option("--scope", default="current")
|
||||
@click.option("--show-accepted/--hide-accepted", default=True)
|
||||
@click.option("--set-state", type=click.Choice(STATES))
|
||||
@require_login
|
||||
def stories(
|
||||
project: str,
|
||||
|
@ -229,18 +223,20 @@ def stories(
|
|||
action: Optional[str],
|
||||
scope: str,
|
||||
show_accepted: bool,
|
||||
set_state: str,
|
||||
) -> None:
|
||||
project_id = int(Config["project_aliases"][project])
|
||||
if story is not None:
|
||||
story_id = base32.decode(story)
|
||||
state_actions = "start", "finish", "deliver", "accept", "reject"
|
||||
if set_state is not None:
|
||||
_set_story_state(story, set_state)
|
||||
elif action is not None:
|
||||
if action is not None:
|
||||
if action in state_actions:
|
||||
_set_story_state(story, f"{action}ed")
|
||||
if action == "comment":
|
||||
# todo
|
||||
pass
|
||||
api.stories.put_story(story_id, current_state=action + "ed")
|
||||
elif action == "comment":
|
||||
print("Enter the comment, and press Ctrl+D to confirm.")
|
||||
comment = sys.stdin.read()
|
||||
print()
|
||||
api.stories.post_comment(project_id, story_id, text=comment)
|
||||
|
||||
|
||||
stories_info(story)
|
||||
else:
|
||||
|
@ -288,19 +284,15 @@ def __calculate_stories(all_owners, hours, point_scale, allow_split=False):
|
|||
@click.argument("project", type=click.STRING)
|
||||
@require_login
|
||||
def meeting(project: str):
|
||||
try:
|
||||
project_id = int(Config["project_aliases"][project])
|
||||
except KeyError:
|
||||
project_id = base32.decode(project)
|
||||
token = Config["user"]["api_token"]
|
||||
project_id = int(Config["project_aliases"][project])
|
||||
|
||||
members = api.projects.get_memberships(token, project_id)
|
||||
members = api.projects.get_memberships(project_id)
|
||||
members = {m["person"]["name"]: m["person"]["id"] for m in members}
|
||||
|
||||
labels = api.projects.get_labels(token, project_id)
|
||||
labels = api.projects.get_labels(project_id)
|
||||
labels = {l["name"]: l["id"] for l in labels}
|
||||
|
||||
project_info = api.projects.get_project(token, project_id)
|
||||
project_info = api.projects.get_project(project_id)
|
||||
point_scale = [
|
||||
1 if p == "0" else int(float(p) * 2)
|
||||
for p in project_info["point_scale"].split(",")
|
||||
|
@ -312,7 +304,7 @@ def meeting(project: str):
|
|||
inquirer.Text(
|
||||
"hours",
|
||||
message="Meeting length (hours, multiple of 0.5)",
|
||||
validate=lambda _, x: re.match("^[0-9]+(\.[05])?$", x),
|
||||
validate=lambda _, x: re.match(r"^[0-9]+(\.[05])?$", x),
|
||||
),
|
||||
inquirer.Checkbox(
|
||||
"owners",
|
||||
|
|
Loading…
Reference in a new issue