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

Opt out private/public repos by optOutPrivateRepos/optOutPublicRepos #54

Merged
merged 9 commits into from
Sep 27, 2021

Conversation

five510
Copy link
Contributor

@five510 five510 commented Sep 19, 2021

Changes

  • Opt out private/public repos by optOutPrivateRepos/optOutPublicRepos
  • Add how to opt out by using optOutPrivateRepos/optOutPublicRepos in opt-out.md

@jeffmendoza
Copy link
Member

Thank you for looking into this! I think it would be good for the config to be a part of OrgOptConfig. We want each individual policy to be easily turned on/off for all public/private repos. For example Allstar could be used on all repos, but the SECURITY.md policy only enabled on public repos.

As mentioned, all the policies include OrgOptConfig in their own org config. This is then passed to the IsEnabled helper function along with the repo name. IsEnabled could get the repo info from GitHub (probably needs the org name as well), then include that in the calculation.

An example of getting the repo info is here: https://github.com/ossf/allstar/blob/main/pkg/policies/branch/branch.go#L158-L161

@five510 five510 changed the title Access private/public repos by accessReposConfig in allstars.yaml Opt out private/public repos by optOutPrivateRepos/optOutPublicRepos Sep 23, 2021
@five510
Copy link
Contributor Author

five510 commented Sep 23, 2021

@jeffmendoza
Thank you for support! I completed my implementation with your advice. Could you please review this PR?

@five510 five510 marked this pull request as ready for review September 23, 2021 16:05
@jeffmendoza
Copy link
Member

Sounds good, I'll take a look.

Copy link
Member

@jeffmendoza jeffmendoza left a comment

Choose a reason for hiding this comment

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

Looking great so far. Updating the policy tests may be a bit tedious. Let me know if you'd like some help and I can update those.

opt-out.md Outdated

optConfig:
optOutStrategy: true
optOutRepos:
- my-repo-name-here

To opt-out all private/public repositories, submit a PR to that `.allstar` repo, and add `optOutPrivateRepos` or `optOutPublicRepos`. ex:
Copy link
Member

Choose a reason for hiding this comment

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

I'd like to keep this file focused on a single repository opt-out. Please revert this, and add this section to the end of the section in https://github.com/ossf/allstar/blob/main/README.md#enable-configuration

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Thanks. Updated with 48d36c7 and 75eee18

GetContents(context.Context, string, string, string,
*github.RepositoryContentGetOptions) (*github.RepositoryContent,
[]*github.RepositoryContent, *github.Response, error)
}

// IsEnabled determines if a repo is enabled by interpreting the provided
// org-level and repo-level OptConfigs.
func IsEnabled(o OrgOptConfig, r RepoOptConfig, repo string) bool {
func IsEnabled(ctx context.Context, o OrgOptConfig, r RepoOptConfig, rep repositories, owner, repo string) (bool, error) {
Copy link
Member

Choose a reason for hiding this comment

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

It's not good to have a public function with a parameter of a private type. Also, all the functions/packages only pass around github.Client in code currently. Make IsEnabled() take a github.Client then simply call a private isEnabled() which takes a repositories, then change each policy to pass in the client, not client.Repositories. The tests should then call the private isEnabled with the repositories mock object.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

It makes sense. Updated with a57b1eb.

*github.Response, error) {
b := test.Org.OptOutPrivateRepos
return &github.Repository{
Private: &b,
Copy link
Member

Choose a reason for hiding this comment

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

This should be a separate input for each test, the mock response from github. Then the org config as you have it, then the expected output.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Thanks. Added mock config with d86295d.

enabled, err := config.IsEnabled(ctx, oc.OptConfig, rc.OptConfig, c.Repositories, owner, repo)
if err != nil {
return nil, err
}
Copy link
Member

Choose a reason for hiding this comment

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

Looks like config.IsEnabled will need to be mocked now for all policies, similar to how configFetchConfig is currently mocked. It probably should have been mocked to begin with, as the policy tests don't need to unit test IsEnabled. The policy tests should now have the return value of IsEnabled be an input instead of the org/repo optconfigs.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Thanks. Updated with c59738b.

@five510
Copy link
Contributor Author

five510 commented Sep 27, 2021

@jeffmendoza Could you please check it again? Thanks!

@jeffmendoza jeffmendoza merged commit 500e2e2 into ossf:main Sep 27, 2021
@jeffmendoza
Copy link
Member

@five510 This deployed yesterday and looks like it is working great. Thanks for your contribution!!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants