feat(FN-4728): complete Step 2 — add shared tracking helper
Fusion-Task-Id: FN-4728 Fusion-Task-Lineage: 6e8e9040-0c2f-4290-8905-1c1be8487894
This commit is contained in:
committed by
gsxdsm
parent
cc701b25e9
commit
aecd1a67fd
@@ -1,6 +1,36 @@
|
|||||||
import { setTaskCreatedHook, type TaskStore, type Task } from "@fusion/core";
|
import { setTaskCreatedHook, type TaskStore, type Task } from "@fusion/core";
|
||||||
import { maybeCreateTrackingIssue } from "./github-tracking.js";
|
import { maybeCreateTrackingIssue } from "./github-tracking.js";
|
||||||
|
|
||||||
|
export async function createTrackingIssueForTask(
|
||||||
|
taskStore: TaskStore,
|
||||||
|
task: Task,
|
||||||
|
options?: { githubToken?: string; logger?: Pick<Console, "warn" | "info"> },
|
||||||
|
): Promise<void> {
|
||||||
|
const logger = options?.logger ?? console;
|
||||||
|
|
||||||
|
try {
|
||||||
|
const projectSettings = await taskStore.getSettings();
|
||||||
|
const globalSettings =
|
||||||
|
(await taskStore.getGlobalSettingsStore?.()?.getSettings?.()) ?? {};
|
||||||
|
const trackingProjectSettings = options?.githubToken
|
||||||
|
? {
|
||||||
|
...projectSettings,
|
||||||
|
githubAuthToken: projectSettings.githubAuthToken ?? options.githubToken,
|
||||||
|
}
|
||||||
|
: projectSettings;
|
||||||
|
|
||||||
|
await maybeCreateTrackingIssue(task, {
|
||||||
|
taskStore,
|
||||||
|
projectSettings: trackingProjectSettings,
|
||||||
|
globalSettings,
|
||||||
|
rootDir: taskStore.getRootDir(),
|
||||||
|
logger,
|
||||||
|
});
|
||||||
|
} catch {
|
||||||
|
// Best-effort only.
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Register a post-create hook that calls `maybeCreateTrackingIssue` for every
|
* Register a post-create hook that calls `maybeCreateTrackingIssue` for every
|
||||||
* new task. Called once at process startup by the dashboard server, the CLI,
|
* new task. Called once at process startup by the dashboard server, the CLI,
|
||||||
@@ -15,19 +45,7 @@ export function registerGithubTrackingHook(
|
|||||||
|
|
||||||
setTaskCreatedHook(async (task: Task, store: TaskStore) => {
|
setTaskCreatedHook(async (task: Task, store: TaskStore) => {
|
||||||
try {
|
try {
|
||||||
const settings = await store.getSettings();
|
await createTrackingIssueForTask(store, task, { logger });
|
||||||
const globalSettingsStore = store.getGlobalSettingsStore?.();
|
|
||||||
const globalSettings = globalSettingsStore
|
|
||||||
? await globalSettingsStore.getSettings()
|
|
||||||
: {};
|
|
||||||
|
|
||||||
await maybeCreateTrackingIssue(task, {
|
|
||||||
taskStore: store,
|
|
||||||
projectSettings: settings,
|
|
||||||
globalSettings,
|
|
||||||
rootDir: store.getRootDir(),
|
|
||||||
logger,
|
|
||||||
});
|
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
// Best-effort: never propagate out of the hook.
|
// Best-effort: never propagate out of the hook.
|
||||||
const message = error instanceof Error ? error.message : String(error);
|
const message = error instanceof Error ? error.message : String(error);
|
||||||
|
|||||||
Reference in New Issue
Block a user