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
Léo-Paul Géneau
gitlab-ce
Commits
bbfbff3a
Commit
bbfbff3a
authored
Mar 31, 2013
by
Dmitriy Zaporozhets
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Extend models functionality with old decorator methods. Use Repository model
parent
b53557ac
Changes
7
Hide whitespace changes
Inline
Side-by-side
Showing
7 changed files
with
67 additions
and
11 deletions
+67
-11
app/contexts/commit_load_context.rb
app/contexts/commit_load_context.rb
+0
-1
app/mailers/emails/notes.rb
app/mailers/emails/notes.rb
+0
-1
app/models/commit.rb
app/models/commit.rb
+47
-4
app/models/merge_request.rb
app/models/merge_request.rb
+11
-2
app/models/project.rb
app/models/project.rb
+1
-1
app/models/tree.rb
app/models/tree.rb
+8
-0
lib/extracts_path.rb
lib/extracts_path.rb
+0
-2
No files found.
app/contexts/commit_load_context.rb
View file @
bbfbff3a
...
@@ -13,7 +13,6 @@ class CommitLoadContext < BaseContext
...
@@ -13,7 +13,6 @@ class CommitLoadContext < BaseContext
if
commit
if
commit
commit
=
Commit
.
new
(
commit
)
commit
=
Commit
.
new
(
commit
)
commit
=
CommitDecorator
.
decorate
(
commit
)
line_notes
=
project
.
notes
.
for_commit_id
(
commit
.
id
).
inline
line_notes
=
project
.
notes
.
for_commit_id
(
commit
.
id
).
inline
result
[
:commit
]
=
commit
result
[
:commit
]
=
commit
...
...
app/mailers/emails/notes.rb
View file @
bbfbff3a
...
@@ -3,7 +3,6 @@ module Emails
...
@@ -3,7 +3,6 @@ module Emails
def
note_commit_email
(
recipient_id
,
note_id
)
def
note_commit_email
(
recipient_id
,
note_id
)
@note
=
Note
.
find
(
note_id
)
@note
=
Note
.
find
(
note_id
)
@commit
=
@note
.
noteable
@commit
=
@note
.
noteable
@commit
=
CommitDecorator
.
decorate
(
@commit
)
@project
=
@note
.
project
@project
=
@note
.
project
mail
(
to:
recipient
(
recipient_id
),
subject:
subject
(
"note for commit
#{
@commit
.
short_id
}
"
,
@commit
.
title
))
mail
(
to:
recipient
(
recipient_id
),
subject:
subject
(
"note for commit
#{
@commit
.
short_id
}
"
,
@commit
.
title
))
end
end
...
...
app/models/commit.rb
View file @
bbfbff3a
...
@@ -10,10 +10,6 @@ class Commit
...
@@ -10,10 +10,6 @@ class Commit
attr_accessor
:raw
attr_accessor
:raw
def
self
.
decorate
(
commits
)
commits
.
map
{
|
c
|
Commit
.
new
(
c
)
}
end
def
initialize
(
raw_commit
)
def
initialize
(
raw_commit
)
raise
"Nil as raw commit passed"
unless
raw_commit
raise
"Nil as raw commit passed"
unless
raw_commit
...
@@ -24,7 +20,54 @@ class Commit
...
@@ -24,7 +20,54 @@ class Commit
@raw
.
id
@raw
.
id
end
end
# Returns a string describing the commit for use in a link title
#
# Example
#
# "Commit: Alex Denisov - Project git clone panel"
def
link_title
"Commit:
#{
author_name
}
-
#{
title
}
"
end
# Returns the commits title.
#
# Usually, the commit title is the first line of the commit message.
# In case this first line is longer than 80 characters, it is cut off
# after 70 characters and ellipses (`&hellp;`) are appended.
def
title
title
=
safe_message
return
no_commit_message
if
title
.
blank?
title_end
=
title
.
index
(
/\n/
)
if
(
!
title_end
&&
title
.
length
>
80
)
||
(
title_end
&&
title_end
>
80
)
title
[
0
..
69
]
<<
"…"
.
html_safe
else
title
.
split
(
/\n/
,
2
).
first
end
end
# Returns the commits description
#
# cut off, ellipses (`&hellp;`) are prepended to the commit message.
def
description
description
=
safe_message
title_end
=
description
.
index
(
/\n/
)
if
(
!
title_end
&&
description
.
length
>
80
)
||
(
title_end
&&
title_end
>
80
)
"…"
.
html_safe
<<
description
[
70
..-
1
]
else
description
.
split
(
/\n/
,
2
)[
1
].
try
(
:chomp
)
end
end
def
method_missing
(
m
,
*
args
,
&
block
)
def
method_missing
(
m
,
*
args
,
&
block
)
@raw
.
send
(
m
,
*
args
,
&
block
)
@raw
.
send
(
m
,
*
args
,
&
block
)
end
end
def
respond_to?
(
method
)
return
true
if
@raw
.
respond_to?
(
method
)
super
end
end
end
app/models/merge_request.rb
View file @
bbfbff3a
...
@@ -152,7 +152,17 @@ class MergeRequest < ActiveRecord::Base
...
@@ -152,7 +152,17 @@ class MergeRequest < ActiveRecord::Base
end
end
def
commits
def
commits
st_commits
||
[]
if
st_commits
.
present?
# check if merge request commits are valid
if
st_commits
.
first
.
respond_to?
(
:short_id
)
st_commits
else
# if commits are invalid - simply reload it from repo
reloaded_commits
end
else
[]
end
end
end
def
probably_merged?
def
probably_merged?
...
@@ -171,7 +181,6 @@ class MergeRequest < ActiveRecord::Base
...
@@ -171,7 +181,6 @@ class MergeRequest < ActiveRecord::Base
def
unmerged_commits
def
unmerged_commits
self
.
project
.
repository
.
self
.
project
.
repository
.
commits_between
(
self
.
target_branch
,
self
.
source_branch
).
commits_between
(
self
.
target_branch
,
self
.
source_branch
).
map
{
|
c
|
Commit
.
new
(
c
)}.
sort_by
(
&
:created_at
).
sort_by
(
&
:created_at
).
reverse
reverse
end
end
...
...
app/models/project.rb
View file @
bbfbff3a
...
@@ -142,7 +142,7 @@ class Project < ActiveRecord::Base
...
@@ -142,7 +142,7 @@ class Project < ActiveRecord::Base
def
repository
def
repository
if
path
if
path
@repository
||=
Gitlab
::
Git
::
Repository
.
new
(
path_with_namespace
,
default_branch
)
@repository
||=
Repository
.
new
(
path_with_namespace
,
default_branch
)
else
else
nil
nil
end
end
...
...
app/models/tree.rb
View file @
bbfbff3a
...
@@ -26,4 +26,12 @@ class Tree
...
@@ -26,4 +26,12 @@ class Tree
def
empty?
def
empty?
data
.
blank?
data
.
blank?
end
end
def
up_dir?
path
.
present?
end
def
readme
@readme
||=
contents
.
find
{
|
c
|
c
.
is_a?
(
Grit
::
Blob
)
and
c
.
name
=~
/^readme/i
}
end
end
end
lib/extracts_path.rb
View file @
bbfbff3a
...
@@ -101,10 +101,8 @@ module ExtractsPath
...
@@ -101,10 +101,8 @@ module ExtractsPath
# It is used "@project.repository.commits(@ref, @path, 1, 0)",
# It is used "@project.repository.commits(@ref, @path, 1, 0)",
# because "@project.repository.commit(@ref)" returns wrong commit when @ref is tag name.
# because "@project.repository.commit(@ref)" returns wrong commit when @ref is tag name.
@commit
=
@project
.
repository
.
commits
(
@ref
,
@path
,
1
,
0
).
first
@commit
=
@project
.
repository
.
commits
(
@ref
,
@path
,
1
,
0
).
first
@commit
=
CommitDecorator
.
decorate
(
@commit
)
@tree
=
Tree
.
new
(
@commit
.
tree
,
@ref
,
@path
)
@tree
=
Tree
.
new
(
@commit
.
tree
,
@ref
,
@path
)
@tree
=
TreeDecorator
.
new
(
@tree
)
raise
InvalidPathError
if
@tree
.
invalid?
raise
InvalidPathError
if
@tree
.
invalid?
rescue
RuntimeError
,
NoMethodError
,
InvalidPathError
rescue
RuntimeError
,
NoMethodError
,
InvalidPathError
...
...
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