public async Task <int> CreateDefs() { var repos = (await GetRepos()).OrderBy(r => r.Name).ToList(); log.LogInformation($"Found {repos.Count} repos"); var buildDefs = await GetBuildDefs(); log.LogInformation($"{buildDefs.Count} build defs already exist"); int created = 0; foreach (var r in repos) { try { if (!buildDefs.Contains(CiBuildManager.BuildDefName(r.Name))) { log.LogInformation($"Creating CI build for {r.Name}...."); var result = await CreateDefinition(r.Name, new Uri(r.CloneUrl)); created++; log.LogInformation(result ? "CREATED" : "SKIPPED"); } } catch (Exception ex) { log.LogInformation($"ERROR: {ex.Message}"); } } return(created); }
private static async Task UpdateBuildSummary(ILogger log, CiBuildManager a) { log.LogInformation("Generating build summary..."); var buildSummary = await a.GenerateBuildSummary(); log.LogInformation("Uploading build summary..."); a.UploadFile("kmaooad18.github.io", "builds.md", buildSummary).GetAwaiter().GetResult(); log.LogInformation("Done!"); }
public static CiBuildManager Create(ILogger log, Config config) { var mgr = new CiBuildManager(log, config); mgr._connection = new VssConnection(new Uri(config.VstsCollectionUri), new VssBasicCredential(string.Empty, config.VstsPat)); mgr._buildClient = mgr._connection.GetClient <BuildHttpClient>(); mgr._serviceClient = mgr._connection.GetClient <ConnectedServiceHttpClient>(); mgr._projectClient = mgr._connection.GetClient <ProjectHttpClient>(); return(mgr); }
public static async Task BuildsSummary(string input, ILogger log, ExecutionContext context) { var config = new ConfigurationBuilder() .SetBasePath(context.FunctionAppDirectory) .AddJsonFile("local.settings.json", optional: true, reloadOnChange: true) .AddEnvironmentVariables() .Build(); var c = config.Get <CiBuildManager.Config>(); var a = CiBuildManager.Create(log, c); await UpdateBuildSummary(log, a); }
public static async Task BuildsGenerator([TimerTrigger("0 */60 * * * *")] TimerInfo myTimer, ILogger log, ExecutionContext context) { var config = new ConfigurationBuilder() .SetBasePath(context.FunctionAppDirectory) .AddJsonFile("local.settings.json", optional: true, reloadOnChange: true) .AddEnvironmentVariables() .Build(); var c = config.Get <CiBuildManager.Config>(); var a = CiBuildManager.Create(log, c); var created = await a.CreateDefs(); if (created > 0) { await UpdateBuildSummary(log, a); } else { log.LogInformation("Nothing to do here!"); } }