public async Task <string> SetStatus(string owner, string repository, string reference, string context, CommitState state, string description, string targetUrl)
        {
            if (String.IsNullOrEmpty(description))
            {
                // Get current status with the same context to preserve description
                CombinedCommitStatus combined = await _client.Repository.CommitStatus.GetCombined(owner, repository, reference);

                var status = combined.Statuses.First(s => s.Context == context);
                description = status.Description;
            }

            NewCommitStatus newStatus = new NewCommitStatus()
            {
                Context     = context,
                State       = state,
                Description = description,
                TargetUrl   = new Uri(targetUrl)
            };

            try
            {
                var rslt = await _client.Repository.CommitStatus.Create(owner, repository, reference, newStatus);

                return(rslt.Id.ToString());
            }
            catch (Exception ex)
            {
                throw ex;
            }
        }
        /// <summary>
        /// Creates a commit status for the specified ref.
        /// </summary>
        /// <param name="repositoryId">The Id of the repository</param>
        /// <param name="reference">The reference (SHA, branch name, or tag name) to list commits for</param>
        /// <param name="newCommitStatus">The commit status to create</param>
        public IObservable <CommitStatus> Create(int repositoryId, string reference, NewCommitStatus newCommitStatus)
        {
            Ensure.ArgumentNotNullOrEmptyString(reference, "reference");
            Ensure.ArgumentNotNull(newCommitStatus, "newCommitStatus");

            return(_client.Create(repositoryId, reference, newCommitStatus).ToObservable());
        }
Beispiel #3
0
 public async Task WriteCommitStatusAsync(PullRequestContext context, CommitState state, string description)
 {
     var client = new CommitStatusClient(new ApiConnection(context.GithubConnection));
     var status = new NewCommitStatus
     {
         State       = state,
         Description = description,
         Context     = _settingsProvider.Settings.StatusContext
     };
     await client.Create(context.Payload.Repository.Id, context.Payload.PullRequest.Head.Sha, status);
 }
            public void PostsToTheCorrectUrlWithRepositoryId()
            {
                var gitHubClient = Substitute.For <IGitHubClient>();
                var client       = new ObservableCommitStatusClient(gitHubClient);

                var newCommitStatus = new NewCommitStatus {
                    State = CommitState.Success
                };

                client.Create(1, "sha", newCommitStatus);

                gitHubClient.Received().Repository.Status.Create(1, "sha", newCommitStatus);
            }
Beispiel #5
0
        public async Task CanAssignPendingToCommit()
        {
            var commit = await SetupCommitForRepository(_github);

            var status = new NewCommitStatus
            {
                State       = CommitState.Pending,
                Description = "this is a test status"
            };

            var result = await _github.Repository.Status.Create(_context.RepositoryOwner, _context.RepositoryName, commit.Sha, status);

            Assert.Equal(CommitState.Pending, result.State);
        }
Beispiel #6
0
        public async Task CanRetrievePendingStatus()
        {
            var commit = await SetupCommitForRepository(_github);

            var status = new NewCommitStatus
            {
                State       = CommitState.Pending,
                Description = "this is a test status"
            };

            await _github.Repository.Status.Create(_context.RepositoryOwner, _context.RepositoryName, commit.Sha, status);

            var statuses = await _github.Repository.Status.GetAll(_context.RepositoryOwner, _context.RepositoryName, commit.Sha);

            Assert.Equal(1, statuses.Count);
            Assert.Equal(CommitState.Pending, statuses[0].State);
        }
Beispiel #7
0
        public async Task CanProvideACommitStatusWithoutRequiringAContext()
        {
            var commit = await SetupCommitForRepository(_github);

            var status = new NewCommitStatus
            {
                State       = CommitState.Pending,
                Description = "this is a test status"
            };

            await _github.Repository.Status.Create(_context.RepositoryOwner, _context.RepositoryName, commit.Sha, status);

            var statuses = await _github.Repository.Status.GetAll(_context.RepositoryOwner, _context.RepositoryName, commit.Sha);

            Assert.Equal(1, statuses.Count);
            Assert.Equal("default", statuses[0].Context);
        }
