Example #1
0
func main() {
	config.LoadConfig()
	dev := viper.Sub("app.development.twitter")
	fmt.Println(dev)
	fmt.Println(dev.Get("consumerKey"))

	consumerKey := viper.Get("app.development.twitter.consumerKey").(string)
	consumerSecret := viper.Get("app.development.twitter.consumerSecret").(string)
	tokenKey := viper.Get("app.development.twitter.token").(string)
	tokenSecret := viper.Get("app.development.twitter.tokenSecret").(string)

	config := oauth1.NewConfig(consumerKey, consumerSecret)
	token := oauth1.NewToken(tokenKey, tokenSecret)
	httpClient := config.Client(oauth1.NoContext, token)

	client := twitter.NewClient(httpClient)

	userShowParams := &twitter.UserShowParams{ScreenName: "realDonaldTrump"}
	user, _, _ := client.Users.Show(userShowParams)
	fmt.Printf("USERS SHOW:\n%v\n", user)

	f := new(bool)
	*f = false
	userTimelineParams := &twitter.UserTimelineParams{ScreenName: "realDonaldTrump", Count: 1, IncludeRetweets: f}
	tweets, _, _ := client.Timelines.UserTimeline(userTimelineParams)
	for tweet := range tweets {
		t, _ := json.MarshalIndent(tweets[tweet], "", "    ")
		fmt.Println(string(t))
	}
}
Example #2
0
func dataMatch(name string, data data.SensorData) (float64, bool) {
	query := viper.Sub("current_data").GetStringMapString(name)
	if t, ok := query["id"]; ok {
		if data.ID != t {
			return 0, false
		}
	}
	if t, ok := query["channel"]; ok {
		x, err := strconv.Atoi(t)
		if err != nil || data.Channel != x {
			return 0, false
		}
	}
	if t, ok := query["serial"]; ok {
		if data.Serial != t {
			return 0, false
		}
	}
	if t, ok := query["type"]; ok {
		if v, ok := data.Data[t]; ok {
			return v, true
		}
	}
	return 0, false
}
Example #3
0
// Configure runs all the checks needed for the config file to be set up correctly and prints the repositories available
func Configure() {

	err := CheckFile()
	if err != nil {
		log.Fatal(err)
	}

	err = CheckRepositories()
	if err != nil {
		log.Fatal(err)
	}

	config := NewConfig(viper.Sub("repositories"))
	resp, err2 := CheckRepositoriesData(config)
	if err2 != nil {
		log.Fatal(err2)
	}

	fmt.Printf("%s", resp)

}
Example #4
0
func get_graph_config() *viper.Viper {
	return viper.Sub("graph")
}
Example #5
0
func get_metric_config() *viper.Viper {
	return viper.Sub("ng_metric")
}
Example #6
0
func get_state_config() *viper.Viper {
	return viper.Sub("ng_state")
}
Example #7
0
func get_daemon_config() *viper.Viper {
	return viper.Sub("daemon")
}
Example #8
0
// Execute checks if the PR defers to be merged.
func Execute(DryRun bool) bool {
	if DryRun {
		fmt.Printf("Working in dry-run mode...\n")
	}
	err := CheckFile()
	if err != nil {
		log.Fatal(err)
	}
	err = CheckRepositories()
	if err != nil {
		log.Fatal(err)
	}
	repositories := NewConfig(viper.Sub("repositories"))
	client, err := GetClient()
	if err != nil {
		log.Fatalf("Error creating GitHub client %v", err)
	}

	//TODO: https://github.com/gophergala2016/reviewer/issues/38
	for _, repoName := range repositories.AllKeys() {
		username := repositories.GetString(repoName + ".username")
		status := repositories.GetBool(repoName + ".status")
		required := repositories.GetInt(repoName + ".required")
		allowed := repositories.GetStringSlice(repoName + ".allowed")

		if !status {
			fmt.Printf("- %v/%v Discarded (repo disabled)\n", username, repoName)
			continue
		}
		prInfos, err := GetPullRequestInfos(client, username, repoName, allowed)
		if err != nil {
			fmt.Printf("Error getting pull request info of repo %v/%v", username, repoName)
			continue
		}
		fmt.Printf("+ %v/%v\n", username, repoName)
		for _, prInfo := range prInfos {
			pullRequest, _, err := client.Changes.Get(username, repoName, prInfo.Number)
			if err != nil {
				fmt.Printf("  - %v NOP   (%v) Failure getting pull request\n", prInfo.Number, prInfo.Title)
				continue
			}
			if !IsMergeable(pullRequest) {
				fmt.Printf("  - %v NOP   (%v) Not mergeable\n", prInfo.Number, prInfo.Title)
				continue
			}
			var passedTests bool
			passedTests, err = PassedTests(client, pullRequest, username, repoName)
			if err != nil {
				fmt.Printf("  - %v NOP   (%v) %s\n", prInfo.Number, prInfo.Title, err)
				continue
			}
			if !passedTests {
				fmt.Printf("  - %v NOP   (%v) Tests not passed\n", prInfo.Number, prInfo.Title)
				continue
			}
			if prInfo.Score < required {
				fmt.Printf("  - %v NOP   (%v) score %v of %v required\n", prInfo.Number, prInfo.Title, prInfo.Score, required)
				continue
			}
			if !DryRun {
				_, err := Merge(client, username, repoName, prInfo.Number)
				if err != nil {
					fmt.Printf("  + %v -merge- (%v)  Merge failed: %v\n", prInfo.Number, prInfo.Title, err)
				}
				fmt.Printf("  + %v MERGE (%v) score %v of %v required\n", prInfo.Number, prInfo.Title, prInfo.Score, required)
			} else {
				fmt.Printf("  - %v (merge)  (%v) score %v of %v required\n", prInfo.Number, prInfo.Title, prInfo.Score, required)
			}
		}
	}
	return true
}