mirror of
https://gitea.com/gitea/tea.git
synced 2024-09-29 04:45:59 -04:00
4cda7e0299
Merge branch 'master' into issue-97/pulls-clean vendor terminal dependency pull/push: provide authentication method automatically select an AuthMethod according to the remote url type. If required, credentials are prompted for login: store username & optional keyfile refactor refactor GetRemote Merge branch 'master' into issue-97/pulls-clean adress code review add --ignore-sha flag When set, the local branch is not matched against the remote sha, but the remote branch name. This makes the command more flexible with diverging branches. add missing error check fix branch-not-found case Merge branch 'master' into issue-97/pulls-clean use directory namespaces for branches & remotes fix TeaCreateBranch() improve method of TeaFindBranch() now only checking .git/refs instead of looking up .git/config which may not list the branch add `tea pulls clean` fixes #97 add copyright to new files make linter happy refactor: use new git functions for old code add `tea pulls checkout` Co-authored-by: Norwin Roosen <git@nroo.de> Co-authored-by: Norwin <git@nroo.de> Reviewed-on: https://gitea.com/gitea/tea/pulls/105 Reviewed-by: 6543 <6543@noreply.gitea.io> Reviewed-by: Lunny Xiao <xiaolunwen@gmail.com>
173 lines
3.6 KiB
Go
173 lines
3.6 KiB
Go
// Copyright 2018 The Gitea Authors. All rights reserved.
|
|
// Use of this source code is governed by a MIT-style
|
|
// license that can be found in the LICENSE file.
|
|
|
|
package cmd
|
|
|
|
import (
|
|
"fmt"
|
|
"log"
|
|
"strconv"
|
|
|
|
"code.gitea.io/sdk/gitea"
|
|
|
|
"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`,
|
|
Action: runIssues,
|
|
Subcommands: []*cli.Command{
|
|
&CmdIssuesList,
|
|
&CmdIssuesCreate,
|
|
},
|
|
Flags: AllDefaultFlags,
|
|
}
|
|
|
|
// CmdIssuesList represents a sub command of issues to list issues
|
|
var CmdIssuesList = cli.Command{
|
|
Name: "ls",
|
|
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...),
|
|
}
|
|
|
|
func runIssues(ctx *cli.Context) error {
|
|
if ctx.Args().Len() == 1 {
|
|
return runIssueDetail(ctx, ctx.Args().First())
|
|
}
|
|
return runIssuesList(ctx)
|
|
}
|
|
|
|
func runIssueDetail(ctx *cli.Context, index string) error {
|
|
login, owner, repo := initCommand()
|
|
|
|
idx, err := argToIndex(index)
|
|
if err != nil {
|
|
return err
|
|
}
|
|
issue, err := login.Client().GetIssue(owner, repo, idx)
|
|
if err != nil {
|
|
return err
|
|
}
|
|
|
|
fmt.Printf("#%d %s\n%s created %s\n\n%s", issue.Index,
|
|
issue.Title,
|
|
issue.Poster.UserName,
|
|
issue.Created.Format("2006-01-02 15:04:05"),
|
|
issue.Body,
|
|
)
|
|
return nil
|
|
}
|
|
|
|
func runIssuesList(ctx *cli.Context) error {
|
|
login, owner, repo := initCommand()
|
|
|
|
state := gitea.StateOpen
|
|
switch ctx.String("state") {
|
|
case "all":
|
|
state = gitea.StateAll
|
|
case "open":
|
|
state = gitea.StateOpen
|
|
case "closed":
|
|
state = gitea.StateClosed
|
|
}
|
|
|
|
issues, err := login.Client().ListRepoIssues(owner, repo, gitea.ListIssueOption{
|
|
Page: 0,
|
|
State: string(state),
|
|
Type: gitea.IssueTypeIssue,
|
|
})
|
|
|
|
if err != nil {
|
|
log.Fatal(err)
|
|
}
|
|
|
|
headers := []string{
|
|
"Index",
|
|
"State",
|
|
"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
|
|
}
|
|
values = append(
|
|
values,
|
|
[]string{
|
|
strconv.FormatInt(issue.Index, 10),
|
|
string(issue.State),
|
|
name,
|
|
issue.Updated.Format("2006-01-02 15:04:05"),
|
|
issue.Title,
|
|
},
|
|
)
|
|
}
|
|
Output(outputValue, headers, values)
|
|
|
|
return nil
|
|
}
|
|
|
|
// CmdIssuesCreate represents a sub command of issues to create issue
|
|
var CmdIssuesCreate = cli.Command{
|
|
Name: "create",
|
|
Usage: "Create an issue on repository",
|
|
Description: `Create an issue on repository`,
|
|
Action: runIssuesCreate,
|
|
Flags: append([]cli.Flag{
|
|
&cli.StringFlag{
|
|
Name: "title",
|
|
Aliases: []string{"t"},
|
|
Usage: "issue title to create",
|
|
},
|
|
&cli.StringFlag{
|
|
Name: "body",
|
|
Aliases: []string{"b"},
|
|
Usage: "issue body to create",
|
|
},
|
|
}, LoginRepoFlags...),
|
|
}
|
|
|
|
func runIssuesCreate(ctx *cli.Context) error {
|
|
login, owner, repo := initCommand()
|
|
|
|
_, err := login.Client().CreateIssue(owner, repo, gitea.CreateIssueOption{
|
|
Title: ctx.String("title"),
|
|
Body: ctx.String("body"),
|
|
// TODO:
|
|
//Assignee string `json:"assignee"`
|
|
//Assignees []string `json:"assignees"`
|
|
//Deadline *time.Time `json:"due_date"`
|
|
//Milestone int64 `json:"milestone"`
|
|
//Labels []int64 `json:"labels"`
|
|
//Closed bool `json:"closed"`
|
|
})
|
|
|
|
if err != nil {
|
|
log.Fatal(err)
|
|
}
|
|
|
|
return nil
|
|
}
|