Ejemplo n.º 1
0
        public static Func <HttpRequest, HttpResponse, RouteData, Task> Create(SyncActor syncActor, IMetrics metrics, HooksHelper hooksHelper)
        {
            return(async(req, res, routedata) =>
            {
                var commitId = req.Query["commit"].ToString();
                if (!IsCommitIdString(commitId))
                {
                    res.StatusCode = 400;
                    await res.WriteAsync("Invalid commit id");

                    return;
                }

                try
                {
                    await syncActor.PushToUpstream(commitId);

                    metrics.Measure.Counter.Increment(Push, Success);

                    #pragma warning disable CS4014
                    hooksHelper.TriggerNotificationHooksForCommit(commitId);
                    #pragma warning restore CS4014
                }
                catch (Exception ex)
                {
                    metrics.Measure.Counter.Increment(Push, Failure);
                    res.StatusCode = 500;
                    await res.WriteAsync(ex.Message);
                }
                #pragma warning disable CS4014
                syncActor.SyncToLatest();
                #pragma warning restore CS4014
            });
        }
Ejemplo n.º 2
0
        public async Task TriggerNotificationHooksForCommit()
        {
            var commitId = "abcdef";

            var(mockHttp, hookRequests) = TriggerNotificationHooksForCommit_Setup(commitId);

            await hooksHelper.TriggerNotificationHooksForCommit(commitId);

            Assert.Equal(1, mockHttp.GetMatchCount(hookRequests[0]));
            Assert.Equal(1, mockHttp.GetMatchCount(hookRequests[1]));
            Assert.Equal(1, mockHttp.GetMatchCount(hookRequests[2]));
            Assert.Equal(0, mockHttp.GetMatchCount(hookRequests[3]));
        }