@@ -48,20 +48,28 @@ class GaugeMetric:
48
48
time_ns : int
49
49
50
50
51
- # Fetches a page of the build list using the GraphQL BuildKite API.
52
- # Returns the BUILDKITE_GRAPHQL_BUILDS_PER_PAGE last **finished** builds by
53
- # default, or the BUILDKITE_GRAPHQL_BUILDS_PER_PAGE **finished** builds older
54
- # than the one pointer by
55
- # |cursor| if provided.
56
- # The |cursor| value is taken from the previous page returned by the API.
57
- # The returned data had the following format:
58
- # [
59
- # {
60
- # "cursor": <value>,
61
- # "number": <build-number>,
62
- # }
63
- # ]
64
- def buildkite_fetch_page_build_list (buildkite_token , after_cursor = None ):
51
+ def buildkite_fetch_page_build_list (
52
+ buildkite_token : str , after_cursor : str = None
53
+ ) -> list [dict [str , str ]]:
54
+ """Fetches a page of the build list using the GraphQL BuildKite API. Returns the BUILDKITE_GRAPHQL_BUILDS_PER_PAGE last **finished** builds by default, or the BUILDKITE_GRAPHQL_BUILDS_PER_PAGE **finished** builds older than the one pointer by |cursor| if provided.
55
+ The |cursor| value is taken from the previous page returned by the API.
56
+
57
+ The returned data had the following format:
58
+
59
+ Args:
60
+ buildkite_token: the secret token to authenticate GraphQL requests.
61
+ after_cursor: cursor after which to start the page fetch.
62
+
63
+ Returns:
64
+ Returns most recents builds after cursor (if set) with the following format:
65
+ [
66
+ {
67
+ "cursor": <value>,
68
+ "number": <build-number>,
69
+ }
70
+ ]
71
+ """
72
+
65
73
BUILDKITE_GRAPHQL_QUERY = """
66
74
query OrganizationShowQuery {{
67
75
organization(slug: "llvm-project") {{
@@ -103,17 +111,29 @@ def buildkite_fetch_page_build_list(buildkite_token, after_cursor=None):
103
111
return [{** x ["node" ], "cursor" : x ["cursor" ]} for x in builds ]
104
112
105
113
106
- # Returns all the info associated with the provided |build_number|.
107
- # Note: for unknown reasons, graphql returns no jobs for a given build, while
108
- # this endpoint does, hence why this uses this API instead of graphql.
109
- def buildkite_get_build_info (build_number ):
114
+ def buildkite_get_build_info (build_number : str ) -> dict :
115
+ """Returns all the info associated with the provided build number.
116
+ Note: for unknown reasons, graphql returns no jobs for a given build, while this endpoint does, hence why this uses this API instead of graphql.
117
+
118
+ Args:
119
+ build_number: which build number to fetch info for.
120
+
121
+ Returns:
122
+ The info for the target build, a JSON dictionnary.
123
+ """
124
+
110
125
URL = "https://buildkite.com/llvm-project/github-pull-requests/builds/{}.json"
111
126
return requests .get (URL .format (build_number )).json ()
112
127
113
128
114
- # returns the last BUILDKITE_GRAPHQL_BUILDS_PER_PAGE builds by default, or
115
- # until the build pointed by |last_cursor| is found.
116
- def buildkite_get_builds_up_to (buildkite_token , last_cursor = None ):
129
+ def buildkite_get_builds_up_to (buildkite_token : str , last_cursor : str = None ) -> list :
130
+ """Returns the last BUILDKITE_GRAPHQL_BUILDS_PER_PAGE builds by default, or
131
+ until the build pointed by |last_cursor| is found.
132
+
133
+ Args:
134
+ buildkite_token: the secret token to authenticate GraphQL requests.
135
+ last_cursor: the cursor to stop at if set. If None, a full page is fetched.
136
+ """
117
137
output = []
118
138
cursor = None
119
139
@@ -137,13 +157,17 @@ def buildkite_get_builds_up_to(buildkite_token, last_cursor=None):
137
157
return output
138
158
139
159
140
- # Returns a (metrics, cursor) tuple.
141
- # Returns the BuildKite workflow metrics up to the build pointed by |last_cursor|.
142
- # If |last_cursor| is None, no metrics are returned.
143
- # The returned cursor is either:
144
- # - the last processed build.
145
- # - the last build if no initial cursor was provided.
146
- def buildkite_get_metrics (buildkite_token , last_cursor = None ):
160
+ def buildkite_get_metrics (
161
+ buildkite_token : str , last_cursor : str = None
162
+ ) -> (list [JobMetrics ], str ):
163
+ """Returns a tuple with:
164
+ - the metrics to record until |last_cursor| is reached, or none if last cursor is None.
165
+ - the cursor of the most recent build processed.
166
+
167
+ Args:
168
+ buildkite_token: the secret token to authenticate GraphQL requests.
169
+ last_cursor: the cursor to stop at if set. If None, a full page is fetched.
170
+ """
147
171
builds = buildkite_get_builds_up_to (buildkite_token , last_cursor )
148
172
# Don't return any metrics if last_cursor is None.
149
173
# This happens when the program starts.
0 commit comments