Skip to content

Commit 6c8f164

Browse files
Merge pull request #469 from Maximilien-R/mra/fix-action-unmarshal-json
fix: fix Action JSON serialization/deserialization
2 parents cadb6f7 + 3a2188a commit 6c8f164

File tree

2 files changed

+30
-1
lines changed

2 files changed

+30
-1
lines changed

scm/const.go

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -141,7 +141,7 @@ func (a Action) String() (s string) {
141141
case ActionSubmitted:
142142
return "submitted"
143143
case ActionDismissed:
144-
return "dismisssed"
144+
return "dismissed"
145145
case ActionAssigned:
146146
return "assigned"
147147
case ActionUnassigned:
@@ -205,6 +205,14 @@ func (a *Action) UnmarshalJSON(data []byte) error {
205205
*a = ActionDismissed
206206
case "edited":
207207
*a = ActionEdited
208+
case "assigned":
209+
*a = ActionAssigned
210+
case "unassigned":
211+
*a = ActionUnassigned
212+
case "review_requested":
213+
*a = ActionReviewRequested
214+
case "review_request_removed":
215+
*a = ActionReviewRequestRemoved
208216
}
209217
return nil
210218
}

scm/const_test.go

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,3 +25,24 @@ func TestStateJSON(t *testing.T) {
2525
})
2626
}
2727
}
28+
29+
func TestActionJSON(t *testing.T) {
30+
for i := ActionCreate; i < ActionCompleted; i++ {
31+
in := i
32+
t.Run(in.String(), func(t *testing.T) {
33+
b, err := json.Marshal(in)
34+
if err != nil {
35+
t.Fatal(err)
36+
}
37+
38+
var out Action
39+
if err := json.Unmarshal(b, &out); err != nil {
40+
t.Fatal(err)
41+
}
42+
43+
if in != out {
44+
t.Errorf("%s != %s", in, out)
45+
}
46+
})
47+
}
48+
}

0 commit comments

Comments
 (0)