ronantakizawa/codereview-bench huggingface dataset:
Repository: google/go-github
File: github/github_test.go (Go)

Code before:
	// Unmarshal the wanted JSON, to verify its correctness, and marshal it back
	// to sort the keys.
	u := reflect.New(reflect.TypeOf(v)).Interface()
	if err := json.Unmarshal([]byte(want), &u); err != nil {
		t.Errorf("Unable to unmarshal JSON for %v: %v", want, err)
	}
	w, err := json.Marshal(u)
	if err != nil {
		t.Errorf("Unable to marshal JSON for %#v", u)
	}

	// Marshal the target value.
	j, err := json.Marshal(v)
	if err != nil {
		t.Errorf("Unable to marshal JSON for %#v", v)
	}

	if string(w) != string(j) {
		t.Errorf("json.Marshal(%q) returned %s, want %s", v, j, w)
	}
}

func testAddOptions(t *testing.T, url string, v interface{}, want string) {
	t.Helper()

	u, err := addOptions(url, v)
	if err != nil {
		t.Errorf("Unable to add %#v as query parameters", v)
	}

	if u != want {
		t.Errorf("addOptions(%q, %#v) returned %s, want %s", url, v, u, want)
	}
}

// Test how bad options are handled. Method f under test should
// return an error.
func testBadOptions(t *testing.T, methodName string, f func() error) {
	t.Helper()
	if methodName == "" {
		t.Error("testBadOptions: must supply method methodName")
	}
	if err := f(); err == nil {
		t.Errorf("bad options %v err = nil, want error", methodName)
	}
}

// Test function under NewRequest failure and then s.client.Do failure.
// Method f should be a regular call that would normally succeed, but
// should return an error when NewRequest or s.client.Do fails.
func testNewRequestAndDoFailure(t *testing.T, methodName string, client *Client, f func() (*Response, error)) {

Review comment (suggestion):
```suggestion
	got, err := addOptions(url, v)
```

Code after:
	// Unmarshal the wanted JSON, to verify its correctness, and marshal it back
	// to sort the keys.
	u := reflect.New(reflect.TypeOf(v)).Interface()
	if err := json.Unmarshal([]byte(want), &u); err != nil {
		t.Errorf("Unable to unmarshal JSON for %v: %v", want, err)
	}
	w, err := json.Marshal(u)
	if err != nil {
		t.Errorf("Unable to marshal JSON for %#v", u)
	}

	// Marshal the target value.
	j, err := json.Marshal(v)
	if err != nil {
		t.Errorf("Unable to marshal JSON for %#v", v)
	}

	if string(w) != string(j) {
		t.Errorf("json.Marshal(%q) returned %s, want %s", v, j, w)
	}
}

// Test whether the v fields have the url tag and the parsing of v
// produces query parameters that corresponds to the want string.
func testAddURLOptions(t *testing.T, url string, v interface{}, want string) {
	t.Helper()

	vt := reflect.Indirect(reflect.ValueOf(v)).Type()
	for i := 0; i < vt.NumField(); i++ {
		field := vt.Field(i)
		if alias, ok := field.Tag.Lookup("url"); ok {
			if alias == "" {
				t.Errorf("The field %+v has a blank url tag", field)
			}
		} else {
			t.Errorf("The field %+v has no url tag specified", field)
		}
	}

	got, err := addOptions(url, v)
	if err != nil {
		t.Errorf("Unable to add %#v as query parameters", v)
	}

	if got != want {
		t.Errorf("addOptions(%q, %#v) returned %v, want %v", url, v, got, want)
	}
}

// Test how bad options are handled. Method f under test should
// return an error.
Repository: google/go-github
File: github/github_test.go (Go)

Code before:
	w, err := json.Marshal(u)
	if err != nil {
		t.Errorf("Unable to marshal JSON for %#v", u)
	}

	// Marshal the target value.
	j, err := json.Marshal(v)
	if err != nil {
		t.Errorf("Unable to marshal JSON for %#v", v)
	}

	if string(w) != string(j) {
		t.Errorf("json.Marshal(%q) returned %s, want %s", v, j, w)
	}
}

