Skip to content
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

Fix Bitbucket push event handling #7833

Merged
merged 3 commits into from
Feb 8, 2022
Merged

Fix Bitbucket push event handling #7833

merged 3 commits into from
Feb 8, 2022

Conversation

AlexTugarev
Copy link
Member

@AlexTugarev AlexTugarev commented Jan 26, 2022

Fixes #7683

This PR also fixes the linking of prebuilds to the related project.

Screen Shot 2022-01-26 at 10 24 43

Fix Bitbucket push event handling

@roboquat
Copy link
Contributor

[APPROVALNOTIFIER] This PR is NOT APPROVED

This pull-request has been approved by:
To complete the pull request process, please ask for approval from alextugarev after the PR has been reviewed.

Associated issue: #7683

The full list of commands accepted by this bot can be found here.

Needs approval from an approver in each of these files:

Approvers can indicate their approval by writing /approve in a comment
Approvers can cancel approval by writing /approve cancel in a comment

@codecov
Copy link

codecov bot commented Jan 26, 2022

Codecov Report

Merging #7833 (50e3740) into main (01dc940) will decrease coverage by 1.15%.
The diff coverage is n/a.

Impacted file tree graph

@@            Coverage Diff             @@
##             main    #7833      +/-   ##
==========================================
- Coverage   12.01%   10.86%   -1.16%     
==========================================
  Files          20       18       -2     
  Lines        1190     1022     -168     
==========================================
- Hits          143      111      -32     
+ Misses       1043      909     -134     
+ Partials        4        2       -2     
Flag Coverage Δ
components-gitpod-cli-app 10.86% <ø> (ø)
components-local-app-app-darwin-amd64 ?
components-local-app-app-darwin-arm64 ?
components-local-app-app-linux-amd64 ?
components-local-app-app-linux-arm64 ?
components-local-app-app-windows-386 ?
components-local-app-app-windows-amd64 ?
components-local-app-app-windows-arm64 ?

Flags with carried forward coverage won't be shown. Click here to find out more.

Impacted Files Coverage Δ
components/local-app/pkg/auth/pkce.go
components/local-app/pkg/auth/auth.go

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update 01dc940...50e3740. Read the comment docs.

@AlexTugarev AlexTugarev marked this pull request as ready for review January 26, 2022 10:04
@gtsiolis gtsiolis added the team: webapp Issue belongs to the WebApp team label Jan 26, 2022
@jankeromnes
Copy link
Contributor

jankeromnes commented Jan 28, 2022

Taking a look now 👀

Copy link
Contributor

@jankeromnes jankeromnes left a comment

Choose a reason for hiding this comment

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

Many thanks for adding the project association for Bitbucket push events! 👍

This change looks good to me in principle, except for the part about impersonating a random team owner (please see inline).

I've also tested that triggering Prebuilds by pushing commits to Bitbucket still works 👍 (both for user projects and team projects).

if (project) {
const owner = !!project.userId
? { userId: project.userId }
: (await this.teamDB.findMembersByTeam(project.teamId || '')).filter(m => m.role === "owner")[0];
Copy link
Contributor

Choose a reason for hiding this comment

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

Why is it useful to pick a random owner from the team here, as opposed to just picking the user that started the prebuild as before?

It still seems weird and potentially dangerous to me that I can potentially perform actions as someone else (impersonation), as opposed to always running Gitpod actions as myself.

Copy link
Member Author

Choose a reason for hiding this comment

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

It still seems weird and potentially dangerous to me that I can potentially perform actions as someone else (impersonation), as opposed to always running Gitpod actions as myself.

First of, here we're are handling projects of a team in that case and this is about the ownership of a prebuild – nothing else. Then also, tagging with any of the current team owners seems to better than potentially tagging with a non-existing userId, which led to this pattern in the first place. BTW it'd be just consistent to do it like this, or change it also for GitHub and GitLab projects/prebuilds.

Copy link
Member Author

Choose a reason for hiding this comment

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

Why is it useful to pick a random owner from the team here, as opposed to just picking the user that started the prebuild as before?

Another explainer: have a user A create a project in a team and then let user A leave the team, which account to use to tag the prebuild?

Copy link
Member Author

Choose a reason for hiding this comment

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

@jankeromnes, can we discuss this in a call?

Copy link
Member

Choose a reason for hiding this comment

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

Hm. I tend to agree with Jan that we should not try to do sth intimate (use token) that is unexpected.
How does the BitBucket "installation flow" look like? E.g., can we store a userId there that we can use here? That way we'd at least maintain the expectation that who registered a repo will also execute the prebuilds (like for GitHub apps).

Another explainer: have a user A create a project in a team and then let user A leave the team, which account to use to tag the prebuild?

This sounds like a very interesting question to me: What is projectId.userId useful for, anyway? 🤔

Copy link
Member

Choose a reason for hiding this comment

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

Suggestion: For the sake of this PR, let's separate the "who owns the Team" and "who owns the BitBucket 'installation'" discussions into (a) separate issue(s). And simply exit here if project.userId is not set. Would that work, @AlexTugarev ?

Copy link
Member Author

Choose a reason for hiding this comment

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

The point is that we're storing the users token in the webhook registration, which is part of history when we had no project introduced yet. I believe it would be more robust to add the project id in the webhook registration and use any available token of any team owner (with access to that BB repo) when doing updates to the webook registration. This is something we concluded while discussing about the ownership of a project within a team, and what should happen when one leaves a team, e.g. should the project be removed?

I'm also ok with trying to maintain the installer's link as far as possible and fallback to a team owner after the installer was removed from the team.

Copy link
Member Author

Choose a reason for hiding this comment

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

@jankeromnes and @geropl, I changed to prefer the previous webhook installer, which should meet the expectation in most cases. I suggest to overhaul the semantics for all providers in a separate issues, because it seems that we did not cover all cases. That's something we can and should cover in unit tests for clear communications.

Copy link
Member

Choose a reason for hiding this comment

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

Sounds good!

Copy link
Member Author

Choose a reason for hiding this comment

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

@jankeromnes and @geropl, thanks once again for pushing this! after re-re-reading the flow and testing once more, I realized that's a bad decision to limit to project owners 🙄. the fallback mechanism should, if applied, try to find and team member to rescue the state of the project, if the original installer was removed from the team. so, priority is to maintain the webhook membership and then to fallback to any of the team member with the relevant provider connection.

I took the change and aligned the gitlab app code as well, because that was the blueprint here.

let's continue the clean up of this in the effort to provide a state of the webhook installation.

@AlexTugarev AlexTugarev requested review from a team, jankeromnes and geropl February 7, 2022 11:08
@geropl
Copy link
Member

geropl commented Feb 8, 2022

/hold
/lgtm

The code LGTM except that I think we should add a comment with the gist of our discussion to findProjectOwner.

Please ping for new /lgtm then!

/**
* Finds the relevant user account and project to the provided webhook event information.
*
* First of all it tries to find the project for the given `cloneURL`, then it tries to
Copy link
Member

Choose a reason for hiding this comment

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

❤️

Copy link
Member

@geropl geropl left a comment

Choose a reason for hiding this comment

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

Code looks good! 👍

Thx for pushing this till the end!

@geropl
Copy link
Member

geropl commented Feb 8, 2022

/unhold

@roboquat roboquat merged commit bbf7036 into main Feb 8, 2022
@roboquat roboquat deleted the at/bitbucket-7683 branch February 8, 2022 12:49
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
release-note size/L team: webapp Issue belongs to the WebApp team
Projects
None yet
Development

Successfully merging this pull request may close these issues.

BitBucket App: Cannot read properties of null (reading 'name')
5 participants