Skip to content

Fix and re-enable automated prebuilds for GitHub Enterprise #8757

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
Mar 14, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 3 additions & 2 deletions components/dashboard/src/projects/NewProject.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -623,13 +623,14 @@ function GitProviders(props: {
setErrorMessage(undefined);

const token = await getGitpodService().server.getToken({ host: ap.host });
if (token) {
const isGitHubEnterprise = AuthProviderInfo.isGitHubEnterprise(ap);
if (token && !(isGitHubEnterprise && !token.scopes.includes("repo"))) {
props.onHostSelected(ap.host);
return;
}
await openAuthorizeWindow({
host: ap.host,
scopes: ap.requirements?.default,
scopes: isGitHubEnterprise ? ["repo"] : ap.requirements?.default,
onSuccess: async () => {
props.onHostSelected(ap.host, true);
},
Expand Down
6 changes: 6 additions & 0 deletions components/gitpod-protocol/src/protocol.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1143,6 +1143,12 @@ export interface AuthProviderInfo {
};
}

export namespace AuthProviderInfo {
export function isGitHubEnterprise(info?: AuthProviderInfo): boolean {
return !!info && info.authProviderType === "GitHub" && info.host !== "github.com";
}
}

export interface AuthProviderEntry {
readonly id: string;
readonly type: AuthProviderEntry.Type;
Expand Down
6 changes: 4 additions & 2 deletions components/server/src/projects/projects-service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
import { inject, injectable } from "inversify";
import { DBWithTracing, ProjectDB, TeamDB, TracedWorkspaceDB, UserDB, WorkspaceDB } from "@gitpod/gitpod-db/lib";
import {
AuthProviderInfo,
Branch,
PrebuildWithStatus,
CreateProjectParams,
Expand Down Expand Up @@ -147,8 +148,9 @@ export class ProjectsService {
let { userId, teamId, cloneUrl } = project;
const parsedUrl = RepoURL.parseRepoUrl(project.cloneUrl);
const hostContext = parsedUrl?.host ? this.hostContextProvider.get(parsedUrl?.host) : undefined;
const type = hostContext && hostContext.authProvider.info.authProviderType;
if (type === "GitLab" || type === "Bitbucket") {
const authProvider = hostContext && hostContext.authProvider.info;
const type = authProvider && authProvider.authProviderType;
if (type === "GitLab" || type === "Bitbucket" || AuthProviderInfo.isGitHubEnterprise(authProvider)) {
const repositoryService = hostContext?.services?.repositoryService;
if (repositoryService) {
// Note: For GitLab, we expect .canInstallAutomatedPrebuilds() to always return true, because earlier
Expand Down