func testAddOptions(t *testing.T, url string, v interface{}, want string) {
	t.Helper()

	u, err := addOptions(url, v)
	if err != nil {
		t.Errorf("Unable to add %#v as query parameters", v)
	}

	if u != want {
		t.Errorf("addOptions(%q, %#v) returned %s, want %s", url, v, u, want)
	}
}

// Test how bad options are handled. Method f under test should
// return an error.
func testBadOptions(t *testing.T, methodName string, f func() error) {
	t.Helper()
	if methodName == "" {
		t.Error("testBadOptions: must supply method methodName")
	}
	if err := f(); err == nil {
		t.Errorf("bad options %v err = nil, want error", methodName)
	}
}

// Test function under NewRequest failure and then s.client.Do failure.
// Method f should be a regular call that would normally succeed, but
// should return an error when NewRequest or s.client.Do fails.
func testNewRequestAndDoFailure(t *testing.T, methodName string, client *Client, f func() (*Response, error)) {
	testNewRequestAndDoFailureCategory(t, methodName, client, coreCategory, f)
}

// testNewRequestAndDoFailureCategory works Like testNewRequestAndDoFailure, but allows setting the category
func testNewRequestAndDoFailureCategory(t *testing.T, methodName string, client *Client, category rateLimitCategory, f func() (*Response, error)) {
	t.Helper()

Review comment (suggestion):
```suggestion
		t.Errorf("addOptions(%q, %#v) returned %v, want %v", url, v, got, want)
```

Code after:
	w, err := json.Marshal(u)
	if err != nil {
		t.Errorf("Unable to marshal JSON for %#v", u)
	}

	// Marshal the target value.
	j, err := json.Marshal(v)
	if err != nil {
		t.Errorf("Unable to marshal JSON for %#v", v)
	}

	if string(w) != string(j) {
		t.Errorf("json.Marshal(%q) returned %s, want %s", v, j, w)
	}
}

// Test whether the v fields have the url tag and the parsing of v
// produces query parameters that corresponds to the want string.
func testAddURLOptions(t *testing.T, url string, v interface{}, want string) {
	t.Helper()

	vt := reflect.Indirect(reflect.ValueOf(v)).Type()
	for i := 0; i < vt.NumField(); i++ {
		field := vt.Field(i)
		if alias, ok := field.Tag.Lookup("url"); ok {
			if alias == "" {
				t.Errorf("The field %+v has a blank url tag", field)
			}
		} else {
			t.Errorf("The field %+v has no url tag specified", field)
		}
	}

	got, err := addOptions(url, v)
	if err != nil {
		t.Errorf("Unable to add %#v as query parameters", v)
	}

	if got != want {
		t.Errorf("addOptions(%q, %#v) returned %v, want %v", url, v, got, want)
	}
}

