@brainervirus/workit-pi 2.1.2 → 2.1.3
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/worker.js +0 -1
- package/dist/workit.js +53 -84
- package/package.json +1 -1
package/dist/worker.js
CHANGED
package/dist/workit.js
CHANGED
|
@@ -10370,7 +10370,6 @@ var LOCALE_RE = /^[a-z]{2,3}(-(?:[A-Z]{2}|[0-9]{3}))?$/;
|
|
|
10370
10370
|
var DEFAULTS = {
|
|
10371
10371
|
locale: "en",
|
|
10372
10372
|
localeOptions: ["en", "es-CL", "es-MX", "es-AR", "pt-BR"],
|
|
10373
|
-
timezone: "America/Santiago",
|
|
10374
10373
|
branchPolicy: {
|
|
10375
10374
|
preset: "gitflow",
|
|
10376
10375
|
allowed: [...PRESETS.gitflow.allowed],
|
|
@@ -10408,7 +10407,6 @@ var parseConfigResult = (raw, file) => {
|
|
|
10408
10407
|
config: {
|
|
10409
10408
|
locale,
|
|
10410
10409
|
localeOptions: Array.isArray(input.localeOptions) ? input.localeOptions : DEFAULTS.localeOptions,
|
|
10411
|
-
timezone: input.timezone ?? DEFAULTS.timezone,
|
|
10412
10410
|
branchPolicy: mergePreset(preset, {
|
|
10413
10411
|
allowed: Array.isArray(input.branchPolicy?.allowed) ? input.branchPolicy.allowed : undefined,
|
|
10414
10412
|
protectedNames: Array.isArray(input.branchPolicy?.protected) ? input.branchPolicy.protected : undefined
|
|
@@ -17670,51 +17668,29 @@ function tzParts(date, tz) {
|
|
|
17670
17668
|
timeZone: tz,
|
|
17671
17669
|
year: "numeric",
|
|
17672
17670
|
month: "2-digit",
|
|
17673
|
-
day: "2-digit"
|
|
17674
|
-
hour: "2-digit",
|
|
17675
|
-
minute: "2-digit",
|
|
17676
|
-
hourCycle: "h23"
|
|
17671
|
+
day: "2-digit"
|
|
17677
17672
|
}).formatToParts(date);
|
|
17678
17673
|
const map = Object.fromEntries(parts.map((p) => [p.type, p.value]));
|
|
17679
|
-
return { y: map.year, m: map.month, d: map.day
|
|
17680
|
-
}
|
|
17681
|
-
|
|
17682
|
-
|
|
17683
|
-
|
|
17684
|
-
|
|
17685
|
-
|
|
17686
|
-
|
|
17687
|
-
|
|
17688
|
-
|
|
17689
|
-
|
|
17690
|
-
|
|
17691
|
-
|
|
17692
|
-
|
|
17693
|
-
|
|
17694
|
-
|
|
17695
|
-
|
|
17696
|
-
const
|
|
17697
|
-
|
|
17698
|
-
|
|
17699
|
-
const now = new Date;
|
|
17700
|
-
const { y, m, d, hour, minute } = tzParts(now, tz);
|
|
17701
|
-
const cutoff = String(config.greetingCutoff ?? "12:00").split(":");
|
|
17702
|
-
const cutoffHour = Number(cutoff[0]);
|
|
17703
|
-
const cutoffMinute = Number(cutoff[1] ?? 0);
|
|
17704
|
-
const greetings = config.greetings ?? {};
|
|
17705
|
-
const isMorning = Number(hour) < cutoffHour || Number(hour) === cutoffHour && Number(minute) < cutoffMinute;
|
|
17706
|
-
const greeting = isMorning ? greetings.morning ?? "buenos días" : greetings.afternoon ?? "buenas tardes";
|
|
17707
|
-
const mention = String(config.defaultMention ?? "Alejandra.Flores");
|
|
17708
|
-
return { stdout: `@${mention} Hola, ${greeting}.
|
|
17709
|
-
`, exitCode: 0, stderr: "" };
|
|
17710
|
-
} catch (err) {
|
|
17711
|
-
return {
|
|
17712
|
-
stdout: "",
|
|
17713
|
-
exitCode: 1,
|
|
17714
|
-
stderr: err instanceof Error ? err.message : "greeting failed"
|
|
17715
|
-
};
|
|
17716
|
-
}
|
|
17717
|
-
}
|
|
17674
|
+
return { y: map.year, m: map.month, d: map.day };
|
|
17675
|
+
}
|
|
17676
|
+
var processTimezone = () => Intl.DateTimeFormat().resolvedOptions().timeZone || "UTC";
|
|
17677
|
+
var effectiveWorkTimezone = (cfg) => {
|
|
17678
|
+
const configured = cfg?.timezone;
|
|
17679
|
+
return typeof configured === "string" && configured.trim() ? { timezone: configured.trim(), source: "youtrack.json" } : { timezone: processTimezone(), source: "process" };
|
|
17680
|
+
};
|
|
17681
|
+
var DEFAULT_MEETING_WORK_ITEM_TEXT = "Meetings";
|
|
17682
|
+
var meetingWorkItemText = (cfg, item) => {
|
|
17683
|
+
if (typeof item?.workItemText === "string" && item.workItemText)
|
|
17684
|
+
return item.workItemText;
|
|
17685
|
+
if (typeof cfg?.meetingWorkItemText === "string" && cfg.meetingWorkItemText)
|
|
17686
|
+
return cfg.meetingWorkItemText;
|
|
17687
|
+
return DEFAULT_MEETING_WORK_ITEM_TEXT;
|
|
17688
|
+
};
|
|
17689
|
+
var utcMidnight = (y, m, d) => {
|
|
17690
|
+
const ms = Date.UTC(y, m - 1, d);
|
|
17691
|
+
const check = new Date(ms);
|
|
17692
|
+
return check.getUTCFullYear() === y && check.getUTCMonth() === m - 1 && check.getUTCDate() === d ? ms : null;
|
|
17693
|
+
};
|
|
17718
17694
|
function youTrackParseDuration(text) {
|
|
17719
17695
|
const lower = String(text).toLowerCase().trim();
|
|
17720
17696
|
let total = 0;
|
|
@@ -17730,7 +17706,7 @@ function youTrackParseDuration(text) {
|
|
|
17730
17706
|
}
|
|
17731
17707
|
function youTrackWorkDateMs(dateRaw) {
|
|
17732
17708
|
const cfgPath = youTrackConfigPath();
|
|
17733
|
-
let
|
|
17709
|
+
let effective = effectiveWorkTimezone(null);
|
|
17734
17710
|
if (fs9.existsSync(cfgPath)) {
|
|
17735
17711
|
let parsed;
|
|
17736
17712
|
try {
|
|
@@ -17741,31 +17717,31 @@ function youTrackWorkDateMs(dateRaw) {
|
|
|
17741
17717
|
if (!isConfigObject(parsed)) {
|
|
17742
17718
|
return { error: `${cfgPath} is not a JSON object` };
|
|
17743
17719
|
}
|
|
17744
|
-
|
|
17720
|
+
effective = effectiveWorkTimezone(parsed);
|
|
17745
17721
|
}
|
|
17722
|
+
const tz = effective.timezone;
|
|
17723
|
+
const meta = { timezone: tz, timezoneSource: effective.source };
|
|
17746
17724
|
const raw = dateRaw || "auto";
|
|
17747
17725
|
try {
|
|
17748
|
-
if (raw === "auto"
|
|
17749
|
-
const
|
|
17750
|
-
const
|
|
17751
|
-
|
|
17752
|
-
|
|
17726
|
+
if (raw === "auto") {
|
|
17727
|
+
const { y, m, d } = tzParts(new Date, tz);
|
|
17728
|
+
const dateMs = utcMidnight(Number(y), Number(m), Number(d));
|
|
17729
|
+
if (dateMs === null)
|
|
17730
|
+
return { error: "could not resolve date" };
|
|
17731
|
+
return { data: { dateMs, ...meta, localDate: `${y}-${m}-${d}` } };
|
|
17753
17732
|
}
|
|
17754
17733
|
if (/^\d+$/.test(raw)) {
|
|
17755
17734
|
const dt = new Date(Number(raw));
|
|
17756
|
-
|
|
17757
|
-
|
|
17758
|
-
|
|
17759
|
-
|
|
17760
|
-
const
|
|
17761
|
-
const dateMs =
|
|
17762
|
-
|
|
17763
|
-
|
|
17764
|
-
|
|
17765
|
-
|
|
17766
|
-
localDate: `${y}-${String(m).padStart(2, "0")}-${String(d).padStart(2, "0")}`
|
|
17767
|
-
}
|
|
17768
|
-
};
|
|
17735
|
+
if (Number.isNaN(dt.getTime()))
|
|
17736
|
+
return { error: `invalid date: ${raw}` };
|
|
17737
|
+
return { data: { dateMs: Number(raw), ...meta, localDate: dt.toISOString().slice(0, 10) } };
|
|
17738
|
+
}
|
|
17739
|
+
const match = /^(\d{4})-(\d{1,2})-(\d{1,2})$/.exec(raw);
|
|
17740
|
+
const dateMs = match ? utcMidnight(Number(match[1]), Number(match[2]), Number(match[3])) : null;
|
|
17741
|
+
if (!match || dateMs === null)
|
|
17742
|
+
return { error: `invalid date: ${raw} (expected YYYY-MM-DD)` };
|
|
17743
|
+
const localDate = `${match[1]}-${match[2].padStart(2, "0")}-${match[3].padStart(2, "0")}`;
|
|
17744
|
+
return { data: { dateMs, ...meta, localDate } };
|
|
17769
17745
|
} catch (err) {
|
|
17770
17746
|
return { error: err instanceof Error ? err.message : "could not resolve date" };
|
|
17771
17747
|
}
|
|
@@ -17887,13 +17863,11 @@ function parseIssueRef(input) {
|
|
|
17887
17863
|
}
|
|
17888
17864
|
var defaultScripts = {
|
|
17889
17865
|
config: () => youTrackConfigLoad(),
|
|
17890
|
-
greeting: () => youTrackGreeting(),
|
|
17891
17866
|
parseDuration: (text) => youTrackParseDuration(text),
|
|
17892
17867
|
api: (args) => youTrackApi(args, process.env.WORKFLOW_YT_WRITE ?? "")
|
|
17893
17868
|
};
|
|
17894
17869
|
var contextScripts = {
|
|
17895
17870
|
config: readYouTrackContextConfig,
|
|
17896
|
-
greeting: () => youTrackGreeting(youTrackReadOnlyConfigPath()),
|
|
17897
17871
|
parseDuration: (text) => youTrackParseDuration(text),
|
|
17898
17872
|
api: () => ({ error: "YouTrack context is read-only" })
|
|
17899
17873
|
};
|
|
@@ -17925,7 +17899,7 @@ function meetingOptionsFromConfig(cfg) {
|
|
|
17925
17899
|
key,
|
|
17926
17900
|
issue: item.issue,
|
|
17927
17901
|
label: item.label ?? item.issue,
|
|
17928
|
-
workItemText: item
|
|
17902
|
+
workItemText: meetingWorkItemText(cfg, item),
|
|
17929
17903
|
url: item.url ?? (base && item.issue ? `${base}/issue/${item.issue}` : null)
|
|
17930
17904
|
}));
|
|
17931
17905
|
}
|
|
@@ -17935,7 +17909,7 @@ function meetingOptionsFromConfig(cfg) {
|
|
|
17935
17909
|
key: "general",
|
|
17936
17910
|
issue,
|
|
17937
17911
|
label: "General meetings",
|
|
17938
|
-
workItemText:
|
|
17912
|
+
workItemText: meetingWorkItemText(cfg),
|
|
17939
17913
|
url: base && issue ? `${base}/issue/${issue}` : null
|
|
17940
17914
|
}
|
|
17941
17915
|
];
|
|
@@ -17957,17 +17931,9 @@ var readOnlyYouTrackConfig = (cfg) => {
|
|
|
17957
17931
|
const baseUrl = publicUrl(cfg.baseUrl);
|
|
17958
17932
|
if (baseUrl)
|
|
17959
17933
|
safe.baseUrl = baseUrl;
|
|
17960
|
-
for (const key of ["timezone", "
|
|
17934
|
+
for (const key of ["timezone", "meetingIssue", "meetingWorkItemText"])
|
|
17961
17935
|
if (typeof cfg[key] === "string")
|
|
17962
17936
|
safe[key] = cfg[key];
|
|
17963
|
-
if (cfg.greetings && typeof cfg.greetings === "object" && !Array.isArray(cfg.greetings)) {
|
|
17964
|
-
const greetings = {};
|
|
17965
|
-
for (const key of ["morning", "afternoon"])
|
|
17966
|
-
if (typeof cfg.greetings[key] === "string")
|
|
17967
|
-
greetings[key] = cfg.greetings[key];
|
|
17968
|
-
if (Object.keys(greetings).length)
|
|
17969
|
-
safe.greetings = greetings;
|
|
17970
|
-
}
|
|
17971
17937
|
if (cfg.meetingIssues && typeof cfg.meetingIssues === "object" && !Array.isArray(cfg.meetingIssues)) {
|
|
17972
17938
|
safe.meetingIssues = Object.fromEntries(Object.entries(cfg.meetingIssues).flatMap(([key, value]) => {
|
|
17973
17939
|
if (!value || typeof value !== "object" || Array.isArray(value))
|
|
@@ -17997,16 +17963,12 @@ function context({
|
|
|
17997
17963
|
const cfg = scripts.config();
|
|
17998
17964
|
if (cfg.error)
|
|
17999
17965
|
return { error: cfg.error };
|
|
18000
|
-
const greeting = scripts.greeting();
|
|
18001
|
-
if (greeting.exitCode !== 0) {
|
|
18002
|
-
return { error: (greeting.stderr || greeting.stdout || "greeting failed").trim() };
|
|
18003
|
-
}
|
|
18004
17966
|
const safeConfig = readOnlyYouTrackConfig(cfg.data);
|
|
18005
17967
|
const meetingOptions = meetingOptionsFromConfig(safeConfig);
|
|
18006
17968
|
if (mode === "meetings" && !issue_id && !issue_url && !issue_ref) {
|
|
18007
17969
|
return {
|
|
18008
17970
|
config: safeConfig,
|
|
18009
|
-
|
|
17971
|
+
workTimezone: effectiveWorkTimezone(safeConfig),
|
|
18010
17972
|
mode: "meetings",
|
|
18011
17973
|
requiresMeetingChoice: true,
|
|
18012
17974
|
meetingOptions,
|
|
@@ -18035,7 +17997,7 @@ function context({
|
|
|
18035
17997
|
const selectedMeeting = meetingOptions.find((m) => m.issue === issue);
|
|
18036
17998
|
return {
|
|
18037
17999
|
config: safeConfig,
|
|
18038
|
-
|
|
18000
|
+
workTimezone: effectiveWorkTimezone(safeConfig),
|
|
18039
18001
|
issueId: issue,
|
|
18040
18002
|
issueUrl,
|
|
18041
18003
|
mode: mode ?? (selectedMeeting ? "meetings" : "task"),
|
|
@@ -18911,6 +18873,11 @@ var actionProposalQuestion = (request, descriptorPayload) => {
|
|
|
18911
18873
|
const cwd = descriptorPayload?.cwd;
|
|
18912
18874
|
return typeof cwd === "string" ? { ...proposal, presented: `${proposal.presented} Target directory: ${cwd}` } : proposal;
|
|
18913
18875
|
};
|
|
18876
|
+
var workDateOf = (data) => ({
|
|
18877
|
+
localDate: data.localDate,
|
|
18878
|
+
timezone: data.timezone,
|
|
18879
|
+
timezoneSource: data.timezoneSource
|
|
18880
|
+
});
|
|
18914
18881
|
var approvedResolvedExternalAction = (content) => {
|
|
18915
18882
|
try {
|
|
18916
18883
|
const value = JSON.parse(content);
|
|
@@ -19748,6 +19715,7 @@ var resolveExternalActionAtRoot = (root, request, preservedDateMs) => {
|
|
|
19748
19715
|
return success(null, null, {
|
|
19749
19716
|
request,
|
|
19750
19717
|
marker,
|
|
19718
|
+
workDate: workDateOf(date.data),
|
|
19751
19719
|
descriptorPayload: {
|
|
19752
19720
|
...request.payload,
|
|
19753
19721
|
resolved: {
|
|
@@ -19784,6 +19752,7 @@ var resolveExternalActionAtRoot = (root, request, preservedDateMs) => {
|
|
|
19784
19752
|
return success(null, null, {
|
|
19785
19753
|
request,
|
|
19786
19754
|
marker,
|
|
19755
|
+
workDate: workDateOf(date.data),
|
|
19787
19756
|
descriptorPayload: {
|
|
19788
19757
|
...request.payload,
|
|
19789
19758
|
resolved: {
|