Exemplo n.º 1
0
        private static string ProcessHashCandidate(GitModule module, string hash)
        {
            if (module == null)
            {
                return(hash);
            }
            string fullHash;

            if (!module.IsExistingCommitHash(hash, out fullHash))
            {
                return(hash);
            }
            return(LinkFactory.CreateCommitLink(guid: fullHash, linkText: hash, preserveGuidInLinkText: true));
        }
Exemplo n.º 2
0
        /// <summary>
        /// Gets the commit info for module.
        /// </summary>
        /// <param name="module">Git module.</param>
        /// <param name="sha1">The sha1.</param>
        /// <returns></returns>
        public static CommitInformation GetCommitInfo(GitModule module, LinkFactory linkFactory, string sha1)
        {
            string     error = "";
            CommitData data  = CommitData.GetCommitData(module, sha1, ref error);

            if (data == null)
            {
                return(new CommitInformation(error, ""));
            }

            string header = data.GetHeader(linkFactory, false);
            string body   = "\n" + WebUtility.HtmlEncode(data.Body.Trim());

            return(new CommitInformation(header, body));
        }
Exemplo n.º 3
0
        /// <summary>
        /// Gets the commit info from CommitData.
        /// </summary>
        /// <returns></returns>
        public static CommitInformation GetCommitInfo(CommitData data, LinkFactory linkFactory, bool showRevisionsAsLinks, GitModule module = null)
        {
            if (data == null)
            {
                throw new ArgumentNullException("data");
            }

            string header = data.GetHeader(linkFactory, showRevisionsAsLinks);
            string body   = "\n" + WebUtility.HtmlEncode(data.Body.Trim());

            if (showRevisionsAsLinks)
            {
                body = GitRevision.Sha1HashShortRegex.Replace(body, match => ProcessHashCandidate(module, linkFactory, hash: match.Value));
            }
            return(new CommitInformation(header, body));
        }
Exemplo n.º 4
0
        /// <summary>
        /// Gets the commit info for module.
        /// </summary>
        /// <param name="module">Git module.</param>
        /// <param name="linkFactory"></param>
        /// <param name="sha1">The sha1.</param>
        /// <returns></returns>
        public static CommitInformation GetCommitInfo(GitModule module, LinkFactory linkFactory, string sha1)
        {
            // TEMP, will be moved in the follow up refactor
            ICommitDataManager commitDataManager = new CommitDataManager(() => module);

            string     error = "";
            CommitData data  = commitDataManager.GetCommitData(sha1, ref error);

            if (data == null)
            {
                return(new CommitInformation(error, ""));
            }

            string header = data.GetHeader(linkFactory, false);
            string body   = "\n" + WebUtility.HtmlEncode(data.Body.Trim());

            return(new CommitInformation(header, body));
        }
Exemplo n.º 5
0
        /// <summary>
        /// Generate header.
        /// </summary>
        /// <returns></returns>
        public static string GetHeader(this CommitData commitData, bool showRevisionsAsLinks)
        {
            StringBuilder header      = new StringBuilder();
            string        authorEmail = GetEmail(commitData.Author);

            header.AppendLine(
                FillToLength(WebUtility.HtmlEncode(Strings.GetAuthorText()) + ":", COMMITHEADER_STRING_LENGTH) +
                "<a href='mailto:" + WebUtility.HtmlEncode(authorEmail) + "'>" +
                WebUtility.HtmlEncode(commitData.Author) + "</a>");
            header.AppendLine(
                FillToLength(WebUtility.HtmlEncode(Strings.GetAuthorDateText()) + ":",
                             COMMITHEADER_STRING_LENGTH) +
                WebUtility.HtmlEncode(
                    LocalizationHelpers.GetRelativeDateString(DateTime.UtcNow, commitData.AuthorDate.UtcDateTime) + " (" +
                    LocalizationHelpers.GetFullDateString(commitData.AuthorDate) + ")"));
            string committerEmail = GetEmail(commitData.Committer);

            header.AppendLine(
                FillToLength(WebUtility.HtmlEncode(Strings.GetCommitterText()) + ":",
                             COMMITHEADER_STRING_LENGTH) +
                "<a href='mailto:" + WebUtility.HtmlEncode(committerEmail) + "'>" +
                WebUtility.HtmlEncode(commitData.Committer) + "</a>");
            header.AppendLine(
                FillToLength(WebUtility.HtmlEncode(Strings.GetCommitDateText()) + ":",
                             COMMITHEADER_STRING_LENGTH) +
                WebUtility.HtmlEncode(
                    LocalizationHelpers.GetRelativeDateString(DateTime.UtcNow, commitData.CommitDate.UtcDateTime) + " (" +
                    LocalizationHelpers.GetFullDateString(commitData.CommitDate) + ")"));
            header.Append(
                FillToLength(WebUtility.HtmlEncode(Strings.GetCommitHashText()) + ":",
                             COMMITHEADER_STRING_LENGTH) +
                WebUtility.HtmlEncode(commitData.Guid));

            if (commitData.ChildrenGuids != null && commitData.ChildrenGuids.Count != 0)
            {
                header.AppendLine();
                string commitsString;
                if (showRevisionsAsLinks)
                {
                    commitsString = commitData.ChildrenGuids.Select(g => LinkFactory.CreateCommitLink(g)).Join(" ");
                }
                else
                {
                    commitsString = commitData.ChildrenGuids.Select(guid => guid.Substring(0, 10)).Join(" ");
                }
                header.Append(FillToLength(WebUtility.HtmlEncode(Strings.GetChildrenText()) + ":",
                                           COMMITHEADER_STRING_LENGTH) + commitsString);
            }

            var parentGuids = commitData.ParentGuids.Where(s => !String.IsNullOrEmpty(s));

            if (parentGuids.Any())
            {
                header.AppendLine();
                string commitsString;
                if (showRevisionsAsLinks)
                {
                    commitsString = parentGuids.Select(g => LinkFactory.CreateCommitLink(g)).Join(" ");
                }
                else
                {
                    commitsString = parentGuids.Select(guid => guid.Substring(0, 10)).Join(" ");
                }
                header.Append(FillToLength(WebUtility.HtmlEncode(Strings.GetParentsText()) + ":",
                                           COMMITHEADER_STRING_LENGTH) + commitsString);
            }

            return(RemoveRedundancies(header.ToString()));
        }
