示例#1
1
        internal static void SetGitHubBuildStatus(
            Build build,
            CommitState state,
            Func<string, string, BuildConfiguration> getBuildConfiguration,
            Func<Build, string> getBuildDescription,
            Func<string> getHost,
            Action<string, string, string, string, CommitState, Uri, string> createGitHubCommitStatus)
        {
            var buildConfiguration = getBuildConfiguration(
                build.RepositoryOwner,
                build.RepositoryName);

            if (buildConfiguration == null)
                throw new Exception("Could not find build configuration.");

            var targetUrl = new Uri(String.Format(
                "http://{0}/{1}/{2}/builds/{3}",
                getHost(),
                build.RepositoryOwner,
                build.RepositoryName,
                build.Id));

            createGitHubCommitStatus(
                buildConfiguration.Token,
                build.RepositoryOwner,
                build.RepositoryName,
                build.Revision,
                state,
                targetUrl,
                getBuildDescription(build));
        }
示例#2
0
        public static void SetGitHubBuildStatus(
            Build build,
            CommitState state)
        {
            SetGitHubBuildStatus(
                build,
                state,
                GetBuildConfiguration,
                GetBuildDescription,
                GetHost,
                (token, owner, name, sha, commitState, targetUrl, description) =>
                {
                    var gitHubClient = GetGitHubClient();
                    gitHubClient.Credentials = new Credentials(token);

                    gitHubClient.Repository.CommitStatus.Create(
                        owner,
                        name,
                        sha,
                        new NewCommitStatus
                        {
                            State = commitState,
                            TargetUrl = targetUrl,
                            Description = description
                        }).Wait();
                });
        }
示例#3
0
        internal static void SetGitHubBuildStatus(
            Build build,
            CommitState state,
            Func <string, string, BuildConfiguration> getBuildConfiguration,
            Func <Build, string> getBuildDescription,
            Func <string> getHost,
            Action <string, string, string, string, CommitState, Uri, string> createGitHubCommitStatus)
        {
            var buildConfiguration = getBuildConfiguration(
                build.RepositoryOwner,
                build.RepositoryName);

            if (buildConfiguration == null)
            {
                throw new Exception("Could not find build configuration.");
            }

            var targetUrl = new Uri(String.Format(
                                        "http://{0}/{1}/{2}/builds/{3}",
                                        getHost(),
                                        build.RepositoryOwner,
                                        build.RepositoryName,
                                        build.Id));

            createGitHubCommitStatus(
                buildConfiguration.Token,
                build.RepositoryOwner,
                build.RepositoryName,
                build.Revision,
                state,
                targetUrl,
                getBuildDescription(build));
        }
示例#4
0
        public static void SetGitHubBuildStatus(
            Build build,
            CommitState state)
        {
            SetGitHubBuildStatus(
                build,
                state,
                GetBuildConfiguration,
                GetGitHubBuildStatusDescription,
                GetHost,
                (token, owner, name, sha, commitState, targetUrl, description) =>
            {
                var gitHubClient         = GetGitHubClient();
                gitHubClient.Credentials = new Credentials(token);

                gitHubClient.Repository.CommitStatus.Create(
                    owner,
                    name,
                    sha,
                    new NewCommitStatus
                {
                    State       = commitState,
                    TargetUrl   = targetUrl,
                    Description = description
                }).Wait();
            });
        }
        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;
            }
        }
 public CombinedCommitStatus(CommitState state, string sha, int totalCount, IReadOnlyList<CommitStatus> statuses, Repository repository)
 {
     State = state;
     Sha = sha;
     TotalCount = totalCount;
     Statuses = statuses;
     Repository = repository;
 }
示例#7
0
 public CombinedCommitStatus(CommitState state, string sha, int totalCount, IReadOnlyList <CommitStatus> statuses, Repository repository)
 {
     State      = state;
     Sha        = sha;
     TotalCount = totalCount;
     Statuses   = statuses;
     Repository = repository;
 }
示例#8
0
        protected DelayedCommitDatabaseConnection(IDbConnectionFactory factory, int commitDelay)
        {
            _lockObject  = new object();
            _commitDelay = commitDelay;
            _commitTimer = new Timer(CommitAfterDelayCallback);
            _commitState = CommitState.Paused;

            Connection   = factory.Open();
            _transaction = Connection.OpenTransaction();
        }
示例#9
0
 /// <summary>
 /// 实例化数据库访问对象
 /// </summary>
 internal DataBaseOperate(DBInfo db, bool isAutoClose)
 {
     _db        = db;
     _dbAdapter = db.CurrentDbAdapter;
     if (!isAutoClose)
     {
         _commitState = CommitState.UserCommit;
     }
     _outputer = db.SqlOutputer.CreateOutput(this);
 }
示例#10
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);
 }
