Skip to content

feat(helpers): add forms +responses - #997

Open
hallelx2 wants to merge 2 commits into
googleworkspace:mainfrom
hallelx2:feat/forms-responses
Open

hallelx2 wants to merge 2 commits into
googleworkspace:mainfrom
hallelx2:feat/forms-responses

Conversation

@hallelx2

Copy link
Copy Markdown

Description

Adds forms +responses: a form's responses as one row each, with the question titles as column headers. The raw forms.responses.list output is keyed by question id, so reading it means a second forms.get and a join by hand.

gws forms +responses 1AbC…xyz                       # or the form's edit URL
gws forms +responses FORM_URL --since 2026-11-01 --format csv > responses.csv
  • Columns: submitted, then each question in form order, then email and score when the form collects them, then response_id.
  • Grid questions become one column per row (Title [row]). Several answers join with ; . Uploaded files show as file name plus Drive link. Headers that repeat, or clash with the fixed columns, get a numeric suffix.
  • --since takes a date (local midnight) or an RFC 3339 time and becomes the API's timestamp >= … filter.
  • Responses are paged (5,000 per page) and sorted by submit time. An empty result prints a clear "no responses" line.
  • Default output is a table; --format csv|json|yaml work as usual.

Input validation (AGENTS.md checklist)

  • The form argument accepts an id or a docs.google.com/forms/d/<id>/edit URL; the id must be URL-safe characters only. The public /forms/d/e/… link (a different id that the API rejects) is refused with a hint to use the edit URL.
  • The id goes into the path through encode_path_segment; the filter through .query().

Shared base commit. The first commit, feat(formatter): ordered report rendering and direct-call JSON fetch (1ab84c5), is shared by this PR and its siblings (Search Console/Analytics reports, YouTube, Forms, Calendar). It adds:

  • formatter::render_report: prints rows in a fixed column order (serde_json has no preserve_order here, so format_value sorts keys), with a title line, and a clear note instead of an empty table. CSV keeps its header and sends the note to stderr; JSON/YAML carry columns, count, rows and a note.
  • executor::fetch_json / api_error: one direct API call with the existing send_with_retry, mapping errors through handle_error_response so helpers keep the structured GwsError::Api shape.
    Whichever of these PRs merges first brings it in; the others then rebase cleanly.

Testing

  • 8 new unit tests: id and URL parsing, --since parsing, column building (grid rows, duplicate titles, reserved names), answer text (multiple answers, files) and row assembly.
  • Live: a form with 8 responses, including a grid question, printed as a table, as CSV and with --since.
  • cargo fmt --check is clean. cargo test: all pass except the two ADC tests that also fail on main on machines with gcloud ADC configured.
  • Skills regenerated for the new helper (skills/gws-forms-responses, docs/skills.md).

Dry Run Output: not applicable; the helper only reads (forms.get, forms.responses.list).

Invariant review

  • The responses loop pages through forms.responses.list, capped at 200 pages of 5,000. Safe by construction.
  • Read-only. No state writes, retries with side effects or secrets.

Checklist:

  • My code follows the AGENTS.md guidelines (no generated google-* crates).
  • I have run cargo fmt --all to format the code perfectly.
  • I have run cargo clippy -- -D warnings and resolved all warnings (none new; main already fails a few lints on rustc 1.99).
  • I have added tests that prove my fix is effective or that my feature works.
  • I have provided a Changeset file (e.g. via pnpx changeset) to document my changes.

Helpers that build reports (Search Console, Analytics, Forms responses,
calendar free slots) need columns in a fixed order: the dimension first,
or a form's questions in form order. serde_json objects sort their keys,
so format_value cannot keep that order. render_report keeps it for
table and CSV, wraps rows in an envelope for JSON and YAML, and prints a
clear note instead of an empty table when there are no rows.

fetch_json and api_error let a helper call an API directly with the same
retry and Google error parsing that execute_method uses.
forms responses list returns answers keyed by opaque question IDs,
so reading results meant joining them to the form's items by hand.
forms +responses does the join: one row per response, oldest first,
with submitted time, respondent email and quiz score when present,
then one column per question titled as in the form. A grid question
gives one column per row ('Question [row]'), several answers to one
question are joined with '; ', file uploads show their name and Drive
link, and duplicate titles are made unique so CSV headers are too.

It takes a form ID or edit URL (a public /forms/d/e/ link is refused
with an explanation), and --since a date (local midnight) or RFC 3339
time, sent as the API's timestamp filter. All pages are fetched.
@changeset-bot

changeset-bot Bot commented Nov 23, 2026

Copy link
Copy Markdown

🦋 Changeset detected

Latest commit: 4a83caf

The changes in this PR will be included in the next version bump.

This PR includes changesets to release 1 package
Name Type
@googleworkspace/cli Minor

Not sure what this means? Click here to learn what changesets are.

Click here if you're a maintainer who wants to add another changeset to this PR

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.

1 participant