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

Commit 10ebef4

Browse files
richmahnzeripath
authored andcommitted
Adds structures for repo file and blob APIs (#152)
* Adds structures for repo file and blob APIs * Updates Git Blob * Moves IdentityOptions to Identity in repo_commit for reusability * Formatting * Fixed quote * Fix to json variable * Fixes to comments * Adds copyright to header * Removes unused code * Makes author and committer pointers * Removes Identity from being a pointer * proper struct
1 parent 4551623 commit 10ebef4

File tree

3 files changed

+98
-3
lines changed

3 files changed

+98
-3
lines changed

gitea/git_blob.go

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
// Copyright 2019 The Gitea Authors. All rights reserved.
2+
// Use of this source code is governed by a MIT-style
3+
// license that can be found in the LICENSE file.
4+
5+
package gitea
6+
7+
// GitBlobResponse represents a git blob
8+
type GitBlobResponse struct {
9+
Content string `json:"content"`
10+
Encoding string `json:"encoding"`
11+
URL string `json:"url"`
12+
SHA string `json:"sha"`
13+
Size int64 `json:"size"`
14+
}

gitea/repo_commit.go

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,13 @@ import (
99
"fmt"
1010
)
1111

12+
// Identity for a person's identity like an author or committer
13+
type Identity struct {
14+
Name string `json:"name" binding:"MaxSize(100)"`
15+
// swagger:strfmt email
16+
Email string `json:"email" binding:"MaxSize(254)"`
17+
}
18+
1219
// CommitMeta contains meta information of a commit in terms of API.
1320
type CommitMeta struct {
1421
URL string `json:"url"`
@@ -17,9 +24,8 @@ type CommitMeta struct {
1724

1825
// CommitUser contains information of a user in the context of a commit.
1926
type CommitUser struct {
20-
Name string `json:"name"`
21-
Email string `json:"email"`
22-
Date string `json:"date"`
27+
Identity
28+
Date string `json:"date"`
2329
}
2430

2531
// RepoCommit contains information of a commit in the context of a repository.

gitea/repo_file.go

Lines changed: 75 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
// Copyright 2014 The Gogs Authors. All rights reserved.
2+
// Copyright 2019 The Gitea Authors. All rights reserved.
23
// Use of this source code is governed by a MIT-style
34
// license that can be found in the LICENSE file.
45

@@ -13,3 +14,77 @@ import (
1314
func (c *Client) GetFile(user, repo, ref, tree string) ([]byte, error) {
1415
return c.getResponse("GET", fmt.Sprintf("/repos/%s/%s/raw/%s/%s", user, repo, ref, tree), nil, nil)
1516
}
17+
18+
// FileOptions options for all file APIs
19+
type FileOptions struct {
20+
Message string `json:"message" binding:"Required"`
21+
BranchName string `json:"branch"`
22+
NewBranchName string `json:"new_branch"`
23+
Author Identity `json:"author"`
24+
Committer Identity `json:"committer"`
25+
}
26+
27+
// CreateFileOptions options for creating files
28+
type CreateFileOptions struct {
29+
FileOptions
30+
Content string `json:"content"`
31+
}
32+
33+
// DeleteFileOptions options for deleting files (used for other File structs below)
34+
type DeleteFileOptions struct {
35+
FileOptions
36+
SHA string `json:"sha" binding:"Required"`
37+
}
38+
39+
// UpdateFileOptions options for updating files
40+
type UpdateFileOptions struct {
41+
DeleteFileOptions
42+
Content string `json:"content"`
43+
FromPath string `json:"from_path" binding:"MaxSize(500)"`
44+
}
45+
46+
// FileLinksResponse contains the links for a repo's file
47+
type FileLinksResponse struct {
48+
Self string `json:"url"`
49+
GitURL string `json:"git_url"`
50+
HTMLURL string `json:"html_url"`
51+
}
52+
53+
// FileContentResponse contains information about a repo's file stats and content
54+
type FileContentResponse struct {
55+
Name string `json:"name"`
56+
Path string `json:"path"`
57+
SHA string `json:"sha"`
58+
Size int64 `json:"size"`
59+
URL string `json:"url"`
60+
HTMLURL string `json:"html_url"`
61+
GitURL string `json:"git_url"`
62+
DownloadURL string `json:"download_url"`
63+
Type string `json:"type"`
64+
Links *FileLinksResponse `json:"_links"`
65+
}
66+
67+
// FileCommitResponse contains information generated from a Git commit for a repo's file.
68+
type FileCommitResponse struct {
69+
CommitMeta
70+
HTMLURL string `json:"html_url"`
71+
Author *CommitUser `json:"author"`
72+
Committer *CommitUser `json:"committer"`
73+
Parents []*CommitMeta `json:"parents"`
74+
Message string `json:"message"`
75+
Tree *CommitMeta `json:"tree"`
76+
}
77+
78+
// FileResponse contains information about a repo's file
79+
type FileResponse struct {
80+
Content *FileContentResponse `json:"content"`
81+
Commit *FileCommitResponse `json:"commit"`
82+
Verification *PayloadCommitVerification `json:"verification"`
83+
}
84+
85+
// FileDeleteResponse contains information about a repo's file that was deleted
86+
type FileDeleteResponse struct {
87+
Content interface{} `json:"content"` // to be set to nil
88+
Commit *FileCommitResponse `json:"commit"`
89+
Verification *PayloadCommitVerification `json:"verification"`
90+
}

0 commit comments

Comments
 (0)