Created
November 28, 2011 19:15
-
-
Save tanglebones/1401596 to your computer and use it in GitHub Desktop.
TC config updater for building project branches
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
using System; | |
using System.Collections.Generic; | |
using System.IO; | |
using System.Linq; | |
using System.Text.RegularExpressions; | |
namespace Move.Platform.TeamCityBranchUpdaterTool | |
{ | |
public static class Program | |
{ | |
public static void Main(string[] args) | |
{ | |
var lsRemote = File.ReadAllLines("ls-remote.txt"); | |
const string projectConfigXml = "project-config.xml"; | |
var projectConfig = File.ReadAllText(projectConfigXml); | |
var rxRef = new Regex("refs/heads/(.*)$"); | |
var branches = new HashSet<string>(from line in lsRemote select rxRef.Match(line) into match where match.Success select match.Groups[1].Value); | |
var rxBuild = new Regex(@"<build-type\s+id=""([^""]+)"".*?</build-type>", RegexOptions.Singleline); | |
projectConfig = rxBuild.Replace(projectConfig,m =>{var name = m.Groups[1].Value;if (branches.Contains(name)){branches.Remove(name);return m.Value;}return string.Empty;}); | |
var newBranches = string.Join(Environment.NewLine,branches.Select(b =>"<build-type id=\"" + b + "\" name=\"" + b +"\"><settings ref=\"template\"></settings></build-type>")); | |
projectConfig = projectConfig.Replace("</project>", newBranches + "</project>"); | |
File.WriteAllText(projectConfigXml, projectConfig); | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment