Пример #1
0
        private void DownloadAll(string alt_folder = "")
        {
            // remove temp folder for this commit if any
            RemoveTemp();

            // create new folder
            string dir_path;

            if (alt_folder.Trim() == "")
            {
                dir_path = Path.GetTempPath() + Commit.Sha;
            }
            else
            {
                dir_path = alt_folder + "/Commit-" + Commit.Sha;
            }
            Directory.CreateDirectory(dir_path);

            // for each file in files
            for (int i = 0; i < Files.Count; i++)
            {
                // get file
                GitHubCommitFile file = Files[i];

                // construct path to this commit
                string path = dir_path + "/";

                // download to commit folder
                DownloadFile(file, path);
            }

            MessageBox.Show("All files should be downloaded or are in queue to be downloaded");
        }
Пример #2
0
        private void DownloadFile(GitHubCommitFile file, string save_to)
        {
            // create all folders in this file names path
            string[] folders = file.Filename.Split('/');
            string   root    = save_to;

            for (int i = 0; i < folders.Length - 1; i++)
            {
                if (!Directory.Exists(root + folders[i]))
                {
                    Directory.CreateDirectory(root + folders[i]);
                }
                root += "/" + folders[i] + "/";
            }

            // download
            using (WebClient wc = new WebClient())
            {
                wc.Headers.Add("user-agent", "Mozilla/5.0 (Windows NT 6.1; WOW64) AppleWebKit/535.2 (KHTML, like Gecko) Chrome/15.0.874.121 Safari/535.2");
                wc.Headers.Add("keep-alive", "timeout=5");
                wc.Headers.Add(HttpRequestHeader.Authorization, "token="); // oAuth token goes here
                wc.DownloadProgressChanged += wc_DownloadProgressChanged;
                wc.DownloadFileCompleted   += wc_DownloadFileCompleted;

                string path = save_to + file.Filename;

                wc.DownloadFileAsync(new Uri(file.RawUrl), path);
            }
        }
Пример #3
0
 private static Dtos.CommitFile GithubCommitFileToCommitFile(GitHubCommitFile commitFile)
 {
     return(new Dtos.CommitFile
     {
         Sha = commitFile.Sha,
         Filename = commitFile.Filename,
         Status = commitFile.Status,
         PreviousFileName = commitFile.PreviousFileName,
         RawUrl = commitFile.RawUrl,
     });
 }
Пример #4
0
 public CommitFile(GitHubCommitFile file)
 {
     Filename         = file.Filename;
     Additions        = file.Additions;
     Deletions        = file.Deletions;
     Changes          = file.Changes;
     Status           = file.Status;
     BlobUrl          = file.BlobUrl;
     ContentsUrl      = file.ContentsUrl;
     RawUrl           = file.RawUrl;
     Sha              = file.Sha;
     PreviousFileName = file.PreviousFileName;
 }
Пример #5
0
        private void FileName_Click(object event_sender, EventArgs event_args, GitHubCommitFile file)
        {
            // open folder open dialog
            save_file_dialog.ShowDialog();
            string save_to = null;

            if (save_file_dialog.SelectedPath != null && save_file_dialog.SelectedPath.Trim() != "")
            {
                // if folder picked, download to that folder
                save_to = save_file_dialog.SelectedPath;
                DownloadFile(file, save_to + "/");
            }
        }
Пример #6
0
 public CommitFileVm(GitHubCommitFile gitHubCommitFile)
 {
     GitHubCommitFile = gitHubCommitFile;
 }
Пример #7
0
 public CommitFile(GitHubCommitFile commitFile)
 {
     _commitFile = commitFile;
     Status      = (FileStatus)(Enum.Parse(typeof(FileStatus), _commitFile.Status));
 }
Пример #8
0
 public static string GetFilePath(this GitHubCommitFile file, string commitSha)
 {
     return(file.Filename + "?ref=" + commitSha);
 }
Пример #9
0
        private void CommitInfoForm_Load(object sender, EventArgs e)
        {
            // set icon
            this.Icon = new Icon(@"GitHub-Mark/github_mark_120px_plus_Bzz_icon.ico");

            // happens when commit message has description also and everything gets merged into one string
            // text is all up to \n\n
            // desc is from there
            // separate those two
            if (Commit.Commit.Message.IndexOf('\n') > -1)
            {
                Text             = Commit.Commit.Message.Substring(0, Commit.Commit.Message.IndexOf('\n'));
                commit_desc.Text = Commit.Commit.Message.Substring(Commit.Commit.Message.IndexOf('\n') + 2);
            }
            else
            {
                // if there is no commit desc, just commit message
                Text = Commit.Commit.Message;

                // hide desc box as not needed
                commit_desc.Hide();
            }

            commit_sha.Text = Commit.Sha;

            // set files to files from this commit
            Files = Commit.Files;

            // write file count label out
            files_count.Text = "Showing " + Files.Count + " files";

            // go through files
            for (int i = 0; i < Files.Count; i++)
            {
                // get current file
                GitHubCommitFile file = Files[i];

                // create wrapper
                Panel wrapper = new Panel();
                wrapper.AutoSize = true;

                // create label to show file name and add events to it
                System.Windows.Forms.Label file_name = new System.Windows.Forms.Label();
                file_name.AutoSize    = true;
                file_name.Font        = new Font(new FontFamily(System.Drawing.Text.GenericFontFamilies.Serif), 12, FontStyle.Bold);
                file_name.Text        = file.Filename;
                file_name.Click      += (event_sender, event_args) => FileName_Click(event_sender, event_args, file);
                file_name.MouseEnter += (event_sender, event_args) =>
                {
                    Cursor = Cursors.Hand;
                    file_name.ForeColor = Color.DarkGreen;
                };
                file_name.MouseLeave += (event_sender, event_args) =>
                {
                    Cursor = Cursors.Default;
                    file_name.ForeColor = Color.Black;
                };
                // add label to wrapper
                wrapper.Controls.Add(file_name);

                // create label about file status
                System.Windows.Forms.Label status_lb = new System.Windows.Forms.Label();
                status_lb.AutoSize = true;
                status_lb.Text     = file.Status;
                if (file.Status == "modified")
                {
                    status_lb.ForeColor = Color.DarkOrange;
                }
                else if (file.Status == "added")
                {
                    status_lb.ForeColor = Color.DarkGreen;
                }
                else if (file.Status == "removed")
                {
                    status_lb.ForeColor = Color.DarkRed;
                }
                status_lb.Location = new Point(0, wrapper.Controls.Count * status_lb.Height);
                // add label to wrapper
                wrapper.Controls.Add(status_lb);

                // set wrapper's bottom margin to 20
                wrapper.Margin = new Padding(0, 0, 0, 20);

                // add wraper to files panel
                files_panel.Controls.Add(wrapper);
            }
        }