Beispiel #8
0
        /// <inheritdoc/>
        protected override async Task <object> CallGitHubApi(DialogContext dc, Octokit.GitHubClient gitHubClient, CancellationToken cancellationToken = default(CancellationToken))
        {
            if (Owner != null && Name != null && Reference != null && NewCommitStatus != null)
            {
                var ownerValue           = Owner.GetValue(dc.State);
                var nameValue            = Name.GetValue(dc.State);
                var referenceValue       = Reference.GetValue(dc.State);
                var newCommitStatusValue = NewCommitStatus.GetValue(dc.State);
                return(await gitHubClient.Repository.Status.Create(ownerValue, nameValue, referenceValue, newCommitStatusValue).ConfigureAwait(false));
            }
            if (RepositoryId != null && Reference != null && NewCommitStatus != null)
            {
                var repositoryIdValue    = RepositoryId.GetValue(dc.State);
                var referenceValue       = Reference.GetValue(dc.State);
                var newCommitStatusValue = NewCommitStatus.GetValue(dc.State);
                return(await gitHubClient.Repository.Status.Create((Int64)repositoryIdValue, referenceValue, newCommitStatusValue).ConfigureAwait(false));
            }

            throw new ArgumentNullException("Required [reference,newCommitStatus] arguments missing for GitHubClient.Repository.Status.Create");
        }
        public async Task CanUpdatePendingStatusToSuccess()
        {
            var commit = await SetupCommitForRepository(_client);

            var status = new NewCommitStatus
            {
                State       = CommitState.Pending,
                Description = "this is a test status"
            };

            await _client.Repository.CommitStatus.Create(_owner, _repository.Name, commit.Sha, status);

            status.State = CommitState.Success;

            await _client.Repository.CommitStatus.Create(_owner, _repository.Name, commit.Sha, status);

            var statuses = await _client.Repository.CommitStatus.GetAll(_owner, _repository.Name, commit.Sha);

            Assert.Equal(2, statuses.Count);
            Assert.Equal(CommitState.Success, statuses[0].State);
        }
Beispiel #10
0
        public async Task CanCreateStatusesForDifferentContexts()
        {
            var commit = await SetupCommitForRepository(_github);

            var status = new NewCommitStatus
            {
                State       = CommitState.Pending,
                Description = "this is a test status",
                Context     = "System A"
            };

            await _github.Repository.Status.Create(_context.RepositoryOwner, _context.RepositoryName, commit.Sha, status);

            status.Context = "System B";

            await _github.Repository.Status.Create(_context.RepositoryOwner, _context.RepositoryName, commit.Sha, status);

            var statuses = await _github.Repository.Status.GetAll(_context.RepositoryOwner, _context.RepositoryName, commit.Sha);

            Assert.Equal(2, statuses.Count);
            Assert.Equal("System B", statuses[0].Context);
            Assert.Equal("System A", statuses[1].Context);
        }
        /// <summary>
        /// Creates a commit status for the specified ref.
        /// </summary>
        /// <param name="owner">The owner of the repository</param>
        /// <param name="name">The name of the repository</param>
        /// <param name="reference">The reference (SHA, branch name, or tag name) to list commits for</param>
        /// <param name="newCommitStatus">The commit status to create</param>
        public IObservable <CommitStatus> Create(string owner, string name, string reference, NewCommitStatus newCommitStatus)
        {
            Ensure.ArgumentNotNullOrEmptyString(owner, nameof(owner));
            Ensure.ArgumentNotNullOrEmptyString(name, nameof(name));
            Ensure.ArgumentNotNullOrEmptyString(reference, nameof(reference));
            Ensure.ArgumentNotNull(newCommitStatus, nameof(newCommitStatus));

            return(_client.Create(owner, name, reference, newCommitStatus).ToObservable());
        }
 /// <summary>
 /// Creates a commit status for the specified ref.
 /// </summary>
 /// <param name="owner">The owner of the repository</param>
 /// <param name="name">The name of the repository</param>
 /// <param name="reference">The reference (SHA, branch name, or tag name) to list commits for</param>
 /// <param name="commitStatus">The commit status to create</param>
 /// <returns></returns>
 public IObservable<CommitStatus> Create(string owner, string name, string reference, NewCommitStatus commitStatus)
 {
     return _client.Create(owner, name, reference, commitStatus).ToObservable();
 }
        /// <summary>
        /// Creates a commit status for the specified ref.
        /// </summary>
        /// <param name="repositoryId">The Id of the repository</param>
        /// <param name="reference">The reference (SHA, branch name, or tag name) to list commits for</param>
        /// <param name="newCommitStatus">The commit status to create</param>
        public IObservable<CommitStatus> Create(int repositoryId, string reference, NewCommitStatus newCommitStatus)
        {
            Ensure.ArgumentNotNullOrEmptyString(reference, "reference");
            Ensure.ArgumentNotNull(newCommitStatus, "newCommitStatus");

            return _client.Create(repositoryId, reference, newCommitStatus).ToObservable();
        }
        /// <summary>
        /// Creates a commit status for the specified ref.
        /// </summary>
        /// <param name="owner">The owner of the repository</param>
        /// <param name="name">The name of the repository</param>
        /// <param name="reference">The reference (SHA, branch name, or tag name) to list commits for</param>
        /// <param name="newCommitStatus">The commit status to create</param>
        public IObservable<CommitStatus> Create(string owner, string name, string reference, NewCommitStatus newCommitStatus)
        {
            Ensure.ArgumentNotNullOrEmptyString(owner, "owner");
            Ensure.ArgumentNotNullOrEmptyString(name, "name");
            Ensure.ArgumentNotNullOrEmptyString(reference, "reference");
            Ensure.ArgumentNotNull(newCommitStatus, "newCommitStatus");

            return _client.Create(owner, name, reference, newCommitStatus).ToObservable();
        }
