git

package
v0.0.0-...-50f4440 Latest Latest
Warning

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

Go to latest
Published: Jun 16, 2026 License: MIT Imports: 33 Imported by: 0

Documentation

Index

Constants

View Source
const (
	GitSyncNeverSynced = "never_synced"
	GitSyncReady       = "ready"
	GitSyncUpdating    = "updating"
	GitSyncError       = "error"

	GitInstallationNotConnected = "not_connected"
	GitInstallationConnected    = "connected"
)
View Source
const (
	GitUploadSessionPending   = "pending_upload"
	GitUploadSessionReady     = "ready_for_pr"
	GitUploadSessionFinalized = "finalized"

	GitUploadFilePending   = "pending_upload"
	GitUploadFileUploaded  = "uploaded"
	GitUploadFileCollision = "collision"
)

Variables

This section is empty.

Functions

func BuildDefaultUploadPRBody

func BuildDefaultUploadPRBody(baseBranch string, subdirectory string) string

func BuildDefaultUploadPRTitle

func BuildDefaultUploadPRTitle(project string, fileCount int) string

func BuildGitUploadBranchName

func BuildGitUploadBranchName(project string) string

func BuildGitUploadTargetPath

func BuildGitUploadTargetPath(subdirectory string, fileName string) string

func BuildLFSPointerContent

func BuildLFSPointerContent(checksum string, size int64) string

func DeleteAuthzResource

func DeleteAuthzResource(ctx context.Context, authorizationHeader, resourcePath string) error

func GitPathExistsInRef

func GitPathExistsInRef(repo *gogit.Repository, hash plumbing.Hash, path string) (bool, error)

func NormalizeGitUploadFileName

func NormalizeGitUploadFileName(value string) (string, error)

func NormalizeGitUploadSubdirectory

func NormalizeGitUploadSubdirectory(value string) string

func OpenRepository

func OpenRepository(path string) (*gogit.Repository, error)

func OrganizationConfigurationState

func OrganizationConfigurationState(appInstalled bool, configuredProjects int, totalProjects int) string

func ProgramProjectResourcePath

func ProgramProjectResourcePath(organization, project string) string

func RepositoryIsEmpty

func RepositoryIsEmpty(repo *gogit.Repository) bool

func ResolveGitReference

func ResolveGitReference(repo *gogit.Repository, requestedRef string, defaultBranch string) (string, plumbing.Hash, error)

func SyncRepositoryMirror

func SyncRepositoryMirror(ctx context.Context, remoteURL string, mirrorPath string, auth *githttp.BasicAuth) error

Types

type CalyprProjectInitializeResponse

type CalyprProjectInitializeResponse struct {
	Success      bool   `json:"success"`
	ProjectID    string `json:"project_id"`
	ResourcePath string `json:"resource_path"`
}

type CalyprProjectReadiness

type CalyprProjectReadiness struct {
	Git    CalyprReadinessCheck `json:"git"`
	Syfon  CalyprReadinessCheck `json:"syfon"`
	Config CalyprReadinessCheck `json:"config"`
}

type CalyprProjectSetupRequest

type CalyprProjectSetupRequest struct {
	Config  appconfig.ProjectConfig     `json:"config"`
	Storage *CalyprProjectStorageIntent `json:"storage,omitempty"`
}

type CalyprProjectSetupResponse

type CalyprProjectSetupResponse struct {
	ProjectID    string                 `json:"project_id"`
	ResourcePath string                 `json:"resource_path"`
	Configured   bool                   `json:"configured"`
	Readiness    CalyprProjectReadiness `json:"readiness"`
}

type CalyprProjectStorageIntent

