Repository: google/go-github
Pull request #2843 (2023-07-26 03:39:33)

Add `old_name` field to `AuditEntry`
This field is used when a repository is renamed.

Fixes: #2844.

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

View this [failed invocation](https://github.com/google/go-github/pull/2843/checks?check_run_id=15347571595) of the CLA check for more information.

For the most up to date status, view the checks section at the bottom of the pull request.
gmlewis: Please run `go generate ./...` in the top of this repo and push (not force-push) the changes to this PR.
See CONTRIBUTING.md for details.
lmartinking: @gmlewis I've run the codegen, as well as rebased against `main`
codecov[bot]: ## [Codecov](https://app.codecov.io/gh/google/go-github/pull/2843?src=pr&el=h1&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=google) Report
> Merging [#2843](https://app.codecov.io/gh/google/go-github/pull/2843?src=pr&el=desc&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=google) (b185d31) into [master](https://app.codecov.io/gh/google/go-github/commit/7e3bb17f55bfb162bf77a3d42f5476ba23194dfb?el=desc&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=google) (7e3bb17) will **not change** coverage.
> The diff coverage is `n/a`.

```diff
@@           Coverage Diff           @@
##           master    #2843   +/-   ##
=======================================
  Coverage   98.06%   98.06%           
=======================================
  Files         138      138           
  Lines       12318    12318           
=======================================
  Hits        12080    12080           
  Misses        162      162           
  Partials       76       76           
```


| [Files Changed](https://app.codecov.io/gh/google/go-github/pull/2843?src=pr&el=tree&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=google) | Coverage Δ | |
|---|---|---|
| [github/orgs\_audit\_log.go](https://app.codecov.io/gh/google/go-github/pull/2843?src=pr&el=tree&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=google#diff-Z2l0aHViL29yZ3NfYXVkaXRfbG9nLmdv) | `100.00% <ø> (ø)` | |



Patch:
diff --git a/github/code-scanning.go b/github/code-scanning.go
index e4a6abeb..09c03647 100644
--- a/github/code-scanning.go
+++ b/github/code-scanning.go
@@ -122,6 +122,12 @@ type AlertListOptions struct {
 	// Return code scanning alerts for a specific branch reference. The ref must be formatted as heads/<branch name>.
 	Ref string `url:"ref,omitempty"`
 
+	// If specified, only code scanning alerts with this severity will be returned. Possible values are: critical, high, medium, low, warning, note, error.
+	Severity string `url:"severity,omitempty"`
+
+	// The name of a code scanning tool. Only results by this tool will be listed.
+	ToolName string `url:"tool_name,omitempty"`
+
 	ListCursorOptions
 
 	// Add ListOptions so offset pagination with integer type "page" query parameter is accepted
diff --git a/github/github-accessors.go b/github/github-accessors.go
index e8d4e1ac..942ec6a9 100644
--- a/github/github-accessors.go
+++ b/github/github-accessors.go
@@ -1278,6 +1278,14 @@ func (a *AuditEntry) GetOAuthApplicationID() int64 {
 	return *a.OAuthApplicationID
 }
 
+// GetOldName returns the OldName field if it's non-nil, zero value otherwise.
+func (a *AuditEntry) GetOldName() string {
+	if a == nil || a.OldName == nil {
+		return ""
+	}
+	return *a.OldName
+}
+
 // GetOldPermission returns the OldPermission field if it's non-nil, zero value otherwise.
 func (a *AuditEntry) GetOldPermission() string {
 	if a == nil || a.OldPermission == nil {
diff --git a/github/orgs_audit_log.go b/github/orgs_audit_log.go
index e2e4692e..a8691053 100644
--- a/github/orgs_audit_log.go
+++ b/github/orgs_audit_log.go
@@ -78,6 +78,7 @@ type AuditEntry struct {
 	Message                *string                 `json:"message,omitempty"`
 	Name                   *string                 `json:"name,omitempty"`
 	OAuthApplicationID     *int64                  `json:"oauth_application_id,omitempty"`
+	OldName                *string                 `json:"old_name,omitempty"` // The previous name of the repository, for a name change
 	OldUser                *string                 `json:"old_user,omitempty"`
 	OldPermission          *string                 `json:"old_permission,omitempty"` // The permission level for membership changes, for example `admin` or `read`.
 	OpenSSHPublicKey       *string                 `json:"openssh_public_key,omitempty"`


Test patch:
diff --git a/github/code-scanning_test.go b/github/code-scanning_test.go
index 29c0b617..20d4817d 100644
--- a/github/code-scanning_test.go
+++ b/github/code-scanning_test.go
@@ -95,7 +95,7 @@ func TestCodeScanningService_ListAlertsForOrg(t *testing.T) {
 
 	mux.HandleFunc("/orgs/o/code-scanning/alerts", func(w http.ResponseWriter, r *http.Request) {
 		testMethod(t, r, "GET")
-		testFormValues(t, r, values{"state": "open", "ref": "heads/master"})
+		testFormValues(t, r, values{"state": "open", "ref": "heads/master", "severity": "warning", "tool_name": "CodeQL"})
 		fmt.Fprint(w, `[{
 				"repository": {
 					"id": 1,
@@ -187,7 +187,7 @@ func TestCodeScanningService_ListAlertsForOrg(t *testing.T) {
 				}]`)
 	})
 
-	opts := &AlertListOptions{State: "open", Ref: "heads/master"}
+	opts := &AlertListOptions{State: "open", Ref: "heads/master", Severity: "warning", ToolName: "CodeQL"}
 	ctx := context.Background()
 	alerts, _, err := client.CodeScanning.ListAlertsForOrg(ctx, "o", opts)
 	if err != nil {
@@ -299,7 +299,7 @@ func TestCodeScanningService_ListAlertsForOrgLisCursorOptions(t *testing.T) {
 
 	mux.HandleFunc("/orgs/o/code-scanning/alerts", func(w http.ResponseWriter, r *http.Request) {
 		testMethod(t, r, "GET")
-		testFormValues(t, r, values{"state": "open", "ref": "heads/master", "per_page": "1", "before": "deadbeefb", "after": "deadbeefa"})
+		testFormValues(t, r, values{"state": "open", "ref": "heads/master", "severity": "warning", "tool_name": "CodeQL", "per_page": "1", "before": "deadbeefb", "after": "deadbeefa"})
 		fmt.Fprint(w, `[{
 				"repository": {
 					"id": 1,
@@ -349,7 +349,7 @@ func TestCodeScanningService_ListAlertsForOrgLisCursorOptions(t *testing.T) {
 				}]`)
 	})
 
-	opts := &AlertListOptions{State: "open", Ref: "heads/master", ListCursorOptions: ListCursorOptions{PerPage: 1, Before: "deadbeefb", After: "deadbeefa"}}
+	opts := &AlertListOptions{State: "open", Ref: "heads/master", Severity: "warning", ToolName: "CodeQL", ListCursorOptions: ListCursorOptions{PerPage: 1, Before: "deadbeefb", After: "deadbeefa"}}
 	ctx := context.Background()
 	alerts, _, err := client.CodeScanning.ListAlertsForOrg(ctx, "o", opts)
 	if err != nil {
@@ -425,7 +425,7 @@ func TestCodeScanningService_ListAlertsForRepo(t *testing.T) {
 
 	mux.HandleFunc("/repos/o/r/code-scanning/alerts", func(w http.ResponseWriter, r *http.Request) {
 		testMethod(t, r, "GET")
-		testFormValues(t, r, values{"state": "open", "ref": "heads/master"})
+		testFormValues(t, r, values{"state": "open", "ref": "heads/master", "severity": "warning", "tool_name": "CodeQL"})
 		fmt.Fprint(w, `[{
 				"rule_id":"js/trivial-conditional",
 				"rule_severity":"warning",
@@ -512,7 +512,7 @@ func TestCodeScanningService_ListAlertsForRepo(t *testing.T) {
 				}]`)
 	})
 
-	opts := &AlertListOptions{State: "open", Ref: "heads/master"}
+	opts := &AlertListOptions{State: "open", Ref: "heads/master", Severity: "warning", ToolName: "CodeQL"}
 	ctx := context.Background()
 	alerts, _, err := client.CodeScanning.ListAlertsForRepo(ctx, "o", "r", opts)
 	if err != nil {
diff --git a/github/github-accessors_test.go b/github/github-accessors_test.go
index 2385aeb0..4eafaf25 100644
--- a/github/github-accessors_test.go
+++ b/github/github-accessors_test.go
@@ -1514,6 +1514,16 @@ func TestAuditEntry_GetOAuthApplicationID(tt *testing.T) {
 	a.GetOAuthApplicationID()
 }
 
+func TestAuditEntry_GetOldName(tt *testing.T) {
+	var zeroValue string
+	a := &AuditEntry{OldName: &zeroValue}
+	a.GetOldName()
+	a = &AuditEntry{}
+	a.GetOldName()
+	a = nil
+	a.GetOldName()
+}
+
 func TestAuditEntry_GetOldPermission(tt *testing.T) {
 	var zeroValue string
 	a := &AuditEntry{OldPermission: &zeroValue}
diff --git a/github/orgs_audit_log_test.go b/github/orgs_audit_log_test.go
index 8d33a986..a5873ee4 100644
--- a/github/orgs_audit_log_test.go
+++ b/github/orgs_audit_log_test.go
@@ -256,6 +256,7 @@ func TestAuditEntry_Marshal(t *testing.T) {
 		LimitedAvailability:    Bool(false),
 		Message:                String("m"),
 		Name:                   String("n"),
+		OldName:                String("on"),
 		OldPermission:          String("op"),
 		OldUser:                String("ou"),
 		OpenSSHPublicKey:       String("osshpk"),
@@ -345,6 +346,7 @@ func TestAuditEntry_Marshal(t *testing.T) {
 		"limited_availability": false,
 		"message": "m",
 		"name": "n",
+                "old_name": "on",
 		"old_permission": "op",
 		"old_user": "ou",
 		"openssh_public_key": "osshpk",