示例#11
0
        public void RollbackAndDispose()
        {
            lock (_lockObject)
            {
                _commitState = CommitState.Completed;

                RollbackAndDisposeTransaction();
                DisposeConnection();

                base.Dispose(true);
            }
        }
示例#12
0
 public CommitStatus(DateTimeOffset createdAt, DateTimeOffset updatedAt, CommitState state, Uri targetUrl, string description, string context, int id, Uri url, User creator)
 {
     CreatedAt   = createdAt;
     UpdatedAt   = updatedAt;
     State       = state;
     TargetUrl   = targetUrl;
     Description = description;
     Context     = context;
     Id          = id;
     Url         = url;
     Creator     = creator;
 }
示例#13
0
 public CommitStatus(DateTimeOffset createdAt, DateTimeOffset updatedAt, CommitState state, Uri targetUrl, string description, string context, int id, Uri url, User creator)
 {
     CreatedAt = createdAt;
     UpdatedAt = updatedAt;
     State = state;
     TargetUrl = targetUrl;
     Description = description;
     Context = context;
     Id = id;
     Url = url;
     Creator = creator;
 }
示例#14
0
        public void passes_the_commit_state_to_the_GitHub_API(CommitState state)
        {
            var build = new Build();

            fn.SetGitHubBuildStatus(
                build,
                state,
                _fakeGetBuildConfiguration,
                _fakeGetBuildDescription,
                _fakeGetHost,
                (token, owner, name, sha, commitState, targetUrl, description) =>
                Assert.Equal(state, commitState));
        }
        public void passes_the_commit_state_to_the_GitHub_API(CommitState state)
        {
            var build = new Build();

            fn.SetGitHubBuildStatus(
                build,
                state,
                _fakeGetBuildConfiguration,
                _fakeGetBuildDescription,
                _fakeGetHost,
                (token, owner, name, sha, commitState, targetUrl, description) =>
                    Assert.Equal(state, commitState));
        }
示例#16
0
        public void DelayedCommitAndDispose()
        {
            lock (_lockObject)
            {
                if (_commitState == CommitState.Completed)
                {
                    return;
                }

                _commitTime = DateTime.UtcNow.AddMilliseconds(_commitDelay);
                _commitTimer.Change(_commitDelay, Timeout.Infinite);
                _commitState = CommitState.CommittingAfterDelay;
            }
        }
        public void SetStateTest()
        {
            Transaction         context = new Transaction();
            ResourceManagerList rms     = new ResourceManagerList(MyRMTest.MockRM());

            rms.Add(MyRMTest.MockRM());
            CommitedTransaction_Accessor target = new CommitedTransaction_Accessor(context, rms);
            CommitState state = CommitState.Prepared;

            target.SetState(0, state);
            Assert.IsFalse(target.stepWaitEvent.WaitOne(300));
            target.SetState(1, state);
            Assert.IsTrue(target.stepWaitEvent.WaitOne(1000));
        }
示例#18
0
        private static string GetStatusDescription(CommitState state)
        {
            switch (state)
            {
            case CommitState.Error: return("Errored");

            case CommitState.Failure: return("Failed");

            case CommitState.Pending: return("In Progress");

            case CommitState.Success: return("Succeeded");

            default: return("Unknown");
            }
        }
示例#19
0
        public void ForceCommitAndDispose()
        {
            lock (_lockObject)
            {
                if (_commitState == CommitState.Completed)
                {
                    return;
                }

                _commitTimer?.Dispose();
                _commitTimer = null;

                _commitState = CommitState.Completed;

                CommitAndDisposeTransaction();
                DisposeConnection();

                base.Dispose(true);
            }
        }
示例#20
0
        /// <inheritdoc />
        public Task SetCommitStatus(PullRequest pullRequest, CommitState commitState, string description)
        {
            if (pullRequest == null)
            {
                throw new ArgumentNullException(nameof(pullRequest));
            }
            if (description == null)
            {
                throw new ArgumentNullException(nameof(description));
            }
            var commit = pullRequest.Head.Sha;

            logger.LogTrace("SetCommitStatus for {0} to {1} with desc: {2}", commit, commitState, description);
            return(gitHubClient.Repository.Status.Create(gitHubConfiguration.RepoOwner, gitHubConfiguration.RepoName, commit, new NewCommitStatus()
            {
                Context = String.Concat(Application.UserAgent, '/', "status"),
                Description = description,
                State = commitState,
                TargetUrl = String.Join('/', generalConfiguration.RootURL, PullRequestController.Route, pullRequest.Number)
            }));
        }
示例#21
0
        public bool PauseCommit()
        {
            lock (_lockObject)
            {
                switch (_commitState)
                {
                case CommitState.Paused:
                    return(true);

                case CommitState.CommittingAfterDelay:
                    _commitState = CommitState.Paused;
                    _commitTimer.Change(Timeout.Infinite, Timeout.Infinite);
                    return(true);

                case CommitState.Completed:
                    return(false);

                default:
                    return(false);
                }
            }
        }
