Repository: google/go-github
Pull request #1555 (2020-06-09 14:23:13)

Add DeleteDeployment for Repositories
Addresses #1554 

googlebot: 
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%2F1555) for more info**.

<!-- need_sender_cla -->
codecov[bot]: # [Codecov](https://codecov.io/gh/google/go-github/pull/1555?src=pr&el=h1) Report
> Merging [#1555](https://codecov.io/gh/google/go-github/pull/1555?src=pr&el=desc) into [master](https://codecov.io/gh/google/go-github/commit/dbeb049409f0ee601f5bb1d4d33d0df86b64003b&el=desc) will **decrease** coverage by `0.00%`.
> The diff coverage is `57.14%`.

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

```diff
@@            Coverage Diff             @@
##           master    #1555      +/-   ##
==========================================
- Coverage   67.92%   67.91%   -0.01%     
==========================================
  Files          94       94              
  Lines        8670     8677       +7     
==========================================
+ Hits         5889     5893       +4     
- Misses       1880     1882       +2     
- Partials      901      902       +1     
```


| [Impacted Files](https://codecov.io/gh/google/go-github/pull/1555?src=pr&el=tree) | Coverage Δ | |
|---|---|---|
| [github/repos\_deployments.go](https://codecov.io/gh/google/go-github/pull/1555/diff?src=pr&el=tree#diff-Z2l0aHViL3JlcG9zX2RlcGxveW1lbnRzLmdv) | `56.31% <57.14%> (+0.06%)` | :arrow_up: |

------

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

gmlewis: This looks great, @nomonamo - thank you!  

Please make sure to sign the Google CLA (see instructions above), and then we can get it approved and merged.
nomonamo: @googlebot I signed it!
nomonamo: > 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).
> 
> 📝 **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%2F1555) for more info**.

@googlebot I signed it!
nomonamo: @googlebot I signed it!
googlebot: CLAs look good, thanks!

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

<!-- ok -->
nomonamo: > @willnorris - when you get a chance, could you please give @nomonamo some guidance on getting the CLA issues straightened out? Thank you!

Took us some time to get the "Corporate signer" CLA right :) 
Thanks for your comment! I'm not sure how to fix the checks from codecov though?
gmlewis: I'm glad you got it fixed. We use the codecov tool as a guideline and not a strict blocker so you do not need to be concerned about it. Ideally, we will increase the code coverage by writing unit tests that cover more code paths.
nomonamo: Thank you @nightlark and @gmlewis for reviewing 🙏   I've addressed your comments

