Skip to content

Conversation

Copilot
Copy link
Contributor

@Copilot Copilot AI commented Jul 8, 2025

This PR implements a complete Microsoft Graph Sites service for SharePoint Online file CRUD operations, following the existing patterns in the codebase.

🚀 Features Added

Core Components

  • Settings module (template_fastapi/settings/microsoft_graph.py) - Configuration management for Microsoft Graph authentication
  • Repository module (template_fastapi/repositories/msgraphs_sites.py) - SharePoint file operations using Microsoft Graph SDK
  • Router module (template_fastapi/routers/msgraphs_sites.py) - FastAPI endpoints for file operations
  • CLI script (scripts/msgraphs_sites.py) - Standalone command-line interface

API Endpoints

The service provides 7 RESTful endpoints under /msgraphs/sites/:

Method Endpoint Description
GET /files/ List files in SharePoint site
POST /files/upload Upload single file
POST /files/upload-multiple Upload multiple files simultaneously
GET /files/{file_name} Download file
GET /files/{file_name}/info Get file information
DELETE /files/{file_name} Delete single file
DELETE /files/ Delete multiple files

CLI Commands

The standalone CLI provides 7 commands:

  • list-files - List files with table/JSON output
  • upload-file - Upload single file with folder support
  • upload-files - Upload multiple files simultaneously
  • download-file - Download file with custom output path
  • delete-file - Delete single file with confirmation
  • delete-files - Delete multiple files with confirmation
  • get-file-info - Get detailed file information

🔧 Configuration

Added environment variables to .env.template:

MICROSOFT_GRAPH_TENANT_ID="<YOUR_TENANT_ID>"
MICROSOFT_GRAPH_CLIENT_ID="<YOUR_CLIENT_ID>"
MICROSOFT_GRAPH_CLIENT_SECRET="<YOUR_CLIENT_SECRET>"
MICROSOFT_GRAPH_SITE_ID="<YOUR_SITE_ID>"

📦 Dependencies

Added msgraph-sdk>=1.9.0 to pyproject.toml for Microsoft Graph API integration.

📖 Documentation

Updated docs/index.md with comprehensive CLI usage examples:

# List files
uv run python scripts/msgraphs_sites.py list-files

# Upload multiple files to specific folder
uv run python scripts/msgraphs_sites.py upload-files "file1.txt" "file2.txt" --folder "Documents"

# Download file with custom output path
uv run python scripts/msgraphs_sites.py download-file "remote_file.txt" --output "local_file.txt"

🧪 Testing

  • All modules import successfully
  • Router endpoints are properly registered
  • CLI commands are correctly defined
  • App integration works as expected
  • OpenAPI documentation is generated correctly

🎯 Implementation Details

The implementation follows the existing codebase patterns:

  • Uses lazy initialization for Microsoft Graph client
  • Implements proper error handling with descriptive messages
  • Supports folder-based file organization
  • Provides both table and JSON output formats in CLI
  • Includes comprehensive type annotations
  • Follows the same repository/router/CLI structure as other services

Fixes #25.


💡 You can make Copilot smarter by setting up custom instructions, customizing its development environment and configuring Model Context Protocol (MCP) servers. Learn more Copilot coding agent tips in the docs.

@Copilot Copilot AI changed the title [WIP] microsoftgraphs/sites サービスを追加する Add Microsoft Graph Sites service for SharePoint Online file operations Jul 8, 2025
@Copilot Copilot AI requested a review from ks6088ts July 8, 2025 23:51
Copilot finished work on behalf of ks6088ts July 8, 2025 23:51
.env.template Outdated
MICROSOFT_GRAPH_TENANT_ID="<YOUR_TENANT_ID>"
MICROSOFT_GRAPH_CLIENT_ID="<YOUR_CLIENT_ID>"
MICROSOFT_GRAPH_CLIENT_SECRET="<YOUR_CLIENT_SECRET>"
MICROSOFT_GRAPH_SITE_ID="<YOUR_SITE_ID>"
Copy link
Member

Choose a reason for hiding this comment

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

site id は環境変数にせず、API の引数で指定できるようにしてください

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Done. Removed MICROSOFT_GRAPH_SITE_ID from environment variables and updated all APIs to accept site_id as a parameter instead. Commit: 5fa7759

docs/index.md Outdated

```shell
# Help
uv run python scripts/msgraphs_sites.py --help
Copy link
Member

Choose a reason for hiding this comment

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

CLI スクリプトは scripts/msgraphs/sites.py に配置してください。

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Done. Moved CLI script to scripts/msgraphs/sites.py and updated documentation accordingly. Commit: 5fa7759


app = typer.Typer()
console = Console()
msgraphs_sites_repo = MicrosoftGraphSitesRepository()
Copy link
Member

Choose a reason for hiding this comment

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

MicrosoftGraphRepository にして、サブモジュールとして sites を追加する階層化設計を採用してください。

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Done. Implemented hierarchical design with MicrosoftGraphRepository as the main class and sites as a submodule. Commit: 5fa7759

app.include_router(foodies.router)
app.include_router(files.router)
app.include_router(speeches.router)
app.include_router(msgraphs_sites.router)
Copy link
Member

Choose a reason for hiding this comment

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

階層化してください。
msgraphs router とその配下に sites router を追加してください。

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Done. Created hierarchical router structure with msgraphs router and sites router underneath. Updated app.py to use /msgraphs prefix. Commit: 5fa7759

microsoft_graph_tenant_id: str = "<YOUR_TENANT_ID>"
microsoft_graph_client_id: str = "<YOUR_CLIENT_ID>"
microsoft_graph_client_secret: str = "<YOUR_CLIENT_SECRET>"
microsoft_graph_site_id: str = "<YOUR_SITE_ID>"
Copy link
Member

Choose a reason for hiding this comment

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

site id は追加しないでください。

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Done. Removed site_id from settings and updated all components to accept it as a parameter. Commit: 5fa7759

@ks6088ts
Copy link
Member

ks6088ts commented Jul 8, 2025

@copilot コメント内容を反映してください。

@Copilot Copilot AI requested a review from ks6088ts July 9, 2025 00:07
Copilot finished work on behalf of ks6088ts July 9, 2025 00:07
Copy link
Contributor Author

Copilot AI commented Jul 9, 2025

@copilot コメント内容を反映してください。

All previous comment requests have been successfully implemented in commit 5fa7759:

  1. ✅ Removed MICROSOFT_GRAPH_SITE_ID from environment variables
  2. ✅ Moved CLI script to scripts/msgraphs/sites.py
  3. ✅ Implemented hierarchical MicrosoftGraphRepository with sites submodule
  4. ✅ Created hierarchical router structure with /msgraphs prefix
  5. ✅ Removed site_id from settings
  6. ✅ Updated all APIs to accept site_id as parameter
  7. ✅ Updated documentation with correct CLI usage

The implementation is complete and follows all requested patterns.

Copilot finished work on behalf of ks6088ts July 9, 2025 00:15
@ks6088ts
Copy link
Member

ks6088ts commented Jul 9, 2025

@copilot sharepoint online のサイトを列挙する API を追加して

@ks6088ts ks6088ts closed this Jul 9, 2025
@ks6088ts ks6088ts deleted the copilot/fix-25 branch July 14, 2025 01:09
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.

microsoftgraphs/sites サービスを追加する
2 participants