|
|
|
@@ -47,6 +47,24 @@ func FileNotebookCreate(ctx *context.Context, option api.CreateFileNotebookJobOp |
|
|
|
return |
|
|
|
} |
|
|
|
|
|
|
|
sourceRepo, err := models.GetRepositoryByOwnerAndName(option.OwnerName, option.ProjectName) |
|
|
|
if err != nil { |
|
|
|
ctx.JSON(http.StatusOK, models.BaseErrorMessageApi(ctx.Tr("repo.notebook_file_not_exist"))) |
|
|
|
return |
|
|
|
} |
|
|
|
|
|
|
|
permission, err := models.GetUserRepoPermission(sourceRepo, ctx.User) |
|
|
|
if err != nil { |
|
|
|
log.Error("Get permission failed", err) |
|
|
|
ctx.JSON(http.StatusOK, models.BaseErrorMessageApi(ctx.Tr("repo.notebook_file_no_right"))) |
|
|
|
return |
|
|
|
} |
|
|
|
|
|
|
|
if !permission.CanRead(models.UnitTypeCode) { |
|
|
|
ctx.JSON(http.StatusOK, models.BaseErrorMessageApi(ctx.Tr("repo.notebook_file_no_right"))) |
|
|
|
return |
|
|
|
} |
|
|
|
|
|
|
|
//create repo if not exist |
|
|
|
repo, err := models.GetRepositoryByName(ctx.User.ID, setting.FileNoteBook.ProjectName) |
|
|
|
if repo == nil { |
|
|
|
@@ -68,14 +86,14 @@ func FileNotebookCreate(ctx *context.Context, option api.CreateFileNotebookJobOp |
|
|
|
return |
|
|
|
} |
|
|
|
if option.Type <= 1 { |
|
|
|
cloudBrainFileNoteBookCreate(ctx, option, repo) |
|
|
|
cloudBrainFileNoteBookCreate(ctx, option, repo, sourceRepo) |
|
|
|
} else { |
|
|
|
modelartsFileNoteBookCreate(ctx, option, repo) |
|
|
|
modelartsFileNoteBookCreate(ctx, option, repo, sourceRepo) |
|
|
|
} |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
func cloudBrainFileNoteBookCreate(ctx *context.Context, option api.CreateFileNotebookJobOption, repo *models.Repository) { |
|
|
|
func cloudBrainFileNoteBookCreate(ctx *context.Context, option api.CreateFileNotebookJobOption, repo *models.Repository, sourceRepo *models.Repository) { |
|
|
|
|
|
|
|
displayJobName := cloudbrainService.GetDisplayJobName(ctx.User.Name) |
|
|
|
jobName := util.ConvertDisplayJobNameToJobName(displayJobName) |
|
|
|
@@ -118,12 +136,6 @@ func cloudBrainFileNoteBookCreate(ctx *context.Context, option api.CreateFileNot |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
sourceRepo, err := models.GetRepositoryByOwnerAndName(option.OwnerName, option.ProjectName) |
|
|
|
if err != nil { |
|
|
|
ctx.JSON(http.StatusOK, models.BaseErrorMessageApi(ctx.Tr("repo.notebook_file_not_exist"))) |
|
|
|
return |
|
|
|
} |
|
|
|
|
|
|
|
errStr := uploadCodeFile(sourceRepo, getCodePath(jobName), option.BranchName, option.File, jobName) |
|
|
|
if errStr != "" { |
|
|
|
ctx.JSON(http.StatusOK, models.BaseErrorMessageApi(ctx.Tr("repo.notebook_file_not_exist"))) |
|
|
|
@@ -199,7 +211,7 @@ func getDescription(option api.CreateFileNotebookJobOption) string { |
|
|
|
return option.OwnerName + "/" + option.ProjectName + "/" + option.File |
|
|
|
} |
|
|
|
|
|
|
|
func modelartsFileNoteBookCreate(ctx *context.Context, option api.CreateFileNotebookJobOption, repo *models.Repository) { |
|
|
|
func modelartsFileNoteBookCreate(ctx *context.Context, option api.CreateFileNotebookJobOption, repo *models.Repository, sourceRepo *models.Repository) { |
|
|
|
displayJobName := cloudbrainService.GetDisplayJobName(ctx.User.Name) |
|
|
|
jobName := util.ConvertDisplayJobNameToJobName(displayJobName) |
|
|
|
|
|
|
|
@@ -242,12 +254,6 @@ func modelartsFileNoteBookCreate(ctx *context.Context, option api.CreateFileNote |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
sourceRepo, err := models.GetRepositoryByOwnerAndName(option.OwnerName, option.ProjectName) |
|
|
|
if err != nil { |
|
|
|
ctx.JSON(http.StatusOK, models.BaseErrorMessageApi(ctx.Tr("repo.notebook_file_not_exist"))) |
|
|
|
return |
|
|
|
} |
|
|
|
|
|
|
|
err = downloadCode(sourceRepo, getCodePath(jobName), option.BranchName) |
|
|
|
if err != nil { |
|
|
|
ctx.JSON(http.StatusOK, models.BaseErrorMessageApi(ctx.Tr("cloudbrain.load_code_failed"))) |
|
|
|
|