From 63b1e2d7b1265ae21d5b556239c5fade71348557 Mon Sep 17 00:00:00 2001 From: calebcartwright Date: Mon, 19 Aug 2019 18:11:46 -0500 Subject: [PATCH 1/5] feat: add BaseSvgScraping service impl for GH Actions --- services/github/github-actions.service.js | 66 +++++++++++++++++++++++ services/github/github-actions.tester.js | 25 +++++++++ 2 files changed, 91 insertions(+) create mode 100644 services/github/github-actions.service.js create mode 100644 services/github/github-actions.tester.js diff --git a/services/github/github-actions.service.js b/services/github/github-actions.service.js new file mode 100644 index 0000000000000..8ca559fca8259 --- /dev/null +++ b/services/github/github-actions.service.js @@ -0,0 +1,66 @@ +'use strict' + +const Joi = require('@hapi/joi') +const { isBuildStatus, renderBuildStatusBadge } = require('../build-status') +const { documentation } = require('./github-helpers') +const { BaseSvgScrapingService } = require('..') + +const schema = Joi.object({ + message: isBuildStatus, +}).required() + +module.exports = class GithubActions extends BaseSvgScrapingService { + static get category() { + return 'build' + } + + static get route() { + return { + base: 'github/actions', + pattern: ':user/:repo/:workflow', + } + } + + static get examples() { + return [ + { + title: 'GitHub Actions', + namedParams: { + user: 'actions', + repo: 'toolkit', + workflow: 'Main workflow', + }, + staticPreview: renderBuildStatusBadge({ + status: 'passing', + }), + documentation, + }, + ] + } + + static get defaultBadgeData() { + return { + label: 'build', + } + } + + async fetch({ user, repo, workflow }) { + const { message: status } = await this._requestSvg({ + schema, + url: `https://github.com/${user}/${repo}/workflows/${encodeURIComponent( + workflow + )}/badge.svg`, + valueMatcher: />([^<>]+)<\/tspan><\/text><\/g> Date: Tue, 20 Aug 2019 14:40:05 -0500 Subject: [PATCH 2/5] chore: fix GH Actions service test name --- services/github/github-actions.tester.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/services/github/github-actions.tester.js b/services/github/github-actions.tester.js index 072459b3bf4cc..f3c1be3c42390 100644 --- a/services/github/github-actions.tester.js +++ b/services/github/github-actions.tester.js @@ -17,7 +17,7 @@ t.create('nonexistent workflow') message: 'repo or workflow not found', }) -t.create('nonexistent workflow') +t.create('valid workflow') .get('/actions/toolkit/Main%20workflow.json') .expectBadge({ label: 'build', From a0a2591cac0bcbc810ac58f22ab0e08a28c4b20a Mon Sep 17 00:00:00 2001 From: Caleb Cartwright Date: Fri, 15 Nov 2019 15:21:07 -0600 Subject: [PATCH 3/5] feat: add branch support to GH Actions/Workflows --- services/github/github-actions.service.js | 26 ++++++++++++++++++----- services/github/github-actions.tester.js | 11 ++++++++-- 2 files changed, 30 insertions(+), 7 deletions(-) diff --git a/services/github/github-actions.service.js b/services/github/github-actions.service.js index 8ca559fca8259..6502f78c196dc 100644 --- a/services/github/github-actions.service.js +++ b/services/github/github-actions.service.js @@ -17,7 +17,7 @@ module.exports = class GithubActions extends BaseSvgScrapingService { static get route() { return { base: 'github/actions', - pattern: ':user/:repo/:workflow', + pattern: ':user/:repo/:workflow/:branch*', } } @@ -25,6 +25,7 @@ module.exports = class GithubActions extends BaseSvgScrapingService { return [ { title: 'GitHub Actions', + pattern: ':user/:repo/:workflow', namedParams: { user: 'actions', repo: 'toolkit', @@ -35,6 +36,20 @@ module.exports = class GithubActions extends BaseSvgScrapingService { }), documentation, }, + { + title: 'GitHub Actions (branch)', + pattern: ':user/:repo/:workflow/:branch', + namedParams: { + user: 'actions', + repo: 'toolkit', + workflow: 'Main workflow', + branch: 'master', + }, + staticPreview: renderBuildStatusBadge({ + status: 'passing', + }), + documentation, + }, ] } @@ -44,23 +59,24 @@ module.exports = class GithubActions extends BaseSvgScrapingService { } } - async fetch({ user, repo, workflow }) { + async fetch({ user, repo, workflow, branch }) { const { message: status } = await this._requestSvg({ schema, url: `https://github.com/${user}/${repo}/workflows/${encodeURIComponent( workflow )}/badge.svg`, + options: { qs: { branch } }, valueMatcher: />([^<>]+)<\/tspan><\/text><\/g> Date: Sun, 17 Nov 2019 11:08:32 -0600 Subject: [PATCH 4/5] chore: fix schema for GH actions --- services/github/github-actions.service.js | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/services/github/github-actions.service.js b/services/github/github-actions.service.js index 6502f78c196dc..eb3e671d2cebf 100644 --- a/services/github/github-actions.service.js +++ b/services/github/github-actions.service.js @@ -6,7 +6,9 @@ const { documentation } = require('./github-helpers') const { BaseSvgScrapingService } = require('..') const schema = Joi.object({ - message: isBuildStatus, + message: Joi.alternatives() + .try(isBuildStatus, Joi.equal('no status')) + .required(), }).required() module.exports = class GithubActions extends BaseSvgScrapingService { From 21e0063cd373f973ac581369089445a48065339f Mon Sep 17 00:00:00 2001 From: Caleb Cartwright Date: Mon, 25 Nov 2019 18:19:07 -0600 Subject: [PATCH 5/5] refactor: update route path per PR discussion --- ....service.js => github-workflow-status.service.js} | 12 ++++++++---- ...ns.tester.js => github-workflow-status.tester.js} | 9 +++++++-- 2 files changed, 15 insertions(+), 6 deletions(-) rename services/github/{github-actions.service.js => github-workflow-status.service.js} (87%) rename services/github/{github-actions.tester.js => github-workflow-status.tester.js} (78%) diff --git a/services/github/github-actions.service.js b/services/github/github-workflow-status.service.js similarity index 87% rename from services/github/github-actions.service.js rename to services/github/github-workflow-status.service.js index eb3e671d2cebf..24ba4800fe8d3 100644 --- a/services/github/github-actions.service.js +++ b/services/github/github-workflow-status.service.js @@ -11,14 +11,16 @@ const schema = Joi.object({ .required(), }).required() -module.exports = class GithubActions extends BaseSvgScrapingService { +const keywords = ['action', 'actions'] + +module.exports = class GithubWorkflowStatus extends BaseSvgScrapingService { static get category() { return 'build' } static get route() { return { - base: 'github/actions', + base: 'github/workflow/status', pattern: ':user/:repo/:workflow/:branch*', } } @@ -26,7 +28,7 @@ module.exports = class GithubActions extends BaseSvgScrapingService { static get examples() { return [ { - title: 'GitHub Actions', + title: 'GitHub Workflow Status', pattern: ':user/:repo/:workflow', namedParams: { user: 'actions', @@ -37,9 +39,10 @@ module.exports = class GithubActions extends BaseSvgScrapingService { status: 'passing', }), documentation, + keywords, }, { - title: 'GitHub Actions (branch)', + title: 'GitHub Workflow Status (branch)', pattern: ':user/:repo/:workflow/:branch', namedParams: { user: 'actions', @@ -51,6 +54,7 @@ module.exports = class GithubActions extends BaseSvgScrapingService { status: 'passing', }), documentation, + keywords, }, ] } diff --git a/services/github/github-actions.tester.js b/services/github/github-workflow-status.tester.js similarity index 78% rename from services/github/github-actions.tester.js rename to services/github/github-workflow-status.tester.js index 24022de96d650..07a6e3400453b 100644 --- a/services/github/github-actions.tester.js +++ b/services/github/github-workflow-status.tester.js @@ -1,8 +1,13 @@ 'use strict' +const Joi = require('@hapi/joi') const { isBuildStatus } = require('../build-status') const t = (module.exports = require('../tester').createServiceTester()) +const isWorkflowStatus = Joi.alternatives() + .try(isBuildStatus, Joi.equal('no status')) + .required() + t.create('nonexistent repo') .get('/badges/shields-fakeness/fake.json') .expectBadge({ @@ -21,12 +26,12 @@ t.create('valid workflow') .get('/actions/toolkit/Main%20workflow.json') .expectBadge({ label: 'build', - message: isBuildStatus, + message: isWorkflowStatus, }) t.create('valid workflow (branch)') .get('/actions/toolkit/Main%20workflow/master.json') .expectBadge({ label: 'build', - message: isBuildStatus, + message: isWorkflowStatus, })