Skip to content

Commit

Permalink
Merge pull request #1065 from Cyb3r-Jak3/pages-project-production_branch
Browse files Browse the repository at this point in the history
  • Loading branch information
jacobbednarz authored Aug 29, 2022
2 parents c9d87aa + ce08d71 commit c48d484
Show file tree
Hide file tree
Showing 3 changed files with 133 additions and 15 deletions.
9 changes: 9 additions & 0 deletions .changelog/1065.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
```release-note:enhancement
pages_project: Add `production_branch` field
```
```release-note:enhancement
pages_project: Add `kv_namespaces`, `durable_object_namespaces`, `r2_buckets`, and `d1_databases` bindings to deployment config
```
```release-note:enhancement
pages_project: Add `preview_deployment_setting`, `preview_branch_includes`, and `preview_branch_excludes` to source config
```
48 changes: 42 additions & 6 deletions pages_project.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,18 +8,27 @@ import (
"time"
)

type PagesPreviewDeploymentSetting string

const (
PagesPreviewAllBranches PagesPreviewDeploymentSetting = "all"
PagesPreviewNoBranches PagesPreviewDeploymentSetting = "none"
PagesPreviewCustomBranches PagesPreviewDeploymentSetting = "custom"
)

// PagesProject represents a Pages project.
type PagesProject struct {
Name string `json:"name,omitempty"`
ID string `json:"id"`
CreatedOn *time.Time `json:"created_on"`
SubDomain string `json:"subdomain"`
Domains []string `json:"domains,omitempty"`
Source PagesProjectSource `json:"source"`
Source *PagesProjectSource `json:"source,omitempty"`
BuildConfig PagesProjectBuildConfig `json:"build_config"`
DeploymentConfigs PagesProjectDeploymentConfigs `json:"deployment_configs"`
LatestDeployment PagesProjectDeployment `json:"latest_deployment"`
CanonicalDeployment PagesProjectDeployment `json:"canonical_deployment"`
ProductionBranch string `json:"production_branch,omitempty"`
}

// PagesProjectSource represents the configuration of a Pages project source.
Expand All @@ -30,11 +39,15 @@ type PagesProjectSource struct {

// PagesProjectSourceConfig represents the properties use to configure a Pages project source.
type PagesProjectSourceConfig struct {
Owner string `json:"owner"`
RepoName string `json:"repo_name"`
ProductionBranch string `json:"production_branch"`
PRCommentsEnabled bool `json:"pr_comments_enabled"`
DeploymentsEnabled bool `json:"deployments_enabled"`
Owner string `json:"owner"`
RepoName string `json:"repo_name"`
ProductionBranch string `json:"production_branch"`
PRCommentsEnabled bool `json:"pr_comments_enabled"`
DeploymentsEnabled bool `json:"deployments_enabled"`
ProductionDeploymentsEnabled bool `json:"production_deployments_enabled"`
PreviewDeploymentSetting PagesPreviewDeploymentSetting `json:"preview_deployment_setting"`
PreviewBranchIncludes []string `json:"preview_branch_includes"`
PreviewBranchExcludes []string `json:"preview_branch_excludes"`
}

// PagesProjectBuildConfig represents the configuration of a Pages project build process.
Expand All @@ -57,6 +70,10 @@ type PagesProjectDeploymentConfigEnvironment struct {
EnvVars map[string]PagesProjectDeploymentVar `json:"env_vars"`
CompatibilityDate string `json:"compatibility_date,omitempty"`
CompatibilityFlags []string `json:"compatibility_flags,omitempty"`
KvNamespaces NamespaceBindingMap `json:"kv_namespaces,omitempty"`
DoNamespaces NamespaceBindingMap `json:"durable_object_namespaces,omitempty"`
D1Databases D1BindingMap `json:"d1_databases,omitempty"`
R2Bindings R2BindingMap `json:"r2_buckets,omitempty"`
}

// PagesProjectDeploymentVar represents a deployment environment variable.
Expand All @@ -83,6 +100,7 @@ type PagesProjectDeployment struct {
Source PagesProjectSource `json:"source"`
CompatibilityDate string `json:"compatibility_date,omitempty"`
CompatibilityFlags []string `json:"compatibility_flags,omitempty"`
ProductionBranch string `json:"production_branch,omitempty"`
}

// PagesProjectDeploymentStage represents an individual stage in a Pages project deployment.
Expand Down Expand Up @@ -117,6 +135,24 @@ type pagesProjectListResponse struct {
ResultInfo `json:"result_info"`
}

type NamespaceBindingMap map[string]*NamespaceBindingValue

type NamespaceBindingValue struct {
Value string `json:"namespace_id"`
}

type R2BindingMap map[string]*R2BindingValue

type R2BindingValue struct {
Name string `json:"name"`
}

type D1BindingMap map[string]*D1Binding

type D1Binding struct {
ID string `json:"id"`
}

// ListPagesProjects returns all Pages projects for an account.
//
// API reference: https://api.cloudflare.com/#pages-project-get-projects
Expand Down
91 changes: 82 additions & 9 deletions pages_project_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,14 +21,26 @@ const (
"testdomain.com",
"testdomain.org"
],
"production_branch": "main",
"source": {
"type": "github",
"config": {
"owner": "cloudflare",
"repo_name": "pages-test",
"production_branch": "main",
"pr_comments_enabled": true,
"deployments_enabled": true
"deployments_enabled": true,
"preview_deployment_setting": "custom",
"preview_branch_includes": [
"release/*",
"production",
"main"
],
"preview_branch_excludes": [
"dependabot/*",
"dev",
"*/ignore"
]
}
},
"build_config": {
Expand Down Expand Up @@ -60,6 +72,26 @@ const (
"value": "production"
}
},
"d1_databases": {
"D1_BINDING": {
"id": "a94509c6-0757-43f3-b053-474b0ab10935"
}
},
"kv_namespaces": {
"KV_BINDING": {
"namespace_id": "5eb63bbbe01eeed093cb22bb8f5acdc3"
}
},
"durable_object_namespaces": {
"DO_BINDING": {
"namespace_id": "5eb63bbbe01eeed093cb22bb8f5acdc3"
}
},
"r2_buckets": {
"R2_BINDING": {
"name": "some-bucket"
}
},
"compatibility_date": "2022-08-15",
"compatibility_flags": ["production_flag"]
}
Expand All @@ -70,6 +102,7 @@ const (
"project_id": "5a321fc7-3162-7d36-adce-1213996a7",
"project_name": "pages-test",
"environment": "preview",
"production_branch": "main",
"url": "https://c35216d1.pages-test.pages.dev",
"created_on": "2021-03-09T00:55:03.923456Z",
"modified_on": "2021-03-09T00:58:59.045655Z",
Expand Down Expand Up @@ -128,7 +161,18 @@ const (
"repo_name": "pages-test",
"production_branch": "main",
"pr_comments_enabled": true,
"deployments_enabled": true
"deployments_enabled": true,
"preview_deployment_setting": "custom",
"preview_branch_includes": [
"release/*",
"production",
"main"
],
"preview_branch_excludes": [
"dependabot/*",
"dev",
"*/ignore"
]
}
}
},
Expand All @@ -141,6 +185,7 @@ const (
"url": "https://c35216d1.pages-test.pages.dev",
"created_on": "2021-03-09T00:55:03.923456Z",
"modified_on": "2021-03-09T00:58:59.045655Z",
"production_branch": "main",
"aliases": [
"https://branchname.pages-test.pages.dev"
],
Expand Down Expand Up @@ -196,7 +241,18 @@ const (
"repo_name": "pages-test",
"production_branch": "main",
"pr_comments_enabled": true,
"deployments_enabled": true
"deployments_enabled": true,
"preview_deployment_setting": "custom",
"preview_branch_includes": [
"release/*",
"production",
"main"
],
"preview_branch_excludes": [
"dependabot/*",
"dev",
"*/ignore"
]
}
}
}
Expand All @@ -217,9 +273,10 @@ var (
BuildConfig: *expectedPagesProjectBuildConfig,
CreatedOn: &pagesProjectCreatedOn,
DeploymentConfigs: *expectedPagesProjectDeploymentConfigs,
Source: *expectedPagesProjectSource,
Source: expectedPagesProjectSource,
ID: "5a321fc7-3162-7d36-adce-1213996a7",
LatestDeployment: *expectedPagesProjectDeployment,
ProductionBranch: "main",
}

