Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
61 changes: 61 additions & 0 deletions flake.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

6 changes: 6 additions & 0 deletions gcalcli/argparsers.py
Original file line number Diff line number Diff line change
Expand Up @@ -609,6 +609,12 @@ def get_argument_parser():
'from lavender, sage, grape, flamingo, banana, tangerine, '
'peacock, graphite, blueberry, basil, tomato.',
)
add.add_argument(
'--availability',
default='busy',
choices=['free', 'busy'],
help='Event availability (free/busy status). Default is busy.',
)
Comment on lines +612 to +617
Copy link
Copy Markdown

Choose a reason for hiding this comment

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

kody code-review Bug high

The code uses user-friendly values ('free', 'busy') instead of the Google Calendar API's required values ('transparent', 'opaque') for the event availability/transparency field. This mismatch causes API errors and prevents the feature from working correctly.

This issue appears in multiple locations:

  • gcalcli/argparsers.py: Lines 612-617
  • gcalcli/details.py: Lines 359-367
    Please ensure all code handling event availability translates between user-facing terms ('free'/'busy') and API-required values ('transparent'/'opaque') consistently across the codebase.
    add.add_argument(
        '--availability',
        dest='transparency',
        default='opaque',
        choices=['transparent', 'opaque'],
        help='Event availability. Use "transparent" for free, "opaque" for busy. Default is opaque.',
    )
Prompt for LLM

File gcalcli/argparsers.py:

Line 612 to 617:

The provided Python code adds a new command-line argument `--availability` to a tool that interacts with the Google Calendar API. The argument is intended to control the event's 'transparency' property, which makes an event appear as 'Free' or 'Busy' on the calendar.

The current implementation defines the choices for this argument as 'free' and 'busy'. However, the Google Calendar API's `transparency` field requires the literal string values 'transparent' or 'opaque'.

The code is missing a step to translate the user-friendly values ('free', 'busy') into the API-required values ('transparent', 'opaque'). This will cause API errors when the feature is used.

Please refactor the `add_argument` call to fix this issue. The most direct solution is to use the API-compliant values directly. You should also update the `dest` parameter to 'transparency' to match the API field name, change the `default` value to its API equivalent, and update the `help` text to guide the user correctly.

Suggested Code:

    add.add_argument(
        '--availability',
        dest='transparency',
        default='opaque',
        choices=['transparent', 'opaque'],
        help='Event availability. Use "transparent" for free, "opaque" for busy. Default is opaque.',
    )

Talk to Kody by mentioning @kody

Was this suggestion helpful? React with 👍 or 👎 to help Kody learn from this interaction.

add.add_argument('--title', default=None, type=str, help='Event title')
add.add_argument(
'--who',
Expand Down
3 changes: 2 additions & 1 deletion gcalcli/cli.py
Original file line number Diff line number Diff line change
Expand Up @@ -304,7 +304,8 @@ def main():

gcal.AddEvent(parsed_args.title, parsed_args.where, estart, eend,
parsed_args.description, parsed_args.who,
parsed_args.reminders, parsed_args.event_color)
parsed_args.reminders, parsed_args.event_color,
parsed_args.availability)

elif parsed_args.command == 'search':
gcal.TextQuery(
Expand Down
12 changes: 12 additions & 0 deletions gcalcli/details.py
Original file line number Diff line number Diff line change
Expand Up @@ -356,6 +356,17 @@ class ID(SimpleSingleFieldHandler):
fieldnames = ['id']


class Availability(SimpleSingleFieldHandler):
"""Handler for event availability (free/busy)."""

fieldnames = ['transparency']

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


class Action(SingleFieldHandler):
"""Handler specifying event processing during an update."""

Expand All @@ -377,6 +388,7 @@ def _get(cls, event):
('calendar', Calendar),
('email', Email),
('attendees', Attendees),
('availability', Availability),
('action', Action)])
HANDLERS_READONLY = {Url, Calendar}

Expand Down
4 changes: 3 additions & 1 deletion gcalcli/gcal.py
Original file line number Diff line number Diff line change
Expand Up @@ -1464,12 +1464,14 @@ def QuickAddEvent(self, event_text, reminders=None):

return new_event

def AddEvent(self, title, where, start, end, descr, who, reminders, color):
def AddEvent(self, title, where, start, end, descr, who, reminders, color,
availability='busy'):

calendar = self._prompt_for_calendar(self.cals)

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

if self.options['allday']:
event['start'] = {'date': start}
Expand Down
20 changes: 20 additions & 0 deletions tests/test_gcalcli.py
Original file line number Diff line number Diff line change
Expand Up @@ -393,3 +393,23 @@ def test_next_cut(PatchedGCalI):

event_title = "樹貞 fun fun fun"
assert gcal._next_cut(event_title) == (8, 6)

def test_add_event_availability(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='transparent event',
where='anywhere',
start='now',
end='tomorrow',
descr='testing',
who='anyone',
reminders=None,
color='banana',
availability='free')
Comment on lines +399 to +409
Copy link
Copy Markdown

Choose a reason for hiding this comment

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

kody code-review Bug high

The test passes the availability option as a keyword argument to the AddEvent method. However, command-line options are typically used to initialize the GCalI object's state via its constructor. The AddEvent method would then read this state from self.options.availability rather than accepting it as a direct parameter.

This approach tests a method signature that likely differs from the production code, which will cause the test to fail with a TypeError: AddEvent() got an unexpected keyword argument 'availability' before the actual logic can be verified. The availability option should be passed to the PatchedGCalI constructor to correctly simulate the application's behavior.

    gcal = PatchedGCalI(
            cal_names=cal_names, allday=False, default_reminders=True,
            availability='free')
    assert gcal.AddEvent(title='transparent event',
                         where='anywhere',
                         start='now',
                         end='tomorrow',
                         descr='testing',
                         who='anyone',
                         reminders=None,
                         color='banana')
Prompt for LLM

File tests/test_gcalcli.py:

Line 399 to 409:

The provided Python test case is flawed. It attempts to test a new 'availability' feature by passing `availability='free'` as a keyword argument directly to the `AddEvent` method. However, in this command-line application, options like this are typically passed to the main class's constructor to set its internal state (e.g., `self.options`). The `AddEvent` method would then read the availability from this internal state, not from a direct method argument. Because the test calls the method with an unexpected keyword argument, it will raise a `TypeError` and crash before it can verify the feature's logic. Please refactor the test to pass the `availability` option to the `PatchedGCalI` constructor instead of the `AddEvent` method call, which will correctly simulate the application's behavior and allow the test to validate the implementation.

Suggested Code:

    gcal = PatchedGCalI(
            cal_names=cal_names, allday=False, default_reminders=True,
            availability='free')
    assert gcal.AddEvent(title='transparent event',
                         where='anywhere',
                         start='now',
                         end='tomorrow',
                         descr='testing',
                         who='anyone',
                         reminders=None,
                         color='banana')

Talk to Kody by mentioning @kody

Was this suggestion helpful? React with 👍 or 👎 to help Kody learn from this interaction.


gcal.api_tracker.verify_all_mutating_calls([
CallMatcher('insert',
body_has_fields={'summary', 'start', 'end', 'transparency'},
body_fields={'transparency': 'transparent'})
])