Ejemplo n.º 1
0
/*
  $ gh issue
*/
func issue(cmd *Command, args *Args) {

	gh := github.New()

	// list all issues

	if args.Noop {
		fmt.Printf("Would request list of issues for %s\n", gh.Project)
	} else {
		issues, err := gh.Issues()
		utils.Check(err)
		for _, issue := range issues {
			var url string
			// use the pull request URL if we have one
			if issue.PullRequest.HTMLURL != "" {
				url = issue.PullRequest.HTMLURL
			} else {
				url = issue.HTMLURL
			}
			// "nobody" should have more than 1 million github issues
			fmt.Printf("% 7d] %s ( %s )\n", issue.Number, issue.Title, url)
		}
	}

	os.Exit(0)
}
Ejemplo n.º 2
0
func fetchCiStatus(ref string) (state, targetURL, desc string, exitCode int, err error) {
	gh := github.New()
	status, err := gh.CIStatus(ref)
	if err != nil {
		return
	}

	if status == nil {
		state = "no status"
	} else {
		state = status.State
		targetURL = status.TargetURL
		desc = status.Description
	}

	switch state {
	case "success":
		exitCode = 0
	case "failure", "error":
		exitCode = 1
	case "pending":
		exitCode = 2
	default:
		exitCode = 3
	}

	return
}
Ejemplo n.º 3
0
func tranformFetchArgs(args *Args) {
	remotes, err := git.Remotes()
	utils.Check(err)

	names := parseRemoteNames(args)
	gh := github.New()
	projects := []github.Project{}
	ownerRegexp := regexp.MustCompile(OwnerRe)
	for _, name := range names {
		if ownerRegexp.MatchString(name) && !isRemoteExist(remotes, name) {
			project := github.NewProjectFromNameAndOwner("", name)
			repo, err := gh.Repository(project)
			if err != nil {
				continue
			}

			project = github.NewProjectFromNameAndOwner("", repo.FullName)
			projects = append(projects, project)
		}
	}

	for _, project := range projects {
		var isSSH bool
		if project.Owner == gh.Config.FetchUser() {
			isSSH = true
		}
		args.Before("git", "remote", "add", project.Owner, project.GitURL("", "", isSSH))
	}
}
Ejemplo n.º 4
0
Archivo: fork.go Proyecto: prsimp/gh
func fork(cmd *Command, args []string) {
	gh := github.New()
	project := gh.Project

	newRemote, err := gh.ForkRepository(project.Name, project.Owner, flagForkNoRemote)
	utils.Check(err)

	if !flagForkNoRemote && newRemote != "" {
		fmt.Printf("New remote: %s\n", newRemote)
	}
}
Ejemplo n.º 5
0
func fetchPullRequest(id string) (*octokat.PullRequest, error) {
	gh := github.New()
	pullRequest, err := gh.PullRequest(id)
	if err != nil {
		return nil, err
	}

	if pullRequest.Head.Repo.ID == 0 {
		user := pullRequest.User.Login
		return nil, fmt.Errorf("%s's fork is not available anymore", user)
	}

	return pullRequest, nil
}
Ejemplo n.º 6
0
Archivo: ci.go Proyecto: prsimp/gh
func ci(cmd *Command, args []string) {
	ref := "HEAD"
	if len(args) > 0 {
		ref = args[0]
	}

	ref, err := git.Ref(ref)
	utils.Check(err)

	gh := github.New()
	status, err := gh.CiStatus(ref)
	utils.Check(err)

	var state string
	var targetURL string
	var desc string
	var exitCode int
	if status == nil {
		state = "no status"
	} else {
		state = status.State
		targetURL = status.TargetURL
		desc = status.Description
	}

	switch state {
	case "success":
		exitCode = 0
	case "failure", "error":
		exitCode = 1
	case "pending":
		exitCode = 2
	default:
		exitCode = 3
	}

	fmt.Println(state)
	if targetURL != "" {
		fmt.Println(targetURL)
	}
	if desc != "" {
		fmt.Println(desc)
	}

	os.Exit(exitCode)
}
Ejemplo n.º 7
0
func release(cmd *Command, args *Args) {
	gh := github.New()
	if args.Noop {
		fmt.Printf("Would request list of releases for %s\n", gh.Project)
	} else {
		releases, err := gh.Releases()
		utils.Check(err)
		var outputs []string
		for _, release := range releases {
			out := fmt.Sprintf("%s (%s)\n%s", release.Name, release.TagName, release.Body)
			outputs = append(outputs, out)
		}

		fmt.Println(strings.Join(outputs, "\n\n"))
	}

	os.Exit(0)
}
Ejemplo n.º 8
0
Archivo: pull.go Proyecto: prsimp/gh
func pull(cmd *Command, args []string) {
	var title, body string
	if len(args) == 1 {
		title = args[0]
	}

	gh := github.New()
	repo := gh.Project.LocalRepoWith(flagPullRequestBase, flagPullRequestHead)
	if title == "" && flagPullRequestIssue == "" {
		messageFile, err := git.PullReqMsgFile()
		utils.Check(err)

		err = writePullRequestChanges(repo, messageFile)
		utils.Check(err)

		editorPath, err := git.EditorPath()
		utils.Check(err)

		err = editTitleAndBody(editorPath, messageFile)
		utils.Check(err)

		title, body, err = readTitleAndBody(messageFile)
		utils.Check(err)
	}

	if title == "" && flagPullRequestIssue == "" {
		log.Fatal("Aborting due to empty pull request title")
	}

	var pullRequestURL string
	var err error
	if title != "" {
		pullRequestURL, err = gh.CreatePullRequest(repo.Base, repo.Head, title, body)
	}
	if flagPullRequestIssue != "" {
		pullRequestURL, err = gh.CreatePullRequestForIssue(repo.Base, repo.Head, flagPullRequestIssue)
	}

	utils.Check(err)

	fmt.Println(pullRequestURL)
}
Ejemplo n.º 9
0
/*
  $ gh fork
  [ repo forked on GitHub ]
  > git remote add -f YOUR_USER [email protected]:YOUR_USER/CURRENT_REPO.git

  $ gh fork --no-remote
  [ repo forked on GitHub ]
*/
func fork(cmd *Command, args *Args) {
	gh := github.New()
	project := gh.Project

	var forkURL string
	if args.Noop {
		args.Before(fmt.Sprintf("Would request a fork to %s:%s", project.Owner, project.Name), "")
		forkURL = "FORK_URL"
	} else {
		repo, err := gh.ForkRepository(project.Name, project.Owner, flagForkNoRemote)
		utils.Check(err)

		forkURL = repo.SshURL
	}

	if !flagForkNoRemote {
		newRemote := gh.Config.User
		args.Replace("git", "remote", "add", "-f", newRemote, forkURL)
		args.After("echo", fmt.Sprintf("New remote: %s", newRemote))
	}
}
Ejemplo n.º 10
0
/*
  # while on a topic branch called "feature":
  $ gh pull-request
  [ opens text editor to edit title & body for the request ]
  [ opened pull request on GitHub for "YOUR_USER:feature" ]

  # explicit pull base & head:
  $ gh pull-request -b jingweno:master -h jingweno:feature

  $ gh pull-request -i 123
  [ attached pull request to issue #123 ]
*/
func pullRequest(cmd *Command, args *Args) {
	var title, body string
	if args.ParamsSize() == 1 {
		title = args.RemoveParam(0)
	}

	gh := github.New()
	repo := gh.Project.LocalRepoWith(flagPullRequestBase, flagPullRequestHead)
	if title == "" && flagPullRequestIssue == "" {
		t, b, err := writePullRequestTitleAndBody(repo)
		utils.Check(err)
		title = t
		body = b
	}

	if title == "" && flagPullRequestIssue == "" {
		utils.Check(fmt.Errorf("Aborting due to empty pull request title"))
	}

	var pullRequestURL string
	if args.Noop {
		args.Before(fmt.Sprintf("Would request a pull request to %s from %s", repo.FullBase(), repo.FullHead()), "")
		pullRequestURL = "PULL_REQUEST_URL"
	} else {
		if title != "" {
			pr, err := gh.CreatePullRequest(repo.Base, repo.Head, title, body)
			utils.Check(err)
			pullRequestURL = pr.HTMLURL
		}

		if flagPullRequestIssue != "" {
			pr, err := gh.CreatePullRequestForIssue(repo.Base, repo.Head, flagPullRequestIssue)
			utils.Check(err)
			pullRequestURL = pr.HTMLURL
		}
	}

	args.Replace("echo", "", pullRequestURL)
}