require 'universal-git-client/normalizers/base' module UniversalGitClient module Normalizers class Bitbucket < Base def first_page_index '1' end def prev_page_index get_page_index('previous') end def next_page_index get_page_index('next') end def last_page_index nil end def per_page_index response.request.options[:query][:pagelen].to_s rescue StandardError nil end private def get_page_index(rel) Hash[ URI::decode_www_form( URI.parse(response[rel]).query ) ]['page'] rescue StandardError nil end class UserSerializer < BaseSerializer set_id :account_id attribute :login, &:username attribute :name, &:display_name attribute :avatar_url do |object| object.links.avatar.href end end class OrganizationSerializer < BaseSerializer set_id :uuid attribute :login, &:username attribute :avatar_url do |object| object.links.avatar.href end end class RepositorySerializer < BaseSerializer set_id :uuid attributes :name, :full_name attribute :full_path, &:full_name attribute :private, &:is_private attribute :archived, &:is_archived attribute :default_branch do |object| object.mainbranch&.name end end class BranchSerializer < BaseSerializer set_id :name attributes :name, :protected attribute :commit do |object| object.target.to_h[:hash] end end class WebhookSerializer < BaseSerializer set_id :uuid attributes :url, :active attribute :events do |object| events = [] events << 'push' if object.events.include?('repo:push') end attribute :type do |object| object.subject.type.capitalize end end end end end