Skip to content

feat: add --availability flag for event transparency (free/busy)#5

Merged
snomiao merged 2 commits into
mainfrom
feat/availability-flag
Feb 17, 2026
Merged

feat: add --availability flag for event transparency (free/busy)#5
snomiao merged 2 commits into
mainfrom
feat/availability-flag

Conversation

@snomiao
Copy link
Copy Markdown
Owner

@snomiao snomiao commented Feb 17, 2026

Ported from insanum/gcalcli#868 by @Aurelian-Shuttleworth.

Summary

  • Adds --availability free|busy flag to the add command (default: busy)
  • Maps to Google Calendar API transparency field (transparent/opaque)
  • Adds Availability detail handler in details.py for display
  • Includes tests verifying transparency field is set correctly

Why

Enables creating "ghost block" events that are visible on the calendar for planning purposes but do not block scheduling availability.

🤖 Generated with Claude Code

- Add Transparency handler to details.py
- Add --transparency flag to argparsers.py
- Update CLI wiring to pass transparency arg
- Add regression test
- Rename CLI flag to --availability
- Update choices to free/busy
- Map free->transparent and busy->opaque in gcal.py
- Rename Transparency handler to Availability and update display logic
- Update tests
Copilot AI review requested due to automatic review settings February 17, 2026 11:14
Copy link
Copy Markdown

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

Adds an --availability free|busy option to the add command to control whether newly created events block free/busy time, mapping to the Google Calendar API transparency field.

Changes:

  • Add --availability CLI flag (default busy) and pass it through to event creation.
  • Set event['transparency'] when creating events and add a details handler intended to display availability.
  • Add a test asserting availability=free produces transparency=transparent.
  • Introduce a new flake.lock file.

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
tests/test_gcalcli.py Adds a unit test for availability=free mapping to transparent.
gcalcli/gcal.py Extends AddEvent to accept availability and set transparency.
gcalcli/details.py Adds an Availability detail handler and registers it in the handler list.
gcalcli/cli.py Passes parsed_args.availability into AddEvent.
gcalcli/argparsers.py Adds --availability argument to the add subcommand parser.
flake.lock Adds a Nix flake lockfile (no matching flake.nix in repo).

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment thread gcalcli/details.py
Comment on lines +362 to +369
fieldnames = ['transparency']

@classmethod
def _get(cls, event):
val = event.get(cls.fieldnames[0], 'opaque')
return 'free' if val == 'transparent' else 'busy'


Copy link

Copilot AI Feb 17, 2026

Choose a reason for hiding this comment

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

Availability is currently using fieldnames = ['transparency'], which makes TSV output label the column as transparency even though values are free/busy. It also makes agendaupdate patch/insert treat the input field as transparency and the inherited _patch will set the event's transparency to free/busy (invalid for the Google API). Suggest using fieldnames = ['availability'] and overriding _patch to map free|busy to transparent|opaque (and keeping _get reading from event.get('transparency', 'opaque')).

Suggested change
fieldnames = ['transparency']
@classmethod
def _get(cls, event):
val = event.get(cls.fieldnames[0], 'opaque')
return 'free' if val == 'transparent' else 'busy'
fieldnames = ['availability']
@classmethod
def _get(cls, event):
# Read the underlying Google API transparency value and map it
# to a user-facing availability value.
val = event.get('transparency', 'opaque')
return 'free' if val == 'transparent' else 'busy'
@classmethod
def _patch(cls, event, value):
"""Map user-facing availability (free/busy) to API transparency."""
if value == 'free':
event['transparency'] = 'transparent'
elif value == 'busy':
event['transparency'] = 'opaque'
else:
raise ReadonlyError('availability',
f"invalid availability value: {value}")

Copilot uses AI. Check for mistakes.
Comment thread gcalcli/gcal.py

event = {}
event['summary'] = title
event['transparency'] = 'transparent' if availability == 'free' else 'opaque'
Copy link

Copilot AI Feb 17, 2026

Choose a reason for hiding this comment

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

This line exceeds the configured Ruff line-length (80) and will likely fail formatting/linting. Consider wrapping it over multiple lines (or using an explicit mapping/dict) to keep within the project's line-length limit.

Suggested change
event['transparency'] = 'transparent' if availability == 'free' else 'opaque'
if availability == 'free':
event['transparency'] = 'transparent'
else:
event['transparency'] = 'opaque'

Copilot uses AI. Check for mistakes.
Comment thread tests/test_gcalcli.py
CallMatcher('insert',
body_has_fields={'summary', 'start', 'end', 'transparency'},
body_fields={'transparency': 'transparent'})
])
Copy link

Copilot AI Feb 17, 2026

Choose a reason for hiding this comment

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

The new availability behavior is only tested for the free -> transparent branch. Since the code also sets opaque for the default/busy case (and always includes the transparency field), consider adding an assertion/test covering availability='busy' (or omitting the arg) to prevent regressions in the default behavior.

Suggested change
])
])
def test_add_event_availability_busy(PatchedGCalI):
cal_names = parse_cal_names(['jcrowgey@uw.edu'], printer=None)
gcal = PatchedGCalI(
cal_names=cal_names, allday=False, default_reminders=True)
assert gcal.AddEvent(title='opaque event',
where='anywhere',
start='now',
end='tomorrow',
descr='testing',
who='anyone',
reminders=None,
color='banana')
gcal.api_tracker.verify_all_mutating_calls([
CallMatcher('insert',
body_has_fields={'summary', 'start', 'end', 'transparency'},
body_fields={'transparency': 'opaque'})
])

Copilot uses AI. Check for mistakes.
@snomiao snomiao merged commit f6ef688 into main Feb 17, 2026
6 checks passed
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.

3 participants