Skip to content

Commit

Permalink
Couple of minor tweaks
Browse files Browse the repository at this point in the history
  • Loading branch information
cdupuis committed Oct 17, 2023
1 parent 1964032 commit 403016b
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 15 deletions.
34 changes: 20 additions & 14 deletions lib/events/register_skill.ts
Original file line number Diff line number Diff line change
Expand Up @@ -113,7 +113,7 @@ export const handler: MappingEventHandler<

skill.version = await version(ctx, skill);
skill.apiVersion = apiVersion(ctx);
await inlineDatalogResources(p, skill, skillYaml.skill);
await inlineDatalogResources(p, skill);
if (isContainer(ctx)) {
await createArtifact(skill, ctx, registry);
} else {
Expand Down Expand Up @@ -381,13 +381,13 @@ type DatalogSubscription = {
name: string;
query: string;
limit?: number;
}
};

async function getDatalogSubscriptionFileMatches(
p: project.Project,
matchPath: string
matchPath: string,
): Promise<Array<DatalogSubscription>> {
return (await project.withGlobMatches<{
return await project.withGlobMatches<{
name: string;
query: string;
limit?: number;
Expand All @@ -399,12 +399,12 @@ async function getDatalogSubscriptionFileMatches(
query: (await fs.readFile(filePath)).toString(),
name: fileName.replace(extName, ""),
};
}))
});
}

function updateSubscriptions(
datalogSubscriptions: Array<DatalogSubscription>,
updates: Array<DatalogSubscription>
updates: Array<DatalogSubscription>,
): void {
updates.forEach(d => {
const eds = datalogSubscriptions.find(ds => d.name === ds.name);
Expand All @@ -419,24 +419,30 @@ function updateSubscriptions(

export async function inlineDatalogResources(
p: project.Project,
skill: AtomistSkillInput,
skillYaml: any,
skill: AtomistYaml["skill"],
): Promise<void> {
const datalogSubscriptions = new Array<DatalogSubscription>();
const datalogSubscriptions: Array<DatalogSubscription> = [];

// common subscriptions
datalogSubscriptions.push(
...(await getDatalogSubscriptionFileMatches(p, "datalog/subscription/*.edn")),
...(await getDatalogSubscriptionFileMatches(
p,
"datalog/subscription/*.edn",
)),
);

// subscription paths defined in yaml
for (const subscriptionPath of (skillYaml.datalogSubscriptionPaths || [])) {
const groupMatches = await getDatalogSubscriptionFileMatches(p, `datalog/subscription/${subscriptionPath}`)
updateSubscriptions(datalogSubscriptions, groupMatches)
for (const subscriptionPath of skill.datalogSubscriptionPaths || []) {
const groupMatches = await getDatalogSubscriptionFileMatches(
p,
`datalog/subscription/${subscriptionPath}`,
);
updateSubscriptions(datalogSubscriptions, groupMatches);
}
delete skill.datalogSubscriptionPaths;

// subscriptions defined in yaml
updateSubscriptions(datalogSubscriptions, skill.datalogSubscriptions || [])
updateSubscriptions(datalogSubscriptions, skill.datalogSubscriptions || []);
skill.datalogSubscriptions = datalogSubscriptions;

const schemata = [...(skill.schemata || [])];
Expand Down
3 changes: 2 additions & 1 deletion lib/util.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
*/

import { handle } from "@atomist/skill";
import { AtomistSkillInput } from "@atomist/skill/lib/definition/subscription/typings/types";
import { Project } from "@atomist/skill/lib/project/project";
import * as fs from "fs-extra";
import * as yaml from "js-yaml";
Expand All @@ -23,7 +24,7 @@ import { Configuration } from "./configuration";
import { RegisterSkill } from "./types";

export interface AtomistYaml {
skill: any;
skill: AtomistSkillInput & { datalogSubscriptionPaths?: string[] };
}

export const AtomistYamlFileName = "skill.package.yaml";
Expand Down

0 comments on commit 403016b

Please sign in to comment.