Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
G
gitlab-ce
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
0
Merge Requests
0
Analytics
Analytics
Repository
Value Stream
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Commits
Issue Boards
Open sidebar
Boxiang Sun
gitlab-ce
Commits
2ed2ef92
Commit
2ed2ef92
authored
Sep 11, 2015
by
Dmitriy Zaporozhets
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Remove network from CI
parent
187face6
Changes
8
Show whitespace changes
Inline
Side-by-side
Showing
8 changed files
with
12 additions
and
215 deletions
+12
-215
app/controllers/ci/application_controller.rb
app/controllers/ci/application_controller.rb
+0
-27
app/controllers/ci/projects_controller.rb
app/controllers/ci/projects_controller.rb
+2
-4
app/models/ci/network.rb
app/models/ci/network.rb
+0
-122
app/models/ci/project.rb
app/models/ci/project.rb
+4
-2
app/services/ci/create_project_service.rb
app/services/ci/create_project_service.rb
+3
-3
lib/api/services.rb
lib/api/services.rb
+2
-2
lib/ci/api/projects.rb
lib/ci/api/projects.rb
+1
-1
spec/models/ci/network_spec.rb
spec/models/ci/network_spec.rb
+0
-54
No files found.
app/controllers/ci/application_controller.rb
View file @
2ed2ef92
...
...
@@ -4,14 +4,8 @@ module Ci
"app/helpers/ci"
end
include
Ci
::
UserSessionsHelper
rescue_from
Ci
::
Network
::
UnauthorizedError
,
with: :invalid_token
before_filter
:default_headers
helper_method
:gl_project
protect_from_forgery
private
def
authenticate_public_page!
...
...
@@ -75,27 +69,6 @@ module Ci
}
end
def
check_config
redirect_to
oauth2_ci_help_path
unless
valid_config?
end
def
valid_config?
server
=
GitlabCi
.
config
.
gitlab_server
if
server
.
blank?
||
server
.
url
.
blank?
||
server
.
app_id
.
blank?
||
server
.
app_secret
.
blank?
false
else
true
end
rescue
Settingslogic
::
MissingSetting
,
NoMethodError
false
end
def
invalid_token
reset_session
redirect_to
ci_root_path
end
def
gl_project
::
Project
.
find
(
@project
.
gitlab_id
)
end
...
...
app/controllers/ci/projects_controller.rb
View file @
2ed2ef92
...
...
@@ -35,8 +35,6 @@ module Ci
pager_json
(
"ci/projects/gitlab"
,
@total_count
)
end
end
rescue
Ci
::
Network
::
UnauthorizedError
raise
rescue
@error
=
'Failed to fetch GitLab projects'
end
...
...
@@ -82,8 +80,8 @@ module Ci
end
def
destroy
project
.
gl_project
.
gitlab_ci_service
.
update_attributes
(
active:
false
)
project
.
destroy
Ci
::
Network
.
new
.
disable_ci
(
project
.
gitlab_id
,
current_user
.
authenticate_options
)
Ci
::
EventService
.
new
.
remove_project
(
current_user
,
project
)
...
...
app/models/ci/network.rb
deleted
100644 → 0
View file @
187face6
module
Ci
class
Network
class
UnauthorizedError
<
StandardError
;
end
include
HTTParty
API_PREFIX
=
'/api/v3/'
def
authenticate
(
api_opts
)
opts
=
{
query:
api_opts
}
endpoint
=
File
.
join
(
url
,
API_PREFIX
,
'user'
)
response
=
self
.
class
.
get
(
endpoint
,
default_opts
.
merge
(
opts
))
build_response
(
response
)
end
def
projects
(
api_opts
,
scope
=
:owned
)
# Dont load archived projects
api_opts
.
merge!
(
archived:
false
)
opts
=
{
query:
api_opts
}
query
=
if
scope
==
:owned
'projects/owned.json'
else
'projects.json'
end
endpoint
=
File
.
join
(
url
,
API_PREFIX
,
query
)
response
=
self
.
class
.
get
(
endpoint
,
default_opts
.
merge
(
opts
))
build_response
(
response
)
end
def
project
(
api_opts
,
project_id
)
opts
=
{
query:
api_opts
}
query
=
"projects/
#{
project_id
}
.json"
endpoint
=
File
.
join
(
url
,
API_PREFIX
,
query
)
response
=
self
.
class
.
get
(
endpoint
,
default_opts
.
merge
(
opts
))
build_response
(
response
)
end
def
project_hooks
(
api_opts
,
project_id
)
opts
=
{
query:
api_opts
}
query
=
"projects/
#{
project_id
}
/hooks.json"
endpoint
=
File
.
join
(
url
,
API_PREFIX
,
query
)
response
=
self
.
class
.
get
(
endpoint
,
default_opts
.
merge
(
opts
))
build_response
(
response
)
end
def
enable_ci
(
project_id
,
data
,
api_opts
)
opts
=
{
body:
data
.
to_json
,
query:
api_opts
}
query
=
"projects/
#{
project_id
}
/services/gitlab-ci.json"
endpoint
=
File
.
join
(
url
,
API_PREFIX
,
query
)
response
=
self
.
class
.
put
(
endpoint
,
default_opts
.
merge
(
opts
))
case
response
.
code
when
200
true
when
401
raise
UnauthorizedError
else
nil
end
end
def
disable_ci
(
project_id
,
api_opts
)
opts
=
{
query:
api_opts
}
query
=
"projects/
#{
project_id
}
/services/gitlab-ci.json"
endpoint
=
File
.
join
(
url
,
API_PREFIX
,
query
)
response
=
self
.
class
.
delete
(
endpoint
,
default_opts
.
merge
(
opts
))
build_response
(
response
)
end
private
def
url
Gitlab
.
config
.
gitlab
.
url
end
def
default_opts
{
headers:
{
"Content-Type"
=>
"application/json"
},
}
end
def
build_response
(
response
)
case
response
.
code
when
200
response
.
parsed_response
when
401
raise
UnauthorizedError
else
nil
end
end
end
end
app/models/ci/project.rb
View file @
2ed2ef92
...
...
@@ -31,7 +31,7 @@ module Ci
include
Ci
::
ProjectStatus
belongs_to
:gl_project
,
class_name:
'Project'
,
foreign_key: :gitlab_id
belongs_to
:gl_project
,
class_name:
'
::
Project'
,
foreign_key: :gitlab_id
has_many
:commits
,
->
()
{
order
(
:committed_at
)
},
dependent: :destroy
,
class_name:
'Ci::Commit'
has_many
:builds
,
through: :commits
,
dependent: :destroy
,
class_name:
'Ci::Build'
...
...
@@ -92,11 +92,13 @@ module Ci
project
end
# TODO: remove
def
from_gitlab
(
user
,
scope
=
:owned
,
options
)
opts
=
user
.
authenticate_options
opts
.
merge!
options
projects
=
Ci
::
Network
.
new
.
projects
(
opts
.
compact
,
scope
)
raise
'Implement me of fix'
#projects = Ci::Network.new.projects(opts.compact, scope)
if
projects
projects
.
map
{
|
pr
|
OpenStruct
.
new
(
pr
)
}
...
...
app/services/ci/create_project_service.rb
View file @
2ed2ef92
...
...
@@ -13,9 +13,9 @@ module Ci
project_url:
project_route
.
gsub
(
":project_id"
,
@project
.
id
.
to_s
),
}
unless
Ci
::
Network
.
new
.
enable_ci
(
@project
.
gitlab_id
,
data
,
{
private_token:
current_user
.
private_token
}
)
raise
ActiveRecord
::
Rollback
end
gl_project
=
::
Project
.
find
(
@project
.
gitlab_id
)
gl_project
.
build_missing_services
gl_project
.
gitlab_ci_service
.
update_attributes
(
data
.
merge
(
active:
true
))
end
if
forked_project
...
...
lib/api/services.rb
View file @
2ed2ef92
lib/ci/api/projects.rb
View file @
2ed2ef92
spec/models/ci/network_spec.rb
deleted
100644 → 0
View file @
187face6
require
'spec_helper'
describe
Network
do
let
(
:network
)
{
Network
.
new
}
describe
:enable_ci
do
subject
{
network
.
enable_ci
''
,
''
,
''
}
context
'on success'
do
before
do
response
=
double
allow
(
response
).
to
receive
(
:code
)
{
200
}
allow
(
network
.
class
).
to
receive
(
:put
)
{
response
}
end
it
{
is_expected
.
to
be_truthy
}
end
context
'on failure'
do
before
do
response
=
double
allow
(
response
).
to
receive
(
:code
)
{
404
}
allow
(
network
.
class
).
to
receive
(
:put
)
{
response
}
end
it
{
is_expected
.
to
be_nil
}
end
end
describe
:disable_ci
do
let
(
:response
)
{
double
}
subject
{
network
.
disable_ci
''
,
''
}
context
'on success'
do
let
(
:parsed_response
)
{
'parsed'
}
before
do
allow
(
response
).
to
receive
(
:code
)
{
200
}
allow
(
response
).
to
receive
(
:parsed_response
)
{
parsed_response
}
allow
(
network
.
class
).
to
receive
(
:delete
)
{
response
}
end
it
{
is_expected
.
to
equal
(
parsed_response
)
}
end
context
'on failure'
do
before
do
allow
(
response
).
to
receive
(
:code
)
{
404
}
allow
(
network
.
class
).
to
receive
(
:delete
)
{
response
}
end
it
{
is_expected
.
to
be_nil
}
end
end
end
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment