Add subcomand 'pulls create' #144

Merged
6543 merged 13 commits from 6543/tea:pulls-create into master 2020-07-16 15:00:54 +00:00
3 changed files with 67 additions and 77 deletions
Showing only changes of commit e0d5487da0 - Show all commits

View File

@ -1,76 +0,0 @@
// 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"
)
// CmdPullRequest creates a pull request
var CmdPullRequest = cli.Command{
Name: "pull-request",
Usage: "Create a pull-request",
Description: "Create a pull-request",
Action: runCreatePullRequest,
Flags: append([]cli.Flag{
&cli.StringFlag{
Name: "head",
Usage: "pull-request head",
},
&cli.StringFlag{
Name: "base, b",
Usage: "pull-request base",
},
&cli.StringFlag{
Name: "title, t",
Usage: "pull-request title",
},
&cli.StringFlag{
Name: "description, d",
Usage: "pull-request description",
},
}, LoginRepoFlags...),
}
func runCreatePullRequest(ctx *cli.Context) error {
login, owner, repo := initCommand()
/*
Head string `json:"head" binding:"Required"`
Base string `json:"base" binding:"Required"`
Title string `json:"title" binding:"Required"`
Body string `json:"body"`
Assignee string `json:"assignee"`
Assignees []string `json:"assignees"`
Milestone int64 `json:"milestone"`
Labels []int64 `json:"labels"`
// swagger:strfmt date-time
Deadline *time.Time `json:"due_date"`
*/
pr, err := login.Client().CreatePullRequest(owner, repo, gitea.CreatePullRequestOption{
Head: ctx.String("head"),
Base: ctx.String("base"),
Title: ctx.String("title"),
Body: ctx.String("body"),
})
if err != nil {
log.Fatal(err)
}
fmt.Printf("#%d %s\n%s created %s\n\n%s", pr.Index,
pr.Title,
pr.Poster.UserName,
pr.Created.Format("2006-01-02 15:04:05"),
pr.Body,
)
return nil
}

View File

@ -35,6 +35,7 @@ var CmdPulls = cli.Command{
Subcommands: []*cli.Command{
&CmdPullsCheckout,
&CmdPullsClean,
&CmdPullsCreate,
},
}
@ -264,6 +265,72 @@ call me again with the --ignore-sha flag`, pr.Head.Ref)
return r.TeaDeleteBranch(branch, pr.Head.Ref, auth)
}
// CmdPullsCreate creates a pull request
var CmdPullsCreate = cli.Command{
Name: "create",
Usage: "Create a pull-request",
Description: "Create a pull-request",
Action: runPullsCreate,
Flags: append([]cli.Flag{
&cli.StringFlag{
Name: "head",
Aliases: []string{"h"},
Usage: "pull-request head",
},
&cli.StringFlag{
Name: "base",
Aliases: []string{"b"},
Usage: "pull-request base",
},
&cli.StringFlag{
Name: "title",
Aliases: []string{"t"},
Usage: "pull-request title",
},
&cli.StringFlag{
Name: "description",
Aliases: []string{"d"},
Usage: "pull-request description",
},
}, AllDefaultFlags...),
}
func runPullsCreate(ctx *cli.Context) error {
login, owner, repo := initCommand()
/*
Head string `json:"head" binding:"Required"`
Base string `json:"base" binding:"Required"`
Title string `json:"title" binding:"Required"`
Body string `json:"body"`
Assignee string `json:"assignee"`
Assignees []string `json:"assignees"`
Milestone int64 `json:"milestone"`
Labels []int64 `json:"labels"`
// swagger:strfmt date-time
Deadline *time.Time `json:"due_date"`
*/
pr, err := login.Client().CreatePullRequest(owner, repo, gitea.CreatePullRequestOption{
Head: ctx.String("head"),
Base: ctx.String("base"),
Title: ctx.String("title"),
Body: ctx.String("body"),
6543 marked this conversation as resolved
Review

There is a chance that head == "" (ex. if TeaGetCurrentBranchName errors), should this be handled?

There is a chance that `head == ""` (ex. if `TeaGetCurrentBranchName` errors), should this be handled?
Review

good question I dont know yet ...

good question I dont know yet ...
Review

@techknowlogick
422 Unprocessable Entity: [{"fieldNames":["Head"],"classification":"RequiredError","message":"Required"},{"fieldNames":["Title"],"classification":"RequiredError","message":"Required"}]

title and head are required :)

@techknowlogick `422 Unprocessable Entity: [{"fieldNames":["Head"],"classification":"RequiredError","message":"Required"},{"fieldNames":["Title"],"classification":"RequiredError","message":"Required"}]` title and head are required :)
Review

So this is only for origin repository branches pull requests? No forked repository?

So this is only for origin repository branches pull requests? No forked repository?
Review

I'd like to get basic feature it first and enhance it later

so you can create pulls from forks but only manualy not automaticaly by branch remote rev
at the moment

I'd like to get basic feature it first and enhance it later so you can create pulls from forks but only manualy not automaticaly by branch remote rev at the moment
})
if err != nil {
log.Fatal(err)
}
fmt.Printf("#%d %s\n%s created %s\n\n%s", pr.Index,
pr.Title,
pr.Poster.UserName,
pr.Created.Format("2006-01-02 15:04:05"),

If this fails, even if it doesn't kill the whole operation, should it inform the user?

If this fails, even if it doesn't kill the whole operation, should it inform the user?
pr.Body,
)
return nil
}
func argToIndex(arg string) (int64, error) {
if strings.HasPrefix(arg, "#") {
arg = arg[1:]

View File

@ -38,7 +38,6 @@ func main() {
&cmd.CmdLogout,
&cmd.CmdIssues,
&cmd.CmdPulls,
&cmd.CmdPullRequest,
&cmd.CmdReleases,
&cmd.CmdRepos,
&cmd.CmdLabels,