예제 #1
0
        public void CreateUpdateDeleteRule()
        {
            IssueRoutingCapability irc = new IssueRoutingCapability(_org, _repo);

            _requestSender.CreateTask(irc.ToJson());
            // delay for the service to react
            Thread.Sleep(3000);

            var ids = _requestSender.GetTaskIds();

            Assert.Contains(IssueRoutingCapability.GetTaskId(_org, _repo), ids);
            // delay for the service to react
            Thread.Sleep(3000);

            _requestSender.UpdateTask(IssueRoutingCapability.GetTaskId(_org, _repo), irc.ToJson());
            // delay for the service to react
            Thread.Sleep(3000);

            ids = _requestSender.GetTaskIds();
            Assert.Contains(IssueRoutingCapability.GetTaskId(_org, _repo), ids);
            // delay for the service to react
            Thread.Sleep(3000);

            _requestSender.DeleteTask(IssueRoutingCapability.GetTaskId(_org, _repo));
            // delay for the service to react
            Thread.Sleep(3000);

            ids = _requestSender.GetTaskIds();
            Assert.False(ids.Any(x => x == IssueRoutingCapability.GetTaskId(_org, _repo)));
        }
예제 #2
0
        private static void Main(string[] args)
        {
            if (!Parser.TryParse(args, out s_options, new ParserOptions()
            {
                VariableNamePrefix = ParserPrefix
            }))
            {
                return;
            }

            if (s_options.CookieToken == null)
            {
                Colorizer.WriteLine($"[Red!Error]: Please specify authentication token as an argument or in the environment variable [Yellow!{ParserPrefix}_token]");
                return;
            }

            FabricBotClient rs = new FabricBotClient(s_options.Owner, s_options.Repo, s_options.CookieToken);

            string payload = string.Empty;
            string taskId  = string.Empty;

            // for Create and update, construct the payload and taskId
            if (s_options.Action == ActionToTake.create || s_options.Action == ActionToTake.update)
            {
                // Instantiate the object based on the TaskType
                BaseCapability capability = CreateCapabilityObject(s_options);
                payload = capability.GetPayload();
                taskId  = capability.GetTaskId();
            }

            if (s_options.Prompt)
            {
                Colorizer.Write("Proceed with [Cyan!{0}] for repo [Yellow!{1}\\{2}] (y/n)? ", s_options.Action, s_options.Owner, s_options.Repo);
                var key = Console.ReadKey();

                if (key.Key != ConsoleKey.Y)
                {
                    Colorizer.WriteLine("No action taken.");
                    return;
                }
                Colorizer.WriteLine("");
            }

            try
            {
                switch (s_options.Action)
                {
                case ActionToTake.create:
                    rs.CreateTask(payload);
                    break;

                case ActionToTake.update:
                    rs.UpdateTask(taskId, payload);
                    break;

                case ActionToTake.delete:
                    rs.DeleteTask(s_options.TaskId);
                    break;

                case ActionToTake.deleteall:
                    rs.DeleteAll();
                    break;

                case ActionToTake.listTaskIds:
                    var taskIds = rs.GetTaskIds();
                    foreach (string item in taskIds)
                    {
                        Colorizer.WriteLine("Found task with id: [Yellow!{0}]", item);
                    }
                    break;

                default:
                    Colorizer.WriteLine($"[Red!Error]: Command [Yellow!{s_options.Action}] unknown.");
                    return;
                }
                Colorizer.WriteLine("[Green!Done].");
            }
            catch (Exception e)
            {
                Colorizer.WriteLine("[Red!Error]: {0}", e.Message);
            }
        }
예제 #3
0
        private static void Main(string[] args)
        {
            if (!Parser.TryParse(args, out s_options, new ParserOptions()
            {
                VariableNamePrefix = ParserPrefix
            }))
            {
                return;
            }

            if (s_options.CookieToken == null)
            {
                Colorizer.WriteLine($"[Red!Error]: Please specify authentication token as an argument or in the environment variable [Yellow!{ParserPrefix}_token]");
                return;
            }

            FabricBotClient        rs  = new FabricBotClient(s_options.Owner, s_options.Repo, s_options.CookieToken);
            IssueRoutingCapability irc = new IssueRoutingCapability(s_options.Owner, s_options.Repo);

            string payload = string.Empty;

            if (s_options.Action == ActionToTake.create || s_options.Action == ActionToTake.update)
            {
                Colorizer.Write("Parsing service table... ");
                MarkdownTable table = MarkdownTable.Parse(s_options.ServicesFile);
                Colorizer.WriteLine("[Green!done].");

                foreach (var row in table.Rows)
                {
                    if (!string.IsNullOrEmpty(row[2].Trim()))
                    {
                        // the row at position 0 is the label to use on top of 'Service Attention'
                        string[] labels = new string[] { "Service Attention", row[0] };

                        // The row at position 2 is the set of mentionees to ping on the issue.
                        IEnumerable <string> mentionees = row[2].Split(',').Select(x => x.Replace("@", "").Trim());

                        //add the service
                        irc.AddService(labels, mentionees);
                    }
                }

                payload = irc.ToJson();
                Colorizer.WriteLine("Found [Yellow!{0}] service routes.", irc.RouteCount);
            }

            if (s_options.Prompt)
            {
                Colorizer.WriteLine("Proceed with [Cyan!{0}] for repo [Yellow!{1}\\{2}] (y/n)? ", s_options.Action, s_options.Owner, s_options.Repo);
                var key = Console.ReadKey();

                if (key.Key != ConsoleKey.Y)
                {
                    Colorizer.WriteLine("No action taken.");
                    return;
                }
            }

            try
            {
                switch (s_options.Action)
                {
                case ActionToTake.create:
                    rs.CreateTask(payload);
                    break;

                case ActionToTake.update:
                    rs.UpdateTask(IssueRoutingCapability.GetTaskId(s_options.Owner, s_options.Repo), payload);
                    break;

                case ActionToTake.delete:
                    rs.DeleteTask(s_options.TaskId);
                    break;

                case ActionToTake.deleteall:
                    rs.DeleteAll();
                    break;

                case ActionToTake.listTaskIds:
                    var taskIds = rs.GetTaskIds();
                    foreach (string item in taskIds)
                    {
                        Colorizer.WriteLine("Found task with id: [Yellow!{0}]", item);
                    }
                    break;

                default:
                    Colorizer.WriteLine($"[Red!Error]: Command [Yellow!{s_options.Action}] unknown.");
                    return;
                }
                Colorizer.WriteLine("[Green!Done].");
            }
            catch (Exception e)
            {
                Colorizer.WriteLine("[Red!Error]: {0}", e.Message);
            }
        }