Skip to content

Commit

Permalink
fix match branches list api (#3984)
Browse files Browse the repository at this point in the history
Signed-off-by: Patrick Zhao <zhaoyu@koderover.com>
  • Loading branch information
PetrusZ authored Feb 7, 2025
1 parent a702470 commit cf594da
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 19 deletions.
34 changes: 16 additions & 18 deletions pkg/microservice/aslan/core/code/handler/codehost.go
Original file line number Diff line number Diff line change
Expand Up @@ -272,40 +272,38 @@ func ListRepoInfos(c *gin.Context) {
ctx.Resp, ctx.RespErr = service.ListRepoInfos(args.Infos, ctx.Logger)
}

type MatchBranchesListRequest struct {
RepoOwner string `json:"repo_owner"`
RepoName string `json:"repo_name"` // pro Name, id/name -> gitlab = id
Regular string `json:"regular"`
}

func MatchBranchesList(c *gin.Context) {
ctx := internalhandler.NewContext(c)
defer func() { internalhandler.JSONResponse(c, ctx) }()

codehostID := c.Param("codehostId")
repoOwner := c.Query("repoOwner")
repoName := c.Query("repoName") // pro Name, id/name -> gitlab = id
regular := c.Query("regular")

if codehostID == "" {
ctx.RespErr = e.ErrInvalidParam.AddDesc("empty codehostId")
return
}
if repoOwner == "" {
ctx.RespErr = e.ErrInvalidParam.AddDesc("empty repoOwner")
return
}
if repoName == "" {
ctx.RespErr = e.ErrInvalidParam.AddDesc("empty repoName")
req := new(MatchBranchesListRequest)
err := c.BindJSON(req)
if err != nil {
ctx.RespErr = e.ErrInvalidParam.AddDesc("invalid request")
return
}
if regular == "" {
ctx.RespErr = e.ErrInvalidParam.AddDesc("empty regular")

if codehostID == "" {
ctx.RespErr = e.ErrInvalidParam.AddDesc("empty codehostId")
return
}

chID, _ := strconv.Atoi(codehostID)
ctx.Resp, ctx.RespErr = service.MatchBranchesList(
chID,
repoName,
strings.Replace(repoOwner, "%2F", "/", -1),
req.RepoName,
strings.Replace(req.RepoOwner, "%2F", "/", -1),
"",
1,
500,
regular,
req.Regular,
ctx.Logger)
}
2 changes: 1 addition & 1 deletion pkg/microservice/aslan/core/code/handler/router.go
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ func (*Router) Inject(router *gin.RouterGroup) {
codehost.GET("/:codehostId/prs", CodeHostGetPRList)
codehost.GET("/:codehostId/commits", CodeHostGetCommits)
codehost.PUT("/infos", ListRepoInfos)
codehost.GET("/:codehostId/branches/regular/check", MatchBranchesList)
codehost.POST("/:codehostId/branches/regular/check", MatchBranchesList)
}

// ---------------------------------------------------------------------------------------
Expand Down

0 comments on commit cf594da

Please sign in to comment.