Esempio n. 1
0
        /// <summary> Заполнить описание проектов в боте </summary>
        private void FillJenkinsProjects([NotNull] IMainBot mainBot,
                                         [NotNull] List <ProjectConfiguration> appConfigurationProjects,
                                         [NotNull] Func <string, JenkinsProject> jenkinsProjectFunc)
        {
            foreach (var projectConfiguration in appConfigurationProjects)
            {
                var prj = jenkinsProjectFunc(projectConfiguration.ProjectName ?? throw new NotSupportedException("Ошибка конфигурации ProjectName"));
                if (projectConfiguration.Builds != null)
                {
                    foreach (var buildConfiguration in projectConfiguration.Builds)
                    {
                        prj.AddBuildPuller(buildConfiguration.Desc ?? throw new NotSupportedException("Ошибка конфигурации ProjectBuild:Desc"),
                                           buildConfiguration.Job ?? throw new NotSupportedException("Ошибка конфигурации ProjectBuild:Job"),
                                           buildConfiguration.JobType);
                    }
                }

                prj.JenkinsPrefix = projectConfiguration.JenkinsPrefix;
                if (projectConfiguration.RedmineProject != null)
                {
                    prj.SetRedmineInfo(projectConfiguration.RedmineProject);
                }

                if (projectConfiguration.GitName != null)
                {
                    prj.GitName = projectConfiguration.GitName;
                }

                mainBot.AddProject(prj);
            }
        }
Esempio n. 2
0
 public Task <IConversation> StartConversation(IMainBot mainBot, ITgUser tgUserInfo, string firstMessage)
 {
     return(Task <IConversation> .Factory.StartNew(() =>
     {
         var conversation = new UserUnbuildedConversation(mainBot, tgUserInfo, firstMessage);
         conversation.ProcessConversation();
         return conversation;
     }));
 }
Esempio n. 3
0
 public TgClientService([NotNull] TelegramBotClient tgClient, [NotNull] IMainBot mainBot, [NotNull] ILog logger)
 {
     this.MainBot                        = mainBot;
     this.Logger                         = logger;
     this.TelegramClient                 = tgClient;
     this.TelegramClient.OnMessage      += OnMessage;
     this.TelegramClient.OnUpdate       += OnUpdate;
     this.TelegramClient.OnReceiveError += OnReceiveError;
 }
Esempio n. 4
0
        /// <summary> Заполнить пользователей </summary>
        private void FillUsers([NotNull] IMainBot mainBot)
        {
            var ldUsers = JsonConvert.DeserializeObject <List <User> >(File.ReadAllText("app.usersettings.json"));

            foreach (var user in ldUsers)
            {
                mainBot.AddUser(user);
            }
        }
Esempio n. 5
0
 public JenkinsProject([NotNull] string name,
                       [NotNull] ILog logger,
                       [NotNull] AppConfiguration.AppConfiguration configuration,
                       [NotNull] IMainBot mainBot,
                       [NotNull] IJenkinsService jenkinsService,
                       [NotNull] IRedmineService redmineService)
 {
     this.Name              = name;
     this.Logger            = logger;
     this.Configuration     = configuration;
     this.MainBot           = mainBot;
     this.JenkinsService    = jenkinsService;
     this.RedmineService    = redmineService;
     this.BuildServerPulles = new List <JenkinsJobInfo>();
     this.VersionCurrent    = "0";
 }