Exemplo n.º 6
0
        /// <summary>
        /// Generate header.
        /// </summary>
        /// <returns></returns>
        public static string GetHeader(this CommitData commitData, LinkFactory linkFactory, bool showRevisionsAsLinks)
        {
            StringBuilder header           = new StringBuilder();
            bool          authorIsCommiter = String.Equals(commitData.Author, commitData.Committer, StringComparison.CurrentCulture);
            bool          datesEqual       = commitData.AuthorDate.EqualsExact(commitData.CommitDate);

            string authorEmail = GetEmail(commitData.Author);

            header.AppendLine(
                (WebUtility.HtmlEncode(Strings.GetAuthorText()) + ":").PadRight(GetHeaderPadding()) +
                linkFactory.CreateLink(commitData.Author, "mailto:" + authorEmail));
            header.AppendLine(
                (WebUtility.HtmlEncode(datesEqual ? Strings.GetDateText() :
                                       Strings.GetAuthorDateText()) + ":").PadRight(GetHeaderPadding()) +
                WebUtility.HtmlEncode(
                    LocalizationHelpers.GetRelativeDateString(DateTime.UtcNow, commitData.AuthorDate.UtcDateTime) + " (" +
                    LocalizationHelpers.GetFullDateString(commitData.AuthorDate) + ")"));

            if (!authorIsCommiter)
            {
                string committerEmail = GetEmail(commitData.Committer);
                header.AppendLine(
                    (WebUtility.HtmlEncode(Strings.GetCommitterText()) + ":").PadRight(GetHeaderPadding()) +
                    "<a href='mailto:" + WebUtility.HtmlEncode(committerEmail) + "'>" +
                    WebUtility.HtmlEncode(commitData.Committer) + "</a>");
            }

            if (!datesEqual)
            {
                header.AppendLine(
                    (WebUtility.HtmlEncode(Strings.GetCommitDateText()) + ":").PadRight(GetHeaderPadding()) +
                    WebUtility.HtmlEncode(
                        LocalizationHelpers.GetRelativeDateString(DateTime.UtcNow, commitData.CommitDate.UtcDateTime) + " (" +
                        LocalizationHelpers.GetFullDateString(commitData.CommitDate) + ")"));
            }

            header.Append(
                (WebUtility.HtmlEncode(Strings.GetCommitHashText()) + ":").PadRight(GetHeaderPadding()) +
                WebUtility.HtmlEncode(commitData.Guid));

            if (commitData.ChildrenGuids != null && commitData.ChildrenGuids.Count != 0)
            {
                header.AppendLine();
                string commitsString;
                if (showRevisionsAsLinks)
                {
                    commitsString = commitData.ChildrenGuids.Select(g => linkFactory.CreateCommitLink(g)).Join(" ");
                }
                else
                {
                    commitsString = commitData.ChildrenGuids.Select(guid => guid.Substring(0, 10)).Join(" ");
                }
                header.Append((WebUtility.HtmlEncode(Strings.GetChildrenText()) + ":").PadRight(GetHeaderPadding()) +
                              commitsString);
            }

            var parentGuids = commitData.ParentGuids.Where(s => !String.IsNullOrEmpty(s));

            if (parentGuids.Any())
            {
                header.AppendLine();
                string commitsString;
                if (showRevisionsAsLinks)
                {
                    commitsString = parentGuids.Select(g => linkFactory.CreateCommitLink(g)).Join(" ");
                }
                else
                {
                    commitsString = parentGuids.Select(guid => guid.Substring(0, 10)).Join(" ");
                }
                header.Append((WebUtility.HtmlEncode(Strings.GetParentsText()) + ":").PadRight(GetHeaderPadding())
                              + commitsString);
            }

            return(header.ToString());
        }