jackherd 1.17.0 → 1.18.1

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.
@@ -1,5 +1,5 @@
1
1
  import { isRecord } from '../shared/is-record'
2
- import { type FeedbackTarget, isReadTime } from './feedback'
2
+ import { isReadTime, type LaneFeedbackTarget } from './feedback'
3
3
  import { FEEDBACK_FORM, type FeedbackItem } from './feedback-item'
4
4
 
5
5
  export const PREVIEW_EVENT = 'preview'
@@ -33,7 +33,7 @@ export type PreviewRecord = { reportedHead: string | null; stamps: Record<string
33
33
  /** `since` is the epoch milliseconds of the last read, null before the first. */
34
34
  export type PreviewState = { since: number | null; pullRequests: Record<string, PreviewRecord> }
35
35
 
36
- export type PreviewRead = { readAt: number; targets: FeedbackTarget[]; candidates: PreviewCandidate[] }
36
+ export type PreviewRead = { readAt: number; targets: LaneFeedbackTarget[]; candidates: PreviewCandidate[] }
37
37
 
38
38
  /** Which comments name a preview: their authors' logins, and optionally a pattern whose first group is the URL. */
39
39
  export type PreviewSettings = { authors: readonly string[]; urlPattern?: string }
@@ -125,7 +125,7 @@ export const previewDeployments = (deployments: readonly Deployment[], deployEnv
125
125
 
126
126
  /** A deployment of `target`'s head as a candidate once its latest status succeeded with an https URL. */
127
127
  export const deploymentCandidate = (
128
- target: FeedbackTarget,
128
+ target: LaneFeedbackTarget,
129
129
  id: number,
130
130
  status: DeploymentStatus,
131
131
  ): PreviewCandidate | null => {
@@ -144,7 +144,7 @@ export const deploymentCandidate = (
144
144
 
145
145
  export const previewReadOf = (
146
146
  readAt: number,
147
- targets: FeedbackTarget[],
147
+ targets: LaneFeedbackTarget[],
148
148
  candidates: readonly PreviewCandidate[],
149
149
  ): PreviewRead => {
150
150
  const numbers = new Set(targets.map(({ number }) => number))
@@ -152,18 +152,18 @@ export const previewReadOf = (
152
152
  }
153
153
 
154
154
  /** A candidate with a URL that may stand for the target's current head: a comment, or a deployment of that head. */
155
- const isUsable = (candidate: PreviewCandidate, target: FeedbackTarget): boolean =>
155
+ const isUsable = (candidate: PreviewCandidate, target: LaneFeedbackTarget): boolean =>
156
156
  candidate.url !== null && (candidate.headCommit === null || candidate.headCommit === target.headCommit)
157
157
 
158
158
  /** Deployments before comments: a deployment names its commit, a comment does not. */
159
159
  const byDeploymentFirst = (a: PreviewCandidate, b: PreviewCandidate): number =>
160
160
  Number(a.source !== PREVIEW_SOURCE.deployment) - Number(b.source !== PREVIEW_SOURCE.deployment)
161
161
 
162
- const candidatesOf = (read: PreviewRead, target: FeedbackTarget): PreviewCandidate[] =>
162
+ const candidatesOf = (read: PreviewRead, target: LaneFeedbackTarget): PreviewCandidate[] =>
163
163
  read.candidates.filter(({ pullRequest }) => pullRequest === target.number).sort(byDeploymentFirst)
164
164
 
165
165
  /** The usable candidate that changed since `record`, when the head has had no preview reported yet. */
166
- const freshPreview = (record: PreviewRecord, target: FeedbackTarget, candidates: readonly PreviewCandidate[]) =>
166
+ const freshPreview = (record: PreviewRecord, target: LaneFeedbackTarget, candidates: readonly PreviewCandidate[]) =>
167
167
  target.headCommit === record.reportedHead
168
168
  ? undefined
169
169
  : candidates.find((candidate) => record.stamps[candidate.key] !== candidate.stamp && isUsable(candidate, target))
@@ -189,7 +189,7 @@ export const previewEvents = (previous: PreviewState, read: PreviewRead): Previe
189
189
  : []
190
190
  })
191
191
 
192
- const recordOf = (record: PreviewRecord | undefined, target: FeedbackTarget, candidates: PreviewCandidate[]) => {
192
+ const recordOf = (record: PreviewRecord | undefined, target: LaneFeedbackTarget, candidates: PreviewCandidate[]) => {
193
193
  const stamps = Object.fromEntries(candidates.map(({ key, stamp }) => [key, stamp]))
194
194
  const shown = record
195
195
  ? freshPreview(record, target, candidates)
@@ -211,7 +211,7 @@ export const recordPreviews = (previous: PreviewState, read: PreviewRead): Previ
211
211
  })
212
212
 
213
213
  /** The targets whose current head has no preview reported yet; only they need their deployments read. */
214
- export const unreportedTargets = (state: PreviewState, targets: readonly FeedbackTarget[]): FeedbackTarget[] =>
214
+ export const unreportedTargets = (state: PreviewState, targets: readonly LaneFeedbackTarget[]): LaneFeedbackTarget[] =>
215
215
  targets.filter(({ number, headCommit }) => state.pullRequests[String(number)]?.reportedHead !== headCommit)
216
216
 
217
217
  const isPreviewRecord = (value: unknown): boolean =>