diff --git a/README.md b/README.md index fb5e7189bf032853f4acd91e1f1c668923183ccf..dd4c97e2e3c2b1596714531699c68ba387d3ac14 100644 --- a/README.md +++ b/README.md @@ -10,7 +10,7 @@ <a href="#sponsors" alt="Sponsors on Open Collective"> <img src="https://img.shields.io/opencollective/sponsors/shields.svg" /></a> <a href="https://github.com/badges/shields/pulse" alt="Activity"> - <img src="https://img.shields.io/github/commit-activity/4w/badges/shields.svg" /></a> + <img src="https://img.shields.io/github/commit-activity/m/badges/shields.svg" /></a> <a href="https://circleci.com/gh/badges/shields/tree/master"> <img src="https://img.shields.io/circleci/project/github/badges/shields/master.svg" alt="build status"></a> <a href="https://circleci.com/gh/badges/daily-tests"> diff --git a/services/github/github-commit-activity.service.js b/services/github/github-commit-activity.service.js index 6eab06e51a0a554956144a857f715c2f5af258d7..36a2c150a5461c7bbf6e925df2e249f5614685c1 100644 --- a/services/github/github-commit-activity.service.js +++ b/services/github/github-commit-activity.service.js @@ -30,7 +30,7 @@ module.exports = class GithubCommitActivity extends LegacyService { static get examples() { return [ { - title: 'GitHub commit activity the past week, 4 weeks, year', + title: 'GitHub commit activity the past year', pattern: 'y/:user/:repo', namedParams: { user: 'eslint', repo: 'eslint' }, staticPreview: { @@ -41,12 +41,36 @@ module.exports = class GithubCommitActivity extends LegacyService { keywords: ['GitHub', 'commit', 'commits', 'activity'], documentation, }, + { + title: 'GitHub commit activity the past month', + pattern: 'm/:user/:repo', + namedParams: { user: 'eslint', repo: 'eslint' }, + staticPreview: { + label: 'commit activity', + message: '38/month', + color: 'blue', + }, + keywords: ['GitHub', 'commit', 'commits', 'activity'], + documentation, + }, + { + title: 'GitHub commit activity the past week', + pattern: 'w/:user/:repo', + namedParams: { user: 'eslint', repo: 'eslint' }, + staticPreview: { + label: 'commit activity', + message: '9/week', + color: 'blue', + }, + keywords: ['GitHub', 'commit', 'commits', 'activity'], + documentation, + }, ] } static registerLegacyRouteHandler({ camp, cache, githubApiProvider }) { camp.route( - /^\/github\/commit-activity\/(y|4w|w)\/([^/]+)\/([^/]+)\.(svg|png|gif|jpg|json)$/, + /^\/github\/commit-activity\/(y|m|4w|w)\/([^/]+)\/([^/]+)\.(svg|png|gif|jpg|json)$/, cache((data, match, sendBadge, request) => { const interval = match[1] const user = match[2] @@ -75,11 +99,24 @@ module.exports = class GithubCommitActivity extends LegacyService { ) intervalLabel = '/year' break + case 'm': + // To approximate the value for the past month, get the sum for the last + // four weeks and add a weighted value for the fifth week. + const fourWeeksValue = parsedData + .slice(-4) + .reduce((sum, weekInfo) => sum + weekInfo.total, 0) + const fifthWeekValue = parsedData.slice(-5)[0].total + const averageWeeksPerMonth = 365 / 12 / 7 + value = + fourWeeksValue + + Math.round((averageWeeksPerMonth - 4) * fifthWeekValue) + intervalLabel = '/month' + break case '4w': value = parsedData .slice(-4) .reduce((sum, weekInfo) => sum + weekInfo.total, 0) - intervalLabel = '/4 weeks' + intervalLabel = '/four weeks' break case 'w': value = parsedData.slice(-2)[0].total diff --git a/services/github/github-commit-activity.tester.js b/services/github/github-commit-activity.tester.js index 68e3543e65342632a593c1115778265277cbd9b3..105912d7b75f5e0d6edfe26b446a5bae0627d47f 100644 --- a/services/github/github-commit-activity.tester.js +++ b/services/github/github-commit-activity.tester.js @@ -14,6 +14,15 @@ t.create('commit activity (1 year)') }) ) +t.create('commit activity (1 month)') + .get('/m/eslint/eslint.json') + .expectJSONTypes( + Joi.object().keys({ + name: 'commit activity', + value: isMetricOverTimePeriod, + }) + ) + t.create('commit activity (4 weeks)') .get('/4w/eslint/eslint.json') .expectJSONTypes( diff --git a/services/test-validators.js b/services/test-validators.js index 394920c49709083ad1c3126ccefa4de49914ad66..590eb9cf20587676aec3e0cdb46875cb561a4b20 100644 --- a/services/test-validators.js +++ b/services/test-validators.js @@ -61,7 +61,7 @@ const isMetric = withRegex(/^[1-9][0-9]*[kMGTPEZY]?$/) const isMetricOpenIssues = withRegex(/^[1-9][0-9]*[kMGTPEZY]? open$/) const isMetricOverTimePeriod = withRegex( - /^[1-9][0-9]*[kMGTPEZY]?\/(year|month|4 weeks|week|day)$/ + /^[1-9][0-9]*[kMGTPEZY]?\/(year|month|four weeks|week|day)$/ ) const isIntegerPercentage = withRegex(/^[1-9][0-9]?%|^100%|^0%$/)