diff --git a/app/controllers/merged/changes_controller.rb b/app/controllers/merged/changes_controller.rb index 4424113..29e911a 100644 --- a/app/controllers/merged/changes_controller.rb +++ b/app/controllers/merged/changes_controller.rb @@ -1,11 +1,23 @@ -require "rugged" +require "git" module Merged class ChangesController < MergedController def index - @git = Rugged::Repository.new(Rails.root) + @git = Git.open(Rails.root) + @status = @git.status() end + def commit + raise "must have message" if params[:message].blank? + git = Git.open(Rails.root) + git.add("cms") + git.add("app/assets/images/cms") + begin + git.commit(params[:message]) + rescue + end + redirect_to changes_index_url + end end end diff --git a/app/views/merged/changes/index.haml b/app/views/merged/changes/index.haml index 784a2d7..75fad91 100644 --- a/app/views/merged/changes/index.haml +++ b/app/views/merged/changes/index.haml @@ -1,13 +1,46 @@ -%p= @git.workdir -%p Lines Changed --@git.diff_workdir("HEAD").each_line do |line| - %p= line.content -%h3 Patches -%h3 Patches -%h3 Patches --@git.diff_workdir("HEAD").each_patch do |patch| - %p= patch.additions - -patch.each_hunk do |hunk| - %p=hunk.header - -hunk.each_line do |line| - %p= line.content +.flex.flex-col.bg-white + .flex.items-center.justify-center.flex-1 + .max-w-xl.px-4.py-8.mx-auto.text-center + %h1.text-2xl.font-bold.tracking-tight.text-gray-900.sm:text-4xl + Changes + %p.mt-4.text-gray-500 + Branch + = @git.current_branch + +.grid.grid-cols-4.gap-2.m-8 + .relative.block.border.border-gray-100 + Changed Files + -@status.changed.each do |name , file| + -next unless name.include?("cms") + %p + = name + + .relative.block.border.border-gray-100 + Deletions + -@status.deleted.each do |name , file| + -next unless name.include?("cms") + %p= name + .relative.block.border.border-gray-100 + Additions + -@status.added.each do |name , file| + -next unless name.include?("cms") + %p= name + .relative.block.border.border-gray-100 + New + -@status.untracked.each do |name , file| + -next if name.starts_with?("merged") + -next unless name.include?("cms") + %p + = name + +.flex.flex-col.bg-white + .flex.items-center.justify-center.flex-1 + .max-w-xl.px-4.py-8.mx-auto.text-center + = form_tag( changes_commit_url() , {method: :post } ) do + %h1.text-2xl.font-bold.tracking-tight.text-gray-900.sm:text-4xl + Commit changes + %p.mt-4.text-gray-500 + %label.block + %h4.text-lg.font-bold Message (short summary of changes) + = text_field_tag( :message , "", class: "block w-full rounded-lg border-gray-200 p-4 pr-12 text-sm shadow-sm") + =submit_button( "Commit") diff --git a/config/routes.rb b/config/routes.rb index 7e02f00..6bf6eb9 100644 --- a/config/routes.rb +++ b/config/routes.rb @@ -1,6 +1,7 @@ Merged::Engine.routes.draw do - get 'changes/index' + get 'changes/index' + post 'changes/commit' get "styles/index" resources :pages , except: [:show] , shallow: true do diff --git a/merged.gemspec b/merged.gemspec index 6dbe7ae..cc97aec 100644 --- a/merged.gemspec +++ b/merged.gemspec @@ -20,5 +20,5 @@ Gem::Specification.new do |spec| spec.add_dependency "rails", ">= 7.0.4" spec.add_dependency "haml-rails" - spec.add_dependency "rugged" + spec.add_dependency "git" end