Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
101 changes: 55 additions & 46 deletions src/lib/github.ts
Original file line number Diff line number Diff line change
Expand Up @@ -485,6 +485,57 @@
} | null;
};

const CONTRIBUTIONS_QUERY = `query($login: String!, $from: DateTime!, $to: DateTime!) {
user(login: $login) {
contributionsCollection(from: $from, to: $to) {
totalCommitContributions
totalPullRequestContributions
totalIssueContributions
totalPullRequestReviewContributions
contributionCalendar {
totalContributions
weeks {
contributionDays {
date
contributionCount
}
}
}
}
}
}`;

type ContributionWeek = NonNullable<ContributionsResponse["user"]>["contributionsCollection"]["contributionCalendar"]["weeks"][number];

Check warning on line 508 in src/lib/github.ts

View workflow job for this annotation

GitHub Actions / Lint

'ContributionWeek' is defined but never used

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P2 未使用の型定義

ContributionWeek 型が定義されていますが、コード内のどこからも参照されていません。processContributionsCalendar の引数型は同じ型を直接 NonNullable<ContributionsResponse["user"]>["contributionsCollection"]["contributionCalendar"]["weeks"] として展開しているため、この型エイリアスは現状デッドコードになっています。削除するか、関数の引数型を ContributionWeek[] に置き換えて活用してください。

Context Used: 日本語で!!! (source)

Prompt To Fix With AI
This is a comment left during a code review.
Path: src/lib/github.ts
Line: 508

Comment:
**未使用の型定義**

`ContributionWeek` 型が定義されていますが、コード内のどこからも参照されていません。`processContributionsCalendar` の引数型は同じ型を直接 `NonNullable<ContributionsResponse["user"]>["contributionsCollection"]["contributionCalendar"]["weeks"]` として展開しているため、この型エイリアスは現状デッドコードになっています。削除するか、関数の引数型を `ContributionWeek[]` に置き換えて活用してください。

