Git hook to send email notification on repo changes

前端 未结 11 1916
情深已故
情深已故 2020-11-28 01:33

How do I configure the appropriate Git hook to send a summary email whenever a set of changes is pushed to the upstream repository?

11条回答
  •  庸人自扰
    2020-11-28 02:26

    You can use pre-commit:

    #!/usr/bin/env ruby
    
    require 'mail'
    
    Mail.defaults do
      delivery_method :smtp,
        address: 'smtp.gmail.com',
        port: 587,
        user_name: '...',
        password: '...',
        authentication: 'plain',
        enable_starttls_auto: true
    end
    
    changes=`git diff --cached --unified=0 Gemfile Bowerfile`
    
    unless changes.empty?
      Mail.deliver do
        from     '...'
        to       '...'
        subject  '[PROJECT] Plese confirm team can use libraries'
        body     changes
      end
    end
    

    Install:

    cd project
    cp pre-commit .git/hooks
    chmod +x .git/hooks/pre-commit
    gem install mail
    

    Test:

    echo "# some change" >> Gemfile && git commit -m 'some change' Gemfile
    

提交回复
热议问题