Пример #1
0
 public VstsPush(VstsRefUpdate refUpdate, VstsCommit vstsCommit)
 {
     RefUpdates = new List <VstsRefUpdate> {
         refUpdate
     };
     Commits = new List <VstsCommit> {
         vstsCommit
     };
 }
Пример #2
0
        public async Task PushFilesAsync(Dictionary <string, GitCommit> filesToCommit, string repoUri, string pullRequestBaseBranch)
        {
            _logger.LogInformation($"Pushing files to '{pullRequestBaseBranch}'...");

            List <VstsChange> changes  = new List <VstsChange>();
            string            repoName = SetApiUriAndGetRepoName(repoUri);

            foreach (string filePath in filesToCommit.Keys)
            {
                string content = this.GetDecodedContent(filesToCommit[filePath].Content);
                string blobSha = await CheckIfFileExistsAsync(repoUri, filePath, pullRequestBaseBranch);

                VstsChange change = new VstsChange(filePath, content);

                if (!string.IsNullOrEmpty(blobSha))
                {
                    change.ChangeType = VstsChangeType.Edit;
                }

                changes.Add(change);
            }

            VstsCommit commit = new VstsCommit(changes, "Dependency files update");

            string latestSha = await GetLastCommitShaAsync(repoName, pullRequestBaseBranch);

            VstsRefUpdate refUpdate = new VstsRefUpdate($"refs/heads/{pullRequestBaseBranch}", latestSha);

            VstsPush vstsPush = new VstsPush(refUpdate, commit);

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

            // VSTS' contents API is only supported in version 5.0-preview.2
            await this.ExecuteGitCommand(HttpMethod.Post, $"repositories/{repoName}/pushes", _logger, body, "5.0-preview.2");

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