Sha256: d05a9bdf9af6efd46fe5687e6375baa5663209b86f2668ff146da405ab2f3191

Contents?: true

Size: 634 Bytes

Versions: 9

Compression:

Stored size: 634 Bytes

Contents

# frozen_string_literal: true

module Overcommit::Hook::PreCommit
  # Runs `nginx -t` against any modified Nginx config files.
  #
  # @see https://www.nginx.com/resources/wiki/start/topics/tutorials/commandline/
  class NginxTest < Base
    MESSAGE_REGEX = /^nginx: .+ in (?<file>.+):(?<line>\d+)$/.freeze

    def run
      messages = []

      applicable_files.each do |file|
        result = execute(command + ['-c', file])
        next if result.success?

        messages += extract_messages(
          result.stderr.split("\n").grep(MESSAGE_REGEX),
          MESSAGE_REGEX
        )
      end

      messages
    end
  end
end

Version data entries

9 entries across 9 versions & 2 rubygems

Version Path
overcommit-0.64.1 lib/overcommit/hook/pre_commit/nginx_test.rb
overcommit-0.64.0 lib/overcommit/hook/pre_commit/nginx_test.rb
overcommit-0.63.0 lib/overcommit/hook/pre_commit/nginx_test.rb
overcommit-0.62.0 lib/overcommit/hook/pre_commit/nginx_test.rb
overcommit-0.61.0 lib/overcommit/hook/pre_commit/nginx_test.rb
overcommit-0.60.0 lib/overcommit/hook/pre_commit/nginx_test.rb
overcommit-0.59.1 lib/overcommit/hook/pre_commit/nginx_test.rb
overcommit-0.59.0 lib/overcommit/hook/pre_commit/nginx_test.rb
overcommit-jeygeethanmedia-0.58.0 lib/overcommit/hook/pre_commit/nginx_test.rb