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
6b3a96d7
Unverified
Commit
6b3a96d7
authored
3 years ago
by
Sébastien Gaya
Browse files
Options
Downloads
Patches
Plain Diff
batch with media + create
parent
f8130a0e
No related branches found
Branches containing commit
No related tags found
Tags containing commit
No related merge requests found
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
app/models/communication/website/github_file.rb
+11
-28
11 additions, 28 deletions
app/models/communication/website/github_file.rb
app/models/concerns/with_github_files.rb
+12
-2
12 additions, 2 deletions
app/models/concerns/with_github_files.rb
with
23 additions
and
30 deletions
app/models/communication/website/github_file.rb
+
11
−
28
View file @
6b3a96d7
...
...
@@ -27,44 +27,18 @@ class Communication::Website::GithubFile < ApplicationRecord
def
publish
return
unless
github
.
valid?
params
=
github_params
.
merge
({
commit:
github_commit_message
})
if
github
.
publish
(
params
)
add_to_batch
(
github
)
if
github
.
commit_batch
(
github_commit_message
)
update_column
:github_path
,
about
.
github_path_generated
publish_media
end
end
handle_asynchronously
:publish
,
queue:
'default'
def
publish_media
return
unless
about
.
respond_to?
(
:active_storage_blobs
)
about
.
active_storage_blobs
.
each
{
|
blob
|
publish_blob
(
blob
)
}
end
def
publish_blob
(
blob
)
return
unless
github
.
valid?
params
=
github_blob_params
(
blob
).
merge
({
commit:
github_blob_commit_message
(
blob
)
})
github
.
publish
(
params
)
end
handle_asynchronously
:publish_blob
,
queue:
'default'
def
add_to_batch
(
github
)
github
.
add_to_batch
github_params
add_media_to_batch
(
github
)
end
def
add_media_to_batch
(
github
)
return
unless
about
.
respond_to?
(
:active_storage_blobs
)
about
.
active_storage_blobs
.
each
{
|
blob
|
add_blob_to_batch
(
github
,
blob
)
}
end
def
add_blob_to_batch
(
github
,
blob
)
github
.
add_to_batch
github_blob_params
(
blob
)
end
def
github_frontmatter
@github_frontmatter
||=
begin
github_content
=
github
.
read_file_at
(
github_path
)
...
...
@@ -76,6 +50,15 @@ class Communication::Website::GithubFile < ApplicationRecord
protected
def
add_media_to_batch
(
github
)
return
unless
about
.
respond_to?
(
:active_storage_blobs
)
about
.
active_storage_blobs
.
each
{
|
blob
|
add_blob_to_batch
(
github
,
blob
)
}
end
def
add_blob_to_batch
(
github
,
blob
)
github
.
add_to_batch
github_blob_params
(
blob
)
end
def
remove_from_github
return
unless
github
.
valid?
github
.
remove
github_path
,
github_remove_commit_message
...
...
This diff is collapsed.
Click to expand it.
app/models/concerns/with_github_files.rb
+
12
−
2
View file @
6b3a96d7
...
...
@@ -4,6 +4,7 @@ module WithGithubFiles
included
do
has_many
:github_files
,
class_name:
"Communication::Website::GithubFile"
,
as: :about
,
dependent: :destroy
after_save
:create_github_files
after_save_commit
:publish_github_files
after_touch
:publish_github_files
end
...
...
@@ -26,11 +27,20 @@ module WithGithubFiles
protected
def
create_github_files
list_of_websites
.
each
do
|
website
|
github_files
.
find_or_create_by
(
website:
website
)
end
end
def
publish_github_files
list_of_websites
=
respond_to?
(
:websites
)
?
websites
:
[
website
]
list_of_websites
.
each
do
|
website
|
github_file
=
github_files
.
where
(
website:
website
)
.
first_or_create
github_file
=
github_files
.
find_or_create_by
(
website:
website
)
github_file
.
publish
end
end
def
list_of_websites
respond_to?
(
:websites
)
?
websites
:
[
website
]
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