【问题标题】:Windows Batch Script for SVN & reviewboard用于 SVN 和评论板的 Windows 批处理脚本
【发布时间】:2016-04-26 09:07:56
【问题描述】:

我是批处理脚本的新手。我写了一个下面的脚本,但它没有运行。请让我知道我是否缺少任何语法或其他内容。

脚本过程:- 变量 %MESSAGEFILE% 将包含两行字符串示例:- PID-PROJECTID DEV SFRNUM:0123 评论:123 如果缺少任何一行应该在块中抛出错误:Commitmsg 否则它应该继续。

    @echo off
setlocal enabledelayedexpansion

set BASEDIR=%CD%
set URL=https://*******:443/reviewboard/
set YES=YES
set MESSAGEFILE=%2%


:: Checking If the API File Exists or Not. If Not Prompt Users to Create

IF NOT EXIST C:\api (
echo Please Create a File api under C:\ and provide ur API details in it 1>&2
exit 1
)
for /f "tokens=*" %%i in ('type "C:\api"') do (
set API=%%i
)


:: Comment Message Validations


type %MESSAGEFILE% > tmpFile
set "file=tmpFile"
call :Commitmsg "%file%" 

type %BASEDIR%\tmpFile |findstr /IB "PID" > tmpFile1
set "file=tmpFile1"
call :Commitmsg "%file%"


type %BASEDIR%\tmpFile |findstr /IB "Review" > tmpFile2
set "file=tmpFile2"
call :Commitmsg "%file%"


:: Checking If SVN Command Client is Installed. If yes Store Some svn info into Variables

svn info > svninfo

IF ERRORLEVEL 1 (
echo Seems like SVN Command-line Client Not Installed. Please Install it. Contact Vercon For Support 1>&2
goto :delFiles
)

for /f "tokens=4 delims=//" %%i in ('findstr /ilc:"Repository Root" "svninfo"') do (
set REP=%%i
)
for /f "tokens=3 delims=^/" %%j in ('findstr /ilc:"Relative URL" "svninfo"') do (
set TARGET_GROUPS=%%j
)

FOR /F "tokens=*" %%F IN (tmpFile1) DO (
set msg=%%F 
)

FOR /F "tokens=2 delims=:" %%F IN (tmpFile2) DO (
set rev=%%F
)
FOR /F "tokens=* delims= " %%a IN ("%rev%") DO ( 
SET rev=%%a
)


:: Creating .reviewboardrc file

echo REVIEWBOARD_URL = "%URL%" >> .reviewboardrc
echo REPOSITORY = "%REP%" >> .reviewboardrc
echo DISABLE_SSL_VERIFICATION = "%YES%" > .reviewboardrc
echo API_TOKEN = "%API%" >> .reviewboardrc
echo TARGET_GROUPS = "%TARGET_GROUPS%" >> .reviewboardrc
echo PUBLISH = "%YES%" >> .reviewboardrc
echo OPEN_BROWSER = "%YES%" >> .reviewboardrc


:: Posting Reviews Based On Comment Message in SVN


if /I "%rev:new=%" neq "%rev%" (
rbt post --summary %msg% --description %msg%
goto :delFiles
) else (
rbt post -r %rev% --summary %msg% --description %msg%
goto :delFiles
)


:: Error Message in Case Of Wrong Commit Message in SVN


:Commitmsg
if %~z1 == 0 (
echo Please Provide the Commit Message in the First Line, Followed by review. 1>&2
echo The First Line will be Taken as a Review Summary. 1>&2
echo Follow the Below Example 1>&2
echo ************************************************************ 1>&2
echo PID-PROJECTID DEV SFRNUM:01234 1>&2
echo Review:New / Review:01 1>&2
echo To Create a New Review -- Review:New 1>&2
echo To Update a Existing Review -- Review:01 1>&2
echo ************************************************************ 1>&2
echo Contact Vercon Team For Support 1>&2
goto :delFiles
)

:delFiles
IF EXIST tmpFile del tmpFile
IF EXIST tmpFile1 del tmpFile1
IF EXIST tmpFile2 del tmpFile2
IF EXIST .reviewboardrc del .reviewboardrc
IF EXIST svninfo del svninfo
exit 1

【问题讨论】:

    标签: windows batch-file batch-processing


    【解决方案1】:

    一个小的修正工作!当我找到解决方案时,请不要浪费您宝贵的时间。 谢谢!

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2012-02-04
      • 1970-01-01
      • 2013-05-16
      • 1970-01-01
      • 1970-01-01
      • 2021-03-28
      • 1970-01-01
      • 2011-02-21
      相关资源
      最近更新 更多