In this example, you will create blueprints for bitbucketProject
, bitbucketRepository
and bitbucketPullrequest
that ingests all projects, repositories and pull requests from your Bitbucket account. Also, you will add some python script to make API calls to Bitbucket REST API and fetch data for your account. In addition to ingesting data via REST API, you will also configure webhooks to automatically update your entities in Port anytime an event occurs in your Bitbucket account. For this example, you will subscribe to project
updates, repository
updates events as well as pull request
events.
Log in to your Port account and create the following blueprints:
Create the project blueprint in Port using this json file
Create the repository blueprint in Port using this json file
Create the pull request blueprint in Port using this json file
To ingest data from your Bitbucket account to Port, run the following commands:
export PORT_CLIENT_ID=<ENTER CLIENT ID>
export PORT_CLIENT_SECRET=<ENTER CLIENT SECRET>
export BITBUCKET_USERNAME=<ENTER BITBUCKET USERNAME>
export BITBUCKET_PASSWORD=<ENTER BITBUCKET PASSWORD>
export BITBUCKET_HOST=<ENTER BITBUCKER HOST>
# optional
export BITBUCKET_PROJECTS_FILTER=<ENTER COMMA SEPARATED PROJECTS>
git clone https://github.com/port-labs/bitbucket-workspace-data.git
cd bitbucket-workspace-data
pip install -r ./requirements.txt
python app.py
The list of variables required to run this script are:
PORT_CLIENT_ID
PORT_CLIENT_SECRET
BITBUCKET_HOST
- BitBucket server host such ashttp://localhost:7990
BITBUCKET_USERNAME
- BitBucket username to use when accessing the BitBucket resourcesBITBUCKET_PASSWORD
- BitBucket account passwordBITBUCKET_PROJECTS_FILTER
- An optional comma separated list of BitBucket projects to filter. If not provided, all projects will be fetched.
Webhooks are a great way to receive updates from third party platforms, and in this case, Bitbucket. To create a bitbucket webhook, you will first need to generate a webhook URL from Port.
Follow the following steps to create a webhook:
-
Navigate to the Builder section in Port and click Data source;
-
Under Webhook tab, click Custom integration;
-
In the basic details tab, you will be asked to provide information about your webhook such as the
title
,identifier
description
, andicon
; -
In the integration configuration tab, copy and pase the webhook configuration file into the Map the data from the external system into Port form;
-
Take note of the webhook
URL
provided by Port on this page. You will need thisURL
when subscribing to events in Bitbucket; -
Test the webhook configuration mapping and click on Save;
-
Under the Advanced settings tab, you will authenticate the payload from Bitbucket. Enter the following details:
Secret
- enter your webhook secret. You will need this value when setting up the webhook trigger in Bitbucket;Signature Header Name
- enterX-Hub-Signature
;Signature Algorithm
- selectsha256
from the dropdown;Signature Prefix
- entersha256=
.
- From your Bitbucket account, open the project where you want to add the webhook;
- Click Project settings or the gear icon on the left sidebar;
- On the Workflow section, select Webhooks on the left sidebar;
- Click the Add webhook button to create a webhook for the repository;
- Input the following details:
Title
- use a meaningful name such as Port Webhook;URL
- enter the value of the webhookURL
you received after creating the webhook configuration in Port;Secret
- enter the value of the secret you provided when configuring the webhook in Port;Triggers
- Under Project selectmodified
Under Repository selectmodified
. Under Pull request select any event based on your case;
- Click Save to save the webhook;
Follow this documentation to learn more about webhook events payload in Bitbucket.
Done! any change that happens to your project, repository or pull requests in Bitbucket will trigger a webhook event to the webhook URL provided by Port. Port will parse the events according to the mapping and update the catalog entities accordingly.