parent
							
								
									6c8332af29
								
							
						
					
					
						commit
						7b3edb2361
					
				|  | @ -1,16 +1,12 @@ | ||||||
| package stage | package stage | ||||||
| 
 | 
 | ||||||
| import ( | import "github.com/mitchellh/mapstructure" | ||||||
| 	"fmt" |  | ||||||
| 
 |  | ||||||
| 	"github.com/mitchellh/mapstructure" |  | ||||||
| ) |  | ||||||
| 
 | 
 | ||||||
| func DecodeConf[T any](confAny any) (*T, error) { | func DecodeConf[T any](confAny any) (*T, error) { | ||||||
| 	var conf T | 	var conf T | ||||||
| 	err := mapstructure.Decode(confAny, &conf) | 	err := mapstructure.Decode(confAny, &conf) | ||||||
| 	if err != nil { | 	if err != nil { | ||||||
| 		return nil, fmt.Errorf("failed to decode conf: %w", err) | 		return nil, err | ||||||
| 	} | 	} | ||||||
| 	return &conf, nil | 	return &conf, nil | ||||||
| } | } | ||||||
|  |  | ||||||
|  | @ -72,7 +72,7 @@ func NonAsciiMsg(root string) error { | ||||||
| 	} | 	} | ||||||
| 
 | 
 | ||||||
| 	if !isCommitLegal { | 	if !isCommitLegal { | ||||||
| 		return fmt.Errorf("non-ASCII characters in commit messages:\n%s", msg) | 		return fmt.Errorf("Non-ASCII characters in commit messages:\n%s", msg) | ||||||
| 	} | 	} | ||||||
| 	return nil | 	return nil | ||||||
| } | } | ||||||
|  |  | ||||||
|  | @ -26,7 +26,7 @@ func getForbiddens(root string, fileList []string, localList string) ([]string, | ||||||
| 	if localList != "" { | 	if localList != "" { | ||||||
| 		file, err := os.Open(localList) | 		file, err := os.Open(localList) | ||||||
| 		if err != nil { | 		if err != nil { | ||||||
| 			return nil, fmt.Errorf("failed to open file %s: %v\n", localList, err) | 			return nil, fmt.Errorf("Failed to open file %s: %v\n", localList, err) | ||||||
| 		} | 		} | ||||||
| 		defer file.Close() | 		defer file.Close() | ||||||
| 
 | 
 | ||||||
|  | @ -35,7 +35,7 @@ func getForbiddens(root string, fileList []string, localList string) ([]string, | ||||||
| 			dirs = append(dirs, scanner.Text()) | 			dirs = append(dirs, scanner.Text()) | ||||||
| 		} | 		} | ||||||
| 		if err := scanner.Err(); err != nil { | 		if err := scanner.Err(); err != nil { | ||||||
| 			return nil, fmt.Errorf("error reading file %s: %v\n", localList, err) | 			return nil, fmt.Errorf("Error reading file %s: %v\n", localList, err) | ||||||
| 		} | 		} | ||||||
| 	} | 	} | ||||||
| 
 | 
 | ||||||
|  | @ -78,7 +78,7 @@ func ForbiddenCheck(rootDir string, regexList []string, localList string, repo s | ||||||
| 	} | 	} | ||||||
| 
 | 
 | ||||||
