Add subcomand 'pulls create' #144
|
@ -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
|
||||
}
|
67
cmd/pulls.go
67
cmd/pulls.go
|
@ -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
|
||||
})
|
||||
|
||||
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"),
|
||||
jolheiser
commented
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:]
|
||||
|
|
Loading…
Reference in New Issue
Block a user
There is a chance that
head == ""
(ex. ifTeaGetCurrentBranchName
errors), should this be handled?good question I dont know yet ...
@techknowlogick
422 Unprocessable Entity: [{"fieldNames":["Head"],"classification":"RequiredError","message":"Required"},{"fieldNames":["Title"],"classification":"RequiredError","message":"Required"}]
title and head are required :)
So this is only for origin repository branches pull requests? No forked repository?
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