Commit 8587e3a3 authored by Dmitriy Zaporozhets's avatar Dmitriy Zaporozhets

create corresponding events when create branch/tag with UI

parent 2a37db4c
...@@ -12,16 +12,20 @@ class Projects::BranchesController < Projects::ApplicationController ...@@ -12,16 +12,20 @@ class Projects::BranchesController < Projects::ApplicationController
end end
def create def create
@project.repository.add_branch(params[:branch_name], params[:ref]) @repository.add_branch(params[:branch_name], params[:ref])
if new_branch = @repository.find_branch(params[:branch_name])
Event.create_ref_event(@project, current_user, new_branch, 'add')
end
redirect_to project_branches_path(@project) redirect_to project_branches_path(@project)
end end
def destroy def destroy
branch = @project.repository.branches.find { |branch| branch.name == params[:id] } branch = @repository.find_branch(params[:id])
if branch && @project.repository.rm_branch(branch.name) if branch && @repository.rm_branch(branch.name)
Event.create_rm_ref(@project, current_user, branch) Event.create_ref_event(@project, current_user, branch, 'rm')
end end
respond_to do |format| respond_to do |format|
......
...@@ -8,20 +8,24 @@ class Projects::TagsController < Projects::ApplicationController ...@@ -8,20 +8,24 @@ class Projects::TagsController < Projects::ApplicationController
before_filter :authorize_admin_project!, only: [:destroy] before_filter :authorize_admin_project!, only: [:destroy]
def index def index
@tags = Kaminari.paginate_array(@project.repository.tags).page(params[:page]).per(30) @tags = Kaminari.paginate_array(@repository.tags).page(params[:page]).per(30)
end end
def create def create
@project.repository.add_tag(params[:tag_name], params[:ref]) @repository.add_tag(params[:tag_name], params[:ref])
if new_tag = @repository.find_tag(params[:tag_name])
Event.create_ref_event(@project, current_user, new_tag, 'add', 'refs/tags')
end
redirect_to project_tags_path(@project) redirect_to project_tags_path(@project)
end end
def destroy def destroy
tag = @project.repository.tags.find { |tag| tag.name == params[:id] } tag = @repository.find_tag(params[:id])
if tag && @project.repository.rm_tag(tag.name) if tag && @repository.rm_tag(tag.name)
Event.create_rm_ref(@project, current_user, tag, 'refs/tags') Event.create_ref_event(@project, current_user, tag, 'rm', 'refs/tags')
end end
respond_to do |format| respond_to do |format|
......
...@@ -55,14 +55,22 @@ class Event < ActiveRecord::Base ...@@ -55,14 +55,22 @@ class Event < ActiveRecord::Base
end end
end end
def create_rm_ref(project, user, ref, prefix = 'refs/heads') def create_ref_event(project, user, ref, action = 'add', prefix = 'refs/heads')
if action.to_s == 'add'
before = '00000000'
after = ref.commit.id
else
before = ref.commit.id
after = '00000000'
end
Event.create( Event.create(
project: project, project: project,
action: Event::PUSHED, action: Event::PUSHED,
data: { data: {
ref: "#{prefix}/#{ref.name}", ref: "#{prefix}/#{ref.name}",
before: ref.commit.id, before: before,
after: '00000000' after: after
}, },
author_id: user.id author_id: user.id
) )
......
...@@ -35,6 +35,14 @@ class Repository ...@@ -35,6 +35,14 @@ class Repository
commits commits
end end
def find_branch(name)
branches.find { |branch| branch.name == name }
end
def find_tag(name)
tags.find { |tag| tag.name == name }
end
def add_branch(branch_name, ref) def add_branch(branch_name, ref)
Rails.cache.delete(cache_key(:branch_names)) Rails.cache.delete(cache_key(:branch_names))
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment