lita-gitlab 1.0.0
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 +7 -0
- data/.gitignore +18 -0
- data/.travis.yml +8 -0
- data/Gemfile +3 -0
- data/LICENSE +19 -0
- data/README.md +39 -0
- data/Rakefile +6 -0
- data/lib/lita/handlers/gitlab.rb +85 -0
- data/lib/lita-gitlab.rb +7 -0
- data/lita-gitlab.gemspec +25 -0
- data/locales/en.yml +23 -0
- data/spec/fixtures/system/new_team_member.json +10 -0
- data/spec/fixtures/system/project_created.json +10 -0
- data/spec/fixtures/system/project_destroyed.json +10 -0
- data/spec/fixtures/system/team_member_removed.json +10 -0
- data/spec/fixtures/system/user_created.json +7 -0
- data/spec/fixtures/system/user_removed.json +7 -0
- data/spec/fixtures/web/issue.json +18 -0
- data/spec/fixtures/web/merge_request.json +22 -0
- data/spec/fixtures/web/push.json +37 -0
- data/spec/lita/handlers/gitlab_spec.rb +132 -0
- data/spec/spec_helper.rb +17 -0
- metadata +175 -0
    
        checksums.yaml
    ADDED
    
    | @@ -0,0 +1,7 @@ | |
| 1 | 
            +
            ---
         | 
| 2 | 
            +
            SHA1:
         | 
| 3 | 
            +
              metadata.gz: a3db94cfc04d0f11a09276ab56a45c1b5031aee0
         | 
| 4 | 
            +
              data.tar.gz: 8887d8ed2fdfb829d83af3600205d2fd4a8b3fd2
         | 
| 5 | 
            +
            SHA512:
         | 
| 6 | 
            +
              metadata.gz: 9852e313140d112eaf089053a6e92fce8b08be804acf38ffbb17a2389077dd26f55f4cf8fdd42dd85c23ca35a3e673937c5e47388ae3e4544a7580c5d8e1c2d0
         | 
| 7 | 
            +
              data.tar.gz: 935c630979fbb661fd6f87e4bbdeb556d45ad6309db93b850c6cc32cb53dd858872260334573bb8e7a32409a8b27ed2a12f66df28491cd6e9efbb6baa26cad13
         | 
    
        data/.gitignore
    ADDED
    
    
    
        data/.travis.yml
    ADDED
    
    
    
        data/Gemfile
    ADDED
    
    
    
        data/LICENSE
    ADDED
    
    | @@ -0,0 +1,19 @@ | |
| 1 | 
            +
            Copyright (c) 2014 Milo
         | 
| 2 | 
            +
             | 
| 3 | 
            +
            Permission is hereby granted, free of charge, to any person obtaining a copy
         | 
| 4 | 
            +
            of this software and associated documentation files (the "Software"), to deal
         | 
| 5 | 
            +
            in the Software without restriction, including without limitation the rights
         | 
| 6 | 
            +
            to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
         | 
| 7 | 
            +
            copies of the Software, and to permit persons to whom the Software is
         | 
| 8 | 
            +
            furnished to do so, subject to the following conditions:
         | 
| 9 | 
            +
             | 
| 10 | 
            +
            The above copyright notice and this permission notice shall be included in
         | 
| 11 | 
            +
            all copies or substantial portions of the Software.
         | 
| 12 | 
            +
             | 
| 13 | 
            +
            THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
         | 
| 14 | 
            +
            IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
         | 
| 15 | 
            +
            FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
         | 
| 16 | 
            +
            AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
         | 
| 17 | 
            +
            LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
         | 
| 18 | 
            +
            OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
         | 
| 19 | 
            +
            THE SOFTWARE.
         | 
    
        data/README.md
    ADDED
    
    | @@ -0,0 +1,39 @@ | |
| 1 | 
            +
            # lita-gitlab
         | 
| 2 | 
            +
             | 
