コード例 #1
0
        public Task Notify(GithubPayload payload)
        {
            string text = _formatter.Format(payload);

            text += "\r\n\r\n";
            File.AppendAllText(_path, text);
            return(Task.CompletedTask);
        }
コード例 #2
0
        public async Task Notify(GithubPayload payload)
        {
            await PopulateChatCollection();

            string message = _formatter.Format(payload);

            foreach (var chat in _chatCollection.Chats)
            {
                await _client.SendTextMessageAsync(chat, message);
            }
        }
コード例 #3
0
        public void Post(GithubPayload githubPayload)
        {
            string review_comments_url = githubPayload.pull_request.review_comments_url;

            IRestResponse response = CallGetAPI(review_comments_url);

            JObject commentsJson  = JObject.Parse("{ 'comments':" + response.Content + "}");
            int     commentsCount = commentsJson.SelectToken("comments").Count();

            Console.WriteLine(commentsCount);
        }
コード例 #4
0
        public void ReceiveWebhook(GithubPayload payload)
        {
            var ip = Request.HttpContext.Connection.RemoteIpAddress;

            _logger.Log(LogLevel.Information, "GitHub webhook received from {Ip}", ip);

            if (!(payload.Action == "closed" && payload.PullRequest.Merged))
            {
                _logger.Log(LogLevel.Debug, "Received a non-merged pull request");
                return;
            }

            _logger.Log(LogLevel.Debug, "Received a merged pull request");
        }
コード例 #5
0
        public string Format(GithubPayload payload)
        {
            StringBuilder sb = new StringBuilder();

            sb.AppendLine($"New push on {payload.Repository.FullName}");
            sb.AppendLine();
            sb.AppendLine($"{payload.Pusher?.Name} pushed {payload.Commits.Count} commit(s):");
            int commitIndex = 1;

            foreach (var commit in payload.Commits)
            {
                sb.AppendLine($"{commitIndex++}) [{commit.Timestamp.ToString("g")} {commit.Author?.Name} ({commit.Author?.Username})] ");
                sb.AppendLine($"added: {commit.AddedFiles.Count}; removed: {commit.RemovedFiles.Count}; modified: {commit.ModifiedFiles.Count}.");
            }
            sb.AppendLine();
            sb.AppendLine($"Browse changes here:");
            sb.AppendLine($"{payload.DiffUrl}");
            return(sb.ToString());
        }
        public async Task FunctionHandler(GithubPayload payload)
        {
            var res = payload.Commits.Select(c =>
                                             new
            {
                Message  = c.Message,
                Added    = c.Added.Where(s => s.StartsWith("Backend/Source/Shared/")),
                Removed  = c.Removed.Where(s => s.StartsWith("Backend/Source/Shared/")),
                Modified = c.Modified.Where(s => s.StartsWith("Backend/Source/Shared/"))
            }
                                             );

            var client = new HttpClient();

            foreach (var r in res)
            {
                if (r.Added.Count() == 0 && r.Removed.Count() == 0 && r.Modified.Count() == 0)
                {
                    continue;
                }
                await client.PostAsync(SlackUrl, new StringContent(
                                           JsonConvert.SerializeObject(
                                               new
                {
                    text = JsonConvert.SerializeObject(
                        new
                    {
                        Message = r.Message,
                        Added = r.Added,
                        Removed = r.Removed,
                        Modified = r.Modified
                    }, Formatting.Indented
                        )
                }
                                               )
                                           ));
            }
        }
コード例 #7
0
        public override Task ExecuteAsync(string receiver, WebHookHandlerContext context)
        {
            GithubPayload payload = GetPayload(context);

            return(Task.WhenAll(_notifierProvider.Provide().Select(n => n.Notify(payload))));
        }
コード例 #8
0
 public Task Notify(GithubPayload payload)
 {
     throw new NotImplementedException();
 }