Skip to content

Commit

Permalink
Merge main into sweep/convert-main-to-functional-component
Browse files Browse the repository at this point in the history
  • Loading branch information
sweep-ai[bot] authored Sep 19, 2023
2 parents b9e8800 + e101a54 commit ab6c91f
Show file tree
Hide file tree
Showing 7 changed files with 19 additions and 4 deletions.
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

0 comments on commit ab6c91f

Please sign in to comment.