From deee5d0a01b9a693ade02790688a3ec17a0e72d8 Mon Sep 17 00:00:00 2001 From: Marcelo Alves Date: Tue, 5 Nov 2019 17:52:44 -0800 Subject: [PATCH] feat: add review links (#213) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit * feat: 🎸 add review links * docs: add marceloalves to contributors --- .all-contributorsrc | 9 +++++++++ README.md | 1 + src/generate/__tests__/format-contribution-type.js | 9 +++++++++ src/generate/__tests__/format-contributor.js | 6 +++--- src/repo/index.js | 12 ++++++++++++ src/util/contribution-types.js | 1 + 6 files changed, 35 insertions(+), 3 deletions(-) diff --git a/.all-contributorsrc b/.all-contributorsrc index 0d4101a..be61bed 100644 --- a/.all-contributorsrc +++ b/.all-contributorsrc @@ -362,6 +362,15 @@ "bug", "code" ] + }, + { + "login": "MarceloAlves", + "name": "Marcelo Alves", + "avatar_url": "https://avatars1.githubusercontent.com/u/216782?v=4", + "profile": "https://github.com/marceloalves", + "contributions": [ + "code" + ] } ] } diff --git a/README.md b/README.md index e6210cf..f42f036 100644 --- a/README.md +++ b/README.md @@ -128,6 +128,7 @@ Thanks goes to these wonderful people Fabrizio
Fabrizio

🐛 💻 + Marcelo Alves
Marcelo Alves

💻 diff --git a/src/generate/__tests__/format-contribution-type.js b/src/generate/__tests__/format-contribution-type.js index a7317af..11bff89 100644 --- a/src/generate/__tests__/format-contribution-type.js +++ b/src/generate/__tests__/format-contribution-type.js @@ -50,6 +50,15 @@ test('return link to issues', () => { expect(formatContributionType(options, contributor, 'bug')).toBe(expected) }) +test('return link to reviews', () => { + const contributor = contributors.kentcdodds + const {options} = fixtures() + const expected = + '👀' + + expect(formatContributionType(options, contributor, 'review')).toBe(expected) +}) + test('make any symbol into a link if contribution is an object', () => { const contributor = contributors.kentcdodds const {options} = fixtures() diff --git a/src/generate/__tests__/format-contributor.js b/src/generate/__tests__/format-contributor.js index b8feece..8ed7564 100644 --- a/src/generate/__tests__/format-contributor.js +++ b/src/generate/__tests__/format-contributor.js @@ -20,7 +20,7 @@ test('format a simple contributor', () => { const {options} = fixtures() const expected = - 'Kent C. Dodds
Kent C. Dodds

👀' + 'Kent C. Dodds
Kent C. Dodds

👀' expect(formatContributor(options, contributor)).toBe(expected) }) @@ -30,7 +30,7 @@ test('format contributor with complex contribution types', () => { const {options} = fixtures() const expected = - 'Kent C. Dodds
Kent C. Dodds

📖 👀 💬' + 'Kent C. Dodds
Kent C. Dodds

📖 👀 💬' expect(formatContributor(options, contributor)).toBe(expected) }) @@ -53,7 +53,7 @@ test('default image size to 100', () => { delete options.imageSize const expected = - 'Kent C. Dodds
Kent C. Dodds

👀' + 'Kent C. Dodds
Kent C. Dodds

👀' expect(formatContributor(options, contributor)).toBe(expected) }) diff --git a/src/repo/index.js b/src/repo/index.js index ac3196c..808d70b 100644 --- a/src/repo/index.js +++ b/src/repo/index.js @@ -12,6 +12,8 @@ const SUPPORTED_REPO_TYPES = { '<%= options.repoHost || "https://github.com" %>/<%= options.projectOwner %>/<%= options.projectName %>/commits?author=<%= contributor.login %>', linkToIssues: '<%= options.repoHost || "https://github.com" %>/<%= options.projectOwner %>/<%= options.projectName %>/issues?q=author%3A<%= contributor.login %>', + linkToReviews: + '<%= options.repoHost || "https://github.com" %>/<%= options.projectOwner %>/<%= options.projectName %>/pulls?q=is%3Apr+reviewed-by%3A<%= contributor.login %>', getUserInfo: githubAPI.getUserInfo, getContributors: githubAPI.getContributors, }, @@ -24,6 +26,8 @@ const SUPPORTED_REPO_TYPES = { '<%= options.repoHost || "https://gitlab.com" %>/<%= options.projectOwner %>/<%= options.projectName %>/commits/master', linkToIssues: '<%= options.repoHost || "https://gitlab.com" %>/<%= options.projectOwner %>/<%= options.projectName %>/issues?author_username=<%= contributor.login %>', + linkToReviews: + '<%= options.repoHost || "https://gitlab.com" %>/<%= options.projectOwner %>/<%= options.projectName %>/merge_requests?scope=all&state=all&approver_usernames[]=<%= contributor.login %>', getUserInfo: gitlabAPI.getUserInfo, getContributors: gitlabAPI.getContributors, }, @@ -77,6 +81,13 @@ const getLinkToIssues = function(repoType) { return null } +const getLinkToReviews = function(repoType) { + if (repoType in SUPPORTED_REPO_TYPES) { + return SUPPORTED_REPO_TYPES[repoType].linkToReviews + } + return null +} + const getUserInfo = function(username, repoType, repoHost) { if (repoType in SUPPORTED_REPO_TYPES) { return SUPPORTED_REPO_TYPES[repoType].getUserInfo( @@ -107,6 +118,7 @@ module.exports = { getTypeName, getLinkToCommits, getLinkToIssues, + getLinkToReviews, getUserInfo, getContributors, } diff --git a/src/util/contribution-types.js b/src/util/contribution-types.js index 8d792c1..dbb2257 100644 --- a/src/util/contribution-types.js +++ b/src/util/contribution-types.js @@ -81,6 +81,7 @@ const defaultTypes = function(repoType) { review: { symbol: '👀', description: 'Reviewed Pull Requests', + link: repo.getLinkToReviews(repoType), }, security: { symbol: '🛡️',