Skip to content

[bitbucket-server] support for projects and prebuilds #8896

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Apr 4, 2022
Merged

Conversation

AlexTugarev
Copy link
Member

@AlexTugarev AlexTugarev commented Mar 19, 2022

Description

This enables prebuilds for Bitbucket Server integrations.

Screenshot 2022-03-19 at 06 00 10

Breaking Changes

  • Admin scopes are required to make the webhook creation work. Full set of scopes to enable for the OAuth App: PUBLIC_REPOS, REPO_READ, REPO_WRITE, REPO_ADMIN, PROJECT_ADMIN
  • Due to a change in Identity.authName mapping, users need to re-login to get that updated, otherwise repository services wont be able to read permissions properly.

Related Issue(s)

Fixes #8455

How to test

  • Make sure to create a new account in the preview environment
  • Make sure to create an account in https://bitbucket.gitpod-self-hosted.com (hint: log in as "roboquat" with the credentials in 1password, then create a new user account for yourself)
  • Try to add repos with admin permission as projects. Test with personal repos as well as repos in repos.
    • Verify that webhooks are created on the BBS.
  • Open workspaces for those repos and make changes.
    • Verify that prebuilds are triggered.
    • Verify that prebuilds ran on the proper branch for example.

TODO

  • manage and use webhook secret to verify events

Known issues or out of scope

  • No support for Issue and PR contexts
  • No UI for setting up a BBS integration (this has to be done via config at the moment)

Release Notes

Adding support for Projects and Prebuilds for Bitbucket Server. 

@AlexTugarev AlexTugarev marked this pull request as ready for review March 28, 2022 13:24
@AlexTugarev AlexTugarev requested a review from a team March 28, 2022 13:24
@github-actions github-actions bot added the team: webapp Issue belongs to the WebApp team label Mar 28, 2022
@csweichel
Copy link
Contributor

Awesome work - we really need this change.
/cc @geropl what do we need to do to get this merged?

@geropl
Copy link
Member

geropl commented Mar 30, 2022

@AlexTugarev Can you raise this within the team to get a review this week? Maybe from Jan?

@jldec
Copy link
Contributor

jldec commented Mar 30, 2022

/werft run

👍 started the job as gitpod-build-at-bbs.14

@jldec
Copy link
Contributor

jldec commented Mar 30, 2022

Validated adding integration as a user by opening a workspace on a prefixed URL.
Works as expected ✅

Screenshot 2022-03-30 at 10 09 09

Screenshot 2022-03-30 at 10 10 04

Screenshot 2022-03-30 at 10 12 00

layout of the scopes is a bit wide, but not a big problem (look similar to existing BB integration)

@jldec
Copy link
Contributor

jldec commented Mar 30, 2022

  • resolved

New project flow fails to fetch branches (upper-case/lower-case issue?) for repo at
https://bitbucket.gitpod-self-hosted.com/projects/JLDEC/repos/jldec-repo-march-30/browse

Screenshot 2022-03-30 at 10 56 19

Screenshot 2022-03-30 at 10 15 30

@jldec
Copy link
Contributor

jldec commented Mar 30, 2022

