You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@subversion.apache.org by Amitakhya Phukan <ap...@fedoraproject.org> on 2012/01/10 16:11:30 UTC

Help with svn pre-commit hook needed

Hi all,

I have a svn structure where we need to enable code collaborator check-in
for a particular branch, branch5.

For this, I have written the following pre-commit hook script.

====================================================
#!/bin/bash

dbUserName="dbuser"
dbPassword="dbuser@123"
dbIP="192.168.0.178"
dbSchema="codecollabdb"
REPOS="$1"
TXN="$2"
SVNLOOK=/usr/bin/svnlook
if [[ `echo "$BRANCH" | grep
"branch1\|branch2\|branch3\|branch4\|branch6\|branch7...\|branch50"`
== "" ]] ; then

 if [[ `echo "$LOGMSG" | grep "review"` != "" ]]; then
   SVNLogMsg=`"$SVNLOOK" log -t "$TXN" "$REPOS"`
   reviewMsg=`echo ${SVNLogMsg#*:}`
   reviewId=`echo ${reviewMsg% *}`
   echo $SVNLogMsg "," $reviewMsg "," $reviewId 1>&1
   query="select review_phaseid from review where review_id='$reviewId';"
   echo "Query is " $query
   reviewPhaseId=`mysql -u $dbUserName --skip-column-names
-p$dbPassword $dbSchema -h $dbIP -e "$query"`
   echo "review Phase Id is " $reviewPhaseId  1>&2
   if [[ $reviewPhaseId > 0 ]]; then
      echo "Review Id exists in DB. Now need to check for review
state. whether review has been completed or not"  1>&2
      phaseQuery="select phase_id from phase where phase_title='Completed';"
      phaseId=`mysql -u $dbUserName --skip-column-names -p$dbPassword
$dbSchema -h $dbIP -e "$phaseQuery"`
      echo "PhaseId is " $phaseId  1>&2
        if [[ $phaseId = $reviewPhaseId ]]; then
          echo "Review has been completed. Hence,allowing user to
proceed for check ins" 1>&2
          echo "Committing changes to svn repository" 1>&2

          export INSTALL4J_NO_DB=true

/usr/local/bin/ccollab --url http://192.168.0.145:8082 --user admin
--password password --scm subversion --svn-repo-path $1 --svn-look-exe
/usr/bin/svnlook admin trigger ensure-reviewed --review-id-regex
"review:\s+(\d+)" $2 || exit 1
      exit 0
          echo "comitted" 1>&2
        else
          echo " Review is not completed yet. You are requested to
complete the review before proceeding for check ins" 1>&2
          exit 1
        fi
    else
     echo "Review Id doesnt exist. You are requested to enter a valid
review Id" 1>&2
     exit 1
   fi
 else
  echo "" 1>&2
  echo "*** Your commit has been blocked." 1>&2
  echo "Please make your commit comment contains review Id" 1>&2
  echo "Process End" 1>&2
  exit 1
 fi
else
echo "this branch doesnot require any checks to proceed for check ins"
fi



====================================================

However, even though I am able to commit to all branches without any review
ID, for branch5 also I am able to commit without a review ID. It is clear
that something is wrong with the script. But I am not able to figure out
what. Please help me to correct it.

----

Best regards,
Amitakhya Phukan

Re: Help with svn pre-commit hook needed

Posted by Andy Levy <an...@gmail.com>.
Please quote context in your replies so people know what you're talking about.

On Tue, Jan 10, 2012 at 10:31, Amitakhya Phukan
<ap...@fedoraproject.org> wrote:
> Hi Andy,
>
>
>
> On Tue, Jan 10, 2012 at 8:46 PM, Andy Levy <an...@gmail.com> wrote:
>>
>>
>> Not sure if that's a typo or not, but you skipped from branch4 to branch6.
>>
>> Wouldn't it be better to do a pattern match here so that you don't
>> have to explicitly list every branch number?
>
>
>
> Can you give me an example please ? I am writing these scripts for the first
> time. An example would be good.

This isn't unique to svn hooks, this is just shell scripting & grep.

My grep is rusty but try this:

grep "branch[0-9]+/"

This should match any string with branch, followed by one or more
numbers, followed by a slash.

Re: Help with svn pre-commit hook needed

Posted by Amitakhya Phukan <ap...@fedoraproject.org>.
Hi Andy,


On Tue, Jan 10, 2012 at 8:46 PM, Andy Levy <an...@gmail.com> wrote:

>
> Not sure if that's a typo or not, but you skipped from branch4 to branch6.
>
> Wouldn't it be better to do a pattern match here so that you don't
> have to explicitly list every branch number?
>


Can you give me an example please ? I am writing these scripts for the
first time. An example would be good.


Best regards,
Amitakhya Phukan

Re: Help with svn pre-commit hook needed

Posted by Andy Levy <an...@gmail.com>.
On Tue, Jan 10, 2012 at 10:11, Amitakhya Phukan
<ap...@fedoraproject.org> wrote:
> Hi all,
>
> I have a svn structure where we need to enable code collaborator check-in
> for a particular branch, branch5.
>
> For this, I have written the following pre-commit hook script.
>
> ====================================================
> #!/bin/bash
>
> dbUserName="dbuser"
> dbPassword="dbuser@123"
> dbIP="192.168.0.178"
> dbSchema="codecollabdb"
> REPOS="$1"
> TXN="$2"
> SVNLOOK=/usr/bin/svnlook
> if [[ `echo "$BRANCH" | grep
> "branch1\|branch2\|branch3\|branch4\|branch6\|branch7...\|branch50"` == ""
> ]] ; then

> ====================================================
>
> However, even though I am able to commit to all branches without any review
> ID, for branch5 also I am able to commit without a review ID. It is clear
> that something is wrong with the script. But I am not able to figure out
> what. Please help me to correct it.

Not sure if that's a typo or not, but you skipped from branch4 to branch6.

Wouldn't it be better to do a pattern match here so that you don't
have to explicitly list every branch number?