Repository: google/go-github
Pull request #3316 (2024-10-08 08:28:18)

feat: Add CreatedAt and UpdatedAt to Ruleset
This PR will expose fields `CreatedAt` and `UpdatedAt` for `Ruleset`

Closes https://github.com/google/go-github/issues/3315

codecov[bot]: ## [Codecov](https://app.codecov.io/gh/google/go-github/pull/3316?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.05%. 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 [(`bd4a180`)](https://app.codecov.io/gh/google/go-github/commit/bd4a180bd3fb95b08b93f74ba4b9e6e20d70b396?dropdown=coverage&el=desc&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=google).
> Report is 141 commits behind head on master.

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


```diff
@@            Coverage Diff             @@
##           master    #3316      +/-   ##
==========================================
- Coverage   97.72%   93.05%   -4.67%     
==========================================
  Files         153      172      +19     
  Lines       13390    11772    -1618     
==========================================
- Hits        13085    10955    -2130     
- Misses        215      723     +508     
- Partials       90       94       +4     
```

</details>

[:umbrella: View full report in Codecov by Sentry](https://app.codecov.io/gh/google/go-github/pull/3316?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).


Patch:
diff --git a/github/github-accessors.go b/github/github-accessors.go
index f8e303c4..1c1f6c33 100644
--- a/github/github-accessors.go
+++ b/github/github-accessors.go
@@ -21150,6 +21150,14 @@ func (r *Ruleset) GetConditions() *RulesetConditions {
 	return r.Conditions
 }
 
+// GetCreatedAt returns the CreatedAt field if it's non-nil, zero value otherwise.
+func (r *Ruleset) GetCreatedAt() Timestamp {
+	if r == nil || r.CreatedAt == nil {
+		return Timestamp{}
+	}
+	return *r.CreatedAt
+}
+
 // GetID returns the ID field if it's non-nil, zero value otherwise.
 func (r *Ruleset) GetID() int64 {
 	if r == nil || r.ID == nil {
@@ -21190,6 +21198,14 @@ func (r *Ruleset) GetTarget() string {
 	return *r.Target
 }
 
+// GetUpdatedAt returns the UpdatedAt field if it's non-nil, zero value otherwise.
+func (r *Ruleset) GetUpdatedAt() Timestamp {
+	if r == nil || r.UpdatedAt == nil {
+		return Timestamp{}
+	}
+	return *r.UpdatedAt
+}
+
 // GetRefName returns the RefName field.
 func (r *RulesetConditions) GetRefName() *RulesetRefConditionParameters {
 	if r == nil {
diff --git a/github/repos_rules.go b/github/repos_rules.go
index d09bb71d..ca9e9ea8 100644
--- a/github/repos_rules.go
+++ b/github/repos_rules.go
@@ -548,6 +548,8 @@ type Ruleset struct {
 	Links        *RulesetLinks      `json:"_links,omitempty"`
 	Conditions   *RulesetConditions `json:"conditions,omitempty"`
 	Rules        []*RepositoryRule  `json:"rules,omitempty"`
+	UpdatedAt    *Timestamp         `json:"updated_at,omitempty"`
+	CreatedAt    *Timestamp         `json:"created_at,omitempty"`
 }
 
 // rulesetNoOmitBypassActors represents a GitHub ruleset object. The struct does not omit bypassActors if the field is nil or an empty array is passed.


Test patch:
diff --git a/github/github-accessors_test.go b/github/github-accessors_test.go
index b9b4b08b..46920943 100644
--- a/github/github-accessors_test.go
+++ b/github/github-accessors_test.go
@@ -27208,6 +27208,17 @@ func TestRuleset_GetConditions(tt *testing.T) {
 	r.GetConditions()
 }
 
+func TestRuleset_GetCreatedAt(tt *testing.T) {
+	tt.Parallel()
+	var zeroValue Timestamp
+	r := &Ruleset{CreatedAt: &zeroValue}
+	r.GetCreatedAt()
+	r = &Ruleset{}
+	r.GetCreatedAt()
+	r = nil
+	r.GetCreatedAt()
+}
+
 func TestRuleset_GetID(tt *testing.T) {
 	tt.Parallel()
 	var zeroValue int64
@@ -27260,6 +27271,17 @@ func TestRuleset_GetTarget(tt *testing.T) {
 	r.GetTarget()
 }
 
+func TestRuleset_GetUpdatedAt(tt *testing.T) {
+	tt.Parallel()
+	var zeroValue Timestamp
+	r := &Ruleset{UpdatedAt: &zeroValue}
+	r.GetUpdatedAt()
+	r = &Ruleset{}
+	r.GetUpdatedAt()
+	r = nil
+	r.GetUpdatedAt()
+}
+
 func TestRulesetConditions_GetRefName(tt *testing.T) {
 	tt.Parallel()
 	r := &RulesetConditions{}
diff --git a/github/repos_rules_test.go b/github/repos_rules_test.go
index 809bd9a8..a34b84cd 100644
--- a/github/repos_rules_test.go
+++ b/github/repos_rules_test.go
@@ -489,14 +489,18 @@ func TestRepositoriesService_GetAllRulesets(t *testing.T) {
 			  "name": "ruleset",
 			  "source_type": "Repository",
 			  "source": "o/repo",
-			  "enforcement": "enabled"
+			  "enforcement": "enabled",
+			  "created_at": `+referenceTimeStr+`,
+			  "updated_at": `+referenceTimeStr+`
 			},
 			{
 			  "id": 314,
 			  "name": "Another ruleset",
 			  "source_type": "Repository",
 			  "source": "o/repo",
-			  "enforcement": "enabled"
+			  "enforcement": "enabled",
+			  "created_at": `+referenceTimeStr+`,
+			  "updated_at": `+referenceTimeStr+`
 			}
 		]`)
 	})
@@ -514,6 +518,8 @@ func TestRepositoriesService_GetAllRulesets(t *testing.T) {
 			SourceType:  String("Repository"),
 			Source:      "o/repo",
 			Enforcement: "enabled",
+			CreatedAt:   &Timestamp{referenceTime},
+			UpdatedAt:   &Timestamp{referenceTime},
 		},
 		{
 			ID:          Int64(314),
@@ -521,6 +527,8 @@ func TestRepositoriesService_GetAllRulesets(t *testing.T) {
 			SourceType:  String("Repository"),
 			Source:      "o/repo",
 			Enforcement: "enabled",
+			CreatedAt:   &Timestamp{referenceTime},
+			UpdatedAt:   &Timestamp{referenceTime},
 		},
 	}
 	if !cmp.Equal(ruleSet, want) {
@@ -683,7 +691,9 @@ func TestRepositoriesService_GetRuleset(t *testing.T) {
 			"name": "ruleset",
 			"source_type": "Organization",
 			"source": "o",
-			"enforcement": "enabled"
+			"enforcement": "enabled",
+			"created_at": `+referenceTimeStr+`,
+			"updated_at": `+referenceTimeStr+`
 		}`)
 	})
 
@@ -699,6 +709,8 @@ func TestRepositoriesService_GetRuleset(t *testing.T) {
 		SourceType:  String("Organization"),
 		Source:      "o",
 		Enforcement: "enabled",
+		CreatedAt:   &Timestamp{referenceTime},
+		UpdatedAt:   &Timestamp{referenceTime},
 	}
 	if !cmp.Equal(ruleSet, want) {
 		t.Errorf("Repositories.GetRuleset returned %+v, want %+v", ruleSet, want)