This is an automated email from the ASF dual-hosted git repository.
xuanwo pushed a commit to branch main
in repository https://gitbox.apache.org/repos/asf/opendal.git
The following commit(s) were added to refs/heads/main by this push:
new fa4c7ee61 feat(services/github): Implement write returns metadata
(#6806)
fa4c7ee61 is described below
commit fa4c7ee618ad5d237146d1166fabc81751e575d6
Author: GUAN-HAO HUANG <[email protected]>
AuthorDate: Thu Nov 20 16:37:43 2025 +0800
feat(services/github): Implement write returns metadata (#6806)
github
---
core/src/services/github/core.rs | 5 +++++
core/src/services/github/writer.rs | 25 ++++++++++++++++++++++++-
2 files changed, 29 insertions(+), 1 deletion(-)
diff --git a/core/src/services/github/core.rs b/core/src/services/github/core.rs
index d7a19afa1..55b1686ae 100644
--- a/core/src/services/github/core.rs
+++ b/core/src/services/github/core.rs
@@ -348,3 +348,8 @@ pub struct Entry {
#[serde(rename = "type")]
pub type_field: String,
}
+
+#[derive(Default, Debug, Clone, Deserialize)]
+pub struct ContentResponse {
+ pub content: Entry,
+}
diff --git a/core/src/services/github/writer.rs
b/core/src/services/github/writer.rs
index 652a4e483..c8ad090d7 100644
--- a/core/src/services/github/writer.rs
+++ b/core/src/services/github/writer.rs
@@ -17,6 +17,7 @@
use std::sync::Arc;
+use bytes::Buf;
use http::StatusCode;
use super::core::GithubCore;
@@ -35,6 +36,22 @@ impl GithubWriter {
pub fn new(core: Arc<GithubCore>, path: String) -> Self {
GithubWriter { core, path }
}
+
+ fn parse_metadata(content: &super::core::Entry) -> Result<Metadata> {
+ let mode = if content.type_field == "dir" {
+ EntryMode::DIR
+ } else {
+ EntryMode::FILE
+ };
+
+ let mut meta = Metadata::new(mode);
+ if mode == EntryMode::FILE {
+ meta.set_content_length(content.size);
+ meta.set_etag(&content.sha);
+ }
+
+ Ok(meta)
+ }
}
impl oio::OneShotWrite for GithubWriter {
@@ -44,7 +61,13 @@ impl oio::OneShotWrite for GithubWriter {
let status = resp.status();
match status {
- StatusCode::OK | StatusCode::CREATED => Ok(Metadata::default()),
+ StatusCode::OK | StatusCode::CREATED => {
+ let body = resp.into_body();
+ let content_resp: super::core::ContentResponse =
+
serde_json::from_reader(body.reader()).map_err(new_json_deserialize_error)?;
+ let metadata =
GithubWriter::parse_metadata(&content_resp.content)?;
+ Ok(metadata)
+ }
_ => Err(parse_error(resp)),
}
}