示例#22
0
        /// <summary>
        /// Sets state of a RM.
        /// If all RMs are set to a state. the stepWaitEvent will be set.
        ///
        /// </summary>
        /// <param name="index"></param>
        /// <param name="state"></param>
        private void SetState(int index, CommitState state)
        {
            CommitState result = CommitState.Rollbacked;

            lock (rmCommitStates)
            {
                rmCommitStates[index] = state;

                foreach (CommitState item in this.rmCommitStates)
                {
                    if (item < result)
                    {
                        result = item;
                    }
                }

                if (result != this.State)
                {
                    this.State = result;
                    this.stepWaitEvent.Set();
                }
            }
        }
        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>
        /// Sets state of a RM.
        /// If all RMs are set to a state. the stepWaitEvent will be set. 
        /// 
        /// </summary>
        /// <param name="index"></param>
        /// <param name="state"></param>
        private void SetState(int index, CommitState state)
        {
            CommitState result = CommitState.Rollbacked;
            lock (rmCommitStates)
            {
                rmCommitStates[index] = state;

                foreach (CommitState item in this.rmCommitStates)
                {
                    if (item < result)
                    {
                        result = item;
                    }
                }

                if (result != this.State)
                {
                    this.State = result;
                    this.stepWaitEvent.Set();
                }
            }
        }
        public Handler()
        {
            Get["/{user}", true] = async(parms, ct) =>
            {
                var user = await client.User.Get(parms.user.ToString());

                return(String.Format("{0} people love {1}!", user.Followers, user.Name));
            };

            // No need to write about this
            Get["/{user}/{repo}/{sha}", true] = async(parms, ct) =>
            {
                var accessToken = Session["accessToken"] as string;
                if (string.IsNullOrEmpty(accessToken))
                {
                    return(RedirectToOAuth());
                }
                client.Credentials = new Credentials(accessToken);

                try
                {
                    IEnumerable <CommitStatus> statuses = await client.Repository.CommitStatus.GetAll(
                        parms.user, parms.repo, parms.sha);

                    return(string.Join("<br/>",
                                       statuses.Select(x => string.Format("{0}: {1}", x.UpdatedAt, x.State))));
                }
                catch (NotFoundException)
                {
                    return(HttpStatusCode.NotFound);
                }
            };

            Get["/{user}/{repo}/{sha}/{status}", true] = async(parms, ct) =>
            {
                var accessToken = Session["accessToken"] as string;
                if (string.IsNullOrEmpty(accessToken))
                {
                    return(RedirectToOAuth());
                }
                client.Credentials = new Credentials(accessToken);

                CommitState newState = Enum.Parse(typeof(CommitState), parms.status, true);
                try
                {
                    await client.Repository.CommitStatus.Create(
                        parms.user, parms.repo, parms.sha, new NewCommitStatus
                    {
                        State     = newState,
                        TargetUrl = new Uri(Request.Url.SiteBase),
                        Context   = "arbitrary",
                    });
                }
                catch (NotFoundException)
                {
                    return(HttpStatusCode.NotFound);
                }
                return(String.Format(
                           @"Done! Go to <a href=""https://api.github.com/repos/{0}/{1}/commits/{2}/status"">this API endpiont</a> " +
                           @"or <a href=""/{0}/{1}/{2}"">the local view</a>",
                           parms.user, parms.repo, parms.sha));
            };

            Get["/authorize", true] = async(parms, ct) =>
            {
                var csrf = Session["CSRF:State"] as string;
                Session.Delete("CSRF:State");
                if (csrf != Request.Query["state"])
                {
                    return(HttpStatusCode.Unauthorized);
                }

                var successUrl = ConfigurationManager.AppSettings["baseUrl"] + "/authorize/success";
                var token      = await client.Oauth.CreateAccessToken(
                    new OauthTokenRequest(clientId, clientSecret, Request.Query["code"].ToString())
                {
                    RedirectUri = new Uri(successUrl)
                });

                Session["accessToken"] = token.AccessToken;
                return(Response.AsRedirect(successUrl));
            };

            Get["/authorize/success"] = _ =>
            {
                var origUrl = Session["OrigUrl"].ToString();
                Session.Delete("OrigUrl");
                return(Response.AsRedirect(origUrl));
            };
        }
示例#26
0
 private string GeneratePullRequestSuccessURL(string selfUrl, string owner, string repo, string reference, dynamic context, CommitState status)
 {
     return String.Format("{0}/github/status/{1}/{2}/{3}/{4}/{5}", selfUrl, owner, repo, reference, status, context);
 }
示例#27
0
 private string GeneratePullRequestSuccessURL(string selfUrl, string owner, string repo, string reference, dynamic context, CommitState status)
 {
     return(String.Format("{0}/github/status/{1}/{2}/{3}/{4}/{5}", selfUrl, owner, repo, reference, status, context));
 }