Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: ニュース一覧・詳細ページを追加 #32

Merged
merged 7 commits into from
Jul 3, 2024

Conversation

tatsutakein
Copy link
Member

@tatsutakein tatsutakein commented Jul 3, 2024

Issue

概要

ニュース一覧・詳細ページを追加します。

レビュー観点

レビューレベル

  • Lv0: まったく見ないで Approve する
  • Lv1: ぱっとみて違和感がないかチェックして Approve する
  • Lv2: 仕様レベルまで理解して、仕様通りに動くかある程度検証して Approve する
  • Lv3: 実際に環境で動作確認したうえで Approve する

レビュー優先度

  • すぐに見てもらいたい ( hotfix など ) 🚀
  • 今日中に見てもらいたい 🚗
  • 今日〜明日中で見てもらいたい 🚶
  • 数日以内で見てもらいたい 🐢

参考リンク

スクリーンショット

Before After

Summary by CodeRabbit

  • New Features

    • Introduced pages for news content with dynamic fetching and rendering.
    • Added a configurable backend URL for various environments.
    • Implemented new components for iterating and conditionally rendering content.
  • Improvements

    • Enhanced the configuration for deploying with Cloudflare.
    • Added support for GraphQL API interactions to fetch news data.
  • Dependencies

    • Added @astrojs/cloudflare dependency.
    • Removed sharp dependency.
  • Configuration

    • Added environment variable support for backend URLs in configuration files and workflows.

Copy link

coderabbitai bot commented Jul 3, 2024

Walkthrough

The recent update primarily enhances our application by adding detailed news functionalities and integrating Cloudflare as a deployment target. These updates include environment setup changes, new components for handling news listings and details, workflow adjustments in GitHub Actions for different environments, and supporting configuration changes in multiple files.

Changes

