Skip to content
GitLab
Explore
Sign in
Register
Primary navigation
Search or go to…
Project
A
Admin
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Package Registry
Container Registry
Model registry
Operate
Environments
Terraform modules
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
osuny
Admin
Commits
413d0200
Commit
413d0200
authored
3 years ago
by
Arnaud Levy
Browse files
Options
Downloads
Patches
Plain Diff
articles and researchers
parent
bd1dc60a
No related branches found
Branches containing commit
No related tags found
Tags containing commit
No related merge requests found
Changes
3
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
app/models/research/journal/article.rb
+16
-15
16 additions, 15 deletions
app/models/research/journal/article.rb
app/models/research/researcher.rb
+11
-8
11 additions, 8 deletions
app/models/research/researcher.rb
app/services/github.rb
+4
-15
4 additions, 15 deletions
app/services/github.rb
with
31 additions
and
38 deletions
app/models/research/journal/article.rb
+
16
−
15
View file @
413d0200
...
@@ -32,13 +32,15 @@
...
@@ -32,13 +32,15 @@
# fk_rails_... (updated_by_id => users.id)
# fk_rails_... (updated_by_id => users.id)
#
#
class
Research::Journal::Article
<
ApplicationRecord
class
Research::Journal::Article
<
ApplicationRecord
include
WithGithub
belongs_to
:university
belongs_to
:university
belongs_to
:journal
,
foreign_key: :research_journal_id
belongs_to
:journal
,
foreign_key: :research_journal_id
belongs_to
:volume
,
foreign_key: :research_journal_volume_id
,
optional:
true
belongs_to
:volume
,
foreign_key: :research_journal_volume_id
,
optional:
true
belongs_to
:updated_by
,
class_name:
'User'
belongs_to
:updated_by
,
class_name:
'User'
has_and_belongs_to_many
:researchers
,
class_name:
'Research::Researcher'
has_and_belongs_to_many
:researchers
,
class_name:
'Research::Researcher'
after_commit
:
publish_to_github
after_commit
:
update_researchers
has_one_attached
:pdf
has_one_attached
:pdf
...
@@ -58,22 +60,21 @@ class Research::Journal::Article < ApplicationRecord
...
@@ -58,22 +60,21 @@ class Research::Journal::Article < ApplicationRecord
protected
protected
def
publish_to_github
def
github_path_generated
github
.
publish
kind: :articles
,
"_articles/
#{
id
}
.html"
file:
"
#{
id
}
.md"
,
end
title:
title
,
data:
ApplicationController
.
render
(
def
to_jekyll
template:
'admin/research/journal/articles/jekyll'
,
ApplicationController
.
render
(
layout:
false
,
template:
'admin/research/journal/articles/jekyll'
,
assigns:
{
article:
self
}
layout:
false
,
)
assigns:
{
article:
self
}
)
end
def
update_researchers
researchers
.
each
do
|
researcher
|
researchers
.
each
do
|
researcher
|
researcher
.
publish_to_website
(
journal
.
website
)
researcher
.
publish_to_website
(
journal
.
website
)
end
end
github
.
send_file
pdf
,
pdf_path
if
pdf
.
attached?
end
def
github
@github
||=
Github
.
with_site
(
journal
.
website
)
end
end
end
end
This diff is collapsed.
Click to expand it.
app/models/research/researcher.rb
+
11
−
8
View file @
413d0200
...
@@ -32,14 +32,9 @@ class Research::Researcher < ApplicationRecord
...
@@ -32,14 +32,9 @@ class Research::Researcher < ApplicationRecord
def
publish_to_website
(
website
)
def
publish_to_website
(
website
)
github
=
Github
.
new
website
.
access_token
,
website
.
repository
github
=
Github
.
new
website
.
access_token
,
website
.
repository
github
.
publish
kind: :authors
,
github
.
publish
path:
"_authors/
#{
id
}
.md"
,
file:
"
#{
id
}
.md"
,
data:
to_jekyll
,
title:
to_s
,
commit:
"[Researcher] Save
#{
to_s
}
"
data:
ApplicationController
.
render
(
template:
'admin/research/researchers/jekyll'
,
layout:
false
,
assigns:
{
researcher:
self
}
)
end
end
def
to_s
def
to_s
...
@@ -48,6 +43,14 @@ class Research::Researcher < ApplicationRecord
...
@@ -48,6 +43,14 @@ class Research::Researcher < ApplicationRecord
protected
protected
def
to_jekyll
ApplicationController
.
render
(
template:
'admin/research/researchers/jekyll'
,
layout:
false
,
assigns:
{
researcher:
self
}
)
end
def
publish_to_github
def
publish_to_github
websites
.
each
{
|
website
|
publish_to_website
(
website
)
}
websites
.
each
{
|
website
|
publish_to_website
(
website
)
}
end
end
...
...
This diff is collapsed.
Click to expand it.
app/services/github.rb
+
4
−
15
View file @
413d0200
...
@@ -10,22 +10,11 @@ class Github
...
@@ -10,22 +10,11 @@ class Github
@repository
=
repository
@repository
=
repository
end
end
def
publish
(
kind:
nil
,
# Deprecated
def
publish
(
path:
nil
,
file:
nil
,
# Deprecated
title:
nil
,
# Deprecated
path:
nil
,
previous_path:
nil
,
previous_path:
nil
,
commit:
nil
,
commit:
nil
,
data
:)
data
:)
if
path
local_path
=
"
#{
tmp_directory
}
/
#{
path
}
"
local_path
=
"
#{
tmp_directory
}
/
#{
path
}
"
remote_file
=
path
else
# Deprecated
local_path
=
"
#{
tmp_directory
}
/
#{
file
}
"
remote_file
=
"_
#{
kind
}
/
#{
file
}
"
commit
=
"Save
#{
title
}
"
end
Pathname
(
local_path
).
dirname
.
mkpath
Pathname
(
local_path
).
dirname
.
mkpath
File
.
write
local_path
,
data
File
.
write
local_path
,
data
return
if
repository
.
blank?
return
if
repository
.
blank?
...
@@ -33,10 +22,10 @@ class Github
...
@@ -33,10 +22,10 @@ class Github
move_file
previous_path
,
path
move_file
previous_path
,
path
end
end
client
.
create_contents
repository
,
client
.
create_contents
repository
,
remote_file
,
path
,
commit
,
commit
,
file:
local_path
,
file:
local_path
,
sha:
file_sha
(
remote_file
)
sha:
file_sha
(
path
)
rescue
rescue
# byebug
# byebug
end
end
...
...
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment