github-web-hooks-receiver 1.0.0 → 1.0.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
 - data/.gitignore +2 -1
 - data/README.md +2 -1
 - data/config.ru +3 -3
 - data/config.yaml.example +28 -8
 - data/doc/text/news.md +27 -0
 - data/github-web-hooks-receiver.gemspec +1 -1
 - data/lib/github-web-hooks-receiver/app.rb +125 -38
 - data/lib/github-web-hooks-receiver/path-resolver.rb +1 -1
 - data/lib/github-web-hooks-receiver/payload.rb +14 -4
 - data/lib/github-web-hooks-receiver/repository.rb +65 -26
 - data/lib/github-web-hooks-receiver/version.rb +1 -1
 - data/test/receiver-test.rb +10 -3
 - metadata +5 -4
 
    
        checksums.yaml
    CHANGED
    
    | 
         @@ -1,7 +1,7 @@ 
     | 
|
| 
       1 
1 
     | 
    
         
             
            ---
         
     | 
| 
       2 
2 
     | 
    
         
             
            SHA1:
         
     | 
| 
       3 
     | 
    
         
            -
              metadata.gz:  
     | 
| 
       4 
     | 
    
         
            -
              data.tar.gz:  
     | 
| 
      
 3 
     | 
    
         
            +
              metadata.gz: 9ee5be645f09fb213a17ddab34dbae213360c97b
         
     | 
| 
      
 4 
     | 
    
         
            +
              data.tar.gz: 59b19d6a18d006ab60ebccb5b690b094c20e97a4
         
     | 
| 
       5 
5 
     | 
    
         
             
            SHA512:
         
     | 
| 
       6 
     | 
    
         
            -
              metadata.gz:  
     | 
| 
       7 
     | 
    
         
            -
              data.tar.gz:  
     | 
| 
      
 6 
     | 
    
         
            +
              metadata.gz: 25b01bbbd7ea6940bf1cb0865532eb9551030591b41b52e1c78d43bdf76a3148f898d4d388c2da80f710b741a3bacd2bd7534320021b0f2c089f422a67bbc4c9
         
     | 
| 
      
 7 
     | 
    
         
            +
              data.tar.gz: 1c69e82f98aeba475370abd2513f44b76d6accb8059404904594282ec53ed066251c26ff32be806d76f8471aaa1ddb77fd8ae1c00ac247ee9e6d0160926b9826
         
     | 
    
        data/.gitignore
    CHANGED
    
    
    
        data/README.md
    CHANGED
    
    | 
         @@ -38,6 +38,8 @@ end 
     | 
|
| 
       38 
38 
     | 
    
         | 
| 
       39 
39 
     | 
    
         
             
            /home/github-web-hooks-receiver/github-web-hooks-receiver/config.yaml:
         
     | 
| 
       40 