type CalyprProjectStorageIntent struct {
	Bucket              string `json:"bucket"`
	Provider            string `json:"provider"`
	Endpoint            string `json:"endpoint"`
	Region              string `json:"region"`
	AccessKey           string `json:"access_key"`
	SecretKey           string `json:"secret_key"`
	Organization        string `json:"organization"`
	ProjectID           string `json:"project_id"`
	Path                string `json:"path,omitempty"`
	PathPrefix          string `json:"path_prefix,omitempty"`
	OrganizationSubPath string `json:"organization_sub_path,omitempty"`
	ProjectSubPath      string `json:"project_sub_path,omitempty"`
}

type CalyprProjectStorageRequest

type CalyprProjectStorageRequest struct {
	Storage *CalyprProjectStorageIntent `json:"storage"`
}

type CalyprProjectStorageResponse

type CalyprProjectStorageResponse struct {
	Success      bool                    `json:"success"`
	ProjectID    string                  `json:"project_id"`
	ResourcePath string                  `json:"resource_path"`
	Storage      ProjectIntegrationCheck `json:"storage"`
}

type CalyprReadinessCheck

type CalyprReadinessCheck struct {
	Pass    bool   `json:"pass"`
	Reason  string `json:"reason,omitempty"`
	Details string `json:"details,omitempty"`
}

type Error

type Error struct {
	Kind       ErrorKind
	Message    string
	StatusCode int
	Details    map[string]any
	Err        error
}

func NewError

func NewError(kind ErrorKind, statusCode int, message string, details map[string]any) *Error

func WrapError

func WrapError(kind ErrorKind, statusCode int, message string, cause error, details map[string]any) *Error

func (*Error) Error

func (err *Error) Error() string

func (*Error) Unwrap

func (err *Error) Unwrap() error

type ErrorKind

type ErrorKind string
const (
	ErrorKindValidation   ErrorKind = "validation"
	ErrorKindForbidden    ErrorKind = "forbidden"
	ErrorKindIntegration  ErrorKind = "integration"
	ErrorKindNotFound     ErrorKind = "not_found"
	ErrorKindDatabase     ErrorKind = "database"
	ErrorKindUnauthorized ErrorKind = "unauthorized"
)

type GitHubInstallationRepository

type GitHubInstallationRepository = domain.GitHubInstallationRepository

GitHubInstallationRepository is an alias for domain.GitHubInstallationRepository.

type GitHubRepositoryMetadata

type GitHubRepositoryMetadata = domain.GitHubRepositoryMetadata

GitHubRepositoryMetadata is an alias for domain.GitHubRepositoryMetadata.

type GitLFSPointerInfo

type GitLFSPointerInfo struct {
	Version string `json:"version"`
	OID     string `json:"oid"`
	Size    int64  `json:"size"`
}

func ParseGitLFSPointer

func ParseGitLFSPointer(content []byte) *GitLFSPointerInfo

type GitOrganizationConnectResponse

type GitOrganizationConnectResponse struct {
	Mode           string                         `json:"mode"`
	RedirectURL    string                         `json:"redirect_url,omitempty"`
	InstallationID *int64                         `json:"installation_id,omitempty"`
	Repositories   []GitHubInstallationRepository `json:"repositories,omitempty"`
}

type GitOrganizationProjectStatus

type GitOrganizationProjectStatus struct {
	ProjectID                 string                          `json:"project_id"`
	Project                   string                          `json:"project"`
	ResourcePath              string                          `json:"resource_path"`
	Repository                GitRepositoryIdentity           `json:"repository"`
	Configured                bool                            `json:"configured"`
	Readiness                 *CalyprProjectReadiness         `json:"readiness,omitempty"`
	Integrations              ProjectIntegrationStatus        `json:"integrations"`
	Accessible                bool                            `json:"accessible"`
	CanManageSettings         bool                            `json:"can_manage_settings"`
	RequestAccess             bool                            `json:"request_access"`
	RequestAccessResourcePath string                          `json:"request_access_resource_path,omitempty"`
	Installation              GitRepositoryInstallationStatus `json:"installation"`
}

type GitOrganizationStatusResponse

