Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[GitHub] Added milestone property to GitHub issue details service #7864

Merged
merged 5 commits into from
May 21, 2022
Merged
Show file tree
Hide file tree
Changes from 4 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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',
})