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 {
	//
	//	}
}
Пример #2
0
func sendAndroidNotification(msg *PushNotification) {
	var data map[string]interface{}
	if msg.Type == PUSH_TYPE_CLEAR {
		data = map[string]interface{}{"type": PUSH_TYPE_CLEAR, "channel_id": msg.ChannelId, "team_id": msg.TeamId}
	} else {
		data = map[string]interface{}{"type": PUSH_TYPE_MESSAGE, "message": emoji.Sprint(msg.Message), "channel_id": msg.ChannelId, "channel_name": msg.ChannelName, "team_id": msg.TeamId}
	}

	regIDs := []string{msg.DeviceId}
	gcmMsg := gcm.NewMessage(data, regIDs...)

	sender := &gcm.Sender{ApiKey: CfgPP.AndroidApiKey}

	if len(CfgPP.AndroidApiKey) > 0 {
		LogInfo("Sending android push notification")
		resp, err := sender.Send(gcmMsg, 2)

		if err != nil {
			LogError(fmt.Sprintf("Failed to send GCM push sid=%v did=%v err=%v", msg.ServerId, msg.DeviceId, err))
			return
		}

		if resp.Failure > 0 {
			LogError(fmt.Sprintf("Android response failure: %v", resp))
		}
	}
}
Пример #3
0
func BenchmarkEmojiKyokomiSprint(b *testing.B) {

	f := func(in []byte) []byte {
		return []byte(emoji.Sprint(string(in)))
	}

	doBenchmarkEmoji(b, f)
}
Пример #4
0
func main() {
	fmt.Println("Hello Wolrd Emoji!")

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

	pizzaMessage := emoji.Sprint("I like a :pizza: and :sushi:!!")
	fmt.Println(pizzaMessage)
}
Пример #5
0
func exitIf(err error) {

	if err == nil {
		return
	}

	fmt.Println(color.RedString("ERROR:"), err, emoji.Sprint(":fire:"))
	os.Exit(1)
}
Пример #6
0
func doBenchmarkEmoji(b *testing.B, f func(in []byte) []byte) {

	type input struct {
		in     []byte
		expect []byte
	}

	data := []struct {
		input  string
		expect string
	}{
		{"A :smile: a day", emoji.Sprint("A :smile: a day")},
		{"A :smile: and a :beer: day keeps the doctor away", emoji.Sprint("A :smile: and a :beer: day keeps the doctor away")},
		{"A :smile: a day and 10 " + strings.Repeat(":beer: ", 10), emoji.Sprint("A :smile: a day and 10 " + strings.Repeat(":beer: ", 10))},
		{"No smiles today.", "No smiles today."},
		{"No smiles for you or " + strings.Repeat("you ", 1000), "No smiles for you or " + strings.Repeat("you ", 1000)},
	}

	var in = make([]input, b.N*len(data))
	var cnt = 0
	for i := 0; i < b.N; i++ {
		for _, this := range data {
			in[cnt] = input{[]byte(this.input), []byte(this.expect)}
			cnt++
		}
	}

	b.ResetTimer()
	cnt = 0
	for i := 0; i < b.N; i++ {
		for j := range data {
			currIn := in[cnt]
			cnt++
			result := f(currIn.in)
			// The Emoji implementations gives slightly different output.
			diffLen := len(result) - len(currIn.expect)
			diffLen = int(math.Abs(float64(diffLen)))
			if diffLen > 30 {
				b.Fatalf("[%d] emoji std, got \n%q but expected \n%q", j, result, currIn.expect)
			}
		}

	}
}
Пример #7
0
func doBenchmarkEmoji(b *testing.B, f func(in []byte) []byte) {

	type input struct {
		in     []byte
		expect []byte
	}

	data := []struct {
		input  string
		expect string
	}{
		{"A :smile: a day", emoji.Sprint("A :smile: a day")},
		{"A :smile: and a :beer: day keeps the doctor away", emoji.Sprint("A :smile: and a :beer: day keeps the doctor away")},
		{"A :smile: a day and 10 " + strings.Repeat(":beer: ", 10), emoji.Sprint("A :smile: a day and 10 " + strings.Repeat(":beer: ", 10))},
		{"No smiles today.", "No smiles today."},
		{"No smiles for you or " + strings.Repeat("you ", 1000), "No smiles for you or " + strings.Repeat("you ", 1000)},
	}

	var in []input = make([]input, b.N*len(data))
	var cnt = 0
	for i := 0; i < b.N; i++ {
		for _, this := range data {
			in[cnt] = input{[]byte(this.input), []byte(this.expect)}
			cnt++
		}
	}

	b.ResetTimer()
	cnt = 0
	for i := 0; i < b.N; i++ {
		for j := range data {
			currIn := in[cnt]
			cnt++
			result := f(currIn.in)
			if len(result) != len(currIn.expect) {
				b.Fatalf("[%d] emoji std, got \n%q but expected \n%q", j, result, currIn.expect)
			}
		}

	}
}
Пример #8
0
func inlineResultArticle(from, to finance.Currency, rate float64) tgbotapi.InlineQueryResultArticle {
	text := fmt.Sprintf("1 %s = %.2f %s", from, rate, to)
	return tgbotapi.InlineQueryResultArticle{
		Type:        telegram.InlineQueryResultArticleType,
		MessageText: text,
		Title:       fmt.Sprintf("%s/%s", from, to),
		ID:          fmt.Sprintf("%X", rand.Int63()),
		Description: fmt.Sprintf("%s\n%s", text, emoji.Sprint(":sunglasses:")),
		ParseMode:   "Markdown",
		ThumbURL:    "http://vasi.net/uploads/posts/2012-07/1342465091_0.jpg",
	}
}
// 絵文字付きターミナル用のコメント作成(Activiyベース)
func createFeedCommentText(currentUser *gogitlab.User, feedCommit *gogitlab.FeedCommit) string {

	var iconName string
	if strings.Contains(feedCommit.Title, "commented") {
		iconName = ":speech_balloon:"
	} else if strings.Contains(feedCommit.Title, "pushed") {
		iconName = ":punch:"
	} else if strings.Contains(feedCommit.Title, "closed") {
		iconName = ":white_check_mark:"
	} else if strings.Contains(feedCommit.Title, "opened") {
		iconName = ":fire:"
	} else if strings.Contains(feedCommit.Title, "accepted") {
		iconName = ":atm:"
	} else {
		iconName = ":beer:"
	}

	if currentUser.Name == feedCommit.Author.Name {
		return emoji.Sprint("@{"+iconName+"}", color.Sprintf("@y[%s] %s", feedCommit.Updated.Format(time.ANSIC), feedCommit.Title))
	} else {
		return emoji.Sprint("@{"+iconName+"}", fmt.Sprintf("[%s] %s", feedCommit.Updated.Format(time.ANSIC), feedCommit.Title))
	}
}
Пример #10
0
// 絵文字付き通知用の簡易コメント作成(Activiyベース)
func createFeedShortCommentText(feedCommit *gogitlab.FeedCommit) string {

	var iconName string
	if strings.Contains(feedCommit.Title, "commented") {
		iconName = ":speech_balloon:"
	} else if strings.Contains(feedCommit.Title, "pushed") {
		iconName = ":punch:"
	} else if strings.Contains(feedCommit.Title, "closed") {
		iconName = ":white_check_mark:"
	} else if strings.Contains(feedCommit.Title, "opened") {
		iconName = ":fire:"
	} else if strings.Contains(feedCommit.Title, "accepted") {
		iconName = ":atm:"
	} else {
		iconName = ":beer:"
	}

	return emoji.Sprint("@{"+iconName+"}", fmt.Sprintf("%s", feedCommit.Title))
}
Пример #11
0
func sendAppleNotification(msg *PushNotification) {

	notification := &apns.Notification{}
	notification.DeviceToken = msg.DeviceId
	payload := payload.NewPayload()
	notification.Payload = payload
	notification.Topic = CfgPP.ApplePushTopic
	payload.Badge(msg.Badge)

	if msg.Type != PUSH_TYPE_CLEAR {
		payload.Alert(emoji.Sprint(msg.Message))
		payload.Category(msg.Category)
		payload.Sound("default")
	}

	if len(msg.ChannelId) > 0 {
		payload.Custom("channel_id", msg.ChannelId)
	}

	if len(msg.TeamId) > 0 {
		payload.Custom("team_id", msg.TeamId)
	}

	if len(msg.ChannelName) > 0 {
		payload.Custom("channel_name", msg.ChannelName)
	}

	if appleClient != nil {
		LogInfo("Sending apple push notification")
		res, err := appleClient.Push(notification)
		if err != nil {
			LogError(fmt.Sprintf("Failed to send apple push sid=%v did=%v err=%v", msg.ServerId, msg.DeviceId, err))
		}

		if !res.Sent() {
			LogError(fmt.Sprintf("Failed to send apple push with res ApnsID=%v reason=%v code=%v", res.ApnsID, res.Reason, res.StatusCode))
		}
	}
}
Пример #12
0
func getEmoji(temp int) (emojiString string) {
	switch temp {
	case 7, 8, 9, 10:
		emojiString = emoji.Sprint(" :snowflake: ")
	case 11, 12, 13, 14, 15:
		emojiString = emoji.Sprint(" :cloud_with_snow: ")
	case 16, 17, 18, 19, 20:
		emojiString = emoji.Sprint(" :cool: ")
	case 21, 22, 23, 24, 25:
		emojiString = emoji.Sprint(" :cloud: ")
	case 26, 27, 28, 29:
		emojiString = emoji.Sprint(" :sunny: ")
	case 30, 31, 32:
		emojiString = emoji.Sprint(" :fire: ")
	}
	return emojiString
}
Пример #13
0
	"time"

	"github.com/fatih/color"
	"github.com/github/hub/cmd"
	"github.com/kyokomi/emoji"
	"github.com/spf13/cobra"
)

