<commit_before>// Copyright © 2016 See CONTRIBUTORS <<EMAIL>>
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
//     http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.

package reviewer

import (
	"errors"
	"strings"

    "github.com/spf13/viper"
	"github.com/google/go-github/github"
	"golang.org/x/oauth2"
)

// GetString contains the function used to lookup environment variables.
var GetString = viper.GetString

// NewGHClient contains the constructor for github.Client.
var NewGHClient = github.NewClient

// PullRequestInfo contains the id of the pull request and its current CR score.
type PullRequestInfo struct {
	number int // id of the pull request
	score  int
}

type PullRequestInfoList []PullRequestInfo

// GetClient returns a github.Client authenticated.
func GetClient() (*github.Client, error) {
	token := GetString("authorization.token")
	if token == "" {
		return nil, errors.New("An error occurred getting REVIEWER_TOKEN environment variable")
	}
	ts := oauth2.StaticTokenSource(
		&oauth2.Token{AccessToken: token},
	)
	tc := oauth2.NewClient(oauth2.NoContext, ts)

	return NewGHClient(tc), nil
}

func getCommentSuccessScore(comment string) int {
	score := 0
	if strings.Contains(comment, "+1") {
		score++
	}
	if strings.Contains(comment, "-1") {
		score--
	}
	return score
}

func GetPullRequestInfos(client *github.Client, owner string, repo string) (*PullRequestInfoList, error) {
	pullRequests, _, err := client.PullRequests.List(owner, repo, nil)
	if err != nil {
		return nil, err
	}
	pris := make(PullRequestInfoList, len(pullRequests))
	for n, pullRequest := range pullRequests {
		pris[n].number = *pullRequest.Number
		comments, _, err := client.Issues.ListComments(owner, repo, *pullRequest.Number, nil)
		if err != nil {<commit_msg>Fixes golint errors<commit_after>// Copyright © 2016 See CONTRIBUTORS <<EMAIL>>
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
//     http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.

package reviewer

import (
	"errors"
	"strings"

    "github.com/spf13/viper"
	"github.com/google/go-github/github"
	"golang.org/x/oauth2"
)

// GetString contains the function used to lookup environment variables.
var GetString = viper.GetString

// NewGHClient contains the constructor for github.Client.
var NewGHClient = github.NewClient

// PullRequestInfo contains the id of the pull request and its current CR score.
type PullRequestInfo struct {
	number int // id of the pull request
	score  int
}

// PullRequestInfoList continas the list of PullRequestInfos.
type PullRequestInfoList []PullRequestInfo

// GetClient returns a github.Client authenticated.
func GetClient() (*github.Client, error) {
	token := GetString("authorization.token")
	if token == "" {
		return nil, errors.New("An error occurred getting REVIEWER_TOKEN environment variable")
	}
	ts := oauth2.StaticTokenSource(
		&oauth2.Token{AccessToken: token},
	)
	tc := oauth2.NewClient(oauth2.NoContext, ts)

	return NewGHClient(tc), nil
}

// getCommentSuccesScore returns the score for the Comment.
func getCommentSuccessScore(comment string) int {
	score := 0
	if strings.Contains(comment, "+1") {
		score++
	}
	if strings.Contains(comment, "-1") {
		score--
	}
	return score
}

// GetPullRequestInfos returns a PullRequestInfoList with the scoring updated.
func GetPullRequestInfos(client *github.Client, owner string, repo string) (*PullRequestInfoList, error) {
	pullRequests, _, err := client.PullRequests.List(owner, repo, nil)
	if err != nil {
		return nil, err
	}
	pris := make(PullRequestInfoList, len(pullRequests))
	for n, pullRequest := range pullRequests {
		pris[n].number = *pullRequest.Number
		comments, _, err := client.Issues.ListComments(owner, repo, *pullRequest.Number, nil)
		if err != nil {
{'fraction_non_alphanumeric': 0.10561411056141105, 'fraction_numerical': 0.007743600774360078, 'mean_word_length': 4.201342281879195, 'pattern_counts': {'":': 0, '<': 7, '<?xml version=': 0, '>': 7, 'https://': 0, 'lorem ipsum': 0, 'www.': 2, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '567613', 'n_tokens_mistral': 1427, 'n_tokens_neox': 1365, 'n_words': 481}