-
Notifications
You must be signed in to change notification settings - Fork 122
/
policydef.go
74 lines (58 loc) · 2.75 KB
/
policydef.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
// Copyright 2021 Allstar Authors
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
// http://www.apache.org/licenses/LICENSE-2.0
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
// Package policydef defines the interface that policies must implement to be
// included in Allstar.
//
// Policies should define and retrieve their own config in the same way that
// Allstar does. There should be an org-level config and repo-level
// config. Each config should include the OptConfig defined in
// github.com/ossf/allstar/pkg/config to determine if the policy is enabled or
// disabled. The config package also provided helper functions to retrieve
// config from the repo.
package policydef
import (
"context"
"github.com/google/go-github/v59/github"
)
// Result is returned from a policy check.
type Result struct {
// Enabled is whether the policy is enabled or not.
Enabled bool
// Pass is whether the policy passes or not.
Pass bool
// NotifyText is the human readable message to provide to the user if the
// configured action is a notify action (issue, email, rpc). It should inform
// the user of the problem and how to fix it.
NotifyText string
// Details are logged on failure. it should be serializable to json and allow
// useful log querying.
Details interface{}
}
// Policy is the interface that policies must implement to be included in
// Allstar.
type Policy interface {
// Name must return the human readable name of the policy.
Name() string
// Check whether this policy is enabled or not
IsEnabled(ctx context.Context, c *github.Client, owner, repo string) (bool, error)
// Check checks whether the provided repo is in compliance with the policy or
// not. It must use the provided context and github client. See Result for
// more details on the return value.
Check(ctx context.Context, c *github.Client, owner, repo string) (*Result, error)
// Fix should modify the provided repo to be in compliance with the
// policy. The provided github client must be used to either edit repo
// settings or modify files. Fix is optional and the policy may simply
// return.
Fix(ctx context.Context, c *github.Client, owner, repo string) error
// GetAction must return the configured action from the policy's config. No
// validation is needed by the policy, it will be done centrally.
GetAction(ctx context.Context, c *github.Client, owner, repo string) string
}