**Context Used:** 日本語で!!! ([source](https://app.greptile.com/review/custom-context?memory=instruction-0))

How can I resolve this? If you propose a fix, please make it concise.

Note: If this suggestion doesn't match your team's coding style, reply to this and let me know. I'll remember it for next time!


function processContributionsCalendar(weeks: NonNullable<ContributionsResponse["user"]>["contributionsCollection"]["contributionCalendar"]["weeks"]) {

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

medium

To improve readability and type safety, you can introduce a ContributionDay type and use the existing ContributionWeek type. This makes the function signature cleaner and more self-documenting.

First, define ContributionDay before this function:

type ContributionDay = { date: string; count: number };

Then, you can update this function's signature. You should also update calculateRecentContributions to use ContributionDay[] for its calendar parameter. Ensure that explicit return types are maintained for type safety.

Suggested change
function processContributionsCalendar(weeks: NonNullable<ContributionsResponse["user"]>["contributionsCollection"]["contributionCalendar"]["weeks"]) {
function processContributionsCalendar(weeks: ContributionWeek[]): ContributionDay[] {
References
  1. Maintain explicit return types for functions in TypeScript to ensure type safety and API clarity.

const calendar = weeks.flatMap((w) =>
w.contributionDays.map((d) => ({
date: d.date,
count: d.contributionCount,
}))
);
calendar.sort((a, b) => a.date.localeCompare(b.date));
return calendar;
}

function calculateRecentContributions(calendar: { date: string; count: number }[], sevenDaysAgoStr: string, thirtyDaysAgoStr: string) {

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

medium

To align with the suggested change in processContributionsCalendar, you should update this function to use the new ContributionDay type for the calendar parameter. Additionally, ensure the function has an explicit return type to maintain type safety and API clarity.

Suggested change
function calculateRecentContributions(calendar: { date: string; count: number }[], sevenDaysAgoStr: string, thirtyDaysAgoStr: string) {
function calculateRecentContributions(calendar: ContributionDay[], sevenDaysAgoStr: string, thirtyDaysAgoStr: string): number {
References
  1. Maintain explicit return types for functions in TypeScript to ensure type safety and API clarity.

let weeklyContributions = 0;
let monthlyContributions = 0;

for (let i = calendar.length - 1; i >= 0; i--) {
const day = calendar[i];
if (day.date < thirtyDaysAgoStr) {
break;
}
monthlyContributions += day.count;
if (day.date >= sevenDaysAgoStr) {
weeklyContributions += day.count;
}
}

return { weeklyContributions, monthlyContributions };
}

/**
* Task⑥: 過去1年間のコントリビューション統計を取得
* GraphQL contributionsCollection (認証必須)
Expand All @@ -509,27 +560,9 @@
const sevenDaysAgoStr = new Date(now.getTime() - 6 * 24 * 60 * 60 * 1000).toISOString().split("T")[0];
const thirtyDaysAgoStr = new Date(now.getTime() - 29 * 24 * 60 * 60 * 1000).toISOString().split("T")[0];

const query = `query($login: String!, $from: DateTime!, $to: DateTime!) {
user(login: $login) {
contributionsCollection(from: $from, to: $to) {
totalCommitContributions
totalPullRequestContributions
totalIssueContributions
totalPullRequestReviewContributions
contributionCalendar {
totalContributions
weeks {
contributionDays {
date
contributionCount
}
}
}
}
}
}`;

const data = await graphql<ContributionsResponse>(query, token, {

const data = await graphql<ContributionsResponse>(CONTRIBUTIONS_QUERY, token, {
Comment on lines 560 to +565

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P2 余分な空行

インラインクエリを削除した後、fetchContributions 内に連続する空行が2行残っています。1行にまとめてください。

Suggested change
const sevenDaysAgoStr = new Date(now.getTime() - 6 * 24 * 60 * 60 * 1000).toISOString().split("T")[0];
const thirtyDaysAgoStr = new Date(now.getTime() - 29 * 24 * 60 * 60 * 1000).toISOString().split("T")[0];
const query = `query($login: String!, $from: DateTime!, $to: DateTime!) {
user(login: $login) {
contributionsCollection(from: $from, to: $to) {
totalCommitContributions
totalPullRequestContributions
totalIssueContributions
totalPullRequestReviewContributions
contributionCalendar {
totalContributions
weeks {
contributionDays {
date
contributionCount
}
}
}
}
}
}`;
const data = await graphql<ContributionsResponse>(query, token, {
const data = await graphql<ContributionsResponse>(CONTRIBUTIONS_QUERY, token, {
const sevenDaysAgoStr = new Date(now.getTime() - 6 * 24 * 60 * 60 * 1000).toISOString().split("T")[0];
const thirtyDaysAgoStr = new Date(now.getTime() - 29 * 24 * 60 * 60 * 1000).toISOString().split("T")[0];
const data = await graphql<ContributionsResponse>(CONTRIBUTIONS_QUERY, token, {
Prompt To Fix With AI
This is a comment left during a code review.
Path: src/lib/github.ts
Line: 560-565

Comment:
**余分な空行**

インラインクエリを削除した後、`fetchContributions` 内に連続する空行が2行残っています。1行にまとめてください。

```suggestion
  const sevenDaysAgoStr = new Date(now.getTime() - 6 * 24 * 60 * 60 * 1000).toISOString().split("T")[0];
  const thirtyDaysAgoStr = new Date(now.getTime() - 29 * 24 * 60 * 60 * 1000).toISOString().split("T")[0];

  const data = await graphql<ContributionsResponse>(CONTRIBUTIONS_QUERY, token, {
```

How can I resolve this? If you propose a fix, please make it concise.

login: username,
from: oneYearAgo.toISOString(),
to: now.toISOString(),
Expand All @@ -539,32 +572,8 @@
}

const cc = data.user.contributionsCollection;
const calendar = cc.contributionCalendar.weeks.flatMap((w) =>
w.contributionDays.map((d) => ({
date: d.date,
count: d.contributionCount,
}))
);


calendar.sort((a, b) => a.date.localeCompare(b.date));

let weeklyContributions = 0;
let monthlyContributions = 0;

for (let i = calendar.length - 1; i >= 0; i--) {
const day = calendar[i];

if (day.date < thirtyDaysAgoStr) {
break;
}

monthlyContributions += day.count;

if (day.date >= sevenDaysAgoStr) {
weeklyContributions += day.count;
}
}
const calendar = processContributionsCalendar(cc.contributionCalendar.weeks);
const { weeklyContributions, monthlyContributions } = calculateRecentContributions(calendar, sevenDaysAgoStr, thirtyDaysAgoStr);

const { longestStreak, currentStreak } = calculateStreaks(calendar);
const mostActiveDay = calculateMostActiveDay(calendar);
Expand Down
Loading