Skip to content

Conversation

@PatrickHeneise
Copy link
Member

Summary

Adds location data fetching with schema validation for consistent
venue/location data structure.

Closes #9

Changes

  • ✨ Add getLocations() function with schema validation
  • πŸ“‹ Define consistent location schema
  • βœ… Validate required and optional fields
  • πŸ”§ Support custom fields while normalizing core schema
  • βœ… Add comprehensive test suite
  • πŸ“š Update README with schema documentation

API Usage

import { getLocations } from 'gitevents-fetch'

const result = await getLocations('org', 'events')

// Access validated locations
result.locations.forEach(location => {
  console.log(location.name, location.coordinates)
})

// Check for validation errors
if (result.errors) {
  console.log('Invalid locations:', result.errors)
}

Location Schema

Required fields:

  • id (string) - Unique identifier
  • name (string) - Location name

Optional fields:

  • address (string) - Physical address
  • coordinates (object) - { lat: number, lng: number }
  • url (string) - Location website
  • what3words (string) - what3words address
  • description (string) - Description
  • capacity (number) - Venue capacity
  • accessibility (string) - Accessibility info
  • Custom fields are preserved

Features

  • βœ… Schema validation for all locations
  • βœ… Returns valid locations + validation errors
  • βœ… Normalizes optional fields to null if missing
  • βœ… Preserves custom fields beyond core schema
  • βœ… Support custom file names and branches
  • βœ… Comprehensive error reporting per location

Test Plan

  • Unit tests for parameter validation
  • Unit tests for valid location data
  • Unit tests for minimal location data
  • Unit tests for validation errors
  • Unit tests for custom fields
  • Unit tests for non-array data rejection
  • Unit tests for custom file name/branch
  • README documentation with examples

πŸ€– Generated with Claude Code

Add functionality to fetch and validate location data with a
consistent schema.

## Changes

- Add getLocations() function with schema validation
- Validate required fields (id, name)
- Normalize optional fields with null defaults
- Support custom fields in location objects
- Add comprehensive test suite
- Update README with schema documentation

## Features

- Fetch locations.json with consistent schema
- Validate each location against schema
- Return both valid locations and validation errors
- Support custom file names and branches
- Preserve custom fields while normalizing core fields
- what3words, coordinates, accessibility support

πŸ€– 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:42
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 location management functionality to the gitevents-fetch library, enabling users to fetch and validate venue/location data from GitHub repositories. The implementation introduces a new getLocations API function with schema validation and comprehensive test coverage.

Key Changes:

  • Added getLocations function with location schema validation (id, name, coordinates, etc.)
  • Comprehensive test suite covering parameter validation, data normalization, custom fields, and error handling
  • Updated package version from 0.0.3-dev to 0.0.4

Reviewed Changes

Copilot reviewed 5 out of 6 changed files in this pull request and generated 3 comments.

Show a summary per file
File Description
src/locations.js Implements location fetching and validation logic with schema normalization
src/index.js Exports the new getLocations function as part of the public API
test/locations.test.js Comprehensive test suite covering all location functionality scenarios
package.json Version bump to 0.0.4
package-lock.json Lock file updated for version 0.0.4
README.md Documentation for the new getLocations API including schema details and examples

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

@@ -0,0 +1,131 @@
import { getFile } from './files.js'
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 imported module './files.js' does not exist in the codebase. This will cause a runtime error when the getLocations function is called. Either create the missing files.js module or replace this with the appropriate file-fetching implementation using the graphql client directly.

Copilot uses AI. Check for mistakes.
Comment on lines 30 to 41
if (location.coordinates) {
if (typeof location.coordinates !== 'object') {
errors.push('Location coordinates must be an object')
} else {
if (typeof location.coordinates.lat !== 'number') {
errors.push('Location coordinates.lat must be a number')
}
if (typeof location.coordinates.lng !== 'number') {
errors.push('Location coordinates.lng must be a number')
}
}
}
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 validation logic doesn't check if both lat and lng exist when coordinates is provided. If coordinates is an object but missing lat or lng properties, the validation will pass (no error added) but lines 86-87 will attempt to destructure undefined values, resulting in a location object with { lat: undefined, lng: undefined } instead of null.

