The bitbucket:mergeCheck
module defines a custom merge check that runs in the context of a pull request. The module
allows a Forge app to define checks that can prevent pull requests from merging in Bitbucket until the specified conditions have been met.
The bitbucket:mergeCheck
module is conceptually similar to the
Forge trigger module in that the Forge infrastructure will invoke
the module only when the subscribed event occurs. A key difference is that bitbucket:mergeCheck
is
triggered by granular, merge check specific, pull request focused events, as opposed to more general
Product events.
Another key difference is that the bitbucket:mergeCheck
module must return a response payload
that indicates whether the check has passed or failed.
Each module will be treated as its own check and have independent results. A check must pass for a pull request to be merged if it is configured to be Required in Repository Settings. If the check is configured to be Recommended, then it is informational only and will not block pull request merge. The check results are rendered on the pull request page, which will help to guide the user towards the changes needed for the check to pass.
Once a Forge app with a bitbucket:mergeCheck
module has been installed into a Bitbucket workspace, the
workspace admin must enable the Custom merge checks
feature in the workspace settings before they can be used.
After this, a repository admin should enable the checks they'd like to run in the repository settings for each repository they wish to utilize the check, and for each enabled checks, whether it should be Required or Recommended.
Property | Type | Required | Description |
---|---|---|---|
key | string | Yes |
A key for the module, which other modules can refer to. Must be unique within the manifest. Regex: |
function | string | Required if no |
A reference to the This function must return a check result. |
endpoint | string | Required if no |
A reference to the This endpoint must return a check result. |
name | string | Yes |
The name of the check which is displayed throughout the UI. |
description | string | No |
The description of the check which is displayed in repository settings. |
triggers | Array<string> | Yes |
The list of triggers the check is subscribed to / will be triggered by. Requires at least 1 element. |
The snippet below defines a merge check that will be triggered when any commits have been pushed to the source branch of the pull request.
1 2modules: bitbucket:mergeCheck: - key: my-bitbucket-custom-merge-check function: check-function-impl name: My first custom merge check description: This is my first check triggers: - on-code-pushed function: - key: check-function-impl handler: index.myCheckFunction
In order to subscribe to bitbucket:mergeCheck
triggers, you need to add read:pullrequest:bitbucket
scope to your app manifest.
The triggers provide a mechanism for the bitbucket:mergeCheck
module to control when the check should be invoked for a
given pull request. These can be seen as business events within the lifecycle of a pull request.
A bitbucket:mergeCheck
module can subscribe to one or more existing triggers. This decision should be based on what
the check is validating. For instance, a check trying to enforce a code quality standard may only require the
on-code-pushed
trigger, while a check preventing pull requests from being merged during a weekend may only require the
on-merge
trigger.
It's important to remember that, unlike traditional Forge Functions, bitbucket:mergeCheck
triggers will only invoke
the subscribed merge check functions if the repository that the event occurs within has the respective check enabled for
that repository. This prevents unnecessary invocations of the Forge functions containing the custom merge check logic.
Trigger | Type | Description |
---|---|---|
on-code-pushed
|
pre-merge
|
Will invoke the check every time new or updated commits are pushed to the |
on-reviewer-status-changed
|
pre-merge
|
Will invoke the check every time a reviewer status (Approved or Changes Requested) changes.
This includes when a status is reset by a branch restriction due to the Note that the check is not invoked when reviewers are added to or removed from the PR, only when the status of their review changes. |
on-merge
|
on-merge
|
Will invoke the check as part of the process of merging the pull request. When the user attempts to merge the
pull request, all If this type of check fails, the merge will be aborted if the check was configured to
be Required. To retry the failed |
Whenever a bitbucket:mergeCheck
module is invoked, an event payload will be provided as an argument to the Forge
function. This payload provides the identifiers of the pull request that the check is being invoked against, and additional
properties where applicable.
Parameter | Type | Description |
---|---|---|
|
Workspace
|
The workspace containing the pull request the check is running against. |
|
Repository
|
The repository containing the pull request the check is running against. |
|
PullRequest
|
The pull request the check is running against. |
|
Trigger
|
The trigger that caused the invocation of the check. |
|
MergeProperties
|
The properties related to the pull request merge, including:
This is only included in the payload for |
1 2interface Workspace { uuid: string; } interface Repository { uuid: string; } interface PullRequest { id: number; } interface Trigger { type: string; } interface MergeProperties { commitMessage: string; commitMessageTruncated: boolean; mergeStrategy: string; closeSourceBranch: boolean; } interface PRCheckEvent { workspace: Workspace; repository: Repository; pullrequest: PullRequest; trigger: Trigger; mergeProperties?: MergeProperties; }
This is an example payload of an on-code-pushed trigger.
1 2{ "workspace": { "uuid": "{cc8e193d-7603-4dfd-8771-fcc8960aa0fb}" }, "repository": { "uuid": "{15a31549-1cff-45dc-9d0d-310114c5038b}" }, "pullrequest": { "id": 123 }, "trigger": { "type": "on-code-pushed" } }
This is an example payload of an on-merge trigger.
1 2{ "workspace": { "uuid": "{cc8e193d-7603-4dfd-8771-fcc8960aa0fb}" }, "repository": { "uuid": "{15a31549-1cff-45dc-9d0d-310114c5038b}" }, "pullrequest": { "id": 123 }, "trigger": { "type": "on-code-pushed" }, "mergeProperties": { "commitMessage": "Merged in testbranch (pull request #5)\n\ntesting PR\n\n", "commitMessageTruncated": false, "mergeStrategy": "merge_commit", "closeSourceBranch": true } }
The only responsibility of the function registered against the bitbucket:mergeCheck
module is that it returns a
well-defined response payload every time the Bitbucket Forge infrastructure invokes it.
This result produced by each invocation of the bitbucket:mergeCheck
module is handled and stored by the Bitbucket
Forge infrastructure, there is no requirement for the Forge app to store it, or send the response back to a specific
Bitbucket API. The merge check is only expected to calculate and return result in the correct response format.
If any exceptions are thrown when executing the check logic, the check result will be treated as a failure. Note that the user can individually rerun failed checks.
success
field.name
field.message
field.Property | Type | Required | Description |
---|---|---|---|
success
|
boolean
| Yes |
Whether or not the check has passed. If |
message
|
string
| No |
A message related to the result of the check. Useful for providing detail to the users about why the check failed, giving hints to what needs to be fixed in the pull request. |
1 2interface MergeCheckResponse{ success: boolean; message?: string; }
1 2{ "success": false, "message": "No merges after 5pm" }
Rate this page: