diff --git a/README.md b/README.md index 621d1e18..b7108b45 100644 --- a/README.md +++ b/README.md @@ -15,6 +15,7 @@ deployments are successful. All in one overview. This is all done via **webhooks - [GitHub](https://cimonitor.readthedocs.io/en/latest/webhook/github/) - [GitLab](https://cimonitor.readthedocs.io/en/latest/webhook/gitlab/) - [Read the Docs](https://cimonitor.readthedocs.io/en/latest/webhook/readthedocs/) +- [BitBucket](https://cimonitor.readthedocs.io/en/latest/webhook/bitbucket/) ## Example diff --git a/backend/parser/bitbucket/index.ts b/backend/parser/bitbucket/index.ts index 34e2c21b..2a478ac2 100644 --- a/backend/parser/bitbucket/index.ts +++ b/backend/parser/bitbucket/index.ts @@ -9,6 +9,7 @@ import { import Status from 'types/status'; import BitBucketBuildParser from './build'; +import BitBucketPullRequestParser from './pull-request'; import BitBucketPushParser from './push'; class BitBucketParser { @@ -60,12 +61,7 @@ class BitBucketParser { const id = this.getInternalId(pr.repository, pr.pullrequest.source.branch.name); - // TODO: parse the PR - console.log('[parser/bitbucket] TODO.'); - id; - return null; - - // return BitBucketPullRequestParser.parse(id, build); + return BitBucketPullRequestParser.parse(id, pr); } } diff --git a/backend/parser/bitbucket/pull-request.ts b/backend/parser/bitbucket/pull-request.ts new file mode 100644 index 00000000..accd8797 --- /dev/null +++ b/backend/parser/bitbucket/pull-request.ts @@ -0,0 +1,36 @@ +import StatusManager from 'backend/status/manager'; +import { BitBucketPullRequestWebhook } from 'types/bitbucket'; +import Status from 'types/status'; + +class BitBucketPullRequestParser { + parse(id: string, pr: BitBucketPullRequestWebhook): Status { + let status = StatusManager.getStatus(id); + + if (!status) { + status = { + id, + project: `${pr.repository.workspace.name} / ${pr.repository.name}`, + state: 'info', + source: 'bitbucket', + time: new Date().toUTCString(), + processes: [], + }; + } + + const commitUser = pr.actor; + return { + ...status, + branch: pr.pullrequest.source.branch.name, + username: commitUser.display_name, + userUrl: commitUser.links.html.href, + userImage: commitUser.links.avatar.href, + mergeTitle: pr.pullrequest.title, + mergeUrl: pr.pullrequest.links.html.href, + projectImage: pr.repository.links.avatar.href, + sourceUrl: pr.repository.links.html.href, + time: new Date().toUTCString(), + }; + } +} + +export default new BitBucketPullRequestParser(); diff --git a/docs/images/status/bitbucket.png b/docs/images/status/bitbucket.png new file mode 100644 index 00000000..92511a71 Binary files /dev/null and b/docs/images/status/bitbucket.png differ diff --git a/docs/webhook/bitbucket.md b/docs/webhook/bitbucket.md new file mode 100644 index 00000000..9fc97041 --- /dev/null +++ b/docs/webhook/bitbucket.md @@ -0,0 +1,15 @@ +# BitBucket + +![BitBucket status example](../images/status/bitbucket.png) + +## Adding webhook + +In your BitBucket project settings, open the webhooks page, and add a webhook: + +- _WebHook URL_: `cimonitor.example.com/webhook/bitbucket` (replace your domain name) +- _Content type_: `application/json` +- _Secret:_ insert the same password you've defined to access your settings +- _What event?_ Select all the events to unluck the most potential. Supported are merge request, pushes and builds. +- Make sure the webhook is active + +Add your webhook! All new builds should become visible on your CIMonitor. diff --git a/mkdocs.yml b/mkdocs.yml index d116d82f..cc4e71a4 100644 --- a/mkdocs.yml +++ b/mkdocs.yml @@ -20,6 +20,7 @@ nav: - GitHub: webhook/github.md - GitLab: webhook/gitlab.md - Read the docs: webhook/readthedocs.md + - BitBucket: webhook/bitbucket.md - Modules: modules.md - Module: - GPIO: module/gpio.md