Repository: google/go-github
Pull request #1789 (2021-02-02 09:05:34)

Add support for removing enterprise Actions runners
adds support for

https://docs.github.com/en/rest/reference/enterprise-admin#delete-a-self-hosted-runner-from-an-enterprise


google-cla[bot]: 
Thanks for your pull request. It looks like this may be your first contribution to a Google open source project (if not, look below for help). Before we can look at your pull request, you'll need to sign a Contributor License Agreement (CLA).

:memo: **Please visit <https://cla.developers.google.com/> to sign.**

Once you've signed (or fixed any issues), please reply here with `@googlebot I signed it!` and we'll verify it.

----

#### What to do if you already signed the CLA

##### Individual signers

*   It's possible we don't have your GitHub username or you're using a different email address on your commit. Check [your existing CLA data](https://cla.developers.google.com/clas) and verify that your [email is set on your git commits](https://help.github.com/articles/setting-your-email-in-git/).

##### Corporate signers

*   Your company has a Point of Contact who decides which employees are authorized to participate. Ask your POC to be added to the group of authorized contributors. If you don't know who your Point of Contact is, direct the Google project maintainer to [go/cla#troubleshoot](http://go/cla#troubleshoot) ([Public version](https://opensource.google/docs/cla/#troubleshoot)).
*   The email used to register you as an authorized contributor must be the email used for the Git commit. Check [your existing CLA data](https://cla.developers.google.com/clas) and verify that your [email is set on your git commits](https://help.github.com/articles/setting-your-email-in-git/).
*   The email used to register you as an authorized contributor must also be [attached to your GitHub account](https://github.com/settings/emails).
		

ℹ️ **Googlers: [Go here](https://goto.google.com/prinfo/https%3A%2F%2Fgithub.com%2Fgoogle%2Fgo-github%2Fpull%2F1789) for more info**.

<!-- need_sender_cla -->
zetaab: @googlebot I signed it!
codecov[bot]: # [Codecov](https://codecov.io/gh/google/go-github/pull/1789?src=pr&el=h1) Report
> Merging [#1789](https://codecov.io/gh/google/go-github/pull/1789?src=pr&el=desc) (18333bc) into [master](https://codecov.io/gh/google/go-github/commit/5cd6a0f4812a5f0fe25e9e3510aa707c7e2eaa87?el=desc) (5cd6a0f) will **decrease** coverage by `0.39%`.
> The diff coverage is `0.00%`.

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

```diff
@@            Coverage Diff             @@
##           master    #1789      +/-   ##
==========================================
- Coverage   97.53%   97.14%   -0.40%     
==========================================
  Files          98       98              
  Lines        6380     6406      +26     
==========================================
  Hits         6223     6223              
- Misses         85      111      +26     
  Partials       72       72              
```


| [Impacted Files](https://codecov.io/gh/google/go-github/pull/1789?src=pr&el=tree) | Coverage Δ | |
|---|---|---|
| [github/actions\_runners.go](https://codecov.io/gh/google/go-github/pull/1789/diff?src=pr&el=tree#diff-Z2l0aHViL2FjdGlvbnNfcnVubmVycy5nbw==) | `81.94% <0.00%> (-18.06%)` | :arrow_down: |

------

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

zetaab: @gmlewis now we could merge this?

Patch:
diff --git a/github/enterprise_actions_runners.go b/github/enterprise_actions_runners.go
index c3cd2ed4..d2758fe8 100644
--- a/github/enterprise_actions_runners.go
+++ b/github/enterprise_actions_runners.go
@@ -53,3 +53,17 @@ func (s *EnterpriseService) ListRunners(ctx context.Context, enterprise string,
 
 	return runners, resp, nil
 }
+
+// RemoveRunner forces the removal of a self-hosted runner from an enterprise using the runner id.
+//
+// GitHub API docs: https://docs.github.com/en/free-pro-team@latest/rest/reference/enterprise-admin/#delete-a-self-hosted-runner-from-an-enterprise
+func (s *EnterpriseService) RemoveRunner(ctx context.Context, enterprise string, runnerID int64) (*Response, error) {
+	u := fmt.Sprintf("enterprises/%v/actions/runners/%v", enterprise, runnerID)
+
+	req, err := s.client.NewRequest("DELETE", u, nil)
+	if err != nil {
+		return nil, err
+	}
+
+	return s.client.Do(ctx, req, nil)
+}


Test patch:
diff --git a/github/enterprise_actions_runners_test.go b/github/enterprise_actions_runners_test.go
index cb5cab5d..5cf9a70f 100644
--- a/github/enterprise_actions_runners_test.go
+++ b/github/enterprise_actions_runners_test.go
@@ -93,3 +93,28 @@ func TestEnterpriseService_ListRunners(t *testing.T) {
 		return resp, err
 	})
 }
+
+func TestEnterpriseService_RemoveRunner(t *testing.T) {
+	client, mux, _, teardown := setup()
+	defer teardown()
+
+	mux.HandleFunc("/enterprises/o/actions/runners/21", func(w http.ResponseWriter, r *http.Request) {
+		testMethod(t, r, "DELETE")
+	})
+
+	ctx := context.Background()
+	_, err := client.Enterprise.RemoveRunner(ctx, "o", 21)
+	if err != nil {
+		t.Errorf("Actions.RemoveRunner returned error: %v", err)
+	}
+
+	const methodName = "RemoveRunner"
+	testBadOptions(t, methodName, func() (err error) {
+		_, err = client.Enterprise.RemoveRunner(ctx, "\n", 21)
+		return err
+	})
+
+	testNewRequestAndDoFailure(t, methodName, client, func() (*Response, error) {
+		return client.Enterprise.RemoveRunner(ctx, "o", 21)
+	})
+}