From 86e63b8a6c3ce258433efaab35f5d3c06167a9fe Mon Sep 17 00:00:00 2001 From: senzacionale Date: Tue, 29 Dec 2015 15:32:33 +0100 Subject: [PATCH] First commit First commit --- .gitattributes | 22 +++ .gitignore | 167 ++++++++++++++++++ README.md | 1 + VisualSVNHookHandler/VisualSVNHookHandler.sln | 22 +++ .../VisualSVNHookHandler/App.config | 6 + .../VisualSVNHookHandler/PostCommit.cs | 94 ++++++++++ .../Properties/AssemblyInfo.cs | 36 ++++ .../VisualSVNHookHandler.csproj | 58 ++++++ 8 files changed, 406 insertions(+) create mode 100644 .gitattributes create mode 100644 .gitignore create mode 100644 README.md create mode 100644 VisualSVNHookHandler/VisualSVNHookHandler.sln create mode 100644 VisualSVNHookHandler/VisualSVNHookHandler/App.config create mode 100644 VisualSVNHookHandler/VisualSVNHookHandler/PostCommit.cs create mode 100644 VisualSVNHookHandler/VisualSVNHookHandler/Properties/AssemblyInfo.cs create mode 100644 VisualSVNHookHandler/VisualSVNHookHandler/VisualSVNHookHandler.csproj diff --git a/.gitattributes b/.gitattributes new file mode 100644 index 0000000..412eeda --- /dev/null +++ b/.gitattributes @@ -0,0 +1,22 @@ +# Auto detect text files and perform LF normalization +* text=auto + +# Custom for Visual Studio +*.cs diff=csharp +*.sln merge=union +*.csproj merge=union +*.vbproj merge=union +*.fsproj merge=union +*.dbproj merge=union + +# Standard to msysgit +*.doc diff=astextplain +*.DOC diff=astextplain +*.docx diff=astextplain +*.DOCX diff=astextplain +*.dot diff=astextplain +*.DOT diff=astextplain +*.pdf diff=astextplain +*.PDF diff=astextplain +*.rtf diff=astextplain +*.RTF diff=astextplain diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..5f4aa9e --- /dev/null +++ b/.gitignore @@ -0,0 +1,167 @@ +################# +## Eclipse +################# + +*.pydevproject +.project +.metadata +bin/ +tmp/ +*.tmp +*.bak +*.swp +*~.nib +local.properties +.classpath +.settings/ +.loadpath + +# External tool builders +.externalToolBuilders/ + +# Locally stored "Eclipse launch configurations" +*.launch + +# CDT-specific +.cproject + +# PDT-specific +.buildpath + + +################# +## Visual Studio +################# + +## Ignore Visual Studio temporary files, build results, and +## files generated by popular Visual Studio add-ons. + +# User-specific files +*.suo +*.user +*.sln.docstates + +# Build results +[Dd]ebug/ +[Rr]elease/ +*_i.c +*_p.c +*.ilk +*.meta +*.obj +*.pch +*.pdb +*.pgc +*.pgd +*.rsp +*.sbr +*.tlb +*.tli +*.tlh +*.tmp +*.vspscc +.builds +*.dotCover + +## TODO: If you have NuGet Package Restore enabled, uncomment this +#packages/ + +# Visual C++ cache files +ipch/ +*.aps +*.ncb +*.opensdf +*.sdf + +# Visual Studio profiler +*.psess +*.vsp + +# ReSharper is a .NET coding add-in +_ReSharper* + +# Installshield output folder +[Ee]xpress + +# DocProject is a documentation generator add-in +DocProject/buildhelp/ +DocProject/Help/*.HxT +DocProject/Help/*.HxC +DocProject/Help/*.hhc +DocProject/Help/*.hhk +DocProject/Help/*.hhp +DocProject/Help/Html2 +DocProject/Help/html + +# Click-Once directory +publish + +# Others +[Bb]in +[Oo]bj +sql +TestResults +*.Cache +ClientBin +stylecop.* +~$* +*.dbmdl +Generated_Code #added for RIA/Silverlight projects + +# Backup & report files from converting an old project file to a newer +# Visual Studio version. Backup files are not needed, because we have git ;-) +_UpgradeReport_Files/ +Backup*/ +UpgradeLog*.XML + + + +############ +## Windows +############ + +# Windows image file caches +Thumbs.db + +# Folder config file +Desktop.ini + +#SVN +*.svn +.svn + + +############# +## Python +############# + +*.py[co] + +# Packages +*.egg +*.egg-info +dist +build +eggs +parts +bin +var +sdist +develop-eggs +.installed.cfg + +# Installer logs +pip-log.txt + +# Unit test / coverage reports +.coverage +.tox + +#Translations +*.mo + +#Mr Developer +.mr.developer.cfg + +# Mac crap +.DS_Store diff --git a/README.md b/README.md new file mode 100644 index 0000000..518e5f6 --- /dev/null +++ b/README.md @@ -0,0 +1 @@ +#VisualSVNHookHandler code repo ##post-commit-hook Code for a custom post-commit hook executable that can be used with VisualSVN server. There is a project that contains C# versions of the code. Build the project and copy the .exe file from the bin/debug folder in your project to the bin folder in your VisualSVN server installation folder, which in my case was C:\Program Files\VisualSVN Server\bin. Then, open up VisualSVN server and right click on the repository that you want to add the post-commit hook to and click properties. Open the hooks tab and double click on Post-commit hook. It will open a window that you need to paste the following code into. All it does is tell VisualSVN to run the .exe when a commit happens and passes in the required arguments: ```csharp "%VISUALSVN_SERVER%bin.exe" "%1" %2 "mail@mail.com,mail2@mail2.com" ``` where "mail@mail.com,mail2@mail2.com" are comma separated recipients list. \ No newline at end of file diff --git a/VisualSVNHookHandler/VisualSVNHookHandler.sln b/VisualSVNHookHandler/VisualSVNHookHandler.sln new file mode 100644 index 0000000..ac2450c --- /dev/null +++ b/VisualSVNHookHandler/VisualSVNHookHandler.sln @@ -0,0 +1,22 @@ + +Microsoft Visual Studio Solution File, Format Version 12.00 +# Visual Studio 2013 +VisualStudioVersion = 12.0.40629.0 +MinimumVisualStudioVersion = 10.0.40219.1 +Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "VisualSVNHookHandler", "VisualSVNHookHandler\VisualSVNHookHandler.csproj", "{2422C5FE-8A64-4C9C-BA45-2518258A257E}" +EndProject +Global + GlobalSection(SolutionConfigurationPlatforms) = preSolution + Debug|Any CPU = Debug|Any CPU + Release|Any CPU = Release|Any CPU + EndGlobalSection + GlobalSection(ProjectConfigurationPlatforms) = postSolution + {2422C5FE-8A64-4C9C-BA45-2518258A257E}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {2422C5FE-8A64-4C9C-BA45-2518258A257E}.Debug|Any CPU.Build.0 = Debug|Any CPU + {2422C5FE-8A64-4C9C-BA45-2518258A257E}.Release|Any CPU.ActiveCfg = Release|Any CPU + {2422C5FE-8A64-4C9C-BA45-2518258A257E}.Release|Any CPU.Build.0 = Release|Any CPU + EndGlobalSection + GlobalSection(SolutionProperties) = preSolution + HideSolutionNode = FALSE + EndGlobalSection +EndGlobal diff --git a/VisualSVNHookHandler/VisualSVNHookHandler/App.config b/VisualSVNHookHandler/VisualSVNHookHandler/App.config new file mode 100644 index 0000000..8e15646 --- /dev/null +++ b/VisualSVNHookHandler/VisualSVNHookHandler/App.config @@ -0,0 +1,6 @@ + + + + + + \ No newline at end of file diff --git a/VisualSVNHookHandler/VisualSVNHookHandler/PostCommit.cs b/VisualSVNHookHandler/VisualSVNHookHandler/PostCommit.cs new file mode 100644 index 0000000..782bbd7 --- /dev/null +++ b/VisualSVNHookHandler/VisualSVNHookHandler/PostCommit.cs @@ -0,0 +1,94 @@ +using System; +using System.Diagnostics; +using System.IO; +using System.Net.Mail; +using System.Text; + +namespace VisualSVNHookHandler +{ + public static class PostCommit + { + private static readonly string Svnpath = Environment.GetEnvironmentVariable("VISUALSVN_SERVER"); + private static int Main(string[] args) + { + //Check if revision number and revision path have been supplied. + if (args.Length < 3) + { + Console.Error.WriteLine("Invalid arguments sent - required"); + return 1; + } + + //Check if VisualSVN is installed. + if (string.IsNullOrEmpty(Svnpath)) + { + Console.Error.WriteLine("VISUALSVN_SERVER environment variable does not exist. VisualSVN installed?"); + return 1; + } + + //Get the required information using SVNLook. + string author = SvnLook("author", args); + string message = SvnLook("log", args); + string changed = SvnLook("changed", args); + + //Get the branch from the first change in the list. + string[] changeList = changed.Split(new string[] { Environment.NewLine }, StringSplitOptions.None); + string changeFirst = changeList[0].Remove(0, 4); + int changeFirstSlash = changeFirst.IndexOf("/", StringComparison.Ordinal); + string repoBranch = changeFirst.Substring(0, changeFirstSlash); + + //Get the name of the repository from the first argument, which is the repo path. + string repoName = args[0].ToString().Substring(args[0].LastIndexOf(@"\", StringComparison.Ordinal) + 1); + + //Get the email template and fill it in. This template can be anywhere, and can be a .HTML file + //for more control over the structure. + const string emailTemplatePath = @"C:\hooks\PostCommit.txt"; + string emailTemplate = string.Format(File.ReadAllText(emailTemplatePath), author, message, changed); + + //Construct the email that will be sent. You can use the .IsBodyHtml property if you are + //using an HTML template. + string subject = string.Format("Commit number {0} for {1}", args[1], repoName); + MailMessage mm = new MailMessage("", args[2]); + mm.Body = emailTemplate; + mm.Subject = subject; + + //Define your mail client. I am using Gmail here as the SMTP server, but you could + //use IIS or Amazon SES or whatever you want. + SmtpClient mailClient = new SmtpClient("smtp.gmail.com"); + mailClient.Port = 587; + mailClient.Credentials = new System.Net.NetworkCredential("", ""); + mailClient.EnableSsl = false; + + mailClient.Send(mm); + + return 0; + } + + /// + /// Runs a command on svnlook.exe to get information + /// about a particular repo and revision. + /// + /// The svnlook command e.g. log, author, message. + /// The arguments passed in to this exe (repo name and rev number). + /// The output of svnlook.exe + private static string SvnLook(string command, string[] args) + { + StringBuilder output = new StringBuilder(); + Process procMessage = new Process(); + + //Start svnlook.exe in a process and pass it the required command-line args. + procMessage.StartInfo = new ProcessStartInfo(Svnpath + @"bin\svnlook.exe", String.Format(@"{0} ""{1}"" -r ""{2}""", command, args[0], args[1])); + procMessage.StartInfo.RedirectStandardOutput = true; + procMessage.StartInfo.UseShellExecute = false; + procMessage.Start(); + + //While reading the output of svnlook, append it to the stringbuilder then + //return the output. + while (!procMessage.HasExited) + { + output.Append(procMessage.StandardOutput.ReadToEnd()); + } + + return output.ToString(); + } + } +} diff --git a/VisualSVNHookHandler/VisualSVNHookHandler/Properties/AssemblyInfo.cs b/VisualSVNHookHandler/VisualSVNHookHandler/Properties/AssemblyInfo.cs new file mode 100644 index 0000000..b56fab5 --- /dev/null +++ b/VisualSVNHookHandler/VisualSVNHookHandler/Properties/AssemblyInfo.cs @@ -0,0 +1,36 @@ +using System.Reflection; +using System.Runtime.CompilerServices; +using System.Runtime.InteropServices; + +// General Information about an assembly is controlled through the following +// set of attributes. Change these attribute values to modify the information +// associated with an assembly. +[assembly: AssemblyTitle("VisualSVNHookHandler")] +[assembly: AssemblyDescription("")] +[assembly: AssemblyConfiguration("")] +[assembly: AssemblyCompany("")] +[assembly: AssemblyProduct("VisualSVNHookHandler")] +[assembly: AssemblyCopyright("Copyright © 2015")] +[assembly: AssemblyTrademark("")] +[assembly: AssemblyCulture("")] + +// Setting ComVisible to false makes the types in this assembly not visible +// to COM components. If you need to access a type in this assembly from +// COM, set the ComVisible attribute to true on that type. +[assembly: ComVisible(false)] + +// The following GUID is for the ID of the typelib if this project is exposed to COM +[assembly: Guid("b9a99c57-8007-4297-ae4f-042ef800ed0e")] + +// Version information for an assembly consists of the following four values: +// +// Major Version +// Minor Version +// Build Number +// Revision +// +// You can specify all the values or you can default the Build and Revision Numbers +// by using the '*' as shown below: +// [assembly: AssemblyVersion("1.0.*")] +[assembly: AssemblyVersion("1.0.0.0")] +[assembly: AssemblyFileVersion("1.0.0.0")] diff --git a/VisualSVNHookHandler/VisualSVNHookHandler/VisualSVNHookHandler.csproj b/VisualSVNHookHandler/VisualSVNHookHandler/VisualSVNHookHandler.csproj new file mode 100644 index 0000000..148bc3b --- /dev/null +++ b/VisualSVNHookHandler/VisualSVNHookHandler/VisualSVNHookHandler.csproj @@ -0,0 +1,58 @@ + + + + + Debug + AnyCPU + {2422C5FE-8A64-4C9C-BA45-2518258A257E} + Exe + Properties + VisualSVNHookHandler + VisualSVNHookHandler + v4.5 + 512 + + + AnyCPU + true + full + false + bin\Debug\ + DEBUG;TRACE + prompt + 4 + + + AnyCPU + pdbonly + true + bin\Release\ + TRACE + prompt + 4 + + + + + + + + + + + + + + + + + + + + \ No newline at end of file