-
Notifications
You must be signed in to change notification settings - Fork 1.3k
Brad/exp 458 fe allow pasting in a git clone url to create project as #18534
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
roboquat
merged 10 commits into
main
from
brad/exp-458-fe-allow-pasting-in-a-git-clone-url-to-create-project-as
Aug 17, 2023
Merged
Changes from all commits
Commits
Show all changes
10 commits
Select commit
Hold shift + click to select a range
d6d09ee
first pass at organizing components for project creation
selfcontained 817ae3f
allow creating from git clone url
selfcontained 6256840
cleanup
selfcontained 49478be
add creating state
selfcontained b093917
cleanup
selfcontained eff5f23
Update components/dashboard/src/projects/new-project/NewProjectCreate…
selfcontained d933bfa
improve git clone url parsing
selfcontained 08429a9
Adding cancelation when query unmounts
selfcontained 5f68e44
fixing slug
selfcontained 16f0df6
showing some help text if they enter a url that isn't a clone url
selfcontained File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
57 changes: 57 additions & 0 deletions
57
components/dashboard/src/data/git-providers/github-queries.ts
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,57 @@ | ||
/** | ||
* Copyright (c) 2023 Gitpod GmbH. All rights reserved. | ||
* Licensed under the GNU Affero General Public License (AGPL). | ||
* See License.AGPL.txt in the project root for license information. | ||
*/ | ||
|
||
import { useQuery } from "@tanstack/react-query"; | ||
import { getGitpodService } from "../../service/service"; | ||
import { useAuthProviders } from "../auth-providers/auth-provider-query"; | ||
import { useCurrentUser } from "../../user-context"; | ||
|
||
export const useIsGithubAppEnabled = () => { | ||
return useQuery(["github-app-enabled"], async () => { | ||
return await getGitpodService().server.isGitHubAppEnabled(); | ||
}); | ||
}; | ||
|
||
export const useAreGithubWebhooksUnauthorized = (providerHost: string) => { | ||
const { data: authProviders } = useAuthProviders(); | ||
const { data: isGitHubAppEnabled } = useIsGithubAppEnabled(); | ||
const { data: token } = useGetGitToken(providerHost); | ||
|
||
// If the app is enabled, authorized | ||
if (isGitHubAppEnabled) { | ||
return false; | ||
} | ||
|
||
// If we don't have auth providers or the provider host, we can't check yet, treat as authorized | ||
if (!authProviders || !providerHost) { | ||
return false; | ||
} | ||
|
||
// Find matching auth provider - if none, treat as authorized | ||
const ap = authProviders?.find((ap) => ap.host === providerHost); | ||
if (!ap || ap.authProviderType !== "GitHub") { | ||
return false; | ||
} | ||
|
||
// Finally, check token for the right scopes - if missing, then uanuthorized | ||
if (!token || !token.scopes.includes("repo")) { | ||
return true; | ||
} | ||
}; | ||
|
||
export const useGetGitToken = (providerHost: string) => { | ||
const user = useCurrentUser(); | ||
|
||
return useQuery( | ||
["git-token", { userId: user?.id }, { providerHost }], | ||
async () => { | ||
return await getGitpodService().server.getToken({ host: providerHost }); | ||
}, | ||
{ | ||
enabled: !!user && !!providerHost, | ||
}, | ||
); | ||
}; |
42 changes: 42 additions & 0 deletions
42
components/dashboard/src/data/git-providers/provider-repositories-query.ts
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,42 @@ | ||
/** | ||
* Copyright (c) 2023 Gitpod GmbH. All rights reserved. | ||
* Licensed under the GNU Affero General Public License (AGPL). | ||
* See License.AGPL.txt in the project root for license information. | ||
*/ | ||
|
||
import { useQuery } from "@tanstack/react-query"; | ||
import { getGitpodService } from "../../service/service"; | ||
import { useCurrentUser } from "../../user-context"; | ||
import { CancellationTokenSource } from "vscode-jsonrpc"; | ||
|
||
type UseProviderRepositoriesQueryArgs = { | ||
provider: string; | ||
installationId?: string; | ||
}; | ||
export const useProviderRepositoriesForUser = ({ provider, installationId }: UseProviderRepositoriesQueryArgs) => { | ||
const user = useCurrentUser(); | ||
|
||
return useQuery( | ||
["provider-repositories", { userId: user?.id }, { provider, installationId }], | ||
async ({ signal }) => { | ||
// jsonrpc cancellation token that we subscribe to the abort signal provided by react-query | ||
const cancelToken = new CancellationTokenSource(); | ||
|
||
signal?.addEventListener("abort", () => { | ||
cancelToken.cancel(); | ||
}); | ||
|
||
return await getGitpodService().server.getProviderRepositoriesForUser( | ||
{ | ||
provider, | ||
hints: { installationId }, | ||
}, | ||
// @ts-ignore - not sure why types don't support this | ||
cancelToken.token, | ||
); | ||
}, | ||
{ | ||
enabled: !!provider, | ||
}, | ||
); | ||
}; |
44 changes: 44 additions & 0 deletions
44
components/dashboard/src/data/projects/create-project-mutation.ts
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,44 @@ | ||
/** | ||
* Copyright (c) 2023 Gitpod GmbH. All rights reserved. | ||
* Licensed under the GNU Affero General Public License (AGPL). | ||
* See License.AGPL.txt in the project root for license information. | ||
*/ | ||
|
||
import { useMutation } from "@tanstack/react-query"; | ||
import { getGitpodService } from "../../service/service"; | ||
import { useCurrentOrg } from "../organizations/orgs-query"; | ||
import { useRefreshProjects } from "./list-projects-query"; | ||
import { CreateProjectParams, Project } from "@gitpod/gitpod-protocol"; | ||
|
||
export type CreateProjectArgs = Omit<CreateProjectParams, "teamId">; | ||
|
||
export const useCreateProject = () => { | ||
const refreshProjects = useRefreshProjects(); | ||
const { data: org } = useCurrentOrg(); | ||
|
||
return useMutation<Project, Error, CreateProjectArgs>( | ||
async ({ name, slug, cloneUrl, appInstallationId }) => { | ||
if (!org) { | ||
throw new Error("No org currently selected"); | ||
} | ||
|
||
return await getGitpodService().server.createProject({ | ||
name, | ||
slug, | ||
cloneUrl, | ||
teamId: org.id, | ||
appInstallationId, | ||
}); | ||
}, | ||
{ | ||
onSuccess: (project) => { | ||
if (org) { | ||
refreshProjects(org.id); | ||
} | ||
|
||
// Kick off a prebuild for the new project | ||
getGitpodService().server.triggerPrebuild(project.id, null); | ||
}, | ||
}, | ||
); | ||
}; |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
(nothing wrong with that line, just don't know where to attach.)
The current check for repository permissions is case-sensitive. This is why the
createProject
will fail, as it's transformed to lower case. Let me see if I can fix the permission check real quick in the other PR.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It's resolved here: 1015169
Please rebase