Svn mandatory submission of comment rules and trigger mail notifications

Source: Internet
Author: User

Background: many projects exist on the company's svn server. In many cases, developers do not enter comments or enter comments when submitting code, which is not conducive to other developers on the team to understand the code changes, after a long period of time, I still don't know the modifications I made. If I had a problem with code rollback, I didn't even know the version was rolled back to. Therefore, it is necessary to force a comment based on certain rules.

Reasons for doing so: (1) submitting comments in a standardized manner to facilitate understanding of the issues in jira Based on the remarks; (2) Preparing for the automatic generation of release reports.

1. Rules:

Project name + "-" + jira question number + space + description of this submission.

2. Notes for mandatory submission

Create a pre-commit file in the hooks directory of the svn project. The content is as follows:

[Root @ svn ~] # More/var/www/svn/beeer/hooks/pre-commit
#! /Bin/sh
### Solve Chinese problems
LANG = en_US.UTF-8
Export LANG

REPOS = "$1"
TXN = "$2"

SVNLOOK =/usr/bin/svnlook

### Create regex
# Pkey = 'mysql-usvn101-p 'test2'-h192.168.100.121 -- disable-column-names jira_5-e "select pkey from project ;"'
# Regex = 'echo $ jira_info | awk '{for (I = 1; I <= NF; I ++) printf "^" $ I "-[1-9] [0-9] {1, 5} [] |"} '| sed's/| $ //''


Regex = "^ BITTER-[1-9] [0-9] {} [] | ^ BOUARD-[1-9] [0-9] {} [] | ^ HORTS-[1-9] [0-9] {1, 5} []"


LOGMSG = '$ SVNLOOK log-t "$ {TXN}" "$ REPOS" | grep-E "^ $ regex" | wc-l'


If ["$ LOGMSG"-lt 1];
Then
Echo "Every commit must include project name and the Jira issue number and issue description, For example: BOUARD-1986 bugfix XXX (issue description)." 1> & 2
Exit 1
Fi

Pre-commit:

[Root @ svn ~] # Chmod + x/var/www/svn/beeer/hooks/pre-commit

3. Trigger mail Notification after svn is submitted

Create a post-commit file in the hooks directory of the svn project. The content is as follows:

[Root @ svn ~] # More/var/www/svn/beeer/hooks/post-commit
#! /Bin/sh
# Source ~ /. Bash_profile
REPOS = "$1"
REV = "$2"
SENDTO = "ops@laijingli.com"

# Send it to these people, calling the script we created abve
/Var/www/svn/scripts/svn_email_commit.sh "$ REPOS" "$ REV" "$ SENDTO"

Post-commit:

[Root @ svn ~] # Chmod + x/var/www/svn/beeer/hooks/post-commit

Create a mail sending script:

[Root @ svn ~] # More/var/www/svn/scripts/svn_email_commit.sh
#! /Bin/bash
# Source ~ /. Bash_profile
### Solve Chinese problems
LANG = en_US.UTF-8
Export LANG


# REPOS = 'echo $1 | cut-d/-f 5'
REPOS = $1
REPOS_SIMPLE = 'echo $1 | cut-d/-f 5'
REV = $2
SENDTO = $3
SENDFROM = svncommit@wfar.com


LIMITDIFF = 200
CHANGELOG = $ (/usr/bin/svnlook log-r $ REV $ REPOS)
AUTHOR = 'svnlook author-r $ REV $ repos'
CHANGED = 'svnlook changed-r $ REV $ repos'
DIFF = 'svnlook diff-r $ REV $ REPOS | head -- lines = $ LIMITDIFF'
DATE = 'date'
# TMPFILE =/tmp/svn _ "$ REPOS_SIMPLE" _ "$ REV" _ $ RANDOM. message
TMPFILE =/tmp/svn _ "$ REPOS_SIMPLE" _ "$ REV" _ $ (date + % Y % m % d % H % M % S). message


Jira_issue_id = 'echo $ CHANGELOG | awk '{print $1 }''
Jira_info = 'mysql-usvn101-p 'test'-h192.168.100.121 jira_5-e "select pkey, REPORTER, ASSIGNEE, SUMMARY, DESCRIPTION from jiraissue where pkey = '$ jira_issue_id' limit
1 ;"'


# Issue_info_sum = 'echo $ jira_info | awk '{print "pkey:" $6; print "REPORTER:" $7; print "ASSIGNEE:" $8; print "SUMMARY: "$9; print" DESCRIPTION: "$10 }''
Issue_info_sum = 'echo $ jira_info | awk '{print "question:" $6; print "Reporter:" $7; print "handler:" $8; print "problem summary: "$9; print" Problem description: "$10 }''


# Echo "$ CHANGELOG">/tmp/echos. log


SUBJECT = "SVNCommit ($ AUTHOR) $ REPOS_SIMPLE [$ REV]"
Echo "-------------------- SVN Commit Notification --------------------
Repository: $ REPOS
Revision: $ REV
Author: $ AUTHOR
Date: $ DATE


Jira_issue_summary:
Issue_url: http: // 192.168.100.121: 8085/browse/$ jira_issue_id
$ Issue_info_sum


-----------------------------------------------------------------
Log Message:
-----------------------------------------------------------------
$ CHANGELOG


-----------------------------------------------------------------
Changes:
-----------------------------------------------------------------
$ CHANGED


-----------------------------------------------------------------
Diff: (only first $ LIMITDIFF lines shown)
-----------------------------------------------------------------
$ DIFF
"> $ TMPFILE


# Send email
# Cat $ TMPFILE | mail-a "From: $ SENDFROM"-s "$ SUBJECT" "$ SENDTO"
# Cat $ TMPFILE | mail-s "$ SUBJECT" "$ SENDTO"
# Cat $ TMPFILE | mutt-s "$ SUBJECT" "$ SENDTO"
Cat $ TMPFILE | iconv-f utf8-t gbk | mail-s "$ SUBJECT" "$ SENDTO" ---f lai@wby.com
# Echo '/usr/bin/svnlook log-r $ REV $ REPOS' | iconv-f utf8-t gbk | mail-s "$ SUBJECT" "$ SENDTO"
# Echo '/usr/bin/svnlook log-r $ REV $ REPOS'>/tmp/log.txt

# Cleanup
# Rm $ TMPFILE

Svn_email_commit.sh:

[Root @ svn ~] # Chmod + x/var/www/svn/scripts/svn_email_commit.sh


So far, two functions of this article have been completed: Force comments and trigger mail notifications.

Effect:


Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.