Skip to content

Commit

Permalink
Add labelled_stats method to Commit model and include html_url and st…
Browse files Browse the repository at this point in the history
…ats in commit JSON response
  • Loading branch information
andrew committed Feb 12, 2024
1 parent 1b29a31 commit 9b9ac5b
Show file tree
Hide file tree
Showing 3 changed files with 40 additions and 2 deletions.
24 changes: 24 additions & 0 deletions app/models/commit.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
4 changes: 3 additions & 1 deletion app/views/api/v1/commits/_commit.json.jbuilder
Original file line number Diff line number Diff line change
@@ -1 +1,3 @@
json.extract! commit, :sha, :message, :author, :committer, :timestamp, :merge
json.extract! commit, :sha, :message, :author, :committer, :timestamp, :merge
json.html_url commit.html_url
json.stats commit.labelled_stats
14 changes: 13 additions & 1 deletion openapi/api/v1/openapi.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -321,4 +321,16 @@ components:
type: string
format: date-time
merge:
type: boolean
type: boolean
html_url:
type: string
stats:
type: object
properties:
files_changed:
type: integer
additions:
type: integer
deletions:
type: integer

0 comments on commit 9b9ac5b

Please sign in to comment.