Skip to content

Commit a37a489

Browse files
EMaherCopilot
andcommitted
refactor: consolidate renderTemplate into src/lib/render-template.ts
Move the shared renderTemplate function from src/templates/shared/template-utils.ts to src/lib/render-template.ts and remove the duplicate private method from identity-guide-service.ts. All template consumers now import from the single canonical location. Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
1 parent e749efb commit a37a489

4 files changed

Lines changed: 10 additions & 25 deletions

File tree

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
// Copyright (c) Microsoft Corporation.
22
// Licensed under the MIT license.
33
/**
4-
* Shared template rendering utility for Copilot prompt templates.
5-
* Replaces {{TOKEN}} placeholders with provided values.
4+
* Template rendering utility.
5+
* Replaces {{TOKEN}} placeholders in template strings with provided values.
66
*/
77

88
/**

src/services/identity-guide-service.ts

Lines changed: 4 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ import {
1111
azureDevOpsIdentityGuideTemplate,
1212
githubActionsIdentityGuideTemplate,
1313
} from '../templates/generated/embedded-markdown.js';
14+
import { renderTemplate } from '../lib/render-template.js';
1415

1516
export interface IdentityGuideService {
1617
generateGitHubActionsGuide(
@@ -25,13 +26,6 @@ export interface IdentityGuideService {
2526
}
2627

2728
class IdentityGuideServiceImpl implements IdentityGuideService {
28-
private renderTemplate(template: string, tokens: Record<string, string>): string {
29-
return Object.entries(tokens).reduce(
30-
(rendered, [key, value]) => rendered.replaceAll(`{{${key}}}`, value),
31-
template
32-
);
33-
}
34-
3529
generateGitHubActionsGuide(
3630
subscriptionId: string,
3731
resourceGroup: string,
@@ -52,7 +46,7 @@ class IdentityGuideServiceImpl implements IdentityGuideService {
5246
- \`APIM_SERVICE_NAME_${env.toUpperCase()}\`: APIM service name for ${env}
5347
`).join('\n');
5448

55-
return this.renderTemplate(githubActionsIdentityGuideTemplate, {
49+
return renderTemplate(githubActionsIdentityGuideTemplate, {
5650
SUBSCRIPTION_ID: subscriptionId,
5751
RESOURCE_GROUP: resourceGroup,
5852
FEDERATED_CREDENTIALS_PER_ENV: federatedCredentialsPerEnvironment,
@@ -70,12 +64,12 @@ class IdentityGuideServiceImpl implements IdentityGuideService {
7064
.map((environment) => `"${environment}"`)
7165
.join(' ');
7266

73-
const coreSteps = this.renderTemplate(azureDevOpsIdentitySetupCoreTemplate, {
67+
const coreSteps = renderTemplate(azureDevOpsIdentitySetupCoreTemplate, {
7468
ENVIRONMENTS_ARRAY_POWERSHELL: environmentsArrayPowerShell,
7569
ENVIRONMENTS_ARRAY_BASH: environmentsArrayBash,
7670
});
7771

78-
return this.renderTemplate(azureDevOpsIdentityGuideTemplate, {
72+
return renderTemplate(azureDevOpsIdentityGuideTemplate, {
7973
AZURE_DEVOPS_CORE_STEPS: coreSteps,
8074
});
8175
}

src/templates/copilot/configure-overrides-prompt.md

Lines changed: 3 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -72,18 +72,9 @@ Using the artifact directory identified in Step 1:
7272
> APIOps and do **not** need overrides.
7373
7474
2. For each environment, create a **stub** `configuration.{env}.yaml` that
75-
covers all the commonly-overridden items you found. Use placeholder example
76-
values so the user can see the shape of the file.
77-
78-
3. **Add everything as YAML comments initially** — a commented-out section is
79-
safe because it will not cause a publish failure. The user can uncomment
80-
and fill in values in Step 3. Example pattern:
81-
```yaml
82-
# namedValues:
83-
# - name: payment-api-key
84-
# properties:
85-
# value: "{#[PAYMENT_API_KEY]#}"
86-
```
75+
covers all the commonly-overridden items you found. Use placeholder values
76+
(e.g., `TODO` or `{#[TOKEN_NAME]#}`) so the user can see the shape of the
77+
file and fill in real values in Step 3.
8778

8879
---
8980

src/templates/copilot/identity-setup-prompt.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ import {
1616
copilotGithubEnvironmentSecretCommandsTemplate,
1717
copilotGitHubActionsIdentitySetupPromptTemplate,
1818
} from '../generated/embedded-markdown.js';
19-
import { renderTemplate } from '../shared/template-utils.js';
19+
import { renderTemplate } from '../../lib/render-template.js';
2020

2121
export interface IdentitySetupPromptConfig {
2222
environments: string[];

0 commit comments

Comments
 (0)