Skip to main content

FLAFL

Flask Application For Listening...

Code style: black

Listens for events triggered by Webhooks in an Atlassian Bitbucket server and responds.

It assumes the main purpose is to trigger test plans in an associated Bamboo instance, but can be persuaded to take other actions.


Requirements

  • User must have a netrc file containing valid login details for the Bamboo hostname used

Installation

git clone .../flafl.git
cd flafl
python3 -m venv /path/to/virtual/environment
source /path/to/virtual/environment/bin/activate
pip3 install -r requirements.txt

Local configuration

Export the following variables with the correct information:

export NETRC_FILE="/path/to/netrc/file"
export BAMB_HOSTNAME="bamboo.yourorg.com"
export BITB_HOSTNAME="bitbucket.yourorg.com"

To run the tests (see below), these environment variables must be defined, but do not need to have the correct values.

export BITB_PROJECT="test"
export BITB_REPO="test"

Tests

To check set-up, run:

python3 -m pytest

or to get test-coverage information run:

coverage run -m pytest

which allows a test-coverage report to be produced:

coverage report

or as a web page:

coverage html
xdg-open htmlcov/index.html

Usage

The main application runs as a background service.

In the flafl directory run:

./flafld <command>

to control the service. Specifically:

  • flafld start or flafld run start the service in the background, recording the process ID to ${TMP:-/tmp}/.flafl.pid
  • flafld stop stops the process (and its children)
  • flafld restart stops the running service and starts it again

On starting the service, the port number of the Flask application is printed. Make a note of this for use in setting webhooks up in Bitbucket.

Bitbucket configuration

In a browser, go to the webhook set-up page of your repository in your Bitbucket server:

https://<bitbucket.yourorg.com>/plugins/servlet/webhooks/projects/<project>/repos/<repo>

Create webhook by clicking "Create webhook", giving it a name (e.g. "flafl"), and specifying the URL of your running FLAFL application, e.g.:

https://<flafl-app-host.yourorg.com>:8080/flafl/api/v1.0/events

No "Secret" is required. Click "Test connection", and you should get a return code of "200", and in "View details", the body of the response from the applications should be:

{
  "debug_info": {
    "payloadReceived": {
      "test": true
    }
  }, 
  "message": "Successful connection."
}

Now select which events should send webhooks to the app. Under the "Repository" column, the following webhooks, if selected, will trigger a respose:

  • Push

and under the "Pull request" column, the following:

  • Opened
  • Modified
  • Merged
  • Declined
  • Deleted
  • Comment added

Others will be quietly ignored. FLAFL can easily be extended to add responses to other tiggers of interest.

Click "Save".

To test the Bitbucket configuration, create a new pull request (the target branch must be within the repository that has the webhooks; the source branch can be outside, e.g. in a fork).

In the directory containing the FLAFL application code, a log file should have been created with some diagnostic output, e.g.:

2019-12-17 17:18:54.360661
Success payload:
{
    "message": "Created PR with ID 321 from project/repo/feature-branch to project/repo/develop. Sent API call to Bamboo and got return code 204",
    "status": "success"
}

Also, the application should have automatically added a comment to the PR asking the PR author to add a Jira ticket ID to the PR title. This is an example of the kind of checks the application can perform.

Adding a comment to the PR, and deleting or declining the PR, should also add similar diagnostic output to the flafl.log file.

Metadata

Release files for flafl 0.0.4

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for flafl 0.0.4
File Size Uploaded
flafl-0.0.4.tar.gz 10.3 kB Details

Built distribution (wheel)

Table of built distributions (wheels) for flafl 0.0.4
File Interpreter ABI Platform
flafl-0.0.4-py3-none-any.whl Python 3 none any Details

Total release size: 24.5 kB

Release files / flafl-0.0.4.tar.gz

Download URL flafl-0.0.4.tar.gz
Size 10.3 kB
Tags Source
SHA-256 checksum
How to use checksums
88812c53bcc555cb9193ec41c6e425dfc70ecd8eb21cac0828346be4bb9d1043
BLAKE2b-256 checksum
How to use checksums
606eaa4d780484054c60832543f409743b8f6f960a43655c22a96c45012c786a
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/3.2.0 pkginfo/1.5.0.1 requests/2.24.0 setuptools/47.1.0 requests-toolbelt/0.9.1 tqdm/4.49.0 CPython/3.8.5

Release files / flafl-0.0.4-py3-none-any.whl

Download URL flafl-0.0.4-py3-none-any.whl
Size 14.2 kB
Tags Python 3
SHA-256 checksum
How to use checksums
2e2b834c45f1af4d51392ed6d31bc280126790995fa54a895c24b402882b254b
BLAKE2b-256 checksum
How to use checksums
36b11bdd4e33b60a3898539d07f96e3c4065281cf57a080d9d9c49820c812f08
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/3.2.0 pkginfo/1.5.0.1 requests/2.24.0 setuptools/47.1.0 requests-toolbelt/0.9.1 tqdm/4.49.0 CPython/3.8.5

Release history Release notifications | RSS feed

0.0.6

2 release files

This release

0.0.4 This release

2 release files

0.0.3

2 release files

0.0.1

2 release files

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page