Skip to content

Commit

Permalink
🐛 fix(#14): Check history on default branch
Browse files Browse the repository at this point in the history
Checks commit data on the default branch rather than hardcoded `master`,
fixes #14
  • Loading branch information
AndreMiras committed Feb 8, 2022
1 parent 7e5ed14 commit aa891d0
Show file tree
Hide file tree
Showing 8 changed files with 66 additions and 42 deletions.
20 changes: 12 additions & 8 deletions src/components/Container.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -24,10 +24,12 @@ test("search forks", (done) => {
nameWithOwner: "django/django",
stargazerCount: 54393,
forkCount: 23386,
object: {
committedDate: "2020-12-18T08:23:22Z",
history: {
totalCount: 29060,
defaultBranchRef: {
target: {
committedDate: "2020-12-18T08:23:22Z",
history: {
totalCount: 29060,
},
},
},
};
Expand All @@ -36,10 +38,12 @@ test("search forks", (done) => {
nameWithOwner: forkId,
stargazerCount: 214,
forkCount: 84,
object: {
committedDate: "2020-08-29T14:23:26Z",
history: {
totalCount: 13990,
defaultBranchRef: {
target: {
committedDate: "2020-08-29T14:23:26Z",
history: {
totalCount: 13990,
},
},
},
},
Expand Down
10 changes: 6 additions & 4 deletions src/components/ForkLine.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -7,10 +7,12 @@ test("renders", () => {
nameWithOwner: "django/django",
stargazerCount: 123,
forkCount: 321,
object: {
committedDate: "2020-08-29T14:23:26Z",
history: {
totalCount: 1234,
defaultBranchRef: {
target: {
committedDate: "2020-08-29T14:23:26Z",
history: {
totalCount: 1234,
},
},
},
};
Expand Down
4 changes: 2 additions & 2 deletions src/components/ForkLine.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,8 @@ const ForkLine: FunctionComponent<ForkLineProps> = ({ info }) => (
</td>
<td>{info.stargazerCount}</td>
<td>{info.forkCount}</td>
<td>{info.object.history.totalCount}</td>
<td>{timeSince(new Date(info.object.committedDate))}</td>
<td>{info.defaultBranchRef.target.history.totalCount}</td>
<td>{timeSince(new Date(info.defaultBranchRef.target.committedDate))}</td>
</tr>
);

Expand Down
30 changes: 18 additions & 12 deletions src/components/ResultTable.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -12,32 +12,38 @@ const forks = [
nameWithOwner: "django-nonrel/django",
stargazerCount: 214,
forkCount: 84,
object: {
committedDate: "2020-08-29T14:23:26Z",
history: {
totalCount: 13990,
defaultBranchRef: {
target: {
committedDate: "2020-08-29T14:23:26Z",
history: {
totalCount: 13990,
},
},
},
},
{
nameWithOwner: "django/django",
stargazerCount: 54330,
forkCount: 23377,
object: {
committedDate: "2020-12-07:14:12Z",
history: {
totalCount: 29000,
defaultBranchRef: {
target: {
committedDate: "2020-12-07:14:12Z",
history: {
totalCount: 29000,
},
},
},
},
{
nameWithOwner: "FlipperPA/django-mssql-backend",
stargazerCount: 18,
forkCount: 2,
object: {
committedDate: "2020-01-13:11:12Z",
history: {
totalCount: 28017,
defaultBranchRef: {
target: {
committedDate: "2020-01-13:11:12Z",
history: {
totalCount: 28017,
},
},
},
},
Expand Down
12 changes: 9 additions & 3 deletions src/components/ResultTable.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,11 @@ const HeaderModified: FunctionComponent<HeaderModifiedProps> = ({
}) => (
<OverlayTrigger
transition={false}
overlay={<Tooltip id="last-commit-tooltip">Last commit on master.</Tooltip>}
overlay={
<Tooltip id="last-commit-tooltip">
Last commit on the default branch.
</Tooltip>
}
>
<th onClick={() => onHeaderClick("committedDate", sortByCommittedDate)}>
<FontAwesomeIcon icon="calendar-alt" /> Modified{" "}
Expand Down Expand Up @@ -87,9 +91,11 @@ const ResultTable: FunctionComponent<ResultTableProps> = ({
);
const sortByStargazerCount = sortObjectsFunc((x) => x.stargazerCount);
const sortByForkCount = sortObjectsFunc((x) => x.forkCount);
const sortByCommits = sortObjectsFunc((x) => x.object.history.totalCount);
const sortByCommits = sortObjectsFunc(
(x) => x.defaultBranchRef.target.history.totalCount
);
const sortByCommittedDate = sortObjectsFunc((x) =>
Date.parse(x.object.committedDate)
Date.parse(x.defaultBranchRef.target.committedDate)
);
const [orderBy, setOrderBy] = useState<{
column: string;
Expand Down
12 changes: 7 additions & 5 deletions src/utils/graphql.ts
Original file line number Diff line number Diff line change
Expand Up @@ -44,11 +44,13 @@ const GET_FORKS_QUERY = gql`
nameWithOwner
stargazerCount
forkCount
object(expression: "master") {
... on Commit {
committedDate
history {
totalCount
defaultBranchRef {
target {
... on Commit {
committedDate
history {
totalCount
}
}
}
}
Expand Down
10 changes: 6 additions & 4 deletions src/utils/search.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,10 +12,12 @@ test("basic case", (done) => {
nameWithOwner: "django/django",
stargazerCount: 54393,
forkCount: 23386,
object: {
committedDate: "2020-12-18T08:23:22Z",
history: {
totalCount: 29060,
defaultBranchRef: {
target: {
committedDate: "2020-12-18T08:23:22Z",
history: {
totalCount: 29060,
},
},
},
};
Expand Down
10 changes: 6 additions & 4 deletions src/utils/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,12 @@ type Node = {
nameWithOwner: string;
stargazerCount: number;
forkCount: number;
object: {
committedDate: string;
history: {
totalCount: number;
defaultBranchRef: {
target: {
committedDate: string;
history: {
totalCount: number;
};
};
};
};
Expand Down

0 comments on commit aa891d0

Please sign in to comment.