Class: Agents::GithubAutocommitAgent

Inherits:
Agent
  • Object
show all
Includes:
FormConfigurable
Defined in:
lib/huginn_github_autocommit_agent/github_autocommit_agent.rb

Instance Method Summary collapse

Instance Method Details

#checkObject



177
178
179
# File 'lib/huginn_github_autocommit_agent/github_autocommit_agent.rb', line 177

def check
  commit
end

#default_optionsObject



92
93
94
95
96
97
98
99
100
101
102
103
104
# File 'lib/huginn_github_autocommit_agent/github_autocommit_agent.rb', line 92

def default_options
  {
    'repository' => '',
    'version' => '',
    'commit_message' => '',
    'committer_name' => '',
    'committer_email' => '',
    'emit_events' => 'true',
    'expected_receive_period_in_days' => '2',
    'token' => '',
    'rules' => '[{name: "", owner: "", my_repository: "", pattern: "", file: "" }'
  }
end

#receive(incoming_events) ⇒ Object



168
169
170
171
172
173
174
175
# File 'lib/huginn_github_autocommit_agent/github_autocommit_agent.rb', line 168

def receive(incoming_events)
  incoming_events.each do |event|
    interpolate_with(event) do
      log event
      commit
    end
  end
end

#validate_optionsObject



117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
# File 'lib/huginn_github_autocommit_agent/github_autocommit_agent.rb', line 117

def validate_options
  unless options['repository'].present?
    errors.add(:base, "repository is a required field")
  end

  unless options['version'].present?
    errors.add(:base, "version is a required field")
  end

  unless options['commit_message'].present?
    errors.add(:base, "commit_message is a required field")
  end

  unless options['committer_name'].present?
    errors.add(:base, "committer_name is a required field")
  end

  unless options['committer_email'].present?
    errors.add(:base, "committer_email is a required field")
  end


  unless options['token'].present?
    errors.add(:base, "token is a required field")
  end
#
#      if options[:type] == :array && (options[:values].blank? || !options[:values].is_a?(Array))
#        raise ArgumentError.new('When using :array as :type you need to provide the :values as an Array')
#      end

  if options.has_key?('add_release_details') && boolify(options['add_release_details']).nil?
    errors.add(:base, "if provided, add_release_details must be true or false")
  end

  if options.has_key?('debug') && boolify(options['debug']).nil?
    errors.add(:base, "if provided, debug must be true or false")
  end

  if options.has_key?('emit_events') && boolify(options['emit_events']).nil?
    errors.add(:base, "if provided, emit_events must be true or false")
  end

  unless options['expected_receive_period_in_days'].present? && options['expected_receive_period_in_days'].to_i > 0
    errors.add(:base, "Please provide 'expected_receive_period_in_days' to indicate how many days can pass before this Agent is considered to be not working")
  end
end

#working?Boolean

Returns:

  • (Boolean)


164
165
166
# File 'lib/huginn_github_autocommit_agent/github_autocommit_agent.rb', line 164

def working?
  event_created_within?(options['expected_receive_period_in_days']) && !recent_error_logs?
end