示例#1
0
文件: fetch.go 项目: rif/golang-stuff
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))
	}
}
示例#2
0
/*
  $ gh create
  ... create repo on github ...
  > git remote add -f origin [email protected]:YOUR_USER/CURRENT_REPO.git

  # with description:
  $ gh create -d 'It shall be mine, all mine!'

  $ gh create recipes
  [ repo created on GitHub ]
  > git remote add origin [email protected]:YOUR_USER/recipes.git

  $ gh create sinatra/recipes
  [ repo created in GitHub organization ]
  > git remote add origin [email protected]:sinatra/recipes.git
*/
func create(command *Command, args *Args) {
	var (
		name string
		err  error
	)
	if args.IsParamsEmpty() {
		name, err = utils.DirName()
		utils.Check(err)
	} else {
		name = args.FirstParam()
	}

	var msg string
	project := github.NewProjectFromNameAndOwner(name, "")
	gh := github.NewWithoutProject()
	if gh.IsRepositoryExist(project) {
		fmt.Printf("%s already exists on %s\n", project, github.GitHubHost)
		msg = "set remmote origin"
	} else {
		if !args.Noop {
			repo, err := gh.CreateRepository(project, flagCreateDescription, flagCreateHomepage, flagCreatePrivate)
			utils.Check(err)
			project = github.NewProjectFromNameAndOwner("", repo.FullName)
		}
		msg = "created repository"
	}

	remote, _ := git.OriginRemote()
	if remote == nil {
		url := project.GitURL("", "", true)
		args.Replace("git", "remote", "add", "-f", "origin", url)
	} else {
		args.Replace("git", "remote", "-v")
	}

	args.After("echo", fmt.Sprintf("%s:", msg), project.String())
}