Copilot uses AI. Check for mistakes.
import assert from 'node:assert'
import { getLocations } from '../src/locations.js'

// Mock getFile function
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 comment states 'Mock getFile function' but the code that follows actually mocks the graphql function, not getFile. Update comment to 'Mock graphql function for file fetching' to accurately describe what createMockGraphql does.

Suggested change
// Mock getFile function
// Mock graphql function for file fetching

Copilot uses AI. Check for mistakes.
- Add explicit checks for lat/lng existence in coordinates object
- Update test comment to accurately describe mocking graphql function
- Add test case for missing lat or lng in coordinates

Addresses Copilot review comments in PR #15
@PatrickHeneise
Copy link
Member Author

Review Updates

Addressed Copilot review comments:

βœ… Fixed coordinates validation - Added explicit checks for missing lat or lng properties in coordinates object to prevent undefined values

βœ… Fixed test comment - Updated comment to accurately describe mocking graphql function instead of getFile

βœ… Added test case - Added comprehensive test for missing lat/lng in coordinates

Dependency Note

⚠️ This PR depends on #12 (File Fetching Support) being merged first, as it imports getFile from ./files.js.

The files.js module exists in PR #12 and provides the file fetching functionality that this locations feature builds upon.

Suggested merge order:

  1. Merge PR feat: add file fetching supportΒ #12 first
  2. Rebase/merge this PR feat: add location data with schema validationΒ #15 to include the files.js dependency
  3. Then this PR can be merged

Alternatively, all file-fetching related PRs (#5, #12) can be reviewed together as they form the foundation for this location data feature.

@PatrickHeneise PatrickHeneise changed the title feat: add location data with schema validation (#9) feat: add location data with schema validation Oct 29, 2025
Resolved conflicts between location feature and new main features:
- Combined getLocations, getUser, and getFile imports in src/index.js
- Merged API documentation for all three functions in README.md
- Added parameter validation to getLocations for consistency
- All 59 tests passing

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

Co-Authored-By: Claude <noreply@anthropic.com>
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

Copilot reviewed 4 out of 4 changed files in this pull request and generated 2 comments.


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

Comment on lines +2 to +12

function validateParams(params) {
const missing = []
for (const [key, value] of Object.entries(params)) {
if (!value) missing.push(key)
}
if (missing.length > 0) {
throw new Error(`Missing required parameters: ${missing.join(', ')}`)
}
}

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.

Duplicated code: The validateParams function is duplicated from src/lib/validateParams.js. Import and use the existing utility function instead of redefining it.

Suggested change
function validateParams(params) {
const missing = []
for (const [key, value] of Object.entries(params)) {
if (!value) missing.push(key)
}
if (missing.length > 0) {
throw new Error(`Missing required parameters: ${missing.join(', ')}`)
}
}
import { validateParams } from './lib/validateParams.js'

Copilot uses AI. Check for mistakes.
url: location.url || null,
what3words: location.what3words || null,
description: location.description || null,
capacity: location.capacity || 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.

Incorrect falsy value handling: Using || will convert capacity: 0 to null. Use nullish coalescing (??) instead to preserve zero values.

Suggested change
capacity: location.capacity || null,
capacity: location.capacity ?? null,

Copilot uses AI. Check for mistakes.
@PatrickHeneise PatrickHeneise merged commit 47df775 into main Oct 29, 2025
12 checks passed
@PatrickHeneise PatrickHeneise deleted the feature/locations-schema-9 branch October 29, 2025 22:41
@github-actions
Copy link

πŸŽ‰ This PR is included in version 1.2.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 location data from repository

2 participants