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()
|
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()
|
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
|
@_with_token
|
||||||
def put_story(story_id: int, token: str, **kwargs: Any) -> Dict[str, Any]:
|
def put_story(story_id: int, token: str, **kwargs: Any) -> Dict[str, Any]:
|
||||||
r = requests.put(
|
r = requests.put(
|
||||||
|
@ -33,20 +44,19 @@ def get_comments(project_id: int, story_id: int, token: str) -> List[Dict[str, A
|
||||||
|
|
||||||
|
|
||||||
@_with_token
|
@_with_token
|
||||||
def get_blockers(project_id: int, story_id: int, token: str) -> List[Dict[str, Any]]:
|
def post_comment(
|
||||||
url = f"{_BASE_URL}/projects/{project_id}/stories/{story_id}/blockers"
|
project_id: int, story_id: int, token: str, **kwargs
|
||||||
r = requests.get(url, headers=_headers(token))
|
) -> 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()
|
r.raise_for_status()
|
||||||
return r.json()
|
return r.json()
|
||||||
|
|
||||||
|
|
||||||
@_with_token
|
@_with_token
|
||||||
def post(project_id: int, token: str, **kwargs: Any) -> Dict[str, Any]:
|
def get_blockers(project_id: int, story_id: int, token: str) -> List[Dict[str, Any]]:
|
||||||
r = requests.post(
|
url = f"{_BASE_URL}/projects/{project_id}/stories/{story_id}/blockers"
|
||||||
f"{_BASE_URL}/projects/{project_id}/stories",
|
r = requests.get(url, headers=_headers(token))
|
||||||
headers={"X-TrackerToken": token},
|
|
||||||
json=kwargs,
|
|
||||||
)
|
|
||||||
r.raise_for_status()
|
r.raise_for_status()
|
||||||
return r.json()
|
return r.json()
|
||||||
|
|
||||||
|
|
|
@ -202,11 +202,6 @@ def _stories_current(project: str, scope: str, show_accepted: bool) -> None:
|
||||||
__print_burndown(iteration, show_accepted)
|
__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(
|
def _complete_projects(
|
||||||
ctx: click.Context, args: List[str], incomplete: str
|
ctx: click.Context, args: List[str], incomplete: str
|
||||||
) -> List[str]:
|
) -> List[str]:
|
||||||
|
@ -221,7 +216,6 @@ def _complete_projects(
|
||||||
@click.argument("action", required=False)
|
@click.argument("action", required=False)
|
||||||
@click.option("--scope", default="current")
|
@click.option("--scope", default="current")
|
||||||
@click.option("--show-accepted/--hide-accepted", default=True)
|
@click.option("--show-accepted/--hide-accepted", default=True)
|
||||||
@click.option("--set-state", type=click.Choice(STATES))
|
|
||||||
@require_login
|
@require_login
|
||||||
def stories(
|
def stories(
|
||||||
project: str,
|
project: str,
|
||||||
|
@ -229,18 +223,20 @@ def stories(
|
||||||
action: Optional[str],
|
action: Optional[str],
|
||||||
scope: str,
|
scope: str,
|
||||||
show_accepted: bool,
|
show_accepted: bool,
|
||||||
set_state: str,
|
|
||||||
) -> None:
|
) -> None:
|
||||||
|
project_id = int(Config["project_aliases"][project])
|
||||||
if story is not None:
|
if story is not None:
|
||||||
|
story_id = base32.decode(story)
|
||||||
state_actions = "start", "finish", "deliver", "accept", "reject"
|
state_actions = "start", "finish", "deliver", "accept", "reject"
|
||||||
if set_state is not None:
|
if action is not None:
|
||||||
_set_story_state(story, set_state)
|
|
||||||
elif action is not None:
|
|
||||||
if action in state_actions:
|
if action in state_actions:
|
||||||
_set_story_state(story, f"{action}ed")
|
api.stories.put_story(story_id, current_state=action + "ed")
|
||||||
if action == "comment":
|
elif action == "comment":
|
||||||
# todo
|
print("Enter the comment, and press Ctrl+D to confirm.")
|
||||||
pass
|
comment = sys.stdin.read()
|
||||||
|
print()
|
||||||
|
api.stories.post_comment(project_id, story_id, text=comment)
|
||||||
|
|
||||||
|
|
||||||
stories_info(story)
|
stories_info(story)
|
||||||
else:
|
else:
|
||||||
|
@ -288,19 +284,15 @@ def __calculate_stories(all_owners, hours, point_scale, allow_split=False):
|
||||||
@click.argument("project", type=click.STRING)
|
@click.argument("project", type=click.STRING)
|
||||||
@require_login
|
@require_login
|
||||||
def meeting(project: str):
|
def meeting(project: str):
|
||||||
try:
|
project_id = int(Config["project_aliases"][project])
|
||||||
project_id = int(Config["project_aliases"][project])
|
|
||||||
except KeyError:
|
|
||||||
project_id = base32.decode(project)
|
|
||||||
token = Config["user"]["api_token"]
|
|
||||||
|
|
||||||
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}
|
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}
|
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 = [
|
point_scale = [
|
||||||
1 if p == "0" else int(float(p) * 2)
|
1 if p == "0" else int(float(p) * 2)
|
||||||
for p in project_info["point_scale"].split(",")
|
for p in project_info["point_scale"].split(",")
|
||||||
|
@ -312,7 +304,7 @@ def meeting(project: str):
|
||||||
inquirer.Text(
|
inquirer.Text(
|
||||||
"hours",
|
"hours",
|
||||||
message="Meeting length (hours, multiple of 0.5)",
|
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(
|
inquirer.Checkbox(
|
||||||
"owners",
|
"owners",
|
||||||
|
|
Loading…
Reference in a new issue