@@ -61,20 +61,31 @@ type Advisory struct {
6161 Affected []AffectedItem `json:"affected"`
6262}
6363
64+ const (
65+ policyBasePath = "policies/V8-policy.json"
66+ cacheBasePath = "src/V8-cache.json"
67+ advisoryBasePath = "advisories/V8-advisory.json"
68+ )
69+
6470var (
6571 now = time .Now ()
6672 nowTimestamp = now .Format (time .RFC3339 )
6773 today = format (now )
68- policyPath = "policies/V8-policy.json"
69- cachePath = "src/V8-cache.json"
70- advisoryPath = "advisories/V8-advisory.json"
74+ dir string
75+ policyPath string
76+ cachePath string
77+ advisoryPath string
7178)
7279
7380type Repositories interface {
7481 ListCommits (ctx context.Context , owner , repo string , opts * github.CommitsListOptions ) ([]* github.RepositoryCommit , * github.Response , error )
7582}
7683
7784func main () {
85+ // Construct absolute path of the runner.
86+ _ , filename , _ , _ := runtime .Caller (0 )
87+ dir = filepath .Dir (filename )
88+
7889 policy , err := loadPolicy ()
7990 if err != nil {
8091 panic (err )
@@ -112,10 +123,8 @@ func main() {
112123}
113124
114125func loadPolicy () (* Policy , error ) {
115- _ , filename , _ , _ := runtime .Caller (0 )
116- dir := filepath .Dir (filename )
117- advisoryFilePath := filepath .Join (dir , "../advisories/V8-advisory.json" )
118- data , err := os .ReadFile (advisoryFilePath )
126+ policyPath = filepath .Join (dir , "../" , policyBasePath )
127+ data , err := os .ReadFile (policyPath )
119128 if err != nil {
120129 return nil , err
121130 }
@@ -131,6 +140,7 @@ func loadPolicy() (*Policy, error) {
131140
132141func loadCache () (map [string ][]string , error ) {
133142 cacheData := make (map [string ][]string )
143+ cachePath = filepath .Join (dir , "../" , cacheBasePath )
134144 data , err := os .ReadFile (cachePath )
135145 if err != nil {
136146 if ! os .IsNotExist (err ) {
@@ -146,7 +156,6 @@ func loadCache() (map[string][]string, error) {
146156}
147157
148158func saveCache (cacheData map [string ][]string ) error {
149-
150159 updatedData , err := json .MarshalIndent (cacheData , "" , " " )
151160 if err != nil {
152161 return fmt .Errorf ("error marshalling cache data: %w" , err )
@@ -159,6 +168,7 @@ func saveCache(cacheData map[string][]string) error {
159168}
160169
161170func loadAdvisory () (* Advisory , error ) {
171+ advisoryPath = filepath .Join (dir , "../" , advisoryBasePath )
162172 advisoryData , err := os .ReadFile (advisoryPath )
163173 var advisory Advisory
164174 if err == nil {
0 commit comments