Пример #10
0
        private bool AddOrModifyFileChange(string commitSha, string parentSha, GitHubCommitFile file, List <DocChange> changes, DateTime utcDateTime, TraceWriter log)
        {
            var diffAnchorHash = BitConverter.ToString(_md5.ComputeHash(Encoding.UTF8.GetBytes(file.Filename)))
                                 .Replace("-", string.Empty).ToLower();

            if (!file.Filename.StartsWith(subfolder) ||
                !file.Filename.EndsWith(".md") ||
                file.Filename.EndsWith("/TOC.md", StringComparison.InvariantCultureIgnoreCase))
            {
                return(false);
            }

            var filename = file.Filename.Replace(subfolder, "").Replace("/", "\\");

            var product = Path.GetDirectoryName(filename);

            if (string.IsNullOrWhiteSpace(product) ||
                product.Split('\\').Length == 0)
            {
                return(false);
            }
            product  = product.Split('\\')[0];
            filename = Path.GetFileName(filename);

            var url = file.ContentsUrl
                      .Substring(0, file.ContentsUrl.IndexOf("?ref="))
                      .Replace("https://api.github.com/repos/", "");

            var existingDocChange = changes
                                    .Where(_ => _.Url == url)
                                    .SingleOrDefault();

            ChangeStatus changeStatus;

            if (!Enum.TryParse(value: file.Status, ignoreCase: true, result: out changeStatus))
            {
                log.Warning($"Could not parse status {file.Status}.");
            }

            if (existingDocChange == null)
            {
                changes.Add(new DocChange
                {
                    Product = product,
                    File    = Path.GetFileName(filename),
                    Url     = url,
                    Commits = new List <DocChangeCommit>
                    {
                        new DocChangeCommit()
                        {
                            Sha       = commitSha,
                            ParentSha = parentSha,
                            Status    = changeStatus,
                            DeepLink  = diffAnchorHash,
                            ChangedAt = utcDateTime
                        }
                    }
                });
            }
            else
            {
                existingDocChange.Commits.Add(
                    new DocChangeCommit()
                {
                    Sha       = commitSha,
                    ParentSha = parentSha,
                    Status    = changeStatus,
                    DeepLink  = diffAnchorHash,
                    ChangedAt = utcDateTime
                }
                    );
            }

            return(true);
        }
Пример #11
0
        public async Task <Tuple <string, string> > FetchDiffContent(GitHubCommitFile diffFile,
                                                                     string headCommit, string baseCommit)
        {
            var    headFileName  = BuildHeadFileName(headCommit, diffFile.Filename);
            var    headPath      = "";
            string contentOfHead = null;

            if (diffFile.Status == GitFileStatus.Removed)
            {
                headPath = await SaveToFile(headFileName, "");
            }
            else if (!_fileContentPersist.ExistsInCached(_pullRequestLocator, headFileName))
            {
                var collectionOfContentOfHead =
                    await
                    _client.Repository.Content.GetAllContents(_pullRequestLocator.Owner,
                                                              _pullRequestLocator.Repository,
                                                              diffFile.GetFilePath(headCommit));

                contentOfHead = collectionOfContentOfHead.First().Content;
                headPath      = await SaveToFile(headFileName, contentOfHead);
            }
            else
            {
                headPath = _fileContentPersist.GetCachedFilePath(_pullRequestLocator, headFileName);
            }

            var baseFileName = BuildBaseFileName(baseCommit, diffFile.Filename);
            var basePath     = "";

            if (_fileContentPersist.ExistsInCached(_pullRequestLocator, baseFileName))
            {
                basePath = _fileContentPersist.GetCachedFilePath(_pullRequestLocator, baseFileName);
            }
            else if (diffFile.Status == GitFileStatus.Renamed)
            {
                if (contentOfHead == null)
                {
                    contentOfHead = await _fileContentPersist.ReadContent(headPath);
                }

                basePath = _fileContentPersist.GetCachedFilePath(_pullRequestLocator, baseFileName);

                await _patchService.RevertViaPatch(contentOfHead, diffFile.Patch, basePath);
            }
            else if (diffFile.Status == GitFileStatus.New)
            {
                basePath = await SaveToFile(baseFileName, "");
            }
            else
            {
                var contentOfBase =
                    await
                    _client.Repository.Content.GetAllContents(_pullRequestLocator.Owner,
                                                              _pullRequestLocator.Repository,
                                                              diffFile.GetFilePath(baseCommit));

                basePath = await SaveToFile(baseFileName, contentOfBase.First().Content);
            }
            return(new Tuple <string, string>(basePath, headPath));
        }