cmd

package
v0.3.0 Latest Latest
Warning

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

Go to latest
Published: Feb 18, 2025 License: MIT Imports: 17 Imported by: 0

Documentation

Index

Constants

View Source
const (
	DefaultConfigFile                   = "gitea-config-wave.yaml"
	DefaultOutputDir                    = ".gitea/defaults"
	DefaultRepoSettingsFile             = "repo_settings.yaml"
	DefaultBranchProtectionsFile        = "branch_protections.yaml"
	DefaultTagProtectionsFile           = "tag_protections.yaml"
	DefaultWebhooksFile                 = "webhooks.yaml"
	DefaultTopicsFile                   = "topics.yaml"
	DefaultTemplatesFile                = "templates.yaml"
	DefaultTemplatesUpdateBranchName    = "gitea-config-wave/sync-templates"
	DefaultTemplatesUpdateCommitMessage = "chore(docs): update PR and issue templates"
	DefaultTemplatesUpdatePRDescription = `` /* 183-byte string literal not displayed */

	DefaultTopicsUpdateStrategy            = UpdateStrategyAppend
	DefaultBranchProtectionsUpdateStrategy = UpdateStrategyAppend
	DefaultTagProtectionsUpdateStrategy    = UpdateStrategyAppend
	DefaultWebhooksUpdateStrategy          = UpdateStrategyAppend
	DefaultTemplatesUpdateStrategy         = UpdateStrategyReplace
)

Variables

View Source
var (
	InfoLogger  = log.New(os.Stdout, "INFO: ", log.Ldate|log.Ltime|log.Lshortfile)
	ErrorLogger = log.New(os.Stderr, "ERROR: ", log.Ldate|log.Ltime|log.Lshortfile)
)
View Source
var Version = "dev"

Functions

func Execute

func Execute()

func GiteaClient

func GiteaClient(cfg *Config) (*gitea.Client, error)

GiteaClient creates a new Gitea client with configuration

func ReadYAMLFile

func ReadYAMLFile(filePath string, out interface{}) error

func WriteYAMLFile

func WriteYAMLFile(filePath string, data interface{}) error

Types

type BranchProtection

type BranchProtection struct {
	BranchName                    string   `yaml:"branch_name"`
	RuleName                      string   `yaml:"rule_name"`
	EnablePush                    bool     `yaml:"enable_push"`
	EnablePushWhitelist           bool     `yaml:"enable_push_whitelist"`
	PushWhitelistUsernames        []string `yaml:"push_whitelist_usernames"`
	PushWhitelistTeams            []string `yaml:"push_whitelist_teams"`
	PushWhitelistDeployKeys       bool     `yaml:"push_whitelist_deploy_keys"`
	EnableMergeWhitelist          bool     `yaml:"enable_merge_whitelist"`
	MergeWhitelistUsernames       []string `yaml:"merge_whitelist_usernames"`
	MergeWhitelistTeams           []string `yaml:"merge_whitelist_teams"`
	EnableStatusCheck             bool     `yaml:"enable_status_check"`
	StatusCheckContexts           []string `yaml:"status_check_contexts"`
	RequiredApprovals             int64    `yaml:"required_approvals"`
	EnableApprovalsWhitelist      bool     `yaml:"enable_approvals_whitelist"`
	ApprovalsWhitelistUsernames   []string `yaml:"approvals_whitelist_usernames"`
	ApprovalsWhitelistTeams       []string `yaml:"approvals_whitelist_teams"`
	BlockOnRejectedReviews        bool     `yaml:"block_on_rejected_reviews"`
	BlockOnOfficialReviewRequests bool     `yaml:"block_on_official_review_requests"`
	BlockOnOutdatedBranch         bool     `yaml:"block_on_outdated_branch"`
	DismissStaleApprovals         bool     `yaml:"dismiss_stale_approvals"`
	RequireSignedCommits          bool     `yaml:"require_signed_commits"`
	ProtectedFilePatterns         string   `yaml:"protected_file_patterns,omitempty"`
	UnprotectedFilePatterns       string   `yaml:"unprotected_file_patterns,omitempty"`
}

type BranchProtectionConfig

type BranchProtectionConfig struct {
	Rules []BranchProtection `yaml:"rules"`
}

type BranchProtectionsHandler

type BranchProtectionsHandler struct{}

func (*BranchProtectionsHandler) Enabled

func (h *BranchProtectionsHandler) Enabled() bool

func (*BranchProtectionsHandler) Load

func (h *BranchProtectionsHandler) Load(path string) (interface{}, error)

func (*BranchProtectionsHandler) Name

func (h *BranchProtectionsHandler) Name() string

func (*BranchProtectionsHandler) Path

func (h *BranchProtectionsHandler) Path() string

func (*BranchProtectionsHandler) Pull

func (h *BranchProtectionsHandler) Pull(client *gitea.Client, owner, repo string) (interface{}, error)

func (*BranchProtectionsHandler) Push

func (h *BranchProtectionsHandler) Push(client *gitea.Client, owner, repo string, data interface{}) error

