Skip to content

Commit

Permalink
Add BitBucket pull request parser and add documentation
Browse files Browse the repository at this point in the history
  • Loading branch information
rick-nu committed Jul 11, 2024
1 parent 5c1b962 commit ecbe992
Show file tree
Hide file tree
Showing 6 changed files with 55 additions and 6 deletions.
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
8 changes: 2 additions & 6 deletions backend/parser/bitbucket/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down Expand Up @@ -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);
}
}

Expand Down
36 changes: 36 additions & 0 deletions backend/parser/bitbucket/pull-request.ts
Original file line number Diff line number Diff line change
@@ -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();
Binary file added docs/images/status/bitbucket.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
15 changes: 15 additions & 0 deletions docs/webhook/bitbucket.md
Original file line number Diff line number Diff line change
@@ -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.
1 change: 1 addition & 0 deletions mkdocs.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit ecbe992

Please sign in to comment.