feat: GithubWorkflowStatus event query string (#5442)
Co-authored-by: repo-ranger[bot] <39074581+repo-ranger[bot]@users.noreply.github.com>
This commit is contained in:
@@ -11,6 +11,10 @@ const schema = Joi.object({
|
||||
.required(),
|
||||
}).required()
|
||||
|
||||
const queryParamSchema = Joi.object({
|
||||
event: Joi.string(),
|
||||
}).required()
|
||||
|
||||
const keywords = ['action', 'actions']
|
||||
|
||||
module.exports = class GithubWorkflowStatus extends BaseSvgScrapingService {
|
||||
@@ -22,6 +26,7 @@ module.exports = class GithubWorkflowStatus extends BaseSvgScrapingService {
|
||||
return {
|
||||
base: 'github/workflow/status',
|
||||
pattern: ':user/:repo/:workflow/:branch*',
|
||||
queryParamSchema,
|
||||
}
|
||||
}
|
||||
|
||||
@@ -33,7 +38,7 @@ module.exports = class GithubWorkflowStatus extends BaseSvgScrapingService {
|
||||
namedParams: {
|
||||
user: 'actions',
|
||||
repo: 'toolkit',
|
||||
workflow: 'Main workflow',
|
||||
workflow: 'toolkit-unit-tests',
|
||||
},
|
||||
staticPreview: renderBuildStatusBadge({
|
||||
status: 'passing',
|
||||
@@ -47,7 +52,7 @@ module.exports = class GithubWorkflowStatus extends BaseSvgScrapingService {
|
||||
namedParams: {
|
||||
user: 'actions',
|
||||
repo: 'toolkit',
|
||||
workflow: 'Main workflow',
|
||||
workflow: 'toolkit-unit-tests',
|
||||
branch: 'master',
|
||||
},
|
||||
staticPreview: renderBuildStatusBadge({
|
||||
@@ -56,6 +61,23 @@ module.exports = class GithubWorkflowStatus extends BaseSvgScrapingService {
|
||||
documentation,
|
||||
keywords,
|
||||
},
|
||||
{
|
||||
title: 'GitHub Workflow Status (event)',
|
||||
pattern: ':user/:repo/:workflow',
|
||||
namedParams: {
|
||||
user: 'actions',
|
||||
repo: 'toolkit',
|
||||
workflow: 'toolkit-unit-tests',
|
||||
},
|
||||
queryParams: {
|
||||
event: 'push',
|
||||
},
|
||||
staticPreview: renderBuildStatusBadge({
|
||||
status: 'passing',
|
||||
}),
|
||||
documentation,
|
||||
keywords,
|
||||
},
|
||||
]
|
||||
}
|
||||
|
||||
@@ -65,13 +87,13 @@ module.exports = class GithubWorkflowStatus extends BaseSvgScrapingService {
|
||||
}
|
||||
}
|
||||
|
||||
async fetch({ user, repo, workflow, branch }) {
|
||||
async fetch({ user, repo, workflow, branch, event }) {
|
||||
const { message: status } = await this._requestSvg({
|
||||
schema,
|
||||
url: `https://github.com/${user}/${repo}/workflows/${encodeURIComponent(
|
||||
workflow
|
||||
)}/badge.svg`,
|
||||
options: { qs: { branch } },
|
||||
options: { qs: { branch, event } },
|
||||
valueMatcher: />([^<>]+)<\/tspan><\/text><\/g><path/,
|
||||
errorMessages: {
|
||||
404: 'repo, branch, or workflow not found',
|
||||
@@ -81,8 +103,8 @@ module.exports = class GithubWorkflowStatus extends BaseSvgScrapingService {
|
||||
return { status }
|
||||
}
|
||||
|
||||
async handle({ user, repo, workflow, branch }) {
|
||||
const { status } = await this.fetch({ user, repo, workflow, branch })
|
||||
async handle({ user, repo, workflow, branch }, { event }) {
|
||||
const { status } = await this.fetch({ user, repo, workflow, branch, event })
|
||||
return renderBuildStatusBadge({ status })
|
||||
}
|
||||
}
|
||||
|
||||
@@ -23,14 +23,21 @@ t.create('nonexistent workflow')
|
||||
})
|
||||
|
||||
t.create('valid workflow')
|
||||
.get('/actions/toolkit/Main%20workflow.json')
|
||||
.get('/actions/toolkit/toolkit-unit-tests.json')
|
||||
.expectBadge({
|
||||
label: 'build',
|
||||
message: isWorkflowStatus,
|
||||
})
|
||||
|
||||
t.create('valid workflow (branch)')
|
||||
.get('/actions/toolkit/Main%20workflow/master.json')
|
||||
.get('/actions/toolkit/toolkit-unit-tests/master.json')
|
||||
.expectBadge({
|
||||
label: 'build',
|
||||
message: isWorkflowStatus,
|
||||
})
|
||||
|
||||
t.create('valid workflow (event)')
|
||||
.get('/actions/toolkit/toolkit-unit-tests.json?event=push')
|
||||
.expectBadge({
|
||||
label: 'build',
|
||||
message: isWorkflowStatus,
|
||||
|
||||
Reference in New Issue
Block a user