type GitOrganizationStatusResponse struct {
	Organization        string                         `json:"organization"`
	Connected           bool                           `json:"connected"`
	AppInstalled        bool                           `json:"app_installed"`
	CanAccessSettings   bool                           `json:"can_access_settings"`
	CanCreateProjects   bool                           `json:"can_create_projects"`
	CanManagePeople     bool                           `json:"can_manage_people"`
	CanDeleteOrg        bool                           `json:"can_delete_org"`
	InstallationID      *int64                         `json:"installation_id,omitempty"`
	HTMLURL             string                         `json:"html_url,omitempty"`
	RepositorySelection string                         `json:"repository_selection,omitempty"`
	ConfigurationState  string                         `json:"configuration_state"`
	ConnectedProjects   int                            `json:"connected_projects"`
	ConfiguredProjects  int                            `json:"configured_projects"`
	TotalProjects       int                            `json:"total_projects"`
	Projects            []GitOrganizationProjectStatus `json:"projects"`
}

type GitOrganizationsStatusResponse

type GitOrganizationsStatusResponse struct {
	Connected              bool                            `json:"connected"`
	AppInstalled           bool                            `json:"app_installed"`
	ConnectedOrganizations int                             `json:"connected_organizations"`
	InstalledOrganizations int                             `json:"installed_organizations"`
	TotalOrganizations     int                             `json:"total_organizations"`
	ConnectedProjects      int                             `json:"connected_projects"`
	ConfiguredProjects     int                             `json:"configured_projects"`
	TotalProjects          int                             `json:"total_projects"`
	ConfigurationState     string                          `json:"configuration_state"`
	Organizations          []GitOrganizationStatusResponse `json:"organizations"`
}

type GitProjectFileResponse

type GitProjectFileResponse struct {
	ProjectID   string             `json:"project_id"`
	Ref         string             `json:"ref"`
	Path        string             `json:"path"`
	Name        string             `json:"name"`
	Hash        string             `json:"hash"`
	Size        int64              `json:"size"`
	HTMLURL     string             `json:"html_url,omitempty"`
	DownloadURL string             `json:"download_url,omitempty"`
	LFSPointer  *GitLFSPointerInfo `json:"lfs_pointer,omitempty"`
}

func BuildGitFileResponse

func BuildGitFileResponse(projectID string, ref string, path string, repo *gogit.Repository, hash plumbing.Hash) (*GitProjectFileResponse, error)

func BuildGitHubFileResponse

func BuildGitHubFileResponse(projectID string, ref string, path string, metadata *github.RepositoryContent, contentBytes []byte) *GitProjectFileResponse

type GitProjectRefreshResponse

type GitProjectRefreshResponse struct {
	Success        bool   `json:"success"`
	ProjectID      string `json:"project_id"`
	SyncState      string `json:"sync_state"`
	DefaultBranch  string `json:"default_branch,omitempty"`
	LastFetchedRef string `json:"last_fetched_ref,omitempty"`
	Error          string `json:"error,omitempty"`
}

type GitProjectRefsResponse

type GitProjectRefsResponse struct {
	ProjectID     string   `json:"project_id"`
	DefaultBranch string   `json:"default_branch,omitempty"`
	Refs          []GitRef `json:"refs"`
}

func BuildGitRefsResponse

func BuildGitRefsResponse(projectID string, defaultBranch string, repo *gogit.Repository) (*GitProjectRefsResponse, error)

type GitProjectStatusResponse

