github.com/google/go-github/v65@v65.0.0/github/repos_pages.go (about) 1 // Copyright 2014 The go-github AUTHORS. All rights reserved. 2 // 3 // Use of this source code is governed by a BSD-style 4 // license that can be found in the LICENSE file. 5 6 package github 7 8 import ( 9 "context" 10 "fmt" 11 ) 12 13 // Pages represents a GitHub Pages site configuration. 14 type Pages struct { 15 URL *string `json:"url,omitempty"` 16 Status *string `json:"status,omitempty"` 17 CNAME *string `json:"cname,omitempty"` 18 Custom404 *bool `json:"custom_404,omitempty"` 19 HTMLURL *string `json:"html_url,omitempty"` 20 BuildType *string `json:"build_type,omitempty"` 21 Source *PagesSource `json:"source,omitempty"` 22 Public *bool `json:"public,omitempty"` 23 HTTPSCertificate *PagesHTTPSCertificate `json:"https_certificate,omitempty"` 24 HTTPSEnforced *bool `json:"https_enforced,omitempty"` 25 } 26 27 // PagesSource represents a GitHub page's source. 28 type PagesSource struct { 29 Branch *string `json:"branch,omitempty"` 30 Path *string `json:"path,omitempty"` 31 } 32 33 // PagesError represents a build error for a GitHub Pages site. 34 type PagesError struct { 35 Message *string `json:"message,omitempty"` 36 } 37 38 // PagesBuild represents the build information for a GitHub Pages site. 39 type PagesBuild struct { 40 URL *string `json:"url,omitempty"` 41 Status *string `json:"status,omitempty"` 42 Error *PagesError `json:"error,omitempty"` 43 Pusher *User `json:"pusher,omitempty"` 44 Commit *string `json:"commit,omitempty"` 45 Duration *int `json:"duration,omitempty"` 46 CreatedAt *Timestamp `json:"created_at,omitempty"` 47 UpdatedAt *Timestamp `json:"updated_at,omitempty"` 48 } 49 50 // PagesDomain represents a domain associated with a GitHub Pages site. 51 type PagesDomain struct { 52 Host *string `json:"host,omitempty"` 53 URI *string `json:"uri,omitempty"` 54 Nameservers *string `json:"nameservers,omitempty"` 55 DNSResolves *bool `json:"dns_resolves,omitempty"` 56 IsProxied *bool `json:"is_proxied,omitempty"` 57 IsCloudflareIP *bool `json:"is_cloudflare_ip,omitempty"` 58 IsFastlyIP *bool `json:"is_fastly_ip,omitempty"` 59 IsOldIPAddress *bool `json:"is_old_ip_address,omitempty"` 60 IsARecord *bool `json:"is_a_record,omitempty"` 61 HasCNAMERecord *bool `json:"has_cname_record,omitempty"` 62 HasMXRecordsPresent *bool `json:"has_mx_records_present,omitempty"` 63 IsValidDomain *bool `json:"is_valid_domain,omitempty"` 64 IsApexDomain *bool `json:"is_apex_domain,omitempty"` 65 ShouldBeARecord *bool `json:"should_be_a_record,omitempty"` 66 IsCNAMEToGithubUserDomain *bool `json:"is_cname_to_github_user_domain,omitempty"` 67 IsCNAMEToPagesDotGithubDotCom *bool `json:"is_cname_to_pages_dot_github_dot_com,omitempty"` 68 IsCNAMEToFastly *bool `json:"is_cname_to_fastly,omitempty"` 69 IsPointedToGithubPagesIP *bool `json:"is_pointed_to_github_pages_ip,omitempty"` 70 IsNonGithubPagesIPPresent *bool `json:"is_non_github_pages_ip_present,omitempty"` 71 IsPagesDomain *bool `json:"is_pages_domain,omitempty"` 72 IsServedByPages *bool `json:"is_served_by_pages,omitempty"` 73 IsValid *bool `json:"is_valid,omitempty"` 74 Reason *string `json:"reason,omitempty"` 75 RespondsToHTTPS *bool `json:"responds_to_https,omitempty"` 76 EnforcesHTTPS *bool `json:"enforces_https,omitempty"` 77 HTTPSError *string `json:"https_error,omitempty"` 78 IsHTTPSEligible *bool `json:"is_https_eligible,omitempty"` 79 CAAError *string `json:"caa_error,omitempty"` 80 } 81 82 // PagesHealthCheckResponse represents the response given for the health check of a GitHub Pages site. 83 type PagesHealthCheckResponse struct { 84 Domain *PagesDomain `json:"domain,omitempty"` 85 AltDomain *PagesDomain `json:"alt_domain,omitempty"` 86 } 87 88 // PagesHTTPSCertificate represents the HTTPS Certificate information for a GitHub Pages site. 89 type PagesHTTPSCertificate struct { 90 State *string `json:"state,omitempty"` 91 Description *string `json:"description,omitempty"` 92 Domains []string `json:"domains,omitempty"` 93 // GitHub's API doesn't return a standard Timestamp, rather it returns a YYYY-MM-DD string. 94 ExpiresAt *string `json:"expires_at,omitempty"` 95 } 96 97 // createPagesRequest is a subset of Pages and is used internally 98 // by EnablePages to pass only the known fields for the endpoint. 99 type createPagesRequest struct { 100 BuildType *string `json:"build_type,omitempty"` 101 Source *PagesSource `json:"source,omitempty"` 102 } 103 104 // EnablePages enables GitHub Pages for the named repo. 105 // 106 // GitHub API docs: https://docs.github.com/rest/pages/pages#create-a-github-pages-site 107 // 108 //meta:operation POST /repos/{owner}/{repo}/pages 109 func (s *RepositoriesService) EnablePages(ctx context.Context, owner, repo string, pages *Pages) (*Pages, *Response, error) { 110 u := fmt.Sprintf("repos/%v/%v/pages", owner, repo) 111 112 pagesReq := &createPagesRequest{ 113 BuildType: pages.BuildType, 114 Source: pages.Source, 115 } 116 117 req, err := s.client.NewRequest("POST", u, pagesReq) 118 if err != nil { 119 return nil, nil, err 120 } 121 122 req.Header.Set("Accept", mediaTypeEnablePagesAPIPreview) 123 124 enable := new(Pages) 125 resp, err := s.client.Do(ctx, req, enable) 126 if err != nil { 127 return nil, resp, err 128 } 129 130 return enable, resp, nil 131 } 132 133 // PagesUpdate sets up parameters needed to update a GitHub Pages site. 134 type PagesUpdate struct { 135 // CNAME represents a custom domain for the repository. 136 // Leaving CNAME empty will remove the custom domain. 137 CNAME *string `json:"cname"` 138 // BuildType is optional and can either be "legacy" or "workflow". 139 // "workflow" - You are using a github workflow to build your pages. 140 // "legacy" - You are deploying from a branch. 141 BuildType *string `json:"build_type,omitempty"` 142 // Source must include the branch name, and may optionally specify the subdirectory "/docs". 143 // Possible values for Source.Branch are usually "gh-pages", "main", and "master", 144 // or any other existing branch name. 145 // Possible values for Source.Path are: "/", and "/docs". 146 Source *PagesSource `json:"source,omitempty"` 147 // Public configures access controls for the site. 148 // If "true", the site will be accessible to anyone on the internet. If "false", 149 // the site will be accessible to anyone with read access to the repository that 150 // published the site. 151 Public *bool `json:"public,omitempty"` 152 // HTTPSEnforced specifies whether HTTPS should be enforced for the repository. 153 HTTPSEnforced *bool `json:"https_enforced,omitempty"` 154 } 155 156 // UpdatePages updates GitHub Pages for the named repo. 157 // 158 // GitHub API docs: https://docs.github.com/rest/pages/pages#update-information-about-a-github-pages-site 159 // 160 //meta:operation PUT /repos/{owner}/{repo}/pages 161 func (s *RepositoriesService) UpdatePages(ctx context.Context, owner, repo string, opts *PagesUpdate) (*Response, error) { 162 u := fmt.Sprintf("repos/%v/%v/pages", owner, repo) 163 164 req, err := s.client.NewRequest("PUT", u, opts) 165 if err != nil { 166 return nil, err 167 } 168 169 resp, err := s.client.Do(ctx, req, nil) 170 if err != nil { 171 return resp, err 172 } 173 174 return resp, nil 175 } 176 177 // DisablePages disables GitHub Pages for the named repo. 178 // 179 // GitHub API docs: https://docs.github.com/rest/pages/pages#delete-a-github-pages-site 180 // 181 //meta:operation DELETE /repos/{owner}/{repo}/pages 182 func (s *RepositoriesService) DisablePages(ctx context.Context, owner, repo string) (*Response, error) { 183 u := fmt.Sprintf("repos/%v/%v/pages", owner, repo) 184 req, err := s.client.NewRequest("DELETE", u, nil) 185 if err != nil { 186 return nil, err 187 } 188 189 // TODO: remove custom Accept header when this API fully launches. 190 req.Header.Set("Accept", mediaTypeEnablePagesAPIPreview) 191 192 return s.client.Do(ctx, req, nil) 193 } 194 195 // GetPagesInfo fetches information about a GitHub Pages site. 196 // 197 // GitHub API docs: https://docs.github.com/rest/pages/pages#get-a-github-pages-site 198 // 199 //meta:operation GET /repos/{owner}/{repo}/pages 200 func (s *RepositoriesService) GetPagesInfo(ctx context.Context, owner, repo string) (*Pages, *Response, error) { 201 u := fmt.Sprintf("repos/%v/%v/pages", owner, repo) 202 req, err := s.client.NewRequest("GET", u, nil) 203 if err != nil { 204 return nil, nil, err 205 } 206 207 site := new(Pages) 208 resp, err := s.client.Do(ctx, req, site) 209 if err != nil { 210 return nil, resp, err 211 } 212 213 return site, resp, nil 214 } 215 216 // ListPagesBuilds lists the builds for a GitHub Pages site. 217 // 218 // GitHub API docs: https://docs.github.com/rest/pages/pages#list-github-pages-builds 219 // 220 //meta:operation GET /repos/{owner}/{repo}/pages/builds 221 func (s *RepositoriesService) ListPagesBuilds(ctx context.Context, owner, repo string, opts *ListOptions) ([]*PagesBuild, *Response, error) { 222 u := fmt.Sprintf("repos/%v/%v/pages/builds", owner, repo) 223 u, err := addOptions(u, opts) 224 if err != nil { 225 return nil, nil, err 226 } 227 228 req, err := s.client.NewRequest("GET", u, nil) 229 if err != nil { 230 return nil, nil, err 231 } 232 233 var pages []*PagesBuild 234 resp, err := s.client.Do(ctx, req, &pages) 235 if err != nil { 236 return nil, resp, err 237 } 238 239 return pages, resp, nil 240 } 241 242 // GetLatestPagesBuild fetches the latest build information for a GitHub pages site. 243 // 244 // GitHub API docs: https://docs.github.com/rest/pages/pages#get-latest-pages-build 245 // 246 //meta:operation GET /repos/{owner}/{repo}/pages/builds/latest 247 func (s *RepositoriesService) GetLatestPagesBuild(ctx context.Context, owner, repo string) (*PagesBuild, *Response, error) { 248 u := fmt.Sprintf("repos/%v/%v/pages/builds/latest", owner, repo) 249 req, err := s.client.NewRequest("GET", u, nil) 250 if err != nil { 251 return nil, nil, err 252 } 253 254 build := new(PagesBuild) 255 resp, err := s.client.Do(ctx, req, build) 256 if err != nil { 257 return nil, resp, err 258 } 259 260 return build, resp, nil 261 } 262 263 // GetPageBuild fetches the specific build information for a GitHub pages site. 264 // 265 // GitHub API docs: https://docs.github.com/rest/pages/pages#get-github-pages-build 266 // 267 //meta:operation GET /repos/{owner}/{repo}/pages/builds/{build_id} 268 func (s *RepositoriesService) GetPageBuild(ctx context.Context, owner, repo string, id int64) (*PagesBuild, *Response, error) { 269 u := fmt.Sprintf("repos/%v/%v/pages/builds/%v", owner, repo, id) 270 req, err := s.client.NewRequest("GET", u, nil) 271 if err != nil { 272 return nil, nil, err 273 } 274 275 build := new(PagesBuild) 276 resp, err := s.client.Do(ctx, req, build) 277 if err != nil { 278 return nil, resp, err 279 } 280 281 return build, resp, nil 282 } 283 284 // RequestPageBuild requests a build of a GitHub Pages site without needing to push new commit. 285 // 286 // GitHub API docs: https://docs.github.com/rest/pages/pages#request-a-github-pages-build 287 // 288 //meta:operation POST /repos/{owner}/{repo}/pages/builds 289 func (s *RepositoriesService) RequestPageBuild(ctx context.Context, owner, repo string) (*PagesBuild, *Response, error) { 290 u := fmt.Sprintf("repos/%v/%v/pages/builds", owner, repo) 291 req, err := s.client.NewRequest("POST", u, nil) 292 if err != nil { 293 return nil, nil, err 294 } 295 296 build := new(PagesBuild) 297 resp, err := s.client.Do(ctx, req, build) 298 if err != nil { 299 return nil, resp, err 300 } 301 302 return build, resp, nil 303 } 304 305 // GetPageHealthCheck gets a DNS health check for the CNAME record configured for a repository's GitHub Pages. 306 // 307 // GitHub API docs: https://docs.github.com/rest/pages/pages#get-a-dns-health-check-for-github-pages 308 // 309 //meta:operation GET /repos/{owner}/{repo}/pages/health 310 func (s *RepositoriesService) GetPageHealthCheck(ctx context.Context, owner, repo string) (*PagesHealthCheckResponse, *Response, error) { 311 u := fmt.Sprintf("repos/%v/%v/pages/health", owner, repo) 312 req, err := s.client.NewRequest("GET", u, nil) 313 if err != nil { 314 return nil, nil, err 315 } 316 317 healthCheckResponse := new(PagesHealthCheckResponse) 318 resp, err := s.client.Do(ctx, req, healthCheckResponse) 319 if err != nil { 320 return nil, resp, err 321 } 322 323 return healthCheckResponse, resp, nil 324 }