Skip to content

Commit

Permalink
fix default template for non-admin users
Browse files Browse the repository at this point in the history
  • Loading branch information
karthikjeeyar committed Jun 8, 2022
1 parent 8e22765 commit 1ccc510
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 12 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -209,4 +209,11 @@ describe('getPipelineRunTemplate', () => {
const template = await getPipelineRunTemplate('nodejs', 'repo-name');
expect(template).toEqual(expect.stringContaining('my-custom-template-string'));
});

it('should return default template if there is an error while fetching', async () => {
/* eslint-disable-next-line prefer-promise-reject-errors */
k8sListResourceItemsMock.mockReturnValueOnce(Promise.reject({ message: '403' }));
const template = await getPipelineRunTemplate('nodejs', 'repo-name');
expect(template).toEqual(expect.stringContaining('name: repo-name'));
});
});
Original file line number Diff line number Diff line change
Expand Up @@ -112,7 +112,7 @@ export const createRepositoryResources = async (
},
// eslint-disable-next-line @typescript-eslint/camelcase
webhook_secret: {
name: secret?.metadata?.name,
name: secretRef?.metadata?.name,
key: 'webhook.secret',
},
}
Expand Down Expand Up @@ -283,18 +283,23 @@ export const getPipelineRunTemplate = async (
runtime: string,
repoName: string,
): Promise<string> => {
const [pipelineRunTemplateCfg] = await k8sListResourceItems<ConfigMapKind>({
model: ConfigMapModel,
queryParams: {
ns: PIPELINE_NAMESPACE,
labelSelector: {
matchLabels: {
'pipelinesascode.openshift.io/runtime': runtime,
let runTimeTemplate;
try {
const [pipelineRunTemplateCfg] = await k8sListResourceItems<ConfigMapKind>({
model: ConfigMapModel,
queryParams: {
ns: PIPELINE_NAMESPACE,
labelSelector: {
matchLabels: {
'pipelinesascode.openshift.io/runtime': runtime,
},
},
},
},
});
const pipelineRunTemplate =
pipelineRunTemplateCfg?.data?.template ?? (await getPipelineRunDefaultTemplate(repoName));
});
runTimeTemplate = pipelineRunTemplateCfg?.data?.template;
} catch (e) {
console.log('failed to fetch runtime template:', e); // eslint-disable-line no-console
}
const pipelineRunTemplate = runTimeTemplate ?? (await getPipelineRunDefaultTemplate(repoName));
return pipelineRunTemplate;
};

0 comments on commit 1ccc510

Please sign in to comment.