Skip to content

Commit

Permalink
🎨 Use Enum for ALLOWED_STATES
Browse files Browse the repository at this point in the history
  • Loading branch information
webknjaz committed Jan 7, 2019
1 parent 1994136 commit f4f8d67
Showing 1 changed file with 7 additions and 5 deletions.
12 changes: 7 additions & 5 deletions cherry_picker/cherry_picker/cherry_picker.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@

import click
import collections
import enum
import os
import subprocess
import webbrowser
Expand Down Expand Up @@ -40,9 +41,9 @@ class InvalidRepoException(Exception):

class CherryPicker:

ALLOWED_STATES = (
'BACKPORT_PAUSED',
'UNSET',
ALLOWED_STATES = enum.Enum(
'Allowed states',
'BACKPORT_PAUSED UNSET',
)
"""The list of states expected at the start of the app."""

Expand Down Expand Up @@ -435,12 +436,13 @@ def get_state_and_verify(self):
cherry_picker would have stored in the config.
"""
state = get_state()
if state not in self.ALLOWED_STATES:
if state not in self.ALLOWED_STATES.__members__:
raise ValueError(
f'Run state cherry-picker.state={state} in Git config '
'is not known.\nPerhaps it has been set by a newer '
'version of cherry-picker. Try upgrading.\n'
f'Valid states are: {", ".join(self.ALLOWED_STATES)}. '
'Valid states are: '
f'{", ".join(self.ALLOWED_STATES.__members__.keys())}. '
'If this looks suspicious, raise an issue at '
'https://github.com/python/core-workflow/issues/new.\n'
'As the last resort you can reset the runtime state '
Expand Down

0 comments on commit f4f8d67

Please sign in to comment.