Compare commits
54 Commits
Author | SHA1 | Date | |
---|---|---|---|
|
6abdddefe3 | ||
|
d9394234b9 | ||
|
d95a6e0392 | ||
|
545830e497 | ||
59ddbdc4be | |||
|
4f96d9ac89 | ||
|
c740b5dd58 | ||
11c860c8e4 | |||
|
2d00f9f4d4 | ||
|
86b999eaa8 | ||
1819385edd | |||
|
7072e1b688 | ||
380b28413e | |||
|
8718470818 | ||
|
aa2397dec8 | ||
|
021567c9c1 | ||
|
79a281c4e3 | ||
9c719de11f | |||
|
ec80752c95 | ||
|
b2308e3f70 | ||
|
7fa627fa5d | ||
40e36e1d2f | |||
1c8d12f79a | |||
142acef5ce | |||
790adaa56b | |||
ea7eeee318 | |||
417abc7c5d | |||
92585b27a0 | |||
39c609e903 | |||
fa91af7569 | |||
cdbef99766 | |||
c026786979 | |||
|
649bdad70e | ||
|
0489f9e4e0 | ||
|
a184f2d334 | ||
|
7296e60b71 | ||
|
bc3f4f78c7 | ||
|
79eee8f12c | ||
|
24adbb03ee | ||
|
4319a1eaff | ||
|
1da52cf95f | ||
|
4eb2c55b4c | ||
|
fc9011e1a1 | ||
|
60c60488f2 | ||
|
2a89a15ce3 | ||
|
efc028eef5 | ||
|
de5155068d | ||
|
11e0aa8cd4 | ||
|
bc243ad6c2 | ||
82df6bc38d | |||
|
90a25c110c | ||
c7c050c877 | |||
|
9990008755 | ||
|
0ccfe01abb |
25
.drone.yml
25
.drone.yml
|
@ -2,9 +2,15 @@ workspace:
|
||||||
base: /srv/app
|
base: /srv/app
|
||||||
path: src/code.gitea.io/sdk
|
path: src/code.gitea.io/sdk
|
||||||
|
|
||||||
|
clone:
|
||||||
|
git:
|
||||||
|
image: plugins/git:1
|
||||||
|
depth: 50
|
||||||
|
tags: true
|
||||||
|
|
||||||
pipeline:
|
pipeline:
|
||||||
testing:
|
testing:
|
||||||
image: webhippie/golang:latest
|
image: webhippie/golang:edge
|
||||||
pull: true
|
pull: true
|
||||||
commands:
|
commands:
|
||||||
- make clean
|
- make clean
|
||||||
|
@ -13,9 +19,16 @@ pipeline:
|
||||||
- make test
|
- make test
|
||||||
- make build
|
- make build
|
||||||
|
|
||||||
coverage:
|
# coverage:
|
||||||
image: plugins/coverage
|
# image: plugins/coverage:1
|
||||||
server: https://coverage.gitea.io
|
# pull: true
|
||||||
|
# secrets: [ github_token ]
|
||||||
|
# server: https://coverage.gitea.io
|
||||||
|
|
||||||
gitter:
|
discord:
|
||||||
image: plugins/gitter
|
image: appleboy/drone-discord:1.0.0
|
||||||
|
pull: true
|
||||||
|
secrets: [ discord_webhook_id, discord_webhook_token ]
|
||||||
|
when:
|
||||||
|
event: [ push, tag, pull_request ]
|
||||||
|
status: [ changed, failure ]
|
||||||
|
|
|
@ -1 +0,0 @@
|
||||||
eyJhbGciOiJIUzI1NiJ9.d29ya3NwYWNlOgogIGJhc2U6IC9zcnYvYXBwCiAgcGF0aDogc3JjL2NvZGUuZ2l0ZWEuaW8vc2RrCgpwaXBlbGluZToKICB0ZXN0aW5nOgogICAgaW1hZ2U6IHdlYmhpcHBpZS9nb2xhbmc6bGF0ZXN0CiAgICBwdWxsOiB0cnVlCiAgICBjb21tYW5kczoKICAgICAgLSBtYWtlIGNsZWFuCiAgICAgIC0gbWFrZSB2ZXQKICAgICAgLSBtYWtlIGxpbnQKICAgICAgLSBtYWtlIHRlc3QKICAgICAgLSBtYWtlIGJ1aWxkCgogIGNvdmVyYWdlOgogICAgaW1hZ2U6IHBsdWdpbnMvY292ZXJhZ2UKICAgIHNlcnZlcjogaHR0cHM6Ly9jb3ZlcmFnZS5naXRlYS5pbwoKICBnaXR0ZXI6CiAgICBpbWFnZTogcGx1Z2lucy9naXR0ZXIK.HIbwP8NEFAdT6Nfjgw2OCVpvO3cE_YTxA-Xwxwevd2A
|
|
|
@ -15,10 +15,14 @@ indent_size = 8
|
||||||
indent_style = tab
|
indent_style = tab
|
||||||
indent_size = 4
|
indent_size = 4
|
||||||
|
|
||||||
[*.{less,yml}]
|
[*.{less}]
|
||||||
indent_style = space
|
indent_style = space
|
||||||
indent_size = 4
|
indent_size = 4
|
||||||
|
|
||||||
|
[*.{yml}]
|
||||||
|
indent_style = space
|
||||||
|
indent_size = 2
|
||||||
|
|
||||||
[*.js]
|
[*.js]
|
||||||
indent_style = space
|
indent_style = space
|
||||||
indent_size = 4
|
indent_size = 4
|
||||||
|
|
14
.github/issue_template.md
vendored
14
.github/issue_template.md
vendored
|
@ -1,6 +1,8 @@
|
||||||
1. Please speak English, this is the language everybody of us can speak and write.
|
<!--
|
||||||
2. Please ask questions or config/deploy problems on our Gitter channel: https://gitter.im/go-gitea/gitea
|
1. Please speak English, this is the language all of us can speak and write.
|
||||||
3. Please take a moment to search that an issue doesn't already exist.
|
2. Please ask questions or configuration/deploy problems on our Discord
|
||||||
4. Please give all relevant information below for bug reports, incomplete details will be handled as an invalid report.
|
server (https://discord.gg/NsatcWJ) or forum (https://discourse.gitea.io).
|
||||||
|
3. Please take a moment to check that your issue doesn't already exist.
|
||||||
**You MUST delete the content above including this line before posting, otherwise your issue will be invalid.**
|
4. Please give all relevant information below for bug reports, because
|
||||||
|
incomplete details will be handled as an invalid report.
|
||||||
|
-->
|
||||||
|
|
3
.lgtm
3
.lgtm
|
@ -1,2 +1,3 @@
|
||||||
self_approval_off = false
|
pattern = "(?)LGTM"
|
||||||
|
self_approval_off = true
|
||||||
ignore_maintainers_file = true
|
ignore_maintainers_file = true
|
||||||
|
|
|
@ -7,6 +7,7 @@ Kim Carlbäcker <kim.carlbacker@gmail.com> (@bkcsoft)
|
||||||
LefsFlare <nobody@nobody.tld> (@LefsFlarey)
|
LefsFlare <nobody@nobody.tld> (@LefsFlarey)
|
||||||
Lunny Xiao <xiaolunwen@gmail.com> (@lunny)
|
Lunny Xiao <xiaolunwen@gmail.com> (@lunny)
|
||||||
Matthias Loibl <mail@matthiasloibl.com> (@metalmatze)
|
Matthias Loibl <mail@matthiasloibl.com> (@metalmatze)
|
||||||
|
Morgan Bazalgette <the@howl.moe> (@thehowl)
|
||||||
Rachid Zarouali <nobody@nobody.tld> (@xinity)
|
Rachid Zarouali <nobody@nobody.tld> (@xinity)
|
||||||
Rémy Boulanouar <admin@dblk.org> (@DblK)
|
Rémy Boulanouar <admin@dblk.org> (@DblK)
|
||||||
Sandro Santilli <strk@kbt.io> (@strk)
|
Sandro Santilli <strk@kbt.io> (@strk)
|
||||||
|
@ -15,3 +16,9 @@ Thomas Boerger <thomas@webhippie.de> (@tboerger)
|
||||||
Antoine Girard <sapk@sapk.fr> (@sapk)
|
Antoine Girard <sapk@sapk.fr> (@sapk)
|
||||||
Lauris Bukšis-Haberkorns <lauris@nix.lv> (@lafriks)
|
Lauris Bukšis-Haberkorns <lauris@nix.lv> (@lafriks)
|
||||||
Jonas Östanbäck <jonas.ostanback@gmail.com> (@cez81)
|
Jonas Östanbäck <jonas.ostanback@gmail.com> (@cez81)
|
||||||
|
David Schneiderbauer <dschneiderbauer@gmail.com> (@daviian)
|
||||||
|
Peter Žeby <morlinest@gmail.com> (@morlinest)
|
||||||
|
Jonas Franz <info@jonasfranz.software> (@JonasFranzDEV)
|
||||||
|
Alexey Terentyev <axifnx@gmail.com> (@axifive)
|
||||||
|
Konrad Langenberg <k@knt.li> (@kolaente)
|
||||||
|
Andrew Thornton <art27@cantab.net> (@zeripath)
|
||||||
|
|
10
Makefile
10
Makefile
|
@ -1,6 +1,6 @@
|
||||||
IMPORT := code.gitea.io/sdk
|
IMPORT := code.gitea.io/sdk
|
||||||
|
|
||||||
PACKAGES ?= $(shell go list ./... | grep -v /vendor/)
|
PACKAGES ?= $(shell go list -e ./... | grep -v /vendor/ | grep -v /benchmark/)
|
||||||
GENERATE ?= code.gitea.io/sdk/gitea
|
GENERATE ?= code.gitea.io/sdk/gitea
|
||||||
|
|
||||||
.PHONY: all
|
.PHONY: all
|
||||||
|
@ -18,7 +18,7 @@ generate:
|
||||||
|
|
||||||
.PHONY: fmt
|
.PHONY: fmt
|
||||||
fmt:
|
fmt:
|
||||||
find . -name "*.go" -type f -not -path "./vendor/*" | xargs gofmt -s -w
|
find . -name "*.go" -type f ! -path "./vendor/*" ! -path "./benchmark/*" | xargs gofmt -s -w
|
||||||
|
|
||||||
.PHONY: vet
|
.PHONY: vet
|
||||||
vet:
|
vet:
|
||||||
|
@ -27,7 +27,7 @@ vet:
|
||||||
.PHONY: lint
|
.PHONY: lint
|
||||||
lint:
|
lint:
|
||||||
@which golint > /dev/null; if [ $$? -ne 0 ]; then \
|
@which golint > /dev/null; if [ $$? -ne 0 ]; then \
|
||||||
go get -u github.com/golang/lint/golint; \
|
go get -u golang.org/x/lint/golint; \
|
||||||
fi
|
fi
|
||||||
for PKG in $(PACKAGES); do golint -set_exit_status $$PKG || exit 1; done;
|
for PKG in $(PACKAGES); do golint -set_exit_status $$PKG || exit 1; done;
|
||||||
|
|
||||||
|
@ -35,6 +35,10 @@ lint:
|
||||||
test:
|
test:
|
||||||
for PKG in $(PACKAGES); do go test -cover -coverprofile $$GOPATH/src/$$PKG/coverage.out $$PKG || exit 1; done;
|
for PKG in $(PACKAGES); do go test -cover -coverprofile $$GOPATH/src/$$PKG/coverage.out $$PKG || exit 1; done;
|
||||||
|
|
||||||
|
.PHONY: bench
|
||||||
|
bench:
|
||||||
|
go test -run=XXXXXX -benchtime=10s -bench=. || exit 1
|
||||||
|
|
||||||
.PHONY: build
|
.PHONY: build
|
||||||
build:
|
build:
|
||||||
go build ./gitea
|
go build ./gitea
|
||||||
|
|
|
@ -3,7 +3,6 @@
|
||||||
[![Build Status](http://drone.gitea.io/api/badges/go-gitea/go-sdk/status.svg)](http://drone.gitea.io/go-gitea/go-sdk)
|
[![Build Status](http://drone.gitea.io/api/badges/go-gitea/go-sdk/status.svg)](http://drone.gitea.io/go-gitea/go-sdk)
|
||||||
[![Join the chat at https://img.shields.io/discord/322538954119184384.svg](https://img.shields.io/discord/322538954119184384.svg)](https://discord.gg/NsatcWJ)
|
[![Join the chat at https://img.shields.io/discord/322538954119184384.svg](https://img.shields.io/discord/322538954119184384.svg)](https://discord.gg/NsatcWJ)
|
||||||
[![](https://images.microbadger.com/badges/image/gitea/gitea.svg)](http://microbadger.com/images/gitea/gitea "Get your own image badge on microbadger.com")
|
[![](https://images.microbadger.com/badges/image/gitea/gitea.svg)](http://microbadger.com/images/gitea/gitea "Get your own image badge on microbadger.com")
|
||||||
[![Coverage Status](https://coverage.gitea.io/badges/go-gitea/go-sdk/coverage.svg)](https://coverage.gitea.io/go-gitea/go-sdk)
|
|
||||||
[![Go Report Card](https://goreportcard.com/badge/code.gitea.io/sdk)](https://goreportcard.com/report/code.gitea.io/sdk)
|
[![Go Report Card](https://goreportcard.com/badge/code.gitea.io/sdk)](https://goreportcard.com/report/code.gitea.io/sdk)
|
||||||
[![GoDoc](https://godoc.org/code.gitea.io/sdk/gitea?status.svg)](https://godoc.org/code.gitea.io/sdk/gitea)
|
[![GoDoc](https://godoc.org/code.gitea.io/sdk/gitea?status.svg)](https://godoc.org/code.gitea.io/sdk/gitea)
|
||||||
|
|
||||||
|
|
|
@ -12,12 +12,16 @@ import (
|
||||||
|
|
||||||
// CreateUserOption create user options
|
// CreateUserOption create user options
|
||||||
type CreateUserOption struct {
|
type CreateUserOption struct {
|
||||||
SourceID int64 `json:"source_id"`
|
SourceID int64 `json:"source_id"`
|
||||||
LoginName string `json:"login_name"`
|
LoginName string `json:"login_name"`
|
||||||
Username string `json:"username" binding:"Required;AlphaDashDot;MaxSize(35)"`
|
// required: true
|
||||||
FullName string `json:"full_name" binding:"MaxSize(100)"`
|
Username string `json:"username" binding:"Required;AlphaDashDot;MaxSize(35)"`
|
||||||
Email string `json:"email" binding:"Required;Email;MaxSize(254)"`
|
FullName string `json:"full_name" binding:"MaxSize(100)"`
|
||||||
Password string `json:"password" binding:"MaxSize(255)"`
|
// required: true
|
||||||
|
// swagger:strfmt email
|
||||||
|
Email string `json:"email" binding:"Required;Email;MaxSize(254)"`
|
||||||
|
// required: true
|
||||||
|
Password string `json:"password" binding:"Required;MaxSize(255)"`
|
||||||
SendNotify bool `json:"send_notify"`
|
SendNotify bool `json:"send_notify"`
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -33,18 +37,22 @@ func (c *Client) AdminCreateUser(opt CreateUserOption) (*User, error) {
|
||||||
|
|
||||||
// EditUserOption edit user options
|
// EditUserOption edit user options
|
||||||
type EditUserOption struct {
|
type EditUserOption struct {
|
||||||
SourceID int64 `json:"source_id"`
|
SourceID int64 `json:"source_id"`
|
||||||
LoginName string `json:"login_name"`
|
LoginName string `json:"login_name"`
|
||||||
FullName string `json:"full_name" binding:"MaxSize(100)"`
|
FullName string `json:"full_name" binding:"MaxSize(100)"`
|
||||||
Email string `json:"email" binding:"Required;Email;MaxSize(254)"`
|
// required: true
|
||||||
Password string `json:"password" binding:"MaxSize(255)"`
|
// swagger:strfmt email
|
||||||
Website string `json:"website" binding:"MaxSize(50)"`
|
Email string `json:"email" binding:"Required;Email;MaxSize(254)"`
|
||||||
Location string `json:"location" binding:"MaxSize(50)"`
|
Password string `json:"password" binding:"MaxSize(255)"`
|
||||||
Active *bool `json:"active"`
|
Website string `json:"website" binding:"MaxSize(50)"`
|
||||||
Admin *bool `json:"admin"`
|
Location string `json:"location" binding:"MaxSize(50)"`
|
||||||
AllowGitHook *bool `json:"allow_git_hook"`
|
Active *bool `json:"active"`
|
||||||
AllowImportLocal *bool `json:"allow_import_local"`
|
Admin *bool `json:"admin"`
|
||||||
MaxRepoCreation *int `json:"max_repo_creation"`
|
AllowGitHook *bool `json:"allow_git_hook"`
|
||||||
|
AllowImportLocal *bool `json:"allow_import_local"`
|
||||||
|
MaxRepoCreation *int `json:"max_repo_creation"`
|
||||||
|
ProhibitLogin *bool `json:"prohibit_login"`
|
||||||
|
AllowCreateOrganization *bool `json:"allow_create_organization"`
|
||||||
}
|
}
|
||||||
|
|
||||||
// AdminEditUser modify user informations
|
// AdminEditUser modify user informations
|
||||||
|
|
92
gitea/attachment.go
Normal file
92
gitea/attachment.go
Normal file
|
@ -0,0 +1,92 @@
|
||||||
|
// Copyright 2017 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 // import "code.gitea.io/sdk/gitea"
|
||||||
|
import (
|
||||||
|
"bytes"
|
||||||
|
"encoding/json"
|
||||||
|
"fmt"
|
||||||
|
"io"
|
||||||
|
"mime/multipart"
|
||||||
|
"net/http"
|
||||||
|
"time"
|
||||||
|
)
|
||||||
|
|
||||||
|
// Attachment a generic attachment
|
||||||
|
// swagger:model
|
||||||
|
type Attachment struct {
|
||||||
|
ID int64 `json:"id"`
|
||||||
|
Name string `json:"name"`
|
||||||
|
Size int64 `json:"size"`
|
||||||
|
DownloadCount int64 `json:"download_count"`
|
||||||
|
// swagger:strfmt date-time
|
||||||
|
Created time.Time `json:"created_at"`
|
||||||
|
UUID string `json:"uuid"`
|
||||||
|
DownloadURL string `json:"browser_download_url"`
|
||||||
|
}
|
||||||
|
|
||||||
|
// ListReleaseAttachments list release's attachments
|
||||||
|
func (c *Client) ListReleaseAttachments(user, repo string, release int64) ([]*Attachment, error) {
|
||||||
|
attachments := make([]*Attachment, 0, 10)
|
||||||
|
err := c.getParsedResponse("GET",
|
||||||
|
fmt.Sprintf("/repos/%s/%s/releases/%d/assets", user, repo, release),
|
||||||
|
nil, nil, &attachments)
|
||||||
|
return attachments, err
|
||||||
|
}
|
||||||
|
|
||||||
|
// GetReleaseAttachment returns the requested attachment
|
||||||
|
func (c *Client) GetReleaseAttachment(user, repo string, release int64, id int64) (*Attachment, error) {
|
||||||
|
a := new(Attachment)
|
||||||
|
err := c.getParsedResponse("GET",
|
||||||
|
fmt.Sprintf("/repos/%s/%s/releases/%d/assets/%d", user, repo, release, id),
|
||||||
|
nil, nil, &a)
|
||||||
|
return a, err
|
||||||
|
}
|
||||||
|
|
||||||
|
// CreateReleaseAttachment creates an attachment for the given release
|
||||||
|
func (c *Client) CreateReleaseAttachment(user, repo string, release int64, file io.Reader, filename string) (*Attachment, error) {
|
||||||
|
// Write file to body
|
||||||
|
body := new(bytes.Buffer)
|
||||||
|
writer := multipart.NewWriter(body)
|
||||||
|
part, err := writer.CreateFormFile("attachment", filename)
|
||||||
|
if err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
|
||||||
|
if _, err = io.Copy(part, file); err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
if err = writer.Close(); err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
|
||||||
|
// Send request
|
||||||
|
attachment := new(Attachment)
|
||||||
|
err = c.getParsedResponse("POST",
|
||||||
|
fmt.Sprintf("/repos/%s/%s/releases/%d/assets", user, repo, release),
|
||||||
|
http.Header{"Content-Type": {writer.FormDataContentType()}}, body, &attachment)
|
||||||
|
return attachment, err
|
||||||
|
}
|
||||||
|
|
||||||
|
// EditReleaseAttachment updates the given attachment with the given options
|
||||||
|
func (c *Client) EditReleaseAttachment(user, repo string, release int64, attachment int64, form EditAttachmentOptions) (*Attachment, error) {
|
||||||
|
body, err := json.Marshal(&form)
|
||||||
|
if err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
attach := new(Attachment)
|
||||||
|
return attach, c.getParsedResponse("PATCH", fmt.Sprintf("/repos/%s/%s/releases/%d/assets/%d", user, repo, release, attachment), jsonHeader, bytes.NewReader(body), attach)
|
||||||
|
}
|
||||||
|
|
||||||
|
// DeleteReleaseAttachment deletes the given attachment including the uploaded file
|
||||||
|
func (c *Client) DeleteReleaseAttachment(user, repo string, release int64, id int64) error {
|
||||||
|
_, err := c.getResponse("DELETE", fmt.Sprintf("/repos/%s/%s/releases/%d/assets/%d", user, repo, release, id), nil, nil)
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
|
||||||
|
// EditAttachmentOptions options for editing attachments
|
||||||
|
// swagger:model
|
||||||
|
type EditAttachmentOptions struct {
|
||||||
|
Name string `json:"name"`
|
||||||
|
}
|
|
@ -21,6 +21,7 @@ func (c *Client) ListForks(user, repo string) ([]*Repository, error) {
|
||||||
|
|
||||||
// CreateForkOption options for creating a fork
|
// CreateForkOption options for creating a fork
|
||||||
type CreateForkOption struct {
|
type CreateForkOption struct {
|
||||||
|
// organization name, if forking into an organization
|
||||||
Organization *string `json:"organization"`
|
Organization *string `json:"organization"`
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -7,6 +7,7 @@ package gitea
|
||||||
import (
|
import (
|
||||||
"encoding/json"
|
"encoding/json"
|
||||||
"errors"
|
"errors"
|
||||||
|
"fmt"
|
||||||
"io"
|
"io"
|
||||||
"io/ioutil"
|
"io/ioutil"
|
||||||
"net/http"
|
"net/http"
|
||||||
|
@ -69,6 +70,8 @@ func (c *Client) getResponse(method, path string, header http.Header, body io.Re
|
||||||
return nil, errors.New("403 Forbidden")
|
return nil, errors.New("403 Forbidden")
|
||||||
case 404:
|
case 404:
|
||||||
return nil, errors.New("404 Not Found")
|
return nil, errors.New("404 Not Found")
|
||||||
|
case 422:
|
||||||
|
return nil, fmt.Errorf("422 Unprocessable Entity: %s", string(data))
|
||||||
}
|
}
|
||||||
|
|
||||||
if resp.StatusCode/100 != 2 {
|
if resp.StatusCode/100 != 2 {
|
||||||
|
|
189
gitea/hook.go
189
gitea/hook.go
|
@ -21,24 +21,29 @@ var (
|
||||||
|
|
||||||
// Hook a hook is a web hook when one repository changed
|
// Hook a hook is a web hook when one repository changed
|
||||||
type Hook struct {
|
type Hook struct {
|
||||||
ID int64 `json:"id"`
|
ID int64 `json:"id"`
|
||||||
Type string `json:"type"`
|
Type string `json:"type"`
|
||||||
URL string `json:"-"`
|
URL string `json:"-"`
|
||||||
Config map[string]string `json:"config"`
|
Config map[string]string `json:"config"`
|
||||||
Events []string `json:"events"`
|
Events []string `json:"events"`
|
||||||
Active bool `json:"active"`
|
Active bool `json:"active"`
|
||||||
Updated time.Time `json:"updated_at"`
|
// swagger:strfmt date-time
|
||||||
Created time.Time `json:"created_at"`
|
Updated time.Time `json:"updated_at"`
|
||||||
|
// swagger:strfmt date-time
|
||||||
|
Created time.Time `json:"created_at"`
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// HookList represents a list of API hook.
|
||||||
|
type HookList []*Hook
|
||||||
|
|
||||||
// ListOrgHooks list all the hooks of one organization
|
// ListOrgHooks list all the hooks of one organization
|
||||||
func (c *Client) ListOrgHooks(org string) ([]*Hook, error) {
|
func (c *Client) ListOrgHooks(org string) (HookList, error) {
|
||||||
hooks := make([]*Hook, 0, 10)
|
hooks := make([]*Hook, 0, 10)
|
||||||
return hooks, c.getParsedResponse("GET", fmt.Sprintf("/orgs/%s/hooks", org), nil, nil, &hooks)
|
return hooks, c.getParsedResponse("GET", fmt.Sprintf("/orgs/%s/hooks", org), nil, nil, &hooks)
|
||||||
}
|
}
|
||||||
|
|
||||||
// ListRepoHooks list all the hooks of one repository
|
// ListRepoHooks list all the hooks of one repository
|
||||||
func (c *Client) ListRepoHooks(user, repo string) ([]*Hook, error) {
|
func (c *Client) ListRepoHooks(user, repo string) (HookList, error) {
|
||||||
hooks := make([]*Hook, 0, 10)
|
hooks := make([]*Hook, 0, 10)
|
||||||
return hooks, c.getParsedResponse("GET", fmt.Sprintf("/repos/%s/%s/hooks", user, repo), nil, nil, &hooks)
|
return hooks, c.getParsedResponse("GET", fmt.Sprintf("/repos/%s/%s/hooks", user, repo), nil, nil, &hooks)
|
||||||
}
|
}
|
||||||
|
@ -57,10 +62,14 @@ func (c *Client) GetRepoHook(user, repo string, id int64) (*Hook, error) {
|
||||||
|
|
||||||
// CreateHookOption options when create a hook
|
// CreateHookOption options when create a hook
|
||||||
type CreateHookOption struct {
|
type CreateHookOption struct {
|
||||||
Type string `json:"type" binding:"Required"`
|
// required: true
|
||||||
|
// enum: gitea,gogs,slack,discord
|
||||||
|
Type string `json:"type" binding:"Required"`
|
||||||
|
// required: true
|
||||||
Config map[string]string `json:"config" binding:"Required"`
|
Config map[string]string `json:"config" binding:"Required"`
|
||||||
Events []string `json:"events"`
|
Events []string `json:"events"`
|
||||||
Active bool `json:"active"`
|
// default: false
|
||||||
|
Active bool `json:"active"`
|
||||||
}
|
}
|
||||||
|
|
||||||
// CreateOrgHook create one hook for an organization, with options
|
// CreateOrgHook create one hook for an organization, with options
|
||||||
|
@ -128,25 +137,32 @@ type Payloader interface {
|
||||||
JSONPayload() ([]byte, error)
|
JSONPayload() ([]byte, error)
|
||||||
}
|
}
|
||||||
|
|
||||||
// PayloadUser FIXME
|
// PayloadUser represents the author or committer of a commit
|
||||||
type PayloadUser struct {
|
type PayloadUser struct {
|
||||||
Name string `json:"name"`
|
// Full name of the commit author
|
||||||
|
Name string `json:"name"`
|
||||||
|
// swagger:strfmt email
|
||||||
Email string `json:"email"`
|
Email string `json:"email"`
|
||||||
UserName string `json:"username"`
|
UserName string `json:"username"`
|
||||||
}
|
}
|
||||||
|
|
||||||
// PayloadCommit FIXME: consider use same format as API when commits API are added.
|
// FIXME: consider using same format as API when commits API are added.
|
||||||
|
// applies to PayloadCommit and PayloadCommitVerification
|
||||||
|
|
||||||
|
// PayloadCommit represents a commit
|
||||||
type PayloadCommit struct {
|
type PayloadCommit struct {
|
||||||
|
// sha1 hash of the commit
|
||||||
ID string `json:"id"`
|
ID string `json:"id"`
|
||||||
Message string `json:"message"`
|
Message string `json:"message"`
|
||||||
URL string `json:"url"`
|
URL string `json:"url"`
|
||||||
Author *PayloadUser `json:"author"`
|
Author *PayloadUser `json:"author"`
|
||||||
Committer *PayloadUser `json:"committer"`
|
Committer *PayloadUser `json:"committer"`
|
||||||
Verification *PayloadCommitVerification `json:"verification"`
|
Verification *PayloadCommitVerification `json:"verification"`
|
||||||
Timestamp time.Time `json:"timestamp"`
|
// swagger:strfmt date-time
|
||||||
|
Timestamp time.Time `json:"timestamp"`
|
||||||
}
|
}
|
||||||
|
|
||||||
// PayloadCommitVerification represent the GPG verification part of a commit. FIXME: like PayloadCommit consider use same format as API when commits API are added.
|
// PayloadCommitVerification represents the GPG verification of a commit
|
||||||
type PayloadCommitVerification struct {
|
type PayloadCommitVerification struct {
|
||||||
Verified bool `json:"verified"`
|
Verified bool `json:"verified"`
|
||||||
Reason string `json:"reason"`
|
Reason string `json:"reason"`
|
||||||
|
@ -156,9 +172,14 @@ type PayloadCommitVerification struct {
|
||||||
|
|
||||||
var (
|
var (
|
||||||
_ Payloader = &CreatePayload{}
|
_ Payloader = &CreatePayload{}
|
||||||
|
_ Payloader = &DeletePayload{}
|
||||||
|
_ Payloader = &ForkPayload{}
|
||||||
_ Payloader = &PushPayload{}
|
_ Payloader = &PushPayload{}
|
||||||
_ Payloader = &IssuePayload{}
|
_ Payloader = &IssuePayload{}
|
||||||
|
_ Payloader = &IssueCommentPayload{}
|
||||||
_ Payloader = &PullRequestPayload{}
|
_ Payloader = &PullRequestPayload{}
|
||||||
|
_ Payloader = &RepositoryPayload{}
|
||||||
|
_ Payloader = &ReleasePayload{}
|
||||||
)
|
)
|
||||||
|
|
||||||
// _________ __
|
// _________ __
|
||||||
|
@ -178,7 +199,7 @@ type CreatePayload struct {
|
||||||
Sender *User `json:"sender"`
|
Sender *User `json:"sender"`
|
||||||
}
|
}
|
||||||
|
|
||||||
// SetSecret FIXME
|
// SetSecret modifies the secret of the CreatePayload
|
||||||
func (p *CreatePayload) SetSecret(secret string) {
|
func (p *CreatePayload) SetSecret(secret string) {
|
||||||
p.Secret = secret
|
p.Secret = secret
|
||||||
}
|
}
|
||||||
|
@ -208,6 +229,133 @@ func ParseCreateHook(raw []byte) (*CreatePayload, error) {
|
||||||
return hook, nil
|
return hook, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// ________ .__ __
|
||||||
|
// \______ \ ____ | | _____/ |_ ____
|
||||||
|
// | | \_/ __ \| | _/ __ \ __\/ __ \
|
||||||
|
// | ` \ ___/| |_\ ___/| | \ ___/
|
||||||
|
// /_______ /\___ >____/\___ >__| \___ >
|
||||||
|
// \/ \/ \/ \/
|
||||||
|
|
||||||
|
// PusherType define the type to push
|
||||||
|
type PusherType string
|
||||||
|
|
||||||
|
// describe all the PusherTypes
|
||||||
|
const (
|
||||||
|
PusherTypeUser PusherType = "user"
|
||||||
|
)
|
||||||
|
|
||||||
|
// DeletePayload represents delete payload
|
||||||
|
type DeletePayload struct {
|
||||||
|
Secret string `json:"secret"`
|
||||||
|
Ref string `json:"ref"`
|
||||||
|
RefType string `json:"ref_type"`
|
||||||
|
PusherType PusherType `json:"pusher_type"`
|
||||||
|
Repo *Repository `json:"repository"`
|
||||||
|
Sender *User `json:"sender"`
|
||||||
|
}
|
||||||
|
|
||||||
|
// SetSecret modifies the secret of the DeletePayload
|
||||||
|
func (p *DeletePayload) SetSecret(secret string) {
|
||||||
|
p.Secret = secret
|
||||||
|
}
|
||||||
|
|
||||||
|
// JSONPayload implements Payload
|
||||||
|
func (p *DeletePayload) JSONPayload() ([]byte, error) {
|
||||||
|
return json.MarshalIndent(p, "", " ")
|
||||||
|
}
|
||||||
|
|
||||||
|
// ___________ __
|
||||||
|
// \_ _____/__________| | __
|
||||||
|
// | __)/ _ \_ __ \ |/ /
|
||||||
|
// | \( <_> ) | \/ <
|
||||||
|
// \___ / \____/|__| |__|_ \
|
||||||
|
// \/ \/
|
||||||
|
|
||||||
|
// ForkPayload represents fork payload
|
||||||
|
type ForkPayload struct {
|
||||||
|
Secret string `json:"secret"`
|
||||||
|
Forkee *Repository `json:"forkee"`
|
||||||
|
Repo *Repository `json:"repository"`
|
||||||
|
Sender *User `json:"sender"`
|
||||||
|
}
|
||||||
|
|
||||||
|
// SetSecret modifies the secret of the ForkPayload
|
||||||
|
func (p *ForkPayload) SetSecret(secret string) {
|
||||||
|
p.Secret = secret
|
||||||
|
}
|
||||||
|
|
||||||
|
// JSONPayload implements Payload
|
||||||
|
func (p *ForkPayload) JSONPayload() ([]byte, error) {
|
||||||
|
return json.MarshalIndent(p, "", " ")
|
||||||
|
}
|
||||||
|
|
||||||
|
// HookIssueCommentAction defines hook issue comment action
|
||||||
|
type HookIssueCommentAction string
|
||||||
|
|
||||||
|
// all issue comment actions
|
||||||
|
const (
|
||||||
|
HookIssueCommentCreated HookIssueCommentAction = "created"
|
||||||
|
HookIssueCommentEdited HookIssueCommentAction = "edited"
|
||||||
|
HookIssueCommentDeleted HookIssueCommentAction = "deleted"
|
||||||
|
)
|
||||||
|
|
||||||
|
// IssueCommentPayload represents a payload information of issue comment event.
|
||||||
|
type IssueCommentPayload struct {
|
||||||
|
Secret string `json:"secret"`
|
||||||
|
Action HookIssueCommentAction `json:"action"`
|
||||||
|
Issue *Issue `json:"issue"`
|
||||||
|
Comment *Comment `json:"comment"`
|
||||||
|
Changes *ChangesPayload `json:"changes,omitempty"`
|
||||||
|
Repository *Repository `json:"repository"`
|
||||||
|
Sender *User `json:"sender"`
|
||||||
|
}
|
||||||
|
|
||||||
|
// SetSecret modifies the secret of the IssueCommentPayload
|
||||||
|
func (p *IssueCommentPayload) SetSecret(secret string) {
|
||||||
|
p.Secret = secret
|
||||||
|
}
|
||||||
|
|
||||||
|
// JSONPayload implements Payload
|
||||||
|
func (p *IssueCommentPayload) JSONPayload() ([]byte, error) {
|
||||||
|
return json.MarshalIndent(p, "", " ")
|
||||||
|
}
|
||||||
|
|
||||||
|
// __________ .__
|
||||||
|
// \______ \ ____ | | ____ _____ ______ ____
|
||||||
|
// | _// __ \| | _/ __ \\__ \ / ___// __ \
|
||||||
|
// | | \ ___/| |_\ ___/ / __ \_\___ \\ ___/
|
||||||
|
// |____|_ /\___ >____/\___ >____ /____ >\___ >
|
||||||
|
// \/ \/ \/ \/ \/ \/
|
||||||
|
|
||||||
|
// HookReleaseAction defines hook release action type
|
||||||
|
type HookReleaseAction string
|
||||||
|
|
||||||
|
// all release actions
|
||||||
|
const (
|
||||||
|
HookReleasePublished HookReleaseAction = "published"
|
||||||
|
HookReleaseUpdated HookReleaseAction = "updated"
|
||||||
|
HookReleaseDeleted HookReleaseAction = "deleted"
|
||||||
|
)
|
||||||
|
|
||||||
|
// ReleasePayload represents a payload information of release event.
|
||||||
|
type ReleasePayload struct {
|
||||||
|
Secret string `json:"secret"`
|
||||||
|
Action HookReleaseAction `json:"action"`
|
||||||
|
Release *Release `json:"release"`
|
||||||
|
Repository *Repository `json:"repository"`
|
||||||
|
Sender *User `json:"sender"`
|
||||||
|
}
|
||||||
|
|
||||||
|
// SetSecret modifies the secret of the ReleasePayload
|
||||||
|
func (p *ReleasePayload) SetSecret(secret string) {
|
||||||
|
p.Secret = secret
|
||||||
|
}
|
||||||
|
|
||||||
|
// JSONPayload implements Payload
|
||||||
|
func (p *ReleasePayload) JSONPayload() ([]byte, error) {
|
||||||
|
return json.MarshalIndent(p, "", " ")
|
||||||
|
}
|
||||||
|
|
||||||
// __________ .__
|
// __________ .__
|
||||||
// \______ \__ __ _____| |__
|
// \______ \__ __ _____| |__
|
||||||
// | ___/ | \/ ___/ | \
|
// | ___/ | \/ ___/ | \
|
||||||
|
@ -223,12 +371,13 @@ type PushPayload struct {
|
||||||
After string `json:"after"`
|
After string `json:"after"`
|
||||||
CompareURL string `json:"compare_url"`
|
CompareURL string `json:"compare_url"`
|
||||||
Commits []*PayloadCommit `json:"commits"`
|
Commits []*PayloadCommit `json:"commits"`
|
||||||
|
HeadCommit *PayloadCommit `json:"head_commit"`
|
||||||
Repo *Repository `json:"repository"`
|
Repo *Repository `json:"repository"`
|
||||||
Pusher *User `json:"pusher"`
|
Pusher *User `json:"pusher"`
|
||||||
Sender *User `json:"sender"`
|
Sender *User `json:"sender"`
|
||||||
}
|
}
|
||||||
|
|
||||||
// SetSecret FIXME
|
// SetSecret modifies the secret of the PushPayload
|
||||||
func (p *PushPayload) SetSecret(secret string) {
|
func (p *PushPayload) SetSecret(secret string) {
|
||||||
p.Secret = secret
|
p.Secret = secret
|
||||||
}
|
}
|
||||||
|
@ -380,7 +529,7 @@ type RepositoryPayload struct {
|
||||||
Sender *User `json:"sender"`
|
Sender *User `json:"sender"`
|
||||||
}
|
}
|
||||||
|
|
||||||
// SetSecret set the payload's secret
|
// SetSecret modifies the secret of the RepositoryPayload
|
||||||
func (p *RepositoryPayload) SetSecret(secret string) {
|
func (p *RepositoryPayload) SetSecret(secret string) {
|
||||||
p.Secret = secret
|
p.Secret = secret
|
||||||
}
|
}
|
||||||
|
|
|
@ -27,7 +27,8 @@ type PullRequestMeta struct {
|
||||||
Merged *time.Time `json:"merged_at"`
|
Merged *time.Time `json:"merged_at"`
|
||||||
}
|
}
|
||||||
|
|
||||||
// Issue an issue to a repository
|
// Issue represents an issue in a repository
|
||||||
|
// swagger:model
|
||||||
type Issue struct {
|
type Issue struct {
|
||||||
ID int64 `json:"id"`
|
ID int64 `json:"id"`
|
||||||
URL string `json:"url"`
|
URL string `json:"url"`
|
||||||
|
@ -38,10 +39,21 @@ type Issue struct {
|
||||||
Labels []*Label `json:"labels"`
|
Labels []*Label `json:"labels"`
|
||||||
Milestone *Milestone `json:"milestone"`
|
Milestone *Milestone `json:"milestone"`
|
||||||
Assignee *User `json:"assignee"`
|
Assignee *User `json:"assignee"`
|
||||||
State StateType `json:"state"`
|
Assignees []*User `json:"assignees"`
|
||||||
Comments int `json:"comments"`
|
// Whether the issue is open or closed
|
||||||
Created time.Time `json:"created_at"`
|
//
|
||||||
Updated time.Time `json:"updated_at"`
|
// type: string
|
||||||
|
// enum: open,closed
|
||||||
|
State StateType `json:"state"`
|
||||||
|
Comments int `json:"comments"`
|
||||||
|
// swagger:strfmt date-time
|
||||||
|
Created time.Time `json:"created_at"`
|
||||||
|
// swagger:strfmt date-time
|
||||||
|
Updated time.Time `json:"updated_at"`
|
||||||
|
// swagger:strfmt date-time
|
||||||
|
Closed *time.Time `json:"closed_at"`
|
||||||
|
// swagger:strfmt date-time
|
||||||
|
Deadline *time.Time `json:"due_date"`
|
||||||
|
|
||||||
PullRequest *PullRequestMeta `json:"pull_request"`
|
PullRequest *PullRequestMeta `json:"pull_request"`
|
||||||
}
|
}
|
||||||
|
@ -78,12 +90,19 @@ func (c *Client) GetIssue(owner, repo string, index int64) (*Issue, error) {
|
||||||
|
|
||||||
// CreateIssueOption options to create one issue
|
// CreateIssueOption options to create one issue
|
||||||
type CreateIssueOption struct {
|
type CreateIssueOption struct {
|
||||||
Title string `json:"title" binding:"Required"`
|
// required:true
|
||||||
Body string `json:"body"`
|
Title string `json:"title" binding:"Required"`
|
||||||
Assignee string `json:"assignee"`
|
Body string `json:"body"`
|
||||||
Milestone int64 `json:"milestone"`
|
// username of assignee
|
||||||
Labels []int64 `json:"labels"`
|
Assignee string `json:"assignee"`
|
||||||
Closed bool `json:"closed"`
|
Assignees []string `json:"assignees"`
|
||||||
|
// swagger:strfmt date-time
|
||||||
|
Deadline *time.Time `json:"due_date"`
|
||||||
|
// milestone id
|
||||||
|
Milestone int64 `json:"milestone"`
|
||||||
|
// list of label ids
|
||||||
|
Labels []int64 `json:"labels"`
|
||||||
|
Closed bool `json:"closed"`
|
||||||
}
|
}
|
||||||
|
|
||||||
// CreateIssue create a new issue for a given repository
|
// CreateIssue create a new issue for a given repository
|
||||||
|
@ -97,13 +116,16 @@ func (c *Client) CreateIssue(owner, repo string, opt CreateIssueOption) (*Issue,
|
||||||
jsonHeader, bytes.NewReader(body), issue)
|
jsonHeader, bytes.NewReader(body), issue)
|
||||||
}
|
}
|
||||||
|
|
||||||
// EditIssueOption edit issue options
|
// EditIssueOption options for editing an issue
|
||||||
type EditIssueOption struct {
|
type EditIssueOption struct {
|
||||||
Title string `json:"title"`
|
Title string `json:"title"`
|
||||||
Body *string `json:"body"`
|
Body *string `json:"body"`
|
||||||
Assignee *string `json:"assignee"`
|
Assignee *string `json:"assignee"`
|
||||||
Milestone *int64 `json:"milestone"`
|
Assignees []string `json:"assignees"`
|
||||||
State *string `json:"state"`
|
Milestone *int64 `json:"milestone"`
|
||||||
|
State *string `json:"state"`
|
||||||
|
// swagger:strfmt date-time
|
||||||
|
Deadline *time.Time `json:"due_date"`
|
||||||
}
|
}
|
||||||
|
|
||||||
// EditIssue modify an existing issue for a given repository
|
// EditIssue modify an existing issue for a given repository
|
||||||
|
@ -116,3 +138,23 @@ func (c *Client) EditIssue(owner, repo string, index int64, opt EditIssueOption)
|
||||||
return issue, c.getParsedResponse("PATCH", fmt.Sprintf("/repos/%s/%s/issues/%d", owner, repo, index),
|
return issue, c.getParsedResponse("PATCH", fmt.Sprintf("/repos/%s/%s/issues/%d", owner, repo, index),
|
||||||
jsonHeader, bytes.NewReader(body), issue)
|
jsonHeader, bytes.NewReader(body), issue)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// EditDeadlineOption options for creating a deadline
|
||||||
|
type EditDeadlineOption struct {
|
||||||
|
// required:true
|
||||||
|
// swagger:strfmt date-time
|
||||||
|
Deadline *time.Time `json:"due_date"`
|
||||||
|
}
|
||||||
|
|
||||||
|
// IssueDeadline represents an issue deadline
|
||||||
|
// swagger:model
|
||||||
|
type IssueDeadline struct {
|
||||||
|
// swagger:strfmt date-time
|
||||||
|
Deadline *time.Time `json:"due_date"`
|
||||||
|
}
|
||||||
|
|
||||||
|
// EditPriorityOption options for updating priority
|
||||||
|
type EditPriorityOption struct {
|
||||||
|
// required:true
|
||||||
|
Priority int `json:"priority"`
|
||||||
|
}
|
||||||
|
|
|
@ -11,16 +11,18 @@ import (
|
||||||
"time"
|
"time"
|
||||||
)
|
)
|
||||||
|
|
||||||
// Comment represents a comment in commit and issue page.
|
// Comment represents a comment on a commit or issue
|
||||||
type Comment struct {
|
type Comment struct {
|
||||||
ID int64 `json:"id"`
|
ID int64 `json:"id"`
|
||||||
HTMLURL string `json:"html_url"`
|
HTMLURL string `json:"html_url"`
|
||||||
PRURL string `json:"pull_request_url"`
|
PRURL string `json:"pull_request_url"`
|
||||||
IssueURL string `json:"issue_url"`
|
IssueURL string `json:"issue_url"`
|
||||||
Poster *User `json:"user"`
|
Poster *User `json:"user"`
|
||||||
Body string `json:"body"`
|
Body string `json:"body"`
|
||||||
Created time.Time `json:"created_at"`
|
// swagger:strfmt date-time
|
||||||
Updated time.Time `json:"updated_at"`
|
Created time.Time `json:"created_at"`
|
||||||
|
// swagger:strfmt date-time
|
||||||
|
Updated time.Time `json:"updated_at"`
|
||||||
}
|
}
|
||||||
|
|
||||||
// ListIssueComments list comments on an issue.
|
// ListIssueComments list comments on an issue.
|
||||||
|
@ -35,8 +37,9 @@ func (c *Client) ListRepoIssueComments(owner, repo string) ([]*Comment, error) {
|
||||||
return comments, c.getParsedResponse("GET", fmt.Sprintf("/repos/%s/%s/issues/comments", owner, repo), nil, nil, &comments)
|
return comments, c.getParsedResponse("GET", fmt.Sprintf("/repos/%s/%s/issues/comments", owner, repo), nil, nil, &comments)
|
||||||
}
|
}
|
||||||
|
|
||||||
// CreateIssueCommentOption is option when creating an issue comment.
|
// CreateIssueCommentOption options for creating a comment on an issue
|
||||||
type CreateIssueCommentOption struct {
|
type CreateIssueCommentOption struct {
|
||||||
|
// required:true
|
||||||
Body string `json:"body" binding:"Required"`
|
Body string `json:"body" binding:"Required"`
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -50,8 +53,9 @@ func (c *Client) CreateIssueComment(owner, repo string, index int64, opt CreateI
|
||||||
return comment, c.getParsedResponse("POST", fmt.Sprintf("/repos/%s/%s/issues/%d/comments", owner, repo, index), jsonHeader, bytes.NewReader(body), comment)
|
return comment, c.getParsedResponse("POST", fmt.Sprintf("/repos/%s/%s/issues/%d/comments", owner, repo, index), jsonHeader, bytes.NewReader(body), comment)
|
||||||
}
|
}
|
||||||
|
|
||||||
// EditIssueCommentOption is option when editing an issue comment.
|
// EditIssueCommentOption options for editing a comment
|
||||||
type EditIssueCommentOption struct {
|
type EditIssueCommentOption struct {
|
||||||
|
// required: true
|
||||||
Body string `json:"body" binding:"Required"`
|
Body string `json:"body" binding:"Required"`
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -11,14 +11,16 @@ import (
|
||||||
)
|
)
|
||||||
|
|
||||||
// Label a label to an issue or a pr
|
// Label a label to an issue or a pr
|
||||||
|
// swagger:model
|
||||||
type Label struct {
|
type Label struct {
|
||||||
ID int64 `json:"id"`
|
ID int64 `json:"id"`
|
||||||
Name string `json:"name"`
|
Name string `json:"name"`
|
||||||
|
// example: 00aabb
|
||||||
Color string `json:"color"`
|
Color string `json:"color"`
|
||||||
URL string `json:"url"`
|
URL string `json:"url"`
|
||||||
}
|
}
|
||||||
|
|
||||||
// ListRepoLabels list lables of one reppsitory
|
// ListRepoLabels list labels of one repository
|
||||||
func (c *Client) ListRepoLabels(owner, repo string) ([]*Label, error) {
|
func (c *Client) ListRepoLabels(owner, repo string) ([]*Label, error) {
|
||||||
labels := make([]*Label, 0, 10)
|
labels := make([]*Label, 0, 10)
|
||||||
return labels, c.getParsedResponse("GET", fmt.Sprintf("/repos/%s/%s/labels", owner, repo), nil, nil, &labels)
|
return labels, c.getParsedResponse("GET", fmt.Sprintf("/repos/%s/%s/labels", owner, repo), nil, nil, &labels)
|
||||||
|
@ -31,9 +33,12 @@ func (c *Client) GetRepoLabel(owner, repo string, id int64) (*Label, error) {
|
||||||
return label, c.getParsedResponse("GET", fmt.Sprintf("/repos/%s/%s/labels/%d", owner, repo, id), nil, nil, label)
|
return label, c.getParsedResponse("GET", fmt.Sprintf("/repos/%s/%s/labels/%d", owner, repo, id), nil, nil, label)
|
||||||
}
|
}
|
||||||
|
|
||||||
// CreateLabelOption create options when one label of repository
|
// CreateLabelOption options for creating a label
|
||||||
type CreateLabelOption struct {
|
type CreateLabelOption struct {
|
||||||
Name string `json:"name" binding:"Required"`
|
// required:true
|
||||||
|
Name string `json:"name" binding:"Required"`
|
||||||
|
// required:true
|
||||||
|
// example: #00aabb
|
||||||
Color string `json:"color" binding:"Required;Size(7)"`
|
Color string `json:"color" binding:"Required;Size(7)"`
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -48,7 +53,7 @@ func (c *Client) CreateLabel(owner, repo string, opt CreateLabelOption) (*Label,
|
||||||
jsonHeader, bytes.NewReader(body), label)
|
jsonHeader, bytes.NewReader(body), label)
|
||||||
}
|
}
|
||||||
|
|
||||||
// EditLabelOption edit label options
|
// EditLabelOption options for editing a label
|
||||||
type EditLabelOption struct {
|
type EditLabelOption struct {
|
||||||
Name *string `json:"name"`
|
Name *string `json:"name"`
|
||||||
Color *string `json:"color"`
|
Color *string `json:"color"`
|
||||||
|
@ -71,8 +76,9 @@ func (c *Client) DeleteLabel(owner, repo string, id int64) error {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
|
||||||
// IssueLabelsOption list one issue's labels options
|
// IssueLabelsOption a collection of labels
|
||||||
type IssueLabelsOption struct {
|
type IssueLabelsOption struct {
|
||||||
|
// list of label IDs
|
||||||
Labels []int64 `json:"labels"`
|
Labels []int64 `json:"labels"`
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -13,14 +13,16 @@ import (
|
||||||
|
|
||||||
// Milestone milestone is a collection of issues on one repository
|
// Milestone milestone is a collection of issues on one repository
|
||||||
type Milestone struct {
|
type Milestone struct {
|
||||||
ID int64 `json:"id"`
|
ID int64 `json:"id"`
|
||||||
Title string `json:"title"`
|
Title string `json:"title"`
|
||||||
Description string `json:"description"`
|
Description string `json:"description"`
|
||||||
State StateType `json:"state"`
|
State StateType `json:"state"`
|
||||||
OpenIssues int `json:"open_issues"`
|
OpenIssues int `json:"open_issues"`
|
||||||
ClosedIssues int `json:"closed_issues"`
|
ClosedIssues int `json:"closed_issues"`
|
||||||
Closed *time.Time `json:"closed_at"`
|
// swagger:strfmt date-time
|
||||||
Deadline *time.Time `json:"due_on"`
|
Closed *time.Time `json:"closed_at"`
|
||||||
|
// swagger:strfmt date-time
|
||||||
|
Deadline *time.Time `json:"due_on"`
|
||||||
}
|
}
|
||||||
|
|
||||||
// ListRepoMilestones list all the milestones of one repository
|
// ListRepoMilestones list all the milestones of one repository
|
||||||
|
@ -35,11 +37,12 @@ func (c *Client) GetMilestone(owner, repo string, id int64) (*Milestone, error)
|
||||||
return milestone, c.getParsedResponse("GET", fmt.Sprintf("/repos/%s/%s/milestones/%d", owner, repo, id), nil, nil, milestone)
|
return milestone, c.getParsedResponse("GET", fmt.Sprintf("/repos/%s/%s/milestones/%d", owner, repo, id), nil, nil, milestone)
|
||||||
}
|
}
|
||||||
|
|
||||||
// CreateMilestoneOption options when creating milestone
|
// CreateMilestoneOption options for creating a milestone
|
||||||
type CreateMilestoneOption struct {
|
type CreateMilestoneOption struct {
|
||||||
Title string `json:"title"`
|
Title string `json:"title"`
|
||||||
Description string `json:"description"`
|
Description string `json:"description"`
|
||||||
Deadline *time.Time `json:"due_on"`
|
// swagger:strfmt date-time
|
||||||
|
Deadline *time.Time `json:"due_on"`
|
||||||
}
|
}
|
||||||
|
|
||||||
// CreateMilestone create one milestone with options
|
// CreateMilestone create one milestone with options
|
||||||
|
@ -52,7 +55,7 @@ func (c *Client) CreateMilestone(owner, repo string, opt CreateMilestoneOption)
|
||||||
return milestone, c.getParsedResponse("POST", fmt.Sprintf("/repos/%s/%s/milestones", owner, repo), jsonHeader, bytes.NewReader(body), milestone)
|
return milestone, c.getParsedResponse("POST", fmt.Sprintf("/repos/%s/%s/milestones", owner, repo), jsonHeader, bytes.NewReader(body), milestone)
|
||||||
}
|
}
|
||||||
|
|
||||||
// EditMilestoneOption options when modify milestone
|
// EditMilestoneOption options for editing a milestone
|
||||||
type EditMilestoneOption struct {
|
type EditMilestoneOption struct {
|
||||||
Title string `json:"title"`
|
Title string `json:"title"`
|
||||||
Description *string `json:"description"`
|
Description *string `json:"description"`
|
||||||
|
|
68
gitea/issue_tracked_time.go
Normal file
68
gitea/issue_tracked_time.go
Normal file
|
@ -0,0 +1,68 @@
|
||||||
|
// Copyright 2017 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
|
||||||
|
|
||||||
|
import (
|
||||||
|
"bytes"
|
||||||
|
"encoding/json"
|
||||||
|
"fmt"
|
||||||
|
"time"
|
||||||
|
)
|
||||||
|
|
||||||
|
// TrackedTime worked time for an issue / pr
|
||||||
|
type TrackedTime struct {
|
||||||
|
ID int64 `json:"id"`
|
||||||
|
// swagger:strfmt date-time
|
||||||
|
Created time.Time `json:"created"`
|
||||||
|
// Time in seconds
|
||||||
|
Time int64 `json:"time"`
|
||||||
|
UserID int64 `json:"user_id"`
|
||||||
|
IssueID int64 `json:"issue_id"`
|
||||||
|
}
|
||||||
|
|
||||||
|
// TrackedTimes represent a list of tracked times
|
||||||
|
type TrackedTimes []*TrackedTime
|
||||||
|
|
||||||
|
// GetUserTrackedTimes list tracked times of a user
|
||||||
|
func (c *Client) GetUserTrackedTimes(owner, repo, user string) (TrackedTimes, error) {
|
||||||
|
times := make(TrackedTimes, 0, 10)
|
||||||
|
return times, c.getParsedResponse("GET", fmt.Sprintf("/repos/%s/%s/times/%s", owner, repo, user), nil, nil, ×)
|
||||||
|
}
|
||||||
|
|
||||||
|
// GetRepoTrackedTimes list tracked times of a repository
|
||||||
|
func (c *Client) GetRepoTrackedTimes(owner, repo string) (TrackedTimes, error) {
|
||||||
|
times := make(TrackedTimes, 0, 10)
|
||||||
|
return times, c.getParsedResponse("GET", fmt.Sprintf("/repos/%s/%s/times", owner, repo), nil, nil, ×)
|
||||||
|
}
|
||||||
|
|
||||||
|
// GetMyTrackedTimes list tracked times of the current user
|
||||||
|
func (c *Client) GetMyTrackedTimes() (TrackedTimes, error) {
|
||||||
|
times := make(TrackedTimes, 0, 10)
|
||||||
|
return times, c.getParsedResponse("GET", "/user/times", nil, nil, ×)
|
||||||
|
}
|
||||||
|
|
||||||
|
// AddTimeOption options for adding time to an issue
|
||||||
|
type AddTimeOption struct {
|
||||||
|
// time in seconds
|
||||||
|
// required: true
|
||||||
|
Time int64 `json:"time" binding:"Required"`
|
||||||
|
}
|
||||||
|
|
||||||
|
// AddTime adds time to issue with the given index
|
||||||
|
func (c *Client) AddTime(owner, repo string, index int64, opt AddTimeOption) (*TrackedTime, error) {
|
||||||
|
body, err := json.Marshal(&opt)
|
||||||
|
if err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
t := new(TrackedTime)
|
||||||
|
return t, c.getParsedResponse("POST", fmt.Sprintf("/repos/%s/%s/issues/%d/times", owner, repo, index),
|
||||||
|
jsonHeader, bytes.NewReader(body), t)
|
||||||
|
}
|
||||||
|
|
||||||
|
// ListTrackedTimes get tracked times of one issue via issue id
|
||||||
|
func (c *Client) ListTrackedTimes(owner, repo string, index int64) (TrackedTimes, error) {
|
||||||
|
times := make(TrackedTimes, 0, 5)
|
||||||
|
return times, c.getParsedResponse("GET", fmt.Sprintf("/repos/%s/%s/issues/%d/times", owner, repo, index), nil, nil, ×)
|
||||||
|
}
|
65
gitea/lfs_lock.go
Normal file
65
gitea/lfs_lock.go
Normal file
|
@ -0,0 +1,65 @@
|
||||||
|
// Copyright 2017 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
|
||||||
|
|
||||||
|
import (
|
||||||
|
"time"
|
||||||
|
)
|
||||||
|
|
||||||
|
// LFSLock represent a lock
|
||||||
|
// for use with the locks API.
|
||||||
|
type LFSLock struct {
|
||||||
|
ID string `json:"id"`
|
||||||
|
Path string `json:"path"`
|
||||||
|
LockedAt time.Time `json:"locked_at"`
|
||||||
|
Owner *LFSLockOwner `json:"owner"`
|
||||||
|
}
|
||||||
|
|
||||||
|
// LFSLockOwner represent a lock owner
|
||||||
|
// for use with the locks API.
|
||||||
|
type LFSLockOwner struct {
|
||||||
|
Name string `json:"name"`
|
||||||
|
}
|
||||||
|
|
||||||
|
// LFSLockRequest contains the path of the lock to create
|
||||||
|
// https://github.com/git-lfs/git-lfs/blob/master/docs/api/locking.md#create-lock
|
||||||
|
type LFSLockRequest struct {
|
||||||
|
Path string `json:"path"`
|
||||||
|
}
|
||||||
|
|
||||||
|
// LFSLockResponse represent a lock created
|
||||||
|
// https://github.com/git-lfs/git-lfs/blob/master/docs/api/locking.md#create-lock
|
||||||
|
type LFSLockResponse struct {
|
||||||
|
Lock *LFSLock `json:"lock"`
|
||||||
|
}
|
||||||
|
|
||||||
|
// LFSLockList represent a list of lock requested
|
||||||
|
// https://github.com/git-lfs/git-lfs/blob/master/docs/api/locking.md#list-locks
|
||||||
|
type LFSLockList struct {
|
||||||
|
Locks []*LFSLock `json:"locks"`
|
||||||
|
Next string `json:"next_cursor,omitempty"`
|
||||||
|
}
|
||||||
|
|
||||||
|
// LFSLockListVerify represent a list of lock verification requested
|
||||||
|
// https://github.com/git-lfs/git-lfs/blob/master/docs/api/locking.md#list-locks-for-verification
|
||||||
|
type LFSLockListVerify struct {
|
||||||
|
Ours []*LFSLock `json:"ours"`
|
||||||
|
Theirs []*LFSLock `json:"theirs"`
|
||||||
|
Next string `json:"next_cursor,omitempty"`
|
||||||
|
}
|
||||||
|
|
||||||
|
// LFSLockError contains information on the error that occurs
|
||||||
|
type LFSLockError struct {
|
||||||
|
Message string `json:"message"`
|
||||||
|
Lock *LFSLock `json:"lock,omitempty"`
|
||||||
|
Documentation string `json:"documentation_url,omitempty"`
|
||||||
|
RequestID string `json:"request_id,omitempty"`
|
||||||
|
}
|
||||||
|
|
||||||
|
// LFSLockDeleteRequest contains params of a delete request
|
||||||
|
// https://github.com/git-lfs/git-lfs/blob/master/docs/api/locking.md#delete-lock
|
||||||
|
type LFSLockDeleteRequest struct {
|
||||||
|
Force bool `json:"force"`
|
||||||
|
}
|
|
@ -4,22 +4,19 @@
|
||||||
|
|
||||||
package gitea
|
package gitea
|
||||||
|
|
||||||
// SearchResults results of search
|
// SearchResults results of a successful search
|
||||||
// swagger:response SearchResults
|
|
||||||
type SearchResults struct {
|
type SearchResults struct {
|
||||||
OK bool `json:"ok"`
|
OK bool `json:"ok"`
|
||||||
Data []*Repository `json:"data"`
|
Data []*Repository `json:"data"`
|
||||||
}
|
}
|
||||||
|
|
||||||
// SearchError error of failing search
|
// SearchError error of a failed search
|
||||||
// swagger:response SearchError
|
|
||||||
type SearchError struct {
|
type SearchError struct {
|
||||||
OK bool `json:"ok"`
|
OK bool `json:"ok"`
|
||||||
Error string `json:"error"`
|
Error string `json:"error"`
|
||||||
}
|
}
|
||||||
|
|
||||||
// MarkdownOption markdown options
|
// MarkdownOption markdown options
|
||||||
// swagger:parameters renderMarkdown
|
|
||||||
type MarkdownOption struct {
|
type MarkdownOption struct {
|
||||||
// Text markdown to render
|
// Text markdown to render
|
||||||
//
|
//
|
||||||
|
@ -44,9 +41,8 @@ type MarkdownOption struct {
|
||||||
type MarkdownRender string
|
type MarkdownRender string
|
||||||
|
|
||||||
// ServerVersion wraps the version of the server
|
// ServerVersion wraps the version of the server
|
||||||
// swagger:response ServerVersion
|
|
||||||
type ServerVersion struct {
|
type ServerVersion struct {
|
||||||
Version string
|
Version string `json:"version"`
|
||||||
}
|
}
|
||||||
|
|
||||||
// ServerVersion returns the version of the server
|
// ServerVersion returns the version of the server
|
||||||
|
|
|
@ -10,7 +10,7 @@ import (
|
||||||
"fmt"
|
"fmt"
|
||||||
)
|
)
|
||||||
|
|
||||||
// Organization a group of some repositories, users and teams
|
// Organization represents an organization
|
||||||
type Organization struct {
|
type Organization struct {
|
||||||
ID int64 `json:"id"`
|
ID int64 `json:"id"`
|
||||||
UserName string `json:"username"`
|
UserName string `json:"username"`
|
||||||
|
@ -39,8 +39,9 @@ func (c *Client) GetOrg(orgname string) (*Organization, error) {
|
||||||
return org, c.getParsedResponse("GET", fmt.Sprintf("/orgs/%s", orgname), nil, nil, org)
|
return org, c.getParsedResponse("GET", fmt.Sprintf("/orgs/%s", orgname), nil, nil, org)
|
||||||
}
|
}
|
||||||
|
|
||||||
// CreateOrgOption create one organization options
|
// CreateOrgOption options for creating an organization
|
||||||
type CreateOrgOption struct {
|
type CreateOrgOption struct {
|
||||||
|
// required: true
|
||||||
UserName string `json:"username" binding:"Required"`
|
UserName string `json:"username" binding:"Required"`
|
||||||
FullName string `json:"full_name"`
|
FullName string `json:"full_name"`
|
||||||
Description string `json:"description"`
|
Description string `json:"description"`
|
||||||
|
@ -48,7 +49,7 @@ type CreateOrgOption struct {
|
||||||
Location string `json:"location"`
|
Location string `json:"location"`
|
||||||
}
|
}
|
||||||
|
|
||||||
// EditOrgOption edit one organization options
|
// EditOrgOption options for editing an organization
|
||||||
type EditOrgOption struct {
|
type EditOrgOption struct {
|
||||||
FullName string `json:"full_name"`
|
FullName string `json:"full_name"`
|
||||||
Description string `json:"description"`
|
Description string `json:"description"`
|
||||||
|
|
|
@ -1,27 +1,39 @@
|
||||||
// Copyright 2016 The Gogs Authors. All rights reserved.
|
// Copyright 2016 The Gogs Authors. All rights reserved.
|
||||||
|
// Copyright 2018 The Gitea Authors. All rights reserved.
|
||||||
// Use of this source code is governed by a MIT-style
|
// Use of this source code is governed by a MIT-style
|
||||||
// license that can be found in the LICENSE file.
|
// license that can be found in the LICENSE file.
|
||||||
|
|
||||||
package gitea
|
package gitea
|
||||||
|
|
||||||
// Team is a sub virtual organization of one Organization
|
// Team represents a team in an organization
|
||||||
type Team struct {
|
type Team struct {
|
||||||
ID int64 `json:"id"`
|
ID int64 `json:"id"`
|
||||||
Name string `json:"name"`
|
Name string `json:"name"`
|
||||||
Description string `json:"description"`
|
Description string `json:"description"`
|
||||||
Permission string `json:"permission"`
|
// enum: none,read,write,admin,owner
|
||||||
|
Permission string `json:"permission"`
|
||||||
|
// enum: repo.code,repo.issues,repo.ext_issues,repo.wiki,repo.pulls,repo.releases,repo.ext_wiki
|
||||||
|
Units []string `json:"units"`
|
||||||
}
|
}
|
||||||
|
|
||||||
// CreateTeamOption options when create team
|
// CreateTeamOption options for creating a team
|
||||||
type CreateTeamOption struct {
|
type CreateTeamOption struct {
|
||||||
|
// required: true
|
||||||
Name string `json:"name" binding:"Required;AlphaDashDot;MaxSize(30)"`
|
Name string `json:"name" binding:"Required;AlphaDashDot;MaxSize(30)"`
|
||||||
Description string `json:"description" binding:"MaxSize(255)"`
|
Description string `json:"description" binding:"MaxSize(255)"`
|
||||||
Permission string `json:"permission"`
|
// enum: read,write,admin
|
||||||
|
Permission string `json:"permission"`
|
||||||
|
// enum: repo.code,repo.issues,repo.ext_issues,repo.wiki,repo.pulls,repo.releases,repo.ext_wiki
|
||||||
|
Units []string `json:"units"`
|
||||||
}
|
}
|
||||||
|
|
||||||
// EditTeamOption options when edit team
|
// EditTeamOption options for editing a team
|
||||||
type EditTeamOption struct {
|
type EditTeamOption struct {
|
||||||
|
// required: true
|
||||||
Name string `json:"name" binding:"Required;AlphaDashDot;MaxSize(30)"`
|
Name string `json:"name" binding:"Required;AlphaDashDot;MaxSize(30)"`
|
||||||
Description string `json:"description" binding:"MaxSize(255)"`
|
Description string `json:"description" binding:"MaxSize(255)"`
|
||||||
Permission string `json:"permission"`
|
// enum: read,write,admin
|
||||||
|
Permission string `json:"permission"`
|
||||||
|
// enum: repo.code,repo.issues,repo.ext_issues,repo.wiki,repo.pulls,repo.releases,repo.ext_wiki
|
||||||
|
Units []string `json:"units"`
|
||||||
}
|
}
|
||||||
|
|
|
@ -11,7 +11,7 @@ import (
|
||||||
"time"
|
"time"
|
||||||
)
|
)
|
||||||
|
|
||||||
// PullRequest represents a pull request API object.
|
// PullRequest represents a pull request
|
||||||
type PullRequest struct {
|
type PullRequest struct {
|
||||||
ID int64 `json:"id"`
|
ID int64 `json:"id"`
|
||||||
URL string `json:"url"`
|
URL string `json:"url"`
|
||||||
|
@ -22,6 +22,7 @@ type PullRequest struct {
|
||||||
Labels []*Label `json:"labels"`
|
Labels []*Label `json:"labels"`
|
||||||
Milestone *Milestone `json:"milestone"`
|
Milestone *Milestone `json:"milestone"`
|
||||||
Assignee *User `json:"assignee"`
|
Assignee *User `json:"assignee"`
|
||||||
|
Assignees []*User `json:"assignees"`
|
||||||
State StateType `json:"state"`
|
State StateType `json:"state"`
|
||||||
Comments int `json:"comments"`
|
Comments int `json:"comments"`
|
||||||
|
|
||||||
|
@ -29,8 +30,9 @@ type PullRequest struct {
|
||||||
DiffURL string `json:"diff_url"`
|
DiffURL string `json:"diff_url"`
|
||||||
PatchURL string `json:"patch_url"`
|
PatchURL string `json:"patch_url"`
|
||||||
|
|
||||||
Mergeable bool `json:"mergeable"`
|
Mergeable bool `json:"mergeable"`
|
||||||
HasMerged bool `json:"merged"`
|
HasMerged bool `json:"merged"`
|
||||||
|
// swagger:strfmt date-time
|
||||||
Merged *time.Time `json:"merged_at"`
|
Merged *time.Time `json:"merged_at"`
|
||||||
MergedCommitID *string `json:"merge_commit_sha"`
|
MergedCommitID *string `json:"merge_commit_sha"`
|
||||||
MergedBy *User `json:"merged_by"`
|
MergedBy *User `json:"merged_by"`
|
||||||
|
@ -39,11 +41,18 @@ type PullRequest struct {
|
||||||
Head *PRBranchInfo `json:"head"`
|
Head *PRBranchInfo `json:"head"`
|
||||||
MergeBase string `json:"merge_base"`
|
MergeBase string `json:"merge_base"`
|
||||||
|
|
||||||
|
// swagger:strfmt date-time
|
||||||
|
Deadline *time.Time `json:"due_date"`
|
||||||
|
|
||||||
|
// swagger:strfmt date-time
|
||||||
Created *time.Time `json:"created_at"`
|
Created *time.Time `json:"created_at"`
|
||||||
|
// swagger:strfmt date-time
|
||||||
Updated *time.Time `json:"updated_at"`
|
Updated *time.Time `json:"updated_at"`
|
||||||
|
// swagger:strfmt date-time
|
||||||
|
Closed *time.Time `json:"closed_at"`
|
||||||
}
|
}
|
||||||
|
|
||||||
// PRBranchInfo base branch info when send a PR
|
// PRBranchInfo information about a branch
|
||||||
type PRBranchInfo struct {
|
type PRBranchInfo struct {
|
||||||
Name string `json:"label"`
|
Name string `json:"label"`
|
||||||
Ref string `json:"ref"`
|
Ref string `json:"ref"`
|
||||||
|
@ -52,7 +61,7 @@ type PRBranchInfo struct {
|
||||||
Repository *Repository `json:"repo"`
|
Repository *Repository `json:"repo"`
|
||||||
}
|
}
|
||||||
|
|
||||||
// ListPullRequestsOptions options when list PRs
|
// ListPullRequestsOptions options for listing pull requests
|
||||||
type ListPullRequestsOptions struct {
|
type ListPullRequestsOptions struct {
|
||||||
Page int `json:"page"`
|
Page int `json:"page"`
|
||||||
State string `json:"state"`
|
State string `json:"state"`
|
||||||
|
@ -76,13 +85,16 @@ func (c *Client) GetPullRequest(owner, repo string, index int64) (*PullRequest,
|
||||||
|
|
||||||
// CreatePullRequestOption options when creating a pull request
|
// CreatePullRequestOption options when creating a pull request
|
||||||
type CreatePullRequestOption struct {
|
type CreatePullRequestOption struct {
|
||||||
Head string `json:"head" binding:"Required"`
|
Head string `json:"head" binding:"Required"`
|
||||||
Base string `json:"base" binding:"Required"`
|
Base string `json:"base" binding:"Required"`
|
||||||
Title string `json:"title" binding:"Required"`
|
Title string `json:"title" binding:"Required"`
|
||||||
Body string `json:"body"`
|
Body string `json:"body"`
|
||||||
Assignee string `json:"assignee"`
|
Assignee string `json:"assignee"`
|
||||||
Milestone int64 `json:"milestone"`
|
Assignees []string `json:"assignees"`
|
||||||
Labels []int64 `json:"labels"`
|
Milestone int64 `json:"milestone"`
|
||||||
|
Labels []int64 `json:"labels"`
|
||||||
|
// swagger:strfmt date-time
|
||||||
|
Deadline *time.Time `json:"due_date"`
|
||||||
}
|
}
|
||||||
|
|
||||||
// CreatePullRequest create pull request with options
|
// CreatePullRequest create pull request with options
|
||||||
|
@ -98,12 +110,15 @@ func (c *Client) CreatePullRequest(owner, repo string, opt CreatePullRequestOpti
|
||||||
|
|
||||||
// EditPullRequestOption options when modify pull request
|
// EditPullRequestOption options when modify pull request
|
||||||
type EditPullRequestOption struct {
|
type EditPullRequestOption struct {
|
||||||
Title string `json:"title"`
|
Title string `json:"title"`
|
||||||
Body string `json:"body"`
|
Body string `json:"body"`
|
||||||
Assignee string `json:"assignee"`
|
Assignee string `json:"assignee"`
|
||||||
Milestone int64 `json:"milestone"`
|
Assignees []string `json:"assignees"`
|
||||||
Labels []int64 `json:"labels"`
|
Milestone int64 `json:"milestone"`
|
||||||
State *string `json:"state"`
|
Labels []int64 `json:"labels"`
|
||||||
|
State *string `json:"state"`
|
||||||
|
// swagger:strfmt date-time
|
||||||
|
Deadline *time.Time `json:"due_date"`
|
||||||
}
|
}
|
||||||
|
|
||||||
// EditPullRequest modify pull request with PR id and options
|
// EditPullRequest modify pull request with PR id and options
|
||||||
|
|
|
@ -13,19 +13,22 @@ import (
|
||||||
|
|
||||||
// Release represents a repository release
|
// Release represents a repository release
|
||||||
type Release struct {
|
type Release struct {
|
||||||
ID int64 `json:"id"`
|
ID int64 `json:"id"`
|
||||||
TagName string `json:"tag_name"`
|
TagName string `json:"tag_name"`
|
||||||
Target string `json:"target_commitish"`
|
Target string `json:"target_commitish"`
|
||||||
Title string `json:"name"`
|
Title string `json:"name"`
|
||||||
Note string `json:"body"`
|
Note string `json:"body"`
|
||||||
URL string `json:"url"`
|
URL string `json:"url"`
|
||||||
TarURL string `json:"tarball_url"`
|
TarURL string `json:"tarball_url"`
|
||||||
ZipURL string `json:"zipball_url"`
|
ZipURL string `json:"zipball_url"`
|
||||||
IsDraft bool `json:"draft"`
|
IsDraft bool `json:"draft"`
|
||||||
IsPrerelease bool `json:"prerelease"`
|
IsPrerelease bool `json:"prerelease"`
|
||||||
CreatedAt time.Time `json:"created_at"`
|
// swagger:strfmt date-time
|
||||||
PublishedAt time.Time `json:"published_at"`
|
CreatedAt time.Time `json:"created_at"`
|
||||||
Publisher *User `json:"author"`
|
// swagger:strfmt date-time
|
||||||
|
PublishedAt time.Time `json:"published_at"`
|
||||||
|
Publisher *User `json:"author"`
|
||||||
|
Attachments []*Attachment `json:"assets"`
|
||||||
}
|
}
|
||||||
|
|
||||||
// ListReleases list releases of a repository
|
// ListReleases list releases of a repository
|
||||||
|
@ -48,8 +51,9 @@ func (c *Client) GetRelease(user, repo string, id int64) (*Release, error) {
|
||||||
|
|
||||||
// CreateReleaseOption options when creating a release
|
// CreateReleaseOption options when creating a release
|
||||||
type CreateReleaseOption struct {
|
type CreateReleaseOption struct {
|
||||||
|
// required: true
|
||||||
TagName string `json:"tag_name" binding:"Required"`
|
TagName string `json:"tag_name" binding:"Required"`
|
||||||
Target string `json:"target_commitish"`
|
Target string `json:"target_commitish" binding:"Required"`
|
||||||
Title string `json:"name"`
|
Title string `json:"name"`
|
||||||
Note string `json:"body"`
|
Note string `json:"body"`
|
||||||
IsDraft bool `json:"draft"`
|
IsDraft bool `json:"draft"`
|
||||||
|
|
|
@ -11,15 +11,14 @@ import (
|
||||||
"time"
|
"time"
|
||||||
)
|
)
|
||||||
|
|
||||||
// Permission represents a API permission.
|
// Permission represents a set of permissions
|
||||||
type Permission struct {
|
type Permission struct {
|
||||||
Admin bool `json:"admin"`
|
Admin bool `json:"admin"`
|
||||||
Push bool `json:"push"`
|
Push bool `json:"push"`
|
||||||
Pull bool `json:"pull"`
|
Pull bool `json:"pull"`
|
||||||
}
|
}
|
||||||
|
|
||||||
// Repository represents a API repository.
|
// Repository represents a repository
|
||||||
// swagger:response Repository
|
|
||||||
type Repository struct {
|
type Repository struct {
|
||||||
ID int64 `json:"id"`
|
ID int64 `json:"id"`
|
||||||
Owner *User `json:"owner"`
|
Owner *User `json:"owner"`
|
||||||
|
@ -41,15 +40,14 @@ type Repository struct {
|
||||||
Watchers int `json:"watchers_count"`
|
Watchers int `json:"watchers_count"`
|
||||||
OpenIssues int `json:"open_issues_count"`
|
OpenIssues int `json:"open_issues_count"`
|
||||||
DefaultBranch string `json:"default_branch"`
|
DefaultBranch string `json:"default_branch"`
|
||||||
Created time.Time `json:"created_at"`
|
Archived bool `json:"archived"`
|
||||||
Updated time.Time `json:"updated_at"`
|
// swagger:strfmt date-time
|
||||||
Permissions *Permission `json:"permissions,omitempty"`
|
Created time.Time `json:"created_at"`
|
||||||
|
// swagger:strfmt date-time
|
||||||
|
Updated time.Time `json:"updated_at"`
|
||||||
|
Permissions *Permission `json:"permissions,omitempty"`
|
||||||
}
|
}
|
||||||
|
|
||||||
// RepositoryList represents a list of API repository.
|
|
||||||
// swagger:response RepositoryList
|
|
||||||
type RepositoryList []*Repository
|
|
||||||
|
|
||||||
// ListMyRepos lists all repositories for the authenticated user that has access to.
|
// ListMyRepos lists all repositories for the authenticated user that has access to.
|
||||||
func (c *Client) ListMyRepos() ([]*Repository, error) {
|
func (c *Client) ListMyRepos() ([]*Repository, error) {
|
||||||
repos := make([]*Repository, 0, 10)
|
repos := make([]*Repository, 0, 10)
|
||||||
|
@ -69,36 +67,24 @@ func (c *Client) ListOrgRepos(org string) ([]*Repository, error) {
|
||||||
}
|
}
|
||||||
|
|
||||||
// CreateRepoOption options when creating repository
|
// CreateRepoOption options when creating repository
|
||||||
//swagger:parameters createOrgRepo
|
// swagger:model
|
||||||
type CreateRepoOption struct {
|
type CreateRepoOption struct {
|
||||||
// Name of the repository to create
|
// Name of the repository to create
|
||||||
//
|
//
|
||||||
// in: body
|
// required: true
|
||||||
// unique: true
|
// unique: true
|
||||||
Name string `json:"name" binding:"Required;AlphaDashDot;MaxSize(100)"`
|
Name string `json:"name" binding:"Required;AlphaDashDot;MaxSize(100)"`
|
||||||
// Description of the repository to create
|
// Description of the repository to create
|
||||||
//
|
|
||||||
// in: body
|
|
||||||
Description string `json:"description" binding:"MaxSize(255)"`
|
Description string `json:"description" binding:"MaxSize(255)"`
|
||||||
// Is the repository to create private ?
|
// Whether the repository is private
|
||||||
//
|
|
||||||
// in: body
|
|
||||||
Private bool `json:"private"`
|
Private bool `json:"private"`
|
||||||
// Init the repository to create ?
|
// Whether the repository should be auto-intialized?
|
||||||
//
|
|
||||||
// in: body
|
|
||||||
AutoInit bool `json:"auto_init"`
|
AutoInit bool `json:"auto_init"`
|
||||||
// Gitignores to use
|
// Gitignores to use
|
||||||
//
|
|
||||||
// in: body
|
|
||||||
Gitignores string `json:"gitignores"`
|
Gitignores string `json:"gitignores"`
|
||||||
// License to use
|
// License to use
|
||||||
//
|
|
||||||
// in: body
|
|
||||||
License string `json:"license"`
|
License string `json:"license"`
|
||||||
// Readme of the repository to create
|
// Readme of the repository to create
|
||||||
//
|
|
||||||
// in: body
|
|
||||||
Readme string `json:"readme"`
|
Readme string `json:"readme"`
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -134,16 +120,19 @@ func (c *Client) DeleteRepo(owner, repo string) error {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
|
||||||
// MigrateRepoOption options when migrate repository from an external place
|
// MigrateRepoOption options for migrating a repository from an external service
|
||||||
type MigrateRepoOption struct {
|
type MigrateRepoOption struct {
|
||||||
|
// required: true
|
||||||
CloneAddr string `json:"clone_addr" binding:"Required"`
|
CloneAddr string `json:"clone_addr" binding:"Required"`
|
||||||
AuthUsername string `json:"auth_username"`
|
AuthUsername string `json:"auth_username"`
|
||||||
AuthPassword string `json:"auth_password"`
|
AuthPassword string `json:"auth_password"`
|
||||||
UID int `json:"uid" binding:"Required"`
|
// required: true
|
||||||
RepoName string `json:"repo_name" binding:"Required"`
|
UID int `json:"uid" binding:"Required"`
|
||||||
Mirror bool `json:"mirror"`
|
// required: true
|
||||||
Private bool `json:"private"`
|
RepoName string `json:"repo_name" binding:"Required"`
|
||||||
Description string `json:"description"`
|
Mirror bool `json:"mirror"`
|
||||||
|
Private bool `json:"private"`
|
||||||
|
Description string `json:"description"`
|
||||||
}
|
}
|
||||||
|
|
||||||
// MigrateRepo migrates a repository from other Git hosting sources for the
|
// MigrateRepo migrates a repository from other Git hosting sources for the
|
||||||
|
|
|
@ -8,7 +8,7 @@ import (
|
||||||
"fmt"
|
"fmt"
|
||||||
)
|
)
|
||||||
|
|
||||||
// Branch represents a repository branch.
|
// Branch represents a repository branch
|
||||||
type Branch struct {
|
type Branch struct {
|
||||||
Name string `json:"name"`
|
Name string `json:"name"`
|
||||||
Commit *PayloadCommit `json:"commit"`
|
Commit *PayloadCommit `json:"commit"`
|
||||||
|
|
|
@ -33,7 +33,7 @@ func (c *Client) IsCollaborator(user, repo, collaborator string) (bool, error) {
|
||||||
return false, nil
|
return false, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
// AddCollaboratorOption options when add some user as a collaborator of a repository
|
// AddCollaboratorOption options when adding a user as a collaborator of a repository
|
||||||
type AddCollaboratorOption struct {
|
type AddCollaboratorOption struct {
|
||||||
Permission *string `json:"permission"`
|
Permission *string `json:"permission"`
|
||||||
}
|
}
|
||||||
|
|
|
@ -13,12 +13,16 @@ import (
|
||||||
|
|
||||||
// DeployKey a deploy key
|
// DeployKey a deploy key
|
||||||
type DeployKey struct {
|
type DeployKey struct {
|
||||||
ID int64 `json:"id"`
|
ID int64 `json:"id"`
|
||||||
Key string `json:"key"`
|
KeyID int64 `json:"key_id"`
|
||||||
URL string `json:"url"`
|
Key string `json:"key"`
|
||||||
Title string `json:"title"`
|
URL string `json:"url"`
|
||||||
Created time.Time `json:"created_at"`
|
Title string `json:"title"`
|
||||||
ReadOnly bool `json:"read_only"`
|
Fingerprint string `json:"fingerprint"`
|
||||||
|
// swagger:strfmt date-time
|
||||||
|
Created time.Time `json:"created_at"`
|
||||||
|
ReadOnly bool `json:"read_only"`
|
||||||
|
Repository *Repository `json:"repository,omitempty"`
|
||||||
}
|
}
|
||||||
|
|
||||||
// ListDeployKeys list all the deploy keys of one repository
|
// ListDeployKeys list all the deploy keys of one repository
|
||||||
|
@ -33,21 +37,22 @@ func (c *Client) GetDeployKey(user, repo string, keyID int64) (*DeployKey, error
|
||||||
return key, c.getParsedResponse("GET", fmt.Sprintf("/repos/%s/%s/keys/%d", user, repo, keyID), nil, nil, &key)
|
return key, c.getParsedResponse("GET", fmt.Sprintf("/repos/%s/%s/keys/%d", user, repo, keyID), nil, nil, &key)
|
||||||
}
|
}
|
||||||
|
|
||||||
// CreateKeyOption options when create deploy key
|
// CreateKeyOption options when creating a key
|
||||||
// swagger:parameters userCurrentPostKey
|
|
||||||
type CreateKeyOption struct {
|
type CreateKeyOption struct {
|
||||||
// Title of the key to add
|
// Title of the key to add
|
||||||
//
|
//
|
||||||
// in: body
|
|
||||||
// required: true
|
// required: true
|
||||||
// unique: true
|
// unique: true
|
||||||
Title string `json:"title" binding:"Required"`
|
Title string `json:"title" binding:"Required"`
|
||||||
// An armored SSH key to add
|
// An armored SSH key to add
|
||||||
//
|
//
|
||||||
// in: body
|
|
||||||
// required: true
|
// required: true
|
||||||
// unique: true
|
// unique: true
|
||||||
Key string `json:"key" binding:"Required"`
|
Key string `json:"key" binding:"Required"`
|
||||||
|
// Describe if the key has only read access or read/write
|
||||||
|
//
|
||||||
|
// required: false
|
||||||
|
ReadOnly bool `json:"read_only"`
|
||||||
}
|
}
|
||||||
|
|
||||||
// CreateDeployKey options when create one deploy key
|
// CreateDeployKey options when create one deploy key
|
||||||
|
|
69
gitea/repo_refs.go
Normal file
69
gitea/repo_refs.go
Normal file
|
@ -0,0 +1,69 @@
|
||||||
|
// Copyright 2018 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
|
||||||
|
|
||||||
|
import (
|
||||||
|
"encoding/json"
|
||||||
|
"errors"
|
||||||
|
"fmt"
|
||||||
|
"strings"
|
||||||
|
)
|
||||||
|
|
||||||
|
// Reference represents a Git reference.
|
||||||
|
type Reference struct {
|
||||||
|
Ref string `json:"ref"`
|
||||||
|
URL string `json:"url"`
|
||||||
|
Object *GitObject `json:"object"`
|
||||||
|
}
|
||||||
|
|
||||||
|
// GitObject represents a Git object.
|
||||||
|
type GitObject struct {
|
||||||
|
Type string `json:"type"`
|
||||||
|
SHA string `json:"sha"`
|
||||||
|
URL string `json:"url"`
|
||||||
|
}
|
||||||
|
|
||||||
|
// GetRepoRef get one ref's information of one repository
|
||||||
|
func (c *Client) GetRepoRef(user, repo, ref string) (*Reference, error) {
|
||||||
|
ref = strings.TrimPrefix(ref, "refs/")
|
||||||
|
r := new(Reference)
|
||||||
|
err := c.getParsedResponse("GET", fmt.Sprintf("/repos/%s/%s/git/refs/%s", user, repo, ref), nil, nil, &r)
|
||||||
|
if _, ok := err.(*json.UnmarshalTypeError); ok {
|
||||||
|
// Multiple refs
|
||||||
|
return nil, errors.New("no exact match found for this ref")
|
||||||
|
} else if err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
|
||||||
|
return r, nil
|
||||||
|
}
|
||||||
|
|
||||||
|
// GetRepoRefs get list of ref's information of one repository
|
||||||
|
func (c *Client) GetRepoRefs(user, repo, ref string) ([]*Reference, error) {
|
||||||
|
ref = strings.TrimPrefix(ref, "refs/")
|
||||||
|
resp, err := c.getResponse("GET", fmt.Sprintf("/repos/%s/%s/git/refs/%s", user, repo, ref), nil, nil)
|
||||||
|
if err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
|
||||||
|
// Attempt to unmarshal single returned ref.
|
||||||
|
r := new(Reference)
|
||||||
|
refErr := json.Unmarshal(resp, r)
|
||||||
|
if refErr == nil {
|
||||||
|
return []*Reference{r}, nil
|
||||||
|
}
|
||||||
|
|
||||||
|
// Attempt to unmarshal multiple refs.
|
||||||
|
var rs []*Reference
|
||||||
|
refsErr := json.Unmarshal(resp, &rs)
|
||||||
|
if refsErr == nil {
|
||||||
|
if len(rs) == 0 {
|
||||||
|
return nil, errors.New("unexpected response: an array of refs with length 0")
|
||||||
|
}
|
||||||
|
return rs, nil
|
||||||
|
}
|
||||||
|
|
||||||
|
return nil, fmt.Errorf("unmarshalling failed for both single and multiple refs: %s and %s", refErr, refsErr)
|
||||||
|
}
|
39
gitea/repo_tree.go
Normal file
39
gitea/repo_tree.go
Normal file
|
@ -0,0 +1,39 @@
|
||||||
|
// Copyright 2018 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
|
||||||
|
|
||||||
|
import (
|
||||||
|
"fmt"
|
||||||
|
)
|
||||||
|
|
||||||
|
// GitEntry represents a git tree
|
||||||
|
type GitEntry struct {
|
||||||
|
Path string `json:"path"`
|
||||||
|
Mode string `json:"mode"`
|
||||||
|
Type string `json:"type"`
|
||||||
|
Size int64 `json:"size"`
|
||||||
|
SHA string `json:"sha"`
|
||||||
|
URL string `json:"url"`
|
||||||
|
}
|
||||||
|
|
||||||
|
// GitTreeResponse returns a git tree
|
||||||
|
type GitTreeResponse struct {
|
||||||
|
SHA string `json:"sha"`
|
||||||
|
URL string `json:"url"`
|
||||||
|
Entries []GitEntry `json:"tree"`
|
||||||
|
Truncated bool `json:"truncated"`
|
||||||
|
}
|
||||||
|
|
||||||
|
// GetTrees downloads a file of repository, ref can be branch/tag/commit.
|
||||||
|
// e.g.: ref -> master, tree -> macaron.go(no leading slash)
|
||||||
|
func (c *Client) GetTrees(user, repo, ref string, recursive bool) (*GitTreeResponse, error) {
|
||||||
|
var trees GitTreeResponse
|
||||||
|
var path = fmt.Sprintf("/repos/%s/%s/git/trees/%s", user, repo, ref)
|
||||||
|
if recursive {
|
||||||
|
path += "?recursive=1"
|
||||||
|
}
|
||||||
|
err := c.getParsedResponse("GET", path, nil, nil, &trees)
|
||||||
|
return &trees, err
|
||||||
|
}
|
|
@ -10,8 +10,7 @@ import (
|
||||||
"time"
|
"time"
|
||||||
)
|
)
|
||||||
|
|
||||||
// WatchInfo represents a API watch status of one repository
|
// WatchInfo represents an API watch status of one repository
|
||||||
// swagger:response WatchInfo
|
|
||||||
type WatchInfo struct {
|
type WatchInfo struct {
|
||||||
Subscribed bool `json:"subscribed"`
|
Subscribed bool `json:"subscribed"`
|
||||||
Ignored bool `json:"ignored"`
|
Ignored bool `json:"ignored"`
|
||||||
|
|
|
@ -21,7 +21,7 @@ const (
|
||||||
// StatusSuccess is for when the Status is Success
|
// StatusSuccess is for when the Status is Success
|
||||||
StatusSuccess StatusState = "success"
|
StatusSuccess StatusState = "success"
|
||||||
// StatusError is for when the Status is Error
|
// StatusError is for when the Status is Error
|
||||||
StatusError StatusState = "error"
|
StatusError StatusState = "error"
|
||||||
// StatusFailure is for when the Status is Failure
|
// StatusFailure is for when the Status is Failure
|
||||||
StatusFailure StatusState = "failure"
|
StatusFailure StatusState = "failure"
|
||||||
// StatusWarning is for when the Status is Warning
|
// StatusWarning is for when the Status is Warning
|
||||||
|
@ -37,8 +37,10 @@ type Status struct {
|
||||||
URL string `json:"url"`
|
URL string `json:"url"`
|
||||||
Context string `json:"context"`
|
Context string `json:"context"`
|
||||||
Creator *User `json:"creator"`
|
Creator *User `json:"creator"`
|
||||||
Created time.Time `json:"created_at"`
|
// swagger:strfmt date-time
|
||||||
Updated time.Time `json:"updated_at"`
|
Created time.Time `json:"created_at"`
|
||||||
|
// swagger:strfmt date-time
|
||||||
|
Updated time.Time `json:"updated_at"`
|
||||||
}
|
}
|
||||||
|
|
||||||
// CombinedStatus holds the combined state of several statuses for a single commit
|
// CombinedStatus holds the combined state of several statuses for a single commit
|
||||||
|
|
|
@ -9,20 +9,23 @@ import (
|
||||||
"fmt"
|
"fmt"
|
||||||
)
|
)
|
||||||
|
|
||||||
// User represents a API user.
|
// User represents a user
|
||||||
// swagger:response User
|
// swagger:model
|
||||||
type User struct {
|
type User struct {
|
||||||
ID int64 `json:"id"`
|
// the user's id
|
||||||
UserName string `json:"login"`
|
ID int64 `json:"id"`
|
||||||
FullName string `json:"full_name"`
|
// the user's username
|
||||||
Email string `json:"email"`
|
UserName string `json:"login"`
|
||||||
|
// the user's full name
|
||||||
|
FullName string `json:"full_name"`
|
||||||
|
// swagger:strfmt email
|
||||||
|
Email string `json:"email"`
|
||||||
|
// URL to the user's avatar
|
||||||
AvatarURL string `json:"avatar_url"`
|
AvatarURL string `json:"avatar_url"`
|
||||||
|
// User locale
|
||||||
|
Language string `json:"language"`
|
||||||
}
|
}
|
||||||
|
|
||||||
// UserList represents a list of API user.
|
|
||||||
// swagger:response UserList
|
|
||||||
type UserList []*User
|
|
||||||
|
|
||||||
// MarshalJSON implements the json.Marshaler interface for User, adding field(s) for backward compatibility
|
// MarshalJSON implements the json.Marshaler interface for User, adding field(s) for backward compatibility
|
||||||
func (u User) MarshalJSON() ([]byte, error) {
|
func (u User) MarshalJSON() ([]byte, error) {
|
||||||
// Re-declaring User to avoid recursion
|
// Re-declaring User to avoid recursion
|
||||||
|
@ -39,3 +42,10 @@ func (c *Client) GetUserInfo(user string) (*User, error) {
|
||||||
err := c.getParsedResponse("GET", fmt.Sprintf("/users/%s", user), nil, nil, u)
|
err := c.getParsedResponse("GET", fmt.Sprintf("/users/%s", user), nil, nil, u)
|
||||||
return u, err
|
return u, err
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// GetMyUserInfo get user info of current user
|
||||||
|
func (c *Client) GetMyUserInfo() (*User, error) {
|
||||||
|
u := new(User)
|
||||||
|
err := c.getParsedResponse("GET", "/user", nil, nil, u)
|
||||||
|
return u, err
|
||||||
|
}
|
||||||
|
|
|
@ -20,13 +20,14 @@ func BasicAuthEncode(user, pass string) string {
|
||||||
// AccessToken represents a API access token.
|
// AccessToken represents a API access token.
|
||||||
// swagger:response AccessToken
|
// swagger:response AccessToken
|
||||||
type AccessToken struct {
|
type AccessToken struct {
|
||||||
|
ID int64 `json:"id"`
|
||||||
Name string `json:"name"`
|
Name string `json:"name"`
|
||||||
Sha1 string `json:"sha1"`
|
Sha1 string `json:"sha1"`
|
||||||
}
|
}
|
||||||
|
|
||||||
// AccessTokenList represents a list of API access token.
|
// AccessTokenList represents a list of API access token.
|
||||||
// swagger:response AccessTokenList
|
// swagger:response AccessTokenList
|
||||||
type AccessTokenList []*AccessToken
|
type AccessTokenList []*AccessToken
|
||||||
|
|
||||||
// ListAccessTokens lista all the access tokens of user
|
// ListAccessTokens lista all the access tokens of user
|
||||||
func (c *Client) ListAccessTokens(user, pass string) ([]*AccessToken, error) {
|
func (c *Client) ListAccessTokens(user, pass string) ([]*AccessToken, error) {
|
||||||
|
@ -54,3 +55,9 @@ func (c *Client) CreateAccessToken(user, pass string, opt CreateAccessTokenOptio
|
||||||
"Authorization": []string{"Basic " + BasicAuthEncode(user, pass)}},
|
"Authorization": []string{"Basic " + BasicAuthEncode(user, pass)}},
|
||||||
bytes.NewReader(body), t)
|
bytes.NewReader(body), t)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// DeleteAccessToken delete token with key id
|
||||||
|
func (c *Client) DeleteAccessToken(user string, keyID int64) error {
|
||||||
|
_, err := c.getResponse("DELETE", fmt.Sprintf("/user/%s/tokens/%d", user, keyID), nil, nil)
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
|
|
@ -9,8 +9,9 @@ import (
|
||||||
"encoding/json"
|
"encoding/json"
|
||||||
)
|
)
|
||||||
|
|
||||||
// Email en email information of user
|
// Email an email address belonging to a user
|
||||||
type Email struct {
|
type Email struct {
|
||||||
|
// swagger:strfmt email
|
||||||
Email string `json:"email"`
|
Email string `json:"email"`
|
||||||
Verified bool `json:"verified"`
|
Verified bool `json:"verified"`
|
||||||
Primary bool `json:"primary"`
|
Primary bool `json:"primary"`
|
||||||
|
@ -22,8 +23,9 @@ func (c *Client) ListEmails() ([]*Email, error) {
|
||||||
return emails, c.getParsedResponse("GET", "/user/emails", nil, nil, &emails)
|
return emails, c.getParsedResponse("GET", "/user/emails", nil, nil, &emails)
|
||||||
}
|
}
|
||||||
|
|
||||||
// CreateEmailOption options when create an email
|
// CreateEmailOption options when creating email addresses
|
||||||
type CreateEmailOption struct {
|
type CreateEmailOption struct {
|
||||||
|
// email addresses to add
|
||||||
Emails []string `json:"emails"`
|
Emails []string `json:"emails"`
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -37,8 +39,14 @@ func (c *Client) AddEmail(opt CreateEmailOption) ([]*Email, error) {
|
||||||
return emails, c.getParsedResponse("POST", "/user/emails", jsonHeader, bytes.NewReader(body), emails)
|
return emails, c.getParsedResponse("POST", "/user/emails", jsonHeader, bytes.NewReader(body), emails)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// DeleteEmailOption options when deleting email addresses
|
||||||
|
type DeleteEmailOption struct {
|
||||||
|
// email addresses to delete
|
||||||
|
Emails []string `json:"emails"`
|
||||||
|
}
|
||||||
|
|
||||||
// DeleteEmail delete one email of current users'
|
// DeleteEmail delete one email of current users'
|
||||||
func (c *Client) DeleteEmail(opt CreateEmailOption) error {
|
func (c *Client) DeleteEmail(opt DeleteEmailOption) error {
|
||||||
body, err := json.Marshal(&opt)
|
body, err := json.Marshal(&opt)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
|
|
|
@ -11,12 +11,7 @@ import (
|
||||||
"time"
|
"time"
|
||||||
)
|
)
|
||||||
|
|
||||||
// GPGKeyList represents a list of GPGKey
|
|
||||||
// swagger:response GPGKeyList
|
|
||||||
type GPGKeyList []*GPGKey
|
|
||||||
|
|
||||||
// GPGKey a user GPG key to sign commit and tag in repository
|
// GPGKey a user GPG key to sign commit and tag in repository
|
||||||
// swagger:response GPGKey
|
|
||||||
type GPGKey struct {
|
type GPGKey struct {
|
||||||
ID int64 `json:"id"`
|
ID int64 `json:"id"`
|
||||||
PrimaryKeyID string `json:"primary_key_id"`
|
PrimaryKeyID string `json:"primary_key_id"`
|
||||||
|
@ -28,11 +23,13 @@ type GPGKey struct {
|
||||||
CanEncryptComms bool `json:"can_encrypt_comms"`
|
CanEncryptComms bool `json:"can_encrypt_comms"`
|
||||||
CanEncryptStorage bool `json:"can_encrypt_storage"`
|
CanEncryptStorage bool `json:"can_encrypt_storage"`
|
||||||
CanCertify bool `json:"can_certify"`
|
CanCertify bool `json:"can_certify"`
|
||||||
Created time.Time `json:"created_at,omitempty"`
|
// swagger:strfmt date-time
|
||||||
Expires time.Time `json:"expires_at,omitempty"`
|
Created time.Time `json:"created_at,omitempty"`
|
||||||
|
// swagger:strfmt date-time
|
||||||
|
Expires time.Time `json:"expires_at,omitempty"`
|
||||||
}
|
}
|
||||||
|
|
||||||
// GPGKeyEmail a email attache to a GPGKey
|
// GPGKeyEmail an email attached to a GPGKey
|
||||||
// swagger:model GPGKeyEmail
|
// swagger:model GPGKeyEmail
|
||||||
type GPGKeyEmail struct {
|
type GPGKeyEmail struct {
|
||||||
Email string `json:"email"`
|
Email string `json:"email"`
|
||||||
|
@ -40,11 +37,9 @@ type GPGKeyEmail struct {
|
||||||
}
|
}
|
||||||
|
|
||||||
// CreateGPGKeyOption options create user GPG key
|
// CreateGPGKeyOption options create user GPG key
|
||||||
// swagger:parameters userCurrentPostGPGKey
|
|
||||||
type CreateGPGKeyOption struct {
|
type CreateGPGKeyOption struct {
|
||||||
// An armored GPG key to add
|
// An armored GPG key to add
|
||||||
//
|
//
|
||||||
// in: body
|
|
||||||
// required: true
|
// required: true
|
||||||
// unique: true
|
// unique: true
|
||||||
ArmoredKey string `json:"armored_public_key" binding:"Required"`
|
ArmoredKey string `json:"armored_public_key" binding:"Required"`
|
||||||
|
|
|
@ -11,18 +11,18 @@ import (
|
||||||
"time"
|
"time"
|
||||||
)
|
)
|
||||||
|
|
||||||
// PublicKeyList represents a list of PublicKey
|
|
||||||
// swagger:response PublicKeyList
|
|
||||||
type PublicKeyList []*PublicKey
|
|
||||||
|
|
||||||
// PublicKey publickey is a user key to push code to repository
|
// PublicKey publickey is a user key to push code to repository
|
||||||
// swagger:response PublicKey
|
|
||||||
type PublicKey struct {
|
type PublicKey struct {
|
||||||
ID int64 `json:"id"`
|
ID int64 `json:"id"`
|
||||||
Key string `json:"key"`
|
Key string `json:"key"`
|
||||||
URL string `json:"url,omitempty"`
|
URL string `json:"url,omitempty"`
|
||||||
Title string `json:"title,omitempty"`
|
Title string `json:"title,omitempty"`
|
||||||
Created time.Time `json:"created_at,omitempty"`
|
Fingerprint string `json:"fingerprint,omitempty"`
|
||||||
|
// swagger:strfmt date-time
|
||||||
|
Created time.Time `json:"created_at,omitempty"`
|
||||||
|
Owner *User `json:"user,omitempty"`
|
||||||
|
ReadOnly bool `json:"read_only,omitempty"`
|
||||||
|
KeyType string `json:"key_type,omitempty"`
|
||||||
}
|
}
|
||||||
|
|
||||||
// ListPublicKeys list all the public keys of the user
|
// ListPublicKeys list all the public keys of the user
|
||||||
|
|
14
gitea/user_search.go
Normal file
14
gitea/user_search.go
Normal file
|
@ -0,0 +1,14 @@
|
||||||
|
package gitea
|
||||||
|
|
||||||
|
import "fmt"
|
||||||
|
|
||||||
|
type searchUsersResponse struct {
|
||||||
|
Users []*User `json:"data"`
|
||||||
|
}
|
||||||
|
|
||||||
|
// SearchUsers finds users by query
|
||||||
|
func (c *Client) SearchUsers(query string, limit int) ([]*User, error) {
|
||||||
|
resp := new(searchUsersResponse)
|
||||||
|
err := c.getParsedResponse("GET", fmt.Sprintf("/users/search?q=%s&limit=%d", query, limit), nil, nil, &resp)
|
||||||
|
return resp.Users, err
|
||||||
|
}
|
Loading…
Reference in New Issue
Block a user