Class: Gitlab::Triage::Policies::BasePolicy

Inherits:
Object
  • Object
show all
Defined in:
lib/gitlab/triage/policies/base_policy.rb

Direct Known Subclasses

RulePolicy, SummaryPolicy

Constant Summary collapse

InvalidPolicyError =
Class.new(StandardError)

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(type, policy_spec, resources, network) ⇒ BasePolicy

Returns a new instance of BasePolicy.



12
13
14
15
16
17
# File 'lib/gitlab/triage/policies/base_policy.rb', line 12

def initialize(type, policy_spec, resources, network)
  @type = type
  @policy_spec = policy_spec
  @resources = resources
  @network = network
end

Instance Attribute Details

#networkObject (readonly)

Returns the value of attribute network.



9
10
11
# File 'lib/gitlab/triage/policies/base_policy.rb', line 9

def network
  @network
end

#policy_specObject (readonly)

Returns the value of attribute policy_spec.



9
10
11
# File 'lib/gitlab/triage/policies/base_policy.rb', line 9

def policy_spec
  @policy_spec
end

#resourcesObject (readonly)

Returns the value of attribute resources.



9
10
11
# File 'lib/gitlab/triage/policies/base_policy.rb', line 9

def resources
  @resources
end

#summaryObject

Returns the value of attribute summary.



10
11
12
# File 'lib/gitlab/triage/policies/base_policy.rb', line 10

def summary
  @summary
end

#typeObject (readonly)

Returns the value of attribute type.



9
10
11
# File 'lib/gitlab/triage/policies/base_policy.rb', line 9

def type
  @type
end

Instance Method Details

#actionsObject



45
46
47
# File 'lib/gitlab/triage/policies/base_policy.rb', line 45

def actions
  @actions ||= policy_spec.fetch(:actions) { {} }
end

#build_issueObject

Raises:

  • (NotImplementedError)


70
71
72
# File 'lib/gitlab/triage/policies/base_policy.rb', line 70

def build_issue
  raise NotImplementedError
end

#build_summaryObject

Raises:

  • (NotImplementedError)


74
75
76
# File 'lib/gitlab/triage/policies/base_policy.rb', line 74

def build_summary
  raise NotImplementedError
end

#comment?Boolean

Returns:

  • (Boolean)


57
58
59
60
# File 'lib/gitlab/triage/policies/base_policy.rb', line 57

def comment?
  # The actual keys are strings
  (actions.keys.map(&:to_sym) - [:summarize, :comment_on_summary, :delete, :issue]).any?
end

#comment_on_summary?Boolean

Returns:

  • (Boolean)


53
54
55
# File 'lib/gitlab/triage/policies/base_policy.rb', line 53

def comment_on_summary?
  actions.key?(:comment_on_summary)
end

#delete?Boolean

Returns:

  • (Boolean)


66
67
68
# File 'lib/gitlab/triage/policies/base_policy.rb', line 66

def delete?
  actions.key?(:delete) && actions[:delete]
end

#issue?Boolean

Returns:

  • (Boolean)


62
63
64
# File 'lib/gitlab/triage/policies/base_policy.rb', line 62

def issue?
  actions.key?(:issue)
end

#nameObject



23
24
25
# File 'lib/gitlab/triage/policies/base_policy.rb', line 23

def name
  @name ||= (policy_spec[:name] || "#{type}-#{object_id}")
end

#sourceObject



27
28
29
30
31
32
33
34
# File 'lib/gitlab/triage/policies/base_policy.rb', line 27

def source
  case type
  when 'epics'
    'groups'
  else
    'projects'
  end
end

#source_id_symObject



36
37
38
39
40
41
42
43
# File 'lib/gitlab/triage/policies/base_policy.rb', line 36

def source_id_sym
  case type
  when 'epics'
    :group_id
  else
    :project_id
  end
end

#summarize?Boolean

Returns:

  • (Boolean)


49
50
51
# File 'lib/gitlab/triage/policies/base_policy.rb', line 49

def summarize?
  actions.key?(:summarize)
end

#validate!Object

Raises:



19
20
21
# File 'lib/gitlab/triage/policies/base_policy.rb', line 19

def validate!
  raise InvalidPolicyError, 'Policies that comment_on_summary must include summarize action' if comment_on_summary? && !summarize?
end