[[["易于理解","easyToUnderstand","thumb-up"],["解决了我的问题","solvedMyProblem","thumb-up"],["其他","otherUp","thumb-up"]],[["很难理解","hardToUnderstand","thumb-down"],["信息或示例代码不正确","incorrectInformationOrSampleCode","thumb-down"],["没有我需要的信息/示例","missingTheInformationSamplesINeed","thumb-down"],["翻译问题","translationIssue","thumb-down"],["其他","otherDown","thumb-down"]],["最后更新时间 (UTC):2025-09-04。"],[],[],null,["# Notifications for Cloud Source Repositories\n\nCloud Source Repositories publishes messages about your repository to named resources\ncalled topics. Apps subscribed to Pub/Sub topics can receive these\nmessages. For example, when your repository state changes, you can receive an\nalert. Additionally, you can configure roles and permissions for your\nPub/Sub topics to control how users interact with the\nPub/Sub events that your repository generates.\n\nThis page provides an overview of Pub/Sub notifications for\nCloud Source Repositories. To learn how to set up and use Pub/Sub\nnotifications, see\n[Configuring Pub/Sub notifications](/source-repositories/docs/configuring-notifications).\n\nScope\n-----\n\nYou can configure Cloud Source Repositories to publish events to a\nPub/Sub topic. You can set the scope of this configuration to be\nyour entire Google Cloud project or an individual\nrepository.\n\nAfter it is configured, Cloud Source Repositories publishes messages to the\nspecified Pub/Sub topic using your service account. You must first\ngive the service account permissions to publish to the topic. If you\nhave audit logging enabled for Pub/Sub, this service account is\nshown as the caller of the Pub/Sub APIs.\n\nPermissions\n-----------\n\nConfiguring Cloud Source Repositories to publish messages requires the following:\n\n- A project or a repository that is watched for events. If a project is specified, all repositories under that project are watched.\n- A Pub/Sub topic that Cloud Source Repositories publishes messages to.\n- A service account to access the Pub/Sub topic.\n- A message format (such as JSON or Protocol Buffers).\n\nWhen you configure Cloud Source Repositories for Pub/Sub, you must\nhave these permissions:\n\n- `source.repos.updateRepo` on the specified repository or `source.repos.updateProjectConfig` on the specified project\n- `iam.serviceAccounts.actAs` on the specified service account\n\nAfter the Pub/Sub topic is registered, the specified service\naccount must have `pubsub.topics.publish` permission to publish a message.\n\nEvent types\n-----------\n\nPub/Sub can notify you when a user creates a repository, deletes a\nrepository, or pushes a commit to a repository. Each event is a specific event\ntype. The following table lists the types and their corresponding\ndefinitions.\n\nNotification format\n-------------------\n\nYou can configure Pub/Sub to use one of two formats for\nnotifications:\n\n- JSON\n- Protocol Buffers\n\nNotification data\n-----------------\n\nEach Pub/Sub notification contains the following information about\nan event:\n\nIf the notification is for a `git push` command, the notification containing the\n`refUpdateEvent` field contains the following information:\n\n| **Note:** If mirroring repositories to Cloud Source Repositories, the email address in Pub/Sub notifications always appears as `gerritcodereview@google.com`.\n\nThe `refUpdates` field contains the following details about the `git push`\ncommand:\n\nUpdate types\n------------\n\nA `git push` event can have one of four update types. You can find the type in\nthe `updateType` field of the notification.\n\nNotification example\n--------------------\n\nThe following is an example of the data contained in a Pub/Sub\nnotification. This notification uses the JSON format. \n\n {\n \"name\": \"projects/test-project/repos/pubsub-test\",\n \"url\": \"[URL_PATH]\",\n \"eventTime\": \"2018-02-21T21:23:25.566175Z\",\n \"refUpdateEvent\": {\n \"email\": \"someone@somecompany.com\",\n \"refUpdates\": {\n \"refs/heads/master\": {\n \"refName\": \"refs/heads/master\",\n \"updateType\": \"UPDATE_FAST_FORWARD\",\n \"oldId\": \"c7a28dd5de3403cc384a025834c9fce2886fe763\",\n \"newId\": \"f00768887da8de62061210295914a0a8a2a38226\"\n }\n }\n }\n }\n\nCross-project setup example\n---------------------------\n\nYou can configure Cloud Source Repositories to publish a message to a topic in a\ndifferent project. In this case, you must create a service account\nin the same project where your repository resides. In the project that contains\nthe Pub/Sub topic, give the role `roles/pubsub.publisher` to this\nservice account. When you configure Cloud Source Repositories with this account and\nthis Pub/Sub topic, the event messages for your repository\nappear in the topic in the other project."]]