Class: ProjectsController
Instance Method Summary
collapse
#after_sign_in_path_for, #api_authenticate!, #current_project, #expire_revision!, #followed_projects, #no_cache, #read_revision, #require_login, #return_or_cache_revision!, #revision, #save_current_project, #set_current_project, #unfurling?
Methods included from UrlHelper
#feature_path, #github_commit_range_url, #github_commit_url, #github_project_url, #github_url?, #goldmine_case_number_url, #link_to_project_feature, #new_release_url, #releases_path
Instance Method Details
#create ⇒ Object
84
85
86
87
88
89
90
91
92
93
|
# File 'app/controllers/projects_controller.rb', line 84
def create
@project = Project.new(project_attributes)
if @project.save
redirect_to projects_path, notice: 'Project was successfully created.'
else
flash.now[:error] = @project.errors[:base].join("\n")
render action: "new"
end
end
|
#create_from_github ⇒ Object
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
|
# File 'app/controllers/projects_controller.rb', line 51
def create_from_github
authorize! :create, Project
repos = params.fetch(:repos, [])
projects = Project.transaction do
repos.map do |repo|
owner, name = repo.split("/")
title = name.humanize.gsub(/\b(?<!['’.`])[a-z]/) { $&.capitalize }.gsub("-", "::")
Project.create!(
name: title,
slug: name,
version_control_name: "Git",
extended_attributes: {"git_location" => "[email protected]:#{repo}.git"})
end
end
flash[:notice] = "#{projects.count} projects added"
redirect_to projects_path
rescue ActiveRecord::RecordInvalid
flash[:error] = $!.message
redirect_to :back
end
|
#destroy ⇒ Object
115
116
117
118
119
120
|
# File 'app/controllers/projects_controller.rb', line 115
def destroy
@project = Project.find_by_slug!(params[:id])
@project.destroy
redirect_to projects_url
end
|
#edit ⇒ Object
76
77
78
79
80
81
|
# File 'app/controllers/projects_controller.rb', line 76
def edit
@project = Project.find_by_slug!(params[:id])
@project.roles.build(user: current_user) if @project.roles.none?
@title = "Edit #{@project.name}"
end
|
#index ⇒ Object
7
8
9
10
11
12
13
14
15
16
|
# File 'app/controllers/projects_controller.rb', line 7
def index
@title = "Projects"
@projects = Project \
.includes(:owners)
.includes(:maintainers)
.includes(:head)
.unretired
@test_runs = TestRun.most_recent.index_by(&:project_id)
@releases = Release.where(environment_name: "production").most_recent.index_by(&:project_id)
end
|
#new ⇒ Object
24
25
26
27
28
29
|
# File 'app/controllers/projects_controller.rb', line 24
def new
@title = "New Project"
@project = Project.new
@project.roles.build(user: current_user) if @project.roles.none?
end
|
#new_from_github ⇒ Object
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
|
# File 'app/controllers/projects_controller.rb', line 31
def new_from_github
authorize! :create, Project
existing_projects = Project.unscoped.where("extended_attributes->'git_location' LIKE '%github.com%'")
github_repos = Houston.benchmark "Fetching repos" do
Houston.github.repos
end
@repos = github_repos.map do |repo|
project = existing_projects.detect { |project|
[repo.git_url, repo.ssh_url, repo.clone_url].member?(project.extended_attributes["git_location"]) }
{ name: repo.name,
owner: repo.owner.login,
full_name: repo.full_name,
private: repo[:private],
git_location: repo.ssh_url,
project: project }
end
end
|
#retire ⇒ Object
108
109
110
111
112
|
# File 'app/controllers/projects_controller.rb', line 108
def retire
@project = Project.find_by_slug!(params[:id])
@project.retire!
redirect_to projects_path, notice: "#{@project.name} was successfully retired."
end
|
#show ⇒ Object
19
20
21
|
# File 'app/controllers/projects_controller.rb', line 19
def show
redirect_to projects_path
end
|
#update ⇒ Object
96
97
98
99
100
101
102
103
104
105
|
# File 'app/controllers/projects_controller.rb', line 96
def update
@project = Project.find_by_slug!(params[:id])
if @project.update_attributes(project_attributes)
redirect_to projects_path, notice: 'Project was successfully updated.'
else
flash.now[:error] = @project.errors[:base].join("\n")
render action: "edit"
end
end
|