type ChangeFileOperation added in v0.3.0

type ChangeFileOperation struct {
	Content   string            `json:"content"`
	FromPath  string            `json:"from_path"`
	Operation FileOperationType `json:"operation"`
	Path      string            `json:"path"`
	SHA       string            `json:"sha"`
}

type ChangeFilesOptions added in v0.3.0

type ChangeFilesOptions struct {
	Author    *gitea.Identity          `json:"author,omitempty"`
	Branch    string                   `json:"branch"`
	Committer *gitea.Identity          `json:"committer,omitempty"`
	Dates     *gitea.CommitDateOptions `json:"dates,omitempty"`
	Files     []ChangeFileOperation    `json:"files"`
	Message   string                   `json:"message"`
	NewBranch string                   `json:"new_branch,omitempty"`
	Signoff   bool                     `json:"signoff,omitempty"`
}

type Config

type Config struct {
	GiteaURL   string `yaml:"gitea_url" validate:"required,url"`
	GiteaToken string `yaml:"gitea_token" validate:"required"`
	Config     struct {
		OutputDir string `yaml:"output_dir" validate:"omitempty,dirpath"`
	} `yaml:"config"`
	Pull struct {
		RepoSettings      bool `yaml:"repo_settings"`
		Topics            bool `yaml:"topics"`
		BranchProtections bool `yaml:"branch_protections"`
		TagProtections    bool `yaml:"tag_protections"`
		Webhooks          bool `yaml:"webhooks"`
		Templates         bool `yaml:"templates"`
	} `yaml:"pull"`
	Push struct {
		RepoSettings      bool `yaml:"repo_settings"`
		Topics            bool `yaml:"topics"`
		BranchProtections bool `yaml:"branch_protections"`
		TagProtections    bool `yaml:"tag_protections"`
		Webhooks          bool `yaml:"webhooks"`
		Templates         bool `yaml:"templates"`
	} `yaml:"push"`
	Targets struct {
		Autodiscover       bool     `yaml:"autodiscover"`
		Organization       string   `yaml:"organization"`
		AutodiscoverFilter string   `yaml:"autodiscover_filter"`
		Repos              []string `yaml:"repos"`
		ExcludeRepos       []string `yaml:"exclude_repos"`
	} `yaml:"targets"`
	DryRun                          bool           `yaml:"dry_run"`
	TopicsUpdateStrategy            UpdateStrategy `yaml:"topics_update_strategy"`
	BranchProtectionsUpdateStrategy UpdateStrategy `yaml:"branch_protections_update_strategy"`
	TagProtectionsUpdateStrategy    UpdateStrategy `yaml:"tag_protections_update_strategy"`
	WebhooksUpdateStrategy          UpdateStrategy `yaml:"webhooks_update_strategy"`
}

func LoadConfig

func LoadConfig(filePath string) (*Config, error)

type ConfigHandler

type ConfigHandler interface {
	Name() string
	Path() string
	Enabled() bool
	Pull(client *gitea.Client, owner, repo string) (interface{}, error)
	Push(client *gitea.Client, owner, repo string, data interface{}) error
	Load(path string) (interface{}, error)
}

type FileOperationType added in v0.3.0

type FileOperationType string
const (
	FileOperationTypeCreate FileOperationType = "create"
	FileOperationTypeUpdate FileOperationType = "update"
	FileOperationTypeDelete FileOperationType = "delete"
)

type FileType added in v0.3.0

type FileType string
const (
	FileTypeIssueTemplate       FileType = "ISSUE_TEMPLATE"
	FileTypeIssueConfig         FileType = "ISSUE_CONFIG"
	FileTypePullRequestTemplate FileType = "PR_TEMPLATE"
)

type RepoSettings

type RepoSettings struct {
	DefaultBranch                 *string                `yaml:"default_branch,omitempty"`
	HasIssues                     *bool                  `yaml:"has_issues,omitempty"`
	ExternalTracker               *gitea.ExternalTracker `yaml:"external_tracker,omitempty"`
	HasWiki                       *bool                  `yaml:"has_wiki,omitempty"`
	HasPullRequests               *bool                  `yaml:"has_pull_requests,omitempty"`
	HasProjects                   *bool                  `yaml:"has_projects,omitempty"`
	HasReleases                   *bool                  `yaml:"has_releases,omitempty"`
	HasPackages                   *bool                  `yaml:"has_packages,omitempty"`
	HasActions                    *bool                  `yaml:"has_actions,omitempty"`
	IgnoreWhitespaceConflicts     *bool                  `yaml:"ignore_whitespace_conflicts,omitempty"`
	AllowMergeCommits             *bool                  `yaml:"allow_merge_commits,omitempty"`
	AllowRebase                   *bool                  `yaml:"allow_rebase,omitempty"`
	AllowRebaseExplicit           *bool                  `yaml:"allow_rebase_explicit,omitempty"`
	AllowSquashMerge              *bool                  `yaml:"allow_squash_merge,omitempty"`
	DefaultDeleteBranchAfterMerge *bool                  `yaml:"default_delete_branch_after_merge,omitempty"`
	DefaultMergeStyle             *string                `yaml:"default_merge_style,omitempty"`
	DefaultAllowMaintainerEdit    *bool                  `yaml:"default_allow_maintainer_edit,omitempty"`
	Topics                        []string               `yaml:"topics,omitempty"`
}