type GitProjectStatusResponse struct {
	ProjectID                       string                  `json:"project_id"`
	Organization                    string                  `json:"organization"`
	Project                         string                  `json:"project"`
	ResourcePath                    string                  `json:"resource_path"`
	Accessible                      bool                    `json:"accessible"`
	RequestAccess                   bool                    `json:"request_access"`
	RequestAccessResourcePath       string                  `json:"request_access_resource_path,omitempty"`
	Config                          appconfig.ProjectConfig `json:"config"`
	Repository                      GitRepositoryIdentity   `json:"repository"`
	InstallationState               string                  `json:"installation_state"`
	InstallationID                  *int64                  `json:"installation_id,omitempty"`
	InstallationTarget              string                  `json:"installation_target,omitempty"`
	InstallationTargetType          string                  `json:"installation_target_type,omitempty"`
	OrganizationAppInstalled        bool                    `json:"organization_app_installed"`
	OrganizationHTMLURL             string                  `json:"organization_html_url,omitempty"`
	OrganizationRepositorySelection string                  `json:"organization_repository_selection,omitempty"`
	SyncState                       string                  `json:"sync_state"`
	DefaultBranch                   string                  `json:"default_branch,omitempty"`
	LastRefreshedAt                 *time.Time              `json:"last_refreshed_at,omitempty"`
	LastError                       string                  `json:"last_error,omitempty"`
	MirrorReady                     bool                    `json:"mirror_ready"`
}

type GitProjectTreeResponse

type GitProjectTreeResponse struct {
	ProjectID string         `json:"project_id"`
	Ref       string         `json:"ref"`
	Path      string         `json:"path"`
	Entries   []GitTreeEntry `json:"entries"`
}

func BuildGitTreeResponse

func BuildGitTreeResponse(projectID string, ref string, path string, repo *gogit.Repository, hash plumbing.Hash) (*GitProjectTreeResponse, error)

type GitRef

type GitRef struct {
	Name    string `json:"name"`
	Type    string `json:"type"`
	Hash    string `json:"hash"`
	Default bool   `json:"default"`
}

type GitRepositoryIdentity

type GitRepositoryIdentity = domain.GitRepositoryIdentity

GitRepositoryIdentity is an alias for domain.GitRepositoryIdentity.

func ParseRepositoryIdentity

func ParseRepositoryIdentity(raw string) (GitRepositoryIdentity, error)

type GitRepositoryInstallationStatus

type GitRepositoryInstallationStatus = domain.GitRepositoryInstallationStatus

GitRepositoryInstallationStatus is an alias for domain.GitRepositoryInstallationStatus.

type GitService

type GitService struct {
	// contains filtered or unexported fields
}

func NewGitService

func NewGitService(config GitServiceConfig) *GitService

func (*GitService) CreateGitHubUploadPullRequest

func (service *GitService) CreateGitHubUploadPullRequest(
	ctx context.Context,
	authorizationHeader string,
	organization string,
	project string,
	identity GitRepositoryIdentity,
	baseBranch string,
	branchName string,
	title string,
	body string,
	files []geckodb.GitUploadSessionFile,
) (string, string, error)

func (*GitService) EnsureDataDir

func (service *GitService) EnsureDataDir() error

func (*GitService) FetchRepositoryMetadata

func (service *GitService) FetchRepositoryMetadata(ctx context.Context, accessToken string, identity GitRepositoryIdentity) (*GitHubRepositoryMetadata, error)

func (*GitService) GetGitHubFileMetadata

func (service *GitService) GetGitHubFileMetadata(ctx context.Context, authorizationHeader string, organization string, project string, identity GitRepositoryIdentity, ref string, path string) (*github.RepositoryContent, []byte, error)

func (*GitService) Init

func (service *GitService) Init(db *sqlx.DB) error

func (*GitService) ListInstallationRepositories

func (service *GitService) ListInstallationRepositories(ctx context.Context, authorizationHeader string, installationID int64) ([]GitHubInstallationRepository, error)

func (*GitService) MirrorPathForIdentity

func (service *GitService) MirrorPathForIdentity(identity GitRepositoryIdentity) string

func (*GitService) RefreshProject

func (service *GitService) RefreshProject(ctx context.Context, projectID string, identity GitRepositoryIdentity, state *geckodb.GitProjectState, accessToken string) (*GitProjectRefreshResponse, *geckodb.GitProjectState, error)

func (*GitService) RequestInstallationStatus