File(s) Change Summary
.env.sample Added BACKEND_URL to connect to the backend API
.github/workflows/** Updated CI/CD workflows to include backend-url configuration for different environments
astro.config.mjs Integrated Cloudflare adapter and updated configuration
package.json Added @astrojs/cloudflare dependency and removed sharp
plopfile.mjs Adjusted generators for environment and sample prompts
src/components/For.astro Implemented logic for iterating over elements and rendering fallback content
src/components/Show.astro Added logic to conditionally render content based on a property
src/lib/api.ts Introduced functions for fetching news data using GraphQL API
src/pages/** (news-related files) Created templates for fetching and displaying news content
src/types.ts Defined News interface for type consistency
templates/env/.env.hbs Added a template for .env file with BACKEND_URL variable

Sequence Diagram(s)

sequenceDiagram
    participant User
    participant NewsPage
    participant GraphQLAPI
    
    User->>NewsPage: Request news list
    NewsPage->>GraphQLAPI: Fetch news list
    GraphQLAPI-->>NewsPage: Return news list
    NewsPage-->>User: Display news list

    User->>NewsDetailPage: Click on news item
    NewsDetailPage->>GraphQLAPI: Fetch news by slug
    GraphQLAPI-->>NewsDetailPage: Return news data
    NewsDetailPage-->>User: Display news details
Loading

Assessment against linked issues

Objective Addressed Explanation
ニュース詳細ページ (#27)
ニュース一覧ページ (#28)

Poem

In the code where we roam,
New pages bring news home,
With Cloudflare's swift embrace,
Data dances through the space.
From slugs to lists we glide,
On a backend magic ride.
🎉🌟

Tip

AI model upgrade

gpt-4o model for reviews and chat is now live

OpenAI claims that this model is better at understanding and generating code than the previous models. Please join our Discord Community to provide any feedback or to report any issues.


Thank you for using CodeRabbit. We offer it for free to the OSS community and would appreciate your support in helping us grow. If you find it useful, would you consider giving us a shout-out on your favorite social media?

Share
Tips

Chat

There are 3 ways to chat with CodeRabbit:

  • Review comments: Directly reply to a review comment made by CodeRabbit. Example:
    • I pushed a fix in commit <commit_id>.
    • Generate unit testing code for this file.
    • Open a follow-up GitHub issue for this discussion.
  • Files and specific lines of code (under the "Files changed" tab): Tag @coderabbitai in a new review comment at the desired location with your query. Examples:
    • @coderabbitai generate unit testing code for this file.
    • @coderabbitai modularize this function.
  • PR comments: Tag @coderabbitai in a new PR comment to ask questions about the PR branch. For the best results, please provide a very specific query, as very limited context is provided in this mode. Examples:
    • @coderabbitai generate interesting stats about this repository and render them as a table.
    • @coderabbitai show all the console.log statements in this repository.
    • @coderabbitai read src/utils.ts and generate unit testing code.
    • @coderabbitai read the files in the src/scheduler package and generate a class diagram using mermaid and a README in the markdown format.
    • @coderabbitai help me debug CodeRabbit configuration file.

Note: Be mindful of the bot's finite context window. It's strongly recommended to break down tasks such as reading entire modules into smaller chunks. For a focused discussion, use review comments to chat about specific files and their changes, instead of using the PR comments.

CodeRabbit Commands (invoked as PR comments)

  • @coderabbitai pause to pause the reviews on a PR.
  • @coderabbitai resume to resume the paused reviews.
  • @coderabbitai review to trigger an incremental review. This is useful when automatic reviews are disabled for the repository.
  • @coderabbitai full review to do a full review from scratch and review all the files again.
  • @coderabbitai summary to regenerate the summary of the PR.
  • @coderabbitai resolve resolve all the CodeRabbit review comments.
  • @coderabbitai configuration to show the current CodeRabbit configuration for the repository.
  • @coderabbitai help to get help.

Additionally, you can add @coderabbitai ignore anywhere in the PR description to prevent this PR from being reviewed.

CodeRabbit Configration File (.coderabbit.yaml)

  • You can programmatically configure CodeRabbit by adding a .coderabbit.yaml file to the root of your repository.
  • Please see the configuration documentation for more information.
  • If your editor has YAML language server enabled, you can add the path at the top of this file to enable auto-completion and validation: # yaml-language-server: $schema=https://coderabbit.ai/integrations/schema.v2.json

Documentation and Community

  • Visit our Documentation for detailed information on how to use CodeRabbit.
  • Join our Discord Community to get help, request features, and share feedback.
  • Follow us on X/Twitter for updates and announcements.

Copy link
Contributor

@tatsutakeinjp-bot tatsutakeinjp-bot bot left a comment

Choose a reason for hiding this comment

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

Device URL
mobile https://248f3b07.asis-quest.pages.dev

Not what you expected? Are your scores flaky? GitHub runners could be the cause.
Try running on Foo instead

Copy link

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

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

Actionable comments posted: 6

Review details

Configuration used: CodeRabbit UI
Review profile: CHILL

Commits

Files that changed from the base of the PR and between 5f496ad and d298e3e.

Files ignored due to path filters (1)
  • bun.lockb is excluded by !**/bun.lockb
Files selected for processing (17)
  • .env.sample (1 hunks)
  • .github/workflows/cd.yml (1 hunks)
  • .github/workflows/preview.yml (1 hunks)
  • .github/workflows/production.yml (1 hunks)
  • .github/workflows/wc-deploy-cloudflare-pages.yml (2 hunks)
  • astro.config.mjs (1 hunks)
  • package.json (1 hunks)
  • plopfile.mjs (1 hunks)
  • src/components/For.astro (1 hunks)
  • src/components/Show.astro (1 hunks)
  • src/lib/api.ts (1 hunks)
  • src/pages/404.astro (1 hunks)
  • src/pages/index.astro (1 hunks)
  • src/pages/news/[slug].astro (1 hunks)
  • src/pages/news/index.astro (1 hunks)
  • src/types.ts (1 hunks)
  • templates/env/.env.hbs (1 hunks)
Files skipped from review due to trivial changes (10)
  • .env.sample
  • .github/workflows/cd.yml
  • .github/workflows/preview.yml
  • .github/workflows/production.yml
  • package.json
  • src/pages/404.astro
  • src/pages/index.astro
  • src/pages/news/[slug].astro
  • src/types.ts
  • templates/env/.env.hbs
Additional comments not posted (18)
src/components/Show.astro (3)

1-4: Ensure TypeScript Interface Completeness

The Props interface defines the expected properties for the component. Ensure that all necessary properties are included and that the interface is used correctly in the component.


