summaryrefslogtreecommitdiff
path: root/app/models/commit.rb
diff options
context:
space:
mode:
authorSean McGivern <sean@mcgivern.me.uk>2017-01-24 13:48:33 +0000
committerSean McGivern <sean@mcgivern.me.uk>2017-01-24 13:48:33 +0000
commit65bf7e0d92856d90215ca908751e676393c10618 (patch)
treefebf109d5461c13b856d7a8e3c51cdd2fa1beb18 /app/models/commit.rb
parenta89aab9c630593524b8a210746d2eb680ac5d102 (diff)
parent99404a5851a4b8bbba8a5786d7351f2d4b024092 (diff)
downloadgitlab-ce-65bf7e0d92856d90215ca908751e676393c10618.tar.gz
Merge branch '24833-Allow-to-search-by-commit-hash-within-project' into 'master'
Allows to search within project by commit's hash #24833 Closes #24833 See merge request !8028
Diffstat (limited to 'app/models/commit.rb')
-rw-r--r--app/models/commit.rb11
1 files changed, 8 insertions, 3 deletions
diff --git a/app/models/commit.rb b/app/models/commit.rb
index 5d942cb0422..316bd2e512b 100644
--- a/app/models/commit.rb
+++ b/app/models/commit.rb
@@ -21,6 +21,9 @@ class Commit
DIFF_HARD_LIMIT_FILES = 1000
DIFF_HARD_LIMIT_LINES = 50000
+ # The SHA can be between 7 and 40 hex characters.
+ COMMIT_SHA_PATTERN = '\h{7,40}'
+
class << self
def decorate(commits, project)
commits.map do |commit|
@@ -52,6 +55,10 @@ class Commit
def from_hash(hash, project)
new(Gitlab::Git::Commit.new(hash), project)
end
+
+ def valid_hash?(key)
+ !!(/\A#{COMMIT_SHA_PATTERN}\z/ =~ key)
+ end
end
attr_accessor :raw
@@ -77,8 +84,6 @@ class Commit
# Pattern used to extract commit references from text
#
- # The SHA can be between 7 and 40 hex characters.
- #
# This pattern supports cross-project references.
def self.reference_pattern
@reference_pattern ||= %r{
@@ -88,7 +93,7 @@ class Commit
end
def self.link_reference_pattern
- @link_reference_pattern ||= super("commit", /(?<commit>\h{7,40})/)
+ @link_reference_pattern ||= super("commit", /(?<commit>#{COMMIT_SHA_PATTERN})/)
end
def to_reference(from_project = nil, full: false)