forked from regro/cf-scripts
-
Notifications
You must be signed in to change notification settings - Fork 0
/
pr_json.py
170 lines (137 loc) · 4.46 KB
/
pr_json.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
from datetime import datetime
from enum import StrEnum
from typing import ClassVar, Literal
from pydantic import UUID4, AnyHttpUrl, Field, TypeAdapter
from pydantic_extra_types.color import Color
from conda_forge_tick.models.common import (
RFC2822Date,
StrictBaseModel,
ValidatedBaseModel,
)
class PullRequestLabelShort(StrictBaseModel):
name: str
"""
The name of the label.
"""
class PullRequestLabel(PullRequestLabelShort):
color: Color
"""
The color of the label, parsed as a hex color.
"""
default: bool
"""
Whether this is a GitHub default label (e.g. bug, documentation, enhancement).
"""
description: str | None = None
id: int
"""
The GitHub label ID.
"""
node_id: str
"""
The GitHub-internally used node ID of the label.
"""
url: AnyHttpUrl
"""
A URL pointing to the GitHub label API endpoint:
https://docs.github.com/de/rest/issues/labels?apiVersion=2022-11-28#get-a-label
"""
class PullRequestState(StrEnum):
OPEN = "open"
CLOSED = "closed"
"""
Merged PRs are also closed.
"""
class PullRequestInfoHead(ValidatedBaseModel):
ref: str
"""
The head branch of the pull request.
This is set to "<this_is_not_a_branch>" or "this_is_not_a_branch" (without the angle brackets) if the branch is
deleted, which seems unnecessary.
"""
class GithubPullRequestMergeableState(StrEnum):
"""
These values are not officially documented by GitHub.
See https://github.com/octokit/octokit.net/issues/1763#issue-297399985 for more information
and an explanation of the different possible values.
"""
DIRTY = "dirty"
UNKNOWN = "unknown"
BLOCKED = "blocked"
BEHIND = "behind"
UNSTABLE = "unstable"
HAS_HOOKS = "has_hooks"
CLEAN = "clean"
class GithubRepository(ValidatedBaseModel):
name: str
class GithubPullRequestBase(ValidatedBaseModel):
repo: GithubRepository
class PullRequestDataValid(ValidatedBaseModel):
"""
Information about a pull request, as retrieved from the GitHub API.
Refer to git_utils.PR_KEYS_TO_KEEP for the keys that are kept in the PR object.
ALSO UPDATE PR_KEYS_TO_KEEP IF YOU CHANGE THIS CLASS!
GitHub documentation: https://docs.github.com/en/rest/pulls/pulls?apiVersion=2022-11-28#get-a-pull-request
"""
HEADER_FIELDS: ClassVar[set[str]] = {
"ETag",
"Last-Modified",
}
"""
A set of all header fields that are stored in the PR object.
Header fields are assumed to be used for caching purposes and always optional.
The corresponding fields should be set to None if they are not present in the response.
"""
e_tag: str | None = Field(None, alias="ETag")
"""
HTTP ETag header field, allowing us to quickly check if the PR has changed.
"""
last_modified: RFC2822Date | None = Field(None, alias="Last-Modified")
"""
Taken from the GitHub response header.
"""
id: int | None = None
"""
The GitHub Pull Request ID (not: the PR number).
"""
html_url: AnyHttpUrl | None = None
"""
The URL of the pull request on GitHub.
"""
created_at: datetime | None = None
updated_at: datetime | None = None
merged_at: datetime | None = None
"""
Note that this field is abused in PullRequestInfoSpecial.
"""
closed_at: datetime | None = None
mergeable_state: GithubPullRequestMergeableState | None = None
"""
Undocumented GitHub API field. See here: https://github.com/octokit/octokit.net/issues/1763#issue-297399985
"""
mergeable: bool | None = None
merged: bool | None = None
draft: bool | None = None
number: int | None = None
"""
The pull request number. Sometimes, this information is missing.
"""
state: PullRequestState
"""
Whether the pull request is open or closed.
"""
labels: list[PullRequestLabel | PullRequestLabelShort] = []
"""
All GitHub labels of the pull request.
"""
head: PullRequestInfoHead | None = None
base: GithubPullRequestBase | None = None
class PullRequestInfoSpecial(StrictBaseModel):
"""
Used instead of pr_json.PullRequestInfo in the graph data to fake a closed pull request.
This is probably not necessary and should be removed.
"""
id: UUID4
merged_at: Literal["never issued", "fix aarch missing prs"]
state: Literal[PullRequestState.CLOSED]
PullRequestData = TypeAdapter(PullRequestDataValid | PullRequestInfoSpecial)