Project on personal repo is able to fetch branches. ✅
Branch list formatting is off (because of avatar - see similar issue for GHE in #8755)

Screenshot 2022-03-30 at 10 54 32

@jldec
Copy link
Contributor

jldec commented Mar 30, 2022

Project on same personal repo shows error when looking for .gitpod.yml under configuration page.

Screenshot 2022-03-30 at 11 19 57

@jldec
Copy link
Contributor

jldec commented Mar 30, 2022

  • error in ~username context urls. ACK'd, but fixup is not yet pushed to not disturb reviewers.

The button to start a new workspace after creating a new project on a personal repo, appears to create a broken context url since it uses the clone url path scm/~jldec/test-repo2.git. Replacing that context url with the actual url path from BBS does work users/jldec/repos/test-repo2/browse

Screenshot 2022-03-30 at 12 25 54

Screenshot 2022-03-30 at 12 26 06

Screenshot 2022-03-30 at 12 26 22

@jldec
Copy link
Contributor

jldec commented Mar 30, 2022

  • fixed

There does not appear to be any installed webhook on any of the repos for which I have created a project.

Screenshot 2022-03-30 at 12 37 09

@AlexTugarev
Copy link
Member Author

AlexTugarev commented Mar 31, 2022

@jldec, please check again 🙏🏻

Also, pay attention to the Breaking Changes, esp. to the re-login step. Casing of the auth name was wrong in my account. I've added tests for that, it should meet the expectations in both directions and match the permission queries.

In your case, which is assumingely uncommon, there is a project and a user account named equally. Something you would not expect to be possible. I've change the workaround to try projects first, this should resolve the issues from above as well.

Let's see if we need a 3rd round 🤞🏻

Screen Shot 2022-04-01 at 08 31 10

@AlexTugarev
Copy link
Member Author

Just found an issue with the New Project wizard, which was actually reported several times, but we seem to not have found a repro for: User.identities contain a Gitpod identity, which AFAIU is used to authorize webhook event handler (i.e. for prebuild events) and this is not handled nor expected.

I'll make a drive-by-change to exclude them from the results of GitpodService.getAuthProviders as it's likely unexpected/unhandled in other places.

Screen Shot 2022-04-01 at 08 47 21

@easyCZ
Copy link
Member

easyCZ commented Apr 1, 2022

  • AT: that's a configuration issue no BBS. they are rendering an error page. I've improved the error message propagation, so if you try to start a workspace, you'll see a helpful message. BTW: we've discussed a general error component in the dashboard to show system/project errors, THIS could be used to provide instant feedback on the branches overview.

I'm unable to see prebuilds for my project:

Steps:

  1. Create a bitbucket project
  2. Import https://gitlab.com/gitpod-milan/gitpod-large-image as a repo
  3. Create gitpod project
  4. Navigate to Branches - nothing visible

Screenshot 2022-04-01 at 9 38 06

5. Try `Run prebuild` - nothing happens, request response contains
Request triggerPrebuild failed with message: 404 / Not Found
  1. Project Settings also seem to not have access to the repo properly

Screenshot 2022-04-01 at 9 42 11

@inject(BitbucketServerContextParser) protected contextParser: BitbucketServerContextParser;

async getRepositoriesForAutomatedPrebuilds(user: User): Promise<ProviderRepository[]> {
const repos = await this.api.getRepos(user, { limit: 100, permission: "REPO_ADMIN" });
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

[nit] Would be good to comment that we're requesting REPO_ADMIN because that's the minimum role required to create webhooks.

Comment on lines 68 to 78
if (permission && ["REPO_ADMIN", "PROJECT_ADMIN"].indexOf(permission) !== -1) {
return true;
}
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

[nit] It can be sometimes helpful to communicate the reasoning for a particular check though a method name. For example:

if (hasPermissionToCreateWebhooks(permission) {

@AlexTugarev
Copy link
Member Author

@easyCZ, please invite me to your project to reproduce #8896 (comment)

@AlexTugarev AlexTugarev requested a review from jankeromnes April 1, 2022 09:17
@jankeromnes
Copy link
Contributor

jankeromnes commented Apr 1, 2022

Many thanks for implementing BBS! 🏭

Gave this a spin, and was able to successfully add a Bitbucket project! 🎉


Minor: The UI looks a little bit unpolished still --

1. No BBS provider icon? 2. Should BBS really be visible by default on Login? 3. Uppercase scopes? 4. Without scope descriptions? 5. Why the ~ in my name? 6. Shouldn't the project name be vertically centered?
Screenshot 2022-04-01 at 11 35 15 Screenshot 2022-04-01 at 11 46 01 Screenshot 2022-04-01 at 11 49 21

Also, I wasn't able to start a workspace for some reason:

  • AT: this is tackled in most recent changes. see comments bellow.
Add empty repo, click on New Workspace Fails with 404? 😳
Screenshot 2022-04-01 at 11 50 28 Screenshot 2022-04-01 at 11 50 14

@AlexTugarev
Copy link
Member Author

@jankeromnes thanks for asking on the ~

Why the ~ in my name?

That indicated personal projects. As @jldec managed to create a personal and a regular project of the same name, I'd consider that a "feature"! Seriously, I've no idea of how to treat that properly. Ambiguity of project name is hard. Let's have the ~ until we learn, how if there is a better way to handle it. Having that said, I see no way in removing it without breaking the other project kinds. Ok?

@jankeromnes
Copy link
Contributor

jankeromnes commented Apr 1, 2022

  • AT: that's the "no default branch" situation to be resolved on BBS. latest change introduced better error message propagation, which explains the problem.

Okay, I was now able to push changes to my BBS repository. Unfortunately, no Prebuilds are being triggered.

When I try the Run Prebuild button, it fails with the same 404 message. I guess this is the ~ problem as well?

Screenshot 2022-04-01 at 12 15 38

@AlexTugarev AlexTugarev requested a review from jldec April 1, 2022 13:30
easyCZ
easyCZ previously approved these changes Apr 1, 2022
Copy link
Member

@easyCZ easyCZ left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks, I've tested this as far as I can and seems to work. There are still some rough edges on the integration (largely due to BitBucket Server being a bit crazy) but I think this is a good enough 🛹 .

Code-wise, looks sensible but I don't yet have full context to know if there are skeletons.

@easyCZ
Copy link
Member

easyCZ commented Apr 1, 2022

/hold

@jankeromnes
Copy link
Contributor

jankeromnes commented Apr 1, 2022

Nice! Feels like this is closing in on the finish line. 🏁

I've noticed a few remaining rough edges though:

Screenshot 2022-04-01 at 17 16 21

Screenshot 2022-04-01 at 17 16 36

(The project is actually still created, but I guess without a webhook, because prebuilds do not trigger automatically on pushes)

@jldec
Copy link
Contributor

jldec commented Apr 4, 2022

I was a bit surprised to get the extra login button when I start a totally new session - if we ship this and configure our BBS integration for testing, we don't want everyone else (non-gitpod) who lands on gitpod.io for the first time to see the extra button. Can you confirm that this will not be the case for SaaS?

Screenshot 2022-04-04 at 00 31 39

@jldec
Copy link
Contributor

jldec commented Apr 4, 2022

Regarding the button formatting - the lack of image, and the way the button text bleeds to the edges does look unpolished. I understand that it's cosmestic, but the first impression users see is important as well.

@AlexTugarev
Copy link
Member Author

Can you confirm that this will not be the case for SaaS?

@jldec, don't worry, one need to do a backflip to get it running on self-hosted, there is no path for this to get initialized on SaaS.

@AlexTugarev
Copy link
Member Author

AlexTugarev commented Apr 4, 2022

Thanks @jankeromnes, overlooked your issue with the 404 error. I could reproduce it on a fork. Trying to get this sorted out before proceeding.

edit

Awesome! That was indeed a bug in "can install webhook" logic for repos in personal accounts. There is an API which should not be called for personal accounts, but it was.

I changed and updated the branch.

@AlexTugarev
Copy link
Member Author

/unhold

@roboquat roboquat merged commit 76b51bc into main Apr 4, 2022
@roboquat roboquat deleted the at/bbs branch April 4, 2022 08:37
@roboquat roboquat added deployed: webapp Meta team change is running in production deployed Change is completely running in production labels Apr 5, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
deployed: webapp Meta team change is running in production deployed Change is completely running in production release-note size/XXL team: webapp Issue belongs to the WebApp team
Projects
None yet
Development

Successfully merging this pull request may close these issues.

[Bitbucket Server] Add support for installing webhooks and prebuilds with projects
7 participants