6-6: LGTM!

The when property is correctly extracted from Astro.props.


9-9: LGTM!

The component correctly implements conditional rendering based on the when property.

astro.config.mjs (4)

1-1: Ensure Correct Import of Cloudflare Integration

The cloudflare integration is imported from @astrojs/cloudflare. Ensure that this dependency is correctly installed and compatible with the current Astro version.


3-3: LGTM!

The defineConfig function is correctly imported from astro/config.


8-8: LGTM!

The sitemap integration is correctly added to the Astro configuration.


9-10: LGTM!

The Astro configuration is correctly set to use the cloudflare adapter and output is set to server.

src/components/For.astro (4)

2-6: Ensure TypeScript Interface Completeness

The Props interface defines the expected properties for the component. Ensure that all necessary properties are included and that the interface is used correctly in the component.


8-8: LGTM!

The each property is correctly extracted from Astro.props.


11-19: LGTM!

The async generator function correctly iterates over the each iterable and renders content for each item.


21-23: LGTM!

The Show component is correctly used to conditionally render fallback content if the each iterable is empty.

src/pages/news/index.astro (2)

2-7: Ensure Correct Imports and Fetching Logic

The imports and fetching logic appear correct. Ensure that the fetchNewsList function is correctly implemented and handles errors gracefully.


10-22: LGTM!

The BaseLayout and For components are correctly used to render a list of news articles.

plopfile.mjs (2)

7-23: Ensure Correct Configuration of Sample Generator

The sample generator appears to be correctly configured. Ensure that the templateFiles and destination paths are correct and that the templates exist.


25-42: LGTM!

The env generator is correctly configured to prompt for a backend URL and add a .env file using a template.

src/lib/api.ts (1)

9-25: Verify the environment variable setup.

Ensure that import.meta.env.BACKEND_URL is correctly set up and available in all environments where this function will be used.

.github/workflows/wc-deploy-cloudflare-pages.yml (2)

18-20: Verify the usage of the new input backend-url.

Ensure that the backend-url input is used correctly in the workflow steps.

Verification successful

The new input backend-url is used correctly in the workflow steps.

  • The input backend-url is passed to the command bun plop env -- --backendUrl "${{ inputs.backend-url }}" as expected.
Scripts executed

The following scripts were executed for the analysis:


Script:

#!/bin/bash
# Description: Verify the usage of the new input `backend-url` in the workflow steps.

# Test: Search for the `backend-url` usage in the workflow file. Expect: Correct usage in the workflow steps.
rg 'backend-url' .github/workflows/wc-deploy-cloudflare-pages.yml

Length of output: 154


49-50: Verify the plop command usage.

Ensure that the backend-url input is passed correctly to the plop command.

Verification successful

Verified the plop command usage.

The backend-url input is correctly passed to the plop command in the workflow file.

  • .github/workflows/wc-deploy-cloudflare-pages.yml line 50
Scripts executed

The following scripts were executed for the analysis:


Script:

#!/bin/bash
# Description: Verify the `plop` command usage with the `backend-url` input.

# Test: Search for the `plop` command usage in the workflow file. Expect: Correct usage with the `backend-url` input.
rg 'plop env -- --backendUrl' .github/workflows/wc-deploy-cloudflare-pages.yml

Length of output: 150

operationsDoc: string,
operationName: string,
// biome-ignore lint/suspicious/noExplicitAny: <explanation>
variables: Record<string, any>
Copy link

Choose a reason for hiding this comment

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

Improve the type of variables parameter.

Instead of using Record<string, any>, consider defining a more specific type for the variables parameter to improve type safety.

-  variables: Record<string, any>
+  variables: Record<string, unknown>
Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.

Suggested change
variables: Record<string, any>
variables: Record<string, unknown>

console.error(errors)
}

console.log(data)
Copy link

Choose a reason for hiding this comment

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

Replace console logs with a proper logging mechanism.

Using console.log is not recommended for production code. Consider using a logging library to handle logs.

-  console.log(data)
+  // Use a logging library instead of console.log
+  logger.info('Fetched news list', data)

Committable suggestion was skipped due to low confidence.

