common.go

  1package lfs
  2
  3import "time"
  4
  5const (
  6	// MediaType contains the media type for LFS server requests.
  7	MediaType = "application/vnd.git-lfs+json"
  8
  9	// OperationDownload is the operation name for a download request.
 10	OperationDownload = "download"
 11
 12	// OperationUpload is the operation name for an upload request.
 13	OperationUpload = "upload"
 14
 15	// ActionDownload is the action name for a download request.
 16	ActionDownload = OperationDownload
 17
 18	// ActionUpload is the action name for an upload request.
 19	ActionUpload = OperationUpload
 20
 21	// ActionVerify is the action name for a verify request.
 22	ActionVerify = "verify"
 23)
 24
 25// Pointer contains LFS pointer data
 26type Pointer struct {
 27	Oid  string `json:"oid"`
 28	Size int64  `json:"size"`
 29}
 30
 31// PointerBlob associates a Git blob with a Pointer.
 32type PointerBlob struct {
 33	Hash string
 34	Pointer
 35}
 36
 37// ErrorResponse describes the error to the client.
 38type ErrorResponse struct {
 39	Message          string `json:"message,omitempty"`
 40	DocumentationURL string `json:"documentation_url,omitempty"`
 41	RequestID        string `json:"request_id,omitempty"`
 42}
 43
 44// BatchResponse contains multiple object metadata Representation structures
 45// for use with the batch API.
 46// https://github.com/git-lfs/git-lfs/blob/main/docs/api/batch.md#successful-responses
 47type BatchResponse struct {
 48	Transfer string            `json:"transfer,omitempty"`
 49	Objects  []*ObjectResponse `json:"objects"`
 50	HashAlgo string            `json:"hash_algo,omitempty"`
 51}
 52
 53// ObjectResponse is object metadata as seen by clients of the LFS server.
 54type ObjectResponse struct {
 55	Pointer
 56	Actions map[string]*Link `json:"actions,omitempty"`
 57	Error   *ObjectError     `json:"error,omitempty"`
 58}
 59
 60// Link provides a structure with information about how to access a object.
 61type Link struct {
 62	Href      string            `json:"href"`
 63	Header    map[string]string `json:"header,omitempty"`
 64	ExpiresAt *time.Time        `json:"expires_at,omitempty"`
 65	ExpiresIn *time.Duration    `json:"expires_in,omitempty"`
 66}
 67
 68// ObjectError defines the JSON structure returned to the client in case of an error.
 69type ObjectError struct {
 70	Code    int    `json:"code"`
 71	Message string `json:"message"`
 72}
 73
 74// BatchRequest contains multiple requests processed in one batch operation.
 75// https://github.com/git-lfs/git-lfs/blob/main/docs/api/batch.md#requests
 76type BatchRequest struct {
 77	Operation string     `json:"operation"`
 78	Transfers []string   `json:"transfers,omitempty"`
 79	Ref       *Reference `json:"ref,omitempty"`
 80	Objects   []Pointer  `json:"objects"`
 81	HashAlgo  string     `json:"hash_algo,omitempty"`
 82}
 83
 84// Reference contains a git reference.
 85// https://github.com/git-lfs/git-lfs/blob/main/docs/api/batch.md#ref-property
 86type Reference struct {
 87	Name string `json:"name"`
 88}
 89
 90// LockCreateRequest contains the request data for creating a lock.
 91// https://github.com/git-lfs/git-lfs/blob/main/docs/api/locking.md
 92// https://github.com/git-lfs/git-lfs/blob/main/locking/schemas/http-lock-create-request-schema.json
 93type LockCreateRequest struct {
 94	Path string    `json:"path"`
 95	Ref  Reference `json:"ref"`
 96}
 97
 98// Lock contains the response data for creating a lock.
 99// https://github.com/git-lfs/git-lfs/blob/main/docs/api/locking.md
100// https://github.com/git-lfs/git-lfs/blob/main/locking/schemas/http-lock-create-response-schema.json
101type Lock struct {
102	ID       string `json:"id"`
103	Path     string `json:"path"`
104	LockedAt string `json:"locked_at"`
105	Owner    struct {
106		Name string `json:"name"`
107	} `json:"owner,omitempty"`
108}
109
110// LockDeleteRequest contains the request data for deleting a lock.
111// https://github.com/git-lfs/git-lfs/blob/main/docs/api/locking.md
112// https://github.com/git-lfs/git-lfs/blob/main/locking/schemas/http-lock-delete-request-schema.json
113type LockDeleteRequest struct {
114	Force bool      `json:"force,omitempty"`
115	Ref   Reference `json:"ref,omitempty"`
116}
117
118// LockListResponse contains the response data for listing locks.
119// https://github.com/git-lfs/git-lfs/blob/main/docs/api/locking.md
120// https://github.com/git-lfs/git-lfs/blob/main/locking/schemas/http-lock-list-response-schema.json
121type LockListResponse struct {
122	Locks      []Lock `json:"locks"`
123	NextCursor string `json:"next_cursor,omitempty"`
124}
125
126// LockVerifyRequest contains the request data for verifying a lock.
127type LockVerifyRequest struct {
128	Ref    Reference `json:"ref"`
129	Cursor string    `json:"cursor,omitempty"`
130	Limit  int       `json:"limit,omitempty"`
131}
132
133// LockVerifyResponse contains the response data for verifying a lock.
134// https://github.com/git-lfs/git-lfs/blob/main/docs/api/locking.md
135// https://github.com/git-lfs/git-lfs/blob/main/locking/schemas/http-lock-verify-response-schema.json
136type LockVerifyResponse struct {
137	Ours       []Lock `json:"ours"`
138	Theirs     []Lock `json:"theirs"`
139	NextCursor string `json:"next_cursor,omitempty"`
140}