r75 - in scripts: . git-tools redmine-tools
Author: tchemit Date: 2014-05-25 10:34:09 +0200 (Sun, 25 May 2014) New Revision: 75 Url: http://forge.codelutin.com/projects/adminsys/repository/revisions/75 Log: refs #5074 create a specific package for git scripts + add scripts to change authors of a git repository Added: scripts/git-tools/ scripts/git-tools/git-change-authors.sh scripts/git-tools/git-get-authors.sh scripts/git-tools/git-multimail-run.py Removed: scripts/redmine-tools/git-multimail-run.py Modified: scripts/redmine-tools/redmine-post-commit-git.sh Added: scripts/git-tools/git-change-authors.sh =================================================================== --- scripts/git-tools/git-change-authors.sh (rev 0) +++ scripts/git-tools/git-change-authors.sh 2014-05-25 08:34:09 UTC (rev 75) @@ -0,0 +1,82 @@ +#! /bin/bash + +############################################################################### +# To change some authors names and emails in a git repository +# Usage git-changes-authors.sh path_to_git_repository +# +# Author : Tony CHEMIT <chemit@codelutin.com> +# +############################################################################### +# History +# +# 2014-05-25 tchemit@codelutin.com +# - initial version +############################################################################### + +if [ ! $# -eq 1 ]; then + echo "usage : $0 path_to_git_repository" + exit 0 +fi + +if [ ! -d $1 ]; then + echo $1 does not exists + exit 0 +fi + +repo=$(readlink -e $1) + +if [ ! -d $repo/refs ]; then + echo "$repo/refs does not exists (probably not a git repository)" + exit 0 +fi + + +change_email() { + oldName=$1 + newCommiterName=$2 + newCommiterEmail=$3 + newAuthorName=$2 + newAuthorEmail=$3 +} + +authors_file=$(basename $repo).authors + +script="/tmp/git-change-authors-script.sh" + +cat << EOF > $script +#! /bin/bash + +cd $repo + +git filter-branch --force --env-filter ' +EOF + +while read line +do + oldName=$(echo $line | cut -d':' -f1) + newName=$(echo $line | cut -d':' -f2) + email=$(echo $line | cut -d':' -f3) + echo "Will change author $oldName to ($newName : $email)"; + + cat << EOF >> $script +if [ "\$GIT_COMMITTER_NAME" = "$oldName" ]; +then + GIT_COMMITTER_NAME="$newName"; + GIT_COMMITTER_EMAIL="$email"; + GIT_AUTHOR_NAME="$newName"; + GIT_AUTHOR_EMAIL="$email"; +fi +EOF + +done < $authors_file + +cat << EOF >> $script +' -- --all +EOF + +chmod +x $script +echo Execute script $script +. $script +rm -rf $script + + Property changes on: scripts/git-tools/git-change-authors.sh ___________________________________________________________________ Added: svn:executable + * Added: scripts/git-tools/git-get-authors.sh =================================================================== --- scripts/git-tools/git-get-authors.sh (rev 0) +++ scripts/git-tools/git-get-authors.sh 2014-05-25 08:34:09 UTC (rev 75) @@ -0,0 +1,37 @@ +#! /bin/bash + +############################################################################### +# To obtain all authors of a git repository +# Usage git-get-all-authors.sh path_to_git_repository +# +# Author : Tony CHEMIT <chemit@codelutin.com> +# +############################################################################### +# History +# +# 2014-05-25 tchemit@codelutin.com +# - initial version +############################################################################### + +if [ ! $# -eq 1 ]; then + echo "usage : $0 path_to_git_repository" + exit 0 +fi + +if [ ! -d $1 ]; then + echo $1 does not exists + exit 0 +fi + +repo=$(readlink -e $1) + +if [ ! -d $repo/refs ]; then + echo "$repo/refs does not exists (probably not a git repository)" + exit 0 +fi + + +file=$(pwd)/$(basename $repo).authors + +(cd $repo ; git log --format='%aN:%aN:%ae' | sort -u > $file) +echo "authors saved in $file" \ No newline at end of file Property changes on: scripts/git-tools/git-get-authors.sh ___________________________________________________________________ Added: svn:executable + * Copied: scripts/git-tools/git-multimail-run.py (from rev 74, scripts/redmine-tools/git-multimail-run.py) =================================================================== --- scripts/git-tools/git-multimail-run.py (rev 0) +++ scripts/git-tools/git-multimail-run.py 2014-05-25 08:34:09 UTC (rev 75) @@ -0,0 +1,139 @@ +#! /usr/bin/env python2 + +"""Example post-receive hook based on git-multimail. + +This script is a simple example of a post-receive hook implemented +using git_multimail.py as a Python module. It is intended to be +customized before use; see the comments in the script to help you get +started. + +It is possible to use git_multimail.py itself as a post-receive or +update hook, configured via git config settings and/or command-line +parameters. But for more flexibility, it can also be imported as a +Python module by a custom post-receive script as done here. The +latter has the following advantages: + +* The tool's behavior can be customized using arbitrary Python code, + without having to edit git_multimail.py. + +* Configuration settings can be read from other sources; for example, + user names and email addresses could be read from LDAP or from a + database. Or the settings can even be hardcoded in the importing + Python script, if this is preferred. + +This script is a very basic example of how to use git_multimail.py as +a module. The comments below explain some of the points at which the +script's behavior could be changed or customized. + +""" + +import sys +import os + +# If necessary, add the path to the directory containing +# git_multimail.py to the Python path as follows. (This is not +# necessary if git_multimail.py is in the same directory as this +# script): + +LIBDIR = '/usr/local/lib/python2.6/dist-packages/git_multimail-1.0.0-py2.6.egg' +sys.path.insert(0, LIBDIR) + +import git_multimail + +# It is possible to modify the output templates here; e.g.: + +#git_multimail.FOOTER_TEMPLATE = """\ +# +#-- \n\ +#This email was generated by the wonderful git-multimail tool. +#""" + +# Specify which "git config" section contains the configuration for +# git-multimail: +config = git_multimail.Config('multimailhook') + +forge = config.get('forge') +reponame = config.get('reponame') + + +git_multimail.REFCHANGE_INTRO_TEMPLATE = """\ +This is an automated email from the git hooks/post-receive script. + +New change to %(refname_type)s %(short_refname)s in repository %(repo_shortname)s. + +See http://git.{}/{}.git + +""".format(forge, reponame) + +git_multimail.REF_CREATED_SUBJECT_TEMPLATE = ( + '%(refname_type)s %(short_refname)s created' + ' (now %(newrev_short)s)' + ) +git_multimail.REF_UPDATED_SUBJECT_TEMPLATE = ( + '%(refname_type)s %(short_refname)s updated' + ' (%(oldrev_short)s -> %(newrev_short)s)' + ) +git_multimail.REF_DELETED_SUBJECT_TEMPLATE = ( + '%(refname_type)s %(short_refname)s deleted' + ' (was %(oldrev_short)s)' + ) + +git_multimail.REVISION_HEADER_TEMPLATE = """\ +Date: %(send_date)s +To: %(recipients)s +Subject: %(num)02d/%(tot)02d: %(oneline)s +MIME-Version: 1.0 +Content-Type: text/plain; charset=%(charset)s +Content-Transfer-Encoding: 8bit +From: %(fromaddr)s +Reply-To: %(reply_to)s +In-Reply-To: %(reply_to_msgid)s +References: %(reply_to_msgid)s +X-Git-Host: %(fqdn)s +X-Git-Repo: %(repo_shortname)s +X-Git-Refname: %(refname)s +X-Git-Reftype: %(refname_type)s +X-Git-Rev: %(rev)s +Auto-Submitted: auto-generated +""" + +git_multimail.REVISION_INTRO_TEMPLATE = """\ +This is an automated email from the git hooks/post-receive script. + +New commit to %(refname_type)s %(short_refname)s in repository %(repo_shortname)s. + +See http://git.{}/{}.git + +""".format(forge, reponame) + + +# Select the type of environment: +environment = git_multimail.GenericEnvironment(config=config) + +# Choose the method of sending emails based on the git config: +mailer = git_multimail.choose_mailer(config, environment) + +# Alternatively, you may hardcode the mailer using code like one of +# the following: + +# Use "/usr/sbin/sendmail -oi -t" to send emails. The envelopesender +# argument is optional: +#mailer = git_multimail.SendMailer( +# command=['/usr/sbin/sendmail', '-oi', '-t'], +# envelopesender='git-repo@example.com', +# ) + +# Use Python's smtplib to send emails. Both arguments are required. +#mailer = git_multimail.SMTPMailer( +# envelopesender='git-repo@example.com', +# # The smtpserver argument can also include a port number; e.g., +# # smtpserver='mail.example.com:25' +# smtpserver='mail.example.com', +# ) + +# OutputMailer is intended only for testing; it writes the emails to +# the specified file stream. +#mailer = git_multimail.OutputMailer(sys.stdout) + +# Read changes from stdin and send notification emails: +git_multimail.run_as_post_receive_hook(environment, mailer) Deleted: scripts/redmine-tools/git-multimail-run.py =================================================================== --- scripts/redmine-tools/git-multimail-run.py 2014-05-25 06:09:19 UTC (rev 74) +++ scripts/redmine-tools/git-multimail-run.py 2014-05-25 08:34:09 UTC (rev 75) @@ -1,139 +0,0 @@ -#! /usr/bin/env python2 - -"""Example post-receive hook based on git-multimail. - -This script is a simple example of a post-receive hook implemented -using git_multimail.py as a Python module. It is intended to be -customized before use; see the comments in the script to help you get -started. - -It is possible to use git_multimail.py itself as a post-receive or -update hook, configured via git config settings and/or command-line -parameters. But for more flexibility, it can also be imported as a -Python module by a custom post-receive script as done here. The -latter has the following advantages: - -* The tool's behavior can be customized using arbitrary Python code, - without having to edit git_multimail.py. - -* Configuration settings can be read from other sources; for example, - user names and email addresses could be read from LDAP or from a - database. Or the settings can even be hardcoded in the importing - Python script, if this is preferred. - -This script is a very basic example of how to use git_multimail.py as -a module. The comments below explain some of the points at which the -script's behavior could be changed or customized. - -""" - -import sys -import os - -# If necessary, add the path to the directory containing -# git_multimail.py to the Python path as follows. (This is not -# necessary if git_multimail.py is in the same directory as this -# script): - -LIBDIR = '/usr/local/lib/python2.6/dist-packages/git_multimail-1.0.0-py2.6.egg' -sys.path.insert(0, LIBDIR) - -import git_multimail - -# It is possible to modify the output templates here; e.g.: - -#git_multimail.FOOTER_TEMPLATE = """\ -# -#-- \n\ -#This email was generated by the wonderful git-multimail tool. -#""" - -# Specify which "git config" section contains the configuration for -# git-multimail: -config = git_multimail.Config('multimailhook') - -forge = config.get('forge') -reponame = config.get('reponame') - - -git_multimail.REFCHANGE_INTRO_TEMPLATE = """\ -This is an automated email from the git hooks/post-receive script. - -New change to %(refname_type)s %(short_refname)s in repository %(repo_shortname)s. - -See http://git.{}/{}.git - -""".format(forge, reponame) - -git_multimail.REF_CREATED_SUBJECT_TEMPLATE = ( - '%(refname_type)s %(short_refname)s created' - ' (now %(newrev_short)s)' - ) -git_multimail.REF_UPDATED_SUBJECT_TEMPLATE = ( - '%(refname_type)s %(short_refname)s updated' - ' (%(oldrev_short)s -> %(newrev_short)s)' - ) -git_multimail.REF_DELETED_SUBJECT_TEMPLATE = ( - '%(refname_type)s %(short_refname)s deleted' - ' (was %(oldrev_short)s)' - ) - -git_multimail.REVISION_HEADER_TEMPLATE = """\ -Date: %(send_date)s -To: %(recipients)s -Subject: %(num)02d/%(tot)02d: %(oneline)s -MIME-Version: 1.0 -Content-Type: text/plain; charset=%(charset)s -Content-Transfer-Encoding: 8bit -From: %(fromaddr)s -Reply-To: %(reply_to)s -In-Reply-To: %(reply_to_msgid)s -References: %(reply_to_msgid)s -X-Git-Host: %(fqdn)s -X-Git-Repo: %(repo_shortname)s -X-Git-Refname: %(refname)s -X-Git-Reftype: %(refname_type)s -X-Git-Rev: %(rev)s -Auto-Submitted: auto-generated -""" - -git_multimail.REVISION_INTRO_TEMPLATE = """\ -This is an automated email from the git hooks/post-receive script. - -New commit to %(refname_type)s %(short_refname)s in repository %(repo_shortname)s. - -See http://git.{}/{}.git - -""".format(forge, reponame) - - -# Select the type of environment: -environment = git_multimail.GenericEnvironment(config=config) - -# Choose the method of sending emails based on the git config: -mailer = git_multimail.choose_mailer(config, environment) - -# Alternatively, you may hardcode the mailer using code like one of -# the following: - -# Use "/usr/sbin/sendmail -oi -t" to send emails. The envelopesender -# argument is optional: -#mailer = git_multimail.SendMailer( -# command=['/usr/sbin/sendmail', '-oi', '-t'], -# envelopesender='git-repo@example.com', -# ) - -# Use Python's smtplib to send emails. Both arguments are required. -#mailer = git_multimail.SMTPMailer( -# envelopesender='git-repo@example.com', -# # The smtpserver argument can also include a port number; e.g., -# # smtpserver='mail.example.com:25' -# smtpserver='mail.example.com', -# ) - -# OutputMailer is intended only for testing; it writes the emails to -# the specified file stream. -#mailer = git_multimail.OutputMailer(sys.stdout) - -# Read changes from stdin and send notification emails: -git_multimail.run_as_post_receive_hook(environment, mailer) Modified: scripts/redmine-tools/redmine-post-commit-git.sh =================================================================== --- scripts/redmine-tools/redmine-post-commit-git.sh 2014-05-25 06:09:19 UTC (rev 74) +++ scripts/redmine-tools/redmine-post-commit-git.sh 2014-05-25 08:34:09 UTC (rev 75) @@ -19,7 +19,7 @@ # send post-commit email #(cd /var/lib/git/git-$DOMAIN/$PROJECT_NAME.git ; python /usr/local/lib/python2.6/dist-packages/git_multimail-1.0.0-py2.6.egg/git_multimail.py) -(cd /var/lib/git/git-$DOMAIN/$PROJECT_NAME.git ; python /opt/redmine-tools/git-multimail-run.py) +(cd /var/lib/git/git-$DOMAIN/$PROJECT_NAME.git ; python /opt/git-tools/git-multimail-run.py) # touch project for nightly build touch /var/cache/redmine/nightly-build/$DOMAIN/$PROJECT_NAME.site
participants (1)
-
tchemit@users.forge.codelutin.com