func getProjectIssues(gitlab *gogitlab.Gitlab, projectId int) {

	events := gitlab.ProjectEvents(projectId)
	for _, event := range events {

		var iconName string
		switch event.TargetType {
		case "Issue":
			iconName = ":beer:"
		default:
			iconName = ":punch:"
		}

		//fmt.Printf("ProjectID[%d] action[%s] targetId[%d] targetType[%s] targetTitle[%s]\n", event.ProductId, event.ActionName,event.TargetId, event.TargetType, event.TargetTitle)
		if event.TargetId != 0 {
			actionText := color.Sprintf("@y[%s]", event.ActionName)
			repositoriesText := color.Sprintf("@c%s(%d)", event.TargetType, event.TargetId)
			userText := color.Sprintf("@c%s", event.Data.UserName)
			titleText := color.Sprintf("@g%s", event.TargetTitle)
			emoji.Println("@{"+iconName+"}", actionText, repositoriesText, userText, titleText)

		} else if event.TargetId == 0 {

			actionText := color.Sprintf("@y[%s]", event.ActionName)
			repositoriesText := color.Sprintf("@c%s", event.Data.Repository.Name)
			userText := color.Sprintf("@c%s", event.Data.UserName)
			var titleText string
			if event.Data.TotalCommitsCount > 0 {
				commitMessage := event.Data.Commits[0].Message
				commitMessage = strings.Replace(commitMessage, "\n\n", "\t", -1)
				titleText = color.Sprintf("@g%s", commitMessage)
			} else if event.Data.Before == "0000000000000000000000000000000000000000" {
				titleText = color.Sprintf("@g%s %s", emoji.Sprint("@{:fire:}"), "create New branch")
			}
			emoji.Println("@{"+iconName+"}", actionText, repositoriesText, userText, titleText)

			//			fmt.Println(" \t user   -> ", event.Data.UserName, event.Data.UserId)
			//			fmt.Println(" \t author -> ", event.Data.AuthorId)
			//
			//			fmt.Println(" \t\t name        -> ", event.Data.Repository.Name)
			//			fmt.Println(" \t\t description -> ", event.Data.Repository.Description)
			//			fmt.Println(" \t\t gitUrl      -> ", event.Data.Repository.GitUrl)
			//			fmt.Println(" \t\t pageUrl     -> ", event.Data.Repository.PageUrl)
			//
			//			fmt.Println(" \t\t totalCount  -> ", event.Data.TotalCommitsCount)
			//
			//			if event.Data.TotalCommitsCount > 0 {
			//				fmt.Println(" \t\t message     -> ", event.Data.Commits[0].Message)
			//				fmt.Println(" \t\t time        -> ", event.Data.Commits[0].Timestamp)
			//			}
		}
	}
	//
	//	for _, event := range events {
	//
	//	}
}
Exemple #2
0
func main() {
	fmt.Println("Hello Wolrd Emoji!")

	emoji.Println(":beer: Beer!!!")

	pizzaMessage := emoji.Sprint("I like a :pizza: and :sushi:!!")
	fmt.Println(pizzaMessage)
}
Exemple #3
0
func gitFire(cmd *cobra.Command, args []string) {

	color.New(color.FgCyan, color.Bold).Println("\nIn case of fire ...\n")

	wg := sync.WaitGroup{}
	email := "anonymous"
	ref := "noref"

	wg.Add(2)

	// get user email
	go func() {

		defer wg.Done()

		resp, err := git("config", "user.email")
		exitIf(err)

		if len(resp) != 0 {
			email = resp[0]
		}
	}()

	// get head ref
	go func() {

		defer wg.Done()

		resp, err := git("rev-parse", "--short", "-q", "head")
		exitIf(err)

		if len(resp) != 0 {
			ref = resp[0]
		}
	}()

	wg.Wait()

	// checkout new branch
	branch := fmt.Sprintf(branchFmt, time.Now().Unix(), email, ref)
	_, err := git("checkout", "-b", branch)
	exitIf(err)

	fmt.Printf("Branch:\n\t%s\n", branch)

	// commit all files
	git("add", "-A")

	if len(args) != 0 {
		message = args[0]
	}
	_, err = git("commit", "--allow-empty", "-m", message)
	exitIf(err)

	fmt.Printf("Message:\n\t%s\n\n\n", message)

	// push remotes
	remotes, err := git("remote")
	exitIf(err)

	count := len(remotes)
	wg.Add(count)
	fmt.Printf("Push (%d remote(s)):\n", count)
	for i := range remotes {
		go func(remote string) {

			defer wg.Done()

			_, err = git("push", remote, branch)
			isPushed(remote, err)

		}(remotes[i])
	}

	wg.Wait()

	// leave building
	emoji.Println(leaveBuilding)
}