示例#1
0
        public async Task TriggerBuild(SlackMessageStorage storage)
        {
            var buildInfos = SlackMessageStorage.Parse(_testMock.SlackBotsLatestMessage);

            var buildInfo = buildInfos.Single(bi => bi.ChannelName == "#ship-it");

            buildInfo.ShipUrl = "https://www.microsoft.com";

            _testMock.SlackBotsLatestMessage = SlackMessageStorage.Stringify(buildInfos);
        }
示例#2
0
        public async Task SetShipUrl(string channelName, string shipUrl)
        {
            var latest = await _slackApiService.ReadLatestMessageToSelf();

            latest ??= "";

            var store   = SlackMessageStorage.Parse(latest);
            var channel = store.FirstOrDefault(c => c.ChannelName == channelName);

            if (channel == null)
            {
                channel = new SlackMessageStorage
                {
                    ChannelName = channelName
                };
                store.Add(channel);
            }
            channel.ShipUrl = shipUrl;
            latest          = SlackMessageStorage.Stringify(store);
            await _slackApiService.PostMessage("@slackbot", latest);


            // notify in chat
            var topic = await _slackApiService.GetChannelTopic(channelName);

            var train  = Train.Parse(topic);
            var driver = train.Carriages.FirstOrDefault()?.Riders.FirstOrDefault();

            if (driver != null)
            {
                var sbShippersExcludingDriver = new StringBuilder();
                foreach (var shipper in train.Carriages[0].Riders.Skip(1))
                {
                    var atShipper = await _slackApiService.FormatAtNotificationFromUserName(shipper.Name);

                    sbShippersExcludingDriver.Append($"{atShipper} ");
                }
                var shippersExcludingDriver = sbShippersExcludingDriver.ToString();
                var atDriver = await _slackApiService.FormatAtNotificationFromUserName(driver.Name);

                await _slackApiService.PostMessage(channelName, $"New build deployed! :tada:\n {shippersExcludingDriver}\n{atDriver} please co-ordinate testing.  Once everyone is .ready we can deploy to PROD.");
            }
            else
            {
                var atHere = await _slackApiService.FormatAtHere();

                await _slackApiService.PostMessage(channelName, $"New build deployed, but wasn't expected {atHere} someone needs to figure out what's going on and post an update here.");
            }
        }
示例#3
0
        public async Task HandleMessage(CommandContext commandContext)
        {
            var channelName = commandContext.ChannelName;
            var topic       = await _slackApiService.GetChannelTopic(channelName);

            var train = Train.Parse(topic);

            await _slackApiService.PostMessage(commandContext.ChannelName, $"Running the build pipeline...");

            var messageToSelf = await _slackApiService.ReadLatestMessageToSelf();

            var store = SlackMessageStorage.Parse(messageToSelf);

            var channel = store.FirstOrDefault(c => c.ChannelName == channelName);

            if (channel == null)
            {
                channel = new SlackMessageStorage
                {
                    ChannelName = channelName,
                    ShipUrl     = ""
                };

                messageToSelf = SlackMessageStorage.Stringify(store);
                await _slackApiService.PostMessage("@slackbot", messageToSelf);
            }
            try
            {
                await _externalBuildTrigger.TriggerBuild(channel);
            }
            catch (Exception ex)
            {
                var atDriver = await _slackApiService.FormatAtNotificationFromUserName(train.Carriages[0].Riders[0].Name);

                await _slackApiService.PostMessage(commandContext.ChannelName, $"Something went wrong with the build pipeline {atDriver}");

                Console.WriteLine(ex.ToString());
            }
        }
示例#4
0
        public async Task TriggerBuild(SlackMessageStorage storage)
        {
            // Example of how to configure this for Github Actions repository_dispatch
            // https://pakstech.com/blog/github-actions-repository-dispatch/
            // Replace all PLACEHOLDER_ s in this file with the appropriate data

            var client = new HttpClient();

            client.DefaultRequestHeaders.Authorization = new AuthenticationHeaderValue("Bearer", _githubPersonalAccessToken);
            client.DefaultRequestHeaders.Host          = "api.github.com";
            client.DefaultRequestHeaders.UserAgent.Add(ProductInfoHeaderValue.Parse("C3PR"));

            var headResult = await client.GetAsync(_githubRepositoryMasterBranch);

            var headInfo = JsonConvert.DeserializeObject <BranchHeadInfo>(await headResult.Content.ReadAsStringAsync());

            var postBody = $"{{\"event_type\": \"{headInfo.Commit.Message}\"}}";
            var result   = await client.PostAsync(_githubRepositoryBuildDispatch, new StringContent(postBody));

            if (!result.IsSuccessStatusCode)
            {
                throw new Exception("Report that things didn't work as planned");
            }
        }
示例#5
0
        async Task AdvanceCarriage(Train train, string channelName)
        {
            // clear ready
            foreach (var rider in train.Carriages[0].Riders)
            {
                if (rider.Flairs.Flairs.Contains(RiderFlair.Ready))
                {
                    rider.Flairs.Flairs.Remove(RiderFlair.Ready);
                    rider.Flairs.PostflairWhitepace = "";
                }
            }
            train.Carriages[0].Riders[0].Flairs.Flairs.Remove(RiderFlair.EverReady);

            await HandlePhaseAdvancement(train, channelName);

            await _slackApiService.SetChannelTopic(channelName, train.ToString());

            if (train.Phase == Phase.Testing)
            {
                var messageToSelf = await _slackApiService.ReadLatestMessageToSelf();

                var store = SlackMessageStorage.Parse(messageToSelf);

                var channel = store.FirstOrDefault(c => c.ChannelName == channelName);
                if (channel == null)
                {
                    channel = new SlackMessageStorage
                    {
                        ChannelName = channelName,
                        ShipUrl     = ""
                    };

                    messageToSelf = SlackMessageStorage.Stringify(store);
                    await _slackApiService.PostMessage("@slackbot", messageToSelf);
                }

                try
                {
                    // trigger the build
                    await _externalBuildTriggerService.TriggerBuild(channel);

                    await _slackApiService.PostMessage(channelName, $"Starting the build...");
                }
                catch (Exception ex)
                {
                    var atHere = await _slackApiService.FormatAtHere();

                    await _slackApiService.PostMessage(channelName, $"Something went wrong triggering the build... {atHere}");

                    Console.WriteLine(ex.ToString());
                }
            }

            string deploymentUrl = null;

            if (train.Phase == Phase.Production)
            {
                var messageToSelf = await _slackApiService.ReadLatestMessageToSelf();

                var channels = SlackMessageStorage.Parse(messageToSelf);

                var channel = channels.FirstOrDefault(c => c.ChannelName == channelName);
                if (channel?.ShipUrl != null)
                {
                    // link to deploy url in channel
                    deploymentUrl = channel.ShipUrl;
                }
                else
                {
                    deploymentUrl = "Isn't configured for some reason...";
                }
            }

            if (train.Carriages.Count > 0)
            {
                await HandleBeginPhaseMessaging(train, channelName, deploymentUrl);
            }
        }