summaryrefslogtreecommitdiff
path: root/app/models/commit.rb
diff options
context:
space:
mode:
authorDouwe Maan <douwe@gitlab.com>2015-12-07 17:12:29 +0100
committerDouwe Maan <douwe@gitlab.com>2015-12-07 17:12:29 +0100
commit5a9a8d03a798c8dfe154e5db4ddf6bcb7a14fa2c (patch)
treede42e220cf35f130e2d2d3d6b2290e639d959d6d /app/models/commit.rb
parentcbcb8dbe702c0b1532327aeb2dc53caffb6e8ed9 (diff)
parentbd5fb1b479f29df3c2150b6c375c1b7bffd28931 (diff)
downloadgitlab-ce-5a9a8d03a798c8dfe154e5db4ddf6bcb7a14fa2c.tar.gz
Merge branch 'master' into ui/dashboard-new-issue
Diffstat (limited to 'app/models/commit.rb')
-rw-r--r--app/models/commit.rb44
1 files changed, 40 insertions, 4 deletions
diff --git a/app/models/commit.rb b/app/models/commit.rb
index 492f6be1ce3..8ae5325d16a 100644
--- a/app/models/commit.rb
+++ b/app/models/commit.rb
@@ -78,11 +78,23 @@ class Commit
}x
end
+ def self.link_reference_pattern
+ super("commit", /(?<commit>\h{6,40})/)
+ end
+
def to_reference(from_project = nil)
if cross_project_reference?(from_project)
- "#{project.to_reference}@#{id}"
+ project.to_reference + self.class.reference_prefix + self.id
else
- id
+ self.id
+ end
+ end
+
+ def reference_link_text(from_project = nil)
+ if cross_project_reference?(from_project)
+ project.to_reference + self.class.reference_prefix + self.short_id
+ else
+ self.short_id
end
end
@@ -135,10 +147,10 @@ class Commit
description.present?
end
- def hook_attrs
+ def hook_attrs(with_changed_files: false)
path_with_namespace = project.path_with_namespace
- {
+ data = {
id: id,
message: safe_message,
timestamp: committed_date.xmlschema,
@@ -148,6 +160,12 @@ class Commit
email: author_email
}
}
+
+ if with_changed_files
+ data.merge!(repo_changes)
+ end
+
+ data
end
# Discover issues should be closed when this commit is pushed to a project's
@@ -196,4 +214,22 @@ class Commit
def status
ci_commit.try(:status) || :not_found
end
+
+ private
+
+ def repo_changes
+ changes = { added: [], modified: [], removed: [] }
+
+ diffs.each do |diff|
+ if diff.deleted_file
+ changes[:removed] << diff.old_path
+ elsif diff.renamed_file || diff.new_file
+ changes[:added] << diff.new_path
+ else
+ changes[:modified] << diff.new_path
+ end
+ end
+
+ changes
+ end
end