Skip to content

Commit

Permalink
Merge pull request #21 from RaphHaddad/master
Browse files Browse the repository at this point in the history
added support for exclusion IDs
  • Loading branch information
aaronpowell committed Apr 28, 2015
2 parents 3ccbc0a + 5ac1e92 commit 318d1f5
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 10 deletions.
33 changes: 23 additions & 10 deletions TeamFlash/Program.cs
Original file line number Diff line number Diff line change
Expand Up @@ -18,15 +18,17 @@ static void Main()
teamFlashConfig.ServerUrl = ReadConfig("TeamCity URL", teamFlashConfig.ServerUrl);
teamFlashConfig.Username = ReadConfig("Username", teamFlashConfig.Username);
var password = ReadConfig("Password", "");
teamFlashConfig.BuildTypeIds = ReadConfig("Comma separated build type ids (eg, \"bt64,bt12\"), or * for all", teamFlashConfig.BuildTypeIds);
teamFlashConfig.BuildTypeIds = ReadConfig("Comma separated build type ids to INCLUDE (eg, \"bt64,bt12\"), or * for ALL", teamFlashConfig.BuildTypeIds);
teamFlashConfig.BuildTypeIdsExcluded =
ReadConfig("Comma separated build type ids to EXCLUDE (eg, \"bt64,bt12\"), or * for NONE",
teamFlashConfig.BuildTypeIdsExcluded);

SaveConfig(teamFlashConfig);

Console.Clear();

var buildTypeIds = teamFlashConfig.BuildTypeIds == "*"
? new string[0]
: teamFlashConfig.BuildTypeIds.Split(new[] { ',' }, StringSplitOptions.RemoveEmptyEntries).ToArray();
var buildTypeIds = ConvertBuildTypeIdsToArray(teamFlashConfig.BuildTypeIds);
var buildTypeIdsExcluded = ConvertBuildTypeIdsToArray(teamFlashConfig.BuildTypeIdsExcluded);

#if __MonoCS__
var buildLight = new Linux.BuildLight();
Expand All @@ -42,7 +44,8 @@ static void Main()
teamFlashConfig.ServerUrl,
teamFlashConfig.Username,
password,
buildTypeIds);
buildTypeIds,
buildTypeIdsExcluded);
switch (lastBuildStatus)
{
case BuildStatus.Unavailable:
Expand All @@ -69,13 +72,20 @@ static void Main()
buildLight.Off();
}

private static string[] ConvertBuildTypeIdsToArray(string buildTypeIds)
{
return buildTypeIds == "*"
? new string[0]
: buildTypeIds.Split(new[] { ',' }, StringSplitOptions.RemoveEmptyEntries).ToArray();
}

static bool PromptForVerboseMode()
{
Console.Write("Would you like to start in VERBOSE mode? (y/n)");
var selection = Console.ReadKey(true /*intercept*/).KeyChar;
Console.WriteLine();
var verbose = char.ToLower(selection) == 'y';
if(verbose) Console.WriteLine("VERBOSE mode is ON. Re-run TeamFlash in order to revert this.");
if (verbose) Console.WriteLine("VERBOSE mode is ON. Re-run TeamFlash in order to revert this.");
Console.WriteLine();
return verbose;
}
Expand All @@ -86,7 +96,7 @@ static TeamFlashConfig LoadConfig()
var configFilePath = Path.Combine(appDataPath, @"TeamFlash\config.json");
try
{
if (!File.Exists(configFilePath))return new TeamFlashConfig();
if (!File.Exists(configFilePath)) return new TeamFlashConfig();

Logger.WriteLine("Reading config values from: {0}", configFilePath);

Expand Down Expand Up @@ -154,11 +164,12 @@ static void Wait()

static BuildStatus RetrieveBuildStatus(
string serverUrl, string username, string password,
IEnumerable<string> buildTypeIds)
IEnumerable<string> buildTypeIds, IEnumerable<string> buildTypeIdsExcluded)
{
Logger.Verbose("Checking build status.");

buildTypeIds = buildTypeIds.ToArray();
buildTypeIdsExcluded = buildTypeIdsExcluded.ToArray();

dynamic query = new Query(serverUrl, username, password);

Expand All @@ -180,8 +191,10 @@ static BuildStatus RetrieveBuildStatus(
foreach (var buildType in project.BuildTypes)
{
Logger.Verbose("Checking Built Type '{0}\\{1}'.", project.Name, buildType.Name);
if (buildTypeIds.Any() &&
buildTypeIds.All(id => id != buildType.Id))
if ((buildTypeIds.Any() &&
buildTypeIds.All(id => id != buildType.Id)) ||
(buildTypeIdsExcluded.Any() &&
buildTypeIdsExcluded.All(id => id == buildType.id)))
{
Logger.Verbose("Bypassing Built Type '{0}\\{1}' because it does NOT match configured built-type list to monitor.", project.Name, buildType.Name);
continue;
Expand Down
1 change: 1 addition & 0 deletions TeamFlash/TeamFlashConfig.cs
Original file line number Diff line number Diff line change
Expand Up @@ -5,5 +5,6 @@ public class TeamFlashConfig
public string ServerUrl { get; set; }
public string Username { get; set; }
public string BuildTypeIds { get; set; }
public string BuildTypeIdsExcluded { get; set; }
}
}

0 comments on commit 318d1f5

Please sign in to comment.