Esempio n. 6
0
        public RedmineService([NotNull] IMainBot mainBot, [NotNull] AppConfiguration.AppConfiguration configuration)
        {
            this.MainBot       = mainBot;
            this.ServerAddress = configuration.Services?.Redmine?.Address ?? throw new NotSupportedException("Ошибка конфигурации. Не задан redmine");

            var usr = configuration.Services?.Redmine?.NetworkCredential?.Name;
            var psw = configuration.Services?.Redmine?.NetworkCredential?.Password;

            if (usr == null || psw == null)
            {
                throw new NotSupportedException("Ошибка конфигурации. Не задан пользователь redmine");
            }
            this.NetCredintal = new NetworkCredential(usr, psw);

            this.TasksCache = new List <RedmineTaskDesc>();
        }
        public Task <IConversation> StartConversation(IMainBot mainBot, ITgUser tgUserInfo, string firstMessage)
        {
            var reMatch = this.FirstMessage.Match(firstMessage);
            var prjName = tgUserInfo.Name;

            if (reMatch.Groups["prj"].Success)
            {
                prjName = reMatch.Groups["prj"].Value.Trim();
            }
            string ver = null;

            if (reMatch.Groups["ver"].Success)
            {
                ver = reMatch.Groups["ver"].Value.Trim();
            }

            var prj = mainBot.Projects.SingleOrDefault(x => x.RedmineProjectName != null && x.RedmineProjectName.ToLower() == prjName.ToLower());

            if (prj != null)
            {
                return(Task <IConversation> .Factory.StartNew(() =>
                {
                    var conversation = new SimpleMessageConversation(mainBot, tgUserInfo);
                    var versionMessage = ConversationHelper.GenerateVersionInfo(prj, mainBot, prj.VersionCurrent).Result;
                    var msgTask = conversation.ProcessMessage(versionMessage);
                    if (!msgTask.IsCompleted)
                    {
                        msgTask.Wait();
                    }
                    return conversation;
                }));
            }
            else
            {
                return(Task <IConversation> .Factory.StartNew(() =>
                {
                    var conversation = new SimpleMessageConversation(mainBot, tgUserInfo);
                    var msgTask = conversation.ProcessMessage("Проект неизвестен");
                    if (!msgTask.IsCompleted)
                    {
                        msgTask.Wait();
                    }
                    return conversation;
                }));
            }
        }
Esempio n. 8
0
 public SimpleMessageConversation([NotNull] IMainBot mainBot, [NotNull] ITgUser tgUserInfo)
 {
     this.MainBot  = mainBot;
     this.TgUser   = tgUserInfo;
     this.IsActive = true;
 }
Esempio n. 9
0
 public UserUnbuildedConversation(IMainBot mainBot, ITgUser tgUserInfo, string firstMessage)
 {
     this.MainBot      = mainBot;
     this.TgUser       = tgUserInfo;
     this.FirstMessage = firstMessage;
 }
Esempio n. 10
0
 public UserStatLongTimeConversation(IMainBot mainBot, ITgUser tgUserInfo, string firstMessage)
 {
     this.MainBot      = mainBot;
     this.TgUser       = tgUserInfo;
     this.FirstMessage = firstMessage;
 }
Esempio n. 11
0
        public static async Task <string> GenerateVersionInfo([NotNull] IProject prj, [NotNull] IMainBot mainBot, [NotNull] string version)
        {
            // Тестировщик
            //    ⚽️
            // Программист
            //    🖥
            //Начальник
            //    💶
            //Аналитик
            //    📡

            var msg   = $"<b>Версия по проекту {prj.Name} Текущая {version}</b>\n";
            var tasks = await mainBot.RedmineService.RedmineTasks(prj.RedmineProjectName, version);

            if (tasks.Count == 0)
            {
                msg += "Задач не найдено";
            }
            else
            {
                foreach (var status in tasks
                         .Select(x => x.Status)
                         .Distinct()
                         .OrderBy(x =>
                                  x.ToLower() == "готов к работе" ? 1 :
                                  x.ToLower() == "в работе" ? 3 :
                                  x.ToLower() == "переоткрыт" ? 2 :
                                  x.ToLower() == "на тестировании" ? 4 :
                                  x.ToLower() == "решен" ? 5 : 10
                                  ))
                {
                    msg += $"\nСтатус <b>{status}</b>\n";

                    foreach (var task in tasks.Where(x => x.Status == status).OrderBy(x => x.Num))
                    {
                        msg += "\n";
                        var usr = mainBot.Users().FirstOrDefault(x => x.RedmineUser == task.AssignOn);
                        if (usr != null)
                        {
                            switch (usr.Role)
                            {
                            case EnumUserRole.Developer:
                                msg += "🖥";
                                break;

                            case EnumUserRole.Tester:
                                msg += "⚽️";
                                break;

                            case EnumUserRole.Boss:
                                msg += "💶";
                                break;

                            case EnumUserRole.Analist:
                                msg += "📡";
                                break;

                            default:
                                msg += "㊙️";
                                break;
                            }
                        }
                        else
                        {
                            msg += "㊙️";
                        }

                        msg += $"<a href=\"{mainBot.RedmineService.FormatTaskAddress(task.Num)}\">#{task.Num}</a> {task.Subject}\n";

                        //msg += "<i>Статус: " + task.Status + "</i>\n";
                        msg += "<i>Назначена: " + task.AssignOn + "</i>\n";
                    }
                }
            }

            return(msg);
        }