diff --git a/active_test.go b/active_test.go index 6c2cd6e..42b2834 100644 --- a/active_test.go +++ b/active_test.go @@ -33,7 +33,7 @@ func TestActiveService_FindByOwner(t *testing.T) { t.Errorf("Active.FindByOwner returned error: %v", err) } - want := []*Build{{Id: testBuildId, Number: "1", State: BuildStateCreated, Duration: 10}} + want := []*Build{{Id: Uint(testBuildId), Number: String("1"), State: String(BuildStateCreated), Duration: Uint(10)}} if !reflect.DeepEqual(builds, want) { t.Errorf("Active.FindByOwner returned %+v, want %+v", builds, want) } @@ -56,7 +56,7 @@ func TestActiveService_FindByGitHubId(t *testing.T) { t.Errorf("Active.FindByGitHubId returned error: %v", err) } - want := []*Build{{Id: testBuildId, Number: "1", State: BuildStateCreated, Duration: 10}} + want := []*Build{{Id: Uint(testBuildId), Number: String("1"), State: String(BuildStateCreated), Duration: Uint(10)}} if !reflect.DeepEqual(builds, want) { t.Errorf("Active.FindByGitHubId returned %+v, want %+v", builds, want) } diff --git a/beta_features.go b/beta_features.go index b03bd13..4044292 100644 --- a/beta_features.go +++ b/beta_features.go @@ -22,15 +22,15 @@ type BetaFeaturesService struct { // Travis CI API docs: https://developer.travis-ci.com/resource/beta_feature#attributes type BetaFeature struct { // Value uniquely identifying the beta feature - Id uint `json:"id,omitempty"` + Id *uint `json:"id,omitempty"` // The name of the feature - Name string `json:"name,omitempty"` + Name *string `json:"name,omitempty"` // Longer description of the feature - Description string `json:"description,omitempty"` + Description *string `json:"description,omitempty"` // Indicates if the user has this feature turned on - Enabled bool `json:"enabled,omitempty"` + Enabled *bool `json:"enabled,omitempty"` // Url for users to leave Travis CI feedback on this feature - FeedbackUrl string `json:"feedback_url,omitempty"` + FeedbackUrl *string `json:"feedback_url,omitempty"` *Metadata } diff --git a/beta_features_integration_test.go b/beta_features_integration_test.go index 4a6616b..2473dca 100644 --- a/beta_features_integration_test.go +++ b/beta_features_integration_test.go @@ -39,7 +39,7 @@ func TestBetaFeaturesService_Integration_Update(t *testing.T) { t.Fatalf("invalid http status: %s", res.Status) } - if feature.Id != integrationBetaFeatureId || feature.Enabled != true { + if *feature.Id != integrationBetaFeatureId || *feature.Enabled != true { t.Fatalf("unexpected beta feature has returned: %v", feature) } @@ -55,7 +55,7 @@ func TestBetaFeaturesService_Integration_Update(t *testing.T) { t.Fatalf("invalid http status: %s", res.Status) } - if feature.Id != integrationBetaFeatureId || feature.Enabled != false { + if *feature.Id != integrationBetaFeatureId || *feature.Enabled != false { t.Fatalf("unexpected beta feature has returned: %v", feature) } } @@ -82,7 +82,7 @@ func TestBetaFeaturesService_Integration_Delete(t *testing.T) { t.Fatalf("invalid http status: %s", res.Status) } - if got, want := int(f.Id), integrationBetaFeatureId; got != want { + if got, want := int(*f.Id), integrationBetaFeatureId; got != want { t.Fatalf("invalid beta feature id: got %d, want: %d", got, want) } } diff --git a/beta_features_test.go b/beta_features_test.go index de7a559..135bf96 100644 --- a/beta_features_test.go +++ b/beta_features_test.go @@ -28,7 +28,7 @@ func TestBetaFeaturesService_List(t *testing.T) { t.Errorf("BetaFeatures.List returned error: %v", err) } - want := []*BetaFeature{{Id: 1, Name: "dashboard", Description: "Try the new personal Dashboard layout", Enabled: true, FeedbackUrl: "https://github.com/travis-ci/beta-features/issues/5"}} + want := []*BetaFeature{{Id: Uint(1), Name: String("dashboard"), Description: String("Try the new personal Dashboard layout"), Enabled: Bool(true), FeedbackUrl: String("https://github.com/travis-ci/beta-features/issues/5")}} if !reflect.DeepEqual(features, want) { t.Errorf("BetaFeatures.List returned %+v, want %+v", features, want) } @@ -50,7 +50,7 @@ func TestBetaFeaturesService_Update(t *testing.T) { t.Errorf("BetaFeatures.Update returned error: %v", err) } - want := &BetaFeature{Id: 1, Name: "dashboard", Description: "Try the new personal Dashboard layout", Enabled: true, FeedbackUrl: "https://github.com/travis-ci/beta-features/issues/5"} + want := &BetaFeature{Id: Uint(1), Name: String("dashboard"), Description: String("Try the new personal Dashboard layout"), Enabled: Bool(true), FeedbackUrl: String("https://github.com/travis-ci/beta-features/issues/5")} if !reflect.DeepEqual(features, want) { t.Errorf("BetaFeatures.Update returned %+v, want %+v", features, want) } @@ -71,7 +71,7 @@ func TestBetaFeaturesService_Delete(t *testing.T) { t.Errorf("BetaFeatures.Delete returned error: %v", err) } - want := &BetaFeature{Id: 1, Name: "dashboard", Description: "Try the new personal Dashboard layout", Enabled: true, FeedbackUrl: "https://github.com/travis-ci/beta-features/issues/5"} + want := &BetaFeature{Id: Uint(1), Name: String("dashboard"), Description: String("Try the new personal Dashboard layout"), Enabled: Bool(true), FeedbackUrl: String("https://github.com/travis-ci/beta-features/issues/5")} if !reflect.DeepEqual(features, want) { t.Errorf("BetaFeatures.Delete returned %+v, want %+v", features, want) } diff --git a/beta_migration_requests.go b/beta_migration_requests.go index b19ee5c..f84a045 100644 --- a/beta_migration_requests.go +++ b/beta_migration_requests.go @@ -22,15 +22,15 @@ type BetaMigrationRequestsService struct { // Travis CI API docs: https://developer.travis-ci.com/resource/beta_migration_request#attributes type BetaMigrationRequest struct { // The beta_migration_request's id - Id uint `json:"id,omitempty"` + Id *uint `json:"id,omitempty"` // The beta_migration_request's owner_id - OwnerId uint `json:"owner_id,omitempty"` + OwnerId *uint `json:"owner_id,omitempty"` // The beta_migration_request's owner_name - OwnerName string `json:"owner_name,omitempty"` + OwnerName *string `json:"owner_name,omitempty"` // Longer description of the feature - OwnerType string `json:"owner_type,omitempty"` + OwnerType *string `json:"owner_type,omitempty"` // The beta_migration_request's accepted_at - AcceptedAt string `json:"accepted_at,omitempty"` + AcceptedAt *string `json:"accepted_at,omitempty"` // The beta_migration_request's organizations Organizations []*Organization `json:"organizations,omitempty"` *Metadata diff --git a/beta_migration_requests_integration_test.go b/beta_migration_requests_integration_test.go index ce5b313..a2e893c 100644 --- a/beta_migration_requests_integration_test.go +++ b/beta_migration_requests_integration_test.go @@ -42,7 +42,7 @@ func TestBetaMigrationRequestsService_Integration_Create(t *testing.T) { t.Fatalf("invalid http status: %s", res.Status) } - if got, want := request.OwnerName, integrationGitHubOwner; got != want { + if got, want := *request.OwnerName, integrationGitHubOwner; got != want { t.Fatalf("invalid owner: got: %s, want: %s", got, want) } } diff --git a/beta_migration_requests_test.go b/beta_migration_requests_test.go index ff6f5de..5669454 100644 --- a/beta_migration_requests_test.go +++ b/beta_migration_requests_test.go @@ -30,7 +30,7 @@ func TestBetaMigrationRequestsService_List(t *testing.T) { t.Errorf("BetaMigrationRequest.List returned error: %v", err) } - want := []*BetaMigrationRequest{{Id: 1, OwnerId: 2, OwnerName: "test", OwnerType: "User"}} + want := []*BetaMigrationRequest{{Id: Uint(1), OwnerId: Uint(2), OwnerName: String("test"), OwnerType: String("User")}} if !reflect.DeepEqual(requests, want) { t.Errorf("BetaMigrationRequest.List returned %+v, want %+v", requests, want) } @@ -53,7 +53,7 @@ func TestBetaMigrationRequestsService_Create(t *testing.T) { t.Errorf("BetaMigrationRequests.Create returned error: %v", err) } - want := &BetaMigrationRequest{Id: 1, OwnerId: 2, OwnerName: "test", OwnerType: "User"} + want := &BetaMigrationRequest{Id: Uint(1), OwnerId: Uint(2), OwnerName: String("test"), OwnerType: String("User")} if !reflect.DeepEqual(request, want) { t.Errorf("BetaMigrationRequests.Create returned %+v, want %+v", request, want) } diff --git a/branches.go b/branches.go index 8462b4b..87c92a0 100644 --- a/branches.go +++ b/branches.go @@ -23,13 +23,13 @@ type BranchesService struct { // Travis CI API docs: https://developer.travis-ci.com/resource/branch#standard-representation type Branch struct { // Name of the git branch - Name string `json:"name,omitempty"` + Name *string `json:"name,omitempty"` // GitHub Repository Repository *Repository `json:"repository,omitempty"` // Whether or not this is the repository's default branch - DefaultBranch bool `json:"default_branch,omitempty"` + DefaultBranch *bool `json:"default_branch,omitempty"` // Whether or not the branch still exists on GitHub - ExistsOnGithub bool `json:"exists_on_github,omitempty"` + ExistsOnGithub *bool `json:"exists_on_github,omitempty"` // Last build on the branch LastBuild *Build `json:"last_build,omitempty"` // Last 10 builds on the branch (when `include=branch.recent_builds` is used) diff --git a/branches_integration_test.go b/branches_integration_test.go index 20c4371..95b81dd 100644 --- a/branches_integration_test.go +++ b/branches_integration_test.go @@ -27,11 +27,11 @@ func TestBranchesService_Integration_FindByRepoId(t *testing.T) { t.Fatalf("#invalid http status: %s", res.Status) } - if branch.Name != "master" { + if *branch.Name != "master" { t.Fatalf("unexpected branch returned: want %s: got %s", "master", branch.Name) } - if branch.Repository.Id != integrationRepoId { + if *branch.Repository.Id != integrationRepoId { t.Fatalf("unexpected branch returned: want %d: got %d", integrationRepoId, branch.Repository.Id) } @@ -53,11 +53,11 @@ func TestBranchesService_Integration_FindByRepoSlug(t *testing.T) { t.Fatalf("#invalid http status: %s", res.Status) } - if branch.Name != "master" { + if *branch.Name != "master" { t.Fatalf("unexpected branch returned: want %s: got %s", "master", branch.Name) } - if branch.Repository.Slug != integrationRepoSlug { + if *branch.Repository.Slug != integrationRepoSlug { t.Fatalf("unexpected branch returned: want %s: got %s", integrationRepoSlug, branch.Repository.Slug) } diff --git a/branches_test.go b/branches_test.go index 1c64b69..e63ff4d 100644 --- a/branches_test.go +++ b/branches_test.go @@ -37,7 +37,7 @@ func TestBranchesService_FindByRepoId(t *testing.T) { t.Errorf("Branch.FindByRepoId returned error: %v", err) } - want := &Branch{Name: "master", Repository: &Repository{Id: 1, Name: "test", Slug: "shuheiktgw/test"}, DefaultBranch: true, ExistsOnGithub: true} + want := &Branch{Name: String("master"), Repository: &Repository{Id: Uint(1), Name: String("test"), Slug: String("shuheiktgw/test")}, DefaultBranch: Bool(true), ExistsOnGithub: Bool(true)} if !reflect.DeepEqual(branch, want) { t.Errorf("Branch.FindByRepoId returned %+v, want %+v", branch, want) } @@ -60,7 +60,7 @@ func TestBranchesService_FindByRepoSlug(t *testing.T) { t.Errorf("Branch.FindByRepoId returned error: %v", err) } - want := &Branch{Name: "master", Repository: &Repository{Id: 1, Name: "test", Slug: "shuheiktgw/test"}, DefaultBranch: true, ExistsOnGithub: true} + want := &Branch{Name: String("master"), Repository: &Repository{Id: Uint(1), Name: String("test"), Slug: String("shuheiktgw/test")}, DefaultBranch: Bool(true), ExistsOnGithub: Bool(true)} if !reflect.DeepEqual(branch, want) { t.Errorf("Branch.FindByRepoId returned %+v, want %+v", branch, want) } @@ -83,7 +83,7 @@ func TestBranchesService_ListByRepoId(t *testing.T) { t.Errorf("Branches.FindByRepoId returned error: %v", err) } - want := []*Branch{{Name: "master", Repository: &Repository{Id: 1, Name: "test", Slug: "shuheiktgw/test"}, DefaultBranch: true, ExistsOnGithub: true}} + want := []*Branch{{Name: String("master"), Repository: &Repository{Id: Uint(1), Name: String("test"), Slug: String("shuheiktgw/test")}, DefaultBranch: Bool(true), ExistsOnGithub: Bool(true)}} if !reflect.DeepEqual(branches, want) { t.Errorf("Branchse.FindByRepoId returned %+v, want %+v", branches, want) } @@ -106,7 +106,7 @@ func TestBranchesService_ListByRepoSlug(t *testing.T) { t.Errorf("Branches.indByRepoSlug returned error: %v", err) } - want := []*Branch{{Name: "master", Repository: &Repository{Id: 1, Name: "test", Slug: "shuheiktgw/test"}, DefaultBranch: true, ExistsOnGithub: true}} + want := []*Branch{{Name: String("master"), Repository: &Repository{Id: Uint(1), Name: String("test"), Slug: String("shuheiktgw/test")}, DefaultBranch: Bool(true), ExistsOnGithub: Bool(true)}} if !reflect.DeepEqual(branches, want) { t.Errorf("Branchse.indByRepoSlug returned %+v, want %+v", branches, want) } diff --git a/broadcasts.go b/broadcasts.go index 4adace1..223e555 100644 --- a/broadcasts.go +++ b/broadcasts.go @@ -21,15 +21,15 @@ type BroadcastsService struct { // Travis CI API docs: https://developer.travis-ci.com/resource/broadcast#standard-representation type Broadcast struct { // Value uniquely identifying the broadcast - Id uint `json:"id,omitempty"` + Id *uint `json:"id,omitempty"` // Message to display to the user - Message string `json:"message,omitempty"` + Message *string `json:"message,omitempty"` // Broadcast category (used for icon and color) - Category string `json:"category,omitempty"` + Category *string `json:"category,omitempty"` // Whether or not the broadcast should still be displayed - Active bool `json:"active,omitempty"` + Active *bool `json:"active,omitempty"` // When the broadcast was created - CreatedAt string `json:"created_at,omitempty"` + CreatedAt *string `json:"created_at,omitempty"` // Either a user, organization or repository, or null for global Recipient interface{} `json:"recipient,omitempty"` *Metadata diff --git a/broadcasts_test.go b/broadcasts_test.go index e4ac38e..5e72ff0 100644 --- a/broadcasts_test.go +++ b/broadcasts_test.go @@ -29,7 +29,7 @@ func TestBroadcastsService_List(t *testing.T) { t.Errorf("Broadcasts.List returned error: %v", err) } - want := []*Broadcast{{Id: 125, Message: "We just switched the default image for", Active: true, CreatedAt: "2014-11-19T14:39:51Z"}} + want := []*Broadcast{{Id: Uint(125), Message: String("We just switched the default image for"), Active: Bool(true), CreatedAt: String("2014-11-19T14:39:51Z")}} if !reflect.DeepEqual(broadcasts, want) { t.Errorf("Broadcasts.List returned %+v, want %+v", broadcasts, want) } diff --git a/builds.go b/builds.go index e6a3208..b422491 100644 --- a/builds.go +++ b/builds.go @@ -23,29 +23,29 @@ type BuildsService struct { // Travis CI API docs: https://developer.travis-ci.com/resource/build#standard-representation type Build struct { // Value uniquely identifying the build - Id uint `json:"id,omitempty"` + Id *uint `json:"id,omitempty"` // Incremental number for a repository's builds - Number string `json:"number,omitempty"` + Number *string `json:"number,omitempty"` // Current state of the build - State string `json:"state,omitempty"` + State *string `json:"state,omitempty"` // Wall clock time in seconds - Duration uint `json:"duration,omitempty"` + Duration *uint `json:"duration,omitempty"` // Event that triggered the build - EventType string `json:"event_type,omitempty"` + EventType *string `json:"event_type,omitempty"` // State of the previous build (useful to see if state changed) - PreviousState string `json:"previous_state,omitempty"` + PreviousState *string `json:"previous_state,omitempty"` // Title of the build's pull request - PullRequestTitle string `json:"pull_request_title,omitempty"` + PullRequestTitle *string `json:"pull_request_title,omitempty"` // Number of the build's pull request - PullRequestNumber uint `json:"pull_request_number,omitempty"` + PullRequestNumber *uint `json:"pull_request_number,omitempty"` // When the build started - StartedAt string `json:"started_at,omitempty"` + StartedAt *string `json:"started_at,omitempty"` // When the build finished - FinishedAt string `json:"finished_at,omitempty"` + FinishedAt *string `json:"finished_at,omitempty"` // The last time the build was updated - UpdatedAt string `json:"updated_at,omitempty"` + UpdatedAt *string `json:"updated_at,omitempty"` // Whether or not the build is private - Private bool `json:"private,omitempty"` + Private *bool `json:"private,omitempty"` // GitHub repository the build is associated with Repository *Repository `json:"repository,omitempty"` // The branch the build is associated with diff --git a/builds_integration_test.go b/builds_integration_test.go index 6eb9871..49e8801 100644 --- a/builds_integration_test.go +++ b/builds_integration_test.go @@ -25,7 +25,7 @@ func TestBuildService_Integration_Find(t *testing.T) { t.Fatalf("invalid http status: %s", res.Status) } - if build.Id != integrationBuildId { + if *build.Id != integrationBuildId { t.Fatalf("unexpected job returned: want job id %d: got job id %d", integrationBuildId, build.Id) } } @@ -134,7 +134,7 @@ func TestBuildService_Integration_RestartAndCancel(t *testing.T) { t.Fatalf("#invalid http status: %s", res.Status) } - if build.Id != integrationBuildId { + if *build.Id != integrationBuildId { t.Fatalf("unexpected job returned: want job id %d: got job id %d", integrationBuildId, build.Id) } @@ -151,7 +151,7 @@ func TestBuildService_Integration_RestartAndCancel(t *testing.T) { t.Fatalf("invalid http status: %s", res.Status) } - if build.Id != integrationBuildId { + if *build.Id != integrationBuildId { t.Fatalf("unexpected job returned: want job id %d: got job id %d", integrationBuildId, build.Id) } } diff --git a/builds_test.go b/builds_test.go index bd01c43..7d044c2 100644 --- a/builds_test.go +++ b/builds_test.go @@ -31,7 +31,7 @@ func TestBuildsService_Find(t *testing.T) { t.Errorf("Build.Find returned error: %v", err) } - want := &Build{Id: testBuildId, Number: "1", State: BuildStateCreated, Duration: 10} + want := &Build{Id: Uint(testBuildId), Number: String("1"), State: String(BuildStateCreated), Duration: Uint(10)} if !reflect.DeepEqual(build, want) { t.Errorf("Build.Find returned %+v, want %+v", build, want) } @@ -53,7 +53,7 @@ func TestBuildsService_List(t *testing.T) { t.Errorf("Builds.Find returned error: %v", err) } - want := []*Build{{Id: testBuildId, Number: "1", State: BuildStateCreated, Duration: 10}} + want := []*Build{{Id: Uint(testBuildId), Number: String("1"), State: String(BuildStateCreated), Duration: Uint(10)}} if !reflect.DeepEqual(builds, want) { t.Errorf("Builds.Find returned %+v, want %+v", builds, want) } @@ -75,7 +75,7 @@ func TestBuildsService_ListByRepoId(t *testing.T) { t.Errorf("Builds.FindByRepoId returned error: %v", err) } - want := []*Build{{Id: testBuildId, Number: "1", State: BuildStateCreated, Duration: 10}} + want := []*Build{{Id: Uint(testBuildId), Number: String("1"), State: String(BuildStateCreated), Duration: Uint(10)}} if !reflect.DeepEqual(builds, want) { t.Errorf("Builds.FindByRepoId returned %+v, want %+v", builds, want) } @@ -97,7 +97,7 @@ func TestBuildsService_ListByRepoSlug(t *testing.T) { t.Errorf("Builds.FindByRepoSlug returned error: %v", err) } - want := []*Build{{Id: testBuildId, Number: "1", State: BuildStateCreated, Duration: 10}} + want := []*Build{{Id: Uint(testBuildId), Number: String("1"), State: String(BuildStateCreated), Duration: Uint(10)}} if !reflect.DeepEqual(builds, want) { t.Errorf("Builds.FindByRepoSlug returned %+v, want %+v", builds, want) } @@ -118,7 +118,7 @@ func TestBuildsService_Cancel(t *testing.T) { t.Errorf("Build.Cancel returned error: %v", err) } - want := &Build{Id: testBuildId, Number: "1", State: BuildStateCreated, Duration: 10} + want := &Build{Id: Uint(testBuildId), Number: String("1"), State: String(BuildStateCreated), Duration: Uint(10)} if !reflect.DeepEqual(build, want) { t.Errorf("Build.Cancel returned %+v, want %+v", build, want) } @@ -139,7 +139,7 @@ func TestBuildsService_Restart(t *testing.T) { t.Errorf("Build.Restart returned error: %v", err) } - want := &Build{Id: testBuildId, Number: "1", State: BuildStateCreated, Duration: 10} + want := &Build{Id: Uint(testBuildId), Number: String("1"), State: String(BuildStateCreated), Duration: Uint(10)} if !reflect.DeepEqual(build, want) { t.Errorf("Build.Restart returned %+v, want %+v", build, want) } diff --git a/caches.go b/caches.go index e07ec74..5fb00cc 100644 --- a/caches.go +++ b/caches.go @@ -23,9 +23,9 @@ type CachesService struct { // Travis CI API docs: https://developer.travis-ci.com/resource/caches#attributes type Cache struct { // The branch the cache belongs to - Branch string `json:"branch,omitempty"` + Branch *string `json:"branch,omitempty"` // The string to match against the cache name - Match string `json:"match,omitempty"` + Match *string `json:"match,omitempty"` *Metadata } diff --git a/caches_test.go b/caches_test.go index 11dbe05..cf7e115 100644 --- a/caches_test.go +++ b/caches_test.go @@ -28,7 +28,7 @@ func TestCachesService_ListByRepoId(t *testing.T) { t.Errorf("Caches.FindByRepoId returned error: %v", err) } - want := []*Cache{{Branch: "master", Match: "test"}} + want := []*Cache{{Branch: String("master"), Match: String("test")}} if !reflect.DeepEqual(caches, want) { t.Errorf("Caches.FindByRepoId returned %+v, want %+v", caches, want) } @@ -49,7 +49,7 @@ func TestCachesService_ListByRepoSlug(t *testing.T) { t.Errorf("Caches.FindByRepoSlug returned error: %v", err) } - want := []*Cache{{Branch: "master", Match: "test"}} + want := []*Cache{{Branch: String("master"), Match: String("test")}} if !reflect.DeepEqual(caches, want) { t.Errorf("Caches.FindByRepoSlug returned %+v, want %+v", caches, want) } @@ -70,7 +70,7 @@ func TestCachesService_DeleteByRepoId(t *testing.T) { t.Errorf("Caches.DeleteByRepoId returned error: %v", err) } - want := []*Cache{{Branch: "master", Match: "test"}} + want := []*Cache{{Branch: String("master"), Match: String("test")}} if !reflect.DeepEqual(caches, want) { t.Errorf("Caches.DeleteByRepoId returned %+v, want %+v", caches, want) } @@ -91,7 +91,7 @@ func TestCachesService_DeleteByRepoSlug(t *testing.T) { t.Errorf("Caches.DeleteByRepoSlug returned error: %v", err) } - want := []*Cache{{Branch: "master", Match: "test"}} + want := []*Cache{{Branch: String("master"), Match: String("test")}} if !reflect.DeepEqual(caches, want) { t.Errorf("Caches.DeleteByRepoSlug returned %+v, want %+v", caches, want) } diff --git a/commits.go b/commits.go index 844ef14..6f02d3f 100644 --- a/commits.go +++ b/commits.go @@ -10,17 +10,17 @@ package travis // Travis CI API docs: https://developer.travis-ci.com/resource/commit#standard-representation type Commit struct { // Value uniquely identifying the commit - Id uint `json:"id,omitempty"` + Id *uint `json:"id,omitempty"` // Checksum the commit has in git and is identified by - Sha string `json:"sha,omitempty"` + Sha *string `json:"sha,omitempty"` // Named reference the commit has in git. - Ref string `json:"ref,omitempty"` + Ref *string `json:"ref,omitempty"` // Commit message - Message string `json:"message,omitempty"` + Message *string `json:"message,omitempty"` // URL to the commit's diff on GitHub - CompareUrl string `json:"compare_url,omitempty"` + CompareUrl *string `json:"compare_url,omitempty"` // Commit date from git - CommittedAt string `json:"committed_at,omitempty"` + CommittedAt *string `json:"committed_at,omitempty"` // Committer of the commit Committer *Committer `json:"committer,omitempty"` // Author of the commit diff --git a/crons.go b/crons.go index 09b11e3..c7775da 100644 --- a/crons.go +++ b/crons.go @@ -23,23 +23,23 @@ type CronsService struct { // Travis CI API docs: https://developer.travis-ci.com/resource/cron#standard-representation type Cron struct { // Value uniquely identifying the cron - Id uint `json:"id,omitempty"` + Id *uint `json:"id,omitempty"` // Github repository to which this cron belongs Repository *Repository `json:"repository,omitempty"` // Git branch of repository to which this cron belongs Branch *Branch `json:"branch,omitempty"` // Interval at which the cron will run (can be "daily", "weekly" or "monthly") - Interval string `json:"interval,omitempty"` + Interval *string `json:"interval,omitempty"` // Whether a cron build should run if there has been a build on this branch in the last 24 hours - DontRunIfRecentBuildExists bool `json:"dont_run_if_recent_build_exists,omitempty"` + DontRunIfRecentBuildExists *bool `json:"dont_run_if_recent_build_exists,omitempty"` // When the cron ran last - LastRun string `json:"last_run,omitempty"` + LastRun *string `json:"last_run,omitempty"` // When the cron is scheduled to run next - NextRun string `json:"next_run,omitempty"` + NextRun *string `json:"next_run,omitempty"` // When the cron was created - CreatedAt string `json:"created_at,omitempty"` + CreatedAt *string `json:"created_at,omitempty"` // Whether the cron is active or not - Active bool `json:"active,omitempty"` + Active *bool `json:"active,omitempty"` *Metadata } diff --git a/crons_integration_test.go b/crons_integration_test.go index 97f267e..4f352bc 100644 --- a/crons_integration_test.go +++ b/crons_integration_test.go @@ -49,7 +49,7 @@ func TestCronService_Integration_ListByRepoId(t *testing.T) { t.Fatalf("Cron.ListByRepoId returns invalid number of items: want %d, got %d", want, got) } - if got, want := crons[0].Id, createdCron.Id; got != want { + if got, want := *crons[0].Id, *createdCron.Id; got != want { t.Fatalf("Cron.ListByRepoId returns invalid item id: want %d, got %d", want, got) } @@ -64,7 +64,7 @@ func TestCronService_Integration_ListByRepoId(t *testing.T) { time.Sleep(2 * time.Second) // Delete a cron - res, err = integrationClient.Crons.Delete(context.TODO(), createdCron.Id) + res, err = integrationClient.Crons.Delete(context.TODO(), *createdCron.Id) if err != nil { t.Fatalf("Cron.Delete unexpected error occured: %s", err) @@ -110,7 +110,7 @@ func TestCronService_Integration_ListByRepoSlug(t *testing.T) { t.Fatalf("Cron.ListByRepoSlug returns invalid number of items: want %d, got %d", want, got) } - if got, want := crons[0].Id, createdCron.Id; got != want { + if got, want := *crons[0].Id, *createdCron.Id; got != want { t.Fatalf("Cron.ListByRepoSlug returns invalid item id: want %d, got %d", want, got) } @@ -125,7 +125,7 @@ func TestCronService_Integration_ListByRepoSlug(t *testing.T) { time.Sleep(2 * time.Second) // Delete a cron - res, err = integrationClient.Crons.Delete(context.TODO(), createdCron.Id) + res, err = integrationClient.Crons.Delete(context.TODO(), *createdCron.Id) if err != nil { t.Fatalf("Cron.Delete unexpected error occured: %s", err) @@ -149,18 +149,18 @@ func TestCronsService_Integration_CreateAndFindAndDeleteCron(t *testing.T) { t.Fatalf("Cron.CreateByRepoId invalid http status: %s", res.Status) } - if got, want := createdCron.Interval, CronIntervalMonthly; got != want { + if got, want := *createdCron.Interval, CronIntervalMonthly; got != want { t.Errorf("Cron.CreateByRepoId unexpected cron interval returned: want %s got %s", want, got) } - if got, want := createdCron.DontRunIfRecentBuildExists, true; got != want { + if got, want := *createdCron.DontRunIfRecentBuildExists, true; got != want { t.Errorf("Cron.CreateByRepoId unexpected cron DontRunIfRecentBuildExists returned: want %v got %v", want, got) } time.Sleep(2 * time.Second) // Delete a cron - res, err = integrationClient.Crons.Delete(context.TODO(), createdCron.Id) + res, err = integrationClient.Crons.Delete(context.TODO(), *createdCron.Id) if err != nil { t.Fatalf("Cron.Delete unexpected error occured: %s", err) @@ -183,11 +183,11 @@ func TestCronsService_Integration_CreateAndFindAndDeleteCron(t *testing.T) { t.Fatalf("Cron.CreateByRepoSlug invalid http status: %s", res.Status) } - if got, want := createdCron.Interval, CronIntervalMonthly; got != want { + if got, want := *createdCron.Interval, CronIntervalMonthly; got != want { t.Errorf("Cron.CreateByRepoSlug unexpected cron interval returned: want %s got %s", want, got) } - if got, want := createdCron.DontRunIfRecentBuildExists, true; got != want { + if got, want := *createdCron.DontRunIfRecentBuildExists, true; got != want { t.Errorf("Cron.CreateByRepoSlug unexpected cron DontRunIfRecentBuildExists returned: want %v got %v", want, got) } @@ -195,7 +195,7 @@ func TestCronsService_Integration_CreateAndFindAndDeleteCron(t *testing.T) { // Find a cron opt := CronOption{Include: []string{"cron.repository", "cron.branch"}} - findCron, res, err := integrationClient.Crons.Find(context.TODO(), createdCron.Id, &opt) + findCron, res, err := integrationClient.Crons.Find(context.TODO(), *createdCron.Id, &opt) if err != nil { t.Fatalf("Cron.Find unexpected error occured: %s", err) @@ -205,15 +205,15 @@ func TestCronsService_Integration_CreateAndFindAndDeleteCron(t *testing.T) { t.Fatalf("Cron.Find invalid http status: %s", res.Status) } - if got, want := findCron.Id, createdCron.Id; got != want { + if got, want := *findCron.Id, *createdCron.Id; got != want { t.Errorf("Cron.Find unexpected cron interval returned: want %d got %d", want, got) } - if got, want := findCron.Interval, CronIntervalMonthly; got != want { + if got, want := *findCron.Interval, CronIntervalMonthly; got != want { t.Errorf("Cron.Find unexpected cron interval returned: want %s got %s", want, got) } - if got, want := findCron.DontRunIfRecentBuildExists, true; got != want { + if got, want := *findCron.DontRunIfRecentBuildExists, true; got != want { t.Errorf("Cron.Find unexpected cron DontRunIfRecentBuildExists returned: want %v got %v", want, got) } @@ -238,15 +238,15 @@ func TestCronsService_Integration_CreateAndFindAndDeleteCron(t *testing.T) { t.Fatalf("Cron.FindByRepoId invalid http status: %s", res.Status) } - if got, want := findCron.Id, createdCron.Id; got != want { + if got, want := *findCron.Id, *createdCron.Id; got != want { t.Errorf("Cron.FindByRepoId unexpected cron interval returned: want %d got %d", want, got) } - if got, want := findCron.Interval, CronIntervalMonthly; got != want { + if got, want := *findCron.Interval, CronIntervalMonthly; got != want { t.Errorf("Cron.FindByRepoId unexpected cron interval returned: want %s got %s", want, got) } - if got, want := findCron.DontRunIfRecentBuildExists, true; got != want { + if got, want := *findCron.DontRunIfRecentBuildExists, true; got != want { t.Errorf("Cron.FindByRepoId unexpected cron DontRunIfRecentBuildExists returned: want %v got %v", want, got) } @@ -271,15 +271,15 @@ func TestCronsService_Integration_CreateAndFindAndDeleteCron(t *testing.T) { t.Fatalf("Cron.FindByRepoSlug invalid http status: %s", res.Status) } - if got, want := findCron.Id, createdCron.Id; got != want { + if got, want := *findCron.Id, *createdCron.Id; got != want { t.Errorf("Cron.FindByRepoSlug unexpected cron interval returned: want %d got %d", want, got) } - if got, want := findCron.Interval, CronIntervalMonthly; got != want { + if got, want := *findCron.Interval, CronIntervalMonthly; got != want { t.Errorf("Cron.FindByRepoSlug unexpected cron interval returned: want %s got %s", want, got) } - if got, want := findCron.DontRunIfRecentBuildExists, true; got != want { + if got, want := *findCron.DontRunIfRecentBuildExists, true; got != want { t.Errorf("Cron.FindByRepoSlug unexpected cron DontRunIfRecentBuildExists returned: want %v got %v", want, got) } @@ -294,7 +294,7 @@ func TestCronsService_Integration_CreateAndFindAndDeleteCron(t *testing.T) { time.Sleep(2 * time.Second) // Delete a cron - res, err = integrationClient.Crons.Delete(context.TODO(), createdCron.Id) + res, err = integrationClient.Crons.Delete(context.TODO(), *createdCron.Id) if err != nil { t.Fatalf("Cron.Delete unexpected error occured: %s", err) diff --git a/crons_test.go b/crons_test.go index 5b70657..a129fb3 100644 --- a/crons_test.go +++ b/crons_test.go @@ -32,7 +32,7 @@ func TestCronsService_Find(t *testing.T) { t.Errorf("Cron.Find returned error: %v", err) } - want := &Cron{Id: testCronId, Interval: CronIntervalWeekly, DontRunIfRecentBuildExists: true, Active: true} + want := &Cron{Id: Uint(testCronId), Interval: String(CronIntervalWeekly), DontRunIfRecentBuildExists: Bool(true), Active: Bool(true)} if !reflect.DeepEqual(cron, want) { t.Errorf("Cron.Find returned %+v, want %+v", cron, want) } @@ -55,7 +55,7 @@ func TestCronsService_FindByRepoId(t *testing.T) { t.Errorf("Cron.FindByRepoId returned error: %v", err) } - want := &Cron{Id: testCronId, Interval: CronIntervalWeekly, DontRunIfRecentBuildExists: true, Active: true} + want := &Cron{Id: Uint(testCronId), Interval: String(CronIntervalWeekly), DontRunIfRecentBuildExists: Bool(true), Active: Bool(true)} if !reflect.DeepEqual(cron, want) { t.Errorf("Cron.FindByRepoId returned %+v, want %+v", cron, want) } @@ -78,7 +78,7 @@ func TestCronsService_FindByRepoSlug(t *testing.T) { t.Errorf("Cron.FindByRepoSlug returned error: %v", err) } - want := &Cron{Id: testCronId, Interval: CronIntervalWeekly, DontRunIfRecentBuildExists: true, Active: true} + want := &Cron{Id: Uint(testCronId), Interval: String(CronIntervalWeekly), DontRunIfRecentBuildExists: Bool(true), Active: Bool(true)} if !reflect.DeepEqual(cron, want) { t.Errorf("Cron.FindByRepoSlug returned %+v, want %+v", cron, want) } @@ -101,7 +101,7 @@ func TestCronsService_ListByRepoId(t *testing.T) { t.Errorf("Crons.FindByRepoId returned error: %v", err) } - want := []*Cron{{Id: testCronId, Interval: CronIntervalWeekly, DontRunIfRecentBuildExists: true, Active: true}} + want := []*Cron{{Id: Uint(testCronId), Interval: String(CronIntervalWeekly), DontRunIfRecentBuildExists: Bool(true), Active: Bool(true)}} if !reflect.DeepEqual(crons, want) { t.Errorf("Crons.FindByRepoId returned %+v, want %+v", crons, want) } @@ -124,7 +124,7 @@ func TestCronsService_ListByRepoSlug(t *testing.T) { t.Errorf("Crons.FindByRepoSlug returned error: %v", err) } - want := []*Cron{{Id: testCronId, Interval: CronIntervalWeekly, DontRunIfRecentBuildExists: true, Active: true}} + want := []*Cron{{Id: Uint(testCronId), Interval: String(CronIntervalWeekly), DontRunIfRecentBuildExists: Bool(true), Active: Bool(true)}} if !reflect.DeepEqual(crons, want) { t.Errorf("Crons.FindByRepoSlug returned %+v, want %+v", crons, want) } @@ -147,7 +147,7 @@ func TestCronsService_CreateByRepoId(t *testing.T) { t.Errorf("Cron.CreateByRepoId returned error: %v", err) } - want := &Cron{Id: testCronId, Interval: CronIntervalWeekly, DontRunIfRecentBuildExists: true, Active: true} + want := &Cron{Id: Uint(testCronId), Interval: String(CronIntervalWeekly), DontRunIfRecentBuildExists: Bool(true), Active: Bool(true)} if !reflect.DeepEqual(cron, want) { t.Errorf("Cron.CreateByRepoId returned %+v, want %+v", cron, want) } @@ -170,7 +170,7 @@ func TestCronsService_CreateByRepoSlug(t *testing.T) { t.Errorf("Cron.CreateByRepoId returned error: %v", err) } - want := &Cron{Id: testCronId, Interval: CronIntervalWeekly, DontRunIfRecentBuildExists: true, Active: true} + want := &Cron{Id: Uint(testCronId), Interval: String(CronIntervalWeekly), DontRunIfRecentBuildExists: Bool(true), Active: Bool(true)} if !reflect.DeepEqual(cron, want) { t.Errorf("Cron.CreateByRepoId returned %+v, want %+v", cron, want) } diff --git a/env_vars.go b/env_vars.go index b031437..3926b17 100644 --- a/env_vars.go +++ b/env_vars.go @@ -23,13 +23,13 @@ type EnvVarsService struct { // Travis CI API docs: https://developer.travis-ci.com/resource/env_var#standard-representation type EnvVar struct { // The environment variable id - Id string `json:"id,omitempty"` + Id *string `json:"id,omitempty"` // The environment variable name, e.g. FOO - Name string `json:"name,omitempty"` + Name *string `json:"name,omitempty"` // The environment variable's value, e.g. bar - Value string `json:"value,omitempty"` + Value *string `json:"value,omitempty"` // Whether this environment variable should be publicly visible or not - Public bool `json:"public,omitempty"` + Public *bool `json:"public,omitempty"` *Metadata } diff --git a/env_vars_integration_test.go b/env_vars_integration_test.go index a936482..7fe669b 100644 --- a/env_vars_integration_test.go +++ b/env_vars_integration_test.go @@ -9,9 +9,7 @@ package travis import ( "context" - "fmt" "net/http" - "reflect" "testing" "time" ) @@ -29,7 +27,7 @@ func TestEnvVarsService_Integration_FindByRepoId(t *testing.T) { t.Fatalf("invalid http status: %s", res.Status) } - if envVar.Id != integrationEnvVarId { + if *envVar.Id != integrationEnvVarId { t.Fatalf("unexpected env var id returned: want %s got %s", integrationEnvVarId, envVar.Id) } } @@ -45,7 +43,7 @@ func TestEnvVarsService_Integration_FindByRepoSlug(t *testing.T) { t.Fatalf("invalid http status: %s", res.Status) } - if envVar.Id != integrationEnvVarId { + if *envVar.Id != integrationEnvVarId { t.Fatalf("unexpected env var id returned: want %s got %s", integrationEnvVarId, envVar.Id) } } @@ -95,20 +93,8 @@ func TestEnvVarsService_Integration_CreateAndUpdateAndDeleteEnvVarByRepoId(t *te t.Fatalf("EnvVars.CreateByRepoId returned invalid http status: %s", res.Status) } - want := &EnvVar{ - Id: envVar.Id, - Name: "TEST", - Value: "test", - Public: true, - Metadata: &Metadata{ - Type: "env_var", - Href: fmt.Sprintf("/repo/20783933/env_var/%s", envVar.Id), - Representation: "standard", - Permissions: Permissions{"read": true, "write": true}, - }, - } - if !reflect.DeepEqual(envVar, want) { - t.Errorf("EnvVars.CreateByRepoId returned %+v, want %+v", envVar, want) + if *envVar.Name != body.Name || *envVar.Value != body.Value || *envVar.Public != body.Public { + t.Fatalf("EnvVars.CreateByRepoId returned invalid EnvVar: %v", envVar) } // Be nice to the API @@ -116,7 +102,7 @@ func TestEnvVarsService_Integration_CreateAndUpdateAndDeleteEnvVarByRepoId(t *te // Update body = EnvVarBody{Name: "NEW_TEST", Value: "new_test", Public: false} - envVar, res, err = integrationClient.EnvVars.UpdateByRepoId(context.TODO(), integrationRepoId, envVar.Id, &body) + envVar, res, err = integrationClient.EnvVars.UpdateByRepoId(context.TODO(), integrationRepoId, *envVar.Id, &body) if err != nil { t.Fatalf("EnvVars.UpdateByRepoId returned unexpected error: %s", err) @@ -126,27 +112,15 @@ func TestEnvVarsService_Integration_CreateAndUpdateAndDeleteEnvVarByRepoId(t *te t.Fatalf("EnvVars.UpdateByRepoId returned invalid http status: %s", res.Status) } - want = &EnvVar{ - Id: envVar.Id, - Name: "NEW_TEST", - Value: "", - Public: false, - Metadata: &Metadata{ - Type: "env_var", - Href: fmt.Sprintf("/repo/20783933/env_var/%s", envVar.Id), - Representation: "standard", - Permissions: Permissions{"read": true, "write": true}, - }, - } - if !reflect.DeepEqual(envVar, want) { - t.Errorf("EnvVars.UpdateByRepoId returned %+v, want %+v", envVar, want) + if *envVar.Name != body.Name || envVar.Value != nil || *envVar.Public != body.Public { + t.Fatalf("EnvVars.UpdateByRepoId returned invalid EnvVar: %v", envVar) } // Be nice to the API time.Sleep(2 * time.Second) // Delete - res, err = integrationClient.EnvVars.DeleteByRepoId(context.TODO(), integrationRepoId, envVar.Id) + res, err = integrationClient.EnvVars.DeleteByRepoId(context.TODO(), integrationRepoId, *envVar.Id) if err != nil { t.Fatalf("EnvVars.DeleteByRepoId returned unexpected error: %s", err) @@ -170,20 +144,8 @@ func TestEnvVarsService_Integration_CreateAndUpdateAndDeleteEnvVarByRepoSlug(t * t.Fatalf("EnvVars.CreateByRepoSlug returned invalid http status: %s", res.Status) } - want := &EnvVar{ - Id: envVar.Id, - Name: "TEST", - Value: "test", - Public: true, - Metadata: &Metadata{ - Type: "env_var", - Href: fmt.Sprintf("/repo/20783933/env_var/%s", envVar.Id), - Representation: "standard", - Permissions: Permissions{"read": true, "write": true}, - }, - } - if !reflect.DeepEqual(envVar, want) { - t.Errorf("EnvVars.CreateByRepoSlug returned %+v, want %+v", envVar, want) + if *envVar.Name != body.Name || *envVar.Value != body.Value || *envVar.Public != body.Public { + t.Fatalf("EnvVars.CreateByRepoSlug returned invalid EnvVar: %v", envVar) } // Be nice to the API @@ -191,7 +153,7 @@ func TestEnvVarsService_Integration_CreateAndUpdateAndDeleteEnvVarByRepoSlug(t * // Update body = EnvVarBody{Name: "NEW_TEST", Value: "new_test", Public: false} - envVar, res, err = integrationClient.EnvVars.UpdateByRepoSlug(context.TODO(), integrationRepoSlug, envVar.Id, &body) + envVar, res, err = integrationClient.EnvVars.UpdateByRepoSlug(context.TODO(), integrationRepoSlug, *envVar.Id, &body) if err != nil { t.Fatalf("EnvVar.UpdateByRepoSlug returned unexpected error: %s", err) @@ -201,27 +163,15 @@ func TestEnvVarsService_Integration_CreateAndUpdateAndDeleteEnvVarByRepoSlug(t * t.Fatalf("EnvVar.UpdateByRepoSlug returned invalid http status: %s", res.Status) } - want = &EnvVar{ - Id: envVar.Id, - Name: "NEW_TEST", - Value: "", - Public: false, - Metadata: &Metadata{ - Type: "env_var", - Href: fmt.Sprintf("/repo/20783933/env_var/%s", envVar.Id), - Representation: "standard", - Permissions: Permissions{"read": true, "write": true}, - }, - } - if !reflect.DeepEqual(envVar, want) { - t.Errorf("EnvVars.UpdateByRepoSlug returned %+v, want %+v", envVar, want) + if *envVar.Name != body.Name || envVar.Value != nil || *envVar.Public != body.Public { + t.Fatalf("EnvVars.UpdateByRepoSlug returned invalid EnvVar: %v", envVar) } // Be nice to the API time.Sleep(2 * time.Second) // Delete - res, err = integrationClient.EnvVars.DeleteByRepoSlug(context.TODO(), integrationRepoSlug, envVar.Id) + res, err = integrationClient.EnvVars.DeleteByRepoSlug(context.TODO(), integrationRepoSlug, *envVar.Id) if err != nil { t.Fatalf("EnvVars.DeleteByRepoSlug returned unexpected error: %s", err) diff --git a/env_vars_test.go b/env_vars_test.go index 5f0a0da..5931953 100644 --- a/env_vars_test.go +++ b/env_vars_test.go @@ -30,7 +30,7 @@ func TestEnvVarsService_FindByRepoId(t *testing.T) { t.Errorf("EnvVars.FindByRepoId returned error: %v", err) } - want := &EnvVar{Id: testEnvVarId, Name: "TEST", Value: "test", Public: false} + want := &EnvVar{Id: String(testEnvVarId), Name: String("TEST"), Value: String("test"), Public: Bool(false)} if !reflect.DeepEqual(envVar, want) { t.Errorf("EnvVars.FindByRepoId returned %+v, want %+v", envVar, want) } @@ -51,7 +51,7 @@ func TestEnvVarsService_FindByRepoSlug(t *testing.T) { t.Errorf("EnvVar.FindByRepoSlug returned error: %v", err) } - want := &EnvVar{Id: testEnvVarId, Name: "TEST", Value: "test", Public: false} + want := &EnvVar{Id: String(testEnvVarId), Name: String("TEST"), Value: String("test"), Public: Bool(false)} if !reflect.DeepEqual(envVar, want) { t.Errorf("EnvVars.FindByRepoSlug returned %+v, want %+v", envVar, want) } @@ -72,7 +72,7 @@ func TestEnvVarsService_ListByRepoId(t *testing.T) { t.Errorf("EnvVars.FindByRepoId returned error: %v", err) } - want := []*EnvVar{{Id: testEnvVarId, Name: "TEST", Value: "test", Public: false}} + want := []*EnvVar{{Id: String(testEnvVarId), Name: String("TEST"), Value: String("test"), Public: Bool(false)}} if !reflect.DeepEqual(envVar, want) { t.Errorf("EnvVars.FindByRepoId returned %+v, want %+v", envVar, want) } @@ -93,7 +93,7 @@ func TestEnvVarsService_ListByRepoSlug(t *testing.T) { t.Errorf("EnvVars.FindByRepoSlug returned error: %v", err) } - want := []*EnvVar{{Id: testEnvVarId, Name: "TEST", Value: "test", Public: false}} + want := []*EnvVar{{Id: String(testEnvVarId), Name: String("TEST"), Value: String("test"), Public: Bool(false)}} if !reflect.DeepEqual(envVar, want) { t.Errorf("EnvVars.FindByRepoSlug returned %+v, want %+v", envVar, want) } @@ -116,7 +116,7 @@ func TestEnvVarsService_CreateByRepoId(t *testing.T) { t.Errorf("EnvVars.CreateByRepoId returned error: %v", err) } - want := &EnvVar{Id: testEnvVarId, Name: "TEST", Value: "test", Public: false} + want := &EnvVar{Id: String(testEnvVarId), Name: String("TEST"), Value: String("test"), Public: Bool(false)} if !reflect.DeepEqual(envVar, want) { t.Errorf("EnvVars.CreateByRepoId returned %+v, want %+v", envVar, want) } @@ -139,7 +139,7 @@ func TestEnvVarsService_CreateByRepoSlug(t *testing.T) { t.Errorf("EnvVars.CreateByRepoSlug returned error: %v", err) } - want := &EnvVar{Id: testEnvVarId, Name: "TEST", Value: "test", Public: false} + want := &EnvVar{Id: String(testEnvVarId), Name: String("TEST"), Value: String("test"), Public: Bool(false)} if !reflect.DeepEqual(envVar, want) { t.Errorf("EnvVars.CreateByRepoSlug returned %+v, want %+v", envVar, want) } @@ -162,7 +162,7 @@ func TestEnvVarsService_UpdateByRepoId(t *testing.T) { t.Errorf("EnvVar.UpdateByRepoId returned error: %v", err) } - want := &EnvVar{Id: testEnvVarId, Name: "TEST", Value: "test", Public: false} + want := &EnvVar{Id: String(testEnvVarId), Name: String("TEST"), Value: String("test"), Public: Bool(false)} if !reflect.DeepEqual(e, want) { t.Errorf("EnvVars.UpdateByRepoId returned %+v, want %+v", envVar, want) } @@ -185,7 +185,7 @@ func TestEnvVarsService_UpdateByRepoSlug(t *testing.T) { t.Errorf("EnvVars.UpdateByRepoSlug returned error: %v", err) } - want := &EnvVar{Id: testEnvVarId, Name: "TEST", Value: "test", Public: false} + want := &EnvVar{Id: String(testEnvVarId), Name: String("TEST"), Value: String("test"), Public: Bool(false)} if !reflect.DeepEqual(e, want) { t.Errorf("EnvVars.UpdateByRepoSlug returned %+v, want %+v", e, want) } diff --git a/installations_test.go b/installations_test.go index 31797e3..d7ab909 100644 --- a/installations_test.go +++ b/installations_test.go @@ -32,7 +32,7 @@ func TestInstallationsService_Find(t *testing.T) { t.Errorf("Installation.Find returned error: %v", err) } - want := &Installation{Id: testInstallationId, GitHubId: testGitHubId} + want := &Installation{Id: Uint(testInstallationId), GitHubId: Uint(testGitHubId)} if !reflect.DeepEqual(installation, want) { t.Errorf("Installation.Find returned %+v, want %+v", installation, want) } diff --git a/installatios.go b/installatios.go index ac03603..fadfaa3 100644 --- a/installatios.go +++ b/installatios.go @@ -22,9 +22,9 @@ type InstallationsService struct { // Travis CI API docs: https://developer.travis-ci.com/resource/installation#standard-representation type Installation struct { // The installation id - Id uint `json:"id,omitempty"` + Id *uint `json:"id,omitempty"` // The installation's id on GitHub - GitHubId uint `json:"github_id,omitempty"` + GitHubId *uint `json:"github_id,omitempty"` // GitHub user or organization the installation belongs to Owner *Owner `json:"owner,omitempty"` *Metadata diff --git a/jobs.go b/jobs.go index 04bd53a..d203622 100644 --- a/jobs.go +++ b/jobs.go @@ -22,21 +22,21 @@ type JobsService struct { // Travis CI API docs: https://developer.travis-ci.com/resource/job#standard-representation type Job struct { // Value uniquely identifying the job - Id uint `json:"id,omitempty"` + Id *uint `json:"id,omitempty"` // The job's allow_failure - AllowFailure bool `json:"allow_failure,omitempty"` + AllowFailure *bool `json:"allow_failure,omitempty"` // Incremental number for a repository's builds - Number string `json:"number,omitempty"` + Number *string `json:"number,omitempty"` // Current state of the job - State string `json:"state,omitempty"` + State *string `json:"state,omitempty"` // When the job started - StartedAt string `json:"started_at,omitempty"` + StartedAt *string `json:"started_at,omitempty"` // When the job finished - FinishedAt string `json:"finished_at,omitempty"` + FinishedAt *string `json:"finished_at,omitempty"` // The build the job is associated with Build *Build `json:"build,omitempty"` // Worker queue this job is/was scheduled on - Queue string `json:"queue,omitempty"` + Queue *string `json:"queue,omitempty"` // GitHub repository the job is associated with Repository *Repository `json:"repository,omitempty"` // The commit the job is associated with @@ -46,11 +46,11 @@ type Job struct { // The stages of the job Stage *Stage `json:"stage,omitempty"` // When the job was created - CreatedAt string `json:"created_at,omitempty"` + CreatedAt *string `json:"created_at,omitempty"` // When the job was updated - UpdatedAt string `json:"updated_at,omitempty"` + UpdatedAt *string `json:"updated_at,omitempty"` // Whether or not the job is private - Private bool `json:"private,omitempty"` + Private *bool `json:"private,omitempty"` *Metadata } diff --git a/jobs_integration_test.go b/jobs_integration_test.go index 49d4f5c..611a689 100644 --- a/jobs_integration_test.go +++ b/jobs_integration_test.go @@ -28,7 +28,7 @@ func TestJobsService_Integration_Find(t *testing.T) { t.Fatalf("#invalid http status: %s", res.Status) } - if job.Id != integrationJobId { + if *job.Id != integrationJobId { t.Fatalf("unexpected job returned: want job id %d: got job id %d", integrationBuildId, job.Id) } @@ -89,7 +89,7 @@ func TestJobsService_Integration_RestartAndCancel(t *testing.T) { t.Fatalf("#invalid http status: %s", res.Status) } - if job.Id != integrationJobId { + if *job.Id != integrationJobId { t.Fatalf("unexpected job returned: want job id %d: got job id %d", integrationJobId, job.Id) } @@ -102,7 +102,7 @@ func TestJobsService_Integration_RestartAndCancel(t *testing.T) { t.Fatalf("unexpected error occured: %s", err) } - if job.Id != integrationJobId { + if *job.Id != integrationJobId { t.Fatalf("unexpected job returned: want job id %d: got job id %d", integrationJobId, job.Id) } } diff --git a/jobs_test.go b/jobs_test.go index 58d681d..8bd2edd 100644 --- a/jobs_test.go +++ b/jobs_test.go @@ -32,7 +32,7 @@ func TestJobsService_Find(t *testing.T) { t.Errorf("Job.Find returned error: %v", err) } - want := &Job{Id: testJobId, AllowFailure: true, Number: "1", State: JobStatusCreated} + want := &Job{Id: Uint(testJobId), AllowFailure: Bool(true), Number: String("1"), State: String(JobStatusCreated)} if !reflect.DeepEqual(job, want) { t.Errorf("Job.Find returned %+v, want %+v", job, want) } @@ -53,7 +53,7 @@ func TestJobsService_ListByBuild(t *testing.T) { t.Errorf("Jobs.ListByBuild returned error: %v", err) } - want := []*Job{{Id: testJobId, AllowFailure: true, Number: "1", State: JobStatusCreated}} + want := []*Job{{Id: Uint(testJobId), AllowFailure: Bool(true), Number: String("1"), State: String(JobStatusCreated)}} if !reflect.DeepEqual(job, want) { t.Errorf("Jobs.ListByBuild returned %+v, want %+v", job, want) } @@ -76,7 +76,7 @@ func TestJobsService_List(t *testing.T) { t.Errorf("Jobs.List returned error: %v", err) } - want := []*Job{{Id: testJobId, AllowFailure: true, Number: "1", State: JobStatusCreated}} + want := []*Job{{Id: Uint(testJobId), AllowFailure: Bool(true), Number: String("1"), State: String(JobStatusCreated)}} if !reflect.DeepEqual(job, want) { t.Errorf("Jobs.List returned %+v, want %+v", job, want) } @@ -97,7 +97,7 @@ func TestJobsService_Cancel(t *testing.T) { t.Errorf("Job.Cancel returned error: %v", err) } - want := &Job{Id: testJobId} + want := &Job{Id: Uint(testJobId)} if !reflect.DeepEqual(job, want) { t.Errorf("Job.Cancel returned %+v, want %+v", job, want) } @@ -118,7 +118,7 @@ func TestJobsService_Restart(t *testing.T) { t.Errorf("Job.Restart returned error: %v", err) } - want := &Job{Id: testJobId} + want := &Job{Id: Uint(testJobId)} if !reflect.DeepEqual(job, want) { t.Errorf("Job.Restart returned %+v, want %+v", job, want) } @@ -139,7 +139,7 @@ func TestJobsService_Debug(t *testing.T) { t.Errorf("Job.Debug returned error: %v", err) } - want := &Job{Id: testJobId} + want := &Job{Id: Uint(testJobId)} if !reflect.DeepEqual(job, want) { t.Errorf("Job.Debug returned %+v, want %+v", job, want) } diff --git a/lint.go b/lint.go index 1bb984c..05244ee 100644 --- a/lint.go +++ b/lint.go @@ -25,8 +25,8 @@ type TravisYml struct { // // Travis CI API docs: https://developer.travis-ci.com/resource/lint type Warning struct { - Key []string `json:"key,omitempty"` - Message string `json:"message,omitempty"` + Key []*string `json:"key,omitempty"` + Message *string `json:"message,omitempty"` *Metadata } diff --git a/lint_test.go b/lint_test.go index 6a407f1..6842609 100644 --- a/lint_test.go +++ b/lint_test.go @@ -29,7 +29,7 @@ func TestLintService_Lint(t *testing.T) { t.Errorf("Lint.Lint returned error: %v", err) } - want := []*Warning{{Key: []string{"test"}, Message: "test!"}} + want := []*Warning{{Key: []*string{String("test")}, Message: String("test!")}} if !reflect.DeepEqual(warnings, want) { t.Errorf("Lint.Lint returned %+v, want %+v", warnings, want) } diff --git a/logs.go b/logs.go index da29f96..bbad480 100644 --- a/logs.go +++ b/logs.go @@ -20,9 +20,9 @@ type LogsService struct { // Log represents a Travis CI job log type Log struct { // The log's id - Id uint `json:"id,omitempty"` + Id *uint `json:"id,omitempty"` // The content of the log - Content string `json:"content,omitempty"` + Content *string `json:"content,omitempty"` // The log parts that form the log LogParts []*LogPart `json:"log_parts,omitempty"` *Metadata @@ -30,9 +30,9 @@ type Log struct { // LogPart is parts that form the log type LogPart struct { - Content string `json:"content,omitempty"` - Final bool `json:"final,omitempty"` - Number uint `json:"number,omitempty"` + Content *string `json:"content,omitempty"` + Final *bool `json:"final,omitempty"` + Number *uint `json:"number,omitempty"` } // FindByJobId fetches a job's log based on it's provided id. diff --git a/logs_test.go b/logs_test.go index b66249d..96bfa00 100644 --- a/logs_test.go +++ b/logs_test.go @@ -28,7 +28,7 @@ func TestLogsService_FindByJobId(t *testing.T) { t.Errorf("Log.FindByJobId returned error: %v", err) } - want := &Log{Id: 1, Content: "test"} + want := &Log{Id: Uint(1), Content: String("test")} if !reflect.DeepEqual(log, want) { t.Errorf("Log.FindByJobId returned %+v, want %+v", log, want) } @@ -49,7 +49,7 @@ func TestLogsService_DeleteByJobId(t *testing.T) { t.Errorf("Log.DeleteByJobId returned error: %v", err) } - want := &Log{Id: 1, Content: "Log removed by XXX at 2017-02-13 16:00:00 UTC"} + want := &Log{Id: Uint(1), Content: String("Log removed by XXX at 2017-02-13 16:00:00 UTC")} if !reflect.DeepEqual(log, want) { t.Errorf("Log.DeleteByJobId returned %+v, want %+v", log, want) } diff --git a/messages.go b/messages.go index a304457..bfd5d97 100644 --- a/messages.go +++ b/messages.go @@ -24,13 +24,13 @@ type MessagesService struct { // Travis CI API docs: https://developer.travis-ci.com/resource/message#message type Message struct { // The message's id - Id uint `json:"id"` + Id *uint `json:"id"` // The message's level - Level string `json:"level"` + Level *string `json:"level"` // The message's key - Key string `json:"key"` + Key *string `json:"key"` // The message's code - Code string `json:"code"` + Code *string `json:"code"` // The message's args Args json.RawMessage `json:"args"` *Metadata diff --git a/messages_test.go b/messages_test.go index 33b6210..2431a4a 100644 --- a/messages_test.go +++ b/messages_test.go @@ -30,7 +30,7 @@ func TestMessagesService_ListByRepoId(t *testing.T) { t.Errorf("Messages.ListByRepoId returned error: %v", err) } - want := &Message{Id: 1, Level: "info", Key: "testKey", Code: "testCode", Args: []byte(`{"test":"test"}`)} + want := &Message{Id: Uint(1), Level: String("info"), Key: String("testKey"), Code: String("testCode"), Args: []byte(`{"test":"test"}`)} if !reflect.DeepEqual(messages[0], want) { t.Errorf("Messages.ListByRepoId returned %+v, want %+v", messages[0], want) } @@ -53,7 +53,7 @@ func TestMessagesService_ListByRepoSlug(t *testing.T) { t.Errorf("Messages.ListByRepoId returned error: %v", err) } - want := &Message{Id: 1, Level: "info", Key: "testKey", Code: "testCode", Args: []byte(`{"test":"test"}`)} + want := &Message{Id: Uint(1), Level: String("info"), Key: String("testKey"), Code: String("testCode"), Args: []byte(`{"test":"test"}`)} if !reflect.DeepEqual(messages[0], want) { t.Errorf("Messages.ListByRepoId returned %+v, want %+v", messages[0], want) } diff --git a/metadata.go b/metadata.go index 45c752d..677a454 100644 --- a/metadata.go +++ b/metadata.go @@ -13,21 +13,21 @@ const ( // Metadata is a metadata returned from the Travis CI API type Metadata struct { // The type of data returned from the API - Type string `json:"@type,omitempty"` + Type *string `json:"@type,omitempty"` // The link for data returned from the API - Href string `json:"@href,omitempty"` + Href *string `json:"@href,omitempty"` // The representation of data returned from the API, standard or minimal - Representation string `json:"@representation,omitempty"` + Representation *string `json:"@representation,omitempty"` // The permissions of data returned from the API - Permissions Permissions `json:"@permissions,omitempty"` + Permissions *Permissions `json:"@permissions,omitempty"` } // IsStandard tells if the struct is in a standard representation func (m *Metadata) IsStandard() bool { - return m.Representation == standardRepresentation + return *m.Representation == standardRepresentation } // IsStandard tells if the struct is in a minimal representation func (m *Metadata) IsMinimal() bool { - return m.Representation == minimalRepresentation + return *m.Representation == minimalRepresentation } diff --git a/metadata_test.go b/metadata_test.go index 17b7bed..76093a0 100644 --- a/metadata_test.go +++ b/metadata_test.go @@ -19,7 +19,7 @@ func TestMetadata_isStandard(t *testing.T) { } for i, c := range cases { - m := Metadata{Representation: c.representation} + m := Metadata{Representation: String(c.representation)} if got := m.IsStandard(); got != c.want { t.Fatalf("#%d invalid: got %v, want: %v", i, got, c.want) @@ -37,7 +37,7 @@ func TestMetadata_isMinimal(t *testing.T) { } for i, c := range cases { - m := Metadata{Representation: c.representation} + m := Metadata{Representation: String(c.representation)} if got := m.IsMinimal(); got != c.want { t.Fatalf("#%d invalid: got %v, want: %v", i, got, c.want) diff --git a/organizations.go b/organizations.go index f2c394c..74c534d 100644 --- a/organizations.go +++ b/organizations.go @@ -22,17 +22,17 @@ type OrganizationsService struct { // Travis CI API docs: https://developer.travis-ci.com/resource/organization#standard-representation type Organization struct { // Value uniquely identifying the organization - Id uint `json:"id,omitempty"` + Id *uint `json:"id,omitempty"` // Login set on GitHub - Login string `json:"login,omitempty"` + Login *string `json:"login,omitempty"` // Name set on GitHub - Name string `json:"name,omitempty"` + Name *string `json:"name,omitempty"` // Id set on GitHub - GithubId uint `json:"github_id,omitempty"` + GithubId *uint `json:"github_id,omitempty"` // Avatar_url set on GitHub - AvatarUrl string `json:"avatar_url,omitempty"` + AvatarUrl *string `json:"avatar_url,omitempty"` // Whether or not the organization has an education account - Education bool `json:"education,omitempty"` + Education *bool `json:"education,omitempty"` // Repositories belonging to this organization. Repositories []*Repository `json:"repositories,omitempty"` // Installation belonging to the organization diff --git a/organizations_integration_test.go b/organizations_integration_test.go index 8d2991c..bcf1b11 100644 --- a/organizations_integration_test.go +++ b/organizations_integration_test.go @@ -27,7 +27,7 @@ func TestOrganizationsService_Integration_Find(t *testing.T) { t.Fatalf("invalid http status: %s", res.Status) } - if got, want := org.Id, uint(integrationOrgId); got != want { + if got, want := *org.Id, uint(integrationOrgId); got != want { t.Fatalf("invalid org id: want: %d, got: %d", want, got) } diff --git a/organizations_test.go b/organizations_test.go index 212856e..f82bf04 100644 --- a/organizations_test.go +++ b/organizations_test.go @@ -30,7 +30,7 @@ func TestOrganizationsService_Find(t *testing.T) { t.Errorf("Organizations.Find returned error: %v", err) } - want := &Organization{Id: 111, Login: "TestOrg", Name: "TestOrg", GithubId: 12345, AvatarUrl: "https:///test.com", Education: false} + want := &Organization{Id: Uint(111), Login: String("TestOrg"), Name: String("TestOrg"), GithubId: Uint(12345), AvatarUrl: String("https:///test.com"), Education: Bool(false)} if !reflect.DeepEqual(org, want) { t.Errorf("Organizations.Find returned %+v, want %+v", org, want) } @@ -53,7 +53,7 @@ func TestOrganizationsService_List(t *testing.T) { t.Errorf("Organizations.List returned error: %v", err) } - want := []*Organization{{Id: 111, Login: "TestOrg", Name: "TestOrg", GithubId: 12345, AvatarUrl: "https:///test.com", Education: false}} + want := []*Organization{{Id: Uint(111), Login: String("TestOrg"), Name: String("TestOrg"), GithubId: Uint(12345), AvatarUrl: String("https:///test.com"), Education: Bool(false)}} if !reflect.DeepEqual(orgs, want) { t.Errorf("Organizations.List returned %+v, want %+v", orgs, want) } diff --git a/owners.go b/owners.go index 8885a4a..ffdec1f 100644 --- a/owners.go +++ b/owners.go @@ -22,17 +22,17 @@ type OwnerService struct { // Travis CI API docs: https://developer.travis-ci.com/resource/owner#standard-representation type Owner struct { // Value uniquely identifying the owner - Id uint `json:"id"` + Id *uint `json:"id"` // User or organization login set on GitHub - Login string `json:"login"` + Login *string `json:"login"` // User or organization name set on GitHub - Name string `json:"name"` + Name *string `json:"name"` // User or organization id set on GitHub - GitHubId uint `json:"github_id"` + GitHubId *uint `json:"github_id"` // Link to user or organization avatar (image) set on GitHub - AvatarUrl string `json:"avatar_url"` + AvatarUrl *string `json:"avatar_url"` // Whether or not the owner has an education account - Education bool `json:"education"` + Education *bool `json:"education"` // Repositories belonging to this account Repositories []*Repository `json:"repositories"` // Installation belonging to the owner diff --git a/owners_integration_test.go b/owners_integration_test.go index db87070..e0c15bf 100644 --- a/owners_integration_test.go +++ b/owners_integration_test.go @@ -25,7 +25,7 @@ func TestOwnerService_Integration_FindByLogin(t *testing.T) { t.Fatalf("invalid http status: %s", res.Status) } - if owner.Login != integrationGitHubOwner { + if *owner.Login != integrationGitHubOwner { t.Fatalf("unexpected owner returned: want %s: got %s", integrationGitHubOwner, owner.Login) } @@ -50,7 +50,7 @@ func TestOwnerService_Integration_FindByGitHubId(t *testing.T) { t.Fatalf("invalid http status: %s", res.Status) } - if owner.GitHubId != integrationGitHubOwnerId { + if *owner.GitHubId != integrationGitHubOwnerId { t.Fatalf("unexpected owner returned: want %s: got %s", integrationGitHubOwner, owner.Login) } } diff --git a/owners_test.go b/owners_test.go index e84d0f2..0c7c379 100644 --- a/owners_test.go +++ b/owners_test.go @@ -30,7 +30,7 @@ func TestOwnerService_FindByLogin(t *testing.T) { t.Errorf("Owner.FindByLogin returned error: %v", err) } - want := &Owner{Id: 1, Login: "shuheiktgw", GitHubId: 1} + want := &Owner{Id: Uint(1), Login: String("shuheiktgw"), GitHubId: Uint(1)} if !reflect.DeepEqual(owner, want) { t.Errorf("Owner.FindByLogin returned %+v, want %+v", owner, want) } @@ -53,7 +53,7 @@ func TestOwnerService_FindByGitHubId(t *testing.T) { t.Errorf("Owner.FindByGitHubId returned error: %v", err) } - want := &Owner{Id: 1, Login: "shuheiktgw", GitHubId: 1} + want := &Owner{Id: Uint(1), Login: String("shuheiktgw"), GitHubId: Uint(1)} if !reflect.DeepEqual(owner, want) { t.Errorf("Owner.FindByGitHubId returned %+v, want %+v", owner, want) } diff --git a/preferences.go b/preferences.go index baf76de..2559c00 100644 --- a/preferences.go +++ b/preferences.go @@ -22,13 +22,21 @@ type PreferencesService struct { // Travis CI API docs: https://developer.travis-ci.com/resource/preference#standard-representation type Preference struct { // The preference's name - Name string `json:"name,omitempty"` + Name *string `json:"name,omitempty"` // The preference's value Value interface{} `json:"value"` *Metadata } -type getPreferencesResponse struct { +// PreferenceBody is body for creating preference +type PreferenceBody struct { + // The preference's name + Name string `json:"name,omitempty"` + // The preference's value + Value interface{} `json:"value"` +} + +type preferencesResponse struct { Preferences []*Preference `json:"preferences,omitempty"` } @@ -70,20 +78,20 @@ func (ps *PreferencesService) List(ctx context.Context) ([]*Preference, *http.Re return nil, nil, err } - var getPreferencesResponse getPreferencesResponse - resp, err := ps.client.Do(ctx, req, &getPreferencesResponse) + var pr preferencesResponse + resp, err := ps.client.Do(ctx, req, &pr) if err != nil { return nil, resp, err } - return getPreferencesResponse.Preferences, resp, err + return pr.Preferences, resp, err } // Update updates the current user's preference based on // the provided preference property // // Travis CI API docs: https://developer.travis-ci.com/resource/preference#update -func (ps *PreferencesService) Update(ctx context.Context, preference *Preference) (*Preference, *http.Response, error) { +func (ps *PreferencesService) Update(ctx context.Context, preference *PreferenceBody) (*Preference, *http.Response, error) { u, err := urlWithOptions(fmt.Sprintf("/preference/%s", preference.Name), nil) if err != nil { return nil, nil, err diff --git a/preferences_integration_test.go b/preferences_integration_test.go index 70e8d2e..a5f945d 100644 --- a/preferences_integration_test.go +++ b/preferences_integration_test.go @@ -28,9 +28,9 @@ func TestPreferencesService_Integration_Find(t *testing.T) { } want := &Preference{ - Name: integrationPreferenceName, + Name: String(integrationPreferenceName), Value: true, - Metadata: &Metadata{Type: "preference", Href: "/v3/preference/build_emails", Representation: "standard"}, + Metadata: &Metadata{Type: String("preference"), Href: String("/v3/preference/build_emails"), Representation: String("standard")}, } if !reflect.DeepEqual(preference, want) { @@ -51,14 +51,14 @@ func TestPreferencesService_Integration_List(t *testing.T) { want := []*Preference{ { - Name: "build_emails", + Name: String("build_emails"), Value: true, - Metadata: &Metadata{Type: "preference", Href: "/v3/preference/build_emails", Representation: "standard"}, + Metadata: &Metadata{Type: String("preference"), Href: String("/v3/preference/build_emails"), Representation: String("standard")}, }, { - Name: "private_insights_visibility", + Name: String("private_insights_visibility"), Value: "private", - Metadata: &Metadata{Type: "preference", Href: "/v3/preference/private_insights_visibility", Representation: "standard"}, + Metadata: &Metadata{Type: String("preference"), Href: String("/v3/preference/private_insights_visibility"), Representation: String("standard")}, }, } @@ -69,7 +69,7 @@ func TestPreferencesService_Integration_List(t *testing.T) { func TestPreferenceServices_Integration_Update(t *testing.T) { // Change build_emails = false - preference, res, err := integrationClient.Preferences.Update(context.TODO(), &Preference{Name: integrationPreferenceName, Value: false}) + preference, res, err := integrationClient.Preferences.Update(context.TODO(), &PreferenceBody{Name: integrationPreferenceName, Value: false}) if err != nil { t.Fatalf("Preference.Update unexpected error occured: %s", err) @@ -80,9 +80,9 @@ func TestPreferenceServices_Integration_Update(t *testing.T) { } want := &Preference{ - Name: integrationPreferenceName, + Name: String(integrationPreferenceName), Value: false, - Metadata: &Metadata{Type: "preference", Href: "/v3/preference/build_emails", Representation: "standard"}, + Metadata: &Metadata{Type: String("preference"), Href: String("/v3/preference/build_emails"), Representation: String("standard")}, } if !reflect.DeepEqual(preference, want) { @@ -90,7 +90,7 @@ func TestPreferenceServices_Integration_Update(t *testing.T) { } // Change build_emails = true - preference, res, err = integrationClient.Preferences.Update(context.TODO(), &Preference{Name: integrationPreferenceName, Value: true}) + preference, res, err = integrationClient.Preferences.Update(context.TODO(), &PreferenceBody{Name: integrationPreferenceName, Value: true}) if err != nil { t.Fatalf("Preference.Update unexpected error occured: %s", err) @@ -101,9 +101,9 @@ func TestPreferenceServices_Integration_Update(t *testing.T) { } want = &Preference{ - Name: integrationPreferenceName, + Name: String(integrationPreferenceName), Value: true, - Metadata: &Metadata{Type: "preference", Href: "/v3/preference/build_emails", Representation: "standard"}, + Metadata: &Metadata{Type: String("preference"), Href: String("/v3/preference/build_emails"), Representation: String("standard")}, } if !reflect.DeepEqual(preference, want) { t.Errorf("Preference.Update returned %+v, want %+v", preference, want) diff --git a/preferences_test.go b/preferences_test.go index 3d0737e..8a30c63 100644 --- a/preferences_test.go +++ b/preferences_test.go @@ -30,7 +30,7 @@ func TestPreferencesService_Find(t *testing.T) { t.Errorf("Preference.Find returned error: %v", err) } - want := &Preference{Name: "builds_email", Value: true} + want := &Preference{Name: String("builds_email"), Value: true} if !reflect.DeepEqual(preference, want) { t.Errorf("Preference.Find returned %+v, want %+v", preference, want) } @@ -51,7 +51,7 @@ func TestPreferencesService_List(t *testing.T) { t.Errorf("Preferences.Find returned error: %v", err) } - want := []*Preference{{Name: "builds_email", Value: true}} + want := []*Preference{{Name: String("builds_email"), Value: true}} if !reflect.DeepEqual(preferences, want) { t.Errorf("Preferences.Find returned %+v, want %+v", preferences, want) } @@ -67,13 +67,13 @@ func TestPreferencesService_Update(t *testing.T) { fmt.Fprint(w, `{"name":"builds_email","value":false}`) }) - preference, _, err := client.Preferences.Update(context.Background(), &Preference{Name: "builds_email", Value: false}) + preference, _, err := client.Preferences.Update(context.Background(), &PreferenceBody{Name: "builds_email", Value: false}) if err != nil { t.Errorf("Preference.Update returned error: %v", err) } - want := &Preference{Name: "builds_email", Value: false} + want := &Preference{Name: String("builds_email"), Value: false} if !reflect.DeepEqual(preference, want) { t.Errorf("Preference.Update returned %+v, want %+v", preference, want) } diff --git a/repositories.go b/repositories.go index edaef31..fe8d1f8 100644 --- a/repositories.go +++ b/repositories.go @@ -24,35 +24,35 @@ type RepositoriesService struct { // Travis CI API docs: https://developer.travis-ci.com/resource/repository#standard-representation type Repository struct { // Value uniquely identifying the repository - Id uint `json:"id"` + Id *uint `json:"id"` // The repository's name on GitHub - Name string `json:"name"` + Name *string `json:"name"` // Same as {repository.owner.name}/{repository.name} - Slug string `json:"slug"` + Slug *string `json:"slug"` // The repository's description from GitHub - Description string `json:"description"` + Description *string `json:"description"` // The repository's id on GitHub - GitHubId uint `json:"github_id"` + GitHubId *uint `json:"github_id"` // The main programming language used according to GitHub - GitHubLanguage string `json:"github_language"` + GitHubLanguage *string `json:"github_language"` // Whether or not this repository is currently enabled on Travis CI - Active bool `json:"active"` + Active *bool `json:"active"` // Whether or not this repository is private - Private bool `json:"private"` + Private *bool `json:"private"` // GitHub user or organization the repository belongs to Owner *Owner `json:"owner"` // The default branch on GitHub DefaultBranch *Branch `json:"default_branch"` // Whether or not this repository is starred - Starred bool `json:"starred"` + Starred *bool `json:"starred"` // Whether or not this repository is managed by a GitHub App installation - ManagedByInstallation bool `json:"managed_by_installation"` + ManagedByInstallation *bool `json:"managed_by_installation"` // Whether or not this repository runs builds on travis-ci.org (may also be null) - ActiveOnOrg bool `json:"active_on_org"` + ActiveOnOrg *bool `json:"active_on_org"` // The repository's migration_status - MigrationStatus string `json:"migration_status"` + MigrationStatus *string `json:"migration_status"` // The repository's allow_migration - AllowMigration bool `json:"allow_migration"` + AllowMigration *bool `json:"allow_migration"` *Metadata } diff --git a/repositories_integration_test.go b/repositories_integration_test.go index 0966edf..8703686 100644 --- a/repositories_integration_test.go +++ b/repositories_integration_test.go @@ -76,7 +76,7 @@ func TestRepositoriesService_Integration_Find(t *testing.T) { t.Fatalf("invalid http status: %s", res.Status) } - if got, want := repo.Slug, integrationRepoSlug; got != want { + if got, want := *repo.Slug, integrationRepoSlug; got != want { t.Fatalf("unexpected repository returned: want %s: got %s", want, got) } @@ -96,7 +96,7 @@ func TestRepositoriesService_Integration_Activation(t *testing.T) { t.Fatalf("invalid http status: %s", res.Status) } - if repo.Slug != integrationRepoSlug { + if *repo.Slug != integrationRepoSlug { t.Fatalf("unexpected repository returned: want %s: got %s", integrationRepoSlug, repo.Slug) } @@ -110,17 +110,13 @@ func TestRepositoriesService_Integration_Activation(t *testing.T) { t.Fatalf("invalid http status: %s", res.Status) } - if repo.Slug != integrationRepoSlug { + if *repo.Slug != integrationRepoSlug { t.Fatalf("unexpected repository returned: want %s: got %s", integrationRepoSlug, repo.Slug) } } func TestRepositoriesService_Integration_Migrate(t *testing.T) { - _, res, err := integrationClient.Repositories.Migrate(context.TODO(), integrationRepoSlug) - - if err != nil { - t.Fatalf("unexpected error occured: %s", err) - } + _, res, _ := integrationClient.Repositories.Migrate(context.TODO(), integrationRepoSlug) // The repository is not allowed to migrate as of May 5th, 2019 if res.StatusCode != http.StatusForbidden { @@ -139,7 +135,7 @@ func TestRepositoriesService_Integration_Star(t *testing.T) { t.Fatalf("invalid http status: %s", res.Status) } - if repo.Slug != integrationRepoSlug { + if *repo.Slug != integrationRepoSlug { t.Fatalf("unexpected repository returned: want %s: got %s", integrationRepoSlug, repo.Slug) } @@ -153,7 +149,7 @@ func TestRepositoriesService_Integration_Star(t *testing.T) { t.Fatalf("invalid http status: %s", res.Status) } - if repo.Slug != integrationRepoSlug { + if *repo.Slug != integrationRepoSlug { t.Fatalf("unexpected repository returned: want %s: got %s", integrationRepoSlug, repo.Slug) } } diff --git a/repositories_test.go b/repositories_test.go index 91e7c94..c32a5da 100644 --- a/repositories_test.go +++ b/repositories_test.go @@ -30,7 +30,7 @@ func TestRepositoriesService_List(t *testing.T) { t.Errorf("Repository.List returned error: %v", err) } - want := &Repository{Id: 1, Name: "go-travis-test", Slug: "shuheiktgw/go-travis-test"} + want := &Repository{Id: Uint(1), Name: String("go-travis-test"), Slug: String("shuheiktgw/go-travis-test")} if !reflect.DeepEqual(repos[0], want) { t.Errorf("Repository.List returned %+v, want %+v", repos[0], want) } @@ -54,7 +54,7 @@ func TestRepositoriesService_ListByOwner(t *testing.T) { t.Errorf("Repository.ListByOwner returned error: %v", err) } - want := &Repository{Id: 1, Name: "go-travis-test", Slug: "shuheiktgw/go-travis-test"} + want := &Repository{Id: Uint(1), Name: String("go-travis-test"), Slug: String("shuheiktgw/go-travis-test")} if !reflect.DeepEqual(repos[0], want) { t.Errorf("Repository.ListByOwner returned %+v, want %+v", repos[0], want) } @@ -78,7 +78,7 @@ func TestRepositoriesService_ListByGitHubId(t *testing.T) { t.Errorf("Repository.ListByOwner returned error: %v", err) } - want := &Repository{Id: 1, Name: "go-travis-test", Slug: "shuheiktgw/go-travis-test"} + want := &Repository{Id: Uint(1), Name: String("go-travis-test"), Slug: String("shuheiktgw/go-travis-test")} if !reflect.DeepEqual(repos[0], want) { t.Errorf("Repository.ListByOwner returned %+v, want %+v", repos[0], want) } @@ -101,7 +101,7 @@ func TestRepositoriesService_Find(t *testing.T) { t.Errorf("Repository.Find returned error: %v", err) } - want := &Repository{Id: 1, Name: "go-travis-test", Slug: "shuheiktgw/go-travis-test"} + want := &Repository{Id: Uint(1), Name: String("go-travis-test"), Slug: String("shuheiktgw/go-travis-test")} if !reflect.DeepEqual(repo, want) { t.Errorf("Repository.Find returned %+v, want %+v", repo, want) } @@ -122,7 +122,7 @@ func TestRepositoriesService_Activate(t *testing.T) { t.Errorf("Repository.Activate returned error: %v", err) } - want := &Repository{Id: 1, Name: "go-travis-test", Slug: "shuheiktgw/go-travis-test"} + want := &Repository{Id: Uint(1), Name: String("go-travis-test"), Slug: String("shuheiktgw/go-travis-test")} if !reflect.DeepEqual(repo, want) { t.Errorf("Repository.Activate returned %+v, want %+v", repo, want) } @@ -143,7 +143,7 @@ func TestRepositoriesService_Deactivate(t *testing.T) { t.Errorf("Repository.Deactivate returned error: %v", err) } - want := &Repository{Id: 1, Name: "go-travis-test", Slug: "shuheiktgw/go-travis-test"} + want := &Repository{Id: Uint(1), Name: String("go-travis-test"), Slug: String("shuheiktgw/go-travis-test")} if !reflect.DeepEqual(repo, want) { t.Errorf("Repository.Deactivate returned %+v, want %+v", repo, want) } @@ -164,7 +164,7 @@ func TestRepositoriesService_Migrate(t *testing.T) { t.Errorf("Repository.Migrate returned error: %v", err) } - want := &Repository{Id: 1, Name: "go-travis-test", Slug: "shuheiktgw/go-travis-test"} + want := &Repository{Id: Uint(1), Name: String("go-travis-test"), Slug: String("shuheiktgw/go-travis-test")} if !reflect.DeepEqual(repo, want) { t.Errorf("Repository.Migrate returned %+v, want %+v", repo, want) } @@ -185,7 +185,7 @@ func TestRepositoriesService_Star(t *testing.T) { t.Errorf("Repository.Star returned error: %v", err) } - want := &Repository{Id: 1, Name: "go-travis-test", Slug: "shuheiktgw/go-travis-test"} + want := &Repository{Id: Uint(1), Name: String("go-travis-test"), Slug: String("shuheiktgw/go-travis-test")} if !reflect.DeepEqual(repo, want) { t.Errorf("Repository.Star returned %+v, want %+v", repo, want) } @@ -206,7 +206,7 @@ func TestRepositoriesService_Unstar(t *testing.T) { t.Errorf("Repository.Unstar returned error: %v", err) } - want := &Repository{Id: 1, Name: "go-travis-test", Slug: "shuheiktgw/go-travis-test"} + want := &Repository{Id: Uint(1), Name: String("go-travis-test"), Slug: String("shuheiktgw/go-travis-test")} if !reflect.DeepEqual(repo, want) { t.Errorf("Repository.Unstar returned %+v, want %+v", repo, want) } diff --git a/requests.go b/requests.go index 41c7650..d63a330 100644 --- a/requests.go +++ b/requests.go @@ -24,17 +24,17 @@ type RequestsService struct { // // Travis CI API docs: https://developer.travis-ci.com/resource/request#standard-representation type Request struct { // Value uniquely identifying the request - Id uint `json:"id,omitempty"` + Id *uint `json:"id,omitempty"` // The state of a request (eg. whether it has been processed or not) - State string `json:"state,omitempty"` + State *string `json:"state,omitempty"` // The result of the request (eg. rejected or approved) - Result string `json:"result,omitempty"` + Result *string `json:"result,omitempty"` // Travis-ci status message attached to the request. - Message string `json:"message,omitempty"` + Message *string `json:"message,omitempty"` // GitHub user or organization the request belongs to Repository *Repository `json:"repository,omitempty"` // Name of the branch requested to be built - BranchName string `json:"branch_name,omitempty"` + BranchName *string `json:"branch_name,omitempty"` // The commit the request is associated with Commit *Commit `json:"commit,omitempty"` // The request's builds @@ -42,13 +42,13 @@ type Request struct { // GitHub user or organization the request belongs to Owner *Owner `json:"owner,omitempty"` // When Travis CI created the request - CreatedAt string `json:"created_at,omitempty"` + CreatedAt *string `json:"created_at,omitempty"` // Origin of request (push, pull request, api) - EventType string `json:"event_type,omitempty"` + EventType *string `json:"event_type,omitempty"` // The base commit the request is associated with - BaseCommit string `json:"base_commit,omitempty"` + BaseCommit *string `json:"base_commit,omitempty"` // The head commit the request is associated with - HeadCommit string `json:"head_commit,omitempty"` + HeadCommit *string `json:"head_commit,omitempty"` *Metadata } diff --git a/requests_integration_test.go b/requests_integration_test.go index 5620550..4d5ecbd 100644 --- a/requests_integration_test.go +++ b/requests_integration_test.go @@ -25,7 +25,7 @@ func TestRequestsService_Integration_CreateAndFindById(t *testing.T) { } opt := RequestOption{Include: []string{"request.repository", "request.commit", "request.builds", "request.owner"}} - request, res, err := integrationClient.Requests.FindByRepoId(context.TODO(), integrationRepoId, createdRequest.Id, &opt) + request, res, err := integrationClient.Requests.FindByRepoId(context.TODO(), integrationRepoId, *createdRequest.Id, &opt) if err != nil { t.Fatalf("unexpected error occured: %s", err) @@ -35,7 +35,7 @@ func TestRequestsService_Integration_CreateAndFindById(t *testing.T) { t.Fatalf("invalid http status: %s", res.Status) } - if request.Id != createdRequest.Id { + if *request.Id != *createdRequest.Id { t.Fatalf("unexpected request is retrieved: got request id: %d, want request id: %d", request.Id, createdRequest.Id) } @@ -68,7 +68,7 @@ func TestRequestsService_Integration_CreateAndFindBySlug(t *testing.T) { } opt := RequestOption{Include: []string{"request.repository", "request.commit", "request.builds", "request.owner"}} - request, res, err := integrationClient.Requests.FindByRepoSlug(context.TODO(), integrationRepoSlug, createdRequest.Id, &opt) + request, res, err := integrationClient.Requests.FindByRepoSlug(context.TODO(), integrationRepoSlug, *createdRequest.Id, &opt) if err != nil { t.Fatalf("unexpected error occured: %s", err) @@ -78,7 +78,7 @@ func TestRequestsService_Integration_CreateAndFindBySlug(t *testing.T) { t.Fatalf("invalid http status: %s", res.Status) } - if request.Id != createdRequest.Id { + if *request.Id != *createdRequest.Id { t.Fatalf("unexpected request is retrieved: got request id: %d, want request id: %d", request.Id, createdRequest.Id) } @@ -120,7 +120,7 @@ func TestRequestsService_CreateAndListById(t *testing.T) { t.Fatalf("invalid http status: %s", res.Status) } - if requests[0].Id != createdRequest.Id { + if *requests[0].Id != *createdRequest.Id { t.Fatalf("unexpected request is retrieved: got request id: %d, want request id: %d", requests[0].Id, createdRequest.Id) } } @@ -146,7 +146,7 @@ func TestRequestsService_CreateAndListBySlug(t *testing.T) { t.Fatalf("invalid http status: %s", res.Status) } - if requests[0].Id != createdRequest.Id { + if *requests[0].Id != *createdRequest.Id { t.Fatalf("unexpected request is retrieved: got request id: %d, want request id: %d", requests[0].Id, createdRequest.Id) } } diff --git a/requests_test.go b/requests_test.go index a1d75c1..10f9521 100644 --- a/requests_test.go +++ b/requests_test.go @@ -32,7 +32,7 @@ func TestRequestsService_FindByRepoId(t *testing.T) { t.Errorf("RequestService.FindByRepoId returned error: %v", err) } - want := &Request{Id: 1, State: "processed", Result: "rejected"} + want := &Request{Id: Uint(1), State: String("processed"), Result: String("rejected")} if !reflect.DeepEqual(repo, want) { t.Errorf("RequestService.FindByRepoId returned %+v, want %+v", repo, want) } @@ -55,7 +55,7 @@ func TestRequestsService_FindByRepoSlug(t *testing.T) { t.Errorf("RequestService.FindByRepoId returned error: %v", err) } - want := &Request{Id: 1, State: "processed", Result: "rejected"} + want := &Request{Id: Uint(1), State: String("processed"), Result: String("rejected")} if !reflect.DeepEqual(repo, want) { t.Errorf("RequestService.FindByRepoId returned %+v, want %+v", repo, want) } @@ -78,7 +78,7 @@ func TestRequestsService_ListByRepoId(t *testing.T) { t.Errorf("RequestsService.FindByRepoId returned error: %v", err) } - want := []*Request{{Id: 1, State: "processed", Result: "rejected"}} + want := []*Request{{Id: Uint(1), State: String("processed"), Result: String("rejected")}} if !reflect.DeepEqual(repos, want) { t.Errorf("RequestsService.FindByRepoId returned %+v, want %+v", repos, want) } @@ -101,7 +101,7 @@ func TestRequestsService_ListByRepoSlug(t *testing.T) { t.Errorf("RequestsService.FindByRepoSlug returned error: %v", err) } - want := []*Request{{Id: 1, State: "processed", Result: "rejected"}} + want := []*Request{{Id: Uint(1), State: String("processed"), Result: String("rejected")}} if !reflect.DeepEqual(repos, want) { t.Errorf("RequestsService.FindByRepoSlug returned %+v, want %+v", repos, want) } @@ -123,7 +123,7 @@ func TestRequestsService_CreateByRepoId(t *testing.T) { t.Errorf("RequestsService.CreateByRepoId returned error: %v", err) } - want := &Request{Id: 1, Message: "message!"} + want := &Request{Id: Uint(1), Message: String("message!")} if !reflect.DeepEqual(repo, want) { t.Errorf("RequestsService.CreateByRepoId returned %+v, want %+v", repo, want) } @@ -145,7 +145,7 @@ func TestRequestsService_CreateByRepoSlug(t *testing.T) { t.Errorf("RequestsService.CreateByRepoSlug returned error: %v", err) } - want := &Request{Id: 1, Message: "message!"} + want := &Request{Id: Uint(1), Message: String("message!")} if !reflect.DeepEqual(repo, want) { t.Errorf("RequestsService.CreateByRepoSlug returned %+v, want %+v", repo, want) } diff --git a/settings.go b/settings.go index 2796235..68ec977 100644 --- a/settings.go +++ b/settings.go @@ -23,15 +23,21 @@ type SettingsService struct { // Travis CI API docs: https://developer.travis-ci.com/resource/setting#standard-representation type Setting struct { // The setting's name - Name string `json:"name,omitempty"` + Name *string `json:"name,omitempty"` // The setting's value // Currently value can be boolean or integer Value interface{} `json:"value,omitempty"` *Metadata } -// getSettingsResponse represents response from the settings endpoints -type getSettingsResponse struct { +// SettingBody is a body to update setting +type SettingBody struct { + Name string `json:"name,omitempty"` + Value interface{} `json:"value,omitempty"` +} + +// settingsResponse represents response from the settings endpoints +type settingsResponse struct { Settings []*Setting `json:"settings,omitempty"` } @@ -110,13 +116,13 @@ func (ss *SettingsService) ListByRepoId(ctx context.Context, repoId uint) ([]*Se return nil, nil, err } - var getSettingsResponse getSettingsResponse - resp, err := ss.client.Do(ctx, req, &getSettingsResponse) + var sr settingsResponse + resp, err := ss.client.Do(ctx, req, &sr) if err != nil { return nil, resp, err } - return getSettingsResponse.Settings, resp, err + return sr.Settings, resp, err } // ListByRepoSlug fetches a list of settings of given repository slug @@ -133,19 +139,19 @@ func (ss *SettingsService) ListByRepoSlug(ctx context.Context, repoSlug string) return nil, nil, err } - var getSettingsResponse getSettingsResponse - resp, err := ss.client.Do(ctx, req, &getSettingsResponse) + var sr settingsResponse + resp, err := ss.client.Do(ctx, req, &sr) if err != nil { return nil, resp, err } - return getSettingsResponse.Settings, resp, err + return sr.Settings, resp, err } // UpdateByRepoId updates a setting with setting property // // Travis CI API docs: https://developer.travis-ci.com/resource/setting#update -func (ss *SettingsService) UpdateByRepoId(ctx context.Context, repoId uint, setting *Setting) (*Setting, *http.Response, error) { +func (ss *SettingsService) UpdateByRepoId(ctx context.Context, repoId uint, setting *SettingBody) (*Setting, *http.Response, error) { u, err := urlWithOptions(fmt.Sprintf("/repo/%d/setting/%s", repoId, setting.Name), nil) if err != nil { return nil, nil, err @@ -174,7 +180,7 @@ func (ss *SettingsService) UpdateByRepoId(ctx context.Context, repoId uint, sett // UpdateByRepoSlug updates a setting with setting property // // Travis CI API docs: https://developer.travis-ci.com/resource/setting#update -func (ss *SettingsService) UpdateByRepoSlug(ctx context.Context, repoSlug string, setting *Setting) (*Setting, *http.Response, error) { +func (ss *SettingsService) UpdateByRepoSlug(ctx context.Context, repoSlug string, setting *SettingBody) (*Setting, *http.Response, error) { u, err := urlWithOptions(fmt.Sprintf("/repo/%s/setting/%s", url.QueryEscape(repoSlug), setting.Name), nil) if err != nil { return nil, nil, err diff --git a/settings_integration_test.go b/settings_integration_test.go index cc2897a..3e0c30c 100644 --- a/settings_integration_test.go +++ b/settings_integration_test.go @@ -27,13 +27,13 @@ func TestSettingsService_Integration_FindByRepoId(t *testing.T) { } want := &Setting{ - Name: BuildsOnlyWithTravisYmlSetting, + Name: String(BuildsOnlyWithTravisYmlSetting), Value: false, Metadata: &Metadata{ - Type: "setting", - Href: "/repo/20783933/setting/builds_only_with_travis_yml", - Representation: "standard", - Permissions: Permissions{"read": true, "write": true}, + Type: String("setting"), + Href: String("/repo/20783933/setting/builds_only_with_travis_yml"), + Representation: String("standard"), + Permissions: &Permissions{"read": true, "write": true}, }, } @@ -54,13 +54,13 @@ func TestSettingsService_Integration_FindByRepoSlug(t *testing.T) { } want := &Setting{ - Name: BuildsOnlyWithTravisYmlSetting, + Name: String(BuildsOnlyWithTravisYmlSetting), Value: false, Metadata: &Metadata{ - Type: "setting", - Href: "/repo/20783933/setting/builds_only_with_travis_yml", - Representation: "standard", - Permissions: Permissions{"read": true, "write": true}, + Type: String("setting"), + Href: String("/repo/20783933/setting/builds_only_with_travis_yml"), + Representation: String("standard"), + Permissions: &Permissions{"read": true, "write": true}, }, } @@ -102,7 +102,7 @@ func TestSettingsService_Integration_ListByRepoSlug(t *testing.T) { } func TestSettingsService_Integration_UpdateByRepoIdAndSlug(t *testing.T) { - s := Setting{Name: BuildsOnlyWithTravisYmlSetting, Value: true} + s := SettingBody{Name: BuildsOnlyWithTravisYmlSetting, Value: true} setting, res, err := integrationClient.Settings.UpdateByRepoId(context.TODO(), integrationRepoId, &s) if err != nil { @@ -114,13 +114,13 @@ func TestSettingsService_Integration_UpdateByRepoIdAndSlug(t *testing.T) { } want := &Setting{ - Name: BuildsOnlyWithTravisYmlSetting, + Name: String(BuildsOnlyWithTravisYmlSetting), Value: true, Metadata: &Metadata{ - Type: "setting", - Href: "/repo/20783933/setting/builds_only_with_travis_yml", - Representation: "standard", - Permissions: Permissions{"read": true, "write": true}, + Type: String("setting"), + Href: String("/repo/20783933/setting/builds_only_with_travis_yml"), + Representation: String("standard"), + Permissions: &Permissions{"read": true, "write": true}, }, } @@ -130,7 +130,7 @@ func TestSettingsService_Integration_UpdateByRepoIdAndSlug(t *testing.T) { time.Sleep(2 * time.Second) - s = Setting{Name: BuildsOnlyWithTravisYmlSetting, Value: false} + s = SettingBody{Name: BuildsOnlyWithTravisYmlSetting, Value: false} setting, res, err = integrationClient.Settings.UpdateByRepoSlug(context.TODO(), integrationRepoSlug, &s) if err != nil { @@ -142,13 +142,13 @@ func TestSettingsService_Integration_UpdateByRepoIdAndSlug(t *testing.T) { } want = &Setting{ - Name: BuildsOnlyWithTravisYmlSetting, + Name: String(BuildsOnlyWithTravisYmlSetting), Value: false, Metadata: &Metadata{ - Type: "setting", - Href: "/repo/20783933/setting/builds_only_with_travis_yml", - Representation: "standard", - Permissions: Permissions{"read": true, "write": true}, + Type: String("setting"), + Href: String("/repo/20783933/setting/builds_only_with_travis_yml"), + Representation: String("standard"), + Permissions: &Permissions{"read": true, "write": true}, }, } diff --git a/settings_test.go b/settings_test.go index 3a49951..b7dab9f 100644 --- a/settings_test.go +++ b/settings_test.go @@ -28,7 +28,7 @@ func TestSettingsService_FindByRepoId(t *testing.T) { t.Errorf("Settings.FindByRepoId returned error: %v", err) } - want := &Setting{Name: BuildsOnlyWithTravisYmlSetting, Value: false} + want := &Setting{Name: String(BuildsOnlyWithTravisYmlSetting), Value: false} if !reflect.DeepEqual(setting, want) { t.Errorf("Settings.FindByRepoId returned %+v, want %+v", setting, want) } @@ -49,7 +49,7 @@ func TestSettingsService_FindByRepoSlug(t *testing.T) { t.Errorf("Settings.FindByRepoSlug returned error: %v", err) } - want := &Setting{Name: BuildsOnlyWithTravisYmlSetting, Value: false} + want := &Setting{Name: String(BuildsOnlyWithTravisYmlSetting), Value: false} if !reflect.DeepEqual(setting, want) { t.Errorf("Settings.FindByRepoSlug returned %+v, want %+v", setting, want) } @@ -65,14 +65,14 @@ func TestSettingsService_UpdateByRepoId(t *testing.T) { fmt.Fprint(w, `{"name":"builds_only_with_travis_yml","value":true}`) }) - s := Setting{Name: BuildsOnlyWithTravisYmlSetting, Value: true} + s := SettingBody{Name: BuildsOnlyWithTravisYmlSetting, Value: true} setting, _, err := client.Settings.UpdateByRepoId(context.Background(), testRepoId, &s) if err != nil { t.Errorf("Settings.UpdateByRepoId returned error: %v", err) } - want := &Setting{Name: BuildsOnlyWithTravisYmlSetting, Value: true} + want := &Setting{Name: String(BuildsOnlyWithTravisYmlSetting), Value: true} if !reflect.DeepEqual(setting, want) { t.Errorf("Settings.UpdateByRepoId returned %+v, want %+v", setting, want) } @@ -88,14 +88,14 @@ func TestSettingsService_UpdateByRepoSlug(t *testing.T) { fmt.Fprint(w, `{"name":"builds_only_with_travis_yml","value":true}`) }) - s := Setting{Name: BuildsOnlyWithTravisYmlSetting, Value: true} + s := SettingBody{Name: BuildsOnlyWithTravisYmlSetting, Value: true} setting, _, err := client.Settings.UpdateByRepoSlug(context.Background(), testRepoSlug, &s) if err != nil { t.Errorf("Settings.UpdateByRepoSlug returned error: %v", err) } - want := &Setting{Name: BuildsOnlyWithTravisYmlSetting, Value: true} + want := &Setting{Name: String(BuildsOnlyWithTravisYmlSetting), Value: true} if !reflect.DeepEqual(setting, want) { t.Errorf("Settings.UpdateByRepoSlug returned %+v, want %+v", setting, want) } diff --git a/stages.go b/stages.go index 1b49d18..be21a1d 100644 --- a/stages.go +++ b/stages.go @@ -22,17 +22,17 @@ type StagesService struct { // Travis CI API docs: https://developer.travis-ci.com/resource/stage#standard-representation type Stage struct { // Value uniquely identifying the stage - Id uint `json:"id,omitempty"` + Id *uint `json:"id,omitempty"` // Incremental number for a stage - Number uint `json:"number,omitempty"` + Number *uint `json:"number,omitempty"` // The name of the stage - Name string `json:"name,omitempty"` + Name *string `json:"name,omitempty"` // Current state of the stage - State string `json:"state,omitempty"` + State *string `json:"state,omitempty"` // When the stage started - StartedAt string `json:"started_at,omitempty"` + StartedAt *string `json:"started_at,omitempty"` // When the stage finished - FinishedAt string `json:"finished_at,omitempty"` + FinishedAt *string `json:"finished_at,omitempty"` // The jobs of a stage. Jobs []*Job `json:"jobs,omitempty"` *Metadata diff --git a/stages_test.go b/stages_test.go index 67ea3cc..99838f5 100644 --- a/stages_test.go +++ b/stages_test.go @@ -31,7 +31,7 @@ func TestStagesService_ListByBuild(t *testing.T) { t.Errorf("Repository.List returned error: %v", err) } - want := &Stage{Id: 1, Number: 2, Name: "Test"} + want := &Stage{Id: Uint(1), Number: Uint(2), Name: String("Test")} if !reflect.DeepEqual(stages[0], want) { t.Errorf("Stages.ListByBuild returned %+v, want %+v", stages[0], want) } diff --git a/tags.go b/tags.go index d9ca3b5..cf1d1f1 100644 --- a/tags.go +++ b/tags.go @@ -8,10 +8,10 @@ package travis // Tag is a standard representation of a Travis CI tag type Tag struct { // Value uniquely identifying a repository of the build belongs to - RepositoryId uint `json:"repository_id"` + RepositoryId *uint `json:"repository_id"` // Name of the tag - Name string `json:"name,omitempty"` + Name *string `json:"name,omitempty"` // Id of a last build on the branch - LastBuildId uint `json:"last_build_id"` + LastBuildId *uint `json:"last_build_id"` *Metadata } diff --git a/travis.go b/travis.go index ee2fc4b..6fd1238 100644 --- a/travis.go +++ b/travis.go @@ -312,3 +312,15 @@ func withContext(ctx context.Context, req *http.Request) *http.Request { // Permissions represents permissions of Travis CI API type Permissions map[string]bool + +// Bool is a helper routine that allocates a new bool value +// to store v and returns a pointer to it. +func Bool(v bool) *bool { return &v } + +// Uint is a helper routine that allocates a new Uint value +// to store v and returns a pointer to it. +func Uint(v uint) *uint { return &v } + +// String is a helper routine that allocates a new string value +// to store v and returns a pointer to it. +func String(v string) *string { return &v } diff --git a/users.go b/users.go index 5d22098..62ca1fd 100644 --- a/users.go +++ b/users.go @@ -22,27 +22,27 @@ type UserService struct { // Travis CI API docs: https://developer.travis-ci.com/resource/user#standard-representation type User struct { // Value uniquely identifying the user - Id uint `json:"id,omitempty"` + Id *uint `json:"id,omitempty"` // Login set on Github - Login string `json:"login,omitempty"` + Login *string `json:"login,omitempty"` // Name set on GitHub - Name string `json:"name,omitempty"` + Name *string `json:"name,omitempty"` // Id set on GitHub - GithubId uint `json:"github_id,omitempty"` + GithubId *uint `json:"github_id,omitempty"` // Avatar URL set on GitHub - AvatarUrl string `json:"avatar_url,omitempty"` + AvatarUrl *string `json:"avatar_url,omitempty"` // Whether or not the user has an education account - Education bool `json:"education,omitempty"` + Education *bool `json:"education,omitempty"` // Whether or not the user is currently being synced with Github - IsSyncing bool `json:"is_syncing,omitempty"` + IsSyncing *bool `json:"is_syncing,omitempty"` // The last time the user was synced with GitHub - SyncedAt string `json:"synced_at,omitempty"` + SyncedAt *string `json:"synced_at,omitempty"` // Repositories belonging to this user Repositories []*Repository `json:"repositories,omitempty"` // Installation belonging to the user Installation []*Repository `json:"installation,omitempty"` // The user's emails - Emails []string `json:"emails,omitempty"` + Emails []*string `json:"emails,omitempty"` *Metadata } diff --git a/users_integration_test.go b/users_integration_test.go index 72c6a24..e8f61a4 100644 --- a/users_integration_test.go +++ b/users_integration_test.go @@ -25,7 +25,7 @@ func TestUserService_Integration_Current(t *testing.T) { t.Fatalf("invalid http status: %s", res.Status) } - if user.Id != integrationUserId { + if *user.Id != integrationUserId { t.Fatalf("unexpected user returned: want user_id: %d, got user_id %d", integrationUserId, user.Id) } @@ -50,7 +50,7 @@ func TestUserService_Integration_Find(t *testing.T) { t.Fatalf("invalid http status: %s", res.Status) } - if user.Id != integrationUserId { + if *user.Id != integrationUserId { t.Fatalf("unexpected user returned: want user_id: %d, got user_id %d", integrationUserId, user.Id) } @@ -74,7 +74,7 @@ func TestUserService_Integration_Sync(t *testing.T) { t.Fatalf("invalid http status: %s", res.Status) } - if user.Id != integrationUserId { + if *user.Id != integrationUserId { t.Fatalf("UserService.Find returned id %+v, want %+v", user.Id, integrationUserId) } } diff --git a/users_test.go b/users_test.go index 96231fe..b1c8699 100644 --- a/users_test.go +++ b/users_test.go @@ -32,7 +32,7 @@ func TestUserService_Current(t *testing.T) { t.Errorf("UserService.Current returned error: %v", err) } - want := &User{Id: 1, Login: "shuheiktgw", Name: "shuheiktgw", GithubId: 1} + want := &User{Id: Uint(1), Login: String("shuheiktgw"), Name: String("shuheiktgw"), GithubId: Uint(1)} if !reflect.DeepEqual(repo, want) { t.Errorf("UserService.Current returned %+v, want %+v", repo, want) } @@ -55,7 +55,7 @@ func TestUserService_Find(t *testing.T) { t.Errorf("UserService.Find returned error: %v", err) } - want := &User{Id: 1, Login: "shuheiktgw", Name: "shuheiktgw", GithubId: 1} + want := &User{Id: Uint(1), Login: String("shuheiktgw"), Name: String("shuheiktgw"), GithubId: Uint(1)} if !reflect.DeepEqual(repo, want) { t.Errorf("UserService.Find returned %+v, want %+v", repo, want) } @@ -76,7 +76,7 @@ func TestUserService_Sync(t *testing.T) { t.Errorf("UserService.Sync returned error: %v", err) } - want := &User{Id: 1, Login: "shuheiktgw", Name: "shuheiktgw", GithubId: 1} + want := &User{Id: Uint(1), Login: String("shuheiktgw"), Name: String("shuheiktgw"), GithubId: Uint(1)} if !reflect.DeepEqual(repo, want) { t.Errorf("UserService.Sync returned %+v, want %+v", repo, want) }