@@ -138,9 +138,9 @@ func getPendingVersions(c echo.Context) (err error) {
138138 return c .JSON (http .StatusOK , filteredVersions )
139139}
140140
141- func approvePendingVersion (c echo.Context ) (err error ) {
141+ func lookForPendingVersion (c echo.Context ) (app * registry. App , version * registry. Version , err error ) {
142142 if err = checkAuthorized (c ); err != nil {
143- return err
143+ return nil , nil , err
144144 }
145145
146146 // Only allow approving versions from editor cozy
@@ -149,23 +149,32 @@ func approvePendingVersion(c echo.Context) (err error) {
149149 editorName := "cozy"
150150 _ , err = checkPermissions (c , editorName , "" , true /* = master */ )
151151 if err != nil {
152- return errshttp .NewError (http .StatusUnauthorized , err .Error ())
152+ return nil , nil , errshttp .NewError (http .StatusUnauthorized , err .Error ())
153153 }
154154
155155 appSlug := c .Param ("app" )
156156 if appSlug == "" {
157- return errshttp .NewError (http .StatusNotFound , "App is missing in the URL" )
157+ return nil , nil , errshttp .NewError (http .StatusNotFound , "App is missing in the URL" )
158158 }
159- app , err : = registry .FindApp (nil , getSpace (c ), appSlug , registry .Stable )
159+ app , err = registry .FindApp (nil , getSpace (c ), appSlug , registry .Stable )
160160 if err != nil {
161- return err
161+ return nil , nil , err
162162 }
163163
164164 ver := stripVersion (c .Param ("version" ))
165165 if ver == "" {
166- return errshttp .NewError (http .StatusNotFound , "Version is missing in the URL" )
166+ return nil , nil , errshttp .NewError (http .StatusNotFound , "Version is missing in the URL" )
167167 }
168- version , err := registry .FindPendingVersion (getSpace (c ), appSlug , ver )
168+ version , err = registry .FindPendingVersion (getSpace (c ), appSlug , ver )
169+ if err != nil {
170+ return nil , nil , err
171+ }
172+
173+ return app , version , nil
174+ }
175+
176+ func approvePendingVersion (c echo.Context ) (err error ) {
177+ app , version , err := lookForPendingVersion (c )
169178 if err != nil {
170179 return err
171180 }
@@ -179,6 +188,17 @@ func approvePendingVersion(c echo.Context) (err error) {
179188 return c .JSON (http .StatusCreated , version )
180189}
181190
191+ func getPendingVersion (c echo.Context ) (err error ) {
192+ _ , version , err := lookForPendingVersion (c )
193+ if err != nil {
194+ return err
195+ }
196+
197+ cleanVersion (version )
198+
199+ return c .JSON (http .StatusOK , version )
200+ }
201+
182202func deletePendingVersion (c echo.Context ) (err error ) {
183203 if err = checkAuthorized (c ); err != nil {
184204 return err
0 commit comments