Skip to content

Conversation

@PatrickHeneise
Copy link
Member

Summary

Adds support for fetching GitHub Discussions with optional category filtering.

Closes #4

Changes

  • ✨ Add discussions() function to main API
  • πŸ“ Add GraphQL query for discussions with category support
  • βœ… Add comprehensive test suite (unit tests + integration test)
  • πŸ“š Update README with API documentation and examples
  • πŸ”§ Update parseGql to include discussions query

API Usage

import { discussions } from 'gitevents-fetch'

// Fetch all discussions
const allDiscussions = await discussions('org', 'repo', { first: 20 })

// Filter by category ID
const announcements = await discussions('org', 'repo', {
  categoryId: 'DIC_kwDOG41Ukc4CBSDX',
  first: 10
})

Features

  • βœ… Category filtering by category ID
  • βœ… Pagination support
  • βœ… Null-safe processing (handles missing authors, categories)
  • βœ… Includes reactions and comment counts
  • βœ… Parses timestamps as Date objects
  • βœ… Follows same patterns as existing event APIs

Discussion Object Structure

{
  id: string
  number: number
  title: string
  url: string
  body: string | null
  createdAt: Date | null
  updatedAt: Date | null
  author: { login, name, avatarUrl, url } | null
  category: { id, name, emoji, description } | null
  reactions: string[]
  commentCount: number
}

Test Plan

  • Unit tests for parameter validation
  • Unit tests for response processing
  • Unit tests for edge cases (missing fields, empty results)
  • Unit tests for GraphQL error handling
  • Integration test with real API (auto-skips without credentials)
  • README documentation updated
  • API exported from main index

Notes

This implementation follows the same patterns as the existing events and teams APIs for consistency. The test infrastructure has a pre-existing issue with .gql?raw imports not working in Node.js test runner (present before this PR), but the feature code is production-ready.

πŸ€– Generated with Claude Code

Add functionality to fetch discussions from GitHub Discussions with optional category filtering.

## Changes

- Add `discussions()` function to fetch discussions from a repository
- Add GraphQL query for discussions with category filtering support
- Add comprehensive test suite for discussions feature
- Update README with API documentation and examples
- Export new discussions function from main index

## API

```javascript
import { discussions } from 'gitevents-fetch'

// Fetch all discussions
const allDiscussions = await discussions('org', 'repo', { first: 20 })

// Filter by category
const announcements = await discussions('org', 'repo', {
  categoryId: 'DIC_kwDOG41Ukc4CBSDX'
})
```

## Features

- Category filtering support
- Pagination support
- Null-safe processing of discussions, authors, and categories
- Includes reactions and comment counts
- Parses dates as Date objects

πŸ€– Generated with [Claude Code](https://claude.com/claude-code)

Co-Authored-By: Claude <noreply@anthropic.com>
Copilot AI review requested due to automatic review settings October 29, 2025 16:12
Copy link
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull Request Overview

This PR adds support for fetching GitHub Discussions from repositories, expanding the library's capabilities beyond events and teams. The version is bumped from 0.0.3-dev to 0.0.4.

  • Implements a new discussions() API to fetch repository discussions with optional filtering by category
  • Adds comprehensive test coverage including unit tests and integration tests
  • Updates documentation with usage examples and API structure

Reviewed Changes

Copilot reviewed 8 out of 9 changed files in this pull request and generated 1 comment.

Show a summary per file
File Description
src/discussions.js New module implementing listDiscussions() function with parameter validation and payload processing
src/graphql/discussions.gql GraphQL query for fetching discussions with full metadata (author, category, reactions, comments)
src/index.js Exports new discussions() function that wraps listDiscussions() with authenticated GraphQL client
src/lib/parseGql.js Registers the discussions GraphQL query for dynamic loading
test/discussions.test.js Comprehensive test suite covering validation, data processing, error handling, and real API integration
test/fetch.test.js Adds export validation test for the new discussions() function
package.json Version bump to 0.0.4
package-lock.json Updates version references to 0.0.4
README.md Documents the new discussions() API with parameters, examples, and return type structure

πŸ’‘ Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment on lines 22 to 25
id: node.id || null,
number: node.number || null,
title: node.title || null,
url: node.url || null,
Copy link

Copilot AI Oct 29, 2025

Choose a reason for hiding this comment

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

The fallback to null is redundant for fields that are expected to always be present in GraphQL responses (id, number, title, url). According to the GraphQL schema, these are required fields. Consider removing the || null fallback for these fields to avoid masking potential data integrity issues, similar to how the existing events.js and teams.js handle required fields.

Suggested change
id: node.id || null,
number: node.number || null,
title: node.title || null,
url: node.url || null,
id: node.id,
number: node.number,
title: node.title,
url: node.url,

Copilot uses AI. Check for mistakes.
@PatrickHeneise PatrickHeneise changed the title feat: add GitHub Discussions support (#4) feat: add GitHub Discussions support Oct 29, 2025
- Remove redundant null fallbacks for required GraphQL fields (id, number, title, url)
- Remove redundant null fallbacks for required nested fields (login, avatarUrl, url in author)
- Remove redundant null fallbacks for required nested fields (id, name, emoji in category)
- Update discussions() to use getGraphqlClient() pattern for consistency
- Add parameter validation for discussions function
- Merge main branch changes (organization, locations, users, files features)
- All tests passing (72/72)
- ESLint passing with no errors

Resolves code review comment from Copilot about redundant null fallbacks.

πŸ€– Generated with [Claude Code](https://claude.com/claude-code)

Co-Authored-By: Claude <noreply@anthropic.com>
@PatrickHeneise PatrickHeneise merged commit b21381d into main Oct 29, 2025
6 checks passed
@PatrickHeneise PatrickHeneise deleted the feature/github-discussions-4 branch October 29, 2025 23:08
@github-actions
Copy link

πŸŽ‰ This PR is included in version 1.4.0 πŸŽ‰

The release is available on:

Your semantic-release bot πŸ“¦πŸš€

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Add support for fetching GitHub Discussions

2 participants