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: jNullj <jNullj@users.noreply.github.com>
Co-authored-by: repo-ranger[bot] <39074581+repo-ranger[bot]@users.noreply.github.com>
This commit is contained in:
jNullj
2023-05-29 22:46:41 +03:00
committed by GitHub
parent 759514337c
commit 8a11db8265
2 changed files with 18 additions and 5 deletions

View File

@@ -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)