Beispiel #15
0
 /// <summary>
 /// Creates a commit status for the specified ref.
 /// </summary>
 /// <param name="owner">The owner of the repository</param>
 /// <param name="name">The name of the repository</param>
 /// <param name="reference">The reference (SHA, branch name, or tag name) to list commits for</param>
 /// <param name="commitStatus">The commit status to create</param>
 /// <returns></returns>
 public IObservable <CommitStatus> Create(string owner, string name, string reference, NewCommitStatus commitStatus)
 {
     return(_client.Create(owner, name, reference, commitStatus).ToObservable());
 }
            public void PostsToTheCorrectUrlWithRepositoryId()
            {
                var gitHubClient = Substitute.For<IGitHubClient>();
                var client = new ObservableCommitStatusClient(gitHubClient);

                var newCommitStatus = new NewCommitStatus { State = CommitState.Success };

                client.Create(1, "sha", newCommitStatus);

                gitHubClient.Received().Repository.Status.Create(1, "sha", newCommitStatus);
            }
Beispiel #17
0
        public static GitHubStatusResult GitHubStatus(this ICakeContext context, string userName, string apiToken, string owner, string repository, string reference, GitHubStatusSettings settings)
        {
#if DEBUG
            if (!Debugger.IsAttached)
            {
                Debugger.Launch();
            }
#endif

            settings = settings ?? new GitHubStatusSettings();

            var connection = CreateApiConnection(userName, apiToken);

            try
            {
                var commitStatus = new NewCommitStatus
                {
                    Description = settings.Description,
                    Context     = settings.Context,
                    TargetUrl   = settings.TargetUrl
                };

                switch (settings.State)
                {
                case GitHubStatusState.Success:
                    commitStatus.State = CommitState.Success;
                    break;

                case GitHubStatusState.Pending:
                    commitStatus.State = CommitState.Pending;
                    break;

                case GitHubStatusState.Failure:
                    commitStatus.State = CommitState.Failure;
                    break;

                case GitHubStatusState.Error:
                    commitStatus.State = CommitState.Error;
                    break;
                }

                var commitStatusClient = new CommitStatusClient(connection);
                var createStatusTask   = commitStatusClient.Create(owner, repository, reference, commitStatus);
                createStatusTask.Wait();

                var taskResult = createStatusTask.Result;

                var result = new GitHubStatusResult
                {
                    Id    = taskResult.Id.ToString(),
                    Url   = taskResult.Url,
                    State = taskResult.State.ToString()
                };

                return(result);
            }
            catch (Exception ex)
            {
                do
                {
                    context.Log.Error(ex.Message);
                } while ((ex = ex.InnerException) != null);

                throw new Exception("Failed to create status.");
            }
        }