Skip to content

Commit 58a730f

Browse files
Merge pull request #442 from Leandro3996/fix/appscript-get-content-endpoint
fix: use getContent() instead of get() for Apps Script file retrieval
2 parents 53de232 + 9bd3bed commit 58a730f

2 files changed

Lines changed: 19 additions & 8 deletions

File tree

gappsscript/apps_script_tools.py

Lines changed: 9 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -105,8 +105,10 @@ async def _get_script_project_impl(
105105
"""Internal implementation for get_script_project."""
106106
logger.info(f"[get_script_project] Email: {user_google_email}, ID: {script_id}")
107107

108-
project = await asyncio.to_thread(
109-
service.projects().get(scriptId=script_id).execute
108+
# Get project metadata and content concurrently (independent requests)
109+
project, content = await asyncio.gather(
110+
asyncio.to_thread(service.projects().get(scriptId=script_id).execute),
111+
asyncio.to_thread(service.projects().getContent(scriptId=script_id).execute),
110112
)
111113

112114
title = project.get("title", "Untitled")
@@ -124,7 +126,7 @@ async def _get_script_project_impl(
124126
"Files:",
125127
]
126128

127-
files = project.get("files", [])
129+
files = content.get("files", [])
128130
for i, file in enumerate(files, 1):
129131
file_name = file.get("name", "Untitled")
130132
file_type = file.get("type", "Unknown")
@@ -172,11 +174,12 @@ async def _get_script_content_impl(
172174
f"[get_script_content] Email: {user_google_email}, ID: {script_id}, File: {file_name}"
173175
)
174176

175-
project = await asyncio.to_thread(
176-
service.projects().get(scriptId=script_id).execute
177+
# Must use getContent() to retrieve files, not get() which only returns metadata
178+
content = await asyncio.to_thread(
179+
service.projects().getContent(scriptId=script_id).execute
177180
)
178181

179-
files = project.get("files", [])
182+
files = content.get("files", [])
180183
target_file = None
181184

182185
for file in files:

tests/gappsscript/test_apps_script_tools.py

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -62,12 +62,19 @@ async def test_list_script_projects():
6262
async def test_get_script_project():
6363
"""Test retrieving complete project details"""
6464
mock_service = Mock()
65-
mock_response = {
65+
66+
# projects().get() returns metadata only (no files)
67+
mock_metadata_response = {
6668
"scriptId": "test123",
6769
"title": "Test Project",
6870
"creator": {"email": "creator@example.com"},
6971
"createTime": "2025-01-10T10:00:00Z",
7072
"updateTime": "2026-01-12T15:30:00Z",
73+
}
74+
75+
# projects().getContent() returns files with source code
76+
mock_content_response = {
77+
"scriptId": "test123",
7178
"files": [
7279
{
7380
"name": "Code",
@@ -77,7 +84,8 @@ async def test_get_script_project():
7784
],
7885
}
7986

80-
mock_service.projects().get().execute.return_value = mock_response
87+
mock_service.projects().get().execute.return_value = mock_metadata_response
88+
mock_service.projects().getContent().execute.return_value = mock_content_response
8189

8290
result = await _get_script_project_impl(
8391
service=mock_service, user_google_email="test@example.com", script_id="test123"

0 commit comments

Comments
 (0)