diff --git a/services/github/github-commit-activity.service.js b/services/github/github-commit-activity.service.js index 821827a77d051e013a257ef320c3c15fea877d94..39af8a2f12f55601a8bab539c5e268d66741fe70 100644 --- a/services/github/github-commit-activity.service.js +++ b/services/github/github-commit-activity.service.js @@ -22,14 +22,14 @@ export default class GitHubCommitActivity extends GithubAuthV4Service { static category = 'activity' static route = { base: 'github/commit-activity', - pattern: ':interval(y|m|4w|w)/:user/:repo/:branch*', + pattern: ':interval(t|y|m|4w|w)/:user/:repo/:branch*', } static examples = [ { title: 'GitHub commit activity', // Override the pattern to omit the deprecated interval "4w". - pattern: ':interval(y|m|w)/:user/:repo', + pattern: ':interval(t|y|m|w)/:user/:repo', namedParams: { interval: 'm', user: 'eslint', repo: 'eslint' }, staticPreview: this.render({ interval: 'm', commitCount: 457 }), keywords: ['commits'], @@ -38,7 +38,7 @@ export default class GitHubCommitActivity extends GithubAuthV4Service { { title: 'GitHub commit activity (branch)', // Override the pattern to omit the deprecated interval "4w". - pattern: ':interval(y|m|w)/:user/:repo/:branch*', + pattern: ':interval(t|y|m|w)/:user/:repo/:branch*', namedParams: { interval: 'm', user: 'badges', @@ -54,7 +54,11 @@ export default class GitHubCommitActivity extends GithubAuthV4Service { static defaultBadgeData = { label: 'commit activity', color: 'blue' } static render({ interval, commitCount }) { + // If total commits selected change label from commit activity to commits + const label = interval === 't' ? 'commits' : undefined + const intervalLabel = { + t: '', y: '/year', m: '/month', '4w': '/four weeks', @@ -62,6 +66,7 @@ export default class GitHubCommitActivity extends GithubAuthV4Service { }[interval] return { + label, message: `${metric(commitCount)}${intervalLabel}`, } } @@ -74,7 +79,7 @@ export default class GitHubCommitActivity extends GithubAuthV4Service { $user: String! $repo: String! $branch: String! - $since: GitTimestamp! + $since: GitTimestamp ) { repository(owner: $user, name: $repo) { object(expression: $branch) { @@ -113,7 +118,9 @@ export default class GitHubCommitActivity extends GithubAuthV4Service { static getIntervalQueryStartDate({ interval }) { const now = new Date() - if (interval === 'y') { + if (interval === 't') { + return null + } else if (interval === 'y') { now.setUTCFullYear(now.getUTCFullYear() - 1) } else if (interval === 'm' || interval === '4w') { now.setUTCDate(now.getUTCDate() - 30) diff --git a/services/github/github-commit-activity.tester.js b/services/github/github-commit-activity.tester.js index b109d5b8102bac3452438bd0ecd9db2aab49ef65..4aacfc4c0359681886e0861ca688cd1b5b747f80 100644 --- a/services/github/github-commit-activity.tester.js +++ b/services/github/github-commit-activity.tester.js @@ -2,6 +2,7 @@ import Joi from 'joi' import { isMetricOverTimePeriod, isZeroOverTimePeriod, + isMetric, } from '../test-validators.js' import { createServiceTester } from '../tester.js' export const t = await createServiceTester() @@ -11,6 +12,11 @@ const isCommitActivity = Joi.alternatives().try( isZeroOverTimePeriod ) +t.create('commit acticity (total)').get('/t/badges/shields.json').expectBadge({ + label: 'commits', + message: isMetric, +}) + t.create('commit activity (1 year)').get('/y/eslint/eslint.json').expectBadge({ label: 'commit activity', message: isMetricOverTimePeriod,