diff --git a/dao/user.go b/dao/user.go index 88da718..bce57da 100644 --- a/dao/user.go +++ b/dao/user.go @@ -37,6 +37,12 @@ func FindUserByID(id int) []proto.User { return users } +func FindUserByUserID(id int) User { + var user User + DB.Debug().Where("id = ?", id).First(&user) + return user +} + func FindUserByName(name string) User { var user User fmt.Println("name:", name) diff --git a/handler/cid.go b/handler/cid.go index 168c802..fb74a09 100644 --- a/handler/cid.go +++ b/handler/cid.go @@ -54,6 +54,7 @@ func RunCID(c *gin.Context) { // 获取用户ID id, _ := c.Get("id") authID := int(id.(float64)) + username, _ := c.Get("username") cid := dao.FindCIDByID(req.ID, authID) if cid.ID == 0 { c.JSON(200, gin.H{"error": "CID not found", "code": proto.OperationFailed, "message": "failed"}) @@ -67,7 +68,7 @@ func RunCID(c *gin.Context) { //脚本内容 scriptContent := ` echo "start" -TARGET_DIR=` + proto.CID_BASE_DIR + `workspace/` + name + ` +TARGET_DIR=` + proto.CID_BASE_DIR + username.(string) + `/workspace/` + name + ` //不同用户的持续集成、部署目录不同 if [ ! -d $TARGET_DIR ]; then git clone ` + cid.Url + ` cd $TARGET_DIR @@ -204,9 +205,10 @@ func CIDCallback(c *gin.Context) { name := strs[len(strs)-1] names := strings.Split(name, ".") name = names[0] + user := dao.FindUserByUserID(res.Auth_id) scriptContent := ` echo "start" -TARGET_DIR=` + proto.CID_BASE_DIR + `workspace/` + name + ` +TARGET_DIR=` + proto.CID_BASE_DIR + user.Name + `workspace/` + name + ` if [ ! -d $TARGET_DIR ]; then git clone ` + res.Url + ` cd $TARGET_DIR