func (service *GitService) RequestInstallationStatus(ctx context.Context, authorizationHeader string, organization string, identity GitRepositoryIdentity) (GitRepositoryInstallationStatus, error)

func (*GitService) RequestInstallationToken

func (service *GitService) RequestInstallationToken(ctx context.Context, authorizationHeader string, organization string, project string, identity GitRepositoryIdentity, access string) (string, error)

func (*GitService) RequestInstallationURL

func (service *GitService) RequestInstallationURL(ctx context.Context, authorizationHeader string, owner string, redirectPath string) (string, error)

func (*GitService) RequestOrganizationInstallationStatus

func (service *GitService) RequestOrganizationInstallationStatus(ctx context.Context, authorizationHeader string, organization string, owner string) (GitRepositoryInstallationStatus, error)

func (*GitService) ResolveTargetAndRepositoryIDs

func (service *GitService) ResolveTargetAndRepositoryIDs(ctx context.Context, identity GitRepositoryIdentity) (int64, int64, error)

func (*GitService) StatusFromState

func (service *GitService) StatusFromState(projectID string, organization string, project string, cfg appconfig.ProjectConfig, identity GitRepositoryIdentity, state *geckodb.GitProjectState, orgState *geckodb.GitOrganizationState) GitProjectStatusResponse

type GitServiceConfig

type GitServiceConfig struct {
	DataDir       string
	GitHubAPIBase string
	FenceBaseURL  string
	HTTPClient    *http.Client
	FenceClient   *fence.Client
	GitHubClient  *gitapi.Client
}

type GitTreeEntry

type GitTreeEntry struct {
	Name           string             `json:"name"`
	Path           string             `json:"path"`
	Type           string             `json:"type"`
	Hash           string             `json:"hash"`
	Size           int64              `json:"size,omitempty"`
	LastModifiedAt *time.Time         `json:"last_modified_at,omitempty"`
	LFSPointer     *GitLFSPointerInfo `json:"lfs_pointer,omitempty"`
}

type GitUploadSessionAttachFilesRequest

type GitUploadSessionAttachFilesRequest struct {
	Files []GitUploadSessionFileAttachment `json:"files"`
}

type GitUploadSessionCreateRequest

type GitUploadSessionCreateRequest struct {
	BaseBranch   string                         `json:"base_branch"`
	TargetSubdir string                         `json:"target_subdirectory"`
	Files        []GitUploadSessionFileManifest `json:"files"`
}

type GitUploadSessionFileAttachment

type GitUploadSessionFileAttachment struct {
	FileName    string `json:"file_name"`
	TargetPath  string `json:"target_path"`
	Checksum    string `json:"checksum"`
	DRSObjectID string `json:"drs_object_id"`
	Size        int64  `json:"size"`
}

type GitUploadSessionFileManifest

type GitUploadSessionFileManifest struct {
	Name string `json:"name"`
	Size int64  `json:"size"`
}

type GitUploadSessionFileStatus

type GitUploadSessionFileStatus struct {
	FileName    string `json:"file_name"`
	TargetPath  string `json:"target_path"`
	Size        int64  `json:"size"`
	Checksum    string `json:"checksum,omitempty"`
	DRSObjectID string `json:"drs_object_id,omitempty"`
	Status      string `json:"status"`
	Error       string `json:"error,omitempty"`
	Collision   bool   `json:"collision"`
}

type GitUploadSessionFinalizeRequest

type GitUploadSessionFinalizeRequest struct {
	PRTitle string `json:"pr_title"`
	PRBody  string `json:"pr_body"`
}

type GitUploadSessionResponse

