Hi.

I was wondering what kind of precommit hooks are you guys using?

Here's what I've come up to in last hour:

$ cat .hg/hgrc | grep -A 1 hooks
[hooks]
pretxncommit.puppet = .hg/check_puppet.rb

$ cat .hg/check_puppet.rb

#!/usr/bin/ruby
def puppet_parser_validate(file)
    if !system('puppet parser validate ' + file + ' > /dev/null 2>&1')
        print('Syntax error in file: ' + file + "\n")
        system('puppet parser validate ' + file)
        exit(1)
    end
end

def puppet_lint(file)
    if !system('puppet-lint --no-80chars-check ' + file + ' > /dev/null
2>&1')
        print('Coding style error in file: ' + file + "\n")
        system('puppet-lint --no-80chars-check ' + file)
        exit(1)
    end
end

def puppet_erb_check(file)
    if !system('erb -x -T \'-\' ' + file + ' | ruby -c > /dev/null 2>&1')
        print('Syntax error in erb template: ' + file + "\n")
        system('erb -x -T \'-\' ' + file + ' | ruby -c')
        exit(1)
    end
end

# go through list of files, and call adequate checks
IO.popen('hg status').readlines.each { |file|
    file.sub!(/^\w (.*)\n/,'\1')
    if file.match('.pp$')
        puppet_parser_validate file
        puppet_lint file
    elsif file.match('.erb$')
        puppet_erb_check file
    end
}




These are very basic checks, but I would like to implement also
something like checking if file from 'source =>' is present in module's
files/ or if template from manifest is present in templates/ and things
like that.

Do you have any other ideas?




-- 
Jakov Sosic
www.srce.unizg.hr

-- 
You received this message because you are subscribed to the Google Groups 
"Puppet Users" group.
To post to this group, send email to puppet-users@googlegroups.com.
To unsubscribe from this group, send email to 
puppet-users+unsubscr...@googlegroups.com.
For more options, visit this group at 
http://groups.google.com/group/puppet-users?hl=en.

Reply via email to