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

Commit f326421

Browse files
committed
Merge branch 'master' of github.com:go-gitea/go-sdk
2 parents fe19296 + 8718470 commit f326421

File tree

7 files changed

+194
-33
lines changed

7 files changed

+194
-33
lines changed

MAINTAINERS

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,3 +19,4 @@ Jonas Östanbäck <[email protected]> (@cez81)
1919
David Schneiderbauer <[email protected]> (@daviian)
2020
Peter Žeby <[email protected]> (@morlinest)
2121
Jonas Franz <[email protected]> (@JonasFranzDEV)
22+
Alexey Terentyev <[email protected]> (@axifive)

gitea/admin_user.go

Lines changed: 11 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -42,15 +42,17 @@ type EditUserOption struct {
4242
FullName string `json:"full_name" binding:"MaxSize(100)"`
4343
// required: true
4444
// swagger:strfmt email
45-
Email string `json:"email" binding:"Required;Email;MaxSize(254)"`
46-
Password string `json:"password" binding:"MaxSize(255)"`
47-
Website string `json:"website" binding:"MaxSize(50)"`
48-
Location string `json:"location" binding:"MaxSize(50)"`
49-
Active *bool `json:"active"`
50-
Admin *bool `json:"admin"`
51-
AllowGitHook *bool `json:"allow_git_hook"`
52-
AllowImportLocal *bool `json:"allow_import_local"`
53-
MaxRepoCreation *int `json:"max_repo_creation"`
45+
Email string `json:"email" binding:"Required;Email;MaxSize(254)"`
46+
Password string `json:"password" binding:"MaxSize(255)"`
47+
Website string `json:"website" binding:"MaxSize(50)"`
48+
Location string `json:"location" binding:"MaxSize(50)"`
49+
Active *bool `json:"active"`
50+
Admin *bool `json:"admin"`
51+
AllowGitHook *bool `json:"allow_git_hook"`
52+
AllowImportLocal *bool `json:"allow_import_local"`
53+
MaxRepoCreation *int `json:"max_repo_creation"`
54+
ProhibitLogin *bool `json:"prohibit_login"`
55+
AllowCreateOrganization *bool `json:"allow_create_organization"`
5456
}
5557

5658
// AdminEditUser modify user informations

gitea/hook.go