type RepoSettingsHandler

type RepoSettingsHandler struct{}

func (*RepoSettingsHandler) Enabled

func (h *RepoSettingsHandler) Enabled() bool

func (*RepoSettingsHandler) Load

func (h *RepoSettingsHandler) Load(path string) (interface{}, error)

func (*RepoSettingsHandler) Name

func (h *RepoSettingsHandler) Name() string

func (*RepoSettingsHandler) Path

func (h *RepoSettingsHandler) Path() string

func (*RepoSettingsHandler) Pull

func (h *RepoSettingsHandler) Pull(client *gitea.Client, owner, repo string) (interface{}, error)

func (*RepoSettingsHandler) Push

func (h *RepoSettingsHandler) Push(client *gitea.Client, owner, repo string, data interface{}) error

type TemplateFile added in v0.3.0

type TemplateFile struct {
	Path    string `yaml:"path"`
	Content string `yaml:"content"`
}

func (TemplateFile) MarshalYAML added in v0.3.0

func (t TemplateFile) MarshalYAML() (interface{}, error)

type TemplatesConfig added in v0.3.0

type TemplatesConfig struct {
	IssueTemplates []TemplateFile `yaml:"issue_templates,omitempty"`
	IssueConfigs   []TemplateFile `yaml:"issue_configs,omitempty"`
	PRTemplates    []TemplateFile `yaml:"pr_templates,omitempty"`
}

type TemplatesHandler added in v0.3.0

type TemplatesHandler struct{}

func (*TemplatesHandler) Enabled added in v0.3.0

func (h *TemplatesHandler) Enabled() bool

func (*TemplatesHandler) Load added in v0.3.0

func (h *TemplatesHandler) Load(path string) (interface{}, error)

func (*TemplatesHandler) Name added in v0.3.0

func (h *TemplatesHandler) Name() string

func (*TemplatesHandler) Path added in v0.3.0

func (h *TemplatesHandler) Path() string

func (*TemplatesHandler) Pull added in v0.3.0

func (h *TemplatesHandler) Pull(client *gitea.Client, owner, repo string) (interface{}, error)

func (*TemplatesHandler) Push added in v0.3.0

func (h *TemplatesHandler) Push(client *gitea.Client, owner, repo string, data interface{}) error

type TopicsConfig

type TopicsConfig struct {
	Topics []string `yaml:"topics"`
}

type TopicsHandler

type TopicsHandler struct{}

func (*TopicsHandler) Enabled

func (h *TopicsHandler) Enabled() bool

func (*TopicsHandler) Load

func (h *TopicsHandler) Load(path string) (interface{}, error)

func (*TopicsHandler) Name

func (h *TopicsHandler) Name() string

func (*TopicsHandler) Path

func (h *TopicsHandler) Path() string

func (*TopicsHandler) Pull

func (h *TopicsHandler) Pull(client *gitea.Client, owner, repo string) (interface{}, error)

func (*TopicsHandler) Push

func (h *TopicsHandler) Push(client *gitea.Client, owner, repo string, data interface{}) error

type UpdateStrategy added in v0.2.0

type UpdateStrategy string
const (
	UpdateStrategyReplace UpdateStrategy = "replace"
	UpdateStrategyMerge   UpdateStrategy = "merge"
	UpdateStrategyAppend  UpdateStrategy = "append"
)

type Webhook

type Webhook struct {
	ID                  int64             `yaml:"id"`
	Type                string            `yaml:"type"`
	URL                 string            `yaml:"url,omitempty"`
	BranchFilter        string            `yaml:"branch_filter,omitempty"`
	Config              map[string]string `yaml:"config"`
	Events              []string          `yaml:"events"`
	Active              bool              `yaml:"active"`
	AuthorizationHeader string            `yaml:"authorization_header,omitempty"`
}

type WebhookConfig

type WebhookConfig struct {
	Hooks []Webhook `yaml:"hooks"`
}

type WebhooksHandler

type WebhooksHandler struct{}

func (*WebhooksHandler) Enabled

func (h *WebhooksHandler) Enabled() bool

func (*WebhooksHandler) Load

func (h *WebhooksHandler) Load(path string) (interface{}, error)

func (*WebhooksHandler) Name

func (h *WebhooksHandler) Name() string

func (*WebhooksHandler) Path

func (h *WebhooksHandler) Path() string

func (*WebhooksHandler) Pull

func (h *WebhooksHandler) Pull(client *gitea.Client, owner, repo string) (interface{}, error)

func (*WebhooksHandler) Push

func (h *WebhooksHandler) Push(client *gitea.Client, owner, repo string, data interface{}) error

Jump to

Keyboard shortcuts

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