Beispiel #1
0
Datei: main.go Projekt: saml/x
func main() {
	token := args.String("token", "SLACK_API_TOKEN", "", "Slack API token.")
	flag.Parse()

	bot, err := slackbot.New(*token)
	if err != nil {
		log.Fatal(err)
	}
	bot.Start()
}
Beispiel #2
0
func main() {
	token := args.String("token", "GITHUB_TOKEN", "", "github api token")
	orgName := args.String("org", "GITHUB_ORGANIZATION", "", "github organization name")
	reposFile := args.String("repos", "GITHUB_REPOS_FILE", "./repos.json", "github repositories")
	flag.Parse()

	ts := oauth2.StaticTokenSource(&oauth2.Token{
		AccessToken: *token,
	})
	tc := oauth2.NewClient(oauth2.NoContext, ts)

	client := github.NewClient(tc)

	var allRepos map[string]github.Repository
	var err error
	allRepos, err = loadOrFetchRepos(client, *orgName, *reposFile)
	if err != nil {
		log.Fatal(err)
	}

	reader := bufio.NewReader(os.Stdin)

	for {
		fmt.Print("> ")
		line, err := reader.ReadString('\n')
		if err != nil {
			if err == io.EOF {
				fmt.Println("")
				break
			}
			log.Fatal(err)
		}
		tokens := tokenize(line)
		if len(tokens) < 1 {
			fmt.Println(".COMMAND ARG1 ARG2 ...")
			continue
		}

		command := tokens[0]
		arguments := tokens[1:]
		switch command {
		case ".quit":
			break
		case ".save":
			err := saveRepos(allRepos, *reposFile)
			if err != nil {
				fmt.Println(err.Error())
			} else {
				fmt.Printf("Saved %s\n", *reposFile)
			}
		case ".repos":
			for repoName, repo := range allRepos {
				fmt.Printf("%s %s\n", repoName, *repo.URL)
			}
		case ".release":
			if len(arguments) < 1 {
				fmt.Println(".release REPO")
			} else {
				repoName := arguments[0]
				repo, ok := allRepos[repoName]
				if !ok {
					fmt.Println("Repo not found")
				} else {
					release, _, err := client.Repositories.GetLatestRelease(*repo.Owner.Login, *repo.Name)
					if err != nil {
						fmt.Printf("ERROR %s\n", err.Error())
					} else {
						fmt.Println(*release.TagName)
					}
				}
			}
		}
	}

}