Skip to content

Commit 0274077

Browse files
Use int64 for GitHub database IDs (cli#13403)
Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
1 parent f4a29a3 commit 0274077

19 files changed

Lines changed: 61 additions & 61 deletions

File tree

internal/codespaces/api/api.go

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -152,7 +152,7 @@ type RepositoryOwner struct {
152152

153153
// Repository represents a GitHub repository.
154154
type Repository struct {
155-
ID int `json:"id"`
155+
ID int64 `json:"id"`
156156
FullName string `json:"full_name"`
157157
DefaultBranch string `json:"default_branch"`
158158
Owner RepositoryOwner `json:"owner"`
@@ -604,7 +604,7 @@ type Machine struct {
604604
}
605605

606606
// GetCodespacesMachines returns the codespaces machines for the given repo, branch and location.
607-
func (a *API) GetCodespacesMachines(ctx context.Context, repoID int, branch, location string, devcontainerPath string) ([]*Machine, error) {
607+
func (a *API) GetCodespacesMachines(ctx context.Context, repoID int64, branch, location string, devcontainerPath string) ([]*Machine, error) {
608608
reqURL := fmt.Sprintf("%s/repositories/%d/codespaces/machines", a.githubAPI, repoID)
609609
req, err := http.NewRequest(http.MethodGet, reqURL, nil)
610610
if err != nil {
@@ -644,7 +644,7 @@ func (a *API) GetCodespacesMachines(ctx context.Context, repoID int, branch, loc
644644
}
645645

646646
// GetCodespacesPermissionsCheck returns a bool indicating whether the user has accepted permissions for the given repo and devcontainer path.
647-
func (a *API) GetCodespacesPermissionsCheck(ctx context.Context, repoID int, branch string, devcontainerPath string) (bool, error) {
647+
func (a *API) GetCodespacesPermissionsCheck(ctx context.Context, repoID int64, branch string, devcontainerPath string) (bool, error) {
648648
reqURL := fmt.Sprintf("%s/repositories/%d/codespaces/permissions_check", a.githubAPI, repoID)
649649
req, err := http.NewRequest(http.MethodGet, reqURL, nil)
650650
if err != nil {
@@ -806,7 +806,7 @@ func (a *API) GetCodespaceBillableOwner(ctx context.Context, nwo string) (*User,
806806

807807
// CreateCodespaceParams are the required parameters for provisioning a Codespace.
808808
type CreateCodespaceParams struct {
809-
RepositoryID int
809+
RepositoryID int64
810810
IdleTimeoutMinutes int
811811
RetentionPeriodMinutes *int
812812
Branch string
@@ -857,7 +857,7 @@ func (a *API) CreateCodespace(ctx context.Context, params *CreateCodespaceParams
857857
}
858858

859859
type startCreateRequest struct {
860-
RepositoryID int `json:"repository_id"`
860+
RepositoryID int64 `json:"repository_id"`
861861
IdleTimeoutMinutes int `json:"idle_timeout_minutes,omitempty"`
862862
RetentionPeriodMinutes *int `json:"retention_period_minutes,omitempty"`
863863
Ref string `json:"ref"`
@@ -1011,7 +1011,7 @@ type DevContainerEntry struct {
10111011

10121012
// ListDevContainers returns a list of valid devcontainer.json files for the repo. Pass a negative limit to request all pages from
10131013
// the API until all devcontainer.json files have been fetched.
1014-
func (a *API) ListDevContainers(ctx context.Context, repoID int, branch string, limit int) (devcontainers []DevContainerEntry, err error) {
1014+
func (a *API) ListDevContainers(ctx context.Context, repoID int64, branch string, limit int) (devcontainers []DevContainerEntry, err error) {
10151015
perPage := 100
10161016
if limit > 0 && limit < 100 {
10171017
perPage = limit

pkg/cmd/agent-task/capi/job.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -35,12 +35,12 @@ type Job struct {
3535
}
3636

3737
type JobActor struct {
38-
ID int `json:"id"`
38+
ID int64 `json:"id"`
3939
Login string `json:"login"`
4040
}
4141

4242
type JobPullRequest struct {
43-
ID int `json:"id"`
43+
ID int64 `json:"id"`
4444
Number int `json:"number"`
4545
BaseRef string `json:"base_ref,omitempty"`
4646
}

pkg/cmd/cache/delete/delete.go

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -147,7 +147,7 @@ func deleteRun(opts *DeleteOptions) error {
147147
}
148148
}
149149
for _, cache := range caches.ActionsCaches {
150-
toDelete = append(toDelete, strconv.Itoa(cache.Id))
150+
toDelete = append(toDelete, strconv.FormatInt(cache.Id, 10))
151151
}
152152
} else {
153153
toDelete = append(toDelete, opts.Identifier)
@@ -201,7 +201,7 @@ func deleteCaches(opts *DeleteOptions, client *api.Client, repo ghrepo.Interface
201201
return nil
202202
}
203203

204-
func deleteCacheByID(client *api.Client, repo ghrepo.Interface, id int) error {
204+
func deleteCacheByID(client *api.Client, repo ghrepo.Interface, id int64) error {
205205
// returns HTTP 204 (NO CONTENT) on success
206206
path := fmt.Sprintf("repos/%s/actions/caches/%d", ghrepo.FullName(repo), id)
207207
return client.REST(repo.RepoHost(), "DELETE", path, nil, nil)
@@ -227,7 +227,7 @@ func deleteCacheByKey(client *api.Client, repo ghrepo.Interface, key, ref string
227227
return payload.TotalCount, nil
228228
}
229229

230-
func parseCacheID(arg string) (int, bool) {
231-
id, err := strconv.Atoi(arg)
230+
func parseCacheID(arg string) (int64, bool) {
231+
id, err := strconv.ParseInt(arg, 10, 64)
232232
return id, err == nil
233233
}

pkg/cmd/cache/shared/shared.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ var CacheFields = []string{
2222

2323
type Cache struct {
2424
CreatedAt time.Time `json:"created_at"`
25-
Id int `json:"id"`
25+
Id int64 `json:"id"`
2626
Key string `json:"key"`
2727
LastAccessedAt time.Time `json:"last_accessed_at"`
2828
Ref string `json:"ref"`

pkg/cmd/codespace/common.go

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -76,10 +76,10 @@ type apiClient interface {
7676
CreateCodespace(ctx context.Context, params *api.CreateCodespaceParams) (*api.Codespace, error)
7777
EditCodespace(ctx context.Context, codespaceName string, params *api.EditCodespaceParams) (*api.Codespace, error)
7878
GetRepository(ctx context.Context, nwo string) (*api.Repository, error)
79-
GetCodespacesMachines(ctx context.Context, repoID int, branch string, location string, devcontainerPath string) ([]*api.Machine, error)
80-
GetCodespacesPermissionsCheck(ctx context.Context, repoID int, branch string, devcontainerPath string) (bool, error)
79+
GetCodespacesMachines(ctx context.Context, repoID int64, branch string, location string, devcontainerPath string) ([]*api.Machine, error)
80+
GetCodespacesPermissionsCheck(ctx context.Context, repoID int64, branch string, devcontainerPath string) (bool, error)
8181
GetCodespaceRepositoryContents(ctx context.Context, codespace *api.Codespace, path string) ([]byte, error)
82-
ListDevContainers(ctx context.Context, repoID int, branch string, limit int) (devcontainers []api.DevContainerEntry, err error)
82+
ListDevContainers(ctx context.Context, repoID int64, branch string, limit int) (devcontainers []api.DevContainerEntry, err error)
8383
GetCodespaceRepoSuggestions(ctx context.Context, partialSearch string, params api.RepoSearchParameters) ([]string, error)
8484
GetCodespaceBillableOwner(ctx context.Context, nwo string) (*api.User, error)
8585
ExternalHTTPClient() (*http.Client, error)

pkg/cmd/codespace/create.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -511,7 +511,7 @@ func (a *App) showStatus(ctx context.Context, codespace *api.Codespace) error {
511511
}
512512

513513
// getMachineName prompts the user to select the machine type, or validates the machine if non-empty.
514-
func getMachineName(ctx context.Context, apiClient apiClient, prompter SurveyPrompter, repoID int, machine, branch, location string, devcontainerPath string) (string, error) {
514+
func getMachineName(ctx context.Context, apiClient apiClient, prompter SurveyPrompter, repoID int64, machine, branch, location string, devcontainerPath string) (string, error) {
515515
machines, err := apiClient.GetCodespacesMachines(ctx, repoID, branch, location, devcontainerPath)
516516
if err != nil {
517517
return "", fmt.Errorf("error requesting machine instance types: %w", err)

pkg/cmd/codespace/create_test.go

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -164,7 +164,7 @@ func TestApp_Create(t *testing.T) {
164164
name: "create codespace with nonexistent machine results in error",
165165
fields: fields{
166166
apiClient: apiCreateDefaults(&apiClientMock{
167-
GetCodespacesMachinesFunc: func(ctx context.Context, repoID int, branch, location string, devcontainerPath string) ([]*api.Machine, error) {
167+
GetCodespacesMachinesFunc: func(ctx context.Context, repoID int64, branch, location string, devcontainerPath string) ([]*api.Machine, error) {
168168
return []*api.Machine{
169169
{
170170
Name: "GIGA",
@@ -208,7 +208,7 @@ func TestApp_Create(t *testing.T) {
208208
name: "create codespace with devcontainer path results in selecting the correct machine type",
209209
fields: fields{
210210
apiClient: apiCreateDefaults(&apiClientMock{
211-
GetCodespacesMachinesFunc: func(ctx context.Context, repoID int, branch, location string, devcontainerPath string) ([]*api.Machine, error) {
211+
GetCodespacesMachinesFunc: func(ctx context.Context, repoID int64, branch, location string, devcontainerPath string) ([]*api.Machine, error) {
212212
if devcontainerPath == "" {
213213
return []*api.Machine{
214214
{
@@ -270,7 +270,7 @@ func TestApp_Create(t *testing.T) {
270270
name: "create codespace with default branch with default devcontainer if no path provided and no devcontainer files exist in the repo",
271271
fields: fields{
272272
apiClient: apiCreateDefaults(&apiClientMock{
273-
ListDevContainersFunc: func(ctx context.Context, repoID int, branch string, limit int) ([]api.DevContainerEntry, error) {
273+
ListDevContainersFunc: func(ctx context.Context, repoID int64, branch string, limit int) ([]api.DevContainerEntry, error) {
274274
return []api.DevContainerEntry{}, nil
275275
},
276276
CreateCodespaceFunc: func(ctx context.Context, params *api.CreateCodespaceParams) (*api.Codespace, error) {
@@ -305,7 +305,7 @@ func TestApp_Create(t *testing.T) {
305305
name: "returns error when getting devcontainer paths fails",
306306
fields: fields{
307307
apiClient: apiCreateDefaults(&apiClientMock{
308-
ListDevContainersFunc: func(ctx context.Context, repoID int, branch string, limit int) ([]api.DevContainerEntry, error) {
308+
ListDevContainersFunc: func(ctx context.Context, repoID int64, branch string, limit int) ([]api.DevContainerEntry, error) {
309309
return nil, fmt.Errorf("some error")
310310
},
311311
}),
@@ -793,7 +793,7 @@ func TestHandleAdditionalPermissions(t *testing.T) {
793793
CreateCodespaceFunc: func(ctx context.Context, params *api.CreateCodespaceParams) (*api.Codespace, error) {
794794
return nil, tt.createCodespaceErr
795795
},
796-
GetCodespacesPermissionsCheckFunc: func(ctx context.Context, repoID int, branch string, devcontainerPath string) (bool, error) {
796+
GetCodespacesPermissionsCheckFunc: func(ctx context.Context, repoID int64, branch string, devcontainerPath string) (bool, error) {
797797
if tt.pollForPermissionsErr != nil {
798798
return false, tt.pollForPermissionsErr
799799
}
@@ -844,12 +844,12 @@ func apiCreateDefaults(c *apiClientMock) *apiClientMock {
844844
}
845845
}
846846
if c.ListDevContainersFunc == nil {
847-
c.ListDevContainersFunc = func(ctx context.Context, repoID int, branch string, limit int) ([]api.DevContainerEntry, error) {
847+
c.ListDevContainersFunc = func(ctx context.Context, repoID int64, branch string, limit int) ([]api.DevContainerEntry, error) {
848848
return []api.DevContainerEntry{{Path: ".devcontainer/devcontainer.json"}}, nil
849849
}
850850
}
851851
if c.GetCodespacesMachinesFunc == nil {
852-
c.GetCodespacesMachinesFunc = func(ctx context.Context, repoID int, branch, location string, devcontainerPath string) ([]*api.Machine, error) {
852+
c.GetCodespacesMachinesFunc = func(ctx context.Context, repoID int64, branch, location string, devcontainerPath string) ([]*api.Machine, error) {
853853
return []*api.Machine{
854854
{
855855
Name: "GIGA",

pkg/cmd/codespace/mock_api.go

Lines changed: 21 additions & 21 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

pkg/cmd/gpg-key/delete/delete.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -74,7 +74,7 @@ func deleteRun(opts *DeleteOptions) error {
7474
id := ""
7575
for _, gpgKey := range gpgKeys {
7676
if gpgKey.KeyID == opts.KeyID {
77-
id = strconv.Itoa(gpgKey.ID)
77+
id = strconv.FormatInt(gpgKey.ID, 10)
7878
break
7979
}
8080
}

pkg/cmd/gpg-key/delete/http.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ import (
1111
)
1212

1313
type gpgKey struct {
14-
ID int
14+
ID int64
1515
KeyID string `json:"key_id"`
1616
}
1717

0 commit comments

Comments
 (0)