Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

🐛 Check GitHub RequiredPullRequestReviews before access #845

Merged
merged 2 commits into from
Jan 27, 2023

Conversation

czunker
Copy link
Contributor

@czunker czunker commented Jan 27, 2023

Fixes mondoohq/cnspec#289

Signed-off-by: Christian Zunker [email protected]

Users: []string{},
Teams: []string{},
}
rprr, err := core.JsonToDict(githubRequiredPullRequestReviews{})
Copy link
Member

Choose a reason for hiding this comment

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

why do you not initialize this as nil? It's making the code shorter and it won't do unnecessary work of serializing stuff.

Suggested change
rprr, err := core.JsonToDict(githubRequiredPullRequestReviews{})
var rprr map[string]interface{}

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Good point. Thanks.

ghDismissalRestrictions.Users = append(ghDismissalRestrictions.Users, branchProtection.RequiredPullRequestReviews.DismissalRestrictions.Users[i].GetLogin())
if branchProtection.RequiredPullRequestReviews.DismissalRestrictions != nil {
ghDismissalRestrictions = &githubDismissalRestrictions{
Users: []string{},
Copy link
Member

Choose a reason for hiding this comment

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

nit: when possible I try to initialize slices with the correct size beforehand. This makes memory allocation a bit more efficient since the underlying array doesn't need to be extended and copied in memory.

Suggested change
Users: []string{},
Users: make([]string{}, 0, len(branchProtection.RequiredPullRequestReviews.DismissalRestrictions.Users)),

This means create a slice with length 0 with an underlying array of size len(branchProtection...)

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Changed.

Signed-off-by: Christian Zunker <[email protected]>
@czunker czunker merged commit ae629f6 into main Jan 27, 2023
@czunker czunker deleted the christian/github_pr_rules branch January 27, 2023 16:34
@github-actions github-actions bot locked and limited conversation to collaborators Jan 27, 2023
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

cnspec panics when getting GitHub repo protection rules
3 participants