From a165a0b23fd6cc81e7fc0163827310f69ce0399a Mon Sep 17 00:00:00 2001 From: Dmitriy Zaporozhets Date: Tue, 16 Jul 2013 22:43:14 +0300 Subject: [PATCH] Create event on dashboard when branch removed via UI --- app/controllers/projects/branches_controller.rb | 6 +++++- app/models/event.rb | 13 +++++++++++++ 2 files changed, 18 insertions(+), 1 deletion(-) diff --git a/app/controllers/projects/branches_controller.rb b/app/controllers/projects/branches_controller.rb index 5168d4d..0703962 100644 --- a/app/controllers/projects/branches_controller.rb +++ b/app/controllers/projects/branches_controller.rb @@ -14,7 +14,11 @@ class Projects::BranchesController < Projects::ApplicationController end def destroy - @project.repository.rm_branch(params[:id]) + branch = @project.repository.branches.find { |branch| branch.name == params[:id] } + + if branch && @project.repository.rm_branch(branch.name) + Event.create_rm_branch(@project, current_user, branch) + end respond_to do |format| format.html { redirect_to project_branches_path } diff --git a/app/models/event.rb b/app/models/event.rb index a6b5167..50c87f8 100644 --- a/app/models/event.rb +++ b/app/models/event.rb @@ -54,6 +54,19 @@ class Event < ActiveRecord::Base Event::COMMENTED end end + + def create_rm_branch(project, user, branch) + Event.create( + project: project, + action: Event::PUSHED, + data: { + ref: branch.name, + before: branch.commit.id, + after: '00000000' + }, + author_id: user.id + ) + end end def proper? -- libgit2 0.21.2