Class: Geet::Services::CreateIssue

Inherits:
Object
  • Object
show all
Extended by:
T::Sig
Includes:
Helpers::OsHelper, Geet::Shared::RepoPermissions, Geet::Shared::Selection
Defined in:
lib/geet/services/create_issue.rb

Constant Summary

Constants included from Geet::Shared::Selection

Geet::Shared::Selection::MANUAL_LIST_SELECTION_FLAG, Geet::Shared::Selection::SELECTION_MULTIPLE, Geet::Shared::Selection::SELECTION_SINGLE, Geet::Shared::Selection::SKIP_LIST_SELECTION_FLAG

Constants included from Geet::Shared::RepoPermissions

Geet::Shared::RepoPermissions::ALL_PERMISSIONS, Geet::Shared::RepoPermissions::PERMISSION_ADMIN, Geet::Shared::RepoPermissions::PERMISSION_NONE, Geet::Shared::RepoPermissions::PERMISSION_READ, Geet::Shared::RepoPermissions::PERMISSION_WRITE

Instance Method Summary collapse

Methods included from Geet::Shared::RepoPermissions

#permission_greater_or_equal_to?

Methods included from Helpers::OsHelper

#execute_command, #open_file_with_default_application

Constructor Details

#initialize(repository, out: $stdout) ⇒ CreateIssue

Returns a new instance of CreateIssue.



16
17
18
19
# File 'lib/geet/services/create_issue.rb', line 16

def initialize(repository, out: $stdout)
  @repository = repository
  @out = out
end

Instance Method Details

#execute(title, description, labels: nil, milestone: nil, assignees: nil, open_browser: false) ⇒ Object



31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
# File 'lib/geet/services/create_issue.rb', line 31

def execute(
    title, description,
    labels: nil, milestone: nil, assignees: nil, open_browser: false
)
  # Inefficient (in worst case, triples the pre issue creation waiting time: #is_collaborator?,
  # #has_permissions?, and the attributes batch), but not trivial to speed up. Not difficult
  # either, but currently not worth spending time.
  #
  # Theoretically, #is_collaborator? could be skipped, but this is cleaner.
  user_has_write_permissions = @repository.authenticated_user.is_collaborator? &&
                               @repository.authenticated_user.has_permission?(PERMISSION_WRITE)

  if user_has_write_permissions
    selected_labels, selected_milestone, selected_assignees = find_and_select_attributes(labels, milestone, assignees)
  end

  issue = create_issue(title, description)

  if user_has_write_permissions
    edit_issue(issue, selected_labels, selected_milestone, selected_assignees)
  end

  if open_browser
    open_file_with_default_application(issue.link)
  else
    @out.puts "Issue address: #{issue.link}"
  end

  issue
end