40 
     | 
    
         
             
            ```
         
     | 
| 
      
 41 
     | 
    
         
            +
            mirrors_directory: /path/to/mirrors
         
     | 
| 
      
 42 
     | 
    
         
            +
            git_commit_mailer: /path/to/git-commit-mailer
         
     | 
| 
       41 
43 
     | 
    
         
             
            to: receiver@example.com
         
     | 
| 
       42 
44 
     | 
    
         
             
            sender: sender@example.com
         
     | 
| 
       43 
45 
     | 
    
         
             
            add_html: true
         
     | 
| 
         @@ -209,4 +211,3 @@ $ sudo -u github-web-hooks-receiver -H ~github-web-hooks-receiver/bin/github-web 
     | 
|
| 
       209 
211 
     | 
    
         | 
| 
       210 
212 
     | 
    
         
             
            You need to edit config.yaml to configure this web application.
         
     | 
| 
       211 
213 
     | 
    
         
             
            See config.yaml.example and test codes.
         
     | 
| 
       212 
     | 
    
         
            -
             
     | 
    
        data/config.ru
    CHANGED
    
    | 
         @@ -1,6 +1,6 @@ 
     | 
|
| 
       1 
1 
     | 
    
         
             
            # -*- mode: ruby; coding: utf-8 -*-
         
     | 
| 
       2 
2 
     | 
    
         
             
            #
         
     | 
| 
       3 
     | 
    
         
            -
            # Copyright (C) 2010- 
     | 
| 
      
 3 
     | 
    
         
            +
            # Copyright (C) 2010-2015  Kouhei Sutou <kou@clear-code.com>
         
     | 
| 
       4 
4 
     | 
    
         
             
            #
         
     | 
| 
       5 
5 
     | 
    
         
             
            # This program is free software: you can redistribute it and/or modify
         
     | 
| 
       6 
6 
     | 
    
         
             
            # it under the terms of the GNU General Public License as published by
         
     | 
| 
         @@ -39,8 +39,8 @@ use Rack::ContentLength 
     | 
|
| 
       39 
39 
     | 
    
         
             
            config_file = base_dir + "config.yaml"
         
     | 
| 
       40 
40 
     | 
    
         
             
            options = YAML.load_file(config_file.to_s)
         
     | 
| 
       41 
41 
     | 
    
         
             
            notifier_options = options.dup
         
     | 
| 
       42 
     | 
    
         
            -
            if options[ 
     | 
| 
       43 
     | 
    
         
            -
              notifier_options[ 
     | 
| 
      
 42 
     | 
    
         
            +
            if options["error_to"]
         
     | 
| 
      
 43 
     | 
    
         
            +
              notifier_options["to"] = options["error_to"]
         
     | 
| 
       44 
44 
     | 
    
         
             
            end
         
     | 
| 
       45 
45 
     | 
    
         
             
            notifier_options.merge!(options["exception_notifier"] || {})
         
     | 
| 
       46 
46 
     | 
    
         
             
            notifiers = [Racknga::ExceptionMailNotifier.new(notifier_options)]
         
     | 
    
        data/config.yaml.example
    CHANGED
    
    | 
         @@ -1,9 +1,3 @@ 
     | 
|
| 
       1 
     | 
    
         
            -
            private_token: VERYSECRETTOKEN
         
     | 
| 
       2 
     | 
    
         
            -
            gitlab_api_end_point: https://gitlab.example.com/api/v3
         
     | 
| 
       3 
     | 
    
         
            -
            web_hooks:
         
     | 
| 
       4 
     | 
    
         
            -
              - http://gh.example.com/post-receiver1
         
     | 
| 
       5 
     | 
    
         
            -
              - http://gh.example.com/post-receiver2
         
     | 
| 
       6 
     | 
    
         
            -
              - http://gh.example.com/post-receiver3
         
     | 
| 
       7 
1 
     | 
    
         
             
            to: receiver@example.com
         
     | 
| 
       8 
2 
     | 
    
         
             
            error_to: admin@example.com
         
     | 
| 
       9 
3 
     | 
    
         
             
            exception_notifier:
         
     | 
| 
         @@ -11,10 +5,36 @@ exception_notifier: 
     | 
|
| 
       11 
5 
     | 
    
         
             
            sender: sender@example.com
         
     | 
| 
       12 
6 
     | 
    
         
             
            add_html: true
         
     | 
| 
       13 
7 
     | 
    
         
             
            owners:
         
     | 
| 
       14 
     | 
    
         
            -
               
     | 
| 
       15 
     | 
    
         
            -
                to: groonga-commit@ 
     | 
| 
      
 8 
     | 
    
         
            +
              mroonga:
         
     | 
| 
      
 9 
     | 
    
         
            +
                to: groonga-mysql-commit@lists.sourceforge.jp
         
     | 
| 
       16 
10 
     | 
    
         
             
                repositories:
         
     | 
| 
       17 
11 
     | 
    
         
             
                  examples:
         
     | 
| 
       18 
12 
     | 
    
         
             
                    to: null@example.com
         
     | 
| 
       19 
13 
     | 
    
         
             
              groonga:
         
     | 
| 
       20 
14 
     | 
    
         
             
                to: groonga-commit@lists.sourceforge.jp
         
     | 
| 
      
 15 
     | 
    
         
            +
             
     | 
| 
      
 16 
     | 
    
         
            +
            # For multiple domains
         
     | 
| 
      
 17 
     | 
    
         
            +
            #
         
     | 
| 
      
 18 
     | 
    
         
            +
            # domains:
         
     | 
| 
      
 19 
     | 
    
         
            +
            #   github.com: &github
         
     | 
| 
      
 20 
     | 
    
         
            +
            #     owners:
         
     | 
| 
      
 21 
     | 
    
         
            +
            #       clear-code:
         
     | 
| 
      
 22 
     | 
    
         
            +
            #         to: commit+clear-code@example.com
         
     | 
| 
      
 23 
     | 
    
         
            +
            #       kou:
         
     | 
| 
      
 24 
     | 
    
         
            +
            #         enabled: false # Disabled by default
         
     | 
| 
      
 25 
     | 
    
         
            +
            #         repositories:
         
     | 
| 
      
 26 
     | 
    
         
            +
            #           mruby-pp:
         
     | 
| 
      
 27 
     | 
    
         
            +
            #             enabled: true # Enabled only the specified repository
         
     | 
| 
      
 28 
     | 
    
         
            +
            #   # GitHub uses api.github.com for gollum event (Wiki change event)
         
     | 
| 
      
 29 
     | 
    
         
            +
            #   # "api.github.com: *github" means that api.github.com configuaration
         
     | 
| 
      
 30 
     | 
    
         
            +
            #   # is the same as github.com.
         
     | 
| 
      
 31 
     | 
    
         
            +
            #   api.github.com: *github
         
     | 
| 
      
 32 
     | 
    
         
            +
            #   gitlab.example.com:
         
     | 
| 
      
 33 
     | 
    
         
            +
            #     to: commit+gitlab@example.com
         
     | 
| 
      
 34 
     | 
    
         
            +
            #     from: null+gitlab@example.com
         
     | 
| 
      
 35 
     | 
    
         
            +
            #     owners:
         
     | 
| 
      
 36 
     | 
    
         
            +
            #       owner1:
         
     | 
| 
      
 37 
     | 
    
         
            +
            #         repositories:
         
     | 
| 
      
 38 
     | 
    
         
            +
            #           repository1:
         
     | 
| 
      
 39 
     | 
    
         
            +
            #             to:
         
     | 
| 
      
 40 
     | 
    
         
            +
            #               - commit+repository1@example.com
         
     | 
    
        data/doc/text/news.md
    ADDED
    
    | 
         @@ -0,0 +1,27 @@ 
     | 
|
| 
      
 1 
     | 
    
         
            +
            # News
         
     | 
| 
      
 2 
     | 
    
         
            +
             
     | 
| 
      
 3 
     | 
    
         
            +
            ## 1.0.1 - 2016-10-07 {#version-1-0-1}
         
     | 
| 
      
 4 
     | 
    
         
            +
             
     | 
| 
      
 5 
     | 
    
         
            +
            ### Improvements
         
     | 
| 
      
 6 
     | 
    
         
            +
             
     | 
| 
      
 7 
     | 
    
         
            +
              * Added `git_commit_mailer` top level option in configure YAML. It's
         
     | 
| 
      
 8 
     | 
    
         
            +
                for changing mailer command.
         
     | 
| 
      
 9 
     | 
    
         
            +
             
     | 
| 
      
 10 
     | 
    
         
            +
              * Serialized Git repository update.
         
     | 
| 
      
 11 
     | 
    
         
            +
             
     | 
| 
      
 12 
     | 
    
         
            +
              * Showed standard output content on git-commit-mailer error.
         
     | 
| 
      
 13 
     | 
    
         
            +
             
     | 
| 
      
 14 
     | 
    
         
            +
              * Returned success response ("202 Accepted") for disabled repository.
         
     | 
| 
      
 15 
     | 
    
         
            +
             
     | 
| 
      
 16 
     | 
    
         
            +
              * Supported `enabled` option to each repository for
         
     | 
| 
      
 17 
     | 
    
         
            +
                enabling/disabling the repository.
         
     | 
| 
      
 18 
     | 
    
         
            +
             
     | 
| 
      
 19 
     | 
    
         
            +
              * Removed branches no longer exist.
         
     | 
| 
      
 20 
     | 
    
         
            +
             
     | 
| 
      
 21 
     | 
    
         
            +
              * [GitLab] Supported Wiki event.
         
     | 
| 
      
 22 
     | 
    
         
            +
             
     | 
| 
      
 23 
     | 
    
         
            +
              * Supported logging on error response.
         
     | 
| 
      
 24 
     | 
    
         
            +
             
     | 
| 
      
 25 
     | 
    
         
            +
            ## 1.0.0 - 2015-05-19 {#version-1-0-0}
         
     | 
| 
      
 26 
     | 
    
         
            +
             
     | 
| 
      
 27 
     | 
    
         
            +
            The initial release!
         
     | 
| 
         @@ -10,7 +10,7 @@ Gem::Specification.new do |spec| 
     | 
|
| 
       10 
10 
     | 
    
         
             
              spec.email         = ["kou@clear-code.com", "okimoto@clear-code.com"]
         
     | 
| 
       11 
11 
     | 
    
         
             
              spec.summary       = %q{GitHub web hook receiver}
         
     | 
| 
       12 
12 
     | 
    
         
             
              spec.description   = %q{GitHub web hook receiver}
         
     | 
| 
       13 
     | 
    
         
            -
              spec.homepage      = ""
         
     | 
| 
      
 13 
     | 
    
         
            +
              spec.homepage      = "https://github.com/clear-code/github-web-hooks-receiver"
         
     | 
| 
       14 
14 
     | 
    
         
             
              spec.license       = "GPL-3.0+"
         
     | 
| 
       15 
15 
     | 
    
         | 
| 
       16 
16 
     | 
    
         
             
              spec.files         = `git ls-files -z`.split("\x0")
         
     | 
| 
         @@ -28,19 +28,22 @@ module GitHubWebHooksReceiver 
     | 
|
| 
       28 
28 
     | 
    
         
             
                def process_payload(request, response, raw_payload)
         
     | 
| 
       29 
29 
     | 
    
         
             
                  metadata = {
         
     | 
| 
       30 
30 
     | 
    
         
             
                    "x-github-event" => github_event(request),
         
     | 
| 
      
 31 
     | 
    
         
            +
                    "x-gitlab-event" => gitlab_event(request),
         
     | 
| 
       31 
32 
     | 
    
         
             
                  }
         
     | 
| 
       32 
33 
     | 
    
         
             
                  payload = Payload.new(raw_payload, metadata)
         
     | 
| 
       33 
34 
     | 
    
         
             
                  case payload.event_name
         
     | 
| 
       34 
35 
     | 
    
         
             
                  when "ping"
         
     | 
| 
       35 
36 
     | 
    
         
             
                    # Do nothing
         
     | 
| 
       36 
     | 
    
         
            -
                  when "push" 
     | 
| 
      
 37 
     | 
    
         
            +
                  when "push"
         
     | 
| 
       37 
38 
     | 
    
         
             
                    process_push_payload(request, response, payload)
         
     | 
| 
       38 
39 
     | 
    
         
             
                  when "gollum"
         
     | 
| 
       39 
40 
     | 
    
         
             
                    process_gollum_payload(request, response, payload)
         
     | 
| 
      
 41 
     | 
    
         
            +
                  when "wiki_page"
         
     | 
| 
      
 42 
     | 
    
         
            +
                    process_gitlab_wiki_payload(request, response, payload)
         
     | 
| 
       40 
43 
     | 
    
         
             
                  else
         
     | 
| 
       41 
     | 
    
         
            -
                     
     | 
| 
       42 
     | 
    
         
            -
             
     | 
| 
       43 
     | 
    
         
            -
             
     | 
| 
      
 44 
     | 
    
         
            +
                    set_response(response,
         
     | 
| 
      
 45 
     | 
    
         
            +
                                 :bad_request,
         
     | 
| 
      
 46 
     | 
    
         
            +
                                 "Unsupported event: <#{payload.event_name}>")
         
     | 
| 
       44 
47 
     | 
    
         
             
                  end
         
     | 
| 
       45 
48 
     | 
    
         
             
                end
         
     | 
| 
       46 
49 
     | 
    
         | 
| 
         @@ -48,6 +51,10 @@ module GitHubWebHooksReceiver 
     | 
|
| 
       48 
51 
     | 
    
         
             
                  request.env["HTTP_X_GITHUB_EVENT"]
         
     | 
| 
       49 
52 
     | 
    
         
             
                end
         
     | 
| 
       50 
53 
     | 
    
         | 
| 
      
 54 
     | 
    
         
            +
                def gitlab_event(request)
         
     | 
| 
      
 55 
     | 
    
         
            +
                  request.env["HTTP_X_GITLAB_EVENT"]
         
     | 
| 
      
 56 
     | 
    
         
            +
                end
         
     | 
| 
      
 57 
     | 
    
         
            +
             
     | 
| 
       51 
58 
     | 
    
         
             
                def process_push_payload(request, response, payload)
         
     | 
| 
       52 
59 
     | 
    
         
             
                  repository = process_payload_repository(request, response, payload)
         
     | 
| 
       53 
60 
     | 
    
         
             
                  return if repository.nil?
         
     | 
| 
         @@ -64,51 +71,117 @@ module GitHubWebHooksReceiver 
     | 
|
| 
       64 
71 
     | 
    
         
             
                  repository.process(*change)
         
     | 
| 
       65 
72 
     | 
    
         
             
                end
         
     | 
| 
       66 
73 
     | 
    
         | 
| 
      
 74 
     | 
    
         
            +
                def process_gitlab_wiki_payload(request, response, payload)
         
     | 
| 
      
 75 
     | 
    
         
            +
                  repository = process_gitlab_wiki_repository(request, response, payload)
         
     | 
| 
      
 76 
     | 
    
         
            +
                  return if repository.nil?
         
     | 
| 
      
 77 
     | 
    
         
            +
                  change = process_gitlab_wiki_parameters(request, response, payload)
         
     | 
| 
      
 78 
     | 
    
         
            +
                  return if change.nil?
         
     | 
| 
      
 79 
     | 
    
         
            +
                  repository.process(*change)
         
     | 
| 
      
 80 
     | 
    
         
            +
                end
         
     | 
| 
      
 81 
     | 
    
         
            +
             
     | 
| 
       67 
82 
     | 
    
         
             
                def process_payload_repository(request, response, payload)
         
     | 
| 
       68 
83 
     | 
    
         
             
                  repository = payload["repository"]
         
     | 
| 
       69 
84 
     | 
    
         
             
                  if repository.nil?
         
     | 
| 
       70 
     | 
    
         
            -
                     
     | 
| 
       71 
     | 
    
         
            -
             
     | 
| 
      
 85 
     | 
    
         
            +
                    set_response(response, :bad_request,
         
     | 
| 
      
 86 
     | 
    
         
            +
                                 "repository information is missing")
         
     | 
| 
       72 
87 
     | 
    
         
             
                    return
         
     | 
| 
       73 
88 
     | 
    
         
             
                  end
         
     | 
| 
       74 
89 
     | 
    
         | 
| 
       75 
90 
     | 
    
         
             
                  unless repository.is_a?(Hash)
         
     | 
| 
       76 
     | 
    
         
            -
                     
     | 
| 
       77 
     | 
    
         
            -
             
     | 
| 
       78 
     | 
    
         
            -
             
     | 
| 
      
 91 
     | 
    
         
            +
                    set_response(response, :bad_request,
         
     | 
| 
      
 92 
     | 
    
         
            +
                                 "invalid repository information format: " +
         
     | 
| 
      
 93 
     | 
    
         
            +
                                 "<#{repository.inspect}>")
         
     | 
| 
       79 
94 
     | 
    
         
             
                    return
         
     | 
| 
       80 
95 
     | 
    
         
             
                  end
         
     | 
| 
       81 
96 
     | 
    
         | 
| 
       82 
97 
     | 
    
         
             
                  repository_uri = repository["url"]
         
     | 
| 
       83 
98 
     | 
    
         
             
                  domain = extract_domain(repository_uri)
         
     | 
| 
       84 
99 
     | 
    
         
             
                  if domain.nil?
         
     | 
| 
       85 
     | 
    
         
            -
                     
     | 
| 
       86 
     | 
    
         
            -
             
     | 
| 
      
 100 
     | 
    
         
            +
                    set_response(response, :bad_request,
         
     | 
| 
      
 101 
     | 
    
         
            +
                                 "invalid repository URI: <#{repository.inspect}>")
         
     | 
| 
       87 
102 
     | 
    
         
             
                    return
         
     | 
| 
       88 
103 
     | 
    
         
             
                  end
         
     | 
| 
       89 
104 
     | 
    
         | 
| 
       90 
105 
     | 
    
         
             
                  repository_name = repository["name"]
         
     | 
| 
       91 
106 
     | 
    
         
             
                  if repository_name.nil?
         
     | 
| 
       92 
     | 
    
         
            -
                     
     | 
| 
       93 
     | 
    
         
            -
             
     | 
| 
      
 107 
     | 
    
         
            +
                    set_response(response, :bad_request,
         
     | 
| 
      
 108 
     | 
    
         
            +
                                 "repository name is missing: <#{repository.inspect}>")
         
     | 
| 
      
 109 
     | 
    
         
            +
                    return
         
     | 
| 
      
 110 
     | 
    
         
            +
                  end
         
     | 
| 
      
 111 
     | 
    
         
            +
             
     | 
| 
      
 112 
     | 
    
         
            +
                  owner_name = extract_owner_name(repository_uri, payload)
         
     | 
| 
      
 113 
     | 
    
         
            +
                  if owner_name.nil?
         
     | 
| 
      
 114 
     | 
    
         
            +
                    set_response(response, :bad_request,
         
     | 
| 
      
 115 
     | 
    
         
            +
                                 "repository owner or owner name is missing: " +
         
     | 
| 
      
 116 
     | 
    
         
            +
                                 "<#{repository.inspect}>")
         
     | 
| 
      
 117 
     | 
    
         
            +
                    return
         
     | 
| 
      
 118 
     | 
    
         
            +
                  end
         
     | 
| 
      
 119 
     | 
    
         
            +
             
     | 
| 
      
 120 
     | 
    
         
            +
                  options = repository_options(domain, owner_name, repository_name)
         
     | 
| 
      
 121 
     | 
    
         
            +
                  repository = repository_class.new(domain, owner_name, repository_name,
         
     | 
| 
      
 122 
     | 
    
         
            +
                                                    payload, options)
         
     | 
| 
      
 123 
     | 
    
         
            +
                  unless repository.enabled?
         
     | 
| 
      
 124 
     | 
    
         
            +
                    set_response(response, :accepted,
         
     | 
| 
      
 125 
     | 
    
         
            +
                                 "ignore disabled repository: " +
         
     | 
| 
      
 126 
     | 
    
         
            +
                                 "<#{owner_name.inspect}>:<#{repository_name.inspect}>")
         
     | 
| 
      
 127 
     | 
    
         
            +
                    return
         
     | 
| 
      
 128 
     | 
    
         
            +
                  end
         
     | 
| 
      
 129 
     | 
    
         
            +
             
     | 
| 
      
 130 
     | 
    
         
            +
                  repository
         
     | 
| 
      
 131 
     | 
    
         
            +
                end
         
     | 
| 
      
 132 
     | 
    
         
            +
             
     | 
| 
      
 133 
     | 
    
         
            +
                def process_gitlab_wiki_repository(request, response, payload)
         
     | 
| 
      
 134 
     | 
    
         
            +
                  wiki = payload["wiki"]
         
     | 
| 
      
 135 
     | 
    
         
            +
                  if wiki.nil?
         
     | 
| 
      
 136 
     | 
    
         
            +
                    set_response(response, :bad_request,
         
     | 
| 
      
 137 
     | 
    
         
            +
                                 "Wiki information is missing")
         
     | 
| 
      
 138 
     | 
    
         
            +
                    return
         
     | 
| 
      
 139 
     | 
    
         
            +
                  end
         
     | 
| 
      
 140 
     | 
    
         
            +
             
     | 
| 
      
 141 
     | 
    
         
            +
                  unless wiki.is_a?(Hash)
         
     | 
| 
      
 142 
     | 
    
         
            +
                    set_response(response, :bad_request,
         
     | 
| 
      
 143 
     | 
    
         
            +
                                 "invalid Wiki information format: " +
         
     | 
| 
      
 144 
     | 
    
         
            +
                                 "<#{wiki.inspect}>")
         
     | 
| 
      
 145 
     | 
    
         
            +
                    return
         
     | 
| 
      
 146 
     | 
    
         
            +
                  end
         
     | 
| 
      
 147 
     | 
    
         
            +
             
     | 
| 
      
 148 
     | 
    
         
            +
                  repository_uri = wiki["git_ssh_url"]
         
     | 
| 
      
 149 
     | 
    
         
            +
                  domain = extract_domain(repository_uri)
         
     | 
| 
      
 150 
     | 
    
         
            +
                  if domain.nil?
         
     | 
| 
      
 151 
     | 
    
         
            +
                    set_response(response, :bad_request,
         
     | 
| 
      
 152 
     | 
    
         
            +
                                 "invalid repository URI: <#{wiki.inspect}>")
         
     | 
| 
      
 153 
     | 
    
         
            +
                    return
         
     | 
| 
      
 154 
     | 
    
         
            +
                  end
         
     | 
| 
      
 155 
     | 
    
         
            +
             
     | 
| 
      
 156 
     | 
    
         
            +
                  project = payload["project"]
         
     | 
| 
      
 157 
     | 
    
         
            +
                  if wiki.nil?
         
     | 
| 
      
 158 
     | 
    
         
            +
                    set_response(response, :bad_request,
         
     | 
| 
      
 159 
     | 
    
         
            +
                                 "Project information is missing")
         
     | 
| 
      
 160 
     | 
    
         
            +
                    return
         
     | 
| 
      
 161 
     | 
    
         
            +
                  end
         
     | 
| 
      
 162 
     | 
    
         
            +
             
     | 
| 
      
 163 
     | 
    
         
            +
                  repository_name = project["name"]
         
     | 
| 
      
 164 
     | 
    
         
            +
                  if repository_name.nil?
         
     | 
| 
      
 165 
     | 
    
         
            +
                    set_response(response, :bad_request,
         
     | 
| 
      
 166 
     | 
    
         
            +
                                 "repository name is missing: <#{project.inspect}>")
         
     | 
| 
       94 
167 
     | 
    
         
             
                    return
         
     | 
| 
       95 
168 
     | 
    
         
             
                  end
         
     | 
| 
       96 
169 
     | 
    
         | 
| 
       97 
170 
     | 
    
         
             
                  owner_name = extract_owner_name(repository_uri, payload)
         
     | 
| 
       98 
171 
     | 
    
         
             
                  if owner_name.nil?
         
     | 
| 
       99 
     | 
    
         
            -
                     
     | 
| 
       100 
     | 
    
         
            -
             
     | 
| 
       101 
     | 
    
         
            -
             
     | 
| 
      
 172 
     | 
    
         
            +
                    set_response(response, :bad_request,
         
     | 
| 
      
 173 
     | 
    
         
            +
                                 "repository owner or owner name is missing: " +
         
     | 
| 
      
 174 
     | 
    
         
            +
                                 "<#{project.inspect}>")
         
     | 
| 
       102 
175 
     | 
    
         
             
                    return
         
     | 
| 
       103 
176 
     | 
    
         
             
                  end
         
     | 
| 
       104 
177 
     | 
    
         | 
| 
       105 
178 
     | 
    
         
             
                  options = repository_options(domain, owner_name, repository_name)
         
     | 
| 
       106 
179 
     | 
    
         
             
                  repository = repository_class.new(domain, owner_name, repository_name,
         
     | 
| 
       107 
180 
     | 
    
         
             
                                                    payload, options)
         
     | 
| 
       108 
     | 
    
         
            -
                  unless repository. 
     | 
| 
       109 
     | 
    
         
            -
                     
     | 
| 
       110 
     | 
    
         
            -
             
     | 
| 
       111 
     | 
    
         
            -
             
     | 
| 
      
 181 
     | 
    
         
            +
                  unless repository.enabled?
         
     | 
| 
      
 182 
     | 
    
         
            +
                    set_response(response, :accepted,
         
     | 
| 
      
 183 
     | 
    
         
            +
                                 "ignore disabled repository: " +
         
     | 
| 
      
 184 
     | 
    
         
            +
                                 "<#{owner_name.inspect}>:<#{repository_name.inspect}>")
         
     | 
| 
       112 
185 
     | 
    
         
             
                    return
         
     | 
| 
       113 
186 
     | 
    
         
             
                  end
         
     | 
| 
       114 
187 
     | 
    
         | 
| 
         @@ -116,21 +189,18 @@ module GitHubWebHooksReceiver 
     | 
|
| 
       116 
189 
     | 
    
         
             
                end
         
     | 
| 
       117 
190 
     | 
    
         | 
| 
       118 
191 
     | 
    
         
             
                def extract_domain(repository_uri)
         
     | 
| 
       119 
     | 
    
         
            -
                  domain = nil
         
     | 
| 
       120 
192 
     | 
    
         
             
                  case repository_uri
         
     | 
| 
       121 
193 
     | 
    
         
             
                  when /\Agit@/
         
     | 
| 
       122 
     | 
    
         
            -
                     
     | 
| 
      
 194 
     | 
    
         
            +
                    repository_uri[/@(.+):/, 1]
         
     | 
| 
       123 
195 
     | 
    
         
             
                  when /\Ahttps:\/\//
         
     | 
| 
       124 
     | 
    
         
            -
                     
     | 
| 
      
 196 
     | 
    
         
            +
                    URI.parse(repository_uri).hostname
         
     | 
| 
       125 
197 
     | 
    
         
             
                  else
         
     | 
| 
       126 
     | 
    
         
            -
                     
     | 
| 
      
 198 
     | 
    
         
            +
                    nil
         
     | 
| 
       127 
199 
     | 
    
         
             
                  end
         
     | 
| 
       128 
     | 
    
         
            -
                  domain
         
     | 
| 
       129 
200 
     | 
    
         
             
                end
         
     | 
| 
       130 
201 
     | 
    
         | 
| 
       131 
202 
     | 
    
         
             
                def extract_owner_name(repository_uri, payload)
         
     | 
| 
       132 
203 
     | 
    
         
             
                  owner_name = nil
         
     | 
| 
       133 
     | 
    
         
            -
                  repository = payload["repository"]
         
     | 
| 
       134 
204 
     | 
    
         
             
                  if payload.gitlab?
         
     | 
| 
       135 
205 
     | 
    
         
             
                    case repository_uri
         
     | 
| 
       136 
206 
     | 
    
         
             
                    when /\Agit@/
         
     | 
| 
         @@ -141,7 +211,7 @@ module GitHubWebHooksReceiver 
     | 
|
| 
       141 
211 
     | 
    
         
             
                      return
         
     | 
| 
       142 
212 
     | 
    
         
             
                    end
         
     | 
| 
       143 
213 
     | 
    
         
             
                  else
         
     | 
| 
       144 
     | 
    
         
            -
                    owner =  
     | 
| 
      
 214 
     | 
    
         
            +
                    owner = payload["repository.owner"]
         
     | 
| 
       145 
215 
     | 
    
         
             
                    return if owner.nil?
         
     | 
| 
       146 
216 
     | 
    
         | 
| 
       147 
217 
     | 
    
         
             
                    owner_name = owner["name"] || owner["login"]
         
     | 
| 
         @@ -153,22 +223,22 @@ module GitHubWebHooksReceiver 
     | 
|
| 
       153 
223 
     | 
    
         
             
                def process_push_parameters(request, response, payload)
         
     | 
| 
       154 
224 
     | 
    
         
             
                  before = payload["before"]
         
     | 
| 
       155 
225 
     | 
    
         
             
                  if before.nil?
         
     | 
| 
       156 
     | 
    
         
            -
                     
     | 
| 
       157 
     | 
    
         
            -
             
     | 
| 
      
 226 
     | 
    
         
            +
                    set_response(response, :bad_request,
         
     | 
| 
      
 227 
     | 
    
         
            +
                                 "before commit ID is missing")
         
     | 
| 
       158 
228 
     | 
    
         
             
                    return
         
     | 
| 
       159 
229 
     | 
    
         
             
                  end
         
     | 
| 
       160 
230 
     | 
    
         | 
| 
       161 
231 
     | 
    
         
             
                  after = payload["after"]
         
     | 
| 
       162 
232 
     | 
    
         
             
                  if after.nil?
         
     | 
| 
       163 
     | 
    
         
            -
                     
     | 
| 
       164 
     | 
    
         
            -
             
     | 
| 
      
 233 
     | 
    
         
            +
                    set_response(response, :bad_request,
         
     | 
| 
      
 234 
     | 
    
         
            +
                                 "after commit ID is missing")
         
     | 
| 
       165 
235 
     | 
    
         
             
                    return
         
     | 
| 
       166 
236 
     | 
    
         
             
                  end
         
     | 
| 
       167 
237 
     | 
    
         | 
| 
       168 
238 
     | 
    
         
             
                  reference = payload["ref"]
         
     | 
| 
       169 
239 
     | 
    
         
             
                  if reference.nil?
         
     | 
| 
       170 
     | 
    
         
            -
                     
     | 
| 
       171 
     | 
    
         
            -
             
     | 
| 
      
 240 
     | 
    
         
            +
                    set_response(response, :bad_request,
         
     | 
| 
      
 241 
     | 
    
         
            +
                                 "reference is missing")
         
     | 
| 
       172 
242 
     | 
    
         
             
                    return
         
     | 
| 
       173 
243 
     | 
    
         
             
                  end
         
     | 
| 
       174 
244 
     | 
    
         | 
| 
         @@ -178,13 +248,14 @@ module GitHubWebHooksReceiver 
     | 
|
| 
       178 
248 
     | 
    
         
             
                def process_gollum_parameters(request, response, payload)
         
     | 
| 
       179 
249 
     | 
    
         
             
                  pages = payload["pages"]
         
     | 
| 
       180 
250 
     | 
    
         
             
                  if pages.nil?
         
     | 
| 
       181 
     | 
    
         
            -
                     
     | 
| 
       182 
     | 
    
         
            -
             
     | 
| 
      
 251 
     | 
    
         
            +
                    set_response(response, :bad_request,
         
     | 
| 
      
 252 
     | 
    
         
            +
                                 "pages are missing")
         
     | 
| 
       183 
253 
     | 
    
         
             
                    return
         
     | 
| 
       184 
254 
     | 
    
         
             
                  end
         
     | 
| 
       185 
255 
     | 
    
         
             
                  if pages.empty?
         
     | 
| 
       186 
     | 
    
         
            -
                     
     | 
| 
       187 
     | 
    
         
            -
             
     | 
| 
      
 256 
     | 
    
         
            +
                    set_response(response, :bad_request,
         
     | 
| 
      
 257 
     | 
    
         
            +
                                 "no pages")
         
     | 
| 
      
 258 
     | 
    
         
            +
                    return
         
     | 
| 
       188 
259 
     | 
    
         
             
                  end
         
     | 
| 
       189 
260 
     | 
    
         | 
| 
       190 
261 
     | 
    
         
             
                  revisions = pages.collect do |page|
         
     | 
| 
         @@ -203,7 +274,23 @@ module GitHubWebHooksReceiver 
     | 
|
| 
       203 
274 
     | 
    
         
             
                  [before, after, reference]
         
     | 
| 
       204 
275 
     | 
    
         
             
                end
         
     | 
| 
       205 
276 
     | 
    
         | 
| 
       206 
     | 
    
         
            -
                def  
     | 
| 
      
 277 
     | 
    
         
            +
                def process_gitlab_wiki_parameters(request, response, payload)
         
     | 
| 
      
 278 
     | 
    
         
            +
                  before = "HEAD~"
         
     | 
| 
      
 279 
     | 
    
         
            +
                  after = "HEAD"
         
     | 
| 
      
 280 
     | 
    
         
            +
                  reference = "refs/heads/master"
         
     | 
| 
      
 281 
     | 
    
         
            +
                  [before, after, reference]
         
     | 
| 
      
 282 
     | 
    
         
            +
                end
         
     | 
| 
      
 283 
     | 
    
         
            +
             
     | 
| 
      
 284 
     | 
    
         
            +
                def set_response(response, status_keyword, message)
         
     | 
| 
      
 285 
     | 
    
         
            +
                  if File.directory?("log")
         
     | 
| 
      
 286 
     | 
    
         
            +
                    begin
         
     | 
| 
      
 287 
     | 
    
         
            +
                      require "pp"
         
     | 
| 
      
 288 
     | 
    
         
            +
                      File.open("log/response.log", "w") do |log|
         
     | 
| 
      
 289 
     | 
    
         
            +
                        PP.pp([status_keyword, message], log)
         
     | 
| 
      
 290 
     | 
    
         
            +
                      end
         
     | 
| 
      
 291 
     | 
    
         
            +
                    rescue SystemCallError
         
     | 
| 
      
 292 
     | 
    
         
            +
                    end
         
     | 
| 
      
 293 
     | 
    
         
            +
                  end
         
     | 
| 
       207 
294 
     | 
    
         
             
                  response.status = status(status_keyword)
         
     | 
| 
       208 
295 
     | 
    
         
             
                  response["Content-Type"] = "text/plain"
         
     | 
| 
       209 
296 
     | 
    
         
             
                  response.write(message)
         
     | 
| 
         @@ -1,4 +1,4 @@ 
     | 
|
| 
       1 
     | 
    
         
            -
            # Copyright (C) 2010- 
     | 
| 
      
 1 
     | 
    
         
            +
            # Copyright (C) 2010-2016  Kouhei Sutou <kou@clear-code.com>
         
     | 
| 
       2 
2 
     | 
    
         
             
            # Copyright (C) 2015  Kenji Okimoto <okimoto@clear-code.com>
         
     | 
| 
       3 
3 
     | 
    
         
             
            #
         
     | 
| 
       4 
4 
     | 
    
         
             
            # This program is free software: you can redistribute it and/or modify
         
     | 
| 
         @@ -32,7 +32,9 @@ module GitHubWebHooksReceiver 
     | 
|
| 
       32 
32 
     | 
    
         
             
                end
         
     | 
| 
       33 
33 
     | 
    
         | 
| 
       34 
34 
     | 
    
         
             
                def repository_url
         
     | 
| 
       35 
     | 
    
         
            -
                  if  
     | 
| 
      
 35 
     | 
    
         
            +
                  if gitlab_wiki?
         
     | 
| 
      
 36 
     | 
    
         
            +
                    self["wiki.git_ssh_url"]
         
     | 
| 
      
 37 
     | 
    
         
            +
                  elsif gitlab?
         
     | 
| 
       36 
38 
     | 
    
         
             
                    self["repository.url"]
         
     | 
| 
       37 
39 
     | 
    
         
             
                  elsif github_gollum?
         
     | 
| 
       38 
40 
     | 
    
         
             
                    self["repository.clone_url"].gsub(/(\.git)\z/, ".wiki\\1")
         
     | 
| 
         @@ -42,7 +44,11 @@ module GitHubWebHooksReceiver 
     | 
|
| 
       42 
44 
     | 
    
         
             
                end
         
     | 
| 
       43 
45 
     | 
    
         | 
| 
       44 
46 
     | 
    
         
             
                def gitlab?
         
     | 
| 
       45 
     | 
    
         
            -
                  not self[" 
     | 
| 
      
 47 
     | 
    
         
            +
                  not self["object_kind"].nil?
         
     | 
| 
      
 48 
     | 
    
         
            +
                end
         
     | 
| 
      
 49 
     | 
    
         
            +
             
     | 
| 
      
 50 
     | 
    
         
            +
                def gitlab_wiki?
         
     | 
| 
      
 51 
     | 
    
         
            +
                  event_name == "wiki_page"
         
     | 
| 
       46 
52 
     | 
    
         
             
                end
         
     | 
| 
       47 
53 
     | 
    
         | 
| 
       48 
54 
     | 
    
         
             
                def github_gollum?
         
     | 
| 
         @@ -50,7 +56,11 @@ module GitHubWebHooksReceiver 
     | 
|
| 
       50 
56 
     | 
    
         
             
                end
         
     | 
| 
       51 
57 
     | 
    
         | 
| 
       52 
58 
     | 
    
         
             
                def event_name
         
     | 
| 
       53 
     | 
    
         
            -
                   
     | 
| 
      
 59 
     | 
    
         
            +
                  if gitlab?
         
     | 
| 
      
 60 
     | 
    
         
            +
                    self["object_kind"]
         
     | 
| 
      
 61 
     | 
    
         
            +
                  else
         
     | 
| 
      
 62 
     | 
    
         
            +
                    @metadata["x-github-event"]
         
     | 
| 
      
 63 
     | 
    
         
            +
                  end
         
     | 
| 
       54 
64 
     | 
    
         
             
                end
         
     | 
| 
       55 
65 
     | 
    
         
             
              end
         
     | 
| 
       56 
66 
     | 
    
         
             
            end
         
     | 
| 
         @@ -1,4 +1,4 @@ 
     | 
|
| 
       1 
     | 
    
         
            -
            # Copyright (C) 2010- 
     | 
| 
      
 1 
     | 
    
         
            +
            # Copyright (C) 2010-2016  Kouhei Sutou <kou@clear-code.com>
         
     | 
| 
       2 
2 
     | 
    
         
             
            # Copyright (C) 2015  Kenji Okimoto <okimoto@clear-code.com>
         
     | 
| 
       3 
3 
     | 
    
         
             
            #
         
     | 
| 
       4 
4 
     | 
    
         
             
            # This program is free software: you can redistribute it and/or modify
         
     | 
| 
         @@ -14,6 +14,8 @@ 
     | 
|
| 
       14 
14 
     | 
    
         
             
            # You should have received a copy of the GNU General Public License
         
     | 
| 
       15 
15 
     | 
    
         
             
            # along with this program.  If not, see <http://www.gnu.org/licenses/>.
         
     | 
| 
       16 
16 
     | 
    
         | 
| 
      
 17 
     | 
    
         
            +
            require "stringio"
         
     | 
| 
      
 18 
     | 
    
         
            +
             
     | 
| 
       17 
19 
     | 
    
         
             
            module GitHubWebHooksReceiver
         
     | 
| 
       18 
20 
     | 
    
         
             
              class Repository
         
     | 
| 
       19 
21 
     | 
    
         
             
                include PathResolver
         
     | 
| 
         @@ -32,39 +34,53 @@ module GitHubWebHooksReceiver 
     | 
|
| 
       32 
34 
     | 
    
         
             
                  raise Error.new("mail receive address is missing: <#{@name}>") if @to.nil?
         
     | 
| 
       33 
35 
     | 
    
         
             
                end
         
     | 
| 
       34 
36 
     | 
    
         | 
| 
       35 
     | 
    
         
            -
                def  
     | 
| 
       36 
     | 
    
         
            -
                   
     | 
| 
       37 
     | 
    
         
            -
             
     | 
| 
       38 
     | 
    
         
            -
                   
     | 
| 
      
 37 
     | 
    
         
            +
                def enabled?
         
     | 
| 
      
 38 
     | 
    
         
            +
                  enabled = @options[:enabled]
         
     | 
| 
      
 39 
     | 
    
         
            +
                  enabled = true if enabled.nil?
         
     | 
| 
      
 40 
     | 
    
         
            +
                  enabled
         
     | 
| 
       39 
41 
     | 
    
         
             
                end
         
     | 
| 
       40 
42 
     | 
    
         | 
| 
       41 
43 
     | 
    
         
             
                def process(before, after, reference)
         
     | 
| 
       42 
     | 
    
         
            -
                  FileUtils.mkdir_p( 
     | 
| 
      
 44 
     | 
    
         
            +
                  FileUtils.mkdir_p(File.dirname(mirror_path))
         
     | 
| 
       43 
45 
     | 
    
         
             
                  n_retries = 0
         
     | 
| 
       44 
     | 
    
         
            -
                   
     | 
| 
       45 
     | 
    
         
            -
                     
     | 
| 
       46 
     | 
    
         
            -
                       
     | 
| 
       47 
     | 
    
         
            -
             
     | 
| 
       48 
     | 
    
         
            -
                       
     | 
| 
       49 
     | 
    
         
            -
             
     | 
| 
       50 
     | 
    
         
            -
             
     | 
| 
      
 46 
     | 
    
         
            +
                  lock("#{mirror_path}.lock") do
         
     | 
| 
      
 47 
     | 
    
         
            +
                    begin
         
     | 
| 
      
 48 
     | 
    
         
            +
                      if File.exist?(mirror_path)
         
     | 
| 
      
 49 
     | 
    
         
            +
                        git("--git-dir", mirror_path, "fetch", "--quiet", "--prune")
         
     | 
| 
      
 50 
     | 
    
         
            +
                      else
         
     | 
| 
      
 51 
     | 
    
         
            +
                        git("clone", "--quiet",
         
     | 
| 
      
 52 
     | 
    
         
            +
                            "--mirror", @payload.repository_url,
         
     | 
| 
      
 53 
     | 
    
         
            +
                            mirror_path)
         
     | 
| 
      
 54 
     | 
    
         
            +
                      end
         
     | 
| 
      
 55 
     | 
    
         
            +
                    rescue Error
         
     | 
| 
      
 56 
     | 
    
         
            +
                      n_retries += 1
         
     | 
| 
      
 57 
     | 
    
         
            +
                      retry if n_retries <= @max_n_retries
         
     | 
| 
      
 58 
     | 
    
         
            +
                      raise
         
     | 
| 
       51 
59 
     | 
    
         
             
                    end
         
     | 
| 
       52 
     | 
    
         
            -
                  rescue Error
         
     | 
| 
       53 
     | 
    
         
            -
                    n_retries += 1
         
     | 
| 
       54 
     | 
    
         
            -
                    retry if n_retries <= @max_n_retries
         
     | 
| 
       55 
     | 
    
         
            -
                    raise
         
     | 
| 
       56 
60 
     | 
    
         
             
                  end
         
     | 
| 
       57 
61 
     | 
    
         
             
                  send_commit_email(before, after, reference)
         
     | 
| 
       58 
62 
     | 
    
         
             
                end
         
     | 
| 
       59 
63 
     | 
    
         | 
| 
      
 64 
     | 
    
         
            +
                def lock(path)
         
     | 
| 
      
 65 
     | 
    
         
            +
                  File.open(path, "w") do |file|
         
     | 
| 
      
 66 
     | 
    
         
            +
                    file.flock(File::LOCK_EX)
         
     | 
| 
      
 67 
     | 
    
         
            +
                    yield
         
     | 
| 
      
 68 
     | 
    
         
            +
                  end
         
     | 
| 
      
 69 
     | 
    
         
            +
                end
         
     | 
| 
      
 70 
     | 
    
         
            +
             
     | 
| 
       60 
71 
     | 
    
         
             
                def send_commit_email(before, after, reference)
         
     | 
| 
       61 
72 
     | 
    
         
             
                  options = [
         
     | 
| 
       62 
73 
     | 
    
         
             
                    "--repository", mirror_path,
         
     | 
| 
       63 
74 
     | 
    
         
             
                    "--max-size", "1M"
         
     | 
| 
       64 
75 
     | 
    
         
             
                  ]
         
     | 
| 
       65 
76 
     | 
    
         
             
                  if @payload.gitlab?
         
     | 
| 
       66 
     | 
    
         
            -
                     
     | 
| 
       67 
     | 
    
         
            -
             
     | 
| 
      
 77 
     | 
    
         
            +
                    if @payload.gitlab_wiki?
         
     | 
| 
      
 78 
     | 
    
         
            +
                      add_option(options, "--repository-browser", "gitlab-wiki")
         
     | 
| 
      
 79 
     | 
    
         
            +
                      gitlab_project_uri = @payload["project"]["homepage"]
         
     | 
| 
      
 80 
     | 
    
         
            +
                    else
         
     | 
| 
      
 81 
     | 
    
         
            +
                      add_option(options, "--repository-browser", "gitlab")
         
     | 
| 
      
 82 
     | 
    
         
            +
                      gitlab_project_uri = @payload["repository"]["homepage"]
         
     | 
| 
      
 83 
     | 
    
         
            +
                    end
         
     | 
| 
       68 
84 
     | 
    
         
             
                    add_option(options, "--gitlab-project-uri", gitlab_project_uri)
         
     | 
| 
       69 
85 
     | 
    
         
             
                  else
         
     | 
| 
       70 
86 
     | 
    
         
             
                    if @payload.github_gollum?
         
     | 
| 
         @@ -92,16 +108,20 @@ module GitHubWebHooksReceiver 
     | 
|
| 
       92 
108 
     | 
    
         
             
                  else
         
     | 
| 
       93 
109 
     | 
    
         
             
                    options << @to
         
     | 
| 
       94 
110 
     | 
    
         
             
                  end
         
     | 
| 
       95 
     | 
    
         
            -
                  command_line = [ruby,  
     | 
| 
      
 111 
     | 
    
         
            +
                  command_line = [ruby, git_commit_mailer, *options].collect do |component|
         
     | 
| 
       96 
112 
     | 
    
         
             
                    Shellwords.escape(component)
         
     | 
| 
       97 
113 
     | 
    
         
             
                  end.join(" ")
         
     | 
| 
       98 
114 
     | 
    
         
             
                  change = "#{before} #{after} #{reference}"
         
     | 
| 
       99 
     | 
    
         
            -
                   
     | 
| 
       100 
     | 
    
         
            -
             
     | 
| 
      
 115 
     | 
    
         
            +
                  status = nil
         
     | 
| 
      
 116 
     | 
    
         
            +
                  output = capture_output do
         
     | 
| 
      
 117 
     | 
    
         
            +
                    IO.popen(command_line, "w") do |io|
         
     | 
| 
      
 118 
     | 
    
         
            +
                      io.puts(change)
         
     | 
| 
      
 119 
     | 
    
         
            +
                    end
         
     | 
| 
      
 120 
     | 
    
         
            +
                    status = $?
         
     | 
| 
       101 
121 
     | 
    
         
             
                  end
         
     | 
| 
       102 
     | 
    
         
            -
                  unless  
     | 
| 
       103 
     | 
    
         
            -
                    raise Error.new("failed to run commit- 
     | 
| 
       104 
     | 
    
         
            -
                                    "<#{command_line}>:<#{change}>")
         
     | 
| 
      
 122 
     | 
    
         
            +
                  unless status.success?
         
     | 
| 
      
 123 
     | 
    
         
            +
                    raise Error.new("failed to run git-commit-mailer: " +
         
     | 
| 
      
 124 
     | 
    
         
            +
                                    "<#{command_line}>:<#{change}>:<#{output}>")
         
     | 
| 
       105 
125 
     | 
    
         
             
                  end
         
     | 
| 
       106 
126 
     | 
    
         
             
                end
         
     | 
| 
       107 
127 
     | 
    
         | 
| 
         @@ -126,7 +146,7 @@ module GitHubWebHooksReceiver 
     | 
|
| 
       126 
146 
     | 
    
         | 
| 
       127 
147 
     | 
    
         
             
                def mirror_path
         
     | 
| 
       128 
148 
     | 
    
         
             
                  components = [mirrors_directory, @domain, @owner_name]
         
     | 
| 
       129 
     | 
    
         
            -
                  if @payload.github_gollum?
         
     | 
| 
      
 149 
     | 
    
         
            +
                  if @payload.github_gollum? or @payload.gitlab_wiki?
         
     | 
| 
       130 
150 
     | 
    
         
             
                    components << "#{@name}.wiki"
         
     | 
| 
       131 
151 
     | 
    
         
             
                  else
         
     | 
| 
       132 
152 
     | 
    
         
             
                    components << @name
         
     | 
| 
         @@ -144,6 +164,10 @@ module GitHubWebHooksReceiver 
     | 
|
| 
       144 
164 
     | 
    
         
             
                    path("..", "commit-email.rb")
         
     | 
| 
       145 
165 
     | 
    
         
             
                end
         
     | 
| 
       146 
166 
     | 
    
         | 
| 
      
 167 
     | 
    
         
            +
                def git_commit_mailer
         
     | 
| 
      
 168 
     | 
    
         
            +
                  @git_commit_mailer ||= @options[:git_commit_mailer] || commit_email
         
     | 
| 
      
 169 
     | 
    
         
            +
                end
         
     | 
| 
      
 170 
     | 
    
         
            +
             
     | 
| 
       147 
171 
     | 
    
         
             
                def from
         
     | 
| 
       148 
172 
     | 
    
         
             
                  @from ||= @options[:from]
         
     | 
| 
       149 
173 
     | 
    
         
             
                end
         
     | 
| 
         @@ -188,5 +212,20 @@ module GitHubWebHooksReceiver 
     | 
|
| 
       188 
212 
     | 
    
         
             
                  return if value.empty?
         
     | 
| 
       189 
213 
     | 
    
         
             
                  options.concat([name, value])
         
     | 
| 
       190 
214 
     | 
    
         
             
                end
         
     | 
| 
      
 215 
     | 
    
         
            +
             
     | 
| 
      
 216 
     | 
    
         
            +
                def capture_output
         
     | 
| 
      
 217 
     | 
    
         
            +
                  output = StringIO.new
         
     | 
| 
      
 218 
     | 
    
         
            +
                  stdout = $stdout
         
     | 
| 
      
 219 
     | 
    
         
            +
                  stderr = $stderr
         
     | 
| 
      
 220 
     | 
    
         
            +
                  begin
         
     | 
| 
      
 221 
     | 
    
         
            +
                    $stdout = output
         
     | 
| 
      
 222 
     | 
    
         
            +
                    $stderr = output
         
     | 
| 
      
 223 
     | 
    
         
            +
                    yield
         
     | 
| 
      
 224 
     | 
    
         
            +
                  ensure
         
     | 
| 
      
 225 
     | 
    
         
            +
                    $stdout = stdout
         
     | 
| 
      
 226 
     | 
    
         
            +
                    $stderr = stderr
         
     | 
| 
      
 227 
     | 
    
         
            +
                  end
         
     | 
| 
      
 228 
     | 
    
         
            +
                  output.string
         
     | 
| 
      
 229 
     | 
    
         
            +
                end
         
     | 
| 
       191 
230 
     | 
    
         
             
              end
         
     | 
| 
       192 
231 
     | 
    
         
             
            end
         
     | 
    
        data/test/receiver-test.rb
    CHANGED
    
    | 
         @@ -102,8 +102,8 @@ class ReceiverTest < Test::Unit::TestCase 
     | 
|
| 
       102 
102 
     | 
    
         
             
                                   :name => owner_name,
         
     | 
| 
       103 
103 
     | 
    
         
             
                                 },
         
     | 
| 
       104 
104 
     | 
    
         
             
                               })
         
     | 
| 
       105 
     | 
    
         
            -
                  assert_response(" 
     | 
| 
       106 
     | 
    
         
            -
                  assert_equal(" 
     | 
| 
      
 105 
     | 
    
         
            +
                  assert_response("Accepted")
         
     | 
| 
      
 106 
     | 
    
         
            +
                  assert_equal("ignore disabled repository: " +
         
     | 
| 
       107 
107 
     | 
    
         
             
                               "<#{owner_name.inspect}>:<#{repository_name.inspect}>",
         
     | 
| 
       108 
108 
     | 
    
         
             
                               body)
         
     | 
| 
       109 
109 
     | 
    
         
             
                end
         
     | 
| 
         @@ -225,6 +225,7 @@ class ReceiverTest < Test::Unit::TestCase 
     | 
|
| 
       225 
225 
     | 
    
         
             
                  assert_false(File.exist?(repository_mirror_path))
         
     | 
| 
       226 
226 
     | 
    
         
             
                  options[:owners] = {
         
     | 
| 
       227 
227 
     | 
    
         
             
                    "ranguba" => {
         
     | 
| 
      
 228 
     | 
    
         
            +
                      :enabled => true,
         
     | 
| 
       228 
229 
     | 
    
         
             
                      :to => "ranguba-commit@example.org",
         
     | 
| 
       229 
230 
     | 
    
         
             
                      :from => "ranguba+commit@example.org",
         
     | 
| 
       230 
231 
     | 
    
         
             
                      :sender => "null@example.org",
         
     | 
| 
         @@ -272,6 +273,7 @@ class ReceiverTest < Test::Unit::TestCase 
     | 
|
| 
       272 
273 
     | 
    
         
             
                      :sender => "null@example.org",
         
     | 
| 
       273 
274 
     | 
    
         
             
                      "repositories" => {
         
     | 
| 
       274 
275 
     | 
    
         
             
                        "rroonga" => {
         
     | 
| 
      
 276 
     | 
    
         
            +
                          :enabled => true,
         
     | 
| 
       275 
277 
     | 
    
         
             
                          :to => "ranguba-commit@example.net",
         
     | 
| 
       276 
278 
     | 
    
         
             
                          :from => "ranguba+commit@example.net",
         
     | 
| 
       277 
279 
     | 
    
         
             
                          :sender => "null@example.net",
         
     | 
| 
         @@ -371,12 +373,17 @@ class ReceiverTest < Test::Unit::TestCase 
     | 
|
| 
       371 
373 
     | 
    
         | 
| 
       372 
374 
     | 
    
         
             
              def options
         
     | 
| 
       373 
375 
     | 
    
         
             
                @options ||= {
         
     | 
| 
       374 
     | 
    
         
            -
                  : 
     | 
| 
      
 376 
     | 
    
         
            +
                  :enabled => false,
         
     | 
| 
       375 
377 
     | 
    
         
             
                  :base_dir => @tmp_dir,
         
     | 
| 
       376 
378 
     | 
    
         
             
                  :fixtures_dir => @fixtures_dir,
         
     | 
| 
       377 
379 
     | 
    
         
             
                  :repository_class => LocalRepository,
         
     | 
| 
       378 
380 
     | 
    
         
             
                  :commit_email => File.join(@fixtures_dir, "mock-commit-email.rb"),
         
     | 
| 
       379 
381 
     | 
    
         
             
                  :to => "null@example.com",
         
     | 
| 
      
 382 
     | 
    
         
            +
                  :owners => {
         
     | 
| 
      
 383 
     | 
    
         
            +
                    "ranguba" => {
         
     | 
| 
      
 384 
     | 
    
         
            +
                      :enabled => true,
         
     | 
| 
      
 385 
     | 
    
         
            +
                    },
         
     | 
| 
      
 386 
     | 
    
         
            +
                  },
         
     | 
| 
       380 
387 
     | 
    
         
             
                }
         
     | 
| 
       381 
388 
     | 
    
         
             
              end
         
     | 
| 
       382 
389 
     | 
    
         | 
    
        metadata
    CHANGED
    
    | 
         @@ -1,7 +1,7 @@ 
     | 
|
| 
       1 
1 
     | 
    
         
             
            --- !ruby/object:Gem::Specification
         
     | 
| 
       2 
2 
     | 
    
         
             
            name: github-web-hooks-receiver
         
     | 
| 
       3 
3 
     | 
    
         
             
            version: !ruby/object:Gem::Version
         
     | 
| 
       4 
     | 
    
         
            -
              version: 1.0. 
     | 
| 
      
 4 
     | 
    
         
            +
              version: 1.0.1
         
     | 
| 
       5 
5 
     | 
    
         
             
            platform: ruby
         
     | 
| 
       6 
6 
     | 
    
         
             
            authors:
         
     | 
| 
       7 
7 
     | 
    
         
             
            - Kouhei Sutou
         
     | 
| 
         @@ -9,7 +9,7 @@ authors: 
     | 
|
| 
       9 
9 
     | 
    
         
             
            autorequire: 
         
     | 
| 
       10 
10 
     | 
    
         
             
            bindir: bin
         
     | 
| 
       11 
11 
     | 
    
         
             
            cert_chain: []
         
     | 
| 
       12 
     | 
    
         
            -
            date:  
     | 
| 
      
 12 
     | 
    
         
            +
            date: 2016-10-07 00:00:00.000000000 Z
         
     | 
| 
       13 
13 
     | 
    
         
             
            dependencies:
         
     | 
| 
       14 
14 
     | 
    
         
             
            - !ruby/object:Gem::Dependency
         
     | 
| 
       15 
15 
     | 
    
         
             
              name: rack
         
     | 
| 
         @@ -110,6 +110,7 @@ files: 
     | 
|
| 
       110 
110 
     | 
    
         
             
            - Rakefile
         
     | 
| 
       111 
111 
     | 
    
         
             
            - config.ru
         
     | 
| 
       112 
112 
     | 
    
         
             
            - config.yaml.example
         
     | 
| 
      
 113 
     | 
    
         
            +
            - doc/text/news.md
         
     | 
| 
       113 
114 
     | 
    
         
             
            - github-web-hooks-receiver.gemspec
         
     | 
| 
       114 
115 
     | 
    
         
             
            - lib/github-web-hooks-receiver.rb
         
     | 
| 
       115 
116 
     | 
    
         
             
            - lib/github-web-hooks-receiver/app.rb
         
     | 
| 
         @@ -128,7 +129,7 @@ files: 
     | 
|
| 
       128 
129 
     | 
    
         
             
            - test/receiver-test.rb
         
     | 
| 
       129 
130 
     | 
    
         
             
            - test/run-test.rb
         
     | 
| 
       130 
131 
     | 
    
         
             
            - test/test-unit.yml
         
     | 
| 
       131 
     | 
    
         
            -
            homepage:  
     | 
| 
      
 132 
     | 
    
         
            +
            homepage: https://github.com/clear-code/github-web-hooks-receiver
         
     | 
| 
       132 
133 
     | 
    
         
             
            licenses:
         
     | 
| 
       133 
134 
     | 
    
         
             
            - GPL-3.0+
         
     | 
| 
       134 
135 
     | 
    
         
             
            metadata: {}
         
     | 
| 
         @@ -148,7 +149,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement 
     | 
|
| 
       148 
149 
     | 
    
         
             
                  version: '0'
         
     | 
| 
       149 
150 
     | 
    
         
             
            requirements: []
         
     | 
| 
       150 
151 
     | 
    
         
             
            rubyforge_project: 
         
     | 
| 
       151 
     | 
    
         
            -
            rubygems_version: 2. 
     | 
| 
      
 152 
     | 
    
         
            +
            rubygems_version: 2.5.1
         
     | 
| 
       152 
153 
     | 
    
         
             
            signing_key: 
         
     | 
| 
       153 
154 
     | 
    
         
             
            specification_version: 4
         
     | 
| 
       154 
155 
     | 
    
         
             
            summary: GitHub web hook receiver
         
     |