const (
	name          = "git-fire"
	version       = "0.0.1"
	branchFmt     = "gf-%d-%s-%s"
	leaveBuilding = "\n\n\n_人人人人人人人人人_\n> Leave building ! <\n ̄Y^Y^Y^Y^Y^Y^Y^Y^Y ̄\n\n:runner: :dash: :dash: :dash: \t :fire: :office:\n"
)

var message = emoji.Sprint(":name_badge:") + " The fire, run!"

func main() {

	cmd := &cobra.Command{
		Use: name,
		Run: gitFire,
	}

	cmd.Execute()
}

func gitFire(cmd *cobra.Command, args []string) {

	color.New(color.FgCyan, color.Bold).Println("\nIn case of fire ...\n")
Пример #14
0
func TestEmojiCustom(t *testing.T) {
	for i, this := range []struct {
		input  string
		expect []byte
	}{
		{"A :smile: a day", []byte(emoji.Sprint("A :smile: a day"))},
		{"A few :smile:s a day", []byte(emoji.Sprint("A few :smile:s a day"))},
		{"A :smile: and a :beer: makes the day for sure.", []byte(emoji.Sprint("A :smile: and a :beer: makes the day for sure."))},
		{"A :smile: and: a :beer:", []byte(emoji.Sprint("A :smile: and: a :beer:"))},
		{"A :diamond_shape_with_a_dot_inside: and then some.", []byte(emoji.Sprint("A :diamond_shape_with_a_dot_inside: and then some."))},
		{":smile:", []byte(emoji.Sprint(":smile:"))},
		{":smi", []byte(":smi")},
		{"A :smile:", []byte(emoji.Sprint("A :smile:"))},
		{":beer:!", []byte(emoji.Sprint(":beer:!"))},
		{"::smile:", []byte(emoji.Sprint("::smile:"))},
		{":beer::", []byte(emoji.Sprint(":beer::"))},
		{" :beer: :", []byte(emoji.Sprint(" :beer: :"))},
		{":beer: and :smile: and another :beer:!", []byte(emoji.Sprint(":beer: and :smile: and another :beer:!"))},
		{" :beer: : ", []byte(emoji.Sprint(" :beer: : "))},
		{"No smilies for you!", []byte("No smilies for you!")},
		{" The motto: no smiles! ", []byte(" The motto: no smiles! ")},
		{":hugo_is_the_best_static_gen:", []byte(":hugo_is_the_best_static_gen:")},
		{"은행 :smile: 은행", []byte(emoji.Sprint("은행 :smile: 은행"))},
	} {
		result := Emojify([]byte(this.input))

		if !reflect.DeepEqual(result, this.expect) {
			t.Errorf("[%d] got '%q' but expected %q", i, result, this.expect)
		}

	}
}