Skip to content
Snippets Groups Projects
Select Git revision
  • move-gl-dropdown
  • improve-table-pagination-spec
  • move-markdown-preview
  • winh-fix-merge-request-spec
  • master default
  • index-namespaces-lower-name
  • winh-single-karma-test
  • 10-3-stable
  • 36782-replace-team-user-role-with-add_role-user-in-specs
  • winh-modal-internal-state
  • tz-ide-file-icons
  • 38869-milestone-select
  • update-autodevops-template
  • jivl-activate-repo-cookie-preferences
  • qa-add-deploy-key
  • docs-move-article-ldap
  • 40780-choose-file
  • 22643-manual-job-page
  • refactor-cluster-show-page-conservative
  • dm-sidekiq-versioning
  • v10.4.0.pre
  • v10.3.0
  • v10.3.0-rc5
  • v10.3.0-rc4
  • v10.3.0-rc3
  • v10.3.0-rc2
  • v10.2.5
  • v10.3.0-rc1
  • v10.0.7
  • v10.1.5
  • v10.2.4
  • v10.2.3
  • v10.2.2
  • v10.2.1
  • v10.3.0.pre
  • v10.2.0
  • v10.2.0-rc4
  • v10.2.0-rc3
  • v10.1.4
  • v10.2.0-rc2
40 results

note_data_builder.rb

Forked from GitLab.org / GitLab FOSS
27403 commits behind the upstream repository.
  • Kirill Zaitsev's avatar
    b123171d
    Add new data to project in push, issue, merge-request and note webhooks data · b123171d
    Kirill Zaitsev authored
    - Add `avatar_url`, `description`, `git_ssh_url`, `git_http_url`,
      `path_with_namespace` and `default_branch` in `project` in push, issue,
      merge-request and note webhooks data
    - Deprecate the `ssh_url` in favor of `git_ssh_url` and `http_url` in
      favor of `git_http_url` in `project` for push, issue, merge-request and
      note webhooks data
    - Deprecate the `repository` key in push, issue, merge-request and
      note webhooks data, use `project` instead
    b123171d
    History
    Add new data to project in push, issue, merge-request and note webhooks data
    Kirill Zaitsev authored
    - Add `avatar_url`, `description`, `git_ssh_url`, `git_http_url`,
      `path_with_namespace` and `default_branch` in `project` in push, issue,
      merge-request and note webhooks data
    - Deprecate the `ssh_url` in favor of `git_ssh_url` and `http_url` in
      favor of `git_http_url` in `project` for push, issue, merge-request and
      note webhooks data
    - Deprecate the `repository` key in push, issue, merge-request and
      note webhooks data, use `project` instead
note_data_builder.rb 1.97 KiB
module Gitlab
  class NoteDataBuilder
    class << self
      # Produce a hash of post-receive data
      #
      # For all notes:
      #
      # data = {
      #   object_kind: "note",
      #   user: {
      #     name: String,
      #     username: String,
      #     avatar_url: String
      #   }
      #   project_id: Integer,
      #   repository: {
      #     name: String,
      #     url: String,
      #     description: String,
      #     homepage: String,
      #   }
      #  object_attributes: {
      #    <hook data for note>
      #  }
      #  <note-specific data>: {
      # }
      # note-specific data is a hash with one of the following keys and contains
      # the hook data for that type.
      #  - commit
      #  - issue
      #  - merge_request
      #  - snippet
      #
      def build(note, user)
        project = note.project
        data = build_base_data(project, user, note)

        if note.for_commit?
          data[:commit] = build_data_for_commit(project, user, note)
        elsif note.for_issue?
          data[:issue] = note.noteable.hook_attrs
        elsif note.for_merge_request?
          data[:merge_request] = note.noteable.hook_attrs
        elsif note.for_project_snippet?
          data[:snippet] = note.noteable.hook_attrs
        end

        data
      end

      def build_base_data(project, user, note)
        base_data = {
          object_kind: "note",
          user: user.hook_attrs,
          project_id: project.id,
          project: project.hook_attrs,
          object_attributes: note.hook_attrs,
          # DEPRECATED
          repository: project.hook_attrs.slice(:name, :url, :description, :homepage)
        }

        base_data[:object_attributes][:url] =
             Gitlab::UrlBuilder.new(:note).build(note.id)
        base_data
      end

      def build_data_for_commit(project, user, note)
        # commit_id is the SHA hash
        commit = project.commit(note.commit_id)
        commit.hook_attrs
      end
    end
  end
end