From f3804fcd2d6360ce5759615410c82e0eeae6e6cd Mon Sep 17 00:00:00 2001 From: Luke Hagar Date: Thu, 11 Sep 2025 21:02:14 +0000 Subject: [PATCH] Add respect_gitignore input to action.yml and update related logic in entrypoint.sh, check.go, and fsurls.go to support .gitignore handling during URL collection. --- action.yml | 5 +++++ cmd/check.go | 12 +++++++----- entrypoint.sh | 6 ++++++ internal/fsurls/fsurls.go | 6 +++--- 4 files changed, 21 insertions(+), 8 deletions(-) diff --git a/action.yml b/action.yml index b4a9315..344ebe2 100644 --- a/action.yml +++ b/action.yml @@ -22,6 +22,10 @@ inputs: description: "HTTP timeout seconds" required: false default: "10" + respect_gitignore: + description: "Respect .gitignore while scanning" + required: false + default: "true" json_out: description: "Optional path to write JSON results" required: false @@ -56,6 +60,7 @@ runs: INPUT_PATTERNS: ${{ inputs.patterns }} INPUT_CONCURRENCY: ${{ inputs.concurrency }} INPUT_TIMEOUT: ${{ inputs.timeout }} + INPUT_RESPECT_GITIGNORE: ${{ inputs.respect_gitignore }} INPUT_JSON_OUT: ${{ inputs.json_out }} INPUT_MD_OUT: ${{ inputs.md_out }} INPUT_REPO_BLOB_BASE: ${{ inputs.repo_blob_base }} diff --git a/cmd/check.go b/cmd/check.go index 93292ac..35a3989 100644 --- a/cmd/check.go +++ b/cmd/check.go @@ -51,7 +51,7 @@ func init() { cfg := web.Config{MaxConcurrency: maxConcurrency, RequestTimeout: timeout} // Collect URLs - urlToFiles, err := fsurls.CollectURLs(path, gl) + urlToFiles, err := fsurls.CollectURLs(path, gl, respectGitignore) if err != nil { return err } @@ -157,13 +157,15 @@ func init() { checkCmd.Flags().StringVar(&repoBlobBase, "repo-blob-base", "", "override GitHub blob base URL (e.g. https://github.com/owner/repo/blob/)") checkCmd.Flags().IntVar(&timeoutSeconds, "timeout", 10, "HTTP request timeout in seconds") checkCmd.Flags().BoolVar(&failOnFailures, "fail-on-failures", true, "exit non-zero if any links fail") + checkCmd.Flags().BoolVar(&respectGitignore, "respect-gitignore", true, "respect .gitignore while scanning (default true)") rootCmd.AddCommand(checkCmd) } var ( - timeoutSeconds int - failOnFailures bool - patterns []string - repoBlobBase string + timeoutSeconds int + failOnFailures bool + patterns []string + repoBlobBase string + respectGitignore bool ) diff --git a/entrypoint.sh b/entrypoint.sh index 4c0cbba..224ff16 100644 --- a/entrypoint.sh +++ b/entrypoint.sh @@ -5,6 +5,7 @@ PATH_ARG="${INPUT_PATH:-.}" PATTERNS_ARG="${INPUT_PATTERNS:-**/*}" CONCURRENCY_ARG="${INPUT_CONCURRENCY:-16}" TIMEOUT_ARG="${INPUT_TIMEOUT:-10}" +RESPECT_GITIGNORE_ARG="${INPUT_RESPECT_GITIGNORE:-true}" JSON_OUT_ARG="${INPUT_JSON_OUT:-results.json}" MD_OUT_ARG="${INPUT_MD_OUT:-results.md}" REPO_BLOB_BASE_ARG="${INPUT_REPO_BLOB_BASE:-}" @@ -35,6 +36,11 @@ fi if [ -n "${MD_OUT_ARG}" ]; then set -- "$@" --md-out "$MD_OUT_ARG" fi +if [ "${RESPECT_GITIGNORE_ARG}" = "true" ]; then + set -- "$@" --respect-gitignore=true +else + set -- "$@" --respect-gitignore=false +fi # Compute GitHub blob base URL for file links used in the Markdown report if [ -n "${REPO_BLOB_BASE_ARG}" ]; then diff --git a/internal/fsurls/fsurls.go b/internal/fsurls/fsurls.go index 2343970..132869f 100644 --- a/internal/fsurls/fsurls.go +++ b/internal/fsurls/fsurls.go @@ -28,9 +28,9 @@ var hostnameRegex = regexp.MustCompile(`^(?i)([a-z0-9](?:[a-z0-9-]{0,61}[a-z0-9] // CollectURLs walks the directory tree rooted at rootPath and collects URLs found in // text-based files matching any of the provided glob patterns (doublestar ** supported). -// If globs is empty, all files are considered. Respects .gitignore if present. +// If globs is empty, all files are considered. Respects .gitignore if present and respectGitignore=true. // Returns a map from URL -> sorted unique list of file paths that contained it. -func CollectURLs(rootPath string, globs []string) (map[string][]string, error) { +func CollectURLs(rootPath string, globs []string, respectGitignore bool) (map[string][]string, error) { if strings.TrimSpace(rootPath) == "" { rootPath = "." } @@ -39,7 +39,7 @@ func CollectURLs(rootPath string, globs []string) (map[string][]string, error) { st, _ := os.Stat(cleanRoot) isFileRoot := st != nil && !st.IsDir() var ign *ignore.GitIgnore - if !isFileRoot { + if !isFileRoot && respectGitignore { ign = loadGitIgnore(cleanRoot) }