From b9e3cd655776847a21afd69dd50c1a6ccabfd082 Mon Sep 17 00:00:00 2001 From: Alexander Wert Date: Mon, 9 May 2022 07:47:53 +0200 Subject: [PATCH] Added milestone property to GitHub issue details service --- .../github/github-issue-detail.service.js | 20 +++++++++++++++++++ services/github/github-issue-detail.spec.js | 20 +++++++++++++++++++ services/github/github-issue-detail.tester.js | 14 +++++++++++++ 3 files changed, 54 insertions(+) diff --git a/services/github/github-issue-detail.service.js b/services/github/github-issue-detail.service.js index b26b092abc7eaa..1a9a41dc3a0071 100644 --- a/services/github/github-issue-detail.service.js +++ b/services/github/github-issue-detail.service.js @@ -9,6 +9,7 @@ import { errorMessagesFor, issueStateColor, commentsColor, + colorForString, } from './github-helpers.js' const commonSchemaFields = { @@ -140,6 +141,23 @@ const ageUpdateMap = { }), } +const milestoneMap = { + schema: Joi.object({ + ...commonSchemaFields, + milestone: Joi.object({ + title: Joi.string().required(), + }).allow(null), + }).required(), + transform: ({ json }) => (json.milestone ? json.milestone.title : '---'), + render: ({ value }) => { + return { + label: 'milestone', + message: value, + color: 'informational', + } + }, +} + const propertyMap = { state: stateMap, title: titleMap, @@ -148,6 +166,7 @@ const propertyMap = { comments: commentsMap, age: ageUpdateMap, 'last-update': ageUpdateMap, + milestone: milestoneMap, } export default class GithubIssueDetail extends GithubAuthV3Service { @@ -182,6 +201,7 @@ export default class GithubIssueDetail extends GithubAuthV3Service { 'comments', 'age', 'last update', + 'milestone', ], documentation, }, diff --git a/services/github/github-issue-detail.spec.js b/services/github/github-issue-detail.spec.js index c20b05adead2f0..b4d7cc0608547c 100644 --- a/services/github/github-issue-detail.spec.js +++ b/services/github/github-issue-detail.spec.js @@ -90,6 +90,14 @@ describe('GithubIssueDetail', function () { message: formatDate('2019-04-02T20:09:31Z'), color: age('2019-04-02T20:09:31Z'), }) + given({ + property: 'milestone', + value: 'MS 1', + }).expect({ + label: 'milestone', + message: 'MS 1', + color: 'informational', + }) }) test(GithubIssueDetail.prototype.transform, () => { @@ -178,6 +186,18 @@ describe('GithubIssueDetail', function () { value: '2019-04-02T20:09:31Z', isPR: false, }) + given({ + property: 'milestone', + json: { milestone: { title: 'MS 1' } }, + }).expect({ + value: 'MS 1', + }) + given({ + property: 'milestone', + json: { milestone: null }, + }).expect({ + value: '---', + }) }) context('transform()', function () { diff --git a/services/github/github-issue-detail.tester.js b/services/github/github-issue-detail.tester.js index bb0103e48ca483..de0652fdfbd6b8 100644 --- a/services/github/github-issue-detail.tester.js +++ b/services/github/github-issue-detail.tester.js @@ -64,3 +64,17 @@ t.create('github pull request merge state (pull request not found)') label: 'issue/pull request', message: 'issue, pull request or repo not found', }) + +t.create('github issue milestone') + .get('/pulls/detail/milestone/badges/shields/4949.json') + .expectBadge({ + label: 'milestone', + message: 'badge-maker v3.4', + }) + +t.create('github issue milestone (without milestone)') + .get('/pulls/detail/milestone/badges/shields/979.json') + .expectBadge({ + label: 'milestone', + message: '---', + })