Exemple #1
0
        public async Task GetCommitMapForPathAsync(string repoUri, string branch, string assetsProducedInCommit, Dictionary <string, GitCommit> commits, string pullRequestBaseBranch, string path = "eng")
        {
            _logger.LogInformation($"Getting the contents of file/files in '{path}' of repo '{repoUri}' at commit '{assetsProducedInCommit}'");

            string repoName = SetApiUriAndGetRepoName(repoUri);

            HttpResponseMessage response = await this.ExecuteGitCommand(HttpMethod.Get, $"repositories/{repoName}/items?scopePath={path}&version={assetsProducedInCommit}&includeContent=true&versionType=commit&recursionLevel=full", _logger);

            JObject         content = JObject.Parse(await response.Content.ReadAsStringAsync());
            List <VstsItem> items   = JsonConvert.DeserializeObject <List <VstsItem> >(Convert.ToString(content["value"]));

            foreach (VstsItem item in items)
            {
                if (!item.IsFolder)
                {
                    if (!DependencyFileManager.DependencyFiles.Contains(item.Path))
                    {
                        string fileContent = await GetFileContentAsync(repoName, item.Path);

                        byte[]    encodedBytes = Encoding.UTF8.GetBytes(fileContent);
                        GitCommit gitCommit    = new GitCommit($"Updating contents of file '{item.Path}'", Convert.ToBase64String(encodedBytes), pullRequestBaseBranch);
                        commits.Add(item.Path, gitCommit);
                    }
                }
            }

            _logger.LogInformation($"Getting the contents of file/files in '{path}' of repo '{repoUri}' at commit '{assetsProducedInCommit}' succeeded!");
        }
Exemple #2
0
        public async Task GetCommitMapForPathAsync(string repoUri, string branch, string assetsProducedInCommit, Dictionary <string, GitCommit> commits, string pullRequestBaseBranch, string path = "eng")
        {
            _logger.LogInformation($"Getting the contents of file/files in '{path}' of repo '{repoUri}' at commit '{assetsProducedInCommit}'");

            string ownerAndRepo          = GetSegments(repoUri);
            HttpResponseMessage response = await this.ExecuteGitCommand(HttpMethod.Get, $"repos/{ownerAndRepo}contents/{path}?ref={assetsProducedInCommit}", _logger);

            List <GitHubContent> contents = JsonConvert.DeserializeObject <List <GitHubContent> >(await response.Content.ReadAsStringAsync());

            foreach (GitHubContent content in contents)
            {
                if (content.Type == GitHubContentType.File)
                {
                    if (!DependencyFileManager.DependencyFiles.Contains(content.Path))
                    {
                        string fileContent = await GetFileContentAsync(ownerAndRepo, content.Path);

                        GitCommit gitCommit = new GitCommit($"Updating contents of file '{content.Path}'", fileContent, pullRequestBaseBranch);
                        commits.Add(content.Path, gitCommit);
                    }
                }
                else
                {
                    await GetCommitMapForPathAsync(repoUri, branch, assetsProducedInCommit, commits, pullRequestBaseBranch, content.Path);
                }
            }

            _logger.LogInformation($"Getting the contents of file/files in '{path}' of repo '{repoUri}' at commit '{assetsProducedInCommit}' succeeded!");
        }
Exemple #3
0
        public GitCommit ToCommit(string branch, string message = null)
        {
            message = message ?? $"Darc update of '{FilePath}'";
            Encode();
            GitCommit commit = new GitCommit(message, Content, branch);

            return(commit);
        }
Exemple #4
0
        public async Task PushFilesAsync(Dictionary <string, GitCommit> filesToCommit, string repoUri, string pullRequestBaseBranch)
        {
            _logger.LogInformation($"Pushing files to '{pullRequestBaseBranch}'...");

            string ownerAndRepo = GetSegments(repoUri);

            foreach (string filePath in filesToCommit.Keys)
            {
                GitCommit commit  = filesToCommit[filePath] as GitCommit;
                string    blobSha = await CheckIfFileExistsAsync(repoUri, filePath, pullRequestBaseBranch);

                if (!string.IsNullOrEmpty(blobSha))
                {
                    commit.Sha = blobSha;
                }

                string body = JsonConvert.SerializeObject(commit, _serializerSettings);

                await this.ExecuteGitCommand(HttpMethod.Put, $"repos/{ownerAndRepo}contents/{filePath}", _logger, body);

                _logger.LogInformation($"Pushing files to '{pullRequestBaseBranch}' succeeded!");
            }
        }