deploymentCreatedOn, _ = time.Parse(time.RFC3339, "2021-03-09T00:55:03.923456Z")
Expand Down Expand Up @@ -252,6 +309,7 @@ var (
Stages: expectedStages,
BuildConfig: *expectedPagesProjectBuildConfig,
Source: *expectedPagesProjectSource,
ProductionBranch: "main",
}

latestDeploymentStageStartedOn, _ = time.Parse(time.RFC3339, "2021-03-09T00:55:03.923456Z")
Expand Down Expand Up @@ -328,6 +386,18 @@ var (
},
CompatibilityDate: "2022-08-15",
CompatibilityFlags: []string{"production_flag"},
KvNamespaces: NamespaceBindingMap{
"KV_BINDING": &NamespaceBindingValue{Value: "5eb63bbbe01eeed093cb22bb8f5acdc3"},
},
D1Databases: D1BindingMap{
"D1_BINDING": &D1Binding{ID: "a94509c6-0757-43f3-b053-474b0ab10935"},
},
DoNamespaces: NamespaceBindingMap{
"DO_BINDING": &NamespaceBindingValue{Value: "5eb63bbbe01eeed093cb22bb8f5acdc3"},
},
R2Bindings: R2BindingMap{
"R2_BINDING": &R2BindingValue{Name: "some-bucket"},
},
}

expectedPagesProjectSource = &PagesProjectSource{
Expand All @@ -336,11 +406,14 @@ var (
}

expectedPagesProjectSourceConfig = &PagesProjectSourceConfig{
Owner: "cloudflare",
RepoName: "pages-test",
ProductionBranch: "main",
PRCommentsEnabled: true,
DeploymentsEnabled: true,
Owner: "cloudflare",
RepoName: "pages-test",
ProductionBranch: "main",
PRCommentsEnabled: true,
DeploymentsEnabled: true,
PreviewDeploymentSetting: PagesPreviewCustomBranches,
PreviewBranchIncludes: []string{"release/*", "production", "main"},
PreviewBranchExcludes: []string{"dependabot/*", "dev", "*/ignore"},
}
)

Expand Down

0 comments on commit c48d484

Please sign in to comment.