| 	if len(forbids) > 0 { | 	if len(forbids) > 0 { | ||||||
| 		return fmt.Errorf("the following forbidden files were found: %s\n\nTo fix it, first make a backup of your repository and then run the following commands:\nfor i in %s%s", | 		return fmt.Errorf("The following forbidden files were found: %s\n\nTo fix it, first make a backup of your repository and then run the following commands:\nfor i in %s%s", | ||||||
| 			strings.Join(forbids, ", "), | 			strings.Join(forbids, ", "), | ||||||
| 			strings.Join(forbids, " "), | 			strings.Join(forbids, " "), | ||||||
| 			fmt.Sprint( | 			fmt.Sprint( | ||||||
|  |  | ||||||
|  | @ -20,7 +20,7 @@ func getNonAscii(root string, localList string) ([]string, error) { | ||||||
| 	if localList != "" { | 	if localList != "" { | ||||||
| 		file, err := os.Open(localList) | 		file, err := os.Open(localList) | ||||||
| 		if err != nil { | 		if err != nil { | ||||||
| 			return nil, fmt.Errorf("failed to open file %s: %v\n", localList, err) | 			return nil, fmt.Errorf("Failed to open file %s: %v\n", localList, err) | ||||||
| 		} | 		} | ||||||
| 		defer file.Close() | 		defer file.Close() | ||||||
| 
 | 
 | ||||||
|  | @ -29,7 +29,7 @@ func getNonAscii(root string, localList string) ([]string, error) { | ||||||
| 			dirs = append(dirs, scanner.Text()) | 			dirs = append(dirs, scanner.Text()) | ||||||
| 		} | 		} | ||||||
| 		if err := scanner.Err(); err != nil { | 		if err := scanner.Err(); err != nil { | ||||||
| 			return nil, fmt.Errorf("error reading file %s: %v\n", localList, err) | 			return nil, fmt.Errorf("Error reading file %s: %v\n", localList, err) | ||||||
| 		} | 		} | ||||||
| 	} | 	} | ||||||
| 
 | 
 | ||||||
|  | @ -86,7 +86,7 @@ func NonAsciiFiles(root string, localList string) error { | ||||||
| 		return fmt.Errorf("error getting non-ascii: %w", err) | 		return fmt.Errorf("error getting non-ascii: %w", err) | ||||||
| 	} | 	} | ||||||
| 	if len(nonAscii) > 0 { | 	if len(nonAscii) > 0 { | ||||||
| 		return fmt.Errorf("non-ASCII characters found in the following files:\n%s", | 		return fmt.Errorf("Non-ASCII characters found in the following files:\n%s", | ||||||
| 			strings.Join(nonAscii, "\n")) | 			strings.Join(nonAscii, "\n")) | ||||||
| 	} | 	} | ||||||
| 	return nil | 	return nil | ||||||
|  |  | ||||||
|  | @ -34,7 +34,7 @@ func RepoSize() error { | ||||||
| 		} | 		} | ||||||
| 	} | 	} | ||||||
| 	if sum > 2048 { | 	if sum > 2048 { | ||||||
| 		return fmt.Errorf("repository larger than 2MB. Please clean up or contact the teaching team.") | 		return fmt.Errorf("Repository larger than 2MB. Please clean up or contact the teaching team.") | ||||||
| 	} | 	} | ||||||
| 	return nil | 	return nil | ||||||
| } | } | ||||||
|  |  | ||||||
|  | @ -56,7 +56,7 @@ func CheckTags(repoPath string, category string, n int) error { | ||||||
| 		} | 		} | ||||||
| 	} | 	} | ||||||
| 	if !found { | 	if !found { | ||||||
| 		return fmt.Errorf("wrong release tag '%s' or missing release tags. Please use one of '%s'.", target, strings.Join(tags, "', '")) | 		return fmt.Errorf("Wrong release tag '%s' or missing release tags. Please use one of '%s'.", target, strings.Join(tags, "', '")) | ||||||
| 	} | 	} | ||||||
| 	return nil | 	return nil | ||||||
| } | } | ||||||
|  |  | ||||||
|  | @ -29,7 +29,7 @@ func getRegex(fileList []string) ([]*regexp.Regexp, error) { | ||||||
| 	for _, pattern := range fileList { | 	for _, pattern := range fileList { | ||||||
| 		regex, err := regexp.Compile("(?i)" + pattern) | 		regex, err := regexp.Compile("(?i)" + pattern) | ||||||
| 		if err != nil { | 		if err != nil { | ||||||
| 			return nil, fmt.Errorf("error compiling regex: %w", err) | 			return nil, fmt.Errorf("Error compiling regex:%w", err) | ||||||
| 		} | 		} | ||||||
| 		regexList = append(regexList, regex) | 		regexList = append(regexList, regex) | ||||||
| 	} | 	} | ||||||
|  |  | ||||||
|  | @ -33,10 +33,10 @@ func checkFileChecksum(rootDir, fileName, expectedChecksum string) error { | ||||||
| 	filePath := filepath.Join(rootDir, strings.TrimSpace(fileName)) | 	filePath := filepath.Join(rootDir, strings.TrimSpace(fileName)) | ||||||
| 	actualChecksum, err := getChecksum(filePath) | 	actualChecksum, err := getChecksum(filePath) | ||||||
| 	if err != nil { | 	if err != nil { | ||||||
| 		return fmt.Errorf("error reading file %s: %v", filePath, err) | 		return fmt.Errorf("Error reading file %s: %v", filePath, err) | ||||||
| 	} | 	} | ||||||
| 	if actualChecksum != expectedChecksum { | 	if actualChecksum != expectedChecksum { | ||||||
| 		return fmt.Errorf("checksum for %s failed. Expected %s, but got %s. Please revert your changes or contact the teaching team if you have a valid reason for adjusting them.", filePath, expectedChecksum, actualChecksum) | 		return fmt.Errorf("Checksum for %s failed. Expected %s, but got %s. Please revert your changes or contact the teaching team if you have a valid reason for adjusting them.", filePath, expectedChecksum, actualChecksum) | ||||||
| 	} | 	} | ||||||
| 	return nil | 	return nil | ||||||
| } | } | ||||||
|  | @ -49,7 +49,7 @@ func VerifyFiles(rootDir string, checkFileNameList string, checkFileSumList stri | ||||||
| 	checkSums := strings.Split(checkFileSumList, ",") | 	checkSums := strings.Split(checkFileSumList, ",") | ||||||
| 	// Check if the number of files matches the number of checksums
 | 	// Check if the number of files matches the number of checksums
 | ||||||
| 	if len(fileNames) != len(checkSums) { | 	if len(fileNames) != len(checkSums) { | ||||||
| 		return fmt.Errorf("the number of files and checksums do not match") | 		return fmt.Errorf("Error: The number of files and checksums do not match.") | ||||||
| 	} | 	} | ||||||
| 	// Check each file's checksum
 | 	// Check each file's checksum
 | ||||||
| 	for i, fileName := range fileNames { | 	for i, fileName := range fileNames { | ||||||
|  |  | ||||||
		Loading…
	
		Reference in New Issue
	
	Block a user