From 0af462f06fbd5fd466073b1718ace1c7e78b9283 Mon Sep 17 00:00:00 2001 From: Patrick O'Brien <51363872+lyspj@users.noreply.github.com> Date: Mon, 6 Feb 2023 12:26:05 +0100 Subject: [PATCH 1/2] Add Account field to MarketplacePurchase struct (#2659) Fixes: #2658. --- github/apps_marketplace.go | 12 +++++ github/github-accessors.go | 64 +++++++++++++++++++++++++++ github/github-accessors_test.go | 77 +++++++++++++++++++++++++++++++++ 3 files changed, 153 insertions(+) diff --git a/github/apps_marketplace.go b/github/apps_marketplace.go index 8253013684..32889abd24 100644 --- a/github/apps_marketplace.go +++ b/github/apps_marketplace.go @@ -46,6 +46,7 @@ type MarketplacePlan struct { // MarketplacePurchase represents a GitHub Apps Marketplace Purchase. type MarketplacePurchase struct { + Account *MarketplacePurchaseAccount `json:"account,omitempty"` // BillingCycle can be one of the values "yearly", "monthly" or nil. BillingCycle *string `json:"billing_cycle,omitempty"` NextBillingDate *Timestamp `json:"next_billing_date,omitempty"` @@ -75,6 +76,17 @@ type MarketplacePlanAccount struct { MarketplacePendingChange *MarketplacePendingChange `json:"marketplace_pending_change,omitempty"` } +// MarketplacePurchaseAccount represents a GitHub Account (user or organization) for a Purchase. +type MarketplacePurchaseAccount struct { + URL *string `json:"url,omitempty"` + Type *string `json:"type,omitempty"` + ID *int64 `json:"id,omitempty"` + Login *string `json:"login,omitempty"` + OrganizationBillingEmail *string `json:"organization_billing_email,omitempty"` + Email *string `json:"email,omitempty"` + NodeID *string `json:"node_id,omitempty"` +} + // ListPlans lists all plans for your Marketplace listing. // // GitHub API docs: https://docs.github.com/en/rest/apps#list-plans diff --git a/github/github-accessors.go b/github/github-accessors.go index 3110d8132d..433d16f303 100644 --- a/github/github-accessors.go +++ b/github/github-accessors.go @@ -9174,6 +9174,14 @@ func (m *MarketplacePlanAccount) GetURL() string { return *m.URL } +// GetAccount returns the Account field. +func (m *MarketplacePurchase) GetAccount() *MarketplacePurchaseAccount { + if m == nil { + return nil + } + return m.Account +} + // GetBillingCycle returns the BillingCycle field if it's non-nil, zero value otherwise. func (m *MarketplacePurchase) GetBillingCycle() string { if m == nil || m.BillingCycle == nil { @@ -9230,6 +9238,62 @@ func (m *MarketplacePurchase) GetUpdatedAt() Timestamp { return *m.UpdatedAt } +// GetEmail returns the Email field if it's non-nil, zero value otherwise. +func (m *MarketplacePurchaseAccount) GetEmail() string { + if m == nil || m.Email == nil { + return "" + } + return *m.Email +} + +// GetID returns the ID field if it's non-nil, zero value otherwise. +func (m *MarketplacePurchaseAccount) GetID() int64 { + if m == nil || m.ID == nil { + return 0 + } + return *m.ID +} + +// GetLogin returns the Login field if it's non-nil, zero value otherwise. +func (m *MarketplacePurchaseAccount) GetLogin() string { + if m == nil || m.Login == nil { + return "" + } + return *m.Login +} + +// GetNodeID returns the NodeID field if it's non-nil, zero value otherwise. +func (m *MarketplacePurchaseAccount) GetNodeID() string { + if m == nil || m.NodeID == nil { + return "" + } + return *m.NodeID +} + +// GetOrganizationBillingEmail returns the OrganizationBillingEmail field if it's non-nil, zero value otherwise. +func (m *MarketplacePurchaseAccount) GetOrganizationBillingEmail() string { + if m == nil || m.OrganizationBillingEmail == nil { + return "" + } + return *m.OrganizationBillingEmail +} + +// GetType returns the Type field if it's non-nil, zero value otherwise. +func (m *MarketplacePurchaseAccount) GetType() string { + if m == nil || m.Type == nil { + return "" + } + return *m.Type +} + +// GetURL returns the URL field if it's non-nil, zero value otherwise. +func (m *MarketplacePurchaseAccount) GetURL() string { + if m == nil || m.URL == nil { + return "" + } + return *m.URL +} + // GetAction returns the Action field if it's non-nil, zero value otherwise. func (m *MarketplacePurchaseEvent) GetAction() string { if m == nil || m.Action == nil { diff --git a/github/github-accessors_test.go b/github/github-accessors_test.go index 9457df769e..dbe7a8e908 100644 --- a/github/github-accessors_test.go +++ b/github/github-accessors_test.go @@ -10790,6 +10790,13 @@ func TestMarketplacePlanAccount_GetURL(tt *testing.T) { m.GetURL() } +func TestMarketplacePurchase_GetAccount(tt *testing.T) { + m := &MarketplacePurchase{} + m.GetAccount() + m = nil + m.GetAccount() +} + func TestMarketplacePurchase_GetBillingCycle(tt *testing.T) { var zeroValue string m := &MarketplacePurchase{BillingCycle: &zeroValue} @@ -10857,6 +10864,76 @@ func TestMarketplacePurchase_GetUpdatedAt(tt *testing.T) { m.GetUpdatedAt() } +func TestMarketplacePurchaseAccount_GetEmail(tt *testing.T) { + var zeroValue string + m := &MarketplacePurchaseAccount{Email: &zeroValue} + m.GetEmail() + m = &MarketplacePurchaseAccount{} + m.GetEmail() + m = nil + m.GetEmail() +} + +func TestMarketplacePurchaseAccount_GetID(tt *testing.T) { + var zeroValue int64 + m := &MarketplacePurchaseAccount{ID: &zeroValue} + m.GetID() + m = &MarketplacePurchaseAccount{} + m.GetID() + m = nil + m.GetID() +} + +func TestMarketplacePurchaseAccount_GetLogin(tt *testing.T) { + var zeroValue string + m := &MarketplacePurchaseAccount{Login: &zeroValue} + m.GetLogin() + m = &MarketplacePurchaseAccount{} + m.GetLogin() + m = nil + m.GetLogin() +} + +func TestMarketplacePurchaseAccount_GetNodeID(tt *testing.T) { + var zeroValue string + m := &MarketplacePurchaseAccount{NodeID: &zeroValue} + m.GetNodeID() + m = &MarketplacePurchaseAccount{} + m.GetNodeID() + m = nil + m.GetNodeID() +} + +func TestMarketplacePurchaseAccount_GetOrganizationBillingEmail(tt *testing.T) { + var zeroValue string + m := &MarketplacePurchaseAccount{OrganizationBillingEmail: &zeroValue} + m.GetOrganizationBillingEmail() + m = &MarketplacePurchaseAccount{} + m.GetOrganizationBillingEmail() + m = nil + m.GetOrganizationBillingEmail() +} + +func TestMarketplacePurchaseAccount_GetType(tt *testing.T) { + var zeroValue string + m := &MarketplacePurchaseAccount{Type: &zeroValue} + m.GetType() + m = &MarketplacePurchaseAccount{} + m.GetType() + m = nil + m.GetType() +} + +func TestMarketplacePurchaseAccount_GetURL(tt *testing.T) { + var zeroValue string + m := &MarketplacePurchaseAccount{URL: &zeroValue} + m.GetURL() + m = &MarketplacePurchaseAccount{} + m.GetURL() + m = nil + m.GetURL() +} + func TestMarketplacePurchaseEvent_GetAction(tt *testing.T) { var zeroValue string m := &MarketplacePurchaseEvent{Action: &zeroValue} From c855eb5fc7dcc46ab35fd5c5dda387dd0a3e0eb1 Mon Sep 17 00:00:00 2001 From: Bryan Callahan Date: Mon, 6 Feb 2023 06:28:57 -0800 Subject: [PATCH 2/2] Add URL, UpdateAt, and WorkflowRun fields to Artifacts (#2660) --- github/actions_artifacts.go | 32 +++++++++---- github/actions_artifacts_test.go | 40 ++++++++++++++++- github/github-accessors.go | 64 ++++++++++++++++++++++++++ github/github-accessors_test.go | 77 ++++++++++++++++++++++++++++++++ 4 files changed, 202 insertions(+), 11 deletions(-) diff --git a/github/actions_artifacts.go b/github/actions_artifacts.go index 99329d989d..441a53910e 100644 --- a/github/actions_artifacts.go +++ b/github/actions_artifacts.go @@ -12,20 +12,34 @@ import ( "net/url" ) -// Artifact reprents a GitHub artifact. Artifacts allow sharing +// ArtifactWorkflowRun represents a GitHub artifact's workflow run. +// +// GitHub API docs: https://docs.github.com/en/rest/actions/artifacts +type ArtifactWorkflowRun struct { + ID *int64 `json:"id,omitempty"` + RepositoryID *int64 `json:"repository_id,omitempty"` + HeadRepositoryID *int64 `json:"head_repository_id,omitempty"` + HeadBranch *string `json:"head_branch,omitempty"` + HeadSHA *string `json:"head_sha,omitempty"` +} + +// Artifact represents a GitHub artifact. Artifacts allow sharing // data between jobs in a workflow and provide storage for data // once a workflow is complete. // // GitHub API docs: https://docs.github.com/en/rest/actions/artifacts type Artifact struct { - ID *int64 `json:"id,omitempty"` - NodeID *string `json:"node_id,omitempty"` - Name *string `json:"name,omitempty"` - SizeInBytes *int64 `json:"size_in_bytes,omitempty"` - ArchiveDownloadURL *string `json:"archive_download_url,omitempty"` - Expired *bool `json:"expired,omitempty"` - CreatedAt *Timestamp `json:"created_at,omitempty"` - ExpiresAt *Timestamp `json:"expires_at,omitempty"` + ID *int64 `json:"id,omitempty"` + NodeID *string `json:"node_id,omitempty"` + Name *string `json:"name,omitempty"` + SizeInBytes *int64 `json:"size_in_bytes,omitempty"` + URL *string `json:"url,omitempty"` + ArchiveDownloadURL *string `json:"archive_download_url,omitempty"` + Expired *bool `json:"expired,omitempty"` + CreatedAt *Timestamp `json:"created_at,omitempty"` + UpdatedAt *Timestamp `json:"updated_at,omitempty"` + ExpiresAt *Timestamp `json:"expires_at,omitempty"` + WorkflowRun *ArtifactWorkflowRun `json:"workflow_run,omitempty"` } // ArtifactList represents a list of GitHub artifacts. diff --git a/github/actions_artifacts_test.go b/github/actions_artifacts_test.go index e35a873bc0..de07c14f84 100644 --- a/github/actions_artifacts_test.go +++ b/github/actions_artifacts_test.go @@ -438,10 +438,19 @@ func TestArtifact_Marshal(t *testing.T) { NodeID: String("nid"), Name: String("n"), SizeInBytes: Int64(1), + URL: String("u"), ArchiveDownloadURL: String("a"), Expired: Bool(false), CreatedAt: &Timestamp{referenceTime}, + UpdatedAt: &Timestamp{referenceTime}, ExpiresAt: &Timestamp{referenceTime}, + WorkflowRun: &ArtifactWorkflowRun{ + ID: Int64(1), + RepositoryID: Int64(1), + HeadRepositoryID: Int64(1), + HeadBranch: String("b"), + HeadSHA: String("s"), + }, } want := `{ @@ -449,10 +458,19 @@ func TestArtifact_Marshal(t *testing.T) { "node_id": "nid", "name": "n", "size_in_bytes": 1, + "url": "u", "archive_download_url": "a", "expired": false, "created_at": ` + referenceTimeStr + `, - "expires_at": ` + referenceTimeStr + ` + "updated_at": ` + referenceTimeStr + `, + "expires_at": ` + referenceTimeStr + `, + "workflow_run": { + "id": 1, + "repository_id": 1, + "head_repository_id": 1, + "head_branch": "b", + "head_sha": "s" + } }` testJSONMarshal(t, u, want) @@ -469,10 +487,19 @@ func TestArtifactList_Marshal(t *testing.T) { NodeID: String("nid"), Name: String("n"), SizeInBytes: Int64(1), + URL: String("u"), ArchiveDownloadURL: String("a"), Expired: Bool(false), CreatedAt: &Timestamp{referenceTime}, + UpdatedAt: &Timestamp{referenceTime}, ExpiresAt: &Timestamp{referenceTime}, + WorkflowRun: &ArtifactWorkflowRun{ + ID: Int64(1), + RepositoryID: Int64(1), + HeadRepositoryID: Int64(1), + HeadBranch: String("b"), + HeadSHA: String("s"), + }, }, }, } @@ -484,10 +511,19 @@ func TestArtifactList_Marshal(t *testing.T) { "node_id": "nid", "name": "n", "size_in_bytes": 1, + "url": "u", "archive_download_url": "a", "expired": false, "created_at": ` + referenceTimeStr + `, - "expires_at": ` + referenceTimeStr + ` + "updated_at": ` + referenceTimeStr + `, + "expires_at": ` + referenceTimeStr + `, + "workflow_run": { + "id": 1, + "repository_id": 1, + "head_repository_id": 1, + "head_branch": "b", + "head_sha": "s" + } }] }` diff --git a/github/github-accessors.go b/github/github-accessors.go index 433d16f303..63b1079cdf 100644 --- a/github/github-accessors.go +++ b/github/github-accessors.go @@ -902,6 +902,30 @@ func (a *Artifact) GetSizeInBytes() int64 { return *a.SizeInBytes } +// GetUpdatedAt returns the UpdatedAt field if it's non-nil, zero value otherwise. +func (a *Artifact) GetUpdatedAt() Timestamp { + if a == nil || a.UpdatedAt == nil { + return Timestamp{} + } + return *a.UpdatedAt +} + +// GetURL returns the URL field if it's non-nil, zero value otherwise. +func (a *Artifact) GetURL() string { + if a == nil || a.URL == nil { + return "" + } + return *a.URL +} + +// GetWorkflowRun returns the WorkflowRun field. +func (a *Artifact) GetWorkflowRun() *ArtifactWorkflowRun { + if a == nil { + return nil + } + return a.WorkflowRun +} + // GetTotalCount returns the TotalCount field if it's non-nil, zero value otherwise. func (a *ArtifactList) GetTotalCount() int64 { if a == nil || a.TotalCount == nil { @@ -910,6 +934,46 @@ func (a *ArtifactList) GetTotalCount() int64 { return *a.TotalCount } +// GetHeadBranch returns the HeadBranch field if it's non-nil, zero value otherwise. +func (a *ArtifactWorkflowRun) GetHeadBranch() string { + if a == nil || a.HeadBranch == nil { + return "" + } + return *a.HeadBranch +} + +// GetHeadRepositoryID returns the HeadRepositoryID field if it's non-nil, zero value otherwise. +func (a *ArtifactWorkflowRun) GetHeadRepositoryID() int64 { + if a == nil || a.HeadRepositoryID == nil { + return 0 + } + return *a.HeadRepositoryID +} + +// GetHeadSHA returns the HeadSHA field if it's non-nil, zero value otherwise. +func (a *ArtifactWorkflowRun) GetHeadSHA() string { + if a == nil || a.HeadSHA == nil { + return "" + } + return *a.HeadSHA +} + +// GetID returns the ID field if it's non-nil, zero value otherwise. +func (a *ArtifactWorkflowRun) GetID() int64 { + if a == nil || a.ID == nil { + return 0 + } + return *a.ID +} + +// GetRepositoryID returns the RepositoryID field if it's non-nil, zero value otherwise. +func (a *ArtifactWorkflowRun) GetRepositoryID() int64 { + if a == nil || a.RepositoryID == nil { + return 0 + } + return *a.RepositoryID +} + // GetBody returns the Body field if it's non-nil, zero value otherwise. func (a *Attachment) GetBody() string { if a == nil || a.Body == nil { diff --git a/github/github-accessors_test.go b/github/github-accessors_test.go index dbe7a8e908..961eba8288 100644 --- a/github/github-accessors_test.go +++ b/github/github-accessors_test.go @@ -1056,6 +1056,33 @@ func TestArtifact_GetSizeInBytes(tt *testing.T) { a.GetSizeInBytes() } +func TestArtifact_GetUpdatedAt(tt *testing.T) { + var zeroValue Timestamp + a := &Artifact{UpdatedAt: &zeroValue} + a.GetUpdatedAt() + a = &Artifact{} + a.GetUpdatedAt() + a = nil + a.GetUpdatedAt() +} + +func TestArtifact_GetURL(tt *testing.T) { + var zeroValue string + a := &Artifact{URL: &zeroValue} + a.GetURL() + a = &Artifact{} + a.GetURL() + a = nil + a.GetURL() +} + +func TestArtifact_GetWorkflowRun(tt *testing.T) { + a := &Artifact{} + a.GetWorkflowRun() + a = nil + a.GetWorkflowRun() +} + func TestArtifactList_GetTotalCount(tt *testing.T) { var zeroValue int64 a := &ArtifactList{TotalCount: &zeroValue} @@ -1066,6 +1093,56 @@ func TestArtifactList_GetTotalCount(tt *testing.T) { a.GetTotalCount() } +func TestArtifactWorkflowRun_GetHeadBranch(tt *testing.T) { + var zeroValue string + a := &ArtifactWorkflowRun{HeadBranch: &zeroValue} + a.GetHeadBranch() + a = &ArtifactWorkflowRun{} + a.GetHeadBranch() + a = nil + a.GetHeadBranch() +} + +func TestArtifactWorkflowRun_GetHeadRepositoryID(tt *testing.T) { + var zeroValue int64 + a := &ArtifactWorkflowRun{HeadRepositoryID: &zeroValue} + a.GetHeadRepositoryID() + a = &ArtifactWorkflowRun{} + a.GetHeadRepositoryID() + a = nil + a.GetHeadRepositoryID() +} + +func TestArtifactWorkflowRun_GetHeadSHA(tt *testing.T) { + var zeroValue string + a := &ArtifactWorkflowRun{HeadSHA: &zeroValue} + a.GetHeadSHA() + a = &ArtifactWorkflowRun{} + a.GetHeadSHA() + a = nil + a.GetHeadSHA() +} + +func TestArtifactWorkflowRun_GetID(tt *testing.T) { + var zeroValue int64 + a := &ArtifactWorkflowRun{ID: &zeroValue} + a.GetID() + a = &ArtifactWorkflowRun{} + a.GetID() + a = nil + a.GetID() +} + +func TestArtifactWorkflowRun_GetRepositoryID(tt *testing.T) { + var zeroValue int64 + a := &ArtifactWorkflowRun{RepositoryID: &zeroValue} + a.GetRepositoryID() + a = &ArtifactWorkflowRun{} + a.GetRepositoryID() + a = nil + a.GetRepositoryID() +} + func TestAttachment_GetBody(tt *testing.T) { var zeroValue string a := &Attachment{Body: &zeroValue}