diff options
| author | Zeger-Jan van de Weg <mail@zjvandeweg.nl> | 2015-12-10 16:27:26 +0100 |
|---|---|---|
| committer | Zeger-Jan van de Weg <mail@zjvandeweg.nl> | 2015-12-10 16:27:26 +0100 |
| commit | 82d2e5c3c561f213a59c1df36c6d5c4bb2eef7d0 (patch) | |
| tree | 0e6e0efcc6dc6ff1b517c82fb3b2a86cf78e8e4f /app/models/commit.rb | |
| parent | 5fd280f3d3264aec3656cb61cd8728f2ca4d61ce (diff) | |
| parent | 4e5897f51ef97d7c3ff6c57f81521f552979a3da (diff) | |
| download | gitlab-ce-82d2e5c3c561f213a59c1df36c6d5c4bb2eef7d0.tar.gz | |
Merge branch 'master' into copying-file-seen-as-licence
Diffstat (limited to 'app/models/commit.rb')
| -rw-r--r-- | app/models/commit.rb | 50 |
1 files changed, 43 insertions, 7 deletions
diff --git a/app/models/commit.rb b/app/models/commit.rb index 492f6be1ce3..0ba7b584d91 100644 --- a/app/models/commit.rb +++ b/app/models/commit.rb @@ -7,7 +7,7 @@ class Commit include Referable include StaticModel - attr_mentionable :safe_message + attr_mentionable :safe_message, pipeline: :single_line participant :author, :committer, :notes attr_accessor :project @@ -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 @@ -157,11 +175,11 @@ class Commit end def author - @author ||= User.find_by_any_email(author_email) + @author ||= User.find_by_any_email(author_email.downcase) end def committer - @committer ||= User.find_by_any_email(committer_email) + @committer ||= User.find_by_any_email(committer_email.downcase) end def parents @@ -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 |
