class Geet::Git::Repository
remote code is separated in each provider module.
This class represents, for convenience, both the local and the remote repository, but the
def action_on_protected_repository?
def action_on_protected_repository? path = @git_client.path(upstream: @upstream) @protected_repositories.include?(path) end
def api_interface
def api_interface path = @git_client.path(upstream: @upstream) attempt_provider_call(:ApiInterface, :new, @api_token, repo_path: path, upstream: @upstream) end
def attempt_provider_call(class_name, meth, *args)
Attempt to find the provider class and send the specified method, returning a friendly
def attempt_provider_call(class_name, meth, *args) module_name = provider_name.capitalize full_class_name = "Geet::#{module_name}::#{class_name}" # Use const_get directly to trigger Zeitwerk autoloading begin klass = Object.const_get(full_class_name) rescue NameError raise "The class referenced (#{full_class_name}) is not currently supported!" end if !klass.respond_to?(meth) raise "The functionality invoked (#{class_name}.#{meth}) is not currently supported!" end # Can't use ruby2_keywords, because the method definitions use named keyword arguments. # kwargs = args.last.is_a?(Hash) ? args.pop : {} klass.send(meth, *args, **kwargs) end
def authenticated_user
def authenticated_user attempt_provider_call(:User, :authenticated, api_interface) end
def close_milestone(number)
def close_milestone(number) attempt_provider_call(:Milestone, :close, number, api_interface) end
def collaborators
def collaborators attempt_provider_call(:User, :list_collaborators, api_interface) end
def confirm(message)
def confirm(message) full_message = "WARNING! #{message.strip}\nPress Enter to continue, or Ctrl+C to exit now." print full_message gets end
def create_issue(title, description)
def create_issue(title, description) confirm(LOCAL_ACTION_ON_UPSTREAM_REPOSITORY_MESSAGE) if local_action_on_upstream_repository? && @warnings confirm(ACTION_ON_PROTECTED_REPOSITORY_MESSAGE) if action_on_protected_repository? && @warnings attempt_provider_call(:Issue, :create, title, description, api_interface) end
def create_label(name, color)
def create_label(name, color) attempt_provider_call(:Label, :create, name, color, api_interface) end
def create_milestone(title)
def create_milestone(title) attempt_provider_call(:Milestone, :create, title, api_interface) end
def create_pr(title, description, head, base, draft)
def create_pr(title, description, head, base, draft) confirm(LOCAL_ACTION_ON_UPSTREAM_REPOSITORY_MESSAGE) if local_action_on_upstream_repository? && @warnings confirm(ACTION_ON_PROTECTED_REPOSITORY_MESSAGE) if action_on_protected_repository? && @warnings attempt_provider_call(:PR, :create, title, description, head, api_interface, base, draft: draft) end
def delete_branch(name)
def delete_branch(name) attempt_provider_call(:Branch, :delete, name, api_interface) end
def downstream
For cases where it's necessary to work on the downstream repo.
def downstream raise "downstream() is not available on not-upstream repositories!" if !upstream? Git::Repository.new(upstream: false, protected_repositories: @protected_repositories) end
def extract_env_api_token
def extract_env_api_token env_variable_name = "#{provider_name.upcase}_API_TOKEN" ENV[env_variable_name] || raise("#{env_variable_name} not set!") end
def initialize(upstream: false, git_client: DEFAULT_GIT_CLIENT, warnings: true, protected_repositories: [])
`owner/repo`).
protected_repositories: warn when creating an issue/pr on this repositories (entry format:
warnings: disable all the warnings.
def initialize(upstream: false, git_client: DEFAULT_GIT_CLIENT, warnings: true, protected_repositories: []) @upstream = upstream @git_client = git_client @api_token = extract_env_api_token @warnings = warnings @protected_repositories = protected_repositories end
def issues(assignee: nil, milestone: nil)
def issues(assignee: nil, milestone: nil) attempt_provider_call(:Issue, :list, api_interface, assignee:, milestone:) end
def labels
def labels attempt_provider_call(:Label, :list, api_interface) end
def local_action_on_upstream_repository?
def local_action_on_upstream_repository? @git_client.remote_defined?(Utils::GitClient::UPSTREAM_NAME) && !@upstream end
def milestones
def milestones attempt_provider_call(:Milestone, :list, api_interface) end
def provider_name
Bare downcase provider name, eg. `github`
def provider_name @git_client.provider_domain[/(.*)\.\w+/, 1] end
def prs(owner: nil, head: nil, milestone: nil)
def prs(owner: nil, head: nil, milestone: nil) attempt_provider_call(:PR, :list, api_interface, owner:, head:, milestone:) end
def remote
Returns the RemoteRepository instance.
def remote attempt_provider_call(:RemoteRepository, :find, api_interface) end
def upstream?
def upstream? @upstream end