void ObjectSpace_Committed(object sender, EventArgs e)
 {
     if (View != null)
     {
         ICommitInfo ci = View.CurrentObject as ICommitInfo;
         if (ci == null)
         {
             return;
         }
         ci.OnCommited();
     }
 }
 void ObjectSpace_Committing(object sender, CancelEventArgs e)
 {
     if (View != null)
     {
         ICommitInfo ci = View.CurrentObject as ICommitInfo;
         if (ci == null)
         {
             return;
         }
         e.Cancel = ci.OnCommiting();
     }
 }
Beispiel #3
0
        public async Task <string> CreateCommitAsync(ICommitInfo commitInfo)
        {
            try
            {
                var creds      = new VssBasicCredential(string.Empty, _config.Token);
                var branchName = $"Updater_{DateTime.Now.Ticks}";

                using (var connection = new VssConnection(new Uri(_config.BaseUrl), creds))
                {
                    var gitClient = connection.GetClient <GitHttpClient>();

                    var items = await gitClient
                                .GetItemsAsync(
                        project : _config.Project,
                        repositoryId : _config.Repository
                        );

                    var commitId = items?.FirstOrDefault()?.CommitId;

                    var plainTextBytes = System.Text.Encoding.UTF8.GetBytes(commitInfo.Content);

                    var result = await gitClient.CreatePushAsync(new GitPush
                    {
                        Commits = new List <GitCommitRef>
                        {
                            new GitCommitRef
                            {
                                Comment = commitInfo.Comment,
                                Changes = new List <GitChange>
                                {
                                    new GitChange
                                    {
                                        ChangeType = VersionControlChangeType.Edit,
                                        Item       = new GitItem
                                        {
                                            Path = commitInfo.FileRelativePath
                                        },
                                        NewContent = new ItemContent
                                        {
                                            Content     = Convert.ToBase64String(plainTextBytes),
                                            ContentType = ItemContentType.Base64Encoded
                                        }
                                    }
                                }
                            }
                        },
                        RefUpdates = new List <GitRefUpdate>
                        {
                            new GitRefUpdate
                            {
                                Name        = $"refs/heads/{branchName}",
                                OldObjectId = commitId,
                            }
                        }
                    },
                                                                 project : _config.Project,
                                                                 repositoryId : _config.Repository
                                                                 );
                }
                return(branchName);
            }
            catch (Exception ex)
            {
                throw;
            }
        }