Skip to content
Snippets Groups Projects
Commit c5195a58 authored by Arnaud Levy's avatar Arnaud Levy
Browse files

nice commit volumes

parent 88d239ca
No related branches found
No related tags found
No related merge requests found
......@@ -25,6 +25,7 @@ gem 'country_select'
gem 'breadcrumbs_on_rails'
gem 'simple-navigation'
gem 'kaminari'
gem 'octokit'
# Front
gem 'jquery-rails'
......
......@@ -137,6 +137,25 @@ GEM
activesupport (>= 3.0.0)
erubi (1.10.0)
execjs (2.8.1)
faraday (1.7.1)
faraday-em_http (~> 1.0)
faraday-em_synchrony (~> 1.0)
faraday-excon (~> 1.1)
faraday-httpclient (~> 1.0.1)
faraday-net_http (~> 1.0)
faraday-net_http_persistent (~> 1.1)
faraday-patron (~> 1.0)
faraday-rack (~> 1.0)
multipart-post (>= 1.2, < 3)
ruby2_keywords (>= 0.0.4)
faraday-em_http (1.0.0)
faraday-em_synchrony (1.0.0)
faraday-excon (1.1.0)
faraday-httpclient (1.0.1)
faraday-net_http (1.0.1)
faraday-net_http_persistent (1.2.0)
faraday-patron (1.0.0)
faraday-rack (1.0.0)
ffi (1.15.3)
globalid (0.5.2)
activesupport (>= 5.0)
......@@ -183,12 +202,16 @@ GEM
mini_portile2 (2.6.1)
minitest (5.14.4)
msgpack (1.4.2)
multipart-post (2.1.1)
mustermann (1.1.1)
ruby2_keywords (~> 0.0.1)
nio4r (2.5.8)
nokogiri (1.12.2)
mini_portile2 (~> 2.6.1)
racc (~> 1.4)
octokit (4.21.0)
faraday (>= 0.9)
sawyer (~> 0.8.0, >= 0.5.3)
orm_adapter (0.5.0)
pg (1.2.3)
popper_js (2.9.2)
......@@ -252,6 +275,9 @@ GEM
sprockets (> 3.0)
sprockets-rails
tilt
sawyer (0.8.2)
addressable (>= 2.3.5)
faraday (> 0.8, < 2.0)
selenium-webdriver (3.142.7)
childprocess (>= 0.5, < 4.0)
rubyzip (>= 1.2.2)
......@@ -324,6 +350,7 @@ DEPENDENCIES
kamifusen
kaminari
listen (~> 3.3)
octokit
pg (~> 1.1)
puma
rack-mini-profiler (~> 2.0)
......
......@@ -45,6 +45,6 @@ class Admin::Research::JournalsController < Admin::Research::Journal::Applicatio
protected
def journal_params
params.require(:research_journal).permit(:title, :description)
params.require(:research_journal).permit(:title, :description, :access_token, :repository)
end
end
......@@ -3,7 +3,9 @@
# Table name: research_journals
#
# id :uuid not null, primary key
# access_token :string
# description :text
# repository :string
# title :string
# created_at :datetime not null
# updated_at :datetime not null
......
......@@ -26,7 +26,33 @@ class Research::Journal::Volume < ApplicationRecord
belongs_to :journal, foreign_key: :research_journal_id
has_many :articles, foreign_key: :research_journal_volume_id
after_save :publish
def to_s
"##{ number } #{ title }"
end
protected
def publish
return if journal.repository.blank?
data = "---\ntitle: #{ title }\nnumber: #{number}\n---"
directory = "tmp/volumes"
FileUtils.mkdir_p directory
local_file = "#{directory}/#{id}.md"
File.write local_file, data
remote_file = "_volumes/#{id}.md"
client = Octokit::Client.new access_token: journal.access_token
begin
content = client.content journal.repository, path: remote_file
sha = content[:sha]
rescue
sha = nil
end
client.create_contents journal.repository,
remote_file,
"Save volume #{ title }",
file: local_file,
sha: sha
end
end
......@@ -2,6 +2,8 @@
<div class="row">
<div class="col-md-6">
<%= f.input :title %>
<%= f.input :repository %>
<%= f.input :access_token %>
</div>
<div class="col-md-6">
<%= f.input :description %>
......
class AddGithubToResearchJournals < ActiveRecord::Migration[6.1]
def change
add_column :research_journals, :access_token, :string
add_column :research_journals, :repository, :string
end
end
......@@ -10,7 +10,7 @@
#
# It's strongly recommended that you check this file into your version control system.
ActiveRecord::Schema.define(version: 2021_08_21_121439) do
ActiveRecord::Schema.define(version: 2021_08_31_122745) do
# These are extensions that must be enabled in order to support this database
enable_extension "pgcrypto"
......@@ -120,6 +120,8 @@ ActiveRecord::Schema.define(version: 2021_08_21_121439) do
t.text "description"
t.datetime "created_at", precision: 6, null: false
t.datetime "updated_at", precision: 6, null: false
t.string "access_token"
t.string "repository"
t.index ["university_id"], name: "index_research_journals_on_university_id"
end
......
......@@ -17,7 +17,8 @@
### Points à vérifier
- [ ] Lecture écriture github
- [ ] Performance avec un backend github
- [ ] Lecture écriture Github
- [ ] Performance avec un backend Github
- [ ] Relations avec les auteurs et les droits (doublon DB, autre...)
- [ ] Articulation avec les objets en DB (volumes et articles par ex.)
- [x] Gestion des mises à jour des templates -> utiliser un template Github
......@@ -3,7 +3,9 @@
# Table name: research_journals
#
# id :uuid not null, primary key
# access_token :string
# description :text
# repository :string
# title :string
# created_at :datetime not null
# updated_at :datetime not null
......
......@@ -3,7 +3,9 @@
# Table name: research_journals
#
# id :uuid not null, primary key
# access_token :string
# description :text
# repository :string
# title :string
# created_at :datetime not null
# updated_at :datetime not null
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment