feat(app/action): add quota_required_* options (#1014)
This commit is contained in:
@@ -140,6 +140,9 @@ function quit(reason) {
|
||||
"output.action": _action,
|
||||
"output.condition": _output_condition,
|
||||
delay,
|
||||
"quota.required.rest":_quota_required_rest,
|
||||
"quota.required.graphql":_quota_required_graphql,
|
||||
"quota.required.search":_quota_required_search,
|
||||
"notice.release": _notice_releases,
|
||||
...config
|
||||
} = metadata.plugins.core.inputs.action({core, preset})
|
||||
@@ -184,19 +187,22 @@ function quit(reason) {
|
||||
//Test token validity and requests count
|
||||
else if (!/^NOT_NEEDED$/.test(token)) {
|
||||
//Check rate limit
|
||||
let ratelimit = false
|
||||
const {data} = await api.rest.rateLimit.get().catch(() => ({data: {resources: {}}}))
|
||||
Object.assign(resources, data.resources)
|
||||
info("API requests (REST)", resources.core ? `${resources.core.remaining}/${resources.core.limit}` : "(unknown)")
|
||||
info("API requests (GraphQL)", resources.graphql ? `${resources.graphql.remaining}/${resources.graphql.limit}` : "(unknown)")
|
||||
info("API requests (search)", resources.search ? `${resources.search.remaining}/${resources.search.limit}` : "(unknown)")
|
||||
if ((!resources.core.remaining) || (!resources.graphql.remaining)) {
|
||||
console.warn("::warning::It seems you have reached your API requests limit. Please retry later.")
|
||||
for (const type of ["core", "graphql", "search"]) {
|
||||
const name = {core: "REST", graphql: "GraphQL", search: "Search"}[type]
|
||||
const quota = {core:_quota_required_rest, graphql:_quota_required_graphql, search:_quota_required_search}[type] ?? 1
|
||||
info(`API requests (${name})`, resources[type] ? `${resources[type].remaining}/${resources[type].limit}${quota ? ` (${quota}+ required)` : ""}` : "(unknown)")
|
||||
if ((resources[type]) && (resources[type].remaining < quota))
|
||||
ratelimit = true
|
||||
}
|
||||
if (ratelimit) {
|
||||
console.warn("::warning::It seems you have reached your API requests limit or configured quota. Please retry later.")
|
||||
info.break()
|
||||
console.log("Nothing can be done currently, thanks for using metrics!")
|
||||
quit("skipped")
|
||||
}
|
||||
if (!resources.search.remaining)
|
||||
console.warn("::warning::It seems you have reached your Search API requests limit. Some plugins may return less accurate results.")
|
||||
//Check scopes
|
||||
try {
|
||||
const {headers} = await api.rest.request("HEAD /")
|
||||
|
||||
@@ -379,6 +379,42 @@ inputs:
|
||||
min: 0
|
||||
max: 3600
|
||||
|
||||
quota_required_rest:
|
||||
description: |
|
||||
Minimum GitHub REST API requests quota required to run
|
||||
|
||||
Action will cancel itself without any errors if requirements are not met
|
||||
|
||||
This option has no effect when `token` is set to `NOT_NEEDED`
|
||||
type: number
|
||||
default: 200
|
||||
min: 0
|
||||
max: 5000
|
||||
|
||||
quota_required_graphql:
|
||||
description: |
|
||||
Minimum GitHub GraphQL API requests quota required to run
|
||||
|
||||
Action will cancel itself without any errors if requirements are not met
|
||||
|
||||
This option has no effect when `token` is set to `NOT_NEEDED`
|
||||
type: number
|
||||
default: 200
|
||||
min: 0
|
||||
max: 5000
|
||||
|
||||
quota_required_search:
|
||||
description: |
|
||||
Minimum GitHub REST API requests quota required to run
|
||||
|
||||
Action will cancel itself without any errors if requirements are not met
|
||||
|
||||
This option has no effect when `token` is set to `NOT_NEEDED`
|
||||
type: number
|
||||
default: 0
|
||||
min: 0
|
||||
max: 30
|
||||
|
||||
notice_releases:
|
||||
description: Notice about new releases of metrics
|
||||
type: boolean
|
||||
|
||||
Reference in New Issue
Block a user