add github
This commit is contained in:
@@ -440,7 +440,7 @@ func PublishExamSubmissionsGitHandler(db *gorm.DB) fiber.Handler {
|
||||
return c.Status(500).JSON(fiber.Map{"error": err.Error(), "warnings": unpackWarn})
|
||||
}
|
||||
|
||||
owner, repo, branch, repoHTML, err := resolvePublishRepo(token, ghLogin, &room)
|
||||
_, repo, branch, repoHTML, err := resolvePublishRepo(db, staffID, token, ghLogin, &room)
|
||||
if err != nil {
|
||||
return c.Status(502).JSON(fiber.Map{"error": err.Error()})
|
||||
}
|
||||
@@ -448,9 +448,10 @@ func PublishExamSubmissionsGitHandler(db *gorm.DB) fiber.Handler {
|
||||
room.GitRepoURL = repoHTML
|
||||
room.GitBranch = branch
|
||||
}
|
||||
pushOwner, pushRepo := resolveGitPushTarget(token, ghLogin, repo, repoHTML)
|
||||
|
||||
commitMsg := fmt.Sprintf("Simple Care: bài nộp phòng thi %s (#%d)", room.Name, roomID)
|
||||
viewURL, pushWarn, err := githubPushFiles(token, owner, repo, branch, files, commitMsg)
|
||||
viewURL, pushWarn, err := githubPushFiles(token, pushOwner, pushRepo, branch, files, commitMsg)
|
||||
allWarn := append(unpackWarn, pushWarn...)
|
||||
if err != nil {
|
||||
return c.Status(502).JSON(fiber.Map{
|
||||
@@ -462,7 +463,7 @@ func PublishExamSubmissionsGitHandler(db *gorm.DB) fiber.Handler {
|
||||
room.GitPublishURL = viewURL
|
||||
_ = db.Save(&room).Error
|
||||
roomIDCopy := roomID
|
||||
recordStaffGitHubRepo(db, staffID, owner, repo, repoHTML, models.GitPublishModeRoom, room.Name, &roomIDCopy, nil)
|
||||
recordStaffGitHubRepo(db, staffID, pushOwner, pushRepo, repoHTML, models.GitPublishModeRoom, room.Name, &roomIDCopy, nil)
|
||||
|
||||
msg := fmt.Sprintf("Đã đẩy %d bài lên GitHub — mỗi sinh viên một folder.", len(rows))
|
||||
if len(allWarn) > 0 {
|
||||
@@ -517,7 +518,6 @@ func PublishExamSubmissionsGitPerStudentHandler(db *gorm.DB) fiber.Handler {
|
||||
return c.Status(400).JSON(fiber.Map{"error": "Chưa có bài nộp"})
|
||||
}
|
||||
|
||||
branch := "main"
|
||||
published := 0
|
||||
var allWarn []string
|
||||
var repoURLs []string
|
||||
@@ -536,14 +536,19 @@ func PublishExamSubmissionsGitPerStudentHandler(db *gorm.DB) fiber.Handler {
|
||||
allWarn = append(allWarn, fmt.Sprintf("%s: không có file để đẩy", studentSubmissionFolder(row.StudentCode, row.FullName)))
|
||||
continue
|
||||
}
|
||||
repoName, repoHTML, err := githubEnsureRepoForStudent(token, ghLogin, &room, &row)
|
||||
repoName, repoHTML, err := githubEnsureRepoForStudent(db, staffID, token, ghLogin, &room, &row)
|
||||
if err != nil {
|
||||
allWarn = append(allWarn, row.StudentCode+": "+err.Error())
|
||||
continue
|
||||
}
|
||||
pushOwner, pushRepo := resolveGitPushTarget(token, ghLogin, repoName, repoHTML)
|
||||
branch := "main"
|
||||
if meta, ok := githubFetchRepo(token, pushOwner, pushRepo); ok && meta.DefaultBranch != "" {
|
||||
branch = meta.DefaultBranch
|
||||
}
|
||||
label := studentSubmissionFolder(row.StudentCode, row.FullName)
|
||||
commitMsg := fmt.Sprintf("Simple Care: bài nộp %s — %s", label, room.Name)
|
||||
viewURL, pushWarn, err := githubPushFiles(token, ghLogin, repoName, branch, files, commitMsg)
|
||||
viewURL, pushWarn, err := githubPushFiles(token, pushOwner, pushRepo, branch, files, commitMsg)
|
||||
allWarn = append(allWarn, pushWarn...)
|
||||
if err != nil {
|
||||
allWarn = append(allWarn, label+": "+err.Error())
|
||||
@@ -553,7 +558,7 @@ func PublishExamSubmissionsGitPerStudentHandler(db *gorm.DB) fiber.Handler {
|
||||
Updates(map[string]any{"git_repo_url": repoHTML, "git_publish_url": viewURL}).Error
|
||||
subID := row.ID
|
||||
roomIDCopy := roomID
|
||||
recordStaffGitHubRepo(db, staffID, ghLogin, repoName, repoHTML, models.GitPublishModeStudent, label, &roomIDCopy, &subID)
|
||||
recordStaffGitHubRepo(db, staffID, pushOwner, pushRepo, repoHTML, models.GitPublishModeStudent, label, &roomIDCopy, &subID)
|
||||
published++
|
||||
repoURLs = append(repoURLs, viewURL)
|
||||
studentRepos = append(studentRepos, studentRepo{
|
||||
|
||||
Reference in New Issue
Block a user