Skip to content
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
23 changes: 23 additions & 0 deletions github/respository_rules_utils.go
Original file line number Diff line number Diff line change
Expand Up @@ -472,6 +472,29 @@ func flattenRules(rules []*github.RepositoryRule, org bool) []interface{} {
rule["required_check"] = requiredStatusChecksSlice
rule["strict_required_status_checks_policy"] = params.StrictRequiredStatusChecksPolicy
rulesMap[v.Type] = []map[string]interface{}{rule}

case "workflows":
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

How might this behavior be unit tested?

var params github.RequiredWorkflowsRuleParameters
log.Printf("[DEBUG] osama test: %v", v.Parameters)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can you remove this before we merge?


err := json.Unmarshal(*v.Parameters, &params)
if err != nil {
log.Printf("[INFO] Unexpected error unmarshalling rule %s with parameters: %v",
v.Type, v.Parameters)
}

requiredWorkflowsSlice := make([]map[string]interface{}, 0)
for _, workflow := range params.RequiredWorkflows {
requiredWorkflowsSlice = append(requiredWorkflowsSlice, map[string]interface{}{
"repository_id": workflow.RepositoryID,
"ref": *workflow.Ref,
"path": workflow.Path,
})
}

rule := make(map[string]interface{})
rule["required_workflow"] = requiredWorkflowsSlice
rulesMap[v.Type] = []map[string]interface{}{rule}
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
rulesMap[v.Type] = []map[string]interface{}{rule}
rulesMap["required_workflows"] = []map[string]interface{}{rule}

you cannot use "v.Type" because it is named required_workflows in the scheme, not workflows. Look in my PR, I also add "do_not_enforce_on_create" to the scheme

}
}

Expand Down