Repository: google/go-github
Pull request #1455 (2020-03-07 21:27:17)

Add support for filter parameter to the list workflow jobs endpoint
This adds support for an optional `filter` parameter to the list workflow jobs endpoint that was recently announced. See #1454.

codecov[bot]: # [Codecov](https://codecov.io/gh/google/go-github/pull/1455?src=pr&el=h1) Report
> Merging [#1455](https://codecov.io/gh/google/go-github/pull/1455?src=pr&el=desc) into [master](https://codecov.io/gh/google/go-github/commit/5a0c02dff48b10470db5615d1a46a7784cb3cb22?src=pr&el=desc) will **increase** coverage by `5.18%`.
> The diff coverage is `100%`.

[![Impacted file tree graph](https://codecov.io/gh/google/go-github/pull/1455/graphs/tree.svg?width=650&token=EgYjGjZlI0&height=150&src=pr)](https://codecov.io/gh/google/go-github/pull/1455?src=pr&el=tree)

```diff
@@            Coverage Diff             @@
##           master    #1455      +/-   ##
==========================================
+ Coverage   67.75%   72.93%   +5.18%     
==========================================
  Files          94       94              
  Lines        8459     6818    -1641     
==========================================
- Hits         5731     4973     -758     
+ Misses       1851      968     -883     
  Partials      877      877
```


| [Impacted Files](https://codecov.io/gh/google/go-github/pull/1455?src=pr&el=tree) | Coverage Δ | |
|---|---|---|
| [github/actions\_workflow\_jobs.go](https://codecov.io/gh/google/go-github/pull/1455/diff?src=pr&el=tree#diff-Z2l0aHViL2FjdGlvbnNfd29ya2Zsb3dfam9icy5nbw==) | `63.26% <100%> (+4.8%)` | :arrow_up: |
| [github/github.go](https://codecov.io/gh/google/go-github/pull/1455/diff?src=pr&el=tree#diff-Z2l0aHViL2dpdGh1Yi5nbw==) | `89.74% <0%> (-0.03%)` | :arrow_down: |
| [github/repos\_traffic.go](https://codecov.io/gh/google/go-github/pull/1455/diff?src=pr&el=tree#diff-Z2l0aHViL3JlcG9zX3RyYWZmaWMuZ28=) | `100% <0%> (ø)` | :arrow_up: |
| [github/admin\_stats.go](https://codecov.io/gh/google/go-github/pull/1455/diff?src=pr&el=tree#diff-Z2l0aHViL2FkbWluX3N0YXRzLmdv) | `100% <0%> (ø)` | :arrow_up: |
| [github/admin.go](https://codecov.io/gh/google/go-github/pull/1455/diff?src=pr&el=tree#diff-Z2l0aHViL2FkbWluLmdv) | `100% <0%> (ø)` | :arrow_up: |
| [github/pulls\_reviewers.go](https://codecov.io/gh/google/go-github/pull/1455/diff?src=pr&el=tree#diff-Z2l0aHViL3B1bGxzX3Jldmlld2Vycy5nbw==) | `100% <0%> (ø)` | :arrow_up: |
| [github/activity.go](https://codecov.io/gh/google/go-github/pull/1455/diff?src=pr&el=tree#diff-Z2l0aHViL2FjdGl2aXR5Lmdv) | `100% <0%> (ø)` | :arrow_up: |
| [github/timestamp.go](https://codecov.io/gh/google/go-github/pull/1455/diff?src=pr&el=tree#diff-Z2l0aHViL3RpbWVzdGFtcC5nbw==) | `100% <0%> (ø)` | :arrow_up: |
| [github/strings.go](https://codecov.io/gh/google/go-github/pull/1455/diff?src=pr&el=tree#diff-Z2l0aHViL3N0cmluZ3MuZ28=) | `100% <0%> (ø)` | :arrow_up: |
| [github/git\_commits.go](https://codecov.io/gh/google/go-github/pull/1455/diff?src=pr&el=tree#diff-Z2l0aHViL2dpdF9jb21taXRzLmdv) | `91.3% <0%> (+1.3%)` | :arrow_up: |
| ... and [82 more](https://codecov.io/gh/google/go-github/pull/1455/diff?src=pr&el=tree-more) | |

------

[Continue to review full report at Codecov](https://codecov.io/gh/google/go-github/pull/1455?src=pr&el=continue).
> **Legend** - [Click here to learn more](https://docs.codecov.io/docs/codecov-delta)
> `Δ = absolute <relative> (impact)`, `ø = not affected`, `? = missing data`
> Powered by [Codecov](https://codecov.io/gh/google/go-github/pull/1455?src=pr&el=footer). Last update [5a0c02d...8f6729d](https://codecov.io/gh/google/go-github/pull/1455?src=pr&el=lastupdated). Read the [comment docs](https://docs.codecov.io/docs/pull-request-comments).


Patch:
diff --git a/github/actions_workflow_jobs.go b/github/actions_workflow_jobs.go
index e3593b6a..8cb7c6aa 100644
--- a/github/actions_workflow_jobs.go
+++ b/github/actions_workflow_jobs.go
@@ -46,10 +46,22 @@ type Jobs struct {
 	Jobs       []*WorkflowJob `json:"jobs,omitempty"`
 }
 
+// ListWorkflowJobsOptions specifies optional parameters to ListWorkflowJobs.
+type ListWorkflowJobsOptions struct {
+	// Filter specifies how jobs should be filtered by their completed_at timestamp.
+	// Possible values are:
+	//     latest - Returns jobs from the most recent execution of the workflow run
+	//     all - Returns all jobs for a workflow run, including from old executions of the workflow run
+	//
+	// Default value is "latest".
+	Filter string `url:"filter,omitempty"`
+	ListOptions
+}
+
 // ListWorkflowJobs lists all jobs for a workflow run.
 //
 // GitHub API docs: https://developer.github.com/v3/actions/workflow_jobs/#list-jobs-for-a-workflow-run
-func (s *ActionsService) ListWorkflowJobs(ctx context.Context, owner, repo string, runID int64, opts *ListOptions) (*Jobs, *Response, error) {
+func (s *ActionsService) ListWorkflowJobs(ctx context.Context, owner, repo string, runID int64, opts *ListWorkflowJobsOptions) (*Jobs, *Response, error) {
 	u := fmt.Sprintf("repos/%s/%s/actions/runs/%v/jobs", owner, repo, runID)
 	u, err := addOptions(u, opts)
 	if err != nil {
diff --git a/github/github-accessors.go b/github/github-accessors.go
index 8598de67..69547c4f 100644
--- a/github/github-accessors.go
+++ b/github/github-accessors.go
@@ -7220,6 +7220,22 @@ func (p *PageStats) GetTotalPages() int {
 	return *p.TotalPages
 }
 
+// GetCNAME returns the CNAME field if it's non-nil, zero value otherwise.
+func (p *PagesUpdate) GetCNAME() string {
+	if p == nil || p.CNAME == nil {
+		return ""
+	}
+	return *p.CNAME
+}
+
+// GetSource returns the Source field if it's non-nil, zero value otherwise.
+func (p *PagesUpdate) GetSource() string {
+	if p == nil || p.Source == nil {
+		return ""
+	}
+	return *p.Source
+}
+
 // GetHook returns the Hook field.
 func (p *PingEvent) GetHook() *Hook {
 	if p == nil {
diff --git a/github/repos_pages.go b/github/repos_pages.go
index ff8d2d55..58826527 100644
--- a/github/repos_pages.go
+++ b/github/repos_pages.go
@@ -75,6 +75,35 @@ func (s *RepositoriesService) EnablePages(ctx context.Context, owner, repo strin
 	return enable, resp, nil
 }
 
+// PagesUpdate sets up parameters needed to update a GitHub Pages site.
+type PagesUpdate struct {
+	// CNAME represents a custom domain for the repository.
+	// Leaving CNAME empty will remove the custom domain.
+	CNAME *string `json:"cname"`
+	// Source must include the branch name, and may optionally specify the subdirectory "/docs".
+	// Possible values are: "gh-pages", "master", and "master /docs".
+	Source *string `json:"source,omitempty"`
+}
+
+// UpdatePages updates GitHub Pages for the named repo.
+//
+// GitHub API docs: https://developer.github.com/v3/repos/pages/#update-information-about-a-pages-site
+func (s *RepositoriesService) UpdatePages(ctx context.Context, owner, repo string, opts *PagesUpdate) (*Response, error) {
+	u := fmt.Sprintf("repos/%v/%v/pages", owner, repo)
+
+	req, err := s.client.NewRequest("PUT", u, opts)
+	if err != nil {
+		return nil, err
+	}
+
+	resp, err := s.client.Do(ctx, req, nil)
+	if err != nil {
+		return resp, err
+	}
+
+	return resp, nil
+}
+
 // DisablePages disables GitHub Pages for the named repo.
 //
 // GitHub API docs: https://developer.github.com/v3/repos/pages/#disable-a-pages-site


Test patch:
diff --git a/github/actions_workflow_jobs_test.go b/github/actions_workflow_jobs_test.go
index 36cf7a82..3cf17ae7 100644
--- a/github/actions_workflow_jobs_test.go
+++ b/github/actions_workflow_jobs_test.go
@@ -25,7 +25,35 @@ func TestActionsService_ListWorkflowJobs(t *testing.T) {
 		fmt.Fprint(w, `{"total_count":4,"jobs":[{"id":399444496,"run_id":29679449,"started_at":"2019-01-02T15:04:05Z","completed_at":"2020-01-02T15:04:05Z"},{"id":399444497,"run_id":29679449,"started_at":"2019-01-02T15:04:05Z","completed_at":"2020-01-02T15:04:05Z"}]}`)
 	})
 
-	opts := &ListOptions{Page: 2, PerPage: 2}
+	opts := &ListWorkflowJobsOptions{ListOptions: ListOptions{Page: 2, PerPage: 2}}
+	jobs, _, err := client.Actions.ListWorkflowJobs(context.Background(), "o", "r", 29679449, opts)
+	if err != nil {
+		t.Errorf("Actions.ListWorkflowJobs returned error: %v", err)
+	}
+
+	want := &Jobs{
+		TotalCount: Int(4),
+		Jobs: []*WorkflowJob{
+			{ID: Int64(399444496), RunID: Int64(29679449), StartedAt: &Timestamp{time.Date(2019, time.January, 02, 15, 04, 05, 0, time.UTC)}, CompletedAt: &Timestamp{time.Date(2020, time.January, 02, 15, 04, 05, 0, time.UTC)}},
+			{ID: Int64(399444497), RunID: Int64(29679449), StartedAt: &Timestamp{time.Date(2019, time.January, 02, 15, 04, 05, 0, time.UTC)}, CompletedAt: &Timestamp{time.Date(2020, time.January, 02, 15, 04, 05, 0, time.UTC)}},
+		},
+	}
+	if !reflect.DeepEqual(jobs, want) {
+		t.Errorf("Actions.ListWorkflowJobs returned %+v, want %+v", jobs, want)
+	}
+}
+
+func TestActionsService_ListWorkflowJobs_Filter(t *testing.T) {
+	client, mux, _, teardown := setup()
+	defer teardown()
+
+	mux.HandleFunc("/repos/o/r/actions/runs/29679449/jobs", func(w http.ResponseWriter, r *http.Request) {
+		testMethod(t, r, "GET")
+		testFormValues(t, r, values{"filter": "all", "per_page": "2", "page": "2"})
+		fmt.Fprint(w, `{"total_count":4,"jobs":[{"id":399444496,"run_id":29679449,"started_at":"2019-01-02T15:04:05Z","completed_at":"2020-01-02T15:04:05Z"},{"id":399444497,"run_id":29679449,"started_at":"2019-01-02T15:04:05Z","completed_at":"2020-01-02T15:04:05Z"}]}`)
+	})
+
+	opts := &ListWorkflowJobsOptions{Filter: "all", ListOptions: ListOptions{Page: 2, PerPage: 2}}
 	jobs, _, err := client.Actions.ListWorkflowJobs(context.Background(), "o", "r", 29679449, opts)
 	if err != nil {
 		t.Errorf("Actions.ListWorkflowJobs returned error: %v", err)
diff --git a/github/repos_pages_test.go b/github/repos_pages_test.go
index 8fe38eb3..b2aa2729 100644
--- a/github/repos_pages_test.go
+++ b/github/repos_pages_test.go
@@ -6,9 +6,11 @@
 package github
 
 import (
+	"bytes"
 	"context"
 	"encoding/json"
 	"fmt"
+	"io/ioutil"
 	"net/http"
 	"reflect"
 	"testing"
@@ -52,6 +54,62 @@ func TestRepositoriesService_EnablePages(t *testing.T) {
 	}
 }
 
+func TestRepositoriesService_UpdatePages(t *testing.T) {
+	client, mux, _, teardown := setup()
+	defer teardown()
+
+	input := &PagesUpdate{
+		CNAME:  String("www.my-domain.com"),
+		Source: String("gh-pages"),
+	}
+
+	mux.HandleFunc("/repos/o/r/pages", func(w http.ResponseWriter, r *http.Request) {
+		v := new(PagesUpdate)
+		json.NewDecoder(r.Body).Decode(v)
+
+		testMethod(t, r, "PUT")
+		want := &PagesUpdate{CNAME: String("www.my-domain.com"), Source: String("gh-pages")}
+		if !reflect.DeepEqual(v, want) {
+			t.Errorf("Request body = %+v, want %+v", v, want)
+		}
+
+		fmt.Fprint(w, `{"cname":"www.my-domain.com","source":"gh-pages"}`)
+	})
+
+	_, err := client.Repositories.UpdatePages(context.Background(), "o", "r", input)
+	if err != nil {
+		t.Errorf("Repositories.UpdatePages returned error: %v", err)
+	}
+}
+
+func TestRepositoriesService_UpdatePages_NullCNAME(t *testing.T) {
+	client, mux, _, teardown := setup()
+	defer teardown()
+
+	input := &PagesUpdate{
+		Source: String("gh-pages"),
+	}
+
+	mux.HandleFunc("/repos/o/r/pages", func(w http.ResponseWriter, r *http.Request) {
+		got, err := ioutil.ReadAll(r.Body)
+		if err != nil {
+			t.Fatalf("unable to read body: %v", err)
+		}
+
+		want := []byte(`{"cname":null,"source":"gh-pages"}` + "\n")
+		if !bytes.Equal(got, want) {
+			t.Errorf("Request body = %+v, want %+v", got, want)
+		}
+
+		fmt.Fprint(w, `{"cname":null,"source":"gh-pages"}`)
+	})
+
+	_, err := client.Repositories.UpdatePages(context.Background(), "o", "r", input)
+	if err != nil {
+		t.Errorf("Repositories.UpdatePages returned error: %v", err)
+	}
+}
+
 func TestRepositoriesService_DisablePages(t *testing.T) {
 	client, mux, _, teardown := setup()
 	defer teardown()