forked from gitlabhq/gitlab-ci
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathprojects_controller.rb
136 lines (107 loc) · 3.08 KB
/
projects_controller.rb
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
class ProjectsController < ApplicationController
before_filter :authenticate_user!, except: [:build, :status, :index, :show]
before_filter :project, only: [:build, :details, :show, :status, :edit, :update, :destroy, :stats]
before_filter :authenticate_token!, only: [:build]
before_filter :no_cache, only: [:status]
def index
@projects = Project.order('name ASC')
@projects = @projects.public unless current_user
@projects = @projects.page(params[:page]).per(20)
end
def show
unless @project.public || current_user
authenticate_user! and return
end
@ref = params[:ref]
@builds = @project.builds
@builds = @builds.where(ref: @ref) if @ref
@builds = @builds.order('id DESC').page(params[:page]).per(20)
end
def details
end
def new
@project = Project.new
end
def edit
end
def create
@project = Project.new(params[:project])
if @project.save
redirect_to @project, notice: 'Project was successfully created.'
else
render action: "new"
end
end
def update
if project.update_attributes(params[:project])
redirect_to project, notice: 'Project was successfully updated.'
else
render action: "edit"
end
end
def destroy
project.destroy
redirect_to projects_url
end
def build
# Ignore remove branch push
return head(200) if params[:after] =~ /^00000000/
# Support payload (like github) push
build_params = if params[:payload]
HashWithIndifferentAccess.new(JSON.parse(params[:payload]))
else
params
end.dup
@build = @project.register_build(build_params)
if @build
head 200
else
head 500
end
rescue
head 500
end
# Project status badge
# Image with build status for sha or ref
def status
image_name = if params[:sha]
@project.sha_status_image(params[:sha])
elsif params[:ref]
@project.status_image(params[:ref])
else
'unknown.png'
end
send_file Rails.root.join('public', image_name), filename: image_name, disposition: 'inline'
end
def stats
end
def gitlab
@projects = Project.from_gitlab(current_user)
end
def add
project = YAML.load(params[:project])
params = {
name: project.name_with_namespace,
gitlab_id: project.id,
gitlab_url: project.web_url,
scripts: 'ls -la',
default_ref: project.default_branch,
ssh_url_to_repo: project.ssh_url_to_repo
}
@project = Project.new(params)
if @project.save
redirect_to project_path(@project, show_guide: true), notice: 'Project was successfully created.'
else
redirect_to :back, alert: 'Cannot save project'
end
end
protected
def project
@project ||= Project.find(params[:id])
end
def no_cache
response.headers["Cache-Control"] = "no-cache, no-store, max-age=0, must-revalidate"
response.headers["Pragma"] = "no-cache"
response.headers["Expires"] = "Fri, 01 Jan 1990 00:00:00 GMT"
end
end