mattermost-community / mattermost-plugin-bitbucket

Mattermost plugin for Bitbucket
Apache License 2.0
6 stars 16 forks source link

Bitbucket Server: Implement Bitbucket API client #121

Open mickmister opened 8 months ago

mickmister commented 8 months ago

First let's define a few terms:


The plugin currently works with Bitbucket Cloud's API using the v2 library. The v1 library implements functionality to work with Bitbucket Server, so we should try and use that library if possible, or pull from established patterns in the v1 library with regards to interacting with Bitbucket Server's API.

We can abstract out usages of the v2 library into a common interface among the two systems. We'll replace references to the v2 *bitbucket.APIClient to our own version of the client. Here's what our interface could look like, based on our current usage:

The contents of these methods will be the minimal differing factors between the two Bitbucket systems. The data model returned by these methods can be a new set of structs that contain the minimal subset of fields that we currently rely on from the v2 library data model.

For the purpose of this task, we can avoid the piece of modularizing between Cloud and Server, and instead just focus on implementing the Server version. This means we can replace the calls to the Bitbucket client in-place, and avoid the overhead of abstracting the interface.

Examples of where API calls are currently in the plugin GetPullRequestById(prId) https://github.com/mattermost/mattermost-plugin-bitbucket/blob/84a4030b48eb91683d9038ba35afacc9ec9e8f92/server/api.go#L519 bitbucketClient.PullrequestsApi.RepositoriesUsernameRepoSlugPullrequestsPullRequestIdGet ListRepositories(options) https://github.com/mattermost/mattermost-plugin-bitbucket/blob/84a4030b48eb91683d9038ba35afacc9ec9e8f92/server/plugin.go#L388 bitbucketClient.PagingApi.RepositoriesPageGet ListIssues(options) https://github.com/mattermost/mattermost-plugin-bitbucket/blob/84a4030b48eb91683d9038ba35afacc9ec9e8f92/server/plugin.go#L421 bitbucketClient.PagingApi.IssuesPageGet ListPullRequests(options) https://github.com/mattermost/mattermost-plugin-bitbucket/blob/84a4030b48eb91683d9038ba35afacc9ec9e8f92/server/plugin.go#L490 bitbucketClient.PagingApi.PullrequestsPageGet GetMe() https://github.com/mattermost/mattermost-plugin-bitbucket/blob/84a4030b48eb91683d9038ba35afacc9ec9e8f92/server/api.go#L245 bitbucketClient.UsersApi.UserGet(ctx) CreateComment(commentPayload) https://github.com/mattermost/mattermost-plugin-bitbucket/blob/84a4030b48eb91683d9038ba35afacc9ec9e8f92/server/api.go#L657 bitbucketClient.IssueTrackerApi.RepositoriesUsernameRepoSlugIssuesIssueIdCommentsPost GetIssueById(issueId) https://github.com/mattermost/mattermost-plugin-bitbucket/blob/84a4030b48eb91683d9038ba35afacc9ec9e8f92/server/api.go#L801 bitbucketClient.IssueTrackerApi.RepositoriesUsernameRepoSlugIssuesIssueIdGet CreateIssue(issuePayload) https://github.com/mattermost/mattermost-plugin-bitbucket/blob/84a4030b48eb91683d9038ba35afacc9ec9e8f92/server/api.go#L955 bitbucketClient.IssueTrackerApi.RepositoriesUsernameRepoSlugIssuesPost HasRepoReadPermission(repo) https://github.com/mattermost/mattermost-plugin-bitbucket/blob/84a4030b48eb91683d9038ba35afacc9ec9e8f92/server/subscriptions.go#L41 RepositoriesUsernameRepoSlugGet

Related User Features

These can be used to test the changes being made. The slash commands in particular are a good way of testing progress on things, as they can be re-run on demand.

Slash commands - `/bitbucket connect/disconnect` - Connect your user account to Bitbucket - GetMe() - `/bitbucket me` - Display info about your connected account - GetMe() - `/bitbucket todo` - Display current tasks from Bitbucket - ListRepositories() - ListIssues() - ListPullRequests() - `/bitbucket subscriptions add/list/delete` - Create webhook subscriptions for different channels - ListRepositories() - HasRepoReadPermission() - `/bitbucket settings` - Change user settings - N/A
Internal API endpoints for the frontend - /todo - ListRepositories() - ListIssues() - ListPullRequests() - /reviews - ListPullRequests() - /yourprs - ListPullRequests() - /prsdetails - GetPullRequestById() - /searchissues - ListIssues() - /yourassignments - ListIssues() - /createissue - CreateIssue(issuePayload) - /createissuecomment - CreateComment() - /repositories - ListRepositories() - /issue - get issue by id - GetIssueById() - /pr - get pr by id - GetPullRequestById() - /webhook - N/A (it’s possible that some webhook events require looking up a PR’s details etc.) - /settings - N/A - /user - get user by id - N/A (fetches from MM KV store rather than BB API)

Ticket Link

Epic ticket https://github.com/mattermost/mattermost-plugin-bitbucket/issues/6

panoramix360 commented 8 months ago

hey! I'll begin working on this task with @Leandro48, we chatted a little yesterday, and just to align, here is what we plan to do on the first PR: