Repository: google/go-github
Pull request #2496 (2022-10-14 13:40:36)

Add enterprise list runner applications download
This change adds ListRunnerApplicationDownloads() to the Enterprise service.

Fixes: #2495

Signed-off-by: Gabriel Adrian Samfira <gsamfira@cloudbasesolutions.com>

codecov[bot]: # [Codecov](https://codecov.io/gh/google/go-github/pull/2496?src=pr&el=h1&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=google) Report
> Merging [#2496](https://codecov.io/gh/google/go-github/pull/2496?src=pr&el=desc&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=google) (c555ecc) into [master](https://codecov.io/gh/google/go-github/commit/33444123bc7eaf03bdfe548dea7ce9ab04fc1008?el=desc&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=google) (3344412) will **increase** coverage by `0.00%`.
> The diff coverage is `100.00%`.

```diff
@@           Coverage Diff           @@
##           master    #2496   +/-   ##
=======================================
  Coverage   97.99%   97.99%           
=======================================
  Files         123      123           
  Lines       10762    10774   +12     
=======================================
+ Hits        10546    10558   +12     
  Misses        148      148           
  Partials       68       68           
```


| [Impacted Files](https://codecov.io/gh/google/go-github/pull/2496?src=pr&el=tree&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=google) | Coverage Δ | |
|---|---|---|
| [github/enterprise\_actions\_runners.go](https://codecov.io/gh/google/go-github/pull/2496/diff?src=pr&el=tree&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=google#diff-Z2l0aHViL2VudGVycHJpc2VfYWN0aW9uc19ydW5uZXJzLmdv) | `100.00% <100.00%> (ø)` | |

Help us with your feedback. Take ten seconds to tell us [how you rate us](https://about.codecov.io/nps?utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=google). Have a feature suggestion? [Share it here.](https://app.codecov.io/gh/feedback/?utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=google)

gmlewis: Thank you, @valbeat !
Merging.

Patch:
diff --git a/github/enterprise_actions_runners.go b/github/enterprise_actions_runners.go
index f2ba1663..daafc5e6 100644
--- a/github/enterprise_actions_runners.go
+++ b/github/enterprise_actions_runners.go
@@ -10,6 +10,25 @@ import (
 	"fmt"
 )
 
+// ListRunnerApplicationDownloads lists self-hosted runner application binaries that can be downloaded and run.
+//
+// GitHub API docs: https://docs.github.com/en/rest/actions/self-hosted-runners#list-runner-applications-for-an-enterprise
+func (s *EnterpriseService) ListRunnerApplicationDownloads(ctx context.Context, enterprise string) ([]*RunnerApplicationDownload, *Response, error) {
+	u := fmt.Sprintf("enterprises/%v/actions/runners/downloads", enterprise)
+	req, err := s.client.NewRequest("GET", u, nil)
+	if err != nil {
+		return nil, nil, err
+	}
+
+	var rads []*RunnerApplicationDownload
+	resp, err := s.client.Do(ctx, req, &rads)
+	if err != nil {
+		return nil, resp, err
+	}
+
+	return rads, resp, nil
+}
+
 // CreateRegistrationToken creates a token that can be used to add a self-hosted runner.
 //
 // GitHub API docs: https://docs.github.com/en/rest/actions/self-hosted-runners#create-a-registration-token-for-an-enterprise


Test patch:
diff --git a/github/enterprise_actions_runners_test.go b/github/enterprise_actions_runners_test.go
index a854b482..b7c3f78b 100644
--- a/github/enterprise_actions_runners_test.go
+++ b/github/enterprise_actions_runners_test.go
@@ -119,3 +119,44 @@ func TestEnterpriseService_RemoveRunner(t *testing.T) {
 		return client.Enterprise.RemoveRunner(ctx, "o", 21)
 	})
 }
+
+func TestEnterpriseService_ListRunnerApplicationDownloads(t *testing.T) {
+	client, mux, _, teardown := setup()
+	defer teardown()
+
+	mux.HandleFunc("/enterprises/o/actions/runners/downloads", func(w http.ResponseWriter, r *http.Request) {
+		testMethod(t, r, "GET")
+		fmt.Fprint(w, `[{"os":"osx","architecture":"x64","download_url":"https://github.com/actions/runner/releases/download/v2.164.0/actions-runner-osx-x64-2.164.0.tar.gz","filename":"actions-runner-osx-x64-2.164.0.tar.gz"},{"os":"linux","architecture":"x64","download_url":"https://github.com/actions/runner/releases/download/v2.164.0/actions-runner-linux-x64-2.164.0.tar.gz","filename":"actions-runner-linux-x64-2.164.0.tar.gz"},{"os": "linux","architecture":"arm","download_url":"https://github.com/actions/runner/releases/download/v2.164.0/actions-runner-linux-arm-2.164.0.tar.gz","filename":"actions-runner-linux-arm-2.164.0.tar.gz"},{"os":"win","architecture":"x64","download_url":"https://github.com/actions/runner/releases/download/v2.164.0/actions-runner-win-x64-2.164.0.zip","filename":"actions-runner-win-x64-2.164.0.zip"},{"os":"linux","architecture":"arm64","download_url":"https://github.com/actions/runner/releases/download/v2.164.0/actions-runner-linux-arm64-2.164.0.tar.gz","filename":"actions-runner-linux-arm64-2.164.0.tar.gz"}]`)
+	})
+
+	ctx := context.Background()
+	downloads, _, err := client.Enterprise.ListRunnerApplicationDownloads(ctx, "o")
+	if err != nil {
+		t.Errorf("Enterprise.ListRunnerApplicationDownloads returned error: %v", err)
+	}
+
+	want := []*RunnerApplicationDownload{
+		{OS: String("osx"), Architecture: String("x64"), DownloadURL: String("https://github.com/actions/runner/releases/download/v2.164.0/actions-runner-osx-x64-2.164.0.tar.gz"), Filename: String("actions-runner-osx-x64-2.164.0.tar.gz")},
+		{OS: String("linux"), Architecture: String("x64"), DownloadURL: String("https://github.com/actions/runner/releases/download/v2.164.0/actions-runner-linux-x64-2.164.0.tar.gz"), Filename: String("actions-runner-linux-x64-2.164.0.tar.gz")},
+		{OS: String("linux"), Architecture: String("arm"), DownloadURL: String("https://github.com/actions/runner/releases/download/v2.164.0/actions-runner-linux-arm-2.164.0.tar.gz"), Filename: String("actions-runner-linux-arm-2.164.0.tar.gz")},
+		{OS: String("win"), Architecture: String("x64"), DownloadURL: String("https://github.com/actions/runner/releases/download/v2.164.0/actions-runner-win-x64-2.164.0.zip"), Filename: String("actions-runner-win-x64-2.164.0.zip")},
+		{OS: String("linux"), Architecture: String("arm64"), DownloadURL: String("https://github.com/actions/runner/releases/download/v2.164.0/actions-runner-linux-arm64-2.164.0.tar.gz"), Filename: String("actions-runner-linux-arm64-2.164.0.tar.gz")},
+	}
+	if !cmp.Equal(downloads, want) {
+		t.Errorf("Enterprise.ListRunnerApplicationDownloads returned %+v, want %+v", downloads, want)
+	}
+
+	const methodName = "ListRunnerApplicationDownloads"
+	testBadOptions(t, methodName, func() (err error) {
+		_, _, err = client.Enterprise.ListRunnerApplicationDownloads(ctx, "\n")
+		return err
+	})
+
+	testNewRequestAndDoFailure(t, methodName, client, func() (*Response, error) {
+		got, resp, err := client.Enterprise.ListRunnerApplicationDownloads(ctx, "o")
+		if got != nil {
+			t.Errorf("testNewRequestAndDoFailure %v = %#v, want nil", methodName, got)
+		}
+		return resp, err
+	})
+}