type GitUploadSessionResponse struct {
	SessionID      string                       `json:"session_id"`
	ProjectID      string                       `json:"project_id"`
	BaseBranch     string                       `json:"base_branch"`
	TargetSubdir   string                       `json:"target_subdirectory,omitempty"`
	BranchName     string                       `json:"branch_name"`
	PRTitle        string                       `json:"pr_title"`
	PRBody         string                       `json:"pr_body"`
	Status         string                       `json:"status"`
	PullRequestURL string                       `json:"pull_request_url,omitempty"`
	CommitSHA      string                       `json:"commit_sha,omitempty"`
	Files          []GitUploadSessionFileStatus `json:"files"`
	HasConflicts   bool                         `json:"has_conflicts"`
}

type HTTPStatusError

type HTTPStatusError = domain.HTTPStatusError

HTTPStatusError is an alias for domain.HTTPStatusError.

type ProjectIntegrationCheck

type ProjectIntegrationCheck struct {
	Pass    bool   `json:"pass"`
	Reason  string `json:"reason,omitempty"`
	Details string `json:"details,omitempty"`
}

type ProjectIntegrationStatus

type ProjectIntegrationStatus struct {
	GitHub  ProjectIntegrationCheck `json:"github"`
	Storage ProjectIntegrationCheck `json:"storage"`
}

type ReconcileService

type ReconcileService struct {
	// contains filtered or unexported fields
}

func NewReconcileService

func NewReconcileService(db *sqlx.DB, storage *syfon.Manager, gitService *GitService) *ReconcileService

func (*ReconcileService) BuildOrganizationStatus

func (service *ReconcileService) BuildOrganizationStatus(ctx context.Context, organization string, projectIDs []string, projectStates map[string]geckodb.GitProjectState, organizationStates map[string]geckodb.GitOrganizationState, allowedResources []string, buckets map[string]StorageBucket, bucketsErr error) (GitOrganizationStatusResponse, error)

func (*ReconcileService) BuildOrganizationsStatus

func (service *ReconcileService) BuildOrganizationsStatus(ctx context.Context, authorizationHeader string, projectIDs []string, allowedResources []string) (GitOrganizationsStatusResponse, error)

func (*ReconcileService) BuildSingleOrganizationStatus

func (service *ReconcileService) BuildSingleOrganizationStatus(ctx context.Context, authorizationHeader string, organization string, projectIDs []string, allowedResources []string) (GitOrganizationStatusResponse, error)

func (*ReconcileService) ReconcileOrganization

func (service *ReconcileService) ReconcileOrganization(ctx context.Context, organization string, authorizationHeader string, projectIDs []string) error

func (*ReconcileService) ReconcileOrganizations

func (service *ReconcileService) ReconcileOrganizations(ctx context.Context, authorizationHeader string, projectIDs []string) error

type SetupService

type SetupService struct {
	// contains filtered or unexported fields
}

func NewSetupService

func NewSetupService(db *sqlx.DB, gitService *GitService, storage *syfon.Manager, accessChecks *servermw.FenceUserAccessHandler) *SetupService

func (*SetupService) CleanupProjectStorage

func (service *SetupService) CleanupProjectStorage(ctx context.Context, authorizationHeader, organization, project string) error

func (*SetupService) InitializeProject

func (service *SetupService) InitializeProject(ctx context.Context, authorizationHeader, organization, project string, request CalyprProjectSetupRequest) (*CalyprProjectInitializeResponse, error)

func (*SetupService) PopulateStorage

func (service *SetupService) PopulateStorage(ctx context.Context, authorizationHeader, organization, project string, request CalyprProjectStorageRequest) (*CalyprProjectStorageResponse, error)

func (*SetupService) PopulateStorageIntent

func (service *SetupService) PopulateStorageIntent(ctx context.Context, authorizationHeader string, intent *CalyprProjectStorageIntent) error

func (*SetupService) StorageCheck

func (service *SetupService) StorageCheck(ctx context.Context, authorizationHeader, organization, project string) (ProjectIntegrationCheck, error)

type StorageBucket

type StorageBucket = domain.StorageBucket

StorageBucket is an alias for domain.StorageBucket.

type StorageConfig

type StorageConfig = domain.StorageConfig

StorageConfig is an alias for domain.StorageConfig.

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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