<commit_before>require 'sinatra/base'
require './chatwork'
require 'json'

def compose_message(title, body)
  "[info][title]#{title}[/title]#{body}[/info]"
end

class GithubWebHook < Sinatra::Base

  post '/hook/:token/:room_id' do

    begin

      cw = Chatwork.new(token: params[:token], room_id: params[:room_id])
      body = JSON.parse request.body.read

      if params[:token].nil? || params[:room_id].nil?
        cw.post compose_message('Error', 'Auth error')
        return 'ng'
      end

      case request.env['HTTP_X_GITHUB_EVENT']
      when 'pull_request'
        cw.post compose_message("PullRequest '#{body['pull_request']['title']}' #{body['action']} by #{body['pull_request']['user']['login']}", <<-EOS)
BODY:
#{body['pull_request']['body']}
--
URL:
#{body['pull_request']['html_url']}
        EOS

        return 'ok - pull_request'

      when 'issue_comment'
        cw.post compose_message("IssueCommented #{body['action']} by #{body['comment']['user']['login']}", <<-EOS)
BODY:
#{body['comment']['body']}
--
URL:
#{body['comment']['html_url']}
        EOS

        return 'ok - issue_comment'

      when 'commit_comment'
        cw.post compose_message("CommitCommented #{body['action']} by #{body['comment']['user']['login']}", <<-EOS)
BODY:
#{body['comment']['body']}
--
URL:
#{body['comment']['html_url']}
        EOS

        return 'ok - issue_comment'

      when 'pull_request_review_comment'<commit_msg>ignore some pullreq<commit_after>require 'sinatra/base'
require './chatwork'
require 'json'

def compose_message(title, body)
  "[info][title]#{title}[/title]#{body}[/info]"
end

class GithubWebHook < Sinatra::Base

  post '/hook/:token/:room_id' do

    begin

      cw = Chatwork.new(token: params[:token], room_id: params[:room_id])
      body = JSON.parse request.body.read

      if params[:token].nil? || params[:room_id].nil?
        cw.post compose_message('Error', 'Auth error')
        return 'ng'
      end

      case request.env['HTTP_X_GITHUB_EVENT']
      when 'pull_request'

        # `opened`以外はOFF
        if body['action'] != 'opened'
          return "ok - pull_request: #{body['action']}"
        end

        cw.post compose_message("PullRequest '#{body['pull_request']['title']}' #{body['action']} by #{body['pull_request']['user']['login']}", <<-EOS)
BODY:
#{body['pull_request']['body']}
--
URL:
#{body['pull_request']['html_url']}
        EOS

        return "ok - pull_request: #{body['action']}"

      when 'issue_comment'
        cw.post compose_message("IssueCommented #{body['action']} by #{body['comment']['user']['login']}", <<-EOS)
BODY:
#{body['comment']['body']}
--
URL:
#{body['comment']['html_url']}
        EOS

        return 'ok - issue_comment'

      when 'commit_comment'
        cw.post compose_message("CommitCommented #{body['action']} by #{body['comment']['user']['login']}", <<-EOS)
BODY:
#{body['comment']['body']}
--
URL:
#{body['comment']['html_url']}
        EOS

        return 'ok - issue_comment'

      when 'pull_request_review_comment'
{'fraction_non_alphanumeric': 0.1997363216875412, 'fraction_numerical': 0.0, 'mean_word_length': 3.7645211930926217, 'pattern_counts': {'":': 0, '<': 17, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '2284267', 'n_tokens_mistral': 1038, 'n_tokens_neox': 1011, 'n_words': 189}