@@ -54,11 +54,16 @@ func Run(ctx context.Context, branchId string, fsys afero.Fs) error {
5454
5555func getBranchDetail (ctx context.Context , branchId string ) (api.BranchDetailResponse , error ) {
5656 var result api.BranchDetailResponse
57- parsed , err := GetBranchID (ctx , branchId )
58- if err != nil {
59- return result , err
57+ if err := uuid .Validate (branchId ); err != nil && ! utils .ProjectRefPattern .Match ([]byte (branchId )) {
58+ resp , err := utils .GetSupabase ().V1GetABranchWithResponse (ctx , flags .ProjectRef , branchId )
59+ if err != nil {
60+ return result , errors .Errorf ("failed to find branch: %w" , err )
61+ } else if resp .JSON200 == nil {
62+ return result , errors .Errorf ("unexpected find branch status %d: %s" , resp .StatusCode (), string (resp .Body ))
63+ }
64+ branchId = resp .JSON200 .ProjectRef
6065 }
61- resp , err := utils .GetSupabase ().V1GetABranchConfigWithResponse (ctx , parsed )
66+ resp , err := utils .GetSupabase ().V1GetABranchConfigWithResponse (ctx , branchId )
6267 if err != nil {
6368 return result , errors .Errorf ("failed to get branch: %w" , err )
6469 } else if resp .JSON200 == nil {
@@ -77,20 +82,6 @@ func getBranchDetail(ctx context.Context, branchId string) (api.BranchDetailResp
7782 return * resp .JSON200 , nil
7883}
7984
80- func GetBranchID (ctx context.Context , branchId string ) (uuid.UUID , error ) {
81- parsed , err := uuid .Parse (branchId )
82- if err == nil {
83- return parsed , nil
84- }
85- resp , err := utils .GetSupabase ().V1GetABranchWithResponse (ctx , flags .ProjectRef , branchId )
86- if err != nil {
87- return parsed , errors .Errorf ("failed to get branch: %w" , err )
88- } else if resp .JSON200 == nil {
89- return parsed , errors .Errorf ("unexpected get branch status %d: %s" , resp .StatusCode (), string (resp .Body ))
90- }
91- return resp .JSON200 .Id , nil
92- }
93-
9485func getPoolerConfig (ctx context.Context , ref string ) (api.SupavisorConfigResponse , error ) {
9586 var result api.SupavisorConfigResponse
9687 resp , err := utils .GetSupabase ().V1GetPoolerConfigWithResponse (ctx , ref )
0 commit comments