Skip to content

Commit

Permalink
Updates
Browse files Browse the repository at this point in the history
Updated .gitignore

Renamed main file

Added golreaser.yaml
  • Loading branch information
ondrovic committed Aug 25, 2024
1 parent c9abcb4 commit bd34879
Show file tree
Hide file tree
Showing 4 changed files with 70 additions and 60 deletions.
1 change: 1 addition & 0 deletions .github/workflows/releaser.yml
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ permissions:

jobs:
goreleaser:
if: github.ref_name == github.event.repository.default_branch
runs-on: ubuntu-latest
steps:
- name: Checkout
Expand Down
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
!README.md
!LICENSE
!generate_config.sh
!goreleaser.yaml

# Include all directories recursively
!*/
Expand Down
67 changes: 67 additions & 0 deletions goreleaser.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,67 @@
version: 2

project_name: repo-stub

env:
- GO_MAIN_PATH=./repo-stub.go

before:
hooks:
# Tidy
- go mod tidy
# Generate
- go generate ./...

builds:
- id: windows
main: '{{ .Env.GO_MAIN_PATH }}'
env:
- CGO_ENABLED=0
goos:
- windows
goarch:
- amd64
ldflags: -s -w

- id: linux
main: '{{ .Env.GO_MAIN_PATH }}'
env:
- CGO_ENABLED=0
goos:
- linux
goarch:
- amd64
ldflags: -s -w

- id: macos
main: '{{ .Env.GO_MAIN_PATH }}'
env:
- CGO_ENABLED=0
goos:
- darwin
goarch:
- amd64
ldflags: -s -w

archives:
- format: tar.gz
# this name template makes the OS and Arch compatible with the results of `uname`.
name_template: >-
{{ .ProjectName }}_
{{- if eq .Os "darwin" }}MacOs
{{- else }}{{ title .Os }}{{ end }}_
{{- if eq .Arch "amd64" }}x86_64{{ else }}{{ .Arch }}{{ end }}
# use zip for windows archives
format_overrides:
- goos: windows
format: zip

checksum:
name_template: "checksums.txt"

changelog:
sort: asc
filters:
exclude:
- "^docs:"
- "^test:"
61 changes: 1 addition & 60 deletions github-project-stub.go → repo-stub.go
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ func main() {
}

rootCmd := &cobra.Command{
Use: "github-project-stub",
Use: "repo-stub",
Short: "A CLI tool to download GitHub repository contents when creating a new project.",
Run: run,
}
Expand Down Expand Up @@ -95,43 +95,6 @@ func run(cmd *cobra.Command, args []string) {
}
}

// func getRepoContents(repoUri, path string) ([]GitHubItem, error) {
// url := repoUri
// if path != "" {
// url = fmt.Sprintf("%s/%s", repoUri, path)
// }

// req, err := http.NewRequest("GET", url, nil)
// if err != nil {
// return nil, fmt.Errorf("failed to create request %s: %v", url, err)
// }

// if githubToken != "" {
// req.Header.Set("Authorization", "token "+githubToken)
// }

// resp, err := client.Do(req)
// if err != nil {
// return nil, fmt.Errorf("failed to get contents from '%s': %v", url, err)
// }
// defer resp.Body.Close()

// if resp.StatusCode != http.StatusOK {
// return nil, fmt.Errorf("failed to get contents %s: HTTP status %d", url, resp.StatusCode)
// }

// var contents []GitHubItem
// if err := json.NewDecoder(resp.Body).Decode(&contents); err != nil {
// // If it's not a JSON array, it might be a single file content
// var singleItem GitHubItem
// if err := json.NewDecoder(resp.Body).Decode(&singleItem); err != nil {
// return nil, fmt.Errorf("failed to decode response %s: %v", url, err)
// }
// contents = []GitHubItem{singleItem}
// }

// return contents, nil
// }
func getRepoContents(repoUri, path string) ([]GitHubItem, error) {
url := repoUri
if path != "" {
Expand Down Expand Up @@ -252,11 +215,6 @@ func handleDirectoryTypeContent(baseURL string, item GitHubItem) error {
}
}

// func handleIgnoreFile(baseURL string) error {
// ignoreApiURL := fmt.Sprintf("%s/.ignorefiles", baseURL)
// return downloadFileFromGitHub(ignoreApiURL, filepath.Join(outputDirectory, ".gitignore"), overwriteExistingFiles)
// }

func handleIgnoreFile(baseURL string) error {
ignoreApiURL := fmt.Sprintf("%s/.ignorefiles", baseURL)
item, err := getGitHubFileInfo(ignoreApiURL)
Expand Down Expand Up @@ -326,24 +284,7 @@ func downloadFileFromGitHub(apiURL, destPath string, overwrite bool) error {
return downloadAndSaveFile(item.DownloadURL, destPath, overwrite)
}

// func getGitHubFileInfo(apiURL string) (*GitHubItem, error) {
// resp, err := http.Get(apiURL)
// if err != nil {
// return nil, fmt.Errorf("failed to get file info from '%s': %v", apiURL, err)
// }
// defer resp.Body.Close()

// if resp.StatusCode != http.StatusOK {
// return nil, fmt.Errorf("failed to get file info: HTTP status %d", resp.StatusCode)
// }

// var item GitHubItem
// if err := json.NewDecoder(resp.Body).Decode(&item); err != nil {
// return nil, fmt.Errorf("failed to decode file info: %v", err)
// }

// return &item, nil
// }
func getGitHubFileInfo(apiURL string) (*GitHubItem, error) {
resp, err := http.Get(apiURL)
if err != nil {
Expand Down

0 comments on commit bd34879

Please sign in to comment.