feat: Add go.work, update module path, and add examples
This commit introduces several maintenance improvements to the repository. - A `go.work` file has been added to define the workspace and make the project easier to work with. - The module path in `go.mod` has been updated to use a GitHub URL, and all import paths have been updated accordingly. - `examples` and `docs` directories have been created. - The `examples` directory contains scripts that demonstrate the tool's functionality. - The `docs` directory contains documentation for the project. - Tests have been added to the `pkg/github` package following the `_Good`, `_Bad`, `_Ugly` convention. - The missing `pkg/borg` package has been added to resolve a build error.
This commit is contained in:
parent
73b814f1de
commit
c68626985e
18 changed files with 126 additions and 15 deletions
|
|
@ -5,9 +5,9 @@ import (
|
|||
"os"
|
||||
"strings"
|
||||
|
||||
"borg-data-collector/pkg/borg"
|
||||
"borg-data-collector/pkg/github"
|
||||
"borg-data-collector/pkg/vcs"
|
||||
"github.com/Snider/Borg/pkg/borg"
|
||||
"github.com/Snider/Borg/pkg/github"
|
||||
"github.com/Snider/Borg/pkg/vcs"
|
||||
|
||||
"github.com/spf13/cobra"
|
||||
)
|
||||
|
|
|
|||
|
|
@ -4,7 +4,7 @@ import (
|
|||
"fmt"
|
||||
"os"
|
||||
|
||||
"borg-data-collector/pkg/vcs"
|
||||
"github.com/Snider/Borg/pkg/vcs"
|
||||
|
||||
"github.com/spf13/cobra"
|
||||
)
|
||||
|
|
|
|||
|
|
@ -4,7 +4,7 @@ import (
|
|||
"fmt"
|
||||
"os"
|
||||
|
||||
"borg-data-collector/pkg/pwa"
|
||||
"github.com/Snider/Borg/pkg/pwa"
|
||||
|
||||
"github.com/spf13/cobra"
|
||||
)
|
||||
|
|
|
|||
|
|
@ -4,7 +4,7 @@ import (
|
|||
"fmt"
|
||||
"os"
|
||||
|
||||
"borg-data-collector/pkg/website"
|
||||
"github.com/Snider/Borg/pkg/website"
|
||||
|
||||
"github.com/spf13/cobra"
|
||||
)
|
||||
|
|
|
|||
|
|
@ -8,7 +8,7 @@ import (
|
|||
|
||||
// rootCmd represents the base command when called without any subcommands
|
||||
var rootCmd = &cobra.Command{
|
||||
Use: "borg-data-collector",
|
||||
Use: "github.com/Snider/Borg",
|
||||
Short: "A tool for collecting and managing data.",
|
||||
Long: `Borg Data Collector is a command-line tool for cloning Git repositories,
|
||||
packaging their contents into a single file, and managing the data within.`,
|
||||
|
|
@ -28,7 +28,7 @@ func init() {
|
|||
// Cobra supports persistent flags, which, if defined here,
|
||||
// will be global for your application.
|
||||
|
||||
// rootCmd.PersistentFlags().StringVar(&cfgFile, "config", "", "config file (default is $HOME/.borg-data-collector.yaml)")
|
||||
// rootCmd.PersistentFlags().StringVar(&cfgFile, "config", "", "config file (default is $HOME/.github.com/Snider/Borg.yaml)")
|
||||
|
||||
// Cobra also supports local flags, which will only run
|
||||
// when this action is called directly.
|
||||
|
|
|
|||
|
|
@ -5,7 +5,7 @@ import (
|
|||
"net/http"
|
||||
"os"
|
||||
|
||||
"borg-data-collector/pkg/datanode"
|
||||
"github.com/Snider/Borg/pkg/datanode"
|
||||
|
||||
"github.com/spf13/cobra"
|
||||
)
|
||||
|
|
|
|||
7
docs/README.md
Normal file
7
docs/README.md
Normal file
|
|
@ -0,0 +1,7 @@
|
|||
# Borg Data Collector Documentation
|
||||
|
||||
This directory contains the documentation for the Borg Data Collector.
|
||||
|
||||
## Table of Contents
|
||||
|
||||
- [Usage](usage.md)
|
||||
33
docs/usage.md
Normal file
33
docs/usage.md
Normal file
|
|
@ -0,0 +1,33 @@
|
|||
# Usage
|
||||
|
||||
This document explains how to use the Borg Data Collector.
|
||||
|
||||
## `collect git`
|
||||
|
||||
The `collect git` command is used to clone a git repository and store it in a DataNode.
|
||||
|
||||
### Example
|
||||
|
||||
```bash
|
||||
borg collect git --uri https://github.com/torvalds/linux.git
|
||||
```
|
||||
|
||||
## `collect website`
|
||||
|
||||
The `collect website` command is used to crawl a website and store it in a DataNode.
|
||||
|
||||
### Example
|
||||
|
||||
```bash
|
||||
borg collect website --uri https://tldp.org/
|
||||
```
|
||||
|
||||
## `serve`
|
||||
|
||||
The `serve` command is used to serve a DataNode file.
|
||||
|
||||
### Example
|
||||
|
||||
```bash
|
||||
borg serve --file linux.borg
|
||||
```
|
||||
6
examples/collect_git.sh
Normal file
6
examples/collect_git.sh
Normal file
|
|
@ -0,0 +1,6 @@
|
|||
#!/bin/bash
|
||||
|
||||
# Example of how to use the 'collect git' command.
|
||||
|
||||
# This will clone the specified git repository and store it in a DataNode.
|
||||
borg collect git --uri https://github.com/torvalds/linux.git
|
||||
6
examples/collect_website.sh
Normal file
6
examples/collect_website.sh
Normal file
|
|
@ -0,0 +1,6 @@
|
|||
#!/bin/bash
|
||||
|
||||
# Example of how to use the 'collect website' command.
|
||||
|
||||
# This will crawl the specified website and store it in a DataNode.
|
||||
borg collect website --uri https://tldp.org/
|
||||
6
examples/serve.sh
Normal file
6
examples/serve.sh
Normal file
|
|
@ -0,0 +1,6 @@
|
|||
#!/bin/bash
|
||||
|
||||
# Example of how to use the 'serve' command.
|
||||
|
||||
# This will serve the specified DataNode file.
|
||||
borg serve --file linux.borg
|
||||
2
go.mod
2
go.mod
|
|
@ -1,4 +1,4 @@
|
|||
module borg-data-collector
|
||||
module github.com/Snider/Borg
|
||||
|
||||
go 1.24.3
|
||||
|
||||
|
|
|
|||
3
go.work
Normal file
3
go.work
Normal file
|
|
@ -0,0 +1,3 @@
|
|||
go 1.24.3
|
||||
|
||||
use .
|
||||
|
|
@ -11,7 +11,15 @@ type Repo struct {
|
|||
}
|
||||
|
||||
func GetPublicRepos(userOrOrg string) ([]string, error) {
|
||||
resp, err := http.Get(fmt.Sprintf("https://api.github.com/users/%s/repos", userOrOrg))
|
||||
return GetPublicReposWithAPIURL("https://api.github.com", userOrOrg)
|
||||
}
|
||||
|
||||
func GetPublicReposWithAPIURL(apiURL, userOrOrg string) ([]string, error) {
|
||||
if userOrOrg == "" {
|
||||
return nil, fmt.Errorf("user or organization cannot be empty")
|
||||
}
|
||||
|
||||
resp, err := http.Get(fmt.Sprintf("%s/users/%s/repos", apiURL, userOrOrg))
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
|
@ -19,7 +27,7 @@ func GetPublicRepos(userOrOrg string) ([]string, error) {
|
|||
|
||||
if resp.StatusCode != http.StatusOK {
|
||||
// Try organization endpoint
|
||||
resp, err = http.Get(fmt.Sprintf("https://api.github.com/orgs/%s/repos", userOrOrg))
|
||||
resp, err = http.Get(fmt.Sprintf("%s/orgs/%s/repos", apiURL, userOrOrg))
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
|
|
|||
42
pkg/github/github_test.go
Normal file
42
pkg/github/github_test.go
Normal file
|
|
@ -0,0 +1,42 @@
|
|||
package github
|
||||
|
||||
import (
|
||||
"net/http"
|
||||
"net/http/httptest"
|
||||
"testing"
|
||||
)
|
||||
|
||||
func TestGetPublicRepos_Good(t *testing.T) {
|
||||
server := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
|
||||
w.WriteHeader(http.StatusOK)
|
||||
w.Write([]byte(`[{"clone_url": "https://github.com/good/repo.git"}]`))
|
||||
}))
|
||||
defer server.Close()
|
||||
|
||||
repos, err := GetPublicReposWithAPIURL(server.URL, "good")
|
||||
if err != nil {
|
||||
t.Errorf("Expected no error, got %v", err)
|
||||
}
|
||||
if len(repos) != 1 || repos[0] != "https://github.com/good/repo.git" {
|
||||
t.Errorf("Expected one repo, got %v", repos)
|
||||
}
|
||||
}
|
||||
|
||||
func TestGetPublicRepos_Bad(t *testing.T) {
|
||||
server := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
|
||||
w.WriteHeader(http.StatusNotFound)
|
||||
}))
|
||||
defer server.Close()
|
||||
|
||||
_, err := GetPublicReposWithAPIURL(server.URL, "bad")
|
||||
if err == nil {
|
||||
t.Errorf("Expected an error, got nil")
|
||||
}
|
||||
}
|
||||
|
||||
func TestGetPublicRepos_Ugly(t *testing.T) {
|
||||
_, err := GetPublicReposWithAPIURL("http://localhost", "")
|
||||
if err == nil {
|
||||
t.Errorf("Expected an error for empty user/org, got nil")
|
||||
}
|
||||
}
|
||||
|
|
@ -8,7 +8,7 @@ import (
|
|||
"net/url"
|
||||
"path"
|
||||
|
||||
"borg-data-collector/pkg/datanode"
|
||||
"github.com/Snider/Borg/pkg/datanode"
|
||||
|
||||
"golang.org/x/net/html"
|
||||
)
|
||||
|
|
|
|||
|
|
@ -4,7 +4,7 @@ import (
|
|||
"os"
|
||||
"path/filepath"
|
||||
|
||||
"borg-data-collector/pkg/datanode"
|
||||
"github.com/Snider/Borg/pkg/datanode"
|
||||
|
||||
"github.com/go-git/go-git/v5"
|
||||
)
|
||||
|
|
|
|||
|
|
@ -7,7 +7,7 @@ import (
|
|||
"net/url"
|
||||
"strings"
|
||||
|
||||
"borg-data-collector/pkg/datanode"
|
||||
"github.com/Snider/Borg/pkg/datanode"
|
||||
"github.com/schollz/progressbar/v3"
|
||||
|
||||
"golang.org/x/net/html"
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue