Skip to content

Instantly share code, notes, and snippets.

@tanglebones
Created November 28, 2011 19:15
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save tanglebones/1401596 to your computer and use it in GitHub Desktop.
Save tanglebones/1401596 to your computer and use it in GitHub Desktop.
TC config updater for building project branches
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