feat: repo health check (#16) #17
|  | @ -64,7 +64,7 @@ func main() { | ||||||
| 	if err != nil { | 	if err != nil { | ||||||
| 
					
					bomingzh marked this conversation as resolved
					
						
						
							Outdated
						
					
				 | |||||||
| 		fmt.Printf("## Forbidden File Check Failed:\n%s\n", err.Error()) | 		fmt.Printf("## Forbidden File Check Failed:\n%s\n", err.Error()) | ||||||
| 	} | 	} | ||||||
| 	err = healthcheck.NonAsciiFiles(*rootDir) | 	err = healthcheck.NonAsciiFiles(*rootDir, *localList) | ||||||
| 	if err != nil { | 	if err != nil { | ||||||
| 		fmt.Printf("## Non-ASCII Characters File Check Failed:\n%s\n", err.Error()) | 		fmt.Printf("## Non-ASCII Characters File Check Failed:\n%s\n", err.Error()) | ||||||
| 	} | 	} | ||||||
|  | @ -81,5 +81,4 @@ func main() { | ||||||
| 	if err != nil { | 	if err != nil { | ||||||
| 		fmt.Printf("## Repo File Check Failed:\n%s\n", err.Error()) | 		fmt.Printf("## Repo File Check Failed:\n%s\n", err.Error()) | ||||||
| 	} | 	} | ||||||
| 
 |  | ||||||
| } | } | ||||||
|  |  | ||||||
|  | @ -12,16 +12,34 @@ import ( | ||||||
| 
 | 
 | ||||||
| // getNonAscii retrieves a list of files in the specified root directory that contain non-ASCII characters.
 | // getNonAscii retrieves a list of files in the specified root directory that contain non-ASCII characters.
 | ||||||
| // It searches for non-ASCII characters in each file's content and returns a list of paths to files containing non-ASCII characters.
 | // It searches for non-ASCII characters in each file's content and returns a list of paths to files containing non-ASCII characters.
 | ||||||
| func getNonAscii(root string) ([]string, error) { | func getNonAscii(root string, localList string) ([]string, error) { | ||||||
| 	var nonAscii []string | 	var nonAscii []string | ||||||
| 
 | 
 | ||||||
|  | 	var dirs []string | ||||||
|  | 
 | ||||||
|  | 	if localList != "" { | ||||||
|  | 		file, err := os.Open(localList) | ||||||
|  | 		if err != nil { | ||||||
|  | 			return nil, fmt.Errorf("Failed to open file %s: %v\n", localList, err) | ||||||
|  | 		} | ||||||
|  | 		defer file.Close() | ||||||
|  | 
 | ||||||
|  | 		scanner := bufio.NewScanner(file) | ||||||
|  | 		for scanner.Scan() { | ||||||
|  | 			dirs = append(dirs, scanner.Text()) | ||||||
|  | 		} | ||||||
|  | 		if err := scanner.Err(); err != nil { | ||||||
|  | 			return nil, fmt.Errorf("Error reading file %s: %v\n", localList, err) | ||||||
|  | 		} | ||||||
|  | 	} | ||||||
|  | 
 | ||||||
| 	err := filepath.Walk(root, func(path string, info os.FileInfo, err error) error { | 	err := filepath.Walk(root, func(path string, info os.FileInfo, err error) error { | ||||||
| 		if err != nil { | 		if err != nil { | ||||||
| 			return err | 			return err | ||||||
| 		} | 		} | ||||||
| 
 | 
 | ||||||
| 		if info.IsDir() { | 		if info.IsDir() { | ||||||
| 			if info.Name() == ".git" || info.Name() == ".gitea" || info.Name() == "ci" { | 			if info.Name() == ".git" || info.Name() == ".gitea" || info.Name() == "ci" || (localList != "" && inString(info.Name(), dirs)) { | ||||||
| 				return filepath.SkipDir | 				return filepath.SkipDir | ||||||
| 			} else { | 			} else { | ||||||
| 				return nil | 				return nil | ||||||
|  | @ -61,8 +79,8 @@ func getNonAscii(root string) ([]string, error) { | ||||||
| 
 | 
 | ||||||
| // nonAsciiFiles checks for non-ASCII characters in files within the specified root directory.
 | // nonAsciiFiles checks for non-ASCII characters in files within the specified root directory.
 | ||||||
| // It prints a message with the paths to files containing non-ASCII characters, if any.
 | // It prints a message with the paths to files containing non-ASCII characters, if any.
 | ||||||
| func NonAsciiFiles(root string) error { | func NonAsciiFiles(root string, localList string) error { | ||||||
| 	nonAscii, err := getNonAscii(root) | 	nonAscii, err := getNonAscii(root, localList) | ||||||
| 	if err != nil { | 	if err != nil { | ||||||
| 		slog.Error("getting non-ascii", "err", err) | 		slog.Error("getting non-ascii", "err", err) | ||||||
| 		return fmt.Errorf("error getting non-ascii: %w", err) | 		return fmt.Errorf("error getting non-ascii: %w", err) | ||||||
|  |  | ||||||
		Loading…
	
		Reference in New Issue
	
	Block a user
	
is it still TODO?
Done yet