diff --git a/app/models/commit.rb b/app/models/commit.rb index 0be26a8..cef20ee 100644 --- a/app/models/commit.rb +++ b/app/models/commit.rb @@ -6,4 +6,28 @@ class Commit < ApplicationRecord scope :since, ->(date) { where('timestamp > ?', date) } scope :until, ->(date) { where('timestamp < ?', date) } + + def labelled_stats + { + files_changed: files_changed, + additions: additions, + deletions: deletions + } + end + + def files_changed + stats[0] + end + + def additions + stats[1] + end + + def deletions + stats[2] + end + + def html_url + "#{repository.html_url}/commit/#{sha}" + end end diff --git a/app/views/api/v1/commits/_commit.json.jbuilder b/app/views/api/v1/commits/_commit.json.jbuilder index eb5eab1..8b47f58 100644 --- a/app/views/api/v1/commits/_commit.json.jbuilder +++ b/app/views/api/v1/commits/_commit.json.jbuilder @@ -1 +1,3 @@ -json.extract! commit, :sha, :message, :author, :committer, :timestamp, :merge \ No newline at end of file +json.extract! commit, :sha, :message, :author, :committer, :timestamp, :merge +json.html_url commit.html_url +json.stats commit.labelled_stats diff --git a/openapi/api/v1/openapi.yaml b/openapi/api/v1/openapi.yaml index 63115bc..42bd50f 100644 --- a/openapi/api/v1/openapi.yaml +++ b/openapi/api/v1/openapi.yaml @@ -321,4 +321,16 @@ components: type: string format: date-time merge: - type: boolean \ No newline at end of file + type: boolean + html_url: + type: string + stats: + type: object + properties: + files_changed: + type: integer + additions: + type: integer + deletions: + type: integer + \ No newline at end of file