-
Notifications
You must be signed in to change notification settings - Fork 57
Apply Git branch dropdown select #1416
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
base: main
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -40,7 +40,7 @@ RUN /dashboard/airgap.sh -i /dashboard/packages/devfile-registry/air-gap/index.j | |
|
|
||
| FROM docker.io/node:18.19.1-alpine3.19 | ||
|
|
||
| RUN apk --no-cache add curl | ||
| RUN apk --no-cache add curl git | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Don’t forget to include Git in the downstream image
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. |
||
|
|
||
| ENV FRONTEND_LIB=/dashboard/packages/dashboard-frontend/lib/public | ||
| ENV BACKEND_LIB=/dashboard/packages/dashboard-backend/lib | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,15 @@ | ||
| /* | ||
| * Copyright (c) 2018-2025 Red Hat, Inc. | ||
| * This program and the accompanying materials are made | ||
| * available under the terms of the Eclipse Public License 2.0 | ||
| * which is available at https://www.eclipse.org/legal/epl-2.0/ | ||
| * | ||
| * SPDX-License-Identifier: EPL-2.0 | ||
| * | ||
| * Contributors: | ||
| * Red Hat, Inc. - initial API and implementation | ||
| */ | ||
|
|
||
| export async function run<T>(exec: () => Promise<T>): Promise<T> { | ||
| return exec(); | ||
| } |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,50 @@ | ||
| /* | ||
| * Copyright (c) 2018-2025 Red Hat, Inc. | ||
| * This program and the accompanying materials are made | ||
| * available under the terms of the Eclipse Public License 2.0 | ||
| * which is available at https://www.eclipse.org/legal/epl-2.0/ | ||
| * | ||
| * SPDX-License-Identifier: EPL-2.0 | ||
| * | ||
| * Contributors: | ||
| * Red Hat, Inc. - initial API and implementation | ||
| */ | ||
|
|
||
| import { FastifyInstance } from 'fastify'; | ||
|
|
||
| import { baseApiPath } from '@/constants/config'; | ||
| import { setup, teardown } from '@/utils/appBuilder'; | ||
|
|
||
| jest.mock('../helpers/getDevWorkspaceClient.ts'); | ||
| jest.mock('../helpers/getServiceAccountToken.ts'); | ||
| const response = | ||
| 'c9440b0ca811e5d8e7abeee8467e1219d5ca4cb6\trefs/heads/master ' + | ||
| '0fa45f3539ca69615d0ccd8e0277fb7f12ee7715\trefs/heads/new/branch ' + | ||
| '42c6289f142a5589f206425d812d0b125ab87990\trefs/heads/newBranch ' + | ||
| '0e647bc78ac310d96251d581e5498b1503729e87\trefs/tags/test ' + | ||
| 'fb3a99a405876f16e2dcb231a061d5a3f735b2aa\trefs/pull/809/head'; | ||
| jest.mock('@/devworkspaceClient/services/helpers/exec', () => { | ||
| return { | ||
| run: async () => response, | ||
| }; | ||
| }); | ||
|
|
||
| describe('GitBranches Route', () => { | ||
| let app: FastifyInstance; | ||
| const url = 'url'; | ||
|
|
||
| beforeEach(async () => { | ||
| app = await setup(); | ||
| }); | ||
|
|
||
| afterEach(() => { | ||
| teardown(app); | ||
| }); | ||
|
|
||
| test('GET ${baseApiPath}/gitbranches:url', async () => { | ||
| const res = await app.inject().get(`${baseApiPath}/gitbranches/${url}`); | ||
|
|
||
| expect(res.statusCode).toEqual(200); | ||
| expect(res.json()).toEqual({ branches: ['master', 'new/branch', 'newBranch', 'test'] }); | ||
| }); | ||
| }); |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,34 @@ | ||
| /* | ||
| * Copyright (c) 2018-2025 Red Hat, Inc. | ||
| * This program and the accompanying materials are made | ||
| * available under the terms of the Eclipse Public License 2.0 | ||
| * which is available at https://www.eclipse.org/legal/epl-2.0/ | ||
| * | ||
| * SPDX-License-Identifier: EPL-2.0 | ||
| * | ||
| * Contributors: | ||
| * Red Hat, Inc. - initial API and implementation | ||
| */ | ||
|
|
||
| import { FastifyInstance, FastifyRequest } from 'fastify'; | ||
|
|
||
| import { baseApiPath } from '@/constants/config'; | ||
| import { gitBranchSchema } from '@/constants/schemas'; | ||
| import { restParams } from '@/models'; | ||
| import { getBranches } from '@/services/gitClient'; | ||
| import { getSchema } from '@/services/helpers'; | ||
|
|
||
| const tags = ['GitBranches']; | ||
|
|
||
| export function registerGitBranchesRoute(instance: FastifyInstance) { | ||
| instance.register(async server => { | ||
| server.get( | ||
| `${baseApiPath}/gitbranches/:url`, | ||
| getSchema({ tags, params: gitBranchSchema }), | ||
| async function (request: FastifyRequest) { | ||
| const { url } = request.params as restParams.IUrlParams; | ||
| return getBranches(url); | ||
| }, | ||
| ); | ||
| }); | ||
| } |
| Original file line number | Diff line number | Diff line change | ||||||||||||||||||||||||||||||||||||||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
| @@ -0,0 +1,34 @@ | ||||||||||||||||||||||||||||||||||||||||||||||||||
| /* | ||||||||||||||||||||||||||||||||||||||||||||||||||
| * Copyright (c) 2018-2025 Red Hat, Inc. | ||||||||||||||||||||||||||||||||||||||||||||||||||
| * This program and the accompanying materials are made | ||||||||||||||||||||||||||||||||||||||||||||||||||
| * available under the terms of the Eclipse Public License 2.0 | ||||||||||||||||||||||||||||||||||||||||||||||||||
| * which is available at https://www.eclipse.org/legal/epl-2.0/ | ||||||||||||||||||||||||||||||||||||||||||||||||||
| * | ||||||||||||||||||||||||||||||||||||||||||||||||||
| * SPDX-License-Identifier: EPL-2.0 | ||||||||||||||||||||||||||||||||||||||||||||||||||
| * | ||||||||||||||||||||||||||||||||||||||||||||||||||
| * Contributors: | ||||||||||||||||||||||||||||||||||||||||||||||||||
| * Red Hat, Inc. - initial API and implementation | ||||||||||||||||||||||||||||||||||||||||||||||||||
| */ | ||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||
| import { api } from '@eclipse-che/common'; | ||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||
| import { run } from '@/devworkspaceClient/services/helpers/exec'; | ||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||
| export async function getBranches(url: string): Promise<api.IGitBranches | undefined> { | ||||||||||||||||||||||||||||||||||||||||||||||||||
olexii4 marked this conversation as resolved.
Show resolved
Hide resolved
|
||||||||||||||||||||||||||||||||||||||||||||||||||
| try { | ||||||||||||||||||||||||||||||||||||||||||||||||||
| return new Promise((resolve, reject) => { | ||||||||||||||||||||||||||||||||||||||||||||||||||
| run(`git`, ['ls-remote', '--refs', url], 1000) | ||||||||||||||||||||||||||||||||||||||||||||||||||
|
||||||||||||||||||||||||||||||||||||||||||||||||||
| @@ -15,6 +15,15 @@ | ||
| import { run } from '@/devworkspaceClient/services/helpers/exec'; | ||
|
|
||
| export async function getBranches(url: string): Promise<api.IGitBranches | undefined> { | ||
| // Disallow remote URLs that start with "-" (prevent git option injection) | ||
| // Optionally, only allow typical git URLs: git@, http(s)://, ssh:// | ||
| if ( | ||
| typeof url !== 'string' || | ||
| url.startsWith('-') || | ||
| !(url.startsWith('git@') || url.startsWith('https://') || url.startsWith('http://') || url.startsWith('ssh://')) | ||
| ) { | ||
| throw new Error('Invalid remote URL: ' + url); | ||
| } | ||
| try { | ||
| return new Promise((resolve, reject) => { | ||
| run(`git`, ['ls-remote', '--refs', url], 1000) |
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.
Please, use async/await for better readability and maintainability.
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,78 @@ | ||
| // Jest Snapshot v1, https://goo.gl/fbAQLP | ||
|
|
||
| exports[`GitBranchDropdown snapshot 1`] = ` | ||
| <div | ||
| className="pf-c-form__group" | ||
| > | ||
| <div | ||
| className="pf-c-form__group-label" | ||
| > | ||
| <label | ||
| className="pf-c-form__label" | ||
| > | ||
| <span | ||
| className="pf-c-form__label-text" | ||
| > | ||
| Git Branch | ||
| </span> | ||
| </label> | ||
|
|
||
| </div> | ||
| <div | ||
| className="pf-c-form__group-control" | ||
| > | ||
| <div | ||
| className="pf-c-dropdown selector" | ||
| data-ouia-component-id="OUIA-Generated-Dropdown-1" | ||
| data-ouia-component-type="PF4/Dropdown" | ||
| data-ouia-safe={true} | ||
| onChange={[Function]} | ||
| > | ||
| <button | ||
| aria-expanded={false} | ||
| aria-haspopup={false} | ||
| aria-label="Git Branch" | ||
| className="pf-c-dropdown__toggle" | ||
| data-ouia-component-id="OUIA-Generated-DropdownToggle-1" | ||
| data-ouia-component-type="PF4/DropdownToggle" | ||
| data-ouia-safe={true} | ||
| disabled={false} | ||
| id="toggle-initial-selection" | ||
| onClick={[Function]} | ||
| onKeyDown={[Function]} | ||
| type="button" | ||
| > | ||
| <span | ||
| className="pf-c-dropdown__toggle-icon" | ||
| > | ||
| <svg | ||
| aria-hidden={true} | ||
| aria-labelledby={null} | ||
| fill="currentColor" | ||
| height="1em" | ||
| role="img" | ||
| style={ | ||
| { | ||
| "verticalAlign": "-0.125em", | ||
| } | ||
| } | ||
| viewBox="0 0 320 512" | ||
| width="1em" | ||
| > | ||
| <path | ||
| d="M31.3 192h257.3c17.8 0 26.7 21.5 14.1 34.1L174.1 354.8c-7.8 7.8-20.5 7.8-28.3 0L17.2 226.1C4.6 213.5 13.5 192 31.3 192z" | ||
| /> | ||
| </svg> | ||
| </span> | ||
| </button> | ||
| </div> | ||
| <div | ||
| aria-live="polite" | ||
| className="pf-c-form__helper-text pf-m-error" | ||
| id="undefined-helper" | ||
| > | ||
| No branch found. Please check the Git repository URL. | ||
| </div> | ||
| </div> | ||
| </div> | ||
| `; |
Uh oh!
There was an error while loading. Please reload this page.