Skip to content

Commit 0e2a8c4

Browse files
committed
Improve local debug experience
1 parent 4f2566d commit 0e2a8c4

File tree

3 files changed

+32
-6
lines changed

3 files changed

+32
-6
lines changed

config/policy-bot.example.yml

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -107,13 +107,23 @@ sessions:
107107
# # POLICYBOT_OPTIONS_POLICY_PATH environment variable.
108108
# policy_path: .policy.yml
109109
#
110+
# # Force using a shared policy file from the organization repository
111+
# # instead of the policy file in the repository. Can also be set by the
112+
# # POLICYBOT_OPTIONS_FORCE_SHARED_POLICY environment variable.
113+
# force_shared_policy: false
114+
#
110115
# # The name of an organization repository to look in for a shared policy if
111116
# # a repository does not define a policy file. Can also be set by the
112117
# # POLICYBOT_OPTIONS_SHARED_REPOSITORY environment variable. Explicitly set
113118
# # this or `shared_policy_path` to an empty string(`""`) to disable searching
114119
# # in a shared repository.
115120
# shared_repository: .github
116121
#
122+
# # The branch in the shared organization repository to look in for a shared
123+
# # policy file. Can also be set by the POLICYBOT_OPTIONS_SHARED_POLICY_BRANCH environment variable.
124+
# # If not set, the default branch of the repository is used.
125+
# shared_policy_branch: ""
126+
#
117127
# # The path to the policy file in the shared organization repository.
118128
# # Can also be set by the POLICYBOT_OPTIONS_SHARED_POLICY_PATH environment variable.
119129
# shared_policy_path: policy.yml
@@ -122,6 +132,9 @@ sessions:
122132
# # POLICYBOT_OPTIONS_STATUS_CHECK_CONTEXT environment variable.
123133
# status_check_context: policy-bot
124134
#
135+
# # If true, the bot removes the base branch from the status check context.
136+
# status_check_context_ignore_base: true
137+
#
125138
# # If true, expand teams, organizations, and permissions in the detils UI to
126139
# # a list of users. This option has security implications; see the README.
127140
# # Can also be set by the POLICYBOT_OPTIONS_EXPAND_REQUIRED_REVIEWERS
@@ -138,3 +151,9 @@ sessions:
138151
# files:
139152
# static: build/static
140153
# templates: server/templates
154+
155+
# Options for OpenTelemetry tracing.
156+
#
157+
# opentelemetry:
158+
# enabled: true
159+
# google_cloud_support: true

server/handler/eval_options.go

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -40,8 +40,9 @@ type DescriptionPrefix struct {
4040
type PullEvaluationOptions struct {
4141
PolicyPath string `yaml:"policy_path"`
4242

43-
SharedRepository *string `yaml:"shared_repository"`
44-
SharedPolicyPath *string `yaml:"shared_policy_path"`
43+
SharedRepository *string `yaml:"shared_repository"`
44+
SharedPolicyBranch *string `yaml:"shared_policy_branch"`
45+
SharedPolicyPath *string `yaml:"shared_policy_path"`
4546

4647
// Ignore PolicyPath and use SharedRepository and SharedPolicyPath only.
4748
ForceSharedPolicy bool `yaml:"force_shared_policy"`

server/handler/fetcher.go

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -101,12 +101,18 @@ type ConfigFetcher struct {
101101
}
102102

103103
func (cf *ConfigFetcher) configForSharedRepository(ctx context.Context, client *github.Client, owner string) (*FetchedConfig, error) {
104-
r, _, err := client.Repositories.Get(ctx, owner, *cf.Options.SharedRepository)
105-
if err != nil {
106-
return nil, fmt.Errorf("failed to get repository %s/%s: %w", owner, *cf.Options.SharedRepository, err)
104+
var ref string
105+
if cf.Options.SharedPolicyBranch != nil {
106+
ref = *cf.Options.SharedPolicyBranch
107+
} else {
108+
r, _, err := client.Repositories.Get(ctx, owner, *cf.Options.SharedRepository)
109+
if err != nil {
110+
return nil, fmt.Errorf("failed to get repository %s/%s: %w", owner, *cf.Options.SharedRepository, err)
111+
}
112+
113+
ref = r.GetDefaultBranch()
107114
}
108115

109-
ref := r.GetDefaultBranch()
110116
file, _, _, err := client.Repositories.GetContents(ctx, owner, *cf.Options.SharedRepository, *cf.Options.SharedPolicyPath, &github.RepositoryContentGetOptions{
111117
Ref: ref,
112118
})

0 commit comments

Comments
 (0)