Lines changed: 124 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -172,9 +172,14 @@ type PayloadCommitVerification struct {
172172

173173
var (
174174
_ Payloader = &CreatePayload{}
175+
_ Payloader = &DeletePayload{}
176+
_ Payloader = &ForkPayload{}
175177
_ Payloader = &PushPayload{}
176178
_ Payloader = &IssuePayload{}
179+
_ Payloader = &IssueCommentPayload{}
177180
_ Payloader = &PullRequestPayload{}
181+
_ Payloader = &RepositoryPayload{}
182+
_ Payloader = &ReleasePayload{}
178183
)
179184

180185
// _________ __
@@ -224,6 +229,125 @@ func ParseCreateHook(raw []byte) (*CreatePayload, error) {
224229
return hook, nil
225230
}
226231

232+
// ________ .__ __
233+
// \______ \ ____ | | _____/ |_ ____
234+
// | | \_/ __ \| | _/ __ \ __\/ __ \
235+
// | ` \ ___/| |_\ ___/| | \ ___/
236+
// /_______ /\___ >____/\___ >__| \___ >
237+
// \/ \/ \/ \/
238+
239+
// PusherType define the type to push
240+
type PusherType string
241+
242+
// describe all the PusherTypes
243+
const (
244+
PusherTypeUser PusherType = "user"
245+
)
246+
247+
// DeletePayload represents delete payload
248+
type DeletePayload struct {
249+
Ref string `json:"ref"`
250+
RefType string `json:"ref_type"`
251+
PusherType PusherType `json:"pusher_type"`
252+
Repo *Repository `json:"repository"`
253+
Sender *User `json:"sender"`
254+
}
255+
256+
// SetSecret implements Payload
257+
func (p *DeletePayload) SetSecret(secret string) {
258+
}
259+
260+
// JSONPayload implements Payload
261+
func (p *DeletePayload) JSONPayload() ([]byte, error) {
262+
return json.MarshalIndent(p, "", " ")
263+
}
264+
265+
// ___________ __
266+
// \_ _____/__________| | __
267+
// | __)/ _ \_ __ \ |/ /
268+
// | \( <_> ) | \/ <
269+
// \___ / \____/|__| |__|_ \
270+
// \/ \/
271+
272+
// ForkPayload represents fork payload
273+
type ForkPayload struct {
274+
Forkee *Repository `json:"forkee"`
275+
Repo *Repository `json:"repository"`
276+
Sender *User `json:"sender"`
277+
}
278+
279+
// SetSecret implements Payload
280+
func (p *ForkPayload) SetSecret(secret string) {
281+
}
282+
283+
// JSONPayload implements Payload
284+
func (p *ForkPayload) JSONPayload() ([]byte, error) {
285+
return json.MarshalIndent(p, "", " ")
286+
}
287+
288+
// HookIssueCommentAction defines hook issue comment action
289+
type HookIssueCommentAction string
290+
291+
// all issue comment actions
292+
const (
293+
HookIssueCommentCreated HookIssueCommentAction = "created"
294+
HookIssueCommentEdited HookIssueCommentAction = "edited"
295+
HookIssueCommentDeleted HookIssueCommentAction = "deleted"
296+
)
297+
298+
// IssueCommentPayload represents a payload information of issue comment event.
299+
type IssueCommentPayload struct {
300+
Action HookIssueCommentAction `json:"action"`
301+
Issue *Issue `json:"issue"`
302+
Comment *Comment `json:"comment"`
303+
Changes *ChangesPayload `json:"changes,omitempty"`
304+
Repository *Repository `json:"repository"`
305+
Sender *User `json:"sender"`
306+
}
307+
308+
// SetSecret implements Payload
309+
func (p *IssueCommentPayload) SetSecret(secret string) {
310+
}
311+
312+
// JSONPayload implements Payload
313+
func (p *IssueCommentPayload) JSONPayload() ([]byte, error) {
314+
return json.MarshalIndent(p, "", " ")
315+
}
316+
317+
// __________ .__
318+
// \______ \ ____ | | ____ _____ ______ ____
319+
// | _// __ \| | _/ __ \\__ \ / ___// __ \
320+
// | | \ ___/| |_\ ___/ / __ \_\___ \\ ___/
321+
// |____|_ /\___ >____/\___ >____ /____ >\___ >
322+
// \/ \/ \/ \/ \/ \/
323+
324+
// HookReleaseAction defines hook release action type
325+
type HookReleaseAction string
326+
327+
// all release actions
328+
const (
329+
HookReleasePublished HookReleaseAction = "published"
330+
HookReleaseUpdated HookReleaseAction = "updated"
331+
HookReleaseDeleted HookReleaseAction = "deleted"
332+
)
333+
334+
// ReleasePayload represents a payload information of release event.
335+
type ReleasePayload struct {
336+
Action HookReleaseAction `json:"action"`
337+
Release *Release `json:"release"`
338+
Repository *Repository `json:"repository"`
339+
Sender *User `json:"sender"`
340+
}
341+
342+
// SetSecret implements Payload
343+
func (p *ReleasePayload) SetSecret(secret string) {
344+
}
345+
346+
// JSONPayload implements Payload
347+
func (p *ReleasePayload) JSONPayload() ([]byte, error) {
348+
return json.MarshalIndent(p, "", " ")
349+
}
350+
227351
// __________ .__
228352
// \______ \__ __ _____| |__
229353
// | ___/ | \/ ___/ | \

gitea/issue.go

Lines changed: 27 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -118,14 +118,14 @@ func (c *Client) CreateIssue(owner, repo string, opt CreateIssueOption) (*Issue,
118118

119119
// EditIssueOption options for editing an issue
120120
type EditIssueOption struct {
121-
Title string `json:"title"`
122-
Body *string `json:"body"`
123-
Assignee *string `json:"assignee"`
124-
Assignees []string `json:"assignees"`
125-
Milestone *int64 `json:"milestone"`
126-
State *string `json:"state"`
121+
Title string `json:"title"`
122+
Body *string `json:"body"`
123+
Assignee *string `json:"assignee"`
124+
Assignees []string `json:"assignees"`
125+
Milestone *int64 `json:"milestone"`
126+
State *string `json:"state"`
127127
// swagger:strfmt date-time
128-
Deadline *time.Time `json:"due_date"`
128+
Deadline *time.Time `json:"due_date"`
129129
}
130130

131131
// EditIssue modify an existing issue for a given repository
@@ -138,3 +138,23 @@ func (c *Client) EditIssue(owner, repo string, index int64, opt EditIssueOption)
138138
return issue, c.getParsedResponse("PATCH", fmt.Sprintf("/repos/%s/%s/issues/%d", owner, repo, index),
139139
jsonHeader, bytes.NewReader(body), issue)
140140
}
141+
142+
// EditDeadlineOption options for creating a deadline
143+
type EditDeadlineOption struct {
144+
// required:true
145+
// swagger:strfmt date-time
146+
Deadline *time.Time `json:"due_date"`
147+
}
148+
149+
// IssueDeadline represents an issue deadline
150+
// swagger:model
151+
type IssueDeadline struct {
152+
// swagger:strfmt date-time
153+
Deadline *time.Time `json:"due_date"`
154+
}
155+
156+
// EditPriorityOption options for updating priority
157+
type EditPriorityOption struct {
158+
// required:true
159+
Priority int `json:"priority"`
160+
}

gitea/pull.go

Lines changed: 17 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -85,16 +85,16 @@ func (c *Client) GetPullRequest(owner, repo string, index int64) (*PullRequest,
8585

8686
// CreatePullRequestOption options when creating a pull request
8787
type CreatePullRequestOption struct {
88-
Head string `json:"head" binding:"Required"`
89-
Base string `json:"base" binding:"Required"`
90-
Title string `json:"title" binding:"Required"`
91-
Body string `json:"body"`
92-
Assignee string `json:"assignee"`
93-
Assignees []string `json:"assignees"`
94-
Milestone int64 `json:"milestone"`
95-
Labels []int64 `json:"labels"`
88+
Head string `json:"head" binding:"Required"`
89+
Base string `json:"base" binding:"Required"`
90+
Title string `json:"title" binding:"Required"`
91+
Body string `json:"body"`
92+
Assignee string `json:"assignee"`
93+
Assignees []string `json:"assignees"`
94+
Milestone int64 `json:"milestone"`
95+
Labels []int64 `json:"labels"`
9696
// swagger:strfmt date-time
97-
Deadline *time.Time `json:"due_date"`
97+
Deadline *time.Time `json:"due_date"`
9898
}
9999

100100
// CreatePullRequest create pull request with options
@@ -110,15 +110,15 @@ func (c *Client) CreatePullRequest(owner, repo string, opt CreatePullRequestOpti
110110

111111
// EditPullRequestOption options when modify pull request
112112
type EditPullRequestOption struct {
113-
Title string `json:"title"`
114-
Body string `json:"body"`
115-
Assignee string `json:"assignee"`
116-
Assignees []string `json:"assignees"`
117-
Milestone int64 `json:"milestone"`
118-
Labels []int64 `json:"labels"`
119-
State *string `json:"state"`
113+
Title string `json:"title"`
114+
Body string `json:"body"`
115+
Assignee string `json:"assignee"`
116+
Assignees []string `json:"assignees"`
117+
Milestone int64 `json:"milestone"`
118+
Labels []int64 `json:"labels"`
119+
State *string `json:"state"`
120120
// swagger:strfmt date-time
121-
Deadline *time.Time `json:"due_date"`
121+
Deadline *time.Time `json:"due_date"`
122122
}
123123

124124
// EditPullRequest modify pull request with PR id and options

gitea/user.go

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -42,3 +42,10 @@ func (c *Client) GetUserInfo(user string) (*User, error) {
4242
err := c.getParsedResponse("GET", fmt.Sprintf("/users/%s", user), nil, nil, u)
4343
return u, err
4444
}
45+
46+
// GetMyUserInfo get user info of current user
47+
func (c *Client) GetMyUserInfo() (*User, error) {
48+
u := new(User)
49+
err := c.getParsedResponse("GET", "/user", nil, nil, u)
50+
return u, err
51+
}

gitea/user_app.go

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@ func BasicAuthEncode(user, pass string) string {
2020
// AccessToken represents a API access token.
2121
// swagger:response AccessToken
2222
type AccessToken struct {
23+
ID int64 `json:"id"`
2324
Name string `json:"name"`
2425
Sha1 string `json:"sha1"`
2526
}
@@ -54,3 +55,9 @@ func (c *Client) CreateAccessToken(user, pass string, opt CreateAccessTokenOptio
5455
"Authorization": []string{"Basic " + BasicAuthEncode(user, pass)}},
5556
bytes.NewReader(body), t)
5657
}
58+
59+
// DeleteAccessToken delete token with key id
60+
func (c *Client) DeleteAccessToken(user string, keyID int64) error {
61+
_, err := c.getResponse("DELETE", fmt.Sprintf("/user/%s/tokens/%d", user, keyID), nil, nil)
62+
return err
63+
}

0 commit comments

Comments
 (0)