Class: Geet::Git::Repository
- Inherits:
-
Object
- Object
- Geet::Git::Repository
- Extended by:
- T::Sig
- 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
- #close_milestone(number) ⇒ Object
- #collaborators ⇒ Object
- #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
-
#initialize(upstream: false, git_client: DEFAULT_GIT_CLIENT, warnings: true, protected_repositories: []) ⇒ Repository
constructor
A new instance of Repository.
- #issues(assignee: nil, milestone: nil) ⇒ Object
- #labels ⇒ Object
- #milestones ⇒ Object
- #parent_path ⇒ Object
- #prs(owner: nil, head: nil, milestone: nil) ⇒ Object
- #upstream? ⇒ Boolean
Constructor Details
#initialize(upstream: false, git_client: DEFAULT_GIT_CLIENT, warnings: true, protected_repositories: []) ⇒ Repository
Returns a new instance of Repository.
30 31 32 33 34 35 36 |
# File 'lib/geet/git/repository.rb', line 30 def initialize(upstream: false, git_client: DEFAULT_GIT_CLIENT, warnings: true, protected_repositories: []) @upstream = upstream @git_client = git_client @api_token = T.let(extract_env_api_token, String) @warnings = warnings @protected_repositories = protected_repositories end |
Instance Method Details
#authenticated_user ⇒ Object
153 154 155 |
# File 'lib/geet/git/repository.rb', line 153 def authenticated_user Github::User.authenticated(api_interface) end |
#close_milestone(number) ⇒ Object
107 108 109 |
# File 'lib/geet/git/repository.rb', line 107 def close_milestone(number) Github::Milestone.close(number, api_interface) end |
#collaborators ⇒ Object
41 42 43 |
# File 'lib/geet/git/repository.rb', line 41 def collaborators Github::User.list_collaborators(api_interface) end |
#create_issue(title, description) ⇒ Object
57 58 59 60 61 62 |
# File 'lib/geet/git/repository.rb', line 57 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 Github::Issue.create(title, description, api_interface) end |
#create_label(name, color) ⇒ Object
71 72 73 |
# File 'lib/geet/git/repository.rb', line 71 def create_label(name, color) Github::Label.create(name, color, api_interface) end |
#create_milestone(title) ⇒ Object
97 98 99 |
# File 'lib/geet/git/repository.rb', line 97 def create_milestone(title) Github::Milestone.create(title, api_interface) end |
#create_pr(title, description, head, base, draft) ⇒ Object
121 122 123 124 125 126 |
# File 'lib/geet/git/repository.rb', line 121 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 Github::PR.create(title, description, head, api_interface, base, draft: draft) end |
#delete_branch(name) ⇒ Object
76 77 78 |
# File 'lib/geet/git/repository.rb', line 76 def delete_branch(name) Github::Branch.delete(name, api_interface) end |
#downstream ⇒ Object
167 168 169 170 171 |
# File 'lib/geet/git/repository.rb', line 167 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
87 88 89 |
# File 'lib/geet/git/repository.rb', line 87 def issues(assignee: nil, milestone: nil) Github::Issue.list(api_interface, assignee:, milestone:) end |
#labels ⇒ Object
46 47 48 |
# File 'lib/geet/git/repository.rb', line 46 def labels Github::Label.list(api_interface) end |
#milestones ⇒ Object
102 103 104 |
# File 'lib/geet/git/repository.rb', line 102 def milestones Github::Milestone.list(api_interface) end |
#parent_path ⇒ Object
143 144 145 146 147 148 |
# File 'lib/geet/git/repository.rb', line 143 def parent_path api_path = "/repos/#{api_interface.repository_path}" response = T.cast(api_interface.send_request(api_path), T::Hash[String, T.untyped]) parent_hash = T.cast(response["parent"], T.nilable(T::Hash[String, T.untyped])) T.cast(parent_hash&.fetch("full_name"), T.nilable(String)) end |
#prs(owner: nil, head: nil, milestone: nil) ⇒ Object
136 137 138 |
# File 'lib/geet/git/repository.rb', line 136 def prs(owner: nil, head: nil, milestone: nil) Github::PR.list(api_interface, owner:, head:, milestone:) end |
#upstream? ⇒ Boolean
160 161 162 |
# File 'lib/geet/git/repository.rb', line 160 def upstream? @upstream end |