Skip to content

Commit

Permalink
Add JSON marshalling support for State codes.
Browse files Browse the repository at this point in the history
This converts JSON serialization of statuses into their string
representation. e.g.

Old:
```
{
  "state": 3,
}
```

New:
```
{
  "state": "success",
}
```
  • Loading branch information
wlynch committed Oct 23, 2019
1 parent e1c8c9d commit fad5b44
Show file tree
Hide file tree
Showing 11 changed files with 22 additions and 13 deletions.
9 changes: 9 additions & 0 deletions scm/const.go
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,15 @@ func ToState(s string) State {
}
}

func (s State) MarshalJSON() ([]byte, error) {
return []byte(s.String()), nil
}

func (s *State) UnmarshalJSON(b []byte) error {
*s = ToState(strings.Trim(string(b), `"`))
return nil
}

// Action identifies webhook actions.
type Action int

Expand Down
2 changes: 1 addition & 1 deletion scm/driver/bitbucket/testdata/status.json.golden
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
{
"State": 3,
"State": "success",
"Label": "drone",
"Desc": "Build has completed successfully",
"Target": "https://ci.example.com/1000/output"
Expand Down
2 changes: 1 addition & 1 deletion scm/driver/bitbucket/testdata/statuses.json.golden
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[
{
"State": 3,
"State": "success",
"Label": "drone",
"Desc": "Build has completed successfully",
"Target": "https://ci.example.com/1000/output"
Expand Down
2 changes: 1 addition & 1 deletion scm/driver/gitea/testdata/status.json.golden
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
{
"State": 3,
"State": "success",
"Label": "continuous-integration/drone",
"Desc": "",
"Target": "https://example.com"
Expand Down
2 changes: 1 addition & 1 deletion scm/driver/gitea/testdata/statuses.json.golden
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[
{
"State": 3,
"State": "success",
"Label": "continuous-integration/drone",
"Desc": "",
"Target": "https://example.com"
Expand Down
6 changes: 3 additions & 3 deletions scm/driver/github/testdata/combined_status.json.golden
Original file line number Diff line number Diff line change
@@ -1,15 +1,15 @@
{
"State": 3,
"State": "success",
"Sha": "6dcb09b5b57875f334f61aebed695e2e4193db5e",
"Statuses": [
{
"State": 3,
"State": "success",
"Label": "continuous-integration/jenkins",
"Desc": "Build has completed successfully",
"Target": "https://ci.example.com/1000/output"
},
{
"State": 3,
"State": "success",
"Label": "security/brakeman",
"Desc": "Testing has completed successfully",
"Target": "https://ci.example.com/2000/output"
Expand Down
2 changes: 1 addition & 1 deletion scm/driver/github/testdata/status.json.golden
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
{
"State": 3,
"State": "success",
"Label": "continuous-integration/drone",
"Desc": "Build has completed successfully",
"Target": "https://ci.example.com/1000/output"
Expand Down
2 changes: 1 addition & 1 deletion scm/driver/github/testdata/statuses.json.golden
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[
{
"State": 3,
"State": "success",
"Label": "continuous-integration/drone",
"Desc": "Build has completed successfully",
"Target": "https://ci.example.com/1000/output"
Expand Down
2 changes: 1 addition & 1 deletion scm/driver/gitlab/testdata/status.json.golden
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
{
"State": 1,
"State": "pending",
"Label": "default",
"Desc": "the dude abides",
"Target": "https://gitlab.example.com/thedude/gitlab-ce/builds/91"
Expand Down
2 changes: 1 addition & 1 deletion scm/driver/gitlab/testdata/statuses.json.golden
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[
{
"State": 1,
"State": "pending",
"Label": "default",
"Desc": "the dude abides",
"Target": "https://gitlab.example.com/thedude/gitlab-ce/builds/91"
Expand Down
4 changes: 2 additions & 2 deletions scm/driver/stash/testdata/commit_build_status.json.golden
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
[
{
"State": 3,
"State": "success",
"Label": "team-bb-server » repo-1 » master #23",
"Desc": "This commit looks good.",
"Target": "http://example.com/master-1/job/kyounger/job/repo-1/job/master/21/display/redirect"
},
{
"State": 3,
"State": "success",
"Label": "team-bb-server » repo-1 » master #22",
"Desc": "This commit looks good.",
"Target": "http://example.com/master-1/job/kyounger/job/repo-1/job/master/22/display/redirect"
Expand Down

0 comments on commit fad5b44

Please sign in to comment.