move images updating here instead of RFD repo
@@ -439,15 +439,30 @@ async fn listen_github_webhooks(rqctx: Arc<RequestContext>, body_param: TypedBod
let mut changed_files = commit.added.clone();
changed_files.append(&mut commit.modified.clone());
for file in changed_files {
- // If the file is not a README.md or README.adoc, skip it.
- // There should only be one per repo, so we will break at the end of this,
- // once we've found one.
- // TODO: handle the updating of images.
- if !file.ends_with("README.md") && !file.ends_with("README.adoc") {
- // Continue through the loop.
+ // Make sure the file has a prefix of "rfd/".
+ if !file.starts_with("rfd/") {
+ // Continue through the loop early.
+ // We only care if a file change in the rfd/ directory.
continue;
}
+ // Update images for the static site.
+ if file.ends_with(".svg") || file.ends_with(".png") || file.ends_with(".jpg") || file.ends_with(".jpeg") {
+ // Some image for an RFD updated. Let's make sure we have that image in the right place
+ // for the RFD shared site.
+ // First, let's read the file contents.
+ let gh_file = github_repo.content().file(&file, branch).await.unwrap();
+ // Let's write the file contents to the location for the static website.
+ // We replace the `rfd/` path with the `src/public/static/images/` path since
+ // this is where images go for the static website.
+ // TODO: On delete of an image file, we should delete the file.
+ create_or_update_file_in_github_repo(&github_repo, branch, &format!("src/public/static/images/{}", file.trim_start_matches("rfd/")), gh_file.content.to_vec()).await;
+ // We are done so we can continue throught the loop.
+ continue;
+ }
+
+ // If the file is a README.md or README.adoc, an RFD doc changed, let's handle it.
+ if file.ends_with("README.md") || file.ends_with("README.adoc") {
// We have a README file that changed, let's parse the RFD and update it
// in our database.
println!("[/github] `{}` event -> file {} was modified on branch {}", event_type.name(), file, branch);
@@ -473,11 +488,13 @@ async fn listen_github_webhooks(rqctx: Arc<RequestContext>, body_param: TypedBod
// TODO: fix this.
// TODO: see if we can make this faster by doing something better than
// dispatching the workflow.
- github_repo
+ api_context
+ .github
+ .repo(github_org(), "configs")
.actions()
.workflows()
.dispatch(
- "run-shorturls.yml",
+ "run-shorturls",
&hubcaps::workflows::WorkflowDispatchOptions::builder().reference(repo.default_branch.to_string()).build(),
)
.await
@@ -606,7 +623,7 @@ async fn listen_github_webhooks(rqctx: Arc<RequestContext>, body_param: TypedBod
}
println!("[/github]: RFD {} updated successfully", rfd.number_string);
- break;
+ }
}
// TODO: should we do something if the file gets deleted (?)
