Skip to content

feat(pubsub): Add pubsub_rollback_schema sample#1816

Closed
torreypayne wants to merge 1 commit into
GoogleCloudPlatform:mainfrom
torreypayne:add-pubsub-rollback-schema
Closed

feat(pubsub): Add pubsub_rollback_schema sample#1816
torreypayne wants to merge 1 commit into
GoogleCloudPlatform:mainfrom
torreypayne:add-pubsub-rollback-schema

Conversation

@torreypayne
Copy link
Copy Markdown
Member

Description

Fixes #

Note: It's a good idea to open an issue first for discussion.

Checklist

  • Tests pass
  • Lint pass: bundle exec rubocop
  • Please merge this PR for me once it is approved.

@torreypayne torreypayne requested review from a team as code owners June 3, 2026 07:05
@snippet-bot
Copy link
Copy Markdown

snippet-bot Bot commented Jun 3, 2026

Here is the summary of changes.

You are about to add 1 region tag.

This comment is generated by snippet-bot.
If you find problems with this result, please file an issue at:
https://github.com/googleapis/repo-automation-bots/issues.
To update this comment, add snippet-bot:force-run label or use the checkbox below:

  • Refresh this comment

@product-auto-label product-auto-label Bot added api: pubsub Issues related to the Pub/Sub API. samples Issues that are directly related to samples. labels Jun 3, 2026
@torreypayne torreypayne closed this Jun 3, 2026
Copy link
Copy Markdown

@gemini-code-assist gemini-code-assist Bot left a comment

Choose a reason for hiding this comment

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

Code Review

This pull request introduces a new feature to roll back a Google Cloud Pub/Sub schema to a previous revision, including a Gemfile, the implementation in rollback_schema.rb, and corresponding RSpec tests. The feedback suggests minor improvements: adding parentheses to the method definition to comply with Ruby style guidelines, using the client's built-in schema_path helper instead of manual string interpolation, and correcting the Protobuf syntax definition in the tests to use double quotes as strictly required by the Protocol Buffers specification.

Comment thread pubsub/rollback_schema.rb
# [START pubsub_rollback_schema]
require "google/cloud/pubsub"

def rollback_schema project_id:, schema_id:, revision_id:
Copy link
Copy Markdown

Choose a reason for hiding this comment

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

medium

According to the community Ruby Style Guide, parentheses should be used for method definitions that have arguments. Adding parentheses also ensures that the code complies with standard RuboCop rules (such as Style/MethodDefParentheses), which is important since the PR checklist includes a RuboCop lint pass.

def rollback_schema(project_id:, schema_id:, revision_id:)
References
  1. Use parentheses for method definitions when they have arguments. (link)

Comment thread pubsub/rollback_schema.rb
pubsub = Google::Cloud::PubSub.new project_id: project_id
schema_client = pubsub.schema_service_client

schema_path = "projects/#{project_id}/schemas/#{schema_id}"
Copy link
Copy Markdown

Choose a reason for hiding this comment

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

medium

Instead of manually constructing the schema resource path using string interpolation, it is more robust and idiomatic to use the path helper method schema_path provided by the GAPIC client. This prevents potential errors in path formatting.

  schema_path = schema_client.schema_path project: project_id, schema: schema_id

@schema_path = "projects/#{@project_id}/schemas/#{@schema_id}"

# Create schema (Revision 1)
@definition_1 = "syntax = 'proto3'; message Message { string data = 1; }"
Copy link
Copy Markdown

Choose a reason for hiding this comment

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

medium

Protocol Buffers specification strictly requires double quotes for the syntax statement (i.e., syntax = "proto3";). While some parsers might be lenient, using single quotes ('proto3') can lead to parsing errors in strict environments or future updates. It is safer and more standard to use single quotes for the Ruby string literal and double quotes for the protobuf definition.

    @definition_1 = 'syntax = "proto3"; message Message { string data = 1; }'

@revision_1_id = @initial_schema.revision_id

# Commit revision (Revision 2)
@definition_2 = "syntax = 'proto3'; message Message { string data = 1; string new_field = 2; }"
Copy link
Copy Markdown

Choose a reason for hiding this comment

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

medium

Protocol Buffers specification strictly requires double quotes for the syntax statement (i.e., syntax = "proto3";). It is safer and more standard to use single quotes for the Ruby string literal and double quotes for the protobuf definition.

    @definition_2 = 'syntax = "proto3"; message Message { string data = 1; string new_field = 2; }'

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

api: pubsub Issues related to the Pub/Sub API. samples Issues that are directly related to samples.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant