feat(blogo,gitea): get single commit metadata method

This commit is contained in:
Guz
2025-01-08 00:12:34 -03:00
parent d7e7dc84af
commit a126c1387e

View File

@@ -37,6 +37,7 @@ import (
"io"
"net/http"
"net/url"
"time"
)
type client struct {
@@ -90,6 +91,25 @@ func (c *client) ListContents(
return directory, res, nil
}
func (c *client) GetSingleCommit(user, repo, commitID string) (*commit, *http.Response, error) {
data, res, err := c.get(
fmt.Sprintf("/repos/%s/%s/git/commits/%s", user, repo, commitID),
)
if err != nil {
return &commit{}, res, err
}
var commit *commit
if err := json.Unmarshal(data, commit); err != nil {
return commit, res, errors.Join(
errors.New("failed to parse JSON response from API"),
err,
)
}
return commit, res, err
}
func (c *client) get(path string) (body []byte, res *http.Response, err error) {
res, err = c.http.Get(c.endpoint + path)
if err != nil {
@@ -169,3 +189,9 @@ type fileLinksResponse struct {
GitURL *string `json:"git"`
HTMLURL *string `json:"html"`
}
type commit struct {
URL string `json:"url"`
SHA string `json:"sha"`
Created time.Time `json:"created"`
}