Patch:
diff --git a/github/actions_workflow_runs.go b/github/actions_workflow_runs.go
index 14d6cd34..47305797 100644
--- a/github/actions_workflow_runs.go
+++ b/github/actions_workflow_runs.go
@@ -22,6 +22,7 @@ type WorkflowRun struct {
 	Event          *string        `json:"event,omitempty"`
 	Status         *string        `json:"status,omitempty"`
 	Conclusion     *string        `json:"conclusion,omitempty"`
+	WorkflowID     *int64         `json:"workflow_id,omitempty"`
 	URL            *string        `json:"url,omitempty"`
 	HTMLURL        *string        `json:"html_url,omitempty"`
 	PullRequests   []*PullRequest `json:"pull_requests,omitempty"`
diff --git a/github/github-accessors.go b/github/github-accessors.go
index a344a557..336beecc 100644
--- a/github/github-accessors.go
+++ b/github/github-accessors.go
@@ -14596,6 +14596,14 @@ func (w *WorkflowRun) GetURL() string {
 	return *w.URL
 }
 
+// GetWorkflowID returns the WorkflowID field if it's non-nil, zero value otherwise.
+func (w *WorkflowRun) GetWorkflowID() int64 {
+	if w == nil || w.WorkflowID == nil {
+		return 0
+	}
+	return *w.WorkflowID
+}
+
 // GetWorkflowURL returns the WorkflowURL field if it's non-nil, zero value otherwise.
 func (w *WorkflowRun) GetWorkflowURL() string {
 	if w == nil || w.WorkflowURL == nil {
diff --git a/github/pulls.go b/github/pulls.go
index 685493f1..ad372d45 100644
--- a/github/pulls.go
+++ b/github/pulls.go
@@ -439,7 +439,7 @@ type PullRequestMergeResult struct {
 
 // PullRequestOptions lets you define how a pull request will be merged.
 type PullRequestOptions struct {
-	CommitTitle string // Extra detail to append to automatic commit message. (Optional.)
+	CommitTitle string // Title for the automatic commit message. (Optional.)
 	SHA         string // SHA that pull request head must match to allow merge. (Optional.)
 
 	// The merge method to use. Possible values include: "merge", "squash", and "rebase" with the default being merge. (Optional.)
@@ -453,10 +453,10 @@ type pullRequestMergeRequest struct {
 	SHA           string `json:"sha,omitempty"`
 }
 
-// Merge a pull request (Merge Button™).
-// commitMessage is the title for the automatic commit message.
+// Merge a pull request.
+// commitMessage is an extra detail to append to automatic commit message.
 //
-// GitHub API docs: https://developer.github.com/v3/pulls/#merge-a-pull-request-merge-button
+// GitHub API docs: https://developer.github.com/v3/pulls/#merge-a-pull-request
 func (s *PullRequestsService) Merge(ctx context.Context, owner string, repo string, number int, commitMessage string, options *PullRequestOptions) (*PullRequestMergeResult, *Response, error) {
 	u := fmt.Sprintf("repos/%v/%v/pulls/%d/merge", owner, repo, number)
 
diff --git a/github/repos_deployments.go b/github/repos_deployments.go
index 57de0a22..3caa9730 100644
--- a/github/repos_deployments.go
+++ b/github/repos_deployments.go
@@ -129,6 +129,18 @@ func (s *RepositoriesService) CreateDeployment(ctx context.Context, owner, repo
 	return d, resp, nil
 }
 
+// DeleteDeployment deletes an existing deployment for a repository.
+//
+// GitHub API docs: https://developer.github.com/v3/repos/deployments/#delete-a-deployment
+func (s *RepositoriesService) DeleteDeployment(ctx context.Context, owner, repo string, deploymentID int64) (*Response, error) {
+	u := fmt.Sprintf("repos/%v/%v/deployments/%v", owner, repo, deploymentID)
+	req, err := s.client.NewRequest("DELETE", u, nil)
+	if err != nil {
+		return nil, err
+	}
+	return s.client.Do(ctx, req, nil)
+}
+
 // DeploymentStatus represents the status of a
 // particular deployment.
 type DeploymentStatus struct {


Test patch:
diff --git a/github/repos_deployments_test.go b/github/repos_deployments_test.go
index fdbfdd3a..53f8cec5 100644
--- a/github/repos_deployments_test.go
+++ b/github/repos_deployments_test.go
@@ -89,6 +89,32 @@ func TestRepositoriesService_CreateDeployment(t *testing.T) {
 	}
 }
 
+func TestRepositoriesService_DeleteDeployment(t *testing.T) {
+	client, mux, _, teardown := setup()
+	defer teardown()
+
+	mux.HandleFunc("/repos/o/r/deployments/1", func(w http.ResponseWriter, r *http.Request) {
+		testMethod(t, r, "DELETE")
+		w.WriteHeader(http.StatusNoContent)
+	})
+
+	resp, err := client.Repositories.DeleteDeployment(context.Background(), "o", "r", 1)
+	if err != nil {
+		t.Errorf("Repositories.DeleteDeployment returned error: %v", err)
+	}
+	if resp.StatusCode != http.StatusNoContent {
+		t.Error("Repositories.DeleteDeployment should return a 204 status")
+	}
+
+	resp, err = client.Repositories.DeleteDeployment(context.Background(), "o", "r", 2)
+	if err == nil {
+		t.Error("Repositories.DeleteDeployment should return an error")
+	}
+	if resp.StatusCode != http.StatusNotFound {
+		t.Error("Repositories.DeleteDeployment should return a 404 status")
+	}
+}
+
 func TestRepositoriesService_ListDeploymentStatuses(t *testing.T) {
 	client, mux, _, teardown := setup()
 	defer teardown()