-
Notifications
You must be signed in to change notification settings - Fork 1.2k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[dashboard] Use SCM Service (gRPC) (#19101)
* [dashboard] Use SCM Service (gRPC) * address review comments * bump cache version
- Loading branch information
1 parent
fa3cca4
commit 79666cd
Showing
6 changed files
with
94 additions
and
9 deletions.
There are no files selected for viewing
This file contains 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
This file contains 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
This file contains 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,79 @@ | ||
/** | ||
* 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 { PartialMessage } from "@bufbuild/protobuf"; | ||
import { PromiseClient } from "@connectrpc/connect"; | ||
import { SCMService } from "@gitpod/public-api/lib/gitpod/v1/scm_connect"; | ||
import { converter } from "./public-api"; | ||
import { getGitpodService } from "./service"; | ||
import { ApplicationError, ErrorCodes } from "@gitpod/gitpod-protocol/lib/messaging/error"; | ||
import { | ||
SearchSCMTokensRequest, | ||
SearchSCMTokensResponse, | ||
GuessTokenScopesRequest, | ||
SearchRepositoriesRequest, | ||
ListSuggestedRepositoriesRequest, | ||
ListSuggestedRepositoriesResponse, | ||
SearchRepositoriesResponse, | ||
GuessTokenScopesResponse, | ||
} from "@gitpod/public-api/lib/gitpod/v1/scm_pb"; | ||
|
||
export class JsonRpcScmClient implements PromiseClient<typeof SCMService> { | ||
async searchSCMTokens({ host }: PartialMessage<SearchSCMTokensRequest>): Promise<SearchSCMTokensResponse> { | ||
if (!host) { | ||
throw new ApplicationError(ErrorCodes.BAD_REQUEST, "host is required"); | ||
} | ||
const response = new SearchSCMTokensResponse(); | ||
const token = await getGitpodService().server.getToken({ host }); | ||
if (token) { | ||
response.tokens.push(converter.toSCMToken(token)); | ||
} | ||
return response; | ||
} | ||
|
||
async guessTokenScopes({ | ||
gitCommand, | ||
host, | ||
repoUrl, | ||
}: PartialMessage<GuessTokenScopesRequest>): Promise<GuessTokenScopesResponse> { | ||
if (!host) { | ||
throw new ApplicationError(ErrorCodes.BAD_REQUEST, "host is required"); | ||
} | ||
const response = await getGitpodService().server.guessGitTokenScopes({ | ||
gitCommand: gitCommand || "", | ||
host, | ||
repoUrl: repoUrl || "", | ||
}); | ||
return new GuessTokenScopesResponse({ | ||
message: response.message, | ||
scopes: response.scopes || [], | ||
}); | ||
} | ||
|
||
async searchRepositories(request: PartialMessage<SearchRepositoriesRequest>): Promise<SearchRepositoriesResponse> { | ||
const { limit, searchString } = request; | ||
if (!searchString) { | ||
throw new ApplicationError(ErrorCodes.BAD_REQUEST, "searchString is required"); | ||
} | ||
const repos = await getGitpodService().server.searchRepositories({ searchString, limit }); | ||
return new SearchRepositoriesResponse({ | ||
repositories: repos.map((r) => converter.toSuggestedRepository(r)), | ||
}); | ||
} | ||
|
||
async listSuggestedRepositories( | ||
request: PartialMessage<ListSuggestedRepositoriesRequest>, | ||
): Promise<ListSuggestedRepositoriesResponse> { | ||
const { organizationId } = request; | ||
if (!organizationId) { | ||
throw new ApplicationError(ErrorCodes.BAD_REQUEST, "organizationId is required"); | ||
} | ||
const repos = await getGitpodService().server.getSuggestedRepositories(organizationId); | ||
return new SearchRepositoriesResponse({ | ||
repositories: repos.map((r) => converter.toSuggestedRepository(r)), | ||
}); | ||
} | ||
} |
This file contains 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
This file contains 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
This file contains 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