Documentation
¶
Index ¶
- func CheckCache(path, name, commitHash string) bool
- func Clone(host, userRepo string, depth bool)
- func CommitBranch(userRepo, branch string) (string, string, error)
- func Extract(source, target, destination string, strip int)
- func Get(name, commit, destination, url string) (string, error)
- func LatestCommit(userRepo string) string
- type Branch
- type Commit
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func CheckCache ¶
CheckCache checks if a specific cache file or directory exists.
Parameters:
- path: The base directory where caches are stored.
- name: The name of the repository or resource (e.g., "nazhard/gigit").
- commitHash: The commit hash or unique identifier for the cache.
Returns:
- `true` if the cache exists.
- `false` if the cache does not exist.
Behavior:
- Constructs the full cache path by combining the base path, name, and commit hash.
- Uses `os.Stat` to check if the specified path exists.
- Returns `false` if the path does not exist or there is an error.
func Clone ¶
Clone clones a Git repository from a specified host and repository name.
Parameters:
- host: The Git server's base URL (e.g., "https://github.com").
- userRepo: The repository in the format "owner/repo" (e.g., "nazhard/gigit").
- depth: A boolean value indicating whether to perform a shallow clone.
- `true`: Clones only the latest commit (`--depth=1`).
- `false`: Clones the entire repository history.
Behavior:
- Constructs a `git clone` command based on the provided parameters.
- Executes the command and streams its output (stdout and stderr) to the console.
- Ensures that the command is properly started and waited on to finish.
func CommitBranch ¶
CommitBranch fetches the commit hash of a specific branch in a GitHub repository. It also constructs the URL to download the branch as a tar.gz archive.
Parameters:
- userRepo: The GitHub repository in the format "owner/repo" (e.g., "nazhard/gigit").
- branch: The branch name (e.g., "main").
Returns:
- The URL to download the branch archive.
- The commit hash of the branch.
- An error if the branch does not exist or the request fails.
func Extract ¶
Extract extracts a tar.gz archive to a specified destination.
Parameters:
- source: Path to the tar.gz archive.
- target: Specific file/directory to extract (leave empty to extract all).
- destination: Directory where the extracted content will be placed.
- strip: Number of leading path components to remove from file paths.
func Get ¶
Get downloads a specific commit or branch tarball from a GitHub repository and saves it locally.
Parameters:
- name: The GitHub repository in the format "owner/repo" (e.g., "nazhard/gigit").
- commit: The specific commit hash or branch name to fetch (e.g., "main" or a hash like "abc123").
- destination: The directory where the tarball will be saved.
- url: (Optional) A custom URL to fetch the tarball from. If empty, the default GitHub API tarball URL is used.
Returns:
- A string containing the URL used for the fetch.
- An error if the fetch fails, the directory cannot be created, or the tarball cannot be saved.
Behavior:
- Constructs the default GitHub tarball URL if no custom URL is provided.
- Sends a GET request to fetch the tarball from the URL.
- Extracts the repository name from the `name` parameter and generates a tarball filename.
- Creates the destination directory if it does not exist.
- Writes the tarball content to a file in the destination directory.
- Returns the URL used and any encountered errors.
func LatestCommit ¶
LatestCommit fetches the latest commit hash from a specified GitHub repository.
Parameters:
- userRepo: The GitHub repository in the format "owner/repo" (e.g., "nazhard/gigit").
Returns:
- The latest commit hash as a string.
- If the request fails or there are no commits, the function returns an empty string.
Behavior:
- Sends a GET request to the GitHub API to retrieve the list of commits for the given repository.
- Parses the JSON response to extract the hash of the most recent commit.
- If there is an error (e.g., invalid repository, no internet connection), it logs the issue and exits the program.