@@ -14,8 +14,9 @@ import (
1414)
1515
1616type PlanStorage interface {
17- StorePlan (planFileName string ) error
18- RetrievePlan (planFileName string ) (* string , error )
17+ StorePlan (localPlanFilePath string , storedPlanFilePath string ) error
18+ RetrievePlan (localPlanFilePath string , storedPlanFilePath string ) (* string , error )
19+ DeleteStoredPlan (storedPlanFilePath string ) error
1920}
2021
2122type PlanStorageGcp struct {
@@ -32,14 +33,14 @@ type GithubPlanStorage struct {
3233 ZipManager Zipper
3334}
3435
35- func (psg * PlanStorageGcp ) StorePlan (planFileName string ) error {
36- file , err := os .Open (planFileName )
36+ func (psg * PlanStorageGcp ) StorePlan (localPlanFilePath string , storedPlanFilePath string ) error {
37+ file , err := os .Open (localPlanFilePath )
3738 if err != nil {
3839 return fmt .Errorf ("unable to open file: %v" , err )
3940 }
4041 defer file .Close ()
4142
42- obj := psg .Bucket .Object (planFileName )
43+ obj := psg .Bucket .Object (storedPlanFilePath )
4344 wc := obj .NewWriter (psg .Context )
4445
4546 if _ , err = io .Copy (wc , file ); err != nil {
@@ -54,15 +55,15 @@ func (psg *PlanStorageGcp) StorePlan(planFileName string) error {
5455 return nil
5556}
5657
57- func (psg * PlanStorageGcp ) RetrievePlan (planFileName string ) (* string , error ) {
58- obj := psg .Bucket .Object (planFileName )
58+ func (psg * PlanStorageGcp ) RetrievePlan (localPlanFilePath string , storedPlanFilePath string ) (* string , error ) {
59+ obj := psg .Bucket .Object (storedPlanFilePath )
5960 rc , err := obj .NewReader (psg .Context )
6061 if err != nil {
6162 return nil , fmt .Errorf ("unable to read data from bucket: %v" , err )
6263 }
6364 defer rc .Close ()
6465
65- file , err := os .Create (planFileName )
66+ file , err := os .Create (localPlanFilePath )
6667 if err != nil {
6768 return nil , fmt .Errorf ("unable to create file: %v" , err )
6869 }
@@ -72,15 +73,25 @@ func (psg *PlanStorageGcp) RetrievePlan(planFileName string) (*string, error) {
7273 return nil , fmt .Errorf ("unable to write data to file: %v" , err )
7374 }
7475
75- return & planFileName , nil
76+ return & localPlanFilePath , nil
7677}
7778
78- func (gps * GithubPlanStorage ) StorePlan (planFileName string ) error {
79- _ = fmt .Sprintf ("Skipping storing plan %s. It should be achieved using actions/upload-artifact@v3" , planFileName )
79+ func (psg * PlanStorageGcp ) DeleteStoredPlan (storedPlanFilePath string ) error {
80+ obj := psg .Bucket .Object (storedPlanFilePath )
81+ err := obj .Delete (psg .Context )
82+
83+ if err != nil {
84+ return fmt .Errorf ("unable to delete file '%v' from bucket: %v" , storedPlanFilePath , err )
85+ }
8086 return nil
8187}
8288
83- func (gps * GithubPlanStorage ) RetrievePlan (planFileName string ) (* string , error ) {
89+ func (gps * GithubPlanStorage ) StorePlan (localPlanFilePath string , storedPlanFilePath string ) error {
90+ _ = fmt .Sprintf ("Skipping storing plan %s. It should be achieved using actions/upload-artifact@v3" , localPlanFilePath )
91+ return nil
92+ }
93+
94+ func (gps * GithubPlanStorage ) RetrievePlan (localPlanFilePath string , storedPlanFilePath string ) (* string , error ) {
8495 plansFilename , err := gps .DownloadLatestPlans ()
8596
8697 if err != nil {
@@ -91,14 +102,18 @@ func (gps *GithubPlanStorage) RetrievePlan(planFileName string) (*string, error)
91102 return nil , fmt .Errorf ("no plans found for this PR" )
92103 }
93104
94- plansFilename , err = gps .ZipManager .GetFileFromZip (plansFilename , planFileName )
105+ plansFilename , err = gps .ZipManager .GetFileFromZip (plansFilename , storedPlanFilePath )
95106
96107 if err != nil {
97108 return nil , fmt .Errorf ("error extracting plan: %v" , err )
98109 }
99110 return & plansFilename , nil
100111}
101112
113+ func (gps * GithubPlanStorage ) DeleteStoredPlan (storedPlanFilePath string ) error {
114+ return nil
115+ }
116+
102117func (gps * GithubPlanStorage ) DownloadLatestPlans () (string , error ) {
103118 artifacts , _ , err := gps .Client .Actions .ListArtifacts (context .Background (), gps .Owner , gps .RepoName , & github.ListOptions {
104119 PerPage : 100 ,
0 commit comments