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

[Self-Hosted] Allow integrating with 'github.com' without a GitHub App #9231

Merged
merged 3 commits into from
Apr 21, 2022

Conversation

jankeromnes
Copy link
Contributor

Description

Allow integrating with 'github.com' without requiring a GitHub App. This simply reuses the same common code as GitLab, Bitbucket and GitHub Enterprise, i.e. API and webhooks.

Related Issue(s)

Fixes #9163

How to test

  1. Don't follow any of the steps from https://www.notion.so/gitpod/How-to-deploy-a-PR-with-a-working-GitHub-App-integration-d297a1ef2f7b4b3aa8483b2ae9b47da2
  2. You should still be able to add Projects and run Prebuilds for github.com repos 🎉

Release Notes

Allow integrating with 'github.com' without a GitHub App

Documentation

@jankeromnes
Copy link
Contributor Author

jankeromnes commented Apr 11, 2022

Left TODO:

  • Ensure "repo" scope for github.com in New Project flow (when there is no GitHub App)
  • Fix "no github.com user repos listed" (when there is no GitHub App)

EDIT: Second problem is, listing user repositories here:

const repositories = (await this.githubApi.run(user, (gh) => gh.repos.listForAuthenticatedUser({}))).data;

is paginated -- we only get the first 30.

We could use per_page: 100, and/or paginate by using octokit.paginate (a little bit tricky to integrate with githubApi.run, because paginate wants to work on and return response.data, while githubApi.run wants to be given a response ... need to figure something out)

EDIT: Fixed ✅

@roboquat roboquat added size/M and removed size/S labels Apr 12, 2022
@roboquat roboquat added size/L and removed size/M labels Apr 12, 2022
@jankeromnes jankeromnes force-pushed the jx/no-app branch 4 times, most recently from a63a602 to 392eff3 Compare April 13, 2022 14:46
@roboquat roboquat added size/XL and removed size/L labels Apr 13, 2022
@jankeromnes jankeromnes force-pushed the jx/no-app branch 2 times, most recently from dc4448e to b255b97 Compare April 14, 2022 08:16
@roboquat roboquat added size/L and removed size/XL labels Apr 14, 2022
@jankeromnes jankeromnes force-pushed the jx/no-app branch 2 times, most recently from 44212e2 to 0632c15 Compare April 14, 2022 08:57
@jankeromnes
Copy link
Contributor Author

jankeromnes commented Apr 14, 2022

Alrighty, this is now ready for review! 🎉 Please take a look. 🙏

(Also, please disregard the merge conflict -- I had to base my PR on an older commit because preview envs got broken in main, but I'll rebase again before merging.)

@jankeromnes jankeromnes marked this pull request as ready for review April 14, 2022 08:58
@jankeromnes jankeromnes requested a review from a team April 14, 2022 08:58
@geropl
Copy link
Member

geropl commented Apr 14, 2022

Thank you @jankeromnes ! 🚀 Will have a look later today 👀

@jankeromnes
Copy link
Contributor Author

jankeromnes commented Apr 19, 2022

Friendly ping @geropl 😇 🙏

@geropl
Copy link
Member

geropl commented Apr 19, 2022

Friendly ping @geropl

Thx @jankeromnes ! still have it on the radar, but might get delayed until tomorrow.

@geropl geropl added the team: webapp Issue belongs to the WebApp team label Apr 20, 2022
@geropl
Copy link
Member

geropl commented Apr 21, 2022

@jankeromnes Starting now.

@@ -26,7 +26,8 @@ export class GitHubService extends RepositoryService {
@inject(GithubContextParser) protected githubContextParser: GithubContextParser;

async getRepositoriesForAutomatedPrebuilds(user: User): Promise<ProviderRepository[]> {
const repositories = (await this.githubApi.run(user, (gh) => gh.repos.listForAuthenticatedUser({}))).data;
const octokit = await this.githubApi.create(user);
const repositories = await octokit.paginate(octokit.repos.listForAuthenticatedUser, { per_page: 100 });
Copy link
Member

Choose a reason for hiding this comment

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

Cool to see there is a library method for this! 👍

We could try to push our map function into paginate to be more conscious about memory usage: https://github.com/octokit/plugin-paginate-rest.js/#octokitpaginate.
Because we do not have a filterMap, it could return ProviderRepository | undefined, followed by a filter(repo => !!) afterwards.

The reason I'm raising this seemingly minor issue is that when looking at COU profiles, our code is riddled with uncertainties about cardinality, leading to performance drops/spikes.
Also happy to review a follow up for this.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Good point! I believe we can simply move our after-the-fact filter into the octokit.paginate call (not sure what you mean with a filterMap, but I think a simple filter might do the trick).

Copy link
Member

Choose a reason for hiding this comment

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

I believe we can simply move our after-the-fact filter into the octokit.paginate

Ah, didn't look close enough to recognize it receives a response, not an individual shape only - nice.

Next step - and the intent of my message - was to also move our map function into paginate, so we can drop all fields we do not need before accumulating them in the repositories array. But again, this is more of a nit. Let's see to merge this as-is to not have us blocked longer than necessary by re-build issues 🙄

Copy link
Contributor Author

@jankeromnes jankeromnes Apr 21, 2022

Choose a reason for hiding this comment

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

Ah, whoops, the map would indeed have a much stronger memory reduction effect than the filter alone. 💡 Follow-up issue to the rescue!

EDIT: #9461

geropl
geropl previously approved these changes Apr 21, 2022
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.

Approving now despite the conflic because my test worked flawlessly, and I like the code as is!

Please ping once the conflict is resolved.

@jankeromnes
Copy link
Contributor Author

Rebased (without change) and moved the filter into octokit.paginate.

Will request re-approval if the deployment still works.

@geropl
Copy link
Member

geropl commented Apr 21, 2022

/werft run with-clean-slate-deployment=true

👍 started the job as gitpod-build-jx-no-app.16

I noticed this error in the previous run:

[Validating configuration]     {
[Validating configuration]       "name": "proxy-config-certificates is present and valid",
[Validating configuration]       "description": "ensures the proxy-config-certificates secret is present and contains the required data",
[Validating configuration]       "status": "ERROR",
[Validating configuration]       "errors": [
[Validating configuration]         {
[Validating configuration]           "message": "secret proxy-config-certificates not found",
[Validating configuration]           "type": "ERROR"
[Validating configuration]         }
[Validating configuration]       ]
[Validating configuration]     },

with-clean-slate-deployment=true helped me with that before, so: 🤞

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.

@roboquat roboquat merged commit d1bb3bd into main Apr 21, 2022
@roboquat roboquat deleted the jx/no-app branch April 21, 2022 13:56
@roboquat roboquat added deployed: webapp Meta team change is running in production deployed Change is completely running in production labels Apr 26, 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/L team: webapp Issue belongs to the WebApp team
Projects
None yet
Development

Successfully merging this pull request may close these issues.

[Self-hosted] Allow projects to work with github.com the same way they do for GHE
3 participants