Skip to content

Commit 6c44502

Browse files
committed
chore: add a helper method for string conversion
1 parent 4ce83a2 commit 6c44502

File tree

1 file changed

+23
-0
lines changed

1 file changed

+23
-0
lines changed

scm/const.go

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ package scm
66

77
import (
88
"encoding/json"
9+
"strings"
910
)
1011

1112
// State represents the commit state.
@@ -47,6 +48,28 @@ func (s State) String() string {
4748
}
4849
}
4950

51+
// ToState converts the given text to a state
52+
func ToState(s string) State {
53+
switch strings.ToLower(s) {
54+
case "pending":
55+
return StatePending
56+
case "running":
57+
return StateRunning
58+
case "success":
59+
return StateSuccess
60+
case "failure":
61+
return StateFailure
62+
case "cancelled":
63+
return StateCanceled
64+
case "expected":
65+
return StateExpected
66+
case "error":
67+
return StateError
68+
default:
69+
return StateUnknown
70+
}
71+
}
72+
5073
// Action identifies webhook actions.
5174
type Action int
5275

0 commit comments

Comments
 (0)