diff --git a/src/Diagram.svelte b/src/Diagram.svelte index 16211e776..97b2bc25a 100644 --- a/src/Diagram.svelte +++ b/src/Diagram.svelte @@ -1,9 +1,9 @@ diff --git a/src/commit.ts b/src/commit.ts index 9ff488aad..fcf50dcfb 100644 --- a/src/commit.ts +++ b/src/commit.ts @@ -60,6 +60,13 @@ export interface CommitGroup { week: number; } +export interface WeeklyActivity { + date: string; + time: number; + commits: number[]; + week: number; +} + export interface DiffStats { additions: number; deletions: number; @@ -137,30 +144,22 @@ export async function fetchCommits(project: Project, parentCommit: string): Prom return groupCommitHistory(commitsQuery); } -export function groupCommitsByWeek(commits: CommitMetadata[]): CommitGroup[] { - const groupedCommits: CommitGroup[] = []; +export function groupCommitsByWeek(commits: number[]): WeeklyActivity[] { + const groupedCommits: WeeklyActivity[] = []; let groupDate: Date | undefined = undefined; if (commits.length === 0) { return []; } - commits = commits.sort((a, b) => { - if (a.header.committerTime > b.header.committerTime) { - return -1; - } else if (a.header.committerTime < b.header.committerTime) { - return 1; - } - - return 0; - }); + commits = commits.sort((a, b) => a > b ? -1 : a < b ? 1 : 0); // A accumulator that increments by the amount of weeks between weekly commit groups - let weekAccumulator = Math.floor(getDaysPassed(new Date(commits[0].header.committerTime * 1000), new Date()) / 7); + let weekAccumulator = Math.floor(getDaysPassed(new Date(commits[0] * 1000), new Date()) / 7); // Loops over all commits and stores them by week with some additional metadata in groupedCommits. for (const commit of commits) { - const time = commit.header.committerTime * 1000; + const time = commit * 1000; const date = new Date(time); const isNewWeek = !groupedCommits.length || diff --git a/src/project.ts b/src/project.ts index 675c7ca20..4b71ee82b 100644 --- a/src/project.ts +++ b/src/project.ts @@ -349,6 +349,13 @@ export class Project implements ProjectInfo { return new Request(`projects/${urn}/commits`, host).get(params); } + static async getActivity( + urn: string, + host: Host, + ): Promise<{ activity: number[] }> { + return new Request(`projects/${urn}/activity`, host).get(); + } + async getCommit(commit: string): Promise { return new Request(`projects/${this.urn}/commits/${commit}`, this.seed.api).get(); }