<commit_before>﻿namespace Nubot.Plugins.Samples.TeamCity
{
    #region

    using System;
    using System.Collections.Generic;
    using System.ComponentModel.Composition;
    using System.Net;
    using System.Net.Http;
    using System.Text;
    using Abstractions;
    using Github.Models;

    #endregion

    [Export(typeof (IRobotPlugin))]
    public class TeamCityBuildTrigger : RobotPluginBase
    {
        private readonly List<IPluginSetting> _settings;

        const string BodyFormat = @"<build branchName=""{0}""><buildType id=""{1}""/></build>";

        [ImportingConstructor]
        public TeamCityBuildTrigger(IRobot robot)
            : base("TeamCity Build Trigger", robot)
        {
            _settings = new List<IPluginSetting>
            {
                new PluginSetting(Robot, this, "TeamCityServerUrl"),
                new PluginSetting(Robot, this, "TeamCityBuildTriggerUsername"),
                new PluginSetting(Robot, this, "TeamCityBuildTriggerPassword")
            };

            Robot.EventEmitter.On<GithubModel>("Github.Push", OnCommit);
        }

        private void OnCommit(IMessage<GithubModel> message)
        {
            TriggerTeamCityBuild(message.Content);
        }

        private void TriggerTeamCityBuild(GithubModel model)
        {
            var branch = model.Ref.Replace("refs/heads/", "");

            var buildConfId = "";

            var branchName = string.Empty;

            if (branch.StartsWith("feature") || branch.StartsWith("bugfix"))
            {
                buildConfId = "SkyeEditor_Features";
                branchName = branch.Substring(branch.LastIndexOf('/') + 1);
            }

            if (branch.StartsWith("release"))
            {
                //todo this seems not to work check http://ci.innoveo.com/viewType.html?buildTypeId=SkyeEditor_Release&branch_SkyeEditor_Releases=skye-editor-4.23.0&tab=buildTypeStatusDiv
                buildConfId = "SkyeEditor_Release";
                //LAURENT: TODO move to settings
                var releaseBranchNamePrefix = "/skye-editor-";
                branchName = branch.Substring(branch.LastIndexOf(releaseBranchNamePrefix, StringComparison.Ordinal) + releaseBranchNamePrefix.Length);
            }

            if (string.IsNullOrWhiteSpace(branchName)) return;<commit_msg>Avoid to start a TeamCity build when a branch is deleted from Github<commit_after>﻿namespace Nubot.Plugins.Samples.TeamCity
{
    #region

    using System;
    using System.Collections.Generic;
    using System.ComponentModel.Composition;
    using System.Net;
    using System.Net.Http;
    using System.Text;
    using Abstractions;
    using Github.Models;

    #endregion

    [Export(typeof (IRobotPlugin))]
    public class TeamCityBuildTrigger : RobotPluginBase
    {
        private readonly List<IPluginSetting> _settings;

        const string BodyFormat = @"<build branchName=""{0}""><buildType id=""{1}""/></build>";

        [ImportingConstructor]
        public TeamCityBuildTrigger(IRobot robot)
            : base("TeamCity Build Trigger", robot)
        {
            _settings = new List<IPluginSetting>
            {
                new PluginSetting(Robot, this, "TeamCityServerUrl"),
                new PluginSetting(Robot, this, "TeamCityBuildTriggerUsername"),
                new PluginSetting(Robot, this, "TeamCityBuildTriggerPassword")
            };

            Robot.EventEmitter.On<GithubModel>("Github.Push", OnPush);
        }

        private void OnPush(IMessage<GithubModel> message)
        {
            var githubModel = message.Content;

            if (githubModel.Deleted) return;

            TriggerTeamCityBuild(githubModel);
        }

        private void TriggerTeamCityBuild(GithubModel model)
        {
            var branch = model.Ref.Replace("refs/heads/", "");

            var buildConfId = "";

            var branchName = string.Empty;

            if (branch.StartsWith("feature") || branch.StartsWith("bugfix"))
            {
                buildConfId = "SkyeEditor_Features";
                branchName = branch.Substring(branch.LastIndexOf('/') + 1);
            }

            if (branch.StartsWith("release"))
            {
                //todo this seems not to work check http://ci.innoveo.com/viewType.html?buildTypeId=SkyeEditor_Release&branch_SkyeEditor_Releases=skye-editor-4.23.0&tab=buildTypeStatusDiv
                buildConfId = "SkyeEditor_Release";
                //LAURENT: TODO move to settings
                var releaseBranchNamePrefix = "/skye-editor-";
                branchName = branch.Substring(branch.LastIndexOf(releaseBranchNamePrefix, StringComparison.Ordinal) + releaseBranchNamePrefix.Length);
            }

            if (string.IsNullOrWhiteSpace(branchName)) return;
{'fraction_non_alphanumeric': 0.10072840790842871, 'fraction_numerical': 0.0029136316337148803, 'mean_word_length': 2.3305613305613306, 'pattern_counts': {'":': 0, '<': 17, '<?xml version=': 0, '>': 17, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '4436927', 'n_tokens_mistral': 1331, 'n_tokens_neox': 1283, 'n_words': 243}