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
end
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)
end
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)
Event.create_rm_ref(@project, current_user, branch)
if branch && @repository.rm_branch(branch.name)
Event.create_ref_event(@project, current_user, branch, 'rm')
end
respond_to do |format|
......
......@@ -8,20 +8,24 @@ class Projects::TagsController < Projects::ApplicationController
before_filter :authorize_admin_project!, only: [:destroy]
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
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)
end
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)
Event.create_rm_ref(@project, current_user, tag, 'refs/tags')
if tag && @repository.rm_tag(tag.name)
Event.create_ref_event(@project, current_user, tag, 'rm', 'refs/tags')
end
respond_to do |format|
......
......@@ -55,14 +55,22 @@ class Event < ActiveRecord::Base
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(
project: project,
action: Event::PUSHED,
data: {
ref: "#{prefix}/#{ref.name}",
before: ref.commit.id,
after: '00000000'
before: before,
after: after
},
author_id: user.id
)
......
......@@ -35,6 +35,14 @@ class Repository
commits
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)
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