Пример #1
0
func checkoutCmd(c *cli.Context) {
	number := c.Args()[0]
	pr, _, err := m.GetPullRequest(number, false)
	if err != nil {
		pulls.WriteError("%s", err)
	}
	if err := m.Checkout(pr); err != nil {
		pulls.WriteError("%s", err)
	}
}
Пример #2
0
func mergeCmd(c *cli.Context) {
	number := c.Args()[0]
	merge, err := m.MergePullRequest(number, c.String("m"), c.Bool("force"))
	if err != nil {
		pulls.WriteError("%s", err)
	}
	if merge.Merged {
		fmt.Fprintf(os.Stdout, "%s\n", brush.Green(merge.Message))
	} else {
		pulls.WriteError("%s", err)
	}
}
Пример #3
0
func repositoryInfoCmd(c *cli.Context) {
	r, err := m.Repository()
	if err != nil {
		pulls.WriteError("%s", err)
	}
	fmt.Fprintf(os.Stdout, "Name: %s\nForks: %d\nStars: %d\nIssues: %d\n", r.Name, r.Forks, r.Watchers, r.OpenIssues)
}
Пример #4
0
func alruCmd(c *cli.Context) {
	lru, err := m.GetFirstIssue("open", "updated")
	if err != nil {
		pulls.WriteError("Error getting issues: %s", err)
	}
	fmt.Printf("%v (#%d)\n", pulls.HumanDuration(time.Since(lru.UpdatedAt)), lru.Number)
}
Пример #5
0
// This is the top level command for
// working with prs
func mainCmd(c *cli.Context) {
	if !c.Args().Present() {
		state := "open"
		if c.Bool("closed") {
			state = "closed"
		}
		displayAllPullRequests(c, state)
		return
	}

	var (
		number  = c.Args().Get(0)
		comment = c.String("comment")
	)

	if comment != "" {
		addComment(number, comment)
		return
	}
	pr, comments, err := m.GetPullRequest(number, true)
	if err != nil {
		pulls.WriteError("%s", err)
	}
	pulls.DisplayPullRequest(pr, comments)
}
Пример #6
0
// Approve a pr by adding a LGTM to the comments
func approveCmd(c *cli.Context) {
	number := c.Args().First()
	if _, err := m.AddComment(number, "LGTM"); err != nil {
		pulls.WriteError("%s", err)
	}
	fmt.Fprintf(os.Stdout, "Pull request %s approved\n", brush.Green(number))
}
Пример #7
0
func addComment(number, comment string) {
	cmt, err := m.AddComment(number, comment)
	if err != nil {
		pulls.WriteError("%s", err)
	}
	pulls.DisplayCommentAdded(cmt)
}
Пример #8
0
func mainCmd(c *cli.Context) {
	issues, err := m.GetIssues("open", c.String("assigned"))
	if err != nil {
		pulls.WriteError("Error getting issues: %s", err)
	}

	fmt.Printf("%c[2K\r", 27)
	pulls.DisplayIssues(c, issues, c.Bool("no-trunc"))
}
Пример #9
0
func displayAllPullRequests(c *cli.Context, state string) {
	filter := getFilter(c)
	prs, err := filter(m.GetPullRequests(state))
	if err != nil {
		pulls.WriteError("Error getting pull requests %s", err)
	}

	fmt.Printf("%c[2K\r", 27)
	pulls.DisplayPullRequests(c, prs, c.Bool("no-trunc"))
}
Пример #10
0
func authCmd(c *cli.Context) {
	if token := c.String("add"); token != "" {
		if err := pulls.SaveConfig(pulls.Config{token}); err != nil {
			pulls.WriteError("%s", err)
		}
		return
	}
	// Display token and user information
	if config, err := pulls.LoadConfig(); err == nil {
		fmt.Fprintf(os.Stdout, "Token: %s\n", config.Token)
	} else {
		fmt.Fprintf(os.Stderr, "No token registered\n")
		os.Exit(1)
	}
}
Пример #11
0
func main() {

	app := cli.NewApp()

	app.Name = "pulls"
	app.Usage = "Manage github pull requests for project maintainers"
	app.Version = "0.0.1"

	client := gh.NewClient()

	org, name, err := pulls.GetOriginUrl()
	if err != nil {
		pulls.WriteError("%s", err)
	}
	t, err := pulls.NewMaintainer(client, org, name)
	if err != nil {
		pulls.WriteError("%s", err)
	}
	m = t

	loadCommands(app)

	app.Run(os.Args)
}