pagescms 3.0.0 → 3.0.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.
- package/dist/package/reference/docs/configuration/content/view.md +2 -0
- package/dist/package/reference/docs/guides/editing.md +1 -1
- package/dist/package/reference/manifest.json +3 -3
- package/dist/types/features/content/unavailable-entry.d.ts +6 -0
- package/dist/types/features/drafts/draft-discard-dialog.d.ts +4 -1
- package/dist/types/features/drafts/draft-store.d.ts +1 -1
- package/dist/types/features/drafts/saved-draft-menu.d.ts +6 -0
- package/dist/types/features/repository/overview-draft-actions.d.ts +5 -0
- package/dist/types/features/repository/repository-route-state.d.ts +6 -2
- package/dist/types/lib/actions.d.ts +1 -0
- package/dist/types/server/access/repository.d.ts +4 -7
- package/dist/types/server/context-cloudflare.d.ts +4 -7
- package/dist/types/server/context-node.d.ts +4 -7
- package/dist/types/server/context.d.ts +4 -7
- package/dist/types/server/github/api.d.ts +4 -7
- package/dist/types/server/repository/provider.d.ts +1 -7
- package/docs/public/configuration/content/view.md +2 -0
- package/docs/public/guides/editing.md +1 -1
- package/package.json +1 -1
- package/public/reference/docs/configuration/content/view.md +2 -0
- package/public/reference/docs/guides/editing.md +1 -1
- package/public/reference/manifest.json +3 -3
- package/src/features/admin/action-run-status.tsx +4 -0
- package/src/features/collections/collection-table.tsx +6 -8
- package/src/features/content/unavailable-entry.tsx +64 -0
- package/src/features/drafts/draft-discard-dialog.tsx +6 -1
- package/src/features/drafts/draft-store.ts +7 -1
- package/src/features/drafts/saved-draft-menu.tsx +108 -0
- package/src/features/repository/overview-draft-actions.tsx +28 -0
- package/src/features/repository/overview-file-item.tsx +2 -0
- package/src/features/repository/overview-loading.tsx +1 -0
- package/src/features/repository/repository-route-state.tsx +18 -3
- package/src/i18n/known-errors.ts +12 -0
- package/src/lib/action-run-tracking.ts +1 -0
- package/src/lib/actions.ts +2 -0
- package/src/lib/configuration-reference.mjs +1 -1
- package/src/locales/de/messages.po +32 -0
- package/src/locales/en/messages.po +32 -0
- package/src/locales/es/messages.po +32 -0
- package/src/locales/fr/messages.po +32 -0
- package/src/locales/ja/messages.po +32 -0
- package/src/locales/pt-BR/messages.po +32 -0
- package/src/locales/zh-CN/messages.po +32 -0
- package/src/routes/github.$owner.$repo.$branch.collection.$name_.entry.$.tsx +10 -5
- package/src/server/actions/actions.ts +115 -128
- package/src/server/github/api.ts +15 -26
- package/src/server/repository/provider.ts +1 -7
- package/src/server/services/actions.ts +9 -2
|
@@ -408,6 +408,10 @@ msgstr "“{value0}” expirou"
|
|
|
408
408
|
msgid "“{value0}” was cancelled"
|
|
409
409
|
msgstr "“{value0}” foi cancelado"
|
|
410
410
|
|
|
411
|
+
#: known-errors.ts
|
|
412
|
+
msgid "“{value0}” was sent to GitHub. Run status is unavailable."
|
|
413
|
+
msgstr "“{value0}” foi enviado ao GitHub. O status da execução está indisponível."
|
|
414
|
+
|
|
411
415
|
#: known-errors.ts
|
|
412
416
|
msgid "“{value0}” was skipped"
|
|
413
417
|
msgstr "“{value0}” foi ignorado"
|
|
@@ -821,6 +825,10 @@ msgstr "Ações"
|
|
|
821
825
|
msgid "Actions for {0}"
|
|
822
826
|
msgstr "Ações para {0}"
|
|
823
827
|
|
|
828
|
+
#: ../features/repository/overview-draft-actions.tsx
|
|
829
|
+
msgid "Actions for {title}"
|
|
830
|
+
msgstr "Ações para {title}"
|
|
831
|
+
|
|
824
832
|
#. placeholder {0}: run.id
|
|
825
833
|
#: ../features/admin/actions-page.tsx
|
|
826
834
|
msgid "Actions for run {0}"
|
|
@@ -1701,6 +1709,7 @@ msgid "Could not delete your account. Try again."
|
|
|
1701
1709
|
msgstr "Não foi possível excluir sua conta. Tente novamente."
|
|
1702
1710
|
|
|
1703
1711
|
#: ../features/drafts/draft-discard-dialog.tsx
|
|
1712
|
+
#: ../features/drafts/saved-draft-menu.tsx
|
|
1704
1713
|
msgid "Could not discard this draft."
|
|
1705
1714
|
msgstr "Não foi possível descartar este rascunho."
|
|
1706
1715
|
|
|
@@ -1708,6 +1717,10 @@ msgstr "Não foi possível descartar este rascunho."
|
|
|
1708
1717
|
msgid "Could not disconnect the GitHub account."
|
|
1709
1718
|
msgstr "Não foi possível desconectar a conta GitHub."
|
|
1710
1719
|
|
|
1720
|
+
#: ../features/drafts/saved-draft-menu.tsx
|
|
1721
|
+
msgid "Could not download this draft."
|
|
1722
|
+
msgstr "Não foi possível baixar este rascunho."
|
|
1723
|
+
|
|
1711
1724
|
#: ../features/drafts/use-duplicate-entry.ts
|
|
1712
1725
|
msgid "Could not duplicate entry."
|
|
1713
1726
|
msgstr "Não foi possível duplicar a entrada."
|
|
@@ -2210,6 +2223,7 @@ msgstr "Descartar"
|
|
|
2210
2223
|
|
|
2211
2224
|
#: ../features/drafts/draft-discard-dialog.tsx
|
|
2212
2225
|
#: ../features/drafts/draft-save-button.tsx
|
|
2226
|
+
#: ../features/drafts/saved-draft-menu.tsx
|
|
2213
2227
|
msgid "Discard draft"
|
|
2214
2228
|
msgstr "Descartar rascunho"
|
|
2215
2229
|
|
|
@@ -2269,6 +2283,7 @@ msgstr "Baixar"
|
|
|
2269
2283
|
#~ msgstr "Baixe uma cópia do seu rascunho."
|
|
2270
2284
|
|
|
2271
2285
|
#: ../features/drafts/draft-save-button.tsx
|
|
2286
|
+
#: ../features/drafts/saved-draft-menu.tsx
|
|
2272
2287
|
msgid "Download draft"
|
|
2273
2288
|
msgstr "Baixar rascunho"
|
|
2274
2289
|
|
|
@@ -3669,6 +3684,10 @@ msgstr "Gerenciar"
|
|
|
3669
3684
|
msgid "Manage accounts"
|
|
3670
3685
|
msgstr "Gerenciar contas"
|
|
3671
3686
|
|
|
3687
|
+
#: ../features/content/unavailable-entry.tsx
|
|
3688
|
+
msgid "Manage draft"
|
|
3689
|
+
msgstr "Gerenciar rascunho"
|
|
3690
|
+
|
|
3672
3691
|
#: ../features/dashboard/repository-selector.tsx
|
|
3673
3692
|
msgid "Manage repository access"
|
|
3674
3693
|
msgstr "Gerenciar o acesso ao repositório"
|
|
@@ -4753,6 +4772,11 @@ msgstr "Executar ação"
|
|
|
4753
4772
|
msgid "Run again"
|
|
4754
4773
|
msgstr "Executar novamente"
|
|
4755
4774
|
|
|
4775
|
+
#: ../features/admin/action-run-status.tsx
|
|
4776
|
+
#: known-errors.ts
|
|
4777
|
+
msgid "Run status unavailable"
|
|
4778
|
+
msgstr "Status da execução indisponível"
|
|
4779
|
+
|
|
4756
4780
|
#: known-errors.ts
|
|
4757
4781
|
msgid "Runtime environment is invalid"
|
|
4758
4782
|
msgstr "O ambiente de execução é inválido"
|
|
@@ -5493,6 +5517,10 @@ msgstr "Esta operação já está em andamento."
|
|
|
5493
5517
|
msgid "This page does not exist in this project. It may have been removed or renamed."
|
|
5494
5518
|
msgstr "Esta página não existe neste projeto. Ela pode ter sido removida ou renomeada."
|
|
5495
5519
|
|
|
5520
|
+
#: ../features/content/unavailable-entry.tsx
|
|
5521
|
+
#~ msgid "This page may have been moved or deleted. You still have a draft in this browser."
|
|
5522
|
+
#~ msgstr "Esta página pode ter sido movida ou excluída. Você ainda tem um rascunho neste navegador."
|
|
5523
|
+
|
|
5496
5524
|
#: known-errors.ts
|
|
5497
5525
|
msgid "This picture could not be read."
|
|
5498
5526
|
msgstr "Esta imagem não pôde ser lida."
|
|
@@ -5830,6 +5858,10 @@ msgstr "Você só pode cancelar as execuções de ações iniciadas por você"
|
|
|
5830
5858
|
msgid "You do not have permission to do this."
|
|
5831
5859
|
msgstr "Você não tem permissão para fazer isso."
|
|
5832
5860
|
|
|
5861
|
+
#: ../features/content/unavailable-entry.tsx
|
|
5862
|
+
msgid "You still have a draft in this browser."
|
|
5863
|
+
msgstr "Você ainda tem um rascunho neste navegador."
|
|
5864
|
+
|
|
5833
5865
|
#: ../features/account/account-deleted-notice.tsx
|
|
5834
5866
|
msgid "Your account has been deleted."
|
|
5835
5867
|
msgstr "Sua conta foi excluída."
|
|
@@ -408,6 +408,10 @@ msgstr "“{value0}”超时"
|
|
|
408
408
|
msgid "“{value0}” was cancelled"
|
|
409
409
|
msgstr "“{value0}”被取消"
|
|
410
410
|
|
|
411
|
+
#: known-errors.ts
|
|
412
|
+
msgid "“{value0}” was sent to GitHub. Run status is unavailable."
|
|
413
|
+
msgstr "“{value0}”已发送到 GitHub。运行状态不可用。"
|
|
414
|
+
|
|
411
415
|
#: known-errors.ts
|
|
412
416
|
msgid "“{value0}” was skipped"
|
|
413
417
|
msgstr "“{value0}”被跳过"
|
|
@@ -821,6 +825,10 @@ msgstr "操作"
|
|
|
821
825
|
msgid "Actions for {0}"
|
|
822
826
|
msgstr "{0} 的操作"
|
|
823
827
|
|
|
828
|
+
#: ../features/repository/overview-draft-actions.tsx
|
|
829
|
+
msgid "Actions for {title}"
|
|
830
|
+
msgstr "{title} 的操作"
|
|
831
|
+
|
|
824
832
|
#. placeholder {0}: run.id
|
|
825
833
|
#: ../features/admin/actions-page.tsx
|
|
826
834
|
msgid "Actions for run {0}"
|
|
@@ -1701,6 +1709,7 @@ msgid "Could not delete your account. Try again."
|
|
|
1701
1709
|
msgstr "无法删除您的账户。请重试。"
|
|
1702
1710
|
|
|
1703
1711
|
#: ../features/drafts/draft-discard-dialog.tsx
|
|
1712
|
+
#: ../features/drafts/saved-draft-menu.tsx
|
|
1704
1713
|
msgid "Could not discard this draft."
|
|
1705
1714
|
msgstr "无法丢弃此草稿。"
|
|
1706
1715
|
|
|
@@ -1708,6 +1717,10 @@ msgstr "无法丢弃此草稿。"
|
|
|
1708
1717
|
msgid "Could not disconnect the GitHub account."
|
|
1709
1718
|
msgstr "无法断开 GitHub 账户的连接。"
|
|
1710
1719
|
|
|
1720
|
+
#: ../features/drafts/saved-draft-menu.tsx
|
|
1721
|
+
msgid "Could not download this draft."
|
|
1722
|
+
msgstr "无法下载此草稿。"
|
|
1723
|
+
|
|
1711
1724
|
#: ../features/drafts/use-duplicate-entry.ts
|
|
1712
1725
|
msgid "Could not duplicate entry."
|
|
1713
1726
|
msgstr "无法创建条目副本。"
|
|
@@ -2210,6 +2223,7 @@ msgstr "丢弃"
|
|
|
2210
2223
|
|
|
2211
2224
|
#: ../features/drafts/draft-discard-dialog.tsx
|
|
2212
2225
|
#: ../features/drafts/draft-save-button.tsx
|
|
2226
|
+
#: ../features/drafts/saved-draft-menu.tsx
|
|
2213
2227
|
msgid "Discard draft"
|
|
2214
2228
|
msgstr "丢弃草稿"
|
|
2215
2229
|
|
|
@@ -2269,6 +2283,7 @@ msgstr "下载"
|
|
|
2269
2283
|
#~ msgstr "下载草稿副本。"
|
|
2270
2284
|
|
|
2271
2285
|
#: ../features/drafts/draft-save-button.tsx
|
|
2286
|
+
#: ../features/drafts/saved-draft-menu.tsx
|
|
2272
2287
|
msgid "Download draft"
|
|
2273
2288
|
msgstr "下载草稿"
|
|
2274
2289
|
|
|
@@ -3669,6 +3684,10 @@ msgstr "管理"
|
|
|
3669
3684
|
msgid "Manage accounts"
|
|
3670
3685
|
msgstr "管理账户"
|
|
3671
3686
|
|
|
3687
|
+
#: ../features/content/unavailable-entry.tsx
|
|
3688
|
+
msgid "Manage draft"
|
|
3689
|
+
msgstr "管理草稿"
|
|
3690
|
+
|
|
3672
3691
|
#: ../features/dashboard/repository-selector.tsx
|
|
3673
3692
|
msgid "Manage repository access"
|
|
3674
3693
|
msgstr "管理仓库访问"
|
|
@@ -4753,6 +4772,11 @@ msgstr "运行操作"
|
|
|
4753
4772
|
msgid "Run again"
|
|
4754
4773
|
msgstr "再次运行"
|
|
4755
4774
|
|
|
4775
|
+
#: ../features/admin/action-run-status.tsx
|
|
4776
|
+
#: known-errors.ts
|
|
4777
|
+
msgid "Run status unavailable"
|
|
4778
|
+
msgstr "运行状态不可用"
|
|
4779
|
+
|
|
4756
4780
|
#: known-errors.ts
|
|
4757
4781
|
msgid "Runtime environment is invalid"
|
|
4758
4782
|
msgstr "运行环境无效"
|
|
@@ -5493,6 +5517,10 @@ msgstr "该操作已经在进行中。"
|
|
|
5493
5517
|
msgid "This page does not exist in this project. It may have been removed or renamed."
|
|
5494
5518
|
msgstr "该页面在该项目中不存在。它可能已被删除或重命名。"
|
|
5495
5519
|
|
|
5520
|
+
#: ../features/content/unavailable-entry.tsx
|
|
5521
|
+
#~ msgid "This page may have been moved or deleted. You still have a draft in this browser."
|
|
5522
|
+
#~ msgstr "此页面可能已移动或删除。此浏览器中仍有一份草稿。"
|
|
5523
|
+
|
|
5496
5524
|
#: known-errors.ts
|
|
5497
5525
|
msgid "This picture could not be read."
|
|
5498
5526
|
msgstr "无法读取此图片。"
|
|
@@ -5830,6 +5858,10 @@ msgstr "您只能取消自己发起的操作运行"
|
|
|
5830
5858
|
msgid "You do not have permission to do this."
|
|
5831
5859
|
msgstr "您无权执行此操作。"
|
|
5832
5860
|
|
|
5861
|
+
#: ../features/content/unavailable-entry.tsx
|
|
5862
|
+
msgid "You still have a draft in this browser."
|
|
5863
|
+
msgstr "此浏览器中仍有一份草稿。"
|
|
5864
|
+
|
|
5833
5865
|
#: ../features/account/account-deleted-notice.tsx
|
|
5834
5866
|
msgid "Your account has been deleted."
|
|
5835
5867
|
msgstr "您的账户已被删除。"
|
|
@@ -2,10 +2,7 @@ import { msg } from '@lingui/core/macro'
|
|
|
2
2
|
import { translateMessage } from '#/i18n/message'
|
|
3
3
|
|
|
4
4
|
import { requireRepositoryResource } from '#/features/repository/repository-route-resource'
|
|
5
|
-
import {
|
|
6
|
-
RepositoryNotFound,
|
|
7
|
-
RepositoryError,
|
|
8
|
-
} from '#/features/repository/repository-route-state'
|
|
5
|
+
import { RepositoryError } from '#/features/repository/repository-route-state'
|
|
9
6
|
import { useRepositoryCoordinates } from '#/hooks/use-repository-coordinates'
|
|
10
7
|
import { pageTitle } from '#/lib/page-title'
|
|
11
8
|
import { createFileRoute, redirect } from '@tanstack/react-router'
|
|
@@ -13,6 +10,7 @@ import { useSuspenseQuery } from '@tanstack/react-query'
|
|
|
13
10
|
|
|
14
11
|
import { ContentEntryEditor } from '#/components/content-entry-editor'
|
|
15
12
|
import { ContentEntrySkeleton } from '#/components/content-entry-skeleton'
|
|
13
|
+
import { UnavailableEntry } from '#/features/content/unavailable-entry'
|
|
16
14
|
import { getSignInUrl } from '#/lib/auth-redirect'
|
|
17
15
|
import { entryQueryOptions } from '#/client/queries/content'
|
|
18
16
|
|
|
@@ -48,7 +46,7 @@ export const Route = createFileRoute(
|
|
|
48
46
|
pendingMs: 100,
|
|
49
47
|
pendingMinMs: 0,
|
|
50
48
|
pendingComponent: ContentEntrySkeleton,
|
|
51
|
-
notFoundComponent:
|
|
49
|
+
notFoundComponent: CollectionEntryNotFound,
|
|
52
50
|
errorComponent: RepositoryError,
|
|
53
51
|
component: CollectionEntryEditor,
|
|
54
52
|
head: ({ params, loaderData, matches, match }) =>
|
|
@@ -71,6 +69,13 @@ export const Route = createFileRoute(
|
|
|
71
69
|
),
|
|
72
70
|
})
|
|
73
71
|
|
|
72
|
+
function CollectionEntryNotFound() {
|
|
73
|
+
const { _splat: path, ...coordinates } = useRepositoryCoordinates(
|
|
74
|
+
Route.useParams(),
|
|
75
|
+
)
|
|
76
|
+
return <UnavailableEntry coordinates={{ ...coordinates, path }} />
|
|
77
|
+
}
|
|
78
|
+
|
|
74
79
|
function CollectionEntryEditor() {
|
|
75
80
|
const params = useRepositoryCoordinates(Route.useParams())
|
|
76
81
|
const path = params._splat!
|
|
@@ -2,6 +2,7 @@ import { configurationStoreFor } from '#/server/cache/configuration-access'
|
|
|
2
2
|
import { UserError } from '#/server/http'
|
|
3
3
|
|
|
4
4
|
import {
|
|
5
|
+
actionRunTrackingUnavailable,
|
|
5
6
|
repositoryActions,
|
|
6
7
|
resolveActionRef,
|
|
7
8
|
schemaActions,
|
|
@@ -20,6 +21,7 @@ import { DEFAULT_REPOSITORY_SOURCE } from '../repository/provider'
|
|
|
20
21
|
import { requireRepositoryManager } from '#/server/access/repository-policy'
|
|
21
22
|
|
|
22
23
|
import type { Database } from '#/server/db/client'
|
|
24
|
+
import type { RepositoryApi } from '../repository/provider'
|
|
23
25
|
import type { RepositoryUser } from '../repository/repositories'
|
|
24
26
|
import type { RepositoryAccessService } from '#/server/access/repository'
|
|
25
27
|
|
|
@@ -81,6 +83,8 @@ const actionColumns = `id, repository_id AS repositoryId, owner, repo, ref,
|
|
|
81
83
|
workflow, workflow_run_id AS workflowRunId, status, conclusion, html_url AS htmlUrl,
|
|
82
84
|
triggered_by AS triggeredBy, failure, payload, created_at AS createdAt,
|
|
83
85
|
updated_at AS updatedAt, checked_at AS checkedAt, completed_at AS completedAt`
|
|
86
|
+
const statusCheckInterval = 120_000
|
|
87
|
+
const dispatchTrackingTimeout = 120_000
|
|
84
88
|
|
|
85
89
|
function actionRun(row: StoredActionRun): ActionRun {
|
|
86
90
|
return {
|
|
@@ -95,6 +99,49 @@ function actionRun(row: StoredActionRun): ActionRun {
|
|
|
95
99
|
}
|
|
96
100
|
}
|
|
97
101
|
|
|
102
|
+
async function selectActionRuns(
|
|
103
|
+
database: Database,
|
|
104
|
+
sql: string,
|
|
105
|
+
args: Parameters<typeof all>[2],
|
|
106
|
+
) {
|
|
107
|
+
const rows = (await all<StoredActionRun>(database, sql, args)).map(actionRun)
|
|
108
|
+
const now = Date.now()
|
|
109
|
+
const cutoff = now - dispatchTrackingTimeout
|
|
110
|
+
const untracked = rows
|
|
111
|
+
.filter(
|
|
112
|
+
(row) =>
|
|
113
|
+
row.workflowRunId === null &&
|
|
114
|
+
row.status !== 'completed' &&
|
|
115
|
+
(row.status !== 'dispatching' || row.createdAt.getTime() <= cutoff),
|
|
116
|
+
)
|
|
117
|
+
.map((row) => row.id)
|
|
118
|
+
if (!untracked.length) return rows
|
|
119
|
+
|
|
120
|
+
// Finish tracking legacy rows in place. A dispatch still in flight can
|
|
121
|
+
// record its exact ID when the response arrives.
|
|
122
|
+
const [result] = await executeAtomic(database, [
|
|
123
|
+
{
|
|
124
|
+
sql: `UPDATE action_run SET status = 'completed', conclusion = ?, updated_at = ?
|
|
125
|
+
WHERE id IN (SELECT value FROM json_each(?)) AND workflow_run_id IS NULL
|
|
126
|
+
AND status <> 'completed' AND (status <> 'dispatching' OR created_at <= ?)
|
|
127
|
+
RETURNING ${actionColumns}`,
|
|
128
|
+
args: [
|
|
129
|
+
actionRunTrackingUnavailable,
|
|
130
|
+
now,
|
|
131
|
+
JSON.stringify(untracked),
|
|
132
|
+
cutoff,
|
|
133
|
+
],
|
|
134
|
+
},
|
|
135
|
+
])
|
|
136
|
+
const updated = new Map(
|
|
137
|
+
result.rows.map((row) => {
|
|
138
|
+
const run = actionRun(row as StoredActionRun)
|
|
139
|
+
return [run.id, run]
|
|
140
|
+
}),
|
|
141
|
+
)
|
|
142
|
+
return rows.map((row) => updated.get(row.id) ?? row)
|
|
143
|
+
}
|
|
144
|
+
|
|
98
145
|
function actionRepository(
|
|
99
146
|
input: Pick<ActionInput, 'owner' | 'repo' | 'repoId'>,
|
|
100
147
|
) {
|
|
@@ -153,11 +200,35 @@ async function failActionRun(database: Database, id: number, error: unknown) {
|
|
|
153
200
|
])
|
|
154
201
|
}
|
|
155
202
|
|
|
156
|
-
async function
|
|
203
|
+
async function startActionRun(
|
|
204
|
+
database: Database,
|
|
205
|
+
api: RepositoryApi,
|
|
206
|
+
run: ActionRun,
|
|
207
|
+
) {
|
|
208
|
+
const dispatched = await api
|
|
209
|
+
.dispatchWorkflow({
|
|
210
|
+
owner: run.owner,
|
|
211
|
+
repo: run.repo,
|
|
212
|
+
workflow: run.workflow,
|
|
213
|
+
ref: run.workflowRef,
|
|
214
|
+
inputs: { payload: JSON.stringify(run.payload) },
|
|
215
|
+
})
|
|
216
|
+
.catch(async (error: unknown) => {
|
|
217
|
+
await failActionRun(database, run.id, error)
|
|
218
|
+
throw error
|
|
219
|
+
})
|
|
157
220
|
const [result] = await executeAtomic(database, [
|
|
158
221
|
{
|
|
159
|
-
sql: `UPDATE action_run SET
|
|
160
|
-
|
|
222
|
+
sql: `UPDATE action_run SET workflow_run_id = ?, html_url = ?, status = ?, conclusion = ?, updated_at = ?
|
|
223
|
+
WHERE id = ? RETURNING ${actionColumns}`,
|
|
224
|
+
args: [
|
|
225
|
+
dispatched?.id ?? null,
|
|
226
|
+
dispatched?.htmlUrl ?? null,
|
|
227
|
+
dispatched ? 'queued' : 'completed',
|
|
228
|
+
dispatched ? null : actionRunTrackingUnavailable,
|
|
229
|
+
Date.now(),
|
|
230
|
+
run.id,
|
|
231
|
+
],
|
|
161
232
|
},
|
|
162
233
|
])
|
|
163
234
|
return result.rows[0] ? actionRun(result.rows[0] as StoredActionRun) : run
|
|
@@ -279,7 +350,9 @@ function summary(
|
|
|
279
350
|
((row.payload as { action?: { cancelable?: boolean } }).action
|
|
280
351
|
?.cancelable ??
|
|
281
352
|
true),
|
|
282
|
-
canRerun:
|
|
353
|
+
canRerun:
|
|
354
|
+
row.conclusion !== actionRunTrackingUnavailable &&
|
|
355
|
+
(isRepositoryManager || allowCollaboratorRerun),
|
|
283
356
|
createdAt: row.createdAt.toISOString(),
|
|
284
357
|
updatedAt: row.updatedAt.toISOString(),
|
|
285
358
|
completedAt: row.completedAt?.toISOString() ?? null,
|
|
@@ -291,73 +364,23 @@ async function syncActionRun(
|
|
|
291
364
|
api: Awaited<ReturnType<RepositoryAccessService['resolve']>>['api'],
|
|
292
365
|
row: typeof actionRunTable.$inferSelect,
|
|
293
366
|
) {
|
|
294
|
-
if (row.status === 'completed') return row
|
|
295
|
-
const interval = row.workflowRunId === null ? 30_000 : 120_000
|
|
367
|
+
if (row.status === 'completed' || row.workflowRunId === null) return row
|
|
296
368
|
const now = new Date()
|
|
297
|
-
if (
|
|
369
|
+
if (
|
|
370
|
+
row.checkedAt &&
|
|
371
|
+
now.getTime() - row.checkedAt.getTime() < statusCheckInterval
|
|
372
|
+
)
|
|
298
373
|
return row
|
|
299
374
|
// A database lease prevents different requests/Workers from repeating the same GitHub check.
|
|
300
375
|
const [lease] = await executeAtomic(input.database, [
|
|
301
376
|
{
|
|
302
377
|
sql: `UPDATE action_run SET checked_at = ? WHERE id = ? AND status <> 'completed'
|
|
303
378
|
AND (checked_at IS NULL OR checked_at < ?) RETURNING id`,
|
|
304
|
-
args: [now.getTime(), row.id, now.getTime() -
|
|
379
|
+
args: [now.getTime(), row.id, now.getTime() - statusCheckInterval],
|
|
305
380
|
},
|
|
306
381
|
])
|
|
307
382
|
if (!lease.rows.length) return row
|
|
308
383
|
try {
|
|
309
|
-
if (row.workflowRunId === null) {
|
|
310
|
-
const claimedRows = await all<{ workflowRunId: number }>(
|
|
311
|
-
input.database,
|
|
312
|
-
`SELECT workflow_run_id AS workflowRunId FROM action_run
|
|
313
|
-
WHERE repository_id = ? AND workflow = ? AND workflow_ref = ?
|
|
314
|
-
AND workflow_run_id IS NOT NULL AND id != ?`,
|
|
315
|
-
[row.repositoryId, row.workflow, row.workflowRef, row.id],
|
|
316
|
-
)
|
|
317
|
-
const claimed = new Set(claimedRows.map((value) => value.workflowRunId))
|
|
318
|
-
const startedAt = row.createdAt.getTime() - 30_000
|
|
319
|
-
const workflowRun = (
|
|
320
|
-
await api.listWorkflowRuns({
|
|
321
|
-
owner: input.owner,
|
|
322
|
-
repo: input.repo,
|
|
323
|
-
workflow: row.workflow,
|
|
324
|
-
ref: row.workflowRef,
|
|
325
|
-
})
|
|
326
|
-
)
|
|
327
|
-
.filter(
|
|
328
|
-
(value) =>
|
|
329
|
-
Date.parse(value.createdAt) >= startedAt && !claimed.has(value.id),
|
|
330
|
-
)
|
|
331
|
-
.sort(
|
|
332
|
-
(left, right) =>
|
|
333
|
-
Date.parse(right.createdAt) - Date.parse(left.createdAt),
|
|
334
|
-
)
|
|
335
|
-
.at(0)
|
|
336
|
-
if (!workflowRun) return row
|
|
337
|
-
const [updated] = await executeAtomic(input.database, [
|
|
338
|
-
{
|
|
339
|
-
sql: `UPDATE action_run SET workflow_run_id = ?, status = ?, conclusion = ?, html_url = ?,
|
|
340
|
-
updated_at = ?, completed_at = ? WHERE id = ? AND checked_at = ?
|
|
341
|
-
AND status <> 'completed' RETURNING ${actionColumns}`,
|
|
342
|
-
args: [
|
|
343
|
-
workflowRun.id,
|
|
344
|
-
workflowRun.status,
|
|
345
|
-
workflowRun.conclusion,
|
|
346
|
-
workflowRun.htmlUrl,
|
|
347
|
-
Date.now(),
|
|
348
|
-
workflowRun.status === 'completed'
|
|
349
|
-
? new Date(workflowRun.updatedAt).getTime()
|
|
350
|
-
: null,
|
|
351
|
-
row.id,
|
|
352
|
-
now.getTime(),
|
|
353
|
-
],
|
|
354
|
-
},
|
|
355
|
-
])
|
|
356
|
-
return updated.rows[0]
|
|
357
|
-
? actionRun(updated.rows[0] as StoredActionRun)
|
|
358
|
-
: row
|
|
359
|
-
}
|
|
360
|
-
|
|
361
384
|
const workflowRun = await api.getWorkflowRun(
|
|
362
385
|
row.owner,
|
|
363
386
|
row.repo,
|
|
@@ -391,21 +414,18 @@ export async function readActionRunStatuses(
|
|
|
391
414
|
input: ActionInput & { runIds: number[]; isRepositoryManager?: boolean },
|
|
392
415
|
) {
|
|
393
416
|
const repository = actionRepository(input)
|
|
394
|
-
const rows = (
|
|
395
|
-
|
|
396
|
-
|
|
397
|
-
`SELECT ${actionColumns} FROM action_run WHERE repository_id = ${repository.sql}
|
|
417
|
+
const rows = await selectActionRuns(
|
|
418
|
+
input.database,
|
|
419
|
+
`SELECT ${actionColumns} FROM action_run WHERE repository_id = ${repository.sql}
|
|
398
420
|
AND ref = ? AND id IN (SELECT value FROM json_each(?))`,
|
|
399
|
-
|
|
400
|
-
|
|
401
|
-
).map(actionRun)
|
|
421
|
+
[...repository.args, input.branch, JSON.stringify(input.runIds)],
|
|
422
|
+
)
|
|
402
423
|
const now = Date.now()
|
|
403
424
|
const due = rows.filter(
|
|
404
425
|
(row) =>
|
|
405
426
|
row.status !== 'completed' &&
|
|
406
|
-
|
|
407
|
-
|
|
408
|
-
(row.workflowRunId === null ? 30_000 : 120_000)),
|
|
427
|
+
row.workflowRunId !== null &&
|
|
428
|
+
(!row.checkedAt || now - row.checkedAt.getTime() >= statusCheckInterval),
|
|
409
429
|
)
|
|
410
430
|
const updates = new Map<number, (typeof rows)[number]>()
|
|
411
431
|
if (due.length) {
|
|
@@ -416,7 +436,6 @@ export async function readActionRunStatuses(
|
|
|
416
436
|
input.branch,
|
|
417
437
|
input.repoId,
|
|
418
438
|
)
|
|
419
|
-
// Sequential discovery also avoids competing pending runs claiming the same workflow.
|
|
420
439
|
for (const row of due.slice(0, 20))
|
|
421
440
|
updates.set(row.id, await syncActionRun(input, api, row))
|
|
422
441
|
}
|
|
@@ -440,7 +459,7 @@ export async function loadRecentActionRuns(
|
|
|
440
459
|
if (!actions.some((action) => action.name === input.actionName))
|
|
441
460
|
throw new UserError('Action is not configured for this context')
|
|
442
461
|
const repository = actionRepository(input)
|
|
443
|
-
const rows = await
|
|
462
|
+
const rows = await selectActionRuns(
|
|
444
463
|
input.database,
|
|
445
464
|
`SELECT ${actionColumns} FROM action_run WHERE repository_id = ${repository.sql}
|
|
446
465
|
AND ref = ? AND action_name = ? AND context_type = ? AND context_name IS ? AND context_path IS ?
|
|
@@ -456,7 +475,7 @@ export async function loadRecentActionRuns(
|
|
|
456
475
|
)
|
|
457
476
|
const runs = []
|
|
458
477
|
for (const stored of rows) {
|
|
459
|
-
const row = await syncActionRun(input, api,
|
|
478
|
+
const row = await syncActionRun(input, api, stored)
|
|
460
479
|
const { id, status, conclusion, createdAt, triggeredBy } = summary(
|
|
461
480
|
row,
|
|
462
481
|
input.user,
|
|
@@ -473,19 +492,13 @@ export async function loadRepositoryActions(
|
|
|
473
492
|
const { actions, api, tokenSource } = await actionContext(input)
|
|
474
493
|
if (input.includeRuns === false) return { actions, runs: [] }
|
|
475
494
|
const repository = actionRepository(input)
|
|
476
|
-
const rows = (
|
|
477
|
-
|
|
478
|
-
|
|
479
|
-
`SELECT ${actionColumns} FROM action_run WHERE repository_id = ${repository.sql}
|
|
495
|
+
const rows = await selectActionRuns(
|
|
496
|
+
input.database,
|
|
497
|
+
`SELECT ${actionColumns} FROM action_run WHERE repository_id = ${repository.sql}
|
|
480
498
|
AND ref = ? ${input.action ? 'AND action_name = ?' : ''}
|
|
481
499
|
ORDER BY created_at DESC, id DESC LIMIT 100`,
|
|
482
|
-
|
|
483
|
-
|
|
484
|
-
input.branch,
|
|
485
|
-
...(input.action ? [input.action] : []),
|
|
486
|
-
],
|
|
487
|
-
)
|
|
488
|
-
).map(actionRun)
|
|
500
|
+
[...repository.args, input.branch, ...(input.action ? [input.action] : [])],
|
|
501
|
+
)
|
|
489
502
|
const synchronized = new Map<number, (typeof rows)[number]>()
|
|
490
503
|
const identifiedActiveRows = rows
|
|
491
504
|
.filter((row) => row.status !== 'completed' && row.workflowRunId !== null)
|
|
@@ -495,15 +508,6 @@ export async function loadRepositoryActions(
|
|
|
495
508
|
)
|
|
496
509
|
for (const row of identifiedUpdates) synchronized.set(row.id, row)
|
|
497
510
|
|
|
498
|
-
const unidentifiedActiveRows = rows
|
|
499
|
-
.filter((row) => row.status !== 'completed' && row.workflowRunId === null)
|
|
500
|
-
.slice(0, 10)
|
|
501
|
-
// Keep discovery sequential so concurrent local runs cannot claim the same
|
|
502
|
-
// GitHub workflow run. Known run IDs are safe to refresh in parallel above.
|
|
503
|
-
for (const row of unidentifiedActiveRows) {
|
|
504
|
-
const updated = await syncActionRun(input, api, row)
|
|
505
|
-
synchronized.set(updated.id, updated)
|
|
506
|
-
}
|
|
507
511
|
return {
|
|
508
512
|
actions,
|
|
509
513
|
runs: rows.map((row) =>
|
|
@@ -580,23 +584,11 @@ export async function dispatchRepositoryAction(
|
|
|
580
584
|
createdAt: timestamp,
|
|
581
585
|
updatedAt: timestamp,
|
|
582
586
|
})
|
|
583
|
-
|
|
584
|
-
await api
|
|
585
|
-
|
|
586
|
-
|
|
587
|
-
|
|
588
|
-
ref: workflowRef,
|
|
589
|
-
inputs: { payload: JSON.stringify(payload) },
|
|
590
|
-
})
|
|
591
|
-
return summary(
|
|
592
|
-
await queueActionRun(input.database, run),
|
|
593
|
-
input.user,
|
|
594
|
-
tokenSource === 'user',
|
|
595
|
-
)
|
|
596
|
-
} catch (error) {
|
|
597
|
-
await failActionRun(input.database, run.id, error)
|
|
598
|
-
throw error
|
|
599
|
-
}
|
|
587
|
+
return summary(
|
|
588
|
+
await startActionRun(input.database, api, run),
|
|
589
|
+
input.user,
|
|
590
|
+
tokenSource === 'user',
|
|
591
|
+
)
|
|
600
592
|
}
|
|
601
593
|
|
|
602
594
|
export async function manageRepositoryAction(
|
|
@@ -621,6 +613,13 @@ export async function manageRepositoryAction(
|
|
|
621
613
|
)
|
|
622
614
|
const row = stored && actionRun(stored)
|
|
623
615
|
if (!row) throw new UserError('Action run not found')
|
|
616
|
+
if (
|
|
617
|
+
input.intent === 'rerun' &&
|
|
618
|
+
row.workflowRunId === null &&
|
|
619
|
+
(row.status !== 'completed' ||
|
|
620
|
+
row.conclusion === actionRunTrackingUnavailable)
|
|
621
|
+
)
|
|
622
|
+
throw new UserError('Run status unavailable')
|
|
624
623
|
if (admission.tokenSource === 'installation') {
|
|
625
624
|
const configured = await actionContext(input, {
|
|
626
625
|
type: row.contextType as RepositoryActionContext['type'],
|
|
@@ -739,24 +738,12 @@ export async function manageRepositoryAction(
|
|
|
739
738
|
createdAt: timestamp,
|
|
740
739
|
updatedAt: timestamp,
|
|
741
740
|
})
|
|
742
|
-
|
|
743
|
-
await api
|
|
744
|
-
|
|
745
|
-
|
|
746
|
-
|
|
747
|
-
|
|
748
|
-
inputs: { payload: JSON.stringify(payload) },
|
|
749
|
-
})
|
|
750
|
-
return summary(
|
|
751
|
-
await queueActionRun(input.database, created),
|
|
752
|
-
input.user,
|
|
753
|
-
admission.tokenSource === 'user',
|
|
754
|
-
input.allowCollaboratorExecution,
|
|
755
|
-
)
|
|
756
|
-
} catch (error) {
|
|
757
|
-
await failActionRun(input.database, created.id, error)
|
|
758
|
-
throw error
|
|
759
|
-
}
|
|
741
|
+
return summary(
|
|
742
|
+
await startActionRun(input.database, api, created),
|
|
743
|
+
input.user,
|
|
744
|
+
admission.tokenSource === 'user',
|
|
745
|
+
input.allowCollaboratorExecution,
|
|
746
|
+
)
|
|
760
747
|
}
|
|
761
748
|
|
|
762
749
|
export async function readActionRunName(
|
package/src/server/github/api.ts
CHANGED
|
@@ -1263,40 +1263,29 @@ export function createGitHubApi(
|
|
|
1263
1263
|
ref: string
|
|
1264
1264
|
inputs: Record<string, string>
|
|
1265
1265
|
}) {
|
|
1266
|
-
await githubRequest(
|
|
1266
|
+
const result = await githubRequest(
|
|
1267
1267
|
fetcher,
|
|
1268
1268
|
token,
|
|
1269
1269
|
`${repoEndpoint(input.owner, input.repo)}/actions/workflows/${encodeURIComponent(input.workflow)}/dispatches`,
|
|
1270
1270
|
{
|
|
1271
1271
|
method: 'POST',
|
|
1272
1272
|
headers: { 'content-type': 'application/json' },
|
|
1273
|
-
body: JSON.stringify({
|
|
1273
|
+
body: JSON.stringify({
|
|
1274
|
+
ref: input.ref,
|
|
1275
|
+
inputs: input.inputs,
|
|
1276
|
+
return_run_details: true,
|
|
1277
|
+
}),
|
|
1274
1278
|
},
|
|
1275
1279
|
)
|
|
1276
|
-
|
|
1277
|
-
|
|
1278
|
-
|
|
1279
|
-
|
|
1280
|
-
|
|
1281
|
-
|
|
1282
|
-
|
|
1283
|
-
|
|
1284
|
-
|
|
1285
|
-
branch: input.ref,
|
|
1286
|
-
event: 'workflow_dispatch',
|
|
1287
|
-
per_page: '10',
|
|
1288
|
-
})
|
|
1289
|
-
const body = requiredRecord(
|
|
1290
|
-
await githubRequest(
|
|
1291
|
-
fetcher,
|
|
1292
|
-
token,
|
|
1293
|
-
`${repoEndpoint(input.owner, input.repo)}/actions/workflows/${encodeURIComponent(input.workflow)}/runs?${query}`,
|
|
1294
|
-
),
|
|
1295
|
-
'workflow runs',
|
|
1296
|
-
)
|
|
1297
|
-
return (Array.isArray(body.workflow_runs) ? body.workflow_runs : []).map(
|
|
1298
|
-
parseWorkflowRun,
|
|
1299
|
-
)
|
|
1280
|
+
// An empty success response still means GitHub accepted the dispatch.
|
|
1281
|
+
if (!isRecord(result)) return null
|
|
1282
|
+
const id = result.workflow_run_id
|
|
1283
|
+
if (typeof id !== 'number' || !Number.isSafeInteger(id) || id <= 0)
|
|
1284
|
+
return null
|
|
1285
|
+
return {
|
|
1286
|
+
id,
|
|
1287
|
+
htmlUrl: typeof result.html_url === 'string' ? result.html_url : null,
|
|
1288
|
+
}
|
|
1300
1289
|
},
|
|
1301
1290
|
|
|
1302
1291
|
async getWorkflowRun(owner: string, repo: string, runId: number) {
|
|
@@ -180,13 +180,7 @@ export interface RepositoryApi {
|
|
|
180
180
|
workflow: string
|
|
181
181
|
ref: string
|
|
182
182
|
inputs: Record<string, string>
|
|
183
|
-
}) => Promise<
|
|
184
|
-
listWorkflowRuns: (input: {
|
|
185
|
-
owner: string
|
|
186
|
-
repo: string
|
|
187
|
-
workflow: string
|
|
188
|
-
ref: string
|
|
189
|
-
}) => Promise<RepositoryWorkflowRun[]>
|
|
183
|
+
}) => Promise<Pick<RepositoryWorkflowRun, 'id' | 'htmlUrl'> | null>
|
|
190
184
|
getWorkflowRun: (
|
|
191
185
|
owner: string,
|
|
192
186
|
repo: string,
|