Skip to content
Snippets Groups Projects
Unverified Commit 8a11db82 authored by jNullj's avatar jNullj Committed by GitHub
Browse files

feat: Add total commits to [GitHubCommitActivity] (#9196)


* feat: Add total commits to GithubCommitActivity

As part of a new feature proposed at issue #6070 added the requested feature.
I also used the conversation at pull request #6081 as a basis for those changes.

This change adds a new interval to the github/commit-activity shield 'total' (t for short).
The interval shows the total commits of the repo since its creation.

* Fix format with prettier

* Label for 'total' interval is now commits

Label change for the 'total' interval from 'commit activity' to 'commits'

---------

Co-authored-by: default avatarjNullj <jNullj@users.noreply.github.com>
Co-authored-by: default avatarrepo-ranger[bot] <39074581+repo-ranger[bot]@users.noreply.github.com>
parent 75951433
No related branches found
No related tags found
No related merge requests found
...@@ -22,14 +22,14 @@ export default class GitHubCommitActivity extends GithubAuthV4Service { ...@@ -22,14 +22,14 @@ export default class GitHubCommitActivity extends GithubAuthV4Service {
static category = 'activity' static category = 'activity'
static route = { static route = {
base: 'github/commit-activity', 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 = [ static examples = [
{ {
title: 'GitHub commit activity', title: 'GitHub commit activity',
// Override the pattern to omit the deprecated interval "4w". // 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' }, namedParams: { interval: 'm', user: 'eslint', repo: 'eslint' },
staticPreview: this.render({ interval: 'm', commitCount: 457 }), staticPreview: this.render({ interval: 'm', commitCount: 457 }),
keywords: ['commits'], keywords: ['commits'],
...@@ -38,7 +38,7 @@ export default class GitHubCommitActivity extends GithubAuthV4Service { ...@@ -38,7 +38,7 @@ export default class GitHubCommitActivity extends GithubAuthV4Service {
{ {
title: 'GitHub commit activity (branch)', title: 'GitHub commit activity (branch)',
// Override the pattern to omit the deprecated interval "4w". // 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: { namedParams: {
interval: 'm', interval: 'm',
user: 'badges', user: 'badges',
...@@ -54,7 +54,11 @@ export default class GitHubCommitActivity extends GithubAuthV4Service { ...@@ -54,7 +54,11 @@ export default class GitHubCommitActivity extends GithubAuthV4Service {
static defaultBadgeData = { label: 'commit activity', color: 'blue' } static defaultBadgeData = { label: 'commit activity', color: 'blue' }
static render({ interval, commitCount }) { static render({ interval, commitCount }) {
// If total commits selected change label from commit activity to commits
const label = interval === 't' ? 'commits' : undefined
const intervalLabel = { const intervalLabel = {
t: '',
y: '/year', y: '/year',
m: '/month', m: '/month',
'4w': '/four weeks', '4w': '/four weeks',
...@@ -62,6 +66,7 @@ export default class GitHubCommitActivity extends GithubAuthV4Service { ...@@ -62,6 +66,7 @@ export default class GitHubCommitActivity extends GithubAuthV4Service {
}[interval] }[interval]
return { return {
label,
message: `${metric(commitCount)}${intervalLabel}`, message: `${metric(commitCount)}${intervalLabel}`,
} }
} }
...@@ -74,7 +79,7 @@ export default class GitHubCommitActivity extends GithubAuthV4Service { ...@@ -74,7 +79,7 @@ export default class GitHubCommitActivity extends GithubAuthV4Service {
$user: String! $user: String!
$repo: String! $repo: String!
$branch: String! $branch: String!
$since: GitTimestamp! $since: GitTimestamp
) { ) {
repository(owner: $user, name: $repo) { repository(owner: $user, name: $repo) {
object(expression: $branch) { object(expression: $branch) {
...@@ -113,7 +118,9 @@ export default class GitHubCommitActivity extends GithubAuthV4Service { ...@@ -113,7 +118,9 @@ export default class GitHubCommitActivity extends GithubAuthV4Service {
static getIntervalQueryStartDate({ interval }) { static getIntervalQueryStartDate({ interval }) {
const now = new Date() const now = new Date()
if (interval === 'y') { if (interval === 't') {
return null
} else if (interval === 'y') {
now.setUTCFullYear(now.getUTCFullYear() - 1) now.setUTCFullYear(now.getUTCFullYear() - 1)
} else if (interval === 'm' || interval === '4w') { } else if (interval === 'm' || interval === '4w') {
now.setUTCDate(now.getUTCDate() - 30) now.setUTCDate(now.getUTCDate() - 30)
......
...@@ -2,6 +2,7 @@ import Joi from 'joi' ...@@ -2,6 +2,7 @@ import Joi from 'joi'
import { import {
isMetricOverTimePeriod, isMetricOverTimePeriod,
isZeroOverTimePeriod, isZeroOverTimePeriod,
isMetric,
} from '../test-validators.js' } from '../test-validators.js'
import { createServiceTester } from '../tester.js' import { createServiceTester } from '../tester.js'
export const t = await createServiceTester() export const t = await createServiceTester()
...@@ -11,6 +12,11 @@ const isCommitActivity = Joi.alternatives().try( ...@@ -11,6 +12,11 @@ const isCommitActivity = Joi.alternatives().try(
isZeroOverTimePeriod 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({ t.create('commit activity (1 year)').get('/y/eslint/eslint.json').expectBadge({
label: 'commit activity', label: 'commit activity',
message: isMetricOverTimePeriod, message: isMetricOverTimePeriod,
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment