Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

added support for exclusion IDs #21

Merged
merged 1 commit into from
Apr 28, 2015
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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; }
}
}