-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathprecommit_log.vbs
137 lines (111 loc) · 6.33 KB
/
precommit_log.vbs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
' Precommit �����������
' https://polyplastic.teamlead.ru/browse/IS-417
' �����������
' 1. ��� ���� ��������� �������� ��������� � WshShell.Run
' 2. ���� �������������� ������ epf, erf (cfe �������� ����)
' 3. apppath - ���� � exe 1c
' serviceib - ���� � ���� ��� ���������� ������
'Option Explicit
Dim WshShell, apppath, serviceib, PathrepoGIT, PathSRC, FolderSrc, FileName, FullPathFile, FSO, File,TempFile,ResultCode,ParsingIsSuccess,DirFileName
const WaitUntilFinished = true, DontWaitUntilFinished = false, ShowWindow = 1, DontShowWindow = 0
apppath = "C:\Program Files\1cv8\8.3.16.1502\bin\1cv8.exe" ' ���� � ����������� ����� 1�
serviceib = "/S srv-msk-test1c1/precommit" ' ���� ������ ������ � ������ ��� ���������� ������ � ����������
ParsingIsSuccess = false
If WScript.Arguments.Count <> 1 Then
WScript.echo "waiting only 1 parameters"
WScript.Quit 1
End If
PathrepoGIT = WScript.Arguments(0)
PathrepoGIT = Replace(PathrepoGIT, "/", "\")
FolderSrc = "src"
PathSRC = PathrepoGIT & "\" & FolderSrc & "\"
Set WshShell = CreateObject("WScript.Shell")
TempFile = "C:\temp\logprecommit.tmp"
' ������� ���������
'Example: show only added , changed, modified files exclude deleted files:
WshShell.Run "cmd /C git diff-index --diff-filter=ACM --name-status --cached HEAD > " & TempFile , DontShowWindow, WaitUntilFinished
Dim objStream, strData, arraystr, Str, i
Set objStream = CreateObject("ADODB.Stream")
objStream.CharSet = "utf-8"
objStream.Open
objStream.LoadFromFile(TempFile)
strData = objStream.ReadText()
WScript.Echo strData
Set FSO = CreateObject("Scripting.FileSystemObject")
'��������� �� ������
arraystr = Split(strData, vbLf)
'���� �� �������
For i = 0 To UBound(arraystr)
Str = Rtrim(arraystr(i))
if Right(Str,3) = "epf" or Right(Str,3) = "erf" then
' or Right(Str,3) = "cfe" ����� �������� ����� ��������. ������� � ������
FileName = Mid(Str,3)
FileName = Replace(FileName, "/", "\")
FileNameWithoutExt = Left(FileName,Len(FileName)-4)
WScript.Echo FileNameWithoutExt
DirFileName = ""
if InStrRev(FileNameWithoutExt,"\") > 1 Then
DirFileName = Left(FileNameWithoutExt,InStrRev(FileNameWithoutExt,"\")-1)
end if
WScript.Echo DirFileName
' �������� ����� � src ���� ���
localsrcDir = PathSRC & DirFileName
Call CreateFolderInSrc(localsrcDir)
FullPathFile = PathrepoGIT & "\" & FileName
' � vbs ������ try catch , ��� ��������������� ������.
' ���� ������, ��� ����� ���������� ����������� ������
On Error Resume Next
' ���� ����� ������� ��� �������� �� 1� ��������� """ /Out C:\Temp\out1.txt"
StrParsing1C = """" & apppath & """" & " DESIGNER " & serviceib & " /DumpExternalDataProcessorOrReportToFiles """ & localsrcDir & """ """ & FullPathFile & """" & " /Out C:\Temp\out1.txt"
WScript.Echo StrParsing1C
ResultCode = WshShell.Run(StrParsing1C, DontShowWindow, WaitUntilFinished)
If Err.Number <> 0 Then
WScript.Echo "Error in starting 1c and parsing: " & Err.Number & vbLf & StrParsing1C
Err.Clear
WScript.Quit 1
End If
' xml ���� � �����. �������� ���� �������� ����������.
' �� �� ���� ��� ���������� ����� ���������� �� ���� ������, �� ���������� ������� ���������� ����� � ����.
if ResultCode=0 Then ' ���� ���������� �������� ����� �������. ������ ����� ���� ������ ��� ���� �� ����� ������ "�������� ���������"
'WshShell.Run "cmd /C git add --all """ & FolderSrc & FileNameWithoutExt & ".xml""", DontShowWindow, WaitUntilFinished
'WshShell.Run "cmd /C git add --all ""./" & FolderSrc & """", DontShowWindow, WaitUntilFinished
ParsingIsSuccess = true
else
WScript.Echo "Parsing 1c - error code: " & ResultCode
WScript.Quit 1
end if
end if
Next
' ������ ����� ��������� ����� src
if ParsingIsSuccess=True Then
WScript.Echo "ParsingIsSuccess: " & ParsingIsSuccess
WshShell.Run "cmd /C git add --all ""./" & FolderSrc & """" & " > " & TempFile, DontShowWindow, WaitUntilFinished
WScript.Echo "cmd /C git add --all ""./" & FolderSrc & """" & " > " & TempFile
objStream.CharSet = "utf-8"
objStream.Open
objStream.LoadFromFile(TempFile)
strData = objStream.ReadText()
WScript.Echo strData
end if
Set objStream = nothing
Set WshShell = nothing
'��������� �������� ����� � src ���� ���
Sub CreateFolderInSrc(localsrcDir)
srcDirTree = Split(localsrcDir, "\")
For k = 0 To UBound(srcDirTree)
If srcDirTree(k) <> "" Then
srcDirNext = srcDirNext & srcDirTree(k) & "\"
If Not FSO.FolderExists(srcDirNext) Then
FSO.CreateFolder(srcDirNext)
End If
End If
Next
End sub
' � vbs ������ try catch , ��� ��������������� ������.
' ���� ������, ��� ����� ���������� ����������� ������
'On Error Resume Next
' If Err.Number <> 0 Then
' WScript.Echo "Error " & Err.Description
' Err.Clear
' WScript.Quit 1
' End If