Use int64 for GitHub database IDs and add lint check
Change all struct fields representing GitHub database IDs from int to int64 to match the API spec and prevent potential overflow on 32-bit architectures. Add a custom go/analysis linter (idtype-checker) that flags struct fields with ID-like names or JSON tags using int instead of int64, integrated into make lint. Closes #9247 Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
This commit is contained in:
parent
1e6bb88c6d
commit
d4cd79e28c
24 changed files with 272 additions and 58 deletions
|
|
@ -76,10 +76,10 @@ type apiClient interface {
|
|||
CreateCodespace(ctx context.Context, params *api.CreateCodespaceParams) (*api.Codespace, error)
|
||||
EditCodespace(ctx context.Context, codespaceName string, params *api.EditCodespaceParams) (*api.Codespace, error)
|
||||
GetRepository(ctx context.Context, nwo string) (*api.Repository, error)
|
||||
GetCodespacesMachines(ctx context.Context, repoID int, branch string, location string, devcontainerPath string) ([]*api.Machine, error)
|
||||
GetCodespacesPermissionsCheck(ctx context.Context, repoID int, branch string, devcontainerPath string) (bool, error)
|
||||
GetCodespacesMachines(ctx context.Context, repoID int64, branch string, location string, devcontainerPath string) ([]*api.Machine, error)
|
||||
GetCodespacesPermissionsCheck(ctx context.Context, repoID int64, branch string, devcontainerPath string) (bool, error)
|
||||
GetCodespaceRepositoryContents(ctx context.Context, codespace *api.Codespace, path string) ([]byte, error)
|
||||
ListDevContainers(ctx context.Context, repoID int, branch string, limit int) (devcontainers []api.DevContainerEntry, err error)
|
||||
ListDevContainers(ctx context.Context, repoID int64, branch string, limit int) (devcontainers []api.DevContainerEntry, err error)
|
||||
GetCodespaceRepoSuggestions(ctx context.Context, partialSearch string, params api.RepoSearchParameters) ([]string, error)
|
||||
GetCodespaceBillableOwner(ctx context.Context, nwo string) (*api.User, error)
|
||||
HTTPClient() (*http.Client, error)
|
||||
|
|
|
|||
|
|
@ -511,7 +511,7 @@ func (a *App) showStatus(ctx context.Context, codespace *api.Codespace) error {
|
|||
}
|
||||
|
||||
// getMachineName prompts the user to select the machine type, or validates the machine if non-empty.
|
||||
func getMachineName(ctx context.Context, apiClient apiClient, prompter SurveyPrompter, repoID int, machine, branch, location string, devcontainerPath string) (string, error) {
|
||||
func getMachineName(ctx context.Context, apiClient apiClient, prompter SurveyPrompter, repoID int64, machine, branch, location string, devcontainerPath string) (string, error) {
|
||||
machines, err := apiClient.GetCodespacesMachines(ctx, repoID, branch, location, devcontainerPath)
|
||||
if err != nil {
|
||||
return "", fmt.Errorf("error requesting machine instance types: %w", err)
|
||||
|
|
|
|||
|
|
@ -164,7 +164,7 @@ func TestApp_Create(t *testing.T) {
|
|||
name: "create codespace with nonexistent machine results in error",
|
||||
fields: fields{
|
||||
apiClient: apiCreateDefaults(&apiClientMock{
|
||||
GetCodespacesMachinesFunc: func(ctx context.Context, repoID int, branch, location string, devcontainerPath string) ([]*api.Machine, error) {
|
||||
GetCodespacesMachinesFunc: func(ctx context.Context, repoID int64, branch, location string, devcontainerPath string) ([]*api.Machine, error) {
|
||||
return []*api.Machine{
|
||||
{
|
||||
Name: "GIGA",
|
||||
|
|
@ -208,7 +208,7 @@ func TestApp_Create(t *testing.T) {
|
|||
name: "create codespace with devcontainer path results in selecting the correct machine type",
|
||||
fields: fields{
|
||||
apiClient: apiCreateDefaults(&apiClientMock{
|
||||
GetCodespacesMachinesFunc: func(ctx context.Context, repoID int, branch, location string, devcontainerPath string) ([]*api.Machine, error) {
|
||||
GetCodespacesMachinesFunc: func(ctx context.Context, repoID int64, branch, location string, devcontainerPath string) ([]*api.Machine, error) {
|
||||
if devcontainerPath == "" {
|
||||
return []*api.Machine{
|
||||
{
|
||||
|
|
@ -270,7 +270,7 @@ func TestApp_Create(t *testing.T) {
|
|||
name: "create codespace with default branch with default devcontainer if no path provided and no devcontainer files exist in the repo",
|
||||
fields: fields{
|
||||
apiClient: apiCreateDefaults(&apiClientMock{
|
||||
ListDevContainersFunc: func(ctx context.Context, repoID int, branch string, limit int) ([]api.DevContainerEntry, error) {
|
||||
ListDevContainersFunc: func(ctx context.Context, repoID int64, branch string, limit int) ([]api.DevContainerEntry, error) {
|
||||
return []api.DevContainerEntry{}, nil
|
||||
},
|
||||
CreateCodespaceFunc: func(ctx context.Context, params *api.CreateCodespaceParams) (*api.Codespace, error) {
|
||||
|
|
@ -305,7 +305,7 @@ func TestApp_Create(t *testing.T) {
|
|||
name: "returns error when getting devcontainer paths fails",
|
||||
fields: fields{
|
||||
apiClient: apiCreateDefaults(&apiClientMock{
|
||||
ListDevContainersFunc: func(ctx context.Context, repoID int, branch string, limit int) ([]api.DevContainerEntry, error) {
|
||||
ListDevContainersFunc: func(ctx context.Context, repoID int64, branch string, limit int) ([]api.DevContainerEntry, error) {
|
||||
return nil, fmt.Errorf("some error")
|
||||
},
|
||||
}),
|
||||
|
|
@ -793,7 +793,7 @@ func TestHandleAdditionalPermissions(t *testing.T) {
|
|||
CreateCodespaceFunc: func(ctx context.Context, params *api.CreateCodespaceParams) (*api.Codespace, error) {
|
||||
return nil, tt.createCodespaceErr
|
||||
},
|
||||
GetCodespacesPermissionsCheckFunc: func(ctx context.Context, repoID int, branch string, devcontainerPath string) (bool, error) {
|
||||
GetCodespacesPermissionsCheckFunc: func(ctx context.Context, repoID int64, branch string, devcontainerPath string) (bool, error) {
|
||||
if tt.pollForPermissionsErr != nil {
|
||||
return false, tt.pollForPermissionsErr
|
||||
}
|
||||
|
|
@ -844,12 +844,12 @@ func apiCreateDefaults(c *apiClientMock) *apiClientMock {
|
|||
}
|
||||
}
|
||||
if c.ListDevContainersFunc == nil {
|
||||
c.ListDevContainersFunc = func(ctx context.Context, repoID int, branch string, limit int) ([]api.DevContainerEntry, error) {
|
||||
c.ListDevContainersFunc = func(ctx context.Context, repoID int64, branch string, limit int) ([]api.DevContainerEntry, error) {
|
||||
return []api.DevContainerEntry{{Path: ".devcontainer/devcontainer.json"}}, nil
|
||||
}
|
||||
}
|
||||
if c.GetCodespacesMachinesFunc == nil {
|
||||
c.GetCodespacesMachinesFunc = func(ctx context.Context, repoID int, branch, location string, devcontainerPath string) ([]*api.Machine, error) {
|
||||
c.GetCodespacesMachinesFunc = func(ctx context.Context, repoID int64, branch, location string, devcontainerPath string) ([]*api.Machine, error) {
|
||||
return []*api.Machine{
|
||||
{
|
||||
Name: "GIGA",
|
||||
|
|
|
|||
|
|
@ -38,10 +38,10 @@ import (
|
|||
// GetCodespaceRepositoryContentsFunc: func(ctx context.Context, codespace *codespacesAPI.Codespace, path string) ([]byte, error) {
|
||||
// panic("mock out the GetCodespaceRepositoryContents method")
|
||||
// },
|
||||
// GetCodespacesMachinesFunc: func(ctx context.Context, repoID int, branch string, location string, devcontainerPath string) ([]*codespacesAPI.Machine, error) {
|
||||
// GetCodespacesMachinesFunc: func(ctx context.Context, repoID int64, branch string, location string, devcontainerPath string) ([]*codespacesAPI.Machine, error) {
|
||||
// panic("mock out the GetCodespacesMachines method")
|
||||
// },
|
||||
// GetCodespacesPermissionsCheckFunc: func(ctx context.Context, repoID int, branch string, devcontainerPath string) (bool, error) {
|
||||
// GetCodespacesPermissionsCheckFunc: func(ctx context.Context, repoID int64, branch string, devcontainerPath string) (bool, error) {
|
||||
// panic("mock out the GetCodespacesPermissionsCheck method")
|
||||
// },
|
||||
// GetOrgMemberCodespaceFunc: func(ctx context.Context, orgName string, userName string, codespaceName string) (*codespacesAPI.Codespace, error) {
|
||||
|
|
@ -59,7 +59,7 @@ import (
|
|||
// ListCodespacesFunc: func(ctx context.Context, opts codespacesAPI.ListCodespacesOptions) ([]*codespacesAPI.Codespace, error) {
|
||||
// panic("mock out the ListCodespaces method")
|
||||
// },
|
||||
// ListDevContainersFunc: func(ctx context.Context, repoID int, branch string, limit int) ([]codespacesAPI.DevContainerEntry, error) {
|
||||
// ListDevContainersFunc: func(ctx context.Context, repoID int64, branch string, limit int) ([]codespacesAPI.DevContainerEntry, error) {
|
||||
// panic("mock out the ListDevContainers method")
|
||||
// },
|
||||
// ServerURLFunc: func() string {
|
||||
|
|
@ -100,10 +100,10 @@ type apiClientMock struct {
|
|||
GetCodespaceRepositoryContentsFunc func(ctx context.Context, codespace *codespacesAPI.Codespace, path string) ([]byte, error)
|
||||
|
||||
// GetCodespacesMachinesFunc mocks the GetCodespacesMachines method.
|
||||
GetCodespacesMachinesFunc func(ctx context.Context, repoID int, branch string, location string, devcontainerPath string) ([]*codespacesAPI.Machine, error)
|
||||
GetCodespacesMachinesFunc func(ctx context.Context, repoID int64, branch string, location string, devcontainerPath string) ([]*codespacesAPI.Machine, error)
|
||||
|
||||
// GetCodespacesPermissionsCheckFunc mocks the GetCodespacesPermissionsCheck method.
|
||||
GetCodespacesPermissionsCheckFunc func(ctx context.Context, repoID int, branch string, devcontainerPath string) (bool, error)
|
||||
GetCodespacesPermissionsCheckFunc func(ctx context.Context, repoID int64, branch string, devcontainerPath string) (bool, error)
|
||||
|
||||
// GetOrgMemberCodespaceFunc mocks the GetOrgMemberCodespace method.
|
||||
GetOrgMemberCodespaceFunc func(ctx context.Context, orgName string, userName string, codespaceName string) (*codespacesAPI.Codespace, error)
|
||||
|
|
@ -121,7 +121,7 @@ type apiClientMock struct {
|
|||
ListCodespacesFunc func(ctx context.Context, opts codespacesAPI.ListCodespacesOptions) ([]*codespacesAPI.Codespace, error)
|
||||
|
||||
// ListDevContainersFunc mocks the ListDevContainers method.
|
||||
ListDevContainersFunc func(ctx context.Context, repoID int, branch string, limit int) ([]codespacesAPI.DevContainerEntry, error)
|
||||
ListDevContainersFunc func(ctx context.Context, repoID int64, branch string, limit int) ([]codespacesAPI.DevContainerEntry, error)
|
||||
|
||||
// ServerURLFunc mocks the ServerURL method.
|
||||
ServerURLFunc func() string
|
||||
|
|
@ -200,7 +200,7 @@ type apiClientMock struct {
|
|||
// Ctx is the ctx argument value.
|
||||
Ctx context.Context
|
||||
// RepoID is the repoID argument value.
|
||||
RepoID int
|
||||
RepoID int64
|
||||
// Branch is the branch argument value.
|
||||
Branch string
|
||||
// Location is the location argument value.
|
||||
|
|
@ -213,7 +213,7 @@ type apiClientMock struct {
|
|||
// Ctx is the ctx argument value.
|
||||
Ctx context.Context
|
||||
// RepoID is the repoID argument value.
|
||||
RepoID int
|
||||
RepoID int64
|
||||
// Branch is the branch argument value.
|
||||
Branch string
|
||||
// DevcontainerPath is the devcontainerPath argument value.
|
||||
|
|
@ -257,7 +257,7 @@ type apiClientMock struct {
|
|||
// Ctx is the ctx argument value.
|
||||
Ctx context.Context
|
||||
// RepoID is the repoID argument value.
|
||||
RepoID int
|
||||
RepoID int64
|
||||
// Branch is the branch argument value.
|
||||
Branch string
|
||||
// Limit is the limit argument value.
|
||||
|
|
@ -582,13 +582,13 @@ func (mock *apiClientMock) GetCodespaceRepositoryContentsCalls() []struct {
|
|||
}
|
||||
|
||||
// GetCodespacesMachines calls GetCodespacesMachinesFunc.
|
||||
func (mock *apiClientMock) GetCodespacesMachines(ctx context.Context, repoID int, branch string, location string, devcontainerPath string) ([]*codespacesAPI.Machine, error) {
|
||||
func (mock *apiClientMock) GetCodespacesMachines(ctx context.Context, repoID int64, branch string, location string, devcontainerPath string) ([]*codespacesAPI.Machine, error) {
|
||||
if mock.GetCodespacesMachinesFunc == nil {
|
||||
panic("apiClientMock.GetCodespacesMachinesFunc: method is nil but apiClient.GetCodespacesMachines was just called")
|
||||
}
|
||||
callInfo := struct {
|
||||
Ctx context.Context
|
||||
RepoID int
|
||||
RepoID int64
|
||||
Branch string
|
||||
Location string
|
||||
DevcontainerPath string
|
||||
|
|
@ -611,14 +611,14 @@ func (mock *apiClientMock) GetCodespacesMachines(ctx context.Context, repoID int
|
|||
// len(mockedapiClient.GetCodespacesMachinesCalls())
|
||||
func (mock *apiClientMock) GetCodespacesMachinesCalls() []struct {
|
||||
Ctx context.Context
|
||||
RepoID int
|
||||
RepoID int64
|
||||
Branch string
|
||||
Location string
|
||||
DevcontainerPath string
|
||||
} {
|
||||
var calls []struct {
|
||||
Ctx context.Context
|
||||
RepoID int
|
||||
RepoID int64
|
||||
Branch string
|
||||
Location string
|
||||
DevcontainerPath string
|
||||
|
|
@ -630,13 +630,13 @@ func (mock *apiClientMock) GetCodespacesMachinesCalls() []struct {
|
|||
}
|
||||
|
||||
// GetCodespacesPermissionsCheck calls GetCodespacesPermissionsCheckFunc.
|
||||
func (mock *apiClientMock) GetCodespacesPermissionsCheck(ctx context.Context, repoID int, branch string, devcontainerPath string) (bool, error) {
|
||||
func (mock *apiClientMock) GetCodespacesPermissionsCheck(ctx context.Context, repoID int64, branch string, devcontainerPath string) (bool, error) {
|
||||
if mock.GetCodespacesPermissionsCheckFunc == nil {
|
||||
panic("apiClientMock.GetCodespacesPermissionsCheckFunc: method is nil but apiClient.GetCodespacesPermissionsCheck was just called")
|
||||
}
|
||||
callInfo := struct {
|
||||
Ctx context.Context
|
||||
RepoID int
|
||||
RepoID int64
|
||||
Branch string
|
||||
DevcontainerPath string
|
||||
}{
|
||||
|
|
@ -657,13 +657,13 @@ func (mock *apiClientMock) GetCodespacesPermissionsCheck(ctx context.Context, re
|
|||
// len(mockedapiClient.GetCodespacesPermissionsCheckCalls())
|
||||
func (mock *apiClientMock) GetCodespacesPermissionsCheckCalls() []struct {
|
||||
Ctx context.Context
|
||||
RepoID int
|
||||
RepoID int64
|
||||
Branch string
|
||||
DevcontainerPath string
|
||||
} {
|
||||
var calls []struct {
|
||||
Ctx context.Context
|
||||
RepoID int
|
||||
RepoID int64
|
||||
Branch string
|
||||
DevcontainerPath string
|
||||
}
|
||||
|
|
@ -849,13 +849,13 @@ func (mock *apiClientMock) ListCodespacesCalls() []struct {
|
|||
}
|
||||
|
||||
// ListDevContainers calls ListDevContainersFunc.
|
||||
func (mock *apiClientMock) ListDevContainers(ctx context.Context, repoID int, branch string, limit int) ([]codespacesAPI.DevContainerEntry, error) {
|
||||
func (mock *apiClientMock) ListDevContainers(ctx context.Context, repoID int64, branch string, limit int) ([]codespacesAPI.DevContainerEntry, error) {
|
||||
if mock.ListDevContainersFunc == nil {
|
||||
panic("apiClientMock.ListDevContainersFunc: method is nil but apiClient.ListDevContainers was just called")
|
||||
}
|
||||
callInfo := struct {
|
||||
Ctx context.Context
|
||||
RepoID int
|
||||
RepoID int64
|
||||
Branch string
|
||||
Limit int
|
||||
}{
|
||||
|
|
@ -876,13 +876,13 @@ func (mock *apiClientMock) ListDevContainers(ctx context.Context, repoID int, br
|
|||
// len(mockedapiClient.ListDevContainersCalls())
|
||||
func (mock *apiClientMock) ListDevContainersCalls() []struct {
|
||||
Ctx context.Context
|
||||
RepoID int
|
||||
RepoID int64
|
||||
Branch string
|
||||
Limit int
|
||||
} {
|
||||
var calls []struct {
|
||||
Ctx context.Context
|
||||
RepoID int
|
||||
RepoID int64
|
||||
Branch string
|
||||
Limit int
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue