Repository: google/go-github
Pull request #1538 (2020-05-23 17:58:25)

Add ListArtifacts to ActionsService
I've based the implementation on ListWorkflowRunArtifacts  as the methods have similar behavior.

Issue at #1537 

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

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

```diff
@@            Coverage Diff             @@
##           master    #1538      +/-   ##
==========================================
+ Coverage   68.01%   73.18%   +5.17%     
==========================================
  Files          94       94              
  Lines        8560     6903    -1657     
==========================================
- Hits         5822     5052     -770     
+ Misses       1852      964     -888     
- Partials      886      887       +1     
```


| [Impacted Files](https://codecov.io/gh/google/go-github/pull/1538?src=pr&el=tree) | Coverage Δ | |
|---|---|---|
| [github/actions\_artifacts.go](https://codecov.io/gh/google/go-github/pull/1538/diff?src=pr&el=tree#diff-Z2l0aHViL2FjdGlvbnNfYXJ0aWZhY3RzLmdv) | `88.23% <84.61%> (+0.56%)` | :arrow_up: |
| [github/github.go](https://codecov.io/gh/google/go-github/pull/1538/diff?src=pr&el=tree#diff-Z2l0aHViL2dpdGh1Yi5nbw==) | `89.62% <0.00%> (-0.03%)` | :arrow_down: |
| [github/admin.go](https://codecov.io/gh/google/go-github/pull/1538/diff?src=pr&el=tree#diff-Z2l0aHViL2FkbWluLmdv) | `100.00% <0.00%> (ø)` | |
| [github/strings.go](https://codecov.io/gh/google/go-github/pull/1538/diff?src=pr&el=tree#diff-Z2l0aHViL3N0cmluZ3MuZ28=) | `100.00% <0.00%> (ø)` | |
| [github/activity.go](https://codecov.io/gh/google/go-github/pull/1538/diff?src=pr&el=tree#diff-Z2l0aHViL2FjdGl2aXR5Lmdv) | `100.00% <0.00%> (ø)` | |
| [github/timestamp.go](https://codecov.io/gh/google/go-github/pull/1538/diff?src=pr&el=tree#diff-Z2l0aHViL3RpbWVzdGFtcC5nbw==) | `100.00% <0.00%> (ø)` | |
| [github/admin\_stats.go](https://codecov.io/gh/google/go-github/pull/1538/diff?src=pr&el=tree#diff-Z2l0aHViL2FkbWluX3N0YXRzLmdv) | `100.00% <0.00%> (ø)` | |
| [github/repos\_traffic.go](https://codecov.io/gh/google/go-github/pull/1538/diff?src=pr&el=tree#diff-Z2l0aHViL3JlcG9zX3RyYWZmaWMuZ28=) | `100.00% <0.00%> (ø)` | |
| [github/pulls\_reviewers.go](https://codecov.io/gh/google/go-github/pull/1538/diff?src=pr&el=tree#diff-Z2l0aHViL3B1bGxzX3Jldmlld2Vycy5nbw==) | `100.00% <0.00%> (ø)` | |
| [github/git\_commits.go](https://codecov.io/gh/google/go-github/pull/1538/diff?src=pr&el=tree#diff-Z2l0aHViL2dpdF9jb21taXRzLmdv) | `91.30% <0.00%> (+1.30%)` | :arrow_up: |
| ... and [82 more](https://codecov.io/gh/google/go-github/pull/1538/diff?src=pr&el=tree-more) | |

------

[Continue to review full report at Codecov](https://codecov.io/gh/google/go-github/pull/1538?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/1538?src=pr&el=footer). Last update [a37dd2d...e08d6a5](https://codecov.io/gh/google/go-github/pull/1538?src=pr&el=lastupdated). Read the [comment docs](https://docs.codecov.io/docs/pull-request-comments).

gmlewis: Thank you, @wesleimp !
Merging.

Patch:
diff --git a/github/actions_artifacts.go b/github/actions_artifacts.go
index 17358495..a236253e 100644
--- a/github/actions_artifacts.go
+++ b/github/actions_artifacts.go
@@ -36,6 +36,30 @@ type ArtifactList struct {
 	Artifacts  []*Artifact `json:"artifacts,omitempty"`
 }
 
+// ListArtifacts lists all artifacts that belong to a repository.
+//
+// GitHub API docs: https://developer.github.com/v3/actions/artifacts/#list-artifacts-for-a-repository
+func (s *ActionsService) ListArtifacts(ctx context.Context, owner, repo string, opts *ListOptions) (*ArtifactList, *Response, error) {
+	u := fmt.Sprintf("repos/%v/%v/actions/artifacts", owner, repo)
+	u, err := addOptions(u, opts)
+	if err != nil {
+		return nil, nil, err
+	}
+
+	req, err := s.client.NewRequest("GET", u, nil)
+	if err != nil {
+		return nil, nil, err
+	}
+
+	artifactList := new(ArtifactList)
+	resp, err := s.client.Do(ctx, req, artifactList)
+	if err != nil {
+		return nil, resp, err
+	}
+
+	return artifactList, resp, nil
+}
+
 // ListWorkflowRunArtifacts lists all artifacts that belong to a workflow run.
 //
 // GitHub API docs: https://developer.github.com/v3/actions/artifacts/#list-workflow-run-artifacts


Test patch:
diff --git a/github/actions_artifacts_test.go b/github/actions_artifacts_test.go
index 2d478e45..bdad8310 100644
--- a/github/actions_artifacts_test.go
+++ b/github/actions_artifacts_test.go
@@ -14,6 +14,70 @@ import (
 	"testing"
 )
 
+func TestActionsService_ListArtifacts(t *testing.T) {
+	client, mux, _, teardown := setup()
+	defer teardown()
+
+	mux.HandleFunc("/repos/o/r/actions/artifacts", func(w http.ResponseWriter, r *http.Request) {
+		testMethod(t, r, "GET")
+		testFormValues(t, r, values{"page": "2"})
+		fmt.Fprint(w,
+			`{
+				"total_count":1, 
+				"artifacts":[{"id":1}]
+			}`,
+		)
+	})
+
+	opts := &ListOptions{Page: 2}
+	artifacts, _, err := client.Actions.ListArtifacts(context.Background(), "o", "r", opts)
+	if err != nil {
+		t.Errorf("Actions.ListArtifacts returned error: %v", err)
+	}
+
+	want := &ArtifactList{TotalCount: Int64(1), Artifacts: []*Artifact{{ID: Int64(1)}}}
+	if !reflect.DeepEqual(artifacts, want) {
+		t.Errorf("Actions.ListArtifacts returned %+v, want %+v", artifacts, want)
+	}
+}
+
+func TestActionsService_ListArtifacts_invalidOwner(t *testing.T) {
+	client, _, _, teardown := setup()
+	defer teardown()
+
+	_, _, err := client.Actions.ListArtifacts(context.Background(), "%", "r", nil)
+	testURLParseError(t, err)
+}
+
+func TestActionsService_ListArtifacts_invalidRepo(t *testing.T) {
+	client, _, _, teardown := setup()
+	defer teardown()
+
+	_, _, err := client.Actions.ListArtifacts(context.Background(), "o", "%", nil)
+	testURLParseError(t, err)
+}
+
+func TestActionsService_ListArtifacts_notFound(t *testing.T) {
+	client, mux, _, teardown := setup()
+	defer teardown()
+
+	mux.HandleFunc("/repos/o/r/actions/artifacts", func(w http.ResponseWriter, r *http.Request) {
+		testMethod(t, r, "GET")
+		w.WriteHeader(http.StatusNotFound)
+	})
+
+	artifacts, resp, err := client.Actions.ListArtifacts(context.Background(), "o", "r", nil)
+	if err == nil {
+		t.Errorf("Expected HTTP 404 response")
+	}
+	if got, want := resp.Response.StatusCode, http.StatusNotFound; got != want {
+		t.Errorf("Actions.ListArtifacts return status %d, want %d", got, want)
+	}
+	if artifacts != nil {
+		t.Errorf("Actions.ListArtifacts return %+v, want nil", artifacts)
+	}
+}
+
 func TestActionsService_ListWorkflowRunArtifacts(t *testing.T) {
 	client, mux, _, teardown := setup()
 	defer teardown()