Class: Vx::ServiceConnector::Model::Payload

Inherits:
Struct
  • Object
show all
Defined in:
lib/vx/service_connector/model.rb

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Instance Attribute Details

#authorObject

Returns the value of attribute author

Returns:

  • (Object)

    the current value of author



17
18
19
# File 'lib/vx/service_connector/model.rb', line 17

def author
  @author
end

#author_emailObject

Returns the value of attribute author_email

Returns:

  • (Object)

    the current value of author_email



17
18
19
# File 'lib/vx/service_connector/model.rb', line 17

def author_email
  @author_email
end

#branchObject

Returns the value of attribute branch

Returns:

  • (Object)

    the current value of branch



17
18
19
# File 'lib/vx/service_connector/model.rb', line 17

def branch
  @branch
end

#branch_labelObject

Returns the value of attribute branch_label

Returns:

  • (Object)

    the current value of branch_label



17
18
19
# File 'lib/vx/service_connector/model.rb', line 17

def branch_label
  @branch_label
end

#foreign_pull_request?Object

Returns the value of attribute foreign_pull_request?

Returns:

  • (Object)

    the current value of foreign_pull_request?



17
18
19
# File 'lib/vx/service_connector/model.rb', line 17

def foreign_pull_request?
  @foreign_pull_request?
end

#internal_pull_request?Object

Returns the value of attribute internal_pull_request?

Returns:

  • (Object)

    the current value of internal_pull_request?



17
18
19
# File 'lib/vx/service_connector/model.rb', line 17

def internal_pull_request?
  @internal_pull_request?
end

#messageObject

Returns the value of attribute message

Returns:

  • (Object)

    the current value of message



17
18
19
# File 'lib/vx/service_connector/model.rb', line 17

def message
  @message
end

#pull_request_numberObject

Returns the value of attribute pull_request_number

Returns:

  • (Object)

    the current value of pull_request_number



17
18
19
# File 'lib/vx/service_connector/model.rb', line 17

def pull_request_number
  @pull_request_number
end

#shaObject

Returns the value of attribute sha

Returns:

  • (Object)

    the current value of sha



17
18
19
# File 'lib/vx/service_connector/model.rb', line 17

def sha
  @sha
end

#skipObject

Returns the value of attribute skip

Returns:

  • (Object)

    the current value of skip



17
18
19
# File 'lib/vx/service_connector/model.rb', line 17

def skip
  @skip
end

#tagObject

Returns the value of attribute tag

Returns:

  • (Object)

    the current value of tag



17
18
19
# File 'lib/vx/service_connector/model.rb', line 17

def tag
  @tag
end

#web_urlObject

Returns the value of attribute web_url

Returns:

  • (Object)

    the current value of web_url



17
18
19
# File 'lib/vx/service_connector/model.rb', line 17

def web_url
  @web_url
end

Class Method Details

.from_hash(params) ⇒ Object



87
88
89
90
91
92
93
# File 'lib/vx/service_connector/model.rb', line 87

def from_hash(params)
  payload = Payload.new
  payload.members.each do |m|
    payload[m] = params.key?(m) ? params[m] : params[m.to_s]
  end
  payload
end

Instance Method Details

#ignore?Boolean

Returns:

  • (Boolean)


74
75
76
# File 'lib/vx/service_connector/model.rb', line 74

def ignore?
  !!(skip || message.to_s =~ PAYLOAD_IGNORE_RE)
end

#perform?(restriction = nil) ⇒ Boolean

Returns:

  • (Boolean)


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
61
62
63
64
65
66
67
68
69
70
71
72
# File 'lib/vx/service_connector/model.rb', line 35

def perform?(restriction = nil)
  if ignore?
    # skip build
    return false
  end

  if restriction.nil?
    # skip internal pr or tag
    # allow all pushes and foreign pr
    return !(internal_pull_request? or tag?)
  end

  if restriction.is_a?(Hash)
    branch_re = restriction[:branch]
    pr        = restriction[:pull_request]

    if !branch_re && internal_pull_request?
      return false
    end

    if branch_re && Regexp.new(branch_re).match(branch)
      # if branch name matches
      # we're already building it,
      # so we should ignore prs.
      return !internal_pull_request?
    end

    if pr && pull_request?
      return true
    end

    return false
  end

  # unknown restriction
  # denied
  return false
end

#pull_request?Boolean

Returns:

  • (Boolean)


82
83
84
# File 'lib/vx/service_connector/model.rb', line 82

def pull_request?
  internal_pull_request? or foreign_pull_request?
end

#tag?Boolean

Returns:

  • (Boolean)


78
79
80
# File 'lib/vx/service_connector/model.rb', line 78

def tag?
  !!tag
end

#to_hashObject



31
32
33
# File 'lib/vx/service_connector/model.rb', line 31

def to_hash
  to_h
end