feat: repo health check (#16) #17
|
@ -77,8 +77,10 @@ func main() {
|
||||||
fmt.Printf("## Release Tag Check Failed:\n%s\n", err.Error())
|
fmt.Printf("## Release Tag Check Failed:\n%s\n", err.Error())
|
||||||
}
|
}
|
||||||
// FIXME: for drone usage
|
// FIXME: for drone usage
|
||||||
|
if adminDir != nil && *adminDir != "" {
|
||||||
zzjc123 marked this conversation as resolved
Outdated
|
|||||||
err = healthcheck.VerifyDirectory(*rootDir, *adminDir)
|
err = healthcheck.VerifyDirectory(*rootDir, *adminDir)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
fmt.Printf("## Directory File Check Failed:\n%s\n", err.Error())
|
fmt.Printf("## Directory File Check Failed:\n%s\n", err.Error())
|
||||||
}
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -6,6 +6,7 @@ import (
|
||||||
"os"
|
"os"
|
||||||
"path/filepath"
|
"path/filepath"
|
||||||
"regexp"
|
"regexp"
|
||||||
|
"strings"
|
||||||
)
|
)
|
||||||
|
|
||||||
// getForbiddens retrieves a list of forbidden files in the specified root directory.
|
// getForbiddens retrieves a list of forbidden files in the specified root directory.
|
||||||
|
@ -61,15 +62,12 @@ func ForbiddenCheck(rootDir string, regexList []string, repo string, droneBranch
|
||||||
var message string
|
var message string
|
||||||
|
|
||||||
if len(forbids) > 0 {
|
if len(forbids) > 0 {
|
||||||
message += fmt.Sprint(103, "the following forbidden files were found: ")
|
message = "The following forbidden files were found: " +
|
||||||
for _, file := range forbids {
|
strings.Join(forbids, ", ") +
|
||||||
message += fmt.Sprint(file, ", ")
|
"\n\nTo fix it, first make a backup of your repository and then run the following commands:\nfor i in " +
|
||||||
}
|
strings.Join(forbids, " ") +
|
||||||
message += "\n\nTo fix it, first make a backup of your repository and then run the following commands:\nfor i in "
|
fmt.Sprint("; do git filter-repo --force --invert-paths --path \\\"\\$i\\\"; done\ngit remote add origin ",
|
||||||
for _, file := range forbids {
|
repo, "\ngit push --set-upstream origin ", droneBranch, " --force")
|
||||||
message += fmt.Sprint(file, " ")
|
|
||||||
}
|
|
||||||
message += fmt.Sprint("; do git filter-repo --force --invert-paths --path \\\"\\$i\\\"; done\ngit remote add origin ", repo, "\ngit push --set-upstream origin ", droneBranch, " --force")
|
|
||||||
return fmt.Errorf(message)
|
return fmt.Errorf(message)
|
||||||
}
|
}
|
||||||
return nil
|
return nil
|
||||||
|
|
|
@ -2,19 +2,12 @@ package healthcheck
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"fmt"
|
"fmt"
|
||||||
|
"strings"
|
||||||
|
|
||||||
"github.com/go-git/go-git/v5"
|
"github.com/go-git/go-git/v5"
|
||||||
"github.com/go-git/go-git/v5/plumbing"
|
"github.com/go-git/go-git/v5/plumbing"
|
||||||
)
|
)
|
||||||
|
|
||||||
func catTags(all []string) (out string) {
|
|
||||||
out = ""
|
|
||||||
for _, str := range all {
|
|
||||||
out += str + " "
|
|
||||||
}
|
|
||||||
return out
|
|
||||||
}
|
|
||||||
|
|
||||||
func getTagsFromRepo(repoPath string) ([]string, error) {
|
func getTagsFromRepo(repoPath string) ([]string, error) {
|
||||||
repo, err := git.PlainOpen(repoPath)
|
repo, err := git.PlainOpen(repoPath)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
|
@ -63,8 +56,7 @@ func CheckReleases(repoPath string, category string, n int) error {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if !found {
|
if !found {
|
||||||
tagList := catTags(tags)
|
return fmt.Errorf("Wrong release tag '%s'. Please use one of '%s'.", target, strings.Join(tags, "', '"))
|
||||||
张泊明518370910136
commented
Why is the Why is the `target` release tag wrong?
汪睿522370910169
commented
I intended to mean release tag is missing or wrong. I intended to mean release tag is missing or wrong.
汪睿522370910169
commented
Do we need to specify missing or wrong? I think only we need to inform students that their release is wrong. Do we need to specify missing or wrong? I think only we need to inform students that their release is wrong.
张泊明518370910136
commented
Do we need to test if they submit extra tags? Do we need to test if they submit extra tags?
汪睿522370910169
commented
I think extra is fine, as long as they don't miss any tags. I think extra is fine, as long as they don't miss any tags.
张泊明518370910136
commented
Then just print the error on missing tags. Then just print the error on missing tags.
|
|||||||
return fmt.Errorf("Wrong release tag '%s'. Please use one of %s.", target, tagList)
|
|
||||||
}
|
}
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
|
@ -57,14 +57,16 @@ func VerifyDirectory(rootDir, compareDir string) error {
|
||||||
relPath, _ := filepath.Rel(rootDir, path)
|
relPath, _ := filepath.Rel(rootDir, path)
|
||||||
file2 := filepath.Join(compareDir, relPath)
|
file2 := filepath.Join(compareDir, relPath)
|
||||||
if !fileExists(file2) {
|
if !fileExists(file2) {
|
||||||
return fmt.Errorf("File %s in %s is missing in %s. Please immediately revert your changes!\n", relPath, rootDir, compareDir)
|
return fmt.Errorf("File %s is missing. Please immediately revert your changes!\n",
|
||||||
|
filepath.Join(rootDir, relPath))
|
||||||
}
|
}
|
||||||
match, err := filesMatch(path, file2)
|
match, err := filesMatch(path, file2)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
张泊明518370910136
commented
remove it remove it
张泊明518370910136
commented
I mean remove the I mean remove the `os.Exit(1)`, and also the one on line 55.
|
|||||||
return fmt.Errorf("error matching files: %w", err)
|
return fmt.Errorf("error matching files: %w", err)
|
||||||
}
|
}
|
||||||
if !match {
|
if !match {
|
||||||
return fmt.Errorf("File %s in %s is not identical to %s. Please revert your changes or contact the teaching team if you have a valid reason for adjusting them.\n", relPath, rootDir, compareDir)
|
return fmt.Errorf("File %s is altered. Please revert your changes or contact the teaching team if you have a valid reason for adjusting them.\n",
|
||||||
|
filepath.Join(rootDir, relPath))
|
||||||
张泊明518370910136
commented
why not just return error on not all passed? why not just return error on not all passed?
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
return nil
|
return nil
|
||||||
|
|
Loading…
Reference in New Issue
Block a user
what should be fixed?
I think it is due to we can only test it when it is deployed on drone so I just skip it when running the code. If not I couldn't push the code.
I think checking an empty value for skipping it is enough. No dir specified = no verify.