project_observer.rb 1.16 KB
Newer Older
1
class ProjectObserver < BaseObserver
2
  def after_create(project)
3
4
5
6
7
8
9
10
11
12
13
14
    return true if project.forked?

    if project.import?
      RepositoryImportWorker.perform_in(5.seconds, project.id)
    else
      GitlabShellWorker.perform_async(
        :add_repository,
        project.path_with_namespace
      )

      log_info("#{project.owner.name} created a new project \"#{project.name_with_namespace}\"")
    end
15
16
  end

17
18
  def after_update(project)
    project.send_move_instructions if project.namespace_id_changed?
Dmitriy Zaporozhets's avatar
Dmitriy Zaporozhets committed
19
    project.rename_repo if project.path_changed?
20
21
22
23
24
25

    GitlabShellWorker.perform_async(
      :update_repository_head,
      project.path_with_namespace,
      project.default_branch
    ) if project.default_branch_changed?
26
27
  end

28
29
30
31
  def before_destroy(project)
    project.repository.expire_cache unless project.empty_repo?
  end

32
  def after_destroy(project)
33
    GitlabShellWorker.perform_async(
34
      :remove_repository,
35
      project.path_with_namespace
36
    )
randx's avatar
randx committed
37

38
39
40
41
42
    GitlabShellWorker.perform_async(
      :remove_repository,
      project.path_with_namespace + ".wiki"
    )

43
    project.satellite.destroy
randx's avatar
randx committed
44

45
    log_info("Project \"#{project.name}\" was removed")
randx's avatar
randx committed
46
  end
47
end