Skip to content

Commit

Permalink
Implementation 2 for fetchDevfile chosen and added. See Issue #720 di…
Browse files Browse the repository at this point in the history
…scussion at: devfile/api#720
  • Loading branch information
michael-valdron committed Feb 7, 2022
1 parent 336153a commit 40db91a
Showing 1 changed file with 33 additions and 0 deletions.
33 changes: 33 additions & 0 deletions index/server/pkg/server/endpoint.go
Original file line number Diff line number Diff line change
Expand Up @@ -143,6 +143,7 @@ func serveDevfile(c *gin.Context) {
func serveDevfileStarterProject(c *gin.Context) {
devfileName := c.Param("devfileName")
starterProjectName := c.Param("starterProjectName")
<<<<<<< HEAD
devfileBytes, devfileIndexSchema := fetchDevfile(c, devfileName)

if len(devfileBytes) == 0 {
Expand Down Expand Up @@ -186,6 +187,15 @@ func serveDevfileStarterProject(c *gin.Context) {
c.JSON(http.StatusNotFound, gin.H{
"status": fmt.Sprintf("the starter project named %s does not exist in the devfile of %s", starterProjectName, devfileName),
})
=======
devfileBytes := fetchDevfile(c, devfileName)

if len(devfileBytes) == 0 {
// fetchDevfile was unsuccessful (error or not found)
return
} else {
// TODO: Add fetch start project and set response source.
>>>>>>> 2bb8eb9... Implementation 2 for fetchDevfile chosen and added. See Issue #720 discussion at: https://github.com/devfile/api/issues/720
}
}

Expand Down Expand Up @@ -312,7 +322,11 @@ func buildIndexAPIResponse(c *gin.Context) {
}

// fetchDevfile retrieves a specified devfile stored under /registry/**/<devfileName>
<<<<<<< HEAD
func fetchDevfile(c *gin.Context, devfileName string) ([]byte, indexSchema.Schema) {
=======
func fetchDevfile(c *gin.Context, devfileName string) []byte {
>>>>>>> 2bb8eb9... Implementation 2 for fetchDevfile chosen and added. See Issue #720 discussion at: https://github.com/devfile/api/issues/720
var index []indexSchema.Schema
bytes, err := ioutil.ReadFile(indexPath)
if err != nil {
Expand All @@ -321,7 +335,11 @@ func fetchDevfile(c *gin.Context, devfileName string) ([]byte, indexSchema.Schem
"error": err.Error(),
"status": fmt.Sprintf("failed to pull the devfile of %s", devfileName),
})
<<<<<<< HEAD
return make([]byte, 0), indexSchema.Schema{}
=======
return make([]byte, 0)
>>>>>>> 2bb8eb9... Implementation 2 for fetchDevfile chosen and added. See Issue #720 discussion at: https://github.com/devfile/api/issues/720
}
err = json.Unmarshal(bytes, &index)
if err != nil {
Expand All @@ -330,7 +348,11 @@ func fetchDevfile(c *gin.Context, devfileName string) ([]byte, indexSchema.Schem
"error": err.Error(),
"status": fmt.Sprintf("failed to pull the devfile of %s", devfileName),
})
<<<<<<< HEAD
return make([]byte, 0), indexSchema.Schema{}
=======
return make([]byte, 0)
>>>>>>> 2bb8eb9... Implementation 2 for fetchDevfile chosen and added. See Issue #720 discussion at: https://github.com/devfile/api/issues/720
}

// Reuse 'bytes' for devfile bytes, assign empty
Expand All @@ -353,18 +375,29 @@ func fetchDevfile(c *gin.Context, devfileName string) ([]byte, indexSchema.Schem
"error": err.Error(),
"status": fmt.Sprintf("failed to pull the devfile of %s", devfileName),
})
<<<<<<< HEAD
return make([]byte, 0), devfileIndex
}

return bytes, devfileIndex
=======
return make([]byte, 0)
}

return bytes
>>>>>>> 2bb8eb9... Implementation 2 for fetchDevfile chosen and added. See Issue #720 discussion at: https://github.com/devfile/api/issues/720
}
}

c.JSON(http.StatusNotFound, gin.H{
"status": fmt.Sprintf("the devfile of %s didn't exist", devfileName),
})

<<<<<<< HEAD
return bytes, indexSchema.Schema{}
=======
return bytes
>>>>>>> 2bb8eb9... Implementation 2 for fetchDevfile chosen and added. See Issue #720 discussion at: https://github.com/devfile/api/issues/720
}

/** source from serveDevfile **/
Expand Down

0 comments on commit 40db91a

Please sign in to comment.