Repository: google/go-github
Pull request #3330 (2024-10-21 01:09:13)

feat!: Add name query parameter to ActionsService.ListArtifacts
Fixes: #3328.

BREAKING CHANGE: `opts` argument to `ActionsService.ListArtifacts` changed from `ListOptions` to `ListArtifactsOptions`.

codecov[bot]: ## [Codecov](https://app.codecov.io/gh/google/go-github/pull/3330?dropdown=coverage&src=pr&el=h1&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=google) Report
All modified and coverable lines are covered by tests :white_check_mark:
> Project coverage is 93.01%. Comparing base [(`2b8c7fa`)](https://app.codecov.io/gh/google/go-github/commit/2b8c7fa86fcd1cb4a89a44c8e7b5a49fe4be8a45?dropdown=coverage&el=desc&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=google) to head [(`76e7f96`)](https://app.codecov.io/gh/google/go-github/commit/76e7f96f354c78cf81916ec03701aa1e592cf573?dropdown=coverage&el=desc&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=google).
> Report is 156 commits behind head on master.

<details><summary>Additional details and impacted files</summary>


```diff
@@            Coverage Diff             @@
##           master    #3330      +/-   ##
==========================================
- Coverage   97.72%   93.01%   -4.71%     
==========================================
  Files         153      172      +19     
  Lines       13390    14848    +1458     
==========================================
+ Hits        13085    13811     +726     
- Misses        215      944     +729     
- Partials       90       93       +3     
```

</details>

[:umbrella: View full report in Codecov by Sentry](https://app.codecov.io/gh/google/go-github/pull/3330?dropdown=coverage&src=pr&el=continue&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=google).   
:loudspeaker: Have feedback on the report? [Share it here](https://about.codecov.io/codecov-pr-comment-feedback/?utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=google).

gmlewis: @muhardanz - can you please take a look at this (and possibly try it out) to see if it fixes the issue you were having?
muhardanz: @gmlewis I can confirm that this fixes the ListArtifacts function so that it can take in the name query string. I can also confirm that it returns the correct result
gmlewis: Thank you, @muhardanz !
Merging.

Patch:
diff --git a/github/actions_artifacts.go b/github/actions_artifacts.go
index f804b809..e05a9a84 100644
--- a/github/actions_artifacts.go
+++ b/github/actions_artifacts.go
@@ -50,12 +50,22 @@ type ArtifactList struct {
 	Artifacts  []*Artifact `json:"artifacts,omitempty"`
 }
 
+// ListArtifactsOptions specifies the optional parameters to the
+// ActionsService.ListArtifacts method.
+type ListArtifactsOptions struct {
+	// Name represents the name field of an artifact.
+	// When specified, only artifacts with this name will be returned.
+	Name *string `url:"name,omitempty"`
+
+	ListOptions
+}
+
 // ListArtifacts lists all artifacts that belong to a repository.
 //
 // GitHub API docs: https://docs.github.com/rest/actions/artifacts#list-artifacts-for-a-repository
 //
 //meta:operation GET /repos/{owner}/{repo}/actions/artifacts
-func (s *ActionsService) ListArtifacts(ctx context.Context, owner, repo string, opts *ListOptions) (*ArtifactList, *Response, error) {
+func (s *ActionsService) ListArtifacts(ctx context.Context, owner, repo string, opts *ListArtifactsOptions) (*ArtifactList, *Response, error) {
 	u := fmt.Sprintf("repos/%v/%v/actions/artifacts", owner, repo)
 	u, err := addOptions(u, opts)
 	if err != nil {
diff --git a/github/github-accessors.go b/github/github-accessors.go
index 019ba354..ea4cfb75 100644
--- a/github/github-accessors.go
+++ b/github/github-accessors.go
@@ -11238,6 +11238,14 @@ func (l *ListAlertsOptions) GetState() string {
 	return *l.State
 }
 
+// GetName returns the Name field if it's non-nil, zero value otherwise.
+func (l *ListArtifactsOptions) GetName() string {
+	if l == nil || l.Name == nil {
+		return ""
+	}
+	return *l.Name
+}
+
 // GetAppID returns the AppID field if it's non-nil, zero value otherwise.
 func (l *ListCheckRunsOptions) GetAppID() int64 {
 	if l == nil || l.AppID == nil {


Test patch:
diff --git a/github/actions_artifacts_test.go b/github/actions_artifacts_test.go
index c592283d..751b6e26 100644
--- a/github/actions_artifacts_test.go
+++ b/github/actions_artifacts_test.go
@@ -22,7 +22,7 @@ func TestActionsService_ListArtifacts(t *testing.T) {
 
 	mux.HandleFunc("/repos/o/r/actions/artifacts", func(w http.ResponseWriter, r *http.Request) {
 		testMethod(t, r, "GET")
-		testFormValues(t, r, values{"page": "2"})
+		testFormValues(t, r, values{"page": "2", "name": "TheArtifact"})
 		fmt.Fprint(w,
 			`{
 				"total_count":1,
@@ -31,7 +31,10 @@ func TestActionsService_ListArtifacts(t *testing.T) {
 		)
 	})
 
-	opts := &ListOptions{Page: 2}
+	opts := &ListArtifactsOptions{
+		Name:        String("TheArtifact"),
+		ListOptions: ListOptions{Page: 2},
+	}
 	ctx := context.Background()
 	artifacts, _, err := client.Actions.ListArtifacts(ctx, "o", "r", opts)
 	if err != nil {
diff --git a/github/github-accessors_test.go b/github/github-accessors_test.go
index 8f1407ee..acd3febe 100644
--- a/github/github-accessors_test.go
+++ b/github/github-accessors_test.go
@@ -14527,6 +14527,17 @@ func TestListAlertsOptions_GetState(tt *testing.T) {
 	l.GetState()
 }
 
+func TestListArtifactsOptions_GetName(tt *testing.T) {
+	tt.Parallel()
+	var zeroValue string
+	l := &ListArtifactsOptions{Name: &zeroValue}
+	l.GetName()
+	l = &ListArtifactsOptions{}
+	l.GetName()
+	l = nil
+	l.GetName()
+}
+
 func TestListCheckRunsOptions_GetAppID(tt *testing.T) {
 	tt.Parallel()
 	var zeroValue int64