| 3 | 
            +
             [](https://travis-ci.org/milo-ft/lita-gitlab)
         | 
| 4 | 
            +
             [](https://codeclimate.com/github/milo-ft/lita-gitlab)
         | 
| 5 | 
            +
             [](https://coveralls.io/r/milo-ft/lita-gitlab)
         | 
| 6 | 
            +
             | 
| 7 | 
            +
            **lita-gitlab** is a [Lita](https://github.com/jimmycuadra/lita) that will display [GitLab](https://www.gitlab.com/gitlab-ce/) messages in the channel.
         | 
| 8 | 
            +
             | 
| 9 | 
            +
            ## Installation
         | 
| 10 | 
            +
             | 
| 11 | 
            +
            Add **lita-gitlab** to your Lita instance's Gemfile:
         | 
| 12 | 
            +
             | 
| 13 | 
            +
            ``` ruby
         | 
| 14 | 
            +
            gem "lita-gitlab"
         | 
| 15 | 
            +
            ```
         | 
| 16 | 
            +
             | 
| 17 | 
            +
            ## Configuration
         | 
| 18 | 
            +
             | 
| 19 | 
            +
            ### Required attributes
         | 
| 20 | 
            +
             | 
| 21 | 
            +
            * `default_room` (String) - A channel idenitifier.
         | 
| 22 | 
            +
            ie: `#general`.
         | 
| 23 | 
            +
             | 
| 24 | 
            +
            ### Example
         | 
| 25 | 
            +
             | 
| 26 | 
            +
            ``` ruby
         | 
| 27 | 
            +
            Lita.configure do |config|
         | 
| 28 | 
            +
              config.handlers.gitlab.default_room = '#general'
         | 
| 29 | 
            +
            end
         | 
| 30 | 
            +
            ```
         | 
| 31 | 
            +
             | 
| 32 | 
            +
            ## Usage
         | 
| 33 | 
            +
             | 
| 34 | 
            +
            * `targets` Channel(s) separated by commas.
         | 
| 35 | 
            +
            You will need to add a GitLab Webhook url that points to: `http://address.of./lita/gitlab?targets=<targets>`
         | 
| 36 | 
            +
             | 
| 37 | 
            +
            ## License
         | 
| 38 | 
            +
             | 
| 39 | 
            +
            [MIT](http://opensource.org/licenses/MIT)
         | 
    
        data/Rakefile
    ADDED
    
    
| @@ -0,0 +1,85 @@ | |
| 1 | 
            +
            module Lita
         | 
| 2 | 
            +
              module Handlers
         | 
| 3 | 
            +
                class Gitlab < Handler
         | 
| 4 | 
            +
             | 
| 5 | 
            +
                  def self.default_config(config)
         | 
| 6 | 
            +
                    config.default_room = '#general'
         | 
| 7 | 
            +
                  end
         | 
| 8 | 
            +
             | 
| 9 | 
            +
                  http.post '/lita/gitlab', :receive
         | 
| 10 | 
            +
             | 
| 11 | 
            +
                  def receive(request, response)
         | 
| 12 | 
            +
                    json_data = parse_payload(request.params['payload'])
         | 
| 13 | 
            +
                    data = symbolize(json_data)
         | 
| 14 | 
            +
                    message = format_message(data)
         | 
| 15 | 
            +
                    targets = request.params['targets'] || '#general'
         | 
| 16 | 
            +
                    rooms = []
         | 
| 17 | 
            +
                    targets.split(',').each do |param_target|
         | 
| 18 | 
            +
                      rooms << param_target
         | 
| 19 | 
            +
                    end
         | 
| 20 | 
            +
                    rooms.each do |room|
         | 
| 21 | 
            +
                      target = Source.new(room: room)
         | 
| 22 | 
            +
                      robot.send_message(target, message)
         | 
| 23 | 
            +
                    end
         | 
| 24 | 
            +
                  end
         | 
| 25 | 
            +
             | 
| 26 | 
            +
                  private
         | 
| 27 | 
            +
             | 
| 28 | 
            +
                  def format_message(data)
         | 
| 29 | 
            +
                    data.key?(:event_name) ? system_message(data) : web_message(data)
         | 
| 30 | 
            +
                  end
         | 
| 31 | 
            +
             | 
| 32 | 
            +
                  def system_message(data)
         | 
| 33 | 
            +
                    build_message "system.#{data[:event_name]}", data
         | 
| 34 | 
            +
                  rescue
         | 
| 35 | 
            +
                    Lita.logger.warn "Error formatting message: #{data.inspect}"
         | 
| 36 | 
            +
                  end
         | 
| 37 | 
            +
             | 
| 38 | 
            +
                  def web_message(data)
         | 
| 39 | 
            +
                    if data.key? :object_kind
         | 
| 40 | 
            +
                      if data[:object_attributes].key? :target_branch
         | 
| 41 | 
            +
                        # Merge request
         | 
| 42 | 
            +
                        data[:object_attributes][:link] = "#{data[:object_attributes][:target_branch]}/#{data[:object_attributes][:iid]}"
         | 
| 43 | 
            +
                        build_message "web.#{data[:object_kind]}.#{data[:object_attributes][:state]}", data[:object_attributes]
         | 
| 44 | 
            +
                      else
         | 
| 45 | 
            +
                        # Issue
         | 
| 46 | 
            +
                        build_message "web.#{data[:object_kind]}.#{data[:object_attributes][:state]}", data[:object_attributes]
         | 
| 47 | 
            +
                      end
         | 
| 48 | 
            +
                    else
         | 
| 49 | 
            +
                      # Push has no object kind
         | 
| 50 | 
            +
                      branch = data[:ref].split('/').drop(2).join('/')
         | 
| 51 | 
            +
                      data[:link] = data[:repository][:name]
         | 
| 52 | 
            +
                      if data[:before] =~ /^0+$/
         | 
| 53 | 
            +
                        build_message 'web.push.new_branch', data
         | 
| 54 | 
            +
                      else
         | 
| 55 | 
            +
                        build_message 'web.push.add_to_branch', data
         | 
| 56 | 
            +
                      end
         | 
| 57 | 
            +
                    end
         | 
| 58 | 
            +
                  rescue
         | 
| 59 | 
            +
                    Lita.logger.warn "Error formatting message: #{data.inspect}"
         | 
| 60 | 
            +
                  end
         | 
| 61 | 
            +
             | 
| 62 | 
            +
                  # General methods
         | 
| 63 | 
            +
             | 
| 64 | 
            +
                  def build_message(key, data)
         | 
| 65 | 
            +
                    t(key) % data
         | 
| 66 | 
            +
                  end
         | 
| 67 | 
            +
             | 
| 68 | 
            +
                  def parse_payload(payload)
         | 
| 69 | 
            +
                    MultiJson.load(payload)
         | 
| 70 | 
            +
                  rescue MultiJson::LoadError => e
         | 
| 71 | 
            +
                    Lita.logger.error("Could not parse JSON payload from Github: #{e.message}")
         | 
| 72 | 
            +
                    return
         | 
| 73 | 
            +
                  end
         | 
| 74 | 
            +
             | 
| 75 | 
            +
                  def symbolize(obj)
         | 
| 76 | 
            +
                    return obj.inject({}){|memo,(k,v)| memo[k.to_sym] =  symbolize(v); memo} if obj.is_a? Hash
         | 
| 77 | 
            +
                    return obj.inject([]){|memo,v    | memo           << symbolize(v); memo} if obj.is_a? Array
         | 
| 78 | 
            +
                    return obj
         | 
| 79 | 
            +
                  end
         | 
| 80 | 
            +
             | 
| 81 | 
            +
                end
         | 
| 82 | 
            +
             | 
| 83 | 
            +
                Lita.register_handler(Gitlab)
         | 
| 84 | 
            +
              end
         | 
| 85 | 
            +
            end
         | 
    
        data/lib/lita-gitlab.rb
    ADDED
    
    
    
        data/lita-gitlab.gemspec
    ADDED
    
    | @@ -0,0 +1,25 @@ | |
| 1 | 
            +
            Gem::Specification.new do |spec|
         | 
| 2 | 
            +
              spec.name          = 'lita-gitlab'
         | 
| 3 | 
            +
              spec.version       = '1.0.0'
         | 
| 4 | 
            +
              spec.authors       = ['Emilio Figueroa']
         | 
| 5 | 
            +
              spec.email         = ['emiliofigueroatorres@gmail.com']
         | 
| 6 | 
            +
              spec.description   = %q{A Lita handler that will display GitLab messages in the channel}
         | 
| 7 | 
            +
              spec.summary       = %q{A Lita handler that will display GitLab messages in the channel}
         | 
| 8 | 
            +
              spec.homepage      = 'https://github.com/milo-ft/lita-gitlab'
         | 
| 9 | 
            +
              spec.license       = 'MIT'
         | 
| 10 | 
            +
              spec.metadata      = { 'lita_plugin_type' => 'handler' }
         | 
| 11 | 
            +
             | 
| 12 | 
            +
              spec.files         = `git ls-files`.split($/)
         | 
| 13 | 
            +
              spec.executables   = spec.files.grep(%r{^bin/}) { |f| File.basename(f) }
         | 
| 14 | 
            +
              spec.test_files    = spec.files.grep(%r{^(test|spec|features)/})
         | 
| 15 | 
            +
              spec.require_paths = ['lib']
         | 
| 16 | 
            +
             | 
| 17 | 
            +
              spec.add_runtime_dependency 'lita', '>= 3.0'
         | 
| 18 | 
            +
             | 
| 19 | 
            +
              spec.add_development_dependency 'bundler', '~> 1.3'
         | 
| 20 | 
            +
              spec.add_development_dependency 'rake'
         | 
| 21 | 
            +
              spec.add_development_dependency 'rspec', '>= 3.0.0.beta2'
         | 
| 22 | 
            +
              spec.add_development_dependency 'shoulda', '>= 3.5.0'
         | 
| 23 | 
            +
              spec.add_development_dependency 'simplecov'
         | 
| 24 | 
            +
              spec.add_development_dependency 'coveralls'
         | 
| 25 | 
            +
            end
         | 
    
        data/locales/en.yml
    ADDED
    
    | @@ -0,0 +1,23 @@ | |
| 1 | 
            +
            en:
         | 
| 2 | 
            +
              lita:
         | 
| 3 | 
            +
                handlers:
         | 
| 4 | 
            +
                  gitlab:
         | 
| 5 | 
            +
                    system:
         | 
| 6 | 
            +
                      user_add_to_team: "%{user_name} has joined the %{project_name} project"
         | 
| 7 | 
            +
                      project_create: "%{owner_name} has created the %{name} project!"
         | 
| 8 | 
            +
                      project_destroy: "%{owner_name} has destroyed the %{name} project!"
         | 
| 9 | 
            +
                      user_remove_from_team: "%{user_name} has left the %{project_name} project"
         | 
| 10 | 
            +
                      user_create: "%{name} has joined the team, welcome %{name}!"
         | 
| 11 | 
            +
                      user_destroy: "%{name} is dead for us."
         | 
| 12 | 
            +
                    web:
         | 
| 13 | 
            +
                      issue:
         | 
| 14 | 
            +
                        opened: "New issue >> %{title}: %{description}"
         | 
| 15 | 
            +
                        reopened: "The issue '%{title}' has been reopened."
         | 
| 16 | 
            +
                        closed: "The issue '%{title}' is now closed"
         | 
| 17 | 
            +
                      merge_request:
         | 
| 18 | 
            +
                        opened: "New merge-request: %{title} to %{link}"
         | 
| 19 | 
            +
                        reopened: "The merge-request '%{title}' has been reopened."
         | 
| 20 | 
            +
                        closed: "The merge-request '%{title}' is now closed."
         | 
| 21 | 
            +
                      push:
         | 
| 22 | 
            +
                        new_branch: "%{user_name} created the new branch '%{link}'"
         | 
| 23 | 
            +
                        add_to_branch: "%{user_name} added %{total_commits_count} commits to branch '%{link}'"
         | 
| @@ -0,0 +1,10 @@ | |
| 1 | 
            +
            {
         | 
| 2 | 
            +
                "created_at": "2012-07-21T07:30:56Z",
         | 
| 3 | 
            +
                "event_name": "user_add_to_team",
         | 
| 4 | 
            +
                "project_access": "Master",
         | 
| 5 | 
            +
                "project_id": 74,
         | 
| 6 | 
            +
                "project_name": "StoreCloud",
         | 
| 7 | 
            +
                "project_path": "storecloud",
         | 
| 8 | 
            +
                "user_email": "johnsmith@gmail.com",
         | 
| 9 | 
            +
                "user_name": "John Smith"
         | 
| 10 | 
            +
            }
         | 
| @@ -0,0 +1,10 @@ | |
| 1 | 
            +
            {
         | 
| 2 | 
            +
                "created_at": "2012-07-21T07:30:54Z",
         | 
| 3 | 
            +
                "event_name": "project_create",
         | 
| 4 | 
            +
                "name": "StoreCloud",
         | 
| 5 | 
            +
                "owner_email": "johnsmith@gmail.com",
         | 
| 6 | 
            +
                "owner_name": "John Smit",
         | 
| 7 | 
            +
                "path": "stormcloud",
         | 
| 8 | 
            +
                "path_with_namespace": "jsmith/stormcloud",
         | 
| 9 | 
            +
                "project_id": 74
         | 
| 10 | 
            +
            }
         | 
| @@ -0,0 +1,10 @@ | |
| 1 | 
            +
            {
         | 
| 2 | 
            +
                "created_at": "2012-07-21T07:30:58Z",
         | 
| 3 | 
            +
                "event_name": "project_destroy",
         | 
| 4 | 
            +
                "name": "Underscore",
         | 
| 5 | 
            +
                "owner_email": "johnsmith@gmail.com",
         | 
| 6 | 
            +
                "owner_name": "John Smith",
         | 
| 7 | 
            +
                "path": "underscore",
         | 
| 8 | 
            +
                "path_with_namespace": "jsmith/underscore",
         | 
| 9 | 
            +
                "project_id": 73
         | 
| 10 | 
            +
            }
         | 
| @@ -0,0 +1,10 @@ | |
| 1 | 
            +
            {
         | 
| 2 | 
            +
                "created_at": "2012-07-21T07:30:56Z",
         | 
| 3 | 
            +
                "event_name": "user_remove_from_team",
         | 
| 4 | 
            +
                "project_access": "Master",
         | 
| 5 | 
            +
                "project_id": 74,
         | 
| 6 | 
            +
                "project_name": "StoreCloud",
         | 
| 7 | 
            +
                "project_path": "storecloud",
         | 
| 8 | 
            +
                "user_email": "johnsmith@gmail.com",
         | 
| 9 | 
            +
                "user_name": "John Smith"
         | 
| 10 | 
            +
            }
         | 
| @@ -0,0 +1,18 @@ | |
| 1 | 
            +
            {
         | 
| 2 | 
            +
                "object_kind": "issue",
         | 
| 3 | 
            +
                "object_attributes": {
         | 
| 4 | 
            +
                    "id": 301,
         | 
| 5 | 
            +
                    "title": "New API: create/update/delete file",
         | 
| 6 | 
            +
                    "assignee_id": 51,
         | 
| 7 | 
            +
                    "author_id": 51,
         | 
| 8 | 
            +
                    "project_id": 14,
         | 
| 9 | 
            +
                    "created_at": "2013-12-03T17:15:43Z",
         | 
| 10 | 
            +
                    "updated_at": "2013-12-03T17:15:43Z",
         | 
| 11 | 
            +
                    "position": 0,
         | 
| 12 | 
            +
                    "branch_name": null,
         | 
| 13 | 
            +
                    "description": "Create new API for manipulations with repository",
         | 
| 14 | 
            +
                    "milestone_id": null,
         | 
| 15 | 
            +
                    "state": "opened",
         | 
| 16 | 
            +
                    "iid": 23
         | 
| 17 | 
            +
                }
         | 
| 18 | 
            +
            }
         | 
| @@ -0,0 +1,22 @@ | |
| 1 | 
            +
            {
         | 
| 2 | 
            +
                "object_kind": "merge_request",
         | 
| 3 | 
            +
                "object_attributes": {
         | 
| 4 | 
            +
                    "id": 99,
         | 
| 5 | 
            +
                    "target_branch": "master",
         | 
| 6 | 
            +
                    "source_branch": "ms-viewport",
         | 
| 7 | 
            +
                    "source_project_id": 14,
         | 
| 8 | 
            +
                    "author_id": 51,
         | 
| 9 | 
            +
                    "assignee_id": 6,
         | 
| 10 | 
            +
                    "title": "MS-Viewport",
         | 
| 11 | 
            +
                    "created_at": "2013-12-03T17:23:34Z",
         | 
| 12 | 
            +
                    "updated_at": "2013-12-03T17:23:34Z",
         | 
| 13 | 
            +
                    "st_commits": null,
         | 
| 14 | 
            +
                    "st_diffs": null,
         | 
| 15 | 
            +
                    "milestone_id": null,
         | 
| 16 | 
            +
                    "state": "opened",
         | 
| 17 | 
            +
                    "merge_status": "unchecked",
         | 
| 18 | 
            +
                    "target_project_id": 14,
         | 
| 19 | 
            +
                    "iid": 1,
         | 
| 20 | 
            +
                    "description": ""
         | 
| 21 | 
            +
                }
         | 
| 22 | 
            +
            }
         | 
| @@ -0,0 +1,37 @@ | |
| 1 | 
            +
            {
         | 
| 2 | 
            +
                "before": "95790bf891e76fee5e1747ab589903a6a1f80f22",
         | 
| 3 | 
            +
                "after": "da1560886d4f094c3e6c9ef40349f7d38b5d27d7",
         | 
| 4 | 
            +
                "ref": "refs/heads/master",
         | 
| 5 | 
            +
                "user_id": 4,
         | 
| 6 | 
            +
                "user_name": "John Smith",
         | 
| 7 | 
            +
                "project_id": 15,
         | 
| 8 | 
            +
                "repository": {
         | 
| 9 | 
            +
                    "name": "Diaspora",
         | 
| 10 | 
            +
                    "url": "git@localhost:diaspora.git",
         | 
| 11 | 
            +
                    "description": "",
         | 
| 12 | 
            +
                    "homepage": "http://localhost/diaspora"
         | 
| 13 | 
            +
                },
         | 
| 14 | 
            +
                "commits": [
         | 
| 15 | 
            +
                    {
         | 
| 16 | 
            +
                        "id": "b6568db1bc1dcd7f8b4d5a946b0b91f9dacd7327",
         | 
| 17 | 
            +
                        "message": "Update Catalan translation to e38cb41.",
         | 
| 18 | 
            +
                        "timestamp": "2011-12-12T14:27:31+02:00",
         | 
| 19 | 
            +
                        "url": "http://localhost/diaspora/commits/b6568db1bc1dcd7f8b4d5a946b0b91f9dacd7327",
         | 
| 20 | 
            +
                        "author": {
         | 
| 21 | 
            +
                            "name": "Jordi Mallach",
         | 
| 22 | 
            +
                            "email": "jordi@softcatala.org"
         | 
| 23 | 
            +
                        }
         | 
| 24 | 
            +
                    },
         | 
| 25 | 
            +
                    {
         | 
| 26 | 
            +
                        "id": "da1560886d4f094c3e6c9ef40349f7d38b5d27d7",
         | 
| 27 | 
            +
                        "message": "fixed readme",
         | 
| 28 | 
            +
                        "timestamp": "2012-01-03T23:36:29+02:00",
         | 
| 29 | 
            +
                        "url": "http://localhost/diaspora/commits/da1560886d4f094c3e6c9ef40349f7d38b5d27d7",
         | 
| 30 | 
            +
                        "author": {
         | 
| 31 | 
            +
                            "name": "GitLab dev user",
         | 
| 32 | 
            +
                            "email": "gitlabdev@dv6700.(none)"
         | 
| 33 | 
            +
                        }
         | 
| 34 | 
            +
                    }
         | 
| 35 | 
            +
                ],
         | 
| 36 | 
            +
                "total_commits_count": 4
         | 
| 37 | 
            +
            }
         | 
| @@ -0,0 +1,132 @@ | |
| 1 | 
            +
            require 'spec_helper'
         | 
| 2 | 
            +
             | 
| 3 | 
            +
            describe Lita::Handlers::Gitlab, lita_handler: true do
         | 
| 4 | 
            +
             | 
| 5 | 
            +
              http_route_path = '/lita/gitlab'
         | 
| 6 | 
            +
             | 
| 7 | 
            +
              it 'registers with Lita' do
         | 
| 8 | 
            +
                expect(Lita.handlers).to include(described_class)
         | 
| 9 | 
            +
              end
         | 
| 10 | 
            +
             | 
| 11 | 
            +
              it "registers HTTP route POST #{http_route_path} to :receive" do
         | 
| 12 | 
            +
                routes_http(:post, http_route_path).to(:receive)
         | 
| 13 | 
            +
              end
         | 
| 14 | 
            +
             | 
| 15 | 
            +
              let(:request) do
         | 
| 16 | 
            +
                request = double('Rack::Request')
         | 
| 17 | 
            +
                allow(request).to receive(:params).and_return(params)
         | 
| 18 | 
            +
                request
         | 
| 19 | 
            +
              end
         | 
| 20 | 
            +
              let(:response) { Rack::Response.new }
         | 
| 21 | 
            +
              let(:params) { {} }
         | 
| 22 | 
            +
              let(:targets) { '#baz' }
         | 
| 23 | 
            +
              let(:matchers) {
         | 
| 24 | 
            +
                {
         | 
| 25 | 
            +
                  new_team_member: 'join',
         | 
| 26 | 
            +
                  project_created: 'created',
         | 
| 27 | 
            +
                  project_destroyed: 'destroyed',
         | 
| 28 | 
            +
                }
         | 
| 29 | 
            +
              }
         | 
| 30 | 
            +
             | 
| 31 | 
            +
              describe '#receive' do
         | 
| 32 | 
            +
                before :each do
         | 
| 33 | 
            +
                  allow(params).to receive(:[]).with('targets').and_return(targets)
         | 
| 34 | 
            +
                end
         | 
| 35 | 
            +
             | 
| 36 | 
            +
                context 'with system hook' do
         | 
| 37 | 
            +
             | 
| 38 | 
            +
                  context 'when new team member' do
         | 
| 39 | 
            +
                    let(:new_team_member_payload) { fixture_file('system/new_team_member') }
         | 
| 40 | 
            +
                    before do
         | 
| 41 | 
            +
                      allow(params).to receive(:[]).with('payload').and_return(new_team_member_payload)
         | 
| 42 | 
            +
                    end
         | 
| 43 | 
            +
             | 
| 44 | 
            +
                    it 'notifies to the applicable rooms' do
         | 
| 45 | 
            +
                      expect(robot).to receive(:send_message) do |target, message|
         | 
| 46 | 
            +
                        expect(target.room).to eq('#baz')
         | 
| 47 | 
            +
                        expect(message).to include matchers[:new_team_member]
         | 
| 48 | 
            +
                      end
         | 
| 49 | 
            +
                      subject.receive(request, response)
         | 
| 50 | 
            +
                    end
         | 
| 51 | 
            +
                  end
         | 
| 52 | 
            +
             | 
| 53 | 
            +
                  context 'when project created' do
         | 
| 54 | 
            +
                    let(:project_created_payload) { fixture_file('system/project_created') }
         | 
| 55 | 
            +
                    before do
         | 
| 56 | 
            +
                      allow(params).to receive(:[]).with('payload').and_return(project_created_payload)
         | 
| 57 | 
            +
                    end
         | 
| 58 | 
            +
             | 
| 59 | 
            +
                    it 'notifies to the applicable rooms' do
         | 
| 60 | 
            +
                      expect(robot).to receive(:send_message) do |target, message|
         | 
| 61 | 
            +
                        expect(target.room).to eq('#baz')
         | 
| 62 | 
            +
                        expect(message).to include matchers[:project_created]
         | 
| 63 | 
            +
                      end
         | 
| 64 | 
            +
                      subject.receive(request, response)
         | 
| 65 | 
            +
                    end
         | 
| 66 | 
            +
                  end
         | 
| 67 | 
            +
             | 
| 68 | 
            +
                  context 'when project destroyed' do
         | 
| 69 | 
            +
                    let(:project_destroyed_payload) { fixture_file('system/project_destroyed') }
         | 
| 70 | 
            +
                    before do
         | 
| 71 | 
            +
                      allow(params).to receive(:[]).with('payload').and_return(project_destroyed_payload)
         | 
| 72 | 
            +
                    end
         | 
| 73 | 
            +
             | 
| 74 | 
            +
                    it 'notifies to the applicable rooms' do
         | 
| 75 | 
            +
                      expect(robot).to receive(:send_message) do |target, message|
         | 
| 76 | 
            +
                        expect(target.room).to eq('#baz')
         | 
| 77 | 
            +
                        expect(message).to include matchers[:project_destroyed]
         | 
| 78 | 
            +
                      end
         | 
| 79 | 
            +
                      subject.receive(request, response)
         | 
| 80 | 
            +
                    end
         | 
| 81 | 
            +
                  end
         | 
| 82 | 
            +
                end
         | 
| 83 | 
            +
             | 
| 84 | 
            +
                context 'when web project hook' do
         | 
| 85 | 
            +
             | 
| 86 | 
            +
                  context 'when issue event' do
         | 
| 87 | 
            +
                    let(:issue_payload) { fixture_file('web/issue') }
         | 
| 88 | 
            +
                    before do
         | 
| 89 | 
            +
                      allow(params).to receive(:[]).with('payload').and_return(issue_payload)
         | 
| 90 | 
            +
                    end
         | 
| 91 | 
            +
             | 
| 92 | 
            +
                    it 'notifies to the applicable rooms' do
         | 
| 93 | 
            +
                      expect(robot).to receive(:send_message) do |target, message|
         | 
| 94 | 
            +
                        expect(target.room).to eq('#baz')
         | 
| 95 | 
            +
                        expect(message).to include 'New issue'
         | 
| 96 | 
            +
                      end
         | 
| 97 | 
            +
                      subject.receive(request, response)
         | 
| 98 | 
            +
                    end
         | 
| 99 | 
            +
                  end
         | 
| 100 | 
            +
             | 
| 101 | 
            +
                  context 'when push event' do
         | 
| 102 | 
            +
                    let(:push_payload) { fixture_file('web/push') }
         | 
| 103 | 
            +
                    before do
         | 
| 104 | 
            +
                      allow(params).to receive(:[]).with('payload').and_return(push_payload)
         | 
| 105 | 
            +
                    end
         | 
| 106 | 
            +
             | 
| 107 | 
            +
                    it 'notifies to the applicable rooms' do
         | 
| 108 | 
            +
                      expect(robot).to receive(:send_message) do |target, message|
         | 
| 109 | 
            +
                        expect(target.room).to eq('#baz')
         | 
| 110 | 
            +
                        expect(message).to include 'branch'
         | 
| 111 | 
            +
                      end
         | 
| 112 | 
            +
                      subject.receive(request, response)
         | 
| 113 | 
            +
                    end
         | 
| 114 | 
            +
                  end
         | 
| 115 | 
            +
             | 
| 116 | 
            +
                  context 'when merge request event' do
         | 
| 117 | 
            +
                    let(:merge_request_payload) { fixture_file('web/merge_request') }
         | 
| 118 | 
            +
                    before do
         | 
| 119 | 
            +
                      allow(params).to receive(:[]).with('payload').and_return(merge_request_payload)
         | 
| 120 | 
            +
                    end
         | 
| 121 | 
            +
             | 
| 122 | 
            +
                    it 'notifies to the applicable rooms' do
         | 
| 123 | 
            +
                      expect(robot).to receive(:send_message) do |target, message|
         | 
| 124 | 
            +
                        expect(target.room).to eq('#baz')
         | 
| 125 | 
            +
                        expect(message).to include 'merge'
         | 
| 126 | 
            +
                      end
         | 
| 127 | 
            +
                      subject.receive(request, response)
         | 
| 128 | 
            +
                    end
         | 
| 129 | 
            +
                  end
         | 
| 130 | 
            +
                end
         | 
| 131 | 
            +
              end
         | 
| 132 | 
            +
            end
         | 
    
        data/spec/spec_helper.rb
    ADDED
    
    | @@ -0,0 +1,17 @@ | |
| 1 | 
            +
            require 'simplecov'
         | 
| 2 | 
            +
            require 'coveralls'
         | 
| 3 | 
            +
            require 'lita-gitlab'
         | 
| 4 | 
            +
            require 'lita/rspec'
         | 
| 5 | 
            +
             | 
| 6 | 
            +
            SimpleCov.formatter = SimpleCov::Formatter::MultiFormatter[
         | 
| 7 | 
            +
              SimpleCov::Formatter::HTMLFormatter,
         | 
| 8 | 
            +
              Coveralls::SimpleCov::Formatter
         | 
| 9 | 
            +
            ]
         | 
| 10 | 
            +
             | 
| 11 | 
            +
            SimpleCov.start { add_filter '/spec/' }
         | 
| 12 | 
            +
             | 
| 13 | 
            +
            def fixture_file(filename)
         | 
| 14 | 
            +
              return '' if filename == ''
         | 
| 15 | 
            +
              file_path = File.expand_path("#{File.dirname(__FILE__)}/fixtures/#{filename}.json")
         | 
| 16 | 
            +
              File.read(file_path)
         | 
| 17 | 
            +
            end
         | 
    
        metadata
    ADDED
    
    | @@ -0,0 +1,175 @@ | |
| 1 | 
            +
            --- !ruby/object:Gem::Specification
         | 
| 2 | 
            +
            name: lita-gitlab
         | 
| 3 | 
            +
            version: !ruby/object:Gem::Version
         | 
| 4 | 
            +
              version: 1.0.0
         | 
| 5 | 
            +
            platform: ruby
         | 
| 6 | 
            +
            authors:
         | 
| 7 | 
            +
            - Emilio Figueroa
         | 
| 8 | 
            +
            autorequire: 
         | 
| 9 | 
            +
            bindir: bin
         | 
| 10 | 
            +
            cert_chain: []
         | 
| 11 | 
            +
            date: 2014-03-20 00:00:00.000000000 Z
         | 
| 12 | 
            +
            dependencies:
         | 
| 13 | 
            +
            - !ruby/object:Gem::Dependency
         | 
| 14 | 
            +
              name: lita
         | 
| 15 | 
            +
              requirement: !ruby/object:Gem::Requirement
         | 
| 16 | 
            +
                requirements:
         | 
| 17 | 
            +
                - - '>='
         | 
| 18 | 
            +
                  - !ruby/object:Gem::Version
         | 
| 19 | 
            +
                    version: '3.0'
         | 
| 20 | 
            +
              type: :runtime
         | 
| 21 | 
            +
              prerelease: false
         | 
| 22 | 
            +
              version_requirements: !ruby/object:Gem::Requirement
         | 
| 23 | 
            +
                requirements:
         | 
| 24 | 
            +
                - - '>='
         | 
| 25 | 
            +
                  - !ruby/object:Gem::Version
         | 
| 26 | 
            +
                    version: '3.0'
         | 
| 27 | 
            +
            - !ruby/object:Gem::Dependency
         | 
| 28 | 
            +
              name: bundler
         | 
| 29 | 
            +
              requirement: !ruby/object:Gem::Requirement
         | 
| 30 | 
            +
                requirements:
         | 
| 31 | 
            +
                - - ~>
         | 
| 32 | 
            +
                  - !ruby/object:Gem::Version
         | 
| 33 | 
            +
                    version: '1.3'
         | 
| 34 | 
            +
              type: :development
         | 
| 35 | 
            +
              prerelease: false
         | 
| 36 | 
            +
              version_requirements: !ruby/object:Gem::Requirement
         | 
| 37 | 
            +
                requirements:
         | 
| 38 | 
            +
                - - ~>
         | 
| 39 | 
            +
                  - !ruby/object:Gem::Version
         | 
| 40 | 
            +
                    version: '1.3'
         | 
| 41 | 
            +
            - !ruby/object:Gem::Dependency
         | 
| 42 | 
            +
              name: rake
         | 
| 43 | 
            +
              requirement: !ruby/object:Gem::Requirement
         | 
| 44 | 
            +
                requirements:
         | 
| 45 | 
            +
                - - '>='
         | 
| 46 | 
            +
                  - !ruby/object:Gem::Version
         | 
| 47 | 
            +
                    version: '0'
         | 
| 48 | 
            +
              type: :development
         | 
| 49 | 
            +
              prerelease: false
         | 
| 50 | 
            +
              version_requirements: !ruby/object:Gem::Requirement
         | 
| 51 | 
            +
                requirements:
         | 
| 52 | 
            +
                - - '>='
         | 
| 53 | 
            +
                  - !ruby/object:Gem::Version
         | 
| 54 | 
            +
                    version: '0'
         | 
| 55 | 
            +
            - !ruby/object:Gem::Dependency
         | 
| 56 | 
            +
              name: rspec
         | 
| 57 | 
            +
              requirement: !ruby/object:Gem::Requirement
         | 
| 58 | 
            +
                requirements:
         | 
| 59 | 
            +
                - - '>='
         | 
| 60 | 
            +
                  - !ruby/object:Gem::Version
         | 
| 61 | 
            +
                    version: 3.0.0.beta2
         | 
| 62 | 
            +
              type: :development
         | 
| 63 | 
            +
              prerelease: false
         | 
| 64 | 
            +
              version_requirements: !ruby/object:Gem::Requirement
         | 
| 65 | 
            +
                requirements:
         | 
| 66 | 
            +
                - - '>='
         | 
| 67 | 
            +
                  - !ruby/object:Gem::Version
         | 
| 68 | 
            +
                    version: 3.0.0.beta2
         | 
| 69 | 
            +
            - !ruby/object:Gem::Dependency
         | 
| 70 | 
            +
              name: shoulda
         | 
| 71 | 
            +
              requirement: !ruby/object:Gem::Requirement
         | 
| 72 | 
            +
                requirements:
         | 
| 73 | 
            +
                - - '>='
         | 
| 74 | 
            +
                  - !ruby/object:Gem::Version
         | 
| 75 | 
            +
                    version: 3.5.0
         | 
| 76 | 
            +
              type: :development
         | 
| 77 | 
            +
              prerelease: false
         | 
| 78 | 
            +
              version_requirements: !ruby/object:Gem::Requirement
         | 
| 79 | 
            +
                requirements:
         | 
| 80 | 
            +
                - - '>='
         | 
| 81 | 
            +
                  - !ruby/object:Gem::Version
         | 
| 82 | 
            +
                    version: 3.5.0
         | 
| 83 | 
            +
            - !ruby/object:Gem::Dependency
         | 
| 84 | 
            +
              name: simplecov
         | 
| 85 | 
            +
              requirement: !ruby/object:Gem::Requirement
         | 
| 86 | 
            +
                requirements:
         | 
| 87 | 
            +
                - - '>='
         | 
| 88 | 
            +
                  - !ruby/object:Gem::Version
         | 
| 89 | 
            +
                    version: '0'
         | 
| 90 | 
            +
              type: :development
         | 
| 91 | 
            +
              prerelease: false
         | 
| 92 | 
            +
              version_requirements: !ruby/object:Gem::Requirement
         | 
| 93 | 
            +
                requirements:
         | 
| 94 | 
            +
                - - '>='
         | 
| 95 | 
            +
                  - !ruby/object:Gem::Version
         | 
| 96 | 
            +
                    version: '0'
         | 
| 97 | 
            +
            - !ruby/object:Gem::Dependency
         | 
| 98 | 
            +
              name: coveralls
         | 
| 99 | 
            +
              requirement: !ruby/object:Gem::Requirement
         | 
| 100 | 
            +
                requirements:
         | 
| 101 | 
            +
                - - '>='
         | 
| 102 | 
            +
                  - !ruby/object:Gem::Version
         | 
| 103 | 
            +
                    version: '0'
         | 
| 104 | 
            +
              type: :development
         | 
| 105 | 
            +
              prerelease: false
         | 
| 106 | 
            +
              version_requirements: !ruby/object:Gem::Requirement
         | 
| 107 | 
            +
                requirements:
         | 
| 108 | 
            +
                - - '>='
         | 
| 109 | 
            +
                  - !ruby/object:Gem::Version
         | 
| 110 | 
            +
                    version: '0'
         | 
| 111 | 
            +
            description: A Lita handler that will display GitLab messages in the channel
         | 
| 112 | 
            +
            email:
         | 
| 113 | 
            +
            - emiliofigueroatorres@gmail.com
         | 
| 114 | 
            +
            executables: []
         | 
| 115 | 
            +
            extensions: []
         | 
| 116 | 
            +
            extra_rdoc_files: []
         | 
| 117 | 
            +
            files:
         | 
| 118 | 
            +
            - .gitignore
         | 
| 119 | 
            +
            - .travis.yml
         | 
| 120 | 
            +
            - Gemfile
         | 
| 121 | 
            +
            - LICENSE
         | 
| 122 | 
            +
            - README.md
         | 
| 123 | 
            +
            - Rakefile
         | 
| 124 | 
            +
            - lib/lita-gitlab.rb
         | 
| 125 | 
            +
            - lib/lita/handlers/gitlab.rb
         | 
| 126 | 
            +
            - lita-gitlab.gemspec
         | 
| 127 | 
            +
            - locales/en.yml
         | 
| 128 | 
            +
            - spec/fixtures/system/new_team_member.json
         | 
| 129 | 
            +
            - spec/fixtures/system/project_created.json
         | 
| 130 | 
            +
            - spec/fixtures/system/project_destroyed.json
         | 
| 131 | 
            +
            - spec/fixtures/system/team_member_removed.json
         | 
| 132 | 
            +
            - spec/fixtures/system/user_created.json
         | 
| 133 | 
            +
            - spec/fixtures/system/user_removed.json
         | 
| 134 | 
            +
            - spec/fixtures/web/issue.json
         | 
| 135 | 
            +
            - spec/fixtures/web/merge_request.json
         | 
| 136 | 
            +
            - spec/fixtures/web/push.json
         | 
| 137 | 
            +
            - spec/lita/handlers/gitlab_spec.rb
         | 
| 138 | 
            +
            - spec/spec_helper.rb
         | 
| 139 | 
            +
            homepage: https://github.com/milo-ft/lita-gitlab
         | 
| 140 | 
            +
            licenses:
         | 
| 141 | 
            +
            - MIT
         | 
| 142 | 
            +
            metadata:
         | 
| 143 | 
            +
              lita_plugin_type: handler
         | 
| 144 | 
            +
            post_install_message: 
         | 
| 145 | 
            +
            rdoc_options: []
         | 
| 146 | 
            +
            require_paths:
         | 
| 147 | 
            +
            - lib
         | 
| 148 | 
            +
            required_ruby_version: !ruby/object:Gem::Requirement
         | 
| 149 | 
            +
              requirements:
         | 
| 150 | 
            +
              - - '>='
         | 
| 151 | 
            +
                - !ruby/object:Gem::Version
         | 
| 152 | 
            +
                  version: '0'
         | 
| 153 | 
            +
            required_rubygems_version: !ruby/object:Gem::Requirement
         | 
| 154 | 
            +
              requirements:
         | 
| 155 | 
            +
              - - '>='
         | 
| 156 | 
            +
                - !ruby/object:Gem::Version
         | 
| 157 | 
            +
                  version: '0'
         | 
| 158 | 
            +
            requirements: []
         | 
| 159 | 
            +
            rubyforge_project: 
         | 
| 160 | 
            +
            rubygems_version: 2.2.2
         | 
| 161 | 
            +
            signing_key: 
         | 
| 162 | 
            +
            specification_version: 4
         | 
| 163 | 
            +
            summary: A Lita handler that will display GitLab messages in the channel
         | 
| 164 | 
            +
            test_files:
         | 
| 165 | 
            +
            - spec/fixtures/system/new_team_member.json
         | 
| 166 | 
            +
            - spec/fixtures/system/project_created.json
         | 
| 167 | 
            +
            - spec/fixtures/system/project_destroyed.json
         | 
| 168 | 
            +
            - spec/fixtures/system/team_member_removed.json
         | 
| 169 | 
            +
            - spec/fixtures/system/user_created.json
         | 
| 170 | 
            +
            - spec/fixtures/system/user_removed.json
         | 
| 171 | 
            +
            - spec/fixtures/web/issue.json
         | 
| 172 | 
            +
            - spec/fixtures/web/merge_request.json
         | 
| 173 | 
            +
            - spec/fixtures/web/push.json
         | 
| 174 | 
            +
            - spec/lita/handlers/gitlab_spec.rb
         | 
| 175 | 
            +
            - spec/spec_helper.rb
         |