Class: Geet::Git::Repository

Inherits:
Object
  • Object
show all
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

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_userObject

REMOTE FUNCTIONALITIES (ACCOUNT)



96
97
98
# File 'lib/geet/git/repository.rb', line 96

def authenticated_user
  attempt_provider_call(:User, :authenticated, api_interface)
end

#close_milestone(number) ⇒ Object



73
74
75
# File 'lib/geet/git/repository.rb', line 73

def close_milestone(number)
  attempt_provider_call(:Milestone, :close, number, api_interface)
end

#collaboratorsObject

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



77
78
79
80
81
82
# File 'lib/geet/git/repository.rb', line 77

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

#downstreamObject

For cases where it’s necessary to work on the downstream repo.



108
109
110
111
112
# File 'lib/geet/git/repository.rb', line 108

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

#labelsObject



38
39
40
# File 'lib/geet/git/repository.rb', line 38

def labels
  attempt_provider_call(:Label, :list, api_interface)
end

#milestone(number) ⇒ Object



65
66
67
# File 'lib/geet/git/repository.rb', line 65

def milestone(number)
  attempt_provider_call(:Milestone, :find, number, api_interface)
end

#milestonesObject



69
70
71
# File 'lib/geet/git/repository.rb', line 69

def milestones
  attempt_provider_call(:Milestone, :list, api_interface)
end

#prs(owner: nil, head: nil, milestone: nil) ⇒ Object



84
85
86
# File 'lib/geet/git/repository.rb', line 84

def prs(owner: nil, head: nil, milestone: nil)
  attempt_provider_call(:PR, :list, api_interface, owner: owner, head: head, milestone: milestone)
end

#remoteObject

Returns the RemoteRepository instance.



90
91
92
# File 'lib/geet/git/repository.rb', line 90

def remote
  attempt_provider_call(:RemoteRepository, :find, api_interface)
end

#upstream?Boolean

OTHER/CONVENIENCE FUNCTIONALITIES

Returns:

  • (Boolean)


102
103
104
# File 'lib/geet/git/repository.rb', line 102

def upstream?
  @upstream
end