Comment on lines +30 to +55
export async function fetchNewsList(): Promise<News[]> {
const { errors, data } = await fetchGraphQL(
`
query GetNewsList {
news {
title
slug
publishedAt
excerpt
coverImageUrl
content
}
}
`,
'GetNewsList',
{}
)

if (errors) {
// handle those errors like a pro
console.error(errors)
}

console.log(data)
return data.news as News[]
}
Copy link

Choose a reason for hiding this comment

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

Add proper error handling.

The function should handle errors more gracefully rather than just logging them to the console.

  if (errors) {
    // handle those errors like a pro
    console.error(errors)
    throw new Error('Failed to fetch news list')
  }
Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.

Suggested change
export async function fetchNewsList(): Promise<News[]> {
const { errors, data } = await fetchGraphQL(
`
query GetNewsList {
news {
title
slug
publishedAt
excerpt
coverImageUrl
content
}
}
`,
'GetNewsList',
{}
)
if (errors) {
// handle those errors like a pro
console.error(errors)
}
console.log(data)
return data.news as News[]
}
export async function fetchNewsList(): Promise<News[]> {
const { errors, data } = await fetchGraphQL(
`
query GetNewsList {
news {
title
slug
publishedAt
excerpt
coverImageUrl
content
}
}
`,
'GetNewsList',
{}
)
if (errors) {
// handle those errors like a pro
console.error(errors)
throw new Error('Failed to fetch news list')
}
console.log(data)
return data.news as News[]
}

console.error(errors)
}

console.log(data)
Copy link

Choose a reason for hiding this comment

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

Replace console logs with a proper logging mechanism.

Using console.log is not recommended for production code. Consider using a logging library to handle logs.

-  console.log(data)
+  // Use a logging library instead of console.log
+  logger.info('Fetched news by slug', data)

Committable suggestion was skipped due to low confidence.

Comment on lines +60 to +87
export async function fetchNewsBySlug(slug: string): Promise<News> {
const { errors, data } = await fetchGraphQL(
`
query GetNewsBySlug($slug: String) {
news(where: {slug: {_eq: $slug}}) {
title
slug
publishedAt
excerpt
coverImageUrl
content
}
}
`,
'GetNewsBySlug',
{
slug
}
)

if (errors) {
// handle those errors like a pro
console.error(errors)
}

console.log(data)
// biome-ignore lint/style/noNonNullAssertion: <explanation>
return (data.news as News[])[0]!
Copy link

Choose a reason for hiding this comment

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

Add proper error handling.

The function should handle errors more gracefully rather than just logging them to the console.

  if (errors) {
    // handle those errors like a pro
    console.error(errors)
    throw new Error('Failed to fetch news by slug')
  }
Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.

Suggested change
export async function fetchNewsBySlug(slug: string): Promise<News> {
const { errors, data } = await fetchGraphQL(
`
query GetNewsBySlug($slug: String) {
news(where: {slug: {_eq: $slug}}) {
title
slug
publishedAt
excerpt
coverImageUrl
content
}
}
`,
'GetNewsBySlug',
{
slug
}
)
if (errors) {
// handle those errors like a pro
console.error(errors)
}
console.log(data)
// biome-ignore lint/style/noNonNullAssertion: <explanation>
return (data.news as News[])[0]!
if (errors) {
// handle those errors like a pro
console.error(errors)
throw new Error('Failed to fetch news by slug')
}


console.log(data)
// biome-ignore lint/style/noNonNullAssertion: <explanation>
return (data.news as News[])[0]!
Copy link

Choose a reason for hiding this comment

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

Avoid non-null assertion.

Instead of using non-null assertion, handle the null case properly to avoid potential runtime errors.

-  return (data.news as News[])[0]!
+  if (!data.news || data.news.length === 0) {
+    throw new Error('No news found for the given slug')
+  }
+  return data.news[0] as News
Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.

Suggested change
return (data.news as News[])[0]!
if (!data.news || data.news.length === 0) {
throw new Error('No news found for the given slug')
}
return data.news[0] as News

@tatsutakein tatsutakein merged commit 7c90e49 into main Jul 3, 2024
8 checks passed
@tatsutakein tatsutakein deleted the feature/GH-28 branch July 3, 2024 15:56
This was referenced Jul 3, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

[Feature]: ニュース一覧ページ [Feature]: ニュース詳細ページ
1 participant