Exemple #1
0
        public static IssueEvent CreateIssueEvent(IDataRecord template, EventType eventType)
        {
            Guard.ArgumentNotNull(template, nameof(template));
            string rp = template.ReadAsString(IssueTableSnapshot.ResourcePathFieldName);

            string[] splits     = rp.Split(new char[] { '/' }, System.StringSplitOptions.RemoveEmptyEntries);
            string   owner      = splits[0];
            string   repository = splits[1];

            IssueEvent ev = new IssueEvent(owner, repository)
            {
                EventType    = eventType,
                CreatedAt    = template.ReadAsDateTime(IssueTableSnapshot.CreatedAtFieldName, enforceValue: true).Value,
                UpdatedAt    = template.ReadAsDateTime(IssueTableSnapshot.UpdatedAtFieldName, enforceValue: true).Value,
                Number       = template.ReadAsString(IssueTableSnapshot.NumberFieldName),
                State        = template.ReadAsString("state"),
                ResourcePath = rp
            };

            return(ev);
        }
Exemple #2
0
        public override string BuildMessage(string[] eventGroups, Func <string, IEnumerable <IEvent> > groupGetter)
        {
            Guard.AssertNotNull(this.Configuration);
            MarkdownNotificationRendererSettings settings = new MarkdownNotificationRendererSettings();

            Guard.ArgumentNotNull(eventGroups, nameof(eventGroups));
            Guard.ArgumentNotNull(groupGetter, nameof(groupGetter));
            System.Reflection.Assembly th = typeof(MarkdownNotificationRenderer).Assembly;

            StringBuilder sb = new StringBuilder();

            if (settings.ShowHeader)
            {
                sb.AppendLine(string.Format("# GGQL Notification"));
            }
            string[] columnNames = new string[] { "Owner", "Repository", "Issue", "Event", "Url" };
            string[] headerLine  = new string[] { "---", "---", "---", "---", "---" };
            Guard.Assert(headerLine.Length == columnNames.Length);
            foreach (string eg in eventGroups)
            {
                if (settings.ShowGroupHeader)
                {
                    sb.AppendLine(string.Format("## {0}", eg));
                }

                if (eg.ToLowerInvariant() == "issue")
                {
                    string line1 = string.Join("|", columnNames);
                    string line2 = string.Join("|", headerLine);

                    sb.AppendLine(line1);
                    sb.AppendLine(line2);

                    foreach (IEvent e1 in groupGetter(eg))
                    {
                        IssueEvent ie = e1 as IssueEvent;
                        {
                            string   uri        = string.Format(@"https://github.com{0}", ie.ResourcePath);
                            string[] rowContent = new string[] { ie.Owner, ie.Repository, ie.Number, ie.EventType.ToString(), uri };
                            Guard.Assert(rowContent.Length == columnNames.Length);
                            string dataLine = String.Join("|", rowContent);
                            sb.AppendLine(dataLine);
                        }
                    }
                }
                else
                {
                    string rowTemplate = "{0}|{1}|{2}|{3}";
                    sb.AppendLine(string.Format(rowTemplate, "Owner", "Repository", "Event", "Url"));
                    sb.AppendLine(string.Format(rowTemplate, "---", "---", "---", "---"));

                    foreach (IEvent e1 in groupGetter(eg))
                    {
                        RepositoryEvent re = e1 as RepositoryEvent;
                        if (re != null)
                        {
                            string uri = string.Format(@"https://github.com/{0}/{1}/", re.Owner, re.Name);
                            sb.AppendLine(string.Format(rowTemplate, re.Owner, re.Name, re.EventType, uri));
                        }
                    }
                } //not issue
                if (settings.ShowGroupHeader)
                {
                    sb.AppendLine(); //group footer
                }
            } //foreach eventGroup
            sb.AppendLine("");
            sb.AppendLine(string.Format("<!-- Created with GGQL NotificationBuilder v {0} --> ", Helper.GetProductVersion(th)));
            return(sb.ToString());
        }