Skip to content

Commit

Permalink
Merge pull request #14 from loftwah/dl/handle-bigger-repos
Browse files Browse the repository at this point in the history
make better and handle larger repos
  • Loading branch information
loftwah authored Sep 10, 2024
2 parents 113f1a0 + 4f2871d commit 82f81c5
Show file tree
Hide file tree
Showing 5 changed files with 476 additions and 90 deletions.
4 changes: 2 additions & 2 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ jobs:
- uses: actions/checkout@v4

- name: Set up Go
uses: actions/setup-go@v4
uses: actions/setup-go@v5 # Update to v5 to support Node.js 20
with:
go-version: '1.21'

Expand All @@ -36,7 +36,7 @@ jobs:
run: go vet ./...

- name: Run golangci-lint
uses: golangci/golangci-lint-action@v3
uses: golangci/golangci-lint-action@v4 # Update to v4 to support Node.js 20
with:
skip-cache: true # Skipping cache to avoid conflicts

Expand Down
116 changes: 116 additions & 0 deletions cmd/grabitsh/config._detection.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,116 @@
package grabitsh

import (
"bytes"
"fmt"
"os"
)

// Detect and collect important configuration files
func DetectImportantFiles(buffer *bytes.Buffer) {
buffer.WriteString("\n### Important Configuration Files ###\n")

// Helper function to check if file exists and then parse
checkAndParseIfExists := func(filename string, parser func(string, *bytes.Buffer), buffer *bytes.Buffer) {
if _, err := os.Stat(filename); err == nil {
parser(filename, buffer)
}
}

// Helper function for parsers that return an error
checkAndParseIfExistsWithError := func(filename string, parser func(string, *bytes.Buffer) error, buffer *bytes.Buffer) {
if _, err := os.Stat(filename); err == nil {
if err := parser(filename, buffer); err != nil {
buffer.WriteString(fmt.Sprintf("Error parsing %s: %v\n", filename, err))
}
}
}

// 1. Version Control
checkAndParseIfExists(".git/config", parseGitConfig, buffer)
checkAndParseIfExists(".gitattributes", parseBasicTextFile, buffer)
checkAndParseIfExists(".gitmodules", parseBasicTextFile, buffer)
checkAndParseIfExists(".gitmessage", parseBasicTextFile, buffer)
checkAndParseIfExists(".gitflow", parseBasicTextFile, buffer)

// 2. Project Configuration
checkAndParseIfExists(".editorconfig", parseBasicTextFile, buffer)
checkAndParseIfExists(".vscode/settings.json", parseJSONFile, buffer)
checkAndParseIfExists(".eslintignore", parseBasicTextFile, buffer)
checkAndParseIfExists(".npmrc", parseBasicTextFile, buffer)
checkAndParseIfExists(".nvmrc", parseBasicTextFile, buffer)
checkAndParseIfExists(".yarnrc", parseBasicTextFile, buffer)
checkAndParseIfExists("lerna.json", parseJSONFile, buffer)
checkAndParseIfExists("nx.json", parseJSONFile, buffer)

// 3. CI/CD and DevOps
checkAndParseIfExists(".travis.yml", parseYAMLFile, buffer)
checkAndParseIfExists(".circleci/config.yml", parseYAMLFile, buffer)
checkAndParseIfExists(".gitlab-ci.yml", parseYAMLFile, buffer)
checkAndParseIfExists(".github/workflows", parseGithubActionsWorkflows, buffer)
checkAndParseIfExists("Jenkinsfile", parseBasicTextFile, buffer)
checkAndParseIfExists("azure-pipelines.yml", parseYAMLFile, buffer)
checkAndParseIfExists("bitbucket-pipelines.yml", parseYAMLFile, buffer)
checkAndParseIfExists("sonar-project.properties", parseBasicTextFile, buffer)
checkAndParseIfExists("codecov.yml", parseYAMLFile, buffer)
checkAndParseIfExists(".snyk", parseBasicTextFile, buffer)

// 4. Docker and Containerization
checkAndParseIfExists("docker-compose.yml", parseYAMLFile, buffer)
checkAndParseIfExists("docker-compose.override.yml", parseYAMLFile, buffer)
checkAndParseIfExists("Dockerfile", parseDockerfile, buffer)
checkAndParseIfExists(".dockerignore", parseBasicTextFile, buffer)
checkAndParseIfExists("docker/", parseDockerDir, buffer)

// 5. Kubernetes
checkAndParseIfExists("k8s/", parseK8sFiles, buffer)
checkAndParseIfExists("helm/", parseHelmFiles, buffer)
checkAndParseIfExists("values.yaml", parseYAMLFile, buffer)
checkAndParseIfExists("kustomization.yaml", parseYAMLFile, buffer)

// 6. Cloud Providers
checkAndParseIfExists("serverless.yml", parseYAMLFile, buffer)
checkAndParseIfExists(".aws/", parseDirectoryContents, buffer)
checkAndParseIfExists("firebase.json", parseJSONFile, buffer)
checkAndParseIfExists("vercel.json", parseJSONFile, buffer)
checkAndParseIfExists("netlify.toml", parseYAMLFile, buffer)

// 7. Infrastructure as Code
checkAndParseIfExists("main.tf", parseBasicTextFile, buffer)
checkAndParseIfExists("Vagrantfile", parseBasicTextFile, buffer)
checkAndParseIfExists("Pulumi.yaml", parseYAMLFile, buffer)

// 8. Language-Specific
checkAndParseIfExistsWithError("Gemfile", parseGemfile, buffer)
checkAndParseIfExists(".ruby-version", parseBasicTextFile, buffer)
checkAndParseIfExists("config/application.rb", parseBasicTextFile, buffer)

// Python
checkAndParseIfExists("requirements.txt", parseBasicTextFile, buffer)
checkAndParseIfExists("setup.py", parseBasicTextFile, buffer)

// JavaScript / TypeScript
checkAndParseIfExistsWithError("package.json", parsePackageJSON, buffer)
checkAndParseIfExists("tsconfig.json", parseJSONFile, buffer)

// Go
checkAndParseIfExists("go.mod", parseBasicTextFile, buffer)
checkAndParseIfExists("go.sum", parseBasicTextFile, buffer)

// PHP
checkAndParseIfExists("composer.json", parseJSONFile, buffer)
checkAndParseIfExists("phpunit.xml", parseBasicTextFile, buffer)

// Java / Kotlin
checkAndParseIfExists("pom.xml", parseBasicTextFile, buffer)
checkAndParseIfExists("build.gradle", parseBasicTextFile, buffer)

// 9. Web Frameworks
checkAndParseIfExists("next.config.js", parseBasicTextFile, buffer)
checkAndParseIfExists("nuxt.config.js", parseBasicTextFile, buffer)

// 10. Miscellaneous
checkAndParseIfExists("CHANGELOG.md", parseBasicTextFile, buffer)
checkAndParseIfExists("CONTRIBUTING.md", parseBasicTextFile, buffer)
checkAndParseIfExists("CODE_OF_CONDUCT.md", parseBasicTextFile, buffer)
}
Loading

0 comments on commit 82f81c5

Please sign in to comment.