mirror of
https://gitea.com/gitea/tea.git
synced 2025-09-19 02:02:55 +02:00
Compare commits
22 Commits
Author | SHA1 | Date | |
---|---|---|---|
9602c149ca | |||
cf2c18c32b | |||
887495f38f | |||
159bf03d49 | |||
288a8574c3 | |||
2e701ee8a2 | |||
eacf1be066 | |||
3652f1dcb2 | |||
d7f429d246 | |||
89e93d90b3 | |||
f8d983b523 | |||
7c30579900 | |||
e4d7a77348 | |||
83b94ab864 | |||
3c1bcdb1e2 | |||
f47ac8f96e | |||
ed961c795e | |||
e7ee745488 | |||
9ae7196a50 | |||
25a7e85c1c | |||
eb37f14923 | |||
edd180a8f5 |
@ -13,7 +13,7 @@ workspace:
|
||||
steps:
|
||||
- name: build
|
||||
pull: always
|
||||
image: golang:1.13
|
||||
image: golang:1.15
|
||||
environment:
|
||||
GOPROXY: https://goproxy.cn
|
||||
commands:
|
||||
@ -32,7 +32,7 @@ steps:
|
||||
|
||||
- name: unit-test
|
||||
pull: always
|
||||
image: golang:1.13
|
||||
image: golang:1.15
|
||||
commands:
|
||||
- make unit-test-coverage
|
||||
settings:
|
||||
@ -46,7 +46,7 @@ steps:
|
||||
|
||||
- name: release-test
|
||||
pull: always
|
||||
image: golang:1.13
|
||||
image: golang:1.15
|
||||
commands:
|
||||
- make test
|
||||
settings:
|
||||
@ -60,7 +60,7 @@ steps:
|
||||
|
||||
- name: tag-test
|
||||
pull: always
|
||||
image: golang:1.13
|
||||
image: golang:1.15
|
||||
commands:
|
||||
- make test
|
||||
settings:
|
||||
|
28
CHANGELOG.md
28
CHANGELOG.md
@ -1,5 +1,33 @@
|
||||
# Changelog
|
||||
|
||||
## [v0.5.0](https://gitea.com/gitea/tea/releases/tag/v0.5.0) - 2020-09-27
|
||||
|
||||
* BREAKING
|
||||
* Add Login Manage Functions (#182)
|
||||
* FEATURES
|
||||
* Add Release Subcomands (#195)
|
||||
* Render Markdown and colorize labels table (#181)
|
||||
* Add BasicAuth & Interactive for Login (#174)
|
||||
* Add milestones subcomands (#149)
|
||||
* BUGFIXES
|
||||
* Fix Pulls Create (#202)
|
||||
* Pulls create: detect head branch repo owner (#193)
|
||||
* Fix Labels Delete (#180)
|
||||
* ENHANCEMENTS
|
||||
* Add Pagination Options for List Subcomands (#204)
|
||||
* Issues/Pulls: Details show State (#196)
|
||||
* Make issues & pulls subcommands consistent (#188)
|
||||
* Update SDK to v0.13.0 (#179)
|
||||
* More Options To Specify Repo (#178)
|
||||
* Add Repo Create subcomand & enhancements (#173)
|
||||
* Times: format duration as seconds for machine-readable outputs (#168)
|
||||
* Add user message to login list view (#166)
|
||||
|
||||
## [v0.4.1](https://gitea.com/gitea/tea/releases/tag/v0.4.1) - 2020-09-13
|
||||
|
||||
* BUGFIXES
|
||||
* Notification don't relay on a repo (#159)
|
||||
|
||||
## [v0.4.0](https://gitea.com/gitea/tea/pulls?q=&type=all&state=closed&milestone=1264) - 2020-07-18
|
||||
|
||||
* FEATURES
|
||||
|
2
Makefile
2
Makefile
@ -71,7 +71,7 @@ vet:
|
||||
# Default vet
|
||||
$(GO) vet -mod=vendor $(PACKAGES)
|
||||
# Custom vet
|
||||
$(GO) build -mod=vendor gitea.com/jolheiser/gitea-vet
|
||||
$(GO) build -mod=vendor code.gitea.io/gitea-vet
|
||||
$(GO) vet -vettool=gitea-vet $(PACKAGES)
|
||||
|
||||
.PHONY: lint
|
||||
|
@ -14,7 +14,7 @@ It uses [code.gitea.io/sdk](https://code.gitea.io/sdk) and interacts with the Gi
|
||||
You can use the prebuilt binaries from [dl.gitea.io](https://dl.gitea.io/tea/)
|
||||
|
||||
|
||||
To install from source, go 1.12 or newer is required:
|
||||
To install from source, go 1.13 or newer is required:
|
||||
```sh
|
||||
go get code.gitea.io/tea
|
||||
go install code.gitea.io/tea
|
||||
@ -46,12 +46,14 @@ Detailed usage information is available via `tea <command> --help`.
|
||||
login Log in to a Gitea server
|
||||
logout Log out from a Gitea server
|
||||
issues List, create and update issues
|
||||
pulls List, checkout and clean pull requests
|
||||
releases Create releases
|
||||
pulls List, create, checkout and clean pull requests
|
||||
releases List, create, update and delete releases
|
||||
repos Operate with repositories
|
||||
labels Manage issue labels
|
||||
times Operate on tracked times of a repositorys issues and pulls
|
||||
open Open something of the repository on web browser
|
||||
notifications Show notifications
|
||||
milestones List and create milestones
|
||||
```
|
||||
|
||||
To fetch issues from different repos, use the `--remote` flag (when inside a gitea repository directory) or `--login` & `--repo` flags.
|
||||
|
2
build.go
2
build.go
@ -10,5 +10,5 @@ package main
|
||||
|
||||
import (
|
||||
// for vet
|
||||
_ "gitea.com/jolheiser/gitea-vet"
|
||||
_ "code.gitea.io/gitea-vet"
|
||||
)
|
||||
|
@ -21,6 +21,8 @@ import (
|
||||
"code.gitea.io/tea/modules/git"
|
||||
"code.gitea.io/tea/modules/utils"
|
||||
|
||||
"github.com/muesli/termenv"
|
||||
"github.com/urfave/cli/v2"
|
||||
"gopkg.in/yaml.v2"
|
||||
)
|
||||
|
||||
@ -29,7 +31,7 @@ type Login struct {
|
||||
Name string `yaml:"name"`
|
||||
URL string `yaml:"url"`
|
||||
Token string `yaml:"token"`
|
||||
Active bool `yaml:"active"`
|
||||
Default bool `yaml:"default"`
|
||||
SSHHost string `yaml:"ssh_host"`
|
||||
// optional path to the private key
|
||||
SSHKey string `yaml:"ssh_key"`
|
||||
@ -40,16 +42,23 @@ type Login struct {
|
||||
|
||||
// Client returns a client to operate Gitea API
|
||||
func (l *Login) Client() *gitea.Client {
|
||||
client := gitea.NewClient(l.URL, l.Token)
|
||||
httpClient := &http.Client{}
|
||||
if l.Insecure {
|
||||
cookieJar, _ := cookiejar.New(nil)
|
||||
|
||||
client.SetHTTPClient(&http.Client{
|
||||
httpClient = &http.Client{
|
||||
Jar: cookieJar,
|
||||
Transport: &http.Transport{
|
||||
TLSClientConfig: &tls.Config{InsecureSkipVerify: true},
|
||||
},
|
||||
})
|
||||
}}
|
||||
}
|
||||
|
||||
client, err := gitea.NewClient(l.URL,
|
||||
gitea.SetToken(l.Token),
|
||||
gitea.SetHTTPClient(httpClient),
|
||||
)
|
||||
if err != nil {
|
||||
log.Fatal(err)
|
||||
}
|
||||
return client
|
||||
}
|
||||
@ -93,20 +102,30 @@ func init() {
|
||||
yamlConfigPath = filepath.Join(dir, "tea.yml")
|
||||
}
|
||||
|
||||
func splitRepo(repoPath string) (string, string) {
|
||||
func getGlamourTheme() string {
|
||||
if termenv.HasDarkBackground() {
|
||||
return "dark"
|
||||
}
|
||||
return "light"
|
||||
}
|
||||
|
||||
func getOwnerAndRepo(repoPath, user string) (string, string) {
|
||||
if len(repoPath) == 0 {
|
||||
return "", ""
|
||||
}
|
||||
p := strings.Split(repoPath, "/")
|
||||
if len(p) >= 2 {
|
||||
return p[0], p[1]
|
||||
}
|
||||
return repoPath, ""
|
||||
return user, repoPath
|
||||
}
|
||||
|
||||
func getActiveLogin() (*Login, error) {
|
||||
func getDefaultLogin() (*Login, error) {
|
||||
if len(config.Logins) == 0 {
|
||||
return nil, errors.New("No available login")
|
||||
}
|
||||
for _, l := range config.Logins {
|
||||
if l.Active {
|
||||
if l.Default {
|
||||
return &l, nil
|
||||
}
|
||||
}
|
||||
@ -197,6 +216,9 @@ func curGitRepoPath(path string) (*Login, string, error) {
|
||||
} else {
|
||||
repo, err = git.RepoFromPath(path)
|
||||
}
|
||||
if err != nil {
|
||||
return nil, "", err
|
||||
}
|
||||
gitConfig, err := repo.Config()
|
||||
if err != nil {
|
||||
return nil, "", err
|
||||
@ -250,3 +272,15 @@ func curGitRepoPath(path string) (*Login, string, error) {
|
||||
|
||||
return nil, "", errors.New("No Gitea login found. You might want to specify --repo (and --login) to work outside of a repository")
|
||||
}
|
||||
|
||||
func getListOptions(ctx *cli.Context) gitea.ListOptions {
|
||||
page := ctx.Int("page")
|
||||
limit := ctx.Int("limit")
|
||||
if limit != 0 && page == 0 {
|
||||
page = 1
|
||||
}
|
||||
return gitea.ListOptions{
|
||||
Page: page,
|
||||
PageSize: limit,
|
||||
}
|
||||
}
|
||||
|
49
cmd/flags.go
49
cmd/flags.go
@ -7,6 +7,8 @@ package cmd
|
||||
import (
|
||||
"log"
|
||||
|
||||
"code.gitea.io/tea/modules/utils"
|
||||
|
||||
"github.com/urfave/cli/v2"
|
||||
)
|
||||
|
||||
@ -51,6 +53,27 @@ var OutputFlag = cli.StringFlag{
|
||||
Destination: &outputValue,
|
||||
}
|
||||
|
||||
// StateFlag provides flag to specify issue/pr state, defaulting to "open"
|
||||
var StateFlag = cli.StringFlag{
|
||||
Name: "state",
|
||||
Usage: "Filter by state (all|open|closed)",
|
||||
DefaultText: "open",
|
||||
}
|
||||
|
||||
// PaginationPageFlag provides flag for pagination options
|
||||
var PaginationPageFlag = cli.StringFlag{
|
||||
Name: "page",
|
||||
Aliases: []string{"p"},
|
||||
Usage: "specify page, default is 1",
|
||||
}
|
||||
|
||||
// PaginationLimitFlag provides flag for pagination options
|
||||
var PaginationLimitFlag = cli.StringFlag{
|
||||
Name: "limit",
|
||||
Aliases: []string{"lm"},
|
||||
Usage: "specify limit of items per page",
|
||||
}
|
||||
|
||||
// LoginOutputFlags defines login and output flags that should
|
||||
// added to all subcommands and appended to the flags of the
|
||||
// subcommand to work around issue and provide --login and --output:
|
||||
@ -79,18 +102,38 @@ var AllDefaultFlags = append([]cli.Flag{
|
||||
&RemoteFlag,
|
||||
}, LoginOutputFlags...)
|
||||
|
||||
// IssuePRFlags defines flags that should be available on issue & pr listing flags.
|
||||
var IssuePRFlags = append([]cli.Flag{
|
||||
&StateFlag,
|
||||
&PaginationPageFlag,
|
||||
&PaginationLimitFlag,
|
||||
}, AllDefaultFlags...)
|
||||
|
||||
// initCommand returns repository and *Login based on flags
|
||||
func initCommand() (*Login, string, string) {
|
||||
var login *Login
|
||||
|
||||
err := loadConfig(yamlConfigPath)
|
||||
if err != nil {
|
||||
log.Fatal("load config file failed ", yamlConfigPath)
|
||||
}
|
||||
|
||||
login, repoPath, err := curGitRepoPath(repoValue)
|
||||
if login, err = getDefaultLogin(); err != nil {
|
||||
log.Fatal(err.Error())
|
||||
}
|
||||
|
||||
exist, err := utils.PathExists(repoValue)
|
||||
if err != nil {
|
||||
log.Fatal(err.Error())
|
||||
}
|
||||
|
||||
if exist || len(repoValue) == 0 {
|
||||
login, repoValue, err = curGitRepoPath(repoValue)
|
||||
if err != nil {
|
||||
log.Fatal(err.Error())
|
||||
}
|
||||
}
|
||||
|
||||
if loginValue != "" {
|
||||
login = getLoginByName(loginValue)
|
||||
if login == nil {
|
||||
@ -98,7 +141,7 @@ func initCommand() (*Login, string, string) {
|
||||
}
|
||||
}
|
||||
|
||||
owner, repo := splitRepo(repoPath)
|
||||
owner, repo := getOwnerAndRepo(repoValue, login.User)
|
||||
return login, owner, repo
|
||||
}
|
||||
|
||||
@ -111,7 +154,7 @@ func initCommandLoginOnly() *Login {
|
||||
|
||||
var login *Login
|
||||
if loginValue == "" {
|
||||
login, err = getActiveLogin()
|
||||
login, err = getDefaultLogin()
|
||||
if err != nil {
|
||||
log.Fatal(err)
|
||||
}
|
||||
|
@ -10,15 +10,15 @@ import (
|
||||
"strconv"
|
||||
|
||||
"code.gitea.io/sdk/gitea"
|
||||
|
||||
"github.com/charmbracelet/glamour"
|
||||
"github.com/urfave/cli/v2"
|
||||
)
|
||||
|
||||
// CmdIssues represents to login a gitea server.
|
||||
var CmdIssues = cli.Command{
|
||||
Name: "issues",
|
||||
Usage: "List and create issues",
|
||||
Description: `List and create issues`,
|
||||
Usage: "List, create and update issues",
|
||||
Description: "List, create and update issues",
|
||||
ArgsUsage: "[<issue index>]",
|
||||
Action: runIssues,
|
||||
Subcommands: []*cli.Command{
|
||||
@ -27,7 +27,7 @@ var CmdIssues = cli.Command{
|
||||
&CmdIssuesReopen,
|
||||
&CmdIssuesClose,
|
||||
},
|
||||
Flags: AllDefaultFlags,
|
||||
Flags: IssuePRFlags,
|
||||
}
|
||||
|
||||
// CmdIssuesList represents a sub command of issues to list issues
|
||||
@ -36,13 +36,7 @@ var CmdIssuesList = cli.Command{
|
||||
Usage: "List issues of the repository",
|
||||
Description: `List issues of the repository`,
|
||||
Action: runIssuesList,
|
||||
Flags: append([]cli.Flag{
|
||||
&cli.StringFlag{
|
||||
Name: "state",
|
||||
Usage: "Filter by issue state (all|open|closed)",
|
||||
DefaultText: "open",
|
||||
},
|
||||
}, AllDefaultFlags...),
|
||||
Flags: IssuePRFlags,
|
||||
}
|
||||
|
||||
func runIssues(ctx *cli.Context) error {
|
||||
@ -59,17 +53,20 @@ func runIssueDetail(ctx *cli.Context, index string) error {
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
issue, err := login.Client().GetIssue(owner, repo, idx)
|
||||
issue, _, err := login.Client().GetIssue(owner, repo, idx)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
fmt.Printf("#%d %s\n%s created %s\n\n%s\n", issue.Index,
|
||||
in := fmt.Sprintf("# #%d %s (%s)\n%s created %s\n\n%s\n", issue.Index,
|
||||
issue.Title,
|
||||
issue.State,
|
||||
issue.Poster.UserName,
|
||||
issue.Created.Format("2006-01-02 15:04:05"),
|
||||
issue.Body,
|
||||
)
|
||||
out, err := glamour.Render(in, getGlamourTheme())
|
||||
fmt.Print(out)
|
||||
return nil
|
||||
}
|
||||
|
||||
@ -86,7 +83,8 @@ func runIssuesList(ctx *cli.Context) error {
|
||||
state = gitea.StateClosed
|
||||
}
|
||||
|
||||
issues, err := login.Client().ListRepoIssues(owner, repo, gitea.ListIssueOption{
|
||||
issues, _, err := login.Client().ListRepoIssues(owner, repo, gitea.ListIssueOption{
|
||||
ListOptions: getListOptions(ctx),
|
||||
State: state,
|
||||
Type: gitea.IssueTypeIssue,
|
||||
})
|
||||
@ -97,10 +95,11 @@ func runIssuesList(ctx *cli.Context) error {
|
||||
|
||||
headers := []string{
|
||||
"Index",
|
||||
"Title",
|
||||
"State",
|
||||
"Author",
|
||||
"Milestone",
|
||||
"Updated",
|
||||
"Title",
|
||||
}
|
||||
|
||||
var values [][]string
|
||||
@ -111,18 +110,23 @@ func runIssuesList(ctx *cli.Context) error {
|
||||
}
|
||||
|
||||
for _, issue := range issues {
|
||||
name := issue.Poster.FullName
|
||||
if len(name) == 0 {
|
||||
name = issue.Poster.UserName
|
||||
author := issue.Poster.FullName
|
||||
if len(author) == 0 {
|
||||
author = issue.Poster.UserName
|
||||
}
|
||||
mile := ""
|
||||
if issue.Milestone != nil {
|
||||
mile = issue.Milestone.Title
|
||||
}
|
||||
values = append(
|
||||
values,
|
||||
[]string{
|
||||
strconv.FormatInt(issue.Index, 10),
|
||||
string(issue.State),
|
||||
name,
|
||||
issue.Updated.Format("2006-01-02 15:04:05"),
|
||||
issue.Title,
|
||||
string(issue.State),
|
||||
author,
|
||||
mile,
|
||||
issue.Updated.Format("2006-01-02 15:04:05"),
|
||||
},
|
||||
)
|
||||
}
|
||||
@ -154,7 +158,7 @@ var CmdIssuesCreate = cli.Command{
|
||||
func runIssuesCreate(ctx *cli.Context) error {
|
||||
login, owner, repo := initCommand()
|
||||
|
||||
_, err := login.Client().CreateIssue(owner, repo, gitea.CreateIssueOption{
|
||||
_, _, err := login.Client().CreateIssue(owner, repo, gitea.CreateIssueOption{
|
||||
Title: ctx.String("title"),
|
||||
Body: ctx.String("body"),
|
||||
// TODO:
|
||||
@ -212,6 +216,6 @@ func editIssueState(ctx *cli.Context, opts gitea.EditIssueOption) error {
|
||||
return err
|
||||
}
|
||||
|
||||
_, err = login.Client().EditIssue(owner, repo, index, opts)
|
||||
_, _, err = login.Client().EditIssue(owner, repo, index, opts)
|
||||
return err
|
||||
}
|
||||
|
@ -14,6 +14,7 @@ import (
|
||||
|
||||
"code.gitea.io/sdk/gitea"
|
||||
|
||||
"github.com/muesli/termenv"
|
||||
"github.com/urfave/cli/v2"
|
||||
)
|
||||
|
||||
@ -34,6 +35,8 @@ var CmdLabels = cli.Command{
|
||||
Aliases: []string{"s"},
|
||||
Usage: "Save all the labels as a file",
|
||||
},
|
||||
&PaginationPageFlag,
|
||||
&PaginationLimitFlag,
|
||||
}, AllDefaultFlags...),
|
||||
}
|
||||
|
||||
@ -49,7 +52,7 @@ func runLabels(ctx *cli.Context) error {
|
||||
|
||||
var values [][]string
|
||||
|
||||
labels, err := login.Client().ListRepoLabels(owner, repo, gitea.ListLabelsOptions{})
|
||||
labels, _, err := login.Client().ListRepoLabels(owner, repo, gitea.ListLabelsOptions{ListOptions: getListOptions(ctx)})
|
||||
if err != nil {
|
||||
log.Fatal(err)
|
||||
}
|
||||
@ -59,6 +62,8 @@ func runLabels(ctx *cli.Context) error {
|
||||
return nil
|
||||
}
|
||||
|
||||
p := termenv.ColorProfile()
|
||||
|
||||
fPath := ctx.String("save")
|
||||
if len(fPath) > 0 {
|
||||
f, err := os.Create(fPath)
|
||||
@ -72,11 +77,13 @@ func runLabels(ctx *cli.Context) error {
|
||||
}
|
||||
} else {
|
||||
for _, label := range labels {
|
||||
color := termenv.String(label.Color)
|
||||
|
||||
values = append(
|
||||
values,
|
||||
[]string{
|
||||
strconv.FormatInt(label.ID, 10),
|
||||
label.Color,
|
||||
fmt.Sprint(color.Background(p.Color("#" + label.Color))),
|
||||
label.Name,
|
||||
label.Description,
|
||||
},
|
||||
@ -141,7 +148,7 @@ func runLabelCreate(ctx *cli.Context) error {
|
||||
labelFile := ctx.String("file")
|
||||
var err error
|
||||
if len(labelFile) == 0 {
|
||||
_, err = login.Client().CreateLabel(owner, repo, gitea.CreateLabelOption{
|
||||
_, _, err = login.Client().CreateLabel(owner, repo, gitea.CreateLabelOption{
|
||||
Name: ctx.String("name"),
|
||||
Color: ctx.String("color"),
|
||||
Description: ctx.String("description"),
|
||||
@ -162,7 +169,7 @@ func runLabelCreate(ctx *cli.Context) error {
|
||||
if color == "" || name == "" {
|
||||
log.Printf("Line %d ignored because lack of enough fields: %s\n", i, line)
|
||||
} else {
|
||||
_, err = login.Client().CreateLabel(owner, repo, gitea.CreateLabelOption{
|
||||
_, _, err = login.Client().CreateLabel(owner, repo, gitea.CreateLabelOption{
|
||||
Name: name,
|
||||
Color: color,
|
||||
Description: description,
|
||||
@ -227,7 +234,7 @@ func runLabelUpdate(ctx *cli.Context) error {
|
||||
}
|
||||
|
||||
var err error
|
||||
_, err = login.Client().EditLabel(owner, repo, id, gitea.EditLabelOption{
|
||||
_, _, err = login.Client().EditLabel(owner, repo, id, gitea.EditLabelOption{
|
||||
Name: pName,
|
||||
Color: pColor,
|
||||
Description: pDescription,
|
||||
@ -245,7 +252,7 @@ var CmdLabelDelete = cli.Command{
|
||||
Name: "delete",
|
||||
Usage: "Delete a label",
|
||||
Description: `Delete a label`,
|
||||
Action: runLabelCreate,
|
||||
Action: runLabelDelete,
|
||||
Flags: []cli.Flag{
|
||||
&cli.IntFlag{
|
||||
Name: "id",
|
||||
@ -257,7 +264,7 @@ var CmdLabelDelete = cli.Command{
|
||||
func runLabelDelete(ctx *cli.Context) error {
|
||||
login, owner, repo := initCommand()
|
||||
|
||||
err := login.Client().DeleteLabel(owner, repo, ctx.Int64("id"))
|
||||
_, err := login.Client().DeleteLabel(owner, repo, ctx.Int64("id"))
|
||||
if err != nil {
|
||||
log.Fatal(err)
|
||||
}
|
||||
|
243
cmd/login.go
243
cmd/login.go
@ -10,9 +10,14 @@ import (
|
||||
"log"
|
||||
"net/http"
|
||||
"net/http/cookiejar"
|
||||
"net/url"
|
||||
"os"
|
||||
"strings"
|
||||
"time"
|
||||
|
||||
"code.gitea.io/sdk/gitea"
|
||||
|
||||
"github.com/skratchdot/open-golang/open"
|
||||
"github.com/urfave/cli/v2"
|
||||
)
|
||||
|
||||
@ -21,13 +26,66 @@ var CmdLogin = cli.Command{
|
||||
Name: "login",
|
||||
Usage: "Log in to a Gitea server",
|
||||
Description: `Log in to a Gitea server`,
|
||||
Action: runLoginList,
|
||||
Action: runLoginAddInteractive,
|
||||
Subcommands: []*cli.Command{
|
||||
&cmdLoginList,
|
||||
&cmdLoginAdd,
|
||||
&cmdLoginEdit,
|
||||
&cmdLoginSetDefault,
|
||||
},
|
||||
}
|
||||
|
||||
// cmdLoginEdit represents to login a gitea server.
|
||||
var cmdLoginEdit = cli.Command{
|
||||
Name: "edit",
|
||||
Usage: "Edit Gitea logins",
|
||||
Description: `Edit Gitea logins`,
|
||||
Action: runLoginEdit,
|
||||
Flags: []cli.Flag{&OutputFlag},
|
||||
}
|
||||
|
||||
func runLoginEdit(ctx *cli.Context) error {
|
||||
return open.Start(yamlConfigPath)
|
||||
}
|
||||
|
||||
// cmdLoginSetDefault represents to login a gitea server.
|
||||
var cmdLoginSetDefault = cli.Command{
|
||||
Name: "default",
|
||||
Usage: "Get or Set Default Login",
|
||||
Description: `Get or Set Default Login`,
|
||||
ArgsUsage: "<Login>",
|
||||
Action: runLoginSetDefault,
|
||||
Flags: []cli.Flag{&OutputFlag},
|
||||
}
|
||||
|
||||
func runLoginSetDefault(ctx *cli.Context) error {
|
||||
if err := loadConfig(yamlConfigPath); err != nil {
|
||||
return err
|
||||
}
|
||||
if ctx.Args().Len() == 0 {
|
||||
l, err := getDefaultLogin()
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
fmt.Printf("Default Login: %s\n", l.Name)
|
||||
return nil
|
||||
}
|
||||
loginExist := false
|
||||
for i := range config.Logins {
|
||||
config.Logins[i].Default = false
|
||||
if config.Logins[i].Name == ctx.Args().First() {
|
||||
config.Logins[i].Default = true
|
||||
loginExist = true
|
||||
}
|
||||
}
|
||||
|
||||
if !loginExist {
|
||||
return fmt.Errorf("login '%s' not found", ctx.Args().First())
|
||||
}
|
||||
|
||||
return saveConfig(yamlConfigPath)
|
||||
}
|
||||
|
||||
// CmdLogin represents to login a gitea server.
|
||||
var cmdLoginAdd = cli.Command{
|
||||
Name: "add",
|
||||
@ -38,7 +96,6 @@ var cmdLoginAdd = cli.Command{
|
||||
Name: "name",
|
||||
Aliases: []string{"n"},
|
||||
Usage: "Login name",
|
||||
Required: true,
|
||||
},
|
||||
&cli.StringFlag{
|
||||
Name: "url",
|
||||
@ -54,7 +111,19 @@ var cmdLoginAdd = cli.Command{
|
||||
Value: "",
|
||||
EnvVars: []string{"GITEA_SERVER_TOKEN"},
|
||||
Usage: "Access token. Can be obtained from Settings > Applications",
|
||||
Required: true,
|
||||
},
|
||||
&cli.StringFlag{
|
||||
Name: "user",
|
||||
Value: "",
|
||||
EnvVars: []string{"GITEA_SERVER_USER"},
|
||||
Usage: "User for basic auth (will create token)",
|
||||
},
|
||||
&cli.StringFlag{
|
||||
Name: "password",
|
||||
Aliases: []string{"pwd"},
|
||||
Value: "",
|
||||
EnvVars: []string{"GITEA_SERVER_PASSWORD"},
|
||||
Usage: "Password for basic auth (will create token)",
|
||||
},
|
||||
&cli.StringFlag{
|
||||
Name: "ssh-key",
|
||||
@ -71,14 +140,100 @@ var cmdLoginAdd = cli.Command{
|
||||
}
|
||||
|
||||
func runLoginAdd(ctx *cli.Context) error {
|
||||
if !ctx.IsSet("url") {
|
||||
return runLoginAddMain(
|
||||
ctx.String("name"),
|
||||
ctx.String("token"),
|
||||
ctx.String("user"),
|
||||
ctx.String("password"),
|
||||
ctx.String("ssh-key"),
|
||||
ctx.String("url"),
|
||||
ctx.Bool("insecure"))
|
||||
}
|
||||
|
||||
func runLoginAddInteractive(ctx *cli.Context) error {
|
||||
var stdin, name, token, user, passwd, sshKey, giteaURL string
|
||||
var insecure = false
|
||||
|
||||
fmt.Print("URL of Gitea instance: ")
|
||||
if _, err := fmt.Scanln(&stdin); err != nil {
|
||||
stdin = ""
|
||||
}
|
||||
giteaURL = strings.TrimSpace(stdin)
|
||||
if len(giteaURL) == 0 {
|
||||
fmt.Println("URL is required!")
|
||||
return nil
|
||||
}
|
||||
|
||||
parsedURL, err := url.Parse(giteaURL)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
name = strings.ReplaceAll(strings.Title(parsedURL.Host), ".", "")
|
||||
|
||||
fmt.Print("Name of new Login [" + name + "]: ")
|
||||
if _, err := fmt.Scanln(&stdin); err != nil {
|
||||
stdin = ""
|
||||
}
|
||||
if len(strings.TrimSpace(stdin)) != 0 {
|
||||
name = strings.TrimSpace(stdin)
|
||||
}
|
||||
|
||||
fmt.Print("Do you have a token [Yes/no]: ")
|
||||
if _, err := fmt.Scanln(&stdin); err != nil {
|
||||
stdin = ""
|
||||
}
|
||||
if len(stdin) != 0 && strings.ToLower(stdin[:1]) == "n" {
|
||||
fmt.Print("Username: ")
|
||||
if _, err := fmt.Scanln(&stdin); err != nil {
|
||||
stdin = ""
|
||||
}
|
||||
user = strings.TrimSpace(stdin)
|
||||
|
||||
fmt.Print("Password: ")
|
||||
if _, err := fmt.Scanln(&stdin); err != nil {
|
||||
stdin = ""
|
||||
}
|
||||
passwd = strings.TrimSpace(stdin)
|
||||
} else {
|
||||
fmt.Print("Token: ")
|
||||
if _, err := fmt.Scanln(&stdin); err != nil {
|
||||
stdin = ""
|
||||
}
|
||||
token = strings.TrimSpace(stdin)
|
||||
}
|
||||
|
||||
fmt.Print("Set Optional settings [yes/No]: ")
|
||||
if _, err := fmt.Scanln(&stdin); err != nil {
|
||||
stdin = ""
|
||||
}
|
||||
if len(stdin) != 0 && strings.ToLower(stdin[:1]) == "y" {
|
||||
fmt.Print("SSH Key Path: ")
|
||||
if _, err := fmt.Scanln(&stdin); err != nil {
|
||||
stdin = ""
|
||||
}
|
||||
sshKey = strings.TrimSpace(stdin)
|
||||
|
||||
fmt.Print("Allow Insecure connections [yes/No]: ")
|
||||
if _, err := fmt.Scanln(&stdin); err != nil {
|
||||
stdin = ""
|
||||
}
|
||||
insecure = len(stdin) != 0 && strings.ToLower(stdin[:1]) == "y"
|
||||
}
|
||||
|
||||
return runLoginAddMain(name, token, user, passwd, sshKey, giteaURL, insecure)
|
||||
}
|
||||
|
||||
func runLoginAddMain(name, token, user, passwd, sshKey, giteaURL string, insecure bool) error {
|
||||
|
||||
if len(giteaURL) == 0 {
|
||||
log.Fatal("You have to input Gitea server URL")
|
||||
}
|
||||
if !ctx.IsSet("token") {
|
||||
log.Fatal("No token found")
|
||||
}
|
||||
if !ctx.IsSet("name") {
|
||||
log.Fatal("You have to set a name for the login")
|
||||
if len(token) == 0 && (len(user)+len(passwd)) == 0 {
|
||||
log.Fatal("No token set")
|
||||
} else if len(user) != 0 && len(passwd) == 0 {
|
||||
log.Fatal("No password set")
|
||||
} else if len(user) == 0 && len(passwd) != 0 {
|
||||
log.Fatal("No user set")
|
||||
}
|
||||
|
||||
err := loadConfig(yamlConfigPath)
|
||||
@ -86,30 +241,72 @@ func runLoginAdd(ctx *cli.Context) error {
|
||||
log.Fatal("Unable to load config file " + yamlConfigPath)
|
||||
}
|
||||
|
||||
client := gitea.NewClient(ctx.String("url"), ctx.String("token"))
|
||||
if ctx.Bool("insecure") {
|
||||
httpClient := &http.Client{}
|
||||
if insecure {
|
||||
cookieJar, _ := cookiejar.New(nil)
|
||||
|
||||
client.SetHTTPClient(&http.Client{
|
||||
httpClient = &http.Client{
|
||||
Jar: cookieJar,
|
||||
Transport: &http.Transport{
|
||||
TLSClientConfig: &tls.Config{InsecureSkipVerify: true},
|
||||
},
|
||||
})
|
||||
}}
|
||||
}
|
||||
u, err := client.GetMyUserInfo()
|
||||
client, err := gitea.NewClient(giteaURL,
|
||||
gitea.SetToken(token),
|
||||
gitea.SetBasicAuth(user, passwd),
|
||||
gitea.SetHTTPClient(httpClient),
|
||||
)
|
||||
if err != nil {
|
||||
log.Fatal(err)
|
||||
}
|
||||
|
||||
u, _, err := client.GetMyUserInfo()
|
||||
if err != nil {
|
||||
log.Fatal(err)
|
||||
}
|
||||
|
||||
if len(token) == 0 {
|
||||
// create token
|
||||
host, _ := os.Hostname()
|
||||
tl, _, err := client.ListAccessTokens(gitea.ListAccessTokensOptions{})
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
tokenName := host + "-tea"
|
||||
for i := range tl {
|
||||
if tl[i].Name == tokenName {
|
||||
tokenName += time.Now().Format("2006-01-02_15-04-05")
|
||||
break
|
||||
}
|
||||
}
|
||||
t, _, err := client.CreateAccessToken(gitea.CreateAccessTokenOption{Name: tokenName})
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
token = t.Token
|
||||
}
|
||||
|
||||
fmt.Println("Login successful! Login name " + u.UserName)
|
||||
|
||||
if len(name) == 0 {
|
||||
parsedURL, err := url.Parse(giteaURL)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
name = strings.ReplaceAll(strings.Title(parsedURL.Host), ".", "")
|
||||
for _, l := range config.Logins {
|
||||
if l.Name == name {
|
||||
name += "_" + u.UserName
|
||||
break
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
err = addLogin(Login{
|
||||
Name: ctx.String("name"),
|
||||
URL: ctx.String("url"),
|
||||
Token: ctx.String("token"),
|
||||
Insecure: ctx.Bool("insecure"),
|
||||
SSHKey: ctx.String("ssh-key"),
|
||||
Name: name,
|
||||
URL: giteaURL,
|
||||
Token: token,
|
||||
Insecure: insecure,
|
||||
SSHKey: sshKey,
|
||||
User: u.UserName,
|
||||
})
|
||||
if err != nil {
|
||||
@ -143,6 +340,8 @@ func runLoginList(ctx *cli.Context) error {
|
||||
"Name",
|
||||
"URL",
|
||||
"SSHHost",
|
||||
"User",
|
||||
"Default",
|
||||
}
|
||||
|
||||
var values [][]string
|
||||
@ -152,6 +351,8 @@ func runLoginList(ctx *cli.Context) error {
|
||||
l.Name,
|
||||
l.URL,
|
||||
l.GetSSHHost(),
|
||||
l.User,
|
||||
fmt.Sprint(l.Default),
|
||||
})
|
||||
}
|
||||
|
||||
|
202
cmd/milestone_issues.go
Normal file
202
cmd/milestone_issues.go
Normal file
@ -0,0 +1,202 @@
|
||||
// Copyright 2020 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 cmd
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"strconv"
|
||||
|
||||
"code.gitea.io/sdk/gitea"
|
||||
"github.com/urfave/cli/v2"
|
||||
)
|
||||
|
||||
// CmdMilestonesIssues represents a sub command of milestones to manage issue/pull of an milestone
|
||||
var CmdMilestonesIssues = cli.Command{
|
||||
Name: "issues",
|
||||
Aliases: []string{"i"},
|
||||
Usage: "manage issue/pull of an milestone",
|
||||
Description: "manage issue/pull of an milestone",
|
||||
ArgsUsage: "<milestone name>",
|
||||
Action: runMilestoneIssueList,
|
||||
Subcommands: []*cli.Command{
|
||||
&CmdMilestoneAddIssue,
|
||||
&CmdMilestoneRemoveIssue,
|
||||
},
|
||||
Flags: append([]cli.Flag{
|
||||
&cli.StringFlag{
|
||||
Name: "state",
|
||||
Usage: "Filter by issue state (all|open|closed)",
|
||||
DefaultText: "open",
|
||||
},
|
||||
&cli.StringFlag{
|
||||
Name: "kind",
|
||||
Usage: "Filter by kind (issue|pull)",
|
||||
},
|
||||
&PaginationPageFlag,
|
||||
&PaginationLimitFlag,
|
||||
}, AllDefaultFlags...),
|
||||
}
|
||||
|
||||
// CmdMilestoneAddIssue represents a sub command of milestone issues to add an issue/pull to an milestone
|
||||
var CmdMilestoneAddIssue = cli.Command{
|
||||
Name: "add",
|
||||
Aliases: []string{"a"},
|
||||
Usage: "Add an issue/pull to an milestone",
|
||||
Description: "Add an issue/pull to an milestone",
|
||||
ArgsUsage: "<milestone name> <issue/pull index>",
|
||||
Action: runMilestoneIssueAdd,
|
||||
Flags: AllDefaultFlags,
|
||||
}
|
||||
|
||||
// CmdMilestoneRemoveIssue represents a sub command of milestones to remove an issue/pull from an milestone
|
||||
var CmdMilestoneRemoveIssue = cli.Command{
|
||||
Name: "remove",
|
||||
Aliases: []string{"r"},
|
||||
Usage: "Remove an issue/pull to an milestone",
|
||||
Description: "Remove an issue/pull to an milestone",
|
||||
ArgsUsage: "<milestone name> <issue/pull index>",
|
||||
Action: runMilestoneIssueRemove,
|
||||
Flags: AllDefaultFlags,
|
||||
}
|
||||
|
||||
func runMilestoneIssueList(ctx *cli.Context) error {
|
||||
login, owner, repo := initCommand()
|
||||
client := login.Client()
|
||||
|
||||
state := gitea.StateOpen
|
||||
switch ctx.String("state") {
|
||||
case "all":
|
||||
state = gitea.StateAll
|
||||
case "closed":
|
||||
state = gitea.StateClosed
|
||||
}
|
||||
|
||||
kind := gitea.IssueTypeAll
|
||||
switch ctx.String("kind") {
|
||||
case "issue":
|
||||
kind = gitea.IssueTypeIssue
|
||||
case "pull":
|
||||
kind = gitea.IssueTypePull
|
||||
}
|
||||
|
||||
fmt.Println(state)
|
||||
|
||||
milestone := ctx.Args().First()
|
||||
// make sure milestone exist
|
||||
_, _, err := client.GetMilestoneByName(owner, repo, milestone)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
issues, _, err := client.ListRepoIssues(owner, repo, gitea.ListIssueOption{
|
||||
ListOptions: getListOptions(ctx),
|
||||
Milestones: []string{milestone},
|
||||
Type: kind,
|
||||
State: state,
|
||||
})
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
headers := []string{
|
||||
"Index",
|
||||
"State",
|
||||
"Kind",
|
||||
"Author",
|
||||
"Updated",
|
||||
"Title",
|
||||
}
|
||||
|
||||
var values [][]string
|
||||
|
||||
if len(issues) == 0 {
|
||||
Output(outputValue, headers, values)
|
||||
return nil
|
||||
}
|
||||
|
||||
for _, issue := range issues {
|
||||
name := issue.Poster.FullName
|
||||
if len(name) == 0 {
|
||||
name = issue.Poster.UserName
|
||||
}
|
||||
kind := "Issue"
|
||||
if issue.PullRequest != nil {
|
||||
kind = "Pull"
|
||||
}
|
||||
values = append(
|
||||
values,
|
||||
[]string{
|
||||
strconv.FormatInt(issue.Index, 10),
|
||||
string(issue.State),
|
||||
kind,
|
||||
name,
|
||||
issue.Updated.Format("2006-01-02 15:04:05"),
|
||||
issue.Title,
|
||||
},
|
||||
)
|
||||
}
|
||||
Output(outputValue, headers, values)
|
||||
return nil
|
||||
}
|
||||
|
||||
func runMilestoneIssueAdd(ctx *cli.Context) error {
|
||||
login, owner, repo := initCommand()
|
||||
client := login.Client()
|
||||
if ctx.Args().Len() == 0 {
|
||||
return fmt.Errorf("need two arguments")
|
||||
}
|
||||
|
||||
mileName := ctx.Args().Get(0)
|
||||
issueIndex := ctx.Args().Get(1)
|
||||
idx, err := argToIndex(issueIndex)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
// make sure milestone exist
|
||||
mile, _, err := client.GetMilestoneByName(owner, repo, mileName)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
_, _, err = client.EditIssue(owner, repo, idx, gitea.EditIssueOption{
|
||||
Milestone: &mile.ID,
|
||||
})
|
||||
return err
|
||||
}
|
||||
|
||||
func runMilestoneIssueRemove(ctx *cli.Context) error {
|
||||
login, owner, repo := initCommand()
|
||||
client := login.Client()
|
||||
if ctx.Args().Len() == 0 {
|
||||
return fmt.Errorf("need two arguments")
|
||||
}
|
||||
|
||||
mileName := ctx.Args().Get(0)
|
||||
issueIndex := ctx.Args().Get(1)
|
||||
idx, err := argToIndex(issueIndex)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
issue, _, err := client.GetIssue(owner, repo, idx)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
if issue.Milestone == nil {
|
||||
return fmt.Errorf("issue is not assigned to a milestone")
|
||||
}
|
||||
|
||||
if issue.Milestone.Title != mileName {
|
||||
return fmt.Errorf("issue is not assigned to this milestone")
|
||||
}
|
||||
|
||||
zero := int64(0)
|
||||
_, _, err = client.EditIssue(owner, repo, idx, gitea.EditIssueOption{
|
||||
Milestone: &zero,
|
||||
})
|
||||
return err
|
||||
}
|
255
cmd/milestones.go
Normal file
255
cmd/milestones.go
Normal file
@ -0,0 +1,255 @@
|
||||
// Copyright 2020 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 cmd
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"log"
|
||||
|
||||
"code.gitea.io/sdk/gitea"
|
||||
"github.com/urfave/cli/v2"
|
||||
)
|
||||
|
||||
// CmdMilestones represents to operate repositories milestones.
|
||||
var CmdMilestones = cli.Command{
|
||||
Name: "milestones",
|
||||
Aliases: []string{"ms", "mile"},
|
||||
Usage: "List and create milestones",
|
||||
Description: `List and create milestones`,
|
||||
ArgsUsage: "[<milestone name>]",
|
||||
Action: runMilestones,
|
||||
Subcommands: []*cli.Command{
|
||||
&CmdMilestonesList,
|
||||
&CmdMilestonesCreate,
|
||||
&CmdMilestonesClose,
|
||||
&CmdMilestonesDelete,
|
||||
&CmdMilestonesReopen,
|
||||
&CmdMilestonesIssues,
|
||||
},
|
||||
Flags: AllDefaultFlags,
|
||||
}
|
||||
|
||||
// CmdMilestonesList represents a sub command of milestones to list milestones
|
||||
var CmdMilestonesList = cli.Command{
|
||||
Name: "ls",
|
||||
Usage: "List milestones of the repository",
|
||||
Description: `List milestones of the repository`,
|
||||
Action: runMilestonesList,
|
||||
Flags: append([]cli.Flag{
|
||||
&cli.StringFlag{
|
||||
Name: "state",
|
||||
Usage: "Filter by milestone state (all|open|closed)",
|
||||
DefaultText: "open",
|
||||
},
|
||||
&PaginationPageFlag,
|
||||
&PaginationLimitFlag,
|
||||
}, AllDefaultFlags...),
|
||||
}
|
||||
|
||||
func runMilestones(ctx *cli.Context) error {
|
||||
if ctx.Args().Len() == 1 {
|
||||
return runMilestoneDetail(ctx, ctx.Args().First())
|
||||
}
|
||||
return runMilestonesList(ctx)
|
||||
}
|
||||
|
||||
func runMilestoneDetail(ctx *cli.Context, name string) error {
|
||||
login, owner, repo := initCommand()
|
||||
client := login.Client()
|
||||
|
||||
milestone, _, err := client.GetMilestoneByName(owner, repo, name)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
fmt.Printf("%s\n",
|
||||
milestone.Title,
|
||||
)
|
||||
if len(milestone.Description) != 0 {
|
||||
fmt.Printf("\n%s\n", milestone.Description)
|
||||
}
|
||||
if milestone.Deadline != nil && !milestone.Deadline.IsZero() {
|
||||
fmt.Printf("\nDeadline: %s\n", milestone.Deadline.Format("2006-01-02 15:04:05"))
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
func runMilestonesList(ctx *cli.Context) error {
|
||||
login, owner, repo := initCommand()
|
||||
|
||||
state := gitea.StateOpen
|
||||
switch ctx.String("state") {
|
||||
case "all":
|
||||
state = gitea.StateAll
|
||||
case "closed":
|
||||
state = gitea.StateClosed
|
||||
}
|
||||
|
||||
milestones, _, err := login.Client().ListRepoMilestones(owner, repo, gitea.ListMilestoneOption{
|
||||
ListOptions: getListOptions(ctx),
|
||||
State: state,
|
||||
})
|
||||
|
||||
if err != nil {
|
||||
log.Fatal(err)
|
||||
}
|
||||
|
||||
headers := []string{
|
||||
"Title",
|
||||
}
|
||||
if state == gitea.StateAll {
|
||||
headers = append(headers, "State")
|
||||
}
|
||||
headers = append(headers,
|
||||
"Open/Closed Issues",
|
||||
"DueDate",
|
||||
)
|
||||
|
||||
var values [][]string
|
||||
|
||||
for _, m := range milestones {
|
||||
var deadline = ""
|
||||
|
||||
if m.Deadline != nil && !m.Deadline.IsZero() {
|
||||
deadline = m.Deadline.Format("2006-01-02 15:04:05")
|
||||
}
|
||||
|
||||
item := []string{
|
||||
m.Title,
|
||||
}
|
||||
if state == gitea.StateAll {
|
||||
item = append(item, string(m.State))
|
||||
}
|
||||
item = append(item,
|
||||
fmt.Sprintf("%d/%d", m.OpenIssues, m.ClosedIssues),
|
||||
deadline,
|
||||
)
|
||||
|
||||
values = append(values, item)
|
||||
}
|
||||
Output(outputValue, headers, values)
|
||||
|
||||
return nil
|
||||
}
|
||||
|
||||
// CmdMilestonesCreate represents a sub command of milestones to create milestone
|
||||
var CmdMilestonesCreate = cli.Command{
|
||||
Name: "create",
|
||||
Usage: "Create an milestone on repository",
|
||||
Description: `Create an milestone on repository`,
|
||||
Action: runMilestonesCreate,
|
||||
Flags: append([]cli.Flag{
|
||||
&cli.StringFlag{
|
||||
Name: "title",
|
||||
Aliases: []string{"t"},
|
||||
Usage: "milestone title to create",
|
||||
},
|
||||
&cli.StringFlag{
|
||||
Name: "description",
|
||||
Aliases: []string{"d"},
|
||||
Usage: "milestone description to create",
|
||||
},
|
||||
&cli.StringFlag{
|
||||
Name: "state",
|
||||
Usage: "set milestone state (default is open)",
|
||||
DefaultText: "open",
|
||||
},
|
||||
}, AllDefaultFlags...),
|
||||
}
|
||||
|
||||
func runMilestonesCreate(ctx *cli.Context) error {
|
||||
login, owner, repo := initCommand()
|
||||
|
||||
title := ctx.String("title")
|
||||
if len(title) == 0 {
|
||||
fmt.Printf("Title is required\n")
|
||||
return nil
|
||||
}
|
||||
|
||||
state := gitea.StateOpen
|
||||
if ctx.String("state") == "closed" {
|
||||
state = gitea.StateClosed
|
||||
}
|
||||
|
||||
mile, _, err := login.Client().CreateMilestone(owner, repo, gitea.CreateMilestoneOption{
|
||||
Title: title,
|
||||
Description: ctx.String("description"),
|
||||
State: state,
|
||||
})
|
||||
if err != nil {
|
||||
log.Fatal(err)
|
||||
}
|
||||
|
||||
return runMilestoneDetail(ctx, mile.Title)
|
||||
}
|
||||
|
||||
// CmdMilestonesClose represents a sub command of milestones to close an milestone
|
||||
var CmdMilestonesClose = cli.Command{
|
||||
Name: "close",
|
||||
Usage: "Change state of an milestone to 'closed'",
|
||||
Description: `Change state of an milestone to 'closed'`,
|
||||
ArgsUsage: "<milestone name>",
|
||||
Action: func(ctx *cli.Context) error {
|
||||
if ctx.Bool("force") {
|
||||
return deleteMilestone(ctx)
|
||||
}
|
||||
return editMilestoneStatus(ctx, true)
|
||||
},
|
||||
Flags: append([]cli.Flag{
|
||||
&cli.BoolFlag{
|
||||
Name: "force",
|
||||
Aliases: []string{"f"},
|
||||
Usage: "delete milestone",
|
||||
},
|
||||
}, AllDefaultFlags...),
|
||||
}
|
||||
|
||||
func editMilestoneStatus(ctx *cli.Context, close bool) error {
|
||||
login, owner, repo := initCommand()
|
||||
client := login.Client()
|
||||
|
||||
state := gitea.StateOpen
|
||||
if close {
|
||||
state = gitea.StateClosed
|
||||
}
|
||||
_, _, err := client.EditMilestoneByName(owner, repo, ctx.Args().First(), gitea.EditMilestoneOption{
|
||||
State: &state,
|
||||
Title: ctx.Args().First(),
|
||||
})
|
||||
|
||||
return err
|
||||
}
|
||||
|
||||
// CmdMilestonesDelete represents a sub command of milestones to delete an milestone
|
||||
var CmdMilestonesDelete = cli.Command{
|
||||
Name: "delete",
|
||||
Aliases: []string{"rm"},
|
||||
Usage: "delete a milestone",
|
||||
Description: "delete a milestone",
|
||||
ArgsUsage: "<milestone name>",
|
||||
Action: deleteMilestone,
|
||||
Flags: AllDefaultFlags,
|
||||
}
|
||||
|
||||
func deleteMilestone(ctx *cli.Context) error {
|
||||
login, owner, repo := initCommand()
|
||||
client := login.Client()
|
||||
|
||||
_, err := client.DeleteMilestoneByName(owner, repo, ctx.Args().First())
|
||||
return err
|
||||
}
|
||||
|
||||
// CmdMilestonesReopen represents a sub command of milestones to open an milestone
|
||||
var CmdMilestonesReopen = cli.Command{
|
||||
Name: "reopen",
|
||||
Aliases: []string{"open"},
|
||||
Usage: "Change state of an milestone to 'open'",
|
||||
Description: `Change state of an milestone to 'open'`,
|
||||
ArgsUsage: "<milestone name>",
|
||||
Action: func(ctx *cli.Context) error {
|
||||
return editMilestoneStatus(ctx, false)
|
||||
},
|
||||
Flags: AllDefaultFlags,
|
||||
}
|
@ -15,8 +15,8 @@ import (
|
||||
// CmdNotifications is the main command to operate with notifications
|
||||
var CmdNotifications = cli.Command{
|
||||
Name: "notifications",
|
||||
Usage: "show notifications",
|
||||
Description: "show notifications, by default based of the current repo and unread one",
|
||||
Usage: "Show notifications",
|
||||
Description: "Show notifications, by default based of the current repo and unread one",
|
||||
Action: runNotifications,
|
||||
Flags: append([]cli.Flag{
|
||||
&cli.BoolFlag{
|
||||
@ -24,46 +24,49 @@ var CmdNotifications = cli.Command{
|
||||
Aliases: []string{"a"},
|
||||
Usage: "show all notifications of related gitea instance",
|
||||
},
|
||||
/* // not supported jet
|
||||
&cli.BoolFlag{
|
||||
Name: "read",
|
||||
Aliases: []string{"rd"},
|
||||
Usage: "show read notifications instead unread",
|
||||
},
|
||||
*/
|
||||
&cli.IntFlag{
|
||||
Name: "page",
|
||||
Aliases: []string{"p"},
|
||||
Usage: "specify page, default is 1",
|
||||
Value: 1,
|
||||
},
|
||||
&cli.IntFlag{
|
||||
Name: "limit",
|
||||
Aliases: []string{"lm"},
|
||||
Usage: "specify limit of items per page",
|
||||
&cli.BoolFlag{
|
||||
Name: "pinned",
|
||||
Aliases: []string{"pd"},
|
||||
Usage: "show pinned notifications instead unread",
|
||||
},
|
||||
&PaginationPageFlag,
|
||||
&PaginationLimitFlag,
|
||||
}, AllDefaultFlags...),
|
||||
}
|
||||
|
||||
func runNotifications(ctx *cli.Context) error {
|
||||
login, owner, repo := initCommand()
|
||||
|
||||
client := login.Client()
|
||||
var news []*gitea.NotificationThread
|
||||
var err error
|
||||
|
||||
listOpts := gitea.ListOptions{
|
||||
Page: ctx.Int("page"),
|
||||
PageSize: ctx.Int("limit"),
|
||||
listOpts := getListOptions(ctx)
|
||||
if listOpts.Page == 0 {
|
||||
listOpts.Page = 1
|
||||
}
|
||||
|
||||
var status []gitea.NotifyStatus
|
||||
if ctx.Bool("read") {
|
||||
status = []gitea.NotifyStatus{gitea.NotifyStatusRead}
|
||||
}
|
||||
if ctx.Bool("pinned") {
|
||||
status = append(status, gitea.NotifyStatusPinned)
|
||||
}
|
||||
|
||||
if ctx.Bool("all") {
|
||||
news, err = client.ListNotifications(gitea.ListNotificationOptions{
|
||||
login := initCommandLoginOnly()
|
||||
news, _, err = login.Client().ListNotifications(gitea.ListNotificationOptions{
|
||||
ListOptions: listOpts,
|
||||
Status: status,
|
||||
})
|
||||
} else {
|
||||
news, err = client.ListRepoNotifications(owner, repo, gitea.ListNotificationOptions{
|
||||
login, owner, repo := initCommand()
|
||||
news, _, err = login.Client().ListRepoNotifications(owner, repo, gitea.ListNotificationOptions{
|
||||
ListOptions: listOpts,
|
||||
Status: status,
|
||||
})
|
||||
}
|
||||
if err != nil {
|
||||
|
141
cmd/pulls.go
141
cmd/pulls.go
@ -13,6 +13,7 @@ import (
|
||||
local_git "code.gitea.io/tea/modules/git"
|
||||
|
||||
"code.gitea.io/sdk/gitea"
|
||||
"github.com/charmbracelet/glamour"
|
||||
"github.com/go-git/go-git/v5"
|
||||
git_config "github.com/go-git/go-git/v5/config"
|
||||
"github.com/urfave/cli/v2"
|
||||
@ -22,17 +23,13 @@ import (
|
||||
var CmdPulls = cli.Command{
|
||||
Name: "pulls",
|
||||
Aliases: []string{"pull", "pr"},
|
||||
Usage: "List open pull requests",
|
||||
Description: `List open pull requests`,
|
||||
Usage: "List, create, checkout and clean pull requests",
|
||||
Description: `List, create, checkout and clean pull requests`,
|
||||
ArgsUsage: "[<pull index>]",
|
||||
Action: runPulls,
|
||||
Flags: append([]cli.Flag{
|
||||
&cli.StringFlag{
|
||||
Name: "state",
|
||||
Usage: "Filter by PR state (all|open|closed)",
|
||||
DefaultText: "open",
|
||||
},
|
||||
}, AllDefaultFlags...),
|
||||
Flags: IssuePRFlags,
|
||||
Subcommands: []*cli.Command{
|
||||
&CmdPullsList,
|
||||
&CmdPullsCheckout,
|
||||
&CmdPullsClean,
|
||||
&CmdPullsCreate,
|
||||
@ -40,6 +37,44 @@ var CmdPulls = cli.Command{
|
||||
}
|
||||
|
||||
func runPulls(ctx *cli.Context) error {
|
||||
if ctx.Args().Len() == 1 {
|
||||
return runPullDetail(ctx, ctx.Args().First())
|
||||
}
|
||||
return runPullsList(ctx)
|
||||
}
|
||||
|
||||
// CmdPullsList represents a sub command of issues to list pulls
|
||||
var CmdPullsList = cli.Command{
|
||||
Name: "ls",
|
||||
Usage: "List pull requests of the repository",
|
||||
Description: `List pull requests of the repository`,
|
||||
Action: runPullsList,
|
||||
Flags: IssuePRFlags,
|
||||
}
|
||||
|
||||
func runPullDetail(ctx *cli.Context, index string) error {
|
||||
login, owner, repo := initCommand()
|
||||
|
||||
idx, err := argToIndex(index)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
pr, _, err := login.Client().GetPullRequest(owner, repo, idx)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
// TODO: use glamour once #181 is merged
|
||||
fmt.Printf("#%d %s\n%s created %s\n\n%s\n", pr.Index,
|
||||
pr.Title,
|
||||
pr.Poster.UserName,
|
||||
pr.Created.Format("2006-01-02 15:04:05"),
|
||||
pr.Body,
|
||||
)
|
||||
return nil
|
||||
}
|
||||
|
||||
func runPullsList(ctx *cli.Context) error {
|
||||
login, owner, repo := initCommand()
|
||||
|
||||
state := gitea.StateOpen
|
||||
@ -52,7 +87,7 @@ func runPulls(ctx *cli.Context) error {
|
||||
state = gitea.StateClosed
|
||||
}
|
||||
|
||||
prs, err := login.Client().ListRepoPullRequests(owner, repo, gitea.ListPullRequestsOptions{
|
||||
prs, _, err := login.Client().ListRepoPullRequests(owner, repo, gitea.ListPullRequestsOptions{
|
||||
State: state,
|
||||
})
|
||||
|
||||
@ -62,10 +97,11 @@ func runPulls(ctx *cli.Context) error {
|
||||
|
||||
headers := []string{
|
||||
"Index",
|
||||
"Title",
|
||||
"State",
|
||||
"Author",
|
||||
"Milestone",
|
||||
"Updated",
|
||||
"Title",
|
||||
}
|
||||
|
||||
var values [][]string
|
||||
@ -79,18 +115,23 @@ func runPulls(ctx *cli.Context) error {
|
||||
if pr == nil {
|
||||
continue
|
||||
}
|
||||
name := pr.Poster.FullName
|
||||
if len(name) == 0 {
|
||||
name = pr.Poster.UserName
|
||||
author := pr.Poster.FullName
|
||||
if len(author) == 0 {
|
||||
author = pr.Poster.UserName
|
||||
}
|
||||
mile := ""
|
||||
if pr.Milestone != nil {
|
||||
mile = pr.Milestone.Title
|
||||
}
|
||||
values = append(
|
||||
values,
|
||||
[]string{
|
||||
strconv.FormatInt(pr.Index, 10),
|
||||
string(pr.State),
|
||||
name,
|
||||
pr.Updated.Format("2006-01-02 15:04:05"),
|
||||
pr.Title,
|
||||
string(pr.State),
|
||||
author,
|
||||
mile,
|
||||
pr.Updated.Format("2006-01-02 15:04:05"),
|
||||
},
|
||||
)
|
||||
}
|
||||
@ -120,7 +161,7 @@ func runPullsCheckout(ctx *cli.Context) error {
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
pr, err := login.Client().GetPullRequest(owner, repo, idx)
|
||||
pr, _, err := login.Client().GetPullRequest(owner, repo, idx)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
@ -204,7 +245,7 @@ func runPullsClean(ctx *cli.Context) error {
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
pr, err := login.Client().GetPullRequest(owner, repo, idx)
|
||||
pr, _, err := login.Client().GetPullRequest(owner, repo, idx)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
@ -298,15 +339,22 @@ func runPullsCreate(ctx *cli.Context) error {
|
||||
login, ownerArg, repoArg := initCommand()
|
||||
client := login.Client()
|
||||
|
||||
repo, err := login.Client().GetRepo(ownerArg, repoArg)
|
||||
repo, _, err := client.GetRepo(ownerArg, repoArg)
|
||||
if err != nil {
|
||||
log.Fatal(err)
|
||||
log.Fatal("could not fetch repo meta: ", err)
|
||||
}
|
||||
|
||||
// open local git repo
|
||||
localRepo, err := local_git.RepoForWorkdir()
|
||||
if err != nil {
|
||||
log.Fatal(err)
|
||||
log.Fatal("could not open local repo: ", err)
|
||||
}
|
||||
|
||||
// push if possible
|
||||
log.Println("git push")
|
||||
err = localRepo.Push(&git.PushOptions{})
|
||||
if err != nil && err != git.NoErrAlreadyUpToDate {
|
||||
log.Printf("Error occurred during 'git push':\n%s\n", err.Error())
|
||||
}
|
||||
|
||||
base := ctx.String("base")
|
||||
@ -318,10 +366,35 @@ func runPullsCreate(ctx *cli.Context) error {
|
||||
head := ctx.String("head")
|
||||
// default is current one
|
||||
if len(head) == 0 {
|
||||
head, err = localRepo.TeaGetCurrentBranchName()
|
||||
headBranch, err := localRepo.Head()
|
||||
if err != nil {
|
||||
log.Fatal(err)
|
||||
}
|
||||
sha := headBranch.Hash().String()
|
||||
|
||||
remote, err := localRepo.TeaFindBranchRemote("", sha)
|
||||
if err != nil {
|
||||
log.Fatal("could not determine remote for current branch: ", err)
|
||||
}
|
||||
|
||||
if remote == nil {
|
||||
// if no remote branch is found for the local hash, we abort:
|
||||
// user has probably not configured a remote for the local branch,
|
||||
// or local branch does not represent remote state.
|
||||
log.Fatal("no matching remote found for this branch. try git push -u <remote> <branch>")
|
||||
}
|
||||
|
||||
branchName, err := localRepo.TeaGetCurrentBranchName()
|
||||
if err != nil {
|
||||
log.Fatal(err)
|
||||
}
|
||||
|
||||
url, err := local_git.ParseURL(remote.Config().URLs[0])
|
||||
if err != nil {
|
||||
log.Fatal(err)
|
||||
}
|
||||
owner, _ := getOwnerAndRepo(strings.TrimLeft(url.Path, "/"), "")
|
||||
head = fmt.Sprintf("%s:%s", owner, branchName)
|
||||
}
|
||||
|
||||
title := ctx.String("title")
|
||||
@ -341,13 +414,7 @@ func runPullsCreate(ctx *cli.Context) error {
|
||||
return nil
|
||||
}
|
||||
|
||||
// push if possible
|
||||
err = localRepo.Push(&git.PushOptions{})
|
||||
if err != nil {
|
||||
fmt.Printf("Error occurred during 'git push':\n%s\n", err.Error())
|
||||
}
|
||||
|
||||
pr, err := client.CreatePullRequest(ownerArg, repoArg, gitea.CreatePullRequestOption{
|
||||
pr, _, err := client.CreatePullRequest(ownerArg, repoArg, gitea.CreatePullRequestOption{
|
||||
Head: head,
|
||||
Base: base,
|
||||
Title: title,
|
||||
@ -355,19 +422,21 @@ func runPullsCreate(ctx *cli.Context) error {
|
||||
})
|
||||
|
||||
if err != nil {
|
||||
log.Fatal(err)
|
||||
log.Fatalf("could not create PR from %s to %s:%s: %s", head, ownerArg, base, err)
|
||||
}
|
||||
|
||||
fmt.Printf("#%d %s\n%s created %s\n", pr.Index,
|
||||
in := fmt.Sprintf("# #%d %s (%s)\n%s created %s\n\n%s\n", pr.Index,
|
||||
pr.Title,
|
||||
pr.State,
|
||||
pr.Poster.UserName,
|
||||
pr.Created.Format("2006-01-02 15:04:05"),
|
||||
pr.Body,
|
||||
)
|
||||
if len(pr.Body) != 0 {
|
||||
fmt.Printf("\n%s\n", pr.Body)
|
||||
}
|
||||
out, err := glamour.Render(in, getGlamourTheme())
|
||||
fmt.Print(out)
|
||||
|
||||
fmt.Println(pr.HTMLURL)
|
||||
return nil
|
||||
return err
|
||||
}
|
||||
|
||||
func argToIndex(arg string) (int64, error) {
|
||||
|
185
cmd/releases.go
185
cmd/releases.go
@ -5,9 +5,12 @@
|
||||
package cmd
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"log"
|
||||
"net/http"
|
||||
"os"
|
||||
"path/filepath"
|
||||
"strings"
|
||||
|
||||
"code.gitea.io/sdk/gitea"
|
||||
|
||||
@ -16,20 +19,36 @@ import (
|
||||
|
||||
// CmdReleases represents to login a gitea server.
|
||||
var CmdReleases = cli.Command{
|
||||
Name: "releases",
|
||||
Usage: "Create releases",
|
||||
Description: `Create releases`,
|
||||
Name: "release",
|
||||
Aliases: []string{"releases"},
|
||||
Usage: "Manage releases",
|
||||
Description: "Manage releases",
|
||||
Action: runReleases,
|
||||
Subcommands: []*cli.Command{
|
||||
&CmdReleaseList,
|
||||
&CmdReleaseCreate,
|
||||
&CmdReleaseDelete,
|
||||
&CmdReleaseEdit,
|
||||
},
|
||||
Flags: AllDefaultFlags,
|
||||
}
|
||||
|
||||
// CmdReleaseList represents a sub command of Release to list releases
|
||||
var CmdReleaseList = cli.Command{
|
||||
Name: "ls",
|
||||
Usage: "List Releases",
|
||||
Description: "List Releases",
|
||||
Action: runReleases,
|
||||
Flags: append([]cli.Flag{
|
||||
&PaginationPageFlag,
|
||||
&PaginationLimitFlag,
|
||||
}, AllDefaultFlags...),
|
||||
}
|
||||
|
||||
func runReleases(ctx *cli.Context) error {
|
||||
login, owner, repo := initCommand()
|
||||
|
||||
releases, err := login.Client().ListReleases(owner, repo, gitea.ListReleasesOptions{})
|
||||
releases, _, err := login.Client().ListReleases(owner, repo, gitea.ListReleasesOptions{ListOptions: getListOptions(ctx)})
|
||||
if err != nil {
|
||||
log.Fatal(err)
|
||||
}
|
||||
@ -38,6 +57,7 @@ func runReleases(ctx *cli.Context) error {
|
||||
"Tag-Name",
|
||||
"Title",
|
||||
"Published At",
|
||||
"Status",
|
||||
"Tar URL",
|
||||
}
|
||||
|
||||
@ -49,12 +69,19 @@ func runReleases(ctx *cli.Context) error {
|
||||
}
|
||||
|
||||
for _, release := range releases {
|
||||
status := "released"
|
||||
if release.IsDraft {
|
||||
status = "draft"
|
||||
} else if release.IsPrerelease {
|
||||
status = "prerelease"
|
||||
}
|
||||
values = append(
|
||||
values,
|
||||
[]string{
|
||||
release.TagName,
|
||||
release.Title,
|
||||
release.PublishedAt.Format("2006-01-02 15:04:05"),
|
||||
status,
|
||||
release.TarURL,
|
||||
},
|
||||
)
|
||||
@ -64,7 +91,7 @@ func runReleases(ctx *cli.Context) error {
|
||||
return nil
|
||||
}
|
||||
|
||||
// CmdReleaseCreate represents a sub command of Release to create release.
|
||||
// CmdReleaseCreate represents a sub command of Release to create release
|
||||
var CmdReleaseCreate = cli.Command{
|
||||
Name: "create",
|
||||
Usage: "Create a release",
|
||||
@ -104,13 +131,13 @@ var CmdReleaseCreate = cli.Command{
|
||||
Aliases: []string{"a"},
|
||||
Usage: "List of files to attach",
|
||||
},
|
||||
}, LoginRepoFlags...),
|
||||
}, AllDefaultFlags...),
|
||||
}
|
||||
|
||||
func runReleaseCreate(ctx *cli.Context) error {
|
||||
login, owner, repo := initCommand()
|
||||
|
||||
release, err := login.Client().CreateRelease(owner, repo, gitea.CreateReleaseOption{
|
||||
release, resp, err := login.Client().CreateRelease(owner, repo, gitea.CreateReleaseOption{
|
||||
TagName: ctx.String("tag"),
|
||||
Target: ctx.String("target"),
|
||||
Title: ctx.String("title"),
|
||||
@ -120,10 +147,10 @@ func runReleaseCreate(ctx *cli.Context) error {
|
||||
})
|
||||
|
||||
if err != nil {
|
||||
if err.Error() == "409 Conflict" {
|
||||
log.Fatal("error: There already is a release for this tag")
|
||||
if resp != nil && resp.StatusCode == http.StatusConflict {
|
||||
fmt.Println("error: There already is a release for this tag")
|
||||
return nil
|
||||
}
|
||||
|
||||
log.Fatal(err)
|
||||
}
|
||||
|
||||
@ -136,7 +163,7 @@ func runReleaseCreate(ctx *cli.Context) error {
|
||||
|
||||
filePath := filepath.Base(asset)
|
||||
|
||||
if _, err = login.Client().CreateReleaseAttachment(owner, repo, release.ID, file, filePath); err != nil {
|
||||
if _, _, err = login.Client().CreateReleaseAttachment(owner, repo, release.ID, file, filePath); err != nil {
|
||||
file.Close()
|
||||
log.Fatal(err)
|
||||
}
|
||||
@ -146,3 +173,139 @@ func runReleaseCreate(ctx *cli.Context) error {
|
||||
|
||||
return nil
|
||||
}
|
||||
|
||||
// CmdReleaseDelete represents a sub command of Release to delete a release
|
||||
var CmdReleaseDelete = cli.Command{
|
||||
Name: "delete",
|
||||
Usage: "Delete a release",
|
||||
Description: `Delete a release`,
|
||||
ArgsUsage: "<release tag>",
|
||||
Action: runReleaseDelete,
|
||||
Flags: AllDefaultFlags,
|
||||
}
|
||||
|
||||
func runReleaseDelete(ctx *cli.Context) error {
|
||||
login, owner, repo := initCommand()
|
||||
client := login.Client()
|
||||
|
||||
tag := ctx.Args().First()
|
||||
if len(tag) == 0 {
|
||||
fmt.Println("Release tag needed to delete")
|
||||
return nil
|
||||
}
|
||||
|
||||
release, err := getReleaseByTag(owner, repo, tag, client)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
if release == nil {
|
||||
return nil
|
||||
}
|
||||
|
||||
_, err = client.DeleteRelease(owner, repo, release.ID)
|
||||
return err
|
||||
}
|
||||
|
||||
func getReleaseByTag(owner, repo, tag string, client *gitea.Client) (*gitea.Release, error) {
|
||||
rl, _, err := client.ListReleases(owner, repo, gitea.ListReleasesOptions{})
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
if len(rl) == 0 {
|
||||
fmt.Println("Repo does not have any release")
|
||||
return nil, nil
|
||||
}
|
||||
for _, r := range rl {
|
||||
if r.TagName == tag {
|
||||
return r, nil
|
||||
}
|
||||
}
|
||||
fmt.Println("Release tag does not exist")
|
||||
return nil, nil
|
||||
}
|
||||
|
||||
// CmdReleaseEdit represents a sub command of Release to edit releases
|
||||
var CmdReleaseEdit = cli.Command{
|
||||
Name: "edit",
|
||||
Usage: "Edit a release",
|
||||
Description: `Edit a release`,
|
||||
ArgsUsage: "<release tag>",
|
||||
Action: runReleaseEdit,
|
||||
Flags: append([]cli.Flag{
|
||||
&cli.StringFlag{
|
||||
Name: "tag",
|
||||
Usage: "Change Tag",
|
||||
},
|
||||
&cli.StringFlag{
|
||||
Name: "target",
|
||||
Usage: "Change Target",
|
||||
},
|
||||
&cli.StringFlag{
|
||||
Name: "title",
|
||||
Aliases: []string{"t"},
|
||||
Usage: "Change Title",
|
||||
},
|
||||
&cli.StringFlag{
|
||||
Name: "note",
|
||||
Aliases: []string{"n"},
|
||||
Usage: "Change Notes",
|
||||
},
|
||||
&cli.StringFlag{
|
||||
Name: "draft",
|
||||
Aliases: []string{"d"},
|
||||
Usage: "Mark as Draft [True/false]",
|
||||
DefaultText: "true",
|
||||
},
|
||||
&cli.StringFlag{
|
||||
Name: "prerelease",
|
||||
Aliases: []string{"p"},
|
||||
Usage: "Mark as Pre-Release [True/false]",
|
||||
DefaultText: "true",
|
||||
},
|
||||
}, AllDefaultFlags...),
|
||||
}
|
||||
|
||||
func runReleaseEdit(ctx *cli.Context) error {
|
||||
login, owner, repo := initCommand()
|
||||
client := login.Client()
|
||||
|
||||
tag := ctx.Args().First()
|
||||
if len(tag) == 0 {
|
||||
fmt.Println("Release tag needed to edit")
|
||||
return nil
|
||||
}
|
||||
|
||||
release, err := getReleaseByTag(owner, repo, tag, client)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
if release == nil {
|
||||
return nil
|
||||
}
|
||||
|
||||
var isDraft, isPre *bool
|
||||
bTrue := true
|
||||
bFalse := false
|
||||
if ctx.IsSet("draft") {
|
||||
isDraft = &bFalse
|
||||
if strings.ToLower(ctx.String("draft"))[:1] == "t" {
|
||||
isDraft = &bTrue
|
||||
}
|
||||
}
|
||||
if ctx.IsSet("prerelease") {
|
||||
isPre = &bFalse
|
||||
if strings.ToLower(ctx.String("prerelease"))[:1] == "t" {
|
||||
isPre = &bTrue
|
||||
}
|
||||
}
|
||||
|
||||
_, _, err = client.EditRelease(owner, repo, release.ID, gitea.EditReleaseOption{
|
||||
TagName: ctx.String("tag"),
|
||||
Target: ctx.String("target"),
|
||||
Title: ctx.String("title"),
|
||||
Note: ctx.String("note"),
|
||||
IsDraft: isDraft,
|
||||
IsPrerelease: isPre,
|
||||
})
|
||||
return err
|
||||
}
|
||||
|
280
cmd/repos.go
280
cmd/repos.go
@ -5,26 +5,32 @@
|
||||
package cmd
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"log"
|
||||
"net/http"
|
||||
"strings"
|
||||
|
||||
"code.gitea.io/tea/modules/utils"
|
||||
|
||||
"code.gitea.io/sdk/gitea"
|
||||
|
||||
"github.com/urfave/cli/v2"
|
||||
)
|
||||
|
||||
// CmdRepos represents to login a gitea server.
|
||||
var CmdRepos = cli.Command{
|
||||
Name: "repos",
|
||||
Usage: "Operate with repositories",
|
||||
Description: `Operate with repositories`,
|
||||
Action: runReposList,
|
||||
Usage: "Show repositories details",
|
||||
Description: "Show repositories details",
|
||||
ArgsUsage: "[<repo owner>/<repo name>]",
|
||||
Action: runRepos,
|
||||
Subcommands: []*cli.Command{
|
||||
&CmdReposList,
|
||||
&CmdRepoCreate,
|
||||
},
|
||||
Flags: LoginOutputFlags,
|
||||
}
|
||||
|
||||
// CmdReposList represents a sub command of issues to list issues
|
||||
// CmdReposList represents a sub command of repos to list them
|
||||
var CmdReposList = cli.Command{
|
||||
Name: "ls",
|
||||
Usage: "List available repositories",
|
||||
@ -33,65 +39,166 @@ var CmdReposList = cli.Command{
|
||||
Flags: append([]cli.Flag{
|
||||
&cli.StringFlag{
|
||||
Name: "mode",
|
||||
Usage: "Filter listed repositories based on mode, optional - fork, mirror, source",
|
||||
Aliases: []string{"m"},
|
||||
Required: false,
|
||||
Usage: "Filter by mode: fork, mirror, source",
|
||||
},
|
||||
&cli.StringFlag{
|
||||
Name: "org",
|
||||
Usage: "Filter listed repositories based on organization, optional",
|
||||
Name: "owner",
|
||||
Aliases: []string{"O"},
|
||||
Required: false,
|
||||
Usage: "Filter by owner",
|
||||
},
|
||||
&cli.StringFlag{
|
||||
Name: "user",
|
||||
Usage: "Filter listed repositories absed on user, optional",
|
||||
Name: "private",
|
||||
Required: false,
|
||||
Usage: "Filter private repos (true|false)",
|
||||
},
|
||||
&cli.StringFlag{
|
||||
Name: "archived",
|
||||
Required: false,
|
||||
Usage: "Filter archived repos (true|false)",
|
||||
},
|
||||
&PaginationPageFlag,
|
||||
&PaginationLimitFlag,
|
||||
}, LoginOutputFlags...),
|
||||
}
|
||||
|
||||
// CmdRepoCreate represents a sub command of repos to create one
|
||||
var CmdRepoCreate = cli.Command{
|
||||
Name: "create",
|
||||
Aliases: []string{"c"},
|
||||
Usage: "Create a repository",
|
||||
Description: "Create a repository",
|
||||
Action: runRepoCreate,
|
||||
Flags: append([]cli.Flag{
|
||||
&cli.StringFlag{
|
||||
Name: "name",
|
||||
Aliases: []string{""},
|
||||
Required: true,
|
||||
Usage: "name of new repo",
|
||||
},
|
||||
&cli.StringFlag{
|
||||
Name: "owner",
|
||||
Aliases: []string{"O"},
|
||||
Required: false,
|
||||
Usage: "name of repo owner",
|
||||
},
|
||||
&cli.BoolFlag{
|
||||
Name: "private",
|
||||
Required: false,
|
||||
Value: false,
|
||||
Usage: "make repo private",
|
||||
},
|
||||
&cli.StringFlag{
|
||||
Name: "description",
|
||||
Aliases: []string{"desc"},
|
||||
Required: false,
|
||||
Usage: "add description to repo",
|
||||
},
|
||||
&cli.BoolFlag{
|
||||
Name: "init",
|
||||
Required: false,
|
||||
Value: false,
|
||||
Usage: "initialize repo",
|
||||
},
|
||||
&cli.StringFlag{
|
||||
Name: "labels",
|
||||
Required: false,
|
||||
Usage: "name of label set to add",
|
||||
},
|
||||
&cli.StringFlag{
|
||||
Name: "gitignores",
|
||||
Aliases: []string{"git"},
|
||||
Required: false,
|
||||
Usage: "list of gitignore templates (need --init)",
|
||||
},
|
||||
&cli.StringFlag{
|
||||
Name: "license",
|
||||
Required: false,
|
||||
Usage: "add license (need --init)",
|
||||
},
|
||||
&cli.StringFlag{
|
||||
Name: "readme",
|
||||
Required: false,
|
||||
Usage: "use readme template (need --init)",
|
||||
},
|
||||
&cli.StringFlag{
|
||||
Name: "branch",
|
||||
Required: false,
|
||||
Usage: "use custom default branch (need --init)",
|
||||
},
|
||||
}, LoginOutputFlags...),
|
||||
}
|
||||
|
||||
func runRepos(ctx *cli.Context) error {
|
||||
if ctx.Args().Len() == 1 {
|
||||
return runRepoDetail(ctx, ctx.Args().First())
|
||||
}
|
||||
return runReposList(ctx)
|
||||
}
|
||||
|
||||
// runReposList list repositories
|
||||
func runReposList(ctx *cli.Context) error {
|
||||
login := initCommandLoginOnly()
|
||||
client := login.Client()
|
||||
|
||||
mode := ctx.String("mode")
|
||||
org := ctx.String("org")
|
||||
user := ctx.String("user")
|
||||
|
||||
var rps []*gitea.Repository
|
||||
var err error
|
||||
|
||||
if org != "" {
|
||||
rps, err = login.Client().ListOrgRepos(org, gitea.ListOrgReposOptions{})
|
||||
} else if user != "" {
|
||||
rps, err = login.Client().ListUserRepos(user, gitea.ListReposOptions{})
|
||||
} else {
|
||||
rps, err = login.Client().ListMyRepos(gitea.ListReposOptions{})
|
||||
}
|
||||
var ownerID int64
|
||||
if ctx.IsSet("owner") {
|
||||
// test if owner is a organisation
|
||||
org, resp, err := client.GetOrg(ctx.String("owner"))
|
||||
if err != nil {
|
||||
log.Fatal(err)
|
||||
if resp == nil || resp.StatusCode != http.StatusNotFound {
|
||||
return err
|
||||
}
|
||||
|
||||
var repos []*gitea.Repository
|
||||
if mode == "" {
|
||||
repos = rps
|
||||
} else if mode == "fork" {
|
||||
for _, rp := range rps {
|
||||
if rp.Fork == true {
|
||||
repos = append(repos, rp)
|
||||
}
|
||||
}
|
||||
} else if mode == "mirror" {
|
||||
for _, rp := range rps {
|
||||
if rp.Mirror == true {
|
||||
repos = append(repos, rp)
|
||||
}
|
||||
}
|
||||
} else if mode == "source" {
|
||||
for _, rp := range rps {
|
||||
if rp.Mirror != true && rp.Fork != true {
|
||||
repos = append(repos, rp)
|
||||
// if owner is no org, its a user
|
||||
user, _, err := client.GetUserInfo(ctx.String("owner"))
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
ownerID = user.ID
|
||||
} else {
|
||||
ownerID = org.ID
|
||||
}
|
||||
} else {
|
||||
log.Fatal("Unknown mode: ", mode, "\nUse one of the following:\n- fork\n- mirror\n- source\n")
|
||||
return nil
|
||||
me, _, err := client.GetMyUserInfo()
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
ownerID = me.ID
|
||||
}
|
||||
|
||||
var isArchived *bool
|
||||
if ctx.IsSet("archived") {
|
||||
archived := strings.ToLower(ctx.String("archived"))[:1] == "t"
|
||||
isArchived = &archived
|
||||
}
|
||||
|
||||
var isPrivate *bool
|
||||
if ctx.IsSet("private") {
|
||||
private := strings.ToLower(ctx.String("private"))[:1] == "t"
|
||||
isArchived = &private
|
||||
}
|
||||
|
||||
mode := gitea.RepoTypeNone
|
||||
switch ctx.String("mode") {
|
||||
case "fork":
|
||||
mode = gitea.RepoTypeFork
|
||||
case "mirror":
|
||||
mode = gitea.RepoTypeMirror
|
||||
case "source":
|
||||
mode = gitea.RepoTypeSource
|
||||
}
|
||||
|
||||
rps, _, err := client.SearchRepos(gitea.SearchRepoOptions{
|
||||
ListOptions: getListOptions(ctx),
|
||||
OwnerID: ownerID,
|
||||
IsPrivate: isPrivate,
|
||||
IsArchived: isArchived,
|
||||
Type: mode,
|
||||
})
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
if len(rps) == 0 {
|
||||
@ -107,7 +214,7 @@ func runReposList(ctx *cli.Context) error {
|
||||
}
|
||||
var values [][]string
|
||||
|
||||
for _, rp := range repos {
|
||||
for _, rp := range rps {
|
||||
var mode = "source"
|
||||
if rp.Fork {
|
||||
mode = "fork"
|
||||
@ -130,3 +237,80 @@ func runReposList(ctx *cli.Context) error {
|
||||
|
||||
return nil
|
||||
}
|
||||
|
||||
func runRepoDetail(_ *cli.Context, path string) error {
|
||||
login := initCommandLoginOnly()
|
||||
client := login.Client()
|
||||
repoOwner, repoName := getOwnerAndRepo(path, login.User)
|
||||
repo, _, err := client.GetRepo(repoOwner, repoName)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
topics, _, err := client.ListRepoTopics(repo.Owner.UserName, repo.Name, gitea.ListRepoTopicsOptions{})
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
output := repo.FullName
|
||||
if repo.Mirror {
|
||||
output += " (mirror)"
|
||||
}
|
||||
if repo.Fork {
|
||||
output += " (fork)"
|
||||
}
|
||||
if repo.Archived {
|
||||
output += " (archived)"
|
||||
}
|
||||
if repo.Empty {
|
||||
output += " (empty)"
|
||||
}
|
||||
output += "\n"
|
||||
if len(topics) != 0 {
|
||||
output += "Topics: " + strings.Join(topics, ", ") + "\n"
|
||||
}
|
||||
output += "\n"
|
||||
output += repo.Description + "\n\n"
|
||||
output += fmt.Sprintf(
|
||||
"Open Issues: %d, Stars: %d, Forks: %d, Size: %s\n\n",
|
||||
repo.OpenIssues,
|
||||
repo.Stars,
|
||||
repo.Forks,
|
||||
utils.FormatSize(int64(repo.Size)),
|
||||
)
|
||||
|
||||
fmt.Print(output)
|
||||
return nil
|
||||
}
|
||||
|
||||
func runRepoCreate(ctx *cli.Context) error {
|
||||
login := initCommandLoginOnly()
|
||||
client := login.Client()
|
||||
var (
|
||||
repo *gitea.Repository
|
||||
err error
|
||||
)
|
||||
opts := gitea.CreateRepoOption{
|
||||
Name: ctx.String("name"),
|
||||
Description: ctx.String("description"),
|
||||
Private: ctx.Bool("private"),
|
||||
AutoInit: ctx.Bool("init"),
|
||||
IssueLabels: ctx.String("labels"),
|
||||
Gitignores: ctx.String("gitignores"),
|
||||
License: ctx.String("license"),
|
||||
Readme: ctx.String("readme"),
|
||||
DefaultBranch: ctx.String("branch"),
|
||||
}
|
||||
if len(ctx.String("owner")) != 0 {
|
||||
repo, _, err = client.CreateOrgRepo(ctx.String("owner"), opts)
|
||||
} else {
|
||||
repo, _, err = client.CreateRepo(opts)
|
||||
}
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
if err = runRepoDetail(ctx, repo.FullName); err != nil {
|
||||
return err
|
||||
}
|
||||
fmt.Printf("%s\n", repo.HTMLURL)
|
||||
return nil
|
||||
}
|
||||
|
25
cmd/times.go
25
cmd/times.go
@ -66,17 +66,17 @@ func runTrackedTimes(ctx *cli.Context) error {
|
||||
fmt.Println(ctx.Command.ArgsUsage)
|
||||
if user == "" {
|
||||
// get all tracked times on the repo
|
||||
times, err = client.GetRepoTrackedTimes(owner, repo)
|
||||
times, _, err = client.GetRepoTrackedTimes(owner, repo)
|
||||
} else if strings.HasPrefix(user, "#") {
|
||||
// get all tracked times on the specified issue
|
||||
issue, err := argToIndex(user)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
times, err = client.ListTrackedTimes(owner, repo, issue, gitea.ListTrackedTimesOptions{})
|
||||
times, _, err = client.ListTrackedTimes(owner, repo, issue, gitea.ListTrackedTimesOptions{})
|
||||
} else {
|
||||
// get all tracked times by the specified user
|
||||
times, err = client.GetUserTrackedTimes(owner, repo, user)
|
||||
times, _, err = client.GetUserTrackedTimes(owner, repo, user)
|
||||
}
|
||||
|
||||
if err != nil {
|
||||
@ -101,6 +101,15 @@ func runTrackedTimes(ctx *cli.Context) error {
|
||||
return nil
|
||||
}
|
||||
|
||||
func formatDuration(seconds int64, outputType string) string {
|
||||
switch outputType {
|
||||
case "yaml":
|
||||
case "csv":
|
||||
return fmt.Sprint(seconds)
|
||||
}
|
||||
return time.Duration(1e9 * seconds).String()
|
||||
}
|
||||
|
||||
func printTrackedTimes(times []*gitea.TrackedTime, outputType string, from, until time.Time, printTotal bool) {
|
||||
var outputValues [][]string
|
||||
var totalDuration int64
|
||||
@ -126,14 +135,14 @@ func printTrackedTimes(times []*gitea.TrackedTime, outputType string, from, unti
|
||||
t.Created.In(localLoc).Format("2006-01-02 15:04:05"),
|
||||
"#" + strconv.FormatInt(t.Issue.Index, 10),
|
||||
t.UserName,
|
||||
time.Duration(1e9 * t.Time).String(),
|
||||
formatDuration(t.Time, outputType),
|
||||
},
|
||||
)
|
||||
}
|
||||
|
||||
if printTotal {
|
||||
outputValues = append(outputValues, []string{
|
||||
"TOTAL", "", "", time.Duration(1e9 * totalDuration).String(),
|
||||
"TOTAL", "", "", formatDuration(totalDuration, outputType),
|
||||
})
|
||||
}
|
||||
|
||||
@ -176,7 +185,7 @@ func runTrackedTimesAdd(ctx *cli.Context) error {
|
||||
log.Fatal(err)
|
||||
}
|
||||
|
||||
_, err = login.Client().AddTime(owner, repo, issue, gitea.AddTimeOption{
|
||||
_, _, err = login.Client().AddTime(owner, repo, issue, gitea.AddTimeOption{
|
||||
Time: int64(duration.Seconds()),
|
||||
})
|
||||
if err != nil {
|
||||
@ -218,7 +227,7 @@ func runTrackedTimesDelete(ctx *cli.Context) error {
|
||||
log.Fatal(err)
|
||||
}
|
||||
|
||||
err = client.DeleteTime(owner, repo, issue, timeID)
|
||||
_, err = client.DeleteTime(owner, repo, issue, timeID)
|
||||
if err != nil {
|
||||
log.Fatal(err)
|
||||
}
|
||||
@ -253,7 +262,7 @@ func runTrackedTimesReset(ctx *cli.Context) error {
|
||||
log.Fatal(err)
|
||||
}
|
||||
|
||||
err = client.ResetIssueTime(owner, repo, issue)
|
||||
_, err = client.ResetIssueTime(owner, repo, issue)
|
||||
if err != nil {
|
||||
log.Fatal(err)
|
||||
}
|
||||
|
9
go.mod
9
go.mod
@ -3,13 +3,14 @@ module code.gitea.io/tea
|
||||
go 1.12
|
||||
|
||||
require (
|
||||
code.gitea.io/sdk/gitea v0.12.1
|
||||
gitea.com/jolheiser/gitea-vet v0.1.0
|
||||
code.gitea.io/gitea-vet v0.2.0
|
||||
code.gitea.io/sdk/gitea v0.13.0
|
||||
github.com/araddon/dateparse v0.0.0-20200409225146-d820a6159ab1
|
||||
github.com/charmbracelet/glamour v0.2.0
|
||||
github.com/cpuguy83/go-md2man/v2 v2.0.0 // indirect
|
||||
github.com/go-git/go-git/v5 v5.1.0
|
||||
github.com/hashicorp/go-version v1.2.1 // indirect
|
||||
github.com/mattn/go-runewidth v0.0.9 // indirect
|
||||
github.com/muesli/termenv v0.7.2
|
||||
github.com/olekukonko/tablewriter v0.0.4
|
||||
github.com/skratchdot/open-golang v0.0.0-20200116055534-eef842397966
|
||||
github.com/stretchr/testify v1.5.1
|
||||
@ -17,6 +18,6 @@ require (
|
||||
golang.org/x/crypto v0.0.0-20200709230013-948cd5f35899
|
||||
golang.org/x/net v0.0.0-20200707034311-ab3426394381 // indirect
|
||||
golang.org/x/sys v0.0.0-20200625212154-ddb9806d33ae // indirect
|
||||
golang.org/x/tools v0.0.0-20200713011307-fd294ab11aed // indirect
|
||||
golang.org/x/tools v0.0.0-20200721032237-77f530d86f9a // indirect
|
||||
gopkg.in/yaml.v2 v2.3.0
|
||||
)
|
||||
|
53
go.sum
53
go.sum
@ -1,24 +1,39 @@
|
||||
code.gitea.io/sdk/gitea v0.12.1 h1:bMgjEqPnNX/i6TpVwXwpjJtFOnUSuC9P6yy/jjy8sjY=
|
||||
code.gitea.io/sdk/gitea v0.12.1/go.mod h1:z3uwDV/b9Ls47NGukYM9XhnHtqPh/J+t40lsUrR6JDY=
|
||||
gitea.com/jolheiser/gitea-vet v0.1.0 h1:gJEms9YWbIcrPOEmDOJ+5JZXCYFxNpwxlI73uRulAi4=
|
||||
gitea.com/jolheiser/gitea-vet v0.1.0/go.mod h1:2Oa6TAdEp1N/38oBNh3ZeiSEER60D/CeDaBFv2sdH58=
|
||||
code.gitea.io/gitea-vet v0.2.0 h1:xkUePzbHI8e0qp4Aly4GBSd0+6cqEMVTrdZq57fPozo=
|
||||
code.gitea.io/gitea-vet v0.2.0/go.mod h1:zcNbT/aJEmivCAhfmkHOlT645KNOf9W2KnkLgFjGGfE=
|
||||
code.gitea.io/sdk/gitea v0.13.0 h1:iHognp8ZMhMFLooUUNZFpm8IHaC9qoHJDvAE5vTm5aw=
|
||||
code.gitea.io/sdk/gitea v0.13.0/go.mod h1:z3uwDV/b9Ls47NGukYM9XhnHtqPh/J+t40lsUrR6JDY=
|
||||
github.com/BurntSushi/toml v0.3.1/go.mod h1:xHWCNGjB5oqiDr8zfno3MHue2Ht5sIBksp03qcyfWMU=
|
||||
github.com/alcortesm/tgz v0.0.0-20161220082320-9c5fe88206d7 h1:uSoVVbwJiQipAclBbw+8quDsfcvFjOpI5iCf4p/cqCs=
|
||||
github.com/alcortesm/tgz v0.0.0-20161220082320-9c5fe88206d7/go.mod h1:6zEj6s6u/ghQa61ZWa/C2Aw3RkjiTBOix7dkqa1VLIs=
|
||||
github.com/alecthomas/assert v0.0.0-20170929043011-405dbfeb8e38 h1:smF2tmSOzy2Mm+0dGI2AIUHY+w0BUc+4tn40djz7+6U=
|
||||
github.com/alecthomas/assert v0.0.0-20170929043011-405dbfeb8e38/go.mod h1:r7bzyVFMNntcxPZXK3/+KdruV1H5KSlyVY0gc+NgInI=
|
||||
github.com/alecthomas/chroma v0.7.3 h1:NfdAERMy+esYQs8OXk0I868/qDxxCEo7FMz1WIqMAeI=
|
||||
github.com/alecthomas/chroma v0.7.3/go.mod h1:sko8vR34/90zvl5QdcUdvzL3J8NKjAUx9va9jPuFNoM=
|
||||
github.com/alecthomas/colour v0.0.0-20160524082231-60882d9e2721 h1:JHZL0hZKJ1VENNfmXvHbgYlbUOvpzYzvy2aZU5gXVeo=
|
||||
github.com/alecthomas/colour v0.0.0-20160524082231-60882d9e2721/go.mod h1:QO9JBoKquHd+jz9nshCh40fOfO+JzsoXy8qTHF68zU0=
|
||||
github.com/alecthomas/kong v0.2.4/go.mod h1:kQOmtJgV+Lb4aj+I2LEn40cbtawdWJ9Y8QLq+lElKxE=
|
||||
github.com/alecthomas/repr v0.0.0-20180818092828-117648cd9897 h1:p9Sln00KOTlrYkxI1zYWl1QLnEqAqEARBEYa8FQnQcY=
|
||||
github.com/alecthomas/repr v0.0.0-20180818092828-117648cd9897/go.mod h1:xTS7Pm1pD1mvyM075QCDSRqH6qRLXylzS24ZTpRiSzQ=
|
||||
github.com/anmitsu/go-shlex v0.0.0-20161002113705-648efa622239 h1:kFOfPq6dUM1hTo4JG6LR5AXSUEsOjtdm0kw0FtQtMJA=
|
||||
github.com/anmitsu/go-shlex v0.0.0-20161002113705-648efa622239/go.mod h1:2FmKhYUyUczH0OGQWaF5ceTx0UBShxjsH6f8oGKYe2c=
|
||||
github.com/araddon/dateparse v0.0.0-20200409225146-d820a6159ab1 h1:TEBmxO80TM04L8IuMWk77SGL1HomBmKTdzdJLLWznxI=
|
||||
github.com/araddon/dateparse v0.0.0-20200409225146-d820a6159ab1/go.mod h1:SLqhdZcd+dF3TEVL2RMoob5bBP5R1P1qkox+HtCBgGI=
|
||||
github.com/armon/go-socks5 v0.0.0-20160902184237-e75332964ef5 h1:0CwZNZbxp69SHPdPJAN/hZIm0C4OItdklCFmMRWYpio=
|
||||
github.com/armon/go-socks5 v0.0.0-20160902184237-e75332964ef5/go.mod h1:wHh0iHkYZB8zMSxRWpUBQtwG5a7fFgvEO+odwuTv2gs=
|
||||
github.com/charmbracelet/glamour v0.2.0 h1:mTgaiNiumpqTZp3qVM6DH9UB0NlbY17wejoMf1kM8Pg=
|
||||
github.com/charmbracelet/glamour v0.2.0/go.mod h1:UA27Kwj3QHialP74iU6C+Gpc8Y7IOAKupeKMLLBURWM=
|
||||
github.com/cpuguy83/go-md2man/v2 v2.0.0-20190314233015-f79a8a8ca69d h1:U+s90UTSYgptZMwQh2aRr3LuazLJIa+Pg3Kc1ylSYVY=
|
||||
github.com/cpuguy83/go-md2man/v2 v2.0.0-20190314233015-f79a8a8ca69d/go.mod h1:maD7wRr/U5Z6m/iR4s+kqSMx2CaBsrgA7czyZG/E6dU=
|
||||
github.com/cpuguy83/go-md2man/v2 v2.0.0 h1:EoUDS0afbrsXAZ9YQ9jdu/mZ2sXgT1/2yyNng4PGlyM=
|
||||
github.com/cpuguy83/go-md2man/v2 v2.0.0/go.mod h1:maD7wRr/U5Z6m/iR4s+kqSMx2CaBsrgA7czyZG/E6dU=
|
||||
github.com/creack/pty v1.1.9/go.mod h1:oKZEueFk5CKHvIhNR5MUki03XCEU+Q6VDXinZuGJ33E=
|
||||
github.com/danwakefield/fnmatch v0.0.0-20160403171240-cbb64ac3d964 h1:y5HC9v93H5EPKqaS1UYVg1uYah5Xf51mBfIoWehClUQ=
|
||||
github.com/danwakefield/fnmatch v0.0.0-20160403171240-cbb64ac3d964/go.mod h1:Xd9hchkHSWYkEqJwUGisez3G1QY8Ryz0sdWrLPMGjLk=
|
||||
github.com/davecgh/go-spew v1.1.0/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
|
||||
github.com/davecgh/go-spew v1.1.1 h1:vj9j/u1bqnvCEfJOwUhtlOARqs3+rkHYY13jYWTU97c=
|
||||
github.com/davecgh/go-spew v1.1.1/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
|
||||
github.com/dlclark/regexp2 v1.2.0 h1:8sAhBGEM0dRWogWqWyQeIJnxjWO6oIjl8FKqREDsGfk=
|
||||
github.com/dlclark/regexp2 v1.2.0/go.mod h1:2pZnwuY/m+8K6iRw6wQdMtk+rH5tNGR1i55kozfMjCc=
|
||||
github.com/emirpasic/gods v1.12.0 h1:QAUIPSaCu4G+POclxeqb3F+WPpdKqFGlw36+yOzGlrg=
|
||||
github.com/emirpasic/gods v1.12.0/go.mod h1:YfzfFFoVP/catgzJb4IKIqXjX78Ha8FMSDh3ymbK86o=
|
||||
github.com/flynn/go-shlex v0.0.0-20150515145356-3f9db97f8568 h1:BHsljHzVlRcyQhjrss6TZTdY2VfCqZPbv5k3iBFa2ZQ=
|
||||
@ -35,6 +50,8 @@ github.com/go-git/go-git/v5 v5.1.0 h1:HxJn9g/E7eYvKW3Fm7Jt4ee8LXfPOm/H1cdDu8vEss
|
||||
github.com/go-git/go-git/v5 v5.1.0/go.mod h1:ZKfuPUoY1ZqIG4QG9BDBh3G4gLM5zvPuSJAozQrZuyM=
|
||||
github.com/google/go-cmp v0.3.0 h1:crn/baboCvb5fXaQ0IJ1SGTsTVrWpDsCWC8EGETZijY=
|
||||
github.com/google/go-cmp v0.3.0/go.mod h1:8QqcDgzrUqlUb/G2PQTWiueGozuR1884gddMywk6iLU=
|
||||
github.com/google/goterm v0.0.0-20190703233501-fc88cf888a3f h1:5CjVwnuUcp5adK4gmY6i72gpVFVnZDP2h5TmPScB6u4=
|
||||
github.com/google/goterm v0.0.0-20190703233501-fc88cf888a3f/go.mod h1:nOFQdrUlIlx6M6ODdSpBj1NVA+VgLC6kmw60mkw34H4=
|
||||
github.com/hashicorp/go-version v1.2.0 h1:3vNe/fWF5CBgRIguda1meWhsZHy3m8gCJ5wx+dIzX/E=
|
||||
github.com/hashicorp/go-version v1.2.0/go.mod h1:fltr4n8CU8Ke44wwGCBoEymUuxUHl09ZGVZPK5anwXA=
|
||||
github.com/hashicorp/go-version v1.2.1 h1:zEfKbn2+PDgroKdiOzqiE8rsmLqU2uwi5PB5pBJ3TkI=
|
||||
@ -53,22 +70,38 @@ github.com/kr/text v0.1.0 h1:45sCR5RtlFHMR4UwH9sdQ5TC8v0qDQCHnXt+kaKSTVE=
|
||||
github.com/kr/text v0.1.0/go.mod h1:4Jbv+DJW3UT/LiOwJeYQe1efqtUx/iVham/4vfdArNI=
|
||||
github.com/kr/text v0.2.0 h1:5Nx0Ya0ZqY2ygV366QzturHI13Jq95ApcVaJBhpS+AY=
|
||||
github.com/kr/text v0.2.0/go.mod h1:eLer722TekiGuMkidMxC/pM04lWEeraHUUmBw8l2grE=
|
||||
github.com/lucasb-eyer/go-colorful v1.0.3 h1:QIbQXiugsb+q10B+MI+7DI1oQLdmnep86tWFlaaUAac=
|
||||
github.com/lucasb-eyer/go-colorful v1.0.3/go.mod h1:R4dSotOR9KMtayYi1e77YzuveK+i7ruzyGqttikkLy0=
|
||||
github.com/mattn/go-colorable v0.1.6/go.mod h1:u6P/XSegPjTcexA+o6vUJrdnUu04hMope9wVRipJSqc=
|
||||
github.com/mattn/go-isatty v0.0.12 h1:wuysRhFDzyxgEmMf5xjvJ2M9dZoWAXNNr5LSBS7uHXY=
|
||||
github.com/mattn/go-isatty v0.0.12/go.mod h1:cbi8OIDigv2wuxKPP5vlRcQ1OAZbq2CE4Kysco4FUpU=
|
||||
github.com/mattn/go-runewidth v0.0.7 h1:Ei8KR0497xHyKJPAv59M1dkC+rOZCMBJ+t3fZ+twI54=
|
||||
github.com/mattn/go-runewidth v0.0.7/go.mod h1:H031xJmbD/WCDINGzjvQ9THkh0rPKHF+m2gUSrubnMI=
|
||||
github.com/mattn/go-runewidth v0.0.9 h1:Lm995f3rfxdpd6TSmuVCHVb/QhupuXlYr8sCI/QdE+0=
|
||||
github.com/mattn/go-runewidth v0.0.9/go.mod h1:H031xJmbD/WCDINGzjvQ9THkh0rPKHF+m2gUSrubnMI=
|
||||
github.com/microcosm-cc/bluemonday v1.0.2 h1:5lPfLTTAvAbtS0VqT+94yOtFnGfUWYyx0+iToC3Os3s=
|
||||
github.com/microcosm-cc/bluemonday v1.0.2/go.mod h1:iVP4YcDBq+n/5fb23BhYFvIMq/leAFZyRl6bYmGDlGc=
|
||||
github.com/mitchellh/go-homedir v1.1.0 h1:lukF9ziXFxDFPkA1vsr5zpc1XuPDn/wFntq5mG+4E0Y=
|
||||
github.com/mitchellh/go-homedir v1.1.0/go.mod h1:SfyaCUpYCn1Vlf4IUYiD9fPX4A5wJrkLzIz1N1q0pr0=
|
||||
github.com/muesli/reflow v0.1.0 h1:oQdpLfO56lr5pgLvqD0TcjW85rDjSYSBVdiG1Ch1ddM=
|
||||
github.com/muesli/reflow v0.1.0/go.mod h1:I9bWAt7QTg/que/qmUCJBGlj7wEq8OAFBjPNjc6xK4I=
|
||||
github.com/muesli/termenv v0.6.0 h1:zxvzTBmo4ZcxhNGGWeMz+Tttm51eF5bmPjfy4MCRYlk=
|
||||
github.com/muesli/termenv v0.6.0/go.mod h1:SohX91w6swWA4AYU+QmPx+aSgXhWO0juiyID9UZmbpA=
|
||||
github.com/muesli/termenv v0.7.2 h1:r1raklL3uKE7rOvWgSenmEm2px+dnc33OTisZ8YR1fw=
|
||||
github.com/muesli/termenv v0.7.2/go.mod h1:ct2L5N2lmix82RaY3bMWwVu/jUFc9Ule0KGDCiKYPh8=
|
||||
github.com/niemeyer/pretty v0.0.0-20200227124842-a10e7caefd8e h1:fD57ERR4JtEqsWbfPhv4DMiApHyliiK5xCTNVSPiaAs=
|
||||
github.com/niemeyer/pretty v0.0.0-20200227124842-a10e7caefd8e/go.mod h1:zD1mROLANZcx1PVRCS0qkT7pwLkGfwJo4zjcN/Tysno=
|
||||
github.com/olekukonko/tablewriter v0.0.4 h1:vHD/YYe1Wolo78koG299f7V/VAS08c6IpCLn+Ejf/w8=
|
||||
github.com/olekukonko/tablewriter v0.0.4/go.mod h1:zq6QwlOf5SlnkVbMSr5EoBv3636FWnp+qbPhuoO21uA=
|
||||
github.com/pkg/errors v0.8.1 h1:iURUrRGxPUNPdy5/HRSm+Yj6okJ6UtLINN0Q9M4+h3I=
|
||||
github.com/pkg/errors v0.8.1/go.mod h1:bwawxfHBFNV+L2hUp1rHADufV3IMtnDRdf1r5NINEl0=
|
||||
github.com/pkg/errors v0.9.1 h1:FEBLx1zS214owpjy7qsBeixbURkuhQAwrK5UwLGTwt4=
|
||||
github.com/pkg/errors v0.9.1/go.mod h1:bwawxfHBFNV+L2hUp1rHADufV3IMtnDRdf1r5NINEl0=
|
||||
github.com/pmezard/go-difflib v1.0.0 h1:4DBwDE0NGyQoBHbLQYPwSUPoCMWR5BEzIk/f1lZbAQM=
|
||||
github.com/pmezard/go-difflib v1.0.0/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZNVY4sRDYZ/4=
|
||||
github.com/russross/blackfriday/v2 v2.0.1 h1:lPqVAte+HuHNfhJ/0LC98ESWRz8afy9tM/0RK8m9o+Q=
|
||||
github.com/russross/blackfriday/v2 v2.0.1/go.mod h1:+Rmxgy9KzJVeS9/2gXHxylqXiyQDYRxCVz55jmeOWTM=
|
||||
github.com/sergi/go-diff v1.0.0/go.mod h1:0CfEIISq7TuYL3j771MWULgwwjU+GofnZX9QAmXWZgo=
|
||||
github.com/sergi/go-diff v1.1.0 h1:we8PVUC3FE2uYfodKH/nBHMSetSfHDR6scGdBi+erh0=
|
||||
github.com/sergi/go-diff v1.1.0/go.mod h1:STckp+ISIX8hZLjrqAeVduY0gWCT9IjLuqbuNXdaHfM=
|
||||
github.com/shurcooL/sanitized_anchor_name v1.0.0 h1:PdmoCO6wvbs+7yrJyMORt4/BmY5IYyJwS/kOiWx8mHo=
|
||||
@ -77,6 +110,8 @@ github.com/skratchdot/open-golang v0.0.0-20200116055534-eef842397966 h1:JIAuq3EE
|
||||
github.com/skratchdot/open-golang v0.0.0-20200116055534-eef842397966/go.mod h1:sUM3LWHvSMaG192sy56D9F7CNvL7jUJVXoqM1QKLnog=
|
||||
github.com/stretchr/objx v0.1.0 h1:4G4v2dO3VZwixGIRoQ5Lfboy6nUhCyYzaqnIAPPhYs4=
|
||||
github.com/stretchr/objx v0.1.0/go.mod h1:HFkY916IF+rwdDfMAkV7OtwuqBVzrE8GR6GFx+wExME=
|
||||
github.com/stretchr/testify v1.2.2/go.mod h1:a8OnRcib4nhh0OaRAV+Yts87kKdq0PP7pXfy6kDkUVs=
|
||||
github.com/stretchr/testify v1.3.0/go.mod h1:M5WIy9Dh21IEIfnGCwXGc5bZfKNJtfHm1UVUgZn+9EI=
|
||||
github.com/stretchr/testify v1.4.0 h1:2E4SXV/wtOkTonXsotYi4li6zVWxYlZuYNCXe9XRJyk=
|
||||
github.com/stretchr/testify v1.4.0/go.mod h1:j7eGeouHqKxXV5pUuKE4zz7dFj8WfuZ+81PSLYec5m4=
|
||||
github.com/stretchr/testify v1.5.1 h1:nOGnQDM7FYENwehXlg/kFVnos3rEvtKTjRvOWSzb6H4=
|
||||
@ -87,6 +122,8 @@ github.com/xanzy/ssh-agent v0.2.1 h1:TCbipTQL2JiiCprBWx9frJ2eJlCYT00NmctrHxVAr70
|
||||
github.com/xanzy/ssh-agent v0.2.1/go.mod h1:mLlQY/MoOhWBj+gOGMQkOeiEvkx+8pJSI+0Bx9h2kr4=
|
||||
github.com/yuin/goldmark v1.1.25/go.mod h1:3hX8gzYuyVAZsxl0MRgGTJEmQBFcNTphYh9decYSb74=
|
||||
github.com/yuin/goldmark v1.1.32/go.mod h1:3hX8gzYuyVAZsxl0MRgGTJEmQBFcNTphYh9decYSb74=
|
||||
github.com/yuin/goldmark v1.2.0 h1:WOOcyaJPlzb8fZ8TloxFe8QZkhOOJx87leDa9MIT9dc=
|
||||
github.com/yuin/goldmark v1.2.0/go.mod h1:3hX8gzYuyVAZsxl0MRgGTJEmQBFcNTphYh9decYSb74=
|
||||
golang.org/x/crypto v0.0.0-20190219172222-a4c6cb3142f2/go.mod h1:6SG95UA2DQfeDnfUPMdvaQW0Q7yPrPDi9nlGo2tz2b4=
|
||||
golang.org/x/crypto v0.0.0-20190308221718-c2843e01d9a2/go.mod h1:djNgcEr1/C05ACkg1iLfiJU5Ep61QUkGW8qpdssI0+w=
|
||||
golang.org/x/crypto v0.0.0-20191011191535-87dc89f01550/go.mod h1:yigFU9vqHzYiE8UmvKecakEJjdnWj3jj499lnFckfCI=
|
||||
@ -99,6 +136,7 @@ golang.org/x/mod v0.2.0 h1:KU7oHjnv3XNWfa5COkzUifxZmxp1TyI7ImMXqFxLwvQ=
|
||||
golang.org/x/mod v0.2.0/go.mod h1:s0Qsj1ACt9ePp/hMypM3fl4fZqREWJwdYDEqhRiZZUA=
|
||||
golang.org/x/mod v0.3.0 h1:RM4zey1++hCTbCVQfnWeKs9/IEsaBLA8vTkd0WVtmH4=
|
||||
golang.org/x/mod v0.3.0/go.mod h1:s0Qsj1ACt9ePp/hMypM3fl4fZqREWJwdYDEqhRiZZUA=
|
||||
golang.org/x/net v0.0.0-20181220203305-927f97764cc3/go.mod h1:mL1N/T3taQHkDXs73rZJwtUhF3w3ftmwwsq0BUmARs4=
|
||||
golang.org/x/net v0.0.0-20190404232315-eb5bcb51f2a3/go.mod h1:t9HGtf8HONx5eT2rtn7q6eTqICYqUVnKs3thJo3Qplg=
|
||||
golang.org/x/net v0.0.0-20190620200207-3b0461eec859/go.mod h1:z5CRVTTTmAJ677TzLLGU+0bjPO0LkuOLi4/5GtJWs/s=
|
||||
golang.org/x/net v0.0.0-20200226121028-0de0cce0169b/go.mod h1:z5CRVTTTmAJ677TzLLGU+0bjPO0LkuOLi4/5GtJWs/s=
|
||||
@ -113,9 +151,12 @@ golang.org/x/sync v0.0.0-20200625203802-6e8e738ad208/go.mod h1:RxMgew5VJxzue5/jJ
|
||||
golang.org/x/sys v0.0.0-20190215142949-d0b11bdaac8a/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY=
|
||||
golang.org/x/sys v0.0.0-20190221075227-b4e8571b14e0/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY=
|
||||
golang.org/x/sys v0.0.0-20190412213103-97732733099d/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
|
||||
golang.org/x/sys v0.0.0-20200116001909-b77594299b42/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
|
||||
golang.org/x/sys v0.0.0-20200223170610-d5e6a3e2c0ae/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
|
||||
golang.org/x/sys v0.0.0-20200302150141-5c8b2ff67527 h1:uYVVQ9WP/Ds2ROhcaGPeIdVq0RIXVLwsHlnvJ+cT1So=
|
||||
golang.org/x/sys v0.0.0-20200302150141-5c8b2ff67527/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
|
||||
golang.org/x/sys v0.0.0-20200323222414-85ca7c5b95cd/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
|
||||
golang.org/x/sys v0.0.0-20200413165638-669c56c373c4/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
|
||||
golang.org/x/sys v0.0.0-20200625212154-ddb9806d33ae h1:Ih9Yo4hSPImZOpfGuA4bR/ORKTAbhZo2AbWNRCnevdo=
|
||||
golang.org/x/sys v0.0.0-20200625212154-ddb9806d33ae/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
|
||||
golang.org/x/text v0.3.0/go.mod h1:NqM8EUOU14njkJ3fqMW+pc6Ldnwhi/IjpwHt7yyuwOQ=
|
||||
@ -125,8 +166,8 @@ golang.org/x/tools v0.0.0-20180917221912-90fa682c2a6e/go.mod h1:n7NCudcB/nEzxVGm
|
||||
golang.org/x/tools v0.0.0-20191119224855-298f0cb1881e/go.mod h1:b+2E5dAYhXwXZwtnZ6UAqBI28+e2cm9otk0dWdXHAEo=
|
||||
golang.org/x/tools v0.0.0-20200325010219-a49f79bcc224 h1:azwY/v0y0K4mFHVsg5+UrTgchqALYWpqVo6vL5OmkmI=
|
||||
golang.org/x/tools v0.0.0-20200325010219-a49f79bcc224/go.mod h1:Sl4aGygMT6LrqrWclx+PTx3U+LnKx/seiNR+3G19Ar8=
|
||||
golang.org/x/tools v0.0.0-20200713011307-fd294ab11aed h1:+qzWo37K31KxduIYaBeMqJ8MUOyTayOQKpH9aDPLMSY=
|
||||
golang.org/x/tools v0.0.0-20200713011307-fd294ab11aed/go.mod h1:njjCfa9FT2d7l9Bc6FUM5FLjQPp3cFF28FI3qnDFljA=
|
||||
golang.org/x/tools v0.0.0-20200721032237-77f530d86f9a h1:kVMPw4f6EVqYdfGQTedjrpw1dbE2PEMfw4jwXsNdn9s=
|
||||
golang.org/x/tools v0.0.0-20200721032237-77f530d86f9a/go.mod h1:njjCfa9FT2d7l9Bc6FUM5FLjQPp3cFF28FI3qnDFljA=
|
||||
golang.org/x/xerrors v0.0.0-20190717185122-a985d3407aa7/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0=
|
||||
golang.org/x/xerrors v0.0.0-20191011141410-1b5146add898/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0=
|
||||
golang.org/x/xerrors v0.0.0-20191204190536-9bdfabe68543 h1:E7g+9GITq07hpfrRu66IVDexMakfv52eLZ2CXBWiKr4=
|
||||
|
1
main.go
1
main.go
@ -44,6 +44,7 @@ func main() {
|
||||
&cmd.CmdTrackedTimes,
|
||||
&cmd.CmdOpen,
|
||||
&cmd.CmdNotifications,
|
||||
&cmd.CmdMilestones,
|
||||
}
|
||||
app.EnableBashCompletion = true
|
||||
err := app.Run(os.Args)
|
||||
|
@ -176,6 +176,48 @@ func (r TeaRepo) TeaFindBranchByName(branchName, repoURL string) (b *git_config.
|
||||
return b, b.Validate()
|
||||
}
|
||||
|
||||
// TeaFindBranchRemote gives the first remote that has a branch with the same name or sha,
|
||||
// depending on what is passed in.
|
||||
// This function is needed, as git does not always define branches in .git/config with remote entries.
|
||||
func (r TeaRepo) TeaFindBranchRemote(branchName, hash string) (*git.Remote, error) {
|
||||
remotes, err := r.Remotes()
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
switch {
|
||||
case len(remotes) == 0:
|
||||
return nil, nil
|
||||
case len(remotes) == 1:
|
||||
return remotes[0], nil
|
||||
}
|
||||
|
||||
// check if the given remote has our branch (.git/refs/remotes/<remoteName>/*)
|
||||
iter, err := r.References()
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
defer iter.Close()
|
||||
|
||||
var match *git.Remote
|
||||
err = iter.ForEach(func(ref *git_plumbing.Reference) error {
|
||||
if ref.Name().IsRemote() {
|
||||
names := strings.SplitN(ref.Name().Short(), "/", 2)
|
||||
remote := names[0]
|
||||
branch := names[1]
|
||||
hashMatch := hash != "" && hash == ref.Hash().String()
|
||||
nameMatch := branchName != "" && branchName == branch
|
||||
if hashMatch || nameMatch {
|
||||
match, err = r.Remote(remote)
|
||||
return err
|
||||
}
|
||||
}
|
||||
return nil
|
||||
})
|
||||
|
||||
return match, err
|
||||
}
|
||||
|
||||
// TeaGetCurrentBranchName return the name of the branch witch is currently active
|
||||
func (r TeaRepo) TeaGetCurrentBranchName() (string, error) {
|
||||
localHead, err := r.Head()
|
||||
@ -187,5 +229,5 @@ func (r TeaRepo) TeaGetCurrentBranchName() (string, error) {
|
||||
return "", fmt.Errorf("active ref is no branch")
|
||||
}
|
||||
|
||||
return strings.TrimLeft(localHead.Name().String(), "refs/heads/"), nil
|
||||
return strings.TrimPrefix(localHead.Name().String(), "refs/heads/"), nil
|
||||
}
|
||||
|
23
modules/utils/format.go
Normal file
23
modules/utils/format.go
Normal file
@ -0,0 +1,23 @@
|
||||
// Copyright 2020 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 utils
|
||||
|
||||
import "fmt"
|
||||
|
||||
// FormatSize get kb in int and return string
|
||||
func FormatSize(kb int64) string {
|
||||
if kb < 1024 {
|
||||
return fmt.Sprintf("%d Kb", kb)
|
||||
}
|
||||
mb := kb / 1024
|
||||
if mb < 1024 {
|
||||
return fmt.Sprintf("%d Mb", mb)
|
||||
}
|
||||
gb := mb / 1024
|
||||
if gb < 1024 {
|
||||
return fmt.Sprintf("%d Gb", gb)
|
||||
}
|
||||
return fmt.Sprintf("%d Tb", gb/1024)
|
||||
}
|
21
modules/utils/path.go
Normal file
21
modules/utils/path.go
Normal file
@ -0,0 +1,21 @@
|
||||
// Copyright 2020 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 utils
|
||||
|
||||
import (
|
||||
"os"
|
||||
)
|
||||
|
||||
// PathExists returns whether the given file or directory exists or not
|
||||
func PathExists(path string) (bool, error) {
|
||||
_, err := os.Stat(path)
|
||||
if err == nil {
|
||||
return true, nil
|
||||
}
|
||||
if os.IsNotExist(err) {
|
||||
return false, nil
|
||||
}
|
||||
return true, err
|
||||
}
|
30
vendor/code.gitea.io/gitea-vet/.changelog.yml
generated
vendored
Normal file
30
vendor/code.gitea.io/gitea-vet/.changelog.yml
generated
vendored
Normal file
@ -0,0 +1,30 @@
|
||||
# The full repository name
|
||||
repo: gitea/gitea-vet
|
||||
|
||||
# Service type (gitea or github)
|
||||
service: gitea
|
||||
|
||||
# Base URL for Gitea instance if using gitea service type (optional)
|
||||
base-url: https://gitea.com
|
||||
|
||||
# Changelog groups and which labeled PRs to add to each group
|
||||
groups:
|
||||
-
|
||||
name: BREAKING
|
||||
labels:
|
||||
- breaking
|
||||
-
|
||||
name: FEATURES
|
||||
labels:
|
||||
- feature
|
||||
-
|
||||
name: BUGFIXES
|
||||
labels:
|
||||
- bug
|
||||
-
|
||||
name: ENHANCEMENTS
|
||||
labels:
|
||||
- enhancement
|
||||
|
||||
# regex indicating which labels to skip for the changelog
|
||||
skip-labels: skip-changelog|backport\/.+
|
45
vendor/code.gitea.io/gitea-vet/.drone.yml
generated
vendored
Normal file
45
vendor/code.gitea.io/gitea-vet/.drone.yml
generated
vendored
Normal file
@ -0,0 +1,45 @@
|
||||
---
|
||||
kind: pipeline
|
||||
name: compliance
|
||||
|
||||
platform:
|
||||
os: linux
|
||||
arch: arm64
|
||||
|
||||
trigger:
|
||||
event:
|
||||
- pull_request
|
||||
|
||||
steps:
|
||||
- name: check
|
||||
pull: always
|
||||
image: golang:1.14
|
||||
environment:
|
||||
GOPROXY: https://goproxy.cn
|
||||
commands:
|
||||
- make build
|
||||
- make lint
|
||||
- make vet
|
||||
|
||||
---
|
||||
kind: pipeline
|
||||
name: build-master
|
||||
|
||||
platform:
|
||||
os: linux
|
||||
arch: amd64
|
||||
|
||||
trigger:
|
||||
branch:
|
||||
- master
|
||||
event:
|
||||
- push
|
||||
|
||||
steps:
|
||||
- name: build
|
||||
pull: always
|
||||
image: techknowlogick/xgo:latest
|
||||
environment:
|
||||
GOPROXY: https://goproxy.cn
|
||||
commands:
|
||||
- make build
|
23
vendor/code.gitea.io/gitea-vet/.golangci.yml
generated
vendored
Normal file
23
vendor/code.gitea.io/gitea-vet/.golangci.yml
generated
vendored
Normal file
@ -0,0 +1,23 @@
|
||||
linters:
|
||||
enable:
|
||||
- deadcode
|
||||
- dogsled
|
||||
- dupl
|
||||
- errcheck
|
||||
- gocognit
|
||||
- goconst
|
||||
- gocritic
|
||||
- gocyclo
|
||||
- gofmt
|
||||
- golint
|
||||
- gosimple
|
||||
- govet
|
||||
- maligned
|
||||
- misspell
|
||||
- prealloc
|
||||
- staticcheck
|
||||
- structcheck
|
||||
- typecheck
|
||||
- unparam
|
||||
- unused
|
||||
- varcheck
|
6
vendor/code.gitea.io/gitea-vet/CHANGELOG.md
generated
vendored
Normal file
6
vendor/code.gitea.io/gitea-vet/CHANGELOG.md
generated
vendored
Normal file
@ -0,0 +1,6 @@
|
||||
## [0.2.0](https://gitea.com/gitea/gitea-vet/pulls?q=&type=all&state=closed&milestone=1272) - 2020-07-20
|
||||
|
||||
* FEATURES
|
||||
* Add migrations check (#5)
|
||||
* BUGFIXES
|
||||
* Correct Import Paths (#6)
|
22
vendor/code.gitea.io/gitea-vet/Makefile
generated
vendored
Normal file
22
vendor/code.gitea.io/gitea-vet/Makefile
generated
vendored
Normal file
@ -0,0 +1,22 @@
|
||||
GO ?= go
|
||||
|
||||
.PHONY: build
|
||||
build:
|
||||
$(GO) build
|
||||
|
||||
.PHONY: fmt
|
||||
fmt:
|
||||
$(GO) fmt ./...
|
||||
|
||||
.PHONY: vet
|
||||
vet: build
|
||||
$(GO) vet ./...
|
||||
$(GO) vet -vettool=gitea-vet ./...
|
||||
|
||||
.PHONY: lint
|
||||
lint:
|
||||
@hash golangci-lint > /dev/null 2>&1; if [ $$? -ne 0 ]; then \
|
||||
export BINARY="golangci-lint"; \
|
||||
curl -sfL https://install.goreleaser.com/github.com/golangci/golangci-lint.sh | sh -s -- -b $(shell $(GO) env GOPATH)/bin v1.24.0; \
|
||||
fi
|
||||
golangci-lint run --timeout 5m
|
11
vendor/code.gitea.io/gitea-vet/README.md
generated
vendored
Normal file
11
vendor/code.gitea.io/gitea-vet/README.md
generated
vendored
Normal file
@ -0,0 +1,11 @@
|
||||
# gitea-vet
|
||||
|
||||
[](https://drone.gitea.com/gitea/gitea-vet)
|
||||
|
||||
`go vet` tool for Gitea
|
||||
|
||||
| Analyzer | Description |
|
||||
|------------|-----------------------------------------------------------------------------|
|
||||
| Imports | Checks for import sorting. stdlib->code.gitea.io->other |
|
||||
| License | Checks file headers for some form of `Copyright...YYYY...Gitea/Gogs` |
|
||||
| Migrations | Checks for black-listed packages in `code.gitea.io/gitea/models/migrations` |
|
@ -12,7 +12,7 @@ import (
|
||||
|
||||
var Imports = &analysis.Analyzer{
|
||||
Name: "imports",
|
||||
Doc: "check for import order.",
|
||||
Doc: "check for import order",
|
||||
Run: runImports,
|
||||
}
|
||||
|
||||
@ -22,11 +22,12 @@ func runImports(pass *analysis.Pass) (interface{}, error) {
|
||||
for _, im := range file.Imports {
|
||||
var lvl int
|
||||
val := im.Path.Value
|
||||
if importHasPrefix(val, "code.gitea.io") {
|
||||
switch {
|
||||
case importHasPrefix(val, "code.gitea.io"):
|
||||
lvl = 2
|
||||
} else if strings.Contains(val, ".") {
|
||||
case strings.Contains(val, "."):
|
||||
lvl = 3
|
||||
} else {
|
||||
default:
|
||||
lvl = 1
|
||||
}
|
||||
|
||||
@ -43,12 +44,3 @@ func runImports(pass *analysis.Pass) (interface{}, error) {
|
||||
func importHasPrefix(s, p string) bool {
|
||||
return strings.HasPrefix(s, "\""+p)
|
||||
}
|
||||
|
||||
func sliceHasPrefix(s string, prefixes ...string) bool {
|
||||
for _, p := range prefixes {
|
||||
if importHasPrefix(s, p) {
|
||||
return true
|
||||
}
|
||||
}
|
||||
return false
|
||||
}
|
@ -19,7 +19,7 @@ var (
|
||||
|
||||
var License = &analysis.Analyzer{
|
||||
Name: "license",
|
||||
Doc: "check for a copyright header.",
|
||||
Doc: "check for a copyright header",
|
||||
Run: runLicense,
|
||||
}
|
||||
|
59
vendor/code.gitea.io/gitea-vet/checks/migrations.go
generated
vendored
Normal file
59
vendor/code.gitea.io/gitea-vet/checks/migrations.go
generated
vendored
Normal file
@ -0,0 +1,59 @@
|
||||
// Copyright 2020 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 checks
|
||||
|
||||
import (
|
||||
"errors"
|
||||
"os/exec"
|
||||
"strings"
|
||||
|
||||
"golang.org/x/tools/go/analysis"
|
||||
)
|
||||
|
||||
var Migrations = &analysis.Analyzer{
|
||||
Name: "migrations",
|
||||
Doc: "check migrations for black-listed packages.",
|
||||
Run: checkMigrations,
|
||||
}
|
||||
|
||||
var migrationBlacklist = []string{
|
||||
"code.gitea.io/gitea/models",
|
||||
"code.gitea.io/gitea/modules/structs",
|
||||
}
|
||||
|
||||
func checkMigrations(pass *analysis.Pass) (interface{}, error) {
|
||||
if !strings.EqualFold(pass.Pkg.Path(), "code.gitea.io/gitea/models/migrations") {
|
||||
return nil, nil
|
||||
}
|
||||
|
||||
if _, err := exec.LookPath("go"); err != nil {
|
||||
return nil, errors.New("go was not found in the PATH")
|
||||
}
|
||||
|
||||
depsCmd := exec.Command("go", "list", "-f", `{{join .Deps "\n"}}`, "code.gitea.io/gitea/models/migrations")
|
||||
depsOut, err := depsCmd.Output()
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
deps := strings.Split(string(depsOut), "\n")
|
||||
for _, dep := range deps {
|
||||
if stringInSlice(dep, migrationBlacklist) {
|
||||
pass.Reportf(0, "code.gitea.io/gitea/models/migrations cannot depend on the following packages: %s", migrationBlacklist)
|
||||
return nil, nil
|
||||
}
|
||||
}
|
||||
|
||||
return nil, nil
|
||||
}
|
||||
|
||||
func stringInSlice(needle string, haystack []string) bool {
|
||||
for _, h := range haystack {
|
||||
if strings.EqualFold(needle, h) {
|
||||
return true
|
||||
}
|
||||
}
|
||||
return false
|
||||
}
|
2
vendor/gitea.com/jolheiser/gitea-vet/go.mod → vendor/code.gitea.io/gitea-vet/go.mod
generated
vendored
2
vendor/gitea.com/jolheiser/gitea-vet/go.mod → vendor/code.gitea.io/gitea-vet/go.mod
generated
vendored
@ -1,4 +1,4 @@
|
||||
module gitea.com/jolheiser/gitea-vet
|
||||
module code.gitea.io/gitea-vet
|
||||
|
||||
go 1.14
|
||||
|
0
vendor/gitea.com/jolheiser/gitea-vet/go.sum → vendor/code.gitea.io/gitea-vet/go.sum
generated
vendored
0
vendor/gitea.com/jolheiser/gitea-vet/go.sum → vendor/code.gitea.io/gitea-vet/go.sum
generated
vendored
@ -5,7 +5,8 @@
|
||||
package main
|
||||
|
||||
import (
|
||||
"gitea.com/jolheiser/gitea-vet/checks"
|
||||
"code.gitea.io/gitea-vet/checks"
|
||||
|
||||
"golang.org/x/tools/go/analysis/unitchecker"
|
||||
)
|
||||
|
||||
@ -13,5 +14,6 @@ func main() {
|
||||
unitchecker.Main(
|
||||
checks.Imports,
|
||||
checks.License,
|
||||
checks.Migrations,
|
||||
)
|
||||
}
|
44
vendor/code.gitea.io/sdk/gitea/admin_cron.go
generated
vendored
Normal file
44
vendor/code.gitea.io/sdk/gitea/admin_cron.go
generated
vendored
Normal file
@ -0,0 +1,44 @@
|
||||
// Copyright 2020 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"
|
||||
"time"
|
||||
)
|
||||
|
||||
// CronTask represents a Cron task
|
||||
type CronTask struct {
|
||||
Name string `json:"name"`
|
||||
Schedule string `json:"schedule"`
|
||||
Next time.Time `json:"next"`
|
||||
Prev time.Time `json:"prev"`
|
||||
ExecTimes int64 `json:"exec_times"`
|
||||
}
|
||||
|
||||
// ListCronTaskOptions list options for ListCronTasks
|
||||
type ListCronTaskOptions struct {
|
||||
ListOptions
|
||||
}
|
||||
|
||||
// ListCronTasks list available cron tasks
|
||||
func (c *Client) ListCronTasks(opt ListCronTaskOptions) ([]*CronTask, *Response, error) {
|
||||
if err := c.CheckServerVersionConstraint(">=1.13.0"); err != nil {
|
||||
return nil, nil, err
|
||||
}
|
||||
opt.setDefaults()
|
||||
ct := make([]*CronTask, 0, opt.PageSize)
|
||||
resp, err := c.getParsedResponse("GET", fmt.Sprintf("/admin/cron?%s", opt.getURLQuery().Encode()), jsonHeader, nil, &ct)
|
||||
return ct, resp, err
|
||||
}
|
||||
|
||||
// RunCronTasks run a cron task
|
||||
func (c *Client) RunCronTasks(task string) (*Response, error) {
|
||||
if err := c.CheckServerVersionConstraint(">=1.13.0"); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
_, resp, err := c.getResponse("POST", fmt.Sprintf("/admin/cron/%s", task), jsonHeader, nil)
|
||||
return resp, err
|
||||
}
|
13
vendor/code.gitea.io/sdk/gitea/admin_org.go
generated
vendored
13
vendor/code.gitea.io/sdk/gitea/admin_org.go
generated
vendored
@ -17,19 +17,20 @@ type AdminListOrgsOptions struct {
|
||||
}
|
||||
|
||||
// AdminListOrgs lists all orgs
|
||||
func (c *Client) AdminListOrgs(opt AdminListOrgsOptions) ([]*Organization, error) {
|
||||
func (c *Client) AdminListOrgs(opt AdminListOrgsOptions) ([]*Organization, *Response, error) {
|
||||
opt.setDefaults()
|
||||
orgs := make([]*Organization, 0, opt.PageSize)
|
||||
return orgs, c.getParsedResponse("GET", fmt.Sprintf("/admin/orgs?%s", opt.getURLQuery().Encode()), nil, nil, &orgs)
|
||||
resp, err := c.getParsedResponse("GET", fmt.Sprintf("/admin/orgs?%s", opt.getURLQuery().Encode()), nil, nil, &orgs)
|
||||
return orgs, resp, err
|
||||
}
|
||||
|
||||
// AdminCreateOrg create an organization
|
||||
func (c *Client) AdminCreateOrg(user string, opt CreateOrgOption) (*Organization, error) {
|
||||
func (c *Client) AdminCreateOrg(user string, opt CreateOrgOption) (*Organization, *Response, error) {
|
||||
body, err := json.Marshal(&opt)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
return nil, nil, err
|
||||
}
|
||||
org := new(Organization)
|
||||
return org, c.getParsedResponse("POST", fmt.Sprintf("/admin/users/%s/orgs", user),
|
||||
jsonHeader, bytes.NewReader(body), org)
|
||||
resp, err := c.getParsedResponse("POST", fmt.Sprintf("/admin/users/%s/orgs", user), jsonHeader, bytes.NewReader(body), org)
|
||||
return org, resp, err
|
||||
}
|
||||
|
8
vendor/code.gitea.io/sdk/gitea/admin_repo.go
generated
vendored
8
vendor/code.gitea.io/sdk/gitea/admin_repo.go
generated
vendored
@ -11,12 +11,12 @@ import (
|
||||
)
|
||||
|
||||
// AdminCreateRepo create a repo
|
||||
func (c *Client) AdminCreateRepo(user string, opt CreateRepoOption) (*Repository, error) {
|
||||
func (c *Client) AdminCreateRepo(user string, opt CreateRepoOption) (*Repository, *Response, error) {
|
||||
body, err := json.Marshal(&opt)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
return nil, nil, err
|
||||
}
|
||||
repo := new(Repository)
|
||||
return repo, c.getParsedResponse("POST", fmt.Sprintf("/admin/users/%s/repos", user),
|
||||
jsonHeader, bytes.NewReader(body), repo)
|
||||
resp, err := c.getParsedResponse("POST", fmt.Sprintf("/admin/users/%s/repos", user), jsonHeader, bytes.NewReader(body), repo)
|
||||
return repo, resp, err
|
||||
}
|
||||
|
69
vendor/code.gitea.io/sdk/gitea/admin_user.go
generated
vendored
69
vendor/code.gitea.io/sdk/gitea/admin_user.go
generated
vendored
@ -17,10 +17,11 @@ type AdminListUsersOptions struct {
|
||||
}
|
||||
|
||||
// AdminListUsers lists all users
|
||||
func (c *Client) AdminListUsers(opt AdminListUsersOptions) ([]*User, error) {
|
||||
func (c *Client) AdminListUsers(opt AdminListUsersOptions) ([]*User, *Response, error) {
|
||||
opt.setDefaults()
|
||||
users := make([]*User, 0, opt.PageSize)
|
||||
return users, c.getParsedResponse("GET", fmt.Sprintf("/admin/users?%s", opt.getURLQuery().Encode()), nil, nil, &users)
|
||||
resp, err := c.getParsedResponse("GET", fmt.Sprintf("/admin/users?%s", opt.getURLQuery().Encode()), nil, nil, &users)
|
||||
return users, resp, err
|
||||
}
|
||||
|
||||
// CreateUserOption create user options
|
||||
@ -35,14 +36,29 @@ type CreateUserOption struct {
|
||||
SendNotify bool `json:"send_notify"`
|
||||
}
|
||||
|
||||
// Validate the CreateUserOption struct
|
||||
func (opt CreateUserOption) Validate() error {
|
||||
if len(opt.Email) == 0 {
|
||||
return fmt.Errorf("email is empty")
|
||||
}
|
||||
if len(opt.Username) == 0 {
|
||||
return fmt.Errorf("username is empty")
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
// AdminCreateUser create a user
|
||||
func (c *Client) AdminCreateUser(opt CreateUserOption) (*User, error) {
|
||||
func (c *Client) AdminCreateUser(opt CreateUserOption) (*User, *Response, error) {
|
||||
if err := opt.Validate(); err != nil {
|
||||
return nil, nil, err
|
||||
}
|
||||
body, err := json.Marshal(&opt)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
return nil, nil, err
|
||||
}
|
||||
user := new(User)
|
||||
return user, c.getParsedResponse("POST", "/admin/users", jsonHeader, bytes.NewReader(body), user)
|
||||
resp, err := c.getParsedResponse("POST", "/admin/users", jsonHeader, bytes.NewReader(body), user)
|
||||
return user, resp, err
|
||||
}
|
||||
|
||||
// EditUserOption edit user options
|
||||
@ -65,33 +81,34 @@ type EditUserOption struct {
|
||||
}
|
||||
|
||||
// AdminEditUser modify user informations
|
||||
func (c *Client) AdminEditUser(user string, opt EditUserOption) error {
|
||||
body, err := json.Marshal(&opt)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
_, err = c.getResponse("PATCH", fmt.Sprintf("/admin/users/%s", user), jsonHeader, bytes.NewReader(body))
|
||||
return err
|
||||
}
|
||||
|
||||
// AdminDeleteUser delete one user according name
|
||||
func (c *Client) AdminDeleteUser(user string) error {
|
||||
_, err := c.getResponse("DELETE", fmt.Sprintf("/admin/users/%s", user), nil, nil)
|
||||
return err
|
||||
}
|
||||
|
||||
// AdminCreateUserPublicKey adds a public key for the user
|
||||
func (c *Client) AdminCreateUserPublicKey(user string, opt CreateKeyOption) (*PublicKey, error) {
|
||||
func (c *Client) AdminEditUser(user string, opt EditUserOption) (*Response, error) {
|
||||
body, err := json.Marshal(&opt)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
_, resp, err := c.getResponse("PATCH", fmt.Sprintf("/admin/users/%s", user), jsonHeader, bytes.NewReader(body))
|
||||
return resp, err
|
||||
}
|
||||
|
||||
// AdminDeleteUser delete one user according name
|
||||
func (c *Client) AdminDeleteUser(user string) (*Response, error) {
|
||||
_, resp, err := c.getResponse("DELETE", fmt.Sprintf("/admin/users/%s", user), nil, nil)
|
||||
return resp, err
|
||||
}
|
||||
|
||||
// AdminCreateUserPublicKey adds a public key for the user
|
||||
func (c *Client) AdminCreateUserPublicKey(user string, opt CreateKeyOption) (*PublicKey, *Response, error) {
|
||||
body, err := json.Marshal(&opt)
|
||||
if err != nil {
|
||||
return nil, nil, err
|
||||
}
|
||||
key := new(PublicKey)
|
||||
return key, c.getParsedResponse("POST", fmt.Sprintf("/admin/users/%s/keys", user), jsonHeader, bytes.NewReader(body), key)
|
||||
resp, err := c.getParsedResponse("POST", fmt.Sprintf("/admin/users/%s/keys", user), jsonHeader, bytes.NewReader(body), key)
|
||||
return key, resp, err
|
||||
}
|
||||
|
||||
// AdminDeleteUserPublicKey deletes a user's public key
|
||||
func (c *Client) AdminDeleteUserPublicKey(user string, keyID int) error {
|
||||
_, err := c.getResponse("DELETE", fmt.Sprintf("/admin/users/%s/keys/%d", user, keyID), nil, nil)
|
||||
return err
|
||||
func (c *Client) AdminDeleteUserPublicKey(user string, keyID int) (*Response, error) {
|
||||
_, resp, err := c.getResponse("DELETE", fmt.Sprintf("/admin/users/%s/keys/%d", user, keyID), nil, nil)
|
||||
return resp, err
|
||||
}
|
||||
|
37
vendor/code.gitea.io/sdk/gitea/attachment.go
generated
vendored
37
vendor/code.gitea.io/sdk/gitea/attachment.go
generated
vendored
@ -30,47 +30,47 @@ type ListReleaseAttachmentsOptions struct {
|
||||
}
|
||||
|
||||
// ListReleaseAttachments list release's attachments
|
||||
func (c *Client) ListReleaseAttachments(user, repo string, release int64, opt ListReleaseAttachmentsOptions) ([]*Attachment, error) {
|
||||
func (c *Client) ListReleaseAttachments(user, repo string, release int64, opt ListReleaseAttachmentsOptions) ([]*Attachment, *Response, error) {
|
||||
opt.setDefaults()
|
||||
attachments := make([]*Attachment, 0, opt.PageSize)
|
||||
err := c.getParsedResponse("GET",
|
||||
resp, err := c.getParsedResponse("GET",
|
||||
fmt.Sprintf("/repos/%s/%s/releases/%d/assets?%s", user, repo, release, opt.getURLQuery().Encode()),
|
||||
nil, nil, &attachments)
|
||||
return attachments, err
|
||||
return attachments, resp, err
|
||||
}
|
||||
|
||||
// GetReleaseAttachment returns the requested attachment
|
||||
func (c *Client) GetReleaseAttachment(user, repo string, release int64, id int64) (*Attachment, error) {
|
||||
func (c *Client) GetReleaseAttachment(user, repo string, release int64, id int64) (*Attachment, *Response, error) {
|
||||
a := new(Attachment)
|
||||
err := c.getParsedResponse("GET",
|
||||
resp, err := c.getParsedResponse("GET",
|
||||
fmt.Sprintf("/repos/%s/%s/releases/%d/assets/%d", user, repo, release, id),
|
||||
nil, nil, &a)
|
||||
return a, err
|
||||
return a, resp, 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) {
|
||||
func (c *Client) CreateReleaseAttachment(user, repo string, release int64, file io.Reader, filename string) (*Attachment, *Response, 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
|
||||
return nil, nil, err
|
||||
}
|
||||
|
||||
if _, err = io.Copy(part, file); err != nil {
|
||||
return nil, err
|
||||
return nil, nil, err
|
||||
}
|
||||
if err = writer.Close(); err != nil {
|
||||
return nil, err
|
||||
return nil, nil, err
|
||||
}
|
||||
|
||||
// Send request
|
||||
attachment := new(Attachment)
|
||||
err = c.getParsedResponse("POST",
|
||||
resp, 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
|
||||
return attachment, resp, err
|
||||
}
|
||||
|
||||
// EditAttachmentOptions options for editing attachments
|
||||
@ -79,17 +79,18 @@ type EditAttachmentOptions struct {
|
||||
}
|
||||
|
||||
// EditReleaseAttachment updates the given attachment with the given options
|
||||
func (c *Client) EditReleaseAttachment(user, repo string, release int64, attachment int64, form EditAttachmentOptions) (*Attachment, error) {
|
||||
func (c *Client) EditReleaseAttachment(user, repo string, release int64, attachment int64, form EditAttachmentOptions) (*Attachment, *Response, error) {
|
||||
body, err := json.Marshal(&form)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
return nil, 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)
|
||||
resp, err := c.getParsedResponse("PATCH", fmt.Sprintf("/repos/%s/%s/releases/%d/assets/%d", user, repo, release, attachment), jsonHeader, bytes.NewReader(body), attach)
|
||||
return attach, resp, err
|
||||
}
|
||||
|
||||
// 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
|
||||
func (c *Client) DeleteReleaseAttachment(user, repo string, release int64, id int64) (*Response, error) {
|
||||
_, resp, err := c.getResponse("DELETE", fmt.Sprintf("/repos/%s/%s/releases/%d/assets/%d", user, repo, release, id), nil, nil)
|
||||
return resp, err
|
||||
}
|
||||
|
144
vendor/code.gitea.io/sdk/gitea/client.go
generated
vendored
144
vendor/code.gitea.io/sdk/gitea/client.go
generated
vendored
@ -6,6 +6,7 @@
|
||||
package gitea
|
||||
|
||||
import (
|
||||
"context"
|
||||
"encoding/json"
|
||||
"errors"
|
||||
"fmt"
|
||||
@ -22,7 +23,7 @@ var jsonHeader = http.Header{"content-type": []string{"application/json"}}
|
||||
|
||||
// Version return the library version
|
||||
func Version() string {
|
||||
return "0.12.0"
|
||||
return "0.13.0"
|
||||
}
|
||||
|
||||
// Client represents a Gitea API client.
|
||||
@ -34,48 +35,123 @@ type Client struct {
|
||||
otp string
|
||||
sudo string
|
||||
client *http.Client
|
||||
ctx context.Context
|
||||
serverVersion *version.Version
|
||||
versionLock sync.RWMutex
|
||||
}
|
||||
|
||||
// NewClient initializes and returns a API client.
|
||||
func NewClient(url, token string) *Client {
|
||||
return &Client{
|
||||
url: strings.TrimSuffix(url, "/"),
|
||||
accessToken: token,
|
||||
client: &http.Client{},
|
||||
// Response represents the gitea response
|
||||
type Response struct {
|
||||
*http.Response
|
||||
}
|
||||
|
||||
// NewClient initializes and returns a API client.
|
||||
func NewClient(url string, options ...func(*Client)) (*Client, error) {
|
||||
client := &Client{
|
||||
url: strings.TrimSuffix(url, "/"),
|
||||
client: &http.Client{},
|
||||
ctx: context.Background(),
|
||||
}
|
||||
for _, opt := range options {
|
||||
opt(client)
|
||||
}
|
||||
if err := client.CheckServerVersionConstraint(">=1.10"); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
return client, nil
|
||||
}
|
||||
|
||||
// NewClientWithHTTP creates an API client with a custom http client
|
||||
// Deprecated use SetHTTPClient option
|
||||
func NewClientWithHTTP(url string, httpClient *http.Client) *Client {
|
||||
client := NewClient(url, "")
|
||||
client.client = httpClient
|
||||
client, _ := NewClient(url, SetHTTPClient(httpClient))
|
||||
return client
|
||||
}
|
||||
|
||||
// SetBasicAuth sets basicauth
|
||||
// SetHTTPClient is an option for NewClient to set custom http client
|
||||
func SetHTTPClient(httpClient *http.Client) func(client *Client) {
|
||||
return func(client *Client) {
|
||||
client.client = httpClient
|
||||
}
|
||||
}
|
||||
|
||||
// SetToken is an option for NewClient to set token
|
||||
func SetToken(token string) func(client *Client) {
|
||||
return func(client *Client) {
|
||||
client.accessToken = token
|
||||
}
|
||||
}
|
||||
|
||||
// SetBasicAuth is an option for NewClient to set username and password
|
||||
func SetBasicAuth(username, password string) func(client *Client) {
|
||||
return func(client *Client) {
|
||||
client.SetBasicAuth(username, password)
|
||||
}
|
||||
}
|
||||
|
||||
// SetBasicAuth sets username and password
|
||||
func (c *Client) SetBasicAuth(username, password string) {
|
||||
c.username, c.password = username, password
|
||||
}
|
||||
|
||||
// SetOTP is an option for NewClient to set OTP for 2FA
|
||||
func SetOTP(otp string) func(client *Client) {
|
||||
return func(client *Client) {
|
||||
client.SetOTP(otp)
|
||||
}
|
||||
}
|
||||
|
||||
// SetOTP sets OTP for 2FA
|
||||
func (c *Client) SetOTP(otp string) {
|
||||
c.otp = otp
|
||||
}
|
||||
|
||||
// SetContext is an option for NewClient to set context
|
||||
func SetContext(ctx context.Context) func(client *Client) {
|
||||
return func(client *Client) {
|
||||
client.SetContext(ctx)
|
||||
}
|
||||
}
|
||||
|
||||
// SetContext set context witch is used for http requests
|
||||
func (c *Client) SetContext(ctx context.Context) {
|
||||
c.ctx = ctx
|
||||
}
|
||||
|
||||
// SetHTTPClient replaces default http.Client with user given one.
|
||||
func (c *Client) SetHTTPClient(client *http.Client) {
|
||||
c.client = client
|
||||
}
|
||||
|
||||
// SetSudo is an option for NewClient to set sudo header
|
||||
func SetSudo(sudo string) func(client *Client) {
|
||||
return func(client *Client) {
|
||||
client.SetSudo(sudo)
|
||||
}
|
||||
}
|
||||
|
||||
// SetSudo sets username to impersonate.
|
||||
func (c *Client) SetSudo(sudo string) {
|
||||
c.sudo = sudo
|
||||
}
|
||||
|
||||
func (c *Client) doRequest(method, path string, header http.Header, body io.Reader) (*http.Response, error) {
|
||||
req, err := http.NewRequest(method, c.url+"/api/v1"+path, body)
|
||||
func (c *Client) getWebResponse(method, path string, body io.Reader) ([]byte, *Response, error) {
|
||||
req, err := http.NewRequestWithContext(c.ctx, method, c.url+path, body)
|
||||
if err != nil {
|
||||
return nil, nil, err
|
||||
}
|
||||
resp, err := c.client.Do(req)
|
||||
if err != nil {
|
||||
return nil, nil, err
|
||||
}
|
||||
|
||||
defer resp.Body.Close()
|
||||
data, err := ioutil.ReadAll(resp.Body)
|
||||
return data, &Response{resp}, nil
|
||||
}
|
||||
|
||||
func (c *Client) doRequest(method, path string, header http.Header, body io.Reader) (*Response, error) {
|
||||
req, err := http.NewRequestWithContext(c.ctx, method, c.url+"/api/v1"+path, body)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
@ -95,30 +171,34 @@ func (c *Client) doRequest(method, path string, header http.Header, body io.Read
|
||||
req.Header[k] = v
|
||||
}
|
||||
|
||||
return c.client.Do(req)
|
||||
}
|
||||
|
||||
func (c *Client) getResponse(method, path string, header http.Header, body io.Reader) ([]byte, error) {
|
||||
resp, err := c.doRequest(method, path, header, body)
|
||||
resp, err := c.client.Do(req)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
return &Response{resp}, nil
|
||||
}
|
||||
|
||||
func (c *Client) getResponse(method, path string, header http.Header, body io.Reader) ([]byte, *Response, error) {
|
||||
resp, err := c.doRequest(method, path, header, body)
|
||||
if err != nil {
|
||||
return nil, nil, err
|
||||
}
|
||||
defer resp.Body.Close()
|
||||
|
||||
data, err := ioutil.ReadAll(resp.Body)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
return nil, resp, err
|
||||
}
|
||||
|
||||
switch resp.StatusCode {
|
||||
case 403:
|
||||
return nil, errors.New("403 Forbidden")
|
||||
return data, resp, errors.New("403 Forbidden")
|
||||
case 404:
|
||||
return nil, errors.New("404 Not Found")
|
||||
return data, resp, errors.New("404 Not Found")
|
||||
case 409:
|
||||
return nil, errors.New("409 Conflict")
|
||||
return data, resp, errors.New("409 Conflict")
|
||||
case 422:
|
||||
return nil, fmt.Errorf("422 Unprocessable Entity: %s", string(data))
|
||||
return data, resp, fmt.Errorf("422 Unprocessable Entity: %s", string(data))
|
||||
}
|
||||
|
||||
if resp.StatusCode/100 != 2 {
|
||||
@ -126,28 +206,28 @@ func (c *Client) getResponse(method, path string, header http.Header, body io.Re
|
||||
if err = json.Unmarshal(data, &errMap); err != nil {
|
||||
// when the JSON can't be parsed, data was probably empty or a plain string,
|
||||
// so we try to return a helpful error anyway
|
||||
return nil, fmt.Errorf("Unknown API Error: %d\nRequest: '%s' with '%s' method '%s' header and '%s' body", resp.StatusCode, path, method, header, string(data))
|
||||
return data, resp, fmt.Errorf("Unknown API Error: %d\nRequest: '%s' with '%s' method '%s' header and '%s' body", resp.StatusCode, path, method, header, string(data))
|
||||
}
|
||||
return nil, errors.New(errMap["message"].(string))
|
||||
return data, resp, errors.New(errMap["message"].(string))
|
||||
}
|
||||
|
||||
return data, nil
|
||||
return data, resp, nil
|
||||
}
|
||||
|
||||
func (c *Client) getParsedResponse(method, path string, header http.Header, body io.Reader, obj interface{}) error {
|
||||
data, err := c.getResponse(method, path, header, body)
|
||||
func (c *Client) getParsedResponse(method, path string, header http.Header, body io.Reader, obj interface{}) (*Response, error) {
|
||||
data, resp, err := c.getResponse(method, path, header, body)
|
||||
if err != nil {
|
||||
return err
|
||||
return nil, err
|
||||
}
|
||||
return json.Unmarshal(data, obj)
|
||||
return resp, json.Unmarshal(data, obj)
|
||||
}
|
||||
|
||||
func (c *Client) getStatusCode(method, path string, header http.Header, body io.Reader) (int, error) {
|
||||
func (c *Client) getStatusCode(method, path string, header http.Header, body io.Reader) (int, *Response, error) {
|
||||
resp, err := c.doRequest(method, path, header, body)
|
||||
if err != nil {
|
||||
return -1, err
|
||||
return -1, resp, err
|
||||
}
|
||||
defer resp.Body.Close()
|
||||
|
||||
return resp.StatusCode, nil
|
||||
return resp.StatusCode, resp, nil
|
||||
}
|
||||
|
12
vendor/code.gitea.io/sdk/gitea/fork.go
generated
vendored
12
vendor/code.gitea.io/sdk/gitea/fork.go
generated
vendored
@ -16,12 +16,13 @@ type ListForksOptions struct {
|
||||
}
|
||||
|
||||
// ListForks list a repository's forks
|
||||
func (c *Client) ListForks(user string, repo string, opt ListForksOptions) ([]*Repository, error) {
|
||||
func (c *Client) ListForks(user string, repo string, opt ListForksOptions) ([]*Repository, *Response, error) {
|
||||
opt.setDefaults()
|
||||
forks := make([]*Repository, opt.PageSize)
|
||||
return forks, c.getParsedResponse("GET",
|
||||
resp, err := c.getParsedResponse("GET",
|
||||
fmt.Sprintf("/repos/%s/%s/forks?%s", user, repo, opt.getURLQuery().Encode()),
|
||||
nil, nil, &forks)
|
||||
return forks, resp, err
|
||||
}
|
||||
|
||||
// CreateForkOption options for creating a fork
|
||||
@ -31,11 +32,12 @@ type CreateForkOption struct {
|
||||
}
|
||||
|
||||
// CreateFork create a fork of a repository
|
||||
func (c *Client) CreateFork(user, repo string, form CreateForkOption) (*Repository, error) {
|
||||
func (c *Client) CreateFork(user, repo string, form CreateForkOption) (*Repository, *Response, error) {
|
||||
body, err := json.Marshal(form)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
return nil, nil, err
|
||||
}
|
||||
fork := new(Repository)
|
||||
return fork, c.getParsedResponse("POST", fmt.Sprintf("/repos/%s/%s/forks", user, repo), jsonHeader, bytes.NewReader(body), &fork)
|
||||
resp, err := c.getParsedResponse("POST", fmt.Sprintf("/repos/%s/%s/forks", user, repo), jsonHeader, bytes.NewReader(body), &fork)
|
||||
return fork, resp, err
|
||||
}
|
||||
|
5
vendor/code.gitea.io/sdk/gitea/git_blob.go
generated
vendored
5
vendor/code.gitea.io/sdk/gitea/git_blob.go
generated
vendored
@ -18,7 +18,8 @@ type GitBlobResponse struct {
|
||||
}
|
||||
|
||||
// GetBlob get the blob of a repository file
|
||||
func (c *Client) GetBlob(user, repo, sha string) (*GitBlobResponse, error) {
|
||||
func (c *Client) GetBlob(user, repo, sha string) (*GitBlobResponse, *Response, error) {
|
||||
blob := new(GitBlobResponse)
|
||||
return blob, c.getParsedResponse("GET", fmt.Sprintf("/repos/%s/%s/git/blobs/%s", user, repo, sha), nil, nil, blob)
|
||||
resp, err := c.getParsedResponse("GET", fmt.Sprintf("/repos/%s/%s/git/blobs/%s", user, repo, sha), nil, nil, blob)
|
||||
return blob, resp, err
|
||||
}
|
||||
|
24
vendor/code.gitea.io/sdk/gitea/git_hook.go
generated
vendored
24
vendor/code.gitea.io/sdk/gitea/git_hook.go
generated
vendored
@ -23,16 +23,18 @@ type ListRepoGitHooksOptions struct {
|
||||
}
|
||||
|
||||
// ListRepoGitHooks list all the Git hooks of one repository
|
||||
func (c *Client) ListRepoGitHooks(user, repo string, opt ListRepoGitHooksOptions) ([]*GitHook, error) {
|
||||
func (c *Client) ListRepoGitHooks(user, repo string, opt ListRepoGitHooksOptions) ([]*GitHook, *Response, error) {
|
||||
opt.setDefaults()
|
||||
hooks := make([]*GitHook, 0, opt.PageSize)
|
||||
return hooks, c.getParsedResponse("GET", fmt.Sprintf("/repos/%s/%s/hooks/git?%s", user, repo, opt.getURLQuery().Encode()), nil, nil, &hooks)
|
||||
resp, err := c.getParsedResponse("GET", fmt.Sprintf("/repos/%s/%s/hooks/git?%s", user, repo, opt.getURLQuery().Encode()), nil, nil, &hooks)
|
||||
return hooks, resp, err
|
||||
}
|
||||
|
||||
// GetRepoGitHook get a Git hook of a repository
|
||||
func (c *Client) GetRepoGitHook(user, repo, id string) (*GitHook, error) {
|
||||
func (c *Client) GetRepoGitHook(user, repo, id string) (*GitHook, *Response, error) {
|
||||
h := new(GitHook)
|
||||
return h, c.getParsedResponse("GET", fmt.Sprintf("/repos/%s/%s/hooks/git/%s", user, repo, id), nil, nil, h)
|
||||
resp, err := c.getParsedResponse("GET", fmt.Sprintf("/repos/%s/%s/hooks/git/%s", user, repo, id), nil, nil, h)
|
||||
return h, resp, err
|
||||
}
|
||||
|
||||
// EditGitHookOption options when modifying one Git hook
|
||||
@ -41,17 +43,17 @@ type EditGitHookOption struct {
|
||||
}
|
||||
|
||||
// EditRepoGitHook modify one Git hook of a repository
|
||||
func (c *Client) EditRepoGitHook(user, repo, id string, opt EditGitHookOption) error {
|
||||
func (c *Client) EditRepoGitHook(user, repo, id string, opt EditGitHookOption) (*Response, error) {
|
||||
body, err := json.Marshal(&opt)
|
||||
if err != nil {
|
||||
return err
|
||||
return nil, err
|
||||
}
|
||||
_, err = c.getResponse("PATCH", fmt.Sprintf("/repos/%s/%s/hooks/git/%s", user, repo, id), jsonHeader, bytes.NewReader(body))
|
||||
return err
|
||||
_, resp, err := c.getResponse("PATCH", fmt.Sprintf("/repos/%s/%s/hooks/git/%s", user, repo, id), jsonHeader, bytes.NewReader(body))
|
||||
return resp, err
|
||||
}
|
||||
|
||||
// DeleteRepoGitHook delete one Git hook from a repository
|
||||
func (c *Client) DeleteRepoGitHook(user, repo, id string) error {
|
||||
_, err := c.getResponse("DELETE", fmt.Sprintf("/repos/%s/%s/hooks/git/%s", user, repo, id), nil, nil)
|
||||
return err
|
||||
func (c *Client) DeleteRepoGitHook(user, repo, id string) (*Response, error) {
|
||||
_, resp, err := c.getResponse("DELETE", fmt.Sprintf("/repos/%s/%s/hooks/git/%s", user, repo, id), nil, nil)
|
||||
return resp, err
|
||||
}
|
||||
|
73
vendor/code.gitea.io/sdk/gitea/hook.go
generated
vendored
73
vendor/code.gitea.io/sdk/gitea/hook.go
generated
vendored
@ -30,29 +30,33 @@ type ListHooksOptions struct {
|
||||
}
|
||||
|
||||
// ListOrgHooks list all the hooks of one organization
|
||||
func (c *Client) ListOrgHooks(org string, opt ListHooksOptions) ([]*Hook, error) {
|
||||
func (c *Client) ListOrgHooks(org string, opt ListHooksOptions) ([]*Hook, *Response, error) {
|
||||
opt.setDefaults()
|
||||
hooks := make([]*Hook, 0, opt.PageSize)
|
||||
return hooks, c.getParsedResponse("GET", fmt.Sprintf("/orgs/%s/hooks?%s", org, opt.getURLQuery().Encode()), nil, nil, &hooks)
|
||||
resp, err := c.getParsedResponse("GET", fmt.Sprintf("/orgs/%s/hooks?%s", org, opt.getURLQuery().Encode()), nil, nil, &hooks)
|
||||
return hooks, resp, err
|
||||
}
|
||||
|
||||
// ListRepoHooks list all the hooks of one repository
|
||||
func (c *Client) ListRepoHooks(user, repo string, opt ListHooksOptions) ([]*Hook, error) {
|
||||
func (c *Client) ListRepoHooks(user, repo string, opt ListHooksOptions) ([]*Hook, *Response, error) {
|
||||
opt.setDefaults()
|
||||
hooks := make([]*Hook, 0, opt.PageSize)
|
||||
return hooks, c.getParsedResponse("GET", fmt.Sprintf("/repos/%s/%s/hooks?%s", user, repo, opt.getURLQuery().Encode()), nil, nil, &hooks)
|
||||
resp, err := c.getParsedResponse("GET", fmt.Sprintf("/repos/%s/%s/hooks?%s", user, repo, opt.getURLQuery().Encode()), nil, nil, &hooks)
|
||||
return hooks, resp, err
|
||||
}
|
||||
|
||||
// GetOrgHook get a hook of an organization
|
||||
func (c *Client) GetOrgHook(org string, id int64) (*Hook, error) {
|
||||
func (c *Client) GetOrgHook(org string, id int64) (*Hook, *Response, error) {
|
||||
h := new(Hook)
|
||||
return h, c.getParsedResponse("GET", fmt.Sprintf("/orgs/%s/hooks/%d", org, id), nil, nil, h)
|
||||
resp, err := c.getParsedResponse("GET", fmt.Sprintf("/orgs/%s/hooks/%d", org, id), nil, nil, h)
|
||||
return h, resp, err
|
||||
}
|
||||
|
||||
// GetRepoHook get a hook of a repository
|
||||
func (c *Client) GetRepoHook(user, repo string, id int64) (*Hook, error) {
|
||||
func (c *Client) GetRepoHook(user, repo string, id int64) (*Hook, *Response, error) {
|
||||
h := new(Hook)
|
||||
return h, c.getParsedResponse("GET", fmt.Sprintf("/repos/%s/%s/hooks/%d", user, repo, id), nil, nil, h)
|
||||
resp, err := c.getParsedResponse("GET", fmt.Sprintf("/repos/%s/%s/hooks/%d", user, repo, id), nil, nil, h)
|
||||
return h, resp, err
|
||||
}
|
||||
|
||||
// CreateHookOption options when create a hook
|
||||
@ -64,24 +68,37 @@ type CreateHookOption struct {
|
||||
Active bool `json:"active"`
|
||||
}
|
||||
|
||||
// Validate the CreateHookOption struct
|
||||
func (opt CreateHookOption) Validate() error {
|
||||
if len(opt.Type) == 0 {
|
||||
return fmt.Errorf("hook type needed")
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
// CreateOrgHook create one hook for an organization, with options
|
||||
func (c *Client) CreateOrgHook(org string, opt CreateHookOption) (*Hook, error) {
|
||||
func (c *Client) CreateOrgHook(org string, opt CreateHookOption) (*Hook, *Response, error) {
|
||||
if err := opt.Validate(); err != nil {
|
||||
return nil, nil, err
|
||||
}
|
||||
body, err := json.Marshal(&opt)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
return nil, nil, err
|
||||
}
|
||||
h := new(Hook)
|
||||
return h, c.getParsedResponse("POST", fmt.Sprintf("/orgs/%s/hooks", org), jsonHeader, bytes.NewReader(body), h)
|
||||
resp, err := c.getParsedResponse("POST", fmt.Sprintf("/orgs/%s/hooks", org), jsonHeader, bytes.NewReader(body), h)
|
||||
return h, resp, err
|
||||
}
|
||||
|
||||
// CreateRepoHook create one hook for a repository, with options
|
||||
func (c *Client) CreateRepoHook(user, repo string, opt CreateHookOption) (*Hook, error) {
|
||||
func (c *Client) CreateRepoHook(user, repo string, opt CreateHookOption) (*Hook, *Response, error) {
|
||||
body, err := json.Marshal(&opt)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
return nil, nil, err
|
||||
}
|
||||
h := new(Hook)
|
||||
return h, c.getParsedResponse("POST", fmt.Sprintf("/repos/%s/%s/hooks", user, repo), jsonHeader, bytes.NewReader(body), h)
|
||||
resp, err := c.getParsedResponse("POST", fmt.Sprintf("/repos/%s/%s/hooks", user, repo), jsonHeader, bytes.NewReader(body), h)
|
||||
return h, resp, err
|
||||
}
|
||||
|
||||
// EditHookOption options when modify one hook
|
||||
@ -93,33 +110,33 @@ type EditHookOption struct {
|
||||
}
|
||||
|
||||
// EditOrgHook modify one hook of an organization, with hook id and options
|
||||
func (c *Client) EditOrgHook(org string, id int64, opt EditHookOption) error {
|
||||
func (c *Client) EditOrgHook(org string, id int64, opt EditHookOption) (*Response, error) {
|
||||
body, err := json.Marshal(&opt)
|
||||
if err != nil {
|
||||
return err
|
||||
return nil, err
|
||||
}
|
||||
_, err = c.getResponse("PATCH", fmt.Sprintf("/orgs/%s/hooks/%d", org, id), jsonHeader, bytes.NewReader(body))
|
||||
return err
|
||||
_, resp, err := c.getResponse("PATCH", fmt.Sprintf("/orgs/%s/hooks/%d", org, id), jsonHeader, bytes.NewReader(body))
|
||||
return resp, err
|
||||
}
|
||||
|
||||
// EditRepoHook modify one hook of a repository, with hook id and options
|
||||
func (c *Client) EditRepoHook(user, repo string, id int64, opt EditHookOption) error {
|
||||
func (c *Client) EditRepoHook(user, repo string, id int64, opt EditHookOption) (*Response, error) {
|
||||
body, err := json.Marshal(&opt)
|
||||
if err != nil {
|
||||
return err
|
||||
return nil, err
|
||||
}
|
||||
_, err = c.getResponse("PATCH", fmt.Sprintf("/repos/%s/%s/hooks/%d", user, repo, id), jsonHeader, bytes.NewReader(body))
|
||||
return err
|
||||
_, resp, err := c.getResponse("PATCH", fmt.Sprintf("/repos/%s/%s/hooks/%d", user, repo, id), jsonHeader, bytes.NewReader(body))
|
||||
return resp, err
|
||||
}
|
||||
|
||||
// DeleteOrgHook delete one hook from an organization, with hook id
|
||||
func (c *Client) DeleteOrgHook(org string, id int64) error {
|
||||
_, err := c.getResponse("DELETE", fmt.Sprintf("/orgs/%s/hooks/%d", org, id), nil, nil)
|
||||
return err
|
||||
func (c *Client) DeleteOrgHook(org string, id int64) (*Response, error) {
|
||||
_, resp, err := c.getResponse("DELETE", fmt.Sprintf("/orgs/%s/hooks/%d", org, id), nil, nil)
|
||||
return resp, err
|
||||
}
|
||||
|
||||
// DeleteRepoHook delete one hook from a repository, with hook id
|
||||
func (c *Client) DeleteRepoHook(user, repo string, id int64) error {
|
||||
_, err := c.getResponse("DELETE", fmt.Sprintf("/repos/%s/%s/hooks/%d", user, repo, id), nil, nil)
|
||||
return err
|
||||
func (c *Client) DeleteRepoHook(user, repo string, id int64) (*Response, error) {
|
||||
_, resp, err := c.getResponse("DELETE", fmt.Sprintf("/repos/%s/%s/hooks/%d", user, repo, id), nil, nil)
|
||||
return resp, err
|
||||
}
|
||||
|
56
vendor/code.gitea.io/sdk/gitea/issue.go
generated
vendored
56
vendor/code.gitea.io/sdk/gitea/issue.go
generated
vendored
@ -44,6 +44,7 @@ type Issue struct {
|
||||
Assignees []*User `json:"assignees"`
|
||||
// Whether the issue is open or closed
|
||||
State StateType `json:"state"`
|
||||
IsLocked bool `json:"is_locked"`
|
||||
Comments int `json:"comments"`
|
||||
Created time.Time `json:"created_at"`
|
||||
Updated time.Time `json:"updated_at"`
|
||||
@ -113,13 +114,13 @@ func (opt *ListIssueOption) QueryEncode() string {
|
||||
}
|
||||
|
||||
// ListIssues returns all issues assigned the authenticated user
|
||||
func (c *Client) ListIssues(opt ListIssueOption) ([]*Issue, error) {
|
||||
func (c *Client) ListIssues(opt ListIssueOption) ([]*Issue, *Response, error) {
|
||||
opt.setDefaults()
|
||||
issues := make([]*Issue, 0, opt.PageSize)
|
||||
|
||||
link, _ := url.Parse("/repos/issues/search")
|
||||
link.RawQuery = opt.QueryEncode()
|
||||
err := c.getParsedResponse("GET", link.String(), jsonHeader, nil, &issues)
|
||||
resp, err := c.getParsedResponse("GET", link.String(), jsonHeader, nil, &issues)
|
||||
if e := c.CheckServerVersionConstraint(">=1.12.0"); e != nil {
|
||||
for i := 0; i < len(issues); i++ {
|
||||
if issues[i].Repository != nil {
|
||||
@ -127,17 +128,17 @@ func (c *Client) ListIssues(opt ListIssueOption) ([]*Issue, error) {
|
||||
}
|
||||
}
|
||||
}
|
||||
return issues, err
|
||||
return issues, resp, err
|
||||
}
|
||||
|
||||
// ListRepoIssues returns all issues for a given repository
|
||||
func (c *Client) ListRepoIssues(owner, repo string, opt ListIssueOption) ([]*Issue, error) {
|
||||
func (c *Client) ListRepoIssues(owner, repo string, opt ListIssueOption) ([]*Issue, *Response, error) {
|
||||
opt.setDefaults()
|
||||
issues := make([]*Issue, 0, opt.PageSize)
|
||||
|
||||
link, _ := url.Parse(fmt.Sprintf("/repos/%s/%s/issues", owner, repo))
|
||||
link.RawQuery = opt.QueryEncode()
|
||||
err := c.getParsedResponse("GET", link.String(), jsonHeader, nil, &issues)
|
||||
resp, err := c.getParsedResponse("GET", link.String(), jsonHeader, nil, &issues)
|
||||
if e := c.CheckServerVersionConstraint(">=1.12.0"); e != nil {
|
||||
for i := 0; i < len(issues); i++ {
|
||||
if issues[i].Repository != nil {
|
||||
@ -145,17 +146,17 @@ func (c *Client) ListRepoIssues(owner, repo string, opt ListIssueOption) ([]*Iss
|
||||
}
|
||||
}
|
||||
}
|
||||
return issues, err
|
||||
return issues, resp, err
|
||||
}
|
||||
|
||||
// GetIssue returns a single issue for a given repository
|
||||
func (c *Client) GetIssue(owner, repo string, index int64) (*Issue, error) {
|
||||
func (c *Client) GetIssue(owner, repo string, index int64) (*Issue, *Response, error) {
|
||||
issue := new(Issue)
|
||||
err := c.getParsedResponse("GET", fmt.Sprintf("/repos/%s/%s/issues/%d", owner, repo, index), nil, nil, issue)
|
||||
resp, err := c.getParsedResponse("GET", fmt.Sprintf("/repos/%s/%s/issues/%d", owner, repo, index), nil, nil, issue)
|
||||
if e := c.CheckServerVersionConstraint(">=1.12.0"); e != nil && issue.Repository != nil {
|
||||
issue.Repository.Owner = strings.Split(issue.Repository.FullName, "/")[0]
|
||||
}
|
||||
return issue, err
|
||||
return issue, resp, err
|
||||
}
|
||||
|
||||
// CreateIssueOption options to create one issue
|
||||
@ -173,15 +174,27 @@ type CreateIssueOption struct {
|
||||
Closed bool `json:"closed"`
|
||||
}
|
||||
|
||||
// Validate the CreateIssueOption struct
|
||||
func (opt CreateIssueOption) Validate() error {
|
||||
if len(strings.TrimSpace(opt.Title)) == 0 {
|
||||
return fmt.Errorf("title is empty")
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
// CreateIssue create a new issue for a given repository
|
||||
func (c *Client) CreateIssue(owner, repo string, opt CreateIssueOption) (*Issue, error) {
|
||||
func (c *Client) CreateIssue(owner, repo string, opt CreateIssueOption) (*Issue, *Response, error) {
|
||||
if err := opt.Validate(); err != nil {
|
||||
return nil, nil, err
|
||||
}
|
||||
body, err := json.Marshal(&opt)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
return nil, nil, err
|
||||
}
|
||||
issue := new(Issue)
|
||||
return issue, c.getParsedResponse("POST", fmt.Sprintf("/repos/%s/%s/issues", owner, repo),
|
||||
resp, err := c.getParsedResponse("POST", fmt.Sprintf("/repos/%s/%s/issues", owner, repo),
|
||||
jsonHeader, bytes.NewReader(body), issue)
|
||||
return issue, resp, err
|
||||
}
|
||||
|
||||
// EditIssueOption options for editing an issue
|
||||
@ -195,13 +208,26 @@ type EditIssueOption struct {
|
||||
Deadline *time.Time `json:"due_date"`
|
||||
}
|
||||
|
||||
// Validate the EditIssueOption struct
|
||||
func (opt EditIssueOption) Validate() error {
|
||||
if len(opt.Title) != 0 && len(strings.TrimSpace(opt.Title)) == 0 {
|
||||
return fmt.Errorf("title is empty")
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
// EditIssue modify an existing issue for a given repository
|
||||
func (c *Client) EditIssue(owner, repo string, index int64, opt EditIssueOption) (*Issue, error) {
|
||||
func (c *Client) EditIssue(owner, repo string, index int64, opt EditIssueOption) (*Issue, *Response, error) {
|
||||
if err := opt.Validate(); err != nil {
|
||||
return nil, nil, err
|
||||
}
|
||||
body, err := json.Marshal(&opt)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
return nil, nil, err
|
||||
}
|
||||
issue := new(Issue)
|
||||
return issue, c.getParsedResponse("PATCH", fmt.Sprintf("/repos/%s/%s/issues/%d", owner, repo, index),
|
||||
resp, err := c.getParsedResponse("PATCH",
|
||||
fmt.Sprintf("/repos/%s/%s/issues/%d", owner, repo, index),
|
||||
jsonHeader, bytes.NewReader(body), issue)
|
||||
return issue, resp, err
|
||||
}
|
||||
|
59
vendor/code.gitea.io/sdk/gitea/issue_comment.go
generated
vendored
59
vendor/code.gitea.io/sdk/gitea/issue_comment.go
generated
vendored
@ -46,30 +46,33 @@ func (opt *ListIssueCommentOptions) QueryEncode() string {
|
||||
}
|
||||
|
||||
// ListIssueComments list comments on an issue.
|
||||
func (c *Client) ListIssueComments(owner, repo string, index int64, opt ListIssueCommentOptions) ([]*Comment, error) {
|
||||
func (c *Client) ListIssueComments(owner, repo string, index int64, opt ListIssueCommentOptions) ([]*Comment, *Response, error) {
|
||||
opt.setDefaults()
|
||||
link, _ := url.Parse(fmt.Sprintf("/repos/%s/%s/issues/%d/comments", owner, repo, index))
|
||||
link.RawQuery = opt.QueryEncode()
|
||||
comments := make([]*Comment, 0, opt.PageSize)
|
||||
return comments, c.getParsedResponse("GET", link.String(), nil, nil, &comments)
|
||||
resp, err := c.getParsedResponse("GET", link.String(), nil, nil, &comments)
|
||||
return comments, resp, err
|
||||
}
|
||||
|
||||
// ListRepoIssueComments list comments for a given repo.
|
||||
func (c *Client) ListRepoIssueComments(owner, repo string, opt ListIssueCommentOptions) ([]*Comment, error) {
|
||||
func (c *Client) ListRepoIssueComments(owner, repo string, opt ListIssueCommentOptions) ([]*Comment, *Response, error) {
|
||||
opt.setDefaults()
|
||||
link, _ := url.Parse(fmt.Sprintf("/repos/%s/%s/issues/comments", owner, repo))
|
||||
link.RawQuery = opt.QueryEncode()
|
||||
comments := make([]*Comment, 0, opt.PageSize)
|
||||
return comments, c.getParsedResponse("GET", link.String(), nil, nil, &comments)
|
||||
resp, err := c.getParsedResponse("GET", link.String(), nil, nil, &comments)
|
||||
return comments, resp, err
|
||||
}
|
||||
|
||||
// GetIssueComment get a comment for a given repo by id.
|
||||
func (c *Client) GetIssueComment(owner, repo string, id int64) (*Comment, error) {
|
||||
func (c *Client) GetIssueComment(owner, repo string, id int64) (*Comment, *Response, error) {
|
||||
comment := new(Comment)
|
||||
if err := c.CheckServerVersionConstraint(">=1.12.0"); err != nil {
|
||||
return comment, err
|
||||
return comment, nil, err
|
||||
}
|
||||
return comment, c.getParsedResponse("GET", fmt.Sprintf("/repos/%s/%s/issues/comments/%d", owner, repo, id), nil, nil, &comment)
|
||||
resp, err := c.getParsedResponse("GET", fmt.Sprintf("/repos/%s/%s/issues/comments/%d", owner, repo, id), nil, nil, &comment)
|
||||
return comment, resp, err
|
||||
}
|
||||
|
||||
// CreateIssueCommentOption options for creating a comment on an issue
|
||||
@ -77,14 +80,26 @@ type CreateIssueCommentOption struct {
|
||||
Body string `json:"body"`
|
||||
}
|
||||
|
||||
// Validate the CreateIssueCommentOption struct
|
||||
func (opt CreateIssueCommentOption) Validate() error {
|
||||
if len(opt.Body) == 0 {
|
||||
return fmt.Errorf("body is empty")
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
// CreateIssueComment create comment on an issue.
|
||||
func (c *Client) CreateIssueComment(owner, repo string, index int64, opt CreateIssueCommentOption) (*Comment, error) {
|
||||
func (c *Client) CreateIssueComment(owner, repo string, index int64, opt CreateIssueCommentOption) (*Comment, *Response, error) {
|
||||
if err := opt.Validate(); err != nil {
|
||||
return nil, nil, err
|
||||
}
|
||||
body, err := json.Marshal(&opt)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
return nil, nil, err
|
||||
}
|
||||
comment := new(Comment)
|
||||
return comment, c.getParsedResponse("POST", fmt.Sprintf("/repos/%s/%s/issues/%d/comments", owner, repo, index), jsonHeader, bytes.NewReader(body), comment)
|
||||
resp, err := c.getParsedResponse("POST", fmt.Sprintf("/repos/%s/%s/issues/%d/comments", owner, repo, index), jsonHeader, bytes.NewReader(body), comment)
|
||||
return comment, resp, err
|
||||
}
|
||||
|
||||
// EditIssueCommentOption options for editing a comment
|
||||
@ -92,18 +107,30 @@ type EditIssueCommentOption struct {
|
||||
Body string `json:"body"`
|
||||
}
|
||||
|
||||
// Validate the EditIssueCommentOption struct
|
||||
func (opt EditIssueCommentOption) Validate() error {
|
||||
if len(opt.Body) == 0 {
|
||||
return fmt.Errorf("body is empty")
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
// EditIssueComment edits an issue comment.
|
||||
func (c *Client) EditIssueComment(owner, repo string, commentID int64, opt EditIssueCommentOption) (*Comment, error) {
|
||||
func (c *Client) EditIssueComment(owner, repo string, commentID int64, opt EditIssueCommentOption) (*Comment, *Response, error) {
|
||||
if err := opt.Validate(); err != nil {
|
||||
return nil, nil, err
|
||||
}
|
||||
body, err := json.Marshal(&opt)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
return nil, nil, err
|
||||
}
|
||||
comment := new(Comment)
|
||||
return comment, c.getParsedResponse("PATCH", fmt.Sprintf("/repos/%s/%s/issues/comments/%d", owner, repo, commentID), jsonHeader, bytes.NewReader(body), comment)
|
||||
resp, err := c.getParsedResponse("PATCH", fmt.Sprintf("/repos/%s/%s/issues/comments/%d", owner, repo, commentID), jsonHeader, bytes.NewReader(body), comment)
|
||||
return comment, resp, err
|
||||
}
|
||||
|
||||
// DeleteIssueComment deletes an issue comment.
|
||||
func (c *Client) DeleteIssueComment(owner, repo string, commentID int64) error {
|
||||
_, err := c.getResponse("DELETE", fmt.Sprintf("/repos/%s/%s/issues/comments/%d", owner, repo, commentID), nil, nil)
|
||||
return err
|
||||
func (c *Client) DeleteIssueComment(owner, repo string, commentID int64) (*Response, error) {
|
||||
_, resp, err := c.getResponse("DELETE", fmt.Sprintf("/repos/%s/%s/issues/comments/%d", owner, repo, commentID), nil, nil)
|
||||
return resp, err
|
||||
}
|
||||
|
106
vendor/code.gitea.io/sdk/gitea/issue_label.go
generated
vendored
106
vendor/code.gitea.io/sdk/gitea/issue_label.go
generated
vendored
@ -8,6 +8,8 @@ import (
|
||||
"bytes"
|
||||
"encoding/json"
|
||||
"fmt"
|
||||
"regexp"
|
||||
"strings"
|
||||
)
|
||||
|
||||
// Label a label to an issue or a pr
|
||||
@ -26,17 +28,18 @@ type ListLabelsOptions struct {
|
||||
}
|
||||
|
||||
// ListRepoLabels list labels of one repository
|
||||
func (c *Client) ListRepoLabels(owner, repo string, opt ListLabelsOptions) ([]*Label, error) {
|
||||
func (c *Client) ListRepoLabels(owner, repo string, opt ListLabelsOptions) ([]*Label, *Response, error) {
|
||||
opt.setDefaults()
|
||||
labels := make([]*Label, 0, opt.PageSize)
|
||||
return labels, c.getParsedResponse("GET", fmt.Sprintf("/repos/%s/%s/labels?%s", owner, repo, opt.getURLQuery().Encode()), nil, nil, &labels)
|
||||
resp, err := c.getParsedResponse("GET", fmt.Sprintf("/repos/%s/%s/labels?%s", owner, repo, opt.getURLQuery().Encode()), nil, nil, &labels)
|
||||
return labels, resp, err
|
||||
}
|
||||
|
||||
// GetRepoLabel get one label of repository by repo it
|
||||
// TODO: maybe we need get a label by name
|
||||
func (c *Client) GetRepoLabel(owner, repo string, id int64) (*Label, error) {
|
||||
func (c *Client) GetRepoLabel(owner, repo string, id int64) (*Label, *Response, error) {
|
||||
label := new(Label)
|
||||
return label, c.getParsedResponse("GET", fmt.Sprintf("/repos/%s/%s/labels/%d", owner, repo, id), nil, nil, label)
|
||||
resp, err := c.getParsedResponse("GET", fmt.Sprintf("/repos/%s/%s/labels/%d", owner, repo, id), nil, nil, label)
|
||||
return label, resp, err
|
||||
}
|
||||
|
||||
// CreateLabelOption options for creating a label
|
||||
@ -47,8 +50,26 @@ type CreateLabelOption struct {
|
||||
Description string `json:"description"`
|
||||
}
|
||||
|
||||
// Validate the CreateLabelOption struct
|
||||
func (opt CreateLabelOption) Validate() error {
|
||||
aw, err := regexp.MatchString("^#?[0-9,a-f,A-F]{6}$", opt.Color)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
if !aw {
|
||||
return fmt.Errorf("invalid color format")
|
||||
}
|
||||
if len(strings.TrimSpace(opt.Name)) == 0 {
|
||||
return fmt.Errorf("empty name not allowed")
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
// CreateLabel create one label of repository
|
||||
func (c *Client) CreateLabel(owner, repo string, opt CreateLabelOption) (*Label, error) {
|
||||
func (c *Client) CreateLabel(owner, repo string, opt CreateLabelOption) (*Label, *Response, error) {
|
||||
if err := opt.Validate(); err != nil {
|
||||
return nil, nil, err
|
||||
}
|
||||
if len(opt.Color) == 6 {
|
||||
if err := c.CheckServerVersionConstraint(">=1.12.0"); err != nil {
|
||||
opt.Color = "#" + opt.Color
|
||||
@ -56,11 +77,13 @@ func (c *Client) CreateLabel(owner, repo string, opt CreateLabelOption) (*Label,
|
||||
}
|
||||
body, err := json.Marshal(&opt)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
return nil, nil, err
|
||||
}
|
||||
label := new(Label)
|
||||
return label, c.getParsedResponse("POST", fmt.Sprintf("/repos/%s/%s/labels", owner, repo),
|
||||
resp, err := c.getParsedResponse("POST",
|
||||
fmt.Sprintf("/repos/%s/%s/labels", owner, repo),
|
||||
jsonHeader, bytes.NewReader(body), label)
|
||||
return label, resp, err
|
||||
}
|
||||
|
||||
// EditLabelOption options for editing a label
|
||||
@ -70,27 +93,50 @@ type EditLabelOption struct {
|
||||
Description *string `json:"description"`
|
||||
}
|
||||
|
||||
// Validate the EditLabelOption struct
|
||||
func (opt EditLabelOption) Validate() error {
|
||||
if opt.Color != nil {
|
||||
aw, err := regexp.MatchString("^#?[0-9,a-f,A-F]{6}$", *opt.Color)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
if !aw {
|
||||
return fmt.Errorf("invalid color format")
|
||||
}
|
||||
}
|
||||
if opt.Name != nil {
|
||||
if len(strings.TrimSpace(*opt.Name)) == 0 {
|
||||
return fmt.Errorf("empty name not allowed")
|
||||
}
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
// EditLabel modify one label with options
|
||||
func (c *Client) EditLabel(owner, repo string, id int64, opt EditLabelOption) (*Label, error) {
|
||||
func (c *Client) EditLabel(owner, repo string, id int64, opt EditLabelOption) (*Label, *Response, error) {
|
||||
if err := opt.Validate(); err != nil {
|
||||
return nil, nil, err
|
||||
}
|
||||
body, err := json.Marshal(&opt)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
return nil, nil, err
|
||||
}
|
||||
label := new(Label)
|
||||
return label, c.getParsedResponse("PATCH", fmt.Sprintf("/repos/%s/%s/labels/%d", owner, repo, id), jsonHeader, bytes.NewReader(body), label)
|
||||
resp, err := c.getParsedResponse("PATCH", fmt.Sprintf("/repos/%s/%s/labels/%d", owner, repo, id), jsonHeader, bytes.NewReader(body), label)
|
||||
return label, resp, err
|
||||
}
|
||||
|
||||
// DeleteLabel delete one label of repository by id
|
||||
// TODO: maybe we need delete by name
|
||||
func (c *Client) DeleteLabel(owner, repo string, id int64) error {
|
||||
_, err := c.getResponse("DELETE", fmt.Sprintf("/repos/%s/%s/labels/%d", owner, repo, id), nil, nil)
|
||||
return err
|
||||
func (c *Client) DeleteLabel(owner, repo string, id int64) (*Response, error) {
|
||||
_, resp, err := c.getResponse("DELETE", fmt.Sprintf("/repos/%s/%s/labels/%d", owner, repo, id), nil, nil)
|
||||
return resp, err
|
||||
}
|
||||
|
||||
// GetIssueLabels get labels of one issue via issue id
|
||||
func (c *Client) GetIssueLabels(owner, repo string, index int64, opts ListLabelsOptions) ([]*Label, error) {
|
||||
func (c *Client) GetIssueLabels(owner, repo string, index int64, opts ListLabelsOptions) ([]*Label, *Response, error) {
|
||||
labels := make([]*Label, 0, 5)
|
||||
return labels, c.getParsedResponse("GET", fmt.Sprintf("/repos/%s/%s/issues/%d/labels?%s", owner, repo, index, opts.getURLQuery().Encode()), nil, nil, &labels)
|
||||
resp, err := c.getParsedResponse("GET", fmt.Sprintf("/repos/%s/%s/issues/%d/labels?%s", owner, repo, index, opts.getURLQuery().Encode()), nil, nil, &labels)
|
||||
return labels, resp, err
|
||||
}
|
||||
|
||||
// IssueLabelsOption a collection of labels
|
||||
@ -100,34 +146,36 @@ type IssueLabelsOption struct {
|
||||
}
|
||||
|
||||
// AddIssueLabels add one or more labels to one issue
|
||||
func (c *Client) AddIssueLabels(owner, repo string, index int64, opt IssueLabelsOption) ([]*Label, error) {
|
||||
func (c *Client) AddIssueLabels(owner, repo string, index int64, opt IssueLabelsOption) ([]*Label, *Response, error) {
|
||||
body, err := json.Marshal(&opt)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
return nil, nil, err
|
||||
}
|
||||
var labels []*Label
|
||||
return labels, c.getParsedResponse("POST", fmt.Sprintf("/repos/%s/%s/issues/%d/labels", owner, repo, index), jsonHeader, bytes.NewReader(body), &labels)
|
||||
resp, err := c.getParsedResponse("POST", fmt.Sprintf("/repos/%s/%s/issues/%d/labels", owner, repo, index), jsonHeader, bytes.NewReader(body), &labels)
|
||||
return labels, resp, err
|
||||
}
|
||||
|
||||
// ReplaceIssueLabels replace old labels of issue with new labels
|
||||
func (c *Client) ReplaceIssueLabels(owner, repo string, index int64, opt IssueLabelsOption) ([]*Label, error) {
|
||||
func (c *Client) ReplaceIssueLabels(owner, repo string, index int64, opt IssueLabelsOption) ([]*Label, *Response, error) {
|
||||
body, err := json.Marshal(&opt)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
return nil, nil, err
|
||||
}
|
||||
var labels []*Label
|
||||
return labels, c.getParsedResponse("PUT", fmt.Sprintf("/repos/%s/%s/issues/%d/labels", owner, repo, index), jsonHeader, bytes.NewReader(body), &labels)
|
||||
resp, err := c.getParsedResponse("PUT", fmt.Sprintf("/repos/%s/%s/issues/%d/labels", owner, repo, index), jsonHeader, bytes.NewReader(body), &labels)
|
||||
return labels, resp, err
|
||||
}
|
||||
|
||||
// DeleteIssueLabel delete one label of one issue by issue id and label id
|
||||
// TODO: maybe we need delete by label name and issue id
|
||||
func (c *Client) DeleteIssueLabel(owner, repo string, index, label int64) error {
|
||||
_, err := c.getResponse("DELETE", fmt.Sprintf("/repos/%s/%s/issues/%d/labels/%d", owner, repo, index, label), nil, nil)
|
||||
return err
|
||||
func (c *Client) DeleteIssueLabel(owner, repo string, index, label int64) (*Response, error) {
|
||||
_, resp, err := c.getResponse("DELETE", fmt.Sprintf("/repos/%s/%s/issues/%d/labels/%d", owner, repo, index, label), nil, nil)
|
||||
return resp, err
|
||||
}
|
||||
|
||||
// ClearIssueLabels delete all the labels of one issue.
|
||||
func (c *Client) ClearIssueLabels(owner, repo string, index int64) error {
|
||||
_, err := c.getResponse("DELETE", fmt.Sprintf("/repos/%s/%s/issues/%d/labels", owner, repo, index), nil, nil)
|
||||
return err
|
||||
func (c *Client) ClearIssueLabels(owner, repo string, index int64) (*Response, error) {
|
||||
_, resp, err := c.getResponse("DELETE", fmt.Sprintf("/repos/%s/%s/issues/%d/labels", owner, repo, index), nil, nil)
|
||||
return resp, err
|
||||
}
|
||||
|
137
vendor/code.gitea.io/sdk/gitea/issue_milestone.go
generated
vendored
137
vendor/code.gitea.io/sdk/gitea/issue_milestone.go
generated
vendored
@ -9,6 +9,7 @@ import (
|
||||
"encoding/json"
|
||||
"fmt"
|
||||
"net/url"
|
||||
"strings"
|
||||
"time"
|
||||
)
|
||||
|
||||
@ -20,6 +21,8 @@ type Milestone struct {
|
||||
State StateType `json:"state"`
|
||||
OpenIssues int `json:"open_issues"`
|
||||
ClosedIssues int `json:"closed_issues"`
|
||||
Created time.Time `json:"created_at"`
|
||||
Updated *time.Time `json:"updated_at"`
|
||||
Closed *time.Time `json:"closed_at"`
|
||||
Deadline *time.Time `json:"due_on"`
|
||||
}
|
||||
@ -29,6 +32,7 @@ type ListMilestoneOption struct {
|
||||
ListOptions
|
||||
// open, closed, all
|
||||
State StateType
|
||||
Name string
|
||||
}
|
||||
|
||||
// QueryEncode turns options into querystring argument
|
||||
@ -37,23 +41,40 @@ func (opt *ListMilestoneOption) QueryEncode() string {
|
||||
if opt.State != "" {
|
||||
query.Add("state", string(opt.State))
|
||||
}
|
||||
if len(opt.Name) != 0 {
|
||||
query.Add("name", opt.Name)
|
||||
}
|
||||
return query.Encode()
|
||||
}
|
||||
|
||||
// ListRepoMilestones list all the milestones of one repository
|
||||
func (c *Client) ListRepoMilestones(owner, repo string, opt ListMilestoneOption) ([]*Milestone, error) {
|
||||
func (c *Client) ListRepoMilestones(owner, repo string, opt ListMilestoneOption) ([]*Milestone, *Response, error) {
|
||||
opt.setDefaults()
|
||||
milestones := make([]*Milestone, 0, opt.PageSize)
|
||||
|
||||
link, _ := url.Parse(fmt.Sprintf("/repos/%s/%s/milestones", owner, repo))
|
||||
link.RawQuery = opt.QueryEncode()
|
||||
return milestones, c.getParsedResponse("GET", link.String(), nil, nil, &milestones)
|
||||
resp, err := c.getParsedResponse("GET", link.String(), nil, nil, &milestones)
|
||||
return milestones, resp, err
|
||||
}
|
||||
|
||||
// GetMilestone get one milestone by repo name and milestone id
|
||||
func (c *Client) GetMilestone(owner, repo string, id int64) (*Milestone, error) {
|
||||
func (c *Client) GetMilestone(owner, repo string, id int64) (*Milestone, *Response, error) {
|
||||
milestone := new(Milestone)
|
||||
return milestone, c.getParsedResponse("GET", fmt.Sprintf("/repos/%s/%s/milestones/%d", owner, repo, id), nil, nil, milestone)
|
||||
resp, err := c.getParsedResponse("GET", fmt.Sprintf("/repos/%s/%s/milestones/%d", owner, repo, id), nil, nil, milestone)
|
||||
return milestone, resp, err
|
||||
}
|
||||
|
||||
// GetMilestoneByName get one milestone by repo and milestone name
|
||||
func (c *Client) GetMilestoneByName(owner, repo string, name string) (*Milestone, *Response, error) {
|
||||
if c.CheckServerVersionConstraint(">=1.13") != nil {
|
||||
// backwards compatibility mode
|
||||
m, resp, err := c.resolveMilestoneByName(owner, repo, name)
|
||||
return m, resp, err
|
||||
}
|
||||
milestone := new(Milestone)
|
||||
resp, err := c.getParsedResponse("GET", fmt.Sprintf("/repos/%s/%s/milestones/%s", owner, repo, name), nil, nil, milestone)
|
||||
return milestone, resp, err
|
||||
}
|
||||
|
||||
// CreateMilestoneOption options for creating a milestone
|
||||
@ -64,47 +85,129 @@ type CreateMilestoneOption struct {
|
||||
Deadline *time.Time `json:"due_on"`
|
||||
}
|
||||
|
||||
// Validate the CreateMilestoneOption struct
|
||||
func (opt CreateMilestoneOption) Validate() error {
|
||||
if len(strings.TrimSpace(opt.Title)) == 0 {
|
||||
return fmt.Errorf("title is empty")
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
// CreateMilestone create one milestone with options
|
||||
func (c *Client) CreateMilestone(owner, repo string, opt CreateMilestoneOption) (*Milestone, error) {
|
||||
func (c *Client) CreateMilestone(owner, repo string, opt CreateMilestoneOption) (*Milestone, *Response, error) {
|
||||
if err := opt.Validate(); err != nil {
|
||||
return nil, nil, err
|
||||
}
|
||||
body, err := json.Marshal(&opt)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
return nil, nil, err
|
||||
}
|
||||
milestone := new(Milestone)
|
||||
err = c.getParsedResponse("POST", fmt.Sprintf("/repos/%s/%s/milestones", owner, repo), jsonHeader, bytes.NewReader(body), milestone)
|
||||
resp, err := c.getParsedResponse("POST", fmt.Sprintf("/repos/%s/%s/milestones", owner, repo), jsonHeader, bytes.NewReader(body), milestone)
|
||||
|
||||
// make creating closed milestones need gitea >= v1.13.0
|
||||
// this make it backwards compatible
|
||||
if err == nil && opt.State == StateClosed && milestone.State != StateClosed {
|
||||
closed := "closed"
|
||||
closed := StateClosed
|
||||
return c.EditMilestone(owner, repo, milestone.ID, EditMilestoneOption{
|
||||
State: &closed,
|
||||
})
|
||||
}
|
||||
|
||||
return milestone, err
|
||||
return milestone, resp, err
|
||||
}
|
||||
|
||||
// EditMilestoneOption options for editing a milestone
|
||||
type EditMilestoneOption struct {
|
||||
Title string `json:"title"`
|
||||
Description *string `json:"description"`
|
||||
State *string `json:"state"`
|
||||
State *StateType `json:"state"`
|
||||
Deadline *time.Time `json:"due_on"`
|
||||
}
|
||||
|
||||
// Validate the EditMilestoneOption struct
|
||||
func (opt EditMilestoneOption) Validate() error {
|
||||
if len(opt.Title) != 0 && len(strings.TrimSpace(opt.Title)) == 0 {
|
||||
return fmt.Errorf("title is empty")
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
// EditMilestone modify milestone with options
|
||||
func (c *Client) EditMilestone(owner, repo string, id int64, opt EditMilestoneOption) (*Milestone, error) {
|
||||
func (c *Client) EditMilestone(owner, repo string, id int64, opt EditMilestoneOption) (*Milestone, *Response, error) {
|
||||
if err := opt.Validate(); err != nil {
|
||||
return nil, nil, err
|
||||
}
|
||||
body, err := json.Marshal(&opt)
|
||||
if err != nil {
|
||||
return nil, nil, err
|
||||
}
|
||||
milestone := new(Milestone)
|
||||
resp, err := c.getParsedResponse("PATCH", fmt.Sprintf("/repos/%s/%s/milestones/%d", owner, repo, id), jsonHeader, bytes.NewReader(body), milestone)
|
||||
return milestone, resp, err
|
||||
}
|
||||
|
||||
// EditMilestoneByName modify milestone with options
|
||||
func (c *Client) EditMilestoneByName(owner, repo string, name string, opt EditMilestoneOption) (*Milestone, *Response, error) {
|
||||
if c.CheckServerVersionConstraint(">=1.13") != nil {
|
||||
// backwards compatibility mode
|
||||
m, _, err := c.resolveMilestoneByName(owner, repo, name)
|
||||
if err != nil {
|
||||
return nil, nil, err
|
||||
}
|
||||
return c.EditMilestone(owner, repo, m.ID, opt)
|
||||
}
|
||||
if err := opt.Validate(); err != nil {
|
||||
return nil, nil, err
|
||||
}
|
||||
body, err := json.Marshal(&opt)
|
||||
if err != nil {
|
||||
return nil, nil, err
|
||||
}
|
||||
milestone := new(Milestone)
|
||||
resp, err := c.getParsedResponse("PATCH", fmt.Sprintf("/repos/%s/%s/milestones/%s", owner, repo, name), jsonHeader, bytes.NewReader(body), milestone)
|
||||
return milestone, resp, err
|
||||
}
|
||||
|
||||
// DeleteMilestone delete one milestone by id
|
||||
func (c *Client) DeleteMilestone(owner, repo string, id int64) (*Response, error) {
|
||||
_, resp, err := c.getResponse("DELETE", fmt.Sprintf("/repos/%s/%s/milestones/%d", owner, repo, id), nil, nil)
|
||||
return resp, err
|
||||
}
|
||||
|
||||
// DeleteMilestoneByName delete one milestone by name
|
||||
func (c *Client) DeleteMilestoneByName(owner, repo string, name string) (*Response, error) {
|
||||
if c.CheckServerVersionConstraint(">=1.13") != nil {
|
||||
// backwards compatibility mode
|
||||
m, _, err := c.resolveMilestoneByName(owner, repo, name)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
milestone := new(Milestone)
|
||||
return milestone, c.getParsedResponse("PATCH", fmt.Sprintf("/repos/%s/%s/milestones/%d", owner, repo, id), jsonHeader, bytes.NewReader(body), milestone)
|
||||
return c.DeleteMilestone(owner, repo, m.ID)
|
||||
}
|
||||
_, resp, err := c.getResponse("DELETE", fmt.Sprintf("/repos/%s/%s/milestones/%s", owner, repo, name), nil, nil)
|
||||
return resp, err
|
||||
}
|
||||
|
||||
// DeleteMilestone delete one milestone by milestone id
|
||||
func (c *Client) DeleteMilestone(owner, repo string, id int64) error {
|
||||
_, err := c.getResponse("DELETE", fmt.Sprintf("/repos/%s/%s/milestones/%d", owner, repo, id), nil, nil)
|
||||
return err
|
||||
// resolveMilestoneByName is a fallback method to find milestone id by name
|
||||
func (c *Client) resolveMilestoneByName(owner, repo, name string) (*Milestone, *Response, error) {
|
||||
for i := 1; ; i++ {
|
||||
miles, resp, err := c.ListRepoMilestones(owner, repo, ListMilestoneOption{
|
||||
ListOptions: ListOptions{
|
||||
Page: i,
|
||||
},
|
||||
State: "all",
|
||||
})
|
||||
if err != nil {
|
||||
return nil, nil, err
|
||||
}
|
||||
if len(miles) == 0 {
|
||||
return nil, nil, fmt.Errorf("milestone '%s' do not exist", name)
|
||||
}
|
||||
for _, m := range miles {
|
||||
if strings.ToLower(strings.TrimSpace(m.Title)) == strings.ToLower(strings.TrimSpace(name)) {
|
||||
return m, resp, nil
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
56
vendor/code.gitea.io/sdk/gitea/issue_reaction.go
generated
vendored
56
vendor/code.gitea.io/sdk/gitea/issue_reaction.go
generated
vendored
@ -19,21 +19,23 @@ type Reaction struct {
|
||||
}
|
||||
|
||||
// GetIssueReactions get a list reactions of an issue
|
||||
func (c *Client) GetIssueReactions(owner, repo string, index int64) ([]*Reaction, error) {
|
||||
func (c *Client) GetIssueReactions(owner, repo string, index int64) ([]*Reaction, *Response, error) {
|
||||
if err := c.CheckServerVersionConstraint(">=1.11.0"); err != nil {
|
||||
return nil, err
|
||||
return nil, nil, err
|
||||
}
|
||||
reactions := make([]*Reaction, 0, 10)
|
||||
return reactions, c.getParsedResponse("GET", fmt.Sprintf("/repos/%s/%s/issues/%d/reactions", owner, repo, index), nil, nil, &reactions)
|
||||
resp, err := c.getParsedResponse("GET", fmt.Sprintf("/repos/%s/%s/issues/%d/reactions", owner, repo, index), nil, nil, &reactions)
|
||||
return reactions, resp, err
|
||||
}
|
||||
|
||||
// GetIssueCommentReactions get a list of reactions from a comment of an issue
|
||||
func (c *Client) GetIssueCommentReactions(owner, repo string, commentID int64) ([]*Reaction, error) {
|
||||
func (c *Client) GetIssueCommentReactions(owner, repo string, commentID int64) ([]*Reaction, *Response, error) {
|
||||
if err := c.CheckServerVersionConstraint(">=1.11.0"); err != nil {
|
||||
return nil, err
|
||||
return nil, nil, err
|
||||
}
|
||||
reactions := make([]*Reaction, 0, 10)
|
||||
return reactions, c.getParsedResponse("GET", fmt.Sprintf("/repos/%s/%s/issues/comments/%d/reactions", owner, repo, commentID), nil, nil, &reactions)
|
||||
resp, err := c.getParsedResponse("GET", fmt.Sprintf("/repos/%s/%s/issues/comments/%d/reactions", owner, repo, commentID), nil, nil, &reactions)
|
||||
return reactions, resp, err
|
||||
}
|
||||
|
||||
// editReactionOption contain the reaction type
|
||||
@ -42,57 +44,61 @@ type editReactionOption struct {
|
||||
}
|
||||
|
||||
// PostIssueReaction add a reaction to an issue
|
||||
func (c *Client) PostIssueReaction(owner, repo string, index int64, reaction string) (*Reaction, error) {
|
||||
func (c *Client) PostIssueReaction(owner, repo string, index int64, reaction string) (*Reaction, *Response, error) {
|
||||
if err := c.CheckServerVersionConstraint(">=1.11.0"); err != nil {
|
||||
return nil, err
|
||||
return nil, nil, err
|
||||
}
|
||||
reactionResponse := new(Reaction)
|
||||
body, err := json.Marshal(&editReactionOption{Reaction: reaction})
|
||||
if err != nil {
|
||||
return nil, err
|
||||
return nil, nil, err
|
||||
}
|
||||
return reactionResponse, c.getParsedResponse("POST", fmt.Sprintf("/repos/%s/%s/issues/%d/reactions", owner, repo, index),
|
||||
resp, err := c.getParsedResponse("POST",
|
||||
fmt.Sprintf("/repos/%s/%s/issues/%d/reactions", owner, repo, index),
|
||||
jsonHeader, bytes.NewReader(body), reactionResponse)
|
||||
return reactionResponse, resp, err
|
||||
}
|
||||
|
||||
// DeleteIssueReaction remove a reaction from an issue
|
||||
func (c *Client) DeleteIssueReaction(owner, repo string, index int64, reaction string) error {
|
||||
func (c *Client) DeleteIssueReaction(owner, repo string, index int64, reaction string) (*Response, error) {
|
||||
if err := c.CheckServerVersionConstraint(">=1.11.0"); err != nil {
|
||||
return err
|
||||
return nil, err
|
||||
}
|
||||
body, err := json.Marshal(&editReactionOption{Reaction: reaction})
|
||||
if err != nil {
|
||||
return err
|
||||
return nil, err
|
||||
}
|
||||
_, err = c.getResponse("DELETE", fmt.Sprintf("/repos/%s/%s/issues/%d/reactions", owner, repo, index), jsonHeader, bytes.NewReader(body))
|
||||
return err
|
||||
_, resp, err := c.getResponse("DELETE", fmt.Sprintf("/repos/%s/%s/issues/%d/reactions", owner, repo, index), jsonHeader, bytes.NewReader(body))
|
||||
return resp, err
|
||||
}
|
||||
|
||||
// PostIssueCommentReaction add a reaction to a comment of an issue
|
||||
func (c *Client) PostIssueCommentReaction(owner, repo string, commentID int64, reaction string) (*Reaction, error) {
|
||||
func (c *Client) PostIssueCommentReaction(owner, repo string, commentID int64, reaction string) (*Reaction, *Response, error) {
|
||||
if err := c.CheckServerVersionConstraint(">=1.11.0"); err != nil {
|
||||
return nil, err
|
||||
return nil, nil, err
|
||||
}
|
||||
reactionResponse := new(Reaction)
|
||||
body, err := json.Marshal(&editReactionOption{Reaction: reaction})
|
||||
if err != nil {
|
||||
return nil, err
|
||||
return nil, nil, err
|
||||
}
|
||||
return reactionResponse, c.getParsedResponse("POST", fmt.Sprintf("/repos/%s/%s/issues/comments/%d/reactions", owner, repo, commentID),
|
||||
resp, err := c.getParsedResponse("POST",
|
||||
fmt.Sprintf("/repos/%s/%s/issues/comments/%d/reactions", owner, repo, commentID),
|
||||
jsonHeader, bytes.NewReader(body), reactionResponse)
|
||||
return reactionResponse, resp, err
|
||||
}
|
||||
|
||||
// DeleteIssueCommentReaction remove a reaction from a comment of an issue
|
||||
func (c *Client) DeleteIssueCommentReaction(owner, repo string, commentID int64, reaction string) error {
|
||||
func (c *Client) DeleteIssueCommentReaction(owner, repo string, commentID int64, reaction string) (*Response, error) {
|
||||
if err := c.CheckServerVersionConstraint(">=1.11.0"); err != nil {
|
||||
return err
|
||||
return nil, err
|
||||
}
|
||||
// swagger:operation DELETE /repos/{owner}/{repo}/issues/comments/{id}/reactions issue issueDeleteCommentReaction
|
||||
body, err := json.Marshal(&editReactionOption{Reaction: reaction})
|
||||
if err != nil {
|
||||
return err
|
||||
return nil, err
|
||||
}
|
||||
_, err = c.getResponse("DELETE", fmt.Sprintf("/repos/%s/%s/issues/comments/%d/reactions", owner, repo, commentID),
|
||||
_, resp, err := c.getResponse("DELETE",
|
||||
fmt.Sprintf("/repos/%s/%s/issues/comments/%d/reactions", owner, repo, commentID),
|
||||
jsonHeader, bytes.NewReader(body))
|
||||
return err
|
||||
return resp, err
|
||||
}
|
||||
|
23
vendor/code.gitea.io/sdk/gitea/issue_stopwatch.go
generated
vendored
23
vendor/code.gitea.io/sdk/gitea/issue_stopwatch.go
generated
vendored
@ -16,27 +16,28 @@ type StopWatch struct {
|
||||
}
|
||||
|
||||
// GetMyStopwatches list all stopwatches
|
||||
func (c *Client) GetMyStopwatches() ([]*StopWatch, error) {
|
||||
func (c *Client) GetMyStopwatches() ([]*StopWatch, *Response, error) {
|
||||
stopwatches := make([]*StopWatch, 0, 1)
|
||||
return stopwatches, c.getParsedResponse("GET", "/user/stopwatches", nil, nil, &stopwatches)
|
||||
resp, err := c.getParsedResponse("GET", "/user/stopwatches", nil, nil, &stopwatches)
|
||||
return stopwatches, resp, err
|
||||
}
|
||||
|
||||
// DeleteIssueStopwatch delete / cancel a specific stopwatch
|
||||
func (c *Client) DeleteIssueStopwatch(owner, repo string, index int64) error {
|
||||
_, err := c.getResponse("DELETE", fmt.Sprintf("/repos/%s/%s/issues/%d/stopwatch/delete", owner, repo, index), nil, nil)
|
||||
return err
|
||||
func (c *Client) DeleteIssueStopwatch(owner, repo string, index int64) (*Response, error) {
|
||||
_, resp, err := c.getResponse("DELETE", fmt.Sprintf("/repos/%s/%s/issues/%d/stopwatch/delete", owner, repo, index), nil, nil)
|
||||
return resp, err
|
||||
}
|
||||
|
||||
// StartIssueStopWatch starts a stopwatch for an existing issue for a given
|
||||
// repository
|
||||
func (c *Client) StartIssueStopWatch(owner, repo string, index int64) error {
|
||||
_, err := c.getResponse("POST", fmt.Sprintf("/repos/%s/%s/issues/%d/stopwatch/start", owner, repo, index), nil, nil)
|
||||
return err
|
||||
func (c *Client) StartIssueStopWatch(owner, repo string, index int64) (*Response, error) {
|
||||
_, resp, err := c.getResponse("POST", fmt.Sprintf("/repos/%s/%s/issues/%d/stopwatch/start", owner, repo, index), nil, nil)
|
||||
return resp, err
|
||||
}
|
||||
|
||||
// StopIssueStopWatch stops an existing stopwatch for an issue in a given
|
||||
// repository
|
||||
func (c *Client) StopIssueStopWatch(owner, repo string, index int64) error {
|
||||
_, err := c.getResponse("POST", fmt.Sprintf("/repos/%s/%s/issues/%d/stopwatch/stop", owner, repo, index), nil, nil)
|
||||
return err
|
||||
func (c *Client) StopIssueStopWatch(owner, repo string, index int64) (*Response, error) {
|
||||
_, resp, err := c.getResponse("POST", fmt.Sprintf("/repos/%s/%s/issues/%d/stopwatch/stop", owner, repo, index), nil, nil)
|
||||
return resp, err
|
||||
}
|
||||
|
54
vendor/code.gitea.io/sdk/gitea/issue_subscription.go
generated
vendored
54
vendor/code.gitea.io/sdk/gitea/issue_subscription.go
generated
vendored
@ -10,73 +10,75 @@ import (
|
||||
)
|
||||
|
||||
// GetIssueSubscribers get list of users who subscribed on an issue
|
||||
func (c *Client) GetIssueSubscribers(owner, repo string, index int64) ([]*User, error) {
|
||||
func (c *Client) GetIssueSubscribers(owner, repo string, index int64) ([]*User, *Response, error) {
|
||||
if err := c.CheckServerVersionConstraint(">=1.11.0"); err != nil {
|
||||
return nil, err
|
||||
return nil, nil, err
|
||||
}
|
||||
subscribers := make([]*User, 0, 10)
|
||||
return subscribers, c.getParsedResponse("GET", fmt.Sprintf("/repos/%s/%s/issues/%d/subscriptions", owner, repo, index), nil, nil, &subscribers)
|
||||
resp, err := c.getParsedResponse("GET", fmt.Sprintf("/repos/%s/%s/issues/%d/subscriptions", owner, repo, index), nil, nil, &subscribers)
|
||||
return subscribers, resp, err
|
||||
}
|
||||
|
||||
// AddIssueSubscription Subscribe user to issue
|
||||
func (c *Client) AddIssueSubscription(owner, repo string, index int64, user string) error {
|
||||
func (c *Client) AddIssueSubscription(owner, repo string, index int64, user string) (*Response, error) {
|
||||
if err := c.CheckServerVersionConstraint(">=1.11.0"); err != nil {
|
||||
return err
|
||||
return nil, err
|
||||
}
|
||||
status, err := c.getStatusCode("PUT", fmt.Sprintf("/repos/%s/%s/issues/%d/subscriptions/%s", owner, repo, index, user), nil, nil)
|
||||
status, resp, err := c.getStatusCode("PUT", fmt.Sprintf("/repos/%s/%s/issues/%d/subscriptions/%s", owner, repo, index, user), nil, nil)
|
||||
if err != nil {
|
||||
return err
|
||||
return resp, err
|
||||
}
|
||||
if status == http.StatusCreated {
|
||||
return nil
|
||||
return resp, nil
|
||||
}
|
||||
if status == http.StatusOK {
|
||||
return fmt.Errorf("already subscribed")
|
||||
return resp, fmt.Errorf("already subscribed")
|
||||
}
|
||||
return fmt.Errorf("unexpected Status: %d", status)
|
||||
return resp, fmt.Errorf("unexpected Status: %d", status)
|
||||
}
|
||||
|
||||
// DeleteIssueSubscription unsubscribe user from issue
|
||||
func (c *Client) DeleteIssueSubscription(owner, repo string, index int64, user string) error {
|
||||
func (c *Client) DeleteIssueSubscription(owner, repo string, index int64, user string) (*Response, error) {
|
||||
if err := c.CheckServerVersionConstraint(">=1.11.0"); err != nil {
|
||||
return err
|
||||
return nil, err
|
||||
}
|
||||
status, err := c.getStatusCode("DELETE", fmt.Sprintf("/repos/%s/%s/issues/%d/subscriptions/%s", owner, repo, index, user), nil, nil)
|
||||
status, resp, err := c.getStatusCode("DELETE", fmt.Sprintf("/repos/%s/%s/issues/%d/subscriptions/%s", owner, repo, index, user), nil, nil)
|
||||
if err != nil {
|
||||
return err
|
||||
return resp, err
|
||||
}
|
||||
if status == http.StatusCreated {
|
||||
return nil
|
||||
return resp, nil
|
||||
}
|
||||
if status == http.StatusOK {
|
||||
return fmt.Errorf("already unsubscribed")
|
||||
return resp, fmt.Errorf("already unsubscribed")
|
||||
}
|
||||
return fmt.Errorf("unexpected Status: %d", status)
|
||||
return resp, fmt.Errorf("unexpected Status: %d", status)
|
||||
}
|
||||
|
||||
// CheckIssueSubscription check if current user is subscribed to an issue
|
||||
func (c *Client) CheckIssueSubscription(owner, repo string, index int64) (*WatchInfo, error) {
|
||||
func (c *Client) CheckIssueSubscription(owner, repo string, index int64) (*WatchInfo, *Response, error) {
|
||||
if err := c.CheckServerVersionConstraint(">=1.12.0"); err != nil {
|
||||
return nil, err
|
||||
return nil, nil, err
|
||||
}
|
||||
wi := new(WatchInfo)
|
||||
return wi, c.getParsedResponse("GET", fmt.Sprintf("/repos/%s/%s/issues/%d/subscriptions/check", owner, repo, index), nil, nil, wi)
|
||||
resp, err := c.getParsedResponse("GET", fmt.Sprintf("/repos/%s/%s/issues/%d/subscriptions/check", owner, repo, index), nil, nil, wi)
|
||||
return wi, resp, err
|
||||
}
|
||||
|
||||
// IssueSubscribe subscribe current user to an issue
|
||||
func (c *Client) IssueSubscribe(owner, repo string, index int64) error {
|
||||
u, err := c.GetMyUserInfo()
|
||||
func (c *Client) IssueSubscribe(owner, repo string, index int64) (*Response, error) {
|
||||
u, _, err := c.GetMyUserInfo()
|
||||
if err != nil {
|
||||
return err
|
||||
return nil, err
|
||||
}
|
||||
return c.AddIssueSubscription(owner, repo, index, u.UserName)
|
||||
}
|
||||
|
||||
// IssueUnSubscribe unsubscribe current user from an issue
|
||||
func (c *Client) IssueUnSubscribe(owner, repo string, index int64) error {
|
||||
u, err := c.GetMyUserInfo()
|
||||
func (c *Client) IssueUnSubscribe(owner, repo string, index int64) (*Response, error) {
|
||||
u, _, err := c.GetMyUserInfo()
|
||||
if err != nil {
|
||||
return err
|
||||
return nil, err
|
||||
}
|
||||
return c.DeleteIssueSubscription(owner, repo, index, u.UserName)
|
||||
}
|
||||
|
74
vendor/code.gitea.io/sdk/gitea/issue_tracked_time.go
generated
vendored
74
vendor/code.gitea.io/sdk/gitea/issue_tracked_time.go
generated
vendored
@ -26,42 +26,70 @@ type TrackedTime struct {
|
||||
}
|
||||
|
||||
// GetUserTrackedTimes list tracked times of a user
|
||||
func (c *Client) GetUserTrackedTimes(owner, repo, user string) ([]*TrackedTime, error) {
|
||||
func (c *Client) GetUserTrackedTimes(owner, repo, user string) ([]*TrackedTime, *Response, error) {
|
||||
if err := c.CheckServerVersionConstraint(">=1.11.0"); err != nil {
|
||||
return nil, nil, err
|
||||
}
|
||||
times := make([]*TrackedTime, 0, 10)
|
||||
return times, c.getParsedResponse("GET", fmt.Sprintf("/repos/%s/%s/times/%s", owner, repo, user), nil, nil, ×)
|
||||
resp, err := c.getParsedResponse("GET", fmt.Sprintf("/repos/%s/%s/times/%s", owner, repo, user), nil, nil, ×)
|
||||
return times, resp, err
|
||||
}
|
||||
|
||||
// GetRepoTrackedTimes list tracked times of a repository
|
||||
func (c *Client) GetRepoTrackedTimes(owner, repo string) ([]*TrackedTime, error) {
|
||||
func (c *Client) GetRepoTrackedTimes(owner, repo string) ([]*TrackedTime, *Response, error) {
|
||||
if err := c.CheckServerVersionConstraint(">=1.11.0"); err != nil {
|
||||
return nil, nil, err
|
||||
}
|
||||
times := make([]*TrackedTime, 0, 10)
|
||||
return times, c.getParsedResponse("GET", fmt.Sprintf("/repos/%s/%s/times", owner, repo), nil, nil, ×)
|
||||
resp, err := c.getParsedResponse("GET", fmt.Sprintf("/repos/%s/%s/times", owner, repo), nil, nil, ×)
|
||||
return times, resp, err
|
||||
}
|
||||
|
||||
// GetMyTrackedTimes list tracked times of the current user
|
||||
func (c *Client) GetMyTrackedTimes() ([]*TrackedTime, error) {
|
||||
func (c *Client) GetMyTrackedTimes() ([]*TrackedTime, *Response, error) {
|
||||
if err := c.CheckServerVersionConstraint(">=1.11.0"); err != nil {
|
||||
return nil, nil, err
|
||||
}
|
||||
times := make([]*TrackedTime, 0, 10)
|
||||
return times, c.getParsedResponse("GET", "/user/times", nil, nil, ×)
|
||||
resp, err := c.getParsedResponse("GET", "/user/times", nil, nil, ×)
|
||||
return times, resp, err
|
||||
}
|
||||
|
||||
// AddTimeOption options for adding time to an issue
|
||||
type AddTimeOption struct {
|
||||
// time in seconds
|
||||
Time int64 `json:"time" binding:"Required"`
|
||||
Time int64 `json:"time"`
|
||||
// optional
|
||||
Created time.Time `json:"created"`
|
||||
// optional
|
||||
User string `json:"user_name"`
|
||||
}
|
||||
|
||||
// Validate the AddTimeOption struct
|
||||
func (opt AddTimeOption) Validate() error {
|
||||
if opt.Time == 0 {
|
||||
return fmt.Errorf("no time to add")
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
// AddTime adds time to issue with the given index
|
||||
func (c *Client) AddTime(owner, repo string, index int64, opt AddTimeOption) (*TrackedTime, error) {
|
||||
func (c *Client) AddTime(owner, repo string, index int64, opt AddTimeOption) (*TrackedTime, *Response, error) {
|
||||
if err := c.CheckServerVersionConstraint(">=1.11.0"); err != nil {
|
||||
return nil, nil, err
|
||||
}
|
||||
if err := opt.Validate(); err != nil {
|
||||
return nil, nil, err
|
||||
}
|
||||
body, err := json.Marshal(&opt)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
return nil, nil, err
|
||||
}
|
||||
t := new(TrackedTime)
|
||||
return t, c.getParsedResponse("POST", fmt.Sprintf("/repos/%s/%s/issues/%d/times", owner, repo, index),
|
||||
resp, err := c.getParsedResponse("POST",
|
||||
fmt.Sprintf("/repos/%s/%s/issues/%d/times", owner, repo, index),
|
||||
jsonHeader, bytes.NewReader(body), t)
|
||||
return t, resp, err
|
||||
}
|
||||
|
||||
// ListTrackedTimesOptions options for listing repository's tracked times
|
||||
@ -70,20 +98,30 @@ type ListTrackedTimesOptions struct {
|
||||
}
|
||||
|
||||
// ListTrackedTimes list tracked times of a single issue for a given repository
|
||||
func (c *Client) ListTrackedTimes(owner, repo string, index int64, opt ListTrackedTimesOptions) ([]*TrackedTime, error) {
|
||||
func (c *Client) ListTrackedTimes(owner, repo string, index int64, opt ListTrackedTimesOptions) ([]*TrackedTime, *Response, error) {
|
||||
if err := c.CheckServerVersionConstraint(">=1.11.0"); err != nil {
|
||||
return nil, nil, err
|
||||
}
|
||||
opt.setDefaults()
|
||||
times := make([]*TrackedTime, 0, opt.PageSize)
|
||||
return times, c.getParsedResponse("GET", fmt.Sprintf("/repos/%s/%s/issues/%d/times?%s", owner, repo, index, opt.getURLQuery().Encode()), nil, nil, ×)
|
||||
resp, err := c.getParsedResponse("GET", fmt.Sprintf("/repos/%s/%s/issues/%d/times?%s", owner, repo, index, opt.getURLQuery().Encode()), nil, nil, ×)
|
||||
return times, resp, err
|
||||
}
|
||||
|
||||
// ResetIssueTime reset tracked time of a single issue for a given repository
|
||||
func (c *Client) ResetIssueTime(owner, repo string, index int64) error {
|
||||
_, err := c.getResponse("DELETE", fmt.Sprintf("/repos/%s/%s/issues/%d/times", owner, repo, index), nil, nil)
|
||||
return err
|
||||
func (c *Client) ResetIssueTime(owner, repo string, index int64) (*Response, error) {
|
||||
if err := c.CheckServerVersionConstraint(">=1.11.0"); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
_, resp, err := c.getResponse("DELETE", fmt.Sprintf("/repos/%s/%s/issues/%d/times", owner, repo, index), nil, nil)
|
||||
return resp, err
|
||||
}
|
||||
|
||||
// DeleteTime delete a specific tracked time by id of a single issue for a given repository
|
||||
func (c *Client) DeleteTime(owner, repo string, index, timeID int64) error {
|
||||
_, err := c.getResponse("DELETE", fmt.Sprintf("/repos/%s/%s/issues/%d/times/%d", owner, repo, index, timeID), nil, nil)
|
||||
return err
|
||||
func (c *Client) DeleteTime(owner, repo string, index, timeID int64) (*Response, error) {
|
||||
if err := c.CheckServerVersionConstraint(">=1.11.0"); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
_, resp, err := c.getResponse("DELETE", fmt.Sprintf("/repos/%s/%s/issues/%d/times/%d", owner, repo, index, timeID), nil, nil)
|
||||
return resp, err
|
||||
}
|
||||
|
111
vendor/code.gitea.io/sdk/gitea/notifications.go
generated
vendored
111
vendor/code.gitea.io/sdk/gitea/notifications.go
generated
vendored
@ -29,16 +29,31 @@ type NotificationSubject struct {
|
||||
Type string `json:"type" binding:"In(Issue,Pull,Commit)"`
|
||||
}
|
||||
|
||||
// NotifyStatus notification status type
|
||||
type NotifyStatus string
|
||||
|
||||
const (
|
||||
// NotifyStatusUnread was not read
|
||||
NotifyStatusUnread NotifyStatus = "unread"
|
||||
// NotifyStatusRead was already read by user
|
||||
NotifyStatusRead NotifyStatus = "read"
|
||||
// NotifyStatusPinned notification is pinned by user
|
||||
NotifyStatusPinned NotifyStatus = "pinned"
|
||||
)
|
||||
|
||||
// ListNotificationOptions represents the filter options
|
||||
type ListNotificationOptions struct {
|
||||
ListOptions
|
||||
Since time.Time
|
||||
Before time.Time
|
||||
Status []NotifyStatus
|
||||
}
|
||||
|
||||
// MarkNotificationOptions represents the filter options
|
||||
// MarkNotificationOptions represents the filter & modify options
|
||||
type MarkNotificationOptions struct {
|
||||
LastReadAt time.Time
|
||||
Status []NotifyStatus
|
||||
ToStatus NotifyStatus
|
||||
}
|
||||
|
||||
// QueryEncode encode options to url query
|
||||
@ -50,88 +65,134 @@ func (opt *ListNotificationOptions) QueryEncode() string {
|
||||
if !opt.Before.IsZero() {
|
||||
query.Add("before", opt.Before.Format(time.RFC3339))
|
||||
}
|
||||
for _, s := range opt.Status {
|
||||
query.Add("status-types", string(s))
|
||||
}
|
||||
return query.Encode()
|
||||
}
|
||||
|
||||
// Validate the CreateUserOption struct
|
||||
func (opt ListNotificationOptions) Validate(c *Client) error {
|
||||
if len(opt.Status) != 0 {
|
||||
return c.CheckServerVersionConstraint(">=1.12.3")
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
// QueryEncode encode options to url query
|
||||
func (opt *MarkNotificationOptions) QueryEncode() string {
|
||||
query := make(url.Values)
|
||||
if !opt.LastReadAt.IsZero() {
|
||||
query.Add("last_read_at", opt.LastReadAt.Format(time.RFC3339))
|
||||
}
|
||||
for _, s := range opt.Status {
|
||||
query.Add("status-types", string(s))
|
||||
}
|
||||
if len(opt.ToStatus) != 0 {
|
||||
query.Add("to-status", string(opt.ToStatus))
|
||||
}
|
||||
return query.Encode()
|
||||
}
|
||||
|
||||
// Validate the CreateUserOption struct
|
||||
func (opt MarkNotificationOptions) Validate(c *Client) error {
|
||||
if len(opt.Status) != 0 || len(opt.ToStatus) != 0 {
|
||||
return c.CheckServerVersionConstraint(">=1.12.3")
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
// CheckNotifications list users's notification threads
|
||||
func (c *Client) CheckNotifications() (int64, error) {
|
||||
func (c *Client) CheckNotifications() (int64, *Response, error) {
|
||||
if err := c.CheckServerVersionConstraint(">=1.12.0"); err != nil {
|
||||
return 0, err
|
||||
return 0, nil, err
|
||||
}
|
||||
new := struct {
|
||||
New int64 `json:"new"`
|
||||
}{}
|
||||
|
||||
return new.New, c.getParsedResponse("GET", "/notifications/new", jsonHeader, nil, &new)
|
||||
resp, err := c.getParsedResponse("GET", "/notifications/new", jsonHeader, nil, &new)
|
||||
return new.New, resp, err
|
||||
}
|
||||
|
||||
// GetNotification get notification thread by ID
|
||||
func (c *Client) GetNotification(id int64) (*NotificationThread, error) {
|
||||
func (c *Client) GetNotification(id int64) (*NotificationThread, *Response, error) {
|
||||
if err := c.CheckServerVersionConstraint(">=1.12.0"); err != nil {
|
||||
return nil, err
|
||||
return nil, nil, err
|
||||
}
|
||||
thread := new(NotificationThread)
|
||||
return thread, c.getParsedResponse("GET", fmt.Sprintf("/notifications/threads/%d", id), nil, nil, thread)
|
||||
resp, err := c.getParsedResponse("GET", fmt.Sprintf("/notifications/threads/%d", id), nil, nil, thread)
|
||||
return thread, resp, err
|
||||
}
|
||||
|
||||
// ReadNotification mark notification thread as read by ID
|
||||
func (c *Client) ReadNotification(id int64) error {
|
||||
// It optionally takes a second argument if status has to be set other than 'read'
|
||||
func (c *Client) ReadNotification(id int64, status ...NotifyStatus) (*Response, error) {
|
||||
if err := c.CheckServerVersionConstraint(">=1.12.0"); err != nil {
|
||||
return err
|
||||
return nil, err
|
||||
}
|
||||
_, err := c.getResponse("PATCH", fmt.Sprintf("/notifications/threads/%d", id), nil, nil)
|
||||
return err
|
||||
link := fmt.Sprintf("/notifications/threads/%d", id)
|
||||
if len(status) != 0 {
|
||||
link += fmt.Sprintf("?to-status=%s", status[0])
|
||||
}
|
||||
_, resp, err := c.getResponse("PATCH", link, nil, nil)
|
||||
return resp, err
|
||||
}
|
||||
|
||||
// ListNotifications list users's notification threads
|
||||
func (c *Client) ListNotifications(opt ListNotificationOptions) ([]*NotificationThread, error) {
|
||||
func (c *Client) ListNotifications(opt ListNotificationOptions) ([]*NotificationThread, *Response, error) {
|
||||
if err := c.CheckServerVersionConstraint(">=1.12.0"); err != nil {
|
||||
return nil, err
|
||||
return nil, nil, err
|
||||
}
|
||||
if err := opt.Validate(c); err != nil {
|
||||
return nil, nil, err
|
||||
}
|
||||
link, _ := url.Parse("/notifications")
|
||||
link.RawQuery = opt.QueryEncode()
|
||||
threads := make([]*NotificationThread, 0, 10)
|
||||
return threads, c.getParsedResponse("GET", link.String(), nil, nil, &threads)
|
||||
resp, err := c.getParsedResponse("GET", link.String(), nil, nil, &threads)
|
||||
return threads, resp, err
|
||||
}
|
||||
|
||||
// ReadNotifications mark notification threads as read
|
||||
func (c *Client) ReadNotifications(opt MarkNotificationOptions) error {
|
||||
func (c *Client) ReadNotifications(opt MarkNotificationOptions) (*Response, error) {
|
||||
if err := c.CheckServerVersionConstraint(">=1.12.0"); err != nil {
|
||||
return err
|
||||
return nil, err
|
||||
}
|
||||
if err := opt.Validate(c); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
link, _ := url.Parse("/notifications")
|
||||
link.RawQuery = opt.QueryEncode()
|
||||
_, err := c.getResponse("PUT", link.String(), nil, nil)
|
||||
return err
|
||||
_, resp, err := c.getResponse("PUT", link.String(), nil, nil)
|
||||
return resp, err
|
||||
}
|
||||
|
||||
// ListRepoNotifications list users's notification threads on a specific repo
|
||||
func (c *Client) ListRepoNotifications(owner, reponame string, opt ListNotificationOptions) ([]*NotificationThread, error) {
|
||||
func (c *Client) ListRepoNotifications(owner, reponame string, opt ListNotificationOptions) ([]*NotificationThread, *Response, error) {
|
||||
if err := c.CheckServerVersionConstraint(">=1.12.0"); err != nil {
|
||||
return nil, err
|
||||
return nil, nil, err
|
||||
}
|
||||
if err := opt.Validate(c); err != nil {
|
||||
return nil, nil, err
|
||||
}
|
||||
link, _ := url.Parse(fmt.Sprintf("/repos/%s/%s/notifications", owner, reponame))
|
||||
link.RawQuery = opt.QueryEncode()
|
||||
threads := make([]*NotificationThread, 0, 10)
|
||||
return threads, c.getParsedResponse("GET", link.String(), nil, nil, &threads)
|
||||
resp, err := c.getParsedResponse("GET", link.String(), nil, nil, &threads)
|
||||
return threads, resp, err
|
||||
}
|
||||
|
||||
// ReadRepoNotifications mark notification threads as read on a specific repo
|
||||
func (c *Client) ReadRepoNotifications(owner, reponame string, opt MarkNotificationOptions) error {
|
||||
func (c *Client) ReadRepoNotifications(owner, reponame string, opt MarkNotificationOptions) (*Response, error) {
|
||||
if err := c.CheckServerVersionConstraint(">=1.12.0"); err != nil {
|
||||
return err
|
||||
return nil, err
|
||||
}
|
||||
if err := opt.Validate(c); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
link, _ := url.Parse(fmt.Sprintf("/repos/%s/%s/notifications", owner, reponame))
|
||||
link.RawQuery = opt.QueryEncode()
|
||||
_, err := c.getResponse("PUT", link.String(), nil, nil)
|
||||
return err
|
||||
_, resp, err := c.getResponse("PUT", link.String(), nil, nil)
|
||||
return resp, err
|
||||
}
|
||||
|
50
vendor/code.gitea.io/sdk/gitea/oauth2.go
generated
vendored
50
vendor/code.gitea.io/sdk/gitea/oauth2.go
generated
vendored
@ -33,55 +33,59 @@ type CreateOauth2Option struct {
|
||||
}
|
||||
|
||||
// CreateOauth2 create an Oauth2 Application and returns a completed Oauth2 object.
|
||||
func (c *Client) CreateOauth2(opt CreateOauth2Option) (*Oauth2, error) {
|
||||
if e := c.CheckServerVersionConstraint(">=1.12.0"); e != nil {
|
||||
return nil, e
|
||||
func (c *Client) CreateOauth2(opt CreateOauth2Option) (*Oauth2, *Response, error) {
|
||||
if err := c.CheckServerVersionConstraint(">=1.12.0"); err != nil {
|
||||
return nil, nil, err
|
||||
}
|
||||
body, err := json.Marshal(&opt)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
return nil, nil, err
|
||||
}
|
||||
oauth := new(Oauth2)
|
||||
return oauth, c.getParsedResponse("POST", "/user/applications/oauth2", jsonHeader, bytes.NewReader(body), oauth)
|
||||
resp, err := c.getParsedResponse("POST", "/user/applications/oauth2", jsonHeader, bytes.NewReader(body), oauth)
|
||||
return oauth, resp, err
|
||||
}
|
||||
|
||||
// UpdateOauth2 a specific Oauth2 Application by ID and return a completed Oauth2 object.
|
||||
func (c *Client) UpdateOauth2(oauth2id int64, opt CreateOauth2Option) (*Oauth2, error) {
|
||||
if e := c.CheckServerVersionConstraint(">=1.12.0"); e != nil {
|
||||
return nil, e
|
||||
func (c *Client) UpdateOauth2(oauth2id int64, opt CreateOauth2Option) (*Oauth2, *Response, error) {
|
||||
if err := c.CheckServerVersionConstraint(">=1.12.0"); err != nil {
|
||||
return nil, nil, err
|
||||
}
|
||||
body, err := json.Marshal(&opt)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
return nil, nil, err
|
||||
}
|
||||
oauth := new(Oauth2)
|
||||
return oauth, c.getParsedResponse("PATCH", fmt.Sprintf("/user/applications/oauth2/%d", oauth2id), jsonHeader, bytes.NewReader(body), oauth)
|
||||
resp, err := c.getParsedResponse("PATCH", fmt.Sprintf("/user/applications/oauth2/%d", oauth2id), jsonHeader, bytes.NewReader(body), oauth)
|
||||
return oauth, resp, err
|
||||
}
|
||||
|
||||
// GetOauth2 a specific Oauth2 Application by ID.
|
||||
func (c *Client) GetOauth2(oauth2id int64) (*Oauth2, error) {
|
||||
if e := c.CheckServerVersionConstraint(">=1.12.0"); e != nil {
|
||||
return nil, e
|
||||
func (c *Client) GetOauth2(oauth2id int64) (*Oauth2, *Response, error) {
|
||||
if err := c.CheckServerVersionConstraint(">=1.12.0"); err != nil {
|
||||
return nil, nil, err
|
||||
}
|
||||
oauth2s := &Oauth2{}
|
||||
return oauth2s, c.getParsedResponse("GET", fmt.Sprintf("/user/applications/oauth2/%d", oauth2id), nil, nil, &oauth2s)
|
||||
resp, err := c.getParsedResponse("GET", fmt.Sprintf("/user/applications/oauth2/%d", oauth2id), nil, nil, &oauth2s)
|
||||
return oauth2s, resp, err
|
||||
}
|
||||
|
||||
// ListOauth2 all of your Oauth2 Applications.
|
||||
func (c *Client) ListOauth2(opt ListOauth2Option) ([]*Oauth2, error) {
|
||||
if e := c.CheckServerVersionConstraint(">=1.12.0"); e != nil {
|
||||
return nil, e
|
||||
func (c *Client) ListOauth2(opt ListOauth2Option) ([]*Oauth2, *Response, error) {
|
||||
if err := c.CheckServerVersionConstraint(">=1.12.0"); err != nil {
|
||||
return nil, nil, err
|
||||
}
|
||||
opt.setDefaults()
|
||||
oauth2s := make([]*Oauth2, 0, opt.PageSize)
|
||||
return oauth2s, c.getParsedResponse("GET", fmt.Sprintf("/user/applications/oauth2?%s", opt.getURLQuery().Encode()), nil, nil, &oauth2s)
|
||||
resp, err := c.getParsedResponse("GET", fmt.Sprintf("/user/applications/oauth2?%s", opt.getURLQuery().Encode()), nil, nil, &oauth2s)
|
||||
return oauth2s, resp, err
|
||||
}
|
||||
|
||||
// DeleteOauth2 delete an Oauth2 application by ID
|
||||
func (c *Client) DeleteOauth2(oauth2id int64) error {
|
||||
if e := c.CheckServerVersionConstraint(">=1.12.0"); e != nil {
|
||||
return e
|
||||
func (c *Client) DeleteOauth2(oauth2id int64) (*Response, error) {
|
||||
if err := c.CheckServerVersionConstraint(">=1.12.0"); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
_, err := c.getResponse("DELETE", fmt.Sprintf("/user/applications/oauth2/%d", oauth2id), nil, nil)
|
||||
return err
|
||||
_, resp, err := c.getResponse("DELETE", fmt.Sprintf("/user/applications/oauth2/%d", oauth2id), nil, nil)
|
||||
return resp, err
|
||||
}
|
||||
|
90
vendor/code.gitea.io/sdk/gitea/org.go
generated
vendored
90
vendor/code.gitea.io/sdk/gitea/org.go
generated
vendored
@ -23,51 +23,86 @@ type Organization struct {
|
||||
Visibility string `json:"visibility"`
|
||||
}
|
||||
|
||||
// VisibleType defines the visibility
|
||||
type VisibleType string
|
||||
|
||||
const (
|
||||
// VisibleTypePublic Visible for everyone
|
||||
VisibleTypePublic VisibleType = "public"
|
||||
|
||||
// VisibleTypeLimited Visible for every connected user
|
||||
VisibleTypeLimited VisibleType = "limited"
|
||||
|
||||
// VisibleTypePrivate Visible only for organization's members
|
||||
VisibleTypePrivate VisibleType = "private"
|
||||
)
|
||||
|
||||
// ListOrgsOptions options for listing organizations
|
||||
type ListOrgsOptions struct {
|
||||
ListOptions
|
||||
}
|
||||
|
||||
// ListMyOrgs list all of current user's organizations
|
||||
func (c *Client) ListMyOrgs(opt ListOrgsOptions) ([]*Organization, error) {
|
||||
func (c *Client) ListMyOrgs(opt ListOrgsOptions) ([]*Organization, *Response, error) {
|
||||
opt.setDefaults()
|
||||
orgs := make([]*Organization, 0, opt.PageSize)
|
||||
return orgs, c.getParsedResponse("GET", fmt.Sprintf("/user/orgs?%s", opt.getURLQuery().Encode()), nil, nil, &orgs)
|
||||
resp, err := c.getParsedResponse("GET", fmt.Sprintf("/user/orgs?%s", opt.getURLQuery().Encode()), nil, nil, &orgs)
|
||||
return orgs, resp, err
|
||||
}
|
||||
|
||||
// ListUserOrgs list all of some user's organizations
|
||||
func (c *Client) ListUserOrgs(user string, opt ListOrgsOptions) ([]*Organization, error) {
|
||||
func (c *Client) ListUserOrgs(user string, opt ListOrgsOptions) ([]*Organization, *Response, error) {
|
||||
opt.setDefaults()
|
||||
orgs := make([]*Organization, 0, opt.PageSize)
|
||||
return orgs, c.getParsedResponse("GET", fmt.Sprintf("/users/%s/orgs?%s", user, opt.getURLQuery().Encode()), nil, nil, &orgs)
|
||||
resp, err := c.getParsedResponse("GET", fmt.Sprintf("/users/%s/orgs?%s", user, opt.getURLQuery().Encode()), nil, nil, &orgs)
|
||||
return orgs, resp, err
|
||||
}
|
||||
|
||||
// GetOrg get one organization by name
|
||||
func (c *Client) GetOrg(orgname string) (*Organization, error) {
|
||||
func (c *Client) GetOrg(orgname string) (*Organization, *Response, error) {
|
||||
org := new(Organization)
|
||||
return org, c.getParsedResponse("GET", fmt.Sprintf("/orgs/%s", orgname), nil, nil, org)
|
||||
resp, err := c.getParsedResponse("GET", fmt.Sprintf("/orgs/%s", orgname), nil, nil, org)
|
||||
return org, resp, err
|
||||
}
|
||||
|
||||
// CreateOrgOption options for creating an organization
|
||||
type CreateOrgOption struct {
|
||||
UserName string `json:"username"`
|
||||
Name string `json:"username"`
|
||||
FullName string `json:"full_name"`
|
||||
Description string `json:"description"`
|
||||
Website string `json:"website"`
|
||||
Location string `json:"location"`
|
||||
// possible values are `public` (default), `limited` or `private`
|
||||
// enum: public,limited,private
|
||||
Visibility string `json:"visibility"`
|
||||
Visibility VisibleType `json:"visibility"`
|
||||
}
|
||||
|
||||
// checkVisibilityOpt check if mode exist
|
||||
func checkVisibilityOpt(v VisibleType) bool {
|
||||
return v == VisibleTypePublic || v == VisibleTypeLimited || v == VisibleTypePrivate
|
||||
}
|
||||
|
||||
// Validate the CreateOrgOption struct
|
||||
func (opt CreateOrgOption) Validate() error {
|
||||
if len(opt.Name) == 0 {
|
||||
return fmt.Errorf("empty org name")
|
||||
}
|
||||
if len(opt.Visibility) != 0 && !checkVisibilityOpt(opt.Visibility) {
|
||||
return fmt.Errorf("infalid bisibility option")
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
// CreateOrg creates an organization
|
||||
func (c *Client) CreateOrg(opt CreateOrgOption) (*Organization, error) {
|
||||
func (c *Client) CreateOrg(opt CreateOrgOption) (*Organization, *Response, error) {
|
||||
if err := opt.Validate(); err != nil {
|
||||
return nil, nil, err
|
||||
}
|
||||
body, err := json.Marshal(&opt)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
return nil, nil, err
|
||||
}
|
||||
org := new(Organization)
|
||||
return org, c.getParsedResponse("POST", "/orgs", jsonHeader, bytes.NewReader(body), org)
|
||||
resp, err := c.getParsedResponse("POST", "/orgs", jsonHeader, bytes.NewReader(body), org)
|
||||
return org, resp, err
|
||||
}
|
||||
|
||||
// EditOrgOption options for editing an organization
|
||||
@ -76,23 +111,32 @@ type EditOrgOption struct {
|
||||
Description string `json:"description"`
|
||||
Website string `json:"website"`
|
||||
Location string `json:"location"`
|
||||
// possible values are `public`, `limited` or `private`
|
||||
// enum: public,limited,private
|
||||
Visibility string `json:"visibility"`
|
||||
Visibility VisibleType `json:"visibility"`
|
||||
}
|
||||
|
||||
// Validate the EditOrgOption struct
|
||||
func (opt EditOrgOption) Validate() error {
|
||||
if len(opt.Visibility) != 0 && !checkVisibilityOpt(opt.Visibility) {
|
||||
return fmt.Errorf("infalid bisibility option")
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
// EditOrg modify one organization via options
|
||||
func (c *Client) EditOrg(orgname string, opt EditOrgOption) error {
|
||||
func (c *Client) EditOrg(orgname string, opt EditOrgOption) (*Response, error) {
|
||||
if err := opt.Validate(); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
body, err := json.Marshal(&opt)
|
||||
if err != nil {
|
||||
return err
|
||||
return nil, err
|
||||
}
|
||||
_, err = c.getResponse("PATCH", fmt.Sprintf("/orgs/%s", orgname), jsonHeader, bytes.NewReader(body))
|
||||
return err
|
||||
_, resp, err := c.getResponse("PATCH", fmt.Sprintf("/orgs/%s", orgname), jsonHeader, bytes.NewReader(body))
|
||||
return resp, err
|
||||
}
|
||||
|
||||
// DeleteOrg deletes an organization
|
||||
func (c *Client) DeleteOrg(orgname string) error {
|
||||
_, err := c.getResponse("DELETE", fmt.Sprintf("/orgs/%s", orgname), nil, nil)
|
||||
return err
|
||||
func (c *Client) DeleteOrg(orgname string) (*Response, error) {
|
||||
_, resp, err := c.getResponse("DELETE", fmt.Sprintf("/orgs/%s", orgname), jsonHeader, nil)
|
||||
return resp, err
|
||||
}
|
||||
|
55
vendor/code.gitea.io/sdk/gitea/org_member.go
generated
vendored
55
vendor/code.gitea.io/sdk/gitea/org_member.go
generated
vendored
@ -11,9 +11,9 @@ import (
|
||||
)
|
||||
|
||||
// DeleteOrgMembership remove a member from an organization
|
||||
func (c *Client) DeleteOrgMembership(org, user string) error {
|
||||
_, err := c.getResponse("DELETE", fmt.Sprintf("/orgs/%s/members/%s", url.PathEscape(org), url.PathEscape(user)), nil, nil)
|
||||
return err
|
||||
func (c *Client) DeleteOrgMembership(org, user string) (*Response, error) {
|
||||
_, resp, err := c.getResponse("DELETE", fmt.Sprintf("/orgs/%s/members/%s", url.PathEscape(org), url.PathEscape(user)), nil, nil)
|
||||
return resp, err
|
||||
}
|
||||
|
||||
// ListOrgMembershipOption list OrgMembership options
|
||||
@ -22,77 +22,80 @@ type ListOrgMembershipOption struct {
|
||||
}
|
||||
|
||||
// ListOrgMembership list an organization's members
|
||||
func (c *Client) ListOrgMembership(org string, opt ListOrgMembershipOption) ([]*User, error) {
|
||||
func (c *Client) ListOrgMembership(org string, opt ListOrgMembershipOption) ([]*User, *Response, error) {
|
||||
opt.setDefaults()
|
||||
users := make([]*User, 0, opt.PageSize)
|
||||
|
||||
link, _ := url.Parse(fmt.Sprintf("/orgs/%s/members", url.PathEscape(org)))
|
||||
link.RawQuery = opt.getURLQuery().Encode()
|
||||
return users, c.getParsedResponse("GET", link.String(), jsonHeader, nil, &users)
|
||||
resp, err := c.getParsedResponse("GET", link.String(), jsonHeader, nil, &users)
|
||||
return users, resp, err
|
||||
}
|
||||
|
||||
// ListPublicOrgMembership list an organization's members
|
||||
func (c *Client) ListPublicOrgMembership(org string, opt ListOrgMembershipOption) ([]*User, error) {
|
||||
func (c *Client) ListPublicOrgMembership(org string, opt ListOrgMembershipOption) ([]*User, *Response, error) {
|
||||
opt.setDefaults()
|
||||
users := make([]*User, 0, opt.PageSize)
|
||||
|
||||
link, _ := url.Parse(fmt.Sprintf("/orgs/%s/public_members", url.PathEscape(org)))
|
||||
link.RawQuery = opt.getURLQuery().Encode()
|
||||
return users, c.getParsedResponse("GET", link.String(), jsonHeader, nil, &users)
|
||||
resp, err := c.getParsedResponse("GET", link.String(), jsonHeader, nil, &users)
|
||||
return users, resp, err
|
||||
}
|
||||
|
||||
// CheckOrgMembership Check if a user is a member of an organization
|
||||
func (c *Client) CheckOrgMembership(org, user string) (bool, error) {
|
||||
status, err := c.getStatusCode("GET", fmt.Sprintf("/orgs/%s/members/%s", url.PathEscape(org), url.PathEscape(user)), nil, nil)
|
||||
func (c *Client) CheckOrgMembership(org, user string) (bool, *Response, error) {
|
||||
status, resp, err := c.getStatusCode("GET", fmt.Sprintf("/orgs/%s/members/%s", url.PathEscape(org), url.PathEscape(user)), nil, nil)
|
||||
if err != nil {
|
||||
return false, err
|
||||
return false, resp, err
|
||||
}
|
||||
switch status {
|
||||
case http.StatusNoContent:
|
||||
return true, nil
|
||||
return true, resp, nil
|
||||
case http.StatusNotFound:
|
||||
return false, nil
|
||||
return false, resp, nil
|
||||
default:
|
||||
return false, fmt.Errorf("unexpected Status: %d", status)
|
||||
return false, resp, fmt.Errorf("unexpected Status: %d", status)
|
||||
}
|
||||
}
|
||||
|
||||
// CheckPublicOrgMembership Check if a user is a member of an organization
|
||||
func (c *Client) CheckPublicOrgMembership(org, user string) (bool, error) {
|
||||
status, err := c.getStatusCode("GET", fmt.Sprintf("/orgs/%s/public_members/%s", url.PathEscape(org), url.PathEscape(user)), nil, nil)
|
||||
func (c *Client) CheckPublicOrgMembership(org, user string) (bool, *Response, error) {
|
||||
status, resp, err := c.getStatusCode("GET", fmt.Sprintf("/orgs/%s/public_members/%s", url.PathEscape(org), url.PathEscape(user)), nil, nil)
|
||||
if err != nil {
|
||||
return false, err
|
||||
return false, resp, err
|
||||
}
|
||||
switch status {
|
||||
case http.StatusNoContent:
|
||||
return true, nil
|
||||
return true, resp, nil
|
||||
case http.StatusNotFound:
|
||||
return false, nil
|
||||
return false, resp, nil
|
||||
default:
|
||||
return false, fmt.Errorf("unexpected Status: %d", status)
|
||||
return false, resp, fmt.Errorf("unexpected Status: %d", status)
|
||||
}
|
||||
}
|
||||
|
||||
// SetPublicOrgMembership publicize/conceal a user's membership
|
||||
func (c *Client) SetPublicOrgMembership(org, user string, visible bool) error {
|
||||
func (c *Client) SetPublicOrgMembership(org, user string, visible bool) (*Response, error) {
|
||||
var (
|
||||
status int
|
||||
err error
|
||||
resp *Response
|
||||
)
|
||||
if visible {
|
||||
status, err = c.getStatusCode("PUT", fmt.Sprintf("/orgs/%s/public_members/%s", url.PathEscape(org), url.PathEscape(user)), nil, nil)
|
||||
status, resp, err = c.getStatusCode("PUT", fmt.Sprintf("/orgs/%s/public_members/%s", url.PathEscape(org), url.PathEscape(user)), nil, nil)
|
||||
} else {
|
||||
status, err = c.getStatusCode("DELETE", fmt.Sprintf("/orgs/%s/public_members/%s", url.PathEscape(org), url.PathEscape(user)), nil, nil)
|
||||
status, resp, err = c.getStatusCode("DELETE", fmt.Sprintf("/orgs/%s/public_members/%s", url.PathEscape(org), url.PathEscape(user)), nil, nil)
|
||||
}
|
||||
if err != nil {
|
||||
return err
|
||||
return resp, err
|
||||
}
|
||||
switch status {
|
||||
case http.StatusNoContent:
|
||||
return nil
|
||||
return resp, nil
|
||||
case http.StatusNotFound:
|
||||
return fmt.Errorf("forbidden")
|
||||
return resp, fmt.Errorf("forbidden")
|
||||
default:
|
||||
return fmt.Errorf("unexpected Status: %d", status)
|
||||
return resp, fmt.Errorf("unexpected Status: %d", status)
|
||||
}
|
||||
}
|
||||
|
136
vendor/code.gitea.io/sdk/gitea/org_team.go
generated
vendored
136
vendor/code.gitea.io/sdk/gitea/org_team.go
generated
vendored
@ -16,8 +16,9 @@ type Team struct {
|
||||
Name string `json:"name"`
|
||||
Description string `json:"description"`
|
||||
Organization *Organization `json:"organization"`
|
||||
// enum: none,read,write,admin,owner
|
||||
Permission string `json:"permission"`
|
||||
Permission AccessMode `json:"permission"`
|
||||
CanCreateOrgRepo bool `json:"can_create_org_repo"`
|
||||
IncludesAllRepositories bool `json:"includes_all_repositories"`
|
||||
// example: ["repo.code","repo.issues","repo.ext_issues","repo.wiki","repo.pulls","repo.releases","repo.ext_wiki"]
|
||||
Units []string `json:"units"`
|
||||
}
|
||||
@ -28,69 +29,119 @@ type ListTeamsOptions struct {
|
||||
}
|
||||
|
||||
// ListOrgTeams lists all teams of an organization
|
||||
func (c *Client) ListOrgTeams(org string, opt ListTeamsOptions) ([]*Team, error) {
|
||||
func (c *Client) ListOrgTeams(org string, opt ListTeamsOptions) ([]*Team, *Response, error) {
|
||||
opt.setDefaults()
|
||||
teams := make([]*Team, 0, opt.PageSize)
|
||||
return teams, c.getParsedResponse("GET", fmt.Sprintf("/orgs/%s/teams?%s", org, opt.getURLQuery().Encode()), nil, nil, &teams)
|
||||
resp, err := c.getParsedResponse("GET", fmt.Sprintf("/orgs/%s/teams?%s", org, opt.getURLQuery().Encode()), nil, nil, &teams)
|
||||
return teams, resp, err
|
||||
}
|
||||
|
||||
// ListMyTeams lists all the teams of the current user
|
||||
func (c *Client) ListMyTeams(opt *ListTeamsOptions) ([]*Team, error) {
|
||||
func (c *Client) ListMyTeams(opt *ListTeamsOptions) ([]*Team, *Response, error) {
|
||||
opt.setDefaults()
|
||||
teams := make([]*Team, 0, opt.PageSize)
|
||||
return teams, c.getParsedResponse("GET", fmt.Sprintf("/user/teams?%s", opt.getURLQuery().Encode()), nil, nil, &teams)
|
||||
resp, err := c.getParsedResponse("GET", fmt.Sprintf("/user/teams?%s", opt.getURLQuery().Encode()), nil, nil, &teams)
|
||||
return teams, resp, err
|
||||
}
|
||||
|
||||
// GetTeam gets a team by ID
|
||||
func (c *Client) GetTeam(id int64) (*Team, error) {
|
||||
func (c *Client) GetTeam(id int64) (*Team, *Response, error) {
|
||||
t := new(Team)
|
||||
return t, c.getParsedResponse("GET", fmt.Sprintf("/teams/%d", id), nil, nil, t)
|
||||
resp, err := c.getParsedResponse("GET", fmt.Sprintf("/teams/%d", id), nil, nil, t)
|
||||
return t, resp, err
|
||||
}
|
||||
|
||||
// CreateTeamOption options for creating a team
|
||||
type CreateTeamOption struct {
|
||||
Name string `json:"name"`
|
||||
Description string `json:"description"`
|
||||
// enum: read,write,admin
|
||||
Permission string `json:"permission"`
|
||||
Permission AccessMode `json:"permission"`
|
||||
CanCreateOrgRepo bool `json:"can_create_org_repo"`
|
||||
IncludesAllRepositories bool `json:"includes_all_repositories"`
|
||||
// example: ["repo.code","repo.issues","repo.ext_issues","repo.wiki","repo.pulls","repo.releases","repo.ext_wiki"]
|
||||
Units []string `json:"units"`
|
||||
}
|
||||
|
||||
// Validate the CreateTeamOption struct
|
||||
func (opt CreateTeamOption) Validate() error {
|
||||
if opt.Permission == AccessModeOwner {
|
||||
opt.Permission = AccessModeAdmin
|
||||
} else if opt.Permission != AccessModeRead && opt.Permission != AccessModeWrite && opt.Permission != AccessModeAdmin {
|
||||
return fmt.Errorf("permission mode invalid")
|
||||
}
|
||||
if len(opt.Name) == 0 {
|
||||
return fmt.Errorf("name required")
|
||||
}
|
||||
if len(opt.Name) > 30 {
|
||||
return fmt.Errorf("name to long")
|
||||
}
|
||||
if len(opt.Description) > 255 {
|
||||
return fmt.Errorf("description to long")
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
// CreateTeam creates a team for an organization
|
||||
func (c *Client) CreateTeam(org string, opt CreateTeamOption) (*Team, error) {
|
||||
func (c *Client) CreateTeam(org string, opt CreateTeamOption) (*Team, *Response, error) {
|
||||
if err := opt.Validate(); err != nil {
|
||||
return nil, nil, err
|
||||
}
|
||||
body, err := json.Marshal(&opt)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
return nil, nil, err
|
||||
}
|
||||
t := new(Team)
|
||||
return t, c.getParsedResponse("POST", fmt.Sprintf("/orgs/%s/teams", org), jsonHeader, bytes.NewReader(body), t)
|
||||
resp, err := c.getParsedResponse("POST", fmt.Sprintf("/orgs/%s/teams", org), jsonHeader, bytes.NewReader(body), t)
|
||||
return t, resp, err
|
||||
}
|
||||
|
||||
// EditTeamOption options for editing a team
|
||||
type EditTeamOption struct {
|
||||
Name string `json:"name"`
|
||||
Description string `json:"description"`
|
||||
// enum: read,write,admin
|
||||
Permission string `json:"permission"`
|
||||
Description *string `json:"description"`
|
||||
Permission AccessMode `json:"permission"`
|
||||
CanCreateOrgRepo *bool `json:"can_create_org_repo"`
|
||||
IncludesAllRepositories *bool `json:"includes_all_repositories"`
|
||||
// example: ["repo.code","repo.issues","repo.ext_issues","repo.wiki","repo.pulls","repo.releases","repo.ext_wiki"]
|
||||
Units []string `json:"units"`
|
||||
}
|
||||
|
||||
// Validate the EditTeamOption struct
|
||||
func (opt EditTeamOption) Validate() error {
|
||||
if opt.Permission == AccessModeOwner {
|
||||
opt.Permission = AccessModeAdmin
|
||||
} else if opt.Permission != AccessModeRead && opt.Permission != AccessModeWrite && opt.Permission != AccessModeAdmin {
|
||||
return fmt.Errorf("permission mode invalid")
|
||||
}
|
||||
if len(opt.Name) == 0 {
|
||||
return fmt.Errorf("name required")
|
||||
}
|
||||
if len(opt.Name) > 30 {
|
||||
return fmt.Errorf("name to long")
|
||||
}
|
||||
if opt.Description != nil && len(*opt.Description) > 255 {
|
||||
return fmt.Errorf("description to long")
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
// EditTeam edits a team of an organization
|
||||
func (c *Client) EditTeam(id int64, opt EditTeamOption) error {
|
||||
func (c *Client) EditTeam(id int64, opt EditTeamOption) (*Response, error) {
|
||||
if err := opt.Validate(); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
body, err := json.Marshal(&opt)
|
||||
if err != nil {
|
||||
return err
|
||||
return nil, err
|
||||
}
|
||||
_, err = c.getResponse("PATCH", fmt.Sprintf("/teams/%d", id), jsonHeader, bytes.NewReader(body))
|
||||
return err
|
||||
_, resp, err := c.getResponse("PATCH", fmt.Sprintf("/teams/%d", id), jsonHeader, bytes.NewReader(body))
|
||||
return resp, err
|
||||
}
|
||||
|
||||
// DeleteTeam deletes a team of an organization
|
||||
func (c *Client) DeleteTeam(id int64) error {
|
||||
_, err := c.getResponse("DELETE", fmt.Sprintf("/teams/%d", id), nil, nil)
|
||||
return err
|
||||
func (c *Client) DeleteTeam(id int64) (*Response, error) {
|
||||
_, resp, err := c.getResponse("DELETE", fmt.Sprintf("/teams/%d", id), nil, nil)
|
||||
return resp, err
|
||||
}
|
||||
|
||||
// ListTeamMembersOptions options for listing team's members
|
||||
@ -99,28 +150,30 @@ type ListTeamMembersOptions struct {
|
||||
}
|
||||
|
||||
// ListTeamMembers lists all members of a team
|
||||
func (c *Client) ListTeamMembers(id int64, opt ListTeamMembersOptions) ([]*User, error) {
|
||||
func (c *Client) ListTeamMembers(id int64, opt ListTeamMembersOptions) ([]*User, *Response, error) {
|
||||
opt.setDefaults()
|
||||
members := make([]*User, 0, opt.PageSize)
|
||||
return members, c.getParsedResponse("GET", fmt.Sprintf("/teams/%d/members?%s", id, opt.getURLQuery().Encode()), nil, nil, &members)
|
||||
resp, err := c.getParsedResponse("GET", fmt.Sprintf("/teams/%d/members?%s", id, opt.getURLQuery().Encode()), nil, nil, &members)
|
||||
return members, resp, err
|
||||
}
|
||||
|
||||
// GetTeamMember gets a member of a team
|
||||
func (c *Client) GetTeamMember(id int64, user string) (*User, error) {
|
||||
func (c *Client) GetTeamMember(id int64, user string) (*User, *Response, error) {
|
||||
m := new(User)
|
||||
return m, c.getParsedResponse("GET", fmt.Sprintf("/teams/%d/members/%s", id, user), nil, nil, m)
|
||||
resp, err := c.getParsedResponse("GET", fmt.Sprintf("/teams/%d/members/%s", id, user), nil, nil, m)
|
||||
return m, resp, err
|
||||
}
|
||||
|
||||
// AddTeamMember adds a member to a team
|
||||
func (c *Client) AddTeamMember(id int64, user string) error {
|
||||
_, err := c.getResponse("PUT", fmt.Sprintf("/teams/%d/members/%s", id, user), nil, nil)
|
||||
return err
|
||||
func (c *Client) AddTeamMember(id int64, user string) (*Response, error) {
|
||||
_, resp, err := c.getResponse("PUT", fmt.Sprintf("/teams/%d/members/%s", id, user), nil, nil)
|
||||
return resp, err
|
||||
}
|
||||
|
||||
// RemoveTeamMember removes a member from a team
|
||||
func (c *Client) RemoveTeamMember(id int64, user string) error {
|
||||
_, err := c.getResponse("DELETE", fmt.Sprintf("/teams/%d/members/%s", id, user), nil, nil)
|
||||
return err
|
||||
func (c *Client) RemoveTeamMember(id int64, user string) (*Response, error) {
|
||||
_, resp, err := c.getResponse("DELETE", fmt.Sprintf("/teams/%d/members/%s", id, user), nil, nil)
|
||||
return resp, err
|
||||
}
|
||||
|
||||
// ListTeamRepositoriesOptions options for listing team's repositories
|
||||
@ -129,20 +182,21 @@ type ListTeamRepositoriesOptions struct {
|
||||
}
|
||||
|
||||
// ListTeamRepositories lists all repositories of a team
|
||||
func (c *Client) ListTeamRepositories(id int64, opt ListTeamRepositoriesOptions) ([]*Repository, error) {
|
||||
func (c *Client) ListTeamRepositories(id int64, opt ListTeamRepositoriesOptions) ([]*Repository, *Response, error) {
|
||||
opt.setDefaults()
|
||||
repos := make([]*Repository, 0, opt.PageSize)
|
||||
return repos, c.getParsedResponse("GET", fmt.Sprintf("/teams/%d/repos?%s", id, opt.getURLQuery().Encode()), nil, nil, &repos)
|
||||
resp, err := c.getParsedResponse("GET", fmt.Sprintf("/teams/%d/repos?%s", id, opt.getURLQuery().Encode()), nil, nil, &repos)
|
||||
return repos, resp, err
|
||||
}
|
||||
|
||||
// AddTeamRepository adds a repository to a team
|
||||
func (c *Client) AddTeamRepository(id int64, org, repo string) error {
|
||||
_, err := c.getResponse("PUT", fmt.Sprintf("/teams/%d/repos/%s/%s", id, org, repo), nil, nil)
|
||||
return err
|
||||
func (c *Client) AddTeamRepository(id int64, org, repo string) (*Response, error) {
|
||||
_, resp, err := c.getResponse("PUT", fmt.Sprintf("/teams/%d/repos/%s/%s", id, org, repo), nil, nil)
|
||||
return resp, err
|
||||
}
|
||||
|
||||
// RemoveTeamRepository removes a repository from a team
|
||||
func (c *Client) RemoveTeamRepository(id int64, org, repo string) error {
|
||||
_, err := c.getResponse("DELETE", fmt.Sprintf("/teams/%d/repos/%s/%s", id, org, repo), nil, nil)
|
||||
return err
|
||||
func (c *Client) RemoveTeamRepository(id int64, org, repo string) (*Response, error) {
|
||||
_, resp, err := c.getResponse("DELETE", fmt.Sprintf("/teams/%d/repos/%s/%s", id, org, repo), nil, nil)
|
||||
return resp, err
|
||||
}
|
||||
|
27
vendor/code.gitea.io/sdk/gitea/org_type.go
generated
vendored
27
vendor/code.gitea.io/sdk/gitea/org_type.go
generated
vendored
@ -1,27 +0,0 @@
|
||||
// Copyright 2019 The Gitea Authors. All rights reserved.
|
||||
// Use of this source code is governed by a MIT-style
|
||||
// license that can be found in the LICENSE file.
|
||||
|
||||
package gitea
|
||||
|
||||
// VisibleType defines the visibility (Organization only)
|
||||
type VisibleType int
|
||||
|
||||
const (
|
||||
// VisibleTypePublic Visible for everyone
|
||||
VisibleTypePublic VisibleType = iota
|
||||
|
||||
// VisibleTypeLimited Visible for every connected user
|
||||
VisibleTypeLimited
|
||||
|
||||
// VisibleTypePrivate Visible only for organization's members
|
||||
VisibleTypePrivate
|
||||
)
|
||||
|
||||
// ExtractKeysFromMapString provides a slice of keys from map
|
||||
func ExtractKeysFromMapString(in map[string]VisibleType) (keys []string) {
|
||||
for k := range in {
|
||||
keys = append(keys, k)
|
||||
}
|
||||
return
|
||||
}
|
99
vendor/code.gitea.io/sdk/gitea/pull.go
generated
vendored
99
vendor/code.gitea.io/sdk/gitea/pull.go
generated
vendored
@ -10,6 +10,7 @@ import (
|
||||
"encoding/json"
|
||||
"fmt"
|
||||
"net/url"
|
||||
"strings"
|
||||
"time"
|
||||
)
|
||||
|
||||
@ -35,6 +36,7 @@ type PullRequest struct {
|
||||
Assignee *User `json:"assignee"`
|
||||
Assignees []*User `json:"assignees"`
|
||||
State StateType `json:"state"`
|
||||
IsLocked bool `json:"is_locked"`
|
||||
Comments int `json:"comments"`
|
||||
|
||||
HTMLURL string `json:"html_url"`
|
||||
@ -96,19 +98,21 @@ func (opt *ListPullRequestsOptions) QueryEncode() string {
|
||||
}
|
||||
|
||||
// ListRepoPullRequests list PRs of one repository
|
||||
func (c *Client) ListRepoPullRequests(owner, repo string, opt ListPullRequestsOptions) ([]*PullRequest, error) {
|
||||
func (c *Client) ListRepoPullRequests(owner, repo string, opt ListPullRequestsOptions) ([]*PullRequest, *Response, error) {
|
||||
opt.setDefaults()
|
||||
prs := make([]*PullRequest, 0, opt.PageSize)
|
||||
|
||||
link, _ := url.Parse(fmt.Sprintf("/repos/%s/%s/pulls", owner, repo))
|
||||
link.RawQuery = opt.QueryEncode()
|
||||
return prs, c.getParsedResponse("GET", link.String(), jsonHeader, nil, &prs)
|
||||
resp, err := c.getParsedResponse("GET", link.String(), jsonHeader, nil, &prs)
|
||||
return prs, resp, err
|
||||
}
|
||||
|
||||
// GetPullRequest get information of one PR
|
||||
func (c *Client) GetPullRequest(owner, repo string, index int64) (*PullRequest, error) {
|
||||
func (c *Client) GetPullRequest(owner, repo string, index int64) (*PullRequest, *Response, error) {
|
||||
pr := new(PullRequest)
|
||||
return pr, c.getParsedResponse("GET", fmt.Sprintf("/repos/%s/%s/pulls/%d", owner, repo, index), nil, nil, pr)
|
||||
resp, err := c.getParsedResponse("GET", fmt.Sprintf("/repos/%s/%s/pulls/%d", owner, repo, index), nil, nil, pr)
|
||||
return pr, resp, err
|
||||
}
|
||||
|
||||
// CreatePullRequestOption options when creating a pull request
|
||||
@ -125,14 +129,16 @@ type CreatePullRequestOption struct {
|
||||
}
|
||||
|
||||
// CreatePullRequest create pull request with options
|
||||
func (c *Client) CreatePullRequest(owner, repo string, opt CreatePullRequestOption) (*PullRequest, error) {
|
||||
func (c *Client) CreatePullRequest(owner, repo string, opt CreatePullRequestOption) (*PullRequest, *Response, error) {
|
||||
body, err := json.Marshal(&opt)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
return nil, nil, err
|
||||
}
|
||||
pr := new(PullRequest)
|
||||
return pr, c.getParsedResponse("POST", fmt.Sprintf("/repos/%s/%s/pulls", owner, repo),
|
||||
resp, err := c.getParsedResponse("POST",
|
||||
fmt.Sprintf("/repos/%s/%s/pulls", owner, repo),
|
||||
jsonHeader, bytes.NewReader(body), pr)
|
||||
return pr, resp, err
|
||||
}
|
||||
|
||||
// EditPullRequestOption options when modify pull request
|
||||
@ -148,15 +154,33 @@ type EditPullRequestOption struct {
|
||||
Deadline *time.Time `json:"due_date"`
|
||||
}
|
||||
|
||||
// Validate the EditPullRequestOption struct
|
||||
func (opt EditPullRequestOption) Validate(c *Client) error {
|
||||
if len(opt.Title) != 0 && len(strings.TrimSpace(opt.Title)) == 0 {
|
||||
return fmt.Errorf("title is empty")
|
||||
}
|
||||
if len(opt.Base) != 0 {
|
||||
if err := c.CheckServerVersionConstraint(">=1.12.0"); err != nil {
|
||||
return fmt.Errorf("can not change base gitea to old")
|
||||
}
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
// EditPullRequest modify pull request with PR id and options
|
||||
func (c *Client) EditPullRequest(owner, repo string, index int64, opt EditPullRequestOption) (*PullRequest, error) {
|
||||
func (c *Client) EditPullRequest(owner, repo string, index int64, opt EditPullRequestOption) (*PullRequest, *Response, error) {
|
||||
if err := opt.Validate(c); err != nil {
|
||||
return nil, nil, err
|
||||
}
|
||||
body, err := json.Marshal(&opt)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
return nil, nil, err
|
||||
}
|
||||
pr := new(PullRequest)
|
||||
return pr, c.getParsedResponse("PATCH", fmt.Sprintf("/repos/%s/%s/pulls/%d", owner, repo, index),
|
||||
resp, err := c.getParsedResponse("PATCH",
|
||||
fmt.Sprintf("/repos/%s/%s/pulls/%d", owner, repo, index),
|
||||
jsonHeader, bytes.NewReader(body), pr)
|
||||
return pr, resp, err
|
||||
}
|
||||
|
||||
// MergePullRequestOption options when merging a pull request
|
||||
@ -166,31 +190,64 @@ type MergePullRequestOption struct {
|
||||
Message string `json:"MergeMessageField"`
|
||||
}
|
||||
|
||||
// MergePullRequest merge a PR to repository by PR id
|
||||
func (c *Client) MergePullRequest(owner, repo string, index int64, opt MergePullRequestOption) (bool, error) {
|
||||
// Validate the MergePullRequestOption struct
|
||||
func (opt MergePullRequestOption) Validate(c *Client) error {
|
||||
if opt.Style == MergeStyleSquash {
|
||||
if err := c.CheckServerVersionConstraint(">=1.11.5"); err != nil {
|
||||
return false, err
|
||||
return err
|
||||
}
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
// MergePullRequest merge a PR to repository by PR id
|
||||
func (c *Client) MergePullRequest(owner, repo string, index int64, opt MergePullRequestOption) (bool, *Response, error) {
|
||||
if err := opt.Validate(c); err != nil {
|
||||
return false, nil, err
|
||||
}
|
||||
body, err := json.Marshal(&opt)
|
||||
if err != nil {
|
||||
return false, err
|
||||
return false, nil, err
|
||||
}
|
||||
status, err := c.getStatusCode("POST", fmt.Sprintf("/repos/%s/%s/pulls/%d/merge", owner, repo, index), jsonHeader, bytes.NewReader(body))
|
||||
status, resp, err := c.getStatusCode("POST", fmt.Sprintf("/repos/%s/%s/pulls/%d/merge", owner, repo, index), jsonHeader, bytes.NewReader(body))
|
||||
if err != nil {
|
||||
return false, err
|
||||
return false, resp, err
|
||||
}
|
||||
return status == 200, nil
|
||||
return status == 200, resp, nil
|
||||
}
|
||||
|
||||
// IsPullRequestMerged test if one PR is merged to one repository
|
||||
func (c *Client) IsPullRequestMerged(owner, repo string, index int64) (bool, error) {
|
||||
statusCode, err := c.getStatusCode("GET", fmt.Sprintf("/repos/%s/%s/pulls/%d/merge", owner, repo, index), nil, nil)
|
||||
func (c *Client) IsPullRequestMerged(owner, repo string, index int64) (bool, *Response, error) {
|
||||
status, resp, err := c.getStatusCode("GET", fmt.Sprintf("/repos/%s/%s/pulls/%d/merge", owner, repo, index), nil, nil)
|
||||
|
||||
if err != nil {
|
||||
return false, err
|
||||
return false, resp, err
|
||||
}
|
||||
|
||||
return statusCode == 204, nil
|
||||
return status == 204, resp, nil
|
||||
}
|
||||
|
||||
// getPullRequestDiffOrPatch gets the patch or diff file as bytes for a PR
|
||||
func (c *Client) getPullRequestDiffOrPatch(owner, repo, kind string, index int64) ([]byte, *Response, error) {
|
||||
if err := c.CheckServerVersionConstraint(">=1.13.0"); err != nil {
|
||||
r, _, err2 := c.GetRepo(owner, repo)
|
||||
if err2 != nil {
|
||||
return nil, nil, err
|
||||
}
|
||||
if r.Private {
|
||||
return nil, nil, err
|
||||
}
|
||||
return c.getWebResponse("GET", fmt.Sprintf("/%s/%s/pulls/%d.%s", owner, repo, index, kind), nil)
|
||||
}
|
||||
return c.getResponse("GET", fmt.Sprintf("/repos/%s/%s/pulls/%d.%s", owner, repo, index, kind), nil, nil)
|
||||
}
|
||||
|
||||
// GetPullRequestPatch gets the .patch file as bytes for a PR
|
||||
func (c *Client) GetPullRequestPatch(owner, repo string, index int64) ([]byte, *Response, error) {
|
||||
return c.getPullRequestDiffOrPatch(owner, repo, "patch", index)
|
||||
}
|
||||
|
||||
// GetPullRequestDiff gets the .diff file as bytes for a PR
|
||||
func (c *Client) GetPullRequestDiff(owner, repo string, index int64) ([]byte, *Response, error) {
|
||||
return c.getPullRequestDiffOrPatch(owner, repo, "diff", index)
|
||||
}
|
||||
|
101
vendor/code.gitea.io/sdk/gitea/pull_review.go
generated
vendored
101
vendor/code.gitea.io/sdk/gitea/pull_review.go
generated
vendored
@ -9,6 +9,7 @@ import (
|
||||
"encoding/json"
|
||||
"fmt"
|
||||
"net/url"
|
||||
"strings"
|
||||
"time"
|
||||
)
|
||||
|
||||
@ -40,7 +41,6 @@ type PullReview struct {
|
||||
Stale bool `json:"stale"`
|
||||
Official bool `json:"official"`
|
||||
CodeCommentsCount int `json:"comments_count"`
|
||||
// swagger:strfmt date-time
|
||||
Submitted time.Time `json:"submitted_at"`
|
||||
|
||||
HTMLURL string `json:"html_url"`
|
||||
@ -54,9 +54,7 @@ type PullReviewComment struct {
|
||||
Reviewer *User `json:"user"`
|
||||
ReviewID int64 `json:"pull_request_review_id"`
|
||||
|
||||
// swagger:strfmt date-time
|
||||
Created time.Time `json:"created_at"`
|
||||
// swagger:strfmt date-time
|
||||
Updated time.Time `json:"updated_at"`
|
||||
|
||||
Path string `json:"path"`
|
||||
@ -100,10 +98,42 @@ type ListPullReviewsOptions struct {
|
||||
ListOptions
|
||||
}
|
||||
|
||||
// Validate the CreatePullReviewOptions struct
|
||||
func (opt CreatePullReviewOptions) Validate() error {
|
||||
if opt.State != ReviewStateApproved && len(strings.TrimSpace(opt.Body)) == 0 {
|
||||
return fmt.Errorf("body is empty")
|
||||
}
|
||||
for i := range opt.Comments {
|
||||
if err := opt.Comments[i].Validate(); err != nil {
|
||||
return err
|
||||
}
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
// Validate the SubmitPullReviewOptions struct
|
||||
func (opt SubmitPullReviewOptions) Validate() error {
|
||||
if opt.State != ReviewStateApproved && len(strings.TrimSpace(opt.Body)) == 0 {
|
||||
return fmt.Errorf("body is empty")
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
// Validate the CreatePullReviewComment struct
|
||||
func (opt CreatePullReviewComment) Validate() error {
|
||||
if len(strings.TrimSpace(opt.Body)) == 0 {
|
||||
return fmt.Errorf("body is empty")
|
||||
}
|
||||
if opt.NewLineNum != 0 && opt.OldLineNum != 0 {
|
||||
return fmt.Errorf("old and new line num are set, cant identify the code comment position")
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
// ListPullReviews lists all reviews of a pull request
|
||||
func (c *Client) ListPullReviews(owner, repo string, index int64, opt ListPullReviewsOptions) ([]*PullReview, error) {
|
||||
func (c *Client) ListPullReviews(owner, repo string, index int64, opt ListPullReviewsOptions) ([]*PullReview, *Response, error) {
|
||||
if err := c.CheckServerVersionConstraint(">=1.12.0"); err != nil {
|
||||
return nil, err
|
||||
return nil, nil, err
|
||||
}
|
||||
opt.setDefaults()
|
||||
rs := make([]*PullReview, 0, opt.PageSize)
|
||||
@ -111,74 +141,79 @@ func (c *Client) ListPullReviews(owner, repo string, index int64, opt ListPullRe
|
||||
link, _ := url.Parse(fmt.Sprintf("/repos/%s/%s/pulls/%d/reviews", owner, repo, index))
|
||||
link.RawQuery = opt.ListOptions.getURLQuery().Encode()
|
||||
|
||||
return rs, c.getParsedResponse("GET", link.String(), jsonHeader, nil, &rs)
|
||||
resp, err := c.getParsedResponse("GET", link.String(), jsonHeader, nil, &rs)
|
||||
return rs, resp, err
|
||||
}
|
||||
|
||||
// GetPullReview gets a specific review of a pull request
|
||||
func (c *Client) GetPullReview(owner, repo string, index, id int64) (*PullReview, error) {
|
||||
func (c *Client) GetPullReview(owner, repo string, index, id int64) (*PullReview, *Response, error) {
|
||||
if err := c.CheckServerVersionConstraint(">=1.12.0"); err != nil {
|
||||
return nil, err
|
||||
return nil, nil, err
|
||||
}
|
||||
|
||||
r := new(PullReview)
|
||||
return r, c.getParsedResponse("GET", fmt.Sprintf("/repos/%s/%s/pulls/%d/reviews/%d", owner, repo, index, id), jsonHeader, nil, &r)
|
||||
}
|
||||
|
||||
// ListPullReviewsCommentsOptions options for listing PullReviewsComments
|
||||
type ListPullReviewsCommentsOptions struct {
|
||||
ListOptions
|
||||
resp, err := c.getParsedResponse("GET", fmt.Sprintf("/repos/%s/%s/pulls/%d/reviews/%d", owner, repo, index, id), jsonHeader, nil, &r)
|
||||
return r, resp, err
|
||||
}
|
||||
|
||||
// ListPullReviewComments lists all comments of a pull request review
|
||||
func (c *Client) ListPullReviewComments(owner, repo string, index, id int64, opt ListPullReviewsCommentsOptions) ([]*PullReviewComment, error) {
|
||||
func (c *Client) ListPullReviewComments(owner, repo string, index, id int64) ([]*PullReviewComment, *Response, error) {
|
||||
if err := c.CheckServerVersionConstraint(">=1.12.0"); err != nil {
|
||||
return nil, err
|
||||
return nil, nil, err
|
||||
}
|
||||
opt.setDefaults()
|
||||
rcl := make([]*PullReviewComment, 0, opt.PageSize)
|
||||
|
||||
rcl := make([]*PullReviewComment, 0, 4)
|
||||
link, _ := url.Parse(fmt.Sprintf("/repos/%s/%s/pulls/%d/reviews/%d/comments", owner, repo, index, id))
|
||||
link.RawQuery = opt.ListOptions.getURLQuery().Encode()
|
||||
|
||||
return rcl, c.getParsedResponse("GET", link.String(), jsonHeader, nil, &rcl)
|
||||
resp, err := c.getParsedResponse("GET", link.String(), jsonHeader, nil, &rcl)
|
||||
return rcl, resp, err
|
||||
}
|
||||
|
||||
// DeletePullReview delete a specific review from a pull request
|
||||
func (c *Client) DeletePullReview(owner, repo string, index, id int64) error {
|
||||
func (c *Client) DeletePullReview(owner, repo string, index, id int64) (*Response, error) {
|
||||
if err := c.CheckServerVersionConstraint(">=1.12.0"); err != nil {
|
||||
return err
|
||||
return nil, err
|
||||
}
|
||||
|
||||
_, err := c.getResponse("DELETE", fmt.Sprintf("/repos/%s/%s/pulls/%d/reviews/%d", owner, repo, index, id), jsonHeader, nil)
|
||||
return err
|
||||
_, resp, err := c.getResponse("DELETE", fmt.Sprintf("/repos/%s/%s/pulls/%d/reviews/%d", owner, repo, index, id), jsonHeader, nil)
|
||||
return resp, err
|
||||
}
|
||||
|
||||
// CreatePullReview create a review to an pull request
|
||||
func (c *Client) CreatePullReview(owner, repo string, index int64, opt CreatePullReviewOptions) (*PullReview, error) {
|
||||
func (c *Client) CreatePullReview(owner, repo string, index int64, opt CreatePullReviewOptions) (*PullReview, *Response, error) {
|
||||
if err := c.CheckServerVersionConstraint(">=1.12.0"); err != nil {
|
||||
return nil, err
|
||||
return nil, nil, err
|
||||
}
|
||||
if err := opt.Validate(); err != nil {
|
||||
return nil, nil, err
|
||||
}
|
||||
body, err := json.Marshal(&opt)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
return nil, nil, err
|
||||
}
|
||||
|
||||
r := new(PullReview)
|
||||
return r, c.getParsedResponse("POST", fmt.Sprintf("/repos/%s/%s/pulls/%d/reviews", owner, repo, index),
|
||||
resp, err := c.getParsedResponse("POST",
|
||||
fmt.Sprintf("/repos/%s/%s/pulls/%d/reviews", owner, repo, index),
|
||||
jsonHeader, bytes.NewReader(body), r)
|
||||
return r, resp, err
|
||||
}
|
||||
|
||||
// SubmitPullReview submit a pending review to an pull request
|
||||
func (c *Client) SubmitPullReview(owner, repo string, index, id int64, opt SubmitPullReviewOptions) (*PullReview, error) {
|
||||
func (c *Client) SubmitPullReview(owner, repo string, index, id int64, opt SubmitPullReviewOptions) (*PullReview, *Response, error) {
|
||||
if err := c.CheckServerVersionConstraint(">=1.12.0"); err != nil {
|
||||
return nil, err
|
||||
return nil, nil, err
|
||||
}
|
||||
if err := opt.Validate(); err != nil {
|
||||
return nil, nil, err
|
||||
}
|
||||
body, err := json.Marshal(&opt)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
return nil, nil, err
|
||||
}
|
||||
|
||||
r := new(PullReview)
|
||||
return r, c.getParsedResponse("POST", fmt.Sprintf("/repos/%s/%s/pulls/%d/reviews/%d", owner, repo, index, id),
|
||||
resp, err := c.getParsedResponse("POST",
|
||||
fmt.Sprintf("/repos/%s/%s/pulls/%d/reviews/%d", owner, repo, index, id),
|
||||
jsonHeader, bytes.NewReader(body), r)
|
||||
return r, resp, err
|
||||
}
|
||||
|
48
vendor/code.gitea.io/sdk/gitea/release.go
generated
vendored
48
vendor/code.gitea.io/sdk/gitea/release.go
generated
vendored
@ -8,6 +8,7 @@ import (
|
||||
"bytes"
|
||||
"encoding/json"
|
||||
"fmt"
|
||||
"strings"
|
||||
"time"
|
||||
)
|
||||
|
||||
@ -35,22 +36,22 @@ type ListReleasesOptions struct {
|
||||
}
|
||||
|
||||
// ListReleases list releases of a repository
|
||||
func (c *Client) ListReleases(user, repo string, opt ListReleasesOptions) ([]*Release, error) {
|
||||
func (c *Client) ListReleases(user, repo string, opt ListReleasesOptions) ([]*Release, *Response, error) {
|
||||
opt.setDefaults()
|
||||
releases := make([]*Release, 0, opt.PageSize)
|
||||
err := c.getParsedResponse("GET",
|
||||
resp, err := c.getParsedResponse("GET",
|
||||
fmt.Sprintf("/repos/%s/%s/releases?%s", user, repo, opt.getURLQuery().Encode()),
|
||||
nil, nil, &releases)
|
||||
return releases, err
|
||||
return releases, resp, err
|
||||
}
|
||||
|
||||
// GetRelease get a release of a repository
|
||||
func (c *Client) GetRelease(user, repo string, id int64) (*Release, error) {
|
||||
func (c *Client) GetRelease(user, repo string, id int64) (*Release, *Response, error) {
|
||||
r := new(Release)
|
||||
err := c.getParsedResponse("GET",
|
||||
resp, err := c.getParsedResponse("GET",
|
||||
fmt.Sprintf("/repos/%s/%s/releases/%d", user, repo, id),
|
||||
nil, nil, &r)
|
||||
return r, err
|
||||
return r, resp, err
|
||||
}
|
||||
|
||||
// CreateReleaseOption options when creating a release
|
||||
@ -63,17 +64,28 @@ type CreateReleaseOption struct {
|
||||
IsPrerelease bool `json:"prerelease"`
|
||||
}
|
||||
|
||||
// Validate the CreateReleaseOption struct
|
||||
func (opt CreateReleaseOption) Validate() error {
|
||||
if len(strings.TrimSpace(opt.Title)) == 0 {
|
||||
return fmt.Errorf("title is empty")
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
// CreateRelease create a release
|
||||
func (c *Client) CreateRelease(user, repo string, form CreateReleaseOption) (*Release, error) {
|
||||
body, err := json.Marshal(form)
|
||||
func (c *Client) CreateRelease(user, repo string, opt CreateReleaseOption) (*Release, *Response, error) {
|
||||
if err := opt.Validate(); err != nil {
|
||||
return nil, nil, err
|
||||
}
|
||||
body, err := json.Marshal(opt)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
return nil, nil, err
|
||||
}
|
||||
r := new(Release)
|
||||
err = c.getParsedResponse("POST",
|
||||
resp, err := c.getParsedResponse("POST",
|
||||
fmt.Sprintf("/repos/%s/%s/releases", user, repo),
|
||||
jsonHeader, bytes.NewReader(body), r)
|
||||
return r, err
|
||||
return r, resp, err
|
||||
}
|
||||
|
||||
// EditReleaseOption options when editing a release
|
||||
@ -87,22 +99,22 @@ type EditReleaseOption struct {
|
||||
}
|
||||
|
||||
// EditRelease edit a release
|
||||
func (c *Client) EditRelease(user, repo string, id int64, form EditReleaseOption) (*Release, error) {
|
||||
func (c *Client) EditRelease(user, repo string, id int64, form EditReleaseOption) (*Release, *Response, error) {
|
||||
body, err := json.Marshal(form)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
return nil, nil, err
|
||||
}
|
||||
r := new(Release)
|
||||
err = c.getParsedResponse("PATCH",
|
||||
resp, err := c.getParsedResponse("PATCH",
|
||||
fmt.Sprintf("/repos/%s/%s/releases/%d", user, repo, id),
|
||||
jsonHeader, bytes.NewReader(body), r)
|
||||
return r, err
|
||||
return r, resp, err
|
||||
}
|
||||
|
||||
// DeleteRelease delete a release from a repository
|
||||
func (c *Client) DeleteRelease(user, repo string, id int64) error {
|
||||
_, err := c.getResponse("DELETE",
|
||||
func (c *Client) DeleteRelease(user, repo string, id int64) (*Response, error) {
|
||||
_, resp, err := c.getResponse("DELETE",
|
||||
fmt.Sprintf("/repos/%s/%s/releases/%d", user, repo, id),
|
||||
nil, nil)
|
||||
return err
|
||||
return resp, err
|
||||
}
|
||||
|
266
vendor/code.gitea.io/sdk/gitea/repo.go
generated
vendored
266
vendor/code.gitea.io/sdk/gitea/repo.go
generated
vendored
@ -1,4 +1,5 @@
|
||||
// Copyright 2014 The Gogs Authors. All rights reserved.
|
||||
// Copyright 2020 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.
|
||||
|
||||
@ -9,6 +10,7 @@ import (
|
||||
"encoding/json"
|
||||
"fmt"
|
||||
"net/url"
|
||||
"strings"
|
||||
"time"
|
||||
)
|
||||
|
||||
@ -57,23 +59,39 @@ type Repository struct {
|
||||
AvatarURL string `json:"avatar_url"`
|
||||
}
|
||||
|
||||
// RepoType represent repo type
|
||||
type RepoType string
|
||||
|
||||
const (
|
||||
// RepoTypeNone dont specify a type
|
||||
RepoTypeNone RepoType = ""
|
||||
// RepoTypeSource is the default repo type
|
||||
RepoTypeSource RepoType = "source"
|
||||
// RepoTypeFork is a repo witch was forked from an other one
|
||||
RepoTypeFork RepoType = "fork"
|
||||
// RepoTypeMirror represents an mirror repo
|
||||
RepoTypeMirror RepoType = "mirror"
|
||||
)
|
||||
|
||||
// ListReposOptions options for listing repositories
|
||||
type ListReposOptions struct {
|
||||
ListOptions
|
||||
}
|
||||
|
||||
// ListMyRepos lists all repositories for the authenticated user that has access to.
|
||||
func (c *Client) ListMyRepos(opt ListReposOptions) ([]*Repository, error) {
|
||||
func (c *Client) ListMyRepos(opt ListReposOptions) ([]*Repository, *Response, error) {
|
||||
opt.setDefaults()
|
||||
repos := make([]*Repository, 0, opt.PageSize)
|
||||
return repos, c.getParsedResponse("GET", fmt.Sprintf("/user/repos?%s", opt.getURLQuery().Encode()), nil, nil, &repos)
|
||||
resp, err := c.getParsedResponse("GET", fmt.Sprintf("/user/repos?%s", opt.getURLQuery().Encode()), nil, nil, &repos)
|
||||
return repos, resp, err
|
||||
}
|
||||
|
||||
// ListUserRepos list all repositories of one user by user's name
|
||||
func (c *Client) ListUserRepos(user string, opt ListReposOptions) ([]*Repository, error) {
|
||||
func (c *Client) ListUserRepos(user string, opt ListReposOptions) ([]*Repository, *Response, error) {
|
||||
opt.setDefaults()
|
||||
repos := make([]*Repository, 0, opt.PageSize)
|
||||
return repos, c.getParsedResponse("GET", fmt.Sprintf("/users/%s/repos?%s", user, opt.getURLQuery().Encode()), nil, nil, &repos)
|
||||
resp, err := c.getParsedResponse("GET", fmt.Sprintf("/users/%s/repos?%s", user, opt.getURLQuery().Encode()), nil, nil, &repos)
|
||||
return repos, resp, err
|
||||
}
|
||||
|
||||
// ListOrgReposOptions options for a organization's repositories
|
||||
@ -82,26 +100,62 @@ type ListOrgReposOptions struct {
|
||||
}
|
||||
|
||||
// ListOrgRepos list all repositories of one organization by organization's name
|
||||
func (c *Client) ListOrgRepos(org string, opt ListOrgReposOptions) ([]*Repository, error) {
|
||||
func (c *Client) ListOrgRepos(org string, opt ListOrgReposOptions) ([]*Repository, *Response, error) {
|
||||
opt.setDefaults()
|
||||
repos := make([]*Repository, 0, opt.PageSize)
|
||||
return repos, c.getParsedResponse("GET", fmt.Sprintf("/orgs/%s/repos?%s", org, opt.getURLQuery().Encode()), nil, nil, &repos)
|
||||
resp, err := c.getParsedResponse("GET", fmt.Sprintf("/orgs/%s/repos?%s", org, opt.getURLQuery().Encode()), nil, nil, &repos)
|
||||
return repos, resp, err
|
||||
}
|
||||
|
||||
// SearchRepoOptions options for searching repositories
|
||||
type SearchRepoOptions struct {
|
||||
ListOptions
|
||||
|
||||
// The keyword to query
|
||||
Keyword string
|
||||
Topic bool
|
||||
IncludeDesc bool
|
||||
UID int64
|
||||
PriorityOwnerID int64
|
||||
StarredBy int64
|
||||
Private bool
|
||||
Template bool
|
||||
Mode string
|
||||
Exclusive bool
|
||||
// Limit search to repositories with keyword as topic
|
||||
KeywordIsTopic bool
|
||||
// Include search of keyword within repository description
|
||||
KeywordInDescription bool
|
||||
|
||||
/*
|
||||
User Filter
|
||||
*/
|
||||
|
||||
// Repo Owner
|
||||
OwnerID int64
|
||||
// Stared By UserID
|
||||
StarredByUserID int64
|
||||
|
||||
/*
|
||||
Repo Attributes
|
||||
*/
|
||||
|
||||
// pubic, private or all repositories (defaults to all)
|
||||
IsPrivate *bool
|
||||
// archived, non-archived or all repositories (defaults to all)
|
||||
IsArchived *bool
|
||||
// Exclude template repos from search
|
||||
ExcludeTemplate bool
|
||||
// Filter by "fork", "source", "mirror"
|
||||
Type RepoType
|
||||
|
||||
/*
|
||||
Sort Filters
|
||||
*/
|
||||
|
||||
// sort repos by attribute. Supported values are "alpha", "created", "updated", "size", and "id". Default is "alpha"
|
||||
Sort string
|
||||
// sort order, either "asc" (ascending) or "desc" (descending). Default is "asc", ignored if "sort" is not specified.
|
||||
Order string
|
||||
// Repo owner to prioritize in the results
|
||||
PrioritizedByOwnerID int64
|
||||
|
||||
/*
|
||||
Cover EdgeCases
|
||||
*/
|
||||
// if set all other options are ignored and this string is used as query
|
||||
RawQuery string
|
||||
}
|
||||
|
||||
// QueryEncode turns options into querystring argument
|
||||
@ -110,34 +164,46 @@ func (opt *SearchRepoOptions) QueryEncode() string {
|
||||
if opt.Keyword != "" {
|
||||
query.Add("q", opt.Keyword)
|
||||
}
|
||||
|
||||
query.Add("topic", fmt.Sprintf("%t", opt.Topic))
|
||||
query.Add("includeDesc", fmt.Sprintf("%t", opt.IncludeDesc))
|
||||
|
||||
if opt.UID > 0 {
|
||||
query.Add("uid", fmt.Sprintf("%d", opt.UID))
|
||||
if opt.KeywordIsTopic {
|
||||
query.Add("topic", "true")
|
||||
}
|
||||
if opt.KeywordInDescription {
|
||||
query.Add("includeDesc", "true")
|
||||
}
|
||||
|
||||
if opt.PriorityOwnerID > 0 {
|
||||
query.Add("priority_owner_id", fmt.Sprintf("%d", opt.PriorityOwnerID))
|
||||
// User Filter
|
||||
if opt.OwnerID > 0 {
|
||||
query.Add("uid", fmt.Sprintf("%d", opt.OwnerID))
|
||||
query.Add("exclusive", "true")
|
||||
}
|
||||
if opt.StarredByUserID > 0 {
|
||||
query.Add("starredBy", fmt.Sprintf("%d", opt.StarredByUserID))
|
||||
}
|
||||
|
||||
if opt.StarredBy > 0 {
|
||||
query.Add("starredBy", fmt.Sprintf("%d", opt.StarredBy))
|
||||
// Repo Attributes
|
||||
if opt.IsPrivate != nil {
|
||||
query.Add("is_private", fmt.Sprintf("%v", opt.IsPrivate))
|
||||
}
|
||||
if opt.IsArchived != nil {
|
||||
query.Add("archived", fmt.Sprintf("%v", opt.IsArchived))
|
||||
}
|
||||
if opt.ExcludeTemplate {
|
||||
query.Add("template", "false")
|
||||
}
|
||||
if len(opt.Type) != 0 {
|
||||
query.Add("mode", string(opt.Type))
|
||||
}
|
||||
|
||||
query.Add("private", fmt.Sprintf("%t", opt.Private))
|
||||
query.Add("template", fmt.Sprintf("%t", opt.Template))
|
||||
|
||||
if opt.Mode != "" {
|
||||
query.Add("mode", opt.Mode)
|
||||
}
|
||||
|
||||
query.Add("exclusive", fmt.Sprintf("%t", opt.Exclusive))
|
||||
|
||||
// Sort Filters
|
||||
if opt.Sort != "" {
|
||||
query.Add("sort", opt.Sort)
|
||||
}
|
||||
if opt.PrioritizedByOwnerID > 0 {
|
||||
query.Add("priority_owner_id", fmt.Sprintf("%d", opt.PrioritizedByOwnerID))
|
||||
}
|
||||
if opt.Order != "" {
|
||||
query.Add("order", opt.Order)
|
||||
}
|
||||
|
||||
return query.Encode()
|
||||
}
|
||||
@ -147,21 +213,33 @@ type searchRepoResponse struct {
|
||||
}
|
||||
|
||||
// SearchRepos searches for repositories matching the given filters
|
||||
func (c *Client) SearchRepos(opt SearchRepoOptions) ([]*Repository, error) {
|
||||
func (c *Client) SearchRepos(opt SearchRepoOptions) ([]*Repository, *Response, error) {
|
||||
opt.setDefaults()
|
||||
resp := new(searchRepoResponse)
|
||||
repos := new(searchRepoResponse)
|
||||
|
||||
link, _ := url.Parse("/repos/search")
|
||||
link.RawQuery = opt.QueryEncode()
|
||||
|
||||
err := c.getParsedResponse("GET", link.String(), nil, nil, &resp)
|
||||
return resp.Repos, err
|
||||
if len(opt.RawQuery) != 0 {
|
||||
link.RawQuery = opt.RawQuery
|
||||
} else {
|
||||
link.RawQuery = opt.QueryEncode()
|
||||
// IsPrivate only works on gitea >= 1.12.0
|
||||
if err := c.CheckServerVersionConstraint(">=1.12.0"); err != nil && opt.IsPrivate != nil {
|
||||
if *opt.IsPrivate {
|
||||
// private repos only not supported on gitea <= 1.11.x
|
||||
return nil, nil, err
|
||||
}
|
||||
link.Query().Add("private", "false")
|
||||
}
|
||||
}
|
||||
|
||||
resp, err := c.getParsedResponse("GET", link.String(), nil, nil, &repos)
|
||||
return repos.Repos, resp, err
|
||||
}
|
||||
|
||||
// CreateRepoOption options when creating repository
|
||||
type CreateRepoOption struct {
|
||||
// Name of the repository to create
|
||||
//
|
||||
Name string `json:"name"`
|
||||
// Description of the repository to create
|
||||
Description string `json:"description"`
|
||||
@ -181,30 +259,47 @@ type CreateRepoOption struct {
|
||||
DefaultBranch string `json:"default_branch"`
|
||||
}
|
||||
|
||||
// Validate the CreateRepoOption struct
|
||||
func (opt CreateRepoOption) Validate() error {
|
||||
if len(strings.TrimSpace(opt.Name)) == 0 {
|
||||
return fmt.Errorf("name is empty")
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
// CreateRepo creates a repository for authenticated user.
|
||||
func (c *Client) CreateRepo(opt CreateRepoOption) (*Repository, error) {
|
||||
func (c *Client) CreateRepo(opt CreateRepoOption) (*Repository, *Response, error) {
|
||||
if err := opt.Validate(); err != nil {
|
||||
return nil, nil, err
|
||||
}
|
||||
body, err := json.Marshal(&opt)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
return nil, nil, err
|
||||
}
|
||||
repo := new(Repository)
|
||||
return repo, c.getParsedResponse("POST", "/user/repos", jsonHeader, bytes.NewReader(body), repo)
|
||||
resp, err := c.getParsedResponse("POST", "/user/repos", jsonHeader, bytes.NewReader(body), repo)
|
||||
return repo, resp, err
|
||||
}
|
||||
|
||||
// CreateOrgRepo creates an organization repository for authenticated user.
|
||||
func (c *Client) CreateOrgRepo(org string, opt CreateRepoOption) (*Repository, error) {
|
||||
func (c *Client) CreateOrgRepo(org string, opt CreateRepoOption) (*Repository, *Response, error) {
|
||||
if err := opt.Validate(); err != nil {
|
||||
return nil, nil, err
|
||||
}
|
||||
body, err := json.Marshal(&opt)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
return nil, nil, err
|
||||
}
|
||||
repo := new(Repository)
|
||||
return repo, c.getParsedResponse("POST", fmt.Sprintf("/org/%s/repos", org), jsonHeader, bytes.NewReader(body), repo)
|
||||
resp, err := c.getParsedResponse("POST", fmt.Sprintf("/org/%s/repos", org), jsonHeader, bytes.NewReader(body), repo)
|
||||
return repo, resp, err
|
||||
}
|
||||
|
||||
// GetRepo returns information of a repository of given owner.
|
||||
func (c *Client) GetRepo(owner, reponame string) (*Repository, error) {
|
||||
func (c *Client) GetRepo(owner, reponame string) (*Repository, *Response, error) {
|
||||
repo := new(Repository)
|
||||
return repo, c.getParsedResponse("GET", fmt.Sprintf("/repos/%s/%s", owner, reponame), nil, nil, repo)
|
||||
resp, err := c.getParsedResponse("GET", fmt.Sprintf("/repos/%s/%s", owner, reponame), nil, nil, repo)
|
||||
return repo, resp, err
|
||||
}
|
||||
|
||||
// EditRepoOption options when editing a repository's properties
|
||||
@ -242,49 +337,54 @@ type EditRepoOption struct {
|
||||
}
|
||||
|
||||
// EditRepo edit the properties of a repository
|
||||
func (c *Client) EditRepo(owner, reponame string, opt EditRepoOption) (*Repository, error) {
|
||||
func (c *Client) EditRepo(owner, reponame string, opt EditRepoOption) (*Repository, *Response, error) {
|
||||
body, err := json.Marshal(&opt)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
return nil, nil, err
|
||||
}
|
||||
repo := new(Repository)
|
||||
return repo, c.getParsedResponse("PATCH", fmt.Sprintf("/repos/%s/%s", owner, reponame), jsonHeader, bytes.NewReader(body), repo)
|
||||
resp, err := c.getParsedResponse("PATCH", fmt.Sprintf("/repos/%s/%s", owner, reponame), jsonHeader, bytes.NewReader(body), repo)
|
||||
return repo, resp, err
|
||||
}
|
||||
|
||||
// DeleteRepo deletes a repository of user or organization.
|
||||
func (c *Client) DeleteRepo(owner, repo string) error {
|
||||
_, err := c.getResponse("DELETE", fmt.Sprintf("/repos/%s/%s", owner, repo), nil, nil)
|
||||
return err
|
||||
}
|
||||
|
||||
// MigrateRepoOption options for migrating a repository from an external service
|
||||
type MigrateRepoOption struct {
|
||||
CloneAddr string `json:"clone_addr"`
|
||||
AuthUsername string `json:"auth_username"`
|
||||
AuthPassword string `json:"auth_password"`
|
||||
UID int `json:"uid"`
|
||||
RepoName string `json:"repo_name"`
|
||||
Mirror bool `json:"mirror"`
|
||||
Private bool `json:"private"`
|
||||
Description string `json:"description"`
|
||||
}
|
||||
|
||||
// MigrateRepo migrates a repository from other Git hosting sources for the
|
||||
// authenticated user.
|
||||
//
|
||||
// To migrate a repository for a organization, the authenticated user must be a
|
||||
// owner of the specified organization.
|
||||
func (c *Client) MigrateRepo(opt MigrateRepoOption) (*Repository, error) {
|
||||
body, err := json.Marshal(&opt)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
repo := new(Repository)
|
||||
return repo, c.getParsedResponse("POST", "/repos/migrate", jsonHeader, bytes.NewReader(body), repo)
|
||||
func (c *Client) DeleteRepo(owner, repo string) (*Response, error) {
|
||||
_, resp, err := c.getResponse("DELETE", fmt.Sprintf("/repos/%s/%s", owner, repo), nil, nil)
|
||||
return resp, err
|
||||
}
|
||||
|
||||
// MirrorSync adds a mirrored repository to the mirror sync queue.
|
||||
func (c *Client) MirrorSync(owner, repo string) error {
|
||||
_, err := c.getResponse("POST", fmt.Sprintf("/repos/%s/%s/mirror-sync", owner, repo), nil, nil)
|
||||
return err
|
||||
func (c *Client) MirrorSync(owner, repo string) (*Response, error) {
|
||||
_, resp, err := c.getResponse("POST", fmt.Sprintf("/repos/%s/%s/mirror-sync", owner, repo), nil, nil)
|
||||
return resp, err
|
||||
}
|
||||
|
||||
// GetRepoLanguages return language stats of a repo
|
||||
func (c *Client) GetRepoLanguages(owner, repo string) (map[string]int64, *Response, error) {
|
||||
langMap := make(map[string]int64)
|
||||
|
||||
data, resp, err := c.getResponse("GET", fmt.Sprintf("/repos/%s/%s/languages", owner, repo), jsonHeader, nil)
|
||||
if err != nil {
|
||||
return nil, resp, err
|
||||
}
|
||||
if err = json.Unmarshal(data, &langMap); err != nil {
|
||||
return nil, resp, err
|
||||
}
|
||||
return langMap, resp, nil
|
||||
}
|
||||
|
||||
// ArchiveType represent supported archive formats by gitea
|
||||
type ArchiveType string
|
||||
|
||||
const (
|
||||
// ZipArchive represent zip format
|
||||
ZipArchive ArchiveType = ".zip"
|
||||
// TarGZArchive represent tar.gz format
|
||||
TarGZArchive ArchiveType = ".tar.gz"
|
||||
)
|
||||
|
||||
// GetArchive get an archive of a repository by git reference
|
||||
// e.g.: ref -> master, 70b7c74b33, v1.2.1, ...
|
||||
func (c *Client) GetArchive(owner, repo, ref string, ext ArchiveType) ([]byte, *Response, error) {
|
||||
return c.getResponse("GET", fmt.Sprintf("/repos/%s/%s/archive/%s%s", owner, repo, url.PathEscape(ref), ext), nil, nil)
|
||||
}
|
||||
|
65
vendor/code.gitea.io/sdk/gitea/repo_branch.go
generated
vendored
65
vendor/code.gitea.io/sdk/gitea/repo_branch.go
generated
vendored
@ -6,6 +6,8 @@
|
||||
package gitea
|
||||
|
||||
import (
|
||||
"bytes"
|
||||
"encoding/json"
|
||||
"fmt"
|
||||
"time"
|
||||
)
|
||||
@ -63,29 +65,70 @@ type ListRepoBranchesOptions struct {
|
||||
}
|
||||
|
||||
// ListRepoBranches list all the branches of one repository
|
||||
func (c *Client) ListRepoBranches(user, repo string, opt ListRepoBranchesOptions) ([]*Branch, error) {
|
||||
func (c *Client) ListRepoBranches(user, repo string, opt ListRepoBranchesOptions) ([]*Branch, *Response, error) {
|
||||
opt.setDefaults()
|
||||
branches := make([]*Branch, 0, opt.PageSize)
|
||||
return branches, c.getParsedResponse("GET", fmt.Sprintf("/repos/%s/%s/branches?%s", user, repo, opt.getURLQuery().Encode()), nil, nil, &branches)
|
||||
resp, err := c.getParsedResponse("GET", fmt.Sprintf("/repos/%s/%s/branches?%s", user, repo, opt.getURLQuery().Encode()), nil, nil, &branches)
|
||||
return branches, resp, err
|
||||
}
|
||||
|
||||
// GetRepoBranch get one branch's information of one repository
|
||||
func (c *Client) GetRepoBranch(user, repo, branch string) (*Branch, error) {
|
||||
func (c *Client) GetRepoBranch(user, repo, branch string) (*Branch, *Response, error) {
|
||||
b := new(Branch)
|
||||
if err := c.getParsedResponse("GET", fmt.Sprintf("/repos/%s/%s/branches/%s", user, repo, branch), nil, nil, &b); err != nil {
|
||||
return nil, err
|
||||
resp, err := c.getParsedResponse("GET", fmt.Sprintf("/repos/%s/%s/branches/%s", user, repo, branch), nil, nil, &b)
|
||||
if err != nil {
|
||||
return nil, resp, err
|
||||
}
|
||||
return b, nil
|
||||
return b, resp, nil
|
||||
}
|
||||
|
||||
// DeleteRepoBranch delete a branch in a repository
|
||||
func (c *Client) DeleteRepoBranch(user, repo, branch string) (bool, error) {
|
||||
func (c *Client) DeleteRepoBranch(user, repo, branch string) (bool, *Response, error) {
|
||||
if err := c.CheckServerVersionConstraint(">=1.12.0"); err != nil {
|
||||
return false, err
|
||||
return false, nil, err
|
||||
}
|
||||
status, err := c.getStatusCode("DELETE", fmt.Sprintf("/repos/%s/%s/branches/%s", user, repo, branch), nil, nil)
|
||||
status, resp, err := c.getStatusCode("DELETE", fmt.Sprintf("/repos/%s/%s/branches/%s", user, repo, branch), nil, nil)
|
||||
if err != nil {
|
||||
return false, err
|
||||
return false, resp, err
|
||||
}
|
||||
return status == 204, nil
|
||||
return status == 204, resp, nil
|
||||
}
|
||||
|
||||
// CreateBranchOption options when creating a branch in a repository
|
||||
type CreateBranchOption struct {
|
||||
// Name of the branch to create
|
||||
BranchName string `json:"new_branch_name"`
|
||||
// Name of the old branch to create from (optional)
|
||||
OldBranchName string `json:"old_branch_name"`
|
||||
}
|
||||
|
||||
// Validate the CreateBranchOption struct
|
||||
func (opt CreateBranchOption) Validate() error {
|
||||
if len(opt.BranchName) == 0 {
|
||||
return fmt.Errorf("BranchName is empty")
|
||||
}
|
||||
if len(opt.BranchName) > 100 {
|
||||
return fmt.Errorf("BranchName to long")
|
||||
}
|
||||
if len(opt.OldBranchName) > 100 {
|
||||
return fmt.Errorf("OldBranchName to long")
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
// CreateBranch creates a branch for a user's repository
|
||||
func (c *Client) CreateBranch(owner, repo string, opt CreateBranchOption) (*Branch, *Response, error) {
|
||||
if err := c.CheckServerVersionConstraint(">=1.13.0"); err != nil {
|
||||
return nil, nil, err
|
||||
}
|
||||
if err := opt.Validate(); err != nil {
|
||||
return nil, nil, err
|
||||
}
|
||||
body, err := json.Marshal(&opt)
|
||||
if err != nil {
|
||||
return nil, nil, err
|
||||
}
|
||||
branch := new(Branch)
|
||||
resp, err := c.getParsedResponse("POST", fmt.Sprintf("/repos/%s/%s/branches", owner, repo), jsonHeader, bytes.NewReader(body), branch)
|
||||
return branch, resp, err
|
||||
}
|
||||
|
44
vendor/code.gitea.io/sdk/gitea/repo_branch_protection.go
generated
vendored
44
vendor/code.gitea.io/sdk/gitea/repo_branch_protection.go
generated
vendored
@ -34,9 +34,7 @@ type BranchProtection struct {
|
||||
DismissStaleApprovals bool `json:"dismiss_stale_approvals"`
|
||||
RequireSignedCommits bool `json:"require_signed_commits"`
|
||||
ProtectedFilePatterns string `json:"protected_file_patterns"`
|
||||
// swagger:strfmt date-time
|
||||
Created time.Time `json:"created_at"`
|
||||
// swagger:strfmt date-time
|
||||
Updated time.Time `json:"updated_at"`
|
||||
}
|
||||
|
||||
@ -93,56 +91,60 @@ type ListBranchProtectionsOptions struct {
|
||||
}
|
||||
|
||||
// ListBranchProtections list branch protections for a repo
|
||||
func (c *Client) ListBranchProtections(owner, repo string, opt ListBranchProtectionsOptions) ([]*BranchProtection, error) {
|
||||
func (c *Client) ListBranchProtections(owner, repo string, opt ListBranchProtectionsOptions) ([]*BranchProtection, *Response, error) {
|
||||
if err := c.CheckServerVersionConstraint(">=1.12.0"); err != nil {
|
||||
return nil, err
|
||||
return nil, nil, err
|
||||
}
|
||||
bps := make([]*BranchProtection, 0, 5)
|
||||
bps := make([]*BranchProtection, 0, opt.PageSize)
|
||||
link, _ := url.Parse(fmt.Sprintf("/repos/%s/%s/branch_protections", owner, repo))
|
||||
link.RawQuery = opt.getURLQuery().Encode()
|
||||
return bps, c.getParsedResponse("GET", link.String(), jsonHeader, nil, &bps)
|
||||
resp, err := c.getParsedResponse("GET", link.String(), jsonHeader, nil, &bps)
|
||||
return bps, resp, err
|
||||
}
|
||||
|
||||
// GetBranchProtection gets a branch protection
|
||||
func (c *Client) GetBranchProtection(owner, repo, name string) (*BranchProtection, error) {
|
||||
func (c *Client) GetBranchProtection(owner, repo, name string) (*BranchProtection, *Response, error) {
|
||||
if err := c.CheckServerVersionConstraint(">=1.12.0"); err != nil {
|
||||
return nil, err
|
||||
return nil, nil, err
|
||||
}
|
||||
bp := new(BranchProtection)
|
||||
return bp, c.getParsedResponse("GET", fmt.Sprintf("/repos/%s/%s/branch_protections/%s", owner, repo, name), jsonHeader, nil, bp)
|
||||
resp, err := c.getParsedResponse("GET", fmt.Sprintf("/repos/%s/%s/branch_protections/%s", owner, repo, name), jsonHeader, nil, bp)
|
||||
return bp, resp, err
|
||||
}
|
||||
|
||||
// CreateBranchProtection creates a branch protection for a repo
|
||||
func (c *Client) CreateBranchProtection(owner, repo string, opt CreateBranchProtectionOption) (*BranchProtection, error) {
|
||||
func (c *Client) CreateBranchProtection(owner, repo string, opt CreateBranchProtectionOption) (*BranchProtection, *Response, error) {
|
||||
if err := c.CheckServerVersionConstraint(">=1.12.0"); err != nil {
|
||||
return nil, err
|
||||
return nil, nil, err
|
||||
}
|
||||
bp := new(BranchProtection)
|
||||
body, err := json.Marshal(&opt)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
return nil, nil, err
|
||||
}
|
||||
return bp, c.getParsedResponse("POST", fmt.Sprintf("/repos/%s/%s/branch_protections", owner, repo), jsonHeader, bytes.NewReader(body), bp)
|
||||
resp, err := c.getParsedResponse("POST", fmt.Sprintf("/repos/%s/%s/branch_protections", owner, repo), jsonHeader, bytes.NewReader(body), bp)
|
||||
return bp, resp, err
|
||||
}
|
||||
|
||||
// EditBranchProtection edits a branch protection for a repo
|
||||
func (c *Client) EditBranchProtection(owner, repo, name string, opt EditBranchProtectionOption) (*BranchProtection, error) {
|
||||
func (c *Client) EditBranchProtection(owner, repo, name string, opt EditBranchProtectionOption) (*BranchProtection, *Response, error) {
|
||||
if err := c.CheckServerVersionConstraint(">=1.12.0"); err != nil {
|
||||
return nil, err
|
||||
return nil, nil, err
|
||||
}
|
||||
bp := new(BranchProtection)
|
||||
body, err := json.Marshal(&opt)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
return nil, nil, err
|
||||
}
|
||||
return bp, c.getParsedResponse("PATCH", fmt.Sprintf("/repos/%s/%s/branch_protections/%s", owner, repo, name), jsonHeader, bytes.NewReader(body), bp)
|
||||
resp, err := c.getParsedResponse("PATCH", fmt.Sprintf("/repos/%s/%s/branch_protections/%s", owner, repo, name), jsonHeader, bytes.NewReader(body), bp)
|
||||
return bp, resp, err
|
||||
}
|
||||
|
||||
// DeleteBranchProtection deletes a branch protection for a repo
|
||||
func (c *Client) DeleteBranchProtection(owner, repo, name string) error {
|
||||
func (c *Client) DeleteBranchProtection(owner, repo, name string) (*Response, error) {
|
||||
if err := c.CheckServerVersionConstraint(">=1.12.0"); err != nil {
|
||||
return err
|
||||
return nil, err
|
||||
}
|
||||
_, err := c.getResponse("DELETE", fmt.Sprintf("/repos/%s/%s/branch_protections/%s", owner, repo, name), jsonHeader, nil)
|
||||
return err
|
||||
_, resp, err := c.getResponse("DELETE", fmt.Sprintf("/repos/%s/%s/branch_protections/%s", owner, repo, name), jsonHeader, nil)
|
||||
return resp, err
|
||||
}
|
||||
|
68
vendor/code.gitea.io/sdk/gitea/repo_collaborator.go
generated
vendored
68
vendor/code.gitea.io/sdk/gitea/repo_collaborator.go
generated
vendored
@ -16,44 +16,82 @@ type ListCollaboratorsOptions struct {
|
||||
}
|
||||
|
||||
// ListCollaborators list a repository's collaborators
|
||||
func (c *Client) ListCollaborators(user, repo string, opt ListCollaboratorsOptions) ([]*User, error) {
|
||||
func (c *Client) ListCollaborators(user, repo string, opt ListCollaboratorsOptions) ([]*User, *Response, error) {
|
||||
opt.setDefaults()
|
||||
collaborators := make([]*User, 0, opt.PageSize)
|
||||
return collaborators, c.getParsedResponse("GET",
|
||||
resp, err := c.getParsedResponse("GET",
|
||||
fmt.Sprintf("/repos/%s/%s/collaborators?%s", user, repo, opt.getURLQuery().Encode()),
|
||||
nil, nil, &collaborators)
|
||||
return collaborators, resp, err
|
||||
}
|
||||
|
||||
// IsCollaborator check if a user is a collaborator of a repository
|
||||
func (c *Client) IsCollaborator(user, repo, collaborator string) (bool, error) {
|
||||
status, err := c.getStatusCode("GET", fmt.Sprintf("/repos/%s/%s/collaborators/%s", user, repo, collaborator), nil, nil)
|
||||
func (c *Client) IsCollaborator(user, repo, collaborator string) (bool, *Response, error) {
|
||||
status, resp, err := c.getStatusCode("GET", fmt.Sprintf("/repos/%s/%s/collaborators/%s", user, repo, collaborator), nil, nil)
|
||||
if err != nil {
|
||||
return false, err
|
||||
return false, resp, err
|
||||
}
|
||||
if status == 204 {
|
||||
return true, nil
|
||||
return true, resp, nil
|
||||
}
|
||||
return false, nil
|
||||
return false, resp, nil
|
||||
}
|
||||
|
||||
// AddCollaboratorOption options when adding a user as a collaborator of a repository
|
||||
type AddCollaboratorOption struct {
|
||||
Permission *string `json:"permission"`
|
||||
Permission *AccessMode `json:"permission"`
|
||||
}
|
||||
|
||||
// AccessMode represent the grade of access you have to something
|
||||
type AccessMode string
|
||||
|
||||
const (
|
||||
// AccessModeNone no access
|
||||
AccessModeNone AccessMode = "none"
|
||||
// AccessModeRead read access
|
||||
AccessModeRead AccessMode = "read"
|
||||
// AccessModeWrite write access
|
||||
AccessModeWrite AccessMode = "write"
|
||||
// AccessModeAdmin admin access
|
||||
AccessModeAdmin AccessMode = "admin"
|
||||
// AccessModeOwner owner
|
||||
AccessModeOwner AccessMode = "owner"
|
||||
)
|
||||
|
||||
// Validate the AddCollaboratorOption struct
|
||||
func (opt AddCollaboratorOption) Validate() error {
|
||||
if opt.Permission != nil {
|
||||
if *opt.Permission == AccessModeOwner {
|
||||
*opt.Permission = AccessModeAdmin
|
||||
return nil
|
||||
}
|
||||
if *opt.Permission == AccessModeNone {
|
||||
opt.Permission = nil
|
||||
return nil
|
||||
}
|
||||
if *opt.Permission != AccessModeRead && *opt.Permission != AccessModeWrite && *opt.Permission != AccessModeAdmin {
|
||||
return fmt.Errorf("permission mode invalid")
|
||||
}
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
// AddCollaborator add some user as a collaborator of a repository
|
||||
func (c *Client) AddCollaborator(user, repo, collaborator string, opt AddCollaboratorOption) error {
|
||||
func (c *Client) AddCollaborator(user, repo, collaborator string, opt AddCollaboratorOption) (*Response, error) {
|
||||
if err := opt.Validate(); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
body, err := json.Marshal(&opt)
|
||||
if err != nil {
|
||||
return err
|
||||
return nil, err
|
||||
}
|
||||
_, err = c.getResponse("PUT", fmt.Sprintf("/repos/%s/%s/collaborators/%s", user, repo, collaborator), jsonHeader, bytes.NewReader(body))
|
||||
return err
|
||||
_, resp, err := c.getResponse("PUT", fmt.Sprintf("/repos/%s/%s/collaborators/%s", user, repo, collaborator), jsonHeader, bytes.NewReader(body))
|
||||
return resp, err
|
||||
}
|
||||
|
||||
// DeleteCollaborator remove a collaborator from a repository
|
||||
func (c *Client) DeleteCollaborator(user, repo, collaborator string) error {
|
||||
_, err := c.getResponse("DELETE",
|
||||
func (c *Client) DeleteCollaborator(user, repo, collaborator string) (*Response, error) {
|
||||
_, resp, err := c.getResponse("DELETE",
|
||||
fmt.Sprintf("/repos/%s/%s/collaborators/%s", user, repo, collaborator), nil, nil)
|
||||
return err
|
||||
return resp, err
|
||||
}
|
||||
|
10
vendor/code.gitea.io/sdk/gitea/repo_commit.go
generated
vendored
10
vendor/code.gitea.io/sdk/gitea/repo_commit.go
generated
vendored
@ -55,9 +55,10 @@ type CommitDateOptions struct {
|
||||
}
|
||||
|
||||
// GetSingleCommit returns a single commit
|
||||
func (c *Client) GetSingleCommit(user, repo, commitID string) (*Commit, error) {
|
||||
func (c *Client) GetSingleCommit(user, repo, commitID string) (*Commit, *Response, error) {
|
||||
commit := new(Commit)
|
||||
return commit, c.getParsedResponse("GET", fmt.Sprintf("/repos/%s/%s/git/commits/%s", user, repo, commitID), nil, nil, &commit)
|
||||
resp, err := c.getParsedResponse("GET", fmt.Sprintf("/repos/%s/%s/git/commits/%s", user, repo, commitID), nil, nil, &commit)
|
||||
return commit, resp, err
|
||||
}
|
||||
|
||||
// ListCommitOptions list commit options
|
||||
@ -77,10 +78,11 @@ func (opt *ListCommitOptions) QueryEncode() string {
|
||||
}
|
||||
|
||||
// ListRepoCommits return list of commits from a repo
|
||||
func (c *Client) ListRepoCommits(user, repo string, opt ListCommitOptions) ([]*Commit, error) {
|
||||
func (c *Client) ListRepoCommits(user, repo string, opt ListCommitOptions) ([]*Commit, *Response, error) {
|
||||
link, _ := url.Parse(fmt.Sprintf("/repos/%s/%s/commits", user, repo))
|
||||
opt.setDefaults()
|
||||
commits := make([]*Commit, 0, opt.PageSize)
|
||||
link.RawQuery = opt.QueryEncode()
|
||||
return commits, c.getParsedResponse("GET", link.String(), nil, nil, &commits)
|
||||
resp, err := c.getParsedResponse("GET", link.String(), nil, nil, &commits)
|
||||
return commits, resp, err
|
||||
}
|
||||
|
44
vendor/code.gitea.io/sdk/gitea/repo_file.go
generated
vendored
44
vendor/code.gitea.io/sdk/gitea/repo_file.go
generated
vendored
@ -114,74 +114,76 @@ type FileDeleteResponse struct {
|
||||
|
||||
// GetFile downloads a file of repository, ref can be branch/tag/commit.
|
||||
// e.g.: ref -> master, tree -> macaron.go(no leading slash)
|
||||
func (c *Client) GetFile(user, repo, ref, tree string) ([]byte, error) {
|
||||
func (c *Client) GetFile(user, repo, ref, tree string) ([]byte, *Response, error) {
|
||||
return c.getResponse("GET", fmt.Sprintf("/repos/%s/%s/raw/%s/%s", user, repo, ref, tree), nil, nil)
|
||||
}
|
||||
|
||||
// GetContents get the metadata and contents (if a file) of an entry in a repository, or a list of entries if a dir
|
||||
// ref is optional
|
||||
func (c *Client) GetContents(owner, repo, ref, filepath string) (*ContentsResponse, error) {
|
||||
func (c *Client) GetContents(owner, repo, ref, filepath string) (*ContentsResponse, *Response, error) {
|
||||
cr := new(ContentsResponse)
|
||||
return cr, c.getParsedResponse("GET", fmt.Sprintf("/repos/%s/%s/contents/%s?ref=%s", owner, repo, filepath, ref), jsonHeader, nil, cr)
|
||||
|
||||
resp, err := c.getParsedResponse("GET", fmt.Sprintf("/repos/%s/%s/contents/%s?ref=%s", owner, repo, filepath, ref), jsonHeader, nil, cr)
|
||||
return cr, resp, err
|
||||
}
|
||||
|
||||
// CreateFile create a file in a repository
|
||||
func (c *Client) CreateFile(owner, repo, filepath string, opt CreateFileOptions) (*FileResponse, error) {
|
||||
func (c *Client) CreateFile(owner, repo, filepath string, opt CreateFileOptions) (*FileResponse, *Response, error) {
|
||||
var err error
|
||||
if opt.BranchName, err = c.setDefaultBranchForOldVersions(owner, repo, opt.BranchName); err != nil {
|
||||
return nil, err
|
||||
return nil, nil, err
|
||||
}
|
||||
|
||||
body, err := json.Marshal(&opt)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
return nil, nil, err
|
||||
}
|
||||
fr := new(FileResponse)
|
||||
return fr, c.getParsedResponse("POST", fmt.Sprintf("/repos/%s/%s/contents/%s", owner, repo, filepath), jsonHeader, bytes.NewReader(body), fr)
|
||||
resp, err := c.getParsedResponse("POST", fmt.Sprintf("/repos/%s/%s/contents/%s", owner, repo, filepath), jsonHeader, bytes.NewReader(body), fr)
|
||||
return fr, resp, err
|
||||
}
|
||||
|
||||
// UpdateFile update a file in a repository
|
||||
func (c *Client) UpdateFile(owner, repo, filepath string, opt UpdateFileOptions) (*FileResponse, error) {
|
||||
func (c *Client) UpdateFile(owner, repo, filepath string, opt UpdateFileOptions) (*FileResponse, *Response, error) {
|
||||
var err error
|
||||
if opt.BranchName, err = c.setDefaultBranchForOldVersions(owner, repo, opt.BranchName); err != nil {
|
||||
return nil, err
|
||||
return nil, nil, err
|
||||
}
|
||||
|
||||
body, err := json.Marshal(&opt)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
return nil, nil, err
|
||||
}
|
||||
fr := new(FileResponse)
|
||||
return fr, c.getParsedResponse("PUT", fmt.Sprintf("/repos/%s/%s/contents/%s", owner, repo, filepath), jsonHeader, bytes.NewReader(body), fr)
|
||||
resp, err := c.getParsedResponse("PUT", fmt.Sprintf("/repos/%s/%s/contents/%s", owner, repo, filepath), jsonHeader, bytes.NewReader(body), fr)
|
||||
return fr, resp, err
|
||||
}
|
||||
|
||||
// DeleteFile delete a file from repository
|
||||
func (c *Client) DeleteFile(owner, repo, filepath string, opt DeleteFileOptions) error {
|
||||
func (c *Client) DeleteFile(owner, repo, filepath string, opt DeleteFileOptions) (*Response, error) {
|
||||
var err error
|
||||
if opt.BranchName, err = c.setDefaultBranchForOldVersions(owner, repo, opt.BranchName); err != nil {
|
||||
return err
|
||||
return nil, err
|
||||
}
|
||||
|
||||
body, err := json.Marshal(&opt)
|
||||
if err != nil {
|
||||
return err
|
||||
return nil, err
|
||||
}
|
||||
status, err := c.getStatusCode("DELETE", fmt.Sprintf("/repos/%s/%s/contents/%s", owner, repo, filepath), jsonHeader, bytes.NewReader(body))
|
||||
status, resp, err := c.getStatusCode("DELETE", fmt.Sprintf("/repos/%s/%s/contents/%s", owner, repo, filepath), jsonHeader, bytes.NewReader(body))
|
||||
if err != nil {
|
||||
return err
|
||||
return resp, err
|
||||
}
|
||||
if status != 200 && status != 204 {
|
||||
return fmt.Errorf("unexpected Status: %d", status)
|
||||
return resp, fmt.Errorf("unexpected Status: %d", status)
|
||||
}
|
||||
return nil
|
||||
return resp, nil
|
||||
}
|
||||
|
||||
func (c *Client) setDefaultBranchForOldVersions(owner, repo, branch string) (string, error) {
|
||||
if len(branch) == 0 {
|
||||
// Gitea >= 1.12.0 Use DefaultBranch on "", mimic this for older versions
|
||||
if err := c.CheckServerVersionConstraint(">=1.12.0"); err != nil {
|
||||
r, err := c.GetRepo(owner, repo)
|
||||
if c.CheckServerVersionConstraint(">=1.12.0") != nil {
|
||||
r, _, err := c.GetRepo(owner, repo)
|
||||
if err != nil {
|
||||
return "", err
|
||||
}
|
||||
|
23
vendor/code.gitea.io/sdk/gitea/repo_key.go
generated
vendored
23
vendor/code.gitea.io/sdk/gitea/repo_key.go
generated
vendored
@ -45,32 +45,35 @@ func (opt *ListDeployKeysOptions) QueryEncode() string {
|
||||
}
|
||||
|
||||
// ListDeployKeys list all the deploy keys of one repository
|
||||
func (c *Client) ListDeployKeys(user, repo string, opt ListDeployKeysOptions) ([]*DeployKey, error) {
|
||||
func (c *Client) ListDeployKeys(user, repo string, opt ListDeployKeysOptions) ([]*DeployKey, *Response, error) {
|
||||
link, _ := url.Parse(fmt.Sprintf("/repos/%s/%s/keys", user, repo))
|
||||
opt.setDefaults()
|
||||
link.RawQuery = opt.QueryEncode()
|
||||
keys := make([]*DeployKey, 0, opt.PageSize)
|
||||
return keys, c.getParsedResponse("GET", link.String(), nil, nil, &keys)
|
||||
resp, err := c.getParsedResponse("GET", link.String(), nil, nil, &keys)
|
||||
return keys, resp, err
|
||||
}
|
||||
|
||||
// GetDeployKey get one deploy key with key id
|
||||
func (c *Client) GetDeployKey(user, repo string, keyID int64) (*DeployKey, error) {
|
||||
func (c *Client) GetDeployKey(user, repo string, keyID int64) (*DeployKey, *Response, error) {
|
||||
key := new(DeployKey)
|
||||
return key, c.getParsedResponse("GET", fmt.Sprintf("/repos/%s/%s/keys/%d", user, repo, keyID), nil, nil, &key)
|
||||
resp, err := c.getParsedResponse("GET", fmt.Sprintf("/repos/%s/%s/keys/%d", user, repo, keyID), nil, nil, &key)
|
||||
return key, resp, err
|
||||
}
|
||||
|
||||
// CreateDeployKey options when create one deploy key
|
||||
func (c *Client) CreateDeployKey(user, repo string, opt CreateKeyOption) (*DeployKey, error) {
|
||||
func (c *Client) CreateDeployKey(user, repo string, opt CreateKeyOption) (*DeployKey, *Response, error) {
|
||||
body, err := json.Marshal(&opt)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
return nil, nil, err
|
||||
}
|
||||
key := new(DeployKey)
|
||||
return key, c.getParsedResponse("POST", fmt.Sprintf("/repos/%s/%s/keys", user, repo), jsonHeader, bytes.NewReader(body), key)
|
||||
resp, err := c.getParsedResponse("POST", fmt.Sprintf("/repos/%s/%s/keys", user, repo), jsonHeader, bytes.NewReader(body), key)
|
||||
return key, resp, err
|
||||
}
|
||||
|
||||
// DeleteDeployKey delete deploy key with key id
|
||||
func (c *Client) DeleteDeployKey(owner, repo string, keyID int64) error {
|
||||
_, err := c.getResponse("DELETE", fmt.Sprintf("/repos/%s/%s/keys/%d", owner, repo, keyID), nil, nil)
|
||||
return err
|
||||
func (c *Client) DeleteDeployKey(owner, repo string, keyID int64) (*Response, error) {
|
||||
_, resp, err := c.getResponse("DELETE", fmt.Sprintf("/repos/%s/%s/keys/%d", owner, repo, keyID), nil, nil)
|
||||
return resp, err
|
||||
}
|
||||
|
115
vendor/code.gitea.io/sdk/gitea/repo_migrate.go
generated
vendored
Normal file
115
vendor/code.gitea.io/sdk/gitea/repo_migrate.go
generated
vendored
Normal file
@ -0,0 +1,115 @@
|
||||
// Copyright 2020 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"
|
||||
)
|
||||
|
||||
// GitServiceType represents a git service
|
||||
type GitServiceType string
|
||||
|
||||
const (
|
||||
// GitServicePlain represents a plain git service
|
||||
GitServicePlain GitServiceType = "git"
|
||||
//GitServiceGithub represents github.com
|
||||
GitServiceGithub GitServiceType = "github"
|
||||
// GitServiceGitlab represents a gitlab service
|
||||
GitServiceGitlab GitServiceType = "gitlab"
|
||||
|
||||
// Not supported jet
|
||||
// // GitServiceGitea represents a gitea service
|
||||
// GitServiceGitea GitServiceType = "gitea"
|
||||
// // GitServiceGogs represents a gogs service
|
||||
// GitServiceGogs GitServiceType = "gogs"
|
||||
)
|
||||
|
||||
// MigrateRepoOption options for migrating a repository from an external service
|
||||
type MigrateRepoOption struct {
|
||||
RepoName string `json:"repo_name"`
|
||||
RepoOwner string `json:"repo_owner"`
|
||||
// deprecated use RepoOwner
|
||||
RepoOwnerID int64 `json:"uid"`
|
||||
CloneAddr string `json:"clone_addr"`
|
||||
Service GitServiceType `json:"service"`
|
||||
AuthUsername string `json:"auth_username"`
|
||||
AuthPassword string `json:"auth_password"`
|
||||
AuthToken string `json:"auth_token"`
|
||||
Mirror bool `json:"mirror"`
|
||||
Private bool `json:"private"`
|
||||
Description string `json:"description"`
|
||||
Wiki bool `json:"wiki"`
|
||||
Milestones bool `json:"milestones"`
|
||||
Labels bool `json:"labels"`
|
||||
Issues bool `json:"issues"`
|
||||
PullRequests bool `json:"pull_requests"`
|
||||
Releases bool `json:"releases"`
|
||||
}
|
||||
|
||||
// Validate the MigrateRepoOption struct
|
||||
func (opt *MigrateRepoOption) Validate() error {
|
||||
// check user options
|
||||
if len(opt.CloneAddr) == 0 {
|
||||
return fmt.Errorf("CloneAddr required")
|
||||
}
|
||||
if len(opt.RepoName) == 0 {
|
||||
return fmt.Errorf("RepoName required")
|
||||
} else if len(opt.RepoName) > 100 {
|
||||
return fmt.Errorf("RepoName to long")
|
||||
}
|
||||
if len(opt.Description) > 255 {
|
||||
return fmt.Errorf("Description to long")
|
||||
}
|
||||
switch opt.Service {
|
||||
case GitServiceGithub:
|
||||
if len(opt.AuthToken) == 0 {
|
||||
return fmt.Errorf("github require token authentication")
|
||||
}
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
// MigrateRepo migrates a repository from other Git hosting sources for the authenticated user.
|
||||
//
|
||||
// To migrate a repository for a organization, the authenticated user must be a
|
||||
// owner of the specified organization.
|
||||
func (c *Client) MigrateRepo(opt MigrateRepoOption) (*Repository, *Response, error) {
|
||||
if err := opt.Validate(); err != nil {
|
||||
return nil, nil, err
|
||||
}
|
||||
|
||||
if err := c.CheckServerVersionConstraint(">=1.13.0"); err != nil {
|
||||
if len(opt.AuthToken) != 0 {
|
||||
// gitea <= 1.12 dont understand AuthToken
|
||||
opt.AuthUsername = opt.AuthToken
|
||||
opt.AuthPassword, opt.AuthToken = "", ""
|
||||
}
|
||||
if len(opt.RepoOwner) != 0 {
|
||||
// gitea <= 1.12 dont understand RepoOwner
|
||||
u, _, err := c.GetUserInfo(opt.RepoOwner)
|
||||
if err != nil {
|
||||
return nil, nil, err
|
||||
}
|
||||
opt.RepoOwnerID = u.ID
|
||||
} else if opt.RepoOwnerID == 0 {
|
||||
// gitea <= 1.12 require RepoOwnerID
|
||||
u, _, err := c.GetMyUserInfo()
|
||||
if err != nil {
|
||||
return nil, nil, err
|
||||
}
|
||||
opt.RepoOwnerID = u.ID
|
||||
}
|
||||
}
|
||||
|
||||
body, err := json.Marshal(&opt)
|
||||
if err != nil {
|
||||
return nil, nil, err
|
||||
}
|
||||
repo := new(Repository)
|
||||
resp, err := c.getParsedResponse("POST", "/repos/migrate", jsonHeader, bytes.NewReader(body), repo)
|
||||
return repo, resp, err
|
||||
}
|
28
vendor/code.gitea.io/sdk/gitea/repo_refs.go
generated
vendored
28
vendor/code.gitea.io/sdk/gitea/repo_refs.go
generated
vendored
@ -26,44 +26,44 @@ type GitObject struct {
|
||||
}
|
||||
|
||||
// GetRepoRef get one ref's information of one repository
|
||||
func (c *Client) GetRepoRef(user, repo, ref string) (*Reference, error) {
|
||||
func (c *Client) GetRepoRef(user, repo, ref string) (*Reference, *Response, 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)
|
||||
resp, 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")
|
||||
return nil, resp, errors.New("no exact match found for this ref")
|
||||
} else if err != nil {
|
||||
return nil, err
|
||||
return nil, resp, err
|
||||
}
|
||||
|
||||
return r, nil
|
||||
return r, resp, nil
|
||||
}
|
||||
|
||||
// GetRepoRefs get list of ref's information of one repository
|
||||
func (c *Client) GetRepoRefs(user, repo, ref string) ([]*Reference, error) {
|
||||
func (c *Client) GetRepoRefs(user, repo, ref string) ([]*Reference, *Response, error) {
|
||||
ref = strings.TrimPrefix(ref, "refs/")
|
||||
resp, err := c.getResponse("GET", fmt.Sprintf("/repos/%s/%s/git/refs/%s", user, repo, ref), nil, nil)
|
||||
data, resp, err := c.getResponse("GET", fmt.Sprintf("/repos/%s/%s/git/refs/%s", user, repo, ref), nil, nil)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
return nil, resp, err
|
||||
}
|
||||
|
||||
// Attempt to unmarshal single returned ref.
|
||||
r := new(Reference)
|
||||
refErr := json.Unmarshal(resp, r)
|
||||
refErr := json.Unmarshal(data, r)
|
||||
if refErr == nil {
|
||||
return []*Reference{r}, nil
|
||||
return []*Reference{r}, resp, nil
|
||||
}
|
||||
|
||||
// Attempt to unmarshal multiple refs.
|
||||
var rs []*Reference
|
||||
refsErr := json.Unmarshal(resp, &rs)
|
||||
refsErr := json.Unmarshal(data, &rs)
|
||||
if refsErr == nil {
|
||||
if len(rs) == 0 {
|
||||
return nil, errors.New("unexpected response: an array of refs with length 0")
|
||||
return nil, resp, errors.New("unexpected response: an array of refs with length 0")
|
||||
}
|
||||
return rs, nil
|
||||
return rs, resp, nil
|
||||
}
|
||||
|
||||
return nil, fmt.Errorf("unmarshalling failed for both single and multiple refs: %s and %s", refErr, refsErr)
|
||||
return nil, resp, fmt.Errorf("unmarshalling failed for both single and multiple refs: %s and %s", refErr, refsErr)
|
||||
}
|
||||
|
5
vendor/code.gitea.io/sdk/gitea/repo_tag.go
generated
vendored
5
vendor/code.gitea.io/sdk/gitea/repo_tag.go
generated
vendored
@ -23,8 +23,9 @@ type ListRepoTagsOptions struct {
|
||||
}
|
||||
|
||||
// ListRepoTags list all the branches of one repository
|
||||
func (c *Client) ListRepoTags(user, repo string, opt ListRepoTagsOptions) ([]*Tag, error) {
|
||||
func (c *Client) ListRepoTags(user, repo string, opt ListRepoTagsOptions) ([]*Tag, *Response, error) {
|
||||
opt.setDefaults()
|
||||
tags := make([]*Tag, 0, opt.PageSize)
|
||||
return tags, c.getParsedResponse("GET", fmt.Sprintf("/repos/%s/%s/tags?%s", user, repo, opt.getURLQuery().Encode()), nil, nil, &tags)
|
||||
resp, err := c.getParsedResponse("GET", fmt.Sprintf("/repos/%s/%s/tags?%s", user, repo, opt.getURLQuery().Encode()), nil, nil, &tags)
|
||||
return tags, resp, err
|
||||
}
|
||||
|
28
vendor/code.gitea.io/sdk/gitea/repo_topics.go
generated
vendored
28
vendor/code.gitea.io/sdk/gitea/repo_topics.go
generated
vendored
@ -21,38 +21,38 @@ type topicsList struct {
|
||||
}
|
||||
|
||||
// ListRepoTopics list all repository's topics
|
||||
func (c *Client) ListRepoTopics(user, repo string, opt ListRepoTopicsOptions) ([]string, error) {
|
||||
func (c *Client) ListRepoTopics(user, repo string, opt ListRepoTopicsOptions) ([]string, *Response, error) {
|
||||
opt.setDefaults()
|
||||
|
||||
list := new(topicsList)
|
||||
err := c.getParsedResponse("GET", fmt.Sprintf("/repos/%s/%s/topics?%s", user, repo, opt.getURLQuery().Encode()), nil, nil, list)
|
||||
resp, err := c.getParsedResponse("GET", fmt.Sprintf("/repos/%s/%s/topics?%s", user, repo, opt.getURLQuery().Encode()), nil, nil, list)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
return nil, resp, err
|
||||
}
|
||||
return list.Topics, nil
|
||||
return list.Topics, resp, nil
|
||||
}
|
||||
|
||||
// SetRepoTopics replaces the list of repo's topics
|
||||
func (c *Client) SetRepoTopics(user, repo string, list []string) error {
|
||||
func (c *Client) SetRepoTopics(user, repo string, list []string) (*Response, error) {
|
||||
|
||||
l := topicsList{Topics: list}
|
||||
|
||||
body, err := json.Marshal(&l)
|
||||
if err != nil {
|
||||
return err
|
||||
return nil, err
|
||||
}
|
||||
_, err = c.getResponse("PUT", fmt.Sprintf("/repos/%s/%s/topics", user, repo), jsonHeader, bytes.NewReader(body))
|
||||
return err
|
||||
_, resp, err := c.getResponse("PUT", fmt.Sprintf("/repos/%s/%s/topics", user, repo), jsonHeader, bytes.NewReader(body))
|
||||
return resp, err
|
||||
}
|
||||
|
||||
// AddRepoTopic adds a topic to a repo's topics list
|
||||
func (c *Client) AddRepoTopic(user, repo, topic string) error {
|
||||
_, err := c.getResponse("PUT", fmt.Sprintf("/repos/%s/%s/topics/%s", user, repo, topic), nil, nil)
|
||||
return err
|
||||
func (c *Client) AddRepoTopic(user, repo, topic string) (*Response, error) {
|
||||
_, resp, err := c.getResponse("PUT", fmt.Sprintf("/repos/%s/%s/topics/%s", user, repo, topic), nil, nil)
|
||||
return resp, err
|
||||
}
|
||||
|
||||
// DeleteRepoTopic deletes a topic from repo's topics list
|
||||
func (c *Client) DeleteRepoTopic(user, repo, topic string) error {
|
||||
_, err := c.getResponse("DELETE", fmt.Sprintf("/repos/%s/%s/topics/%s", user, repo, topic), nil, nil)
|
||||
return err
|
||||
func (c *Client) DeleteRepoTopic(user, repo, topic string) (*Response, error) {
|
||||
_, resp, err := c.getResponse("DELETE", fmt.Sprintf("/repos/%s/%s/topics/%s", user, repo, topic), nil, nil)
|
||||
return resp, err
|
||||
}
|
||||
|
9
vendor/code.gitea.io/sdk/gitea/repo_transfer.go
generated
vendored
9
vendor/code.gitea.io/sdk/gitea/repo_transfer.go
generated
vendored
@ -19,14 +19,15 @@ type TransferRepoOption struct {
|
||||
}
|
||||
|
||||
// TransferRepo transfers the ownership of a repository
|
||||
func (c *Client) TransferRepo(owner, reponame string, opt TransferRepoOption) (*Repository, error) {
|
||||
func (c *Client) TransferRepo(owner, reponame string, opt TransferRepoOption) (*Repository, *Response, error) {
|
||||
if err := c.CheckServerVersionConstraint(">=1.12.0"); err != nil {
|
||||
return nil, err
|
||||
return nil, nil, err
|
||||
}
|
||||
body, err := json.Marshal(&opt)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
return nil, nil, err
|
||||
}
|
||||
repo := new(Repository)
|
||||
return repo, c.getParsedResponse("POST", fmt.Sprintf("/repos/%s/%s/transfer", owner, reponame), jsonHeader, bytes.NewReader(body), repo)
|
||||
resp, err := c.getParsedResponse("POST", fmt.Sprintf("/repos/%s/%s/transfer", owner, reponame), jsonHeader, bytes.NewReader(body), repo)
|
||||
return repo, resp, err
|
||||
}
|
||||
|
5
vendor/code.gitea.io/sdk/gitea/repo_tree.go
generated
vendored
5
vendor/code.gitea.io/sdk/gitea/repo_tree.go
generated
vendored
@ -30,11 +30,12 @@ type GitTreeResponse struct {
|
||||
|
||||
// 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) {
|
||||
func (c *Client) GetTrees(user, repo, ref string, recursive bool) (*GitTreeResponse, *Response, error) {
|
||||
trees := new(GitTreeResponse)
|
||||
var path = fmt.Sprintf("/repos/%s/%s/git/trees/%s", user, repo, ref)
|
||||
if recursive {
|
||||
path += "?recursive=1"
|
||||
}
|
||||
return trees, c.getParsedResponse("GET", path, nil, nil, trees)
|
||||
resp, err := c.getParsedResponse("GET", path, nil, nil, trees)
|
||||
return trees, resp, err
|
||||
}
|
||||
|
42
vendor/code.gitea.io/sdk/gitea/repo_watch.go
generated
vendored
42
vendor/code.gitea.io/sdk/gitea/repo_watch.go
generated
vendored
@ -21,53 +21,55 @@ type WatchInfo struct {
|
||||
}
|
||||
|
||||
// GetWatchedRepos list all the watched repos of user
|
||||
func (c *Client) GetWatchedRepos(user string) ([]*Repository, error) {
|
||||
func (c *Client) GetWatchedRepos(user string) ([]*Repository, *Response, error) {
|
||||
repos := make([]*Repository, 0, 10)
|
||||
return repos, c.getParsedResponse("GET", fmt.Sprintf("/users/%s/subscriptions", user), nil, nil, &repos)
|
||||
resp, err := c.getParsedResponse("GET", fmt.Sprintf("/users/%s/subscriptions", user), nil, nil, &repos)
|
||||
return repos, resp, err
|
||||
}
|
||||
|
||||
// GetMyWatchedRepos list repositories watched by the authenticated user
|
||||
func (c *Client) GetMyWatchedRepos() ([]*Repository, error) {
|
||||
func (c *Client) GetMyWatchedRepos() ([]*Repository, *Response, error) {
|
||||
repos := make([]*Repository, 0, 10)
|
||||
return repos, c.getParsedResponse("GET", fmt.Sprintf("/user/subscriptions"), nil, nil, &repos)
|
||||
resp, err := c.getParsedResponse("GET", fmt.Sprintf("/user/subscriptions"), nil, nil, &repos)
|
||||
return repos, resp, err
|
||||
}
|
||||
|
||||
// CheckRepoWatch check if the current user is watching a repo
|
||||
func (c *Client) CheckRepoWatch(repoUser, repoName string) (bool, error) {
|
||||
status, err := c.getStatusCode("GET", fmt.Sprintf("/repos/%s/%s/subscription", repoUser, repoName), nil, nil)
|
||||
func (c *Client) CheckRepoWatch(repoUser, repoName string) (bool, *Response, error) {
|
||||
status, resp, err := c.getStatusCode("GET", fmt.Sprintf("/repos/%s/%s/subscription", repoUser, repoName), nil, nil)
|
||||
if err != nil {
|
||||
return false, err
|
||||
return false, resp, err
|
||||
}
|
||||
switch status {
|
||||
case http.StatusNotFound:
|
||||
return false, nil
|
||||
return false, resp, nil
|
||||
case http.StatusOK:
|
||||
return true, nil
|
||||
return true, resp, nil
|
||||
default:
|
||||
return false, fmt.Errorf("unexpected Status: %d", status)
|
||||
return false, resp, fmt.Errorf("unexpected Status: %d", status)
|
||||
}
|
||||
}
|
||||
|
||||
// WatchRepo start to watch a repository
|
||||
func (c *Client) WatchRepo(repoUser, repoName string) error {
|
||||
status, err := c.getStatusCode("PUT", fmt.Sprintf("/repos/%s/%s/subscription", repoUser, repoName), nil, nil)
|
||||
func (c *Client) WatchRepo(repoUser, repoName string) (*Response, error) {
|
||||
status, resp, err := c.getStatusCode("PUT", fmt.Sprintf("/repos/%s/%s/subscription", repoUser, repoName), nil, nil)
|
||||
if err != nil {
|
||||
return err
|
||||
return resp, err
|
||||
}
|
||||
if status == http.StatusOK {
|
||||
return nil
|
||||
return resp, nil
|
||||
}
|
||||
return fmt.Errorf("unexpected Status: %d", status)
|
||||
return resp, fmt.Errorf("unexpected Status: %d", status)
|
||||
}
|
||||
|
||||
// UnWatchRepo stop to watch a repository
|
||||
func (c *Client) UnWatchRepo(repoUser, repoName string) error {
|
||||
status, err := c.getStatusCode("DELETE", fmt.Sprintf("/repos/%s/%s/subscription", repoUser, repoName), nil, nil)
|
||||
func (c *Client) UnWatchRepo(repoUser, repoName string) (*Response, error) {
|
||||
status, resp, err := c.getStatusCode("DELETE", fmt.Sprintf("/repos/%s/%s/subscription", repoUser, repoName), nil, nil)
|
||||
if err != nil {
|
||||
return err
|
||||
return resp, err
|
||||
}
|
||||
if status == http.StatusNoContent {
|
||||
return nil
|
||||
return resp, nil
|
||||
}
|
||||
return fmt.Errorf("unexpected Status: %d", status)
|
||||
return resp, fmt.Errorf("unexpected Status: %d", status)
|
||||
}
|
||||
|
72
vendor/code.gitea.io/sdk/gitea/settings.go
generated
vendored
Normal file
72
vendor/code.gitea.io/sdk/gitea/settings.go
generated
vendored
Normal file
@ -0,0 +1,72 @@
|
||||
// Copyright 2020 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
|
||||
|
||||
// GlobalUISettings represent the global ui settings of a gitea instance witch is exposed by API
|
||||
type GlobalUISettings struct {
|
||||
AllowedReactions []string `json:"allowed_reactions"`
|
||||
}
|
||||
|
||||
// GlobalRepoSettings represent the global repository settings of a gitea instance witch is exposed by API
|
||||
type GlobalRepoSettings struct {
|
||||
MirrorsDisabled bool `json:"mirrors_disabled"`
|
||||
HTTPGitDisabled bool `json:"http_git_disabled"`
|
||||
}
|
||||
|
||||
// GlobalAPISettings contains global api settings exposed by it
|
||||
type GlobalAPISettings struct {
|
||||
MaxResponseItems int `json:"max_response_items"`
|
||||
DefaultPagingNum int `json:"default_paging_num"`
|
||||
DefaultGitTreesPerPage int `json:"default_git_trees_per_page"`
|
||||
DefaultMaxBlobSize int64 `json:"default_max_blob_size"`
|
||||
}
|
||||
|
||||
// GlobalAttachmentSettings contains global Attachment settings exposed by API
|
||||
type GlobalAttachmentSettings struct {
|
||||
Enabled bool `json:"enabled"`
|
||||
AllowedTypes string `json:"allowed_types"`
|
||||
MaxSize int64 `json:"max_size"`
|
||||
MaxFiles int `json:"max_files"`
|
||||
}
|
||||
|
||||
// GetGlobalUISettings get global ui settings witch are exposed by API
|
||||
func (c *Client) GetGlobalUISettings() (*GlobalUISettings, *Response, error) {
|
||||
if err := c.CheckServerVersionConstraint(">=1.13.0"); err != nil {
|
||||
return nil, nil, err
|
||||
}
|
||||
conf := new(GlobalUISettings)
|
||||
resp, err := c.getParsedResponse("GET", "/settings/ui", jsonHeader, nil, &conf)
|
||||
return conf, resp, err
|
||||
}
|
||||
|
||||
// GetGlobalRepoSettings get global repository settings witch are exposed by API
|
||||
func (c *Client) GetGlobalRepoSettings() (*GlobalRepoSettings, *Response, error) {
|
||||
if err := c.CheckServerVersionConstraint(">=1.13.0"); err != nil {
|
||||
return nil, nil, err
|
||||
}
|
||||
conf := new(GlobalRepoSettings)
|
||||
resp, err := c.getParsedResponse("GET", "/settings/repository", jsonHeader, nil, &conf)
|
||||
return conf, resp, err
|
||||
}
|
||||
|
||||
// GetGlobalAPISettings get global api settings witch are exposed by it
|
||||
func (c *Client) GetGlobalAPISettings() (*GlobalAPISettings, *Response, error) {
|
||||
if err := c.CheckServerVersionConstraint(">=1.13.0"); err != nil {
|
||||
return nil, nil, err
|
||||
}
|
||||
conf := new(GlobalAPISettings)
|
||||
resp, err := c.getParsedResponse("GET", "/settings/api", jsonHeader, nil, &conf)
|
||||
return conf, resp, err
|
||||
}
|
||||
|
||||
// GetGlobalAttachmentSettings get global repository settings witch are exposed by API
|
||||
func (c *Client) GetGlobalAttachmentSettings() (*GlobalAttachmentSettings, *Response, error) {
|
||||
if err := c.CheckServerVersionConstraint(">=1.13.0"); err != nil {
|
||||
return nil, nil, err
|
||||
}
|
||||
conf := new(GlobalAttachmentSettings)
|
||||
resp, err := c.getParsedResponse("GET", "/settings/attachment", jsonHeader, nil, &conf)
|
||||
return conf, resp, err
|
||||
}
|
17
vendor/code.gitea.io/sdk/gitea/status.go
generated
vendored
17
vendor/code.gitea.io/sdk/gitea/status.go
generated
vendored
@ -50,13 +50,14 @@ type CreateStatusOption struct {
|
||||
}
|
||||
|
||||
// CreateStatus creates a new Status for a given Commit
|
||||
func (c *Client) CreateStatus(owner, repo, sha string, opts CreateStatusOption) (*Status, error) {
|
||||
func (c *Client) CreateStatus(owner, repo, sha string, opts CreateStatusOption) (*Status, *Response, error) {
|
||||
body, err := json.Marshal(&opts)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
return nil, nil, err
|
||||
}
|
||||
status := new(Status)
|
||||
return status, c.getParsedResponse("POST", fmt.Sprintf("/repos/%s/%s/statuses/%s", owner, repo, sha), jsonHeader, bytes.NewReader(body), status)
|
||||
resp, err := c.getParsedResponse("POST", fmt.Sprintf("/repos/%s/%s/statuses/%s", owner, repo, sha), jsonHeader, bytes.NewReader(body), status)
|
||||
return status, resp, err
|
||||
}
|
||||
|
||||
// ListStatusesOption options for listing a repository's commit's statuses
|
||||
@ -65,10 +66,11 @@ type ListStatusesOption struct {
|
||||
}
|
||||
|
||||
// ListStatuses returns all statuses for a given Commit
|
||||
func (c *Client) ListStatuses(owner, repo, sha string, opt ListStatusesOption) ([]*Status, error) {
|
||||
func (c *Client) ListStatuses(owner, repo, sha string, opt ListStatusesOption) ([]*Status, *Response, error) {
|
||||
opt.setDefaults()
|
||||
statuses := make([]*Status, 0, opt.PageSize)
|
||||
return statuses, c.getParsedResponse("GET", fmt.Sprintf("/repos/%s/%s/commits/%s/statuses?%s", owner, repo, sha, opt.getURLQuery().Encode()), nil, nil, &statuses)
|
||||
resp, err := c.getParsedResponse("GET", fmt.Sprintf("/repos/%s/%s/commits/%s/statuses?%s", owner, repo, sha, opt.getURLQuery().Encode()), nil, nil, &statuses)
|
||||
return statuses, resp, err
|
||||
}
|
||||
|
||||
// CombinedStatus holds the combined state of several statuses for a single commit
|
||||
@ -83,7 +85,8 @@ type CombinedStatus struct {
|
||||
}
|
||||
|
||||
// GetCombinedStatus returns the CombinedStatus for a given Commit
|
||||
func (c *Client) GetCombinedStatus(owner, repo, sha string) (*CombinedStatus, error) {
|
||||
func (c *Client) GetCombinedStatus(owner, repo, sha string) (*CombinedStatus, *Response, error) {
|
||||
status := new(CombinedStatus)
|
||||
return status, c.getParsedResponse("GET", fmt.Sprintf("/repos/%s/%s/commits/%s/status", owner, repo, sha), nil, nil, status)
|
||||
resp, err := c.getParsedResponse("GET", fmt.Sprintf("/repos/%s/%s/commits/%s/status", owner, repo, sha), nil, nil, status)
|
||||
return status, resp, err
|
||||
}
|
||||
|
12
vendor/code.gitea.io/sdk/gitea/user.go
generated
vendored
12
vendor/code.gitea.io/sdk/gitea/user.go
generated
vendored
@ -29,15 +29,15 @@ type User struct {
|
||||
}
|
||||
|
||||
// GetUserInfo get user info by user's name
|
||||
func (c *Client) GetUserInfo(user string) (*User, error) {
|
||||
func (c *Client) GetUserInfo(user string) (*User, *Response, error) {
|
||||
u := new(User)
|
||||
err := c.getParsedResponse("GET", fmt.Sprintf("/users/%s", user), nil, nil, u)
|
||||
return u, err
|
||||
resp, err := c.getParsedResponse("GET", fmt.Sprintf("/users/%s", user), nil, nil, u)
|
||||
return u, resp, err
|
||||
}
|
||||
|
||||
// GetMyUserInfo get user info of current user
|
||||
func (c *Client) GetMyUserInfo() (*User, error) {
|
||||
func (c *Client) GetMyUserInfo() (*User, *Response, error) {
|
||||
u := new(User)
|
||||
err := c.getParsedResponse("GET", "/user", nil, nil, u)
|
||||
return u, err
|
||||
resp, err := c.getParsedResponse("GET", "/user", nil, nil, u)
|
||||
return u, resp, err
|
||||
}
|
||||
|
42
vendor/code.gitea.io/sdk/gitea/user_app.go
generated
vendored
42
vendor/code.gitea.io/sdk/gitea/user_app.go
generated
vendored
@ -9,6 +9,7 @@ import (
|
||||
"bytes"
|
||||
"encoding/json"
|
||||
"fmt"
|
||||
"reflect"
|
||||
)
|
||||
|
||||
// AccessToken represents an API access token.
|
||||
@ -25,13 +26,14 @@ type ListAccessTokensOptions struct {
|
||||
}
|
||||
|
||||
// ListAccessTokens lists all the access tokens of user
|
||||
func (c *Client) ListAccessTokens(opts ListAccessTokensOptions) ([]*AccessToken, error) {
|
||||
func (c *Client) ListAccessTokens(opts ListAccessTokensOptions) ([]*AccessToken, *Response, error) {
|
||||
if len(c.username) == 0 {
|
||||
return nil, fmt.Errorf("\"username\" not set: only BasicAuth allowed")
|
||||
return nil, nil, fmt.Errorf("\"username\" not set: only BasicAuth allowed")
|
||||
}
|
||||
opts.setDefaults()
|
||||
tokens := make([]*AccessToken, 0, opts.PageSize)
|
||||
return tokens, c.getParsedResponse("GET", fmt.Sprintf("/users/%s/tokens?%s", c.username, opts.getURLQuery().Encode()), jsonHeader, nil, &tokens)
|
||||
resp, err := c.getParsedResponse("GET", fmt.Sprintf("/users/%s/tokens?%s", c.username, opts.getURLQuery().Encode()), jsonHeader, nil, &tokens)
|
||||
return tokens, resp, err
|
||||
}
|
||||
|
||||
// CreateAccessTokenOption options when create access token
|
||||
@ -40,23 +42,39 @@ type CreateAccessTokenOption struct {
|
||||
}
|
||||
|
||||
// CreateAccessToken create one access token with options
|
||||
func (c *Client) CreateAccessToken(opt CreateAccessTokenOption) (*AccessToken, error) {
|
||||
func (c *Client) CreateAccessToken(opt CreateAccessTokenOption) (*AccessToken, *Response, error) {
|
||||
if len(c.username) == 0 {
|
||||
return nil, fmt.Errorf("\"username\" not set: only BasicAuth allowed")
|
||||
return nil, nil, fmt.Errorf("\"username\" not set: only BasicAuth allowed")
|
||||
}
|
||||
body, err := json.Marshal(&opt)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
return nil, nil, err
|
||||
}
|
||||
t := new(AccessToken)
|
||||
return t, c.getParsedResponse("POST", fmt.Sprintf("/users/%s/tokens", c.username), jsonHeader, bytes.NewReader(body), t)
|
||||
resp, err := c.getParsedResponse("POST", fmt.Sprintf("/users/%s/tokens", c.username), jsonHeader, bytes.NewReader(body), t)
|
||||
return t, resp, err
|
||||
}
|
||||
|
||||
// DeleteAccessToken delete token with key id
|
||||
func (c *Client) DeleteAccessToken(keyID int64) error {
|
||||
// DeleteAccessToken delete token, identified by ID and if not available by name
|
||||
func (c *Client) DeleteAccessToken(value interface{}) (*Response, error) {
|
||||
if len(c.username) == 0 {
|
||||
return fmt.Errorf("\"username\" not set: only BasicAuth allowed")
|
||||
return nil, fmt.Errorf("\"username\" not set: only BasicAuth allowed")
|
||||
}
|
||||
_, err := c.getResponse("DELETE", fmt.Sprintf("/users/%s/tokens/%d", c.username, keyID), jsonHeader, nil)
|
||||
return err
|
||||
|
||||
var token = ""
|
||||
|
||||
switch reflect.ValueOf(value).Kind() {
|
||||
case reflect.Int64:
|
||||
token = fmt.Sprintf("%d", value.(int64))
|
||||
case reflect.String:
|
||||
if err := c.CheckServerVersionConstraint(">= 1.13.0"); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
token = value.(string)
|
||||
default:
|
||||
return nil, fmt.Errorf("only string and int64 supported")
|
||||
}
|
||||
|
||||
_, resp, err := c.getResponse("DELETE", fmt.Sprintf("/users/%s/tokens/%s", c.username, token), jsonHeader, nil)
|
||||
return resp, err
|
||||
}
|
||||
|
20
vendor/code.gitea.io/sdk/gitea/user_email.go
generated
vendored
20
vendor/code.gitea.io/sdk/gitea/user_email.go
generated
vendored
@ -23,10 +23,11 @@ type ListEmailsOptions struct {
|
||||
}
|
||||
|
||||
// ListEmails all the email addresses of user
|
||||
func (c *Client) ListEmails(opt ListEmailsOptions) ([]*Email, error) {
|
||||
func (c *Client) ListEmails(opt ListEmailsOptions) ([]*Email, *Response, error) {
|
||||
opt.setDefaults()
|
||||
emails := make([]*Email, 0, opt.PageSize)
|
||||
return emails, c.getParsedResponse("GET", fmt.Sprintf("/user/emails?%s", opt.getURLQuery().Encode()), nil, nil, &emails)
|
||||
resp, err := c.getParsedResponse("GET", fmt.Sprintf("/user/emails?%s", opt.getURLQuery().Encode()), nil, nil, &emails)
|
||||
return emails, resp, err
|
||||
}
|
||||
|
||||
// CreateEmailOption options when creating email addresses
|
||||
@ -36,13 +37,14 @@ type CreateEmailOption struct {
|
||||
}
|
||||
|
||||
// AddEmail add one email to current user with options
|
||||
func (c *Client) AddEmail(opt CreateEmailOption) ([]*Email, error) {
|
||||
func (c *Client) AddEmail(opt CreateEmailOption) ([]*Email, *Response, error) {
|
||||
body, err := json.Marshal(&opt)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
return nil, nil, err
|
||||
}
|
||||
emails := make([]*Email, 0, 3)
|
||||
return emails, c.getParsedResponse("POST", "/user/emails", jsonHeader, bytes.NewReader(body), &emails)
|
||||
resp, err := c.getParsedResponse("POST", "/user/emails", jsonHeader, bytes.NewReader(body), &emails)
|
||||
return emails, resp, err
|
||||
}
|
||||
|
||||
// DeleteEmailOption options when deleting email addresses
|
||||
@ -52,11 +54,11 @@ type DeleteEmailOption struct {
|
||||
}
|
||||
|
||||
// DeleteEmail delete one email of current users'
|
||||
func (c *Client) DeleteEmail(opt DeleteEmailOption) error {
|
||||
func (c *Client) DeleteEmail(opt DeleteEmailOption) (*Response, error) {
|
||||
body, err := json.Marshal(&opt)
|
||||
if err != nil {
|
||||
return err
|
||||
return nil, err
|
||||
}
|
||||
_, err = c.getResponse("DELETE", "/user/emails", jsonHeader, bytes.NewReader(body))
|
||||
return err
|
||||
_, resp, err := c.getResponse("DELETE", "/user/emails", jsonHeader, bytes.NewReader(body))
|
||||
return resp, err
|
||||
}
|
||||
|
44
vendor/code.gitea.io/sdk/gitea/user_follow.go
generated
vendored
44
vendor/code.gitea.io/sdk/gitea/user_follow.go
generated
vendored
@ -12,17 +12,19 @@ type ListFollowersOptions struct {
|
||||
}
|
||||
|
||||
// ListMyFollowers list all the followers of current user
|
||||
func (c *Client) ListMyFollowers(opt ListFollowersOptions) ([]*User, error) {
|
||||
func (c *Client) ListMyFollowers(opt ListFollowersOptions) ([]*User, *Response, error) {
|
||||
opt.setDefaults()
|
||||
users := make([]*User, 0, opt.PageSize)
|
||||
return users, c.getParsedResponse("GET", fmt.Sprintf("/user/followers?%s", opt.getURLQuery().Encode()), nil, nil, &users)
|
||||
resp, err := c.getParsedResponse("GET", fmt.Sprintf("/user/followers?%s", opt.getURLQuery().Encode()), nil, nil, &users)
|
||||
return users, resp, err
|
||||
}
|
||||
|
||||
// ListFollowers list all the followers of one user
|
||||
func (c *Client) ListFollowers(user string, opt ListFollowersOptions) ([]*User, error) {
|
||||
func (c *Client) ListFollowers(user string, opt ListFollowersOptions) ([]*User, *Response, error) {
|
||||
opt.setDefaults()
|
||||
users := make([]*User, 0, opt.PageSize)
|
||||
return users, c.getParsedResponse("GET", fmt.Sprintf("/users/%s/followers?%s", user, opt.getURLQuery().Encode()), nil, nil, &users)
|
||||
resp, err := c.getParsedResponse("GET", fmt.Sprintf("/users/%s/followers?%s", user, opt.getURLQuery().Encode()), nil, nil, &users)
|
||||
return users, resp, err
|
||||
}
|
||||
|
||||
// ListFollowingOptions options for listing a user's users being followed
|
||||
@ -31,39 +33,41 @@ type ListFollowingOptions struct {
|
||||
}
|
||||
|
||||
// ListMyFollowing list all the users current user followed
|
||||
func (c *Client) ListMyFollowing(opt ListFollowingOptions) ([]*User, error) {
|
||||
func (c *Client) ListMyFollowing(opt ListFollowingOptions) ([]*User, *Response, error) {
|
||||
opt.setDefaults()
|
||||
users := make([]*User, 0, opt.PageSize)
|
||||
return users, c.getParsedResponse("GET", fmt.Sprintf("/user/following?%s", opt.getURLQuery().Encode()), nil, nil, &users)
|
||||
resp, err := c.getParsedResponse("GET", fmt.Sprintf("/user/following?%s", opt.getURLQuery().Encode()), nil, nil, &users)
|
||||
return users, resp, err
|
||||
}
|
||||
|
||||
// ListFollowing list all the users the user followed
|
||||
func (c *Client) ListFollowing(user string, opt ListFollowingOptions) ([]*User, error) {
|
||||
func (c *Client) ListFollowing(user string, opt ListFollowingOptions) ([]*User, *Response, error) {
|
||||
opt.setDefaults()
|
||||
users := make([]*User, 0, opt.PageSize)
|
||||
return users, c.getParsedResponse("GET", fmt.Sprintf("/users/%s/following?%s", user, opt.getURLQuery().Encode()), nil, nil, &users)
|
||||
resp, err := c.getParsedResponse("GET", fmt.Sprintf("/users/%s/following?%s", user, opt.getURLQuery().Encode()), nil, nil, &users)
|
||||
return users, resp, err
|
||||
}
|
||||
|
||||
// IsFollowing if current user followed the target
|
||||
func (c *Client) IsFollowing(target string) bool {
|
||||
_, err := c.getResponse("GET", fmt.Sprintf("/user/following/%s", target), nil, nil)
|
||||
return err == nil
|
||||
func (c *Client) IsFollowing(target string) (bool, *Response) {
|
||||
_, resp, err := c.getResponse("GET", fmt.Sprintf("/user/following/%s", target), nil, nil)
|
||||
return err == nil, resp
|
||||
}
|
||||
|
||||
// IsUserFollowing if the user followed the target
|
||||
func (c *Client) IsUserFollowing(user, target string) bool {
|
||||
_, err := c.getResponse("GET", fmt.Sprintf("/users/%s/following/%s", user, target), nil, nil)
|
||||
return err == nil
|
||||
func (c *Client) IsUserFollowing(user, target string) (bool, *Response) {
|
||||
_, resp, err := c.getResponse("GET", fmt.Sprintf("/users/%s/following/%s", user, target), nil, nil)
|
||||
return err == nil, resp
|
||||
}
|
||||
|
||||
// Follow set current user follow the target
|
||||
func (c *Client) Follow(target string) error {
|
||||
_, err := c.getResponse("PUT", fmt.Sprintf("/user/following/%s", target), nil, nil)
|
||||
return err
|
||||
func (c *Client) Follow(target string) (*Response, error) {
|
||||
_, resp, err := c.getResponse("PUT", fmt.Sprintf("/user/following/%s", target), nil, nil)
|
||||
return resp, err
|
||||
}
|
||||
|
||||
// Unfollow set current user unfollow the target
|
||||
func (c *Client) Unfollow(target string) error {
|
||||
_, err := c.getResponse("DELETE", fmt.Sprintf("/user/following/%s", target), nil, nil)
|
||||
return err
|
||||
func (c *Client) Unfollow(target string) (*Response, error) {
|
||||
_, resp, err := c.getResponse("DELETE", fmt.Sprintf("/user/following/%s", target), nil, nil)
|
||||
return resp, err
|
||||
}
|
||||
|
28
vendor/code.gitea.io/sdk/gitea/user_gpgkey.go
generated
vendored
28
vendor/code.gitea.io/sdk/gitea/user_gpgkey.go
generated
vendored
@ -39,23 +39,26 @@ type ListGPGKeysOptions struct {
|
||||
}
|
||||
|
||||
// ListGPGKeys list all the GPG keys of the user
|
||||
func (c *Client) ListGPGKeys(user string, opt ListGPGKeysOptions) ([]*GPGKey, error) {
|
||||
func (c *Client) ListGPGKeys(user string, opt ListGPGKeysOptions) ([]*GPGKey, *Response, error) {
|
||||
opt.setDefaults()
|
||||
keys := make([]*GPGKey, 0, opt.PageSize)
|
||||
return keys, c.getParsedResponse("GET", fmt.Sprintf("/users/%s/gpg_keys?%s", user, opt.getURLQuery().Encode()), nil, nil, &keys)
|
||||
resp, err := c.getParsedResponse("GET", fmt.Sprintf("/users/%s/gpg_keys?%s", user, opt.getURLQuery().Encode()), nil, nil, &keys)
|
||||
return keys, resp, err
|
||||
}
|
||||
|
||||
// ListMyGPGKeys list all the GPG keys of current user
|
||||
func (c *Client) ListMyGPGKeys(opt *ListGPGKeysOptions) ([]*GPGKey, error) {
|
||||
func (c *Client) ListMyGPGKeys(opt *ListGPGKeysOptions) ([]*GPGKey, *Response, error) {
|
||||
opt.setDefaults()
|
||||
keys := make([]*GPGKey, 0, opt.PageSize)
|
||||
return keys, c.getParsedResponse("GET", fmt.Sprintf("/user/gpg_keys?%s", opt.getURLQuery().Encode()), nil, nil, &keys)
|
||||
resp, err := c.getParsedResponse("GET", fmt.Sprintf("/user/gpg_keys?%s", opt.getURLQuery().Encode()), nil, nil, &keys)
|
||||
return keys, resp, err
|
||||
}
|
||||
|
||||
// GetGPGKey get current user's GPG key by key id
|
||||
func (c *Client) GetGPGKey(keyID int64) (*GPGKey, error) {
|
||||
func (c *Client) GetGPGKey(keyID int64) (*GPGKey, *Response, error) {
|
||||
key := new(GPGKey)
|
||||
return key, c.getParsedResponse("GET", fmt.Sprintf("/user/gpg_keys/%d", keyID), nil, nil, &key)
|
||||
resp, err := c.getParsedResponse("GET", fmt.Sprintf("/user/gpg_keys/%d", keyID), nil, nil, &key)
|
||||
return key, resp, err
|
||||
}
|
||||
|
||||
// CreateGPGKeyOption options create user GPG key
|
||||
@ -66,17 +69,18 @@ type CreateGPGKeyOption struct {
|
||||
}
|
||||
|
||||
// CreateGPGKey create GPG key with options
|
||||
func (c *Client) CreateGPGKey(opt CreateGPGKeyOption) (*GPGKey, error) {
|
||||
func (c *Client) CreateGPGKey(opt CreateGPGKeyOption) (*GPGKey, *Response, error) {
|
||||
body, err := json.Marshal(&opt)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
return nil, nil, err
|
||||
}
|
||||
key := new(GPGKey)
|
||||
return key, c.getParsedResponse("POST", "/user/gpg_keys", jsonHeader, bytes.NewReader(body), key)
|
||||
resp, err := c.getParsedResponse("POST", "/user/gpg_keys", jsonHeader, bytes.NewReader(body), key)
|
||||
return key, resp, err
|
||||
}
|
||||
|
||||
// DeleteGPGKey delete GPG key with key id
|
||||
func (c *Client) DeleteGPGKey(keyID int64) error {
|
||||
_, err := c.getResponse("DELETE", fmt.Sprintf("/user/gpg_keys/%d", keyID), nil, nil)
|
||||
return err
|
||||
func (c *Client) DeleteGPGKey(keyID int64) (*Response, error) {
|
||||
_, resp, err := c.getResponse("DELETE", fmt.Sprintf("/user/gpg_keys/%d", keyID), nil, nil)
|
||||
return resp, err
|
||||
}
|
||||
|
28
vendor/code.gitea.io/sdk/gitea/user_key.go
generated
vendored
28
vendor/code.gitea.io/sdk/gitea/user_key.go
generated
vendored
@ -30,23 +30,26 @@ type ListPublicKeysOptions struct {
|
||||
}
|
||||
|
||||
// ListPublicKeys list all the public keys of the user
|
||||
func (c *Client) ListPublicKeys(user string, opt ListPublicKeysOptions) ([]*PublicKey, error) {
|
||||
func (c *Client) ListPublicKeys(user string, opt ListPublicKeysOptions) ([]*PublicKey, *Response, error) {
|
||||
opt.setDefaults()
|
||||
keys := make([]*PublicKey, 0, opt.PageSize)
|
||||
return keys, c.getParsedResponse("GET", fmt.Sprintf("/users/%s/keys?%s", user, opt.getURLQuery().Encode()), nil, nil, &keys)
|
||||
resp, err := c.getParsedResponse("GET", fmt.Sprintf("/users/%s/keys?%s", user, opt.getURLQuery().Encode()), nil, nil, &keys)
|
||||
return keys, resp, err
|
||||
}
|
||||
|
||||
// ListMyPublicKeys list all the public keys of current user
|
||||
func (c *Client) ListMyPublicKeys(opt ListPublicKeysOptions) ([]*PublicKey, error) {
|
||||
func (c *Client) ListMyPublicKeys(opt ListPublicKeysOptions) ([]*PublicKey, *Response, error) {
|
||||
opt.setDefaults()
|
||||
keys := make([]*PublicKey, 0, opt.PageSize)
|
||||
return keys, c.getParsedResponse("GET", fmt.Sprintf("/user/keys?%s", opt.getURLQuery().Encode()), nil, nil, &keys)
|
||||
resp, err := c.getParsedResponse("GET", fmt.Sprintf("/user/keys?%s", opt.getURLQuery().Encode()), nil, nil, &keys)
|
||||
return keys, resp, err
|
||||
}
|
||||
|
||||
// GetPublicKey get current user's public key by key id
|
||||
func (c *Client) GetPublicKey(keyID int64) (*PublicKey, error) {
|
||||
func (c *Client) GetPublicKey(keyID int64) (*PublicKey, *Response, error) {
|
||||
key := new(PublicKey)
|
||||
return key, c.getParsedResponse("GET", fmt.Sprintf("/user/keys/%d", keyID), nil, nil, &key)
|
||||
resp, err := c.getParsedResponse("GET", fmt.Sprintf("/user/keys/%d", keyID), nil, nil, &key)
|
||||
return key, resp, err
|
||||
}
|
||||
|
||||
// CreateKeyOption options when creating a key
|
||||
@ -60,17 +63,18 @@ type CreateKeyOption struct {
|
||||
}
|
||||
|
||||
// CreatePublicKey create public key with options
|
||||
func (c *Client) CreatePublicKey(opt CreateKeyOption) (*PublicKey, error) {
|
||||
func (c *Client) CreatePublicKey(opt CreateKeyOption) (*PublicKey, *Response, error) {
|
||||
body, err := json.Marshal(&opt)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
return nil, nil, err
|
||||
}
|
||||
key := new(PublicKey)
|
||||
return key, c.getParsedResponse("POST", "/user/keys", jsonHeader, bytes.NewReader(body), key)
|
||||
resp, err := c.getParsedResponse("POST", "/user/keys", jsonHeader, bytes.NewReader(body), key)
|
||||
return key, resp, err
|
||||
}
|
||||
|
||||
// DeletePublicKey delete public key with key id
|
||||
func (c *Client) DeletePublicKey(keyID int64) error {
|
||||
_, err := c.getResponse("DELETE", fmt.Sprintf("/user/keys/%d", keyID), nil, nil)
|
||||
return err
|
||||
func (c *Client) DeletePublicKey(keyID int64) (*Response, error) {
|
||||
_, resp, err := c.getResponse("DELETE", fmt.Sprintf("/user/keys/%d", keyID), nil, nil)
|
||||
return resp, err
|
||||
}
|
||||
|
8
vendor/code.gitea.io/sdk/gitea/user_search.go
generated
vendored
8
vendor/code.gitea.io/sdk/gitea/user_search.go
generated
vendored
@ -35,10 +35,10 @@ func (opt *SearchUsersOption) QueryEncode() string {
|
||||
}
|
||||
|
||||
// SearchUsers finds users by query
|
||||
func (c *Client) SearchUsers(opt SearchUsersOption) ([]*User, error) {
|
||||
func (c *Client) SearchUsers(opt SearchUsersOption) ([]*User, *Response, error) {
|
||||
link, _ := url.Parse("/users/search")
|
||||
link.RawQuery = opt.QueryEncode()
|
||||
resp := new(searchUsersResponse)
|
||||
err := c.getParsedResponse("GET", link.String(), nil, nil, &resp)
|
||||
return resp.Users, err
|
||||
userResp := new(searchUsersResponse)
|
||||
resp, err := c.getParsedResponse("GET", link.String(), nil, nil, &userResp)
|
||||
return userResp.Users, resp, err
|
||||
}
|
||||
|
7
vendor/code.gitea.io/sdk/gitea/version.go
generated
vendored
7
vendor/code.gitea.io/sdk/gitea/version.go
generated
vendored
@ -11,11 +11,12 @@ import (
|
||||
)
|
||||
|
||||
// ServerVersion returns the version of the server
|
||||
func (c *Client) ServerVersion() (string, error) {
|
||||
func (c *Client) ServerVersion() (string, *Response, error) {
|
||||
var v = struct {
|
||||
Version string `json:"version"`
|
||||
}{}
|
||||
return v.Version, c.getParsedResponse("GET", "/version", nil, nil, &v)
|
||||
resp, err := c.getParsedResponse("GET", "/version", nil, nil, &v)
|
||||
return v.Version, resp, err
|
||||
}
|
||||
|
||||
// CheckServerVersionConstraint validates that the login's server satisfies a
|
||||
@ -46,7 +47,7 @@ func (c *Client) loadClientServerVersion() error {
|
||||
c.versionLock.Lock()
|
||||
defer c.versionLock.Unlock()
|
||||
|
||||
raw, err := c.ServerVersion()
|
||||
raw, _, err := c.ServerVersion()
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
7
vendor/gitea.com/jolheiser/gitea-vet/Makefile
generated
vendored
7
vendor/gitea.com/jolheiser/gitea-vet/Makefile
generated
vendored
@ -1,7 +0,0 @@
|
||||
.PHONY: build
|
||||
build:
|
||||
go build
|
||||
|
||||
.PHONY: fmt
|
||||
fmt:
|
||||
go fmt ./...
|
7
vendor/gitea.com/jolheiser/gitea-vet/README.md
generated
vendored
7
vendor/gitea.com/jolheiser/gitea-vet/README.md
generated
vendored
@ -1,7 +0,0 @@
|
||||
# gitea-vet
|
||||
`go vet` tool for Gitea
|
||||
|
||||
| Analyzer | Description |
|
||||
|----------|---------------------------------------------------------------------|
|
||||
| Imports | Checks for import sorting. stdlib->code.gitea.io->other |
|
||||
| License | Checks file headers for some form of `Copyright...YYYY...Gitea/Gogs`|
|
19
vendor/github.com/alecthomas/chroma/.gitignore
generated
vendored
Normal file
19
vendor/github.com/alecthomas/chroma/.gitignore
generated
vendored
Normal file
@ -0,0 +1,19 @@
|
||||
# Binaries for programs and plugins
|
||||
*.exe
|
||||
*.dll
|
||||
*.so
|
||||
*.dylib
|
||||
/cmd/chroma/chroma
|
||||
|
||||
# Test binary, build with `go test -c`
|
||||
*.test
|
||||
|
||||
# Output of the go coverage tool, specifically when used with LiteIDE
|
||||
*.out
|
||||
|
||||
# Project-local glide cache, RE: https://github.com/Masterminds/glide/issues/736
|
||||
.glide/
|
||||
|
||||
_models/
|
||||
|
||||
_examples/
|
55
vendor/github.com/alecthomas/chroma/.golangci.yml
generated
vendored
Normal file
55
vendor/github.com/alecthomas/chroma/.golangci.yml
generated
vendored
Normal file
@ -0,0 +1,55 @@
|
||||
run:
|
||||
tests: true
|
||||
skip-dirs:
|
||||
- _examples
|
||||
|
||||
output:
|
||||
print-issued-lines: false
|
||||
|
||||
linters:
|
||||
enable-all: true
|
||||
disable:
|
||||
- maligned
|
||||
- megacheck
|
||||
- lll
|
||||
- gocyclo
|
||||
- dupl
|
||||
- gochecknoglobals
|
||||
- funlen
|
||||
- godox
|
||||
- wsl
|
||||
- gomnd
|
||||
- gocognit
|
||||
|
||||
linters-settings:
|
||||
govet:
|
||||
check-shadowing: true
|
||||
gocyclo:
|
||||
min-complexity: 10
|
||||
dupl:
|
||||
threshold: 100
|
||||
goconst:
|
||||
min-len: 8
|
||||
min-occurrences: 3
|
||||
|
||||
issues:
|
||||
max-per-linter: 0
|
||||
max-same: 0
|
||||
exclude-use-default: false
|
||||
exclude:
|
||||
# Captured by errcheck.
|
||||
- '^(G104|G204):'
|
||||
# Very commonly not checked.
|
||||
- 'Error return value of .(.*\.Help|.*\.MarkFlagRequired|(os\.)?std(out|err)\..*|.*Close|.*Flush|os\.Remove(All)?|.*printf?|os\.(Un)?Setenv). is not checked'
|
||||
- 'exported method (.*\.MarshalJSON|.*\.UnmarshalJSON|.*\.EntityURN|.*\.GoString|.*\.Pos) should have comment or be unexported'
|
||||
- 'composite literal uses unkeyed fields'
|
||||
- 'declaration of "err" shadows declaration'
|
||||
- 'should not use dot imports'
|
||||
- 'Potential file inclusion via variable'
|
||||
- 'should have comment or be unexported'
|
||||
- 'comment on exported var .* should be of the form'
|
||||
- 'at least one file in a package should have a package comment'
|
||||
- 'string literal contains the Unicode'
|
||||
- 'methods on the same type should have the same receiver name'
|
||||
- '_TokenType_name should be _TokenTypeName'
|
||||
- '`_TokenType_map` should be `_TokenTypeMap`'
|
33
vendor/github.com/alecthomas/chroma/.goreleaser.yml
generated
vendored
Normal file
33
vendor/github.com/alecthomas/chroma/.goreleaser.yml
generated
vendored
Normal file
@ -0,0 +1,33 @@
|
||||
project_name: chroma
|
||||
release:
|
||||
github:
|
||||
owner: alecthomas
|
||||
name: chroma
|
||||
brews:
|
||||
-
|
||||
install: bin.install "chroma"
|
||||
builds:
|
||||
- goos:
|
||||
- linux
|
||||
- darwin
|
||||
- windows
|
||||
goarch:
|
||||
- amd64
|
||||
- "386"
|
||||
goarm:
|
||||
- "6"
|
||||
main: ./cmd/chroma/main.go
|
||||
ldflags: -s -w -X main.version={{.Version}} -X main.commit={{.Commit}} -X main.date={{.Date}}
|
||||
binary: chroma
|
||||
archives:
|
||||
-
|
||||
format: tar.gz
|
||||
name_template: '{{ .Binary }}-{{ .Version }}-{{ .Os }}-{{ .Arch }}{{ if .Arm }}v{{
|
||||
.Arm }}{{ end }}'
|
||||
files:
|
||||
- COPYING
|
||||
- README*
|
||||
snapshot:
|
||||
name_template: SNAPSHOT-{{ .Commit }}
|
||||
checksum:
|
||||
name_template: '{{ .ProjectName }}-{{ .Version }}-checksums.txt'
|
12
vendor/github.com/alecthomas/chroma/.travis.yml
generated
vendored
Normal file
12
vendor/github.com/alecthomas/chroma/.travis.yml
generated
vendored
Normal file
@ -0,0 +1,12 @@
|
||||
sudo: false
|
||||
language: go
|
||||
go:
|
||||
- "1.13.x"
|
||||
script:
|
||||
- go test -v ./...
|
||||
- curl -sfL https://install.goreleaser.com/github.com/golangci/golangci-lint.sh | bash -s v1.22.2
|
||||
- ./bin/golangci-lint run
|
||||
- git clean -fdx .
|
||||
after_success:
|
||||
curl -sL https://git.io/goreleaser | bash && goreleaser
|
||||
|
19
vendor/github.com/alecthomas/chroma/COPYING
generated
vendored
Normal file
19
vendor/github.com/alecthomas/chroma/COPYING
generated
vendored
Normal file
@ -0,0 +1,19 @@
|
||||
Copyright (C) 2017 Alec Thomas
|
||||
|
||||
Permission is hereby granted, free of charge, to any person obtaining a copy of
|
||||
this software and associated documentation files (the "Software"), to deal in
|
||||
the Software without restriction, including without limitation the rights to
|
||||
use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies
|
||||
of the Software, and to permit persons to whom the Software is furnished to do
|
||||
so, subject to the following conditions:
|
||||
|
||||
The above copyright notice and this permission notice shall be included in all
|
||||
copies or substantial portions of the Software.
|
||||
|
||||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
||||
SOFTWARE.
|
19
vendor/github.com/alecthomas/chroma/Makefile
generated
vendored
Normal file
19
vendor/github.com/alecthomas/chroma/Makefile
generated
vendored
Normal file
@ -0,0 +1,19 @@
|
||||
.PHONY: chromad upload all
|
||||
|
||||
all: README.md tokentype_string.go
|
||||
|
||||
README.md: lexers/*/*.go
|
||||
./table.py
|
||||
|
||||
tokentype_string.go: types.go
|
||||
go generate
|
||||
|
||||
chromad:
|
||||
(cd ./cmd/chromad && go get github.com/GeertJohan/go.rice/rice@master && go install github.com/GeertJohan/go.rice/rice)
|
||||
rm -f chromad
|
||||
(export CGOENABLED=0 GOOS=linux ; cd ./cmd/chromad && go build -o ../../chromad .)
|
||||
rice append -i ./cmd/chromad --exec=./chromad
|
||||
|
||||
upload: chromad
|
||||
scp chromad root@swapoff.org: && \
|
||||
ssh root@swapoff.org 'install -m755 ./chromad /srv/http/swapoff.org/bin && service chromad restart'
|
267
vendor/github.com/alecthomas/chroma/README.md
generated
vendored
Normal file
267
vendor/github.com/alecthomas/chroma/README.md
generated
vendored
Normal file
@ -0,0 +1,267 @@
|
||||
# Chroma — A general purpose syntax highlighter in pure Go [](https://godoc.org/github.com/alecthomas/chroma) [](https://travis-ci.org/alecthomas/chroma) [](https://gitter.im/alecthomas/Lobby)
|
||||
|
||||
> **NOTE:** As Chroma has just been released, its API is still in flux. That said, the high-level interface should not change significantly.
|
||||
|
||||
Chroma takes source code and other structured text and converts it into syntax
|
||||
highlighted HTML, ANSI-coloured text, etc.
|
||||
|
||||
Chroma is based heavily on [Pygments](http://pygments.org/), and includes
|
||||
translators for Pygments lexers and styles.
|
||||
|
||||
<a id="markdown-table-of-contents" name="table-of-contents"></a>
|
||||
## Table of Contents
|
||||
|
||||
<!-- TOC -->
|
||||
|
||||
1. [Table of Contents](#table-of-contents)
|
||||
2. [Supported languages](#supported-languages)
|
||||
3. [Try it](#try-it)
|
||||
4. [Using the library](#using-the-library)
|
||||
1. [Quick start](#quick-start)
|
||||
2. [Identifying the language](#identifying-the-language)
|
||||
3. [Formatting the output](#formatting-the-output)
|
||||
4. [The HTML formatter](#the-html-formatter)
|
||||
5. [More detail](#more-detail)
|
||||
1. [Lexers](#lexers)
|
||||
2. [Formatters](#formatters)
|
||||
3. [Styles](#styles)
|
||||
6. [Command-line interface](#command-line-interface)
|
||||
7. [What's missing compared to Pygments?](#whats-missing-compared-to-pygments)
|
||||
|
||||
<!-- /TOC -->
|
||||
|
||||
<a id="markdown-supported-languages" name="supported-languages"></a>
|
||||
## Supported languages
|
||||
|
||||
Prefix | Language
|
||||
:----: | --------
|
||||
A | ABAP, ABNF, ActionScript, ActionScript 3, Ada, Angular2, ANTLR, ApacheConf, APL, AppleScript, Arduino, Awk
|
||||
B | Ballerina, Base Makefile, Bash, Batchfile, BlitzBasic, BNF, Brainfuck
|
||||
C | C, C#, C++, Cap'n Proto, Cassandra CQL, Ceylon, CFEngine3, cfstatement, ChaiScript, Cheetah, Clojure, CMake, COBOL, CoffeeScript, Common Lisp, Coq, Crystal, CSS, Cython
|
||||
D | D, Dart, Diff, Django/Jinja, Docker, DTD
|
||||
E | EBNF, Elixir, Elm, EmacsLisp, Erlang
|
||||
F | Factor, Fish, Forth, Fortran, FSharp
|
||||
G | GAS, GDScript, Genshi, Genshi HTML, Genshi Text, GLSL, Gnuplot, Go, Go HTML Template, Go Text Template, GraphQL, Groovy
|
||||
H | Handlebars, Haskell, Haxe, HCL, Hexdump, HTML, HTTP, Hy
|
||||
I | Idris, INI, Io
|
||||
J | J, Java, JavaScript, JSON, Julia, Jungle
|
||||
K | Kotlin
|
||||
L | Lighttpd configuration file, LLVM, Lua
|
||||
M | Mako, markdown, Mason, Mathematica, Matlab, MiniZinc, MLIR, Modula-2, MonkeyC, MorrowindScript, Myghty, MySQL
|
||||
N | NASM, Newspeak, Nginx configuration file, Nim, Nix
|
||||
O | Objective-C, OCaml, Octave, OpenSCAD, Org Mode
|
||||
P | PacmanConf, Perl, PHP, Pig, PkgConfig, PL/pgSQL, plaintext, PostgreSQL SQL dialect, PostScript, POVRay, PowerShell, Prolog, Protocol Buffer, Puppet, Python, Python 3
|
||||
Q | QBasic
|
||||
R | R, Racket, Ragel, react, reg, reStructuredText, Rexx, Ruby, Rust
|
||||
S | Sass, Scala, Scheme, Scilab, SCSS, Smalltalk, Smarty, SML, Snobol, Solidity, SPARQL, SQL, SquidConf, Swift, SYSTEMD, systemverilog
|
||||
T | TableGen, TASM, Tcl, Tcsh, Termcap, Terminfo, Terraform, TeX, Thrift, TOML, TradingView, Transact-SQL, Turing, Turtle, Twig, TypeScript, TypoScript, TypoScriptCssData, TypoScriptHtmlData
|
||||
V | VB.net, verilog, VHDL, VimL, vue
|
||||
W | WDTE
|
||||
X | XML, Xorg
|
||||
Y | YAML
|
||||
|
||||
|
||||
_I will attempt to keep this section up to date, but an authoritative list can be
|
||||
displayed with `chroma --list`._
|
||||
|
||||
<a id="markdown-try-it" name="try-it"></a>
|
||||
## Try it
|
||||
|
||||
Try out various languages and styles on the [Chroma Playground](https://swapoff.org/chroma/playground/).
|
||||
|
||||
<a id="markdown-using-the-library" name="using-the-library"></a>
|
||||
## Using the library
|
||||
|
||||
Chroma, like Pygments, has the concepts of
|
||||
[lexers](https://github.com/alecthomas/chroma/tree/master/lexers),
|
||||
[formatters](https://github.com/alecthomas/chroma/tree/master/formatters) and
|
||||
[styles](https://github.com/alecthomas/chroma/tree/master/styles).
|
||||
|
||||
Lexers convert source text into a stream of tokens, styles specify how token
|
||||
types are mapped to colours, and formatters convert tokens and styles into
|
||||
formatted output.
|
||||
|
||||
A package exists for each of these, containing a global `Registry` variable
|
||||
with all of the registered implementations. There are also helper functions
|
||||
for using the registry in each package, such as looking up lexers by name or
|
||||
matching filenames, etc.
|
||||
|
||||
In all cases, if a lexer, formatter or style can not be determined, `nil` will
|
||||
be returned. In this situation you may want to default to the `Fallback`
|
||||
value in each respective package, which provides sane defaults.
|
||||
|
||||
<a id="markdown-quick-start" name="quick-start"></a>
|
||||
### Quick start
|
||||
|
||||
A convenience function exists that can be used to simply format some source
|
||||
text, without any effort:
|
||||
|
||||
```go
|
||||
err := quick.Highlight(os.Stdout, someSourceCode, "go", "html", "monokai")
|
||||
```
|
||||
|
||||
<a id="markdown-identifying-the-language" name="identifying-the-language"></a>
|
||||
### Identifying the language
|
||||
|
||||
To highlight code, you'll first have to identify what language the code is
|
||||
written in. There are three primary ways to do that:
|
||||
|
||||
1. Detect the language from its filename.
|
||||
|
||||
```go
|
||||
lexer := lexers.Match("foo.go")
|
||||
```
|
||||
|
||||
3. Explicitly specify the language by its Chroma syntax ID (a full list is available from `lexers.Names()`).
|
||||
|
||||
```go
|
||||
lexer := lexers.Get("go")
|
||||
```
|
||||
|
||||
3. Detect the language from its content.
|
||||
|
||||
```go
|
||||
lexer := lexers.Analyse("package main\n\nfunc main()\n{\n}\n")
|
||||
```
|
||||
|
||||
In all cases, `nil` will be returned if the language can not be identified.
|
||||
|
||||
```go
|
||||
if lexer == nil {
|
||||
lexer = lexers.Fallback
|
||||
}
|
||||
```
|
||||
|
||||
At this point, it should be noted that some lexers can be extremely chatty. To
|
||||
mitigate this, you can use the coalescing lexer to coalesce runs of identical
|
||||
token types into a single token:
|
||||
|
||||
```go
|
||||
lexer = chroma.Coalesce(lexer)
|
||||
```
|
||||
|
||||
<a id="markdown-formatting-the-output" name="formatting-the-output"></a>
|
||||
### Formatting the output
|
||||
|
||||
Once a language is identified you will need to pick a formatter and a style (theme).
|
||||
|
||||
```go
|
||||
style := styles.Get("swapoff")
|
||||
if style == nil {
|
||||
style = styles.Fallback
|
||||
}
|
||||
formatter := formatters.Get("html")
|
||||
if formatter == nil {
|
||||
formatter = formatters.Fallback
|
||||
}
|
||||
```
|
||||
|
||||
Then obtain an iterator over the tokens:
|
||||
|
||||
```go
|
||||
contents, err := ioutil.ReadAll(r)
|
||||
iterator, err := lexer.Tokenise(nil, string(contents))
|
||||
```
|
||||
|
||||
And finally, format the tokens from the iterator:
|
||||
|
||||
```go
|
||||
err := formatter.Format(w, style, iterator)
|
||||
```
|
||||
|
||||
<a id="markdown-the-html-formatter" name="the-html-formatter"></a>
|
||||
### The HTML formatter
|
||||
|
||||
By default the `html` registered formatter generates standalone HTML with
|
||||
embedded CSS. More flexibility is available through the `formatters/html` package.
|
||||
|
||||
Firstly, the output generated by the formatter can be customised with the
|
||||
following constructor options:
|
||||
|
||||
- `Standalone()` - generate standalone HTML with embedded CSS.
|
||||
- `WithClasses()` - use classes rather than inlined style attributes.
|
||||
- `ClassPrefix(prefix)` - prefix each generated CSS class.
|
||||
- `TabWidth(width)` - Set the rendered tab width, in characters.
|
||||
- `WithLineNumbers()` - Render line numbers (style with `LineNumbers`).
|
||||
- `LinkableLineNumbers()` - Make the line numbers linkable.
|
||||
- `HighlightLines(ranges)` - Highlight lines in these ranges (style with `LineHighlight`).
|
||||
- `LineNumbersInTable()` - Use a table for formatting line numbers and code, rather than spans.
|
||||
|
||||
If `WithClasses()` is used, the corresponding CSS can be obtained from the formatter with:
|
||||
|
||||
```go
|
||||
formatter := html.New(html.WithClasses())
|
||||
err := formatter.WriteCSS(w, style)
|
||||
```
|
||||
|
||||
<a id="markdown-more-detail" name="more-detail"></a>
|
||||
## More detail
|
||||
|
||||
<a id="markdown-lexers" name="lexers"></a>
|
||||
### Lexers
|
||||
|
||||
See the [Pygments documentation](http://pygments.org/docs/lexerdevelopment/)
|
||||
for details on implementing lexers. Most concepts apply directly to Chroma,
|
||||
but see existing lexer implementations for real examples.
|
||||
|
||||
In many cases lexers can be automatically converted directly from Pygments by
|
||||
using the included Python 3 script `pygments2chroma.py`. I use something like
|
||||
the following:
|
||||
|
||||
```sh
|
||||
python3 ~/Projects/chroma/_tools/pygments2chroma.py \
|
||||
pygments.lexers.jvm.KotlinLexer \
|
||||
> ~/Projects/chroma/lexers/kotlin.go \
|
||||
&& gofmt -s -w ~/Projects/chroma/lexers/*.go
|
||||
```
|
||||
|
||||
See notes in [pygments-lexers.go](https://github.com/alecthomas/chroma/blob/master/pygments-lexers.txt)
|
||||
for a list of lexers, and notes on some of the issues importing them.
|
||||
|
||||
<a id="markdown-formatters" name="formatters"></a>
|
||||
### Formatters
|
||||
|
||||
Chroma supports HTML output, as well as terminal output in 8 colour, 256 colour, and true-colour.
|
||||
|
||||
A `noop` formatter is included that outputs the token text only, and a `tokens`
|
||||
formatter outputs raw tokens. The latter is useful for debugging lexers.
|
||||
|
||||
<a id="markdown-styles" name="styles"></a>
|
||||
### Styles
|
||||
|
||||
Chroma styles use the [same syntax](http://pygments.org/docs/styles/) as Pygments.
|
||||
|
||||
All Pygments styles have been converted to Chroma using the `_tools/style.py` script.
|
||||
|
||||
When you work with one of [Chroma's styles](https://github.com/alecthomas/chroma/tree/master/styles), know that the `chroma.Background` token type provides the default style for tokens. It does so by defining a foreground color and background color.
|
||||
|
||||
For example, this gives each token name not defined in the style a default color of `#f8f8f8` and uses `#000000` for the highlighted code block's background:
|
||||
|
||||
~~~go
|
||||
chroma.Background: "#f8f8f2 bg:#000000",
|
||||
~~~
|
||||
|
||||
Also, token types in a style file are hierarchical. For instance, when `CommentSpecial` is not defined, Chroma uses the token style from `Comment`. So when several comment tokens use the same color, you'll only need to define `Comment` and override the one that has a different color.
|
||||
|
||||
For a quick overview of the available styles and how they look, check out the [Chroma Style Gallery](https://xyproto.github.io/splash/docs/).
|
||||
|
||||
<a id="markdown-command-line-interface" name="command-line-interface"></a>
|
||||
## Command-line interface
|
||||
|
||||
A command-line interface to Chroma is included. It can be installed with:
|
||||
|
||||
```sh
|
||||
go get -u github.com/alecthomas/chroma/cmd/chroma
|
||||
```
|
||||
|
||||
<a id="markdown-whats-missing-compared-to-pygments" name="whats-missing-compared-to-pygments"></a>
|
||||
## What's missing compared to Pygments?
|
||||
|
||||
- Quite a few lexers, for various reasons (pull-requests welcome):
|
||||
- Pygments lexers for complex languages often include custom code to
|
||||
handle certain aspects, such as Perl6's ability to nest code inside
|
||||
regular expressions. These require time and effort to convert.
|
||||
- I mostly only converted languages I had heard of, to reduce the porting cost.
|
||||
- Some more esoteric features of Pygments are omitted for simplicity.
|
||||
- Though the Chroma API supports content detection, very few languages support them.
|
||||
I have plans to implement a statistical analyser at some point, but not enough time.
|
35
vendor/github.com/alecthomas/chroma/coalesce.go
generated
vendored
Normal file
35
vendor/github.com/alecthomas/chroma/coalesce.go
generated
vendored
Normal file
@ -0,0 +1,35 @@
|
||||
package chroma
|
||||
|
||||
// Coalesce is a Lexer interceptor that collapses runs of common types into a single token.
|
||||
func Coalesce(lexer Lexer) Lexer { return &coalescer{lexer} }
|
||||
|
||||
type coalescer struct{ Lexer }
|
||||
|
||||
func (d *coalescer) Tokenise(options *TokeniseOptions, text string) (Iterator, error) {
|
||||
var prev Token
|
||||
it, err := d.Lexer.Tokenise(options, text)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
return func() Token {
|
||||
for token := it(); token != (EOF); token = it() {
|
||||
if len(token.Value) == 0 {
|
||||
continue
|
||||
}
|
||||
if prev == EOF {
|
||||
prev = token
|
||||
} else {
|
||||
if prev.Type == token.Type && len(prev.Value) < 8192 {
|
||||
prev.Value += token.Value
|
||||
} else {
|
||||
out := prev
|
||||
prev = token
|
||||
return out
|
||||
}
|
||||
}
|
||||
}
|
||||
out := prev
|
||||
prev = EOF
|
||||
return out
|
||||
}, nil
|
||||
}
|
164
vendor/github.com/alecthomas/chroma/colour.go
generated
vendored
Normal file
164
vendor/github.com/alecthomas/chroma/colour.go
generated
vendored
Normal file
@ -0,0 +1,164 @@
|
||||
package chroma
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"math"
|
||||
"strconv"
|
||||
"strings"
|
||||
)
|
||||
|
||||
// ANSI2RGB maps ANSI colour names, as supported by Chroma, to hex RGB values.
|
||||
var ANSI2RGB = map[string]string{
|
||||
"#ansiblack": "000000",
|
||||
"#ansidarkred": "7f0000",
|
||||
"#ansidarkgreen": "007f00",
|
||||
"#ansibrown": "7f7fe0",
|
||||
"#ansidarkblue": "00007f",
|
||||
"#ansipurple": "7f007f",
|
||||
"#ansiteal": "007f7f",
|
||||
"#ansilightgray": "e5e5e5",
|
||||
// Normal
|
||||
"#ansidarkgray": "555555",
|
||||
"#ansired": "ff0000",
|
||||
"#ansigreen": "00ff00",
|
||||
"#ansiyellow": "ffff00",
|
||||
"#ansiblue": "0000ff",
|
||||
"#ansifuchsia": "ff00ff",
|
||||
"#ansiturquoise": "00ffff",
|
||||
"#ansiwhite": "ffffff",
|
||||
|
||||
// Aliases without the "ansi" prefix, because...why?
|
||||
"#black": "000000",
|
||||
"#darkred": "7f0000",
|
||||
"#darkgreen": "007f00",
|
||||
"#brown": "7f7fe0",
|
||||
"#darkblue": "00007f",
|
||||
"#purple": "7f007f",
|
||||
"#teal": "007f7f",
|
||||
"#lightgray": "e5e5e5",
|
||||
// Normal
|
||||
"#darkgray": "555555",
|
||||
"#red": "ff0000",
|
||||
"#green": "00ff00",
|
||||
"#yellow": "ffff00",
|
||||
"#blue": "0000ff",
|
||||
"#fuchsia": "ff00ff",
|
||||
"#turquoise": "00ffff",
|
||||
"#white": "ffffff",
|
||||
}
|
||||
|
||||
// Colour represents an RGB colour.
|
||||
type Colour int32
|
||||
|
||||
// NewColour creates a Colour directly from RGB values.
|
||||
func NewColour(r, g, b uint8) Colour {
|
||||
return ParseColour(fmt.Sprintf("%02x%02x%02x", r, g, b))
|
||||
}
|
||||
|
||||
// Distance between this colour and another.
|
||||
//
|
||||
// This uses the approach described here (https://www.compuphase.com/cmetric.htm).
|
||||
// This is not as accurate as LAB, et. al. but is *vastly* simpler and sufficient for our needs.
|
||||
func (c Colour) Distance(e2 Colour) float64 {
|
||||
ar, ag, ab := int64(c.Red()), int64(c.Green()), int64(c.Blue())
|
||||
br, bg, bb := int64(e2.Red()), int64(e2.Green()), int64(e2.Blue())
|
||||
rmean := (ar + br) / 2
|
||||
r := ar - br
|
||||
g := ag - bg
|
||||
b := ab - bb
|
||||
return math.Sqrt(float64((((512 + rmean) * r * r) >> 8) + 4*g*g + (((767 - rmean) * b * b) >> 8)))
|
||||
}
|
||||
|
||||
// Brighten returns a copy of this colour with its brightness adjusted.
|
||||
//
|
||||
// If factor is negative, the colour is darkened.
|
||||
//
|
||||
// Uses approach described here (http://www.pvladov.com/2012/09/make-color-lighter-or-darker.html).
|
||||
func (c Colour) Brighten(factor float64) Colour {
|
||||
r := float64(c.Red())
|
||||
g := float64(c.Green())
|
||||
b := float64(c.Blue())
|
||||
|
||||
if factor < 0 {
|
||||
factor++
|
||||
r *= factor
|
||||
g *= factor
|
||||
b *= factor
|
||||
} else {
|
||||
r = (255-r)*factor + r
|
||||
g = (255-g)*factor + g
|
||||
b = (255-b)*factor + b
|
||||
}
|
||||
return NewColour(uint8(r), uint8(g), uint8(b))
|
||||
}
|
||||
|
||||
// BrightenOrDarken brightens a colour if it is < 0.5 brighteness or darkens if > 0.5 brightness.
|
||||
func (c Colour) BrightenOrDarken(factor float64) Colour {
|
||||
if c.Brightness() < 0.5 {
|
||||
return c.Brighten(factor)
|
||||
}
|
||||
return c.Brighten(-factor)
|
||||
}
|
||||
|
||||
// Brightness of the colour (roughly) in the range 0.0 to 1.0
|
||||
func (c Colour) Brightness() float64 {
|
||||
return (float64(c.Red()) + float64(c.Green()) + float64(c.Blue())) / 255.0 / 3.0
|
||||
}
|
||||
|
||||
// ParseColour in the forms #rgb, #rrggbb, #ansi<colour>, or #<colour>.
|
||||
// Will return an "unset" colour if invalid.
|
||||
func ParseColour(colour string) Colour {
|
||||
colour = normaliseColour(colour)
|
||||
n, err := strconv.ParseUint(colour, 16, 32)
|
||||
if err != nil {
|
||||
return 0
|
||||
}
|
||||
return Colour(n + 1)
|
||||
}
|
||||
|
||||
// MustParseColour is like ParseColour except it panics if the colour is invalid.
|
||||
//
|
||||
// Will panic if colour is in an invalid format.
|
||||
func MustParseColour(colour string) Colour {
|
||||
parsed := ParseColour(colour)
|
||||
if !parsed.IsSet() {
|
||||
panic(fmt.Errorf("invalid colour %q", colour))
|
||||
}
|
||||
return parsed
|
||||
}
|
||||
|
||||
// IsSet returns true if the colour is set.
|
||||
func (c Colour) IsSet() bool { return c != 0 }
|
||||
|
||||
func (c Colour) String() string { return fmt.Sprintf("#%06x", int(c-1)) }
|
||||
func (c Colour) GoString() string { return fmt.Sprintf("Colour(0x%06x)", int(c-1)) }
|
||||
|
||||
// Red component of colour.
|
||||
func (c Colour) Red() uint8 { return uint8(((c - 1) >> 16) & 0xff) }
|
||||
|
||||
// Green component of colour.
|
||||
func (c Colour) Green() uint8 { return uint8(((c - 1) >> 8) & 0xff) }
|
||||
|
||||
// Blue component of colour.
|
||||
func (c Colour) Blue() uint8 { return uint8((c - 1) & 0xff) }
|
||||
|
||||
// Colours is an orderable set of colours.
|
||||
type Colours []Colour
|
||||
|
||||
func (c Colours) Len() int { return len(c) }
|
||||
func (c Colours) Swap(i, j int) { c[i], c[j] = c[j], c[i] }
|
||||
func (c Colours) Less(i, j int) bool { return c[i] < c[j] }
|
||||
|
||||
// Convert colours to #rrggbb.
|
||||
func normaliseColour(colour string) string {
|
||||
if ansi, ok := ANSI2RGB[colour]; ok {
|
||||
return ansi
|
||||
}
|
||||
if strings.HasPrefix(colour, "#") {
|
||||
colour = colour[1:]
|
||||
if len(colour) == 3 {
|
||||
return colour[0:1] + colour[0:1] + colour[1:2] + colour[1:2] + colour[2:3] + colour[2:3]
|
||||
}
|
||||
}
|
||||
return colour
|
||||
}
|
137
vendor/github.com/alecthomas/chroma/delegate.go
generated
vendored
Normal file
137
vendor/github.com/alecthomas/chroma/delegate.go
generated
vendored
Normal file
@ -0,0 +1,137 @@
|
||||
package chroma
|
||||
|
||||
import (
|
||||
"bytes"
|
||||
)
|
||||
|
||||
type delegatingLexer struct {
|
||||
root Lexer
|
||||
language Lexer
|
||||
}
|
||||
|
||||
// DelegatingLexer combines two lexers to handle the common case of a language embedded inside another, such as PHP
|
||||
// inside HTML or PHP inside plain text.
|
||||
//
|
||||
// It takes two lexer as arguments: a root lexer and a language lexer. First everything is scanned using the language
|
||||
// lexer, which must return "Other" for unrecognised tokens. Then all "Other" tokens are lexed using the root lexer.
|
||||
// Finally, these two sets of tokens are merged.
|
||||
//
|
||||
// The lexers from the template lexer package use this base lexer.
|
||||
func DelegatingLexer(root Lexer, language Lexer) Lexer {
|
||||
return &delegatingLexer{
|
||||
root: root,
|
||||
language: language,
|
||||
}
|
||||
}
|
||||
|
||||
func (d *delegatingLexer) Config() *Config {
|
||||
return d.language.Config()
|
||||
}
|
||||
|
||||
// An insertion is the character range where language tokens should be inserted.
|
||||
type insertion struct {
|
||||
start, end int
|
||||
tokens []Token
|
||||
}
|
||||
|
||||
func (d *delegatingLexer) Tokenise(options *TokeniseOptions, text string) (Iterator, error) { // nolint: gocognit
|
||||
tokens, err := Tokenise(Coalesce(d.language), options, text)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
// Compute insertions and gather "Other" tokens.
|
||||
others := &bytes.Buffer{}
|
||||
insertions := []*insertion{}
|
||||
var insert *insertion
|
||||
offset := 0
|
||||
var last Token
|
||||
for _, t := range tokens {
|
||||
if t.Type == Other {
|
||||
if last != EOF && insert != nil && last.Type != Other {
|
||||
insert.end = offset
|
||||
}
|
||||
others.WriteString(t.Value)
|
||||
} else {
|
||||
if last == EOF || last.Type == Other {
|
||||
insert = &insertion{start: offset}
|
||||
insertions = append(insertions, insert)
|
||||
}
|
||||
insert.tokens = append(insert.tokens, t)
|
||||
}
|
||||
last = t
|
||||
offset += len(t.Value)
|
||||
}
|
||||
|
||||
if len(insertions) == 0 {
|
||||
return d.root.Tokenise(options, text)
|
||||
}
|
||||
|
||||
// Lex the other tokens.
|
||||
rootTokens, err := Tokenise(Coalesce(d.root), options, others.String())
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
// Interleave the two sets of tokens.
|
||||
var out []Token
|
||||
offset = 0 // Offset into text.
|
||||
tokenIndex := 0
|
||||
nextToken := func() Token {
|
||||
if tokenIndex >= len(rootTokens) {
|
||||
return EOF
|
||||
}
|
||||
t := rootTokens[tokenIndex]
|
||||
tokenIndex++
|
||||
return t
|
||||
}
|
||||
insertionIndex := 0
|
||||
nextInsertion := func() *insertion {
|
||||
if insertionIndex >= len(insertions) {
|
||||
return nil
|
||||
}
|
||||
i := insertions[insertionIndex]
|
||||
insertionIndex++
|
||||
return i
|
||||
}
|
||||
t := nextToken()
|
||||
i := nextInsertion()
|
||||
for t != EOF || i != nil {
|
||||
// fmt.Printf("%d->%d:%q %d->%d:%q\n", offset, offset+len(t.Value), t.Value, i.start, i.end, Stringify(i.tokens...))
|
||||
if t == EOF || (i != nil && i.start < offset+len(t.Value)) {
|
||||
var l Token
|
||||
l, t = splitToken(t, i.start-offset)
|
||||
if l != EOF {
|
||||
out = append(out, l)
|
||||
offset += len(l.Value)
|
||||
}
|
||||
out = append(out, i.tokens...)
|
||||
offset += i.end - i.start
|
||||
if t == EOF {
|
||||
t = nextToken()
|
||||
}
|
||||
i = nextInsertion()
|
||||
} else {
|
||||
out = append(out, t)
|
||||
offset += len(t.Value)
|
||||
t = nextToken()
|
||||
}
|
||||
}
|
||||
return Literator(out...), nil
|
||||
}
|
||||
|
||||
func splitToken(t Token, offset int) (l Token, r Token) {
|
||||
if t == EOF {
|
||||
return EOF, EOF
|
||||
}
|
||||
if offset == 0 {
|
||||
return EOF, t
|
||||
}
|
||||
if offset == len(t.Value) {
|
||||
return t, EOF
|
||||
}
|
||||
l = t.Clone()
|
||||
r = t.Clone()
|
||||
l.Value = l.Value[:offset]
|
||||
r.Value = r.Value[offset:]
|
||||
return
|
||||
}
|
Some files were not shown because too many files have changed in this diff Show More
Reference in New Issue
Block a user