Skip to content

Commit 30e6569

Browse files
authored
Merge branch 'main' into v6
2 parents 5a2df39 + 819abbf commit 30e6569

3 files changed

+30
-10
lines changed

github/resource_github_organization_ruleset.go

+4-3
Original file line numberDiff line numberDiff line change
@@ -44,9 +44,10 @@ func resourceGithubOrganizationRuleset() *schema.Resource {
4444
Description: "Possible values for Enforcement are `disabled`, `active`, `evaluate`. Note: `evaluate` is currently only supported for owners of type `organization`.",
4545
},
4646
"bypass_actors": {
47-
Type: schema.TypeList,
48-
Optional: true,
49-
Description: "The actors that can bypass the rules in this ruleset.",
47+
Type: schema.TypeList,
48+
Optional: true,
49+
DiffSuppressFunc: bypassActorsDiffSuppressFunc,
50+
Description: "The actors that can bypass the rules in this ruleset.",
5051
Elem: &schema.Resource{
5152
Schema: map[string]*schema.Schema{
5253
"actor_id": {

github/resource_github_repository_ruleset.go

+4-3
Original file line numberDiff line numberDiff line change
@@ -49,9 +49,10 @@ func resourceGithubRepositoryRuleset() *schema.Resource {
4949
Description: "Possible values for Enforcement are `disabled`, `active`, `evaluate`. Note: `evaluate` is currently only supported for owners of type `organization`.",
5050
},
5151
"bypass_actors": {
52-
Type: schema.TypeList,
53-
Optional: true,
54-
Description: "The actors that can bypass the rules in this ruleset.",
52+
Type: schema.TypeList,
53+
Optional: true,
54+
DiffSuppressFunc: bypassActorsDiffSuppressFunc,
55+
Description: "The actors that can bypass the rules in this ruleset.",
5556
Elem: &schema.Resource{
5657
Schema: map[string]*schema.Schema{
5758
"actor_id": {

github/respository_rules_utils.go

+22-4
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ package github
33
import (
44
"encoding/json"
55
"log"
6+
"reflect"
67
"sort"
78

89
"github.com/google/go-github/v57/github"
@@ -63,10 +64,6 @@ func flattenBypassActors(bypassActors []*github.BypassActor) []interface{} {
6364
return []interface{}{}
6465
}
6566

66-
sort.SliceStable(bypassActors, func(i, j int) bool {
67-
return bypassActors[i].GetActorID() > bypassActors[j].GetActorID()
68-
})
69-
7067
actorsSlice := make([]interface{}, 0)
7168
for _, v := range bypassActors {
7269
actorMap := make(map[string]interface{})
@@ -480,3 +477,24 @@ func flattenRules(rules []*github.RepositoryRule, org bool) []interface{} {
480477

481478
return []interface{}{rulesMap}
482479
}
480+
481+
func bypassActorsDiffSuppressFunc(k, old, new string, d *schema.ResourceData) bool {
482+
// If the length has changed, no need to suppress
483+
if k == "bypass_actors.#" {
484+
return old == new
485+
}
486+
487+
// Get change to bypass actors
488+
o, n := d.GetChange("bypass_actors")
489+
oldBypassActors := o.([]interface{})
490+
newBypassActors := n.([]interface{})
491+
492+
sort.SliceStable(oldBypassActors, func(i, j int) bool {
493+
return oldBypassActors[i].(map[string]interface{})["actor_id"].(int) > oldBypassActors[j].(map[string]interface{})["actor_id"].(int)
494+
})
495+
sort.SliceStable(newBypassActors, func(i, j int) bool {
496+
return newBypassActors[i].(map[string]interface{})["actor_id"].(int) > newBypassActors[j].(map[string]interface{})["actor_id"].(int)
497+
})
498+
499+
return reflect.DeepEqual(oldBypassActors, newBypassActors)
500+
}

0 commit comments

Comments
 (0)