Add start, finish, deliver and accept commands.
Hacky for now, will clean up later.
This commit is contained in:
parent
66742ee4e0
commit
37346015a0
3 changed files with 58 additions and 4 deletions
|
@ -9,6 +9,14 @@ def get(token: str, story_id: int = None) -> Dict[str, Any]:
|
||||||
return r.json()
|
return r.json()
|
||||||
|
|
||||||
|
|
||||||
|
def put_story(token: str, story_id: int, **kwargs) -> Dict[str, Any]:
|
||||||
|
r = requests.put(
|
||||||
|
f'https://www.pivotaltracker.com/services/v5/stories/{story_id}',
|
||||||
|
headers={'X-TrackerToken': token}, json=kwargs)
|
||||||
|
print(r.text)
|
||||||
|
return r.json()
|
||||||
|
|
||||||
|
|
||||||
def get_tasks(token: str, project_id: int, story_id: int) \
|
def get_tasks(token: str, project_id: int, story_id: int) \
|
||||||
-> List[Dict[str, Any]]:
|
-> List[Dict[str, Any]]:
|
||||||
r = requests.get(
|
r = requests.get(
|
||||||
|
@ -28,6 +36,6 @@ def get_comments(token: str, project_id: int, story_id: int) \
|
||||||
def get_blockers(token: str, project_id: int, story_id: int) \
|
def get_blockers(token: str, project_id: int, story_id: int) \
|
||||||
-> List[Dict[str, Any]]:
|
-> List[Dict[str, Any]]:
|
||||||
r = requests.get(
|
r = requests.get(
|
||||||
f'https://www.pivotaltracker.com/services/v5/projects/{project_id}'
|
f'https://www.pivotaltracker.com/services/v5/projects/{project_id}'
|
||||||
f'/stories/{story_id}/blockers', headers={'X-TrackerToken': token})
|
f'/stories/{story_id}/blockers', headers={'X-TrackerToken': token})
|
||||||
return r.json()
|
return r.json()
|
||||||
|
|
|
@ -52,6 +52,8 @@ def __format_story(story: Dict[str, Any], persons: Persons, totals: Totals) \
|
||||||
value = f'\033[96m{value}\033[97m'
|
value = f'\033[96m{value}\033[97m'
|
||||||
initials.append(value)
|
initials.append(value)
|
||||||
|
|
||||||
|
type_ = story['story_type']
|
||||||
|
|
||||||
estimate = story.get('estimate')
|
estimate = story.get('estimate')
|
||||||
if estimate:
|
if estimate:
|
||||||
for owner_id in owner_ids:
|
for owner_id in owner_ids:
|
||||||
|
@ -65,7 +67,7 @@ def __format_story(story: Dict[str, Any], persons: Persons, totals: Totals) \
|
||||||
owners = ', '.join(initials)
|
owners = ', '.join(initials)
|
||||||
|
|
||||||
state = _format_state(story['current_state'])
|
state = _format_state(story['current_state'])
|
||||||
return code, story['story_type'], story['name'], owners, state, estimate
|
return code, type_, story['name'], owners, state, estimate
|
||||||
|
|
||||||
|
|
||||||
def __print_stories(stories: List[Dict[str, Any]], persons: Persons,
|
def __print_stories(stories: List[Dict[str, Any]], persons: Persons,
|
||||||
|
@ -82,7 +84,7 @@ def __print_totals(totals: Totals, persons: Persons) -> None:
|
||||||
headers = ('Owner', *state_headers, 'Total', 'Progress')
|
headers = ('Owner', *state_headers, 'Total', 'Progress')
|
||||||
|
|
||||||
data = [__get_row(item, persons) for item in totals.items()]
|
data = [__get_row(item, persons) for item in totals.items()]
|
||||||
data.sort(key=lambda row: row[-2])
|
data.sort(key=lambda row: row[-2], reverse=True)
|
||||||
print(tabulate.tabulate(data, headers), end='\n\n')
|
print(tabulate.tabulate(data, headers), end='\n\n')
|
||||||
|
|
||||||
|
|
||||||
|
|
|
@ -3,8 +3,32 @@ import argparse
|
||||||
import commands.login as cmd_login
|
import commands.login as cmd_login
|
||||||
import commands.projects as cmd_projects
|
import commands.projects as cmd_projects
|
||||||
import commands.stories as cmd_stories
|
import commands.stories as cmd_stories
|
||||||
|
import api.stories
|
||||||
|
|
||||||
from config import Config
|
from config import Config
|
||||||
|
from base32_crockford import decode as b32_decode
|
||||||
|
|
||||||
|
|
||||||
|
def start_story(args) -> None:
|
||||||
|
story_set_state(args.story, 'finished')
|
||||||
|
|
||||||
|
|
||||||
|
def finish_story(args) -> None:
|
||||||
|
story_set_state(args.story, 'finished')
|
||||||
|
|
||||||
|
|
||||||
|
def deliver_story(args) -> None:
|
||||||
|
story_set_state(args.story, 'delivered')
|
||||||
|
|
||||||
|
|
||||||
|
def accept_story(args) -> None:
|
||||||
|
story_set_state(args.story, 'accepted')
|
||||||
|
|
||||||
|
|
||||||
|
def story_set_state(args, state: str) -> None:
|
||||||
|
token = Config['user']['api_token']
|
||||||
|
story_id = b32_decode(args.story)
|
||||||
|
api.stories.put_story(token, story_id, current_state=state)
|
||||||
|
|
||||||
|
|
||||||
def parse_arguments() -> None:
|
def parse_arguments() -> None:
|
||||||
|
@ -43,6 +67,26 @@ def parse_arguments() -> None:
|
||||||
stories_parser.add_argument('--hide-accepted', nargs='?', type=bool,
|
stories_parser.add_argument('--hide-accepted', nargs='?', type=bool,
|
||||||
const=True, default=False)
|
const=True, default=False)
|
||||||
|
|
||||||
|
story_start_parser = commands.add_parser('start')
|
||||||
|
story_start_parser.set_defaults(
|
||||||
|
func=lambda args: story_set_state(args, 'started'))
|
||||||
|
story_start_parser.add_argument('story', type=str)
|
||||||
|
|
||||||
|
story_finish_parser = commands.add_parser('finish')
|
||||||
|
story_finish_parser.set_defaults(
|
||||||
|
func=lambda args: story_set_state(args, 'finished'))
|
||||||
|
story_finish_parser.add_argument('story', type=str)
|
||||||
|
|
||||||
|
story_deliver_parser = commands.add_parser('deliver')
|
||||||
|
story_deliver_parser.set_defaults(
|
||||||
|
func=lambda args: story_set_state(args, 'delivered'))
|
||||||
|
story_deliver_parser.add_argument('story', type=str)
|
||||||
|
|
||||||
|
story_accept_parser = commands.add_parser('accept')
|
||||||
|
story_accept_parser.set_defaults(
|
||||||
|
func=lambda args: story_set_state(args, 'accepted'))
|
||||||
|
story_accept_parser.add_argument('story', type=str)
|
||||||
|
|
||||||
args = parser.parse_args()
|
args = parser.parse_args()
|
||||||
args.func(args)
|
args.func(args)
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue