Skip to content

Commit

Permalink
[GitHub] Added milestone property to GitHub issue details service (#7864
Browse files Browse the repository at this point in the history
)

* Added milestone property to GitHub issue details service

* Fixed case when no milestone is available

* fixing unit test

* fixed service test for milestone property

Co-authored-by: repo-ranger[bot] <39074581+repo-ranger[bot]@users.noreply.github.com>
  • Loading branch information
AlexanderWert and repo-ranger[bot] authored May 21, 2022
1 parent 07bc032 commit 5b07779
Show file tree
Hide file tree
Showing 3 changed files with 66 additions and 1 deletion.
24 changes: 23 additions & 1 deletion services/github/github-issue-detail.service.js
Original file line number Diff line number Diff line change
Expand Up @@ -140,6 +140,26 @@ const ageUpdateMap = {
}),
}

const milestoneMap = {
schema: Joi.object({
...commonSchemaFields,
milestone: Joi.object({
title: Joi.string().required(),
}).allow(null),
}).required(),
transform: ({ json }) => {
if (!json.milestone) {
throw new InvalidResponse({ prettyMessage: 'no milestone' })
}
return json.milestone.title
},
render: ({ value }) => ({
label: 'milestone',
message: value,
color: 'informational',
}),
}

const propertyMap = {
state: stateMap,
title: titleMap,
Expand All @@ -148,14 +168,15 @@ const propertyMap = {
comments: commentsMap,
age: ageUpdateMap,
'last-update': ageUpdateMap,
milestone: milestoneMap,
}

export default class GithubIssueDetail extends GithubAuthV3Service {
static category = 'issue-tracking'
static route = {
base: 'github',
pattern:
':issueKind(issues|pulls)/detail/:property(state|title|author|label|comments|age|last-update)/:user/:repo/:number([0-9]+)',
':issueKind(issues|pulls)/detail/:property(state|title|author|label|comments|age|last-update|milestone)/:user/:repo/:number([0-9]+)',
}

static examples = [
Expand All @@ -182,6 +203,7 @@ export default class GithubIssueDetail extends GithubAuthV3Service {
'comments',
'age',
'last update',
'milestone',
],
documentation,
},
Expand Down
30 changes: 30 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,13 @@ describe('GithubIssueDetail', function () {
value: '2019-04-02T20:09:31Z',
isPR: false,
})
given({
property: 'milestone',
json: { milestone: { title: 'MS 1' } },
}).expect({
value: 'MS 1',
isPR: false,
})
})

context('transform()', function () {
Expand All @@ -194,4 +209,19 @@ describe('GithubIssueDetail', function () {
}
})
})

context('transform()', function () {
it('throws InvalidResponse error when issue has no milestone', function () {
try {
GithubIssueDetail.prototype.transform({
property: 'milestone',
json: { milestone: null },
})
expect.fail('Expected to throw')
} catch (e) {
expect(e).to.be.an.instanceof(InvalidResponse)
expect(e.prettyMessage).to.equal('no milestone')
}
})
})
})
13 changes: 13 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,16 @@ 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('/issues/detail/milestone/badges/shields/4949.json')
.expectBadge({
label: 'milestone',
message: 'badge-maker v3.4',
})

t.create('github issue milestone (without milestone)')
.get('/issues/detail/milestone/badges/shields/979.json')
.expectBadge({
message: 'no milestone',
})

0 comments on commit 5b07779

Please sign in to comment.