From e68b9d00a6e05b3a941f63ffb696f91e554ac5ec Mon Sep 17 00:00:00 2001 From: Daniel Baumann Date: Fri, 18 Oct 2024 20:33:49 +0200 Subject: Adding upstream version 9.0.3. Signed-off-by: Daniel Baumann --- web_src/js/bootstrap.js | 109 +++ web_src/js/bootstrap.test.js | 12 + web_src/js/components/.eslintrc.yaml | 21 + web_src/js/components/ActionRunStatus.vue | 39 + web_src/js/components/ActivityHeatmap.vue | 83 ++ web_src/js/components/ContextPopup.test.js | 163 ++++ web_src/js/components/ContextPopup.vue | 130 +++ web_src/js/components/DashboardRepoList.vue | 537 ++++++++++++ web_src/js/components/DiffCommitSelector.vue | 306 +++++++ web_src/js/components/DiffFileList.vue | 58 ++ web_src/js/components/DiffFileTree.vue | 144 ++++ web_src/js/components/DiffFileTreeItem.vue | 97 +++ web_src/js/components/PullRequestMergeForm.test.js | 34 + web_src/js/components/PullRequestMergeForm.vue | 252 ++++++ web_src/js/components/RepoActionView.test.js | 105 +++ web_src/js/components/RepoActionView.vue | 905 +++++++++++++++++++++ web_src/js/components/RepoActivityTopAuthors.vue | 164 ++++ web_src/js/components/RepoBranchTagSelector.vue | 357 ++++++++ web_src/js/components/RepoCodeFrequency.vue | 172 ++++ web_src/js/components/RepoContributors.vue | 431 ++++++++++ web_src/js/components/RepoRecentCommits.vue | 149 ++++ .../js/components/ScopedAccessTokenSelector.vue | 115 +++ web_src/js/features/admin/common.js | 258 ++++++ web_src/js/features/admin/config.js | 24 + web_src/js/features/admin/emails.js | 14 + web_src/js/features/admin/users.js | 39 + web_src/js/features/autofocus-end.js | 6 + web_src/js/features/captcha.js | 51 ++ web_src/js/features/citation.js | 50 ++ web_src/js/features/clipboard.js | 32 + web_src/js/features/code-frequency.js | 21 + web_src/js/features/codeeditor.js | 191 +++++ web_src/js/features/colorpicker.js | 66 ++ web_src/js/features/common-global.js | 463 +++++++++++ web_src/js/features/common-issue-list.js | 68 ++ web_src/js/features/common-issue-list.test.js | 16 + web_src/js/features/common-organization.js | 16 + web_src/js/features/comp/ComboMarkdownEditor.js | 413 ++++++++++ web_src/js/features/comp/ConfirmModal.js | 30 + web_src/js/features/comp/EasyMDEToolbarActions.js | 152 ++++ web_src/js/features/comp/LabelEdit.js | 96 +++ web_src/js/features/comp/Paste.js | 144 ++++ web_src/js/features/comp/QuickSubmit.js | 17 + web_src/js/features/comp/ReactionSelector.js | 38 + web_src/js/features/comp/SearchUserBox.js | 51 ++ web_src/js/features/comp/TextExpander.js | 61 ++ web_src/js/features/comp/WebHookEditor.js | 28 + web_src/js/features/contextpopup.js | 43 + web_src/js/features/contributors.js | 29 + web_src/js/features/copycontent.js | 56 ++ web_src/js/features/dropzone.js | 7 + web_src/js/features/emoji.js | 38 + web_src/js/features/eventsource.sharedworker.js | 141 ++++ web_src/js/features/file-fold.js | 19 + web_src/js/features/heatmap.js | 40 + web_src/js/features/imagediff.js | 271 ++++++ web_src/js/features/install.js | 119 +++ web_src/js/features/notification.js | 192 +++++ web_src/js/features/org-team.js | 26 + web_src/js/features/pull-view-file.js | 96 +++ web_src/js/features/recent-commits.js | 21 + web_src/js/features/repo-branch.js | 42 + web_src/js/features/repo-code.js | 195 +++++ web_src/js/features/repo-code.test.js | 17 + web_src/js/features/repo-commit.js | 27 + web_src/js/features/repo-common.js | 83 ++ web_src/js/features/repo-diff-commit.js | 53 ++ web_src/js/features/repo-diff-commitselect.js | 10 + web_src/js/features/repo-diff-filetree.js | 17 + web_src/js/features/repo-diff.js | 232 ++++++ web_src/js/features/repo-editor.js | 203 +++++ web_src/js/features/repo-findfile.js | 117 +++ web_src/js/features/repo-findfile.test.js | 34 + web_src/js/features/repo-graph.js | 155 ++++ web_src/js/features/repo-home.js | 147 ++++ web_src/js/features/repo-issue-content.js | 154 ++++ web_src/js/features/repo-issue-list.js | 245 ++++++ web_src/js/features/repo-issue-pr-form.js | 10 + web_src/js/features/repo-issue-pr-status.js | 10 + web_src/js/features/repo-issue.js | 797 ++++++++++++++++++ web_src/js/features/repo-issue.test.js | 24 + web_src/js/features/repo-legacy.js | 610 ++++++++++++++ web_src/js/features/repo-migrate.js | 64 ++ web_src/js/features/repo-migration.js | 69 ++ web_src/js/features/repo-projects.js | 188 +++++ web_src/js/features/repo-release.js | 95 +++ web_src/js/features/repo-search.js | 22 + web_src/js/features/repo-settings.js | 120 +++ web_src/js/features/repo-template.js | 51 ++ web_src/js/features/repo-unicode-escape.js | 27 + web_src/js/features/repo-wiki.js | 89 ++ web_src/js/features/sshkey-helper.js | 10 + web_src/js/features/stopwatch.js | 167 ++++ web_src/js/features/tablesort.js | 22 + web_src/js/features/tribute.js | 57 ++ web_src/js/features/user-auth-webauthn.js | 194 +++++ web_src/js/features/user-auth.js | 22 + web_src/js/features/user-settings.js | 63 ++ web_src/js/htmx.js | 21 + web_src/js/index.js | 190 +++++ web_src/js/jquery.js | 3 + web_src/js/markup/anchors.js | 70 ++ web_src/js/markup/asciicast.js | 17 + web_src/js/markup/codecopy.js | 21 + web_src/js/markup/common.js | 8 + web_src/js/markup/content.js | 18 + web_src/js/markup/math.js | 47 ++ web_src/js/markup/mermaid.js | 74 ++ web_src/js/markup/tasklist.js | 90 ++ web_src/js/modules/dirauto.js | 40 + web_src/js/modules/fetch.js | 41 + web_src/js/modules/fetch.test.js | 10 + web_src/js/modules/fomantic.js | 34 + web_src/js/modules/fomantic/api.js | 40 + web_src/js/modules/fomantic/aria.md | 117 +++ web_src/js/modules/fomantic/base.js | 18 + web_src/js/modules/fomantic/checkbox.js | 13 + web_src/js/modules/fomantic/dropdown.js | 256 ++++++ web_src/js/modules/fomantic/form.js | 13 + web_src/js/modules/fomantic/modal.js | 28 + web_src/js/modules/fomantic/transition.js | 54 ++ web_src/js/modules/sortable.js | 19 + web_src/js/modules/stores.js | 10 + web_src/js/modules/tippy.js | 195 +++++ web_src/js/modules/toast.js | 55 ++ web_src/js/modules/toast.test.js | 16 + web_src/js/render/ansi.js | 45 + web_src/js/render/ansi.test.js | 20 + web_src/js/render/pdf.js | 19 + web_src/js/standalone/devtest.js | 11 + web_src/js/standalone/forgejo-swagger.js | 23 + web_src/js/standalone/swagger.js | 34 + web_src/js/svg.js | 228 ++++++ web_src/js/svg.test.js | 27 + web_src/js/utils.js | 144 ++++ web_src/js/utils.test.js | 189 +++++ web_src/js/utils/color.js | 33 + web_src/js/utils/color.test.js | 22 + web_src/js/utils/dom.js | 305 +++++++ web_src/js/utils/dom.test.js | 5 + web_src/js/utils/image.js | 47 ++ web_src/js/utils/image.test.js | 29 + web_src/js/utils/match.js | 43 + web_src/js/utils/match.test.js | 50 ++ web_src/js/utils/time.js | 72 ++ web_src/js/utils/time.test.js | 40 + web_src/js/utils/url.js | 15 + web_src/js/utils/url.test.js | 13 + web_src/js/vendor/jquery.are-you-sure.js | 195 +++++ web_src/js/vitest.setup.js | 18 + web_src/js/webcomponents/README.md | 11 + web_src/js/webcomponents/absolute-date.js | 40 + web_src/js/webcomponents/absolute-date.test.js | 15 + web_src/js/webcomponents/index.js | 5 + web_src/js/webcomponents/origin-url.js | 22 + web_src/js/webcomponents/origin-url.test.js | 17 + web_src/js/webcomponents/overflow-menu.js | 220 +++++ web_src/js/webcomponents/polyfills.js | 17 + 158 files changed, 15760 insertions(+) create mode 100644 web_src/js/bootstrap.js create mode 100644 web_src/js/bootstrap.test.js create mode 100644 web_src/js/components/.eslintrc.yaml create mode 100644 web_src/js/components/ActionRunStatus.vue create mode 100644 web_src/js/components/ActivityHeatmap.vue create mode 100644 web_src/js/components/ContextPopup.test.js create mode 100644 web_src/js/components/ContextPopup.vue create mode 100644 web_src/js/components/DashboardRepoList.vue create mode 100644 web_src/js/components/DiffCommitSelector.vue create mode 100644 web_src/js/components/DiffFileList.vue create mode 100644 web_src/js/components/DiffFileTree.vue create mode 100644 web_src/js/components/DiffFileTreeItem.vue create mode 100644 web_src/js/components/PullRequestMergeForm.test.js create mode 100644 web_src/js/components/PullRequestMergeForm.vue create mode 100644 web_src/js/components/RepoActionView.test.js create mode 100644 web_src/js/components/RepoActionView.vue create mode 100644 web_src/js/components/RepoActivityTopAuthors.vue create mode 100644 web_src/js/components/RepoBranchTagSelector.vue create mode 100644 web_src/js/components/RepoCodeFrequency.vue create mode 100644 web_src/js/components/RepoContributors.vue create mode 100644 web_src/js/components/RepoRecentCommits.vue create mode 100644 web_src/js/components/ScopedAccessTokenSelector.vue create mode 100644 web_src/js/features/admin/common.js create mode 100644 web_src/js/features/admin/config.js create mode 100644 web_src/js/features/admin/emails.js create mode 100644 web_src/js/features/admin/users.js create mode 100644 web_src/js/features/autofocus-end.js create mode 100644 web_src/js/features/captcha.js create mode 100644 web_src/js/features/citation.js create mode 100644 web_src/js/features/clipboard.js create mode 100644 web_src/js/features/code-frequency.js create mode 100644 web_src/js/features/codeeditor.js create mode 100644 web_src/js/features/colorpicker.js create mode 100644 web_src/js/features/common-global.js create mode 100644 web_src/js/features/common-issue-list.js create mode 100644 web_src/js/features/common-issue-list.test.js create mode 100644 web_src/js/features/common-organization.js create mode 100644 web_src/js/features/comp/ComboMarkdownEditor.js create mode 100644 web_src/js/features/comp/ConfirmModal.js create mode 100644 web_src/js/features/comp/EasyMDEToolbarActions.js create mode 100644 web_src/js/features/comp/LabelEdit.js create mode 100644 web_src/js/features/comp/Paste.js create mode 100644 web_src/js/features/comp/QuickSubmit.js create mode 100644 web_src/js/features/comp/ReactionSelector.js create mode 100644 web_src/js/features/comp/SearchUserBox.js create mode 100644 web_src/js/features/comp/TextExpander.js create mode 100644 web_src/js/features/comp/WebHookEditor.js create mode 100644 web_src/js/features/contextpopup.js create mode 100644 web_src/js/features/contributors.js create mode 100644 web_src/js/features/copycontent.js create mode 100644 web_src/js/features/dropzone.js create mode 100644 web_src/js/features/emoji.js create mode 100644 web_src/js/features/eventsource.sharedworker.js create mode 100644 web_src/js/features/file-fold.js create mode 100644 web_src/js/features/heatmap.js create mode 100644 web_src/js/features/imagediff.js create mode 100644 web_src/js/features/install.js create mode 100644 web_src/js/features/notification.js create mode 100644 web_src/js/features/org-team.js create mode 100644 web_src/js/features/pull-view-file.js create mode 100644 web_src/js/features/recent-commits.js create mode 100644 web_src/js/features/repo-branch.js create mode 100644 web_src/js/features/repo-code.js create mode 100644 web_src/js/features/repo-code.test.js create mode 100644 web_src/js/features/repo-commit.js create mode 100644 web_src/js/features/repo-common.js create mode 100644 web_src/js/features/repo-diff-commit.js create mode 100644 web_src/js/features/repo-diff-commitselect.js create mode 100644 web_src/js/features/repo-diff-filetree.js create mode 100644 web_src/js/features/repo-diff.js create mode 100644 web_src/js/features/repo-editor.js create mode 100644 web_src/js/features/repo-findfile.js create mode 100644 web_src/js/features/repo-findfile.test.js create mode 100644 web_src/js/features/repo-graph.js create mode 100644 web_src/js/features/repo-home.js create mode 100644 web_src/js/features/repo-issue-content.js create mode 100644 web_src/js/features/repo-issue-list.js create mode 100644 web_src/js/features/repo-issue-pr-form.js create mode 100644 web_src/js/features/repo-issue-pr-status.js create mode 100644 web_src/js/features/repo-issue.js create mode 100644 web_src/js/features/repo-issue.test.js create mode 100644 web_src/js/features/repo-legacy.js create mode 100644 web_src/js/features/repo-migrate.js create mode 100644 web_src/js/features/repo-migration.js create mode 100644 web_src/js/features/repo-projects.js create mode 100644 web_src/js/features/repo-release.js create mode 100644 web_src/js/features/repo-search.js create mode 100644 web_src/js/features/repo-settings.js create mode 100644 web_src/js/features/repo-template.js create mode 100644 web_src/js/features/repo-unicode-escape.js create mode 100644 web_src/js/features/repo-wiki.js create mode 100644 web_src/js/features/sshkey-helper.js create mode 100644 web_src/js/features/stopwatch.js create mode 100644 web_src/js/features/tablesort.js create mode 100644 web_src/js/features/tribute.js create mode 100644 web_src/js/features/user-auth-webauthn.js create mode 100644 web_src/js/features/user-auth.js create mode 100644 web_src/js/features/user-settings.js create mode 100644 web_src/js/htmx.js create mode 100644 web_src/js/index.js create mode 100644 web_src/js/jquery.js create mode 100644 web_src/js/markup/anchors.js create mode 100644 web_src/js/markup/asciicast.js create mode 100644 web_src/js/markup/codecopy.js create mode 100644 web_src/js/markup/common.js create mode 100644 web_src/js/markup/content.js create mode 100644 web_src/js/markup/math.js create mode 100644 web_src/js/markup/mermaid.js create mode 100644 web_src/js/markup/tasklist.js create mode 100644 web_src/js/modules/dirauto.js create mode 100644 web_src/js/modules/fetch.js create mode 100644 web_src/js/modules/fetch.test.js create mode 100644 web_src/js/modules/fomantic.js create mode 100644 web_src/js/modules/fomantic/api.js create mode 100644 web_src/js/modules/fomantic/aria.md create mode 100644 web_src/js/modules/fomantic/base.js create mode 100644 web_src/js/modules/fomantic/checkbox.js create mode 100644 web_src/js/modules/fomantic/dropdown.js create mode 100644 web_src/js/modules/fomantic/form.js create mode 100644 web_src/js/modules/fomantic/modal.js create mode 100644 web_src/js/modules/fomantic/transition.js create mode 100644 web_src/js/modules/sortable.js create mode 100644 web_src/js/modules/stores.js create mode 100644 web_src/js/modules/tippy.js create mode 100644 web_src/js/modules/toast.js create mode 100644 web_src/js/modules/toast.test.js create mode 100644 web_src/js/render/ansi.js create mode 100644 web_src/js/render/ansi.test.js create mode 100644 web_src/js/render/pdf.js create mode 100644 web_src/js/standalone/devtest.js create mode 100644 web_src/js/standalone/forgejo-swagger.js create mode 100644 web_src/js/standalone/swagger.js create mode 100644 web_src/js/svg.js create mode 100644 web_src/js/svg.test.js create mode 100644 web_src/js/utils.js create mode 100644 web_src/js/utils.test.js create mode 100644 web_src/js/utils/color.js create mode 100644 web_src/js/utils/color.test.js create mode 100644 web_src/js/utils/dom.js create mode 100644 web_src/js/utils/dom.test.js create mode 100644 web_src/js/utils/image.js create mode 100644 web_src/js/utils/image.test.js create mode 100644 web_src/js/utils/match.js create mode 100644 web_src/js/utils/match.test.js create mode 100644 web_src/js/utils/time.js create mode 100644 web_src/js/utils/time.test.js create mode 100644 web_src/js/utils/url.js create mode 100644 web_src/js/utils/url.test.js create mode 100644 web_src/js/vendor/jquery.are-you-sure.js create mode 100644 web_src/js/vitest.setup.js create mode 100644 web_src/js/webcomponents/README.md create mode 100644 web_src/js/webcomponents/absolute-date.js create mode 100644 web_src/js/webcomponents/absolute-date.test.js create mode 100644 web_src/js/webcomponents/index.js create mode 100644 web_src/js/webcomponents/origin-url.js create mode 100644 web_src/js/webcomponents/origin-url.test.js create mode 100644 web_src/js/webcomponents/overflow-menu.js create mode 100644 web_src/js/webcomponents/polyfills.js (limited to 'web_src/js') diff --git a/web_src/js/bootstrap.js b/web_src/js/bootstrap.js new file mode 100644 index 0000000..c707979 --- /dev/null +++ b/web_src/js/bootstrap.js @@ -0,0 +1,109 @@ +// DO NOT IMPORT window.config HERE! +// to make sure the error handler always works, we should never import `window.config`, because +// some user's custom template breaks it. + +// This sets up the URL prefix used in webpack's chunk loading. +// This file must be imported before any lazy-loading is being attempted. +__webpack_public_path__ = `${window.config?.assetUrlPrefix ?? '/assets'}/`; + +// Ignore external and some known internal errors that we are unable to currently fix. +function shouldIgnoreError(err) { + const assetBaseUrl = String(new URL(__webpack_public_path__, window.location.origin)); + + if (!(err instanceof Error)) return false; + // If the error stack trace does not include the base URL of our script assets, it likely came + // from a browser extension or inline script. Ignore these errors. + if (!err.stack?.includes(assetBaseUrl)) return true; + // Ignore some known internal errors that we are unable to currently fix (eg via Monaco). + const ignorePatterns = [ + '/assets/js/monaco.', // https://codeberg.org/forgejo/forgejo/issues/3638 , https://github.com/go-gitea/gitea/issues/30861 , https://github.com/microsoft/monaco-editor/issues/4496 + ]; + for (const pattern of ignorePatterns) { + if (err.stack?.includes(pattern)) return true; + } + return false; +} + +const filteredErrors = new Set([ + 'getModifierState is not a function', // https://github.com/microsoft/monaco-editor/issues/4325 +]); + +export function showGlobalErrorMessage(msg) { + const pageContent = document.querySelector('.page-content'); + if (!pageContent) return; + + for (const filteredError of filteredErrors) { + if (msg.includes(filteredError)) return; + } + + // compact the message to a data attribute to avoid too many duplicated messages + const msgCompact = msg.replace(/\W/g, '').trim(); + let msgDiv = pageContent.querySelector(`.js-global-error[data-global-error-msg-compact="${msgCompact}"]`); + if (!msgDiv) { + const el = document.createElement('div'); + el.innerHTML = `
`; + msgDiv = el.childNodes[0]; + } + // merge duplicated messages into "the message (count)" format + const msgCount = Number(msgDiv.getAttribute(`data-global-error-msg-count`)) + 1; + msgDiv.setAttribute(`data-global-error-msg-compact`, msgCompact); + msgDiv.setAttribute(`data-global-error-msg-count`, msgCount.toString()); + msgDiv.textContent = msg + (msgCount > 1 ? ` (${msgCount})` : ''); + pageContent.prepend(msgDiv); +} + +/** + * @param {ErrorEvent|PromiseRejectionEvent} event - Event + * @param {string} event.message - Only present on ErrorEvent + * @param {string} event.error - Only present on ErrorEvent + * @param {string} event.type - Only present on ErrorEvent + * @param {string} event.filename - Only present on ErrorEvent + * @param {number} event.lineno - Only present on ErrorEvent + * @param {number} event.colno - Only present on ErrorEvent + * @param {string} event.reason - Only present on PromiseRejectionEvent + * @param {number} event.promise - Only present on PromiseRejectionEvent + */ +function processWindowErrorEvent({error, reason, message, type, filename, lineno, colno}) { + const err = error ?? reason; + const {runModeIsProd} = window.config ?? {}; + + // `error` and `reason` are not guaranteed to be errors. If the value is falsy, it is likely a + // non-critical event from the browser. We log them but don't show them to users. Examples: + // - https://developer.mozilla.org/en-US/docs/Web/API/ResizeObserver#observation_errors + // - https://github.com/mozilla-mobile/firefox-ios/issues/10817 + // - https://github.com/go-gitea/gitea/issues/20240 + if (!err) { + if (message) console.error(new Error(message)); + if (runModeIsProd) return; + } + + // In production do not display errors that should be ignored. + if (runModeIsProd && shouldIgnoreError(err)) return; + + let msg = err?.message ?? message; + if (lineno) msg += ` (${filename} @ ${lineno}:${colno})`; + const dot = msg.endsWith('.') ? '' : '.'; + const renderedType = type === 'unhandledrejection' ? 'promise rejection' : type; + showGlobalErrorMessage(`JavaScript ${renderedType}: ${msg}${dot} Open browser console to see more details.`); +} + +function initGlobalErrorHandler() { + if (window._globalHandlerErrors?._inited) { + showGlobalErrorMessage(`The global error handler has been initialized, do not initialize it again`); + return; + } + if (!window.config) { + showGlobalErrorMessage(`Gitea JavaScript code couldn't run correctly, please check your custom templates`); + } + // we added an event handler for window error at the very beginning of + diff --git a/web_src/js/components/ActivityHeatmap.vue b/web_src/js/components/ActivityHeatmap.vue new file mode 100644 index 0000000..be0841e --- /dev/null +++ b/web_src/js/components/ActivityHeatmap.vue @@ -0,0 +1,83 @@ + + diff --git a/web_src/js/components/ContextPopup.test.js b/web_src/js/components/ContextPopup.test.js new file mode 100644 index 0000000..2726567 --- /dev/null +++ b/web_src/js/components/ContextPopup.test.js @@ -0,0 +1,163 @@ +import {flushPromises, mount} from '@vue/test-utils'; +import ContextPopup from './ContextPopup.vue'; + +async function assertPopup(popupData, expectedIconColor, expectedIcon) { + const date = new Date('2024-07-13T22:00:00Z'); + + vi.spyOn(global, 'fetch').mockResolvedValue({ + json: vi.fn().mockResolvedValue({ + ok: true, + created_at: date.toISOString(), + repository: {full_name: 'user2/repo1'}, + ...popupData, + }), + ok: true, + }); + + const popup = mount(ContextPopup); + popup.vm.$el.dispatchEvent(new CustomEvent('ce-load-context-popup', { + detail: {owner: 'user2', repo: 'repo1', index: popupData.number}, + })); + await flushPromises(); + + expect(popup.get('p:nth-of-type(1)').text()).toEqual(`user2/repo1 on ${date.toLocaleDateString(undefined, {year: 'numeric', month: 'short', day: 'numeric'})}`); + expect(popup.get('p:nth-of-type(2)').text()).toEqual(`${popupData.title} #${popupData.number}`); + expect(popup.get('p:nth-of-type(3)').text()).toEqual(popupData.body); + + expect(popup.get('svg').classes()).toContain(expectedIcon); + expect(popup.get('svg').classes()).toContain(expectedIconColor); + + for (const l of popupData.labels) { + expect(popup.findAll('.ui.label').map((x) => x.text())).toContain(l.name); + } +} + +test('renders an open issue popup', async () => { + await assertPopup({ + title: 'Open Issue', + body: 'Open Issue Body', + number: 1, + labels: [{color: 'd21b1fff', name: 'Bug'}, {color: 'aaff00', name: 'Confirmed'}], + state: 'open', + pull_request: null, + }, 'green', 'octicon-issue-opened'); +}); + +test('renders a closed issue popup', async () => { + await assertPopup({ + title: 'Closed Issue', + body: 'Closed Issue Body', + number: 1, + labels: [{color: 'd21b1fff', name: 'Bug'}, {color: 'aaff00', name: 'Confirmed'}], + state: 'closed', + pull_request: null, + }, 'red', 'octicon-issue-closed'); +}); + +test('renders an open PR popup', async () => { + await assertPopup({ + title: 'Open PR', + body: 'Open PR Body', + number: 1, + labels: [{color: 'd21b1fff', name: 'Bug'}, {color: 'aaff00', name: 'Confirmed'}], + state: 'open', + pull_request: {merged: false, draft: false}, + }, 'green', 'octicon-git-pull-request'); +}); + +test('renders an open WIP PR popup', async () => { + await assertPopup({ + title: 'WIP: Open PR', + body: 'WIP Open PR Body', + number: 1, + labels: [{color: 'd21b1fff', name: 'Bug'}, {color: 'aaff00', name: 'Confirmed'}], + state: 'open', + pull_request: {merged: false, draft: true}, + }, 'grey', 'octicon-git-pull-request-draft'); +}); + +test('renders a closed PR popup', async () => { + await assertPopup({ + title: 'Closed PR', + body: 'Closed PR Body', + number: 1, + labels: [{color: 'd21b1fff', name: 'Bug'}, {color: 'aaff00', name: 'Confirmed'}], + state: 'closed', + pull_request: {merged: false, draft: false}, + }, 'red', 'octicon-git-pull-request-closed'); +}); + +test('renders a closed WIP PR popup', async () => { + await assertPopup({ + title: 'WIP: Closed PR', + body: 'WIP Closed PR Body', + number: 1, + labels: [{color: 'd21b1fff', name: 'Bug'}, {color: 'aaff00', name: 'Confirmed'}], + state: 'closed', + pull_request: {merged: false, draft: true}, + }, 'red', 'octicon-git-pull-request-closed'); +}); + +test('renders a merged PR popup', async () => { + await assertPopup({ + title: 'Merged PR', + body: 'Merged PR Body', + number: 1, + labels: [{color: 'd21b1fff', name: 'Bug'}, {color: 'aaff00', name: 'Confirmed'}], + state: 'closed', + pull_request: {merged: true, draft: false}, + }, 'purple', 'octicon-git-merge'); +}); + +test('renders an issue popup with escaped HTML', async () => { + const evil = ''; + + vi.spyOn(global, 'fetch').mockResolvedValue({ + json: vi.fn().mockResolvedValue({ + ok: true, + created_at: '2024-07-13T22:00:00Z', + repository: {full_name: evil}, + title: evil, + body: evil, + labels: [{color: '000666', name: evil}], + state: 'open', + pull_request: null, + }), + ok: true, + }); + + const popup = mount(ContextPopup); + popup.vm.$el.dispatchEvent(new CustomEvent('ce-load-context-popup', { + detail: {owner: evil, repo: evil, index: 1}, + })); + await flushPromises(); + + expect(() => popup.get('.evil')).toThrowError(); + expect(popup.get('p:nth-of-type(1)').text()).toContain(evil); + expect(popup.get('p:nth-of-type(2)').text()).toContain(evil); + expect(popup.get('p:nth-of-type(3)').text()).toContain(evil); +}); + +test('renders an issue popup with emojis', async () => { + vi.spyOn(global, 'fetch').mockResolvedValue({ + json: vi.fn().mockResolvedValue({ + ok: true, + created_at: '2024-07-13T22:00:00Z', + repository: {full_name: 'user2/repo1'}, + title: 'Title', + body: 'Body', + labels: [{color: '000666', name: 'Tag :+1:'}], + state: 'open', + pull_request: null, + }), + ok: true, + }); + + const popup = mount(ContextPopup); + popup.vm.$el.dispatchEvent(new CustomEvent('ce-load-context-popup', { + detail: {owner: 'user2', repo: 'repo1', index: 1}, + })); + await flushPromises(); + + expect(popup.get('.ui.label').text()).toEqual('Tag 👍'); +}); diff --git a/web_src/js/components/ContextPopup.vue b/web_src/js/components/ContextPopup.vue new file mode 100644 index 0000000..752a9a1 --- /dev/null +++ b/web_src/js/components/ContextPopup.vue @@ -0,0 +1,130 @@ + + diff --git a/web_src/js/components/DashboardRepoList.vue b/web_src/js/components/DashboardRepoList.vue new file mode 100644 index 0000000..e587413 --- /dev/null +++ b/web_src/js/components/DashboardRepoList.vue @@ -0,0 +1,537 @@ + + + diff --git a/web_src/js/components/DiffCommitSelector.vue b/web_src/js/components/DiffCommitSelector.vue new file mode 100644 index 0000000..3f6e4e4 --- /dev/null +++ b/web_src/js/components/DiffCommitSelector.vue @@ -0,0 +1,306 @@ + + + diff --git a/web_src/js/components/DiffFileList.vue b/web_src/js/components/DiffFileList.vue new file mode 100644 index 0000000..916780d --- /dev/null +++ b/web_src/js/components/DiffFileList.vue @@ -0,0 +1,58 @@ + + diff --git a/web_src/js/components/DiffFileTree.vue b/web_src/js/components/DiffFileTree.vue new file mode 100644 index 0000000..cddfee1 --- /dev/null +++ b/web_src/js/components/DiffFileTree.vue @@ -0,0 +1,144 @@ + + + diff --git a/web_src/js/components/DiffFileTreeItem.vue b/web_src/js/components/DiffFileTreeItem.vue new file mode 100644 index 0000000..0f6e543 --- /dev/null +++ b/web_src/js/components/DiffFileTreeItem.vue @@ -0,0 +1,97 @@ + + + diff --git a/web_src/js/components/PullRequestMergeForm.test.js b/web_src/js/components/PullRequestMergeForm.test.js new file mode 100644 index 0000000..7b856e0 --- /dev/null +++ b/web_src/js/components/PullRequestMergeForm.test.js @@ -0,0 +1,34 @@ +// Copyright 2024 The Forgejo Authors. All rights reserved. +// SPDX-License-Identifier: MIT +import {flushPromises, mount} from '@vue/test-utils'; +import PullRequestMergeForm from './PullRequestMergeForm.vue'; + +async function renderMergeForm(branchName) { + window.config.pageData.pullRequestMergeForm = { + textDeleteBranch: `Delete branch "${branchName}"`, + textDoMerge: 'Merge', + defaultMergeStyle: 'merge', + isPullBranchDeletable: true, + canMergeNow: true, + mergeStyles: [{ + 'name': 'merge', + 'allowed': true, + 'textDoMerge': 'Merge', + 'mergeTitleFieldText': 'Merge PR', + 'mergeMessageFieldText': 'Description', + 'hideAutoMerge': 'Hide this message', + }], + }; + const mergeform = mount(PullRequestMergeForm); + mergeform.get('.merge-button').trigger('click'); + await flushPromises(); + return mergeform; +} + +test('renders escaped branch name', async () => { + let mergeform = await renderMergeForm('evil'); + expect(mergeform.get('label[for="delete-branch-after-merge"]').text()).toBe('Delete branch "evil"'); + + mergeform = await renderMergeForm(''); + expect(mergeform.get('label[for="delete-branch-after-merge"]').text()).toBe('Delete branch ""'); +}); diff --git a/web_src/js/components/PullRequestMergeForm.vue b/web_src/js/components/PullRequestMergeForm.vue new file mode 100644 index 0000000..bd0901a --- /dev/null +++ b/web_src/js/components/PullRequestMergeForm.vue @@ -0,0 +1,252 @@ + +