Skip to content
This repository has been archived by the owner on Jun 8, 2019. It is now read-only.

Adds structures for repo file and blob APIs #152

Merged
14 changes: 14 additions & 0 deletions gitea/git_blob.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
// Copyright 2019 The Gitea Authors. All rights reserved.
// Use of this source code is governed by a MIT-style
// license that can be found in the LICENSE file.

package gitea

// GitBlobResponse represents a git blob
type GitBlobResponse struct {
Content string `json:"content"`
Encoding string `json:"encoding"`
URL string `json:"url"`
SHA string `json:"sha"`
Size int64 `json:"size"`
}
86 changes: 86 additions & 0 deletions gitea/repo_file.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,3 +13,89 @@ import (
func (c *Client) GetFile(user, repo, ref, tree string) ([]byte, error) {
return c.getResponse("GET", fmt.Sprintf("/repos/%s/%s/raw/%s/%s", user, repo, ref, tree), nil, nil)
}

richmahn marked this conversation as resolved.
Show resolved Hide resolved
// IdentityOptions for a person's identity like an author or committer
type IdentityOptions struct {
richmahn marked this conversation as resolved.
Show resolved Hide resolved
Name string `json:"name" binding:"MaxSize(100)"`
// swagger:strfmt email
Email string `json:"email" binding:"MaxSize(254)"`
}

// FileOptions options for all file APIs
type FileOptions struct {
Message string `json:"message"" binding:"Required"`
techknowlogick marked this conversation as resolved.
Show resolved Hide resolved
BranchName string `json:"branch"`
NewBranchName string `json:"new_branch"`
Author IdentityOptions `json:"author"`
Committer IdentityOptions `json:"committer"`
}

// CreateFileOptions options for creating files
type CreateFileOptions struct {
*FileOptions
Content string `json:"content"`
}

// DeleteFileOptions options for deleting files (used for other File structs below)
type DeleteFileOptions struct {
*FileOptions
SHA string `json:"sha" binding:"Required"`
}

// UpdateFileOptions options for updating files
type UpdateFileOptions struct {
*DeleteFileOptions
Content string `json:"content"`
FromPath string `json:"from_path binding:"MaxSize(500)`
}

// FileLinksResponse contains the links for a repo's file
type FileLinksResponse struct {
Self string `json:"url"`
GitURL string `json:"git_url"`
HTMLURL string `json:"html_url"`
}

// FileContent contains information about a repo's file stats and content
type FileContentResponse struct {
Name string `json:"name"`
Path string `json:"path"`
SHA string `json:"sha"`
Size int64 `json:"size"`
URL string `json:"url"`
HTMLURL string `json:"html_url"`
GitURL string `json:"git_url"`
DownloadURL string `json:"download_url"`
Type string `json:"type"`
Links *FileLinksResponse `json:"_links"`
}

// FileCommit contains information generated from a Git commit for a repo's file.
type FileCommitResponse struct {
*CommitMeta
HTMLURL string `json:"html_url"`
Author *CommitUser `json:"author"`
Committer *CommitUser `json:"committer"`
Parents []*CommitMeta `json:"parents"`
Message string `json:"message"`
Tree *CommitMeta `json:"tree"`
}

// FileResponse contains information about a repo's file
type FileResponse struct {
Content *FileContentResponse `json:"content"`
Commit *FileCommitResponse `json:"commit"`
Verification *PayloadCommitVerification `json:"verification"`
}

// FileDeleteResponse contains information about a repo's file that was deleted
type FileDeleteResponse struct {
Content interface{} `json:"content"` // to be set to nil
Commit *FileCommitResponse `json:"commit"`
Verification *PayloadCommitVerification `json:"verification"`
}

type FileError struct {
Message string `json:"message"`
DocumentationUrl string ``
}