Beispiel #1
0
        /// <summary>
        /// Generates the badge and stores is on the BadgesBlob blob storage.
        ///
        /// The BadgesBlob needs to be configured in the config files
        /// </summary>
        /// <param name="helper"></param>
        /// <param name="configurationHelper"></param>
        /// <param name="binder"></param>
        /// <param name="badgeFileName"></param>
        /// <returns>the uri of the blob the badge was written to</returns>
        private static async Task <string> WriteBadgeToStorage(DeploymentCompletedEventHelper helper, ConfigurationHelper configurationHelper, Binder binder, string badgeFileName, string contentType)
        {
            var generator = new ShieldsIOBadgeGenerator();

            var badgeContent = await generator.GenerateBadge(
                helper.ReleaseDefinitionName,
                helper.ReleaseName,
                helper.GetColor(),
                configurationHelper.GetFileType(),
                configurationHelper.GetStyle()
                );

            var attributes = new Attribute[]
            {
                new BlobAttribute($"badges/{badgeFileName}", FileAccess.ReadWrite),
                new StorageAccountAttribute("BadgesBlob")
            };

            var maxAge = configurationHelper.GetMaxAge();

            CloudBlockBlob cloudBlob = await binder.BindAsync <CloudBlockBlob>(attributes);

            cloudBlob.Properties.CacheControl = $"public, max-age={maxAge}";
            cloudBlob.Properties.ContentType  = (contentType == "svg") ? $"image/{contentType}+xml" : $"image/{contentType}";

            await cloudBlob.UploadFromByteArrayAsync(badgeContent, 0, badgeContent.Length);

            return(cloudBlob.Uri.AbsoluteUri);
        }
Beispiel #2
0
        public static async Task <object> Run([HttpTrigger(WebHookType = "genericJson")] HttpRequestMessage req, Binder binder, TraceWriter log)
        {
            string badgeFileName = null;

            log.Info($"Webhook was triggered!");

            var eventHelper     = new DeploymentCompletedEventHelper(await req.Content.ReadAsStringAsync());
            var parameterHelper = new ConfigurationHelper(req);

            if (eventHelper.IsValidEvent())
            {
                return(req.CreateResponse(HttpStatusCode.BadRequest, new { error = "invalid event" }));
            }

            log.Info($"{eventHelper.Id} with status {eventHelper.Status} for environment {eventHelper.EnvironmentName}");

            if (eventHelper.Status != "succeeded" && parameterHelper.EnabledAllStatus() == false)
            {
                return(req.CreateResponse(HttpStatusCode.OK, new { result = $"status {eventHelper.Status} ignored for for {eventHelper.Id}" }));
            }

            string releaseIdentifier = GetReleaseIdentifier(parameterHelper, eventHelper);

            badgeFileName = string.Format("{0}/{1}-{2}.{3}", eventHelper.GetTeamProjectName(), releaseIdentifier, eventHelper.EnvironmentName, parameterHelper.GetFileType());

            log.Info($"going to generate badge with name {badgeFileName}");

            var blobUri = await WriteBadgeToStorage(eventHelper, parameterHelper, binder, badgeFileName, parameterHelper.GetFileType());

            log.Info($"badge stored on {blobUri}");

            return(req.CreateResponse(HttpStatusCode.OK, new { result = $"Generated {badgeFileName} for {eventHelper.Id} on {blobUri}" }));
        }
Beispiel #3
0
        private static string GetReleaseIdentifier(ConfigurationHelper parameterHelper, DeploymentCompletedEventHelper eventHelper)
        {
            var releaseFriendlyName = parameterHelper.GetReleaseDefinitionFriendlyName();

            if (releaseFriendlyName != null)
            {
                return(releaseFriendlyName);
            }

            if (parameterHelper.UseReleaseName())
            {
                return(eventHelper.GetReleaseName());
            }

            return(eventHelper.GetReleaseIdentifier());
        }