-
Notifications
You must be signed in to change notification settings - Fork 8
feat(lib): add support for git repositories as data source #49
feat(lib): add support for git repositories as data source #49
Conversation
|
||
def local_path, do: @local_path | ||
|
||
def list_files(folder \\ Settings.posts_folder()) do |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@alfredbaudisch So my thoughts here are we can default to the root of the repository and document that in the docs. We can then do one of two things:
- Add another optional setting in the config for the
git_repo_data_path
, - Have
root_path
accept a different data type, perhaps a keyword list would be a good option.
For example my website is written in NextJS with MDX all the md(x)
files live at data
:
config :pardall_markdown, PardallMarkdown.Content,
root_path: ["https://github.com/rockchalkwushock/codybrunner.dev.git", "data"]
What are your thoughts on how to expose this API to the end user?
This is a very good start, thanks for sharing. We still have some work to do, the repository provider has to be connected to a watcher, the watcher also needs to pool the repository (as opposed to the current FileWatcher which detects file changes on the fly), and then when getting new content, parse it with the FileParser through the current PardallMarkdown workflow. blogit/server.ex has a good start for a Repository watcher. It needs to be adjusted into PardallMarkdown but the main core is there. Our current FileWatcher and the new RepositoryWatcher can be loaded and started side by side. Then, RepositoryWatcher could clone the files into Do you want to give it a try? Otherwise I can do this next step in the weekend. |
Hi @alfredbaudisch I'd like to take another shot at implementing the Thank you for your guidance and patience. It's challenging, but also exciting to be contributing to an Elixir project! Even more so a project I am absolutely going to use in the coming weeks for a side project! |
@alfredbaudisch I am working on the # application.ex
def start do
children = [
...
# Start the repository_watcher.ex first
# How does the GenServer respond if no config value provided?
# Do we just not invoke the watcher?
# Would it make sense to look for the config here an provide it to the keyword list?
# { ..., remote: Application.get_env(:pardall_mardown, :remote_source) }
{PardallMarkdown.RepositoryWatcher, name: PardallMarkdown.RepositoryWatcher},
{PardallMarkdown.FileWatcher, name: PardallMarkdown.FileWatcher, dirs: [PardallMarkdown.Content.Utils.root_path()]]},
...
]
...
Supervisor.start_link(children, opts)
end With PardallMarkdown running as an application inside the mix project if a Now it is my understanding that when a process is created on the beam those processes are isolated from one another so I am slightly confused as to how the From your YT video PardallMarkdown is "framework agnostic". You don't have to use it with Phoenix. It can be used in a standalone mix project with no problem so adding something like the RepositoryWatcher POCdefmodule PardallMarkdown.RepositoryWatcher do
use GenServer
require Logger
alias PardallMarkdown.RepositoryProvider, as: Repository
@recheck_interval Application.get_env(:pardall_markdown, PardallMarkdown.Content)[:recheck_pending_remote_events_interval]
def start_link(args) do
GenServer.start_link(__MODULE__, args, args)
end
def init(args) do
# Fetch the repository or create a local git repo if remote source not found.
Repository.repository()
# Is it possible to update the config at runtime so the `root_path` is updated?
# If not how does the FileWatcher subscribe to the path being created here?
# My assumption is that if a `remote_source` is provided and we are executing in Mix.env() == :dev
# the local_path is pointing to the local git repository and any polling of the remote is disabled.
# When executing in Mix.env() == :prod then the callbacks associated with listening on the remote are enabled.
# Start Polling
schedule_next_recheck()
# Send out message on the initialized state of the GenServer.
{:ok, %{}}
end
def handle_info() when Mix.env() == :dev, do: # do things with the local git repository "FileWatcher"
def handle_info() when Mix.env() == :prod, do: # do things with remote_source "FileWatcher + RepositoryWatcher"
defp schedule_next_recheck, do: Process.send_after(self(), :check_pending_events, @recheck_interval)
end Other Thoughts Not Relevant To the Above 😂Also just a thought, but I would figure that this feature could extend past just Thank you for your patience with a noobie 🙏🏻 |
Nice questions, @rockchalkwushock.
It's because it's not necessary.
Yes, but then we would implement something like webhooks, so the headless CMS can call PardallMarkdown webhooks and we refresh the content. But this is separate from implementing the Git provider. We can also always refactor later.
Use the same format as FileWatcher is started, passing configuration at runtime, either via a helper function or directly via {
PardallMarkdown.FileWatcher,
name: PardallMarkdown.FileWatcher, dirs: [PardallMarkdown.Content.Utils.root_path()]
}
I think this is answered above, but let's explain the order of execution of a PardallMarkdown application: Fresh Start
Lifecycle
|
@alfredbaudisch sorry for the late reply I am just now seeing this. I will see if I can get around to writing the implementation tomorrow for this. |
@alfredbaudisch I think I've just about got it where it needs to be. There are a few known bugs at the moment
|
Thank you! Gonna check it out by the weekend. |
…is the path which FileWatcher watches, the idea is to keep the content logic in a single path as consistency; removed unused functions and callbacks; do not crash in case of existing repository, do not try to clone if the repo exists; crash in case the local cloned repository has local changes
@rockchalkwushock I committed the final changes needed to make the feature work. My changes also answer your last questions. I greatly simplified repository_providers/git.ex, and added the necessary fixes/additions to make it correctly work with
Do you want to add something more? If no, then it is ready to be merged. The CI build fail is not related to this feature, so we can ignore it. |
@alfredbaudisch looking at this now |
@alfredbaudisch everything looks great! Good catch with the hidden files I had not considered that. I also was racking my brain with how to conditionally start the Merge when ready |
@rockchalkwushock well done. Published https://hex.pm/packages/pardall_markdown/0.4.0 - you are also mentioned in the README and the README has instructions regarding to this new feature. |
What does this PR do?
Adds support for users to use git repositories as a data source for PardallMarkdown.
Example
Closes #31