Skip to content

Commit

Permalink
fix: exclude bots from contributors list (#88)
Browse files Browse the repository at this point in the history
  • Loading branch information
krowter authored Oct 12, 2023
1 parent 82f24bb commit dcb9ae4
Show file tree
Hide file tree
Showing 3 changed files with 48 additions and 2 deletions.
6 changes: 4 additions & 2 deletions frontend/src/services/list-contributors.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,10 @@ import { $ } from "@builder.io/qwik";
import { API_BASE_URL } from "~/env";
import { Contributor } from "~/models/contributor";

export const getContributorsList = $(async (): Promise<Contributor[]> => {
export const getContributorsList = $(async () => {
const url = new URL("/contrib", API_BASE_URL);
const response = await fetch(url);
return response.json();
const contributors: Contributor[] = await response.json();

return contributors.filter(({ full_name }) => !full_name.includes("[bot]"));
});
28 changes: 28 additions & 0 deletions frontend/tests/services/contributors.fixture.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
import { Contributor } from "~/models/contributor";

export const sampleContributors: Contributor[] = [
{
full_name: "Iiqbal2000",
profile_url: "https://github.com/Iiqbal2000",
merged_pulls: 0,
pending_pulls: 1,
},
{
full_name: "YogiPristiawan",
profile_url: "https://github.com/YogiPristiawan",
merged_pulls: 1,
pending_pulls: 3,
},
{
full_name: "WahidinAji",
profile_url: "https://github.com/WahidinAji",
merged_pulls: 0,
pending_pulls: 1,
},
{
full_name: "dependabot[bot]",
profile_url: "https://github.com/apps/dependabot",
merged_pulls: 2,
pending_pulls: 6,
},
];
16 changes: 16 additions & 0 deletions frontend/tests/services/list-contributors.test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
import { expect, it, vi } from "vitest";
import { getContributorsList } from "~/services/list-contributors";
import { sampleContributors } from "./contributors.fixture";

global.fetch = vi.fn();

it("should exclude [bot] users", async () => {
vi.mocked(fetch).mockResolvedValue({
ok: true,
json: () => Promise.resolve(sampleContributors),
} as Response);

const contributors = await getContributorsList();

expect(contributors.map((c) => c.full_name)).not.toContain("dependabot[bot]");
});

0 comments on commit dcb9ae4

Please sign in to comment.