-
-
Notifications
You must be signed in to change notification settings - Fork 64
/
Copy pathconfig.py
177 lines (148 loc) · 6.53 KB
/
config.py
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
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
from __future__ import annotations
from enum import Enum
from typing import List, Optional, Union
import toml
from pydantic import BaseModel, ValidationError, validator
from typing_extensions import Literal
class MergeMethod(str, Enum):
merge = "merge"
squash = "squash"
rebase = "rebase"
rebase_fast_forward = "rebase_fast_forward"
class MergeTitleStyle(Enum):
github_default = "github_default"
pull_request_title = "pull_request_title"
class MergeBodyStyle(Enum):
github_default = "github_default"
pull_request_body = "pull_request_body"
empty = "empty"
class BodyText(Enum):
plain_text = "plain_text"
markdown = "markdown"
html = "html"
class MergeMessage(BaseModel):
"""
https://developer.github.com/v3/pulls/#merge-a-pull-request-merge-button
"""
title: MergeTitleStyle = MergeTitleStyle.github_default
body: MergeBodyStyle = MergeBodyStyle.github_default
include_pr_number: bool = True
body_type: BodyText = BodyText.markdown
strip_html_comments: bool = False
include_pull_request_author: bool = False
include_coauthors: bool = False
include_pull_request_url: bool = False
cut_body_before: str = ""
cut_body_after: str = ""
cut_body_and_text: bool = False
# this pattern indicates that the user has the field unset.
UNSET_TITLE_REGEX = ":::|||kodiak|||internal|||reserved|||:::"
DEFAULT_TITLE_REGEX = "^WIP:.*"
class AutomergeDependencies(BaseModel):
versions: List[Literal["major", "minor", "patch"]] = []
usernames: List[str] = []
class Merge(BaseModel):
# label or labels to enable merging of pull request.
automerge_label: Union[str, List[str]] = "automerge"
automerge_dependencies: AutomergeDependencies = AutomergeDependencies()
# if disabled, kodiak won't require a label to queue a PR for merge
require_automerge_label: bool = True
# Show message when automerge label is missing on a PR
show_missing_automerge_label_message: bool = True
# regex to match against title and block merging. Set to empty string to
# disable check.
blacklist_title_regex: str = (
UNSET_TITLE_REGEX # deprecated for blocking_title_regex
)
blocking_title_regex: str = UNSET_TITLE_REGEX
# labels to block merging of pull request
blacklist_labels: List[str] = [] # deprecated for blocking_labels
blocking_labels: List[str] = []
# action to take when attempting to merge PR. An error will occur if method
# is disabled for repository
method: Optional[MergeMethod] = None
# delete branch when PR is merged
delete_branch_on_merge: bool = False
# DEPRECATED
# this feature is flawed and cannot be fixed. see
# https://github.com/chdsbd/kodiak/issues/153#issuecomment-523057332.
#
# block merging if there are outstanding review requests
block_on_reviews_requested: bool = False
# block merging if there are neutral required check runs.
block_on_neutral_required_check_runs: bool = False
# comment on merge conflict and remove automerge label
notify_on_conflict: bool = True
# don't wait for status checks to run before updating branch
optimistic_updates: bool = True
# configuration for commit message of merge
message: MergeMessage = MergeMessage()
# status checks that we don't want to wait to complete when they are in a
# pending state. This is useful for checks that will complete in an
# indefinite amount of time, like the wip-app checks or status checks
# requiring manual approval.
dont_wait_on_status_checks: List[str] = []
# DEPRECATED
# This setting only updates PRs that are passing passing all
# requirements or waiting for status checks to pass. `update.always = True`
# will deliver better behavior in many use cases.
#
# immediately update a PR whenever the target updates
update_branch_immediately: bool = False
# if a PR is passing all checks and is able to be merged, merge it without
# placing it in the queue. This will introduce some unfairness where those
# waiting in the queue the longest will not be served first.
prioritize_ready_to_merge: bool = False
# when applied to a PR, add the PR to the front of the merge queue.
priority_merge_label: Optional[str] = None
# never merge a PR. This can be used with merge.update_branch_immediately to
# automatically update a PR without merging.
do_not_merge: bool = False
class Update(BaseModel):
# update PR whenever the PR is out of date with the base branch. PR will be
# updated regardless of failing requirements for merge (e.g. failing status
# checks, missing reviews, blacklist labels). Kodiak will only update the PR
# if the automerge label is enabled or `update.require_automerge_label` is
# false.
always: bool = False
require_automerge_label: bool = True
autoupdate_label: Optional[str] = None
# Do not update PRs created by a listed user.
blacklist_usernames: List[str] = [] # deprecated for ignored_usernames
ignored_usernames: List[str] = []
class Approve(BaseModel):
# auto approve any PR created by a listed user.
auto_approve_usernames: List[str] = []
# auto approve any PR to which a listed label is assigned.
auto_approve_labels: List[str] = []
class InvalidVersion(ValueError):
pass
class V1(BaseModel):
version: int
# _internal_ value to require a certain github app ID to process this repo.
# This is useful for development, so we can globally install the production
# kodiak, but also run the development version on a specific repo. By
# setting _app_id to the development github app ID, we can prevent the
# production kodiak instance from interfering.
app_id: Optional[str]
merge: Merge = Merge()
update: Update = Update()
approve: Approve = Approve()
# when added to a Pull Request Kodiak will be prevented from taking any action
# (approvals, updates, merges, comments, labels). Kodiak will still set
# status checks. A user should generally not need to change this label as it
# should rarely be applied.
disable_bot_label: str = "kodiak:disabled"
@validator("version", pre=True, always=True)
def correct_version(cls, v: int) -> int:
if v != 1:
raise InvalidVersion("Version must be `1`")
return v
@classmethod
def parse_toml(
cls, content: str
) -> Union[V1, toml.TomlDecodeError, ValidationError]:
try:
return cls.parse_obj(toml.loads(content))
except (toml.TomlDecodeError, ValidationError) as e:
return e