This repository was archived by the owner on Feb 14, 2023. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathjson.go
91 lines (75 loc) · 1.9 KB
/
json.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
package main
import (
"io/ioutil"
"log"
"os"
"encoding/json"
)
// PushEventData is workaround to use *github.PushEvent.
// If we available, we should use *github.PushEvent.
// But we cannot use it by parsing error. See https://github.com/cats-oss/github-action-detect-unmergeable/issues/71
type PushEventData struct {
Ref *string `json:"ref,omitempty"`
Compare *string `json:"compare,omitempty"`
}
func (p *PushEventData) GetRef() string {
if p == nil || p.Ref == nil {
return ""
}
return *p.Ref
}
func (p *PushEventData) GetCompare() string {
if p == nil || p.Compare == nil {
return ""
}
return *p.Compare
}
func loadJSONFileForPushEventData(path string) *PushEventData {
jsonFile, err := os.Open(path)
defer jsonFile.Close()
if err != nil {
log.Fatal(err)
return nil
}
var data PushEventData
byteValue, _ := ioutil.ReadAll(jsonFile)
if err := json.Unmarshal(byteValue, &data); err != nil {
log.Fatal(err)
return nil
}
return &data
}
// PullRequestEventData is workaround to use *github.PushEvent.
// If we available, we should use *github.PushEvent.
// But we cannot use it by parsing error. See https://github.com/cats-oss/github-action-detect-unmergeable/issues/71
type PullRequestEventData struct {
Action *string `json:"action,omitempty"`
Number *int `json:"number,omitempty"`
}
func (p *PullRequestEventData) GetAction() string {
if p == nil || p.Action == nil {
return ""
}
return *p.Action
}
func (p *PullRequestEventData) GetNumber() int {
if p == nil || p.Number == nil {
return -1
}
return *p.Number
}
func loadJSONFileForPullRequestEventData(path string) *PullRequestEventData {
jsonFile, err := os.Open(path)
defer jsonFile.Close()
if err != nil {
log.Fatal(err)
return nil
}
var data PullRequestEventData
byteValue, _ := ioutil.ReadAll(jsonFile)
if err := json.Unmarshal(byteValue, &data); err != nil {
log.Fatal(err)
return nil
}
return &data
}