This repository has been archived by the owner on Jan 16, 2023. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
/
handlers_artifact.go
59 lines (55 loc) · 1.5 KB
/
handlers_artifact.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
package src
import (
"net/http"
"strconv"
"github.com/gin-gonic/gin"
"github.com/revan730/clipper-api/types"
"google.golang.org/grpc/status"
)
func (s *Server) getBuildArtifactHandler(c *gin.Context) {
buildIDStr := c.Param("id")
buildID, err := strconv.Atoi(buildIDStr)
if err != nil {
c.JSON(http.StatusBadRequest, gin.H{"err": "build id is not int"})
return
}
artifact, err := s.ciClient.GetBuildArtifact(int64(buildID))
if err != nil {
statusErr, ok := status.FromError(err)
if ok == true {
if statusErr.Code() == http.StatusNotFound {
c.JSON(http.StatusNotFound, gin.H{"err": "build artifact not found"})
return
}
}
s.log.Error("Find build artifact error", err)
c.Writer.WriteHeader(http.StatusInternalServerError)
return
}
c.JSON(http.StatusOK, artifact)
}
func (s *Server) getAllArtifactsHandler(c *gin.Context) {
repoIDStr := c.Param("id")
repoID, err := strconv.Atoi(repoIDStr)
if err != nil {
c.JSON(http.StatusBadRequest, gin.H{"err": "repo id is not int"})
return
}
params := &types.BuildsQueryParams{
Branch: "master",
Page: 1,
Limit: 20,
}
err = c.ShouldBind(params)
if err != nil {
c.JSON(http.StatusBadRequest, gin.H{"err": err.Error()})
}
artifacts, err := s.ciClient.GetAllArtifacts(int64(repoID), *params)
if err != nil {
s.log.Error("Find artifacts error", err)
c.Writer.WriteHeader(http.StatusInternalServerError)
return
}
artifactArrayMsg := types.ArtifactArrayMsgFromProto(artifacts)
c.JSON(http.StatusOK, artifactArrayMsg)
}