Class: Geet::Git::Repository
- Inherits:
-
Object
- Object
- Geet::Git::Repository
- Defined in:
- lib/geet/git/repository.rb
Overview
This class represents, for convenience, both the local and the remote repository, but the remote code is separated in each provider module.
Constant Summary collapse
- LOCAL_ACTION_ON_UPSTREAM_REPOSITORY_MESSAGE =
<<~STR The action will be performed on a fork, but an upstream repository has been found! STR
- ACTION_ON_PROTECTED_REPOSITORY_MESSAGE =
<<~STR This action will be performed on a protected repository! STR
- DEFAULT_GIT_CLIENT =
Geet::Utils::GitClient.new
Instance Method Summary collapse
-
#authenticated_user ⇒ Object
REMOTE FUNCTIONALITIES (ACCOUNT).
- #close_milestone(number) ⇒ Object
-
#collaborators ⇒ Object
REMOTE FUNCTIONALITIES (REPOSITORY).
- #create_issue(title, description) ⇒ Object
- #create_label(name, color) ⇒ Object
- #create_milestone(title) ⇒ Object
- #create_pr(title, description, head, base, draft) ⇒ Object
- #delete_branch(name) ⇒ Object
-
#downstream ⇒ Object
For cases where it’s necessary to work on the downstream repo.
-
#initialize(upstream: false, git_client: DEFAULT_GIT_CLIENT, warnings: true, protected_repositories: []) ⇒ Repository
constructor
warnings: disable all the warnings.
- #issues(assignee: nil, milestone: nil) ⇒ Object
- #labels ⇒ Object
- #milestones ⇒ Object
- #prs(owner: nil, head: nil, milestone: nil) ⇒ Object
-
#remote ⇒ Object
Returns the RemoteRepository instance.
-
#upstream? ⇒ Boolean
OTHER/CONVENIENCE FUNCTIONALITIES.
Constructor Details
#initialize(upstream: false, git_client: DEFAULT_GIT_CLIENT, warnings: true, protected_repositories: []) ⇒ Repository
warnings: disable all the warnings. protected_repositories: warn when creating an issue/pr on this repositories (entry format:
`owner/repo`).
24 25 26 27 28 29 30 |
# File 'lib/geet/git/repository.rb', line 24 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 |
Instance Method Details
#authenticated_user ⇒ Object
REMOTE FUNCTIONALITIES (ACCOUNT)
92 93 94 |
# File 'lib/geet/git/repository.rb', line 92 def authenticated_user attempt_provider_call(:User, :authenticated, api_interface) end |
#close_milestone(number) ⇒ Object
69 70 71 |
# File 'lib/geet/git/repository.rb', line 69 def close_milestone(number) attempt_provider_call(:Milestone, :close, number, api_interface) end |
#collaborators ⇒ Object
REMOTE FUNCTIONALITIES (REPOSITORY)
34 35 36 |
# File 'lib/geet/git/repository.rb', line 34 def collaborators attempt_provider_call(:User, :list_collaborators, api_interface) end |
#create_issue(title, description) ⇒ Object
42 43 44 45 46 47 |
# File 'lib/geet/git/repository.rb', line 42 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 |
#create_label(name, color) ⇒ Object
49 50 51 |
# File 'lib/geet/git/repository.rb', line 49 def create_label(name, color) attempt_provider_call(:Label, :create, name, color, api_interface) end |
#create_milestone(title) ⇒ Object
61 62 63 |
# File 'lib/geet/git/repository.rb', line 61 def create_milestone(title) attempt_provider_call(:Milestone, :create, title, api_interface) end |
#create_pr(title, description, head, base, draft) ⇒ Object
73 74 75 76 77 78 |
# File 'lib/geet/git/repository.rb', line 73 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 |
#delete_branch(name) ⇒ Object
53 54 55 |
# File 'lib/geet/git/repository.rb', line 53 def delete_branch(name) attempt_provider_call(:Branch, :delete, name, api_interface) end |
#downstream ⇒ Object
For cases where it’s necessary to work on the downstream repo.
104 105 106 107 108 |
# File 'lib/geet/git/repository.rb', line 104 def downstream raise "downstream() is not available on not-upstream repositories!" if !upstream? Git::Repository.new(upstream: false, protected_repositories: @protected_repositories) end |
#issues(assignee: nil, milestone: nil) ⇒ Object
57 58 59 |
# File 'lib/geet/git/repository.rb', line 57 def issues(assignee: nil, milestone: nil) attempt_provider_call(:Issue, :list, api_interface, assignee: assignee, milestone: milestone) end |
#labels ⇒ Object
38 39 40 |
# File 'lib/geet/git/repository.rb', line 38 def labels attempt_provider_call(:Label, :list, api_interface) end |
#milestones ⇒ Object
65 66 67 |
# File 'lib/geet/git/repository.rb', line 65 def milestones attempt_provider_call(:Milestone, :list, api_interface) end |
#prs(owner: nil, head: nil, milestone: nil) ⇒ Object
80 81 82 |
# File 'lib/geet/git/repository.rb', line 80 def prs(owner: nil, head: nil, milestone: nil) attempt_provider_call(:PR, :list, api_interface, owner: owner, head: head, milestone: milestone) end |
#remote ⇒ Object
Returns the RemoteRepository instance.
86 87 88 |
# File 'lib/geet/git/repository.rb', line 86 def remote attempt_provider_call(:RemoteRepository, :find, api_interface) end |
#upstream? ⇒ Boolean
OTHER/CONVENIENCE FUNCTIONALITIES
98 99 100 |
# File 'lib/geet/git/repository.rb', line 98 def upstream? @upstream end |