#45 差分表示以外完了

This commit is contained in:
2025-06-18 23:44:33 +09:00
parent c6f7e8a696
commit 0c4ee9744e
4 changed files with 83 additions and 10 deletions
@@ -52,12 +52,17 @@ class WikiPagesController < ApplicationController
def changes
id = params[:id]
log = id.present? ? wiki.page("#{ id }.md").versions : wiki.repo.log('main', nil, max_count: 50)
log = id.present? ? wiki.page("#{ id }.md")&.versions : wiki.repo.log('main', nil, max_count: 50)
return render json: [] unless log
render json: log.map { |commit|
{ sha: commit.id,
author: commit.author.name,
message: commit.message,
timestamp: commit.authored_date } }
wiki_page = WikiPage.find(commit.message.split(' ')[1].to_i)
user = User.find(commit.author.name.to_i)
{ sha: commit.id,
wiki_page: wiki_page && { id: wiki_page.id, title: wiki_page.title },
user: user && { id: user.id, name: user.name },
change_type: commit.message.split(' ')[0].downcase[0...(-1)],
timestamp: commit.authored_date } }
end
private
+4 -5
View File
@@ -14,15 +14,14 @@ class WikiPage < ApplicationRecord
end
def set_body content, user:
page = wiki.page("#{ id }.md")
commit_info = { message: "Update #{ title }",
name: user.id.to_s,
commit_info = { name: user.id.to_s,
email: 'dummy@example.com' }
page = wiki.page("#{ id }.md")
if page
commit_info[:message] = "Updated #{ id }"
wiki.update_page(page, id.to_s, :markdown, content, commit_info)
else
commit_info[:message] = "Created #{ id }"
wiki.write_page(id.to_s, :markdown, content, commit_info)
end
end