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

support env vars for options in server config #364

Merged
merged 4 commits into from
Jan 14, 2022

Conversation

devinburnette
Copy link
Contributor

Closes #363

As discussed in the attached issue, I've made an attempt at setting the policy path and shared options from env vars if they exist. If env vars are not set, then it should just fall back to the defaults. Let me know if there's a more clever way of accomplishing the same. I also updated the example config to reflect the possibilities.

server/config.go Outdated
}
if v, ok := os.LookupEnv("POLICYBOT_STATUS_CHECK_CONTEXT"); ok {
c.Options.StatusCheckContext = v
}
Copy link
Contributor Author

Choose a reason for hiding this comment

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

This would work right? @bluekeyes

setStringFromEnv("SHARED_POLICY_PATH", prefix, &p.SharedPolicyPath)
setStringFromEnv("STATUS_CHECK_CONTEXT", prefix, &p.StatusCheckContext)
p.fillDefaults()
}
Copy link
Contributor Author

@devinburnette devinburnette Jan 14, 2022

Choose a reason for hiding this comment

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

i think maybe this is the better way mirroring your pattern from go-baseapp and go-githubapp, but i felt like these options weren't suited to live in those codebases. so i put them here instead.

only thing i felt weird about was setting the defaults here, probably fine, but let me know what you think

Copy link
Member

Choose a reason for hiding this comment

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

I agree it's a bit weird, but I think it's fine since this is only used in one place.

@@ -126,7 +126,8 @@ define a `remote` key. Only 1 level of remote configuration is supported by desi

```yaml
# The remote repository to read the policy file from. This is required, and must
# be in the form of "org/repo-name". Must be a public repository.
# be in the form of "org/repo-name". The policy bot github app must have read
# access to this repository.
Copy link
Contributor Author

Choose a reason for hiding this comment

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

i added this because it was little misleading

Copy link
Member

Choose a reason for hiding this comment

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

Thanks, that's probably a bit clearer... hopefully it is implied that apps have read access to public repositories.

@devinburnette devinburnette force-pushed the set-options-from-env-vars branch from 5aa1ddd to 73e29f0 Compare January 14, 2022 16:01
`policy-bot` works with private repositories, but currently does not support
pull requests from private _forks_ of private repositories due to GitHub API
limitations. Please file an issue if this functionality is important to you.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

removing this, because I don't think it's true anymore. private forks of private repos seem to work fine on my end.

Copy link
Member

Choose a reason for hiding this comment

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

Interesting, this was originally added due to this fallback condition when loading commit pushed dates. Maybe GitHub improved the GraphQL API so that pushed dates are returned from forks now and we don't need the fallback.

Copy link
Member

@bluekeyes bluekeyes left a comment

Choose a reason for hiding this comment

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

Looks good, thanks for updating the docs along with this.

@@ -126,7 +126,8 @@ define a `remote` key. Only 1 level of remote configuration is supported by desi

```yaml
# The remote repository to read the policy file from. This is required, and must
# be in the form of "org/repo-name". Must be a public repository.
# be in the form of "org/repo-name". The policy bot github app must have read
# access to this repository.
Copy link
Member

Choose a reason for hiding this comment

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

Thanks, that's probably a bit clearer... hopefully it is implied that apps have read access to public repositories.

`policy-bot` works with private repositories, but currently does not support
pull requests from private _forks_ of private repositories due to GitHub API
limitations. Please file an issue if this functionality is important to you.

Copy link
Member

Choose a reason for hiding this comment

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

Interesting, this was originally added due to this fallback condition when loading commit pushed dates. Maybe GitHub improved the GraphQL API so that pushed dates are returned from forks now and we don't need the fallback.

setStringFromEnv("SHARED_POLICY_PATH", prefix, &p.SharedPolicyPath)
setStringFromEnv("STATUS_CHECK_CONTEXT", prefix, &p.StatusCheckContext)
p.fillDefaults()
}
Copy link
Member

Choose a reason for hiding this comment

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

I agree it's a bit weird, but I think it's fine since this is only used in one place.

@bluekeyes bluekeyes merged commit d76287e into palantir:develop Jan 14, 2022
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.

Support Env Variables for Options in Server Config
2 participants