Commit 729207a1 authored by Bakhdaulet's avatar Bakhdaulet Committed by Sander van Harmelen

add new endpoint HEAD get file metadata (#511)

* add HEAD get file metadata

* add new endpoint HEAD GetFileMetaData
parent 06cc3264
......@@ -20,6 +20,7 @@ import (
"bytes"
"fmt"
"net/url"
"strconv"
)
// RepositoryFilesService handles communication with the repository files
......@@ -82,6 +83,53 @@ func (s *RepositoryFilesService) GetFile(pid interface{}, fileName string, opt *
return f, resp, err
}
// GetFileMetaDataOptions represents the available GetFileMetaData() options.
//
// GitLab API docs:
// https://docs.gitlab.com/ce/api/repository_files.html#get-file-from-repository
type GetFileMetaDataOptions struct {
Ref *string `url:"ref,omitempty" json:"ref,omitempty"`
}
// GetFileMetaData allows you to receive meta information about a file in repository like
// name, size.
//
// GitLab API docs:
// https://docs.gitlab.com/ce/api/repository_files.html#get-file-from-repository
func (s *RepositoryFilesService) GetFileMetaData(pid interface{}, fileName string, opt *GetFileMetaDataOptions, options ...OptionFunc) (*File, *Response, error) {
project, err := parseID(pid)
if err != nil {
return nil, nil, err
}
u := fmt.Sprintf("projects/%s/repository/files/%s", url.QueryEscape(project), url.PathEscape(fileName))
req, err := s.client.NewRequest("HEAD", u, opt, options)
if err != nil {
return nil, nil, err
}
f := new(File)
resp, err := s.client.Do(req, nil)
if err != nil {
return nil, resp, err
}
f.BlobID = resp.Header.Get("X-Gitlab-Blob-Id")
f.CommitID = resp.Header.Get("X-Gitlab-Last-Commit-Id")
f.Encoding = resp.Header.Get("X-Gitlab-Encoding")
f.FileName = resp.Header.Get("X-Gitlab-File-Name")
f.FilePath = resp.Header.Get("X-Gitlab-File-Path")
f.Ref = resp.Header.Get("X-Gitlab-Ref")
if sizeString := resp.Header.Get("X-Gitlab-Size"); sizeString != "" {
f.Size, err = strconv.Atoi(sizeString)
if err != nil {
return nil, resp, err
}
}
return f, resp, err
}
// GetRawFileOptions represents the available GetRawFile() options.
//
// GitLab API docs:
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment