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
1
Merge Requests
1
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
nexedi
gitlab-ce
Commits
0eb3d18c
Commit
0eb3d18c
authored
Jun 26, 2017
by
Adam Niedzielski
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Store merge request ref_fetched status in the database
Closes #34052
parent
d4384dc1
Changes
7
Hide whitespace changes
Inline
Side-by-side
Showing
7 changed files
with
63 additions
and
3 deletions
+63
-3
app/models/merge_request.rb
app/models/merge_request.rb
+8
-1
changelogs/unreleased/34052-store-mr-ref-fetched-in-database.yml
...ogs/unreleased/34052-store-mr-ref-fetched-in-database.yml
+4
-0
db/migrate/20170622162730_add_ref_fetched_to_merge_request.rb
...igrate/20170622162730_add_ref_fetched_to_merge_request.rb
+9
-0
db/schema.rb
db/schema.rb
+2
-1
lib/gitlab/import_export/import_export.yml
lib/gitlab/import_export/import_export.yml
+1
-0
spec/lib/gitlab/import_export/fork_spec.rb
spec/lib/gitlab/import_export/fork_spec.rb
+3
-1
spec/models/merge_request_spec.rb
spec/models/merge_request_spec.rb
+36
-0
No files found.
app/models/merge_request.rb
View file @
0eb3d18c
...
@@ -771,6 +771,7 @@ class MergeRequest < ActiveRecord::Base
...
@@ -771,6 +771,7 @@ class MergeRequest < ActiveRecord::Base
"refs/heads/
#{
source_branch
}
"
,
"refs/heads/
#{
source_branch
}
"
,
ref_path
ref_path
)
)
update_column
(
:ref_fetched
,
true
)
end
end
def
ref_path
def
ref_path
...
@@ -778,7 +779,13 @@ class MergeRequest < ActiveRecord::Base
...
@@ -778,7 +779,13 @@ class MergeRequest < ActiveRecord::Base
end
end
def
ref_fetched?
def
ref_fetched?
project
.
repository
.
ref_exists?
(
ref_path
)
super
||
begin
computed_value
=
project
.
repository
.
ref_exists?
(
ref_path
)
update_column
(
:ref_fetched
,
true
)
if
computed_value
computed_value
end
end
end
def
ensure_ref_fetched
def
ensure_ref_fetched
...
...
changelogs/unreleased/34052-store-mr-ref-fetched-in-database.yml
0 → 100644
View file @
0eb3d18c
---
title
:
Store merge request ref_fetched status in the database
merge_request
:
12424
author
:
db/migrate/20170622162730_add_ref_fetched_to_merge_request.rb
0 → 100644
View file @
0eb3d18c
class
AddRefFetchedToMergeRequest
<
ActiveRecord
::
Migration
include
Gitlab
::
Database
::
MigrationHelpers
DOWNTIME
=
false
def
change
add_column
:merge_requests
,
:ref_fetched
,
:boolean
end
end
db/schema.rb
View file @
0eb3d18c
...
@@ -11,7 +11,7 @@
...
@@ -11,7 +11,7 @@
#
#
# It's strongly recommended that you check this file into your version control system.
# It's strongly recommended that you check this file into your version control system.
ActiveRecord
::
Schema
.
define
(
version:
2017062
110240
0
)
do
ActiveRecord
::
Schema
.
define
(
version:
2017062
216273
0
)
do
# These are extensions that must be enabled in order to support this database
# These are extensions that must be enabled in order to support this database
enable_extension
"plpgsql"
enable_extension
"plpgsql"
...
@@ -770,6 +770,7 @@ ActiveRecord::Schema.define(version: 20170621102400) do
...
@@ -770,6 +770,7 @@ ActiveRecord::Schema.define(version: 20170621102400) do
t
.
datetime
"last_edited_at"
t
.
datetime
"last_edited_at"
t
.
integer
"last_edited_by_id"
t
.
integer
"last_edited_by_id"
t
.
integer
"head_pipeline_id"
t
.
integer
"head_pipeline_id"
t
.
boolean
"ref_fetched"
end
end
add_index
"merge_requests"
,
[
"assignee_id"
],
name:
"index_merge_requests_on_assignee_id"
,
using: :btree
add_index
"merge_requests"
,
[
"assignee_id"
],
name:
"index_merge_requests_on_assignee_id"
,
using: :btree
...
...
lib/gitlab/import_export/import_export.yml
View file @
0eb3d18c
...
@@ -99,6 +99,7 @@ excluded_attributes:
...
@@ -99,6 +99,7 @@ excluded_attributes:
-
:milestone_id
-
:milestone_id
merge_requests
:
merge_requests
:
-
:milestone_id
-
:milestone_id
-
:ref_fetched
award_emoji
:
award_emoji
:
-
:awardable_id
-
:awardable_id
statuses
:
statuses
:
...
...
spec/lib/gitlab/import_export/fork_spec.rb
View file @
0eb3d18c
...
@@ -44,6 +44,8 @@ describe 'forked project import', services: true do
...
@@ -44,6 +44,8 @@ describe 'forked project import', services: true do
end
end
it
'can access the MR'
do
it
'can access the MR'
do
expect
(
project
.
merge_requests
.
first
.
ensure_ref_fetched
.
first
).
to
include
(
'refs/merge-requests/1/head'
)
project
.
merge_requests
.
first
.
ensure_ref_fetched
expect
(
project
.
repository
.
ref_exists?
(
'refs/merge-requests/1/head'
)).
to
be_truthy
end
end
end
end
spec/models/merge_request_spec.rb
View file @
0eb3d18c
...
@@ -1574,4 +1574,40 @@ describe MergeRequest, models: true do
...
@@ -1574,4 +1574,40 @@ describe MergeRequest, models: true do
end
end
end
end
end
end
describe
'#fetch_ref'
do
it
'sets "ref_fetched" flag to true'
do
subject
.
update!
(
ref_fetched:
nil
)
subject
.
fetch_ref
expect
(
subject
.
reload
.
ref_fetched
).
to
be_truthy
end
end
describe
'#ref_fetched?'
do
it
'does not perform git operation when value is cached'
do
subject
.
ref_fetched
=
true
expect_any_instance_of
(
Repository
).
not_to
receive
(
:ref_exists?
)
expect
(
subject
.
ref_fetched?
).
to
be_truthy
end
it
'caches the value when ref exists but value is not cached'
do
subject
.
update!
(
ref_fetched:
nil
)
allow_any_instance_of
(
Repository
).
to
receive
(
:ref_exists?
)
.
and_return
(
true
)
expect
(
subject
.
ref_fetched?
).
to
be_truthy
expect
(
subject
.
reload
.
ref_fetched
).
to
be_truthy
end
it
'returns false when ref does not exist'
do
subject
.
update!
(
ref_fetched:
nil
)
allow_any_instance_of
(
Repository
).
to
receive
(
:ref_exists?
)
.
and_return
(
false
)
expect
(
subject
.
ref_fetched?
).
to
be_falsey
end
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