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
2 changed files with 77 additions and 0 deletions
Showing only changes of commit c50a65182b - Show all commits

76
cmd/pull-request.go Normal file
View 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
}

View File

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