Add subcomand 'pulls create' #144
76
cmd/pull-request.go
Normal file
76
cmd/pull-request.go
Normal file
@ -0,0 +1,76 @@
|
||||
// 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
|
||||
}
|
1
main.go
1
main.go
@ -38,6 +38,7 @@ func main() {
|
||||
&cmd.CmdLogout,
|
||||
&cmd.CmdIssues,
|
||||
&cmd.CmdPulls,
|
||||
&cmd.CmdPullRequest,
|
||||
&cmd.CmdReleases,
|
||||
&cmd.CmdRepos,
|
||||
&cmd.CmdLabels,
|
||||
|
Loading…
Reference in New Issue
Block a user