Documentation ¶
Index ¶
Constants ¶
This section is empty.
Variables ¶
View Source
var Collab = cli.Command{ Name: "collab", Aliases: []string{"c"}, Usage: "Collaborator actions", Subcommands: []cli.Command{ collabAdd, collabRm, collabList, }, }
Collab provides collaboration-related commands
View Source
var NewRepo = cli.Command{ Name: "new", Usage: "Creates a new repository", ArgsUsage: "(--private) (--init) (--license LICENSE) (--gitignore LANGUAGE_OR_PLATFORM) [name, ...]", Flags: []cli.Flag{ cli.BoolFlag{ Name: "private", Usage: "creates a private repository", }, cli.BoolFlag{ Name: "init", Usage: "initializes the repository with a commit and empty README", }, cli.StringFlag{ Name: "license", Usage: "selects a license template to apply. Use a license name from https://github.com/github/choosealicense.com/tree/gh-pages/_licenses, without the extension (For example, 'mit' or 'mozilla')", Value: "", }, cli.StringFlag{ Name: "gitignore", Usage: "selects a gitignore template to apply. Use a language or platform name from https://github.com/github/gitignore withtout the extension (For example, 'Haskell')", Value: "", }, }, Action: func(c *cli.Context) error { if len(c.Args()) < 1 { return fmt.Errorf("the 'new' command requires at least one repository name") } client := utils.NewClient() private := c.Bool("private") repos := []utils.RepoURL{} usersOrgs := map[string]bool{} for _, re := range c.Args() { r := utils.RepoURLFromString(re) r.AutoComplete() if newName, changed := utils.NormalizeRepoName(r.RepoName); changed { fmt.Printf("Your repository will be created as %s/%s\n", r.Username, newName) if !utils.Confirm("Seems okay? [y]/n", true) { return fmt.Errorf("aborted") } r.RepoName = newName } repos = append(repos, r) } for _, re := range repos { newRepoLogger.Timing("Creating %s", re.ToURL()) uri := octokit.UserRepositoriesURL params := octokit.M{} userIsOrg := false if isOrg, present := usersOrgs[re.Username]; !present { usersOrgs[re.Username] = utils.UserIsOrg(re.Username) userIsOrg = usersOrgs[re.Username] } else { userIsOrg = isOrg } if userIsOrg { uri = octokit.OrganizationReposURL params = octokit.M{"org": re.Username} } repo, res := client.Repositories().Create(&uri, params, octokit.Repository{ Name: re.RepoName, Private: private, GitIgnoreTemplate: c.String("gitignore"), LicenseTemplate: c.String("license"), }) if res.HasError() { if err, ok := res.Err.(*octokit.ResponseError); ok { newRepoLogger.Error("%s", utils.FormatError(err)) os.Exit(1) } else { panic(err) } } newRepoLogger.Success("Created: %s", repo.FullName) } return nil }, }
NewRepo is responsible for creating repositories
View Source
var Open = cli.Command{ Name: "open", Aliases: []string{"o"}, Usage: "Opens a repository on GitHub.com", UsageText: "gh open [repository]", ArgsUsage: "[repository]", Action: func(c *cli.Context) error { if len(c.Args()) != 1 { return fmt.Errorf("usage: gh o (owner/)[repo]") } rep := utils.RepoURLFromString(c.Args()[0]) url := fmt.Sprintf("https://github.com/%s", rep.ToURL()) var err error switch runtime.GOOS { case "linux": err = exec.Command("xdg-open", url).Start() case "darwin": err = exec.Command("open", url).Start() case "windows": err = exec.Command(`C:\Windows\System32\rundll32.exe`, "url.dll,FileProtocolHandler", url).Start() default: err = fmt.Errorf("unsupported platform '%s'. Please open an issue at https://github.com/victorgama/gh", runtime.GOOS) } return err }, }
Open exposes a command responsible for opening repositories on the default browser
View Source
var RepoList = cli.Command{ Name: "list", Aliases: []string{"l", "ls"}, Usage: "Lists your repositories", Action: func(c *cli.Context) error { listRepoLogger.Timing("Fetching repositories...") allRepos, err := utils.GetAllUserRepositories() if err != nil { if err, ok := err.(*octokit.ResponseError); ok { listRepoLogger.Error("%s", utils.FormatError(err)) os.Exit(1) } return err } orgs := []string{} orgsRepos := map[string][]string{} repos := map[string]octokit.Repository{} for _, repo := range allRepos { orgName := repo.Owner.Login if _, present := orgsRepos[orgName]; !present { orgs = append(orgs, orgName) orgsRepos[orgName] = []string{} } orgsRepos[orgName] = append(orgsRepos[orgName], repo.Name) repos[repo.FullName] = repo } if username, present := utils.CurrentUserName(); present { username = strings.ToLower(username) index := -1 for idx, n := range orgs { if strings.ToLower(n) == username { index = idx break } } if index > -1 { currentUser := orgs[index] orgs = append(orgs[:index], orgs[index+1:]...) sortedRepos := orgsRepos[currentUser] sort.Sort(utils.Alphabetic(sortedRepos)) printRepositories(currentUser, sortedRepos, &repos, "You") } } sort.Sort(utils.Alphabetic(orgs)) for _, orgName := range orgs { sortedRepos := orgsRepos[orgName] sort.Sort(utils.Alphabetic(sortedRepos)) printRepositories(orgName, sortedRepos, &repos, "") } return nil }, }
RepoList exposes a command responsible for listing repositories
View Source
var RmRepo = cli.Command{ Name: "rm", Usage: "Destroys a repository", Action: func(c *cli.Context) error { if len(c.Args()) != 1 { return fmt.Errorf("the 'rm' command requires one repository name") } client := utils.NewClient() rmRepoLogger.Timing("One moment, please...") r := utils.RepoURLFromString(c.Args()[0]) r.AutoComplete() repo, resp := client.Repositories().One(&octokit.RepositoryURL, octokit.M{"owner": r.Username, "repo": r.RepoName}) utils.HandleClientError(resp, rmRepoLogger) fmt.Println("Hey! You're about to perform a really dangerous action.") fmt.Printf("To confirm you really want to delete %s, please enter its name again:\n", repo.FullName) fmt.Print("What is its name again? ") reader := bufio.NewReader(os.Stdin) s, err := reader.ReadString('\n') if err != nil { panic(err) } s = strings.TrimSpace(s) s = strings.ToLower(s) if s != strings.ToLower(repo.Name) { fmt.Println("Nope. That's not its name. Aborting.") return fmt.Errorf("aborted") } rmRepoLogger.Info("Removing %s...", repo.FullName) success, resp := client.Repositories().Delete(&octokit.RepositoryURL, octokit.M{"owner": r.Username, "repo": r.RepoName}) if !success { utils.HandleClientError(resp, rmRepoLogger) } rmRepoLogger.Success("Removed %s", repo.FullName) return nil }, }
RmRepo exposes a command responsible for deleting a repository
View Source
var Teams = cli.Command{ Name: "teams", Aliases: []string{"t"}, Usage: "Manages organization teams", Subcommands: []cli.Command{ teamsList, teamsMembers, teamAddUser, teamRmUser, }, }
Teams exposes team-related commands
Functions ¶
This section is empty.
Types ¶
This section is empty.
Click to show internal directories.
Click to hide internal directories.