2018-07-17 20:28:37 +03:00
|
|
|
package bug
|
|
|
|
|
2018-09-09 21:13:46 +03:00
|
|
|
import (
|
|
|
|
"fmt"
|
|
|
|
"strings"
|
|
|
|
)
|
|
|
|
|
2018-07-17 20:28:37 +03:00
|
|
|
type Status int
|
|
|
|
|
|
|
|
const (
|
|
|
|
_ Status = iota
|
|
|
|
OpenStatus
|
|
|
|
ClosedStatus
|
|
|
|
)
|
|
|
|
|
|
|
|
func (s Status) String() string {
|
|
|
|
switch s {
|
|
|
|
case OpenStatus:
|
|
|
|
return "open"
|
|
|
|
case ClosedStatus:
|
|
|
|
return "closed"
|
|
|
|
default:
|
|
|
|
return "unknown status"
|
|
|
|
}
|
|
|
|
}
|
2018-08-09 16:28:32 +03:00
|
|
|
|
|
|
|
func (s Status) Action() string {
|
|
|
|
switch s {
|
|
|
|
case OpenStatus:
|
|
|
|
return "opened"
|
|
|
|
case ClosedStatus:
|
|
|
|
return "closed"
|
|
|
|
default:
|
|
|
|
return "unknown status"
|
|
|
|
}
|
|
|
|
}
|
2018-09-09 21:13:46 +03:00
|
|
|
|
|
|
|
func StatusFromString(str string) (Status, error) {
|
|
|
|
cleaned := strings.ToLower(strings.TrimSpace(str))
|
|
|
|
|
|
|
|
switch cleaned {
|
|
|
|
case "open":
|
|
|
|
return OpenStatus, nil
|
|
|
|
case "closed":
|
|
|
|
return ClosedStatus, nil
|
|
|
|
default:
|
2020-01-24 02:30:13 +03:00
|
|
|
return 0, fmt.Errorf("unknown status")
|
2018-09-09 21:13:46 +03:00
|
|
|
}
|
|
|
|
}
|
2018-09-15 14:15:00 +03:00
|
|
|
|
|
|
|
func (s Status) Validate() error {
|
|
|
|
if s != OpenStatus && s != ClosedStatus {
|
|
|
|
return fmt.Errorf("invalid")
|
|
|
|
}
|
|
|
|
|
|
|
|
return nil
|
|
|
|
}
|