Esempio n. 1
0
func fireNotification() {
	if err := notification.SendMessage(projectVersion, projectBuild); err != nil {
		if notification.IsNotConfigured(err) {
			exitError("Notifications not configured. Use 'kocho slack init'")
		} else if notification.IsInvalidConfiguration(err) {
			exitError("Invalid configuration file: %v", err)
		} else {
			exitError("failed to send message: %v", err)
		}
	}
}
Esempio n. 2
0
func runSlack(args []string) (exit int) {
	if len(args) != 1 {
		return exitError("usage: kocho slack init|test")
	}

	switch args[0] {
	case "init":
		slackConfiguration := notification.SlackConfiguration{}

		slackConfiguration.Token = readFromStdin(LabelToken)
		slackConfiguration.Username = readFromStdin(LabelUsername)
		slackConfiguration.NotificationUsername = readFromStdin(LabelNotificationUsername)
		slackConfiguration.EmojiIcon = readFromStdin(LabelEmoji)
		slackConfiguration.NotificationChannel = readFromStdin(LabelNotificationChannel)

		if !strings.HasPrefix(slackConfiguration.NotificationChannel, "#") {
			slackConfiguration.NotificationChannel = "#" + slackConfiguration.NotificationChannel
		}

		if err := notification.WriteConfig(slackConfiguration); err != nil {
			return exitError("failed to write configuration: ", err)
		}
	case "test":
		if err := notification.SendMessage(projectVersion, projectBuild); err != nil {
			if notification.IsNotConfigured(err) {
				exitError("Notifications not configured. Use 'kocho slack init'")
			} else if notification.IsInvalidConfiguration(err) {
				exitError("Invalid configuration file:", err)
			} else {
				exitError("Failed to send message:", err)
			}
		} else {
			fmt.Println("test message sent successfully.")
		}
	}

	return 0
}