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

add app name to front end parse yaml api call #3593

Merged
merged 8 commits into from
Sep 19, 2023
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
7 changes: 6 additions & 1 deletion dashboard/src/lib/hooks/usePorterYaml.ts
Original file line number Diff line number Diff line change
Expand Up @@ -30,9 +30,11 @@ type PorterYamlStatus =
*/
export const usePorterYaml = ({
source,
appName = "",
useDefaults = true,
}: {
source: (SourceOptions & { type: "github" }) | null;
appName?: string;
useDefaults?: boolean;
}): PorterYamlStatus => {
const { currentProject, currentCluster } = useContext(Context);
Expand Down Expand Up @@ -93,17 +95,19 @@ export const usePorterYaml = ({
const detectServices = useCallback(
async ({
b64Yaml,
appName,
projectId,
clusterId,
}: {
b64Yaml: string;
appName: string;
projectId: number;
clusterId: number;
}) => {
try {
const res = await api.parsePorterYaml(
"<token>",
{ b64_yaml: b64Yaml },
{ b64_yaml: b64Yaml, app_name: appName},
{
project_id: projectId,
cluster_id: clusterId,
Expand Down Expand Up @@ -147,6 +151,7 @@ export const usePorterYaml = ({
if (data) {
detectServices({
b64Yaml: data,
appName: appName,
projectId: currentProject.id,
clusterId: currentCluster.id,
});
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -145,6 +145,7 @@ export const LatestRevisionProvider = ({

const { loading: porterYamlLoading, detectedServices } = usePorterYaml({
source: latestSource?.type === "github" ? latestSource : null,
appName: appName,
useDefaults: false,
});

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -183,7 +183,7 @@ const CreateApp: React.FC<CreateAppProps> = ({ history }) => {
porterYamlFound,
detectedName,
loading: isLoadingPorterYaml,
} = usePorterYaml({ source: source?.type === "github" ? source : null });
} = usePorterYaml({ source: source?.type === "github" ? source : null, appName: name.value });
const deploymentTarget = useDefaultDeploymentTarget();
const { updateAppStep } = useAppAnalytics(name.value);
const { validateApp } = useAppValidation({
Expand Down
1 change: 1 addition & 0 deletions dashboard/src/shared/api.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -832,6 +832,7 @@ const getPorterYamlContents = baseApi<
const parsePorterYaml = baseApi<
{
b64_yaml: string;
app_name?: string;
},
{
project_id: number;
Expand Down
2 changes: 1 addition & 1 deletion internal/porter_app/parse_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ func TestParseYAML(t *testing.T) {
}

var result_nobuild = &porterv1.PorterApp{
Name: "js-test-app",
Name: "test-app",
Services: map[string]*porterv1.Service{
"example-job": {
Run: "echo 'hello world'",
Expand Down
2 changes: 1 addition & 1 deletion internal/porter_app/testdata/v2_input_nobuild.yaml
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
version: v2
name: "js-test-app"
name: "test-app"
image:
repository: nginx
tag: latest
Expand Down
8 changes: 8 additions & 0 deletions internal/porter_app/v2/yaml.go
Original file line number Diff line number Diff line change
Expand Up @@ -31,10 +31,18 @@ func AppProtoFromYaml(ctx context.Context, porterYamlBytes []byte, appName strin
porterYaml.Name = appName
}

if porterYaml.Name != "" && appName != "" && porterYaml.Name != appName {
return nil, nil, telemetry.Error(ctx, span, nil, "name specified in porter.yaml does not match app name")
}

appProto := &porterv1.PorterApp{
Name: porterYaml.Name,
}

if appProto.Name == "" {
return nil, nil, telemetry.Error(ctx, span, nil, "app name is empty")
}

if porterYaml.Build != nil {
appProto.Build = &porterv1.Build{
Context: porterYaml.Build.Context,
Expand Down
Loading