feat(app/action): add quota_required_* options (#1014)
This commit is contained in:
@@ -140,6 +140,9 @@ function quit(reason) {
|
|||||||
"output.action": _action,
|
"output.action": _action,
|
||||||
"output.condition": _output_condition,
|
"output.condition": _output_condition,
|
||||||
delay,
|
delay,
|
||||||
|
"quota.required.rest":_quota_required_rest,
|
||||||
|
"quota.required.graphql":_quota_required_graphql,
|
||||||
|
"quota.required.search":_quota_required_search,
|
||||||
"notice.release": _notice_releases,
|
"notice.release": _notice_releases,
|
||||||
...config
|
...config
|
||||||
} = metadata.plugins.core.inputs.action({core, preset})
|
} = metadata.plugins.core.inputs.action({core, preset})
|
||||||
@@ -184,19 +187,22 @@ function quit(reason) {
|
|||||||
//Test token validity and requests count
|
//Test token validity and requests count
|
||||||
else if (!/^NOT_NEEDED$/.test(token)) {
|
else if (!/^NOT_NEEDED$/.test(token)) {
|
||||||
//Check rate limit
|
//Check rate limit
|
||||||
|
let ratelimit = false
|
||||||
const {data} = await api.rest.rateLimit.get().catch(() => ({data: {resources: {}}}))
|
const {data} = await api.rest.rateLimit.get().catch(() => ({data: {resources: {}}}))
|
||||||
Object.assign(resources, data.resources)
|
Object.assign(resources, data.resources)
|
||||||
info("API requests (REST)", resources.core ? `${resources.core.remaining}/${resources.core.limit}` : "(unknown)")
|
for (const type of ["core", "graphql", "search"]) {
|
||||||
info("API requests (GraphQL)", resources.graphql ? `${resources.graphql.remaining}/${resources.graphql.limit}` : "(unknown)")
|
const name = {core: "REST", graphql: "GraphQL", search: "Search"}[type]
|
||||||
info("API requests (search)", resources.search ? `${resources.search.remaining}/${resources.search.limit}` : "(unknown)")
|
const quota = {core:_quota_required_rest, graphql:_quota_required_graphql, search:_quota_required_search}[type] ?? 1
|
||||||
if ((!resources.core.remaining) || (!resources.graphql.remaining)) {
|
info(`API requests (${name})`, resources[type] ? `${resources[type].remaining}/${resources[type].limit}${quota ? ` (${quota}+ required)` : ""}` : "(unknown)")
|
||||||
console.warn("::warning::It seems you have reached your API requests limit. Please retry later.")
|
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()
|
info.break()
|
||||||
console.log("Nothing can be done currently, thanks for using metrics!")
|
console.log("Nothing can be done currently, thanks for using metrics!")
|
||||||
quit("skipped")
|
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
|
//Check scopes
|
||||||
try {
|
try {
|
||||||
const {headers} = await api.rest.request("HEAD /")
|
const {headers} = await api.rest.request("HEAD /")
|
||||||
|
|||||||
@@ -379,6 +379,42 @@ inputs:
|
|||||||
min: 0
|
min: 0
|
||||||
max: 3600
|
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:
|
notice_releases:
|
||||||
description: Notice about new releases of metrics
|
description: Notice about new releases of metrics
|
||||||
type: boolean
|
type: boolean
|
||||||
|
|||||||
Reference in New Issue
Block a user