Skip to content

Commit

Permalink
Added milestone property to GitHub issue details service
Browse files Browse the repository at this point in the history
  • Loading branch information
AlexanderWert committed May 9, 2022
1 parent 377a036 commit f17bf20
Show file tree
Hide file tree
Showing 3 changed files with 53 additions and 0 deletions.
19 changes: 19 additions & 0 deletions services/github/github-issue-detail.service.js
Original file line number Diff line number Diff line change
Expand Up @@ -140,6 +140,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,
Expand All @@ -148,6 +165,7 @@ const propertyMap = {
comments: commentsMap,
age: ageUpdateMap,
'last-update': ageUpdateMap,
milestone: milestoneMap,
}

export default class GithubIssueDetail extends GithubAuthV3Service {
Expand Down Expand Up @@ -182,6 +200,7 @@ export default class GithubIssueDetail extends GithubAuthV3Service {
'comments',
'age',
'last update',
'milestone',
],
documentation,
},
Expand Down
20 changes: 20 additions & 0 deletions services/github/github-issue-detail.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -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, () => {
Expand Down Expand Up @@ -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 () {
Expand Down
14 changes: 14 additions & 0 deletions services/github/github-issue-detail.tester.js
Original file line number Diff line number Diff line change
Expand Up @@ -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: '---',
})

0 comments on commit f17bf20

Please sign in to comment.