Esempio n. 1
0
 public Comment(CommitComment comment)
 {
     Id   = comment.Id;
     Url  = comment.Url;
     Body = comment.Body;
     User = comment.User.Id;
 }
Esempio n. 2
0
        public async Task PostComment(string comment, int?lineFrom, int?lineTo)
        {
            var c = await _applicationService.Client.Commits.CreateComment(Username, Repository, Node, new NewChangesetComment
            {
                Content  = comment,
                LineFrom = lineFrom,
                LineTo   = lineTo,
                Filename = Filename
            });

            var newComment = new CommitComment
            {
                Content = new CommitCommentContent
                {
                    Html = c.ContentRendered,
                    Raw  = c.Content
                },
                CreatedOn = c.UtcCreatedOn,
                Id        = c.CommentId,
                UpdatedOn = c.UtcLastUpdated,
                Inline    = new CommitCommentInline
                {
                    From = c.LineFrom,
                    Path = c.Filename,
                    To   = c.LineTo
                },
                User = new Client.User
                {
                    Username = c.Username,
                    Links    = new Client.User.UserLinks
                    {
                        Avatar = new Link(c.UserAvatarUrl)
                    }
                }
            };

            Comments = new List <CommitComment>(Comments.Concat(Enumerable.Repeat(newComment, 1)));
        }
        private async void btnScan_Click(object sender, EventArgs e)
        {
            this.btnScan.Enabled = false;

            var repository = this.cmbRepositories.SelectedItem as Repository;
            var branch     = this.cmbBranches.SelectedItem as Branch;

            if (this.cmbRepositories.SelectedIndex < 0)
            {
                MessageBox.Show("Please select at least one repository.");
                this.btnScan.Enabled = true;
                return;
            }

            if (this.cmbBranches.SelectedIndex < 0)
            {
                MessageBox.Show("Please select at least one branch.");
                this.btnScan.Enabled = true;
                return;
            }

            var gitHubClient = new GitHubClient(new ProductHeaderValue("SmartWork"))
            {
                //Credentials = new Credentials("*****@*****.**", "xiangning520")
                Credentials = new Credentials("*****@*****.**", "change_2017")
            };

            DateTime start = this.dtpStart.Value;
            DateTime end   = this.dtpEnd.Value;

            //var request = new CommitRequest { Since = DateTime.Today.AddDays(-2), Until = DateTime.Now };
            //var request = new CommitRequest { Author = "tracyxiang-tx" };
            //var commits = await gitHubClient.Repository.Commit.GetAll(repository.Id, request);
            // https://stackoverflow.com/questions/16517405/get-git-commits-by-branch-name-id-with-git-api
            var request = new CommitRequest {
                Since = start, Until = end, Sha = branch.Name
            };
            var commits = await gitHubClient.Repository.Commit.GetAll(repository.Id, request);

            List <CommitComment> commitComments = new List <CommitComment>();

            foreach (var commit in commits)
            {
                // var comments = await gitHubClient.Repository.Comment.GetAllForCommit(repository.Id, commit.Sha);
                // https://github.com/octokit/octokit.net/issues/869
                var comment = await gitHubClient.Repository.Commit.Get(repository.Id, commit.Sha);

                if (comment.Files != null)
                {
                    CommitComment commitComment = new CommitComment();
                    commitComment.Gitlink      = comment.HtmlUrl;
                    commitComment.Message      = comment.Commit.Message;
                    commitComment.AuthorName   = comment.Commit.Author.Name;
                    commitComment.AuthorEmail  = comment.Commit.Author.Email;
                    commitComment.CommitedDate = comment.Commit.Author.Date.Date;

                    commitComment.FileList = new List <CommitedFileInfo>();
                    foreach (var file in comment.Files)
                    {
                        CommitedFileInfo fileInfo = new CommitedFileInfo();
                        fileInfo.Name   = file.Filename;
                        fileInfo.Status = file.Status;

                        commitComment.FileList.Add(fileInfo);
                    }

                    commitComments.Add(commitComment);
                }
            }

            this.txtCommitCommentOutput.Text = "";
            StringBuilder sb    = new StringBuilder();
            int           index = 1;

            foreach (var commitComment in commitComments)
            {
                sb.Append("" + index + ". " + commitComment.Gitlink + Environment.NewLine);
                sb.Append("------------------------------------------------" + Environment.NewLine);
                sb.Append(commitComment.Message + Environment.NewLine);
                sb.Append("------ File List ------------" + Environment.NewLine);
                foreach (var fileInfo in commitComment.FileList)
                {
                    sb.Append("[" + fileInfo.Status + "]" + fileInfo.Name + Environment.NewLine);
                }
                sb.Append("------------------------------------------------" + Environment.NewLine);
                sb.Append("Author: " + commitComment.AuthorName + "[" + commitComment.AuthorEmail + "] - " + commitComment.CommitedDate.ToString() + Environment.NewLine);
                sb.Append(Environment.NewLine + Environment.NewLine);

                index++;
            }

            this.txtCommitCommentOutput.Text = sb.ToString();
            this.btnScan.Enabled             = true;
        }