- repo size - forbidden files - meta files - ascii character in files - integrity check - ascii character in the commit message - release tag check Co-authored-by: Boming Zhang <bomingzh@sjtu.edu.cn> Co-authored-by: zzjc1234 <2359047351@qq.com> Co-authored-by: Hydraallen <wangruiallen@gmail.com> Reviewed-on: FOCS-dev/JOJ3#17 Co-authored-by: 周赵嘉程521432910016 <zzjc123@sjtu.edu.cn> Co-committed-by: 周赵嘉程521432910016 <zzjc123@sjtu.edu.cn>
41 lines
1.1 KiB
Go
41 lines
1.1 KiB
Go
package healthcheck
|
|
|
|
import (
|
|
"fmt"
|
|
"log/slog"
|
|
"os/exec"
|
|
"strconv"
|
|
"strings"
|
|
)
|
|
|
|
// RepoSize checks the size of the repository to determine if it is oversized.
|
|
// It executes the 'git count-objects -v' command to obtain the size information,
|
|
func RepoSize() error {
|
|
// TODO: reimplement here when go-git is available
|
|
// https://github.com/go-git/go-git/blob/master/COMPATIBILITY.md
|
|
cmd := exec.Command("git", "count-objects", "-v")
|
|
output, err := cmd.CombinedOutput()
|
|
if err != nil {
|
|
slog.Error("running git command:", "err", err)
|
|
return fmt.Errorf("error running git command: %w", err)
|
|
}
|
|
lines := strings.Split(string(output), "\n")
|
|
var sum int
|
|
for _, line := range lines {
|
|
if strings.Contains(line, "size") {
|
|
fields := strings.Fields(line)
|
|
sizeStr := fields[1]
|
|
size, err := strconv.Atoi(sizeStr)
|
|
if err != nil {
|
|
slog.Error("running git command:", "err", err)
|
|
return fmt.Errorf("error running git command: %w", err)
|
|
}
|
|
sum += size
|
|
}
|
|
}
|
|
if sum > 2048 {
|
|
return fmt.Errorf("Repository larger than 2MB. Please clean up or contact the teaching team.")
|
|
}
|
|
return nil
|
|
}
|