jbox-web/redmine_git_hosting

View on GitHub
lib/redmine_git_hosting/patches/watchers_controller_patch.rb

Summary

Maintainability
A
0 mins
Test Coverage
# frozen_string_literal: true

require_dependency 'watchers_controller'

module RedmineGitHosting
  module Patches
    module WatchersControllerPatch
      include RedmineGitHosting::GitoliteAccessor::Methods

      def create
        super
        update_repository @watched
      end

      def destroy
        super
        update_repository @watched
      end

      def watch
        super
        update_repository @watchables.first
      end

      def unwatch
        super
        update_repository @watchables.first
      end

      private

      def update_repository(repo)
        return unless repo.is_a? Repository::Xitolite

        options = { message: "Watcher changes on repository '#{repo}', update!" }
        gitolite_accessor.update_repository repo, **options
      end
    end
  end
end

unless WatchersController.included_modules.include? RedmineGitHosting::Patches::WatchersControllerPatch
  WatchersController.prepend RedmineGitHosting::Patches::WatchersControllerPatch
end