示例#1
0
文件: project.go 项目: johnbellone/gh
func CurrentProject() *Project {
	remote, err := git.OriginRemote()
	utils.Check(err)

	owner, name := parseOwnerAndName(remote.URL)

	return &Project{name, owner}
}
示例#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())
}