gitops

package
v0.1.15 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Dec 26, 2023 License: MIT Imports: 6 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func SyncFiles

func SyncFiles(repoPath string, mappings []FileSyncMapping) error

SyncFiles synchronizes files from the repository to the local file system based on the provided mappings.

Types

type FileSyncMapping

type FileSyncMapping struct {
	Source      string
	Destination string
}

FileSyncMapping defines a mapping of a file from its source location in the repository to a destination path in the local file system.

type Manager

type Manager struct {
	Auth *gitHttp.BasicAuth
}

Manager manages Git operations and file synchronization.

Example:

package main

import (

"fmt"
"log"
"your-module-name/gitops"

)

func main() {
    repoURL := "https://github.com/example-user/example-repo.git"
    destination := "./example-repo"

    // Initialize GitOpsManager with credentials
    manager := gitops.NewGitOpsManager("your-username", "your-personal-access-token")

    // Clone a repository
    if err := manager.CloneRepository(repoURL, destination); err != nil {
        log.Fatalf("Clone failed: %s", err)
    }
    fmt.Println("Repository cloned successfully.")

    // Pull the repository
    changes, err := manager.PullRepository(destination)
    if err != nil {
        log.Fatalf("Pull failed: %s", err)
    }
    if changes {
        fmt.Println("Repository updated.")
    } else {
        fmt.Println("Repository already up to date.")
    }

    // Define file synchronization mappings
    mappings := []gitops.FileSyncMapping{
        {Source: "file1.txt", Destination: "/path/to/local/file1.txt"},
        // Add more mappings as needed
    }

    // Check for changes and synchronize files
    changes, err := manager.PullRepository(destination)
    if err != nil {
        log.Fatalf("Pull failed: %s", err)
    }
    if changes {
        fmt.Println("Changes detected, synchronizing files...")

        // Synchronize files
        if err := manager.SyncFiles(destination, mappings); err != nil {
            log.Fatalf("Sync failed: %s", err)
        }
        fmt.Println("Files synchronized successfully.")
    } else {
        fmt.Println("No changes detected.")
    }

    // Additional operations can be added here as needed
}

func NewGitOpsManager

func NewGitOpsManager(username, password string) *Manager

NewGitOpsManager creates a new instance of GitOpsManager with optional authentication.

func (*Manager) CloneRepository

func (m *Manager) CloneRepository(repoURL, destination string) error

CloneRepository clones a Git repository into a given directory.

func (*Manager) PullRepository

func (m *Manager) PullRepository(repoPath string) (bool, error)

PullRepository updates the local copy of a Git repository and returns true if there were changes.

func (*Manager) SyncFiles

func (m *Manager) SyncFiles(repoPath string, mappings []FileSyncMapping) error

SyncFiles synchronizes files from the repository to the local file system based on the provided mappings.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL