Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

USHIFT-2392: require story points and set target version on jira tickets #3040

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
50 changes: 47 additions & 3 deletions scripts/jira/manage_ticket.py
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,12 @@
The `--target-version` flag can be used to set a target version if one
is not set already.

Story Points
------------

The `--story-points` flag can be used to set the number of points the
work represents, if it was not pre-planned.

Status
------

Expand Down Expand Up @@ -158,7 +164,7 @@ def command_start(args):
server=SERVER_URL,
token_auth=os.environ.get('JIRA_API_TOKEN'),
)
_, setter = custom_field_manager(server)
getter, setter = custom_field_manager(server)

print(f'finding ticket {args.ticket_id}')
ticket = server.issue(args.ticket_id)
Expand All @@ -178,6 +184,25 @@ def command_start(args):
print(f'...setting the target version to "{args.target_version}"')
setter(ticket, 'Target Version', [{'name': args.target_version}])

if args.story_points:
print(f'...setting the story points to "{args.story_points}"')
setter(ticket, 'Story Points', args.story_points)
else:
points = getter(ticket, 'Story Points')
if not points:
print('...WARNING: story points unset')
else:
print(f'...story points set to "{points}"')

if args.no_qe:
labels = ticket.fields.labels
if 'no-qe-needed' not in labels:
labels.append('no-qe-needed')
ticket.update(fields={'labels': labels})
print('...added no-qe-needed label')
else:
print('...already have no-qe-needed')

if args.sprint:
active_sprint = get_active_sprint(server, sprint_project_id)
if not active_sprint:
Expand Down Expand Up @@ -219,7 +244,7 @@ def command_close(args):
server=SERVER_URL,
token_auth=os.environ.get('JIRA_API_TOKEN'),
)
getter, _ = custom_field_manager(server)
getter, setter = custom_field_manager(server)
active_sprint = get_active_sprint(server, 'USHIFT')
jira_id = server.myself()['name']
gh_auth = github.Auth.Token(os.environ['GITHUB_TOKEN'])
Expand All @@ -236,6 +261,8 @@ def command_close(args):
print(' Status:', ticket.fields.status)
if ticket.fields.labels:
print(' Labels:', ticket.fields.labels)
points = getter(ticket, 'Story Points')
print(f' Story Points: {points}')

all_merged = True
links = server.remote_links(ticket.id)
Expand Down Expand Up @@ -265,8 +292,11 @@ def command_close(args):
next_state = 'Review'
print(f' Transition: {next_state}')
if args.dry_run:
print('f DRY RUN')
print(' DRY RUN')
else:
if not points:
print(' SKIPPING: story points are not set')
continue
server.transition_issue(
issue=ticket,
transition=next_state,
Expand All @@ -292,15 +322,29 @@ def main():
)
start_parser.add_argument(
'--target-version',
default=os.environ.get('DEFAULT_TARGET_VERSION'),
help='the target version',
)
start_parser.add_argument(
'--story-points',
help='the story points',
default=None,
type=int,
)
start_parser.add_argument(
'--no-sprint',
dest='sprint',
default=True,
action='store_false',
help='set the sprint to the active sprint',
)
start_parser.add_argument(
'--no-qe',
dest='no_qe',
default=False,
action='store_true',
help='add the no-qe-needed label',
)
start_parser.add_argument(
'--review',
dest='status',
Expand Down
4 changes: 4 additions & 0 deletions scripts/jira/manage_ticket.sh
Original file line number Diff line number Diff line change
Expand Up @@ -14,4 +14,8 @@ if [ ! -d "${ENVDIR}" ]; then
"${ENVDIR}/bin/pip3" install -r "${SCRIPTDIR}/requirements.txt"
fi

version_file="${REPOROOT}/Makefile.version.$(uname -m).var"
version=$(cut -f2 -d= "${version_file}" | cut -f1-2 -d. | sed -e 's/ //g')
export DEFAULT_TARGET_VERSION="openshift-${version}"

"${ENVDIR}/bin/python3" "${SCRIPTDIR}/manage_ticket.py" "$@"