// Test how bad options are handled. Method f under test should
// return an error.
func testBadOptions(t *testing.T, methodName string, f func() error) {
	t.Helper()
	if methodName == "" {
		t.Error("testBadOptions: must supply method methodName")
	}
	if err := f(); err == nil {
Repository: google/go-github
File: github/timestamp.go (Go)

Code before:
// Copyright 2013 The go-github AUTHORS. All rights reserved.
//
// Use of this source code is governed by a BSD-style
// license that can be found in the LICENSE file.

package github

import (
	"strconv"
	"time"
)

// Timestamp represents a time that can be unmarshalled from a JSON string
// formatted as either an RFC3339 or Unix timestamp. This is necessary for some
// fields since the GitHub API is inconsistent in how it represents times. All
// exported methods of time.Time can be called on Timestamp.
type Timestamp struct {
	time.Time
}

func (t Timestamp) String() string {
	return t.Time.String()
}

// GetTime returns std time.Time
func (t *Timestamp) GetTime() *time.Time {
	if t == nil {
		return nil
	}
	return &t.Time
}

// UnmarshalJSON implements the json.Unmarshaler interface.
// Time is expected in RFC3339 or Unix format.
func (t *Timestamp) UnmarshalJSON(data []byte) (err error) {
	str := string(data)
	i, err := strconv.ParseInt(str, 10, 64)
	if err == nil {
		t.Time = time.Unix(i, 0)
		if t.Time.Year() > 3000 {
			t.Time = time.Unix(0, i*1e6)
		}
	} else {
		t.Time, err = time.Parse(`"`+time.RFC3339+`"`, str)
	}
	return
}

// Equal reports whether t and u are equal based on time.Equal
func (t Timestamp) Equal(u Timestamp) bool {

Review comment (suggestion):
```suggestion
// GetTime returns std time.Time.
```

Code after:
// Copyright 2013 The go-github AUTHORS. All rights reserved.
//
// Use of this source code is governed by a BSD-style
// license that can be found in the LICENSE file.

package github

import (
	"strconv"
	"time"
)

// Timestamp represents a time that can be unmarshalled from a JSON string
// formatted as either an RFC3339 or Unix timestamp. This is necessary for some
// fields since the GitHub API is inconsistent in how it represents times. All
// exported methods of time.Time can be called on Timestamp.
type Timestamp struct {
	time.Time
}

func (t Timestamp) String() string {
	return t.Time.String()
}

// GetTime returns std time.Time.
func (t *Timestamp) GetTime() *time.Time {
	if t == nil {
		return nil
	}
	return &t.Time
}

// UnmarshalJSON implements the json.Unmarshaler interface.
// Time is expected in RFC3339 or Unix format.
func (t *Timestamp) UnmarshalJSON(data []byte) (err error) {
	str := string(data)
	i, err := strconv.ParseInt(str, 10, 64)
	if err == nil {
		t.Time = time.Unix(i, 0)
		if t.Time.Year() > 3000 {
			t.Time = time.Unix(0, i*1e6)
		}
	} else {
		t.Time, err = time.Parse(`"`+time.RFC3339+`"`, str)
	}
	return
}

// Equal reports whether t and u are equal based on time.Equal
func (t Timestamp) Equal(u Timestamp) bool {
Repository: google/go-github
File: github/event_types.go (Go)

Code before:
}

// EditBase represents the change of a pull-request base branch.
type EditBase struct {
	Ref *EditRef `json:"ref,omitempty"`
	SHA *EditSHA `json:"sha,omitempty"`
}

// EditRef represents a ref change of a pull-request.
type EditRef struct {
	From *string `json:"from,omitempty"`
}

// EditRepo represents a change of repository name.
type EditRepo struct {
	Name *RepoName `json:"name,omitempty"`
}

// EditOwner represents a change of repository ownership.
type EditOwner struct {
	OwnerInfo *OwnerInfo `json:"from,omitempty"`
}

// OwnerInfo represents the account info of the owner of the repo (could be User or Organization but both are User structs).
type OwnerInfo struct {
	Actor *User `json:"user,omitempty"`
	Org   *User `json:"organization,omitempty"`
}

// RepoName represents a change of repository name.
type RepoName struct {
	From *string `json:"from,omitempty"`
}

// EditSHA represents a sha change of a pull-request.
type EditSHA struct {
	From *string `json:"from,omitempty"`
}

// ProjectChange represents the changes when a project has been edited.
type ProjectChange struct {
	Name *ProjectName `json:"name,omitempty"`
	Body *ProjectBody `json:"body,omitempty"`
}

// ProjectName represents a project name change.
type ProjectName struct {
	From *string `json:"from,omitempty"`
}

// ProjectBody represents a project body change.

Review comment (suggestion):
I think the following would be less confusing or at least more consistent.

```suggestion
	User *User `json:"user,omitempty"`
```

Code after:
}

// EditBase represents the change of a pull-request base branch.
type EditBase struct {
	Ref *EditRef `json:"ref,omitempty"`
	SHA *EditSHA `json:"sha,omitempty"`
}

// EditRef represents a ref change of a pull-request.
type EditRef struct {
	From *string `json:"from,omitempty"`
}

// EditRepo represents a change of repository name.
type EditRepo struct {
	Name *RepoName `json:"name,omitempty"`
}

// EditOwner represents a change of repository ownership.
type EditOwner struct {
	OwnerInfo *OwnerInfo `json:"from,omitempty"`
}

// OwnerInfo represents the account info of the owner of the repo (could be User or Organization but both are User structs).
type OwnerInfo struct {
	User *User `json:"user,omitempty"`
	Org  *User `json:"organization,omitempty"`
}

// RepoName represents a change of repository name.
type RepoName struct {
	From *string `json:"from,omitempty"`
}

// EditSHA represents a sha change of a pull-request.
type EditSHA struct {
	From *string `json:"from,omitempty"`
}

// ProjectChange represents the changes when a project has been edited.
type ProjectChange struct {
	Name *ProjectName `json:"name,omitempty"`
	Body *ProjectBody `json:"body,omitempty"`
}

// ProjectName represents a project name change.
type ProjectName struct {
	From *string `json:"from,omitempty"`
}

// ProjectBody represents a project body change.
Repository: google/go-github
File: github/orgs_rules_test.go (Go)

Code before:
		Target:      String("branch"),
		SourceType:  String("Organization"),
		Source:      "o",
		Enforcement: "active",
		BypassMode:  String("none"),
		NodeID:      String("nid"),
		Links: &RulesetLinks{
			Self: &RulesetLink{HRef: String("https://api.github.com/orgs/o/rulesets/26110")},
		},
	}}
	if !cmp.Equal(rulesets, want) {
		t.Errorf("Organizations.GetAllOrganizationRulesets returned %+v, want %+v", rulesets, want)
	}

	const methodName = "GetAllOrganizationRulesets"

	testNewRequestAndDoFailure(t, methodName, client, func() (*Response, error) {
		got, resp, err := client.Organizations.GetAllOrganizationRulesets(ctx, "o")
		if got != nil {
			t.Errorf("testNewRequestAndDoFailure %v = %#v, want nil", methodName, got)
		}
		return resp, err
	})
}

