Class: Geet::Services::CreateIssue

Inherits:
AbstractCreateIssue show all
Includes:
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 inherited from AbstractCreateIssue

#initialize

Methods included from Helpers::OsHelper

#execute_command, #open_file_with_default_application

Constructor Details

This class inherits a constructor from Geet::Services::AbstractCreateIssue

Instance Method Details

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

options:

:labels
:milestone:     number or description pattern.
:assignees
:open_browser


19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
# File 'lib/geet/services/create_issue.rb', line 19

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