获取单个工作区的信息
(workingMode workspace.WorkingModeEnum, workingDir string, gitCloneUrl string, branch string, confingFilePath string, remoteId int, remoteHost string, remoteUserName string)
| 221 | |
| 222 | // 获取单个工作区的信息 |
| 223 | func GetSingleWorkspaceByParams(workingMode workspace.WorkingModeEnum, |
| 224 | workingDir string, |
| 225 | gitCloneUrl string, branch string, confingFilePath string, |
| 226 | remoteId int, remoteHost string, remoteUserName string) (workspaceInfo workspace.WorkspaceInfo, err error) { |
| 227 | db := getDb() |
| 228 | defer db.Close() |
| 229 | |
| 230 | // 查询参数 |
| 231 | params := workspaceDo{} |
| 232 | params.w_mode = string(workingMode) |
| 233 | |
| 234 | if remoteId <= 0 { |
| 235 | remoteInfo, err := getRemote(remoteId, remoteHost, remoteUserName) |
| 236 | common.CheckError(err) |
| 237 | if remoteInfo != nil && remoteInfo.ID > 0 { |
| 238 | params.r_id = sql.NullInt32{Int32: int32(remoteInfo.ID), Valid: true} |
| 239 | } |
| 240 | } else { |
| 241 | params.r_id = sql.NullInt32{Int32: int32(remoteId), Valid: true} |
| 242 | } |
| 243 | |
| 244 | // sql |
| 245 | var row *sql.Row |
| 246 | whereStr := " and w_mode=? " |
| 247 | args := []interface{}{workingMode} |
| 248 | if workingMode == workspace.WorkingMode_Remote { |
| 249 | whereStr += " and r_id = ?" |
| 250 | args = append(args, params.r_id) |
| 251 | } |
| 252 | if workingDir != "" { // 远程主机模式时,工作目录是不确定的 |
| 253 | params.w_workingdir = sql.NullString{String: workingDir, Valid: true} |
| 254 | whereStr += " and w_workingdir = ?" |
| 255 | args = append(args, params.w_workingdir) |
| 256 | } |
| 257 | if gitCloneUrl != "" { |
| 258 | params.w_git_clone_repo_url = sql.NullString{String: gitCloneUrl, Valid: true} |
| 259 | whereStr += " and w_git_clone_repo_url = ?" |
| 260 | args = append(args, params.w_git_clone_repo_url) |
| 261 | } |
| 262 | if branch != "" { |
| 263 | params.w_branch = branch |
| 264 | whereStr += " and w_branch = ?" |
| 265 | args = append(args, params.w_branch) |
| 266 | } |
| 267 | if confingFilePath != "" { |
| 268 | params.w_config_file = sql.NullString{String: confingFilePath, Valid: true} |
| 269 | whereStr += " and w_config_file = ?" |
| 270 | args = append(args, params.w_config_file) |
| 271 | } |
| 272 | row = db.QueryRow(`select w_id, w_name, w_workingdir, w_docker_compose_file_path, w_mode, w_config_file, |
| 273 | w_git_clone_repo_url, w_git_auth_type, w_git_username, w_git_password, w_branch, |
| 274 | r_id, k_id, w_is_del, |
| 275 | w_json, w_config_content, w_link_compose_content, w_temp_compose_content, |
| 276 | w_created |
| 277 | from workspace |
| 278 | where w_is_del = 0 `+whereStr, args...) |
| 279 | |
| 280 | // 赋值 |
nothing calls this directly
no test coverage detected