func TestOrganizationsService_CreateOrganizationRulesetRepoNames(t *testing.T) {
	client, mux, _, teardown := setup()
	defer teardown()

	mux.HandleFunc("/orgs/o/rulesets", func(w http.ResponseWriter, r *http.Request) {
		testMethod(t, r, "POST")
		fmt.Fprint(w, `{
			"id": 21,
			"name": "ruleset",
			"target": "branch",
			"source_type": "Organization",
			"source": "o",
			"enforcement": "active",
			"bypass_actors": [
			  {
				"actor_id": 234,
				"actor_type": "Team"
			  }
			],
			"conditions": {
			  "ref_name": {
				"include": [
				  "refs/heads/main",
				  "refs/heads/master"
				],
				"exclude": [

Review comment (suggestion):
```suggestion
func TestOrganizationsService_CreateOrganizationRuleset_RepoNames(t *testing.T) {
```

Code after:
		Target:      String("branch"),
		SourceType:  String("Organization"),
		Source:      "o",
		Enforcement: "active",
		BypassMode:  String("none"),
		NodeID:      String("nid"),
		Links: &RulesetLinks{
			Self: &RulesetLink{HRef: String("https://api.github.com/orgs/o/rulesets/26110")},
		},
	}}
	if !cmp.Equal(rulesets, want) {
		t.Errorf("Organizations.GetAllOrganizationRulesets returned %+v, want %+v", rulesets, want)
	}

	const methodName = "GetAllOrganizationRulesets"

	testNewRequestAndDoFailure(t, methodName, client, func() (*Response, error) {
		got, resp, err := client.Organizations.GetAllOrganizationRulesets(ctx, "o")
		if got != nil {
			t.Errorf("testNewRequestAndDoFailure %v = %#v, want nil", methodName, got)
		}
		return resp, err
	})
}

func TestOrganizationsService_CreateOrganizationRuleset_RepoNames(t *testing.T) {
	client, mux, _, teardown := setup()
	defer teardown()

	mux.HandleFunc("/orgs/o/rulesets", func(w http.ResponseWriter, r *http.Request) {
		testMethod(t, r, "POST")
		fmt.Fprint(w, `{
			"id": 21,
			"name": "ruleset",
			"target": "branch",
			"source_type": "Organization",
			"source": "o",
			"enforcement": "active",
			"bypass_actors": [
			  {
				"actor_id": 234,
				"actor_type": "Team"
			  }
			],
			"conditions": {
			  "ref_name": {
				"include": [
				  "refs/heads/main",
				  "refs/heads/master"
				],
				"exclude": [
Repository: google/go-github
File: github/orgs_rules_test.go (Go)

Code before:
				Pattern:  "github$",
			}),
			NewTagNamePatternRule(&RulePatternParameters{
				Name:     String("avoid tag names"),
				Negate:   Bool(true),
				Operator: "contains",
				Pattern:  "github",
			}),
		},
	}
	if !cmp.Equal(ruleset, want) {
		t.Errorf("Organizations.CreateOrganizationRuleset returned %+v, want %+v", ruleset, want)
	}

	const methodName = "CreateOrganizationRuleset"

	testNewRequestAndDoFailure(t, methodName, client, func() (*Response, error) {
		got, resp, err := client.Organizations.CreateOrganizationRuleset(ctx, "o", nil)
		if got != nil {
			t.Errorf("testNewRequestAndDoFailure %v = %#v, want nil", methodName, got)
		}
		return resp, err
	})
}

func TestOrganizationsService_CreateOrganizationRulesetRepoIds(t *testing.T) {
	client, mux, _, teardown := setup()
	defer teardown()

	mux.HandleFunc("/orgs/o/rulesets", func(w http.ResponseWriter, r *http.Request) {
		testMethod(t, r, "POST")
		fmt.Fprint(w, `{
			"id": 21,
			"name": "ruleset",
			"target": "branch",
			"source_type": "Organization",
			"source": "o",
			"enforcement": "active",
			"bypass_actors": [
			  {
				"actor_id": 234,
				"actor_type": "Team"
			  }
			],
			"conditions": {
			  "ref_name": {
				"include": [
				  "refs/heads/main",
				  "refs/heads/master"
				],
				"exclude": [

Review comment (suggestion):
```suggestion
func TestOrganizationsService_CreateOrganizationRuleset_RepoIDs(t *testing.T) {
```

Code after:
				Pattern:  "github$",
			}),
			NewTagNamePatternRule(&RulePatternParameters{
				Name:     String("avoid tag names"),
				Negate:   Bool(true),
				Operator: "contains",
				Pattern:  "github",
			}),
		},
	}
	if !cmp.Equal(ruleset, want) {
		t.Errorf("Organizations.CreateOrganizationRuleset returned %+v, want %+v", ruleset, want)
	}

	const methodName = "CreateOrganizationRuleset"

	testNewRequestAndDoFailure(t, methodName, client, func() (*Response, error) {
		got, resp, err := client.Organizations.CreateOrganizationRuleset(ctx, "o", nil)
		if got != nil {
			t.Errorf("testNewRequestAndDoFailure %v = %#v, want nil", methodName, got)
		}
		return resp, err
	})
}

func TestOrganizationsService_CreateOrganizationRuleset_RepoIDs(t *testing.T) {
	client, mux, _, teardown := setup()
	defer teardown()

	mux.HandleFunc("/orgs/o/rulesets", func(w http.ResponseWriter, r *http.Request) {
		testMethod(t, r, "POST")
		fmt.Fprint(w, `{
			"id": 21,
			"name": "ruleset",
			"target": "branch",
			"source_type": "Organization",
			"source": "o",
			"enforcement": "active",
			"bypass_actors": [
			  {
				"actor_id": 234,
				"actor_type": "Team"
			  }
			],
			"conditions": {
			  "ref_name": {
				"include": [
				  "refs/heads/main",
				  "refs/heads/master"
				],
				"exclude": [
Repository: google/go-github
File: github/orgs_personal_access_tokens.go (Go)

Code before:
package github

import (
	"context"
	"fmt"
	"net/http"
)

// Approves or denies a pending request to access organization resources via a fine-grained personal access token.
// Only GitHub Apps can call this API, using the `organization_personal_access_token_requests: write` permission.
// `action` can be one of `approve` or `deny`.
//
// GitHub API docs: https://docs.github.com/en/rest/orgs/personal-access-tokens?apiVersion=2022-11-28#review-a-request-to-access-organization-resources-with-a-fine-grained-personal-access-token
func (s *OrganizationsService) ReviewPersonalAccessTokenRequest(ctx context.Context, org, requestID, action, reason string) (*Response, error) {
	u := fmt.Sprintf("orgs/%v/personal-access-token-requests/%v", org, requestID)
	body := struct {
		Action string `json:"action"`
		Reason string `json:"reason,omitempty"`
	}{
		Action: action,
		Reason: reason,
	}

	req, err := s.client.NewRequest(http.MethodPost, u, &body)
	if err != nil {
		return nil, err
	}

	return s.client.Do(ctx, req, nil)
}


Review comment (security):
```suggestion
// Copyright 2023 The go-github AUTHORS. All rights reserved.
//
// Use of this source code is governed by a BSD-style
// license that can be found in the LICENSE file.

package github
```

Code after:
// Copyright 2023 The go-github AUTHORS. All rights reserved.
//
// Use of this source code is governed by a BSD-style
// license that can be found in the LICENSE file.

package github

import (
	"context"
	"fmt"
	"net/http"
)

// ReviewPersonalAccessTokenRequestOptions specifies the parameters to the ReviewPersonalAccessTokenRequest method.
type ReviewPersonalAccessTokenRequestOptions struct {
	Action string  `json:"action"`
	Reason *string `json:"reason,omitempty"`
}

// ReviewPersonalAccessTokenRequest approves or denies a pending request to access organization resources via a fine-grained personal access token.
// Only GitHub Apps can call this API, using the `organization_personal_access_token_requests: write` permission.
// `action` can be one of `approve` or `deny`.
//
// GitHub API docs: https://docs.github.com/en/rest/orgs/personal-access-tokens?apiVersion=2022-11-28#review-a-request-to-access-organization-resources-with-a-fine-grained-personal-access-token
func (s *OrganizationsService) ReviewPersonalAccessTokenRequest(ctx context.Context, org string, requestID int64, opts ReviewPersonalAccessTokenRequestOptions) (*Response, error) {
	u := fmt.Sprintf("orgs/%v/personal-access-token-requests/%v", org, requestID)

	req, err := s.client.NewRequest(http.MethodPost, u, &opts)
	if err != nil {
		return nil, err
	}
Repository: google/go-github
File: github/orgs_personal_access_tokens_test.go (Go)

Code before:
package github

import (
	"context"
	"encoding/json"
	"net/http"
	"testing"

	"github.com/google/go-cmp/cmp"
)

func TestOrganizationsService_ReviewPersonalAccessTokenRequest(t *testing.T) {
	type body struct {
		Action string `json:"action"`
		Reason string `json:"reason,omitempty"`
	}

	client, mux, _, teardown := setup()
	defer teardown()

	input := &body{
		Action: "a",
		Reason: "r",
	}

	mux.HandleFunc("/orgs/o/personal-access-token-requests/r", func(w http.ResponseWriter, r *http.Request) {
		v := new(body)
		json.NewDecoder(r.Body).Decode(v)

		testMethod(t, r, http.MethodPost)
		if !cmp.Equal(v, input) {

Review comment (security):
```suggestion
// Copyright 2023 The go-github AUTHORS. All rights reserved.
//
// Use of this source code is governed by a BSD-style
// license that can be found in the LICENSE file.

package github
```

Code after:
// Copyright 2023 The go-github AUTHORS. All rights reserved.
//
// Use of this source code is governed by a BSD-style
// license that can be found in the LICENSE file.

package github

import (
	"context"
	"encoding/json"
	"net/http"
	"testing"

	"github.com/google/go-cmp/cmp"
)

func TestOrganizationsService_ReviewPersonalAccessTokenRequest(t *testing.T) {
	client, mux, _, teardown := setup()
	defer teardown()

	input := ReviewPersonalAccessTokenRequestOptions{
		Action: "a",
		Reason: String("r"),
	}

	mux.HandleFunc("/orgs/o/personal-access-token-requests/1", func(w http.ResponseWriter, r *http.Request) {
		v := new(ReviewPersonalAccessTokenRequestOptions)
		json.NewDecoder(r.Body).Decode(v)

		testMethod(t, r, http.MethodPost)
		if !cmp.Equal(v, &input) {