Radish alpha
r
Radicle web interface
Radicle
Git (anonymous pull)
Log in to clone via SSH
Implements activity endpoint for project graph
Sebastian Martinez committed 3 years ago
commit 3a5527208ba947e01408f9e4e3ef8dc744a584e4
parent 7481808014be1e11ebe27395a4b34521104a959a
4 files changed +24 -26
modified src/Diagram.svelte
@@ -1,9 +1,9 @@
<script lang="ts">
  import { onMount } from "svelte";
-
  import type { CommitGroup } from "./commit";
+
  import type { WeeklyActivity } from "./commit";

  export let strokeWidth: number;
-
  export let points: CommitGroup[];
+
  export let points: WeeklyActivity[];
  export let viewBoxWidth: number;
  export let viewBoxHeight: number;

modified src/base/projects/Widget.svelte
@@ -13,18 +13,10 @@
  export let anchor: proj.Anchor | null = null;
  export let compact = false;

-
  const getTimestampOneYearAgo = () => {
-
    const now = new Date();
-
    const oneYearAgo = new Date(now.getFullYear() - 1, now.getMonth(), now.getDate());
-
    return Math.floor(oneYearAgo.getTime() / 1000).toString();
-
  };
-

  const loadCommits = async () => {
-
    const commits = await Project.getCommits(project.urn, seed.api, {
-
      parent: project.head ?? null,
-
      since: getTimestampOneYearAgo(),
-
    });
-
    return groupCommitsByWeek(commits.headers);
+
    const commits = await Project.getActivity(project.urn, seed.api);
+

+
    return groupCommitsByWeek(commits.activity);
  };
</script>

modified 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 ||
modified 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<Commit> {
    return new Request(`projects/${this.urn}/commits/${commit}`, this.seed.api).get();
  }