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)



82
83
84
# File 'lib/geet/git/repository.rb', line 82

def authenticated_user
  attempt_provider_call(:User, :authenticated, 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_pr(title, description, head, base: nil) ⇒ Object



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

def create_pr(title, description, head, base: nil)
  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: base)
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

#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



61
62
63
# File 'lib/geet/git/repository.rb', line 61

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

#milestonesObject



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

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

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



76
77
78
# File 'lib/geet/git/repository.rb', line 76

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

#upstream?Boolean

OTHER/CONVENIENCE FUNCTIONALITIES

Returns:

  • (Boolean)


88
89
90
# File 'lib/geet/git/repository.rb', line 88

def upstream?
  @upstream
end