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

Link prebuilds with projects #4727

Merged
merged 4 commits into from
Jul 14, 2021
Merged

Link prebuilds with projects #4727

merged 4 commits into from
Jul 14, 2021

Conversation

AlexTugarev
Copy link
Member

With this PR push events will trigger prebuilds and associate them with a project (PrebuiltWorkspace.projectId) when the App installation is found.

This also includes a deduplication fix for the drop down on New Project:

Screen Shot 2021-07-07 at 11 21 21

@AlexTugarev AlexTugarev requested a review from a team as a code owner July 7, 2021 10:43
@AlexTugarev AlexTugarev requested review from a team and removed request for a team July 7, 2021 10:43
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.

Awesome, many thanks for implementing this! 💯

Here a first quick pass. Will do a deeper review soon.

components/server/ee/src/prebuilds/github-app.ts Outdated Show resolved Hide resolved
components/gitpod-protocol/src/gitpod-service.ts Outdated Show resolved Hide resolved
@AlexTugarev AlexTugarev force-pushed the at/select-repo branch 2 times, most recently from 695d6bb to 93195a4 Compare July 7, 2021 13:58
@jankeromnes jankeromnes self-requested a review July 12, 2021 09:43
@jankeromnes
Copy link
Contributor

jankeromnes commented Jul 12, 2021

/werft run

👍 started the job as gitpod-build-at-select-repo.84

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 @AlexTugarev! The code looks good to me.

How should this change be tested? (In particular, prebuilds in relation to the GitHub/GitLab/Bitbucket apps/integrations.) I've briefly tested that the /#prebuild/ manual prefix still works, but I'd love to play with a proper App/Integration in order to confirm that everything (still) works as expected.

//
const project = await this.projectDB.findProjectByInstallationId(String(installationId));
if (project) {
const owner = (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.

When there are multiple owners in a team, here we pick a "random" owner. Is this okay/expected?

It could very well be a different user than whoever installed the app for a given project in that 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.

It could very well be a different user than whoever installed the app for a given project in that team.

This is a fair point. We haven't discussed the differentiation between installer and owner. I guess for now it's good enough, as there is no accounting for this.


// Legacy mode
//
const installation = await this.appInstallationDB.findInstallation("github", String(installationId));
Copy link
Contributor

Choose a reason for hiding this comment

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

When we do find a project + owner + user above, we no longer perform this check at all.

Do we really want to trust projectDB and teamDB to implicitly guarantee the existence / validity of a given installationId?

(E.g. what happens if I install the Gitpod app to add some project to some team, but then uninstall the app again? Or it gets revoked? Or I leave the team?)

I would feel a bit safer if this sanity check is common to both modes ("project" and "legacy").

Copy link
Member Author

Choose a reason for hiding this comment

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

Do we really want to trust projectDB and teamDB to implicitly guarantee the existence / validity of a given installationId?

you are absolutely right about the "uninstalled" event. It should also either clean up or disable projects.
putting this on TODO list.

what else would you expect?

Copy link
Contributor

Choose a reason for hiding this comment

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

what else would you expect?

For the sanity check "does this installation ID actually correspond to anything?" to be above both "modes" (not just performed in "legacy" mode as currently). You can simply move the entire const installation = ... and if (!installation) block up several lines.

Comment on lines +824 to +825
const res = await query.getMany();
return res;
Copy link
Contributor

Choose a reason for hiding this comment

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

Suggested change
const res = await query.getMany();
return res;
return query.getMany();

Comment on lines +86 to +87
const inst = await this.internalStoreInstance(instance);
return inst;
Copy link
Contributor

Choose a reason for hiding this comment

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

Suggested change
const inst = await this.internalStoreInstance(instance);
return inst;
return this.internalStoreInstance(instance);

@@ -47,6 +46,8 @@ export class WorkspaceFactoryEE extends WorkspaceFactory {
throw new Error("Can only prebuild workspaces with a commit context")
}

const { project, branch } = context;
Copy link
Contributor

Choose a reason for hiding this comment

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

Do you expect to use project or branch somewhere else in the code below?

Otherwise, you could avoid the single-use local variables by using context.project and context.branch directly in the storePrebuiltWorkspace() call below.

components/gitpod-db/src/typeorm/workspace-db-impl.ts Outdated Show resolved Hide resolved
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.

After testing this some more, with an installed GitHub App, I'm more confident that this works as expected. Thus, approving. Thanks again!

However, could you please wait and only merge this after tomorrow's production deployment? This would allow more time to test on staging as well.

EDIT: Also, please squash all related commits together.

@AlexTugarev
Copy link
Member Author

However, could you please wait and only merge this after tomorrow's production deployment? This would allow more time to test on staging as well.

@jankeromnes, thank you very much! I'll do so.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants