From 476d5cfee4d1c32a53a8763ea2f5dc7280ba830f Mon Sep 17 00:00:00 2001
From: mengning
Date: Sat, 20 Jun 2026 06:22:04 +0000
Subject: [PATCH 1/3] =?UTF-8?q?=E4=BB=8E=20Gitea=20v1.25.3=E5=90=8C?=
=?UTF-8?q?=E6=AD=A5=E4=B8=8A=E6=B8=B8=E5=8F=98=E6=9B=B4=E8=87=B3=20v1.26.?=
=?UTF-8?q?2=20(#342)?=
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit
从 Gitea v1.25.3.0 同步上游变更至 v1.26.2
Co-authored-by: wxiaoguang
Co-authored-by: Nicolas
Co-authored-by: Lunny Xiao
Co-authored-by: mengning
Co-authored-by: Giteabot
Co-authored-by: techknowlogick
Co-authored-by: ChristopherHX
Co-authored-by: Zettat123
Co-authored-by: silverwind
Co-authored-by: a1012112796 <1012112796@qq.com>
Reviewed-on: https://devstar.cn/devstar/devstar/pulls/342
Co-authored-by: mengning
Co-committed-by: mengning
---
.air.toml | 2 +-
.devcontainer/devcontainer.json | 3 +-
.dockerignore | 3 +
.gitattributes | 1 +
.github/ISSUE_TEMPLATE/bug-report.yaml | 53 +-
.github/ISSUE_TEMPLATE/config.yml | 14 +-
.github/ISSUE_TEMPLATE/feature-request.yaml | 11 +-
.github/ISSUE_TEMPLATE/ui.bug-report.yaml | 32 +-
.github/dependabot.yml | 10 +
.github/labeler.yml | 8 +-
.github/pull_request_template.md | 4 +-
.../workflows/PushDevStarImage2DockerHub.yml | 52 +-
.github/workflows/cron-flake-updater.yml | 22 +
.github/workflows/cron-translations.yml | 8 +-
.github/workflows/files-changed.yml | 15 +-
.github/workflows/pull-docker-dryrun.yml | 33 +-
.github/workflows/pull-labeler.yml | 2 +-
.github/workflows/release-tag-rc.yml | 86 +-
.github/workflows/release-tag-version.yml | 83 +-
.gitignore | 21 +-
.gitpod.yml | 51 -
.golangci.yml | 34 +-
.yamllint.yaml | 4 +-
AGENTS.md | 11 +
CLAUDE.md | 1 +
CONTRIBUTING.md | 46 +-
Dockerfile | 65 +-
Dockerfile.rootless | 60 +-
MAINTAINERS | 1 +
README.md | 10 +-
README.zh-cn.md | 13 +-
README.zh-tw.md | 12 +-
SECURITY.md | 76 +-
assets/emoji.json | 11484 +++++++++++++++-
{tools => assets}/misspellings.csv | 0
build.go | 14 -
build/backport-locales.go | 115 -
build/generate-emoji.go | 8 +-
build/generate-go-licenses.go | 237 +-
build/update-locales.sh | 44 +-
cmd/actions.go | 13 +-
cmd/admin.go | 47 +-
cmd/admin_auth.go | 11 +-
cmd/admin_auth_ldap.go | 7 +
cmd/admin_auth_ldap_test.go | 4 +-
cmd/admin_regenerate.go | 10 +-
cmd/admin_user.go | 24 +-
cmd/admin_user_create.go | 1 +
cmd/admin_user_generate_access_token.go | 52 +-
cmd/admin_user_list.go | 20 +-
cmd/admin_user_must_change_password.go | 1 +
cmd/config.go | 156 +
cmd/config_test.go | 85 +
cmd/docs.go | 33 +-
cmd/doctor.go | 118 +-
cmd/doctor_convert.go | 13 +-
cmd/doctor_test.go | 2 +-
cmd/dump.go | 143 +-
cmd/dump_repo.go | 107 +-
cmd/embedded.go | 29 +-
cmd/generate.go | 38 +-
cmd/hook.go | 88 +-
cmd/hook_test.go | 14 +
cmd/keys.go | 68 +-
cmd/mailer.go | 4 +-
cmd/main.go | 38 +-
cmd/main_test.go | 6 +-
cmd/manager.go | 44 +-
cmd/manager_logging.go | 14 +-
cmd/migrate.go | 13 +-
cmd/migrate_storage.go | 201 +-
cmd/restore_repo.go | 65 +-
cmd/serv.go | 31 +-
cmd/web.go | 99 +-
cmd/web_acme.go | 5 +-
contrib/backport/backport.go | 2 +-
contrib/environment-to-ini/README | 47 -
.../environment-to-ini/environment-to-ini.go | 112 -
contrib/upgrade.sh | 6 +-
crowdin.yml | 6 +-
custom/conf/app.example.ini | 190 +-
docker/root/etc/s6/openssh/finish | 6 +
docker/root/usr/local/bin/environment-to-ini | 2 +
.../rootless/usr/local/bin/environment-to-ini | 2 +
eslint.config.ts | 173 +-
eslint.json.config.ts | 30 +
flake.lock | 40 +-
flake.nix | 139 +-
main.go | 9 +-
models/actions/artifact.go | 42 +-
models/actions/config.go | 74 +
models/actions/run_job.go | 126 +-
models/actions/run_job_list.go | 19 +-
models/actions/run_list.go | 25 +-
models/actions/runner.go | 29 +
models/actions/task.go | 50 +-
models/actions/task_step.go | 4 +-
models/actions/task_test.go | 77 +
models/actions/token_permissions.go | 60 +
models/actions/utils.go | 17 +-
models/actions/utils_test.go | 47 +-
models/activities/action.go | 16 +-
models/activities/action_list.go | 2 +-
models/activities/notification_list.go | 2 +-
models/activities/user_heatmap.go | 17 +-
models/admin/task.go | 7 +
models/asymkey/gpg_key_commit_verification.go | 4 +-
models/asymkey/gpg_key_test.go | 5 +-
.../asymkey/ssh_key_authorized_keys_test.go | 90 +
models/asymkey/ssh_key_principals.go | 2 +-
models/auth/oauth2.go | 138 +-
models/auth/oauth2_test.go | 139 +-
models/auth/source.go | 8 +-
models/auth/source_test.go | 42 +-
models/db/collation.go | 2 +-
models/db/common.go | 30 +-
models/db/convert.go | 22 +-
models/db/engine_init.go | 2 +-
models/dbfs/dbfile.go | 29 +-
models/dbfs/dbfs.go | 3 +
models/dbfs/dbfs_test.go | 84 +-
models/fixtures/action_artifact.yml | 36 +
models/fixtures/attachment.yml | 13 +
models/fixtures/badge.yml | 5 +
models/fixtures/branch.yml | 24 +
models/git/branch.go | 68 +-
models/git/branch_test.go | 108 +-
models/git/commit_status.go | 58 +-
models/git/commit_status_test.go | 4 +-
models/git/lfs.go | 58 +-
models/git/lfs_lock.go | 42 +-
models/git/lfs_lock_test.go | 82 +
models/git/lfs_test.go | 61 +
models/git/protected_branch.go | 8 +-
models/git/protected_tag.go | 4 +-
models/issues/comment.go | 102 +-
models/issues/comment_code.go | 1 +
models/issues/issue.go | 21 +-
models/issues/issue_label.go | 2 +-
models/issues/issue_project.go | 30 -
models/issues/issue_update.go | 4 +-
models/issues/issue_xref.go | 2 +-
models/issues/label_test.go | 2 +-
models/issues/milestone.go | 11 +-
models/issues/milestone_list.go | 12 +
models/issues/pull.go | 38 +-
models/issues/pull_list.go | 92 +-
models/issues/pull_list_test.go | 95 +-
models/issues/pull_test.go | 134 +-
models/issues/review.go | 38 +-
models/issues/review_list.go | 4 +-
models/issues/review_test.go | 18 +-
models/issues/stopwatch.go | 13 +
models/issues/tracked_time.go | 6 +-
models/migrations/base/db.go | 132 +-
models/migrations/base/db_test.go | 4 +
models/migrations/base/main_test.go | 12 -
models/migrations/base/tests.go | 155 +-
.../action_run.yml | 29 +
.../action_run_job.yml | 16 +
.../commit_status.yml | 51 +
.../commit_status_summary.yml | 19 +
.../repository.yml | 9 +
models/migrations/migrations.go | 15 +-
models/migrations/v1_12/v128.go | 8 +-
models/migrations/v1_12/v134.go | 4 +-
models/migrations/v1_12/v136.go | 12 +-
models/migrations/v1_21/v276.go | 19 +-
models/migrations/v1_25/v321_test.go | 38 +-
models/migrations/v1_25/v322_test.go | 34 +
models/migrations/v1_26/main_test.go | 14 +
models/migrations/v1_26/v323.go | 43 +
models/migrations/v1_26/v324.go | 24 +
models/migrations/v1_26/v325.go | 18 +
models/migrations/v1_26/v325_test.go | 45 +
models/migrations/v1_26/v326.go | 315 +
models/migrations/v1_26/v326_test.go | 113 +
models/migrations/v1_26/v327.go | 17 +
models/migrations/v1_26/v327_test.go | 33 +
models/migrations/v1_26/v328.go | 16 +
models/migrations/v1_26/v329.go | 62 +
models/migrations/v1_26/v329_test.go | 85 +
models/migrations/v1_26/v330.go | 16 +
models/migrations/v1_9/v82.go | 17 +-
models/organization/org.go | 2 +-
models/organization/org_list.go | 6 +
models/organization/org_user.go | 50 +-
models/packages/descriptor.go | 24 +-
models/packages/package.go | 50 +-
models/packages/package_blob.go | 11 +-
models/packages/package_blob_test.go | 51 +
models/packages/package_file.go | 16 +-
models/packages/package_property.go | 45 +-
models/packages/package_version.go | 6 +
models/perm/access/access.go | 75 +-
models/perm/access/access_test.go | 87 +-
.../access/actions_repo_permission_test.go | 155 +
models/perm/access/repo_permission.go | 167 +-
models/perm/access/repo_permission_test.go | 44 +-
models/project/column.go | 51 +-
models/project/project.go | 12 +
models/pull/automerge.go | 14 +-
models/renderhelper/repo_file.go | 10 +-
models/renderhelper/repo_wiki.go | 2 +-
models/repo.go | 16 +-
.../repo/archive_test.go | 2 +-
models/repo/archiver.go | 50 +-
models/repo/attachment.go | 5 +
models/repo/attachment_test.go | 16 +
models/repo/avatar.go | 12 +-
models/repo/fork.go | 2 +-
models/repo/pull_request_default.go | 16 +
models/repo/pull_request_default_test.go | 32 +
models/repo/release.go | 40 +-
models/repo/release_test.go | 53 +
models/repo/repo.go | 82 +-
models/repo/repo_list.go | 15 +
models/repo/repo_unit.go | 90 +-
models/repo/repo_unit_actions.go | 153 +
models/repo/repo_unit_test.go | 76 +-
models/repo/topic.go | 2 +-
models/repo/update.go | 31 -
models/repo/user_repo.go | 44 +-
models/repo/user_repo_test.go | 42 +-
models/repo/watch.go | 10 +
models/repo/watch_test.go | 19 +
models/repo/wiki.go | 13 +-
models/repo/wiki_test.go | 13 +-
models/unittest/fixtures_loader.go | 2 +-
models/unittest/fixtures_test.go | 13 +-
models/unittest/fscopy.go | 17 +-
models/unittest/testdb.go | 59 +-
models/user/avatar.go | 14 +-
models/user/badge.go | 187 +-
models/user/badge_test.go | 185 +
models/user/block.go | 2 +-
models/user/email_address.go | 21 +-
models/user/email_address_test.go | 8 +-
models/user/list.go | 4 +-
models/user/openid.go | 12 +-
models/user/openid_test.go | 17 +-
models/user/search.go | 34 +-
models/user/setting.go | 43 +
models/user/setting_options.go | 6 +-
models/user/user.go | 238 +-
models/user/user_system.go | 55 +-
models/user/user_system_test.go | 22 +-
models/user/user_test.go | 92 +-
models/webhook/webhook.go | 1 +
models/webhook/webhook_system.go | 31 +-
models/webhook/webhook_system_test.go | 13 +-
modules/actions/artifacts.go | 71 +-
modules/actions/artifacts_test.go | 36 +
modules/actions/github.go | 4 +
modules/actions/jobparser/evaluator.go | 189 +
modules/actions/jobparser/interpeter.go | 87 +
modules/actions/jobparser/jobparser.go | 180 +
modules/actions/jobparser/jobparser_test.go | 104 +
modules/actions/jobparser/model.go | 497 +
modules/actions/jobparser/model_test.go | 373 +
.../jobparser/testdata/empty_step.in.yaml | 8 +
.../jobparser/testdata/empty_step.out.yaml | 7 +
.../jobparser/testdata/erase_needs.in.yaml | 16 +
.../jobparser/testdata/erase_needs.out.yaml | 23 +
.../jobparser/testdata/has_needs.in.yaml | 16 +
.../jobparser/testdata/has_needs.out.yaml | 25 +
.../jobparser/testdata/has_secrets.in.yaml | 14 +
.../jobparser/testdata/has_secrets.out.yaml | 16 +
.../jobparser/testdata/has_with.in.yaml | 15 +
.../jobparser/testdata/has_with.out.yaml | 17 +
.../testdata/job_name_with_matrix.in.yaml | 14 +
.../testdata/job_name_with_matrix.out.yaml | 101 +
.../jobparser/testdata/multiple_jobs.in.yaml | 22 +
.../jobparser/testdata/multiple_jobs.out.yaml | 39 +
.../testdata/multiple_matrix.in.yaml | 13 +
.../testdata/multiple_matrix.out.yaml | 101 +
.../testdata/null_job_explicit.in.yaml | 9 +
.../testdata/null_job_implicit.in.yaml | 9 +
.../testdata/prefixed_newline.in.yaml | 14 +
.../testdata/prefixed_newline.out.yaml | 15 +
modules/actions/jobparser/testdata_test.go | 21 +
modules/actions/log.go | 22 +-
modules/actions/workflows.go | 45 +-
modules/actions/workflows_test.go | 87 +-
modules/activitypub/client.go | 124 -
modules/activitypub/client_test.go | 45 -
modules/activitypub/main_test.go | 18 -
modules/activitypub/user_settings.go | 48 -
modules/activitypub/user_settings_test.go | 28 -
modules/analyze/code_language.go | 5 +-
modules/analyze/vendor.go | 24 +-
modules/analyze/vendor_test.go | 9 +
modules/assetfs/embed.go | 10 +-
modules/assetfs/layered.go | 75 +-
modules/auth/pam/pam.go | 3 +-
modules/auth/password/hash/argon2.go | 16 +-
modules/auth/password/hash/common.go | 8 +-
modules/auth/password/hash/setting.go | 2 +-
modules/auth/password/pwn/pwn.go | 4 +-
modules/auth/password/pwn/pwn_test.go | 12 +-
modules/auth/webauthn/webauthn.go | 2 +-
modules/avatar/avatar.go | 17 +-
modules/avatar/avatar_test.go | 28 +-
modules/avatar/identicon/identicon.go | 31 +-
modules/avatar/identicon/identicon_test.go | 2 +-
modules/base/natural_sort.go | 12 +-
modules/base/natural_sort_test.go | 6 +-
modules/base/tool_test.go | 4 +-
modules/charset/ambiguous.go | 14 +-
modules/charset/ambiguous/generate.go | 188 -
modules/charset/ambiguous_gen.go | 1590 +--
modules/charset/ambiguous_gen_test.go | 8 +-
modules/charset/breakwriter.go | 43 -
modules/charset/breakwriter_test.go | 68 -
modules/charset/escape.go | 45 +-
modules/charset/escape_status.go | 8 +-
modules/charset/escape_stream.go | 537 +-
modules/charset/escape_test.go | 99 +-
.../{ambiguous => generate}/ambiguous.json | 0
.../{invisible => generate}/generate.go | 152 +-
modules/charset/htmlstream.go | 200 -
modules/charset/invisible_gen.go | 60 +-
modules/commitstatus/commit_status.go | 5 +-
modules/commitstatus/commit_status_test.go | 14 +-
modules/dump/dumper.go | 3 +-
modules/emoji/emoji_data.go | 142 +-
modules/eventsource/manager_run.go | 9 +-
modules/fileicon/render.go | 8 +-
modules/fileicon/render_test.go | 75 +
modules/generate/generate.go | 8 +-
modules/generate/generate_test.go | 6 +-
modules/git/attribute/attribute.go | 4 +-
modules/git/attribute/batch.go | 34 +-
modules/git/attribute/checker.go | 17 +-
modules/git/batch.go | 47 -
modules/git/batch_reader.go | 329 -
modules/git/blob_gogit.go | 24 +-
modules/git/blob_nogogit.go | 52 +-
modules/git/catfile_batch.go | 52 +
modules/git/catfile_batch_command.go | 74 +
modules/git/catfile_batch_legacy.go | 89 +
modules/git/catfile_batch_reader.go | 264 +
modules/git/catfile_batch_test.go | 105 +
modules/git/commit.go | 228 +-
modules/git/commit_info_test.go | 61 +-
modules/git/commit_sha256_test.go | 63 -
modules/git/commit_submodule.go | 4 +-
modules/git/commit_test.go | 163 +-
modules/git/config.go | 21 +-
modules/git/diff.go | 125 +-
modules/git/error.go | 50 +-
modules/git/foreachref/format.go | 10 +-
modules/git/foreachref/parser.go | 18 +-
modules/git/git.go | 58 +-
modules/git/git_test.go | 34 +-
modules/git/gitcmd/command.go | 475 +-
modules/git/gitcmd/command_race_test.go | 38 -
modules/git/gitcmd/command_test.go | 123 +-
modules/git/gitcmd/context.go | 32 +
modules/git/gitcmd/error.go | 108 +
modules/git/gitcmd/pipe.go | 87 +
modules/git/gitcmd/utils.go | 14 -
modules/git/gpg.go | 102 +
modules/git/grep.go | 42 +-
modules/git/hook.go | 2 +-
modules/git/key.go | 53 +-
.../git/languagestats/language_stats_gogit.go | 2 +-
.../languagestats/language_stats_nogogit.go | 31 +-
modules/git/languagestats/main_test.go | 28 +-
modules/git/last_commit_cache.go | 4 +-
modules/git/log_name_status.go | 41 +-
modules/git/notes_gogit.go | 7 +-
modules/git/notes_test.go | 2 +-
modules/git/object_id_test.go | 2 +
modules/git/parse.go | 12 +-
modules/git/parse_gogit.go | 96 -
modules/git/parse_gogit_test.go | 78 -
.../{parse_nogogit.go => parse_treeentry.go} | 5 +-
...ogogit_test.go => parse_treeentry_test.go} | 2 -
modules/git/pipeline/catfile.go | 75 +-
modules/git/pipeline/lfs_common.go | 5 -
modules/git/pipeline/lfs_gogit.go | 71 +-
modules/git/pipeline/lfs_nogogit.go | 139 +-
modules/git/pipeline/lfs_test.go | 38 +
modules/git/pipeline/main_test.go | 14 +
modules/git/pipeline/namerev.go | 62 +-
modules/git/pipeline/revlist.go | 57 +-
modules/git/ref.go | 11 +
modules/git/remote.go | 8 +-
modules/git/repo.go | 184 +-
modules/git/repo_archive.go | 75 -
modules/git/repo_base_gogit.go | 1 -
modules/git/repo_base_nogogit.go | 82 +-
modules/git/repo_base_nogogit_test.go | 26 +
modules/git/repo_blame.go | 25 -
modules/git/repo_blob.go | 8 +-
modules/git/repo_blob_gogit.go | 22 -
modules/git/repo_blob_nogogit.go | 16 -
modules/git/repo_branch.go | 70 +-
modules/git/repo_branch_nogogit.go | 183 +-
modules/git/repo_commit.go | 260 +-
modules/git/repo_commit_gogit.go | 17 +-
modules/git/repo_commit_nogogit.go | 72 +-
modules/git/repo_commitgraph.go | 2 +-
modules/git/repo_compare.go | 128 +-
modules/git/repo_compare_test.go | 8 +-
modules/git/repo_gpg.go | 71 -
modules/git/repo_index.go | 42 +-
modules/git/repo_object.go | 32 +-
modules/git/repo_ref.go | 3 +-
modules/git/repo_ref_nogogit.go | 116 +-
modules/git/repo_stats.go | 35 +-
modules/git/repo_tag.go | 83 +-
modules/git/repo_tag_nogogit.go | 18 +-
modules/git/repo_test.go | 34 -
modules/git/repo_tree.go | 17 +-
modules/git/repo_tree_gogit.go | 7 +-
modules/git/repo_tree_nogogit.go | 22 +-
modules/git/submodule.go | 25 +-
modules/git/submodule_test.go | 6 +-
modules/git/tree.go | 19 +-
modules/git/tree_blob_gogit.go | 14 +-
modules/git/tree_entry.go | 105 +-
modules/git/tree_entry_gogit_test.go | 27 +
modules/git/tree_entry_mode.go | 36 +-
modules/git/tree_entry_nogogit.go | 56 +-
modules/git/tree_entry_test.go | 80 +-
modules/git/tree_nogogit.go | 50 +-
modules/gitrepo/archive.go | 80 +
modules/{git => gitrepo}/blame.go | 91 +-
modules/{git => gitrepo}/blame_sha256_test.go | 15 +-
modules/{git => gitrepo}/blame_test.go | 14 +-
modules/gitrepo/branch.go | 50 +-
modules/gitrepo/cat_file.go | 14 +
modules/gitrepo/clone.go | 24 +
modules/gitrepo/command.go | 26 +
modules/gitrepo/commit.go | 112 +
modules/gitrepo/commit_file.go | 88 +
modules/gitrepo/commit_file_test.go | 175 +
modules/gitrepo/commit_test.go | 45 +
modules/gitrepo/commitgraph.go | 14 +
modules/gitrepo/compare.go | 71 +
modules/gitrepo/compare_test.go | 178 +
modules/gitrepo/config.go | 15 +-
modules/gitrepo/diff.go | 71 +
modules/gitrepo/fetch.go | 28 +
modules/gitrepo/fsck.go | 2 +-
modules/gitrepo/gitrepo.go | 48 +-
modules/gitrepo/main_test.go | 25 +
modules/gitrepo/merge.go | 26 +
modules/gitrepo/merge_tree.go | 59 +
modules/gitrepo/merge_tree_test.go | 82 +
modules/gitrepo/push.go | 27 +
modules/gitrepo/ref.go | 8 +-
modules/gitrepo/remote.go | 30 +-
modules/gitrepo/repo_lock.go | 10 +
modules/gitrepo/signing.go | 14 +
modules/gitrepo/size.go | 37 +
modules/graceful/manager.go | 12 -
modules/graceful/net_unix.go | 4 +-
modules/graceful/server.go | 131 +-
modules/graceful/server_hooks.go | 21 +-
modules/graceful/server_http.go | 5 +
modules/hcaptcha/hcaptcha_test.go | 5 -
modules/highlight/highlight.go | 256 +-
modules/highlight/highlight_test.go | 29 +-
modules/highlight/lexerdetect.go | 311 +
modules/highlight/lexerdetect_test.go | 116 +
modules/htmlutil/html.go | 35 +-
modules/httpcache/httpcache.go | 34 +-
modules/httpcache/httpcache_test.go | 143 +-
modules/httplib/content_disposition.go | 65 +
modules/httplib/content_disposition_test.go | 64 +
modules/httplib/serve_test.go | 43 +-
modules/httplib/url.go | 36 +-
modules/httplib/url_test.go | 25 +
modules/indexer/code/bleve/bleve.go | 24 +-
modules/indexer/code/bleve/token/path/path.go | 2 +-
.../code/elasticsearch/elasticsearch.go | 25 +-
modules/indexer/code/git.go | 11 +-
modules/indexer/code/gitgrep/gitgrep.go | 4 +-
modules/indexer/code/internal/util.go | 14 +-
modules/indexer/code/search.go | 11 +-
.../elasticsearch/elasticsearch_test.go | 6 +-
.../indexer/issues/meilisearch/meilisearch.go | 2 +-
.../issues/meilisearch/meilisearch_test.go | 6 +-
modules/json/json.go | 68 +-
modules/json/json_test.go | 10 +
modules/json/jsonlegacy.go | 25 +
modules/json/jsonv1.go | 34 +
modules/json/jsonv2.go | 95 +
modules/lfs/content_store.go | 2 +-
modules/lfs/http_client_test.go | 16 +-
modules/lfs/pointer_scanner_gogit.go | 11 +-
modules/lfs/pointer_scanner_nogogit.go | 79 +-
modules/lfs/shared.go | 15 +
modules/lfstransfer/backend/backend.go | 2 +-
modules/lfstransfer/backend/lock.go | 4 +-
modules/lfstransfer/logger.go | 2 +-
modules/log/init.go | 6 +-
modules/log/logger_global.go | 1 +
modules/log/logger_impl.go | 21 +
modules/log/logger_test.go | 7 +
modules/log/misc.go | 1 +
modules/markup/asciicast/asciicast.go | 8 +-
modules/markup/camo.go | 3 +-
modules/markup/common/footnote.go | 8 +-
modules/markup/common/linkify.go | 11 +-
modules/markup/console/console.go | 9 +-
modules/markup/csv/csv.go | 8 +-
modules/markup/external/external.go | 39 +-
modules/markup/external/frontend.go | 95 +
modules/markup/html.go | 52 +-
modules/markup/html_commit.go | 63 +-
modules/markup/html_internal_test.go | 16 +-
modules/markup/html_issue.go | 3 +-
modules/markup/html_link.go | 16 +-
modules/markup/html_mention.go | 8 +-
modules/markup/html_node.go | 74 +-
modules/markup/html_node_test.go | 104 +
modules/markup/html_test.go | 61 +-
modules/markup/html_toc_test.go | 60 +
modules/markup/main_test.go | 2 +
modules/markup/markdown/goldmark.go | 24 +-
modules/markup/markdown/markdown.go | 58 +-
modules/markup/markdown/markdown_test.go | 87 +-
modules/markup/markdown/meta.go | 4 +-
modules/markup/markdown/prefixed_id.go | 59 -
modules/markup/markdown/toc.go | 59 -
modules/markup/markdown/transform_heading.go | 32 -
modules/markup/markdown/transform_list.go | 13 +-
modules/markup/mdstripper/mdstripper.go | 3 +-
modules/markup/orgmode/orgmode.go | 46 +-
modules/markup/render_link.go | 35 +-
modules/markup/render_link_test.go | 8 +
modules/markup/render_test.go | 31 +
modules/markup/renderer.go | 68 +-
modules/markup/sanitizer_default.go | 8 +-
modules/markup/sanitizer_default_test.go | 3 +
modules/markup/sanitizer_description_test.go | 2 +-
modules/migration/file_format.go | 11 +-
modules/migration/file_format_test.go | 2 +-
modules/migration/options.go | 4 +-
modules/migration/release.go | 9 +-
modules/migration/schemas_bindata.go | 12 +-
modules/migration/schemas_dynamic.go | 12 +-
modules/migration/uploader.go | 1 +
modules/nosql/manager.go | 2 +-
modules/optional/option.go | 14 +
modules/optional/serialization.go | 2 +-
modules/optional/serialization_test.go | 25 +-
modules/packages/composer/metadata.go | 148 +-
modules/packages/composer/metadata_test.go | 77 +-
modules/packages/container/metadata.go | 4 +-
modules/packages/container/metadata_test.go | 2 +
modules/packages/content_store.go | 4 +-
modules/packages/cran/metadata.go | 2 +-
modules/packages/cran/metadata_test.go | 11 +-
modules/packages/nuget/metadata.go | 2 +-
modules/packages/nuget/symbol_extractor.go | 6 +-
modules/packages/rpm/metadata.go | 49 +-
modules/packages/rubygems/metadata.go | 9 +-
modules/packages/rubygems/metadata_test.go | 127 +-
modules/packages/swift/metadata.go | 31 +-
modules/packages/swift/metadata_test.go | 75 +-
modules/packages/terraform/lock.go | 100 +
modules/packages/terraform/state.go | 38 +
modules/private/hook.go | 2 +-
modules/process/manager.go | 51 +-
modules/process/process.go | 3 +-
modules/public/manifest.go | 164 +
modules/public/manifest_test.go | 80 +
modules/public/mime_types.go | 62 +-
modules/public/public.go | 17 +-
modules/public/vitedev.go | 204 +
modules/queue/workerqueue.go | 2 +-
modules/recaptcha/recaptcha.go | 8 +-
modules/references/references.go | 30 +-
modules/references/references_test.go | 56 +
modules/repository/branch.go | 46 +-
modules/repository/commits.go | 3 +-
modules/repository/create.go | 33 +-
modules/repository/create_test.go | 3 +-
modules/repository/env.go | 72 +-
modules/repository/repo.go | 63 +-
modules/session/db.go | 13 +-
modules/session/redis.go | 26 +-
modules/session/virtual.go | 23 +-
modules/setting/actions.go | 18 +
modules/setting/actions_test.go | 59 +
modules/setting/admin.go | 22 +
modules/setting/attachment.go | 10 +-
modules/setting/config.go | 33 +-
modules/setting/config/value.go | 149 +-
modules/setting/config_env.go | 41 +-
modules/setting/config_option_instance.go | 58 +
modules/setting/config_provider.go | 27 +-
modules/setting/config_provider_test.go | 18 -
modules/setting/cors.go | 10 +-
modules/setting/git.go | 71 +-
modules/setting/incoming_email.go | 21 +-
modules/setting/indexer_test.go | 2 +-
modules/setting/lfs.go | 5 +-
modules/setting/mailer_test.go | 37 +-
modules/setting/oauth2.go | 12 +-
modules/setting/packages.go | 50 +-
modules/setting/picture.go | 25 +-
modules/setting/repository.go | 19 +-
modules/setting/security.go | 19 +-
modules/setting/server.go | 26 +-
modules/setting/session.go | 7 +-
modules/setting/setting.go | 63 +-
modules/setting/setting_test.go | 33 +-
modules/setting/storage.go | 6 +-
modules/setting/testenv.go | 72 +
modules/setting/ui.go | 12 +-
modules/storage/azureblob.go | 56 +-
modules/storage/azureblob_test.go | 25 +-
modules/storage/helper.go | 2 +-
modules/storage/helper_test.go | 2 +-
modules/storage/local.go | 79 +-
modules/storage/local_test.go | 46 +
modules/storage/minio.go | 44 +-
modules/storage/minio_test.go | 25 +-
modules/storage/storage.go | 53 +-
modules/storage/storage_test.go | 52 +
modules/structs/activity.go | 2 +-
modules/structs/activitypub.go | 10 -
modules/structs/hook.go | 8 +-
modules/structs/issue.go | 30 +-
modules/structs/issue_milestone.go | 3 +-
modules/structs/notifications.go | 17 +-
modules/structs/org.go | 20 +-
modules/structs/org_team.go | 6 +-
modules/structs/pull.go | 6 +
modules/structs/pull_review.go | 15 +-
modules/structs/repo.go | 73 +-
modules/structs/repo_actions.go | 15 +
modules/structs/repo_collaborator.go | 2 +-
modules/structs/repo_file.go | 32 +-
modules/svg/svg.go | 74 +-
modules/svg/svg_test.go | 54 +
modules/sync/status_pool.go | 57 -
modules/sync/status_pool_test.go | 31 -
modules/tempdir/tempdir.go | 2 +-
modules/templates/base.go | 23 -
modules/templates/helper.go | 77 +-
modules/templates/helper_test.go | 20 +
modules/templates/htmlrenderer.go | 127 +-
modules/templates/mail.go | 245 +
modules/templates/mailer.go | 117 -
modules/templates/page.go | 98 +
modules/templates/scopedtmpl/scopedtmpl.go | 4 +
modules/templates/util_avatar.go | 9 +-
modules/templates/util_date.go | 6 +-
modules/templates/util_date_test.go | 4 +-
modules/templates/util_misc.go | 48 +
modules/templates/util_render.go | 48 +-
modules/templates/util_render_comment.go | 48 +
modules/templates/util_render_comment_test.go | 31 +
modules/templates/vars/vars.go | 25 +-
modules/test/logchecker.go | 4 +-
modules/test/utils.go | 100 +-
modules/test/utils_test.go | 17 -
modules/testlogger/testlogger.go | 46 +-
modules/timeutil/since_test.go | 6 +-
modules/translation/i18n/i18n.go | 2 +-
modules/translation/i18n/i18n_test.go | 98 +-
modules/translation/i18n/localestore.go | 77 +-
modules/translation/mock.go | 41 +-
modules/translation/translation.go | 11 +-
modules/typesniffer/typesniffer.go | 27 +
modules/typesniffer/typesniffer_test.go | 23 +
modules/util/buffer.go | 22 +
modules/util/color.go | 9 +-
modules/util/path_test.go | 68 +
modules/util/runtime.go | 8 +-
modules/util/runtime_test.go | 4 +-
modules/util/sanitize.go | 122 +-
modules/util/sanitize_test.go | 53 +-
modules/util/timer_test.go | 24 +-
modules/util/url.go | 22 -
modules/util/util.go | 38 +-
modules/util/util_test.go | 83 +-
modules/validation/binding.go | 46 +-
modules/validation/helpers.go | 21 +-
modules/validation/helpers_test.go | 21 +
modules/web/handler.go | 28 +-
modules/web/middleware/binding.go | 2 +
modules/web/middleware/cookie.go | 23 +-
modules/web/middleware/data.go | 2 +
modules/web/router.go | 87 +-
modules/web/router_path.go | 36 +-
modules/web/router_test.go | 164 +-
modules/web/routing/context.go | 15 +-
modules/web/routing/logger.go | 37 +-
modules/web/routing/logger_manager.go | 4 +-
modules/web/routing/requestrecord.go | 5 +-
modules/webhook/type.go | 14 +
options/fileicon/material-icon-rules.json | 2715 +++-
options/fileicon/material-icon-svgs.json | 92 +-
options/license/Unlicense | 24 +-
options/locale/locale_cs-CZ.ini | 3604 -----
options/locale/locale_cs-CZ.json | 3310 +++++
options/locale/locale_de-DE.ini | 3665 -----
options/locale/locale_de-DE.json | 3252 +++++
options/locale/locale_el-GR.ini | 3296 -----
options/locale/locale_el-GR.json | 3004 ++++
options/locale/locale_en-US.json | 3850 ++++++
options/locale/locale_es-ES.ini | 3273 -----
options/locale/locale_es-ES.json | 2963 ++++
options/locale/locale_fa-IR.ini | 2454 ----
options/locale/locale_fa-IR.json | 2232 +++
options/locale/locale_fi-FI.ini | 1700 ---
options/locale/locale_fi-FI.json | 1478 ++
options/locale/locale_fr-FR.ini | 3922 ------
options/locale/locale_fr-FR.json | 3823 +++++
options/locale/locale_ga-IE.ini | 3926 ------
options/locale/locale_ga-IE.json | 3823 +++++
options/locale/locale_hu-HU.ini | 1613 ---
options/locale/locale_hu-HU.json | 1387 ++
options/locale/locale_id-ID.ini | 1444 --
options/locale/locale_id-ID.json | 1202 ++
options/locale/locale_is-IS.ini | 1341 --
options/locale/locale_is-IS.json | 1120 ++
options/locale/locale_it-IT.ini | 2714 ----
options/locale/locale_it-IT.json | 2381 ++++
options/locale/locale_ja-JP.ini | 3926 ------
options/locale/locale_ja-JP.json | 3747 +++++
options/locale/locale_ko-KR.ini | 1561 ---
options/locale/locale_ko-KR.json | 3811 +++++
options/locale/locale_lv-LV.ini | 3298 -----
options/locale/locale_lv-LV.json | 3046 ++++
options/locale/locale_nl-NL.ini | 2466 ----
options/locale/locale_nl-NL.json | 2097 +++
options/locale/locale_pl-PL.ini | 2355 ----
options/locale/locale_pl-PL.json | 2114 +++
options/locale/locale_pt-BR.ini | 3548 -----
options/locale/locale_pt-BR.json | 3290 +++++
options/locale/locale_pt-PT.ini | 3926 ------
options/locale/locale_pt-PT.json | 3728 +++++
options/locale/locale_ru-RU.ini | 3241 -----
options/locale/locale_ru-RU.json | 2986 ++++
options/locale/locale_si-LK.ini | 2399 ----
options/locale/locale_si-LK.json | 2193 +++
options/locale/locale_sk-SK.ini | 1300 --
options/locale/locale_sk-SK.json | 1164 ++
options/locale/locale_sv-SE.ini | 1976 ---
options/locale/locale_sv-SE.json | 1737 +++
options/locale/locale_tr-TR.ini | 3588 -----
options/locale/locale_tr-TR.json | 3747 +++++
options/locale/locale_uk-UA.ini | 3447 -----
options/locale/locale_uk-UA.json | 3186 +++++
options/locale/locale_zh-CN.ini | 3916 ------
options/locale/locale_zh-CN.json | 3753 +++++
options/locale/locale_zh-HK.ini | 987 --
options/locale/locale_zh-TW.ini | 3571 -----
options/locale/locale_zh-TW.json | 3301 +++++
package.json | 186 +-
playwright.config.ts | 96 +-
pnpm-lock.yaml | 7581 +++++-----
.../img/svg/gitea-colorblind-blueyellow.svg | 1 +
.../img/svg/gitea-colorblind-redgreen.svg | 1 +
public/assets/img/svg/gitea-eclipse.svg | 1 +
public/assets/img/svg/gitea-terraform.svg | 1 +
public/assets/img/svg/gitea-vscode.svg | 1 -
public/assets/img/svg/octicon-book-locked.svg | 1 +
public/assets/img/svg/octicon-boolean-off.svg | 1 +
public/assets/img/svg/octicon-boolean-on.svg | 1 +
public/assets/img/svg/octicon-comment-ai.svg | 1 +
.../assets/img/svg/octicon-comment-locked.svg | 1 +
public/assets/img/svg/octicon-compose.svg | 1 +
public/assets/img/svg/octicon-crosshairs.svg | 1 +
public/assets/img/svg/octicon-dice.svg | 1 +
public/assets/img/svg/octicon-exclamation.svg | 1 +
public/assets/img/svg/octicon-file-check.svg | 1 +
public/assets/img/svg/octicon-flowchart.svg | 1 +
.../assets/img/svg/octicon-focus-center.svg | 1 +
.../img/svg/octicon-git-branch-check.svg | 1 +
.../svg/octicon-git-pull-request-locked.svg | 1 +
.../img/svg/octicon-graph-bar-horizontal.svg | 1 +
.../img/svg/octicon-graph-bar-vertical.svg | 1 +
public/assets/img/svg/octicon-inbox-fill.svg | 1 +
.../assets/img/svg/octicon-issue-locked.svg | 1 +
.../assets/img/svg/octicon-lockup-github.svg | 1 +
public/assets/img/svg/octicon-logo-github.svg | 2 +-
public/assets/img/svg/octicon-mark-github.svg | 2 +-
public/assets/img/svg/octicon-node.svg | 1 +
public/assets/img/svg/octicon-pencil-ai.svg | 1 +
.../assets/img/svg/octicon-smiley-frown.svg | 1 +
.../img/svg/octicon-smiley-frustrated.svg | 1 +
public/assets/img/svg/octicon-smiley-grin.svg | 1 +
.../assets/img/svg/octicon-smiley-neutral.svg | 1 +
.../assets/img/svg/octicon-spacing-large.svg | 1 +
.../assets/img/svg/octicon-spacing-medium.svg | 1 +
.../assets/img/svg/octicon-spacing-small.svg | 1 +
public/assets/img/svg/octicon-split-view.svg | 1 +
public/assets/img/svg/octicon-unwrap.svg | 1 +
public/assets/img/svg/octicon-vscode.svg | 1 +
public/assets/img/svg/octicon-wrap.svg | 1 +
pyproject.toml | 2 +-
routers/api/actions/artifact.pb.go | 607 +-
routers/api/actions/artifact.proto | 3 +
routers/api/actions/artifacts.go | 28 +-
routers/api/actions/artifacts_chunks.go | 294 +-
routers/api/actions/artifacts_utils.go | 11 +-
routers/api/actions/artifactsv4.go | 355 +-
routers/api/actions/runner/runner.go | 35 +-
routers/api/packages/alpine/alpine.go | 2 +-
routers/api/packages/api.go | 52 +-
routers/api/packages/arch/arch.go | 8 +-
routers/api/packages/{conan => }/auth.go | 31 +-
routers/api/packages/chef/auth.go | 4 +-
routers/api/packages/composer/api.go | 18 +-
routers/api/packages/composer/composer.go | 18 +-
routers/api/packages/container/auth.go | 47 -
routers/api/packages/container/blob.go | 13 +-
routers/api/packages/container/container.go | 25 +-
routers/api/packages/debian/debian.go | 4 +-
routers/api/packages/helper/helper.go | 6 +-
routers/api/packages/maven/maven.go | 2 +-
routers/api/packages/npm/npm.go | 2 +-
routers/api/packages/nuget/auth.go | 32 +-
routers/api/packages/rpm/rpm.go | 199 +-
routers/api/packages/rubygems/rubygems.go | 11 +-
routers/api/packages/swift/swift.go | 33 +-
routers/api/packages/terraform/terraform.go | 438 +
.../api/packages/terraform/terraform_test.go | 36 +
routers/api/v1/activitypub/person.go | 96 +-
routers/api/v1/activitypub/reqsignature.go | 98 -
routers/api/v1/admin/adopt.go | 12 +-
routers/api/v1/admin/email.go | 2 +-
routers/api/v1/admin/hooks.go | 9 +-
routers/api/v1/admin/org.go | 4 +-
routers/api/v1/admin/runners.go | 66 +-
routers/api/v1/admin/user.go | 114 +-
routers/api/v1/api.go | 284 +-
routers/api/v1/misc/markup_test.go | 4 +-
routers/api/v1/misc/nodeinfo.go | 78 -
routers/api/v1/misc/signing.go | 9 +-
routers/api/v1/notify/repo.go | 2 +-
routers/api/v1/notify/user.go | 1 +
routers/api/v1/org/action.go | 72 +-
routers/api/v1/org/hook.go | 2 +-
routers/api/v1/org/member.go | 4 +-
routers/api/v1/org/org.go | 41 +-
routers/api/v1/org/team.go | 26 +-
routers/api/v1/packages/package.go | 43 +-
routers/api/v1/repo/action.go | 369 +-
routers/api/v1/repo/actions_run.go | 8 +-
routers/api/v1/repo/branch.go | 101 +-
routers/api/v1/repo/collaborators.go | 2 +-
routers/api/v1/repo/commits.go | 11 +-
routers/api/v1/repo/compare.go | 31 +-
routers/api/v1/repo/download.go | 32 +-
routers/api/v1/repo/file.go | 74 +-
routers/api/v1/repo/fork.go | 72 +-
routers/api/v1/repo/git_ref.go | 4 +-
routers/api/v1/repo/issue.go | 212 +-
routers/api/v1/repo/issue_attachment.go | 2 +-
routers/api/v1/repo/issue_comment.go | 37 +-
.../api/v1/repo/issue_comment_attachment.go | 2 +-
routers/api/v1/repo/issue_dependency.go | 26 +-
routers/api/v1/repo/issue_pin.go | 2 +-
routers/api/v1/repo/issue_reaction.go | 10 +-
routers/api/v1/repo/issue_stopwatch.go | 2 +-
routers/api/v1/repo/issue_subscription.go | 2 +-
routers/api/v1/repo/issue_tracked_time.go | 2 +-
routers/api/v1/repo/migrate.go | 1 +
routers/api/v1/repo/milestone.go | 8 +-
routers/api/v1/repo/mirror.go | 2 +-
routers/api/v1/repo/pull_review.go | 122 +-
routers/api/v1/repo/release.go | 32 +-
routers/api/v1/repo/release_attachment.go | 11 +-
routers/api/v1/repo/repo.go | 145 +-
routers/api/v1/repo/status.go | 7 +-
routers/api/v1/repo/tag.go | 17 +-
routers/api/v1/repo/wiki.go | 6 +-
routers/api/v1/shared/action.go | 12 +-
routers/api/v1/shared/block.go | 4 +-
routers/api/v1/shared/runners.go | 27 +-
routers/api/v1/swagger/action.go | 7 +
routers/api/v1/swagger/activitypub.go | 15 -
routers/api/v1/swagger/options.go | 5 +
routers/api/v1/user/action.go | 5 +-
routers/api/v1/user/follower.go | 8 +-
routers/api/v1/user/key.go | 20 +-
routers/api/v1/user/repo.go | 19 +-
routers/api/v1/user/runners.go | 64 +-
routers/api/v1/user/star.go | 11 +-
routers/api/v1/user/user.go | 17 +-
routers/api/v1/user/watch.go | 12 +-
routers/api/v1/utils/git.go | 3 +-
routers/api/v1/utils/hook.go | 10 +-
routers/api/v1/utils/page.go | 2 +-
routers/common/actions.go | 23 +-
routers/common/auth.go | 8 +-
routers/common/blockexpensive.go | 4 +-
routers/common/compare_test.go | 105 +
routers/common/errpage.go | 64 +-
routers/common/errpage_test.go | 33 +-
routers/common/issue_filter.go | 25 +
routers/common/maintenancemode.go | 53 +
routers/common/markup.go | 22 +-
routers/common/qos.go | 24 +-
routers/common/qos_test.go | 28 -
routers/common/redirect.go | 9 +-
routers/common/redirect_test.go | 48 +
routers/common/serve.go | 31 +-
routers/init.go | 12 +-
routers/install/install.go | 142 +-
routers/install/routes.go | 11 +-
routers/private/hook_post_receive.go | 8 +-
routers/private/hook_pre_receive.go | 65 +-
routers/private/hook_verification.go | 83 +-
routers/private/internal.go | 8 +-
routers/private/manager.go | 2 +-
routers/private/serv.go | 2 +-
routers/web/admin/admin_test.go | 23 +-
routers/web/admin/applications.go | 2 +-
routers/web/admin/auths.go | 17 +-
routers/web/admin/badges.go | 317 +
routers/web/admin/config.go | 71 +-
routers/web/admin/diagnosis.go | 8 +-
routers/web/admin/emails.go | 2 +-
routers/web/admin/notice.go | 2 +-
routers/web/admin/orgs.go | 2 +-
routers/web/admin/packages.go | 4 +-
routers/web/admin/repos.go | 6 +-
routers/web/admin/runners.go | 13 -
routers/web/admin/users.go | 46 +-
routers/web/auth/2fa.go | 10 +-
routers/web/auth/auth.go | 278 +-
routers/web/auth/auth_test.go | 94 +-
routers/web/auth/linkaccount.go | 92 +-
routers/web/auth/oauth2_provider.go | 42 +-
routers/web/auth/oauth_signin_sync.go | 2 +-
routers/web/auth/openid.go | 95 +-
routers/web/auth/password.go | 35 +-
routers/web/auth/webauthn.go | 18 +-
routers/web/base.go | 96 +-
routers/web/devtest/devtest.go | 62 +-
routers/web/devtest/mail_preview.go | 12 +-
routers/web/devtest/mock_actions.go | 60 +-
routers/web/explore/code.go | 4 +-
routers/web/explore/org.go | 4 +-
routers/web/explore/repo.go | 6 +-
routers/web/explore/user.go | 8 +-
routers/web/feed/convert.go | 6 +-
routers/web/feed/profile_test.go | 2 -
routers/web/githttp.go | 6 +-
routers/web/healthcheck/check.go | 9 +
routers/web/home.go | 2 +-
routers/web/misc/misc.go | 15 +
routers/web/misc/swagger.go | 8 +-
routers/web/misc/webtheme.go | 42 +
routers/web/org/home.go | 2 +-
routers/web/org/members.go | 47 +-
routers/web/org/mention.go | 42 +
routers/web/org/org.go | 8 +-
routers/web/org/projects.go | 167 +-
routers/web/org/projects_test.go | 30 +
routers/web/org/setting.go | 24 +-
routers/web/org/setting/runners.go | 12 -
routers/web/org/setting_oauth2.go | 2 +-
routers/web/org/teams.go | 8 +-
routers/web/repo/actions/actions.go | 223 +-
routers/web/repo/actions/view_test.go | 47 +
routers/web/repo/activity.go | 31 +-
routers/web/repo/attachment.go | 117 +-
routers/web/repo/blame.go | 137 +-
routers/web/repo/branch.go | 13 +-
routers/web/repo/commit.go | 33 +-
routers/web/repo/common_recentbranches.go | 4 +-
routers/web/repo/compare_test.go | 127 +
routers/web/repo/download.go | 61 +-
routers/web/repo/editor_apply_patch.go | 3 +-
routers/web/repo/editor_cherry_pick.go | 7 +-
routers/web/repo/editor_preview.go | 10 +-
routers/web/repo/editor_util.go | 41 +-
routers/web/repo/find.go | 24 -
routers/web/repo/githttp.go | 300 +-
routers/web/repo/issue.go | 60 +-
routers/web/repo/issue_comment.go | 273 +-
routers/web/repo/issue_content_history.go | 29 +-
routers/web/repo/issue_dependency.go | 6 +-
routers/web/repo/issue_list.go | 52 +-
routers/web/repo/issue_new.go | 10 +-
routers/web/repo/issue_page_meta.go | 45 +-
routers/web/repo/issue_poster.go | 7 +-
routers/web/repo/issue_timetrack.go | 2 +-
routers/web/repo/issue_view.go | 37 +-
routers/web/repo/mention.go | 59 +
routers/web/repo/middlewares.go | 43 +-
routers/web/repo/middlewares_test.go | 59 +
routers/web/repo/migrate.go | 43 +-
routers/web/repo/milestone.go | 6 +-
routers/web/repo/packages.go | 2 +-
routers/web/repo/projects.go | 38 +-
routers/web/repo/pull.go | 6 +-
routers/web/repo/pull_review_test.go | 2 +-
routers/web/repo/release.go | 84 +-
routers/web/repo/release_test.go | 2 +-
routers/web/repo/repo.go | 56 +-
routers/web/repo/search.go | 2 +-
routers/web/repo/setting/actions.go | 191 +
routers/web/repo/setting/collaboration.go | 2 +-
routers/web/repo/setting/deploy_key.go | 8 +-
routers/web/repo/setting/git_hooks.go | 2 +
routers/web/repo/setting/lfs.go | 23 +-
routers/web/repo/setting/protected_branch.go | 15 +-
routers/web/repo/setting/secrets.go | 4 +-
routers/web/repo/setting/setting.go | 105 +-
routers/web/repo/setting/webhook.go | 13 +-
routers/web/repo/setting/webhook_test.go | 15 +
routers/web/repo/treelist.go | 2 +-
routers/web/repo/view_home.go | 77 +-
routers/web/repo/view_readme.go | 30 +-
routers/web/repo/view_readme_test.go | 70 +
routers/web/repo/wiki.go | 35 +-
routers/web/shared/actions/general.go | 160 +
routers/web/shared/actions/runners.go | 49 +-
routers/web/shared/actions/variables.go | 2 +-
routers/web/shared/mention/mention.go | 89 +
routers/web/shared/secrets/secrets.go | 2 +-
routers/web/shared/user/header.go | 2 +-
routers/web/user/avatar.go | 2 +-
routers/web/user/code.go | 2 +-
routers/web/user/heatmap.go | 66 +
routers/web/user/home.go | 39 +-
routers/web/user/home_test.go | 2 +-
routers/web/user/notification.go | 14 +-
routers/web/user/package.go | 133 +-
routers/web/user/profile.go | 36 +-
routers/web/user/search.go | 6 +-
routers/web/user/setting/account.go | 26 +-
routers/web/user/setting/adopt.go | 10 +-
routers/web/user/setting/applications.go | 5 +-
routers/web/user/setting/block.go | 2 -
routers/web/user/setting/keys.go | 25 +-
routers/web/user/setting/oauth2.go | 6 +-
routers/web/user/setting/packages.go | 10 +-
routers/web/user/setting/profile.go | 28 +-
routers/web/user/setting/runner.go | 13 -
routers/web/user/setting/security/2fa.go | 8 +-
.../web/user/setting/security/main_test.go | 14 +
routers/web/user/setting/security/openid.go | 28 +-
.../web/user/setting/security/openid_test.go | 36 +
routers/web/user/setting/security/security.go | 1 -
routers/web/user/setting/settings.go | 8 +
routers/web/user/setting/webhooks.go | 4 +-
routers/web/user/stop_watch.go | 2 +-
services/actions/cleanup.go | 2 +
services/actions/clear_tasks.go | 129 +-
services/actions/commit_status.go | 194 +-
services/actions/commit_status_test.go | 88 +
services/actions/concurrency.go | 121 +
services/actions/context.go | 4 +-
services/actions/context_test.go | 72 +
services/actions/init_test.go | 1 -
services/actions/interface.go | 4 +-
services/actions/job_emitter.go | 311 +-
services/actions/job_emitter_test.go | 123 +-
services/actions/notifier.go | 53 +-
services/actions/notifier_helper.go | 106 +-
services/actions/permission_parser.go | 146 +
services/actions/permission_parser_test.go | 226 +
services/actions/rerun.go | 184 +-
services/actions/rerun_test.go | 97 +
services/actions/run.go | 190 +
services/actions/schedule_tasks.go | 78 +-
services/actions/schedule_tasks_test.go | 52 +
services/actions/task.go | 11 +-
services/actions/token_permission_design.md | 123 +
services/actions/variables.go | 4 +-
services/agit/agit.go | 72 +-
services/agit/agit_test.go | 45 +
services/asymkey/commit.go | 2 +-
services/asymkey/commit_test.go | 2 +-
services/asymkey/sign.go | 140 +-
services/asymkey/ssh_key_test.go | 2 +-
services/attachment/attachment.go | 13 +-
services/auth/auth.go | 100 +-
services/auth/auth_test.go | 155 -
services/auth/auth_token.go | 2 +-
services/auth/basic.go | 50 +-
services/auth/httpsign.go | 8 +-
services/auth/oauth2.go | 64 +-
services/auth/oauth2_test.go | 13 +-
services/auth/reverseproxy.go | 12 +-
services/auth/session.go | 8 +-
services/auth/signin.go | 2 +-
services/auth/source/ldap/source.go | 1 +
.../auth/source/ldap/source_authenticate.go | 4 +-
services/auth/source/ldap/source_sync.go | 4 +-
services/auth/source/oauth2/init.go | 5 +-
services/auth/source/oauth2/providers.go | 23 +-
services/auth/source/oauth2/providers_base.go | 4 +-
.../auth/source/oauth2/providers_openid.go | 2 +-
services/auth/source/oauth2/providers_test.go | 4 +-
services/auth/source/oauth2/source_sync.go | 2 +-
.../auth/source/pam/source_authenticate.go | 6 +-
.../auth/source/smtp/source_authenticate.go | 12 +-
services/auth/sspi.go | 29 +-
services/automerge/automerge.go | 12 +-
services/context/access_log.go | 14 +
services/context/access_log_test.go | 5 +
services/context/api.go | 18 +-
services/context/base.go | 16 +-
services/context/base_path.go | 13 +-
services/context/captcha.go | 30 +-
services/context/context.go | 61 +-
services/context/context_cookie.go | 2 -
services/context/context_response.go | 19 +-
services/context/context_template.go | 54 +-
services/context/context_test.go | 14 +
services/context/csrf.go | 168 -
services/context/org.go | 10 +-
services/context/package.go | 53 +-
services/context/pagination.go | 17 +-
services/context/pagination_test.go | 35 +
services/context/permission.go | 69 +-
services/context/repo.go | 121 +-
services/context/response.go | 11 +
services/context/upload/upload.go | 4 +-
services/context/xsrf.go | 99 -
services/context/xsrf_test.go | 91 -
services/contexttest/context_tests.go | 11 +-
services/convert/action_test.go | 179 +
services/convert/activity.go | 4 +-
services/convert/convert.go | 143 +-
services/convert/git_commit.go | 10 +-
services/convert/git_commit_test.go | 3 +-
services/convert/issue.go | 41 +-
services/convert/issue_test.go | 69 +
services/convert/notification.go | 24 +-
services/convert/notification_test.go | 132 +
services/convert/package.go | 2 +-
services/convert/pull.go | 26 +-
services/convert/pull_review.go | 50 +-
services/convert/repository.go | 33 +-
services/convert/status.go | 3 +
services/convert/wiki.go | 2 +-
services/cron/cron.go | 33 +-
services/cron/tasks.go | 34 +-
services/cron/tasks_basic.go | 2 +-
services/cron/tasks_test.go | 6 +-
services/doctor/checkOldArchives.go | 14 +-
services/doctor/fix16961.go | 2 +-
services/doctor/heads.go | 9 +-
services/doctor/mergebase.go | 10 +-
services/doctor/misc.go | 27 +-
services/feed/feed.go | 6 +-
services/forms/admin.go | 25 +
services/forms/auth_form.go | 1 +
services/forms/org.go | 14 +-
services/forms/package_form.go | 2 +-
services/forms/repo_form_test.go | 48 +
services/forms/user_form.go | 3 -
services/git/compare.go | 107 +
services/gitdiff/csv.go | 2 +-
services/gitdiff/git_diff_tree.go | 21 +-
services/gitdiff/gitdiff_excerpt.go | 124 +
services/gitdiff/gitdiff_excerpt_test.go | 39 +
services/gitdiff/highlightdiff.go | 271 +-
services/gitdiff/highlightdiff_test.go | 108 +-
services/issue/assignee.go | 16 +-
services/issue/commit.go | 27 +-
services/issue/commit_test.go | 56 +
services/issue/issue.go | 4 +-
services/issue/label.go | 2 +-
services/issue/pull.go | 34 +-
services/lfs/locks.go | 16 +-
services/lfs/server.go | 103 +-
services/mailer/incoming/incoming.go | 76 +-
services/mailer/incoming/incoming_handler.go | 6 +-
services/mailer/incoming/incoming_test.go | 16 +-
services/mailer/mail.go | 20 +-
services/mailer/mail_issue_common.go | 27 +-
services/mailer/mail_release.go | 13 +
services/mailer/mail_release_test.go | 64 +
services/mailer/mail_test.go | 35 +-
services/mailer/mail_workflow_run.go | 35 +-
services/mailer/mailer.go | 2 +-
services/mailer/sender/smtp_auth.go | 10 +-
services/mailer/token/token.go | 13 +-
services/markup/renderhelper_codepreview.go | 4 +-
.../markup/renderhelper_codepreview_test.go | 15 +-
.../markup/renderhelper_issueicontitle.go | 2 +-
.../renderhelper_issueicontitle_test.go | 10 +-
services/migrations/codebase_test.go | 6 +-
services/migrations/codecommit.go | 9 +-
services/migrations/dump.go | 21 +-
services/migrations/error.go | 2 +-
services/migrations/gitea_downloader.go | 56 +-
services/migrations/gitea_downloader_test.go | 23 +-
services/migrations/gitea_uploader.go | 57 +-
services/migrations/gitea_uploader_test.go | 302 -
services/migrations/github.go | 37 +-
services/migrations/github_test.go | 20 +-
services/migrations/gitlab.go | 91 +-
services/migrations/gitlab_test.go | 40 +-
services/migrations/gogs_test.go | 1 +
services/migrations/main_test.go | 7 +-
services/migrations/migrate.go | 36 +-
services/migrations/onedev.go | 14 +-
services/migrations/onedev_test.go | 4 +-
services/mirror/mirror_pull.go | 314 +-
services/mirror/mirror_pull_test.go | 56 -
services/mirror/mirror_push.go | 24 +-
services/oauth2_provider/jwtsigningkey.go | 11 +-
.../oauth2_provider/jwtsigningkey_test.go | 61 +
services/org/org.go | 33 +-
services/org/org_test.go | 66 +-
services/org/team.go | 13 +-
services/org/team_test.go | 31 +
services/packages/arch/repository.go | 2 +-
services/packages/auth.go | 13 +-
services/packages/cargo/index.go | 4 +-
services/packages/cleanup/cleanup.go | 3 +-
services/packages/container/blob_uploader.go | 14 +-
services/packages/debian/repository.go | 10 +-
services/packages/package_update.go | 4 +-
services/packages/packages.go | 81 +-
services/packages/pkgspec/manager.go | 17 +
services/packages/rpm/repository.go | 105 +-
services/packages/spec.go | 51 +
services/packages/terraform/spec.go | 85 +
services/packages/terraform/state.go | 44 +
services/projects/issue.go | 37 +-
services/projects/issue_test.go | 15 +
services/pull/check.go | 87 +-
services/pull/comment.go | 177 +-
services/pull/comment_test.go | 123 +
services/pull/commit_status.go | 24 +-
services/pull/compare.go | 95 -
services/pull/edits.go | 2 +-
services/pull/lfs.go | 87 +-
services/pull/merge.go | 76 +-
services/pull/merge_ff_only.go | 2 +-
services/pull/merge_merge.go | 2 +-
services/pull/merge_prepare.go | 152 +-
services/pull/merge_rebase.go | 21 +-
services/pull/merge_tree.go | 144 +
services/pull/merge_tree_test.go | 154 +
services/pull/patch.go | 245 +-
services/pull/patch_unmerged.go | 86 +-
services/pull/protected_branch.go | 4 +-
services/pull/review.go | 71 +-
services/pull/reviewer.go | 11 +-
services/pull/temp_repo.go | 74 +-
services/pull/update_rebase.go | 36 +-
services/pull/update_test.go | 172 +
services/release/notes.go | 188 +
services/release/notes_test.go | 97 +
services/release/release.go | 9 +-
services/repository/adopt.go | 37 +-
services/repository/adopt_test.go | 16 +-
services/repository/archiver/archiver.go | 136 +-
services/repository/archiver/archiver_test.go | 38 +-
services/repository/avatar.go | 8 +-
services/repository/cache.go | 5 +-
services/repository/check.go | 21 +-
services/repository/collaboration.go | 5 +
services/repository/collaboration_test.go | 54 +-
.../repository/commitstatus/commitstatus.go | 8 +-
services/repository/contributors_graph.go | 30 +-
services/repository/create.go | 41 +-
services/repository/delete.go | 4 +-
services/repository/files/cherry_pick.go | 11 +-
services/repository/files/commit.go | 10 -
services/repository/files/content.go | 29 +-
services/repository/files/content_test.go | 5 +-
services/repository/files/diff.go | 6 +-
services/repository/files/diff_test.go | 64 +-
services/repository/files/patch.go | 29 +-
services/repository/files/temp_repo.go | 165 +-
services/repository/files/temp_repo_test.go | 45 +
services/repository/files/tree.go | 38 +-
services/repository/files/tree_test.go | 19 +-
services/repository/files/update.go | 72 +-
services/repository/fork.go | 23 +-
services/repository/generate.go | 50 +-
services/repository/generate_test.go | 47 +-
services/repository/gitgraph/graph.go | 33 +-
services/repository/gitgraph/graph_test.go | 4 +-
services/repository/gitgraph/parser.go | 10 +-
services/repository/init.go | 19 +-
services/repository/lfs.go | 6 +-
services/repository/lfs_test.go | 30 +-
services/repository/merge_upstream.go | 4 +-
services/repository/migrate.go | 51 +-
services/repository/push.go | 2 +-
services/repository/repo_team.go | 2 +-
services/repository/repository.go | 145 +-
services/repository/repository_test.go | 40 +-
services/repository/template.go | 15 +-
services/repository/transfer.go | 60 +-
services/task/task.go | 5 +
services/user/avatar.go | 6 +-
services/user/email.go | 62 +-
services/user/email_test.go | 63 +-
services/user/user.go | 30 +-
services/user/user_test.go | 51 +-
services/webhook/deliver_test.go | 64 +-
services/webhook/dingtalk.go | 10 +-
services/webhook/discord.go | 8 +-
services/webhook/feishu.go | 11 +-
services/webhook/general.go | 3 +-
services/webhook/matrix.go | 10 +-
services/webhook/matrix_test.go | 5 +-
services/webhook/msteams.go | 8 +-
services/webhook/notifier.go | 53 +-
services/webhook/slack.go | 8 +-
services/webhook/telegram.go | 8 +-
services/webhook/wechatwork.go | 8 +-
services/webtheme/webtheme.go | 206 +-
services/webtheme/webtheme_test.go | 6 +
services/wiki/wiki.go | 50 +-
services/wiki/wiki_path.go | 6 +-
snap/part-gitea-build.sh | 19 +
snap/part-gitea-pull.sh | 62 +
snap/snapcraft.yaml | 36 +-
stylelint.config.ts => stylelint.config.js | 16 +-
tailwind.config.ts | 18 +-
templates/admin/auth/edit.tmpl | 7 +-
templates/admin/auth/list.tmpl | 2 +-
templates/admin/auth/new.tmpl | 92 +-
templates/admin/auth/source/ldap.tmpl | 6 +
templates/admin/badge/edit.tmpl | 44 +
templates/admin/badge/list.tmpl | 67 +
templates/admin/badge/new.tmpl | 26 +
templates/admin/badge/users.tmpl | 40 +
templates/admin/badge/view.tmpl | 44 +
templates/admin/config.tmpl | 16 +-
templates/admin/config_settings/avatars.tmpl | 12 +-
.../config_settings/config_settings.tmpl | 8 +-
templates/admin/config_settings/instance.tmpl | 63 +
.../admin/config_settings/repository.tmpl | 15 +-
templates/admin/cron.tmpl | 3 +-
templates/admin/dashboard.tmpl | 1 -
templates/admin/emails/list.tmpl | 4 +-
templates/admin/layout_head.tmpl | 2 +-
templates/admin/navbar.tmpl | 5 +-
templates/admin/notice.tmpl | 5 +-
templates/admin/org/list.tmpl | 11 +-
templates/admin/packages/list.tmpl | 10 +-
templates/admin/queue.tmpl | 2 +-
templates/admin/queue_manage.tmpl | 4 +-
templates/admin/repo/list.tmpl | 7 +-
templates/admin/repo/unadopted.tmpl | 4 +-
templates/admin/stacktrace-row.tmpl | 2 +-
templates/admin/stats.tmpl | 2 +-
templates/admin/user/edit.tmpl | 5 +-
templates/admin/user/list.tmpl | 2 +-
templates/admin/user/new.tmpl | 1 -
templates/base/footer.tmpl | 1 +
templates/base/footer_content.tmpl | 15 +-
templates/base/head.tmpl | 6 +-
templates/base/head_banner.tmpl | 11 +
templates/base/head_navbar.tmpl | 40 +-
templates/base/head_navbar_icons.tmpl | 9 +-
templates/base/head_opengraph.tmpl | 4 +-
templates/base/head_script.tmpl | 20 +-
templates/base/head_style.tmpl | 4 +-
templates/base/markup_codepreview.tmpl | 5 +-
templates/base/modal_actions_confirm.tmpl | 8 +-
templates/devtest/devtest-footer.tmpl | 2 -
templates/devtest/devtest-header.tmpl | 3 +-
templates/devtest/flex-list.tmpl | 8 +-
templates/devtest/form-fields.tmpl | 109 +
templates/devtest/gitea-ui.tmpl | 29 +-
templates/devtest/keyboard-shortcut.tmpl | 23 +
templates/devtest/relative-time.tmpl | 66 +
templates/devtest/repo-action-view.tmpl | 14 +-
templates/devtest/severity-colors.tmpl | 115 +
templates/devtest/unicode-escape.tmpl | 17 +
templates/home.tmpl | 2 +-
templates/install.tmpl | 26 +-
templates/mail/repo/release.tmpl | 2 +-
templates/org/create.tmpl | 1 -
templates/org/header.tmpl | 6 +-
templates/org/home.tmpl | 20 +-
templates/org/member/members.tmpl | 75 +-
templates/org/settings/actions_general.tmpl | 5 +
templates/org/settings/labels.tmpl | 2 +-
templates/org/settings/navbar.tmpl | 5 +-
templates/org/settings/options.tmpl | 2 -
.../org/settings/options_dangerzone.tmpl | 7 +-
templates/org/team/invite.tmpl | 1 -
templates/org/team/members.tmpl | 4 +-
templates/org/team/new.tmpl | 1 -
templates/org/team/repositories.tmpl | 16 +-
templates/org/team/sidebar.tmpl | 10 +-
templates/org/team/teams.tmpl | 14 +-
templates/org/worktime/empty_placeholder.tmpl | 9 +
templates/org/worktime/table_members.tmpl | 2 +
templates/org/worktime/table_milestones.tmpl | 2 +
templates/org/worktime/table_repos.tmpl | 2 +
templates/package/content/alpine.tmpl | 4 +-
templates/package/content/arch.tmpl | 6 +-
templates/package/content/cargo.tmpl | 4 +-
templates/package/content/chef.tmpl | 2 +-
templates/package/content/composer.tmpl | 2 +-
templates/package/content/conan.tmpl | 2 +-
templates/package/content/conda.tmpl | 6 +-
templates/package/content/container.tmpl | 2 +-
templates/package/content/cran.tmpl | 2 +-
templates/package/content/debian.tmpl | 4 +-
templates/package/content/generic.tmpl | 2 +-
templates/package/content/go.tmpl | 2 +-
templates/package/content/helm.tmpl | 2 +-
templates/package/content/maven.tmpl | 10 +-
templates/package/content/npm.tmpl | 2 +-
templates/package/content/nuget.tmpl | 6 +-
templates/package/content/pub.tmpl | 2 +-
templates/package/content/pypi.tmpl | 2 +-
templates/package/content/rpm.tmpl | 10 +-
templates/package/content/rubygems.tmpl | 4 +-
templates/package/content/swift.tmpl | 2 +-
templates/package/content/terraform.tmpl | 26 +
templates/package/content/vagrant.tmpl | 2 +-
templates/package/metadata/alpine.tmpl | 2 +-
templates/package/metadata/arch.tmpl | 2 +-
templates/package/metadata/cargo.tmpl | 6 +-
templates/package/metadata/chef.tmpl | 2 +-
templates/package/metadata/composer.tmpl | 2 +-
templates/package/metadata/conan.tmpl | 4 +-
templates/package/metadata/conda.tmpl | 6 +-
templates/package/metadata/container.tmpl | 6 +-
templates/package/metadata/cran.tmpl | 2 +-
templates/package/metadata/debian.tmpl | 2 +-
templates/package/metadata/helm.tmpl | 2 +-
templates/package/metadata/maven.tmpl | 2 +-
templates/package/metadata/npm.tmpl | 2 +-
templates/package/metadata/nuget.tmpl | 4 +-
templates/package/metadata/pub.tmpl | 6 +-
templates/package/metadata/pypi.tmpl | 2 +-
templates/package/metadata/rpm.tmpl | 2 +-
templates/package/metadata/rubygems.tmpl | 2 +-
templates/package/metadata/swift.tmpl | 2 +-
templates/package/metadata/terraform.tmpl | 41 +
templates/package/metadata/vagrant.tmpl | 4 +-
templates/package/settings.tmpl | 32 +-
templates/package/shared/cargo.tmpl | 2 -
.../package/shared/cleanup_rules/edit.tmpl | 1 -
.../package/shared/cleanup_rules/preview.tmpl | 9 +-
templates/package/shared/list.tmpl | 7 +-
templates/package/shared/versionlist.tmpl | 8 +-
templates/package/shared/view.tmpl | 32 +-
.../package/shared/visibility_badge.tmpl | 7 +
templates/package/view.tmpl | 2 +
templates/projects/list.tmpl | 17 +-
templates/projects/new.tmpl | 10 +-
templates/projects/view.tmpl | 14 +-
templates/repo/actions/list.tmpl | 99 +-
templates/repo/actions/runs_list.tmpl | 22 +-
templates/repo/actions/status.tmpl | 14 +-
templates/repo/actions/view.tmpl | 4 +-
templates/repo/actions/view_component.tmpl | 12 +-
templates/repo/actions/workflow_dispatch.tmpl | 10 +-
.../actions/workflow_dispatch_inputs.tmpl | 2 +-
templates/repo/blame.tmpl | 20 +-
templates/repo/branch/list.tmpl | 30 +-
.../code/recently_pushed_new_branches.tmpl | 2 +-
templates/repo/commit_page.tmpl | 8 +-
templates/repo/commit_status.tmpl | 12 +-
templates/repo/commits_list.tmpl | 23 +-
templates/repo/commits_ref_name.tmpl | 9 +
templates/repo/commits_table.tmpl | 8 +-
templates/repo/create.tmpl | 1 -
templates/repo/diff/blob_excerpt.tmpl | 96 +-
templates/repo/diff/box.tmpl | 77 +-
templates/repo/diff/comment_form.tmpl | 6 +-
templates/repo/diff/comments.tmpl | 8 +-
templates/repo/diff/compare.tmpl | 88 +-
templates/repo/diff/conversation.tmpl | 2 +-
templates/repo/diff/escape_title.tmpl | 2 -
templates/repo/diff/new_review.tmpl | 8 +-
templates/repo/diff/section_code.tmpl | 2 +-
templates/repo/diff/section_split.tmpl | 34 +-
templates/repo/diff/section_unified.tmpl | 34 +-
templates/repo/diff/stats.tmpl | 22 +-
templates/repo/editor/cherry_pick.tmpl | 1 -
templates/repo/editor/commit_form.tmpl | 2 +-
templates/repo/editor/common_breadcrumb.tmpl | 2 +-
templates/repo/editor/delete.tmpl | 28 +-
templates/repo/editor/edit.tmpl | 90 +-
templates/repo/editor/fork.tmpl | 1 -
templates/repo/editor/options.tmpl | 32 +
templates/repo/editor/patch.tmpl | 24 +-
templates/repo/editor/upload.tmpl | 27 +-
templates/repo/find/files.tmpl | 21 -
templates/repo/graph.tmpl | 4 +-
templates/repo/graph/commits.tmpl | 13 +-
templates/repo/header.tmpl | 8 +-
templates/repo/home_sidebar_top.tmpl | 10 +-
.../repo/issue/branch_selector_field.tmpl | 7 +-
templates/repo/issue/card.tmpl | 8 +-
templates/repo/issue/comment_tab.tmpl | 3 +-
templates/repo/issue/fields/textarea.tmpl | 3 +-
.../repo/issue/filter_item_milestone.tmpl | 42 +
.../repo/issue/filter_item_user_assign.tmpl | 2 +-
templates/repo/issue/filter_list.tmpl | 54 +-
.../repo/issue/labels/label_edit_modal.tmpl | 1 -
.../issue/labels/label_load_template.tmpl | 1 -
templates/repo/issue/list.tmpl | 5 +-
templates/repo/issue/milestone_issues.tmpl | 2 +-
templates/repo/issue/milestone_new.tmpl | 4 +-
templates/repo/issue/milestones.tmpl | 4 +-
templates/repo/issue/new_form.tmpl | 5 +-
templates/repo/issue/search.tmpl | 2 +-
.../repo/issue/sidebar/assignee_list.tmpl | 8 +-
templates/repo/issue/sidebar/due_date.tmpl | 3 +-
.../issue/sidebar/issue_dependencies.tmpl | 8 +-
.../repo/issue/sidebar/issue_management.tmpl | 3 -
templates/repo/issue/sidebar/label_list.tmpl | 7 +-
.../repo/issue/sidebar/label_list_item.tmpl | 3 +-
.../repo/issue/sidebar/milestone_list.tmpl | 8 +-
.../repo/issue/sidebar/project_list.tmpl | 10 +-
.../repo/issue/sidebar/reviewer_list.tmpl | 5 +-
.../issue/sidebar/stopwatch_timetracker.tmpl | 2 -
templates/repo/issue/view_content.tmpl | 38 +-
.../repo/issue/view_content/add_reaction.tmpl | 2 +-
.../repo/issue/view_content/attachments.tmpl | 8 +-
.../repo/issue/view_content/comments.tmpl | 64 +-
.../view_content/comments_authorlink.tmpl | 2 +-
.../view_content/comments_delete_time.tmpl | 2 +-
.../repo/issue/view_content/context_menu.tmpl | 1 +
.../repo/issue/view_content/conversation.tmpl | 11 +-
.../issue/view_content/pull_merge_box.tmpl | 75 +-
.../view_content/pull_merge_instruction.tmpl | 2 +-
.../repo/issue/view_content/reactions.tmpl | 4 +-
.../view_content/reference_issue_dialog.tmpl | 1 -
.../repo/issue/view_content/sidebar.tmpl | 2 +-
.../view_content/update_branch_by_merge.tmpl | 1 -
.../repo/issue/view_content/watching.tmpl | 4 +-
templates/repo/latest_commit.tmpl | 22 +-
templates/repo/migrate/codebase.tmpl | 1 -
templates/repo/migrate/codecommit.tmpl | 1 -
templates/repo/migrate/git.tmpl | 1 -
templates/repo/migrate/gitbucket.tmpl | 1 -
templates/repo/migrate/gitea.tmpl | 1 -
templates/repo/migrate/github.tmpl | 1 -
templates/repo/migrate/gitlab.tmpl | 1 -
templates/repo/migrate/gogs.tmpl | 1 -
templates/repo/migrate/migrate.tmpl | 2 +-
templates/repo/migrate/migrating.tmpl | 10 +-
templates/repo/migrate/onedev.tmpl | 1 -
templates/repo/pulls/fork.tmpl | 1 -
templates/repo/pulls/status.tmpl | 55 +-
templates/repo/pulls/tab_menu.tmpl | 7 +-
templates/repo/pulse.tmpl | 12 +-
templates/repo/release/list.tmpl | 2 +-
templates/repo/release/new.tmpl | 210 +-
templates/repo/search_name.tmpl | 2 +-
templates/repo/settings/actions.tmpl | 2 +
templates/repo/settings/actions_general.tmpl | 100 +
templates/repo/settings/branches.tmpl | 28 +-
templates/repo/settings/collaboration.tmpl | 4 +-
templates/repo/settings/deploy_keys.tmpl | 5 +-
templates/repo/settings/githook_edit.tmpl | 29 +-
templates/repo/settings/githooks.tmpl | 2 +-
templates/repo/settings/lfs.tmpl | 1 -
templates/repo/settings/lfs_file_find.tmpl | 2 +-
templates/repo/settings/lfs_locks.tmpl | 2 -
templates/repo/settings/lfs_pointers.tmpl | 1 -
templates/repo/settings/navbar.tmpl | 9 +-
templates/repo/settings/options.tmpl | 195 +-
templates/repo/settings/protected_branch.tmpl | 1 -
templates/repo/settings/public_access.tmpl | 1 -
.../repo/settings/push_mirror_sync_modal.tmpl | 1 -
.../settings/repo_name_confirm_fields.tmpl | 10 +
templates/repo/settings/tags.tmpl | 2 -
.../repo/settings/webhook/base_list.tmpl | 7 +-
templates/repo/settings/webhook/dingtalk.tmpl | 1 -
templates/repo/settings/webhook/discord.tmpl | 1 -
templates/repo/settings/webhook/feishu.tmpl | 1 -
templates/repo/settings/webhook/gitea.tmpl | 1 -
templates/repo/settings/webhook/gogs.tmpl | 1 -
templates/repo/settings/webhook/history.tmpl | 9 +-
templates/repo/settings/webhook/matrix.tmpl | 1 -
templates/repo/settings/webhook/msteams.tmpl | 1 -
.../repo/settings/webhook/packagist.tmpl | 1 -
templates/repo/settings/webhook/settings.tmpl | 6 +
templates/repo/settings/webhook/slack.tmpl | 1 -
templates/repo/settings/webhook/telegram.tmpl | 1 -
.../repo/settings/webhook/wechatwork.tmpl | 1 -
templates/repo/tag/list.tmpl | 2 +-
templates/repo/user_cards.tmpl | 4 +-
templates/repo/view.tmpl | 4 +-
templates/repo/view_content.tmpl | 106 +-
templates/repo/view_file.tmpl | 14 +-
templates/repo/view_file_tree.tmpl | 30 +-
.../repo/view_file_tree_toggle_button.tmpl | 6 +
templates/repo/view_list.tmpl | 6 +-
templates/repo/wiki/new.tmpl | 4 +-
templates/repo/wiki/pages.tmpl | 2 +-
.../actions/owner_general_settings.tmpl | 58 +
.../actions/permission_mode_select.tmpl | 18 +
.../shared/actions/permissions_table.tmpl | 77 +
.../actions/permissions_table_unit.tmpl | 24 +
templates/shared/actions/runner_edit.tmpl | 20 +-
templates/shared/actions/runner_list.tmpl | 9 +-
templates/shared/combomarkdowneditor.tmpl | 29 +-
templates/shared/issueicon.tmpl | 14 +-
templates/shared/issuelist.tmpl | 10 +-
templates/shared/repo/list.tmpl | 4 +-
templates/shared/repo/search.tmpl | 2 +-
templates/shared/search/code/search.tmpl | 6 +
templates/shared/search/combo.tmpl | 27 +-
templates/shared/secrets/add_list.tmpl | 1 -
templates/shared/user/authorlink.tmpl | 2 +-
templates/shared/user/avatarlink.tmpl | 2 +-
templates/shared/user/block_user_dialog.tmpl | 5 +-
templates/shared/user/blocked_users.tmpl | 13 +-
templates/shared/user/org_profile_avatar.tmpl | 4 +-
templates/shared/user/profile_big_avatar.tmpl | 24 +-
templates/shared/variables/variable_list.tmpl | 1 -
templates/status/500.tmpl | 6 +-
templates/swagger/openapi-viewer.tmpl | 16 +
templates/swagger/ui.tmpl | 14 -
templates/user/auth/activate.tmpl | 1 -
templates/user/auth/captcha.tmpl | 7 +-
templates/user/auth/change_passwd_inner.tmpl | 1 -
.../user/auth/external_auth_methods.tmpl | 17 +
templates/user/auth/forgot_passwd.tmpl | 1 -
templates/user/auth/grant.tmpl | 1 -
templates/user/auth/oauth_container.tmpl | 24 -
templates/user/auth/reset_passwd.tmpl | 1 -
templates/user/auth/signin_inner.tmpl | 12 +-
templates/user/auth/signin_openid.tmpl | 1 -
templates/user/auth/signup_inner.tmpl | 9 +-
.../user/auth/signup_openid_connect.tmpl | 1 -
.../user/auth/signup_openid_register.tmpl | 1 -
templates/user/auth/twofa.tmpl | 1 -
templates/user/auth/twofa_scratch.tmpl | 1 -
templates/user/dashboard/feeds.tmpl | 26 +-
templates/user/dashboard/issues.tmpl | 2 +-
templates/user/dashboard/milestones.tmpl | 4 +-
templates/user/heatmap.tmpl | 6 +-
.../user/notification/notification_div.tmpl | 8 +-
templates/user/settings/account.tmpl | 5 -
templates/user/settings/actions_general.tmpl | 3 +
templates/user/settings/appearance.tmpl | 21 +-
templates/user/settings/applications.tmpl | 7 +-
.../applications_oauth2_edit_form.tmpl | 3 -
.../settings/applications_oauth2_list.tmpl | 5 +-
templates/user/settings/keys_gpg.tmpl | 4 +-
templates/user/settings/keys_principal.tmpl | 3 +-
templates/user/settings/keys_ssh.tmpl | 6 +-
templates/user/settings/navbar.tmpl | 5 +-
templates/user/settings/notifications.tmpl | 2 -
templates/user/settings/organization.tmpl | 1 -
templates/user/settings/packages.tmpl | 1 -
templates/user/settings/profile.tmpl | 10 +-
templates/user/settings/repos.tmpl | 8 +-
.../user/settings/security/accountlinks.tmpl | 4 +-
templates/user/settings/security/openid.tmpl | 2 -
templates/user/settings/security/twofa.tmpl | 2 -
.../user/settings/security/twofa_enroll.tmpl | 1 -
templates/webhook/new.tmpl | 2 +-
tests/e2e/README.md | 92 -
tests/e2e/codeeditor.test.ts | 20 +
tests/e2e/e2e_test.go | 115 -
tests/e2e/env.d.ts | 9 +
tests/e2e/events.test.ts | 89 +
tests/e2e/example.test.e2e.ts | 56 -
tests/e2e/explore.test.ts | 17 +
tests/e2e/external-render.test.ts | 61 +
tests/e2e/file-view-render.test.ts | 69 +
tests/e2e/licenses.test.ts | 9 +
tests/e2e/login.test.ts | 12 +
tests/e2e/mermaid.test.ts | 22 +
tests/e2e/milestone.test.ts | 13 +
tests/e2e/org.test.ts | 13 +
tests/e2e/reactions.test.ts | 30 +
tests/e2e/readme.test.ts | 11 +
tests/e2e/register.test.ts | 70 +
tests/e2e/relative-time.test.ts | 10 +
tests/e2e/repo.test.ts | 13 +
tests/e2e/user-settings.test.ts | 20 +
tests/e2e/utils.ts | 138 +
tests/e2e/utils_e2e.ts | 62 -
tests/e2e/utils_e2e_test.go | 56 -
tests/integration/actions_approve_test.go | 142 +
tests/integration/actions_concurrency_test.go | 1679 +++
tests/integration/actions_delete_run_test.go | 43 +-
tests/integration/actions_inputs_test.go | 5 +-
tests/integration/actions_job_test.go | 117 +
tests/integration/actions_job_token_test.go | 476 +
.../integration/actions_log_finalize_test.go | 77 +
tests/integration/actions_log_test.go | 18 +-
tests/integration/actions_route_test.go | 300 +
.../integration/actions_runner_modify_test.go | 24 +-
tests/integration/actions_runner_test.go | 26 +-
tests/integration/actions_settings_test.go | 81 +
tests/integration/actions_variables_test.go | 9 +-
tests/integration/admin_config_test.go | 46 +
tests/integration/admin_user_test.go | 11 +-
.../api_actions_artifact_v4_test.go | 508 +-
.../api_actions_permission_test.go | 54 +
tests/integration/api_actions_run_test.go | 176 +-
tests/integration/api_actions_runner_test.go | 107 +-
.../api_activitypub_person_test.go | 88 -
tests/integration/api_branch_test.go | 127 +-
tests/integration/api_fork_test.go | 50 +-
tests/integration/api_gpg_keys_test.go | 6 +-
tests/integration/api_httpsig_test.go | 2 -
tests/integration/api_issue_config_test.go | 17 +
tests/integration/api_issue_reaction_test.go | 14 +-
tests/integration/api_issue_templates_test.go | 18 +
tests/integration/api_issue_test.go | 124 +-
.../api_issue_tracked_time_test.go | 6 +
tests/integration/api_nodeinfo_test.go | 35 -
tests/integration/api_notification_test.go | 22 +-
tests/integration/api_org_test.go | 53 +-
tests/integration/api_packages_arch_test.go | 37 +-
.../integration/api_packages_composer_test.go | 83 +
tests/integration/api_packages_conan_test.go | 7 +-
.../api_packages_container_test.go | 40 +-
.../integration/api_packages_generic_test.go | 31 +-
tests/integration/api_packages_maven_test.go | 2 +-
tests/integration/api_packages_nuget_test.go | 31 +
tests/integration/api_packages_rpm_test.go | 472 +-
tests/integration/api_packages_swift_test.go | 74 +-
.../api_packages_terraform_test.go | 302 +
tests/integration/api_packages_test.go | 44 +
tests/integration/api_private_serv_test.go | 8 +-
tests/integration/api_public_only_test.go | 107 +
tests/integration/api_pull_review_test.go | 77 +-
tests/integration/api_pull_test.go | 81 +-
.../api_releases_attachment_test.go | 39 +-
tests/integration/api_repo_branch_test.go | 14 +-
tests/integration/api_repo_compare_test.go | 58 +-
tests/integration/api_repo_edit_test.go | 15 +
.../integration/api_repo_file_create_test.go | 11 +-
.../integration/api_repo_file_delete_test.go | 26 +-
tests/integration/api_repo_file_get_test.go | 6 +-
.../integration/api_repo_file_update_test.go | 42 +-
.../integration/api_repo_files_change_test.go | 79 +
.../api_repo_get_contents_list_test.go | 9 +-
.../integration/api_repo_get_contents_test.go | 25 +-
tests/integration/api_repo_git_tags_test.go | 8 +-
tests/integration/api_repo_hook_test.go | 51 +
tests/integration/api_repo_languages_test.go | 1 -
tests/integration/api_repo_lfs_test.go | 18 +-
tests/integration/api_repo_license_test.go | 1 -
tests/integration/api_repo_test.go | 12 +
tests/integration/api_token_test.go | 11 +-
tests/integration/api_user_org_perm_test.go | 80 +-
tests/integration/api_user_orgs_test.go | 41 +
.../integration/api_user_public_only_test.go | 177 +
tests/integration/api_user_star_test.go | 22 +
tests/integration/api_user_watch_test.go | 25 +
tests/integration/auth_ldap_test.go | 16 +-
tests/integration/branches_test.go | 4 +-
.../integration/change_default_branch_test.go | 14 +-
tests/integration/cmd_keys_test.go | 6 +-
tests/integration/compare_test.go | 76 +
tests/integration/config_instance_test.go | 126 +
tests/integration/create_no_session_test.go | 2 -
tests/integration/csrf_test.go | 34 -
tests/integration/delete_user_test.go | 10 +-
tests/integration/download_test.go | 252 +-
tests/integration/editor_test.go | 55 +-
tests/integration/empty_repo_test.go | 4 -
tests/integration/git_general_test.go | 105 +-
.../git_helper_for_declarative_test.go | 98 +-
tests/integration/git_misc_test.go | 23 +-
tests/integration/git_push_test.go | 4 +-
tests/integration/git_smart_http_test.go | 48 +
tests/integration/gpg_ssh_git_test.go | 47 +
tests/integration/heatmap_test.go | 59 +
tests/integration/html_helper.go | 5 -
tests/integration/incoming_email_test.go | 11 +-
tests/integration/integration_test.go | 73 +-
tests/integration/issue_test.go | 47 +-
tests/integration/issue_timetrack_test.go | 32 +
tests/integration/linguist_test.go | 11 +
tests/integration/manual_merge_test.go | 104 +
tests/integration/migrate_test.go | 182 +-
.../migration-test/migration_test.go | 22 +-
tests/integration/mirror_push_test.go | 43 +-
tests/integration/nonascii_branches_test.go | 2 -
tests/integration/oauth_avatar_test.go | 92 +
tests/integration/oauth_test.go | 239 +-
tests/integration/org_project_test.go | 2 -
tests/integration/org_team_invite_test.go | 31 +-
tests/integration/org_test.go | 58 +-
tests/integration/packages_service_test.go | 118 +
tests/integration/privateactivity_test.go | 1 -
tests/integration/project_test.go | 170 +-
tests/integration/pull_comment_test.go | 3 +-
tests/integration/pull_commit_test.go | 2 +-
tests/integration/pull_compare_test.go | 2 -
tests/integration/pull_diff_test.go | 37 +-
tests/integration/pull_review_test.go | 33 +-
tests/integration/pull_status_test.go | 64 +-
tests/integration/release_test.go | 1 -
tests/integration/rename_branch_test.go | 30 +-
tests/integration/repo_activity_test.go | 5 +-
tests/integration/repo_archive_test.go | 39 +-
tests/integration/repo_branch_test.go | 30 +-
tests/integration/repo_commits_test.go | 192 +-
tests/integration/repo_fork_test.go | 1 -
tests/integration/repo_generate_test.go | 1 -
tests/integration/repo_merge_upstream_test.go | 12 +-
tests/integration/repo_migrate_test.go | 1 -
tests/integration/repo_tag_test.go | 24 +-
tests/integration/repo_test.go | 44 +-
tests/integration/repo_visibility_test.go | 59 +
tests/integration/repofiles_change_test.go | 234 +-
tests/integration/schemas/nodeinfo_2.1.json | 188 -
tests/integration/signin_test.go | 4 +-
tests/integration/signout_test.go | 33 +-
tests/integration/ssh_key_test.go | 4 +-
tests/integration/timetracking_test.go | 8 +-
tests/integration/user_avatar_test.go | 84 +-
tests/integration/user_settings_test.go | 75 +-
tests/integration/user_test.go | 95 +-
tests/integration/view_test.go | 16 +
tests/integration/webfinger_test.go | 66 -
tests/integration/wiki_test.go | 148 +-
.../workflow_run_api_check_test.go | 4 +
tests/integration/xss_test.go | 39 -
tests/mssql.ini.tmpl | 24 +-
tests/mysql.ini.tmpl | 25 +-
tests/pgsql.ini.tmpl | 24 +-
tests/test_utils.go | 42 +-
{build => tools}/code-batch-process.go | 16 +-
{build => tools}/codeformat/formatimports.go | 0
.../codeformat/formatimports_test.go | 0
tools/generate-svg.ts | 26 +-
{build => tools}/gocovmerge.go | 0
tools/lint-go-gopls.sh | 23 -
tools/test-e2e.sh | 114 +
{build => tools}/test-echo.go | 0
tsconfig.json | 33 +-
types.d.ts | 93 +-
updates.config.ts | 10 +-
uv.lock | 397 +-
vite.config.ts | 342 +
vitest.config.ts | 4 +
web_src/css/actions.css | 8 -
web_src/css/admin.css | 8 +
web_src/css/chroma/base.css | 46 -
web_src/css/chroma/dark.css | 76 -
web_src/css/chroma/light.css | 76 -
web_src/css/codemirror/base.css | 49 -
web_src/css/codemirror/dark.css | 106 -
web_src/css/codemirror/light.css | 1 -
web_src/css/dashboard.css | 5 -
web_src/css/{standalone => }/devtest.css | 0
web_src/css/easymde.css | 465 +
web_src/css/editor/fileeditor.css | 76 -
.../external-render-iframe.css | 0
web_src/css/features/captcha.css | 33 +
web_src/css/features/codeeditor.css | 42 -
web_src/css/features/gitgraph.css | 4 -
web_src/css/form.css | 312 -
web_src/css/home.css | 27 +-
web_src/css/index.css | 15 +-
web_src/css/markup/asciicast.css | 4 +-
web_src/css/markup/codeblock.css | 10 +
web_src/css/markup/codecopy.css | 30 -
web_src/css/modules/animations.css | 11 +-
web_src/css/modules/breadcrumb.css | 1 +
web_src/css/modules/button.css | 7 +-
web_src/css/modules/charescape.css | 55 +
web_src/css/modules/checkbox.css | 75 +-
web_src/css/modules/chroma.css | 79 +
web_src/css/modules/codeeditor.css | 569 +
web_src/css/modules/comment.css | 9 -
web_src/css/modules/container.css | 18 +
web_src/css/modules/divider.css | 5 -
web_src/css/modules/dropdown.css | 954 ++
web_src/css/modules/form.css | 483 +
web_src/css/modules/input.css | 5 +-
web_src/css/modules/label.css | 1 +
web_src/css/modules/list.css | 9 -
web_src/css/modules/message.css | 27 +-
web_src/css/modules/modal.css | 301 +-
web_src/css/modules/navbar.css | 26 +-
web_src/css/modules/search.css | 86 +
web_src/css/modules/shortcut.css | 26 +
web_src/css/modules/table.css | 32 -
web_src/css/repo.css | 206 +-
web_src/css/repo/commit-sign.css | 4 +
web_src/css/repo/home.css | 10 +-
web_src/css/repo/release-tag.css | 43 -
web_src/css/repo/wiki.css | 6 +-
web_src/css/review.css | 38 +-
web_src/css/standalone/swagger.css | 42 -
web_src/css/swagger-render.css | 13 +
web_src/css/swagger-standalone.css | 29 +
...eme-gitea-auto-protanopia-deuteranopia.css | 4 +-
.../themes/theme-gitea-auto-tritanopia.css | 8 +
web_src/css/themes/theme-gitea-auto.css | 1 +
...eme-gitea-dark-protanopia-deuteranopia.css | 19 +-
.../themes/theme-gitea-dark-tritanopia.css | 15 +
web_src/css/themes/theme-gitea-dark.css | 254 +-
...me-gitea-light-protanopia-deuteranopia.css | 19 +-
.../themes/theme-gitea-light-tritanopia.css | 15 +
web_src/css/themes/theme-gitea-light.css | 108 +-
web_src/css/user.css | 22 +-
web_src/fomantic/build/components/api.js | 4 +-
.../fomantic/build/components/dropdown.css | 1755 ---
web_src/fomantic/build/components/dropdown.js | 7 +-
web_src/fomantic/build/components/form.css | 1633 ---
web_src/fomantic/build/components/modal.css | 698 -
web_src/fomantic/build/components/modal.js | 2 +-
web_src/fomantic/build/components/search.css | 520 -
web_src/fomantic/build/fomantic.css | 4 -
web_src/fomantic/semantic.json | 4 -
web_src/js/bootstrap.test.ts | 12 -
web_src/js/bootstrap.ts | 84 +-
web_src/js/components/ActionRunJobView.vue | 721 +
web_src/js/components/ActionRunStatus.vue | 14 +-
.../js/components/ActionRunSummaryView.vue | 70 +
web_src/js/components/ActionRunView.test.ts | 32 +
web_src/js/components/ActionRunView.ts | 181 +
web_src/js/components/ActivityHeatmap.vue | 4 +-
web_src/js/components/DashboardRepoList.vue | 100 +-
web_src/js/components/DiffCommitSelector.vue | 18 +-
web_src/js/components/DiffFileTree.vue | 17 +-
web_src/js/components/DiffFileTreeItem.vue | 14 +-
.../js/components/PullRequestMergeForm.vue | 10 +-
web_src/js/components/RepoActionView.vue | 957 +-
.../js/components/RepoActivityTopAuthors.vue | 7 +-
.../js/components/RepoBranchTagSelector.vue | 57 +-
web_src/js/components/RepoCodeFrequency.vue | 4 +-
web_src/js/components/RepoContributors.vue | 32 +-
web_src/js/components/RepoFileSearch.vue | 233 +
web_src/js/components/RepoRecentCommits.vue | 8 +-
web_src/js/components/ViewFileTree.vue | 6 +-
web_src/js/components/ViewFileTreeItem.vue | 22 +-
web_src/js/components/WorkflowGraph.vue | 802 ++
.../eventsource.sharedworker.ts | 24 +-
web_src/js/external-render-frontend.ts | 67 +
web_src/js/external-render-helper.test.ts | 25 +
web_src/js/external-render-helper.ts | 95 +
web_src/js/features/admin/common.ts | 41 +-
web_src/js/features/admin/config.test.ts | 48 +
web_src/js/features/admin/config.ts | 225 +-
web_src/js/features/admin/selfcheck.ts | 4 +-
web_src/js/features/captcha.ts | 23 +-
web_src/js/features/citation.ts | 27 +-
web_src/js/features/clipboard.ts | 19 +-
web_src/js/features/code-frequency.ts | 2 +-
web_src/js/features/codeeditor.ts | 242 -
web_src/js/features/colorpicker.ts | 19 +-
.../js/features/common-actions-permissions.ts | 34 +
web_src/js/features/common-button.ts | 21 +-
web_src/js/features/common-fetch-action.ts | 17 +-
web_src/js/features/common-form.ts | 9 +-
web_src/js/features/common-issue-list.test.ts | 2 +-
web_src/js/features/common-issue-list.ts | 39 +-
web_src/js/features/common-organization.ts | 2 +-
web_src/js/features/common-page.ts | 65 +-
.../js/features/comp/ComboMarkdownEditor.ts | 116 +-
web_src/js/features/comp/ConfirmModal.ts | 4 +
web_src/js/features/comp/Cropper.ts | 13 +-
.../js/features/comp/EditorMarkdown.test.ts | 12 +-
web_src/js/features/comp/EditorMarkdown.ts | 58 +-
web_src/js/features/comp/EditorUpload.ts | 15 +-
web_src/js/features/comp/LabelEdit.ts | 28 +-
web_src/js/features/comp/ReactionSelector.ts | 9 +-
web_src/js/features/comp/SearchRepoBox.ts | 7 +-
web_src/js/features/comp/SearchUserBox.ts | 5 +-
web_src/js/features/comp/TextExpander.ts | 67 +-
web_src/js/features/comp/WebHookEditor.ts | 9 +-
web_src/js/features/contributors.ts | 2 +-
web_src/js/features/copycontent.ts | 2 +-
web_src/js/features/dropzone.ts | 25 +-
web_src/js/features/file-view.ts | 39 +-
web_src/js/features/heatmap.ts | 24 +-
web_src/js/features/install.ts | 57 +-
web_src/js/features/issue.ts | 16 +-
web_src/js/features/notification.ts | 63 +-
web_src/js/features/oauth2-settings.ts | 8 +-
web_src/js/features/pull-view-file.ts | 35 +-
web_src/js/features/recent-commits.ts | 2 +-
web_src/js/features/repo-actions.ts | 18 +-
web_src/js/features/repo-branch.ts | 18 +-
web_src/js/features/repo-code.ts | 22 +-
web_src/js/features/repo-commit.ts | 4 +-
web_src/js/features/repo-common.ts | 29 +-
web_src/js/features/repo-diff-commit.ts | 14 +-
web_src/js/features/repo-diff.ts | 89 +-
web_src/js/features/repo-findfile.ts | 65 +-
web_src/js/features/repo-graph.ts | 6 +-
web_src/js/features/repo-home.ts | 20 +-
web_src/js/features/repo-issue-content.ts | 10 +-
web_src/js/features/repo-issue-list.ts | 41 +-
web_src/js/features/repo-issue-pull.ts | 22 +-
.../repo-issue-sidebar-combolist.test.ts | 61 +
.../features/repo-issue-sidebar-combolist.ts | 116 +-
web_src/js/features/repo-issue-sidebar.md | 13 +
web_src/js/features/repo-issue-sidebar.ts | 103 +-
web_src/js/features/repo-issue.ts | 205 +-
web_src/js/features/repo-legacy.ts | 4 +-
web_src/js/features/repo-migrate.ts | 10 +-
web_src/js/features/repo-migration.ts | 6 +-
web_src/js/features/repo-milestone.ts | 4 +-
web_src/js/features/repo-new.ts | 28 +-
web_src/js/features/repo-projects.ts | 77 +-
web_src/js/features/repo-release.test.ts | 9 +
web_src/js/features/repo-release.ts | 159 +-
web_src/js/features/repo-search.ts | 8 +-
.../features/repo-settings-branches.test.ts | 76 +-
web_src/js/features/repo-settings-branches.ts | 6 +-
web_src/js/features/repo-settings.ts | 38 +-
web_src/js/features/repo-unicode-escape.ts | 4 +-
web_src/js/features/repo-view-file-tree.ts | 12 +-
web_src/js/features/repo-wiki.ts | 4 +-
web_src/js/features/sshkey-helper.ts | 2 +-
web_src/js/features/stopwatch.ts | 56 +-
web_src/js/features/tablesort.ts | 8 +-
web_src/js/features/tribute.ts | 89 +-
web_src/js/features/user-auth.ts | 26 +-
web_src/js/features/user-settings.ts | 6 +-
web_src/js/globals.d.ts | 89 +-
web_src/js/globals.ts | 18 +-
web_src/js/htmx.ts | 26 -
web_src/js/iife.ts | 11 +
web_src/js/index.ts | 215 +-
web_src/js/markup/anchors.ts | 19 +-
web_src/js/markup/asciicast.ts | 7 +-
web_src/js/markup/codecopy.ts | 21 +-
web_src/js/markup/math.ts | 4 +-
web_src/js/markup/mermaid.test.ts | 59 +
web_src/js/markup/mermaid.ts | 287 +-
web_src/js/markup/render-iframe.test.ts | 48 +
web_src/js/markup/tasklist.test.ts | 9 +
web_src/js/markup/tasklist.ts | 44 +-
.../js/modules/codeeditor/command-palette.ts | 216 +
web_src/js/modules/codeeditor/context-menu.ts | 249 +
web_src/js/modules/codeeditor/linter.ts | 39 +
web_src/js/modules/codeeditor/main.ts | 330 +
web_src/js/modules/codeeditor/utils.test.ts | 47 +
web_src/js/modules/codeeditor/utils.ts | 131 +
web_src/js/modules/devtest.ts | 20 +
web_src/js/modules/diff-file.ts | 8 +-
web_src/js/modules/errors.test.ts | 27 +
web_src/js/modules/errors.ts | 57 +
web_src/js/modules/fetch.ts | 12 +-
web_src/js/modules/fomantic.ts | 1 -
web_src/js/modules/fomantic/base.ts | 6 +-
web_src/js/modules/fomantic/dimmer.ts | 1 -
web_src/js/modules/fomantic/dropdown.ts | 4 +-
web_src/js/modules/fomantic/form.ts | 2 +-
web_src/js/modules/fomantic/modal.ts | 1 -
web_src/js/modules/fomantic/tab.ts | 3 +-
web_src/js/modules/fomantic/transition.ts | 2 -
web_src/js/modules/gitea-actions.ts | 53 +
web_src/js/modules/init.ts | 2 +-
web_src/js/modules/observer.ts | 5 +-
web_src/js/modules/shortcut.ts | 76 +
web_src/js/modules/sortable.ts | 10 +-
web_src/js/modules/tippy.ts | 38 +-
web_src/js/modules/toast.ts | 19 +-
web_src/js/modules/user-settings.ts | 73 +
web_src/js/modules/worker.ts | 68 +-
web_src/js/render/ansi.test.ts | 5 +
web_src/js/render/ansi.ts | 29 +-
web_src/js/render/plugin.ts | 23 +-
web_src/js/render/plugins/3d-viewer.ts | 59 -
.../plugins/frontend-openapi-swagger.ts | 19 +
.../js/render/plugins/frontend-viewer-3d.ts | 36 +
.../{pdf-viewer.ts => inplace-pdf-viewer.ts} | 7 +-
web_src/js/render/swagger.ts | 54 +
web_src/js/standalone/devtest.ts | 15 -
web_src/js/standalone/swagger.ts | 30 -
web_src/js/svg.ts | 8 +-
web_src/js/swagger.ts | 14 +
web_src/js/types.ts | 44 +-
web_src/js/utils.test.ts | 2 +-
web_src/js/utils.ts | 66 +-
web_src/js/utils/color.ts | 15 +-
web_src/js/utils/dom.test.ts | 16 +-
web_src/js/utils/dom.ts | 29 +-
web_src/js/utils/glob.test.ts | 1 -
web_src/js/utils/image.test.ts | 2 +-
web_src/js/utils/match.test.ts | 116 +-
web_src/js/utils/match.ts | 35 +-
web_src/js/utils/testhelper.ts | 18 +-
web_src/js/utils/time.ts | 1 -
web_src/js/utils/url.test.ts | 61 +-
web_src/js/utils/url.ts | 68 +-
web_src/js/vendor/jquery.are-you-sure.ts | 21 +-
web_src/js/vitest.setup.ts | 32 +-
web_src/js/webcomponents/README.md | 2 +-
.../js/webcomponents/absolute-date.test.ts | 26 -
web_src/js/webcomponents/absolute-date.ts | 39 -
web_src/js/webcomponents/index.ts | 15 +-
web_src/js/webcomponents/origin-url.ts | 7 -
web_src/js/webcomponents/overflow-menu.ts | 130 +-
web_src/js/webcomponents/polyfills.ts | 19 -
.../js/webcomponents/relative-time.test.ts | 139 +
web_src/js/webcomponents/relative-time.ts | 506 +
web_src/svg/gitea-colorblind-blueyellow.svg | 13 +
web_src/svg/gitea-colorblind-redgreen.svg | 13 +
web_src/svg/gitea-eclipse.svg | 1 +
web_src/svg/gitea-terraform.svg | 2 +
web_src/svg/gitea-vscode.svg | 1 -
2106 files changed, 155593 insertions(+), 116225 deletions(-)
create mode 100644 .github/dependabot.yml
create mode 100644 .github/workflows/cron-flake-updater.yml
delete mode 100644 .gitpod.yml
create mode 100644 AGENTS.md
create mode 100644 CLAUDE.md
rename {tools => assets}/misspellings.csv (100%)
delete mode 100644 build.go
delete mode 100644 build/backport-locales.go
create mode 100644 cmd/config.go
create mode 100644 cmd/config_test.go
delete mode 100644 contrib/environment-to-ini/README
delete mode 100644 contrib/environment-to-ini/environment-to-ini.go
create mode 100644 docker/root/usr/local/bin/environment-to-ini
create mode 100644 docker/rootless/usr/local/bin/environment-to-ini
create mode 100644 eslint.json.config.ts
create mode 100644 models/actions/config.go
create mode 100644 models/actions/task_test.go
create mode 100644 models/actions/token_permissions.go
create mode 100644 models/asymkey/ssh_key_authorized_keys_test.go
create mode 100644 models/fixtures/badge.yml
create mode 100644 models/git/lfs_lock_test.go
create mode 100644 models/git/lfs_test.go
delete mode 100644 models/migrations/base/main_test.go
create mode 100644 models/migrations/fixtures/Test_FixCommitStatusTargetURLToUseRunAndJobID/action_run.yml
create mode 100644 models/migrations/fixtures/Test_FixCommitStatusTargetURLToUseRunAndJobID/action_run_job.yml
create mode 100644 models/migrations/fixtures/Test_FixCommitStatusTargetURLToUseRunAndJobID/commit_status.yml
create mode 100644 models/migrations/fixtures/Test_FixCommitStatusTargetURLToUseRunAndJobID/commit_status_summary.yml
create mode 100644 models/migrations/fixtures/Test_FixCommitStatusTargetURLToUseRunAndJobID/repository.yml
create mode 100644 models/migrations/v1_25/v322_test.go
create mode 100644 models/migrations/v1_26/main_test.go
create mode 100644 models/migrations/v1_26/v323.go
create mode 100644 models/migrations/v1_26/v324.go
create mode 100644 models/migrations/v1_26/v325.go
create mode 100644 models/migrations/v1_26/v325_test.go
create mode 100644 models/migrations/v1_26/v326.go
create mode 100644 models/migrations/v1_26/v326_test.go
create mode 100644 models/migrations/v1_26/v327.go
create mode 100644 models/migrations/v1_26/v327_test.go
create mode 100644 models/migrations/v1_26/v328.go
create mode 100644 models/migrations/v1_26/v329.go
create mode 100644 models/migrations/v1_26/v329_test.go
create mode 100644 models/migrations/v1_26/v330.go
create mode 100644 models/packages/package_blob_test.go
create mode 100644 models/perm/access/actions_repo_permission_test.go
rename modules/git/repo_archive_test.go => models/repo/archive_test.go (98%)
create mode 100644 models/repo/pull_request_default.go
create mode 100644 models/repo/pull_request_default_test.go
create mode 100644 models/repo/repo_unit_actions.go
create mode 100644 models/user/badge_test.go
create mode 100644 modules/actions/artifacts_test.go
create mode 100644 modules/actions/jobparser/evaluator.go
create mode 100644 modules/actions/jobparser/interpeter.go
create mode 100644 modules/actions/jobparser/jobparser.go
create mode 100644 modules/actions/jobparser/jobparser_test.go
create mode 100644 modules/actions/jobparser/model.go
create mode 100644 modules/actions/jobparser/model_test.go
create mode 100644 modules/actions/jobparser/testdata/empty_step.in.yaml
create mode 100644 modules/actions/jobparser/testdata/empty_step.out.yaml
create mode 100644 modules/actions/jobparser/testdata/erase_needs.in.yaml
create mode 100644 modules/actions/jobparser/testdata/erase_needs.out.yaml
create mode 100644 modules/actions/jobparser/testdata/has_needs.in.yaml
create mode 100644 modules/actions/jobparser/testdata/has_needs.out.yaml
create mode 100644 modules/actions/jobparser/testdata/has_secrets.in.yaml
create mode 100644 modules/actions/jobparser/testdata/has_secrets.out.yaml
create mode 100644 modules/actions/jobparser/testdata/has_with.in.yaml
create mode 100644 modules/actions/jobparser/testdata/has_with.out.yaml
create mode 100644 modules/actions/jobparser/testdata/job_name_with_matrix.in.yaml
create mode 100644 modules/actions/jobparser/testdata/job_name_with_matrix.out.yaml
create mode 100644 modules/actions/jobparser/testdata/multiple_jobs.in.yaml
create mode 100644 modules/actions/jobparser/testdata/multiple_jobs.out.yaml
create mode 100644 modules/actions/jobparser/testdata/multiple_matrix.in.yaml
create mode 100644 modules/actions/jobparser/testdata/multiple_matrix.out.yaml
create mode 100644 modules/actions/jobparser/testdata/null_job_explicit.in.yaml
create mode 100644 modules/actions/jobparser/testdata/null_job_implicit.in.yaml
create mode 100644 modules/actions/jobparser/testdata/prefixed_newline.in.yaml
create mode 100644 modules/actions/jobparser/testdata/prefixed_newline.out.yaml
create mode 100644 modules/actions/jobparser/testdata_test.go
delete mode 100644 modules/activitypub/client.go
delete mode 100644 modules/activitypub/client_test.go
delete mode 100644 modules/activitypub/main_test.go
delete mode 100644 modules/activitypub/user_settings.go
delete mode 100644 modules/activitypub/user_settings_test.go
delete mode 100644 modules/charset/ambiguous/generate.go
delete mode 100644 modules/charset/breakwriter.go
delete mode 100644 modules/charset/breakwriter_test.go
rename modules/charset/{ambiguous => generate}/ambiguous.json (100%)
rename modules/charset/{invisible => generate}/generate.go (57%)
delete mode 100644 modules/charset/htmlstream.go
create mode 100644 modules/fileicon/render_test.go
delete mode 100644 modules/git/batch.go
delete mode 100644 modules/git/batch_reader.go
create mode 100644 modules/git/catfile_batch.go
create mode 100644 modules/git/catfile_batch_command.go
create mode 100644 modules/git/catfile_batch_legacy.go
create mode 100644 modules/git/catfile_batch_reader.go
create mode 100644 modules/git/catfile_batch_test.go
delete mode 100644 modules/git/gitcmd/command_race_test.go
create mode 100644 modules/git/gitcmd/context.go
create mode 100644 modules/git/gitcmd/error.go
create mode 100644 modules/git/gitcmd/pipe.go
delete mode 100644 modules/git/gitcmd/utils.go
create mode 100644 modules/git/gpg.go
delete mode 100644 modules/git/parse_gogit.go
delete mode 100644 modules/git/parse_gogit_test.go
rename modules/git/{parse_nogogit.go => parse_treeentry.go} (96%)
rename modules/git/{parse_nogogit_test.go => parse_treeentry_test.go} (99%)
create mode 100644 modules/git/pipeline/lfs_test.go
create mode 100644 modules/git/pipeline/main_test.go
delete mode 100644 modules/git/repo_archive.go
create mode 100644 modules/git/repo_base_nogogit_test.go
delete mode 100644 modules/git/repo_blame.go
delete mode 100644 modules/git/repo_blob_gogit.go
delete mode 100644 modules/git/repo_blob_nogogit.go
delete mode 100644 modules/git/repo_gpg.go
create mode 100644 modules/git/tree_entry_gogit_test.go
create mode 100644 modules/gitrepo/archive.go
rename modules/{git => gitrepo}/blame.go (70%)
rename modules/{git => gitrepo}/blame_sha256_test.go (88%)
rename modules/{git => gitrepo}/blame_test.go (89%)
create mode 100644 modules/gitrepo/cat_file.go
create mode 100644 modules/gitrepo/clone.go
create mode 100644 modules/gitrepo/command.go
create mode 100644 modules/gitrepo/commit.go
create mode 100644 modules/gitrepo/commit_file.go
create mode 100644 modules/gitrepo/commit_file_test.go
create mode 100644 modules/gitrepo/commit_test.go
create mode 100644 modules/gitrepo/commitgraph.go
create mode 100644 modules/gitrepo/compare.go
create mode 100644 modules/gitrepo/compare_test.go
create mode 100644 modules/gitrepo/diff.go
create mode 100644 modules/gitrepo/fetch.go
create mode 100644 modules/gitrepo/main_test.go
create mode 100644 modules/gitrepo/merge.go
create mode 100644 modules/gitrepo/merge_tree.go
create mode 100644 modules/gitrepo/merge_tree_test.go
create mode 100644 modules/gitrepo/push.go
create mode 100644 modules/gitrepo/repo_lock.go
create mode 100644 modules/gitrepo/signing.go
create mode 100644 modules/gitrepo/size.go
create mode 100644 modules/highlight/lexerdetect.go
create mode 100644 modules/highlight/lexerdetect_test.go
create mode 100644 modules/httplib/content_disposition.go
create mode 100644 modules/httplib/content_disposition_test.go
create mode 100644 modules/json/jsonlegacy.go
create mode 100644 modules/json/jsonv1.go
create mode 100644 modules/json/jsonv2.go
create mode 100644 modules/markup/external/frontend.go
create mode 100644 modules/markup/html_node_test.go
create mode 100644 modules/markup/html_toc_test.go
delete mode 100644 modules/markup/markdown/prefixed_id.go
delete mode 100644 modules/markup/markdown/toc.go
delete mode 100644 modules/markup/markdown/transform_heading.go
create mode 100644 modules/markup/render_test.go
create mode 100644 modules/packages/terraform/lock.go
create mode 100644 modules/packages/terraform/state.go
create mode 100644 modules/public/manifest.go
create mode 100644 modules/public/manifest_test.go
create mode 100644 modules/public/vitedev.go
create mode 100644 modules/setting/config_option_instance.go
create mode 100644 modules/setting/testenv.go
delete mode 100644 modules/structs/activitypub.go
create mode 100644 modules/svg/svg_test.go
delete mode 100644 modules/sync/status_pool.go
delete mode 100644 modules/sync/status_pool_test.go
create mode 100644 modules/templates/mail.go
delete mode 100644 modules/templates/mailer.go
create mode 100644 modules/templates/page.go
create mode 100644 modules/templates/util_render_comment.go
create mode 100644 modules/templates/util_render_comment_test.go
delete mode 100644 modules/test/utils_test.go
create mode 100644 modules/util/buffer.go
delete mode 100644 options/locale/locale_cs-CZ.ini
create mode 100644 options/locale/locale_cs-CZ.json
delete mode 100644 options/locale/locale_de-DE.ini
create mode 100644 options/locale/locale_de-DE.json
delete mode 100644 options/locale/locale_el-GR.ini
create mode 100644 options/locale/locale_el-GR.json
create mode 100644 options/locale/locale_en-US.json
delete mode 100644 options/locale/locale_es-ES.ini
create mode 100644 options/locale/locale_es-ES.json
delete mode 100644 options/locale/locale_fa-IR.ini
create mode 100644 options/locale/locale_fa-IR.json
delete mode 100644 options/locale/locale_fi-FI.ini
create mode 100644 options/locale/locale_fi-FI.json
delete mode 100644 options/locale/locale_fr-FR.ini
create mode 100644 options/locale/locale_fr-FR.json
delete mode 100644 options/locale/locale_ga-IE.ini
create mode 100644 options/locale/locale_ga-IE.json
delete mode 100644 options/locale/locale_hu-HU.ini
create mode 100644 options/locale/locale_hu-HU.json
delete mode 100644 options/locale/locale_id-ID.ini
create mode 100644 options/locale/locale_id-ID.json
delete mode 100644 options/locale/locale_is-IS.ini
create mode 100644 options/locale/locale_is-IS.json
delete mode 100644 options/locale/locale_it-IT.ini
create mode 100644 options/locale/locale_it-IT.json
delete mode 100644 options/locale/locale_ja-JP.ini
create mode 100644 options/locale/locale_ja-JP.json
delete mode 100644 options/locale/locale_ko-KR.ini
create mode 100644 options/locale/locale_ko-KR.json
delete mode 100644 options/locale/locale_lv-LV.ini
create mode 100644 options/locale/locale_lv-LV.json
delete mode 100644 options/locale/locale_nl-NL.ini
create mode 100644 options/locale/locale_nl-NL.json
delete mode 100644 options/locale/locale_pl-PL.ini
create mode 100644 options/locale/locale_pl-PL.json
delete mode 100644 options/locale/locale_pt-BR.ini
create mode 100644 options/locale/locale_pt-BR.json
delete mode 100644 options/locale/locale_pt-PT.ini
create mode 100644 options/locale/locale_pt-PT.json
delete mode 100644 options/locale/locale_ru-RU.ini
create mode 100644 options/locale/locale_ru-RU.json
delete mode 100644 options/locale/locale_si-LK.ini
create mode 100644 options/locale/locale_si-LK.json
delete mode 100644 options/locale/locale_sk-SK.ini
create mode 100644 options/locale/locale_sk-SK.json
delete mode 100644 options/locale/locale_sv-SE.ini
create mode 100644 options/locale/locale_sv-SE.json
delete mode 100644 options/locale/locale_tr-TR.ini
create mode 100644 options/locale/locale_tr-TR.json
delete mode 100644 options/locale/locale_uk-UA.ini
create mode 100644 options/locale/locale_uk-UA.json
delete mode 100644 options/locale/locale_zh-CN.ini
create mode 100644 options/locale/locale_zh-CN.json
delete mode 100644 options/locale/locale_zh-HK.ini
delete mode 100644 options/locale/locale_zh-TW.ini
create mode 100644 options/locale/locale_zh-TW.json
create mode 100644 public/assets/img/svg/gitea-colorblind-blueyellow.svg
create mode 100644 public/assets/img/svg/gitea-colorblind-redgreen.svg
create mode 100644 public/assets/img/svg/gitea-eclipse.svg
create mode 100644 public/assets/img/svg/gitea-terraform.svg
delete mode 100644 public/assets/img/svg/gitea-vscode.svg
create mode 100644 public/assets/img/svg/octicon-book-locked.svg
create mode 100644 public/assets/img/svg/octicon-boolean-off.svg
create mode 100644 public/assets/img/svg/octicon-boolean-on.svg
create mode 100644 public/assets/img/svg/octicon-comment-ai.svg
create mode 100644 public/assets/img/svg/octicon-comment-locked.svg
create mode 100644 public/assets/img/svg/octicon-compose.svg
create mode 100644 public/assets/img/svg/octicon-crosshairs.svg
create mode 100644 public/assets/img/svg/octicon-dice.svg
create mode 100644 public/assets/img/svg/octicon-exclamation.svg
create mode 100644 public/assets/img/svg/octicon-file-check.svg
create mode 100644 public/assets/img/svg/octicon-flowchart.svg
create mode 100644 public/assets/img/svg/octicon-focus-center.svg
create mode 100644 public/assets/img/svg/octicon-git-branch-check.svg
create mode 100644 public/assets/img/svg/octicon-git-pull-request-locked.svg
create mode 100644 public/assets/img/svg/octicon-graph-bar-horizontal.svg
create mode 100644 public/assets/img/svg/octicon-graph-bar-vertical.svg
create mode 100644 public/assets/img/svg/octicon-inbox-fill.svg
create mode 100644 public/assets/img/svg/octicon-issue-locked.svg
create mode 100644 public/assets/img/svg/octicon-lockup-github.svg
create mode 100644 public/assets/img/svg/octicon-node.svg
create mode 100644 public/assets/img/svg/octicon-pencil-ai.svg
create mode 100644 public/assets/img/svg/octicon-smiley-frown.svg
create mode 100644 public/assets/img/svg/octicon-smiley-frustrated.svg
create mode 100644 public/assets/img/svg/octicon-smiley-grin.svg
create mode 100644 public/assets/img/svg/octicon-smiley-neutral.svg
create mode 100644 public/assets/img/svg/octicon-spacing-large.svg
create mode 100644 public/assets/img/svg/octicon-spacing-medium.svg
create mode 100644 public/assets/img/svg/octicon-spacing-small.svg
create mode 100644 public/assets/img/svg/octicon-split-view.svg
create mode 100644 public/assets/img/svg/octicon-unwrap.svg
create mode 100644 public/assets/img/svg/octicon-vscode.svg
create mode 100644 public/assets/img/svg/octicon-wrap.svg
rename routers/api/packages/{conan => }/auth.go (54%)
delete mode 100644 routers/api/packages/container/auth.go
create mode 100644 routers/api/packages/terraform/terraform.go
create mode 100644 routers/api/packages/terraform/terraform_test.go
delete mode 100644 routers/api/v1/activitypub/reqsignature.go
delete mode 100644 routers/api/v1/misc/nodeinfo.go
delete mode 100644 routers/api/v1/swagger/activitypub.go
create mode 100644 routers/common/compare_test.go
create mode 100644 routers/common/issue_filter.go
create mode 100644 routers/common/maintenancemode.go
create mode 100644 routers/common/redirect_test.go
create mode 100644 routers/web/admin/badges.go
delete mode 100644 routers/web/admin/runners.go
create mode 100644 routers/web/misc/webtheme.go
create mode 100644 routers/web/org/mention.go
delete mode 100644 routers/web/org/setting/runners.go
create mode 100644 routers/web/repo/actions/view_test.go
create mode 100644 routers/web/repo/compare_test.go
delete mode 100644 routers/web/repo/find.go
create mode 100644 routers/web/repo/mention.go
create mode 100644 routers/web/repo/middlewares_test.go
create mode 100644 routers/web/repo/setting/actions.go
create mode 100644 routers/web/repo/setting/webhook_test.go
create mode 100644 routers/web/repo/view_readme_test.go
create mode 100644 routers/web/shared/actions/general.go
create mode 100644 routers/web/shared/mention/mention.go
create mode 100644 routers/web/user/heatmap.go
delete mode 100644 routers/web/user/setting/runner.go
create mode 100644 routers/web/user/setting/security/main_test.go
create mode 100644 routers/web/user/setting/security/openid_test.go
create mode 100644 services/actions/commit_status_test.go
create mode 100644 services/actions/concurrency.go
create mode 100644 services/actions/permission_parser.go
create mode 100644 services/actions/permission_parser_test.go
create mode 100644 services/actions/run.go
create mode 100644 services/actions/schedule_tasks_test.go
create mode 100644 services/actions/token_permission_design.md
delete mode 100644 services/auth/auth_test.go
delete mode 100644 services/context/csrf.go
create mode 100644 services/context/pagination_test.go
delete mode 100644 services/context/xsrf.go
delete mode 100644 services/context/xsrf_test.go
create mode 100644 services/convert/action_test.go
create mode 100644 services/convert/notification_test.go
create mode 100644 services/git/compare.go
create mode 100644 services/gitdiff/gitdiff_excerpt.go
create mode 100644 services/gitdiff/gitdiff_excerpt_test.go
create mode 100644 services/mailer/mail_release_test.go
create mode 100644 services/oauth2_provider/jwtsigningkey_test.go
create mode 100644 services/packages/pkgspec/manager.go
create mode 100644 services/packages/spec.go
create mode 100644 services/packages/terraform/spec.go
create mode 100644 services/packages/terraform/state.go
create mode 100644 services/pull/comment_test.go
delete mode 100644 services/pull/compare.go
create mode 100644 services/pull/merge_tree.go
create mode 100644 services/pull/merge_tree_test.go
create mode 100644 services/pull/update_test.go
create mode 100644 services/release/notes.go
create mode 100644 services/release/notes_test.go
create mode 100644 services/repository/files/temp_repo_test.go
create mode 100755 snap/part-gitea-build.sh
create mode 100755 snap/part-gitea-pull.sh
rename stylelint.config.ts => stylelint.config.js (93%)
create mode 100644 templates/admin/badge/edit.tmpl
create mode 100644 templates/admin/badge/list.tmpl
create mode 100644 templates/admin/badge/new.tmpl
create mode 100644 templates/admin/badge/users.tmpl
create mode 100644 templates/admin/badge/view.tmpl
create mode 100644 templates/admin/config_settings/instance.tmpl
create mode 100644 templates/base/head_banner.tmpl
create mode 100644 templates/devtest/form-fields.tmpl
create mode 100644 templates/devtest/keyboard-shortcut.tmpl
create mode 100644 templates/devtest/relative-time.tmpl
create mode 100644 templates/devtest/severity-colors.tmpl
create mode 100644 templates/devtest/unicode-escape.tmpl
create mode 100644 templates/org/settings/actions_general.tmpl
create mode 100644 templates/org/worktime/empty_placeholder.tmpl
create mode 100644 templates/package/content/terraform.tmpl
create mode 100644 templates/package/metadata/terraform.tmpl
create mode 100644 templates/package/shared/visibility_badge.tmpl
create mode 100644 templates/repo/commits_ref_name.tmpl
delete mode 100644 templates/repo/diff/escape_title.tmpl
create mode 100644 templates/repo/editor/options.tmpl
delete mode 100644 templates/repo/find/files.tmpl
create mode 100644 templates/repo/issue/filter_item_milestone.tmpl
create mode 100644 templates/repo/settings/actions_general.tmpl
create mode 100644 templates/repo/settings/repo_name_confirm_fields.tmpl
create mode 100644 templates/repo/view_file_tree_toggle_button.tmpl
create mode 100644 templates/shared/actions/owner_general_settings.tmpl
create mode 100644 templates/shared/actions/permission_mode_select.tmpl
create mode 100644 templates/shared/actions/permissions_table.tmpl
create mode 100644 templates/shared/actions/permissions_table_unit.tmpl
create mode 100644 templates/swagger/openapi-viewer.tmpl
delete mode 100644 templates/swagger/ui.tmpl
create mode 100644 templates/user/auth/external_auth_methods.tmpl
delete mode 100644 templates/user/auth/oauth_container.tmpl
create mode 100644 templates/user/settings/actions_general.tmpl
delete mode 100644 tests/e2e/README.md
create mode 100644 tests/e2e/codeeditor.test.ts
delete mode 100644 tests/e2e/e2e_test.go
create mode 100644 tests/e2e/env.d.ts
create mode 100644 tests/e2e/events.test.ts
delete mode 100644 tests/e2e/example.test.e2e.ts
create mode 100644 tests/e2e/explore.test.ts
create mode 100644 tests/e2e/external-render.test.ts
create mode 100644 tests/e2e/file-view-render.test.ts
create mode 100644 tests/e2e/licenses.test.ts
create mode 100644 tests/e2e/login.test.ts
create mode 100644 tests/e2e/mermaid.test.ts
create mode 100644 tests/e2e/milestone.test.ts
create mode 100644 tests/e2e/org.test.ts
create mode 100644 tests/e2e/reactions.test.ts
create mode 100644 tests/e2e/readme.test.ts
create mode 100644 tests/e2e/register.test.ts
create mode 100644 tests/e2e/relative-time.test.ts
create mode 100644 tests/e2e/repo.test.ts
create mode 100644 tests/e2e/user-settings.test.ts
create mode 100644 tests/e2e/utils.ts
delete mode 100644 tests/e2e/utils_e2e.ts
delete mode 100644 tests/e2e/utils_e2e_test.go
create mode 100644 tests/integration/actions_approve_test.go
create mode 100644 tests/integration/actions_concurrency_test.go
create mode 100644 tests/integration/actions_job_token_test.go
create mode 100644 tests/integration/actions_log_finalize_test.go
create mode 100644 tests/integration/actions_route_test.go
create mode 100644 tests/integration/actions_settings_test.go
create mode 100644 tests/integration/api_actions_permission_test.go
delete mode 100644 tests/integration/api_activitypub_person_test.go
delete mode 100644 tests/integration/api_nodeinfo_test.go
create mode 100644 tests/integration/api_packages_terraform_test.go
create mode 100644 tests/integration/api_public_only_test.go
create mode 100644 tests/integration/api_user_public_only_test.go
create mode 100644 tests/integration/config_instance_test.go
delete mode 100644 tests/integration/csrf_test.go
create mode 100644 tests/integration/heatmap_test.go
create mode 100644 tests/integration/issue_timetrack_test.go
create mode 100644 tests/integration/manual_merge_test.go
create mode 100644 tests/integration/oauth_avatar_test.go
create mode 100644 tests/integration/packages_service_test.go
create mode 100644 tests/integration/repo_visibility_test.go
delete mode 100644 tests/integration/schemas/nodeinfo_2.1.json
delete mode 100644 tests/integration/webfinger_test.go
delete mode 100644 tests/integration/xss_test.go
rename {build => tools}/code-batch-process.go (95%)
rename {build => tools}/codeformat/formatimports.go (100%)
rename {build => tools}/codeformat/formatimports_test.go (100%)
rename {build => tools}/gocovmerge.go (100%)
delete mode 100755 tools/lint-go-gopls.sh
create mode 100755 tools/test-e2e.sh
rename {build => tools}/test-echo.go (100%)
create mode 100644 vite.config.ts
delete mode 100644 web_src/css/chroma/base.css
delete mode 100644 web_src/css/chroma/dark.css
delete mode 100644 web_src/css/chroma/light.css
delete mode 100644 web_src/css/codemirror/base.css
delete mode 100644 web_src/css/codemirror/dark.css
delete mode 100644 web_src/css/codemirror/light.css
rename web_src/css/{standalone => }/devtest.css (100%)
create mode 100644 web_src/css/easymde.css
delete mode 100644 web_src/css/editor/fileeditor.css
rename web_src/css/{standalone => }/external-render-iframe.css (100%)
create mode 100644 web_src/css/features/captcha.css
delete mode 100644 web_src/css/features/codeeditor.css
delete mode 100644 web_src/css/form.css
create mode 100644 web_src/css/markup/codeblock.css
delete mode 100644 web_src/css/markup/codecopy.css
create mode 100644 web_src/css/modules/charescape.css
create mode 100644 web_src/css/modules/chroma.css
create mode 100644 web_src/css/modules/codeeditor.css
create mode 100644 web_src/css/modules/dropdown.css
create mode 100644 web_src/css/modules/form.css
create mode 100644 web_src/css/modules/search.css
create mode 100644 web_src/css/modules/shortcut.css
delete mode 100644 web_src/css/standalone/swagger.css
create mode 100644 web_src/css/swagger-render.css
create mode 100644 web_src/css/swagger-standalone.css
create mode 100644 web_src/css/themes/theme-gitea-auto-tritanopia.css
create mode 100644 web_src/css/themes/theme-gitea-dark-tritanopia.css
create mode 100644 web_src/css/themes/theme-gitea-light-tritanopia.css
delete mode 100644 web_src/fomantic/build/components/dropdown.css
delete mode 100644 web_src/fomantic/build/components/form.css
delete mode 100644 web_src/fomantic/build/components/modal.css
delete mode 100644 web_src/fomantic/build/components/search.css
delete mode 100644 web_src/fomantic/build/fomantic.css
delete mode 100644 web_src/js/bootstrap.test.ts
create mode 100644 web_src/js/components/ActionRunJobView.vue
create mode 100644 web_src/js/components/ActionRunSummaryView.vue
create mode 100644 web_src/js/components/ActionRunView.test.ts
create mode 100644 web_src/js/components/ActionRunView.ts
create mode 100644 web_src/js/components/RepoFileSearch.vue
create mode 100644 web_src/js/components/WorkflowGraph.vue
rename web_src/js/{features => }/eventsource.sharedworker.ts (85%)
create mode 100644 web_src/js/external-render-frontend.ts
create mode 100644 web_src/js/external-render-helper.test.ts
create mode 100644 web_src/js/external-render-helper.ts
create mode 100644 web_src/js/features/admin/config.test.ts
delete mode 100644 web_src/js/features/codeeditor.ts
create mode 100644 web_src/js/features/common-actions-permissions.ts
create mode 100644 web_src/js/features/repo-issue-sidebar-combolist.test.ts
create mode 100644 web_src/js/features/repo-release.test.ts
delete mode 100644 web_src/js/htmx.ts
create mode 100644 web_src/js/iife.ts
create mode 100644 web_src/js/markup/mermaid.test.ts
create mode 100644 web_src/js/markup/render-iframe.test.ts
create mode 100644 web_src/js/markup/tasklist.test.ts
create mode 100644 web_src/js/modules/codeeditor/command-palette.ts
create mode 100644 web_src/js/modules/codeeditor/context-menu.ts
create mode 100644 web_src/js/modules/codeeditor/linter.ts
create mode 100644 web_src/js/modules/codeeditor/main.ts
create mode 100644 web_src/js/modules/codeeditor/utils.test.ts
create mode 100644 web_src/js/modules/codeeditor/utils.ts
create mode 100644 web_src/js/modules/devtest.ts
create mode 100644 web_src/js/modules/errors.test.ts
create mode 100644 web_src/js/modules/errors.ts
create mode 100644 web_src/js/modules/gitea-actions.ts
create mode 100644 web_src/js/modules/shortcut.ts
create mode 100644 web_src/js/modules/user-settings.ts
delete mode 100644 web_src/js/render/plugins/3d-viewer.ts
create mode 100644 web_src/js/render/plugins/frontend-openapi-swagger.ts
create mode 100644 web_src/js/render/plugins/frontend-viewer-3d.ts
rename web_src/js/render/plugins/{pdf-viewer.ts => inplace-pdf-viewer.ts} (63%)
create mode 100644 web_src/js/render/swagger.ts
delete mode 100644 web_src/js/standalone/devtest.ts
delete mode 100644 web_src/js/standalone/swagger.ts
create mode 100644 web_src/js/swagger.ts
delete mode 100644 web_src/js/webcomponents/absolute-date.test.ts
delete mode 100644 web_src/js/webcomponents/absolute-date.ts
delete mode 100644 web_src/js/webcomponents/origin-url.ts
create mode 100644 web_src/js/webcomponents/relative-time.test.ts
create mode 100644 web_src/js/webcomponents/relative-time.ts
create mode 100644 web_src/svg/gitea-colorblind-blueyellow.svg
create mode 100644 web_src/svg/gitea-colorblind-redgreen.svg
create mode 100644 web_src/svg/gitea-eclipse.svg
create mode 100644 web_src/svg/gitea-terraform.svg
delete mode 100644 web_src/svg/gitea-vscode.svg
diff --git a/.air.toml b/.air.toml
index 8854041a25..6e3c5bdc83 100644
--- a/.air.toml
+++ b/.air.toml
@@ -4,7 +4,7 @@ tmp_dir = ".air"
[build]
pre_cmd = ["killall -9 gitea 2>/dev/null || true"] # kill off potential zombie processes from previous runs
cmd = "make --no-print-directory backend"
-bin = "gitea"
+entrypoint = ["./gitea"]
delay = 2000
include_ext = ["go", "tmpl"]
include_file = ["main.go"]
diff --git a/.devcontainer/devcontainer.json b/.devcontainer/devcontainer.json
index 0b20da7c16..f8e5972af1 100644
--- a/.devcontainer/devcontainer.json
+++ b/.devcontainer/devcontainer.json
@@ -13,14 +13,13 @@
"ghcr.io/devcontainers/features/git-lfs:1.2.5": {},
"ghcr.io/jsburckhardt/devcontainer-features/uv:1": {},
"ghcr.io/devcontainers/features/python:1": {
- "version": "3.13"
+ "version": "3.14"
},
"ghcr.io/warrenbuckley/codespace-features/sqlite:1": {}
},
"customizations": {
"vscode": {
"settings": {},
- // same extensions as Gitpod, should match /.gitpod.yml
"extensions": [
"editorconfig.editorconfig",
"dbaeumer.vscode-eslint",
diff --git a/.dockerignore b/.dockerignore
index 8e0d6b3666..c88fb144fe 100644
--- a/.dockerignore
+++ b/.dockerignore
@@ -74,6 +74,9 @@ cpu.out
/VERSION
/.air
/.go-licenses
+/Dockerfile
+/Dockerfile.rootless
+/.venv
# Files and folders that were previously generated
/public/assets/img/webpack
diff --git a/.gitattributes b/.gitattributes
index e218bbe25d..afd02555f5 100644
--- a/.gitattributes
+++ b/.gitattributes
@@ -8,3 +8,4 @@
/vendor/** -text -eol linguist-vendored
/web_src/js/vendor/** -text -eol linguist-vendored
Dockerfile.* linguist-language=Dockerfile
+Makefile.* linguist-language=Makefile
diff --git a/.github/ISSUE_TEMPLATE/bug-report.yaml b/.github/ISSUE_TEMPLATE/bug-report.yaml
index 4dbe1a4c56..67845fe68b 100644
--- a/.github/ISSUE_TEMPLATE/bug-report.yaml
+++ b/.github/ISSUE_TEMPLATE/bug-report.yaml
@@ -5,55 +5,20 @@ body:
- type: markdown
attributes:
value: |
- NOTE: If your issue is a security concern, please send an email to security@gitea.io instead of opening a public issue.
- - type: markdown
- attributes:
- value: |
- 1. Please speak English, this is the language all maintainers can speak and write.
- 2. Please ask questions or configuration/deploy problems on our Discord
- server (https://discord.gg/gitea) or forum (https://forum.gitea.com).
- 3. Make sure you are using the latest release and
- take a moment to check that your issue hasn't been reported before.
- 4. Make sure it's not mentioned in the FAQ (https://docs.gitea.com/help/faq)
- 5. It's really important to provide pertinent details and logs (https://docs.gitea.com/help/support),
- incomplete details will be handled as an invalid report.
+ NOTE: If your issue is a security concern, please send an email to contact@mengning.com.cn instead of opening a public issue.
- type: textarea
id: description
attributes:
label: Description
description: |
- Please provide a description of your issue here, with a URL if you were able to reproduce the issue (see below)
- If you are using a proxy or a CDN (e.g. Cloudflare) in front of Gitea, please disable the proxy/CDN fully and access Gitea directly to confirm the issue still persists without those services.
+ Please provide a description of your issue here.
- type: input
- id: gitea-ver
- attributes:
- label: Gitea Version
- description: Gitea version (or commit reference) of your instance
- validations:
- required: true
- - type: dropdown
- id: can-reproduce
+ id: devstar-ver
attributes:
- label: Can you reproduce the bug on the Gitea demo site?
- description: |
- If so, please provide a URL in the Description field
- URL of Gitea demo: https://demo.gitea.com
- options:
- - "Yes"
- - "No"
+ label: DevStar Version
+ description: DevStar version (or commit reference) of your instance
validations:
required: true
- - type: markdown
- attributes:
- value: |
- It's really important to provide pertinent logs
- Please read https://docs.gitea.com/administration/logging-config#collecting-logs-for-help
- In addition, if your problem relates to git commands set `RUN_MODE=dev` at the top of app.ini
- - type: input
- id: logs
- attributes:
- label: Log Gist
- description: Please provide a gist URL of your logs, with any sensitive information (e.g. API keys) removed/hidden
- type: textarea
id: screenshots
attributes:
@@ -68,14 +33,14 @@ body:
id: os-ver
attributes:
label: Operating System
- description: The operating system you are using to run Gitea
+ description: The operating system you are using to run DevStar
- type: textarea
id: run-info
attributes:
- label: How are you running Gitea?
+ label: How are you running DevStar?
description: |
- Please include information on whether you built Gitea yourself, used one of our downloads, are using https://demo.gitea.com or are using some other package
- Please also tell us how you are running Gitea, e.g. if it is being run from docker, a command-line, systemd etc.
+ Please include information on whether you built DevStar yourself, used one of our downloads, are using https://devstar.cn or are using some other package
+ Please also tell us how you are running DevStar, e.g. if it is being run from docker, a command-line, systemd etc.
If you are using a package or systemd tell us what distribution you are using
validations:
required: true
diff --git a/.github/ISSUE_TEMPLATE/config.yml b/.github/ISSUE_TEMPLATE/config.yml
index d409f18cd9..5914bdebc7 100644
--- a/.github/ISSUE_TEMPLATE/config.yml
+++ b/.github/ISSUE_TEMPLATE/config.yml
@@ -1,17 +1,5 @@
blank_issues_enabled: false
contact_links:
- - name: Security Concern
- url: https://tinyurl.com/security-gitea
- about: For security concerns, please send a mail to security@gitea.io instead of opening a public issue.
- - name: Discord Server
- url: https://discord.gg/Gitea
- about: Please ask questions and discuss configuration or deployment problems here.
- - name: Discourse Forum
- url: https://forum.gitea.com
- about: Questions and configuration or deployment problems can also be discussed on our forum.
- name: Frequently Asked Questions
- url: https://docs.gitea.com/help/faq
+ url: https://github.com/mengning/DevStar/wiki/FAQ
about: Please check if your question isn't mentioned here.
- - name: Crowdin Translations
- url: https://translate.gitea.com
- about: Translations are managed here.
diff --git a/.github/ISSUE_TEMPLATE/feature-request.yaml b/.github/ISSUE_TEMPLATE/feature-request.yaml
index d5c480d202..1c8d6704fd 100644
--- a/.github/ISSUE_TEMPLATE/feature-request.yaml
+++ b/.github/ISSUE_TEMPLATE/feature-request.yaml
@@ -1,20 +1,13 @@
name: Feature Request
-description: Got an idea for a feature that Gitea doesn't have currently? Submit your idea here!
+description: Got an idea for a feature that DevStar doesn't have currently? Submit your idea here!
labels: ["type/proposal"]
body:
- - type: markdown
- attributes:
- value: |
- 1. Please speak English, this is the language all maintainers can speak and write.
- 2. Please ask questions or configuration/deploy problems on our Discord
- server (https://discord.gg/gitea) or forum (https://forum.gitea.com).
- 3. Please take a moment to check that your feature hasn't already been suggested.
- type: textarea
id: description
attributes:
label: Feature Description
placeholder: |
- I think it would be great if Gitea had...
+ I think it would be great if DevStar had...
validations:
required: true
- type: textarea
diff --git a/.github/ISSUE_TEMPLATE/ui.bug-report.yaml b/.github/ISSUE_TEMPLATE/ui.bug-report.yaml
index 3ad5dbaf54..90b70e2d8c 100644
--- a/.github/ISSUE_TEMPLATE/ui.bug-report.yaml
+++ b/.github/ISSUE_TEMPLATE/ui.bug-report.yaml
@@ -5,27 +5,13 @@ body:
- type: markdown
attributes:
value: |
- NOTE: If your issue is a security concern, please send an email to security@gitea.io instead of opening a public issue.
- - type: markdown
- attributes:
- value: |
- 1. Please speak English, this is the language all maintainers can speak and write.
- 2. Please ask questions or configuration/deploy problems on our Discord
- server (https://discord.gg/gitea) or forum (https://forum.gitea.com).
- 3. Please take a moment to check that your issue doesn't already exist.
- 4. Make sure it's not mentioned in the FAQ (https://docs.gitea.com/help/faq)
- 5. Please give all relevant information below for bug reports, because
- incomplete details will be handled as an invalid report.
- 6. In particular it's really important to provide pertinent logs. If you are certain that this is a javascript
- error, show us the javascript console. If the error appears to relate to Gitea the server you must also give us
- DEBUG level logs. (See https://docs.gitea.com/administration/logging-config#collecting-logs-for-help)
+ NOTE: If your issue is a security concern, please send an email to contact@mengning.com.cn instead of opening a public issue.
- type: textarea
id: description
attributes:
label: Description
description: |
- Please provide a description of your issue here, with a URL if you were able to reproduce the issue (see below)
- If using a proxy or a CDN (e.g. CloudFlare) in front of gitea, please disable the proxy/CDN fully and connect to gitea directly to confirm the issue still persists without those services.
+ Please provide a description of your issue here.
- type: textarea
id: screenshots
attributes:
@@ -34,19 +20,19 @@ body:
validations:
required: true
- type: input
- id: gitea-ver
+ id: devstar-ver
attributes:
- label: Gitea Version
- description: Gitea version (or commit reference) your instance is running
+ label: DevStar Version
+ description: DevStar version (or commit reference) your instance is running
validations:
required: true
- type: dropdown
id: can-reproduce
attributes:
- label: Can you reproduce the bug on the Gitea demo site?
+ label: Can you reproduce the bug on the DevStar demo site?
description: |
If so, please provide a URL in the Description field
- URL of Gitea demo: https://demo.gitea.com
+ URL of DevStar demo: https://devstar.cn
options:
- "Yes"
- "No"
@@ -56,11 +42,11 @@ body:
id: os-ver
attributes:
label: Operating System
- description: The operating system you are using to access Gitea
+ description: The operating system you are using to access DevStar
- type: input
id: browser-ver
attributes:
label: Browser Version
- description: The browser and version that you are using to access Gitea
+ description: The browser and version that you are using to access DevStar
validations:
required: true
diff --git a/.github/dependabot.yml b/.github/dependabot.yml
new file mode 100644
index 0000000000..be33b8975f
--- /dev/null
+++ b/.github/dependabot.yml
@@ -0,0 +1,10 @@
+version: 2
+
+updates:
+ - package-ecosystem: github-actions
+ labels: [modifies/dependencies]
+ directory: /
+ schedule:
+ interval: daily
+ cooldown:
+ default-days: 5
diff --git a/.github/labeler.yml b/.github/labeler.yml
index 49679d28cf..0f3c508041 100644
--- a/.github/labeler.yml
+++ b/.github/labeler.yml
@@ -43,15 +43,13 @@ modifies/internal:
- ".editorconfig"
- ".eslintrc.cjs"
- ".golangci.yml"
- - ".gitpod.yml"
- ".markdownlint.yaml"
- ".spectral.yaml"
- - "stylelint.config.js"
+ - "stylelint.config.*"
- ".yamllint.yaml"
- ".github/**"
- ".gitea/**"
- ".devcontainer/**"
- - "build.go"
- "build/**"
- "contrib/**"
@@ -85,9 +83,9 @@ docs-update-needed:
topic/code-linting:
- changed-files:
- any-glob-to-any-file:
- - ".eslintrc.cjs"
- ".golangci.yml"
- ".markdownlint.yaml"
- ".spectral.yaml"
- ".yamllint.yaml"
- - "stylelint.config.js"
+ - "eslint*.config.*"
+ - "stylelint.config.*"
diff --git a/.github/pull_request_template.md b/.github/pull_request_template.md
index b7594a1ba7..3502849161 100644
--- a/.github/pull_request_template.md
+++ b/.github/pull_request_template.md
@@ -1,8 +1,8 @@
Please check the following:
1. Make sure you are targeting the `main` branch, pull requests on release branches are only allowed for backports.
-2. Make sure you have read contributing guidelines: https://github.com/go-gitea/gitea/blob/main/CONTRIBUTING.md .
-3. For documentations contribution, please go to https://gitea.com/gitea/docs
+2. Make sure you have read contributing guidelines: CONTRIBUTING.md .
+3. For documentations contribution, please go to https://github.com/mengning/DevStar/wiki
4. Describe what your pull request does and which issue you're targeting (if any).
5. It is recommended to enable "Allow edits by maintainers", so maintainers can help more easily.
6. Your input here will be included in the commit message when this PR has been merged. If you don't want some content to be included, please separate them with a line like `---`.
diff --git a/.github/workflows/PushDevStarImage2DockerHub.yml b/.github/workflows/PushDevStarImage2DockerHub.yml
index 3f77646dd2..bba4dc593f 100644
--- a/.github/workflows/PushDevStarImage2DockerHub.yml
+++ b/.github/workflows/PushDevStarImage2DockerHub.yml
@@ -17,31 +17,29 @@ jobs:
build:
# The type of runner that the job will run on
runs-on: ubuntu-latest
-
- steps:
- - name: Log in to DevStar.cn Registry
- uses: docker/login-action@v2
- with:
- registry: devstar.cn # 替换为目标镜像仓库
- username: ${{ secrets.DEVSTAR_USERNAME }} # 目标仓库用户名
- password: ${{ secrets.DEVSTAR_PASSWORD }} # 目标仓库密码
-
- - name: Pull DevStar Image
- run: |
- docker pull devstarcn/${{ github.event.inputs.IMAGE_NAME }}
- docker pull devstar.cn/devstar/${{ github.event.inputs.IMAGE_NAME }}
+ steps:
+ - name: Install skopeo
+ run: |
+ sudo apt-get update
+ sudo apt-get install -y skopeo
+
+ - name: Login to source registry (devstar.cn)
+ run: |
+ skopeo login devstar.cn \
+ --username ${{ secrets.DEVSTAR_USERNAME }} \
+ --password ${{ secrets.DEVSTAR_PASSWORD }}
+
+ - name: Login to target registry (Docker Hub)
+ run: |
+ skopeo login docker.io \
+ --username ${{ secrets.DOCKER_USERNAME }} \
+ --password ${{ secrets.DOCKER_PASSWORD }}
+
+ - name: Copy image
+ run: |
+ skopeo copy --all \
+ --src-tls-verify=false \
+ --dest-tls-verify=true \
+ docker://devstar.cn/devstar/${{ github.event.inputs.IMAGE_NAME }} \
+ docker://devstarcn/${{ github.event.inputs.IMAGE_NAME }}
- - name: Log in to Target Docker Registry
- uses: docker/login-action@v2
- with:
- registry: docker.io # 替换为目标镜像仓库
- username: ${{ secrets.DOCKER_USERNAME }} # 目标仓库用户名
- password: ${{ secrets.DOCKER_PASSWORD }} # 目标仓库密码
-
- - name: Tag Docker Image for Target Registry
- run: |
- docker tag devstar.cn/devstar/${{ github.event.inputs.IMAGE_NAME }} devstarcn/${{ github.event.inputs.IMAGE_NAME }} # 替换为目标镜像名称和标签
-
- - name: Push Docker Image to Target Registry
- run: |
- docker push devstarcn/${{ github.event.inputs.IMAGE_NAME }} # 替换为目标镜像名称和标签
diff --git a/.github/workflows/cron-flake-updater.yml b/.github/workflows/cron-flake-updater.yml
new file mode 100644
index 0000000000..c9a1f22a2a
--- /dev/null
+++ b/.github/workflows/cron-flake-updater.yml
@@ -0,0 +1,22 @@
+name: cron-flake-updater
+
+on:
+ workflow_dispatch:
+ schedule:
+ - cron: '0 0 * * 0' # runs weekly on Sunday at 00:00
+
+jobs:
+ nix-flake-update:
+ permissions:
+ contents: write
+ issues: write
+ pull-requests: write
+ runs-on: ubuntu-latest
+ steps:
+ - uses: actions/checkout@v6
+ - uses: DeterminateSystems/determinate-nix-action@v3
+ - uses: DeterminateSystems/update-flake-lock@main
+ with:
+ pr-title: "Update Nix flake"
+ pr-labels: |
+ dependencies
diff --git a/.github/workflows/cron-translations.yml b/.github/workflows/cron-translations.yml
index f1b51debf1..56a30fb5ba 100644
--- a/.github/workflows/cron-translations.yml
+++ b/.github/workflows/cron-translations.yml
@@ -9,9 +9,11 @@ jobs:
crowdin-pull:
runs-on: ubuntu-latest
if: github.repository == 'go-gitea/gitea'
+ permissions:
+ contents: write
steps:
- - uses: actions/checkout@v4
- - uses: crowdin/github-action@v1
+ - uses: actions/checkout@v6
+ - uses: crowdin/github-action@v2
with:
upload_sources: true
upload_translations: false
@@ -27,7 +29,7 @@ jobs:
- name: update locales
run: ./build/update-locales.sh
- name: push translations to repo
- uses: appleboy/git-push-action@v0.0.3
+ uses: appleboy/git-push-action@v1.2.0
with:
author_email: "teabot@gitea.io"
author_name: GiteaBot
diff --git a/.github/workflows/files-changed.yml b/.github/workflows/files-changed.yml
index edceef0092..55d206bb0f 100644
--- a/.github/workflows/files-changed.yml
+++ b/.github/workflows/files-changed.yml
@@ -19,11 +19,15 @@ on:
value: ${{ jobs.detect.outputs.swagger }}
yaml:
value: ${{ jobs.detect.outputs.yaml }}
+ json:
+ value: ${{ jobs.detect.outputs.json }}
jobs:
detect:
runs-on: ubuntu-latest
timeout-minutes: 3
+ permissions:
+ contents: read
outputs:
backend: ${{ steps.changes.outputs.backend }}
frontend: ${{ steps.changes.outputs.frontend }}
@@ -33,9 +37,10 @@ jobs:
docker: ${{ steps.changes.outputs.docker }}
swagger: ${{ steps.changes.outputs.swagger }}
yaml: ${{ steps.changes.outputs.yaml }}
+ json: ${{ steps.changes.outputs.json }}
steps:
- - uses: actions/checkout@v4
- - uses: dorny/paths-filter@v3
+ - uses: actions/checkout@v6
+ - uses: dorny/paths-filter@v4
id: changes
with:
filters: |
@@ -48,7 +53,7 @@ jobs:
- "Makefile"
- ".golangci.yml"
- ".editorconfig"
- - "options/locale/locale_en-US.ini"
+ - "options/locale/locale_en-US.json"
frontend:
- "*.js"
@@ -80,6 +85,7 @@ jobs:
- "uv.lock"
docker:
+ - ".github/workflows/pull-docker-dryrun.yml"
- "Dockerfile"
- "Dockerfile.rootless"
- "docker/**"
@@ -98,3 +104,6 @@ jobs:
- "**/*.yaml"
- ".yamllint.yaml"
- "pyproject.toml"
+
+ json:
+ - "**/*.json"
diff --git a/.github/workflows/pull-docker-dryrun.yml b/.github/workflows/pull-docker-dryrun.yml
index f74277de67..201825ccba 100644
--- a/.github/workflows/pull-docker-dryrun.yml
+++ b/.github/workflows/pull-docker-dryrun.yml
@@ -10,26 +10,31 @@ concurrency:
jobs:
files-changed:
uses: ./.github/workflows/files-changed.yml
+ permissions:
+ contents: read
- regular:
- if: needs.files-changed.outputs.docker == 'true' || needs.files-changed.outputs.actions == 'true'
+ container:
+ if: needs.files-changed.outputs.docker == 'true'
needs: files-changed
runs-on: ubuntu-latest
+ permissions:
+ contents: read
steps:
- - uses: docker/setup-buildx-action@v3
- - uses: docker/build-push-action@v5
+ - uses: actions/checkout@v6
+ - uses: docker/setup-qemu-action@v4
+ - uses: docker/setup-buildx-action@v4
+ - name: Build regular container image
+ uses: docker/build-push-action@v7
with:
+ context: .
+ platforms: linux/amd64,linux/arm64,linux/riscv64
push: false
- tags: gitea/gitea:linux-amd64
-
- rootless:
- if: needs.files-changed.outputs.docker == 'true' || needs.files-changed.outputs.actions == 'true'
- needs: files-changed
- runs-on: ubuntu-latest
- steps:
- - uses: docker/setup-buildx-action@v3
- - uses: docker/build-push-action@v5
+ cache-from: type=registry,ref=ghcr.io/go-gitea/gitea:buildcache-rootful
+ - name: Build rootless container image
+ uses: docker/build-push-action@v7
with:
+ context: .
push: false
+ platforms: linux/amd64,linux/arm64,linux/riscv64
file: Dockerfile.rootless
- tags: gitea/gitea:linux-amd64
+ cache-from: type=registry,ref=ghcr.io/go-gitea/gitea:buildcache-rootless
diff --git a/.github/workflows/pull-labeler.yml b/.github/workflows/pull-labeler.yml
index 812819b599..d05483e56c 100644
--- a/.github/workflows/pull-labeler.yml
+++ b/.github/workflows/pull-labeler.yml
@@ -15,6 +15,6 @@ jobs:
contents: read
pull-requests: write
steps:
- - uses: actions/labeler@v5
+ - uses: actions/labeler@v6
with:
sync-labels: true
diff --git a/.github/workflows/release-tag-rc.yml b/.github/workflows/release-tag-rc.yml
index b57e5e602f..248fa532ee 100644
--- a/.github/workflows/release-tag-rc.yml
+++ b/.github/workflows/release-tag-rc.yml
@@ -12,8 +12,10 @@ concurrency:
jobs:
binary:
runs-on: namespace-profile-gitea-release-binary
+ permissions:
+ contents: read
steps:
- - uses: actions/checkout@v4
+ - uses: actions/checkout@v6
# fetch all commits instead of only the last as some branches are long lived and could have many between versions
# fetch all tags to ensure that "git describe" reports expected Gitea version, eg. v1.21.0-dev-1-g1234567
- run: git fetch --unshallow --quiet --tags --force
@@ -21,10 +23,12 @@ jobs:
with:
go-version-file: go.mod
check-latest: true
- - uses: pnpm/action-setup@v4
- - uses: actions/setup-node@v5
+ - uses: pnpm/action-setup@v5
+ - uses: actions/setup-node@v6
with:
node-version: 24
+ cache: pnpm
+ cache-dependency-path: pnpm-lock.yaml
- run: make deps-frontend deps-backend
# xgo build
- run: make release
@@ -32,7 +36,7 @@ jobs:
TAGS: bindata sqlite sqlite_unlock_notify
- name: import gpg key
id: import_gpg
- uses: crazy-max/ghaction-import-gpg@v6
+ uses: crazy-max/ghaction-import-gpg@v7
with:
gpg_private_key: ${{ secrets.GPGSIGN_KEY }}
passphrase: ${{ secrets.GPGSIGN_PASSPHRASE }}
@@ -49,7 +53,7 @@ jobs:
echo "Cleaned name is ${REF_NAME}"
echo "branch=${REF_NAME}" >> "$GITHUB_OUTPUT"
- name: configure aws
- uses: aws-actions/configure-aws-credentials@v4
+ uses: aws-actions/configure-aws-credentials@v6
with:
aws-region: ${{ secrets.AWS_REGION }}
aws-access-key-id: ${{ secrets.AWS_ACCESS_KEY_ID }}
@@ -58,7 +62,7 @@ jobs:
run: |
aws s3 sync dist/release s3://${{ secrets.AWS_S3_BUCKET }}/gitea/${{ steps.clean_name.outputs.branch }} --no-progress
- name: Install GH CLI
- uses: dev-hanz-ops/install-gh-cli-action@v0.1.0
+ uses: dev-hanz-ops/install-gh-cli-action@v0.2.1
with:
gh-cli-version: 2.39.1
- name: create github release
@@ -66,18 +70,20 @@ jobs:
gh release create ${{ github.ref_name }} --title ${{ github.ref_name }} --draft --notes-from-tag dist/release/*
env:
GITHUB_TOKEN: ${{ secrets.RELEASE_TOKEN }}
- docker-rootful:
+
+ container:
runs-on: namespace-profile-gitea-release-docker
permissions:
+ contents: read
packages: write # to publish to ghcr.io
steps:
- - uses: actions/checkout@v4
+ - uses: actions/checkout@v6
# fetch all commits instead of only the last as some branches are long lived and could have many between versions
# fetch all tags to ensure that "git describe" reports expected Gitea version, eg. v1.21.0-dev-1-g1234567
- run: git fetch --unshallow --quiet --tags --force
- - uses: docker/setup-qemu-action@v3
- - uses: docker/setup-buildx-action@v3
- - uses: docker/metadata-action@v5
+ - uses: docker/setup-qemu-action@v4
+ - uses: docker/setup-buildx-action@v4
+ - uses: docker/metadata-action@v6
id: meta
with:
images: |-
@@ -88,38 +94,10 @@ jobs:
# 1.2.3-rc0
tags: |
type=semver,pattern={{version}}
- - name: Login to Docker Hub
- uses: docker/login-action@v3
- with:
- username: ${{ secrets.DOCKERHUB_USERNAME }}
- password: ${{ secrets.DOCKERHUB_TOKEN }}
- - name: Login to GHCR using PAT
- uses: docker/login-action@v3
- with:
- registry: ghcr.io
- username: ${{ github.repository_owner }}
- password: ${{ secrets.GITHUB_TOKEN }}
- - name: build rootful docker image
- uses: docker/build-push-action@v5
- with:
- context: .
- platforms: linux/amd64,linux/arm64,linux/riscv64
- push: true
- tags: ${{ steps.meta.outputs.tags }}
- labels: ${{ steps.meta.outputs.labels }}
- docker-rootless:
- runs-on: namespace-profile-gitea-release-docker
- permissions:
- packages: write # to publish to ghcr.io
- steps:
- - uses: actions/checkout@v4
- # fetch all commits instead of only the last as some branches are long lived and could have many between versions
- # fetch all tags to ensure that "git describe" reports expected Gitea version, eg. v1.21.0-dev-1-g1234567
- - run: git fetch --unshallow --quiet --tags --force
- - uses: docker/setup-qemu-action@v3
- - uses: docker/setup-buildx-action@v3
- - uses: docker/metadata-action@v5
- id: meta
+ annotations: |
+ org.opencontainers.image.authors="maintainers@gitea.io"
+ - uses: docker/metadata-action@v6
+ id: meta_rootless
with:
images: |-
gitea/gitea
@@ -131,23 +109,33 @@ jobs:
# 1.2.3-rc0
tags: |
type=semver,pattern={{version}}
+ annotations: |
+ org.opencontainers.image.authors="maintainers@gitea.io"
- name: Login to Docker Hub
- uses: docker/login-action@v3
+ uses: docker/login-action@v4
with:
username: ${{ secrets.DOCKERHUB_USERNAME }}
password: ${{ secrets.DOCKERHUB_TOKEN }}
- name: Login to GHCR using PAT
- uses: docker/login-action@v3
+ uses: docker/login-action@v4
with:
registry: ghcr.io
username: ${{ github.repository_owner }}
password: ${{ secrets.GITHUB_TOKEN }}
- - name: build rootless docker image
- uses: docker/build-push-action@v5
+ - name: build regular container image
+ uses: docker/build-push-action@v7
with:
context: .
platforms: linux/amd64,linux/arm64,linux/riscv64
push: true
- file: Dockerfile.rootless
tags: ${{ steps.meta.outputs.tags }}
- labels: ${{ steps.meta.outputs.labels }}
+ annotations: ${{ steps.meta.outputs.annotations }}
+ - name: build rootless container image
+ uses: docker/build-push-action@v7
+ with:
+ context: .
+ platforms: linux/amd64,linux/arm64,linux/riscv64
+ push: true
+ file: Dockerfile.rootless
+ tags: ${{ steps.meta_rootless.outputs.tags }}
+ annotations: ${{ steps.meta_rootless.outputs.annotations }}
diff --git a/.github/workflows/release-tag-version.yml b/.github/workflows/release-tag-version.yml
index c40aa8f030..1e84ae1739 100644
--- a/.github/workflows/release-tag-version.yml
+++ b/.github/workflows/release-tag-version.yml
@@ -15,9 +15,10 @@ jobs:
binary:
runs-on: namespace-profile-gitea-release-binary
permissions:
+ contents: read
packages: write # to publish to ghcr.io
steps:
- - uses: actions/checkout@v4
+ - uses: actions/checkout@v6
# fetch all commits instead of only the last as some branches are long lived and could have many between versions
# fetch all tags to ensure that "git describe" reports expected Gitea version, eg. v1.21.0-dev-1-g1234567
- run: git fetch --unshallow --quiet --tags --force
@@ -25,10 +26,12 @@ jobs:
with:
go-version-file: go.mod
check-latest: true
- - uses: pnpm/action-setup@v4
- - uses: actions/setup-node@v5
+ - uses: pnpm/action-setup@v5
+ - uses: actions/setup-node@v6
with:
node-version: 24
+ cache: pnpm
+ cache-dependency-path: pnpm-lock.yaml
- run: make deps-frontend deps-backend
# xgo build
- run: make release
@@ -36,7 +39,7 @@ jobs:
TAGS: bindata sqlite sqlite_unlock_notify
- name: import gpg key
id: import_gpg
- uses: crazy-max/ghaction-import-gpg@v6
+ uses: crazy-max/ghaction-import-gpg@v7
with:
gpg_private_key: ${{ secrets.GPGSIGN_KEY }}
passphrase: ${{ secrets.GPGSIGN_PASSPHRASE }}
@@ -53,7 +56,7 @@ jobs:
echo "Cleaned name is ${REF_NAME}"
echo "branch=${REF_NAME}" >> "$GITHUB_OUTPUT"
- name: configure aws
- uses: aws-actions/configure-aws-credentials@v4
+ uses: aws-actions/configure-aws-credentials@v6
with:
aws-region: ${{ secrets.AWS_REGION }}
aws-access-key-id: ${{ secrets.AWS_ACCESS_KEY_ID }}
@@ -62,7 +65,7 @@ jobs:
run: |
aws s3 sync dist/release s3://${{ secrets.AWS_S3_BUCKET }}/gitea/${{ steps.clean_name.outputs.branch }} --no-progress
- name: Install GH CLI
- uses: dev-hanz-ops/install-gh-cli-action@v0.1.0
+ uses: dev-hanz-ops/install-gh-cli-action@v0.2.1
with:
gh-cli-version: 2.39.1
- name: create github release
@@ -70,18 +73,20 @@ jobs:
gh release create ${{ github.ref_name }} --title ${{ github.ref_name }} --notes-from-tag dist/release/*
env:
GITHUB_TOKEN: ${{ secrets.RELEASE_TOKEN }}
- docker-rootful:
+
+ container:
runs-on: namespace-profile-gitea-release-docker
permissions:
+ contents: read
packages: write # to publish to ghcr.io
steps:
- - uses: actions/checkout@v4
+ - uses: actions/checkout@v6
# fetch all commits instead of only the last as some branches are long lived and could have many between versions
# fetch all tags to ensure that "git describe" reports expected Gitea version, eg. v1.21.0-dev-1-g1234567
- run: git fetch --unshallow --quiet --tags --force
- - uses: docker/setup-qemu-action@v3
- - uses: docker/setup-buildx-action@v3
- - uses: docker/metadata-action@v5
+ - uses: docker/setup-qemu-action@v4
+ - uses: docker/setup-buildx-action@v4
+ - uses: docker/metadata-action@v6
id: meta
with:
images: |-
@@ -96,36 +101,10 @@ jobs:
type=semver,pattern={{version}}
type=semver,pattern={{major}}
type=semver,pattern={{major}}.{{minor}}
- - name: Login to Docker Hub
- uses: docker/login-action@v3
- with:
- username: ${{ secrets.DOCKERHUB_USERNAME }}
- password: ${{ secrets.DOCKERHUB_TOKEN }}
- - name: Login to GHCR using PAT
- uses: docker/login-action@v3
- with:
- registry: ghcr.io
- username: ${{ github.repository_owner }}
- password: ${{ secrets.GITHUB_TOKEN }}
- - name: build rootful docker image
- uses: docker/build-push-action@v5
- with:
- context: .
- platforms: linux/amd64,linux/arm64,linux/riscv64
- push: true
- tags: ${{ steps.meta.outputs.tags }}
- labels: ${{ steps.meta.outputs.labels }}
- docker-rootless:
- runs-on: namespace-profile-gitea-release-docker
- steps:
- - uses: actions/checkout@v4
- # fetch all commits instead of only the last as some branches are long lived and could have many between versions
- # fetch all tags to ensure that "git describe" reports expected Gitea version, eg. v1.21.0-dev-1-g1234567
- - run: git fetch --unshallow --quiet --tags --force
- - uses: docker/setup-qemu-action@v3
- - uses: docker/setup-buildx-action@v3
- - uses: docker/metadata-action@v5
- id: meta
+ annotations: |
+ org.opencontainers.image.authors="maintainers@gitea.io"
+ - uses: docker/metadata-action@v6
+ id: meta_rootless
with:
images: |-
gitea/gitea
@@ -142,23 +121,33 @@ jobs:
type=semver,pattern={{version}}
type=semver,pattern={{major}}
type=semver,pattern={{major}}.{{minor}}
+ annotations: |
+ org.opencontainers.image.authors="maintainers@gitea.io"
- name: Login to Docker Hub
- uses: docker/login-action@v3
+ uses: docker/login-action@v4
with:
username: ${{ secrets.DOCKERHUB_USERNAME }}
password: ${{ secrets.DOCKERHUB_TOKEN }}
- name: Login to GHCR using PAT
- uses: docker/login-action@v3
+ uses: docker/login-action@v4
with:
registry: ghcr.io
username: ${{ github.repository_owner }}
password: ${{ secrets.GITHUB_TOKEN }}
- - name: build rootless docker image
- uses: docker/build-push-action@v5
+ - name: build regular container image
+ uses: docker/build-push-action@v7
with:
context: .
platforms: linux/amd64,linux/arm64,linux/riscv64
push: true
- file: Dockerfile.rootless
tags: ${{ steps.meta.outputs.tags }}
- labels: ${{ steps.meta.outputs.labels }}
+ annotations: ${{ steps.meta.outputs.annotations }}
+ - name: build rootless container image
+ uses: docker/build-push-action@v7
+ with:
+ context: .
+ platforms: linux/amd64,linux/arm64,linux/riscv64
+ push: true
+ file: Dockerfile.rootless
+ tags: ${{ steps.meta_rootless.outputs.tags }}
+ annotations: ${{ steps.meta_rootless.outputs.annotations }}
diff --git a/.gitignore b/.gitignore
index a580861a51..019ee94c7a 100644
--- a/.gitignore
+++ b/.gitignore
@@ -25,6 +25,9 @@ __debug_bin*
# Visual Studio
/.vs/
+# mise version managment tool
+mise.toml
+
*.cgo1.go
*.cgo2.c
_cgo_defun.c
@@ -52,6 +55,7 @@ cpu.out
*.log.*.gz
/gitea
+/gitea-e2e
/gitea-vet
/debug
/integrations.test
@@ -64,13 +68,9 @@ cpu.out
/indexers
/log
/public/assets/img/avatar
+/tests/e2e-output
/tests/integration/gitea-integration-*
/tests/integration/indexers-*
-/tests/e2e/gitea-e2e-*
-/tests/e2e/indexers-*
-/tests/e2e/reports
-/tests/e2e/test-artifacts
-/tests/e2e/test-snapshots
/tests/*.ini
/tests/**/*.git/**/*.sample
/node_modules
@@ -79,6 +79,7 @@ cpu.out
/yarn-error.log
/npm-debug.log*
/.pnpm-store
+/public/assets/.vite
/public/assets/js
/public/assets/css
/public/assets/fonts
@@ -86,10 +87,7 @@ cpu.out
/vendor
/VERSION
/.air
-/.go-licenses
-# Files and folders that were previously generated
-/public/assets/img/webpack
# Snapcraft
/gitea_a*.txt
@@ -118,7 +116,10 @@ prime/
/.goosehints
/.windsurfrules
/.github/copilot-instructions.md
-/AGENT.md
-/CLAUDE.md
/llms.txt
+# Ignore worktrees when working on multiple branches
+.worktrees/
+
+# A Makefile for custom make targets
+Makefile.local
diff --git a/.gitpod.yml b/.gitpod.yml
deleted file mode 100644
index 8671edc47c..0000000000
--- a/.gitpod.yml
+++ /dev/null
@@ -1,51 +0,0 @@
-tasks:
- - name: Setup
- init: |
- cp -r contrib/ide/vscode .vscode
- make deps
- make build
- command: |
- gp sync-done setup
- exit 0
- - name: Run backend
- command: |
- gp sync-await setup
-
- # Get the URL and extract the domain
- url=$(gp url 3000)
- domain=$(echo $url | awk -F[/:] '{print $4}')
-
- if [ -f custom/conf/app.ini ]; then
- sed -i "s|^ROOT_URL =.*|ROOT_URL = ${url}/|" custom/conf/app.ini
- sed -i "s|^DOMAIN =.*|DOMAIN = ${domain}|" custom/conf/app.ini
- sed -i "s|^SSH_DOMAIN =.*|SSH_DOMAIN = ${domain}|" custom/conf/app.ini
- sed -i "s|^NO_REPLY_ADDRESS =.*|SSH_DOMAIN = noreply.${domain}|" custom/conf/app.ini
- else
- mkdir -p custom/conf/
- echo -e "[server]\nROOT_URL = ${url}/" > custom/conf/app.ini
- echo -e "\n[database]\nDB_TYPE = sqlite3\nPATH = $GITPOD_REPO_ROOT/data/gitea.db" >> custom/conf/app.ini
- fi
- export TAGS="sqlite sqlite_unlock_notify"
- make watch-backend
- - name: Run frontend
- command: |
- gp sync-await setup
- make watch-frontend
- openMode: split-right
-
-vscode:
- extensions:
- - editorconfig.editorconfig
- - dbaeumer.vscode-eslint
- - golang.go
- - stylelint.vscode-stylelint
- - DavidAnson.vscode-markdownlint
- - Vue.volar
- - ms-azuretools.vscode-docker
- - vitest.explorer
- - cweijan.vscode-database-client2
- - GitHub.vscode-pull-request-github
-
-ports:
- - name: Gitea
- port: 3000
diff --git a/.golangci.yml b/.golangci.yml
index 2ad39fbae2..afd91d65e5 100644
--- a/.golangci.yml
+++ b/.golangci.yml
@@ -6,15 +6,19 @@ linters:
default: none
enable:
- bidichk
+ - bodyclose
- depguard
- dupl
- errcheck
- forbidigo
+ - gocheckcompilerdirectives
- gocritic
- govet
- ineffassign
- mirror
+ - modernize
- nakedret
+ - nilnil
- nolintlint
- perfsprint
- revive
@@ -45,6 +49,8 @@ linters:
desc: do not use the ini package, use gitea's config system instead
- pkg: gitea.com/go-chi/cache
desc: do not use the go-chi cache package, use gitea's cache system
+ - pkg: github.com/pkg/errors
+ desc: use builtin errors package instead
nolintlint:
allow-unused: false
require-explanation: true
@@ -55,38 +61,28 @@ linters:
disabled-checks:
- ifElseChain
- singleCaseSwitch # Every time this occurred in the code, there was no other way.
+ - deprecatedComment # conflicts with go-swagger comments
revive:
severity: error
rules:
- - name: atomic
- - name: bare-return
- name: blank-imports
- name: constant-logical-expr
- name: context-as-argument
- name: context-keys-type
- name: dot-imports
- - name: duplicated-imports
- name: empty-lines
- - name: error-naming
- name: error-return
- name: error-strings
- - name: errorf
- name: exported
- name: identical-branches
- name: if-return
- name: increment-decrement
- - name: indent-error-flow
- name: modifies-value-receiver
- name: package-comments
- - name: range
- - name: receiver-naming
- name: redefines-builtin-id
- - name: string-of-int
- name: superfluous-else
- name: time-naming
- - name: unconditional-recursion
- name: unexported-return
- - name: unreachable-code
- name: var-declaration
- name: var-naming
arguments:
@@ -107,6 +103,12 @@ linters:
- require-error
usetesting:
os-temp-dir: true
+ perfsprint:
+ concat-loop: false
+ govet:
+ enable:
+ - nilness
+ - unusedwrite
exclusions:
generated: lax
presets:
@@ -118,16 +120,12 @@ linters:
- linters:
- dupl
- errcheck
- - gocyclo
- - gosec
- staticcheck
- unparam
path: _test\.go
- linters:
- dupl
- errcheck
- - gocyclo
- - gosec
path: models/migrations/v
- linters:
- forbidigo
@@ -139,12 +137,8 @@ linters:
- gocritic
text: (?i)`ID' should not be capitalized
- linters:
- - deadcode
- unused
text: (?i)swagger
- - linters:
- - staticcheck
- text: (?i)argument x is overwritten before first use
- linters:
- gocritic
text: '(?i)commentFormatting: put a space between `//` and comment text'
@@ -153,6 +147,7 @@ linters:
text: '(?i)exitAfterDefer:'
paths:
- node_modules
+ - .venv
- public
- web_src
- third_party$
@@ -172,6 +167,7 @@ formatters:
generated: lax
paths:
- node_modules
+ - .venv
- public
- web_src
- third_party$
diff --git a/.yamllint.yaml b/.yamllint.yaml
index 5a1e1e8751..1d33eceeb8 100644
--- a/.yamllint.yaml
+++ b/.yamllint.yaml
@@ -21,9 +21,7 @@ rules:
comments-indentation:
level: error
- document-start:
- level: error
- present: false
+ document-start: disable
document-end:
present: false
diff --git a/AGENTS.md b/AGENTS.md
new file mode 100644
index 0000000000..589dea7865
--- /dev/null
+++ b/AGENTS.md
@@ -0,0 +1,11 @@
+- Use `make help` to find available development targets
+- Run `make fmt` to format `.go` files, and run `make lint-go` to lint them
+- Run `make lint-js` to lint `.ts` files
+- Run `make tidy` after any `go.mod` changes
+- Add the current year into the copyright header of new `.go` files
+- Ensure no trailing whitespace in edited files
+- Never force-push, amend, or squash unless asked. Use new commits and normal push for pull request updates
+- Preserve existing code comments, do not remove or rewrite comments that are still relevant
+- In TypeScript, use `!` (non-null assertion) instead of `?.`/`??` when a value is known to always exist
+- Include authorship attribution in issue and pull request comments
+- Add `Co-Authored-By` lines to all commits, indicating name and model used
diff --git a/CLAUDE.md b/CLAUDE.md
new file mode 100644
index 0000000000..43c994c2d3
--- /dev/null
+++ b/CLAUDE.md
@@ -0,0 +1 @@
+@AGENTS.md
diff --git a/CONTRIBUTING.md b/CONTRIBUTING.md
index 96e05c578f..4b32631d6a 100644
--- a/CONTRIBUTING.md
+++ b/CONTRIBUTING.md
@@ -4,6 +4,7 @@
- [Contribution Guidelines](#contribution-guidelines)
- [Introduction](#introduction)
+ - [AI Contribution Policy](#ai-contribution-policy)
- [Issues](#issues)
- [How to report issues](#how-to-report-issues)
- [Types of issues](#types-of-issues)
@@ -67,6 +68,21 @@ Sensitive security-related issues should be reported to [security@gitea.io](mail
For configuring IDEs for Gitea development, see the [contributed IDE configurations](contrib/ide/).
+## AI Contribution Policy
+
+Contributions made with the assistance of AI tools are welcome, but contributors must use them responsibly and disclose that use clearly.
+
+1. Review AI-generated code closely before marking a pull request ready for review.
+2. Manually test the changes and add appropriate automated tests where feasible.
+3. Only use AI to assist in contributions that you understand well enough to explain, defend, and revise yourself during review.
+4. Disclose AI-assisted content clearly.
+5. Do not use AI to reply to questions about your issue or pull request. The questions are for you, not an AI model.
+6. AI may be used to help draft issues and pull requests, but contributors remain responsible for the accuracy, completeness, and intent of what they submit.
+
+Maintainers reserve the right to close pull requests and issues that do not disclose AI assistance, that appear to be low-quality AI-generated content, or where the contributor cannot explain or defend the proposed changes themselves.
+
+We welcome new contributors, but cannot sustain the effort of supporting contributors who primarily defer to AI rather than engaging substantively with the review process.
+
## Issues
### How to report issues
@@ -80,7 +96,7 @@ The more detailed and specific you are, the faster we can fix the issue. \
It is really helpful if you can reproduce your problem on a site running on the latest commits, i.e. , as perhaps your problem has already been fixed on a current version. \
Please follow the guidelines described in [How to Report Bugs Effectively](http://www.chiark.greenend.org.uk/~sgtatham/bugs.html) for your report.
-Please be kind, remember that Gitea comes at no cost to you, and you're getting free help.
+Please be kind—remember that Gitea comes at no cost to you, and you're getting free help.
### Types of issues
@@ -166,24 +182,32 @@ Here's how to run the test suite:
- code lint
-| | |
-| :-------------------- | :---------------------------------------------------------------- |
+| | |
+| :-------------------- | :--------------------------------------------------------------------------- |
|``make lint`` | lint everything (not needed if you only change the front- **or** backend) |
-|``make lint-frontend`` | lint frontend files |
-|``make lint-backend`` | lint backend files |
+|``make lint-frontend`` | lint frontend files |
+|``make lint-backend`` | lint backend files |
- run tests (we suggest running them on Linux)
-| Command | Action | |
-| :------------------------------------- | :----------------------------------------------- | ------------ |
-|``make test[\#SpecificTestName]`` | run unit test(s) | |
-|``make test-sqlite[\#SpecificTestName]``| run [integration](tests/integration) test(s) for SQLite |[More details](tests/integration/README.md) |
-|``make test-e2e-sqlite[\#SpecificTestName]``| run [end-to-end](tests/e2e) test(s) for SQLite |[More details](tests/e2e/README.md) |
+| Command | Action | |
+| :------------------------------------------ | :------------------------------------------------------- | ------------------------------------------- |
+|``make test[\#SpecificTestName]`` | run unit test(s) | |
+|``make test-sqlite[\#SpecificTestName]`` | run [integration](tests/integration) test(s) for SQLite | [More details](tests/integration/README.md) |
+|``make test-e2e`` | run [end-to-end](tests/e2e) test(s) using Playwright | |
+
+- E2E test environment variables
+
+| Variable | Description |
+| :-------------------------------- | :---------------------------------------------------------- |
+| ``GITEA_TEST_E2E_DEBUG`` | When set, show Gitea server output |
+| ``GITEA_TEST_E2E_FLAGS`` | Additional flags passed to Playwright, for example ``--ui`` |
+| ``GITEA_TEST_E2E_TIMEOUT_FACTOR`` | Timeout multiplier (default: 3 on CI, 1 locally) |
## Translation
All translation work happens on [Crowdin](https://translate.gitea.com).
-The only translation that is maintained in this repository is [the English translation](https://github.com/go-gitea/gitea/blob/main/options/locale/locale_en-US.ini).
+The only translation that is maintained in this repository is [the English translation](https://github.com/go-gitea/gitea/blob/main/options/locale/locale_en-US.json).
It is synced regularly with Crowdin. \
Other locales on main branch **should not** be updated manually as they will be overwritten with each sync. \
Once a language has reached a **satisfactory percentage** of translated keys (~25%), it will be synced back into this repo and included in the next released version.
diff --git a/Dockerfile b/Dockerfile
index 78a556497a..323f06125f 100644
--- a/Dockerfile
+++ b/Dockerfile
@@ -1,8 +1,15 @@
-# Build stage
-FROM docker.io/library/golang:1.25-alpine3.22 AS build-env
-
-ARG GOPROXY
-ENV GOPROXY=${GOPROXY:-direct}
+# syntax=docker/dockerfile:1
+# Build frontend on the native platform to avoid QEMU-related issues with nodejs ecosystem
+FROM --platform=$BUILDPLATFORM docker.io/library/golang:1.26-alpine3.23 AS frontend-build
+RUN apk --no-cache add build-base git nodejs pnpm
+WORKDIR /src
+COPY package.json pnpm-lock.yaml .npmrc ./
+RUN --mount=type=cache,target=/root/.local/share/pnpm/store pnpm install --frozen-lockfile
+COPY --exclude=.git/ . .
+RUN make frontend
+
+# Build backend for each target platform
+FROM docker.io/library/golang:1.26-alpine3.23 AS build-env
ARG GITEA_VERSION
ARG TAGS="sqlite sqlite_unlock_notify"
@@ -12,37 +19,32 @@ ARG CGO_EXTRA_CFLAGS
# Build deps
RUN apk --no-cache add \
build-base \
- git \
- nodejs \
- npm \
- && npm install -g pnpm@10 \
- && rm -rf /var/cache/apk/*
+ git
-# Setup repo
-COPY . ${GOPATH}/src/code.gitea.io/gitea
WORKDIR ${GOPATH}/src/code.gitea.io/gitea
+COPY go.mod go.sum ./
+RUN go mod download
+# Use COPY instead of bind mount as read-only one breaks makefile state tracking and read-write one needs binary to be moved as it's discarded.
+# ".git" directory is mounted separately later only for version data extraction.
+COPY --exclude=.git/ . .
+COPY --from=frontend-build /src/public/assets public/assets
+
+# Build gitea, .git mount is required for version data
+RUN --mount=type=cache,target="/root/.cache/go-build" \
+ --mount=type=bind,source=".git/",target=".git/" \
+ make backend
-# Checkout version if set
-RUN if [ -n "${GITEA_VERSION}" ]; then git checkout "${GITEA_VERSION}"; fi \
- && make clean-all build
-
-# Begin env-to-ini build
-RUN go build contrib/environment-to-ini/environment-to-ini.go
-
-# Copy local files
COPY docker/root /tmp/local
-# Set permissions
+# Set permissions for builds that made under windows which strips the executable bit from file
RUN chmod 755 /tmp/local/usr/bin/entrypoint \
- /tmp/local/usr/local/bin/gitea \
+ /tmp/local/usr/local/bin/* \
/tmp/local/etc/s6/gitea/* \
/tmp/local/etc/s6/openssh/* \
/tmp/local/etc/s6/.s6-svscan/* \
- /go/src/code.gitea.io/gitea/gitea \
- /go/src/code.gitea.io/gitea/environment-to-ini
+ /go/src/code.gitea.io/gitea/gitea
-FROM docker.io/library/alpine:3.22
-LABEL maintainer="maintainers@gitea.io"
+FROM docker.io/library/alpine:3.23 AS gitea
EXPOSE 22 3000
@@ -57,8 +59,7 @@ RUN apk --no-cache add \
s6 \
sqlite \
su-exec \
- gnupg \
- && rm -rf /var/cache/apk/*
+ gnupg
RUN addgroup \
-S -g 1000 \
@@ -72,14 +73,14 @@ RUN addgroup \
git && \
echo "git:*" | chpasswd -e
+COPY --from=build-env /tmp/local /
+COPY --from=build-env /go/src/code.gitea.io/gitea/gitea /app/gitea/gitea
+
ENV USER=git
ENV GITEA_CUSTOM=/data/gitea
VOLUME ["/data"]
+# HINT: HEALTH-CHECK-ENDPOINT: don't use HEALTHCHECK, search this hint keyword for more information
ENTRYPOINT ["/usr/bin/entrypoint"]
CMD ["/usr/bin/s6-svscan", "/etc/s6"]
-
-COPY --from=build-env /tmp/local /
-COPY --from=build-env /go/src/code.gitea.io/gitea/gitea /app/gitea/gitea
-COPY --from=build-env /go/src/code.gitea.io/gitea/environment-to-ini /usr/local/bin/environment-to-ini
diff --git a/Dockerfile.rootless b/Dockerfile.rootless
index e83c1af33b..83c69cbd51 100644
--- a/Dockerfile.rootless
+++ b/Dockerfile.rootless
@@ -1,46 +1,45 @@
-# Build stage
-FROM docker.io/library/golang:1.25-alpine3.22 AS build-env
-
-ARG GOPROXY
-ENV GOPROXY=${GOPROXY:-direct}
+# syntax=docker/dockerfile:1
+# Build frontend on the native platform to avoid QEMU-related issues with nodejs ecosystem
+FROM --platform=$BUILDPLATFORM docker.io/library/golang:1.26-alpine3.23 AS frontend-build
+RUN apk --no-cache add build-base git nodejs pnpm
+WORKDIR /src
+COPY package.json pnpm-lock.yaml .npmrc ./
+RUN --mount=type=cache,target=/root/.local/share/pnpm/store pnpm install --frozen-lockfile
+COPY --exclude=.git/ . .
+RUN make frontend
+
+# Build backend for each target platform
+FROM docker.io/library/golang:1.26-alpine3.23 AS build-env
ARG GITEA_VERSION
ARG TAGS="sqlite sqlite_unlock_notify"
ENV TAGS="bindata timetzdata $TAGS"
ARG CGO_EXTRA_CFLAGS
-#Build deps
+# Build deps
RUN apk --no-cache add \
build-base \
- git \
- nodejs \
- npm \
- && npm install -g pnpm@10 \
- && rm -rf /var/cache/apk/*
+ git
-# Setup repo
-COPY . ${GOPATH}/src/code.gitea.io/gitea
WORKDIR ${GOPATH}/src/code.gitea.io/gitea
+COPY go.mod go.sum ./
+RUN go mod download
+# See the comments in Dockerfile
+COPY --exclude=.git/ . .
+COPY --from=frontend-build /src/public/assets public/assets
-# Checkout version if set
-RUN if [ -n "${GITEA_VERSION}" ]; then git checkout "${GITEA_VERSION}"; fi \
- && make clean-all build
-
-# Begin env-to-ini build
-RUN go build contrib/environment-to-ini/environment-to-ini.go
+# Build gitea, .git mount is required for version data
+RUN --mount=type=cache,target="/root/.cache/go-build" \
+ --mount=type=bind,source=".git/",target=".git/" \
+ make backend
-# Copy local files
COPY docker/rootless /tmp/local
-# Set permissions
-RUN chmod 755 /tmp/local/usr/local/bin/docker-entrypoint.sh \
- /tmp/local/usr/local/bin/docker-setup.sh \
- /tmp/local/usr/local/bin/gitea \
- /go/src/code.gitea.io/gitea/gitea \
- /go/src/code.gitea.io/gitea/environment-to-ini
+# Set permissions for builds that made under windows which strips the executable bit from file
+RUN chmod 755 /tmp/local/usr/local/bin/* \
+ /go/src/code.gitea.io/gitea/gitea
-FROM docker.io/library/alpine:3.22
-LABEL maintainer="maintainers@gitea.io"
+FROM docker.io/library/alpine:3.23 AS gitea-rootless
EXPOSE 2222 3000
@@ -52,8 +51,7 @@ RUN apk --no-cache add \
git \
curl \
gnupg \
- openssh-keygen \
- && rm -rf /var/cache/apk/*
+ openssh-keygen
RUN addgroup \
-S -g 1000 \
@@ -71,7 +69,6 @@ RUN chown git:git /var/lib/gitea /etc/gitea
COPY --from=build-env /tmp/local /
COPY --from=build-env --chown=root:root /go/src/code.gitea.io/gitea/gitea /app/gitea/gitea
-COPY --from=build-env --chown=root:root /go/src/code.gitea.io/gitea/environment-to-ini /usr/local/bin/environment-to-ini
# git:git
USER 1000:1000
@@ -86,5 +83,6 @@ ENV HOME="/var/lib/gitea/git"
VOLUME ["/var/lib/gitea", "/etc/gitea"]
WORKDIR /var/lib/gitea
+# HINT: HEALTH-CHECK-ENDPOINT: don't use HEALTHCHECK, search this hint keyword for more information
ENTRYPOINT ["/usr/bin/dumb-init", "--", "/usr/local/bin/docker-entrypoint.sh"]
CMD []
diff --git a/MAINTAINERS b/MAINTAINERS
index 1c7afc6f6c..26192eff44 100644
--- a/MAINTAINERS
+++ b/MAINTAINERS
@@ -64,3 +64,4 @@ metiftikci (@metiftikci)
Christopher Homberger (@ChristopherHX)
Tobias Balle-Petersen (@tobiasbp)
TheFox (@TheFox0x7)
+Nicolas (@bircni)
\ No newline at end of file
diff --git a/README.md b/README.md
index 9357c32548..6928c01449 100644
--- a/README.md
+++ b/README.md
@@ -1,5 +1,7 @@
# DevStar
+DevStar AI 2.0 Agent Teams: Empowering innovators to make the world better.
+
The Last Mile of Al for R&D. Make it possible to code everything.
Delivering a truly AI‑Native, all‑in‑one R&D ecosystem, and designed for hybrid teams of AI and human developers, DevStar is the next‑generation intelligent platform built for the AI era.
@@ -19,7 +21,7 @@ This project has been
| Feature Type | Capabilities | License | Pricing Model |
|-------------|-------------|---------|--------------|
| **Core Features** | ✅ Git Repository Hosting ✅ Issues & Pull Requests ✅ Wiki & Project Boards ✅ Built-in CI/CD (GitHub Actions Compatible) ✅ Granular Permissions ✅ User & Organization Management ✅ Multi-Package Registry ✅ REST API ✅ Multi-DB Support / Lightweight Deployment | MIT License | Free & Open Source |
-| **Enhanced Features** | ✅ Built-in DevContainer Environment ✅ Built-in MCP Server ✅ Built-in AI Assistant ✅ Integration with AI CLI Tools (Claude Code/OpenCode/etc.) ✅ Integration with AI IDEs (Copilot/Cursor/Trae/etc.) ✅ One-click Actions Runner Deployment ✅ Online CI/CD Script Debugging ✅ Project Template Ecosystem (Best Practice Templates) | Commercial License | **Personal Use:** Free Forever (Non-commercial) **Enterprise Use:** Annual License ✅ Standard: CNY 1,888/user/year (Human or AI) ✅ Self-Report Discount: CNY 188/user/year (90% off) ✅ First-Year Trial: CNY 1.88/user |
+| **Enhanced Features** | ✅ Full-process AI-native support for R&D, including AI Issues, AI Actions, AI Coding, AI Code Review, AI Testing, etc. ✅ Built-in Agent orchestration solution (Agent Team) ✅ One-click deployment of mainstream LLMs ✅ Built-in MCP server ✅ Built-in AI-powered Chatbot ✅ Customizable integration with AI CLI tools such as Claude Code, Codex, OpenCode, etc. ✅ Customizable integration with AI IDEs such as VS Code, Cursor, Trae, etc. ✅ One-click deployment of Actions Runner (GitHub Actions-compatible) and online CI script debugging ✅ Built-in DevContainer Environment ✅ Project Template Ecosystem (Best Practice Templates) | Commercial License | **Personal Use:** Free Forever (Non-commercial) **Enterprise Use:** Annual License ✅ Standard: CNY 1,888/user/year (Human or AI) ✅ Self-Report Discount: CNY 188/user/year (90% off) ✅ First-Year Trial: CNY 1.88/user |
## Quick Start
@@ -30,7 +32,7 @@ devstar start # Run command to deploy DevStar Studio
For online demonstrations, you can visit [DevStar.cn](https://DevStar.cn).
-You can find comprehensive documentation on our official [documentation website](https://mengning.com.cn).
+You can find comprehensive documentation on our official [documentation website](https://github.com/mengning/DevStar/wiki).
## Building
@@ -134,9 +136,7 @@ In the [release log](https://github.com/go-gitea/gitea/releases) or the [change
## License
-This project is licensed under the MIT License.
-See the [LICENSE](https://github.com/go-gitea/gitea/blob/main/LICENSE) file
-for the full license text.
+this project is licensed under the MIT License. The project name DevStar, together with the registered trademark and official domain devstar.cn, constitutes its brand identity. Derivative works are not permitted to use the same or similar names without permission, in order to avoid public confusion.
## Further information
diff --git a/README.zh-cn.md b/README.zh-cn.md
index dda84d1582..426a9bd3fc 100644
--- a/README.zh-cn.md
+++ b/README.zh-cn.md
@@ -1,6 +1,8 @@
# DevStar
-AI 赋能研发的“最后一公里”。让一切皆可编程。
+DevStar AI 2.0 Agent Teams: Empowering innovators to make the world better.
+
+The Last Mile of Al for R&D. Make it possible to code everything.
DevStar 提供真正 AI 原生的全栈研发生态,专为 AI 与人类开发者组成的混合团队设计,是面向 AI 时代打造的新一代智能平台。
@@ -14,7 +16,7 @@ DevStar 是 Gitea 的商业发行版。由于 [Gitea](https://github.com/go-gite
| 功能类型 | 能力 | 许可证 | 定价模式 |
| :--- | :--- | :--- | :--- |
| **核心功能** | ✅ Git 仓库托管 ✅ 议题与拉取请求 ✅ Wiki 与项目看板 ✅ 内置 CI/CD(兼容 GitHub Actions) ✅ 细粒度权限控制 ✅ 用户与组织管理 ✅ 多包注册表 ✅ REST API ✅ 多数据库支持 / 轻量级部署 | MIT 许可证 | 免费开源 |
-| **增强功能** | ✅ 内置 DevContainer 环境 ✅ 内置 MCP 服务器 ✅ 内置 AI 助手 ✅ 集成 AI CLI 工具(Claude Code/OpenCode 等) ✅ 集成 AI IDE(Copilot/Cursor/Trae 等) ✅ 一键部署 Actions Runner ✅ 在线调试 CI/CD 脚本 ✅ 项目模板生态(最佳实践模板) | 商业许可证 | **个人使用:** 永久免费(非商业用途) **企业使用:** 年度许可 ✅ 标准版:CNY 1,888/用户/年(人类或 AI 用户) ✅ 自主申报折扣:CNY 188/用户/年(9折优惠) ✅ 首年试用:CNY 1.88/用户 |
+| **增强功能** | ✅ 研发全流程智能原生支持,如AI Issues、AI Actions、AI Coding、AI Code Review、AI Testing等 ✅ 内置Agent 编排解决方案(Agent Team) ✅ 一键部署主流LLM大模型 ✅ 内置 MCP 服务器 ✅ 内置 AI 助手Chatbot ✅ 自定义集成 AI CLI 工具Claude Code、Codex、OpenCode 等 ✅ 自定义集成 AI IDE如VS Code、Cursor、Trae 等 ✅ 一键部署 Actions Runner (Github Actions兼容)及在线调试 CI脚本 ✅ 内置 DevContainer 环境 ✅ 项目模板生态(最佳实践模板) | 商业许可证 | **个人使用:** 永久免费(非商业用途) **企业使用:** 年度许可 ✅ 标准版:CNY 1,888/用户/年(人类或 AI 用户) ✅ 自主申报折扣:CNY 188/用户/年(1折优惠) ✅ 首年试用:CNY 1.88/用户 |
## 快速开始
@@ -25,7 +27,7 @@ devstar start # 运行命令部署 DevStar Studio
如需在线演示,请访问 [DevStar.cn](https://DevStar.cn)。
-你可以在我们的官方 [文档网站](https://mengning.com.cn) 找到完整文档。
+你可以在我们的官方 [文档网站](https://github.com/mengning/DevStar/wiki) 找到完整文档。
## 构建
@@ -40,7 +42,7 @@ devstar start # 运行命令部署 DevStar Studio
`build` 目标分为两个子目标:
- `make backend` 需要 [Go Stable](https://go.dev/dl/),所需版本在 [go.mod](/go.mod) 中定义。
-- `make frontend` 需要 [Node.js LTS](https://nodejs.org/en/download/) 或更高版本。
+- `make frontend` 需要 [Node.js LTS](https://nodejs.org/en/download/) 或更高版本以及 [pnpm](https://pnpm.io/installation)。
需要互联网连接来下载 go 和 npm 模块。从包含预构建前端文件的官方源代码压缩包构建时,不会触发 `frontend` 目标,因此可以在没有 Node.js 的情况下构建。
@@ -129,8 +131,7 @@ Gitea 的发音是 [/ɡɪ’ti:/](https://youtu.be/EM71-2uDAoY),就像 "gi-tea
## 许可证
-这个项目是根据 MIT 许可证授权的。
-请参阅 [LICENSE](https://github.com/go-gitea/gitea/blob/main/LICENSE) 文件以获取完整的许可证文本。
+这个项目是根据 MIT 许可证授权的。项目名称DevStar与已注册相关商标及官方域名devstar.cn共同构成品牌标识,未经许可,衍生产品不得使用相同或近似名称,以免造成公众混淆。翻译成英语
## 进一步信息
diff --git a/README.zh-tw.md b/README.zh-tw.md
index 9371e4e95c..aee4074dc2 100644
--- a/README.zh-tw.md
+++ b/README.zh-tw.md
@@ -1,6 +1,8 @@
# DevStar
-AI 赋能研发的“最后一公里”。让一切皆可编程。
+DevStar AI 2.0 Agent Teams: Empowering innovators to make the world better.
+
+The Last Mile of Al for R&D. Make it possible to code everything.
DevStar 提供真正 AI 原生的全栈研发生态,专为 AI 与人类开发者组成的混合团队设计,是面向 AI 时代打造的新一代智能平台。
@@ -14,7 +16,7 @@ DevStar 是 Gitea 的商业发行版。由于 [Gitea](https://github.com/go-gite
| 功能类型 | 能力 | 许可证 | 定价模式 |
| :--- | :--- | :--- | :--- |
| **核心功能** | ✅ Git 仓库托管 ✅ 议题与拉取请求 ✅ Wiki 与项目看板 ✅ 内置 CI/CD(兼容 GitHub Actions) ✅ 细粒度权限控制 ✅ 用户与组织管理 ✅ 多包注册表 ✅ REST API ✅ 多数据库支持 / 轻量级部署 | MIT 许可证 | 免费开源 |
-| **增强功能** | ✅ 内置 DevContainer 环境 ✅ 内置 MCP 服务器 ✅ 内置 AI 助手 ✅ 集成 AI CLI 工具(Claude Code/OpenCode 等) ✅ 集成 AI IDE(Copilot/Cursor/Trae 等) ✅ 一键部署 Actions Runner ✅ 在线调试 CI/CD 脚本 ✅ 项目模板生态(最佳实践模板) | 商业许可证 | **个人使用:** 永久免费(非商业用途) **企业使用:** 年度许可 ✅ 标准版:CNY 1,888/用户/年(人类或 AI 用户) ✅ 自主申报折扣:CNY 188/用户/年(9折优惠) ✅ 首年试用:CNY 1.88/用户 |
+| **增强功能** | ✅ 研发全流程智能原生支持,如AI Issues、AI Actions、AI Coding、AI Code Review、AI Testing等 ✅ 内置Agent 编排解决方案(Agent Team) ✅ 一键部署主流LLM大模型 ✅ 内置 MCP 服务器 ✅ 内置 AI 助手Chatbot ✅ 自定义集成 AI CLI 工具Claude Code、Codex、OpenCode 等 ✅ 自定义集成 AI IDE如VS Code、Cursor、Trae 等 ✅ 一键部署 Actions Runner (Github Actions兼容)及在线调试 CI脚本 ✅ 内置 DevContainer 环境 ✅ 项目模板生态(最佳实践模板) | 商业许可证 | **个人使用:** 永久免费(非商业用途) **企业使用:** 年度许可 ✅ 标准版:CNY 1,888/用户/年(人类或 AI 用户) ✅ 自主申报折扣:CNY 188/用户/年(1折优惠) ✅ 首年试用:CNY 1.88/用户 |
## 快速开始
@@ -25,7 +27,7 @@ devstar start # 运行命令部署 DevStar Studio
如需在线演示,请访问 [DevStar.cn](https://DevStar.cn)。
-你可以在我们的官方 [文档网站](https://mengning.com.cn) 找到完整文档。
+你可以在我们的官方 [文档网站](https://github.com/mengning/DevStar/wiki) 找到完整文档。
## 構建
@@ -40,7 +42,7 @@ devstar start # 运行命令部署 DevStar Studio
`build` 目標分為兩個子目標:
- `make backend` 需要 [Go Stable](https://go.dev/dl/),所需版本在 [go.mod](/go.mod) 中定義。
-- `make frontend` 需要 [Node.js LTS](https://nodejs.org/en/download/) 或更高版本。
+- `make frontend` 需要 [Node.js LTS](https://nodejs.org/en/download/) 或更高版本以及 [pnpm](https://pnpm.io/installation)。
需要互聯網連接來下載 go 和 npm 模塊。從包含預構建前端文件的官方源代碼壓縮包構建時,不會觸發 `frontend` 目標,因此可以在沒有 Node.js 的情況下構建。
@@ -130,7 +132,7 @@ Gitea 的發音是 [/ɡɪ’ti:/](https://youtu.be/EM71-2uDAoY),就像 "gi-tea
## 許可證
這個項目是根據 MIT 許可證授權的。
-請參閱 [LICENSE](https://github.com/go-gitea/gitea/blob/main/LICENSE) 文件以獲取完整的許可證文本。
+项目名称DevStar与已注册相关商标及官方域名devstar.cn共同构成品牌标识,未经许可,衍生产品不得使用相同或近似名称,以免造成公众混淆。翻译成英语
## 進一步信息
diff --git a/SECURITY.md b/SECURITY.md
index d7c27ea613..212579a278 100644
--- a/SECURITY.md
+++ b/SECURITY.md
@@ -1,85 +1,13 @@
# Reporting security issues
-The Gitea maintainers take security seriously.
+The DevStar maintainers take security seriously.
If you discover a security issue, please bring it to their attention right away!
-Previous vulnerabilities are listed at https://about.gitea.com/security.
-
## Reporting a Vulnerability
-Please **DO NOT** file a public issue, instead send your report privately to `security@gitea.io`.
+Please **DO NOT** file a public issue, instead send your report privately to `contact@mengning.com.cn`.
## Protecting Security Information
-Due to the sensitive nature of security information, you can use the below GPG public key to encrypt your mail body.
-
-The PGP key is valid until July 4, 2026.
-
-```
-Key ID: 6FCD2D5B
-Key Type: RSA
-Expires: 7/4/2026
-Key Size: 4096/4096
-Fingerprint: 3DE0 3D1E 144A 7F06 9359 99DC AAFD 2381 6FCD 2D5B
-```
-
-UserID: Gitea Security
-
-```
------BEGIN PGP PUBLIC KEY BLOCK-----
-
-mQINBGK1Z/4BEADFMqXA9DeeChmSxUjF0Be5sq99ZUhgrZjcN/wOzz0wuCJZC0l8
-4uC+d6mfv7JpJYlzYzOK97/x5UguKHkYNZ6mm1G9KHaXmoIBDLKDzfPdJopVNv2r
-OajijaE0uMCnMjadlg5pbhMLRQG8a9J32yyaz7ZEAw72Ab31fvvcA53NkuqO4j2w
-k7dtFQzhbNOYV0VffQT90WDZdalYHB1JHyEQ+70U9OjVD5ggNYSzX98Eu3Hjn7V7
-kqFrcAxr5TE1elf0IXJcuBJtFzQSTUGlQldKOHtGTGgGjj9r/FFAE5ioBgVD05bV
-rEEgIMM/GqYaG/nbNpWE6P3mEc2Mnn3pZaRJL0LuF26TLjnqEcMMDp5iIhLdFzXR
-3tMdtKgQFu+Mtzs3ipwWARYgHyU09RJsI2HeBx7RmZO/Xqrec763Z7zdJ7SpCn0Z
-q+pHZl24JYR0Kf3T/ZiOC0cGd2QJqpJtg5J6S/OqfX9NH6MsCczO8pUC1N/aHH2X
-CTme2nF56izORqDWKoiICteL3GpYsCV9nyCidcCmoQsS+DKvE86YhIhVIVWGRY2F
-lzpAjnN9/KLtQroutrm+Ft0mdjDiJUeFVl1cOHDhoyfCsQh62HumoyZoZvqzQd6e
-AbN11nq6aViMe2Q3je1AbiBnRnQSHxt1Tc8X4IshO3MQK1Sk7oPI6LA5oQARAQAB
-tCJHaXRlYSBTZWN1cml0eSA8c2VjdXJpdHlAZ2l0ZWEuaW8+iQJXBBMBCABBAhsD
-BQsJCAcCAiICBhUKCQgLAgQWAgMBAh4HAheAFiEEPeA9HhRKfwaTWZncqv0jgW/N
-LVsFAmhoHmkFCQeT6esACgkQqv0jgW/NLVuFLRAAmjBQSKRAgs2bFIEj7HLAbDp4
-f+XkdH+GsT3jRPOZ9QZgmtM+TfoE4yNgIVfOl+s4RdjM/W4QzqZuPQ55hbEHd056
-cJmm7B+6GsHFcdrPmh65sOCEIyh4+t45dUfeWpFsDPqm9j1UHXAJQIpB8vDEVAPH
-t+3wLCk8GMPJs1o5tIyMmaO23ngvkwn8eG7KgY+rp2PzObrb5g7ppci0ILzILkrp
-HVjZsEfUWRgSVF7LuU5ppqDKrlcqwUpQq6n3kGMZcLrCp6ACKP04TBmTfUxNwdL7
-I0N7apI2Pbct9T1Gv/lYAUFWyU2c3gh/EBLbO6BukaLOFRQHrtNfdJV/YnMPlcXr
-LUJjK9K4eAH9DsrZqrisz/LthsC2BaNIN3KRMTk5YTYgmIh8GXzSgihORmtDFELC
-RroID3pTuS0zjXh+wpY9GuPTh7UW23p42Daxca4fAT4k5EclvDRUrL21xMopPMiL
-HuNdELz4FVchRTy05PjzKVyjVInDNojE2KUxnjxZDzYJ6aT/g+coD5yfntYm8BEj
-+ZzL0ndZES54hzKLpv7zwBQwFzam68clZYmDPILOPTflQDfpGEWmJK4undFU5obz
-ZsQRz0R3ulspChATbZxO0d5LX2obLpKO9X3b5VoO1KF+R8Vjw1Y0KxrNZ6rIcfqH
-Z50QVQKSe9dm08K0ON+5Ag0EYrVn/gEQALrFLQjCR3GjuHSindz0rd3Fnx/t7Sen
-T+p07yCSSoSlmnJHCQmwh4vfg1blyz0zZ4vkIhtpHsEgc+ZAG+WQXSsJ2iRz+eSN
-GwoOQl4XC3n+QWkc1ws+btr48+6UqXIQU+F8TPQyx/PIgi2nZXJB7f5+mjCqsk46
-XvH4nTr4kJjuqMSR/++wvre2qNQRa/q/dTsK0OaN/mJsdX6Oi+aGNaQJUhIG7F+E
-ZDMkn/O6xnwWNzy/+bpg43qH/Gk0eakOmz5NmQLRkV58SZLiJvuCUtkttf6CyhnX
-03OcWaajv5W8qA39dBYQgDrrPbBWUnwfO3yMveqhwV4JjDoe8sPAyn1NwzakNYqP
-RzsWyLrLS7R7J9s3FkZXhQw/QQcsaSMcGNQO047dm1P83N8JY5aEpiRo9zSWjoiw
-qoExANj5lUTZPe8M50lI182FrcjAN7dClO3QI6pg7wy0erMxfFly3j8UQ91ysS9T
-s+GsP9I3cmWWQcKYxWHtE8xTXnNCVPFZQj2nwhJzae8ypfOtulBRA3dUKWGKuDH/
-axFENhUsT397aOU3qkP/od4a64JyNIEo4CTTSPVeWd7njsGqli2U3A4xL2CcyYvt
-D/MWcMBGEoLSNTswwKdom4FaJpn5KThnK/T0bQcmJblJhoCtppXisbexZnCpuS0x
-Zdlm2T14KJ3LABEBAAGJAjwEGAEIACYCGwwWIQQ94D0eFEp/BpNZmdyq/SOBb80t
-WwUCaGgeJAUJB5PppgAKCRCq/SOBb80tW/NWEACB6Jrf0gWlk7e+hNCdnbM0ZVWU
-f2sHNFfXxxsdhpcDgKbNHtkZb8nZgv8AX+5fTtUwMVa3vKcdw30xFiIM5N7cCIPV
-vg/5z5BtfEaitnabEUG2iiVDIy8IHXIcK10rX+7BosA3QDl2PsiBHwyi5G13lRk8
-zGTSNDuOalug33h5/lr2dPigamkq74Aoy29q8Rjad6GfWHipL2bFimgtY+Zdi0BH
-NLk4EJXxj1SgVx5dtkQzWJReBA5M+FQ4QYQZBO+f4TDoOLmjui152uhkoLBQbGAa
-WWJFTVxm0bG5MXloEL3gA8DfU7XDwuW/sHJC5pBko8RpQViooOhckMepZV3Y83DK
-bwLYa3JmPgj2rEv4993dvrJbQhpGd082HOxOsllCs8pgNq1SnXpWYfcGTgGKC3ts
-U8YZUUJUQ7mi2L8Tv3ix20c9EiGmA30JAmA8eZTC3cWup91ZkkVBFRml2czTXajd
-RWZ6GbHV5503ueDQcB8yBVgF3CSixs67+dGSbD3p86OqGrjAcJzM5TFbNKcnGLdE
-kGbZpNwAISy750lXzXKmyrh5RTCeTOQerbwCMBvHZO+HAevA/LXDTw2OAiSIQlP5
-sYA4sFYLQ30OAkgJcmdp/pSgVj/erNtSN07ClrOpDb/uFpQymO6K2h0Pst3feNVK
-9M2VbqL9C51z/wyHLg==
-=SfZA
------END PGP PUBLIC KEY BLOCK-----
-
-```
-
Security reports are greatly appreciated and we will publicly thank you for it, although we keep your name confidential if you request it.
diff --git a/assets/emoji.json b/assets/emoji.json
index 28244caa65..2d6329e44f 100644
--- a/assets/emoji.json
+++ b/assets/emoji.json
@@ -1 +1,11483 @@
-[{"emoji":"👍","aliases":["+1","thumbsup"]},{"emoji":"👎","aliases":["-1","thumbsdown"]},{"emoji":"💯","aliases":["100"]},{"emoji":"🔢","aliases":["1234"]},{"emoji":"🥇","aliases":["1st_place_medal"]},{"emoji":"🥈","aliases":["2nd_place_medal"]},{"emoji":"🥉","aliases":["3rd_place_medal"]},{"emoji":"🎱","aliases":["8ball"]},{"emoji":"🅰️","aliases":["a"]},{"emoji":"🆎","aliases":["ab"]},{"emoji":"🧮","aliases":["abacus"]},{"emoji":"🔤","aliases":["abc"]},{"emoji":"🔡","aliases":["abcd"]},{"emoji":"🉑","aliases":["accept"]},{"emoji":"🪗","aliases":["accordion"]},{"emoji":"🩹","aliases":["adhesive_bandage"]},{"emoji":"🧑","aliases":["adult"]},{"emoji":"🚡","aliases":["aerial_tramway"]},{"emoji":"🇦🇫","aliases":["afghanistan"]},{"emoji":"✈️","aliases":["airplane"]},{"emoji":"🇦🇽","aliases":["aland_islands"]},{"emoji":"⏰","aliases":["alarm_clock"]},{"emoji":"🇦🇱","aliases":["albania"]},{"emoji":"⚗️","aliases":["alembic"]},{"emoji":"🇩🇿","aliases":["algeria"]},{"emoji":"👽","aliases":["alien"]},{"emoji":"🚑","aliases":["ambulance"]},{"emoji":"🇦🇸","aliases":["american_samoa"]},{"emoji":"🏺","aliases":["amphora"]},{"emoji":"🫀","aliases":["anatomical_heart"]},{"emoji":"⚓","aliases":["anchor"]},{"emoji":"🇦🇩","aliases":["andorra"]},{"emoji":"👼","aliases":["angel"]},{"emoji":"💢","aliases":["anger"]},{"emoji":"🇦🇴","aliases":["angola"]},{"emoji":"😠","aliases":["angry"]},{"emoji":"🇦🇮","aliases":["anguilla"]},{"emoji":"😧","aliases":["anguished"]},{"emoji":"🐜","aliases":["ant"]},{"emoji":"🇦🇶","aliases":["antarctica"]},{"emoji":"🇦🇬","aliases":["antigua_barbuda"]},{"emoji":"🍎","aliases":["apple"]},{"emoji":"♒","aliases":["aquarius"]},{"emoji":"🇦🇷","aliases":["argentina"]},{"emoji":"♈","aliases":["aries"]},{"emoji":"🇦🇲","aliases":["armenia"]},{"emoji":"◀️","aliases":["arrow_backward"]},{"emoji":"⏬","aliases":["arrow_double_down"]},{"emoji":"⏫","aliases":["arrow_double_up"]},{"emoji":"⬇️","aliases":["arrow_down"]},{"emoji":"🔽","aliases":["arrow_down_small"]},{"emoji":"▶️","aliases":["arrow_forward"]},{"emoji":"⤵️","aliases":["arrow_heading_down"]},{"emoji":"⤴️","aliases":["arrow_heading_up"]},{"emoji":"⬅️","aliases":["arrow_left"]},{"emoji":"↙️","aliases":["arrow_lower_left"]},{"emoji":"↘️","aliases":["arrow_lower_right"]},{"emoji":"➡️","aliases":["arrow_right"]},{"emoji":"↪️","aliases":["arrow_right_hook"]},{"emoji":"⬆️","aliases":["arrow_up"]},{"emoji":"↕️","aliases":["arrow_up_down"]},{"emoji":"🔼","aliases":["arrow_up_small"]},{"emoji":"↖️","aliases":["arrow_upper_left"]},{"emoji":"↗️","aliases":["arrow_upper_right"]},{"emoji":"🔃","aliases":["arrows_clockwise"]},{"emoji":"🔄","aliases":["arrows_counterclockwise"]},{"emoji":"🎨","aliases":["art"]},{"emoji":"🚛","aliases":["articulated_lorry"]},{"emoji":"🛰️","aliases":["artificial_satellite"]},{"emoji":"🧑🎨","aliases":["artist"]},{"emoji":"🇦🇼","aliases":["aruba"]},{"emoji":"🇦🇨","aliases":["ascension_island"]},{"emoji":"*️⃣","aliases":["asterisk"]},{"emoji":"😲","aliases":["astonished"]},{"emoji":"🧑🚀","aliases":["astronaut"]},{"emoji":"👟","aliases":["athletic_shoe"]},{"emoji":"🏧","aliases":["atm"]},{"emoji":"⚛️","aliases":["atom_symbol"]},{"emoji":"🇦🇺","aliases":["australia"]},{"emoji":"🇦🇹","aliases":["austria"]},{"emoji":"🛺","aliases":["auto_rickshaw"]},{"emoji":"🥑","aliases":["avocado"]},{"emoji":"🪓","aliases":["axe"]},{"emoji":"🇦🇿","aliases":["azerbaijan"]},{"emoji":"🅱️","aliases":["b"]},{"emoji":"👶","aliases":["baby"]},{"emoji":"🍼","aliases":["baby_bottle"]},{"emoji":"🐤","aliases":["baby_chick"]},{"emoji":"🚼","aliases":["baby_symbol"]},{"emoji":"🔙","aliases":["back"]},{"emoji":"🥓","aliases":["bacon"]},{"emoji":"🦡","aliases":["badger"]},{"emoji":"🏸","aliases":["badminton"]},{"emoji":"🥯","aliases":["bagel"]},{"emoji":"🛄","aliases":["baggage_claim"]},{"emoji":"🥖","aliases":["baguette_bread"]},{"emoji":"🇧🇸","aliases":["bahamas"]},{"emoji":"🇧🇭","aliases":["bahrain"]},{"emoji":"⚖️","aliases":["balance_scale"]},{"emoji":"👨🦲","aliases":["bald_man"]},{"emoji":"👩🦲","aliases":["bald_woman"]},{"emoji":"🩰","aliases":["ballet_shoes"]},{"emoji":"🎈","aliases":["balloon"]},{"emoji":"🗳️","aliases":["ballot_box"]},{"emoji":"☑️","aliases":["ballot_box_with_check"]},{"emoji":"🎍","aliases":["bamboo"]},{"emoji":"🍌","aliases":["banana"]},{"emoji":"‼️","aliases":["bangbang"]},{"emoji":"🇧🇩","aliases":["bangladesh"]},{"emoji":"🪕","aliases":["banjo"]},{"emoji":"🏦","aliases":["bank"]},{"emoji":"📊","aliases":["bar_chart"]},{"emoji":"🇧🇧","aliases":["barbados"]},{"emoji":"💈","aliases":["barber"]},{"emoji":"⚾","aliases":["baseball"]},{"emoji":"🧺","aliases":["basket"]},{"emoji":"🏀","aliases":["basketball"]},{"emoji":"🦇","aliases":["bat"]},{"emoji":"🛀","aliases":["bath"]},{"emoji":"🛁","aliases":["bathtub"]},{"emoji":"🔋","aliases":["battery"]},{"emoji":"🏖️","aliases":["beach_umbrella"]},{"emoji":"🫘","aliases":["beans"]},{"emoji":"🐻","aliases":["bear"]},{"emoji":"🧔","aliases":["bearded_person"]},{"emoji":"🦫","aliases":["beaver"]},{"emoji":"🛏️","aliases":["bed"]},{"emoji":"🐝","aliases":["bee","honeybee"]},{"emoji":"🍺","aliases":["beer"]},{"emoji":"🍻","aliases":["beers"]},{"emoji":"🪲","aliases":["beetle"]},{"emoji":"🔰","aliases":["beginner"]},{"emoji":"🇧🇾","aliases":["belarus"]},{"emoji":"🇧🇪","aliases":["belgium"]},{"emoji":"🇧🇿","aliases":["belize"]},{"emoji":"🔔","aliases":["bell"]},{"emoji":"🫑","aliases":["bell_pepper"]},{"emoji":"🛎️","aliases":["bellhop_bell"]},{"emoji":"🇧🇯","aliases":["benin"]},{"emoji":"🍱","aliases":["bento"]},{"emoji":"🇧🇲","aliases":["bermuda"]},{"emoji":"🧃","aliases":["beverage_box"]},{"emoji":"🇧🇹","aliases":["bhutan"]},{"emoji":"🚴","aliases":["bicyclist"]},{"emoji":"🚲","aliases":["bike"]},{"emoji":"🚴♂️","aliases":["biking_man"]},{"emoji":"🚴♀️","aliases":["biking_woman"]},{"emoji":"👙","aliases":["bikini"]},{"emoji":"🧢","aliases":["billed_cap"]},{"emoji":"☣️","aliases":["biohazard"]},{"emoji":"🐦","aliases":["bird"]},{"emoji":"🎂","aliases":["birthday"]},{"emoji":"🦬","aliases":["bison"]},{"emoji":"🫦","aliases":["biting_lip"]},{"emoji":"🐦⬛","aliases":["black_bird"]},{"emoji":"🐈⬛","aliases":["black_cat"]},{"emoji":"⚫","aliases":["black_circle"]},{"emoji":"🏴","aliases":["black_flag"]},{"emoji":"🖤","aliases":["black_heart"]},{"emoji":"🃏","aliases":["black_joker"]},{"emoji":"⬛","aliases":["black_large_square"]},{"emoji":"◾","aliases":["black_medium_small_square"]},{"emoji":"◼️","aliases":["black_medium_square"]},{"emoji":"✒️","aliases":["black_nib"]},{"emoji":"▪️","aliases":["black_small_square"]},{"emoji":"🔲","aliases":["black_square_button"]},{"emoji":"👱♂️","aliases":["blond_haired_man"]},{"emoji":"👱","aliases":["blond_haired_person"]},{"emoji":"👱♀️","aliases":["blond_haired_woman","blonde_woman"]},{"emoji":"🌼","aliases":["blossom"]},{"emoji":"🐡","aliases":["blowfish"]},{"emoji":"📘","aliases":["blue_book"]},{"emoji":"🚙","aliases":["blue_car"]},{"emoji":"💙","aliases":["blue_heart"]},{"emoji":"🟦","aliases":["blue_square"]},{"emoji":"🫐","aliases":["blueberries"]},{"emoji":"😊","aliases":["blush"]},{"emoji":"🐗","aliases":["boar"]},{"emoji":"⛵","aliases":["boat","sailboat"]},{"emoji":"🇧🇴","aliases":["bolivia"]},{"emoji":"💣","aliases":["bomb"]},{"emoji":"🦴","aliases":["bone"]},{"emoji":"📖","aliases":["book","open_book"]},{"emoji":"🔖","aliases":["bookmark"]},{"emoji":"📑","aliases":["bookmark_tabs"]},{"emoji":"📚","aliases":["books"]},{"emoji":"💥","aliases":["boom","collision"]},{"emoji":"🪃","aliases":["boomerang"]},{"emoji":"👢","aliases":["boot"]},{"emoji":"🇧🇦","aliases":["bosnia_herzegovina"]},{"emoji":"🇧🇼","aliases":["botswana"]},{"emoji":"⛹️♂️","aliases":["bouncing_ball_man","basketball_man"]},{"emoji":"⛹️","aliases":["bouncing_ball_person"]},{"emoji":"⛹️♀️","aliases":["bouncing_ball_woman","basketball_woman"]},{"emoji":"💐","aliases":["bouquet"]},{"emoji":"🇧🇻","aliases":["bouvet_island"]},{"emoji":"🙇","aliases":["bow"]},{"emoji":"🏹","aliases":["bow_and_arrow"]},{"emoji":"🙇♂️","aliases":["bowing_man"]},{"emoji":"🙇♀️","aliases":["bowing_woman"]},{"emoji":"🥣","aliases":["bowl_with_spoon"]},{"emoji":"🎳","aliases":["bowling"]},{"emoji":"🥊","aliases":["boxing_glove"]},{"emoji":"👦","aliases":["boy"]},{"emoji":"🧠","aliases":["brain"]},{"emoji":"🇧🇷","aliases":["brazil"]},{"emoji":"🍞","aliases":["bread"]},{"emoji":"🤱","aliases":["breast_feeding"]},{"emoji":"🧱","aliases":["bricks"]},{"emoji":"🌉","aliases":["bridge_at_night"]},{"emoji":"💼","aliases":["briefcase"]},{"emoji":"🇮🇴","aliases":["british_indian_ocean_territory"]},{"emoji":"🇻🇬","aliases":["british_virgin_islands"]},{"emoji":"🥦","aliases":["broccoli"]},{"emoji":"💔","aliases":["broken_heart"]},{"emoji":"🧹","aliases":["broom"]},{"emoji":"🟤","aliases":["brown_circle"]},{"emoji":"🤎","aliases":["brown_heart"]},{"emoji":"🟫","aliases":["brown_square"]},{"emoji":"🇧🇳","aliases":["brunei"]},{"emoji":"🧋","aliases":["bubble_tea"]},{"emoji":"🫧","aliases":["bubbles"]},{"emoji":"🪣","aliases":["bucket"]},{"emoji":"🐛","aliases":["bug"]},{"emoji":"🏗️","aliases":["building_construction"]},{"emoji":"💡","aliases":["bulb"]},{"emoji":"🇧🇬","aliases":["bulgaria"]},{"emoji":"🚅","aliases":["bullettrain_front"]},{"emoji":"🚄","aliases":["bullettrain_side"]},{"emoji":"🇧🇫","aliases":["burkina_faso"]},{"emoji":"🌯","aliases":["burrito"]},{"emoji":"🇧🇮","aliases":["burundi"]},{"emoji":"🚌","aliases":["bus"]},{"emoji":"🕴️","aliases":["business_suit_levitating"]},{"emoji":"🚏","aliases":["busstop"]},{"emoji":"👤","aliases":["bust_in_silhouette"]},{"emoji":"👥","aliases":["busts_in_silhouette"]},{"emoji":"🧈","aliases":["butter"]},{"emoji":"🦋","aliases":["butterfly"]},{"emoji":"🌵","aliases":["cactus"]},{"emoji":"🍰","aliases":["cake"]},{"emoji":"📆","aliases":["calendar"]},{"emoji":"🤙","aliases":["call_me_hand"]},{"emoji":"📲","aliases":["calling"]},{"emoji":"🇰🇭","aliases":["cambodia"]},{"emoji":"🐫","aliases":["camel"]},{"emoji":"📷","aliases":["camera"]},{"emoji":"📸","aliases":["camera_flash"]},{"emoji":"🇨🇲","aliases":["cameroon"]},{"emoji":"🏕️","aliases":["camping"]},{"emoji":"🇨🇦","aliases":["canada"]},{"emoji":"🇮🇨","aliases":["canary_islands"]},{"emoji":"♋","aliases":["cancer"]},{"emoji":"🕯️","aliases":["candle"]},{"emoji":"🍬","aliases":["candy"]},{"emoji":"🥫","aliases":["canned_food"]},{"emoji":"🛶","aliases":["canoe"]},{"emoji":"🇨🇻","aliases":["cape_verde"]},{"emoji":"🔠","aliases":["capital_abcd"]},{"emoji":"♑","aliases":["capricorn"]},{"emoji":"🚗","aliases":["car","red_car"]},{"emoji":"🗃️","aliases":["card_file_box"]},{"emoji":"📇","aliases":["card_index"]},{"emoji":"🗂️","aliases":["card_index_dividers"]},{"emoji":"🇧🇶","aliases":["caribbean_netherlands"]},{"emoji":"🎠","aliases":["carousel_horse"]},{"emoji":"🪚","aliases":["carpentry_saw"]},{"emoji":"🥕","aliases":["carrot"]},{"emoji":"🤸","aliases":["cartwheeling"]},{"emoji":"🐱","aliases":["cat"]},{"emoji":"🐈","aliases":["cat2"]},{"emoji":"🇰🇾","aliases":["cayman_islands"]},{"emoji":"💿","aliases":["cd"]},{"emoji":"🇨🇫","aliases":["central_african_republic"]},{"emoji":"🇪🇦","aliases":["ceuta_melilla"]},{"emoji":"🇹🇩","aliases":["chad"]},{"emoji":"⛓️","aliases":["chains"]},{"emoji":"🪑","aliases":["chair"]},{"emoji":"🍾","aliases":["champagne"]},{"emoji":"💹","aliases":["chart"]},{"emoji":"📉","aliases":["chart_with_downwards_trend"]},{"emoji":"📈","aliases":["chart_with_upwards_trend"]},{"emoji":"🏁","aliases":["checkered_flag"]},{"emoji":"🧀","aliases":["cheese"]},{"emoji":"🍒","aliases":["cherries"]},{"emoji":"🌸","aliases":["cherry_blossom"]},{"emoji":"♟️","aliases":["chess_pawn"]},{"emoji":"🌰","aliases":["chestnut"]},{"emoji":"🐔","aliases":["chicken"]},{"emoji":"🧒","aliases":["child"]},{"emoji":"🚸","aliases":["children_crossing"]},{"emoji":"🇨🇱","aliases":["chile"]},{"emoji":"🐿️","aliases":["chipmunk"]},{"emoji":"🍫","aliases":["chocolate_bar"]},{"emoji":"🥢","aliases":["chopsticks"]},{"emoji":"🇨🇽","aliases":["christmas_island"]},{"emoji":"🎄","aliases":["christmas_tree"]},{"emoji":"⛪","aliases":["church"]},{"emoji":"🎦","aliases":["cinema"]},{"emoji":"🎪","aliases":["circus_tent"]},{"emoji":"🌇","aliases":["city_sunrise"]},{"emoji":"🌆","aliases":["city_sunset"]},{"emoji":"🏙️","aliases":["cityscape"]},{"emoji":"🆑","aliases":["cl"]},{"emoji":"🗜️","aliases":["clamp"]},{"emoji":"👏","aliases":["clap"]},{"emoji":"🎬","aliases":["clapper"]},{"emoji":"🏛️","aliases":["classical_building"]},{"emoji":"🧗","aliases":["climbing"]},{"emoji":"🧗♂️","aliases":["climbing_man"]},{"emoji":"🧗♀️","aliases":["climbing_woman"]},{"emoji":"🥂","aliases":["clinking_glasses"]},{"emoji":"📋","aliases":["clipboard"]},{"emoji":"🇨🇵","aliases":["clipperton_island"]},{"emoji":"🕐","aliases":["clock1"]},{"emoji":"🕙","aliases":["clock10"]},{"emoji":"🕥","aliases":["clock1030"]},{"emoji":"🕚","aliases":["clock11"]},{"emoji":"🕦","aliases":["clock1130"]},{"emoji":"🕛","aliases":["clock12"]},{"emoji":"🕧","aliases":["clock1230"]},{"emoji":"🕜","aliases":["clock130"]},{"emoji":"🕑","aliases":["clock2"]},{"emoji":"🕝","aliases":["clock230"]},{"emoji":"🕒","aliases":["clock3"]},{"emoji":"🕞","aliases":["clock330"]},{"emoji":"🕓","aliases":["clock4"]},{"emoji":"🕟","aliases":["clock430"]},{"emoji":"🕔","aliases":["clock5"]},{"emoji":"🕠","aliases":["clock530"]},{"emoji":"🕕","aliases":["clock6"]},{"emoji":"🕡","aliases":["clock630"]},{"emoji":"🕖","aliases":["clock7"]},{"emoji":"🕢","aliases":["clock730"]},{"emoji":"🕗","aliases":["clock8"]},{"emoji":"🕣","aliases":["clock830"]},{"emoji":"🕘","aliases":["clock9"]},{"emoji":"🕤","aliases":["clock930"]},{"emoji":"📕","aliases":["closed_book"]},{"emoji":"🔐","aliases":["closed_lock_with_key"]},{"emoji":"🌂","aliases":["closed_umbrella"]},{"emoji":"☁️","aliases":["cloud"]},{"emoji":"🌩️","aliases":["cloud_with_lightning"]},{"emoji":"⛈️","aliases":["cloud_with_lightning_and_rain"]},{"emoji":"🌧️","aliases":["cloud_with_rain"]},{"emoji":"🌨️","aliases":["cloud_with_snow"]},{"emoji":"🤡","aliases":["clown_face"]},{"emoji":"♣️","aliases":["clubs"]},{"emoji":"🇨🇳","aliases":["cn"]},{"emoji":"🧥","aliases":["coat"]},{"emoji":"🪳","aliases":["cockroach"]},{"emoji":"🍸","aliases":["cocktail"]},{"emoji":"🥥","aliases":["coconut"]},{"emoji":"🇨🇨","aliases":["cocos_islands"]},{"emoji":"☕","aliases":["coffee"]},{"emoji":"⚰️","aliases":["coffin"]},{"emoji":"🪙","aliases":["coin"]},{"emoji":"🥶","aliases":["cold_face"]},{"emoji":"😰","aliases":["cold_sweat"]},{"emoji":"🇨🇴","aliases":["colombia"]},{"emoji":"☄️","aliases":["comet"]},{"emoji":"🇰🇲","aliases":["comoros"]},{"emoji":"🧭","aliases":["compass"]},{"emoji":"💻","aliases":["computer"]},{"emoji":"🖱️","aliases":["computer_mouse"]},{"emoji":"🎊","aliases":["confetti_ball"]},{"emoji":"😖","aliases":["confounded"]},{"emoji":"😕","aliases":["confused"]},{"emoji":"🇨🇬","aliases":["congo_brazzaville"]},{"emoji":"🇨🇩","aliases":["congo_kinshasa"]},{"emoji":"㊗️","aliases":["congratulations"]},{"emoji":"🚧","aliases":["construction"]},{"emoji":"👷","aliases":["construction_worker"]},{"emoji":"👷♂️","aliases":["construction_worker_man"]},{"emoji":"👷♀️","aliases":["construction_worker_woman"]},{"emoji":"🎛️","aliases":["control_knobs"]},{"emoji":"🏪","aliases":["convenience_store"]},{"emoji":"🧑🍳","aliases":["cook"]},{"emoji":"🇨🇰","aliases":["cook_islands"]},{"emoji":"🍪","aliases":["cookie"]},{"emoji":"🆒","aliases":["cool"]},{"emoji":"©️","aliases":["copyright"]},{"emoji":"🪸","aliases":["coral"]},{"emoji":"🌽","aliases":["corn"]},{"emoji":"🇨🇷","aliases":["costa_rica"]},{"emoji":"🇨🇮","aliases":["cote_divoire"]},{"emoji":"🛋️","aliases":["couch_and_lamp"]},{"emoji":"👫","aliases":["couple"]},{"emoji":"💑","aliases":["couple_with_heart"]},{"emoji":"👨❤️👨","aliases":["couple_with_heart_man_man"]},{"emoji":"👩❤️👨","aliases":["couple_with_heart_woman_man"]},{"emoji":"👩❤️👩","aliases":["couple_with_heart_woman_woman"]},{"emoji":"💏","aliases":["couplekiss"]},{"emoji":"👨❤️💋👨","aliases":["couplekiss_man_man"]},{"emoji":"👩❤️💋👨","aliases":["couplekiss_man_woman"]},{"emoji":"👩❤️💋👩","aliases":["couplekiss_woman_woman"]},{"emoji":"🐮","aliases":["cow"]},{"emoji":"🐄","aliases":["cow2"]},{"emoji":"🤠","aliases":["cowboy_hat_face"]},{"emoji":"🦀","aliases":["crab"]},{"emoji":"🖍️","aliases":["crayon"]},{"emoji":"💳","aliases":["credit_card"]},{"emoji":"🌙","aliases":["crescent_moon"]},{"emoji":"🦗","aliases":["cricket"]},{"emoji":"🏏","aliases":["cricket_game"]},{"emoji":"🇭🇷","aliases":["croatia"]},{"emoji":"🐊","aliases":["crocodile"]},{"emoji":"🥐","aliases":["croissant"]},{"emoji":"🤞","aliases":["crossed_fingers"]},{"emoji":"🎌","aliases":["crossed_flags"]},{"emoji":"⚔️","aliases":["crossed_swords"]},{"emoji":"👑","aliases":["crown"]},{"emoji":"🩼","aliases":["crutch"]},{"emoji":"😢","aliases":["cry"]},{"emoji":"😿","aliases":["crying_cat_face"]},{"emoji":"🔮","aliases":["crystal_ball"]},{"emoji":"🇨🇺","aliases":["cuba"]},{"emoji":"🥒","aliases":["cucumber"]},{"emoji":"🥤","aliases":["cup_with_straw"]},{"emoji":"🧁","aliases":["cupcake"]},{"emoji":"💘","aliases":["cupid"]},{"emoji":"🇨🇼","aliases":["curacao"]},{"emoji":"🥌","aliases":["curling_stone"]},{"emoji":"👨🦱","aliases":["curly_haired_man"]},{"emoji":"👩🦱","aliases":["curly_haired_woman"]},{"emoji":"➰","aliases":["curly_loop"]},{"emoji":"💱","aliases":["currency_exchange"]},{"emoji":"🍛","aliases":["curry"]},{"emoji":"🤬","aliases":["cursing_face"]},{"emoji":"🍮","aliases":["custard"]},{"emoji":"🛃","aliases":["customs"]},{"emoji":"🥩","aliases":["cut_of_meat"]},{"emoji":"🌀","aliases":["cyclone"]},{"emoji":"🇨🇾","aliases":["cyprus"]},{"emoji":"🇨🇿","aliases":["czech_republic"]},{"emoji":"🗡️","aliases":["dagger"]},{"emoji":"👯","aliases":["dancers"]},{"emoji":"👯♂️","aliases":["dancing_men"]},{"emoji":"👯♀️","aliases":["dancing_women"]},{"emoji":"🍡","aliases":["dango"]},{"emoji":"🕶️","aliases":["dark_sunglasses"]},{"emoji":"🎯","aliases":["dart"]},{"emoji":"💨","aliases":["dash"]},{"emoji":"📅","aliases":["date"]},{"emoji":"🇩🇪","aliases":["de"]},{"emoji":"🧏♂️","aliases":["deaf_man"]},{"emoji":"🧏","aliases":["deaf_person"]},{"emoji":"🧏♀️","aliases":["deaf_woman"]},{"emoji":"🌳","aliases":["deciduous_tree"]},{"emoji":"🦌","aliases":["deer"]},{"emoji":"🇩🇰","aliases":["denmark"]},{"emoji":"🏬","aliases":["department_store"]},{"emoji":"🏚️","aliases":["derelict_house"]},{"emoji":"🏜️","aliases":["desert"]},{"emoji":"🏝️","aliases":["desert_island"]},{"emoji":"🖥️","aliases":["desktop_computer"]},{"emoji":"🕵️","aliases":["detective"]},{"emoji":"💠","aliases":["diamond_shape_with_a_dot_inside"]},{"emoji":"♦️","aliases":["diamonds"]},{"emoji":"🇩🇬","aliases":["diego_garcia"]},{"emoji":"😞","aliases":["disappointed"]},{"emoji":"😥","aliases":["disappointed_relieved"]},{"emoji":"🥸","aliases":["disguised_face"]},{"emoji":"🤿","aliases":["diving_mask"]},{"emoji":"🪔","aliases":["diya_lamp"]},{"emoji":"💫","aliases":["dizzy"]},{"emoji":"😵","aliases":["dizzy_face"]},{"emoji":"🇩🇯","aliases":["djibouti"]},{"emoji":"🧬","aliases":["dna"]},{"emoji":"🚯","aliases":["do_not_litter"]},{"emoji":"🦤","aliases":["dodo"]},{"emoji":"🐶","aliases":["dog"]},{"emoji":"🐕","aliases":["dog2"]},{"emoji":"💵","aliases":["dollar"]},{"emoji":"🎎","aliases":["dolls"]},{"emoji":"🐬","aliases":["dolphin","flipper"]},{"emoji":"🇩🇲","aliases":["dominica"]},{"emoji":"🇩🇴","aliases":["dominican_republic"]},{"emoji":"🫏","aliases":["donkey"]},{"emoji":"🚪","aliases":["door"]},{"emoji":"🫥","aliases":["dotted_line_face"]},{"emoji":"🍩","aliases":["doughnut"]},{"emoji":"🕊️","aliases":["dove"]},{"emoji":"🐉","aliases":["dragon"]},{"emoji":"🐲","aliases":["dragon_face"]},{"emoji":"👗","aliases":["dress"]},{"emoji":"🐪","aliases":["dromedary_camel"]},{"emoji":"🤤","aliases":["drooling_face"]},{"emoji":"🩸","aliases":["drop_of_blood"]},{"emoji":"💧","aliases":["droplet"]},{"emoji":"🥁","aliases":["drum"]},{"emoji":"🦆","aliases":["duck"]},{"emoji":"🥟","aliases":["dumpling"]},{"emoji":"📀","aliases":["dvd"]},{"emoji":"🦅","aliases":["eagle"]},{"emoji":"👂","aliases":["ear"]},{"emoji":"🌾","aliases":["ear_of_rice"]},{"emoji":"🦻","aliases":["ear_with_hearing_aid"]},{"emoji":"🌍","aliases":["earth_africa"]},{"emoji":"🌎","aliases":["earth_americas"]},{"emoji":"🌏","aliases":["earth_asia"]},{"emoji":"🇪🇨","aliases":["ecuador"]},{"emoji":"🥚","aliases":["egg"]},{"emoji":"🍆","aliases":["eggplant"]},{"emoji":"🇪🇬","aliases":["egypt"]},{"emoji":"8️⃣","aliases":["eight"]},{"emoji":"✴️","aliases":["eight_pointed_black_star"]},{"emoji":"✳️","aliases":["eight_spoked_asterisk"]},{"emoji":"⏏️","aliases":["eject_button"]},{"emoji":"🇸🇻","aliases":["el_salvador"]},{"emoji":"🔌","aliases":["electric_plug"]},{"emoji":"🐘","aliases":["elephant"]},{"emoji":"🛗","aliases":["elevator"]},{"emoji":"🧝","aliases":["elf"]},{"emoji":"🧝♂️","aliases":["elf_man"]},{"emoji":"🧝♀️","aliases":["elf_woman"]},{"emoji":"📧","aliases":["email","e-mail"]},{"emoji":"🪹","aliases":["empty_nest"]},{"emoji":"🔚","aliases":["end"]},{"emoji":"🏴","aliases":["england"]},{"emoji":"✉️","aliases":["envelope"]},{"emoji":"📩","aliases":["envelope_with_arrow"]},{"emoji":"🇬🇶","aliases":["equatorial_guinea"]},{"emoji":"🇪🇷","aliases":["eritrea"]},{"emoji":"🇪🇸","aliases":["es"]},{"emoji":"🇪🇪","aliases":["estonia"]},{"emoji":"🇪🇹","aliases":["ethiopia"]},{"emoji":"🇪🇺","aliases":["eu","european_union"]},{"emoji":"💶","aliases":["euro"]},{"emoji":"🏰","aliases":["european_castle"]},{"emoji":"🏤","aliases":["european_post_office"]},{"emoji":"🌲","aliases":["evergreen_tree"]},{"emoji":"❗","aliases":["exclamation","heavy_exclamation_mark"]},{"emoji":"🤯","aliases":["exploding_head"]},{"emoji":"😑","aliases":["expressionless"]},{"emoji":"👁️","aliases":["eye"]},{"emoji":"👁️🗨️","aliases":["eye_speech_bubble"]},{"emoji":"👓","aliases":["eyeglasses"]},{"emoji":"👀","aliases":["eyes"]},{"emoji":"😮💨","aliases":["face_exhaling"]},{"emoji":"🥹","aliases":["face_holding_back_tears"]},{"emoji":"😶🌫️","aliases":["face_in_clouds"]},{"emoji":"🫤","aliases":["face_with_diagonal_mouth"]},{"emoji":"🤕","aliases":["face_with_head_bandage"]},{"emoji":"🫢","aliases":["face_with_open_eyes_and_hand_over_mouth"]},{"emoji":"🫣","aliases":["face_with_peeking_eye"]},{"emoji":"😵💫","aliases":["face_with_spiral_eyes"]},{"emoji":"🤒","aliases":["face_with_thermometer"]},{"emoji":"🤦","aliases":["facepalm"]},{"emoji":"🏭","aliases":["factory"]},{"emoji":"🧑🏭","aliases":["factory_worker"]},{"emoji":"🧚","aliases":["fairy"]},{"emoji":"🧚♂️","aliases":["fairy_man"]},{"emoji":"🧚♀️","aliases":["fairy_woman"]},{"emoji":"🧆","aliases":["falafel"]},{"emoji":"🇫🇰","aliases":["falkland_islands"]},{"emoji":"🍂","aliases":["fallen_leaf"]},{"emoji":"👪","aliases":["family"]},{"emoji":"👨👦","aliases":["family_man_boy"]},{"emoji":"👨👦👦","aliases":["family_man_boy_boy"]},{"emoji":"👨👧","aliases":["family_man_girl"]},{"emoji":"👨👧👦","aliases":["family_man_girl_boy"]},{"emoji":"👨👧👧","aliases":["family_man_girl_girl"]},{"emoji":"👨👨👦","aliases":["family_man_man_boy"]},{"emoji":"👨👨👦👦","aliases":["family_man_man_boy_boy"]},{"emoji":"👨👨👧","aliases":["family_man_man_girl"]},{"emoji":"👨👨👧👦","aliases":["family_man_man_girl_boy"]},{"emoji":"👨👨👧👧","aliases":["family_man_man_girl_girl"]},{"emoji":"👨👩👦","aliases":["family_man_woman_boy"]},{"emoji":"👨👩👦👦","aliases":["family_man_woman_boy_boy"]},{"emoji":"👨👩👧","aliases":["family_man_woman_girl"]},{"emoji":"👨👩👧👦","aliases":["family_man_woman_girl_boy"]},{"emoji":"👨👩👧👧","aliases":["family_man_woman_girl_girl"]},{"emoji":"👩👦","aliases":["family_woman_boy"]},{"emoji":"👩👦👦","aliases":["family_woman_boy_boy"]},{"emoji":"👩👧","aliases":["family_woman_girl"]},{"emoji":"👩👧👦","aliases":["family_woman_girl_boy"]},{"emoji":"👩👧👧","aliases":["family_woman_girl_girl"]},{"emoji":"👩👩👦","aliases":["family_woman_woman_boy"]},{"emoji":"👩👩👦👦","aliases":["family_woman_woman_boy_boy"]},{"emoji":"👩👩👧","aliases":["family_woman_woman_girl"]},{"emoji":"👩👩👧👦","aliases":["family_woman_woman_girl_boy"]},{"emoji":"👩👩👧👧","aliases":["family_woman_woman_girl_girl"]},{"emoji":"🧑🌾","aliases":["farmer"]},{"emoji":"🇫🇴","aliases":["faroe_islands"]},{"emoji":"⏩","aliases":["fast_forward"]},{"emoji":"📠","aliases":["fax"]},{"emoji":"😨","aliases":["fearful"]},{"emoji":"🪶","aliases":["feather"]},{"emoji":"🐾","aliases":["feet","paw_prints"]},{"emoji":"🕵️♀️","aliases":["female_detective"]},{"emoji":"♀️","aliases":["female_sign"]},{"emoji":"🎡","aliases":["ferris_wheel"]},{"emoji":"⛴️","aliases":["ferry"]},{"emoji":"🏑","aliases":["field_hockey"]},{"emoji":"🇫🇯","aliases":["fiji"]},{"emoji":"🗄️","aliases":["file_cabinet"]},{"emoji":"📁","aliases":["file_folder"]},{"emoji":"📽️","aliases":["film_projector"]},{"emoji":"🎞️","aliases":["film_strip"]},{"emoji":"🇫🇮","aliases":["finland"]},{"emoji":"🔥","aliases":["fire"]},{"emoji":"🚒","aliases":["fire_engine"]},{"emoji":"🧯","aliases":["fire_extinguisher"]},{"emoji":"🧨","aliases":["firecracker"]},{"emoji":"🧑🚒","aliases":["firefighter"]},{"emoji":"🎆","aliases":["fireworks"]},{"emoji":"🌓","aliases":["first_quarter_moon"]},{"emoji":"🌛","aliases":["first_quarter_moon_with_face"]},{"emoji":"🐟","aliases":["fish"]},{"emoji":"🍥","aliases":["fish_cake"]},{"emoji":"🎣","aliases":["fishing_pole_and_fish"]},{"emoji":"🤛","aliases":["fist_left"]},{"emoji":"👊","aliases":["fist_oncoming","facepunch","punch"]},{"emoji":"✊","aliases":["fist_raised","fist"]},{"emoji":"🤜","aliases":["fist_right"]},{"emoji":"5️⃣","aliases":["five"]},{"emoji":"🎏","aliases":["flags"]},{"emoji":"🦩","aliases":["flamingo"]},{"emoji":"🔦","aliases":["flashlight"]},{"emoji":"🥿","aliases":["flat_shoe"]},{"emoji":"🫓","aliases":["flatbread"]},{"emoji":"⚜️","aliases":["fleur_de_lis"]},{"emoji":"🛬","aliases":["flight_arrival"]},{"emoji":"🛫","aliases":["flight_departure"]},{"emoji":"💾","aliases":["floppy_disk"]},{"emoji":"🎴","aliases":["flower_playing_cards"]},{"emoji":"😳","aliases":["flushed"]},{"emoji":"🪈","aliases":["flute"]},{"emoji":"🪰","aliases":["fly"]},{"emoji":"🥏","aliases":["flying_disc"]},{"emoji":"🛸","aliases":["flying_saucer"]},{"emoji":"🌫️","aliases":["fog"]},{"emoji":"🌁","aliases":["foggy"]},{"emoji":"🪭","aliases":["folding_hand_fan"]},{"emoji":"🫕","aliases":["fondue"]},{"emoji":"🦶","aliases":["foot"]},{"emoji":"🏈","aliases":["football"]},{"emoji":"👣","aliases":["footprints"]},{"emoji":"🍴","aliases":["fork_and_knife"]},{"emoji":"🥠","aliases":["fortune_cookie"]},{"emoji":"⛲","aliases":["fountain"]},{"emoji":"🖋️","aliases":["fountain_pen"]},{"emoji":"4️⃣","aliases":["four"]},{"emoji":"🍀","aliases":["four_leaf_clover"]},{"emoji":"🦊","aliases":["fox_face"]},{"emoji":"🇫🇷","aliases":["fr"]},{"emoji":"🖼️","aliases":["framed_picture"]},{"emoji":"🆓","aliases":["free"]},{"emoji":"🇬🇫","aliases":["french_guiana"]},{"emoji":"🇵🇫","aliases":["french_polynesia"]},{"emoji":"🇹🇫","aliases":["french_southern_territories"]},{"emoji":"🍳","aliases":["fried_egg"]},{"emoji":"🍤","aliases":["fried_shrimp"]},{"emoji":"🍟","aliases":["fries"]},{"emoji":"🐸","aliases":["frog"]},{"emoji":"😦","aliases":["frowning"]},{"emoji":"☹️","aliases":["frowning_face"]},{"emoji":"🙍♂️","aliases":["frowning_man"]},{"emoji":"🙍","aliases":["frowning_person"]},{"emoji":"🙍♀️","aliases":["frowning_woman"]},{"emoji":"⛽","aliases":["fuelpump"]},{"emoji":"🌕","aliases":["full_moon"]},{"emoji":"🌝","aliases":["full_moon_with_face"]},{"emoji":"⚱️","aliases":["funeral_urn"]},{"emoji":"🇬🇦","aliases":["gabon"]},{"emoji":"🇬🇲","aliases":["gambia"]},{"emoji":"🎲","aliases":["game_die"]},{"emoji":"🧄","aliases":["garlic"]},{"emoji":"🇬🇧","aliases":["gb","uk"]},{"emoji":"⚙️","aliases":["gear"]},{"emoji":"💎","aliases":["gem"]},{"emoji":"♊","aliases":["gemini"]},{"emoji":"🧞","aliases":["genie"]},{"emoji":"🧞♂️","aliases":["genie_man"]},{"emoji":"🧞♀️","aliases":["genie_woman"]},{"emoji":"🇬🇪","aliases":["georgia"]},{"emoji":"🇬🇭","aliases":["ghana"]},{"emoji":"👻","aliases":["ghost"]},{"emoji":"🇬🇮","aliases":["gibraltar"]},{"emoji":"🎁","aliases":["gift"]},{"emoji":"💝","aliases":["gift_heart"]},{"emoji":"🫚","aliases":["ginger_root"]},{"emoji":"🦒","aliases":["giraffe"]},{"emoji":"👧","aliases":["girl"]},{"emoji":"🌐","aliases":["globe_with_meridians"]},{"emoji":"🧤","aliases":["gloves"]},{"emoji":"🥅","aliases":["goal_net"]},{"emoji":"🐐","aliases":["goat"]},{"emoji":"🥽","aliases":["goggles"]},{"emoji":"⛳","aliases":["golf"]},{"emoji":"🏌️","aliases":["golfing"]},{"emoji":"🏌️♂️","aliases":["golfing_man"]},{"emoji":"🏌️♀️","aliases":["golfing_woman"]},{"emoji":"🪿","aliases":["goose"]},{"emoji":"🦍","aliases":["gorilla"]},{"emoji":"🍇","aliases":["grapes"]},{"emoji":"🇬🇷","aliases":["greece"]},{"emoji":"🍏","aliases":["green_apple"]},{"emoji":"📗","aliases":["green_book"]},{"emoji":"🟢","aliases":["green_circle"]},{"emoji":"💚","aliases":["green_heart"]},{"emoji":"🥗","aliases":["green_salad"]},{"emoji":"🟩","aliases":["green_square"]},{"emoji":"🇬🇱","aliases":["greenland"]},{"emoji":"🇬🇩","aliases":["grenada"]},{"emoji":"❕","aliases":["grey_exclamation"]},{"emoji":"🩶","aliases":["grey_heart"]},{"emoji":"❔","aliases":["grey_question"]},{"emoji":"😬","aliases":["grimacing"]},{"emoji":"😁","aliases":["grin"]},{"emoji":"😀","aliases":["grinning"]},{"emoji":"🇬🇵","aliases":["guadeloupe"]},{"emoji":"🇬🇺","aliases":["guam"]},{"emoji":"💂","aliases":["guard"]},{"emoji":"💂♂️","aliases":["guardsman"]},{"emoji":"💂♀️","aliases":["guardswoman"]},{"emoji":"🇬🇹","aliases":["guatemala"]},{"emoji":"🇬🇬","aliases":["guernsey"]},{"emoji":"🦮","aliases":["guide_dog"]},{"emoji":"🇬🇳","aliases":["guinea"]},{"emoji":"🇬🇼","aliases":["guinea_bissau"]},{"emoji":"🎸","aliases":["guitar"]},{"emoji":"🔫","aliases":["gun"]},{"emoji":"🇬🇾","aliases":["guyana"]},{"emoji":"🪮","aliases":["hair_pick"]},{"emoji":"💇","aliases":["haircut"]},{"emoji":"💇♂️","aliases":["haircut_man"]},{"emoji":"💇♀️","aliases":["haircut_woman"]},{"emoji":"🇭🇹","aliases":["haiti"]},{"emoji":"🍔","aliases":["hamburger"]},{"emoji":"🔨","aliases":["hammer"]},{"emoji":"⚒️","aliases":["hammer_and_pick"]},{"emoji":"🛠️","aliases":["hammer_and_wrench"]},{"emoji":"🪬","aliases":["hamsa"]},{"emoji":"🐹","aliases":["hamster"]},{"emoji":"✋","aliases":["hand","raised_hand"]},{"emoji":"🤭","aliases":["hand_over_mouth"]},{"emoji":"🫰","aliases":["hand_with_index_finger_and_thumb_crossed"]},{"emoji":"👜","aliases":["handbag"]},{"emoji":"🤾","aliases":["handball_person"]},{"emoji":"🤝","aliases":["handshake"]},{"emoji":"💩","aliases":["hankey","poop","shit"]},{"emoji":"#️⃣","aliases":["hash"]},{"emoji":"🐥","aliases":["hatched_chick"]},{"emoji":"🐣","aliases":["hatching_chick"]},{"emoji":"🎧","aliases":["headphones"]},{"emoji":"🪦","aliases":["headstone"]},{"emoji":"🧑⚕️","aliases":["health_worker"]},{"emoji":"🙉","aliases":["hear_no_evil"]},{"emoji":"🇭🇲","aliases":["heard_mcdonald_islands"]},{"emoji":"❤️","aliases":["heart"]},{"emoji":"💟","aliases":["heart_decoration"]},{"emoji":"😍","aliases":["heart_eyes"]},{"emoji":"😻","aliases":["heart_eyes_cat"]},{"emoji":"🫶","aliases":["heart_hands"]},{"emoji":"❤️🔥","aliases":["heart_on_fire"]},{"emoji":"💓","aliases":["heartbeat"]},{"emoji":"💗","aliases":["heartpulse"]},{"emoji":"♥️","aliases":["hearts"]},{"emoji":"✔️","aliases":["heavy_check_mark"]},{"emoji":"➗","aliases":["heavy_division_sign"]},{"emoji":"💲","aliases":["heavy_dollar_sign"]},{"emoji":"🟰","aliases":["heavy_equals_sign"]},{"emoji":"❣️","aliases":["heavy_heart_exclamation"]},{"emoji":"➖","aliases":["heavy_minus_sign"]},{"emoji":"✖️","aliases":["heavy_multiplication_x"]},{"emoji":"➕","aliases":["heavy_plus_sign"]},{"emoji":"🦔","aliases":["hedgehog"]},{"emoji":"🚁","aliases":["helicopter"]},{"emoji":"🌿","aliases":["herb"]},{"emoji":"🌺","aliases":["hibiscus"]},{"emoji":"🔆","aliases":["high_brightness"]},{"emoji":"👠","aliases":["high_heel"]},{"emoji":"🥾","aliases":["hiking_boot"]},{"emoji":"🛕","aliases":["hindu_temple"]},{"emoji":"🦛","aliases":["hippopotamus"]},{"emoji":"🔪","aliases":["hocho","knife"]},{"emoji":"🕳️","aliases":["hole"]},{"emoji":"🇭🇳","aliases":["honduras"]},{"emoji":"🍯","aliases":["honey_pot"]},{"emoji":"🇭🇰","aliases":["hong_kong"]},{"emoji":"🪝","aliases":["hook"]},{"emoji":"🐴","aliases":["horse"]},{"emoji":"🏇","aliases":["horse_racing"]},{"emoji":"🏥","aliases":["hospital"]},{"emoji":"🥵","aliases":["hot_face"]},{"emoji":"🌶️","aliases":["hot_pepper"]},{"emoji":"🌭","aliases":["hotdog"]},{"emoji":"🏨","aliases":["hotel"]},{"emoji":"♨️","aliases":["hotsprings"]},{"emoji":"⌛","aliases":["hourglass"]},{"emoji":"⏳","aliases":["hourglass_flowing_sand"]},{"emoji":"🏠","aliases":["house"]},{"emoji":"🏡","aliases":["house_with_garden"]},{"emoji":"🏘️","aliases":["houses"]},{"emoji":"🤗","aliases":["hugs"]},{"emoji":"🇭🇺","aliases":["hungary"]},{"emoji":"😯","aliases":["hushed"]},{"emoji":"🛖","aliases":["hut"]},{"emoji":"🪻","aliases":["hyacinth"]},{"emoji":"🍨","aliases":["ice_cream"]},{"emoji":"🧊","aliases":["ice_cube"]},{"emoji":"🏒","aliases":["ice_hockey"]},{"emoji":"⛸️","aliases":["ice_skate"]},{"emoji":"🍦","aliases":["icecream"]},{"emoji":"🇮🇸","aliases":["iceland"]},{"emoji":"🆔","aliases":["id"]},{"emoji":"🪪","aliases":["identification_card"]},{"emoji":"🉐","aliases":["ideograph_advantage"]},{"emoji":"👿","aliases":["imp"]},{"emoji":"📥","aliases":["inbox_tray"]},{"emoji":"📨","aliases":["incoming_envelope"]},{"emoji":"🫵","aliases":["index_pointing_at_the_viewer"]},{"emoji":"🇮🇳","aliases":["india"]},{"emoji":"🇮🇩","aliases":["indonesia"]},{"emoji":"♾️","aliases":["infinity"]},{"emoji":"ℹ️","aliases":["information_source"]},{"emoji":"😇","aliases":["innocent"]},{"emoji":"⁉️","aliases":["interrobang"]},{"emoji":"📱","aliases":["iphone"]},{"emoji":"🇮🇷","aliases":["iran"]},{"emoji":"🇮🇶","aliases":["iraq"]},{"emoji":"🇮🇪","aliases":["ireland"]},{"emoji":"🇮🇲","aliases":["isle_of_man"]},{"emoji":"🇮🇱","aliases":["israel"]},{"emoji":"🇮🇹","aliases":["it"]},{"emoji":"🏮","aliases":["izakaya_lantern","lantern"]},{"emoji":"🎃","aliases":["jack_o_lantern"]},{"emoji":"🇯🇲","aliases":["jamaica"]},{"emoji":"🗾","aliases":["japan"]},{"emoji":"🏯","aliases":["japanese_castle"]},{"emoji":"👺","aliases":["japanese_goblin"]},{"emoji":"👹","aliases":["japanese_ogre"]},{"emoji":"🫙","aliases":["jar"]},{"emoji":"👖","aliases":["jeans"]},{"emoji":"🪼","aliases":["jellyfish"]},{"emoji":"🇯🇪","aliases":["jersey"]},{"emoji":"🧩","aliases":["jigsaw"]},{"emoji":"🇯🇴","aliases":["jordan"]},{"emoji":"😂","aliases":["joy"]},{"emoji":"😹","aliases":["joy_cat"]},{"emoji":"🕹️","aliases":["joystick"]},{"emoji":"🇯🇵","aliases":["jp"]},{"emoji":"🧑⚖️","aliases":["judge"]},{"emoji":"🤹","aliases":["juggling_person"]},{"emoji":"🕋","aliases":["kaaba"]},{"emoji":"🦘","aliases":["kangaroo"]},{"emoji":"🇰🇿","aliases":["kazakhstan"]},{"emoji":"🇰🇪","aliases":["kenya"]},{"emoji":"🔑","aliases":["key"]},{"emoji":"⌨️","aliases":["keyboard"]},{"emoji":"🔟","aliases":["keycap_ten"]},{"emoji":"🪯","aliases":["khanda"]},{"emoji":"🛴","aliases":["kick_scooter"]},{"emoji":"👘","aliases":["kimono"]},{"emoji":"🇰🇮","aliases":["kiribati"]},{"emoji":"💋","aliases":["kiss"]},{"emoji":"😗","aliases":["kissing"]},{"emoji":"😽","aliases":["kissing_cat"]},{"emoji":"😚","aliases":["kissing_closed_eyes"]},{"emoji":"😘","aliases":["kissing_heart"]},{"emoji":"😙","aliases":["kissing_smiling_eyes"]},{"emoji":"🪁","aliases":["kite"]},{"emoji":"🥝","aliases":["kiwi_fruit"]},{"emoji":"🧎♂️","aliases":["kneeling_man"]},{"emoji":"🧎","aliases":["kneeling_person"]},{"emoji":"🧎♀️","aliases":["kneeling_woman"]},{"emoji":"🪢","aliases":["knot"]},{"emoji":"🐨","aliases":["koala"]},{"emoji":"🈁","aliases":["koko"]},{"emoji":"🇽🇰","aliases":["kosovo"]},{"emoji":"🇰🇷","aliases":["kr"]},{"emoji":"🇰🇼","aliases":["kuwait"]},{"emoji":"🇰🇬","aliases":["kyrgyzstan"]},{"emoji":"🥼","aliases":["lab_coat"]},{"emoji":"🏷️","aliases":["label"]},{"emoji":"🥍","aliases":["lacrosse"]},{"emoji":"🪜","aliases":["ladder"]},{"emoji":"🐞","aliases":["lady_beetle"]},{"emoji":"🇱🇦","aliases":["laos"]},{"emoji":"🔵","aliases":["large_blue_circle"]},{"emoji":"🔷","aliases":["large_blue_diamond"]},{"emoji":"🔶","aliases":["large_orange_diamond"]},{"emoji":"🌗","aliases":["last_quarter_moon"]},{"emoji":"🌜","aliases":["last_quarter_moon_with_face"]},{"emoji":"✝️","aliases":["latin_cross"]},{"emoji":"🇱🇻","aliases":["latvia"]},{"emoji":"😆","aliases":["laughing","satisfied","laugh"]},{"emoji":"🥬","aliases":["leafy_green"]},{"emoji":"🍃","aliases":["leaves"]},{"emoji":"🇱🇧","aliases":["lebanon"]},{"emoji":"📒","aliases":["ledger"]},{"emoji":"🛅","aliases":["left_luggage"]},{"emoji":"↔️","aliases":["left_right_arrow"]},{"emoji":"🗨️","aliases":["left_speech_bubble"]},{"emoji":"↩️","aliases":["leftwards_arrow_with_hook"]},{"emoji":"🫲","aliases":["leftwards_hand"]},{"emoji":"🫷","aliases":["leftwards_pushing_hand"]},{"emoji":"🦵","aliases":["leg"]},{"emoji":"🍋","aliases":["lemon"]},{"emoji":"♌","aliases":["leo"]},{"emoji":"🐆","aliases":["leopard"]},{"emoji":"🇱🇸","aliases":["lesotho"]},{"emoji":"🎚️","aliases":["level_slider"]},{"emoji":"🇱🇷","aliases":["liberia"]},{"emoji":"♎","aliases":["libra"]},{"emoji":"🇱🇾","aliases":["libya"]},{"emoji":"🇱🇮","aliases":["liechtenstein"]},{"emoji":"🩵","aliases":["light_blue_heart"]},{"emoji":"🚈","aliases":["light_rail"]},{"emoji":"🔗","aliases":["link"]},{"emoji":"🦁","aliases":["lion"]},{"emoji":"👄","aliases":["lips"]},{"emoji":"💄","aliases":["lipstick"]},{"emoji":"🇱🇹","aliases":["lithuania"]},{"emoji":"🦎","aliases":["lizard"]},{"emoji":"🦙","aliases":["llama"]},{"emoji":"🦞","aliases":["lobster"]},{"emoji":"🔒","aliases":["lock"]},{"emoji":"🔏","aliases":["lock_with_ink_pen"]},{"emoji":"🍭","aliases":["lollipop"]},{"emoji":"🪘","aliases":["long_drum"]},{"emoji":"➿","aliases":["loop"]},{"emoji":"🧴","aliases":["lotion_bottle"]},{"emoji":"🪷","aliases":["lotus"]},{"emoji":"🧘","aliases":["lotus_position"]},{"emoji":"🧘♂️","aliases":["lotus_position_man"]},{"emoji":"🧘♀️","aliases":["lotus_position_woman"]},{"emoji":"🔊","aliases":["loud_sound"]},{"emoji":"📢","aliases":["loudspeaker"]},{"emoji":"🏩","aliases":["love_hotel"]},{"emoji":"💌","aliases":["love_letter"]},{"emoji":"🤟","aliases":["love_you_gesture"]},{"emoji":"🪫","aliases":["low_battery"]},{"emoji":"🔅","aliases":["low_brightness"]},{"emoji":"🧳","aliases":["luggage"]},{"emoji":"🫁","aliases":["lungs"]},{"emoji":"🇱🇺","aliases":["luxembourg"]},{"emoji":"🤥","aliases":["lying_face"]},{"emoji":"Ⓜ️","aliases":["m"]},{"emoji":"🇲🇴","aliases":["macau"]},{"emoji":"🇲🇰","aliases":["macedonia"]},{"emoji":"🇲🇬","aliases":["madagascar"]},{"emoji":"🔍","aliases":["mag"]},{"emoji":"🔎","aliases":["mag_right"]},{"emoji":"🧙","aliases":["mage"]},{"emoji":"🧙♂️","aliases":["mage_man"]},{"emoji":"🧙♀️","aliases":["mage_woman"]},{"emoji":"🪄","aliases":["magic_wand"]},{"emoji":"🧲","aliases":["magnet"]},{"emoji":"🀄","aliases":["mahjong"]},{"emoji":"📫","aliases":["mailbox"]},{"emoji":"📪","aliases":["mailbox_closed"]},{"emoji":"📬","aliases":["mailbox_with_mail"]},{"emoji":"📭","aliases":["mailbox_with_no_mail"]},{"emoji":"🇲🇼","aliases":["malawi"]},{"emoji":"🇲🇾","aliases":["malaysia"]},{"emoji":"🇲🇻","aliases":["maldives"]},{"emoji":"🕵️♂️","aliases":["male_detective"]},{"emoji":"♂️","aliases":["male_sign"]},{"emoji":"🇲🇱","aliases":["mali"]},{"emoji":"🇲🇹","aliases":["malta"]},{"emoji":"🦣","aliases":["mammoth"]},{"emoji":"👨","aliases":["man"]},{"emoji":"👨🎨","aliases":["man_artist"]},{"emoji":"👨🚀","aliases":["man_astronaut"]},{"emoji":"🧔♂️","aliases":["man_beard"]},{"emoji":"🤸♂️","aliases":["man_cartwheeling"]},{"emoji":"👨🍳","aliases":["man_cook"]},{"emoji":"🕺","aliases":["man_dancing"]},{"emoji":"🤦♂️","aliases":["man_facepalming"]},{"emoji":"👨🏭","aliases":["man_factory_worker"]},{"emoji":"👨🌾","aliases":["man_farmer"]},{"emoji":"👨🍼","aliases":["man_feeding_baby"]},{"emoji":"👨🚒","aliases":["man_firefighter"]},{"emoji":"👨⚕️","aliases":["man_health_worker"]},{"emoji":"👨🦽","aliases":["man_in_manual_wheelchair"]},{"emoji":"👨🦼","aliases":["man_in_motorized_wheelchair"]},{"emoji":"🤵♂️","aliases":["man_in_tuxedo"]},{"emoji":"👨⚖️","aliases":["man_judge"]},{"emoji":"🤹♂️","aliases":["man_juggling"]},{"emoji":"👨🔧","aliases":["man_mechanic"]},{"emoji":"👨💼","aliases":["man_office_worker"]},{"emoji":"👨✈️","aliases":["man_pilot"]},{"emoji":"🤾♂️","aliases":["man_playing_handball"]},{"emoji":"🤽♂️","aliases":["man_playing_water_polo"]},{"emoji":"👨🔬","aliases":["man_scientist"]},{"emoji":"🤷♂️","aliases":["man_shrugging"]},{"emoji":"👨🎤","aliases":["man_singer"]},{"emoji":"👨🎓","aliases":["man_student"]},{"emoji":"👨🏫","aliases":["man_teacher"]},{"emoji":"👨💻","aliases":["man_technologist"]},{"emoji":"👲","aliases":["man_with_gua_pi_mao"]},{"emoji":"👨🦯","aliases":["man_with_probing_cane"]},{"emoji":"👳♂️","aliases":["man_with_turban"]},{"emoji":"👰♂️","aliases":["man_with_veil"]},{"emoji":"🥭","aliases":["mango"]},{"emoji":"👞","aliases":["mans_shoe","shoe"]},{"emoji":"🕰️","aliases":["mantelpiece_clock"]},{"emoji":"🦽","aliases":["manual_wheelchair"]},{"emoji":"🍁","aliases":["maple_leaf"]},{"emoji":"🪇","aliases":["maracas"]},{"emoji":"🇲🇭","aliases":["marshall_islands"]},{"emoji":"🥋","aliases":["martial_arts_uniform"]},{"emoji":"🇲🇶","aliases":["martinique"]},{"emoji":"😷","aliases":["mask"]},{"emoji":"💆","aliases":["massage"]},{"emoji":"💆♂️","aliases":["massage_man"]},{"emoji":"💆♀️","aliases":["massage_woman"]},{"emoji":"🧉","aliases":["mate"]},{"emoji":"🇲🇷","aliases":["mauritania"]},{"emoji":"🇲🇺","aliases":["mauritius"]},{"emoji":"🇾🇹","aliases":["mayotte"]},{"emoji":"🍖","aliases":["meat_on_bone"]},{"emoji":"🧑🔧","aliases":["mechanic"]},{"emoji":"🦾","aliases":["mechanical_arm"]},{"emoji":"🦿","aliases":["mechanical_leg"]},{"emoji":"🎖️","aliases":["medal_military"]},{"emoji":"🏅","aliases":["medal_sports"]},{"emoji":"⚕️","aliases":["medical_symbol"]},{"emoji":"📣","aliases":["mega"]},{"emoji":"🍈","aliases":["melon"]},{"emoji":"🫠","aliases":["melting_face"]},{"emoji":"📝","aliases":["memo","pencil"]},{"emoji":"🤼♂️","aliases":["men_wrestling"]},{"emoji":"❤️🩹","aliases":["mending_heart"]},{"emoji":"🕎","aliases":["menorah"]},{"emoji":"🚹","aliases":["mens"]},{"emoji":"🧜♀️","aliases":["mermaid"]},{"emoji":"🧜♂️","aliases":["merman"]},{"emoji":"🧜","aliases":["merperson"]},{"emoji":"🤘","aliases":["metal"]},{"emoji":"🚇","aliases":["metro"]},{"emoji":"🇲🇽","aliases":["mexico"]},{"emoji":"🦠","aliases":["microbe"]},{"emoji":"🇫🇲","aliases":["micronesia"]},{"emoji":"🎤","aliases":["microphone"]},{"emoji":"🔬","aliases":["microscope"]},{"emoji":"🖕","aliases":["middle_finger","fu"]},{"emoji":"🪖","aliases":["military_helmet"]},{"emoji":"🥛","aliases":["milk_glass"]},{"emoji":"🌌","aliases":["milky_way"]},{"emoji":"🚐","aliases":["minibus"]},{"emoji":"💽","aliases":["minidisc"]},{"emoji":"🪞","aliases":["mirror"]},{"emoji":"🪩","aliases":["mirror_ball"]},{"emoji":"📴","aliases":["mobile_phone_off"]},{"emoji":"🇲🇩","aliases":["moldova"]},{"emoji":"🇲🇨","aliases":["monaco"]},{"emoji":"🤑","aliases":["money_mouth_face"]},{"emoji":"💸","aliases":["money_with_wings"]},{"emoji":"💰","aliases":["moneybag"]},{"emoji":"🇲🇳","aliases":["mongolia"]},{"emoji":"🐒","aliases":["monkey"]},{"emoji":"🐵","aliases":["monkey_face"]},{"emoji":"🧐","aliases":["monocle_face"]},{"emoji":"🚝","aliases":["monorail"]},{"emoji":"🇲🇪","aliases":["montenegro"]},{"emoji":"🇲🇸","aliases":["montserrat"]},{"emoji":"🌔","aliases":["moon","waxing_gibbous_moon"]},{"emoji":"🥮","aliases":["moon_cake"]},{"emoji":"🫎","aliases":["moose"]},{"emoji":"🇲🇦","aliases":["morocco"]},{"emoji":"🎓","aliases":["mortar_board"]},{"emoji":"🕌","aliases":["mosque"]},{"emoji":"🦟","aliases":["mosquito"]},{"emoji":"🛥️","aliases":["motor_boat"]},{"emoji":"🛵","aliases":["motor_scooter"]},{"emoji":"🏍️","aliases":["motorcycle"]},{"emoji":"🦼","aliases":["motorized_wheelchair"]},{"emoji":"🛣️","aliases":["motorway"]},{"emoji":"🗻","aliases":["mount_fuji"]},{"emoji":"⛰️","aliases":["mountain"]},{"emoji":"🚵","aliases":["mountain_bicyclist"]},{"emoji":"🚵♂️","aliases":["mountain_biking_man"]},{"emoji":"🚵♀️","aliases":["mountain_biking_woman"]},{"emoji":"🚠","aliases":["mountain_cableway"]},{"emoji":"🚞","aliases":["mountain_railway"]},{"emoji":"🏔️","aliases":["mountain_snow"]},{"emoji":"🐭","aliases":["mouse"]},{"emoji":"🐁","aliases":["mouse2"]},{"emoji":"🪤","aliases":["mouse_trap"]},{"emoji":"🎥","aliases":["movie_camera"]},{"emoji":"🗿","aliases":["moyai"]},{"emoji":"🇲🇿","aliases":["mozambique"]},{"emoji":"🤶","aliases":["mrs_claus"]},{"emoji":"💪","aliases":["muscle"]},{"emoji":"🍄","aliases":["mushroom"]},{"emoji":"🎹","aliases":["musical_keyboard"]},{"emoji":"🎵","aliases":["musical_note"]},{"emoji":"🎼","aliases":["musical_score"]},{"emoji":"🔇","aliases":["mute"]},{"emoji":"🧑🎄","aliases":["mx_claus"]},{"emoji":"🇲🇲","aliases":["myanmar"]},{"emoji":"💅","aliases":["nail_care"]},{"emoji":"📛","aliases":["name_badge"]},{"emoji":"🇳🇦","aliases":["namibia"]},{"emoji":"🏞️","aliases":["national_park"]},{"emoji":"🇳🇷","aliases":["nauru"]},{"emoji":"🤢","aliases":["nauseated_face"]},{"emoji":"🧿","aliases":["nazar_amulet"]},{"emoji":"👔","aliases":["necktie"]},{"emoji":"❎","aliases":["negative_squared_cross_mark"]},{"emoji":"🇳🇵","aliases":["nepal"]},{"emoji":"🤓","aliases":["nerd_face"]},{"emoji":"🪺","aliases":["nest_with_eggs"]},{"emoji":"🪆","aliases":["nesting_dolls"]},{"emoji":"🇳🇱","aliases":["netherlands"]},{"emoji":"😐","aliases":["neutral_face"]},{"emoji":"🆕","aliases":["new"]},{"emoji":"🇳🇨","aliases":["new_caledonia"]},{"emoji":"🌑","aliases":["new_moon"]},{"emoji":"🌚","aliases":["new_moon_with_face"]},{"emoji":"🇳🇿","aliases":["new_zealand"]},{"emoji":"📰","aliases":["newspaper"]},{"emoji":"🗞️","aliases":["newspaper_roll"]},{"emoji":"⏭️","aliases":["next_track_button"]},{"emoji":"🆖","aliases":["ng"]},{"emoji":"🇳🇮","aliases":["nicaragua"]},{"emoji":"🇳🇪","aliases":["niger"]},{"emoji":"🇳🇬","aliases":["nigeria"]},{"emoji":"🌃","aliases":["night_with_stars"]},{"emoji":"9️⃣","aliases":["nine"]},{"emoji":"🥷","aliases":["ninja"]},{"emoji":"🇳🇺","aliases":["niue"]},{"emoji":"🔕","aliases":["no_bell"]},{"emoji":"🚳","aliases":["no_bicycles"]},{"emoji":"⛔","aliases":["no_entry"]},{"emoji":"🚫","aliases":["no_entry_sign"]},{"emoji":"🙅","aliases":["no_good"]},{"emoji":"🙅♂️","aliases":["no_good_man","ng_man"]},{"emoji":"🙅♀️","aliases":["no_good_woman","ng_woman"]},{"emoji":"📵","aliases":["no_mobile_phones"]},{"emoji":"😶","aliases":["no_mouth"]},{"emoji":"🚷","aliases":["no_pedestrians"]},{"emoji":"🚭","aliases":["no_smoking"]},{"emoji":"🚱","aliases":["non-potable_water"]},{"emoji":"🇳🇫","aliases":["norfolk_island"]},{"emoji":"🇰🇵","aliases":["north_korea"]},{"emoji":"🇲🇵","aliases":["northern_mariana_islands"]},{"emoji":"🇳🇴","aliases":["norway"]},{"emoji":"👃","aliases":["nose"]},{"emoji":"📓","aliases":["notebook"]},{"emoji":"📔","aliases":["notebook_with_decorative_cover"]},{"emoji":"🎶","aliases":["notes"]},{"emoji":"🔩","aliases":["nut_and_bolt"]},{"emoji":"⭕","aliases":["o"]},{"emoji":"🅾️","aliases":["o2"]},{"emoji":"🌊","aliases":["ocean"]},{"emoji":"🐙","aliases":["octopus"]},{"emoji":"🍢","aliases":["oden"]},{"emoji":"🏢","aliases":["office"]},{"emoji":"🧑💼","aliases":["office_worker"]},{"emoji":"🛢️","aliases":["oil_drum"]},{"emoji":"🆗","aliases":["ok"]},{"emoji":"👌","aliases":["ok_hand"]},{"emoji":"🙆♂️","aliases":["ok_man"]},{"emoji":"🙆","aliases":["ok_person"]},{"emoji":"🙆♀️","aliases":["ok_woman"]},{"emoji":"🗝️","aliases":["old_key"]},{"emoji":"🧓","aliases":["older_adult"]},{"emoji":"👴","aliases":["older_man"]},{"emoji":"👵","aliases":["older_woman"]},{"emoji":"🫒","aliases":["olive"]},{"emoji":"🕉️","aliases":["om"]},{"emoji":"🇴🇲","aliases":["oman"]},{"emoji":"🔛","aliases":["on"]},{"emoji":"🚘","aliases":["oncoming_automobile"]},{"emoji":"🚍","aliases":["oncoming_bus"]},{"emoji":"🚔","aliases":["oncoming_police_car"]},{"emoji":"🚖","aliases":["oncoming_taxi"]},{"emoji":"1️⃣","aliases":["one"]},{"emoji":"🩱","aliases":["one_piece_swimsuit"]},{"emoji":"🧅","aliases":["onion"]},{"emoji":"📂","aliases":["open_file_folder"]},{"emoji":"👐","aliases":["open_hands"]},{"emoji":"😮","aliases":["open_mouth"]},{"emoji":"☂️","aliases":["open_umbrella"]},{"emoji":"⛎","aliases":["ophiuchus"]},{"emoji":"📙","aliases":["orange_book"]},{"emoji":"🟠","aliases":["orange_circle"]},{"emoji":"🧡","aliases":["orange_heart"]},{"emoji":"🟧","aliases":["orange_square"]},{"emoji":"🦧","aliases":["orangutan"]},{"emoji":"☦️","aliases":["orthodox_cross"]},{"emoji":"🦦","aliases":["otter"]},{"emoji":"📤","aliases":["outbox_tray"]},{"emoji":"🦉","aliases":["owl"]},{"emoji":"🐂","aliases":["ox"]},{"emoji":"🦪","aliases":["oyster"]},{"emoji":"📦","aliases":["package"]},{"emoji":"📄","aliases":["page_facing_up"]},{"emoji":"📃","aliases":["page_with_curl"]},{"emoji":"📟","aliases":["pager"]},{"emoji":"🖌️","aliases":["paintbrush"]},{"emoji":"🇵🇰","aliases":["pakistan"]},{"emoji":"🇵🇼","aliases":["palau"]},{"emoji":"🇵🇸","aliases":["palestinian_territories"]},{"emoji":"🫳","aliases":["palm_down_hand"]},{"emoji":"🌴","aliases":["palm_tree"]},{"emoji":"🫴","aliases":["palm_up_hand"]},{"emoji":"🤲","aliases":["palms_up_together"]},{"emoji":"🇵🇦","aliases":["panama"]},{"emoji":"🥞","aliases":["pancakes"]},{"emoji":"🐼","aliases":["panda_face"]},{"emoji":"📎","aliases":["paperclip"]},{"emoji":"🖇️","aliases":["paperclips"]},{"emoji":"🇵🇬","aliases":["papua_new_guinea"]},{"emoji":"🪂","aliases":["parachute"]},{"emoji":"🇵🇾","aliases":["paraguay"]},{"emoji":"⛱️","aliases":["parasol_on_ground"]},{"emoji":"🅿️","aliases":["parking"]},{"emoji":"🦜","aliases":["parrot"]},{"emoji":"〽️","aliases":["part_alternation_mark"]},{"emoji":"⛅","aliases":["partly_sunny"]},{"emoji":"🥳","aliases":["partying_face"]},{"emoji":"🛳️","aliases":["passenger_ship"]},{"emoji":"🛂","aliases":["passport_control"]},{"emoji":"⏸️","aliases":["pause_button"]},{"emoji":"🫛","aliases":["pea_pod"]},{"emoji":"☮️","aliases":["peace_symbol"]},{"emoji":"🍑","aliases":["peach"]},{"emoji":"🦚","aliases":["peacock"]},{"emoji":"🥜","aliases":["peanuts"]},{"emoji":"🍐","aliases":["pear"]},{"emoji":"🖊️","aliases":["pen"]},{"emoji":"✏️","aliases":["pencil2"]},{"emoji":"🐧","aliases":["penguin"]},{"emoji":"😔","aliases":["pensive"]},{"emoji":"🧑🤝🧑","aliases":["people_holding_hands"]},{"emoji":"🫂","aliases":["people_hugging"]},{"emoji":"🎭","aliases":["performing_arts"]},{"emoji":"😣","aliases":["persevere"]},{"emoji":"🧑🦲","aliases":["person_bald"]},{"emoji":"🧑🦱","aliases":["person_curly_hair"]},{"emoji":"🧑🍼","aliases":["person_feeding_baby"]},{"emoji":"🤺","aliases":["person_fencing"]},{"emoji":"🧑🦽","aliases":["person_in_manual_wheelchair"]},{"emoji":"🧑🦼","aliases":["person_in_motorized_wheelchair"]},{"emoji":"🤵","aliases":["person_in_tuxedo"]},{"emoji":"🧑🦰","aliases":["person_red_hair"]},{"emoji":"🧑🦳","aliases":["person_white_hair"]},{"emoji":"🫅","aliases":["person_with_crown"]},{"emoji":"🧑🦯","aliases":["person_with_probing_cane"]},{"emoji":"👳","aliases":["person_with_turban"]},{"emoji":"👰","aliases":["person_with_veil"]},{"emoji":"🇵🇪","aliases":["peru"]},{"emoji":"🧫","aliases":["petri_dish"]},{"emoji":"🇵🇭","aliases":["philippines"]},{"emoji":"☎️","aliases":["phone","telephone"]},{"emoji":"⛏️","aliases":["pick"]},{"emoji":"🛻","aliases":["pickup_truck"]},{"emoji":"🥧","aliases":["pie"]},{"emoji":"🐷","aliases":["pig"]},{"emoji":"🐖","aliases":["pig2"]},{"emoji":"🐽","aliases":["pig_nose"]},{"emoji":"💊","aliases":["pill"]},{"emoji":"🧑✈️","aliases":["pilot"]},{"emoji":"🪅","aliases":["pinata"]},{"emoji":"🤌","aliases":["pinched_fingers"]},{"emoji":"🤏","aliases":["pinching_hand"]},{"emoji":"🍍","aliases":["pineapple"]},{"emoji":"🏓","aliases":["ping_pong"]},{"emoji":"🩷","aliases":["pink_heart"]},{"emoji":"🏴☠️","aliases":["pirate_flag"]},{"emoji":"♓","aliases":["pisces"]},{"emoji":"🇵🇳","aliases":["pitcairn_islands"]},{"emoji":"🍕","aliases":["pizza"]},{"emoji":"🪧","aliases":["placard"]},{"emoji":"🛐","aliases":["place_of_worship"]},{"emoji":"🍽️","aliases":["plate_with_cutlery"]},{"emoji":"⏯️","aliases":["play_or_pause_button"]},{"emoji":"🛝","aliases":["playground_slide"]},{"emoji":"🥺","aliases":["pleading_face"]},{"emoji":"🪠","aliases":["plunger"]},{"emoji":"👇","aliases":["point_down"]},{"emoji":"👈","aliases":["point_left"]},{"emoji":"👉","aliases":["point_right"]},{"emoji":"☝️","aliases":["point_up"]},{"emoji":"👆","aliases":["point_up_2"]},{"emoji":"🇵🇱","aliases":["poland"]},{"emoji":"🐻❄️","aliases":["polar_bear"]},{"emoji":"🚓","aliases":["police_car"]},{"emoji":"👮","aliases":["police_officer","cop"]},{"emoji":"👮♂️","aliases":["policeman"]},{"emoji":"👮♀️","aliases":["policewoman"]},{"emoji":"🐩","aliases":["poodle"]},{"emoji":"🍿","aliases":["popcorn"]},{"emoji":"🇵🇹","aliases":["portugal"]},{"emoji":"🏣","aliases":["post_office"]},{"emoji":"📯","aliases":["postal_horn"]},{"emoji":"📮","aliases":["postbox"]},{"emoji":"🚰","aliases":["potable_water"]},{"emoji":"🥔","aliases":["potato"]},{"emoji":"🪴","aliases":["potted_plant"]},{"emoji":"👝","aliases":["pouch"]},{"emoji":"🍗","aliases":["poultry_leg"]},{"emoji":"💷","aliases":["pound"]},{"emoji":"🫗","aliases":["pouring_liquid"]},{"emoji":"😾","aliases":["pouting_cat"]},{"emoji":"🙎","aliases":["pouting_face"]},{"emoji":"🙎♂️","aliases":["pouting_man"]},{"emoji":"🙎♀️","aliases":["pouting_woman"]},{"emoji":"🙏","aliases":["pray"]},{"emoji":"📿","aliases":["prayer_beads"]},{"emoji":"🫃","aliases":["pregnant_man"]},{"emoji":"🫄","aliases":["pregnant_person"]},{"emoji":"🤰","aliases":["pregnant_woman"]},{"emoji":"🥨","aliases":["pretzel"]},{"emoji":"⏮️","aliases":["previous_track_button"]},{"emoji":"🤴","aliases":["prince"]},{"emoji":"👸","aliases":["princess"]},{"emoji":"🖨️","aliases":["printer"]},{"emoji":"🦯","aliases":["probing_cane"]},{"emoji":"🇵🇷","aliases":["puerto_rico"]},{"emoji":"🟣","aliases":["purple_circle"]},{"emoji":"💜","aliases":["purple_heart"]},{"emoji":"🟪","aliases":["purple_square"]},{"emoji":"👛","aliases":["purse"]},{"emoji":"📌","aliases":["pushpin"]},{"emoji":"🚮","aliases":["put_litter_in_its_place"]},{"emoji":"🇶🇦","aliases":["qatar"]},{"emoji":"❓","aliases":["question"]},{"emoji":"🐰","aliases":["rabbit"]},{"emoji":"🐇","aliases":["rabbit2"]},{"emoji":"🦝","aliases":["raccoon"]},{"emoji":"🐎","aliases":["racehorse"]},{"emoji":"🏎️","aliases":["racing_car"]},{"emoji":"📻","aliases":["radio"]},{"emoji":"🔘","aliases":["radio_button"]},{"emoji":"☢️","aliases":["radioactive"]},{"emoji":"😡","aliases":["rage","pout"]},{"emoji":"🚃","aliases":["railway_car"]},{"emoji":"🛤️","aliases":["railway_track"]},{"emoji":"🌈","aliases":["rainbow"]},{"emoji":"🏳️🌈","aliases":["rainbow_flag"]},{"emoji":"🤚","aliases":["raised_back_of_hand"]},{"emoji":"🤨","aliases":["raised_eyebrow"]},{"emoji":"🖐️","aliases":["raised_hand_with_fingers_splayed"]},{"emoji":"🙌","aliases":["raised_hands"]},{"emoji":"🙋","aliases":["raising_hand"]},{"emoji":"🙋♂️","aliases":["raising_hand_man"]},{"emoji":"🙋♀️","aliases":["raising_hand_woman"]},{"emoji":"🐏","aliases":["ram"]},{"emoji":"🍜","aliases":["ramen"]},{"emoji":"🐀","aliases":["rat"]},{"emoji":"🪒","aliases":["razor"]},{"emoji":"🧾","aliases":["receipt"]},{"emoji":"⏺️","aliases":["record_button"]},{"emoji":"♻️","aliases":["recycle"]},{"emoji":"🔴","aliases":["red_circle"]},{"emoji":"🧧","aliases":["red_envelope"]},{"emoji":"👨🦰","aliases":["red_haired_man"]},{"emoji":"👩🦰","aliases":["red_haired_woman"]},{"emoji":"🟥","aliases":["red_square"]},{"emoji":"®️","aliases":["registered"]},{"emoji":"☺️","aliases":["relaxed"]},{"emoji":"😌","aliases":["relieved"]},{"emoji":"🎗️","aliases":["reminder_ribbon"]},{"emoji":"🔁","aliases":["repeat"]},{"emoji":"🔂","aliases":["repeat_one"]},{"emoji":"⛑️","aliases":["rescue_worker_helmet"]},{"emoji":"🚻","aliases":["restroom"]},{"emoji":"🇷🇪","aliases":["reunion"]},{"emoji":"💞","aliases":["revolving_hearts"]},{"emoji":"⏪","aliases":["rewind"]},{"emoji":"🦏","aliases":["rhinoceros"]},{"emoji":"🎀","aliases":["ribbon"]},{"emoji":"🍚","aliases":["rice"]},{"emoji":"🍙","aliases":["rice_ball"]},{"emoji":"🍘","aliases":["rice_cracker"]},{"emoji":"🎑","aliases":["rice_scene"]},{"emoji":"🗯️","aliases":["right_anger_bubble"]},{"emoji":"🫱","aliases":["rightwards_hand"]},{"emoji":"🫸","aliases":["rightwards_pushing_hand"]},{"emoji":"💍","aliases":["ring"]},{"emoji":"🛟","aliases":["ring_buoy"]},{"emoji":"🪐","aliases":["ringed_planet"]},{"emoji":"🤖","aliases":["robot"]},{"emoji":"🪨","aliases":["rock"]},{"emoji":"🚀","aliases":["rocket"]},{"emoji":"🤣","aliases":["rofl"]},{"emoji":"🙄","aliases":["roll_eyes"]},{"emoji":"🧻","aliases":["roll_of_paper"]},{"emoji":"🎢","aliases":["roller_coaster"]},{"emoji":"🛼","aliases":["roller_skate"]},{"emoji":"🇷🇴","aliases":["romania"]},{"emoji":"🐓","aliases":["rooster"]},{"emoji":"🌹","aliases":["rose"]},{"emoji":"🏵️","aliases":["rosette"]},{"emoji":"🚨","aliases":["rotating_light"]},{"emoji":"📍","aliases":["round_pushpin"]},{"emoji":"🚣","aliases":["rowboat"]},{"emoji":"🚣♂️","aliases":["rowing_man"]},{"emoji":"🚣♀️","aliases":["rowing_woman"]},{"emoji":"🇷🇺","aliases":["ru"]},{"emoji":"🏉","aliases":["rugby_football"]},{"emoji":"🏃","aliases":["runner","running"]},{"emoji":"🏃♂️","aliases":["running_man"]},{"emoji":"🎽","aliases":["running_shirt_with_sash"]},{"emoji":"🏃♀️","aliases":["running_woman"]},{"emoji":"🇷🇼","aliases":["rwanda"]},{"emoji":"🈂️","aliases":["sa"]},{"emoji":"🧷","aliases":["safety_pin"]},{"emoji":"🦺","aliases":["safety_vest"]},{"emoji":"♐","aliases":["sagittarius"]},{"emoji":"🍶","aliases":["sake"]},{"emoji":"🧂","aliases":["salt"]},{"emoji":"🫡","aliases":["saluting_face"]},{"emoji":"🇼🇸","aliases":["samoa"]},{"emoji":"🇸🇲","aliases":["san_marino"]},{"emoji":"👡","aliases":["sandal"]},{"emoji":"🥪","aliases":["sandwich"]},{"emoji":"🎅","aliases":["santa"]},{"emoji":"🇸🇹","aliases":["sao_tome_principe"]},{"emoji":"🥻","aliases":["sari"]},{"emoji":"📡","aliases":["satellite"]},{"emoji":"🇸🇦","aliases":["saudi_arabia"]},{"emoji":"🧖♂️","aliases":["sauna_man"]},{"emoji":"🧖","aliases":["sauna_person"]},{"emoji":"🧖♀️","aliases":["sauna_woman"]},{"emoji":"🦕","aliases":["sauropod"]},{"emoji":"🎷","aliases":["saxophone"]},{"emoji":"🧣","aliases":["scarf"]},{"emoji":"🏫","aliases":["school"]},{"emoji":"🎒","aliases":["school_satchel"]},{"emoji":"🧑🔬","aliases":["scientist"]},{"emoji":"✂️","aliases":["scissors"]},{"emoji":"🦂","aliases":["scorpion"]},{"emoji":"♏","aliases":["scorpius"]},{"emoji":"🏴","aliases":["scotland"]},{"emoji":"😱","aliases":["scream"]},{"emoji":"🙀","aliases":["scream_cat"]},{"emoji":"🪛","aliases":["screwdriver"]},{"emoji":"📜","aliases":["scroll"]},{"emoji":"🦭","aliases":["seal"]},{"emoji":"💺","aliases":["seat"]},{"emoji":"㊙️","aliases":["secret"]},{"emoji":"🙈","aliases":["see_no_evil"]},{"emoji":"🌱","aliases":["seedling"]},{"emoji":"🤳","aliases":["selfie"]},{"emoji":"🇸🇳","aliases":["senegal"]},{"emoji":"🇷🇸","aliases":["serbia"]},{"emoji":"🐕🦺","aliases":["service_dog"]},{"emoji":"7️⃣","aliases":["seven"]},{"emoji":"🪡","aliases":["sewing_needle"]},{"emoji":"🇸🇨","aliases":["seychelles"]},{"emoji":"🫨","aliases":["shaking_face"]},{"emoji":"🥘","aliases":["shallow_pan_of_food"]},{"emoji":"☘️","aliases":["shamrock"]},{"emoji":"🦈","aliases":["shark"]},{"emoji":"🍧","aliases":["shaved_ice"]},{"emoji":"🐑","aliases":["sheep"]},{"emoji":"🐚","aliases":["shell"]},{"emoji":"🛡️","aliases":["shield"]},{"emoji":"⛩️","aliases":["shinto_shrine"]},{"emoji":"🚢","aliases":["ship"]},{"emoji":"👕","aliases":["shirt","tshirt"]},{"emoji":"🛍️","aliases":["shopping"]},{"emoji":"🛒","aliases":["shopping_cart"]},{"emoji":"🩳","aliases":["shorts"]},{"emoji":"🚿","aliases":["shower"]},{"emoji":"🦐","aliases":["shrimp"]},{"emoji":"🤷","aliases":["shrug"]},{"emoji":"🤫","aliases":["shushing_face"]},{"emoji":"🇸🇱","aliases":["sierra_leone"]},{"emoji":"📶","aliases":["signal_strength"]},{"emoji":"🇸🇬","aliases":["singapore"]},{"emoji":"🧑🎤","aliases":["singer"]},{"emoji":"🇸🇽","aliases":["sint_maarten"]},{"emoji":"6️⃣","aliases":["six"]},{"emoji":"🔯","aliases":["six_pointed_star"]},{"emoji":"🛹","aliases":["skateboard"]},{"emoji":"🎿","aliases":["ski"]},{"emoji":"⛷️","aliases":["skier"]},{"emoji":"💀","aliases":["skull"]},{"emoji":"☠️","aliases":["skull_and_crossbones"]},{"emoji":"🦨","aliases":["skunk"]},{"emoji":"🛷","aliases":["sled"]},{"emoji":"😴","aliases":["sleeping"]},{"emoji":"🛌","aliases":["sleeping_bed"]},{"emoji":"😪","aliases":["sleepy"]},{"emoji":"🙁","aliases":["slightly_frowning_face"]},{"emoji":"🙂","aliases":["slightly_smiling_face"]},{"emoji":"🎰","aliases":["slot_machine"]},{"emoji":"🦥","aliases":["sloth"]},{"emoji":"🇸🇰","aliases":["slovakia"]},{"emoji":"🇸🇮","aliases":["slovenia"]},{"emoji":"🛩️","aliases":["small_airplane"]},{"emoji":"🔹","aliases":["small_blue_diamond"]},{"emoji":"🔸","aliases":["small_orange_diamond"]},{"emoji":"🔺","aliases":["small_red_triangle"]},{"emoji":"🔻","aliases":["small_red_triangle_down"]},{"emoji":"😄","aliases":["smile"]},{"emoji":"😸","aliases":["smile_cat"]},{"emoji":"😃","aliases":["smiley"]},{"emoji":"😺","aliases":["smiley_cat"]},{"emoji":"🥲","aliases":["smiling_face_with_tear"]},{"emoji":"🥰","aliases":["smiling_face_with_three_hearts"]},{"emoji":"😈","aliases":["smiling_imp"]},{"emoji":"😏","aliases":["smirk"]},{"emoji":"😼","aliases":["smirk_cat"]},{"emoji":"🚬","aliases":["smoking"]},{"emoji":"🐌","aliases":["snail"]},{"emoji":"🐍","aliases":["snake"]},{"emoji":"🤧","aliases":["sneezing_face"]},{"emoji":"🏂","aliases":["snowboarder"]},{"emoji":"❄️","aliases":["snowflake"]},{"emoji":"⛄","aliases":["snowman"]},{"emoji":"☃️","aliases":["snowman_with_snow"]},{"emoji":"🧼","aliases":["soap"]},{"emoji":"😭","aliases":["sob"]},{"emoji":"⚽","aliases":["soccer"]},{"emoji":"🧦","aliases":["socks"]},{"emoji":"🥎","aliases":["softball"]},{"emoji":"🇸🇧","aliases":["solomon_islands"]},{"emoji":"🇸🇴","aliases":["somalia"]},{"emoji":"🔜","aliases":["soon"]},{"emoji":"🆘","aliases":["sos"]},{"emoji":"🔉","aliases":["sound"]},{"emoji":"🇿🇦","aliases":["south_africa"]},{"emoji":"🇬🇸","aliases":["south_georgia_south_sandwich_islands"]},{"emoji":"🇸🇸","aliases":["south_sudan"]},{"emoji":"👾","aliases":["space_invader"]},{"emoji":"♠️","aliases":["spades"]},{"emoji":"🍝","aliases":["spaghetti"]},{"emoji":"❇️","aliases":["sparkle"]},{"emoji":"🎇","aliases":["sparkler"]},{"emoji":"✨","aliases":["sparkles"]},{"emoji":"💖","aliases":["sparkling_heart"]},{"emoji":"🙊","aliases":["speak_no_evil"]},{"emoji":"🔈","aliases":["speaker"]},{"emoji":"🗣️","aliases":["speaking_head"]},{"emoji":"💬","aliases":["speech_balloon"]},{"emoji":"🚤","aliases":["speedboat"]},{"emoji":"🕷️","aliases":["spider"]},{"emoji":"🕸️","aliases":["spider_web"]},{"emoji":"🗓️","aliases":["spiral_calendar"]},{"emoji":"🗒️","aliases":["spiral_notepad"]},{"emoji":"🧽","aliases":["sponge"]},{"emoji":"🥄","aliases":["spoon"]},{"emoji":"🦑","aliases":["squid"]},{"emoji":"🇱🇰","aliases":["sri_lanka"]},{"emoji":"🇧🇱","aliases":["st_barthelemy"]},{"emoji":"🇸🇭","aliases":["st_helena"]},{"emoji":"🇰🇳","aliases":["st_kitts_nevis"]},{"emoji":"🇱🇨","aliases":["st_lucia"]},{"emoji":"🇲🇫","aliases":["st_martin"]},{"emoji":"🇵🇲","aliases":["st_pierre_miquelon"]},{"emoji":"🇻🇨","aliases":["st_vincent_grenadines"]},{"emoji":"🏟️","aliases":["stadium"]},{"emoji":"🧍♂️","aliases":["standing_man"]},{"emoji":"🧍","aliases":["standing_person"]},{"emoji":"🧍♀️","aliases":["standing_woman"]},{"emoji":"⭐","aliases":["star"]},{"emoji":"🌟","aliases":["star2"]},{"emoji":"☪️","aliases":["star_and_crescent"]},{"emoji":"✡️","aliases":["star_of_david"]},{"emoji":"🤩","aliases":["star_struck"]},{"emoji":"🌠","aliases":["stars"]},{"emoji":"🚉","aliases":["station"]},{"emoji":"🗽","aliases":["statue_of_liberty"]},{"emoji":"🚂","aliases":["steam_locomotive"]},{"emoji":"🩺","aliases":["stethoscope"]},{"emoji":"🍲","aliases":["stew"]},{"emoji":"⏹️","aliases":["stop_button"]},{"emoji":"🛑","aliases":["stop_sign"]},{"emoji":"⏱️","aliases":["stopwatch"]},{"emoji":"📏","aliases":["straight_ruler"]},{"emoji":"🍓","aliases":["strawberry"]},{"emoji":"😛","aliases":["stuck_out_tongue"]},{"emoji":"😝","aliases":["stuck_out_tongue_closed_eyes"]},{"emoji":"😜","aliases":["stuck_out_tongue_winking_eye"]},{"emoji":"🧑🎓","aliases":["student"]},{"emoji":"🎙️","aliases":["studio_microphone"]},{"emoji":"🥙","aliases":["stuffed_flatbread"]},{"emoji":"🇸🇩","aliases":["sudan"]},{"emoji":"🌥️","aliases":["sun_behind_large_cloud"]},{"emoji":"🌦️","aliases":["sun_behind_rain_cloud"]},{"emoji":"🌤️","aliases":["sun_behind_small_cloud"]},{"emoji":"🌞","aliases":["sun_with_face"]},{"emoji":"🌻","aliases":["sunflower"]},{"emoji":"😎","aliases":["sunglasses"]},{"emoji":"☀️","aliases":["sunny"]},{"emoji":"🌅","aliases":["sunrise"]},{"emoji":"🌄","aliases":["sunrise_over_mountains"]},{"emoji":"🦸","aliases":["superhero"]},{"emoji":"🦸♂️","aliases":["superhero_man"]},{"emoji":"🦸♀️","aliases":["superhero_woman"]},{"emoji":"🦹","aliases":["supervillain"]},{"emoji":"🦹♂️","aliases":["supervillain_man"]},{"emoji":"🦹♀️","aliases":["supervillain_woman"]},{"emoji":"🏄","aliases":["surfer"]},{"emoji":"🏄♂️","aliases":["surfing_man"]},{"emoji":"🏄♀️","aliases":["surfing_woman"]},{"emoji":"🇸🇷","aliases":["suriname"]},{"emoji":"🍣","aliases":["sushi"]},{"emoji":"🚟","aliases":["suspension_railway"]},{"emoji":"🇸🇯","aliases":["svalbard_jan_mayen"]},{"emoji":"🦢","aliases":["swan"]},{"emoji":"🇸🇿","aliases":["swaziland"]},{"emoji":"😓","aliases":["sweat"]},{"emoji":"💦","aliases":["sweat_drops"]},{"emoji":"😅","aliases":["sweat_smile"]},{"emoji":"🇸🇪","aliases":["sweden"]},{"emoji":"🍠","aliases":["sweet_potato"]},{"emoji":"🩲","aliases":["swim_brief"]},{"emoji":"🏊","aliases":["swimmer"]},{"emoji":"🏊♂️","aliases":["swimming_man"]},{"emoji":"🏊♀️","aliases":["swimming_woman"]},{"emoji":"🇨🇭","aliases":["switzerland"]},{"emoji":"🔣","aliases":["symbols"]},{"emoji":"🕍","aliases":["synagogue"]},{"emoji":"🇸🇾","aliases":["syria"]},{"emoji":"💉","aliases":["syringe"]},{"emoji":"🦖","aliases":["t-rex"]},{"emoji":"🌮","aliases":["taco"]},{"emoji":"🎉","aliases":["tada","hooray"]},{"emoji":"🇹🇼","aliases":["taiwan"]},{"emoji":"🇹🇯","aliases":["tajikistan"]},{"emoji":"🥡","aliases":["takeout_box"]},{"emoji":"🫔","aliases":["tamale"]},{"emoji":"🎋","aliases":["tanabata_tree"]},{"emoji":"🍊","aliases":["tangerine","orange","mandarin"]},{"emoji":"🇹🇿","aliases":["tanzania"]},{"emoji":"♉","aliases":["taurus"]},{"emoji":"🚕","aliases":["taxi"]},{"emoji":"🍵","aliases":["tea"]},{"emoji":"🧑🏫","aliases":["teacher"]},{"emoji":"🫖","aliases":["teapot"]},{"emoji":"🧑💻","aliases":["technologist"]},{"emoji":"🧸","aliases":["teddy_bear"]},{"emoji":"📞","aliases":["telephone_receiver"]},{"emoji":"🔭","aliases":["telescope"]},{"emoji":"🎾","aliases":["tennis"]},{"emoji":"⛺","aliases":["tent"]},{"emoji":"🧪","aliases":["test_tube"]},{"emoji":"🇹🇭","aliases":["thailand"]},{"emoji":"🌡️","aliases":["thermometer"]},{"emoji":"🤔","aliases":["thinking"]},{"emoji":"🩴","aliases":["thong_sandal"]},{"emoji":"💭","aliases":["thought_balloon"]},{"emoji":"🧵","aliases":["thread"]},{"emoji":"3️⃣","aliases":["three"]},{"emoji":"🎫","aliases":["ticket"]},{"emoji":"🎟️","aliases":["tickets"]},{"emoji":"🐯","aliases":["tiger"]},{"emoji":"🐅","aliases":["tiger2"]},{"emoji":"⏲️","aliases":["timer_clock"]},{"emoji":"🇹🇱","aliases":["timor_leste"]},{"emoji":"💁♂️","aliases":["tipping_hand_man","sassy_man"]},{"emoji":"💁","aliases":["tipping_hand_person","information_desk_person"]},{"emoji":"💁♀️","aliases":["tipping_hand_woman","sassy_woman"]},{"emoji":"😫","aliases":["tired_face"]},{"emoji":"™️","aliases":["tm"]},{"emoji":"🇹🇬","aliases":["togo"]},{"emoji":"🚽","aliases":["toilet"]},{"emoji":"🇹🇰","aliases":["tokelau"]},{"emoji":"🗼","aliases":["tokyo_tower"]},{"emoji":"🍅","aliases":["tomato"]},{"emoji":"🇹🇴","aliases":["tonga"]},{"emoji":"👅","aliases":["tongue"]},{"emoji":"🧰","aliases":["toolbox"]},{"emoji":"🦷","aliases":["tooth"]},{"emoji":"🪥","aliases":["toothbrush"]},{"emoji":"🔝","aliases":["top"]},{"emoji":"🎩","aliases":["tophat"]},{"emoji":"🌪️","aliases":["tornado"]},{"emoji":"🇹🇷","aliases":["tr"]},{"emoji":"🖲️","aliases":["trackball"]},{"emoji":"🚜","aliases":["tractor"]},{"emoji":"🚥","aliases":["traffic_light"]},{"emoji":"🚋","aliases":["train"]},{"emoji":"🚆","aliases":["train2"]},{"emoji":"🚊","aliases":["tram"]},{"emoji":"🏳️⚧️","aliases":["transgender_flag"]},{"emoji":"⚧️","aliases":["transgender_symbol"]},{"emoji":"🚩","aliases":["triangular_flag_on_post"]},{"emoji":"📐","aliases":["triangular_ruler"]},{"emoji":"🔱","aliases":["trident"]},{"emoji":"🇹🇹","aliases":["trinidad_tobago"]},{"emoji":"🇹🇦","aliases":["tristan_da_cunha"]},{"emoji":"😤","aliases":["triumph"]},{"emoji":"🧌","aliases":["troll"]},{"emoji":"🚎","aliases":["trolleybus"]},{"emoji":"🏆","aliases":["trophy"]},{"emoji":"🍹","aliases":["tropical_drink"]},{"emoji":"🐠","aliases":["tropical_fish"]},{"emoji":"🚚","aliases":["truck"]},{"emoji":"🎺","aliases":["trumpet"]},{"emoji":"🌷","aliases":["tulip"]},{"emoji":"🥃","aliases":["tumbler_glass"]},{"emoji":"🇹🇳","aliases":["tunisia"]},{"emoji":"🦃","aliases":["turkey"]},{"emoji":"🇹🇲","aliases":["turkmenistan"]},{"emoji":"🇹🇨","aliases":["turks_caicos_islands"]},{"emoji":"🐢","aliases":["turtle"]},{"emoji":"🇹🇻","aliases":["tuvalu"]},{"emoji":"📺","aliases":["tv"]},{"emoji":"🔀","aliases":["twisted_rightwards_arrows"]},{"emoji":"2️⃣","aliases":["two"]},{"emoji":"💕","aliases":["two_hearts"]},{"emoji":"👬","aliases":["two_men_holding_hands"]},{"emoji":"👭","aliases":["two_women_holding_hands"]},{"emoji":"🈹","aliases":["u5272"]},{"emoji":"🈴","aliases":["u5408"]},{"emoji":"🈺","aliases":["u55b6"]},{"emoji":"🈯","aliases":["u6307"]},{"emoji":"🈷️","aliases":["u6708"]},{"emoji":"🈶","aliases":["u6709"]},{"emoji":"🈵","aliases":["u6e80"]},{"emoji":"🈚","aliases":["u7121"]},{"emoji":"🈸","aliases":["u7533"]},{"emoji":"🈲","aliases":["u7981"]},{"emoji":"🈳","aliases":["u7a7a"]},{"emoji":"🇺🇬","aliases":["uganda"]},{"emoji":"🇺🇦","aliases":["ukraine"]},{"emoji":"☔","aliases":["umbrella"]},{"emoji":"😒","aliases":["unamused"]},{"emoji":"🔞","aliases":["underage"]},{"emoji":"🦄","aliases":["unicorn"]},{"emoji":"🇦🇪","aliases":["united_arab_emirates"]},{"emoji":"🇺🇳","aliases":["united_nations"]},{"emoji":"🔓","aliases":["unlock"]},{"emoji":"🆙","aliases":["up"]},{"emoji":"🙃","aliases":["upside_down_face"]},{"emoji":"🇺🇾","aliases":["uruguay"]},{"emoji":"🇺🇸","aliases":["us"]},{"emoji":"🇺🇲","aliases":["us_outlying_islands"]},{"emoji":"🇻🇮","aliases":["us_virgin_islands"]},{"emoji":"🇺🇿","aliases":["uzbekistan"]},{"emoji":"✌️","aliases":["v"]},{"emoji":"🧛","aliases":["vampire"]},{"emoji":"🧛♂️","aliases":["vampire_man"]},{"emoji":"🧛♀️","aliases":["vampire_woman"]},{"emoji":"🇻🇺","aliases":["vanuatu"]},{"emoji":"🇻🇦","aliases":["vatican_city"]},{"emoji":"🇻🇪","aliases":["venezuela"]},{"emoji":"🚦","aliases":["vertical_traffic_light"]},{"emoji":"📼","aliases":["vhs"]},{"emoji":"📳","aliases":["vibration_mode"]},{"emoji":"📹","aliases":["video_camera"]},{"emoji":"🎮","aliases":["video_game"]},{"emoji":"🇻🇳","aliases":["vietnam"]},{"emoji":"🎻","aliases":["violin"]},{"emoji":"♍","aliases":["virgo"]},{"emoji":"🌋","aliases":["volcano"]},{"emoji":"🏐","aliases":["volleyball"]},{"emoji":"🤮","aliases":["vomiting_face"]},{"emoji":"🆚","aliases":["vs"]},{"emoji":"🖖","aliases":["vulcan_salute"]},{"emoji":"🧇","aliases":["waffle"]},{"emoji":"🏴","aliases":["wales"]},{"emoji":"🚶","aliases":["walking"]},{"emoji":"🚶♂️","aliases":["walking_man"]},{"emoji":"🚶♀️","aliases":["walking_woman"]},{"emoji":"🇼🇫","aliases":["wallis_futuna"]},{"emoji":"🌘","aliases":["waning_crescent_moon"]},{"emoji":"🌖","aliases":["waning_gibbous_moon"]},{"emoji":"⚠️","aliases":["warning"]},{"emoji":"🗑️","aliases":["wastebasket"]},{"emoji":"⌚","aliases":["watch"]},{"emoji":"🐃","aliases":["water_buffalo"]},{"emoji":"🤽","aliases":["water_polo"]},{"emoji":"🍉","aliases":["watermelon"]},{"emoji":"👋","aliases":["wave"]},{"emoji":"〰️","aliases":["wavy_dash"]},{"emoji":"🌒","aliases":["waxing_crescent_moon"]},{"emoji":"🚾","aliases":["wc"]},{"emoji":"😩","aliases":["weary"]},{"emoji":"💒","aliases":["wedding"]},{"emoji":"🏋️","aliases":["weight_lifting"]},{"emoji":"🏋️♂️","aliases":["weight_lifting_man"]},{"emoji":"🏋️♀️","aliases":["weight_lifting_woman"]},{"emoji":"🇪🇭","aliases":["western_sahara"]},{"emoji":"🐳","aliases":["whale"]},{"emoji":"🐋","aliases":["whale2"]},{"emoji":"🛞","aliases":["wheel"]},{"emoji":"☸️","aliases":["wheel_of_dharma"]},{"emoji":"♿","aliases":["wheelchair"]},{"emoji":"✅","aliases":["white_check_mark"]},{"emoji":"⚪","aliases":["white_circle"]},{"emoji":"🏳️","aliases":["white_flag"]},{"emoji":"💮","aliases":["white_flower"]},{"emoji":"👨🦳","aliases":["white_haired_man"]},{"emoji":"👩🦳","aliases":["white_haired_woman"]},{"emoji":"🤍","aliases":["white_heart"]},{"emoji":"⬜","aliases":["white_large_square"]},{"emoji":"◽","aliases":["white_medium_small_square"]},{"emoji":"◻️","aliases":["white_medium_square"]},{"emoji":"▫️","aliases":["white_small_square"]},{"emoji":"🔳","aliases":["white_square_button"]},{"emoji":"🥀","aliases":["wilted_flower"]},{"emoji":"🎐","aliases":["wind_chime"]},{"emoji":"🌬️","aliases":["wind_face"]},{"emoji":"🪟","aliases":["window"]},{"emoji":"🍷","aliases":["wine_glass"]},{"emoji":"🪽","aliases":["wing"]},{"emoji":"😉","aliases":["wink"]},{"emoji":"🛜","aliases":["wireless"]},{"emoji":"🐺","aliases":["wolf"]},{"emoji":"👩","aliases":["woman"]},{"emoji":"👩🎨","aliases":["woman_artist"]},{"emoji":"👩🚀","aliases":["woman_astronaut"]},{"emoji":"🧔♀️","aliases":["woman_beard"]},{"emoji":"🤸♀️","aliases":["woman_cartwheeling"]},{"emoji":"👩🍳","aliases":["woman_cook"]},{"emoji":"💃","aliases":["woman_dancing","dancer"]},{"emoji":"🤦♀️","aliases":["woman_facepalming"]},{"emoji":"👩🏭","aliases":["woman_factory_worker"]},{"emoji":"👩🌾","aliases":["woman_farmer"]},{"emoji":"👩🍼","aliases":["woman_feeding_baby"]},{"emoji":"👩🚒","aliases":["woman_firefighter"]},{"emoji":"👩⚕️","aliases":["woman_health_worker"]},{"emoji":"👩🦽","aliases":["woman_in_manual_wheelchair"]},{"emoji":"👩🦼","aliases":["woman_in_motorized_wheelchair"]},{"emoji":"🤵♀️","aliases":["woman_in_tuxedo"]},{"emoji":"👩⚖️","aliases":["woman_judge"]},{"emoji":"🤹♀️","aliases":["woman_juggling"]},{"emoji":"👩🔧","aliases":["woman_mechanic"]},{"emoji":"👩💼","aliases":["woman_office_worker"]},{"emoji":"👩✈️","aliases":["woman_pilot"]},{"emoji":"🤾♀️","aliases":["woman_playing_handball"]},{"emoji":"🤽♀️","aliases":["woman_playing_water_polo"]},{"emoji":"👩🔬","aliases":["woman_scientist"]},{"emoji":"🤷♀️","aliases":["woman_shrugging"]},{"emoji":"👩🎤","aliases":["woman_singer"]},{"emoji":"👩🎓","aliases":["woman_student"]},{"emoji":"👩🏫","aliases":["woman_teacher"]},{"emoji":"👩💻","aliases":["woman_technologist"]},{"emoji":"🧕","aliases":["woman_with_headscarf"]},{"emoji":"👩🦯","aliases":["woman_with_probing_cane"]},{"emoji":"👳♀️","aliases":["woman_with_turban"]},{"emoji":"👰♀️","aliases":["woman_with_veil","bride_with_veil"]},{"emoji":"👚","aliases":["womans_clothes"]},{"emoji":"👒","aliases":["womans_hat"]},{"emoji":"🤼♀️","aliases":["women_wrestling"]},{"emoji":"🚺","aliases":["womens"]},{"emoji":"🪵","aliases":["wood"]},{"emoji":"🥴","aliases":["woozy_face"]},{"emoji":"🗺️","aliases":["world_map"]},{"emoji":"🪱","aliases":["worm"]},{"emoji":"😟","aliases":["worried"]},{"emoji":"🔧","aliases":["wrench"]},{"emoji":"🤼","aliases":["wrestling"]},{"emoji":"✍️","aliases":["writing_hand"]},{"emoji":"❌","aliases":["x"]},{"emoji":"🩻","aliases":["x_ray"]},{"emoji":"🧶","aliases":["yarn"]},{"emoji":"🥱","aliases":["yawning_face"]},{"emoji":"🟡","aliases":["yellow_circle"]},{"emoji":"💛","aliases":["yellow_heart"]},{"emoji":"🟨","aliases":["yellow_square"]},{"emoji":"🇾🇪","aliases":["yemen"]},{"emoji":"💴","aliases":["yen"]},{"emoji":"☯️","aliases":["yin_yang"]},{"emoji":"🪀","aliases":["yo_yo"]},{"emoji":"😋","aliases":["yum"]},{"emoji":"🇿🇲","aliases":["zambia"]},{"emoji":"🤪","aliases":["zany_face"]},{"emoji":"⚡","aliases":["zap"]},{"emoji":"🦓","aliases":["zebra"]},{"emoji":"0️⃣","aliases":["zero"]},{"emoji":"🇿🇼","aliases":["zimbabwe"]},{"emoji":"🤐","aliases":["zipper_mouth_face"]},{"emoji":"🧟","aliases":["zombie"]},{"emoji":"🧟♂️","aliases":["zombie_man"]},{"emoji":"🧟♀️","aliases":["zombie_woman"]},{"emoji":"💤","aliases":["zzz"]}]
\ No newline at end of file
+[
+ {
+ "emoji": "👍",
+ "aliases": [
+ "+1",
+ "thumbsup"
+ ]
+ },
+ {
+ "emoji": "👎",
+ "aliases": [
+ "-1",
+ "thumbsdown"
+ ]
+ },
+ {
+ "emoji": "💯",
+ "aliases": [
+ "100"
+ ]
+ },
+ {
+ "emoji": "🔢",
+ "aliases": [
+ "1234"
+ ]
+ },
+ {
+ "emoji": "🥇",
+ "aliases": [
+ "1st_place_medal"
+ ]
+ },
+ {
+ "emoji": "🥈",
+ "aliases": [
+ "2nd_place_medal"
+ ]
+ },
+ {
+ "emoji": "🥉",
+ "aliases": [
+ "3rd_place_medal"
+ ]
+ },
+ {
+ "emoji": "🎱",
+ "aliases": [
+ "8ball"
+ ]
+ },
+ {
+ "emoji": "🅰️",
+ "aliases": [
+ "a"
+ ]
+ },
+ {
+ "emoji": "🆎",
+ "aliases": [
+ "ab"
+ ]
+ },
+ {
+ "emoji": "🧮",
+ "aliases": [
+ "abacus"
+ ]
+ },
+ {
+ "emoji": "🔤",
+ "aliases": [
+ "abc"
+ ]
+ },
+ {
+ "emoji": "🔡",
+ "aliases": [
+ "abcd"
+ ]
+ },
+ {
+ "emoji": "🉑",
+ "aliases": [
+ "accept"
+ ]
+ },
+ {
+ "emoji": "🪗",
+ "aliases": [
+ "accordion"
+ ]
+ },
+ {
+ "emoji": "🩹",
+ "aliases": [
+ "adhesive_bandage"
+ ]
+ },
+ {
+ "emoji": "🧑",
+ "aliases": [
+ "adult"
+ ]
+ },
+ {
+ "emoji": "🚡",
+ "aliases": [
+ "aerial_tramway"
+ ]
+ },
+ {
+ "emoji": "🇦🇫",
+ "aliases": [
+ "afghanistan"
+ ]
+ },
+ {
+ "emoji": "✈️",
+ "aliases": [
+ "airplane"
+ ]
+ },
+ {
+ "emoji": "🇦🇽",
+ "aliases": [
+ "aland_islands"
+ ]
+ },
+ {
+ "emoji": "⏰",
+ "aliases": [
+ "alarm_clock"
+ ]
+ },
+ {
+ "emoji": "🇦🇱",
+ "aliases": [
+ "albania"
+ ]
+ },
+ {
+ "emoji": "⚗️",
+ "aliases": [
+ "alembic"
+ ]
+ },
+ {
+ "emoji": "🇩🇿",
+ "aliases": [
+ "algeria"
+ ]
+ },
+ {
+ "emoji": "👽",
+ "aliases": [
+ "alien"
+ ]
+ },
+ {
+ "emoji": "🚑",
+ "aliases": [
+ "ambulance"
+ ]
+ },
+ {
+ "emoji": "🇦🇸",
+ "aliases": [
+ "american_samoa"
+ ]
+ },
+ {
+ "emoji": "🏺",
+ "aliases": [
+ "amphora"
+ ]
+ },
+ {
+ "emoji": "🫀",
+ "aliases": [
+ "anatomical_heart"
+ ]
+ },
+ {
+ "emoji": "⚓",
+ "aliases": [
+ "anchor"
+ ]
+ },
+ {
+ "emoji": "🇦🇩",
+ "aliases": [
+ "andorra"
+ ]
+ },
+ {
+ "emoji": "👼",
+ "aliases": [
+ "angel"
+ ]
+ },
+ {
+ "emoji": "💢",
+ "aliases": [
+ "anger"
+ ]
+ },
+ {
+ "emoji": "🇦🇴",
+ "aliases": [
+ "angola"
+ ]
+ },
+ {
+ "emoji": "😠",
+ "aliases": [
+ "angry"
+ ]
+ },
+ {
+ "emoji": "🇦🇮",
+ "aliases": [
+ "anguilla"
+ ]
+ },
+ {
+ "emoji": "😧",
+ "aliases": [
+ "anguished"
+ ]
+ },
+ {
+ "emoji": "🐜",
+ "aliases": [
+ "ant"
+ ]
+ },
+ {
+ "emoji": "🇦🇶",
+ "aliases": [
+ "antarctica"
+ ]
+ },
+ {
+ "emoji": "🇦🇬",
+ "aliases": [
+ "antigua_barbuda"
+ ]
+ },
+ {
+ "emoji": "🍎",
+ "aliases": [
+ "apple"
+ ]
+ },
+ {
+ "emoji": "♒",
+ "aliases": [
+ "aquarius"
+ ]
+ },
+ {
+ "emoji": "🇦🇷",
+ "aliases": [
+ "argentina"
+ ]
+ },
+ {
+ "emoji": "♈",
+ "aliases": [
+ "aries"
+ ]
+ },
+ {
+ "emoji": "🇦🇲",
+ "aliases": [
+ "armenia"
+ ]
+ },
+ {
+ "emoji": "◀️",
+ "aliases": [
+ "arrow_backward"
+ ]
+ },
+ {
+ "emoji": "⏬",
+ "aliases": [
+ "arrow_double_down"
+ ]
+ },
+ {
+ "emoji": "⏫",
+ "aliases": [
+ "arrow_double_up"
+ ]
+ },
+ {
+ "emoji": "⬇️",
+ "aliases": [
+ "arrow_down"
+ ]
+ },
+ {
+ "emoji": "🔽",
+ "aliases": [
+ "arrow_down_small"
+ ]
+ },
+ {
+ "emoji": "▶️",
+ "aliases": [
+ "arrow_forward"
+ ]
+ },
+ {
+ "emoji": "⤵️",
+ "aliases": [
+ "arrow_heading_down"
+ ]
+ },
+ {
+ "emoji": "⤴️",
+ "aliases": [
+ "arrow_heading_up"
+ ]
+ },
+ {
+ "emoji": "⬅️",
+ "aliases": [
+ "arrow_left"
+ ]
+ },
+ {
+ "emoji": "↙️",
+ "aliases": [
+ "arrow_lower_left"
+ ]
+ },
+ {
+ "emoji": "↘️",
+ "aliases": [
+ "arrow_lower_right"
+ ]
+ },
+ {
+ "emoji": "➡️",
+ "aliases": [
+ "arrow_right"
+ ]
+ },
+ {
+ "emoji": "↪️",
+ "aliases": [
+ "arrow_right_hook"
+ ]
+ },
+ {
+ "emoji": "⬆️",
+ "aliases": [
+ "arrow_up"
+ ]
+ },
+ {
+ "emoji": "↕️",
+ "aliases": [
+ "arrow_up_down"
+ ]
+ },
+ {
+ "emoji": "🔼",
+ "aliases": [
+ "arrow_up_small"
+ ]
+ },
+ {
+ "emoji": "↖️",
+ "aliases": [
+ "arrow_upper_left"
+ ]
+ },
+ {
+ "emoji": "↗️",
+ "aliases": [
+ "arrow_upper_right"
+ ]
+ },
+ {
+ "emoji": "🔃",
+ "aliases": [
+ "arrows_clockwise"
+ ]
+ },
+ {
+ "emoji": "🔄",
+ "aliases": [
+ "arrows_counterclockwise"
+ ]
+ },
+ {
+ "emoji": "🎨",
+ "aliases": [
+ "art"
+ ]
+ },
+ {
+ "emoji": "🚛",
+ "aliases": [
+ "articulated_lorry"
+ ]
+ },
+ {
+ "emoji": "🛰️",
+ "aliases": [
+ "artificial_satellite"
+ ]
+ },
+ {
+ "emoji": "🧑🎨",
+ "aliases": [
+ "artist"
+ ]
+ },
+ {
+ "emoji": "🇦🇼",
+ "aliases": [
+ "aruba"
+ ]
+ },
+ {
+ "emoji": "🇦🇨",
+ "aliases": [
+ "ascension_island"
+ ]
+ },
+ {
+ "emoji": "*️⃣",
+ "aliases": [
+ "asterisk"
+ ]
+ },
+ {
+ "emoji": "😲",
+ "aliases": [
+ "astonished"
+ ]
+ },
+ {
+ "emoji": "🧑🚀",
+ "aliases": [
+ "astronaut"
+ ]
+ },
+ {
+ "emoji": "👟",
+ "aliases": [
+ "athletic_shoe"
+ ]
+ },
+ {
+ "emoji": "🏧",
+ "aliases": [
+ "atm"
+ ]
+ },
+ {
+ "emoji": "⚛️",
+ "aliases": [
+ "atom_symbol"
+ ]
+ },
+ {
+ "emoji": "🇦🇺",
+ "aliases": [
+ "australia"
+ ]
+ },
+ {
+ "emoji": "🇦🇹",
+ "aliases": [
+ "austria"
+ ]
+ },
+ {
+ "emoji": "🛺",
+ "aliases": [
+ "auto_rickshaw"
+ ]
+ },
+ {
+ "emoji": "🥑",
+ "aliases": [
+ "avocado"
+ ]
+ },
+ {
+ "emoji": "🪓",
+ "aliases": [
+ "axe"
+ ]
+ },
+ {
+ "emoji": "🇦🇿",
+ "aliases": [
+ "azerbaijan"
+ ]
+ },
+ {
+ "emoji": "🅱️",
+ "aliases": [
+ "b"
+ ]
+ },
+ {
+ "emoji": "👶",
+ "aliases": [
+ "baby"
+ ]
+ },
+ {
+ "emoji": "🍼",
+ "aliases": [
+ "baby_bottle"
+ ]
+ },
+ {
+ "emoji": "🐤",
+ "aliases": [
+ "baby_chick"
+ ]
+ },
+ {
+ "emoji": "🚼",
+ "aliases": [
+ "baby_symbol"
+ ]
+ },
+ {
+ "emoji": "🔙",
+ "aliases": [
+ "back"
+ ]
+ },
+ {
+ "emoji": "🥓",
+ "aliases": [
+ "bacon"
+ ]
+ },
+ {
+ "emoji": "🦡",
+ "aliases": [
+ "badger"
+ ]
+ },
+ {
+ "emoji": "🏸",
+ "aliases": [
+ "badminton"
+ ]
+ },
+ {
+ "emoji": "🥯",
+ "aliases": [
+ "bagel"
+ ]
+ },
+ {
+ "emoji": "🛄",
+ "aliases": [
+ "baggage_claim"
+ ]
+ },
+ {
+ "emoji": "🥖",
+ "aliases": [
+ "baguette_bread"
+ ]
+ },
+ {
+ "emoji": "🇧🇸",
+ "aliases": [
+ "bahamas"
+ ]
+ },
+ {
+ "emoji": "🇧🇭",
+ "aliases": [
+ "bahrain"
+ ]
+ },
+ {
+ "emoji": "⚖️",
+ "aliases": [
+ "balance_scale"
+ ]
+ },
+ {
+ "emoji": "👨🦲",
+ "aliases": [
+ "bald_man"
+ ]
+ },
+ {
+ "emoji": "👩🦲",
+ "aliases": [
+ "bald_woman"
+ ]
+ },
+ {
+ "emoji": "🩰",
+ "aliases": [
+ "ballet_shoes"
+ ]
+ },
+ {
+ "emoji": "🎈",
+ "aliases": [
+ "balloon"
+ ]
+ },
+ {
+ "emoji": "🗳️",
+ "aliases": [
+ "ballot_box"
+ ]
+ },
+ {
+ "emoji": "☑️",
+ "aliases": [
+ "ballot_box_with_check"
+ ]
+ },
+ {
+ "emoji": "🎍",
+ "aliases": [
+ "bamboo"
+ ]
+ },
+ {
+ "emoji": "🍌",
+ "aliases": [
+ "banana"
+ ]
+ },
+ {
+ "emoji": "‼️",
+ "aliases": [
+ "bangbang"
+ ]
+ },
+ {
+ "emoji": "🇧🇩",
+ "aliases": [
+ "bangladesh"
+ ]
+ },
+ {
+ "emoji": "🪕",
+ "aliases": [
+ "banjo"
+ ]
+ },
+ {
+ "emoji": "🏦",
+ "aliases": [
+ "bank"
+ ]
+ },
+ {
+ "emoji": "📊",
+ "aliases": [
+ "bar_chart"
+ ]
+ },
+ {
+ "emoji": "🇧🇧",
+ "aliases": [
+ "barbados"
+ ]
+ },
+ {
+ "emoji": "💈",
+ "aliases": [
+ "barber"
+ ]
+ },
+ {
+ "emoji": "⚾",
+ "aliases": [
+ "baseball"
+ ]
+ },
+ {
+ "emoji": "🧺",
+ "aliases": [
+ "basket"
+ ]
+ },
+ {
+ "emoji": "🏀",
+ "aliases": [
+ "basketball"
+ ]
+ },
+ {
+ "emoji": "🦇",
+ "aliases": [
+ "bat"
+ ]
+ },
+ {
+ "emoji": "🛀",
+ "aliases": [
+ "bath"
+ ]
+ },
+ {
+ "emoji": "🛁",
+ "aliases": [
+ "bathtub"
+ ]
+ },
+ {
+ "emoji": "🔋",
+ "aliases": [
+ "battery"
+ ]
+ },
+ {
+ "emoji": "🏖️",
+ "aliases": [
+ "beach_umbrella"
+ ]
+ },
+ {
+ "emoji": "🫘",
+ "aliases": [
+ "beans"
+ ]
+ },
+ {
+ "emoji": "🐻",
+ "aliases": [
+ "bear"
+ ]
+ },
+ {
+ "emoji": "🧔",
+ "aliases": [
+ "bearded_person"
+ ]
+ },
+ {
+ "emoji": "🦫",
+ "aliases": [
+ "beaver"
+ ]
+ },
+ {
+ "emoji": "🛏️",
+ "aliases": [
+ "bed"
+ ]
+ },
+ {
+ "emoji": "🐝",
+ "aliases": [
+ "bee",
+ "honeybee"
+ ]
+ },
+ {
+ "emoji": "🍺",
+ "aliases": [
+ "beer"
+ ]
+ },
+ {
+ "emoji": "🍻",
+ "aliases": [
+ "beers"
+ ]
+ },
+ {
+ "emoji": "🪲",
+ "aliases": [
+ "beetle"
+ ]
+ },
+ {
+ "emoji": "🔰",
+ "aliases": [
+ "beginner"
+ ]
+ },
+ {
+ "emoji": "🇧🇾",
+ "aliases": [
+ "belarus"
+ ]
+ },
+ {
+ "emoji": "🇧🇪",
+ "aliases": [
+ "belgium"
+ ]
+ },
+ {
+ "emoji": "🇧🇿",
+ "aliases": [
+ "belize"
+ ]
+ },
+ {
+ "emoji": "🔔",
+ "aliases": [
+ "bell"
+ ]
+ },
+ {
+ "emoji": "🫑",
+ "aliases": [
+ "bell_pepper"
+ ]
+ },
+ {
+ "emoji": "🛎️",
+ "aliases": [
+ "bellhop_bell"
+ ]
+ },
+ {
+ "emoji": "🇧🇯",
+ "aliases": [
+ "benin"
+ ]
+ },
+ {
+ "emoji": "🍱",
+ "aliases": [
+ "bento"
+ ]
+ },
+ {
+ "emoji": "🇧🇲",
+ "aliases": [
+ "bermuda"
+ ]
+ },
+ {
+ "emoji": "🧃",
+ "aliases": [
+ "beverage_box"
+ ]
+ },
+ {
+ "emoji": "🇧🇹",
+ "aliases": [
+ "bhutan"
+ ]
+ },
+ {
+ "emoji": "🚴",
+ "aliases": [
+ "bicyclist"
+ ]
+ },
+ {
+ "emoji": "🚲",
+ "aliases": [
+ "bike"
+ ]
+ },
+ {
+ "emoji": "🚴♂️",
+ "aliases": [
+ "biking_man"
+ ]
+ },
+ {
+ "emoji": "🚴♀️",
+ "aliases": [
+ "biking_woman"
+ ]
+ },
+ {
+ "emoji": "👙",
+ "aliases": [
+ "bikini"
+ ]
+ },
+ {
+ "emoji": "🧢",
+ "aliases": [
+ "billed_cap"
+ ]
+ },
+ {
+ "emoji": "☣️",
+ "aliases": [
+ "biohazard"
+ ]
+ },
+ {
+ "emoji": "🐦",
+ "aliases": [
+ "bird"
+ ]
+ },
+ {
+ "emoji": "🎂",
+ "aliases": [
+ "birthday"
+ ]
+ },
+ {
+ "emoji": "🦬",
+ "aliases": [
+ "bison"
+ ]
+ },
+ {
+ "emoji": "🫦",
+ "aliases": [
+ "biting_lip"
+ ]
+ },
+ {
+ "emoji": "🐦⬛",
+ "aliases": [
+ "black_bird"
+ ]
+ },
+ {
+ "emoji": "🐈⬛",
+ "aliases": [
+ "black_cat"
+ ]
+ },
+ {
+ "emoji": "⚫",
+ "aliases": [
+ "black_circle"
+ ]
+ },
+ {
+ "emoji": "🏴",
+ "aliases": [
+ "black_flag"
+ ]
+ },
+ {
+ "emoji": "🖤",
+ "aliases": [
+ "black_heart"
+ ]
+ },
+ {
+ "emoji": "🃏",
+ "aliases": [
+ "black_joker"
+ ]
+ },
+ {
+ "emoji": "⬛",
+ "aliases": [
+ "black_large_square"
+ ]
+ },
+ {
+ "emoji": "◾",
+ "aliases": [
+ "black_medium_small_square"
+ ]
+ },
+ {
+ "emoji": "◼️",
+ "aliases": [
+ "black_medium_square"
+ ]
+ },
+ {
+ "emoji": "✒️",
+ "aliases": [
+ "black_nib"
+ ]
+ },
+ {
+ "emoji": "▪️",
+ "aliases": [
+ "black_small_square"
+ ]
+ },
+ {
+ "emoji": "🔲",
+ "aliases": [
+ "black_square_button"
+ ]
+ },
+ {
+ "emoji": "👱♂️",
+ "aliases": [
+ "blond_haired_man"
+ ]
+ },
+ {
+ "emoji": "👱",
+ "aliases": [
+ "blond_haired_person"
+ ]
+ },
+ {
+ "emoji": "👱♀️",
+ "aliases": [
+ "blond_haired_woman",
+ "blonde_woman"
+ ]
+ },
+ {
+ "emoji": "🌼",
+ "aliases": [
+ "blossom"
+ ]
+ },
+ {
+ "emoji": "🐡",
+ "aliases": [
+ "blowfish"
+ ]
+ },
+ {
+ "emoji": "📘",
+ "aliases": [
+ "blue_book"
+ ]
+ },
+ {
+ "emoji": "🚙",
+ "aliases": [
+ "blue_car"
+ ]
+ },
+ {
+ "emoji": "💙",
+ "aliases": [
+ "blue_heart"
+ ]
+ },
+ {
+ "emoji": "🟦",
+ "aliases": [
+ "blue_square"
+ ]
+ },
+ {
+ "emoji": "🫐",
+ "aliases": [
+ "blueberries"
+ ]
+ },
+ {
+ "emoji": "😊",
+ "aliases": [
+ "blush"
+ ]
+ },
+ {
+ "emoji": "🐗",
+ "aliases": [
+ "boar"
+ ]
+ },
+ {
+ "emoji": "⛵",
+ "aliases": [
+ "boat",
+ "sailboat"
+ ]
+ },
+ {
+ "emoji": "🇧🇴",
+ "aliases": [
+ "bolivia"
+ ]
+ },
+ {
+ "emoji": "💣",
+ "aliases": [
+ "bomb"
+ ]
+ },
+ {
+ "emoji": "🦴",
+ "aliases": [
+ "bone"
+ ]
+ },
+ {
+ "emoji": "📖",
+ "aliases": [
+ "book",
+ "open_book"
+ ]
+ },
+ {
+ "emoji": "🔖",
+ "aliases": [
+ "bookmark"
+ ]
+ },
+ {
+ "emoji": "📑",
+ "aliases": [
+ "bookmark_tabs"
+ ]
+ },
+ {
+ "emoji": "📚",
+ "aliases": [
+ "books"
+ ]
+ },
+ {
+ "emoji": "💥",
+ "aliases": [
+ "boom",
+ "collision"
+ ]
+ },
+ {
+ "emoji": "🪃",
+ "aliases": [
+ "boomerang"
+ ]
+ },
+ {
+ "emoji": "👢",
+ "aliases": [
+ "boot"
+ ]
+ },
+ {
+ "emoji": "🇧🇦",
+ "aliases": [
+ "bosnia_herzegovina"
+ ]
+ },
+ {
+ "emoji": "🇧🇼",
+ "aliases": [
+ "botswana"
+ ]
+ },
+ {
+ "emoji": "⛹️♂️",
+ "aliases": [
+ "bouncing_ball_man",
+ "basketball_man"
+ ]
+ },
+ {
+ "emoji": "⛹️",
+ "aliases": [
+ "bouncing_ball_person"
+ ]
+ },
+ {
+ "emoji": "⛹️♀️",
+ "aliases": [
+ "bouncing_ball_woman",
+ "basketball_woman"
+ ]
+ },
+ {
+ "emoji": "💐",
+ "aliases": [
+ "bouquet"
+ ]
+ },
+ {
+ "emoji": "🇧🇻",
+ "aliases": [
+ "bouvet_island"
+ ]
+ },
+ {
+ "emoji": "🙇",
+ "aliases": [
+ "bow"
+ ]
+ },
+ {
+ "emoji": "🏹",
+ "aliases": [
+ "bow_and_arrow"
+ ]
+ },
+ {
+ "emoji": "🙇♂️",
+ "aliases": [
+ "bowing_man"
+ ]
+ },
+ {
+ "emoji": "🙇♀️",
+ "aliases": [
+ "bowing_woman"
+ ]
+ },
+ {
+ "emoji": "🥣",
+ "aliases": [
+ "bowl_with_spoon"
+ ]
+ },
+ {
+ "emoji": "🎳",
+ "aliases": [
+ "bowling"
+ ]
+ },
+ {
+ "emoji": "🥊",
+ "aliases": [
+ "boxing_glove"
+ ]
+ },
+ {
+ "emoji": "👦",
+ "aliases": [
+ "boy"
+ ]
+ },
+ {
+ "emoji": "🧠",
+ "aliases": [
+ "brain"
+ ]
+ },
+ {
+ "emoji": "🇧🇷",
+ "aliases": [
+ "brazil"
+ ]
+ },
+ {
+ "emoji": "🍞",
+ "aliases": [
+ "bread"
+ ]
+ },
+ {
+ "emoji": "🤱",
+ "aliases": [
+ "breast_feeding"
+ ]
+ },
+ {
+ "emoji": "🧱",
+ "aliases": [
+ "bricks"
+ ]
+ },
+ {
+ "emoji": "🌉",
+ "aliases": [
+ "bridge_at_night"
+ ]
+ },
+ {
+ "emoji": "💼",
+ "aliases": [
+ "briefcase"
+ ]
+ },
+ {
+ "emoji": "🇮🇴",
+ "aliases": [
+ "british_indian_ocean_territory"
+ ]
+ },
+ {
+ "emoji": "🇻🇬",
+ "aliases": [
+ "british_virgin_islands"
+ ]
+ },
+ {
+ "emoji": "🥦",
+ "aliases": [
+ "broccoli"
+ ]
+ },
+ {
+ "emoji": "⛓️💥",
+ "aliases": [
+ "broken_chain"
+ ]
+ },
+ {
+ "emoji": "💔",
+ "aliases": [
+ "broken_heart"
+ ]
+ },
+ {
+ "emoji": "🧹",
+ "aliases": [
+ "broom"
+ ]
+ },
+ {
+ "emoji": "🟤",
+ "aliases": [
+ "brown_circle"
+ ]
+ },
+ {
+ "emoji": "🤎",
+ "aliases": [
+ "brown_heart"
+ ]
+ },
+ {
+ "emoji": "🍄🟫",
+ "aliases": [
+ "brown_mushroom"
+ ]
+ },
+ {
+ "emoji": "🟫",
+ "aliases": [
+ "brown_square"
+ ]
+ },
+ {
+ "emoji": "🇧🇳",
+ "aliases": [
+ "brunei"
+ ]
+ },
+ {
+ "emoji": "🧋",
+ "aliases": [
+ "bubble_tea"
+ ]
+ },
+ {
+ "emoji": "🫧",
+ "aliases": [
+ "bubbles"
+ ]
+ },
+ {
+ "emoji": "🪣",
+ "aliases": [
+ "bucket"
+ ]
+ },
+ {
+ "emoji": "🐛",
+ "aliases": [
+ "bug"
+ ]
+ },
+ {
+ "emoji": "🏗️",
+ "aliases": [
+ "building_construction"
+ ]
+ },
+ {
+ "emoji": "💡",
+ "aliases": [
+ "bulb"
+ ]
+ },
+ {
+ "emoji": "🇧🇬",
+ "aliases": [
+ "bulgaria"
+ ]
+ },
+ {
+ "emoji": "🚅",
+ "aliases": [
+ "bullettrain_front"
+ ]
+ },
+ {
+ "emoji": "🚄",
+ "aliases": [
+ "bullettrain_side"
+ ]
+ },
+ {
+ "emoji": "🇧🇫",
+ "aliases": [
+ "burkina_faso"
+ ]
+ },
+ {
+ "emoji": "🌯",
+ "aliases": [
+ "burrito"
+ ]
+ },
+ {
+ "emoji": "🇧🇮",
+ "aliases": [
+ "burundi"
+ ]
+ },
+ {
+ "emoji": "🚌",
+ "aliases": [
+ "bus"
+ ]
+ },
+ {
+ "emoji": "🕴️",
+ "aliases": [
+ "business_suit_levitating"
+ ]
+ },
+ {
+ "emoji": "🚏",
+ "aliases": [
+ "busstop"
+ ]
+ },
+ {
+ "emoji": "👤",
+ "aliases": [
+ "bust_in_silhouette"
+ ]
+ },
+ {
+ "emoji": "👥",
+ "aliases": [
+ "busts_in_silhouette"
+ ]
+ },
+ {
+ "emoji": "🧈",
+ "aliases": [
+ "butter"
+ ]
+ },
+ {
+ "emoji": "🦋",
+ "aliases": [
+ "butterfly"
+ ]
+ },
+ {
+ "emoji": "🌵",
+ "aliases": [
+ "cactus"
+ ]
+ },
+ {
+ "emoji": "🍰",
+ "aliases": [
+ "cake"
+ ]
+ },
+ {
+ "emoji": "📆",
+ "aliases": [
+ "calendar"
+ ]
+ },
+ {
+ "emoji": "🤙",
+ "aliases": [
+ "call_me_hand"
+ ]
+ },
+ {
+ "emoji": "📲",
+ "aliases": [
+ "calling"
+ ]
+ },
+ {
+ "emoji": "🇰🇭",
+ "aliases": [
+ "cambodia"
+ ]
+ },
+ {
+ "emoji": "🐫",
+ "aliases": [
+ "camel"
+ ]
+ },
+ {
+ "emoji": "📷",
+ "aliases": [
+ "camera"
+ ]
+ },
+ {
+ "emoji": "📸",
+ "aliases": [
+ "camera_flash"
+ ]
+ },
+ {
+ "emoji": "🇨🇲",
+ "aliases": [
+ "cameroon"
+ ]
+ },
+ {
+ "emoji": "🏕️",
+ "aliases": [
+ "camping"
+ ]
+ },
+ {
+ "emoji": "🇨🇦",
+ "aliases": [
+ "canada"
+ ]
+ },
+ {
+ "emoji": "🇮🇨",
+ "aliases": [
+ "canary_islands"
+ ]
+ },
+ {
+ "emoji": "♋",
+ "aliases": [
+ "cancer"
+ ]
+ },
+ {
+ "emoji": "🕯️",
+ "aliases": [
+ "candle"
+ ]
+ },
+ {
+ "emoji": "🍬",
+ "aliases": [
+ "candy"
+ ]
+ },
+ {
+ "emoji": "🥫",
+ "aliases": [
+ "canned_food"
+ ]
+ },
+ {
+ "emoji": "🛶",
+ "aliases": [
+ "canoe"
+ ]
+ },
+ {
+ "emoji": "🇨🇻",
+ "aliases": [
+ "cape_verde"
+ ]
+ },
+ {
+ "emoji": "🔠",
+ "aliases": [
+ "capital_abcd"
+ ]
+ },
+ {
+ "emoji": "♑",
+ "aliases": [
+ "capricorn"
+ ]
+ },
+ {
+ "emoji": "🚗",
+ "aliases": [
+ "car",
+ "red_car"
+ ]
+ },
+ {
+ "emoji": "🗃️",
+ "aliases": [
+ "card_file_box"
+ ]
+ },
+ {
+ "emoji": "📇",
+ "aliases": [
+ "card_index"
+ ]
+ },
+ {
+ "emoji": "🗂️",
+ "aliases": [
+ "card_index_dividers"
+ ]
+ },
+ {
+ "emoji": "🇧🇶",
+ "aliases": [
+ "caribbean_netherlands"
+ ]
+ },
+ {
+ "emoji": "🎠",
+ "aliases": [
+ "carousel_horse"
+ ]
+ },
+ {
+ "emoji": "🪚",
+ "aliases": [
+ "carpentry_saw"
+ ]
+ },
+ {
+ "emoji": "🥕",
+ "aliases": [
+ "carrot"
+ ]
+ },
+ {
+ "emoji": "🤸",
+ "aliases": [
+ "cartwheeling"
+ ]
+ },
+ {
+ "emoji": "🐱",
+ "aliases": [
+ "cat"
+ ]
+ },
+ {
+ "emoji": "🐈",
+ "aliases": [
+ "cat2"
+ ]
+ },
+ {
+ "emoji": "🇰🇾",
+ "aliases": [
+ "cayman_islands"
+ ]
+ },
+ {
+ "emoji": "💿",
+ "aliases": [
+ "cd"
+ ]
+ },
+ {
+ "emoji": "🇨🇫",
+ "aliases": [
+ "central_african_republic"
+ ]
+ },
+ {
+ "emoji": "🇪🇦",
+ "aliases": [
+ "ceuta_melilla"
+ ]
+ },
+ {
+ "emoji": "🇹🇩",
+ "aliases": [
+ "chad"
+ ]
+ },
+ {
+ "emoji": "⛓️",
+ "aliases": [
+ "chains"
+ ]
+ },
+ {
+ "emoji": "🪑",
+ "aliases": [
+ "chair"
+ ]
+ },
+ {
+ "emoji": "🍾",
+ "aliases": [
+ "champagne"
+ ]
+ },
+ {
+ "emoji": "💹",
+ "aliases": [
+ "chart"
+ ]
+ },
+ {
+ "emoji": "📉",
+ "aliases": [
+ "chart_with_downwards_trend"
+ ]
+ },
+ {
+ "emoji": "📈",
+ "aliases": [
+ "chart_with_upwards_trend"
+ ]
+ },
+ {
+ "emoji": "🏁",
+ "aliases": [
+ "checkered_flag"
+ ]
+ },
+ {
+ "emoji": "🧀",
+ "aliases": [
+ "cheese"
+ ]
+ },
+ {
+ "emoji": "🍒",
+ "aliases": [
+ "cherries"
+ ]
+ },
+ {
+ "emoji": "🌸",
+ "aliases": [
+ "cherry_blossom"
+ ]
+ },
+ {
+ "emoji": "♟️",
+ "aliases": [
+ "chess_pawn"
+ ]
+ },
+ {
+ "emoji": "🌰",
+ "aliases": [
+ "chestnut"
+ ]
+ },
+ {
+ "emoji": "🐔",
+ "aliases": [
+ "chicken"
+ ]
+ },
+ {
+ "emoji": "🧒",
+ "aliases": [
+ "child"
+ ]
+ },
+ {
+ "emoji": "🚸",
+ "aliases": [
+ "children_crossing"
+ ]
+ },
+ {
+ "emoji": "🇨🇱",
+ "aliases": [
+ "chile"
+ ]
+ },
+ {
+ "emoji": "🐿️",
+ "aliases": [
+ "chipmunk"
+ ]
+ },
+ {
+ "emoji": "🍫",
+ "aliases": [
+ "chocolate_bar"
+ ]
+ },
+ {
+ "emoji": "🥢",
+ "aliases": [
+ "chopsticks"
+ ]
+ },
+ {
+ "emoji": "🇨🇽",
+ "aliases": [
+ "christmas_island"
+ ]
+ },
+ {
+ "emoji": "🎄",
+ "aliases": [
+ "christmas_tree"
+ ]
+ },
+ {
+ "emoji": "⛪",
+ "aliases": [
+ "church"
+ ]
+ },
+ {
+ "emoji": "🎦",
+ "aliases": [
+ "cinema"
+ ]
+ },
+ {
+ "emoji": "🎪",
+ "aliases": [
+ "circus_tent"
+ ]
+ },
+ {
+ "emoji": "🌇",
+ "aliases": [
+ "city_sunrise"
+ ]
+ },
+ {
+ "emoji": "🌆",
+ "aliases": [
+ "city_sunset"
+ ]
+ },
+ {
+ "emoji": "🏙️",
+ "aliases": [
+ "cityscape"
+ ]
+ },
+ {
+ "emoji": "🆑",
+ "aliases": [
+ "cl"
+ ]
+ },
+ {
+ "emoji": "🗜️",
+ "aliases": [
+ "clamp"
+ ]
+ },
+ {
+ "emoji": "👏",
+ "aliases": [
+ "clap"
+ ]
+ },
+ {
+ "emoji": "🎬",
+ "aliases": [
+ "clapper"
+ ]
+ },
+ {
+ "emoji": "🏛️",
+ "aliases": [
+ "classical_building"
+ ]
+ },
+ {
+ "emoji": "🧗",
+ "aliases": [
+ "climbing"
+ ]
+ },
+ {
+ "emoji": "🧗♂️",
+ "aliases": [
+ "climbing_man"
+ ]
+ },
+ {
+ "emoji": "🧗♀️",
+ "aliases": [
+ "climbing_woman"
+ ]
+ },
+ {
+ "emoji": "🥂",
+ "aliases": [
+ "clinking_glasses"
+ ]
+ },
+ {
+ "emoji": "📋",
+ "aliases": [
+ "clipboard"
+ ]
+ },
+ {
+ "emoji": "🇨🇵",
+ "aliases": [
+ "clipperton_island"
+ ]
+ },
+ {
+ "emoji": "🕐",
+ "aliases": [
+ "clock1"
+ ]
+ },
+ {
+ "emoji": "🕙",
+ "aliases": [
+ "clock10"
+ ]
+ },
+ {
+ "emoji": "🕥",
+ "aliases": [
+ "clock1030"
+ ]
+ },
+ {
+ "emoji": "🕚",
+ "aliases": [
+ "clock11"
+ ]
+ },
+ {
+ "emoji": "🕦",
+ "aliases": [
+ "clock1130"
+ ]
+ },
+ {
+ "emoji": "🕛",
+ "aliases": [
+ "clock12"
+ ]
+ },
+ {
+ "emoji": "🕧",
+ "aliases": [
+ "clock1230"
+ ]
+ },
+ {
+ "emoji": "🕜",
+ "aliases": [
+ "clock130"
+ ]
+ },
+ {
+ "emoji": "🕑",
+ "aliases": [
+ "clock2"
+ ]
+ },
+ {
+ "emoji": "🕝",
+ "aliases": [
+ "clock230"
+ ]
+ },
+ {
+ "emoji": "🕒",
+ "aliases": [
+ "clock3"
+ ]
+ },
+ {
+ "emoji": "🕞",
+ "aliases": [
+ "clock330"
+ ]
+ },
+ {
+ "emoji": "🕓",
+ "aliases": [
+ "clock4"
+ ]
+ },
+ {
+ "emoji": "🕟",
+ "aliases": [
+ "clock430"
+ ]
+ },
+ {
+ "emoji": "🕔",
+ "aliases": [
+ "clock5"
+ ]
+ },
+ {
+ "emoji": "🕠",
+ "aliases": [
+ "clock530"
+ ]
+ },
+ {
+ "emoji": "🕕",
+ "aliases": [
+ "clock6"
+ ]
+ },
+ {
+ "emoji": "🕡",
+ "aliases": [
+ "clock630"
+ ]
+ },
+ {
+ "emoji": "🕖",
+ "aliases": [
+ "clock7"
+ ]
+ },
+ {
+ "emoji": "🕢",
+ "aliases": [
+ "clock730"
+ ]
+ },
+ {
+ "emoji": "🕗",
+ "aliases": [
+ "clock8"
+ ]
+ },
+ {
+ "emoji": "🕣",
+ "aliases": [
+ "clock830"
+ ]
+ },
+ {
+ "emoji": "🕘",
+ "aliases": [
+ "clock9"
+ ]
+ },
+ {
+ "emoji": "🕤",
+ "aliases": [
+ "clock930"
+ ]
+ },
+ {
+ "emoji": "📕",
+ "aliases": [
+ "closed_book"
+ ]
+ },
+ {
+ "emoji": "🔐",
+ "aliases": [
+ "closed_lock_with_key"
+ ]
+ },
+ {
+ "emoji": "🌂",
+ "aliases": [
+ "closed_umbrella"
+ ]
+ },
+ {
+ "emoji": "☁️",
+ "aliases": [
+ "cloud"
+ ]
+ },
+ {
+ "emoji": "🌩️",
+ "aliases": [
+ "cloud_with_lightning"
+ ]
+ },
+ {
+ "emoji": "⛈️",
+ "aliases": [
+ "cloud_with_lightning_and_rain"
+ ]
+ },
+ {
+ "emoji": "🌧️",
+ "aliases": [
+ "cloud_with_rain"
+ ]
+ },
+ {
+ "emoji": "🌨️",
+ "aliases": [
+ "cloud_with_snow"
+ ]
+ },
+ {
+ "emoji": "🤡",
+ "aliases": [
+ "clown_face"
+ ]
+ },
+ {
+ "emoji": "♣️",
+ "aliases": [
+ "clubs"
+ ]
+ },
+ {
+ "emoji": "🇨🇳",
+ "aliases": [
+ "cn"
+ ]
+ },
+ {
+ "emoji": "🧥",
+ "aliases": [
+ "coat"
+ ]
+ },
+ {
+ "emoji": "🪳",
+ "aliases": [
+ "cockroach"
+ ]
+ },
+ {
+ "emoji": "🍸",
+ "aliases": [
+ "cocktail"
+ ]
+ },
+ {
+ "emoji": "🥥",
+ "aliases": [
+ "coconut"
+ ]
+ },
+ {
+ "emoji": "🇨🇨",
+ "aliases": [
+ "cocos_islands"
+ ]
+ },
+ {
+ "emoji": "☕",
+ "aliases": [
+ "coffee"
+ ]
+ },
+ {
+ "emoji": "⚰️",
+ "aliases": [
+ "coffin"
+ ]
+ },
+ {
+ "emoji": "🪙",
+ "aliases": [
+ "coin"
+ ]
+ },
+ {
+ "emoji": "🥶",
+ "aliases": [
+ "cold_face"
+ ]
+ },
+ {
+ "emoji": "😰",
+ "aliases": [
+ "cold_sweat"
+ ]
+ },
+ {
+ "emoji": "🇨🇴",
+ "aliases": [
+ "colombia"
+ ]
+ },
+ {
+ "emoji": "☄️",
+ "aliases": [
+ "comet"
+ ]
+ },
+ {
+ "emoji": "🇰🇲",
+ "aliases": [
+ "comoros"
+ ]
+ },
+ {
+ "emoji": "🧭",
+ "aliases": [
+ "compass"
+ ]
+ },
+ {
+ "emoji": "💻",
+ "aliases": [
+ "computer"
+ ]
+ },
+ {
+ "emoji": "🖱️",
+ "aliases": [
+ "computer_mouse"
+ ]
+ },
+ {
+ "emoji": "🎊",
+ "aliases": [
+ "confetti_ball"
+ ]
+ },
+ {
+ "emoji": "😖",
+ "aliases": [
+ "confounded"
+ ]
+ },
+ {
+ "emoji": "😕",
+ "aliases": [
+ "confused"
+ ]
+ },
+ {
+ "emoji": "🇨🇬",
+ "aliases": [
+ "congo_brazzaville"
+ ]
+ },
+ {
+ "emoji": "🇨🇩",
+ "aliases": [
+ "congo_kinshasa"
+ ]
+ },
+ {
+ "emoji": "㊗️",
+ "aliases": [
+ "congratulations"
+ ]
+ },
+ {
+ "emoji": "🚧",
+ "aliases": [
+ "construction"
+ ]
+ },
+ {
+ "emoji": "👷",
+ "aliases": [
+ "construction_worker"
+ ]
+ },
+ {
+ "emoji": "👷♂️",
+ "aliases": [
+ "construction_worker_man"
+ ]
+ },
+ {
+ "emoji": "👷♀️",
+ "aliases": [
+ "construction_worker_woman"
+ ]
+ },
+ {
+ "emoji": "🎛️",
+ "aliases": [
+ "control_knobs"
+ ]
+ },
+ {
+ "emoji": "🏪",
+ "aliases": [
+ "convenience_store"
+ ]
+ },
+ {
+ "emoji": "🧑🍳",
+ "aliases": [
+ "cook"
+ ]
+ },
+ {
+ "emoji": "🇨🇰",
+ "aliases": [
+ "cook_islands"
+ ]
+ },
+ {
+ "emoji": "🍪",
+ "aliases": [
+ "cookie"
+ ]
+ },
+ {
+ "emoji": "🆒",
+ "aliases": [
+ "cool"
+ ]
+ },
+ {
+ "emoji": "©️",
+ "aliases": [
+ "copyright"
+ ]
+ },
+ {
+ "emoji": "🪸",
+ "aliases": [
+ "coral"
+ ]
+ },
+ {
+ "emoji": "🌽",
+ "aliases": [
+ "corn"
+ ]
+ },
+ {
+ "emoji": "🇨🇷",
+ "aliases": [
+ "costa_rica"
+ ]
+ },
+ {
+ "emoji": "🇨🇮",
+ "aliases": [
+ "cote_divoire"
+ ]
+ },
+ {
+ "emoji": "🛋️",
+ "aliases": [
+ "couch_and_lamp"
+ ]
+ },
+ {
+ "emoji": "👫",
+ "aliases": [
+ "couple"
+ ]
+ },
+ {
+ "emoji": "💑",
+ "aliases": [
+ "couple_with_heart"
+ ]
+ },
+ {
+ "emoji": "👨❤️👨",
+ "aliases": [
+ "couple_with_heart_man_man"
+ ]
+ },
+ {
+ "emoji": "👩❤️👨",
+ "aliases": [
+ "couple_with_heart_woman_man"
+ ]
+ },
+ {
+ "emoji": "👩❤️👩",
+ "aliases": [
+ "couple_with_heart_woman_woman"
+ ]
+ },
+ {
+ "emoji": "💏",
+ "aliases": [
+ "couplekiss"
+ ]
+ },
+ {
+ "emoji": "👨❤️💋👨",
+ "aliases": [
+ "couplekiss_man_man"
+ ]
+ },
+ {
+ "emoji": "👩❤️💋👨",
+ "aliases": [
+ "couplekiss_man_woman"
+ ]
+ },
+ {
+ "emoji": "👩❤️💋👩",
+ "aliases": [
+ "couplekiss_woman_woman"
+ ]
+ },
+ {
+ "emoji": "🐮",
+ "aliases": [
+ "cow"
+ ]
+ },
+ {
+ "emoji": "🐄",
+ "aliases": [
+ "cow2"
+ ]
+ },
+ {
+ "emoji": "🤠",
+ "aliases": [
+ "cowboy_hat_face"
+ ]
+ },
+ {
+ "emoji": "🦀",
+ "aliases": [
+ "crab"
+ ]
+ },
+ {
+ "emoji": "🖍️",
+ "aliases": [
+ "crayon"
+ ]
+ },
+ {
+ "emoji": "💳",
+ "aliases": [
+ "credit_card"
+ ]
+ },
+ {
+ "emoji": "🌙",
+ "aliases": [
+ "crescent_moon"
+ ]
+ },
+ {
+ "emoji": "🦗",
+ "aliases": [
+ "cricket"
+ ]
+ },
+ {
+ "emoji": "🏏",
+ "aliases": [
+ "cricket_game"
+ ]
+ },
+ {
+ "emoji": "🇭🇷",
+ "aliases": [
+ "croatia"
+ ]
+ },
+ {
+ "emoji": "🐊",
+ "aliases": [
+ "crocodile"
+ ]
+ },
+ {
+ "emoji": "🥐",
+ "aliases": [
+ "croissant"
+ ]
+ },
+ {
+ "emoji": "🤞",
+ "aliases": [
+ "crossed_fingers"
+ ]
+ },
+ {
+ "emoji": "🎌",
+ "aliases": [
+ "crossed_flags"
+ ]
+ },
+ {
+ "emoji": "⚔️",
+ "aliases": [
+ "crossed_swords"
+ ]
+ },
+ {
+ "emoji": "👑",
+ "aliases": [
+ "crown"
+ ]
+ },
+ {
+ "emoji": "🩼",
+ "aliases": [
+ "crutch"
+ ]
+ },
+ {
+ "emoji": "😢",
+ "aliases": [
+ "cry"
+ ]
+ },
+ {
+ "emoji": "😿",
+ "aliases": [
+ "crying_cat_face"
+ ]
+ },
+ {
+ "emoji": "🔮",
+ "aliases": [
+ "crystal_ball"
+ ]
+ },
+ {
+ "emoji": "🇨🇺",
+ "aliases": [
+ "cuba"
+ ]
+ },
+ {
+ "emoji": "🥒",
+ "aliases": [
+ "cucumber"
+ ]
+ },
+ {
+ "emoji": "🥤",
+ "aliases": [
+ "cup_with_straw"
+ ]
+ },
+ {
+ "emoji": "🧁",
+ "aliases": [
+ "cupcake"
+ ]
+ },
+ {
+ "emoji": "💘",
+ "aliases": [
+ "cupid"
+ ]
+ },
+ {
+ "emoji": "🇨🇼",
+ "aliases": [
+ "curacao"
+ ]
+ },
+ {
+ "emoji": "🥌",
+ "aliases": [
+ "curling_stone"
+ ]
+ },
+ {
+ "emoji": "👨🦱",
+ "aliases": [
+ "curly_haired_man"
+ ]
+ },
+ {
+ "emoji": "👩🦱",
+ "aliases": [
+ "curly_haired_woman"
+ ]
+ },
+ {
+ "emoji": "➰",
+ "aliases": [
+ "curly_loop"
+ ]
+ },
+ {
+ "emoji": "💱",
+ "aliases": [
+ "currency_exchange"
+ ]
+ },
+ {
+ "emoji": "🍛",
+ "aliases": [
+ "curry"
+ ]
+ },
+ {
+ "emoji": "🤬",
+ "aliases": [
+ "cursing_face"
+ ]
+ },
+ {
+ "emoji": "🍮",
+ "aliases": [
+ "custard"
+ ]
+ },
+ {
+ "emoji": "🛃",
+ "aliases": [
+ "customs"
+ ]
+ },
+ {
+ "emoji": "🥩",
+ "aliases": [
+ "cut_of_meat"
+ ]
+ },
+ {
+ "emoji": "🌀",
+ "aliases": [
+ "cyclone"
+ ]
+ },
+ {
+ "emoji": "🇨🇾",
+ "aliases": [
+ "cyprus"
+ ]
+ },
+ {
+ "emoji": "🇨🇿",
+ "aliases": [
+ "czech_republic"
+ ]
+ },
+ {
+ "emoji": "🗡️",
+ "aliases": [
+ "dagger"
+ ]
+ },
+ {
+ "emoji": "👯",
+ "aliases": [
+ "dancers"
+ ]
+ },
+ {
+ "emoji": "👯♂️",
+ "aliases": [
+ "dancing_men"
+ ]
+ },
+ {
+ "emoji": "👯♀️",
+ "aliases": [
+ "dancing_women"
+ ]
+ },
+ {
+ "emoji": "🍡",
+ "aliases": [
+ "dango"
+ ]
+ },
+ {
+ "emoji": "🕶️",
+ "aliases": [
+ "dark_sunglasses"
+ ]
+ },
+ {
+ "emoji": "🎯",
+ "aliases": [
+ "dart"
+ ]
+ },
+ {
+ "emoji": "💨",
+ "aliases": [
+ "dash"
+ ]
+ },
+ {
+ "emoji": "📅",
+ "aliases": [
+ "date"
+ ]
+ },
+ {
+ "emoji": "🇩🇪",
+ "aliases": [
+ "de"
+ ]
+ },
+ {
+ "emoji": "🧏♂️",
+ "aliases": [
+ "deaf_man"
+ ]
+ },
+ {
+ "emoji": "🧏",
+ "aliases": [
+ "deaf_person"
+ ]
+ },
+ {
+ "emoji": "🧏♀️",
+ "aliases": [
+ "deaf_woman"
+ ]
+ },
+ {
+ "emoji": "🌳",
+ "aliases": [
+ "deciduous_tree"
+ ]
+ },
+ {
+ "emoji": "🦌",
+ "aliases": [
+ "deer"
+ ]
+ },
+ {
+ "emoji": "🇩🇰",
+ "aliases": [
+ "denmark"
+ ]
+ },
+ {
+ "emoji": "🏬",
+ "aliases": [
+ "department_store"
+ ]
+ },
+ {
+ "emoji": "🏚️",
+ "aliases": [
+ "derelict_house"
+ ]
+ },
+ {
+ "emoji": "🏜️",
+ "aliases": [
+ "desert"
+ ]
+ },
+ {
+ "emoji": "🏝️",
+ "aliases": [
+ "desert_island"
+ ]
+ },
+ {
+ "emoji": "🖥️",
+ "aliases": [
+ "desktop_computer"
+ ]
+ },
+ {
+ "emoji": "🕵️",
+ "aliases": [
+ "detective"
+ ]
+ },
+ {
+ "emoji": "💠",
+ "aliases": [
+ "diamond_shape_with_a_dot_inside"
+ ]
+ },
+ {
+ "emoji": "♦️",
+ "aliases": [
+ "diamonds"
+ ]
+ },
+ {
+ "emoji": "🇩🇬",
+ "aliases": [
+ "diego_garcia"
+ ]
+ },
+ {
+ "emoji": "😞",
+ "aliases": [
+ "disappointed"
+ ]
+ },
+ {
+ "emoji": "😥",
+ "aliases": [
+ "disappointed_relieved"
+ ]
+ },
+ {
+ "emoji": "🥸",
+ "aliases": [
+ "disguised_face"
+ ]
+ },
+ {
+ "emoji": "🤿",
+ "aliases": [
+ "diving_mask"
+ ]
+ },
+ {
+ "emoji": "🪔",
+ "aliases": [
+ "diya_lamp"
+ ]
+ },
+ {
+ "emoji": "💫",
+ "aliases": [
+ "dizzy"
+ ]
+ },
+ {
+ "emoji": "😵",
+ "aliases": [
+ "dizzy_face"
+ ]
+ },
+ {
+ "emoji": "🇩🇯",
+ "aliases": [
+ "djibouti"
+ ]
+ },
+ {
+ "emoji": "🧬",
+ "aliases": [
+ "dna"
+ ]
+ },
+ {
+ "emoji": "🚯",
+ "aliases": [
+ "do_not_litter"
+ ]
+ },
+ {
+ "emoji": "🦤",
+ "aliases": [
+ "dodo"
+ ]
+ },
+ {
+ "emoji": "🐶",
+ "aliases": [
+ "dog"
+ ]
+ },
+ {
+ "emoji": "🐕",
+ "aliases": [
+ "dog2"
+ ]
+ },
+ {
+ "emoji": "💵",
+ "aliases": [
+ "dollar"
+ ]
+ },
+ {
+ "emoji": "🎎",
+ "aliases": [
+ "dolls"
+ ]
+ },
+ {
+ "emoji": "🐬",
+ "aliases": [
+ "dolphin",
+ "flipper"
+ ]
+ },
+ {
+ "emoji": "🇩🇲",
+ "aliases": [
+ "dominica"
+ ]
+ },
+ {
+ "emoji": "🇩🇴",
+ "aliases": [
+ "dominican_republic"
+ ]
+ },
+ {
+ "emoji": "🫏",
+ "aliases": [
+ "donkey"
+ ]
+ },
+ {
+ "emoji": "🚪",
+ "aliases": [
+ "door"
+ ]
+ },
+ {
+ "emoji": "🫥",
+ "aliases": [
+ "dotted_line_face"
+ ]
+ },
+ {
+ "emoji": "🍩",
+ "aliases": [
+ "doughnut"
+ ]
+ },
+ {
+ "emoji": "🕊️",
+ "aliases": [
+ "dove"
+ ]
+ },
+ {
+ "emoji": "🐉",
+ "aliases": [
+ "dragon"
+ ]
+ },
+ {
+ "emoji": "🐲",
+ "aliases": [
+ "dragon_face"
+ ]
+ },
+ {
+ "emoji": "👗",
+ "aliases": [
+ "dress"
+ ]
+ },
+ {
+ "emoji": "🐪",
+ "aliases": [
+ "dromedary_camel"
+ ]
+ },
+ {
+ "emoji": "🤤",
+ "aliases": [
+ "drooling_face"
+ ]
+ },
+ {
+ "emoji": "🩸",
+ "aliases": [
+ "drop_of_blood"
+ ]
+ },
+ {
+ "emoji": "💧",
+ "aliases": [
+ "droplet"
+ ]
+ },
+ {
+ "emoji": "🥁",
+ "aliases": [
+ "drum"
+ ]
+ },
+ {
+ "emoji": "🦆",
+ "aliases": [
+ "duck"
+ ]
+ },
+ {
+ "emoji": "🥟",
+ "aliases": [
+ "dumpling"
+ ]
+ },
+ {
+ "emoji": "📀",
+ "aliases": [
+ "dvd"
+ ]
+ },
+ {
+ "emoji": "🦅",
+ "aliases": [
+ "eagle"
+ ]
+ },
+ {
+ "emoji": "👂",
+ "aliases": [
+ "ear"
+ ]
+ },
+ {
+ "emoji": "🌾",
+ "aliases": [
+ "ear_of_rice"
+ ]
+ },
+ {
+ "emoji": "🦻",
+ "aliases": [
+ "ear_with_hearing_aid"
+ ]
+ },
+ {
+ "emoji": "🌍",
+ "aliases": [
+ "earth_africa"
+ ]
+ },
+ {
+ "emoji": "🌎",
+ "aliases": [
+ "earth_americas"
+ ]
+ },
+ {
+ "emoji": "🌏",
+ "aliases": [
+ "earth_asia"
+ ]
+ },
+ {
+ "emoji": "🇪🇨",
+ "aliases": [
+ "ecuador"
+ ]
+ },
+ {
+ "emoji": "🥚",
+ "aliases": [
+ "egg"
+ ]
+ },
+ {
+ "emoji": "🍆",
+ "aliases": [
+ "eggplant"
+ ]
+ },
+ {
+ "emoji": "🇪🇬",
+ "aliases": [
+ "egypt"
+ ]
+ },
+ {
+ "emoji": "8️⃣",
+ "aliases": [
+ "eight"
+ ]
+ },
+ {
+ "emoji": "✴️",
+ "aliases": [
+ "eight_pointed_black_star"
+ ]
+ },
+ {
+ "emoji": "✳️",
+ "aliases": [
+ "eight_spoked_asterisk"
+ ]
+ },
+ {
+ "emoji": "⏏️",
+ "aliases": [
+ "eject_button"
+ ]
+ },
+ {
+ "emoji": "🇸🇻",
+ "aliases": [
+ "el_salvador"
+ ]
+ },
+ {
+ "emoji": "🔌",
+ "aliases": [
+ "electric_plug"
+ ]
+ },
+ {
+ "emoji": "🐘",
+ "aliases": [
+ "elephant"
+ ]
+ },
+ {
+ "emoji": "🛗",
+ "aliases": [
+ "elevator"
+ ]
+ },
+ {
+ "emoji": "🧝",
+ "aliases": [
+ "elf"
+ ]
+ },
+ {
+ "emoji": "🧝♂️",
+ "aliases": [
+ "elf_man"
+ ]
+ },
+ {
+ "emoji": "🧝♀️",
+ "aliases": [
+ "elf_woman"
+ ]
+ },
+ {
+ "emoji": "📧",
+ "aliases": [
+ "email",
+ "e-mail"
+ ]
+ },
+ {
+ "emoji": "🪹",
+ "aliases": [
+ "empty_nest"
+ ]
+ },
+ {
+ "emoji": "🔚",
+ "aliases": [
+ "end"
+ ]
+ },
+ {
+ "emoji": "🏴",
+ "aliases": [
+ "england"
+ ]
+ },
+ {
+ "emoji": "✉️",
+ "aliases": [
+ "envelope"
+ ]
+ },
+ {
+ "emoji": "📩",
+ "aliases": [
+ "envelope_with_arrow"
+ ]
+ },
+ {
+ "emoji": "🇬🇶",
+ "aliases": [
+ "equatorial_guinea"
+ ]
+ },
+ {
+ "emoji": "🇪🇷",
+ "aliases": [
+ "eritrea"
+ ]
+ },
+ {
+ "emoji": "🇪🇸",
+ "aliases": [
+ "es"
+ ]
+ },
+ {
+ "emoji": "🇪🇪",
+ "aliases": [
+ "estonia"
+ ]
+ },
+ {
+ "emoji": "🇪🇹",
+ "aliases": [
+ "ethiopia"
+ ]
+ },
+ {
+ "emoji": "🇪🇺",
+ "aliases": [
+ "eu",
+ "european_union"
+ ]
+ },
+ {
+ "emoji": "💶",
+ "aliases": [
+ "euro"
+ ]
+ },
+ {
+ "emoji": "🏰",
+ "aliases": [
+ "european_castle"
+ ]
+ },
+ {
+ "emoji": "🏤",
+ "aliases": [
+ "european_post_office"
+ ]
+ },
+ {
+ "emoji": "🌲",
+ "aliases": [
+ "evergreen_tree"
+ ]
+ },
+ {
+ "emoji": "❗",
+ "aliases": [
+ "exclamation",
+ "heavy_exclamation_mark"
+ ]
+ },
+ {
+ "emoji": "🤯",
+ "aliases": [
+ "exploding_head"
+ ]
+ },
+ {
+ "emoji": "😑",
+ "aliases": [
+ "expressionless"
+ ]
+ },
+ {
+ "emoji": "👁️",
+ "aliases": [
+ "eye"
+ ]
+ },
+ {
+ "emoji": "👁️🗨️",
+ "aliases": [
+ "eye_speech_bubble"
+ ]
+ },
+ {
+ "emoji": "👓",
+ "aliases": [
+ "eyeglasses"
+ ]
+ },
+ {
+ "emoji": "👀",
+ "aliases": [
+ "eyes"
+ ]
+ },
+ {
+ "emoji": "😮💨",
+ "aliases": [
+ "face_exhaling"
+ ]
+ },
+ {
+ "emoji": "🥹",
+ "aliases": [
+ "face_holding_back_tears"
+ ]
+ },
+ {
+ "emoji": "😶🌫️",
+ "aliases": [
+ "face_in_clouds"
+ ]
+ },
+ {
+ "emoji": "",
+ "aliases": [
+ "face_with_bags_under_eyes"
+ ]
+ },
+ {
+ "emoji": "🫤",
+ "aliases": [
+ "face_with_diagonal_mouth"
+ ]
+ },
+ {
+ "emoji": "🤕",
+ "aliases": [
+ "face_with_head_bandage"
+ ]
+ },
+ {
+ "emoji": "🫢",
+ "aliases": [
+ "face_with_open_eyes_and_hand_over_mouth"
+ ]
+ },
+ {
+ "emoji": "🫣",
+ "aliases": [
+ "face_with_peeking_eye"
+ ]
+ },
+ {
+ "emoji": "😵💫",
+ "aliases": [
+ "face_with_spiral_eyes"
+ ]
+ },
+ {
+ "emoji": "🤒",
+ "aliases": [
+ "face_with_thermometer"
+ ]
+ },
+ {
+ "emoji": "🤦",
+ "aliases": [
+ "facepalm"
+ ]
+ },
+ {
+ "emoji": "🏭",
+ "aliases": [
+ "factory"
+ ]
+ },
+ {
+ "emoji": "🧑🏭",
+ "aliases": [
+ "factory_worker"
+ ]
+ },
+ {
+ "emoji": "🧚",
+ "aliases": [
+ "fairy"
+ ]
+ },
+ {
+ "emoji": "🧚♂️",
+ "aliases": [
+ "fairy_man"
+ ]
+ },
+ {
+ "emoji": "🧚♀️",
+ "aliases": [
+ "fairy_woman"
+ ]
+ },
+ {
+ "emoji": "🧆",
+ "aliases": [
+ "falafel"
+ ]
+ },
+ {
+ "emoji": "🇫🇰",
+ "aliases": [
+ "falkland_islands"
+ ]
+ },
+ {
+ "emoji": "🍂",
+ "aliases": [
+ "fallen_leaf"
+ ]
+ },
+ {
+ "emoji": "👪",
+ "aliases": [
+ "family"
+ ]
+ },
+ {
+ "emoji": "🧑🧑🧒",
+ "aliases": [
+ "family_adult_adult_child"
+ ]
+ },
+ {
+ "emoji": "🧑🧑🧒🧒",
+ "aliases": [
+ "family_adult_adult_child_child"
+ ]
+ },
+ {
+ "emoji": "🧑🧒",
+ "aliases": [
+ "family_adult_child"
+ ]
+ },
+ {
+ "emoji": "🧑🧒🧒",
+ "aliases": [
+ "family_adult_child_child"
+ ]
+ },
+ {
+ "emoji": "👨👦",
+ "aliases": [
+ "family_man_boy"
+ ]
+ },
+ {
+ "emoji": "👨👦👦",
+ "aliases": [
+ "family_man_boy_boy"
+ ]
+ },
+ {
+ "emoji": "👨👧",
+ "aliases": [
+ "family_man_girl"
+ ]
+ },
+ {
+ "emoji": "👨👧👦",
+ "aliases": [
+ "family_man_girl_boy"
+ ]
+ },
+ {
+ "emoji": "👨👧👧",
+ "aliases": [
+ "family_man_girl_girl"
+ ]
+ },
+ {
+ "emoji": "👨👨👦",
+ "aliases": [
+ "family_man_man_boy"
+ ]
+ },
+ {
+ "emoji": "👨👨👦👦",
+ "aliases": [
+ "family_man_man_boy_boy"
+ ]
+ },
+ {
+ "emoji": "👨👨👧",
+ "aliases": [
+ "family_man_man_girl"
+ ]
+ },
+ {
+ "emoji": "👨👨👧👦",
+ "aliases": [
+ "family_man_man_girl_boy"
+ ]
+ },
+ {
+ "emoji": "👨👨👧👧",
+ "aliases": [
+ "family_man_man_girl_girl"
+ ]
+ },
+ {
+ "emoji": "👨👩👦",
+ "aliases": [
+ "family_man_woman_boy"
+ ]
+ },
+ {
+ "emoji": "👨👩👦👦",
+ "aliases": [
+ "family_man_woman_boy_boy"
+ ]
+ },
+ {
+ "emoji": "👨👩👧",
+ "aliases": [
+ "family_man_woman_girl"
+ ]
+ },
+ {
+ "emoji": "👨👩👧👦",
+ "aliases": [
+ "family_man_woman_girl_boy"
+ ]
+ },
+ {
+ "emoji": "👨👩👧👧",
+ "aliases": [
+ "family_man_woman_girl_girl"
+ ]
+ },
+ {
+ "emoji": "👩👦",
+ "aliases": [
+ "family_woman_boy"
+ ]
+ },
+ {
+ "emoji": "👩👦👦",
+ "aliases": [
+ "family_woman_boy_boy"
+ ]
+ },
+ {
+ "emoji": "👩👧",
+ "aliases": [
+ "family_woman_girl"
+ ]
+ },
+ {
+ "emoji": "👩👧👦",
+ "aliases": [
+ "family_woman_girl_boy"
+ ]
+ },
+ {
+ "emoji": "👩👧👧",
+ "aliases": [
+ "family_woman_girl_girl"
+ ]
+ },
+ {
+ "emoji": "👩👩👦",
+ "aliases": [
+ "family_woman_woman_boy"
+ ]
+ },
+ {
+ "emoji": "👩👩👦👦",
+ "aliases": [
+ "family_woman_woman_boy_boy"
+ ]
+ },
+ {
+ "emoji": "👩👩👧",
+ "aliases": [
+ "family_woman_woman_girl"
+ ]
+ },
+ {
+ "emoji": "👩👩👧👦",
+ "aliases": [
+ "family_woman_woman_girl_boy"
+ ]
+ },
+ {
+ "emoji": "👩👩👧👧",
+ "aliases": [
+ "family_woman_woman_girl_girl"
+ ]
+ },
+ {
+ "emoji": "🧑🌾",
+ "aliases": [
+ "farmer"
+ ]
+ },
+ {
+ "emoji": "🇫🇴",
+ "aliases": [
+ "faroe_islands"
+ ]
+ },
+ {
+ "emoji": "⏩",
+ "aliases": [
+ "fast_forward"
+ ]
+ },
+ {
+ "emoji": "📠",
+ "aliases": [
+ "fax"
+ ]
+ },
+ {
+ "emoji": "😨",
+ "aliases": [
+ "fearful"
+ ]
+ },
+ {
+ "emoji": "🪶",
+ "aliases": [
+ "feather"
+ ]
+ },
+ {
+ "emoji": "🐾",
+ "aliases": [
+ "feet",
+ "paw_prints"
+ ]
+ },
+ {
+ "emoji": "🕵️♀️",
+ "aliases": [
+ "female_detective"
+ ]
+ },
+ {
+ "emoji": "♀️",
+ "aliases": [
+ "female_sign"
+ ]
+ },
+ {
+ "emoji": "🎡",
+ "aliases": [
+ "ferris_wheel"
+ ]
+ },
+ {
+ "emoji": "⛴️",
+ "aliases": [
+ "ferry"
+ ]
+ },
+ {
+ "emoji": "🏑",
+ "aliases": [
+ "field_hockey"
+ ]
+ },
+ {
+ "emoji": "🇫🇯",
+ "aliases": [
+ "fiji"
+ ]
+ },
+ {
+ "emoji": "🗄️",
+ "aliases": [
+ "file_cabinet"
+ ]
+ },
+ {
+ "emoji": "📁",
+ "aliases": [
+ "file_folder"
+ ]
+ },
+ {
+ "emoji": "📽️",
+ "aliases": [
+ "film_projector"
+ ]
+ },
+ {
+ "emoji": "🎞️",
+ "aliases": [
+ "film_strip"
+ ]
+ },
+ {
+ "emoji": "",
+ "aliases": [
+ "fingerprint"
+ ]
+ },
+ {
+ "emoji": "🇫🇮",
+ "aliases": [
+ "finland"
+ ]
+ },
+ {
+ "emoji": "🔥",
+ "aliases": [
+ "fire"
+ ]
+ },
+ {
+ "emoji": "🚒",
+ "aliases": [
+ "fire_engine"
+ ]
+ },
+ {
+ "emoji": "🧯",
+ "aliases": [
+ "fire_extinguisher"
+ ]
+ },
+ {
+ "emoji": "🧨",
+ "aliases": [
+ "firecracker"
+ ]
+ },
+ {
+ "emoji": "🧑🚒",
+ "aliases": [
+ "firefighter"
+ ]
+ },
+ {
+ "emoji": "🎆",
+ "aliases": [
+ "fireworks"
+ ]
+ },
+ {
+ "emoji": "🌓",
+ "aliases": [
+ "first_quarter_moon"
+ ]
+ },
+ {
+ "emoji": "🌛",
+ "aliases": [
+ "first_quarter_moon_with_face"
+ ]
+ },
+ {
+ "emoji": "🐟",
+ "aliases": [
+ "fish"
+ ]
+ },
+ {
+ "emoji": "🍥",
+ "aliases": [
+ "fish_cake"
+ ]
+ },
+ {
+ "emoji": "🎣",
+ "aliases": [
+ "fishing_pole_and_fish"
+ ]
+ },
+ {
+ "emoji": "🤛",
+ "aliases": [
+ "fist_left"
+ ]
+ },
+ {
+ "emoji": "👊",
+ "aliases": [
+ "fist_oncoming",
+ "facepunch",
+ "punch"
+ ]
+ },
+ {
+ "emoji": "✊",
+ "aliases": [
+ "fist_raised",
+ "fist"
+ ]
+ },
+ {
+ "emoji": "🤜",
+ "aliases": [
+ "fist_right"
+ ]
+ },
+ {
+ "emoji": "5️⃣",
+ "aliases": [
+ "five"
+ ]
+ },
+ {
+ "emoji": "🇨🇶",
+ "aliases": [
+ "flag_sark"
+ ]
+ },
+ {
+ "emoji": "🎏",
+ "aliases": [
+ "flags"
+ ]
+ },
+ {
+ "emoji": "🦩",
+ "aliases": [
+ "flamingo"
+ ]
+ },
+ {
+ "emoji": "🔦",
+ "aliases": [
+ "flashlight"
+ ]
+ },
+ {
+ "emoji": "🥿",
+ "aliases": [
+ "flat_shoe"
+ ]
+ },
+ {
+ "emoji": "🫓",
+ "aliases": [
+ "flatbread"
+ ]
+ },
+ {
+ "emoji": "⚜️",
+ "aliases": [
+ "fleur_de_lis"
+ ]
+ },
+ {
+ "emoji": "🛬",
+ "aliases": [
+ "flight_arrival"
+ ]
+ },
+ {
+ "emoji": "🛫",
+ "aliases": [
+ "flight_departure"
+ ]
+ },
+ {
+ "emoji": "💾",
+ "aliases": [
+ "floppy_disk"
+ ]
+ },
+ {
+ "emoji": "🎴",
+ "aliases": [
+ "flower_playing_cards"
+ ]
+ },
+ {
+ "emoji": "😳",
+ "aliases": [
+ "flushed"
+ ]
+ },
+ {
+ "emoji": "🪈",
+ "aliases": [
+ "flute"
+ ]
+ },
+ {
+ "emoji": "🪰",
+ "aliases": [
+ "fly"
+ ]
+ },
+ {
+ "emoji": "🥏",
+ "aliases": [
+ "flying_disc"
+ ]
+ },
+ {
+ "emoji": "🛸",
+ "aliases": [
+ "flying_saucer"
+ ]
+ },
+ {
+ "emoji": "🌫️",
+ "aliases": [
+ "fog"
+ ]
+ },
+ {
+ "emoji": "🌁",
+ "aliases": [
+ "foggy"
+ ]
+ },
+ {
+ "emoji": "🪭",
+ "aliases": [
+ "folding_hand_fan"
+ ]
+ },
+ {
+ "emoji": "🫕",
+ "aliases": [
+ "fondue"
+ ]
+ },
+ {
+ "emoji": "🦶",
+ "aliases": [
+ "foot"
+ ]
+ },
+ {
+ "emoji": "🏈",
+ "aliases": [
+ "football"
+ ]
+ },
+ {
+ "emoji": "👣",
+ "aliases": [
+ "footprints"
+ ]
+ },
+ {
+ "emoji": "🍴",
+ "aliases": [
+ "fork_and_knife"
+ ]
+ },
+ {
+ "emoji": "🥠",
+ "aliases": [
+ "fortune_cookie"
+ ]
+ },
+ {
+ "emoji": "⛲",
+ "aliases": [
+ "fountain"
+ ]
+ },
+ {
+ "emoji": "🖋️",
+ "aliases": [
+ "fountain_pen"
+ ]
+ },
+ {
+ "emoji": "4️⃣",
+ "aliases": [
+ "four"
+ ]
+ },
+ {
+ "emoji": "🍀",
+ "aliases": [
+ "four_leaf_clover"
+ ]
+ },
+ {
+ "emoji": "🦊",
+ "aliases": [
+ "fox_face"
+ ]
+ },
+ {
+ "emoji": "🇫🇷",
+ "aliases": [
+ "fr"
+ ]
+ },
+ {
+ "emoji": "🖼️",
+ "aliases": [
+ "framed_picture"
+ ]
+ },
+ {
+ "emoji": "🆓",
+ "aliases": [
+ "free"
+ ]
+ },
+ {
+ "emoji": "🇬🇫",
+ "aliases": [
+ "french_guiana"
+ ]
+ },
+ {
+ "emoji": "🇵🇫",
+ "aliases": [
+ "french_polynesia"
+ ]
+ },
+ {
+ "emoji": "🇹🇫",
+ "aliases": [
+ "french_southern_territories"
+ ]
+ },
+ {
+ "emoji": "🍳",
+ "aliases": [
+ "fried_egg"
+ ]
+ },
+ {
+ "emoji": "🍤",
+ "aliases": [
+ "fried_shrimp"
+ ]
+ },
+ {
+ "emoji": "🍟",
+ "aliases": [
+ "fries"
+ ]
+ },
+ {
+ "emoji": "🐸",
+ "aliases": [
+ "frog"
+ ]
+ },
+ {
+ "emoji": "😦",
+ "aliases": [
+ "frowning"
+ ]
+ },
+ {
+ "emoji": "☹️",
+ "aliases": [
+ "frowning_face"
+ ]
+ },
+ {
+ "emoji": "🙍♂️",
+ "aliases": [
+ "frowning_man"
+ ]
+ },
+ {
+ "emoji": "🙍",
+ "aliases": [
+ "frowning_person"
+ ]
+ },
+ {
+ "emoji": "🙍♀️",
+ "aliases": [
+ "frowning_woman"
+ ]
+ },
+ {
+ "emoji": "⛽",
+ "aliases": [
+ "fuelpump"
+ ]
+ },
+ {
+ "emoji": "🌕",
+ "aliases": [
+ "full_moon"
+ ]
+ },
+ {
+ "emoji": "🌝",
+ "aliases": [
+ "full_moon_with_face"
+ ]
+ },
+ {
+ "emoji": "⚱️",
+ "aliases": [
+ "funeral_urn"
+ ]
+ },
+ {
+ "emoji": "🇬🇦",
+ "aliases": [
+ "gabon"
+ ]
+ },
+ {
+ "emoji": "🇬🇲",
+ "aliases": [
+ "gambia"
+ ]
+ },
+ {
+ "emoji": "🎲",
+ "aliases": [
+ "game_die"
+ ]
+ },
+ {
+ "emoji": "🧄",
+ "aliases": [
+ "garlic"
+ ]
+ },
+ {
+ "emoji": "🇬🇧",
+ "aliases": [
+ "gb",
+ "uk"
+ ]
+ },
+ {
+ "emoji": "⚙️",
+ "aliases": [
+ "gear"
+ ]
+ },
+ {
+ "emoji": "💎",
+ "aliases": [
+ "gem"
+ ]
+ },
+ {
+ "emoji": "♊",
+ "aliases": [
+ "gemini"
+ ]
+ },
+ {
+ "emoji": "🧞",
+ "aliases": [
+ "genie"
+ ]
+ },
+ {
+ "emoji": "🧞♂️",
+ "aliases": [
+ "genie_man"
+ ]
+ },
+ {
+ "emoji": "🧞♀️",
+ "aliases": [
+ "genie_woman"
+ ]
+ },
+ {
+ "emoji": "🇬🇪",
+ "aliases": [
+ "georgia"
+ ]
+ },
+ {
+ "emoji": "🇬🇭",
+ "aliases": [
+ "ghana"
+ ]
+ },
+ {
+ "emoji": "👻",
+ "aliases": [
+ "ghost"
+ ]
+ },
+ {
+ "emoji": "🇬🇮",
+ "aliases": [
+ "gibraltar"
+ ]
+ },
+ {
+ "emoji": "🎁",
+ "aliases": [
+ "gift"
+ ]
+ },
+ {
+ "emoji": "💝",
+ "aliases": [
+ "gift_heart"
+ ]
+ },
+ {
+ "emoji": "🫚",
+ "aliases": [
+ "ginger_root"
+ ]
+ },
+ {
+ "emoji": "🦒",
+ "aliases": [
+ "giraffe"
+ ]
+ },
+ {
+ "emoji": "👧",
+ "aliases": [
+ "girl"
+ ]
+ },
+ {
+ "emoji": "🌐",
+ "aliases": [
+ "globe_with_meridians"
+ ]
+ },
+ {
+ "emoji": "🧤",
+ "aliases": [
+ "gloves"
+ ]
+ },
+ {
+ "emoji": "🥅",
+ "aliases": [
+ "goal_net"
+ ]
+ },
+ {
+ "emoji": "🐐",
+ "aliases": [
+ "goat"
+ ]
+ },
+ {
+ "emoji": "🥽",
+ "aliases": [
+ "goggles"
+ ]
+ },
+ {
+ "emoji": "⛳",
+ "aliases": [
+ "golf"
+ ]
+ },
+ {
+ "emoji": "🏌️",
+ "aliases": [
+ "golfing"
+ ]
+ },
+ {
+ "emoji": "🏌️♂️",
+ "aliases": [
+ "golfing_man"
+ ]
+ },
+ {
+ "emoji": "🏌️♀️",
+ "aliases": [
+ "golfing_woman"
+ ]
+ },
+ {
+ "emoji": "🪿",
+ "aliases": [
+ "goose"
+ ]
+ },
+ {
+ "emoji": "🦍",
+ "aliases": [
+ "gorilla"
+ ]
+ },
+ {
+ "emoji": "🍇",
+ "aliases": [
+ "grapes"
+ ]
+ },
+ {
+ "emoji": "🇬🇷",
+ "aliases": [
+ "greece"
+ ]
+ },
+ {
+ "emoji": "🍏",
+ "aliases": [
+ "green_apple"
+ ]
+ },
+ {
+ "emoji": "📗",
+ "aliases": [
+ "green_book"
+ ]
+ },
+ {
+ "emoji": "🟢",
+ "aliases": [
+ "green_circle"
+ ]
+ },
+ {
+ "emoji": "💚",
+ "aliases": [
+ "green_heart"
+ ]
+ },
+ {
+ "emoji": "🥗",
+ "aliases": [
+ "green_salad"
+ ]
+ },
+ {
+ "emoji": "🟩",
+ "aliases": [
+ "green_square"
+ ]
+ },
+ {
+ "emoji": "🇬🇱",
+ "aliases": [
+ "greenland"
+ ]
+ },
+ {
+ "emoji": "🇬🇩",
+ "aliases": [
+ "grenada"
+ ]
+ },
+ {
+ "emoji": "❕",
+ "aliases": [
+ "grey_exclamation"
+ ]
+ },
+ {
+ "emoji": "🩶",
+ "aliases": [
+ "grey_heart"
+ ]
+ },
+ {
+ "emoji": "❔",
+ "aliases": [
+ "grey_question"
+ ]
+ },
+ {
+ "emoji": "😬",
+ "aliases": [
+ "grimacing"
+ ]
+ },
+ {
+ "emoji": "😁",
+ "aliases": [
+ "grin"
+ ]
+ },
+ {
+ "emoji": "😀",
+ "aliases": [
+ "grinning"
+ ]
+ },
+ {
+ "emoji": "🇬🇵",
+ "aliases": [
+ "guadeloupe"
+ ]
+ },
+ {
+ "emoji": "🇬🇺",
+ "aliases": [
+ "guam"
+ ]
+ },
+ {
+ "emoji": "💂",
+ "aliases": [
+ "guard"
+ ]
+ },
+ {
+ "emoji": "💂♂️",
+ "aliases": [
+ "guardsman"
+ ]
+ },
+ {
+ "emoji": "💂♀️",
+ "aliases": [
+ "guardswoman"
+ ]
+ },
+ {
+ "emoji": "🇬🇹",
+ "aliases": [
+ "guatemala"
+ ]
+ },
+ {
+ "emoji": "🇬🇬",
+ "aliases": [
+ "guernsey"
+ ]
+ },
+ {
+ "emoji": "🦮",
+ "aliases": [
+ "guide_dog"
+ ]
+ },
+ {
+ "emoji": "🇬🇳",
+ "aliases": [
+ "guinea"
+ ]
+ },
+ {
+ "emoji": "🇬🇼",
+ "aliases": [
+ "guinea_bissau"
+ ]
+ },
+ {
+ "emoji": "🎸",
+ "aliases": [
+ "guitar"
+ ]
+ },
+ {
+ "emoji": "🔫",
+ "aliases": [
+ "gun"
+ ]
+ },
+ {
+ "emoji": "🇬🇾",
+ "aliases": [
+ "guyana"
+ ]
+ },
+ {
+ "emoji": "🪮",
+ "aliases": [
+ "hair_pick"
+ ]
+ },
+ {
+ "emoji": "💇",
+ "aliases": [
+ "haircut"
+ ]
+ },
+ {
+ "emoji": "💇♂️",
+ "aliases": [
+ "haircut_man"
+ ]
+ },
+ {
+ "emoji": "💇♀️",
+ "aliases": [
+ "haircut_woman"
+ ]
+ },
+ {
+ "emoji": "🇭🇹",
+ "aliases": [
+ "haiti"
+ ]
+ },
+ {
+ "emoji": "🍔",
+ "aliases": [
+ "hamburger"
+ ]
+ },
+ {
+ "emoji": "🔨",
+ "aliases": [
+ "hammer"
+ ]
+ },
+ {
+ "emoji": "⚒️",
+ "aliases": [
+ "hammer_and_pick"
+ ]
+ },
+ {
+ "emoji": "🛠️",
+ "aliases": [
+ "hammer_and_wrench"
+ ]
+ },
+ {
+ "emoji": "🪬",
+ "aliases": [
+ "hamsa"
+ ]
+ },
+ {
+ "emoji": "🐹",
+ "aliases": [
+ "hamster"
+ ]
+ },
+ {
+ "emoji": "✋",
+ "aliases": [
+ "hand",
+ "raised_hand"
+ ]
+ },
+ {
+ "emoji": "🤭",
+ "aliases": [
+ "hand_over_mouth"
+ ]
+ },
+ {
+ "emoji": "🫰",
+ "aliases": [
+ "hand_with_index_finger_and_thumb_crossed"
+ ]
+ },
+ {
+ "emoji": "👜",
+ "aliases": [
+ "handbag"
+ ]
+ },
+ {
+ "emoji": "🤾",
+ "aliases": [
+ "handball_person"
+ ]
+ },
+ {
+ "emoji": "🤝",
+ "aliases": [
+ "handshake"
+ ]
+ },
+ {
+ "emoji": "💩",
+ "aliases": [
+ "hankey",
+ "poop",
+ "shit"
+ ]
+ },
+ {
+ "emoji": "",
+ "aliases": [
+ "harp"
+ ]
+ },
+ {
+ "emoji": "#️⃣",
+ "aliases": [
+ "hash"
+ ]
+ },
+ {
+ "emoji": "🐥",
+ "aliases": [
+ "hatched_chick"
+ ]
+ },
+ {
+ "emoji": "🐣",
+ "aliases": [
+ "hatching_chick"
+ ]
+ },
+ {
+ "emoji": "🙂↔️",
+ "aliases": [
+ "head_shaking_horizontally"
+ ]
+ },
+ {
+ "emoji": "🙂↕️",
+ "aliases": [
+ "head_shaking_vertically"
+ ]
+ },
+ {
+ "emoji": "🎧",
+ "aliases": [
+ "headphones"
+ ]
+ },
+ {
+ "emoji": "🪦",
+ "aliases": [
+ "headstone"
+ ]
+ },
+ {
+ "emoji": "🧑⚕️",
+ "aliases": [
+ "health_worker"
+ ]
+ },
+ {
+ "emoji": "🙉",
+ "aliases": [
+ "hear_no_evil"
+ ]
+ },
+ {
+ "emoji": "🇭🇲",
+ "aliases": [
+ "heard_mcdonald_islands"
+ ]
+ },
+ {
+ "emoji": "❤️",
+ "aliases": [
+ "heart"
+ ]
+ },
+ {
+ "emoji": "💟",
+ "aliases": [
+ "heart_decoration"
+ ]
+ },
+ {
+ "emoji": "😍",
+ "aliases": [
+ "heart_eyes"
+ ]
+ },
+ {
+ "emoji": "😻",
+ "aliases": [
+ "heart_eyes_cat"
+ ]
+ },
+ {
+ "emoji": "🫶",
+ "aliases": [
+ "heart_hands"
+ ]
+ },
+ {
+ "emoji": "❤️🔥",
+ "aliases": [
+ "heart_on_fire"
+ ]
+ },
+ {
+ "emoji": "💓",
+ "aliases": [
+ "heartbeat"
+ ]
+ },
+ {
+ "emoji": "💗",
+ "aliases": [
+ "heartpulse"
+ ]
+ },
+ {
+ "emoji": "♥️",
+ "aliases": [
+ "hearts"
+ ]
+ },
+ {
+ "emoji": "✔️",
+ "aliases": [
+ "heavy_check_mark"
+ ]
+ },
+ {
+ "emoji": "➗",
+ "aliases": [
+ "heavy_division_sign"
+ ]
+ },
+ {
+ "emoji": "💲",
+ "aliases": [
+ "heavy_dollar_sign"
+ ]
+ },
+ {
+ "emoji": "🟰",
+ "aliases": [
+ "heavy_equals_sign"
+ ]
+ },
+ {
+ "emoji": "❣️",
+ "aliases": [
+ "heavy_heart_exclamation"
+ ]
+ },
+ {
+ "emoji": "➖",
+ "aliases": [
+ "heavy_minus_sign"
+ ]
+ },
+ {
+ "emoji": "✖️",
+ "aliases": [
+ "heavy_multiplication_x"
+ ]
+ },
+ {
+ "emoji": "➕",
+ "aliases": [
+ "heavy_plus_sign"
+ ]
+ },
+ {
+ "emoji": "🦔",
+ "aliases": [
+ "hedgehog"
+ ]
+ },
+ {
+ "emoji": "🚁",
+ "aliases": [
+ "helicopter"
+ ]
+ },
+ {
+ "emoji": "🌿",
+ "aliases": [
+ "herb"
+ ]
+ },
+ {
+ "emoji": "🌺",
+ "aliases": [
+ "hibiscus"
+ ]
+ },
+ {
+ "emoji": "🔆",
+ "aliases": [
+ "high_brightness"
+ ]
+ },
+ {
+ "emoji": "👠",
+ "aliases": [
+ "high_heel"
+ ]
+ },
+ {
+ "emoji": "🥾",
+ "aliases": [
+ "hiking_boot"
+ ]
+ },
+ {
+ "emoji": "🛕",
+ "aliases": [
+ "hindu_temple"
+ ]
+ },
+ {
+ "emoji": "🦛",
+ "aliases": [
+ "hippopotamus"
+ ]
+ },
+ {
+ "emoji": "🔪",
+ "aliases": [
+ "hocho",
+ "knife"
+ ]
+ },
+ {
+ "emoji": "🕳️",
+ "aliases": [
+ "hole"
+ ]
+ },
+ {
+ "emoji": "🇭🇳",
+ "aliases": [
+ "honduras"
+ ]
+ },
+ {
+ "emoji": "🍯",
+ "aliases": [
+ "honey_pot"
+ ]
+ },
+ {
+ "emoji": "🇭🇰",
+ "aliases": [
+ "hong_kong"
+ ]
+ },
+ {
+ "emoji": "🪝",
+ "aliases": [
+ "hook"
+ ]
+ },
+ {
+ "emoji": "🐴",
+ "aliases": [
+ "horse"
+ ]
+ },
+ {
+ "emoji": "🏇",
+ "aliases": [
+ "horse_racing"
+ ]
+ },
+ {
+ "emoji": "🏥",
+ "aliases": [
+ "hospital"
+ ]
+ },
+ {
+ "emoji": "🥵",
+ "aliases": [
+ "hot_face"
+ ]
+ },
+ {
+ "emoji": "🌶️",
+ "aliases": [
+ "hot_pepper"
+ ]
+ },
+ {
+ "emoji": "🌭",
+ "aliases": [
+ "hotdog"
+ ]
+ },
+ {
+ "emoji": "🏨",
+ "aliases": [
+ "hotel"
+ ]
+ },
+ {
+ "emoji": "♨️",
+ "aliases": [
+ "hotsprings"
+ ]
+ },
+ {
+ "emoji": "⌛",
+ "aliases": [
+ "hourglass"
+ ]
+ },
+ {
+ "emoji": "⏳",
+ "aliases": [
+ "hourglass_flowing_sand"
+ ]
+ },
+ {
+ "emoji": "🏠",
+ "aliases": [
+ "house"
+ ]
+ },
+ {
+ "emoji": "🏡",
+ "aliases": [
+ "house_with_garden"
+ ]
+ },
+ {
+ "emoji": "🏘️",
+ "aliases": [
+ "houses"
+ ]
+ },
+ {
+ "emoji": "🤗",
+ "aliases": [
+ "hugs"
+ ]
+ },
+ {
+ "emoji": "🇭🇺",
+ "aliases": [
+ "hungary"
+ ]
+ },
+ {
+ "emoji": "😯",
+ "aliases": [
+ "hushed"
+ ]
+ },
+ {
+ "emoji": "🛖",
+ "aliases": [
+ "hut"
+ ]
+ },
+ {
+ "emoji": "🪻",
+ "aliases": [
+ "hyacinth"
+ ]
+ },
+ {
+ "emoji": "🍨",
+ "aliases": [
+ "ice_cream"
+ ]
+ },
+ {
+ "emoji": "🧊",
+ "aliases": [
+ "ice_cube"
+ ]
+ },
+ {
+ "emoji": "🏒",
+ "aliases": [
+ "ice_hockey"
+ ]
+ },
+ {
+ "emoji": "⛸️",
+ "aliases": [
+ "ice_skate"
+ ]
+ },
+ {
+ "emoji": "🍦",
+ "aliases": [
+ "icecream"
+ ]
+ },
+ {
+ "emoji": "🇮🇸",
+ "aliases": [
+ "iceland"
+ ]
+ },
+ {
+ "emoji": "🆔",
+ "aliases": [
+ "id"
+ ]
+ },
+ {
+ "emoji": "🪪",
+ "aliases": [
+ "identification_card"
+ ]
+ },
+ {
+ "emoji": "🉐",
+ "aliases": [
+ "ideograph_advantage"
+ ]
+ },
+ {
+ "emoji": "👿",
+ "aliases": [
+ "imp"
+ ]
+ },
+ {
+ "emoji": "📥",
+ "aliases": [
+ "inbox_tray"
+ ]
+ },
+ {
+ "emoji": "📨",
+ "aliases": [
+ "incoming_envelope"
+ ]
+ },
+ {
+ "emoji": "🫵",
+ "aliases": [
+ "index_pointing_at_the_viewer"
+ ]
+ },
+ {
+ "emoji": "🇮🇳",
+ "aliases": [
+ "india"
+ ]
+ },
+ {
+ "emoji": "🇮🇩",
+ "aliases": [
+ "indonesia"
+ ]
+ },
+ {
+ "emoji": "♾️",
+ "aliases": [
+ "infinity"
+ ]
+ },
+ {
+ "emoji": "ℹ️",
+ "aliases": [
+ "information_source"
+ ]
+ },
+ {
+ "emoji": "😇",
+ "aliases": [
+ "innocent"
+ ]
+ },
+ {
+ "emoji": "⁉️",
+ "aliases": [
+ "interrobang"
+ ]
+ },
+ {
+ "emoji": "📱",
+ "aliases": [
+ "iphone"
+ ]
+ },
+ {
+ "emoji": "🇮🇷",
+ "aliases": [
+ "iran"
+ ]
+ },
+ {
+ "emoji": "🇮🇶",
+ "aliases": [
+ "iraq"
+ ]
+ },
+ {
+ "emoji": "🇮🇪",
+ "aliases": [
+ "ireland"
+ ]
+ },
+ {
+ "emoji": "🇮🇲",
+ "aliases": [
+ "isle_of_man"
+ ]
+ },
+ {
+ "emoji": "🇮🇱",
+ "aliases": [
+ "israel"
+ ]
+ },
+ {
+ "emoji": "🇮🇹",
+ "aliases": [
+ "it"
+ ]
+ },
+ {
+ "emoji": "🏮",
+ "aliases": [
+ "izakaya_lantern",
+ "lantern"
+ ]
+ },
+ {
+ "emoji": "🎃",
+ "aliases": [
+ "jack_o_lantern"
+ ]
+ },
+ {
+ "emoji": "🇯🇲",
+ "aliases": [
+ "jamaica"
+ ]
+ },
+ {
+ "emoji": "🗾",
+ "aliases": [
+ "japan"
+ ]
+ },
+ {
+ "emoji": "🏯",
+ "aliases": [
+ "japanese_castle"
+ ]
+ },
+ {
+ "emoji": "👺",
+ "aliases": [
+ "japanese_goblin"
+ ]
+ },
+ {
+ "emoji": "👹",
+ "aliases": [
+ "japanese_ogre"
+ ]
+ },
+ {
+ "emoji": "🫙",
+ "aliases": [
+ "jar"
+ ]
+ },
+ {
+ "emoji": "👖",
+ "aliases": [
+ "jeans"
+ ]
+ },
+ {
+ "emoji": "🪼",
+ "aliases": [
+ "jellyfish"
+ ]
+ },
+ {
+ "emoji": "🇯🇪",
+ "aliases": [
+ "jersey"
+ ]
+ },
+ {
+ "emoji": "🧩",
+ "aliases": [
+ "jigsaw"
+ ]
+ },
+ {
+ "emoji": "🇯🇴",
+ "aliases": [
+ "jordan"
+ ]
+ },
+ {
+ "emoji": "😂",
+ "aliases": [
+ "joy"
+ ]
+ },
+ {
+ "emoji": "😹",
+ "aliases": [
+ "joy_cat"
+ ]
+ },
+ {
+ "emoji": "🕹️",
+ "aliases": [
+ "joystick"
+ ]
+ },
+ {
+ "emoji": "🇯🇵",
+ "aliases": [
+ "jp"
+ ]
+ },
+ {
+ "emoji": "🧑⚖️",
+ "aliases": [
+ "judge"
+ ]
+ },
+ {
+ "emoji": "🤹",
+ "aliases": [
+ "juggling_person"
+ ]
+ },
+ {
+ "emoji": "🕋",
+ "aliases": [
+ "kaaba"
+ ]
+ },
+ {
+ "emoji": "🦘",
+ "aliases": [
+ "kangaroo"
+ ]
+ },
+ {
+ "emoji": "🇰🇿",
+ "aliases": [
+ "kazakhstan"
+ ]
+ },
+ {
+ "emoji": "🇰🇪",
+ "aliases": [
+ "kenya"
+ ]
+ },
+ {
+ "emoji": "🔑",
+ "aliases": [
+ "key"
+ ]
+ },
+ {
+ "emoji": "⌨️",
+ "aliases": [
+ "keyboard"
+ ]
+ },
+ {
+ "emoji": "🔟",
+ "aliases": [
+ "keycap_ten"
+ ]
+ },
+ {
+ "emoji": "🪯",
+ "aliases": [
+ "khanda"
+ ]
+ },
+ {
+ "emoji": "🛴",
+ "aliases": [
+ "kick_scooter"
+ ]
+ },
+ {
+ "emoji": "👘",
+ "aliases": [
+ "kimono"
+ ]
+ },
+ {
+ "emoji": "🇰🇮",
+ "aliases": [
+ "kiribati"
+ ]
+ },
+ {
+ "emoji": "💋",
+ "aliases": [
+ "kiss"
+ ]
+ },
+ {
+ "emoji": "😗",
+ "aliases": [
+ "kissing"
+ ]
+ },
+ {
+ "emoji": "😽",
+ "aliases": [
+ "kissing_cat"
+ ]
+ },
+ {
+ "emoji": "😚",
+ "aliases": [
+ "kissing_closed_eyes"
+ ]
+ },
+ {
+ "emoji": "😘",
+ "aliases": [
+ "kissing_heart"
+ ]
+ },
+ {
+ "emoji": "😙",
+ "aliases": [
+ "kissing_smiling_eyes"
+ ]
+ },
+ {
+ "emoji": "🪁",
+ "aliases": [
+ "kite"
+ ]
+ },
+ {
+ "emoji": "🥝",
+ "aliases": [
+ "kiwi_fruit"
+ ]
+ },
+ {
+ "emoji": "🧎♂️",
+ "aliases": [
+ "kneeling_man"
+ ]
+ },
+ {
+ "emoji": "🧎",
+ "aliases": [
+ "kneeling_person"
+ ]
+ },
+ {
+ "emoji": "🧎♀️",
+ "aliases": [
+ "kneeling_woman"
+ ]
+ },
+ {
+ "emoji": "🪢",
+ "aliases": [
+ "knot"
+ ]
+ },
+ {
+ "emoji": "🐨",
+ "aliases": [
+ "koala"
+ ]
+ },
+ {
+ "emoji": "🈁",
+ "aliases": [
+ "koko"
+ ]
+ },
+ {
+ "emoji": "🇽🇰",
+ "aliases": [
+ "kosovo"
+ ]
+ },
+ {
+ "emoji": "🇰🇷",
+ "aliases": [
+ "kr"
+ ]
+ },
+ {
+ "emoji": "🇰🇼",
+ "aliases": [
+ "kuwait"
+ ]
+ },
+ {
+ "emoji": "🇰🇬",
+ "aliases": [
+ "kyrgyzstan"
+ ]
+ },
+ {
+ "emoji": "🥼",
+ "aliases": [
+ "lab_coat"
+ ]
+ },
+ {
+ "emoji": "🏷️",
+ "aliases": [
+ "label"
+ ]
+ },
+ {
+ "emoji": "🥍",
+ "aliases": [
+ "lacrosse"
+ ]
+ },
+ {
+ "emoji": "🪜",
+ "aliases": [
+ "ladder"
+ ]
+ },
+ {
+ "emoji": "🐞",
+ "aliases": [
+ "lady_beetle"
+ ]
+ },
+ {
+ "emoji": "🇱🇦",
+ "aliases": [
+ "laos"
+ ]
+ },
+ {
+ "emoji": "🔵",
+ "aliases": [
+ "large_blue_circle"
+ ]
+ },
+ {
+ "emoji": "🔷",
+ "aliases": [
+ "large_blue_diamond"
+ ]
+ },
+ {
+ "emoji": "🔶",
+ "aliases": [
+ "large_orange_diamond"
+ ]
+ },
+ {
+ "emoji": "🌗",
+ "aliases": [
+ "last_quarter_moon"
+ ]
+ },
+ {
+ "emoji": "🌜",
+ "aliases": [
+ "last_quarter_moon_with_face"
+ ]
+ },
+ {
+ "emoji": "✝️",
+ "aliases": [
+ "latin_cross"
+ ]
+ },
+ {
+ "emoji": "🇱🇻",
+ "aliases": [
+ "latvia"
+ ]
+ },
+ {
+ "emoji": "😆",
+ "aliases": [
+ "laughing",
+ "satisfied",
+ "laugh"
+ ]
+ },
+ {
+ "emoji": "",
+ "aliases": [
+ "leafless_tree"
+ ]
+ },
+ {
+ "emoji": "🥬",
+ "aliases": [
+ "leafy_green"
+ ]
+ },
+ {
+ "emoji": "🍃",
+ "aliases": [
+ "leaves"
+ ]
+ },
+ {
+ "emoji": "🇱🇧",
+ "aliases": [
+ "lebanon"
+ ]
+ },
+ {
+ "emoji": "📒",
+ "aliases": [
+ "ledger"
+ ]
+ },
+ {
+ "emoji": "🛅",
+ "aliases": [
+ "left_luggage"
+ ]
+ },
+ {
+ "emoji": "↔️",
+ "aliases": [
+ "left_right_arrow"
+ ]
+ },
+ {
+ "emoji": "🗨️",
+ "aliases": [
+ "left_speech_bubble"
+ ]
+ },
+ {
+ "emoji": "↩️",
+ "aliases": [
+ "leftwards_arrow_with_hook"
+ ]
+ },
+ {
+ "emoji": "🫲",
+ "aliases": [
+ "leftwards_hand"
+ ]
+ },
+ {
+ "emoji": "🫷",
+ "aliases": [
+ "leftwards_pushing_hand"
+ ]
+ },
+ {
+ "emoji": "🦵",
+ "aliases": [
+ "leg"
+ ]
+ },
+ {
+ "emoji": "🍋",
+ "aliases": [
+ "lemon"
+ ]
+ },
+ {
+ "emoji": "♌",
+ "aliases": [
+ "leo"
+ ]
+ },
+ {
+ "emoji": "🐆",
+ "aliases": [
+ "leopard"
+ ]
+ },
+ {
+ "emoji": "🇱🇸",
+ "aliases": [
+ "lesotho"
+ ]
+ },
+ {
+ "emoji": "🎚️",
+ "aliases": [
+ "level_slider"
+ ]
+ },
+ {
+ "emoji": "🇱🇷",
+ "aliases": [
+ "liberia"
+ ]
+ },
+ {
+ "emoji": "♎",
+ "aliases": [
+ "libra"
+ ]
+ },
+ {
+ "emoji": "🇱🇾",
+ "aliases": [
+ "libya"
+ ]
+ },
+ {
+ "emoji": "🇱🇮",
+ "aliases": [
+ "liechtenstein"
+ ]
+ },
+ {
+ "emoji": "🩵",
+ "aliases": [
+ "light_blue_heart"
+ ]
+ },
+ {
+ "emoji": "🚈",
+ "aliases": [
+ "light_rail"
+ ]
+ },
+ {
+ "emoji": "🍋🟩",
+ "aliases": [
+ "lime"
+ ]
+ },
+ {
+ "emoji": "🔗",
+ "aliases": [
+ "link"
+ ]
+ },
+ {
+ "emoji": "🦁",
+ "aliases": [
+ "lion"
+ ]
+ },
+ {
+ "emoji": "👄",
+ "aliases": [
+ "lips"
+ ]
+ },
+ {
+ "emoji": "💄",
+ "aliases": [
+ "lipstick"
+ ]
+ },
+ {
+ "emoji": "🇱🇹",
+ "aliases": [
+ "lithuania"
+ ]
+ },
+ {
+ "emoji": "🦎",
+ "aliases": [
+ "lizard"
+ ]
+ },
+ {
+ "emoji": "🦙",
+ "aliases": [
+ "llama"
+ ]
+ },
+ {
+ "emoji": "🦞",
+ "aliases": [
+ "lobster"
+ ]
+ },
+ {
+ "emoji": "🔒",
+ "aliases": [
+ "lock"
+ ]
+ },
+ {
+ "emoji": "🔏",
+ "aliases": [
+ "lock_with_ink_pen"
+ ]
+ },
+ {
+ "emoji": "🍭",
+ "aliases": [
+ "lollipop"
+ ]
+ },
+ {
+ "emoji": "🪘",
+ "aliases": [
+ "long_drum"
+ ]
+ },
+ {
+ "emoji": "➿",
+ "aliases": [
+ "loop"
+ ]
+ },
+ {
+ "emoji": "🧴",
+ "aliases": [
+ "lotion_bottle"
+ ]
+ },
+ {
+ "emoji": "🪷",
+ "aliases": [
+ "lotus"
+ ]
+ },
+ {
+ "emoji": "🧘",
+ "aliases": [
+ "lotus_position"
+ ]
+ },
+ {
+ "emoji": "🧘♂️",
+ "aliases": [
+ "lotus_position_man"
+ ]
+ },
+ {
+ "emoji": "🧘♀️",
+ "aliases": [
+ "lotus_position_woman"
+ ]
+ },
+ {
+ "emoji": "🔊",
+ "aliases": [
+ "loud_sound"
+ ]
+ },
+ {
+ "emoji": "📢",
+ "aliases": [
+ "loudspeaker"
+ ]
+ },
+ {
+ "emoji": "🏩",
+ "aliases": [
+ "love_hotel"
+ ]
+ },
+ {
+ "emoji": "💌",
+ "aliases": [
+ "love_letter"
+ ]
+ },
+ {
+ "emoji": "🤟",
+ "aliases": [
+ "love_you_gesture"
+ ]
+ },
+ {
+ "emoji": "🪫",
+ "aliases": [
+ "low_battery"
+ ]
+ },
+ {
+ "emoji": "🔅",
+ "aliases": [
+ "low_brightness"
+ ]
+ },
+ {
+ "emoji": "🧳",
+ "aliases": [
+ "luggage"
+ ]
+ },
+ {
+ "emoji": "🫁",
+ "aliases": [
+ "lungs"
+ ]
+ },
+ {
+ "emoji": "🇱🇺",
+ "aliases": [
+ "luxembourg"
+ ]
+ },
+ {
+ "emoji": "🤥",
+ "aliases": [
+ "lying_face"
+ ]
+ },
+ {
+ "emoji": "Ⓜ️",
+ "aliases": [
+ "m"
+ ]
+ },
+ {
+ "emoji": "🇲🇴",
+ "aliases": [
+ "macau"
+ ]
+ },
+ {
+ "emoji": "🇲🇰",
+ "aliases": [
+ "macedonia"
+ ]
+ },
+ {
+ "emoji": "🇲🇬",
+ "aliases": [
+ "madagascar"
+ ]
+ },
+ {
+ "emoji": "🔍",
+ "aliases": [
+ "mag"
+ ]
+ },
+ {
+ "emoji": "🔎",
+ "aliases": [
+ "mag_right"
+ ]
+ },
+ {
+ "emoji": "🧙",
+ "aliases": [
+ "mage"
+ ]
+ },
+ {
+ "emoji": "🧙♂️",
+ "aliases": [
+ "mage_man"
+ ]
+ },
+ {
+ "emoji": "🧙♀️",
+ "aliases": [
+ "mage_woman"
+ ]
+ },
+ {
+ "emoji": "🪄",
+ "aliases": [
+ "magic_wand"
+ ]
+ },
+ {
+ "emoji": "🧲",
+ "aliases": [
+ "magnet"
+ ]
+ },
+ {
+ "emoji": "🀄",
+ "aliases": [
+ "mahjong"
+ ]
+ },
+ {
+ "emoji": "📫",
+ "aliases": [
+ "mailbox"
+ ]
+ },
+ {
+ "emoji": "📪",
+ "aliases": [
+ "mailbox_closed"
+ ]
+ },
+ {
+ "emoji": "📬",
+ "aliases": [
+ "mailbox_with_mail"
+ ]
+ },
+ {
+ "emoji": "📭",
+ "aliases": [
+ "mailbox_with_no_mail"
+ ]
+ },
+ {
+ "emoji": "🇲🇼",
+ "aliases": [
+ "malawi"
+ ]
+ },
+ {
+ "emoji": "🇲🇾",
+ "aliases": [
+ "malaysia"
+ ]
+ },
+ {
+ "emoji": "🇲🇻",
+ "aliases": [
+ "maldives"
+ ]
+ },
+ {
+ "emoji": "🕵️♂️",
+ "aliases": [
+ "male_detective"
+ ]
+ },
+ {
+ "emoji": "♂️",
+ "aliases": [
+ "male_sign"
+ ]
+ },
+ {
+ "emoji": "🇲🇱",
+ "aliases": [
+ "mali"
+ ]
+ },
+ {
+ "emoji": "🇲🇹",
+ "aliases": [
+ "malta"
+ ]
+ },
+ {
+ "emoji": "🦣",
+ "aliases": [
+ "mammoth"
+ ]
+ },
+ {
+ "emoji": "👨",
+ "aliases": [
+ "man"
+ ]
+ },
+ {
+ "emoji": "👨🎨",
+ "aliases": [
+ "man_artist"
+ ]
+ },
+ {
+ "emoji": "👨🚀",
+ "aliases": [
+ "man_astronaut"
+ ]
+ },
+ {
+ "emoji": "🧔♂️",
+ "aliases": [
+ "man_beard"
+ ]
+ },
+ {
+ "emoji": "🤸♂️",
+ "aliases": [
+ "man_cartwheeling"
+ ]
+ },
+ {
+ "emoji": "👨🍳",
+ "aliases": [
+ "man_cook"
+ ]
+ },
+ {
+ "emoji": "🕺",
+ "aliases": [
+ "man_dancing"
+ ]
+ },
+ {
+ "emoji": "🤦♂️",
+ "aliases": [
+ "man_facepalming"
+ ]
+ },
+ {
+ "emoji": "👨🏭",
+ "aliases": [
+ "man_factory_worker"
+ ]
+ },
+ {
+ "emoji": "👨🌾",
+ "aliases": [
+ "man_farmer"
+ ]
+ },
+ {
+ "emoji": "👨🍼",
+ "aliases": [
+ "man_feeding_baby"
+ ]
+ },
+ {
+ "emoji": "👨🚒",
+ "aliases": [
+ "man_firefighter"
+ ]
+ },
+ {
+ "emoji": "👨⚕️",
+ "aliases": [
+ "man_health_worker"
+ ]
+ },
+ {
+ "emoji": "👨🦽",
+ "aliases": [
+ "man_in_manual_wheelchair"
+ ]
+ },
+ {
+ "emoji": "👨🦽➡️",
+ "aliases": [
+ "man_in_manual_wheelchair_facing_right"
+ ]
+ },
+ {
+ "emoji": "👨🦼",
+ "aliases": [
+ "man_in_motorized_wheelchair"
+ ]
+ },
+ {
+ "emoji": "👨🦼➡️",
+ "aliases": [
+ "man_in_motorized_wheelchair_facing_right"
+ ]
+ },
+ {
+ "emoji": "🤵♂️",
+ "aliases": [
+ "man_in_tuxedo"
+ ]
+ },
+ {
+ "emoji": "👨⚖️",
+ "aliases": [
+ "man_judge"
+ ]
+ },
+ {
+ "emoji": "🤹♂️",
+ "aliases": [
+ "man_juggling"
+ ]
+ },
+ {
+ "emoji": "🧎♂️➡️",
+ "aliases": [
+ "man_kneeling_facing_right"
+ ]
+ },
+ {
+ "emoji": "👨🔧",
+ "aliases": [
+ "man_mechanic"
+ ]
+ },
+ {
+ "emoji": "👨💼",
+ "aliases": [
+ "man_office_worker"
+ ]
+ },
+ {
+ "emoji": "👨✈️",
+ "aliases": [
+ "man_pilot"
+ ]
+ },
+ {
+ "emoji": "🤾♂️",
+ "aliases": [
+ "man_playing_handball"
+ ]
+ },
+ {
+ "emoji": "🤽♂️",
+ "aliases": [
+ "man_playing_water_polo"
+ ]
+ },
+ {
+ "emoji": "🏃♂️➡️",
+ "aliases": [
+ "man_running_facing_right"
+ ]
+ },
+ {
+ "emoji": "👨🔬",
+ "aliases": [
+ "man_scientist"
+ ]
+ },
+ {
+ "emoji": "🤷♂️",
+ "aliases": [
+ "man_shrugging"
+ ]
+ },
+ {
+ "emoji": "👨🎤",
+ "aliases": [
+ "man_singer"
+ ]
+ },
+ {
+ "emoji": "👨🎓",
+ "aliases": [
+ "man_student"
+ ]
+ },
+ {
+ "emoji": "👨🏫",
+ "aliases": [
+ "man_teacher"
+ ]
+ },
+ {
+ "emoji": "👨💻",
+ "aliases": [
+ "man_technologist"
+ ]
+ },
+ {
+ "emoji": "🚶♂️➡️",
+ "aliases": [
+ "man_walking_facing_right"
+ ]
+ },
+ {
+ "emoji": "👲",
+ "aliases": [
+ "man_with_gua_pi_mao"
+ ]
+ },
+ {
+ "emoji": "👨🦯",
+ "aliases": [
+ "man_with_probing_cane"
+ ]
+ },
+ {
+ "emoji": "👳♂️",
+ "aliases": [
+ "man_with_turban"
+ ]
+ },
+ {
+ "emoji": "👰♂️",
+ "aliases": [
+ "man_with_veil"
+ ]
+ },
+ {
+ "emoji": "👨🦯➡️",
+ "aliases": [
+ "man_with_white_cane_facing_right"
+ ]
+ },
+ {
+ "emoji": "🥭",
+ "aliases": [
+ "mango"
+ ]
+ },
+ {
+ "emoji": "👞",
+ "aliases": [
+ "mans_shoe",
+ "shoe"
+ ]
+ },
+ {
+ "emoji": "🕰️",
+ "aliases": [
+ "mantelpiece_clock"
+ ]
+ },
+ {
+ "emoji": "🦽",
+ "aliases": [
+ "manual_wheelchair"
+ ]
+ },
+ {
+ "emoji": "🍁",
+ "aliases": [
+ "maple_leaf"
+ ]
+ },
+ {
+ "emoji": "🪇",
+ "aliases": [
+ "maracas"
+ ]
+ },
+ {
+ "emoji": "🇲🇭",
+ "aliases": [
+ "marshall_islands"
+ ]
+ },
+ {
+ "emoji": "🥋",
+ "aliases": [
+ "martial_arts_uniform"
+ ]
+ },
+ {
+ "emoji": "🇲🇶",
+ "aliases": [
+ "martinique"
+ ]
+ },
+ {
+ "emoji": "😷",
+ "aliases": [
+ "mask"
+ ]
+ },
+ {
+ "emoji": "💆",
+ "aliases": [
+ "massage"
+ ]
+ },
+ {
+ "emoji": "💆♂️",
+ "aliases": [
+ "massage_man"
+ ]
+ },
+ {
+ "emoji": "💆♀️",
+ "aliases": [
+ "massage_woman"
+ ]
+ },
+ {
+ "emoji": "🧉",
+ "aliases": [
+ "mate"
+ ]
+ },
+ {
+ "emoji": "🇲🇷",
+ "aliases": [
+ "mauritania"
+ ]
+ },
+ {
+ "emoji": "🇲🇺",
+ "aliases": [
+ "mauritius"
+ ]
+ },
+ {
+ "emoji": "🇾🇹",
+ "aliases": [
+ "mayotte"
+ ]
+ },
+ {
+ "emoji": "🍖",
+ "aliases": [
+ "meat_on_bone"
+ ]
+ },
+ {
+ "emoji": "🧑🔧",
+ "aliases": [
+ "mechanic"
+ ]
+ },
+ {
+ "emoji": "🦾",
+ "aliases": [
+ "mechanical_arm"
+ ]
+ },
+ {
+ "emoji": "🦿",
+ "aliases": [
+ "mechanical_leg"
+ ]
+ },
+ {
+ "emoji": "🎖️",
+ "aliases": [
+ "medal_military"
+ ]
+ },
+ {
+ "emoji": "🏅",
+ "aliases": [
+ "medal_sports"
+ ]
+ },
+ {
+ "emoji": "⚕️",
+ "aliases": [
+ "medical_symbol"
+ ]
+ },
+ {
+ "emoji": "📣",
+ "aliases": [
+ "mega"
+ ]
+ },
+ {
+ "emoji": "🍈",
+ "aliases": [
+ "melon"
+ ]
+ },
+ {
+ "emoji": "🫠",
+ "aliases": [
+ "melting_face"
+ ]
+ },
+ {
+ "emoji": "📝",
+ "aliases": [
+ "memo",
+ "pencil"
+ ]
+ },
+ {
+ "emoji": "🤼♂️",
+ "aliases": [
+ "men_wrestling"
+ ]
+ },
+ {
+ "emoji": "❤️🩹",
+ "aliases": [
+ "mending_heart"
+ ]
+ },
+ {
+ "emoji": "🕎",
+ "aliases": [
+ "menorah"
+ ]
+ },
+ {
+ "emoji": "🚹",
+ "aliases": [
+ "mens"
+ ]
+ },
+ {
+ "emoji": "🧜♀️",
+ "aliases": [
+ "mermaid"
+ ]
+ },
+ {
+ "emoji": "🧜♂️",
+ "aliases": [
+ "merman"
+ ]
+ },
+ {
+ "emoji": "🧜",
+ "aliases": [
+ "merperson"
+ ]
+ },
+ {
+ "emoji": "🤘",
+ "aliases": [
+ "metal"
+ ]
+ },
+ {
+ "emoji": "🚇",
+ "aliases": [
+ "metro"
+ ]
+ },
+ {
+ "emoji": "🇲🇽",
+ "aliases": [
+ "mexico"
+ ]
+ },
+ {
+ "emoji": "🦠",
+ "aliases": [
+ "microbe"
+ ]
+ },
+ {
+ "emoji": "🇫🇲",
+ "aliases": [
+ "micronesia"
+ ]
+ },
+ {
+ "emoji": "🎤",
+ "aliases": [
+ "microphone"
+ ]
+ },
+ {
+ "emoji": "🔬",
+ "aliases": [
+ "microscope"
+ ]
+ },
+ {
+ "emoji": "🖕",
+ "aliases": [
+ "middle_finger",
+ "fu"
+ ]
+ },
+ {
+ "emoji": "🪖",
+ "aliases": [
+ "military_helmet"
+ ]
+ },
+ {
+ "emoji": "🥛",
+ "aliases": [
+ "milk_glass"
+ ]
+ },
+ {
+ "emoji": "🌌",
+ "aliases": [
+ "milky_way"
+ ]
+ },
+ {
+ "emoji": "🚐",
+ "aliases": [
+ "minibus"
+ ]
+ },
+ {
+ "emoji": "💽",
+ "aliases": [
+ "minidisc"
+ ]
+ },
+ {
+ "emoji": "🪞",
+ "aliases": [
+ "mirror"
+ ]
+ },
+ {
+ "emoji": "🪩",
+ "aliases": [
+ "mirror_ball"
+ ]
+ },
+ {
+ "emoji": "📴",
+ "aliases": [
+ "mobile_phone_off"
+ ]
+ },
+ {
+ "emoji": "🇲🇩",
+ "aliases": [
+ "moldova"
+ ]
+ },
+ {
+ "emoji": "🇲🇨",
+ "aliases": [
+ "monaco"
+ ]
+ },
+ {
+ "emoji": "🤑",
+ "aliases": [
+ "money_mouth_face"
+ ]
+ },
+ {
+ "emoji": "💸",
+ "aliases": [
+ "money_with_wings"
+ ]
+ },
+ {
+ "emoji": "💰",
+ "aliases": [
+ "moneybag"
+ ]
+ },
+ {
+ "emoji": "🇲🇳",
+ "aliases": [
+ "mongolia"
+ ]
+ },
+ {
+ "emoji": "🐒",
+ "aliases": [
+ "monkey"
+ ]
+ },
+ {
+ "emoji": "🐵",
+ "aliases": [
+ "monkey_face"
+ ]
+ },
+ {
+ "emoji": "🧐",
+ "aliases": [
+ "monocle_face"
+ ]
+ },
+ {
+ "emoji": "🚝",
+ "aliases": [
+ "monorail"
+ ]
+ },
+ {
+ "emoji": "🇲🇪",
+ "aliases": [
+ "montenegro"
+ ]
+ },
+ {
+ "emoji": "🇲🇸",
+ "aliases": [
+ "montserrat"
+ ]
+ },
+ {
+ "emoji": "🌔",
+ "aliases": [
+ "moon",
+ "waxing_gibbous_moon"
+ ]
+ },
+ {
+ "emoji": "🥮",
+ "aliases": [
+ "moon_cake"
+ ]
+ },
+ {
+ "emoji": "🫎",
+ "aliases": [
+ "moose"
+ ]
+ },
+ {
+ "emoji": "🇲🇦",
+ "aliases": [
+ "morocco"
+ ]
+ },
+ {
+ "emoji": "🎓",
+ "aliases": [
+ "mortar_board"
+ ]
+ },
+ {
+ "emoji": "🕌",
+ "aliases": [
+ "mosque"
+ ]
+ },
+ {
+ "emoji": "🦟",
+ "aliases": [
+ "mosquito"
+ ]
+ },
+ {
+ "emoji": "🛥️",
+ "aliases": [
+ "motor_boat"
+ ]
+ },
+ {
+ "emoji": "🛵",
+ "aliases": [
+ "motor_scooter"
+ ]
+ },
+ {
+ "emoji": "🏍️",
+ "aliases": [
+ "motorcycle"
+ ]
+ },
+ {
+ "emoji": "🦼",
+ "aliases": [
+ "motorized_wheelchair"
+ ]
+ },
+ {
+ "emoji": "🛣️",
+ "aliases": [
+ "motorway"
+ ]
+ },
+ {
+ "emoji": "🗻",
+ "aliases": [
+ "mount_fuji"
+ ]
+ },
+ {
+ "emoji": "⛰️",
+ "aliases": [
+ "mountain"
+ ]
+ },
+ {
+ "emoji": "🚵",
+ "aliases": [
+ "mountain_bicyclist"
+ ]
+ },
+ {
+ "emoji": "🚵♂️",
+ "aliases": [
+ "mountain_biking_man"
+ ]
+ },
+ {
+ "emoji": "🚵♀️",
+ "aliases": [
+ "mountain_biking_woman"
+ ]
+ },
+ {
+ "emoji": "🚠",
+ "aliases": [
+ "mountain_cableway"
+ ]
+ },
+ {
+ "emoji": "🚞",
+ "aliases": [
+ "mountain_railway"
+ ]
+ },
+ {
+ "emoji": "🏔️",
+ "aliases": [
+ "mountain_snow"
+ ]
+ },
+ {
+ "emoji": "🐭",
+ "aliases": [
+ "mouse"
+ ]
+ },
+ {
+ "emoji": "🐁",
+ "aliases": [
+ "mouse2"
+ ]
+ },
+ {
+ "emoji": "🪤",
+ "aliases": [
+ "mouse_trap"
+ ]
+ },
+ {
+ "emoji": "🎥",
+ "aliases": [
+ "movie_camera"
+ ]
+ },
+ {
+ "emoji": "🗿",
+ "aliases": [
+ "moyai"
+ ]
+ },
+ {
+ "emoji": "🇲🇿",
+ "aliases": [
+ "mozambique"
+ ]
+ },
+ {
+ "emoji": "🤶",
+ "aliases": [
+ "mrs_claus"
+ ]
+ },
+ {
+ "emoji": "💪",
+ "aliases": [
+ "muscle"
+ ]
+ },
+ {
+ "emoji": "🍄",
+ "aliases": [
+ "mushroom"
+ ]
+ },
+ {
+ "emoji": "🎹",
+ "aliases": [
+ "musical_keyboard"
+ ]
+ },
+ {
+ "emoji": "🎵",
+ "aliases": [
+ "musical_note"
+ ]
+ },
+ {
+ "emoji": "🎼",
+ "aliases": [
+ "musical_score"
+ ]
+ },
+ {
+ "emoji": "🔇",
+ "aliases": [
+ "mute"
+ ]
+ },
+ {
+ "emoji": "🧑🎄",
+ "aliases": [
+ "mx_claus"
+ ]
+ },
+ {
+ "emoji": "🇲🇲",
+ "aliases": [
+ "myanmar"
+ ]
+ },
+ {
+ "emoji": "💅",
+ "aliases": [
+ "nail_care"
+ ]
+ },
+ {
+ "emoji": "📛",
+ "aliases": [
+ "name_badge"
+ ]
+ },
+ {
+ "emoji": "🇳🇦",
+ "aliases": [
+ "namibia"
+ ]
+ },
+ {
+ "emoji": "🏞️",
+ "aliases": [
+ "national_park"
+ ]
+ },
+ {
+ "emoji": "🇳🇷",
+ "aliases": [
+ "nauru"
+ ]
+ },
+ {
+ "emoji": "🤢",
+ "aliases": [
+ "nauseated_face"
+ ]
+ },
+ {
+ "emoji": "🧿",
+ "aliases": [
+ "nazar_amulet"
+ ]
+ },
+ {
+ "emoji": "👔",
+ "aliases": [
+ "necktie"
+ ]
+ },
+ {
+ "emoji": "❎",
+ "aliases": [
+ "negative_squared_cross_mark"
+ ]
+ },
+ {
+ "emoji": "🇳🇵",
+ "aliases": [
+ "nepal"
+ ]
+ },
+ {
+ "emoji": "🤓",
+ "aliases": [
+ "nerd_face"
+ ]
+ },
+ {
+ "emoji": "🪺",
+ "aliases": [
+ "nest_with_eggs"
+ ]
+ },
+ {
+ "emoji": "🪆",
+ "aliases": [
+ "nesting_dolls"
+ ]
+ },
+ {
+ "emoji": "🇳🇱",
+ "aliases": [
+ "netherlands"
+ ]
+ },
+ {
+ "emoji": "😐",
+ "aliases": [
+ "neutral_face"
+ ]
+ },
+ {
+ "emoji": "🆕",
+ "aliases": [
+ "new"
+ ]
+ },
+ {
+ "emoji": "🇳🇨",
+ "aliases": [
+ "new_caledonia"
+ ]
+ },
+ {
+ "emoji": "🌑",
+ "aliases": [
+ "new_moon"
+ ]
+ },
+ {
+ "emoji": "🌚",
+ "aliases": [
+ "new_moon_with_face"
+ ]
+ },
+ {
+ "emoji": "🇳🇿",
+ "aliases": [
+ "new_zealand"
+ ]
+ },
+ {
+ "emoji": "📰",
+ "aliases": [
+ "newspaper"
+ ]
+ },
+ {
+ "emoji": "🗞️",
+ "aliases": [
+ "newspaper_roll"
+ ]
+ },
+ {
+ "emoji": "⏭️",
+ "aliases": [
+ "next_track_button"
+ ]
+ },
+ {
+ "emoji": "🆖",
+ "aliases": [
+ "ng"
+ ]
+ },
+ {
+ "emoji": "🇳🇮",
+ "aliases": [
+ "nicaragua"
+ ]
+ },
+ {
+ "emoji": "🇳🇪",
+ "aliases": [
+ "niger"
+ ]
+ },
+ {
+ "emoji": "🇳🇬",
+ "aliases": [
+ "nigeria"
+ ]
+ },
+ {
+ "emoji": "🌃",
+ "aliases": [
+ "night_with_stars"
+ ]
+ },
+ {
+ "emoji": "9️⃣",
+ "aliases": [
+ "nine"
+ ]
+ },
+ {
+ "emoji": "🥷",
+ "aliases": [
+ "ninja"
+ ]
+ },
+ {
+ "emoji": "🇳🇺",
+ "aliases": [
+ "niue"
+ ]
+ },
+ {
+ "emoji": "🔕",
+ "aliases": [
+ "no_bell"
+ ]
+ },
+ {
+ "emoji": "🚳",
+ "aliases": [
+ "no_bicycles"
+ ]
+ },
+ {
+ "emoji": "⛔",
+ "aliases": [
+ "no_entry"
+ ]
+ },
+ {
+ "emoji": "🚫",
+ "aliases": [
+ "no_entry_sign"
+ ]
+ },
+ {
+ "emoji": "🙅",
+ "aliases": [
+ "no_good"
+ ]
+ },
+ {
+ "emoji": "🙅♂️",
+ "aliases": [
+ "no_good_man",
+ "ng_man"
+ ]
+ },
+ {
+ "emoji": "🙅♀️",
+ "aliases": [
+ "no_good_woman",
+ "ng_woman"
+ ]
+ },
+ {
+ "emoji": "📵",
+ "aliases": [
+ "no_mobile_phones"
+ ]
+ },
+ {
+ "emoji": "😶",
+ "aliases": [
+ "no_mouth"
+ ]
+ },
+ {
+ "emoji": "🚷",
+ "aliases": [
+ "no_pedestrians"
+ ]
+ },
+ {
+ "emoji": "🚭",
+ "aliases": [
+ "no_smoking"
+ ]
+ },
+ {
+ "emoji": "🚱",
+ "aliases": [
+ "non-potable_water"
+ ]
+ },
+ {
+ "emoji": "🇳🇫",
+ "aliases": [
+ "norfolk_island"
+ ]
+ },
+ {
+ "emoji": "🇰🇵",
+ "aliases": [
+ "north_korea"
+ ]
+ },
+ {
+ "emoji": "🇲🇵",
+ "aliases": [
+ "northern_mariana_islands"
+ ]
+ },
+ {
+ "emoji": "🇳🇴",
+ "aliases": [
+ "norway"
+ ]
+ },
+ {
+ "emoji": "👃",
+ "aliases": [
+ "nose"
+ ]
+ },
+ {
+ "emoji": "📓",
+ "aliases": [
+ "notebook"
+ ]
+ },
+ {
+ "emoji": "📔",
+ "aliases": [
+ "notebook_with_decorative_cover"
+ ]
+ },
+ {
+ "emoji": "🎶",
+ "aliases": [
+ "notes"
+ ]
+ },
+ {
+ "emoji": "🔩",
+ "aliases": [
+ "nut_and_bolt"
+ ]
+ },
+ {
+ "emoji": "⭕",
+ "aliases": [
+ "o"
+ ]
+ },
+ {
+ "emoji": "🅾️",
+ "aliases": [
+ "o2"
+ ]
+ },
+ {
+ "emoji": "🌊",
+ "aliases": [
+ "ocean"
+ ]
+ },
+ {
+ "emoji": "🐙",
+ "aliases": [
+ "octopus"
+ ]
+ },
+ {
+ "emoji": "🍢",
+ "aliases": [
+ "oden"
+ ]
+ },
+ {
+ "emoji": "🏢",
+ "aliases": [
+ "office"
+ ]
+ },
+ {
+ "emoji": "🧑💼",
+ "aliases": [
+ "office_worker"
+ ]
+ },
+ {
+ "emoji": "🛢️",
+ "aliases": [
+ "oil_drum"
+ ]
+ },
+ {
+ "emoji": "🆗",
+ "aliases": [
+ "ok"
+ ]
+ },
+ {
+ "emoji": "👌",
+ "aliases": [
+ "ok_hand"
+ ]
+ },
+ {
+ "emoji": "🙆♂️",
+ "aliases": [
+ "ok_man"
+ ]
+ },
+ {
+ "emoji": "🙆",
+ "aliases": [
+ "ok_person"
+ ]
+ },
+ {
+ "emoji": "🙆♀️",
+ "aliases": [
+ "ok_woman"
+ ]
+ },
+ {
+ "emoji": "🗝️",
+ "aliases": [
+ "old_key"
+ ]
+ },
+ {
+ "emoji": "🧓",
+ "aliases": [
+ "older_adult"
+ ]
+ },
+ {
+ "emoji": "👴",
+ "aliases": [
+ "older_man"
+ ]
+ },
+ {
+ "emoji": "👵",
+ "aliases": [
+ "older_woman"
+ ]
+ },
+ {
+ "emoji": "🫒",
+ "aliases": [
+ "olive"
+ ]
+ },
+ {
+ "emoji": "🕉️",
+ "aliases": [
+ "om"
+ ]
+ },
+ {
+ "emoji": "🇴🇲",
+ "aliases": [
+ "oman"
+ ]
+ },
+ {
+ "emoji": "🔛",
+ "aliases": [
+ "on"
+ ]
+ },
+ {
+ "emoji": "🚘",
+ "aliases": [
+ "oncoming_automobile"
+ ]
+ },
+ {
+ "emoji": "🚍",
+ "aliases": [
+ "oncoming_bus"
+ ]
+ },
+ {
+ "emoji": "🚔",
+ "aliases": [
+ "oncoming_police_car"
+ ]
+ },
+ {
+ "emoji": "🚖",
+ "aliases": [
+ "oncoming_taxi"
+ ]
+ },
+ {
+ "emoji": "1️⃣",
+ "aliases": [
+ "one"
+ ]
+ },
+ {
+ "emoji": "🩱",
+ "aliases": [
+ "one_piece_swimsuit"
+ ]
+ },
+ {
+ "emoji": "🧅",
+ "aliases": [
+ "onion"
+ ]
+ },
+ {
+ "emoji": "📂",
+ "aliases": [
+ "open_file_folder"
+ ]
+ },
+ {
+ "emoji": "👐",
+ "aliases": [
+ "open_hands"
+ ]
+ },
+ {
+ "emoji": "😮",
+ "aliases": [
+ "open_mouth"
+ ]
+ },
+ {
+ "emoji": "☂️",
+ "aliases": [
+ "open_umbrella"
+ ]
+ },
+ {
+ "emoji": "⛎",
+ "aliases": [
+ "ophiuchus"
+ ]
+ },
+ {
+ "emoji": "📙",
+ "aliases": [
+ "orange_book"
+ ]
+ },
+ {
+ "emoji": "🟠",
+ "aliases": [
+ "orange_circle"
+ ]
+ },
+ {
+ "emoji": "🧡",
+ "aliases": [
+ "orange_heart"
+ ]
+ },
+ {
+ "emoji": "🟧",
+ "aliases": [
+ "orange_square"
+ ]
+ },
+ {
+ "emoji": "🦧",
+ "aliases": [
+ "orangutan"
+ ]
+ },
+ {
+ "emoji": "☦️",
+ "aliases": [
+ "orthodox_cross"
+ ]
+ },
+ {
+ "emoji": "🦦",
+ "aliases": [
+ "otter"
+ ]
+ },
+ {
+ "emoji": "📤",
+ "aliases": [
+ "outbox_tray"
+ ]
+ },
+ {
+ "emoji": "🦉",
+ "aliases": [
+ "owl"
+ ]
+ },
+ {
+ "emoji": "🐂",
+ "aliases": [
+ "ox"
+ ]
+ },
+ {
+ "emoji": "🦪",
+ "aliases": [
+ "oyster"
+ ]
+ },
+ {
+ "emoji": "📦",
+ "aliases": [
+ "package"
+ ]
+ },
+ {
+ "emoji": "📄",
+ "aliases": [
+ "page_facing_up"
+ ]
+ },
+ {
+ "emoji": "📃",
+ "aliases": [
+ "page_with_curl"
+ ]
+ },
+ {
+ "emoji": "📟",
+ "aliases": [
+ "pager"
+ ]
+ },
+ {
+ "emoji": "🖌️",
+ "aliases": [
+ "paintbrush"
+ ]
+ },
+ {
+ "emoji": "🇵🇰",
+ "aliases": [
+ "pakistan"
+ ]
+ },
+ {
+ "emoji": "🇵🇼",
+ "aliases": [
+ "palau"
+ ]
+ },
+ {
+ "emoji": "🇵🇸",
+ "aliases": [
+ "palestinian_territories"
+ ]
+ },
+ {
+ "emoji": "🫳",
+ "aliases": [
+ "palm_down_hand"
+ ]
+ },
+ {
+ "emoji": "🌴",
+ "aliases": [
+ "palm_tree"
+ ]
+ },
+ {
+ "emoji": "🫴",
+ "aliases": [
+ "palm_up_hand"
+ ]
+ },
+ {
+ "emoji": "🤲",
+ "aliases": [
+ "palms_up_together"
+ ]
+ },
+ {
+ "emoji": "🇵🇦",
+ "aliases": [
+ "panama"
+ ]
+ },
+ {
+ "emoji": "🥞",
+ "aliases": [
+ "pancakes"
+ ]
+ },
+ {
+ "emoji": "🐼",
+ "aliases": [
+ "panda_face"
+ ]
+ },
+ {
+ "emoji": "📎",
+ "aliases": [
+ "paperclip"
+ ]
+ },
+ {
+ "emoji": "🖇️",
+ "aliases": [
+ "paperclips"
+ ]
+ },
+ {
+ "emoji": "🇵🇬",
+ "aliases": [
+ "papua_new_guinea"
+ ]
+ },
+ {
+ "emoji": "🪂",
+ "aliases": [
+ "parachute"
+ ]
+ },
+ {
+ "emoji": "🇵🇾",
+ "aliases": [
+ "paraguay"
+ ]
+ },
+ {
+ "emoji": "⛱️",
+ "aliases": [
+ "parasol_on_ground"
+ ]
+ },
+ {
+ "emoji": "🅿️",
+ "aliases": [
+ "parking"
+ ]
+ },
+ {
+ "emoji": "🦜",
+ "aliases": [
+ "parrot"
+ ]
+ },
+ {
+ "emoji": "〽️",
+ "aliases": [
+ "part_alternation_mark"
+ ]
+ },
+ {
+ "emoji": "⛅",
+ "aliases": [
+ "partly_sunny"
+ ]
+ },
+ {
+ "emoji": "🥳",
+ "aliases": [
+ "partying_face"
+ ]
+ },
+ {
+ "emoji": "🛳️",
+ "aliases": [
+ "passenger_ship"
+ ]
+ },
+ {
+ "emoji": "🛂",
+ "aliases": [
+ "passport_control"
+ ]
+ },
+ {
+ "emoji": "⏸️",
+ "aliases": [
+ "pause_button"
+ ]
+ },
+ {
+ "emoji": "🫛",
+ "aliases": [
+ "pea_pod"
+ ]
+ },
+ {
+ "emoji": "☮️",
+ "aliases": [
+ "peace_symbol"
+ ]
+ },
+ {
+ "emoji": "🍑",
+ "aliases": [
+ "peach"
+ ]
+ },
+ {
+ "emoji": "🦚",
+ "aliases": [
+ "peacock"
+ ]
+ },
+ {
+ "emoji": "🥜",
+ "aliases": [
+ "peanuts"
+ ]
+ },
+ {
+ "emoji": "🍐",
+ "aliases": [
+ "pear"
+ ]
+ },
+ {
+ "emoji": "🖊️",
+ "aliases": [
+ "pen"
+ ]
+ },
+ {
+ "emoji": "✏️",
+ "aliases": [
+ "pencil2"
+ ]
+ },
+ {
+ "emoji": "🐧",
+ "aliases": [
+ "penguin"
+ ]
+ },
+ {
+ "emoji": "😔",
+ "aliases": [
+ "pensive"
+ ]
+ },
+ {
+ "emoji": "🧑🤝🧑",
+ "aliases": [
+ "people_holding_hands"
+ ]
+ },
+ {
+ "emoji": "🫂",
+ "aliases": [
+ "people_hugging"
+ ]
+ },
+ {
+ "emoji": "🎭",
+ "aliases": [
+ "performing_arts"
+ ]
+ },
+ {
+ "emoji": "😣",
+ "aliases": [
+ "persevere"
+ ]
+ },
+ {
+ "emoji": "🧑🦲",
+ "aliases": [
+ "person_bald"
+ ]
+ },
+ {
+ "emoji": "🧑🦱",
+ "aliases": [
+ "person_curly_hair"
+ ]
+ },
+ {
+ "emoji": "🧑🍼",
+ "aliases": [
+ "person_feeding_baby"
+ ]
+ },
+ {
+ "emoji": "🤺",
+ "aliases": [
+ "person_fencing"
+ ]
+ },
+ {
+ "emoji": "🧑🦽",
+ "aliases": [
+ "person_in_manual_wheelchair"
+ ]
+ },
+ {
+ "emoji": "🧑🦽➡️",
+ "aliases": [
+ "person_in_manual_wheelchair_facing_right"
+ ]
+ },
+ {
+ "emoji": "🧑🦼",
+ "aliases": [
+ "person_in_motorized_wheelchair"
+ ]
+ },
+ {
+ "emoji": "🧑🦼➡️",
+ "aliases": [
+ "person_in_motorized_wheelchair_facing_right"
+ ]
+ },
+ {
+ "emoji": "🤵",
+ "aliases": [
+ "person_in_tuxedo"
+ ]
+ },
+ {
+ "emoji": "🧎➡️",
+ "aliases": [
+ "person_kneeling_facing_right"
+ ]
+ },
+ {
+ "emoji": "🧑🦰",
+ "aliases": [
+ "person_red_hair"
+ ]
+ },
+ {
+ "emoji": "🏃➡️",
+ "aliases": [
+ "person_running_facing_right"
+ ]
+ },
+ {
+ "emoji": "🚶➡️",
+ "aliases": [
+ "person_walking_facing_right"
+ ]
+ },
+ {
+ "emoji": "🧑🦳",
+ "aliases": [
+ "person_white_hair"
+ ]
+ },
+ {
+ "emoji": "🫅",
+ "aliases": [
+ "person_with_crown"
+ ]
+ },
+ {
+ "emoji": "🧑🦯",
+ "aliases": [
+ "person_with_probing_cane"
+ ]
+ },
+ {
+ "emoji": "👳",
+ "aliases": [
+ "person_with_turban"
+ ]
+ },
+ {
+ "emoji": "👰",
+ "aliases": [
+ "person_with_veil"
+ ]
+ },
+ {
+ "emoji": "🧑🦯➡️",
+ "aliases": [
+ "person_with_white_cane_facing_right"
+ ]
+ },
+ {
+ "emoji": "🇵🇪",
+ "aliases": [
+ "peru"
+ ]
+ },
+ {
+ "emoji": "🧫",
+ "aliases": [
+ "petri_dish"
+ ]
+ },
+ {
+ "emoji": "🇵🇭",
+ "aliases": [
+ "philippines"
+ ]
+ },
+ {
+ "emoji": "🐦🔥",
+ "aliases": [
+ "phoenix"
+ ]
+ },
+ {
+ "emoji": "☎️",
+ "aliases": [
+ "phone",
+ "telephone"
+ ]
+ },
+ {
+ "emoji": "⛏️",
+ "aliases": [
+ "pick"
+ ]
+ },
+ {
+ "emoji": "🛻",
+ "aliases": [
+ "pickup_truck"
+ ]
+ },
+ {
+ "emoji": "🥧",
+ "aliases": [
+ "pie"
+ ]
+ },
+ {
+ "emoji": "🐷",
+ "aliases": [
+ "pig"
+ ]
+ },
+ {
+ "emoji": "🐖",
+ "aliases": [
+ "pig2"
+ ]
+ },
+ {
+ "emoji": "🐽",
+ "aliases": [
+ "pig_nose"
+ ]
+ },
+ {
+ "emoji": "💊",
+ "aliases": [
+ "pill"
+ ]
+ },
+ {
+ "emoji": "🧑✈️",
+ "aliases": [
+ "pilot"
+ ]
+ },
+ {
+ "emoji": "🪅",
+ "aliases": [
+ "pinata"
+ ]
+ },
+ {
+ "emoji": "🤌",
+ "aliases": [
+ "pinched_fingers"
+ ]
+ },
+ {
+ "emoji": "🤏",
+ "aliases": [
+ "pinching_hand"
+ ]
+ },
+ {
+ "emoji": "🍍",
+ "aliases": [
+ "pineapple"
+ ]
+ },
+ {
+ "emoji": "🏓",
+ "aliases": [
+ "ping_pong"
+ ]
+ },
+ {
+ "emoji": "🩷",
+ "aliases": [
+ "pink_heart"
+ ]
+ },
+ {
+ "emoji": "🏴☠️",
+ "aliases": [
+ "pirate_flag"
+ ]
+ },
+ {
+ "emoji": "♓",
+ "aliases": [
+ "pisces"
+ ]
+ },
+ {
+ "emoji": "🇵🇳",
+ "aliases": [
+ "pitcairn_islands"
+ ]
+ },
+ {
+ "emoji": "🍕",
+ "aliases": [
+ "pizza"
+ ]
+ },
+ {
+ "emoji": "🪧",
+ "aliases": [
+ "placard"
+ ]
+ },
+ {
+ "emoji": "🛐",
+ "aliases": [
+ "place_of_worship"
+ ]
+ },
+ {
+ "emoji": "🍽️",
+ "aliases": [
+ "plate_with_cutlery"
+ ]
+ },
+ {
+ "emoji": "⏯️",
+ "aliases": [
+ "play_or_pause_button"
+ ]
+ },
+ {
+ "emoji": "🛝",
+ "aliases": [
+ "playground_slide"
+ ]
+ },
+ {
+ "emoji": "🥺",
+ "aliases": [
+ "pleading_face"
+ ]
+ },
+ {
+ "emoji": "🪠",
+ "aliases": [
+ "plunger"
+ ]
+ },
+ {
+ "emoji": "👇",
+ "aliases": [
+ "point_down"
+ ]
+ },
+ {
+ "emoji": "👈",
+ "aliases": [
+ "point_left"
+ ]
+ },
+ {
+ "emoji": "👉",
+ "aliases": [
+ "point_right"
+ ]
+ },
+ {
+ "emoji": "☝️",
+ "aliases": [
+ "point_up"
+ ]
+ },
+ {
+ "emoji": "👆",
+ "aliases": [
+ "point_up_2"
+ ]
+ },
+ {
+ "emoji": "🇵🇱",
+ "aliases": [
+ "poland"
+ ]
+ },
+ {
+ "emoji": "🐻❄️",
+ "aliases": [
+ "polar_bear"
+ ]
+ },
+ {
+ "emoji": "🚓",
+ "aliases": [
+ "police_car"
+ ]
+ },
+ {
+ "emoji": "👮",
+ "aliases": [
+ "police_officer",
+ "cop"
+ ]
+ },
+ {
+ "emoji": "👮♂️",
+ "aliases": [
+ "policeman"
+ ]
+ },
+ {
+ "emoji": "👮♀️",
+ "aliases": [
+ "policewoman"
+ ]
+ },
+ {
+ "emoji": "🐩",
+ "aliases": [
+ "poodle"
+ ]
+ },
+ {
+ "emoji": "🍿",
+ "aliases": [
+ "popcorn"
+ ]
+ },
+ {
+ "emoji": "🇵🇹",
+ "aliases": [
+ "portugal"
+ ]
+ },
+ {
+ "emoji": "🏣",
+ "aliases": [
+ "post_office"
+ ]
+ },
+ {
+ "emoji": "📯",
+ "aliases": [
+ "postal_horn"
+ ]
+ },
+ {
+ "emoji": "📮",
+ "aliases": [
+ "postbox"
+ ]
+ },
+ {
+ "emoji": "🚰",
+ "aliases": [
+ "potable_water"
+ ]
+ },
+ {
+ "emoji": "🥔",
+ "aliases": [
+ "potato"
+ ]
+ },
+ {
+ "emoji": "🪴",
+ "aliases": [
+ "potted_plant"
+ ]
+ },
+ {
+ "emoji": "👝",
+ "aliases": [
+ "pouch"
+ ]
+ },
+ {
+ "emoji": "🍗",
+ "aliases": [
+ "poultry_leg"
+ ]
+ },
+ {
+ "emoji": "💷",
+ "aliases": [
+ "pound"
+ ]
+ },
+ {
+ "emoji": "🫗",
+ "aliases": [
+ "pouring_liquid"
+ ]
+ },
+ {
+ "emoji": "😾",
+ "aliases": [
+ "pouting_cat"
+ ]
+ },
+ {
+ "emoji": "🙎",
+ "aliases": [
+ "pouting_face"
+ ]
+ },
+ {
+ "emoji": "🙎♂️",
+ "aliases": [
+ "pouting_man"
+ ]
+ },
+ {
+ "emoji": "🙎♀️",
+ "aliases": [
+ "pouting_woman"
+ ]
+ },
+ {
+ "emoji": "🙏",
+ "aliases": [
+ "pray"
+ ]
+ },
+ {
+ "emoji": "📿",
+ "aliases": [
+ "prayer_beads"
+ ]
+ },
+ {
+ "emoji": "🫃",
+ "aliases": [
+ "pregnant_man"
+ ]
+ },
+ {
+ "emoji": "🫄",
+ "aliases": [
+ "pregnant_person"
+ ]
+ },
+ {
+ "emoji": "🤰",
+ "aliases": [
+ "pregnant_woman"
+ ]
+ },
+ {
+ "emoji": "🥨",
+ "aliases": [
+ "pretzel"
+ ]
+ },
+ {
+ "emoji": "⏮️",
+ "aliases": [
+ "previous_track_button"
+ ]
+ },
+ {
+ "emoji": "🤴",
+ "aliases": [
+ "prince"
+ ]
+ },
+ {
+ "emoji": "👸",
+ "aliases": [
+ "princess"
+ ]
+ },
+ {
+ "emoji": "🖨️",
+ "aliases": [
+ "printer"
+ ]
+ },
+ {
+ "emoji": "🦯",
+ "aliases": [
+ "probing_cane"
+ ]
+ },
+ {
+ "emoji": "🇵🇷",
+ "aliases": [
+ "puerto_rico"
+ ]
+ },
+ {
+ "emoji": "🟣",
+ "aliases": [
+ "purple_circle"
+ ]
+ },
+ {
+ "emoji": "💜",
+ "aliases": [
+ "purple_heart"
+ ]
+ },
+ {
+ "emoji": "🟪",
+ "aliases": [
+ "purple_square"
+ ]
+ },
+ {
+ "emoji": "👛",
+ "aliases": [
+ "purse"
+ ]
+ },
+ {
+ "emoji": "📌",
+ "aliases": [
+ "pushpin"
+ ]
+ },
+ {
+ "emoji": "🚮",
+ "aliases": [
+ "put_litter_in_its_place"
+ ]
+ },
+ {
+ "emoji": "🇶🇦",
+ "aliases": [
+ "qatar"
+ ]
+ },
+ {
+ "emoji": "❓",
+ "aliases": [
+ "question"
+ ]
+ },
+ {
+ "emoji": "🐰",
+ "aliases": [
+ "rabbit"
+ ]
+ },
+ {
+ "emoji": "🐇",
+ "aliases": [
+ "rabbit2"
+ ]
+ },
+ {
+ "emoji": "🦝",
+ "aliases": [
+ "raccoon"
+ ]
+ },
+ {
+ "emoji": "🐎",
+ "aliases": [
+ "racehorse"
+ ]
+ },
+ {
+ "emoji": "🏎️",
+ "aliases": [
+ "racing_car"
+ ]
+ },
+ {
+ "emoji": "📻",
+ "aliases": [
+ "radio"
+ ]
+ },
+ {
+ "emoji": "🔘",
+ "aliases": [
+ "radio_button"
+ ]
+ },
+ {
+ "emoji": "☢️",
+ "aliases": [
+ "radioactive"
+ ]
+ },
+ {
+ "emoji": "😡",
+ "aliases": [
+ "rage",
+ "pout"
+ ]
+ },
+ {
+ "emoji": "🚃",
+ "aliases": [
+ "railway_car"
+ ]
+ },
+ {
+ "emoji": "🛤️",
+ "aliases": [
+ "railway_track"
+ ]
+ },
+ {
+ "emoji": "🌈",
+ "aliases": [
+ "rainbow"
+ ]
+ },
+ {
+ "emoji": "🏳️🌈",
+ "aliases": [
+ "rainbow_flag"
+ ]
+ },
+ {
+ "emoji": "🤚",
+ "aliases": [
+ "raised_back_of_hand"
+ ]
+ },
+ {
+ "emoji": "🤨",
+ "aliases": [
+ "raised_eyebrow"
+ ]
+ },
+ {
+ "emoji": "🖐️",
+ "aliases": [
+ "raised_hand_with_fingers_splayed"
+ ]
+ },
+ {
+ "emoji": "🙌",
+ "aliases": [
+ "raised_hands"
+ ]
+ },
+ {
+ "emoji": "🙋",
+ "aliases": [
+ "raising_hand"
+ ]
+ },
+ {
+ "emoji": "🙋♂️",
+ "aliases": [
+ "raising_hand_man"
+ ]
+ },
+ {
+ "emoji": "🙋♀️",
+ "aliases": [
+ "raising_hand_woman"
+ ]
+ },
+ {
+ "emoji": "🐏",
+ "aliases": [
+ "ram"
+ ]
+ },
+ {
+ "emoji": "🍜",
+ "aliases": [
+ "ramen"
+ ]
+ },
+ {
+ "emoji": "🐀",
+ "aliases": [
+ "rat"
+ ]
+ },
+ {
+ "emoji": "🪒",
+ "aliases": [
+ "razor"
+ ]
+ },
+ {
+ "emoji": "🧾",
+ "aliases": [
+ "receipt"
+ ]
+ },
+ {
+ "emoji": "⏺️",
+ "aliases": [
+ "record_button"
+ ]
+ },
+ {
+ "emoji": "♻️",
+ "aliases": [
+ "recycle"
+ ]
+ },
+ {
+ "emoji": "🔴",
+ "aliases": [
+ "red_circle"
+ ]
+ },
+ {
+ "emoji": "🧧",
+ "aliases": [
+ "red_envelope"
+ ]
+ },
+ {
+ "emoji": "👨🦰",
+ "aliases": [
+ "red_haired_man"
+ ]
+ },
+ {
+ "emoji": "👩🦰",
+ "aliases": [
+ "red_haired_woman"
+ ]
+ },
+ {
+ "emoji": "🟥",
+ "aliases": [
+ "red_square"
+ ]
+ },
+ {
+ "emoji": "®️",
+ "aliases": [
+ "registered"
+ ]
+ },
+ {
+ "emoji": "☺️",
+ "aliases": [
+ "relaxed"
+ ]
+ },
+ {
+ "emoji": "😌",
+ "aliases": [
+ "relieved"
+ ]
+ },
+ {
+ "emoji": "🎗️",
+ "aliases": [
+ "reminder_ribbon"
+ ]
+ },
+ {
+ "emoji": "🔁",
+ "aliases": [
+ "repeat"
+ ]
+ },
+ {
+ "emoji": "🔂",
+ "aliases": [
+ "repeat_one"
+ ]
+ },
+ {
+ "emoji": "⛑️",
+ "aliases": [
+ "rescue_worker_helmet"
+ ]
+ },
+ {
+ "emoji": "🚻",
+ "aliases": [
+ "restroom"
+ ]
+ },
+ {
+ "emoji": "🇷🇪",
+ "aliases": [
+ "reunion"
+ ]
+ },
+ {
+ "emoji": "💞",
+ "aliases": [
+ "revolving_hearts"
+ ]
+ },
+ {
+ "emoji": "⏪",
+ "aliases": [
+ "rewind"
+ ]
+ },
+ {
+ "emoji": "🦏",
+ "aliases": [
+ "rhinoceros"
+ ]
+ },
+ {
+ "emoji": "🎀",
+ "aliases": [
+ "ribbon"
+ ]
+ },
+ {
+ "emoji": "🍚",
+ "aliases": [
+ "rice"
+ ]
+ },
+ {
+ "emoji": "🍙",
+ "aliases": [
+ "rice_ball"
+ ]
+ },
+ {
+ "emoji": "🍘",
+ "aliases": [
+ "rice_cracker"
+ ]
+ },
+ {
+ "emoji": "🎑",
+ "aliases": [
+ "rice_scene"
+ ]
+ },
+ {
+ "emoji": "🗯️",
+ "aliases": [
+ "right_anger_bubble"
+ ]
+ },
+ {
+ "emoji": "🫱",
+ "aliases": [
+ "rightwards_hand"
+ ]
+ },
+ {
+ "emoji": "🫸",
+ "aliases": [
+ "rightwards_pushing_hand"
+ ]
+ },
+ {
+ "emoji": "💍",
+ "aliases": [
+ "ring"
+ ]
+ },
+ {
+ "emoji": "🛟",
+ "aliases": [
+ "ring_buoy"
+ ]
+ },
+ {
+ "emoji": "🪐",
+ "aliases": [
+ "ringed_planet"
+ ]
+ },
+ {
+ "emoji": "🤖",
+ "aliases": [
+ "robot"
+ ]
+ },
+ {
+ "emoji": "🪨",
+ "aliases": [
+ "rock"
+ ]
+ },
+ {
+ "emoji": "🚀",
+ "aliases": [
+ "rocket"
+ ]
+ },
+ {
+ "emoji": "🤣",
+ "aliases": [
+ "rofl"
+ ]
+ },
+ {
+ "emoji": "🙄",
+ "aliases": [
+ "roll_eyes"
+ ]
+ },
+ {
+ "emoji": "🧻",
+ "aliases": [
+ "roll_of_paper"
+ ]
+ },
+ {
+ "emoji": "🎢",
+ "aliases": [
+ "roller_coaster"
+ ]
+ },
+ {
+ "emoji": "🛼",
+ "aliases": [
+ "roller_skate"
+ ]
+ },
+ {
+ "emoji": "🇷🇴",
+ "aliases": [
+ "romania"
+ ]
+ },
+ {
+ "emoji": "🐓",
+ "aliases": [
+ "rooster"
+ ]
+ },
+ {
+ "emoji": "",
+ "aliases": [
+ "root_vegetable"
+ ]
+ },
+ {
+ "emoji": "🌹",
+ "aliases": [
+ "rose"
+ ]
+ },
+ {
+ "emoji": "🏵️",
+ "aliases": [
+ "rosette"
+ ]
+ },
+ {
+ "emoji": "🚨",
+ "aliases": [
+ "rotating_light"
+ ]
+ },
+ {
+ "emoji": "📍",
+ "aliases": [
+ "round_pushpin"
+ ]
+ },
+ {
+ "emoji": "🚣",
+ "aliases": [
+ "rowboat"
+ ]
+ },
+ {
+ "emoji": "🚣♂️",
+ "aliases": [
+ "rowing_man"
+ ]
+ },
+ {
+ "emoji": "🚣♀️",
+ "aliases": [
+ "rowing_woman"
+ ]
+ },
+ {
+ "emoji": "🇷🇺",
+ "aliases": [
+ "ru"
+ ]
+ },
+ {
+ "emoji": "🏉",
+ "aliases": [
+ "rugby_football"
+ ]
+ },
+ {
+ "emoji": "🏃",
+ "aliases": [
+ "runner",
+ "running"
+ ]
+ },
+ {
+ "emoji": "🏃♂️",
+ "aliases": [
+ "running_man"
+ ]
+ },
+ {
+ "emoji": "🎽",
+ "aliases": [
+ "running_shirt_with_sash"
+ ]
+ },
+ {
+ "emoji": "🏃♀️",
+ "aliases": [
+ "running_woman"
+ ]
+ },
+ {
+ "emoji": "🇷🇼",
+ "aliases": [
+ "rwanda"
+ ]
+ },
+ {
+ "emoji": "🈂️",
+ "aliases": [
+ "sa"
+ ]
+ },
+ {
+ "emoji": "🧷",
+ "aliases": [
+ "safety_pin"
+ ]
+ },
+ {
+ "emoji": "🦺",
+ "aliases": [
+ "safety_vest"
+ ]
+ },
+ {
+ "emoji": "♐",
+ "aliases": [
+ "sagittarius"
+ ]
+ },
+ {
+ "emoji": "🍶",
+ "aliases": [
+ "sake"
+ ]
+ },
+ {
+ "emoji": "🧂",
+ "aliases": [
+ "salt"
+ ]
+ },
+ {
+ "emoji": "🫡",
+ "aliases": [
+ "saluting_face"
+ ]
+ },
+ {
+ "emoji": "🇼🇸",
+ "aliases": [
+ "samoa"
+ ]
+ },
+ {
+ "emoji": "🇸🇲",
+ "aliases": [
+ "san_marino"
+ ]
+ },
+ {
+ "emoji": "👡",
+ "aliases": [
+ "sandal"
+ ]
+ },
+ {
+ "emoji": "🥪",
+ "aliases": [
+ "sandwich"
+ ]
+ },
+ {
+ "emoji": "🎅",
+ "aliases": [
+ "santa"
+ ]
+ },
+ {
+ "emoji": "🇸🇹",
+ "aliases": [
+ "sao_tome_principe"
+ ]
+ },
+ {
+ "emoji": "🥻",
+ "aliases": [
+ "sari"
+ ]
+ },
+ {
+ "emoji": "📡",
+ "aliases": [
+ "satellite"
+ ]
+ },
+ {
+ "emoji": "🇸🇦",
+ "aliases": [
+ "saudi_arabia"
+ ]
+ },
+ {
+ "emoji": "🧖♂️",
+ "aliases": [
+ "sauna_man"
+ ]
+ },
+ {
+ "emoji": "🧖",
+ "aliases": [
+ "sauna_person"
+ ]
+ },
+ {
+ "emoji": "🧖♀️",
+ "aliases": [
+ "sauna_woman"
+ ]
+ },
+ {
+ "emoji": "🦕",
+ "aliases": [
+ "sauropod"
+ ]
+ },
+ {
+ "emoji": "🎷",
+ "aliases": [
+ "saxophone"
+ ]
+ },
+ {
+ "emoji": "🧣",
+ "aliases": [
+ "scarf"
+ ]
+ },
+ {
+ "emoji": "🏫",
+ "aliases": [
+ "school"
+ ]
+ },
+ {
+ "emoji": "🎒",
+ "aliases": [
+ "school_satchel"
+ ]
+ },
+ {
+ "emoji": "🧑🔬",
+ "aliases": [
+ "scientist"
+ ]
+ },
+ {
+ "emoji": "✂️",
+ "aliases": [
+ "scissors"
+ ]
+ },
+ {
+ "emoji": "🦂",
+ "aliases": [
+ "scorpion"
+ ]
+ },
+ {
+ "emoji": "♏",
+ "aliases": [
+ "scorpius"
+ ]
+ },
+ {
+ "emoji": "🏴",
+ "aliases": [
+ "scotland"
+ ]
+ },
+ {
+ "emoji": "😱",
+ "aliases": [
+ "scream"
+ ]
+ },
+ {
+ "emoji": "🙀",
+ "aliases": [
+ "scream_cat"
+ ]
+ },
+ {
+ "emoji": "🪛",
+ "aliases": [
+ "screwdriver"
+ ]
+ },
+ {
+ "emoji": "📜",
+ "aliases": [
+ "scroll"
+ ]
+ },
+ {
+ "emoji": "🦭",
+ "aliases": [
+ "seal"
+ ]
+ },
+ {
+ "emoji": "💺",
+ "aliases": [
+ "seat"
+ ]
+ },
+ {
+ "emoji": "㊙️",
+ "aliases": [
+ "secret"
+ ]
+ },
+ {
+ "emoji": "🙈",
+ "aliases": [
+ "see_no_evil"
+ ]
+ },
+ {
+ "emoji": "🌱",
+ "aliases": [
+ "seedling"
+ ]
+ },
+ {
+ "emoji": "🤳",
+ "aliases": [
+ "selfie"
+ ]
+ },
+ {
+ "emoji": "🇸🇳",
+ "aliases": [
+ "senegal"
+ ]
+ },
+ {
+ "emoji": "🇷🇸",
+ "aliases": [
+ "serbia"
+ ]
+ },
+ {
+ "emoji": "🐕🦺",
+ "aliases": [
+ "service_dog"
+ ]
+ },
+ {
+ "emoji": "7️⃣",
+ "aliases": [
+ "seven"
+ ]
+ },
+ {
+ "emoji": "🪡",
+ "aliases": [
+ "sewing_needle"
+ ]
+ },
+ {
+ "emoji": "🇸🇨",
+ "aliases": [
+ "seychelles"
+ ]
+ },
+ {
+ "emoji": "🫨",
+ "aliases": [
+ "shaking_face"
+ ]
+ },
+ {
+ "emoji": "🥘",
+ "aliases": [
+ "shallow_pan_of_food"
+ ]
+ },
+ {
+ "emoji": "☘️",
+ "aliases": [
+ "shamrock"
+ ]
+ },
+ {
+ "emoji": "🦈",
+ "aliases": [
+ "shark"
+ ]
+ },
+ {
+ "emoji": "🍧",
+ "aliases": [
+ "shaved_ice"
+ ]
+ },
+ {
+ "emoji": "🐑",
+ "aliases": [
+ "sheep"
+ ]
+ },
+ {
+ "emoji": "🐚",
+ "aliases": [
+ "shell"
+ ]
+ },
+ {
+ "emoji": "🛡️",
+ "aliases": [
+ "shield"
+ ]
+ },
+ {
+ "emoji": "⛩️",
+ "aliases": [
+ "shinto_shrine"
+ ]
+ },
+ {
+ "emoji": "🚢",
+ "aliases": [
+ "ship"
+ ]
+ },
+ {
+ "emoji": "👕",
+ "aliases": [
+ "shirt",
+ "tshirt"
+ ]
+ },
+ {
+ "emoji": "🛍️",
+ "aliases": [
+ "shopping"
+ ]
+ },
+ {
+ "emoji": "🛒",
+ "aliases": [
+ "shopping_cart"
+ ]
+ },
+ {
+ "emoji": "🩳",
+ "aliases": [
+ "shorts"
+ ]
+ },
+ {
+ "emoji": "",
+ "aliases": [
+ "shovel"
+ ]
+ },
+ {
+ "emoji": "🚿",
+ "aliases": [
+ "shower"
+ ]
+ },
+ {
+ "emoji": "🦐",
+ "aliases": [
+ "shrimp"
+ ]
+ },
+ {
+ "emoji": "🤷",
+ "aliases": [
+ "shrug"
+ ]
+ },
+ {
+ "emoji": "🤫",
+ "aliases": [
+ "shushing_face"
+ ]
+ },
+ {
+ "emoji": "🇸🇱",
+ "aliases": [
+ "sierra_leone"
+ ]
+ },
+ {
+ "emoji": "📶",
+ "aliases": [
+ "signal_strength"
+ ]
+ },
+ {
+ "emoji": "🇸🇬",
+ "aliases": [
+ "singapore"
+ ]
+ },
+ {
+ "emoji": "🧑🎤",
+ "aliases": [
+ "singer"
+ ]
+ },
+ {
+ "emoji": "🇸🇽",
+ "aliases": [
+ "sint_maarten"
+ ]
+ },
+ {
+ "emoji": "6️⃣",
+ "aliases": [
+ "six"
+ ]
+ },
+ {
+ "emoji": "🔯",
+ "aliases": [
+ "six_pointed_star"
+ ]
+ },
+ {
+ "emoji": "🛹",
+ "aliases": [
+ "skateboard"
+ ]
+ },
+ {
+ "emoji": "🎿",
+ "aliases": [
+ "ski"
+ ]
+ },
+ {
+ "emoji": "⛷️",
+ "aliases": [
+ "skier"
+ ]
+ },
+ {
+ "emoji": "💀",
+ "aliases": [
+ "skull"
+ ]
+ },
+ {
+ "emoji": "☠️",
+ "aliases": [
+ "skull_and_crossbones"
+ ]
+ },
+ {
+ "emoji": "🦨",
+ "aliases": [
+ "skunk"
+ ]
+ },
+ {
+ "emoji": "🛷",
+ "aliases": [
+ "sled"
+ ]
+ },
+ {
+ "emoji": "😴",
+ "aliases": [
+ "sleeping"
+ ]
+ },
+ {
+ "emoji": "🛌",
+ "aliases": [
+ "sleeping_bed"
+ ]
+ },
+ {
+ "emoji": "😪",
+ "aliases": [
+ "sleepy"
+ ]
+ },
+ {
+ "emoji": "🙁",
+ "aliases": [
+ "slightly_frowning_face"
+ ]
+ },
+ {
+ "emoji": "🙂",
+ "aliases": [
+ "slightly_smiling_face"
+ ]
+ },
+ {
+ "emoji": "🎰",
+ "aliases": [
+ "slot_machine"
+ ]
+ },
+ {
+ "emoji": "🦥",
+ "aliases": [
+ "sloth"
+ ]
+ },
+ {
+ "emoji": "🇸🇰",
+ "aliases": [
+ "slovakia"
+ ]
+ },
+ {
+ "emoji": "🇸🇮",
+ "aliases": [
+ "slovenia"
+ ]
+ },
+ {
+ "emoji": "🛩️",
+ "aliases": [
+ "small_airplane"
+ ]
+ },
+ {
+ "emoji": "🔹",
+ "aliases": [
+ "small_blue_diamond"
+ ]
+ },
+ {
+ "emoji": "🔸",
+ "aliases": [
+ "small_orange_diamond"
+ ]
+ },
+ {
+ "emoji": "🔺",
+ "aliases": [
+ "small_red_triangle"
+ ]
+ },
+ {
+ "emoji": "🔻",
+ "aliases": [
+ "small_red_triangle_down"
+ ]
+ },
+ {
+ "emoji": "😄",
+ "aliases": [
+ "smile"
+ ]
+ },
+ {
+ "emoji": "😸",
+ "aliases": [
+ "smile_cat"
+ ]
+ },
+ {
+ "emoji": "😃",
+ "aliases": [
+ "smiley"
+ ]
+ },
+ {
+ "emoji": "😺",
+ "aliases": [
+ "smiley_cat"
+ ]
+ },
+ {
+ "emoji": "🥲",
+ "aliases": [
+ "smiling_face_with_tear"
+ ]
+ },
+ {
+ "emoji": "🥰",
+ "aliases": [
+ "smiling_face_with_three_hearts"
+ ]
+ },
+ {
+ "emoji": "😈",
+ "aliases": [
+ "smiling_imp"
+ ]
+ },
+ {
+ "emoji": "😏",
+ "aliases": [
+ "smirk"
+ ]
+ },
+ {
+ "emoji": "😼",
+ "aliases": [
+ "smirk_cat"
+ ]
+ },
+ {
+ "emoji": "🚬",
+ "aliases": [
+ "smoking"
+ ]
+ },
+ {
+ "emoji": "🐌",
+ "aliases": [
+ "snail"
+ ]
+ },
+ {
+ "emoji": "🐍",
+ "aliases": [
+ "snake"
+ ]
+ },
+ {
+ "emoji": "🤧",
+ "aliases": [
+ "sneezing_face"
+ ]
+ },
+ {
+ "emoji": "🏂",
+ "aliases": [
+ "snowboarder"
+ ]
+ },
+ {
+ "emoji": "❄️",
+ "aliases": [
+ "snowflake"
+ ]
+ },
+ {
+ "emoji": "⛄",
+ "aliases": [
+ "snowman"
+ ]
+ },
+ {
+ "emoji": "☃️",
+ "aliases": [
+ "snowman_with_snow"
+ ]
+ },
+ {
+ "emoji": "🧼",
+ "aliases": [
+ "soap"
+ ]
+ },
+ {
+ "emoji": "😭",
+ "aliases": [
+ "sob"
+ ]
+ },
+ {
+ "emoji": "⚽",
+ "aliases": [
+ "soccer"
+ ]
+ },
+ {
+ "emoji": "🧦",
+ "aliases": [
+ "socks"
+ ]
+ },
+ {
+ "emoji": "🥎",
+ "aliases": [
+ "softball"
+ ]
+ },
+ {
+ "emoji": "🇸🇧",
+ "aliases": [
+ "solomon_islands"
+ ]
+ },
+ {
+ "emoji": "🇸🇴",
+ "aliases": [
+ "somalia"
+ ]
+ },
+ {
+ "emoji": "🔜",
+ "aliases": [
+ "soon"
+ ]
+ },
+ {
+ "emoji": "🆘",
+ "aliases": [
+ "sos"
+ ]
+ },
+ {
+ "emoji": "🔉",
+ "aliases": [
+ "sound"
+ ]
+ },
+ {
+ "emoji": "🇿🇦",
+ "aliases": [
+ "south_africa"
+ ]
+ },
+ {
+ "emoji": "🇬🇸",
+ "aliases": [
+ "south_georgia_south_sandwich_islands"
+ ]
+ },
+ {
+ "emoji": "🇸🇸",
+ "aliases": [
+ "south_sudan"
+ ]
+ },
+ {
+ "emoji": "👾",
+ "aliases": [
+ "space_invader"
+ ]
+ },
+ {
+ "emoji": "♠️",
+ "aliases": [
+ "spades"
+ ]
+ },
+ {
+ "emoji": "🍝",
+ "aliases": [
+ "spaghetti"
+ ]
+ },
+ {
+ "emoji": "❇️",
+ "aliases": [
+ "sparkle"
+ ]
+ },
+ {
+ "emoji": "🎇",
+ "aliases": [
+ "sparkler"
+ ]
+ },
+ {
+ "emoji": "✨",
+ "aliases": [
+ "sparkles"
+ ]
+ },
+ {
+ "emoji": "💖",
+ "aliases": [
+ "sparkling_heart"
+ ]
+ },
+ {
+ "emoji": "🙊",
+ "aliases": [
+ "speak_no_evil"
+ ]
+ },
+ {
+ "emoji": "🔈",
+ "aliases": [
+ "speaker"
+ ]
+ },
+ {
+ "emoji": "🗣️",
+ "aliases": [
+ "speaking_head"
+ ]
+ },
+ {
+ "emoji": "💬",
+ "aliases": [
+ "speech_balloon"
+ ]
+ },
+ {
+ "emoji": "🚤",
+ "aliases": [
+ "speedboat"
+ ]
+ },
+ {
+ "emoji": "🕷️",
+ "aliases": [
+ "spider"
+ ]
+ },
+ {
+ "emoji": "🕸️",
+ "aliases": [
+ "spider_web"
+ ]
+ },
+ {
+ "emoji": "🗓️",
+ "aliases": [
+ "spiral_calendar"
+ ]
+ },
+ {
+ "emoji": "🗒️",
+ "aliases": [
+ "spiral_notepad"
+ ]
+ },
+ {
+ "emoji": "",
+ "aliases": [
+ "splatter"
+ ]
+ },
+ {
+ "emoji": "🧽",
+ "aliases": [
+ "sponge"
+ ]
+ },
+ {
+ "emoji": "🥄",
+ "aliases": [
+ "spoon"
+ ]
+ },
+ {
+ "emoji": "🦑",
+ "aliases": [
+ "squid"
+ ]
+ },
+ {
+ "emoji": "🇱🇰",
+ "aliases": [
+ "sri_lanka"
+ ]
+ },
+ {
+ "emoji": "🇧🇱",
+ "aliases": [
+ "st_barthelemy"
+ ]
+ },
+ {
+ "emoji": "🇸🇭",
+ "aliases": [
+ "st_helena"
+ ]
+ },
+ {
+ "emoji": "🇰🇳",
+ "aliases": [
+ "st_kitts_nevis"
+ ]
+ },
+ {
+ "emoji": "🇱🇨",
+ "aliases": [
+ "st_lucia"
+ ]
+ },
+ {
+ "emoji": "🇲🇫",
+ "aliases": [
+ "st_martin"
+ ]
+ },
+ {
+ "emoji": "🇵🇲",
+ "aliases": [
+ "st_pierre_miquelon"
+ ]
+ },
+ {
+ "emoji": "🇻🇨",
+ "aliases": [
+ "st_vincent_grenadines"
+ ]
+ },
+ {
+ "emoji": "🏟️",
+ "aliases": [
+ "stadium"
+ ]
+ },
+ {
+ "emoji": "🧍♂️",
+ "aliases": [
+ "standing_man"
+ ]
+ },
+ {
+ "emoji": "🧍",
+ "aliases": [
+ "standing_person"
+ ]
+ },
+ {
+ "emoji": "🧍♀️",
+ "aliases": [
+ "standing_woman"
+ ]
+ },
+ {
+ "emoji": "⭐",
+ "aliases": [
+ "star"
+ ]
+ },
+ {
+ "emoji": "🌟",
+ "aliases": [
+ "star2"
+ ]
+ },
+ {
+ "emoji": "☪️",
+ "aliases": [
+ "star_and_crescent"
+ ]
+ },
+ {
+ "emoji": "✡️",
+ "aliases": [
+ "star_of_david"
+ ]
+ },
+ {
+ "emoji": "🤩",
+ "aliases": [
+ "star_struck"
+ ]
+ },
+ {
+ "emoji": "🌠",
+ "aliases": [
+ "stars"
+ ]
+ },
+ {
+ "emoji": "🚉",
+ "aliases": [
+ "station"
+ ]
+ },
+ {
+ "emoji": "🗽",
+ "aliases": [
+ "statue_of_liberty"
+ ]
+ },
+ {
+ "emoji": "🚂",
+ "aliases": [
+ "steam_locomotive"
+ ]
+ },
+ {
+ "emoji": "🩺",
+ "aliases": [
+ "stethoscope"
+ ]
+ },
+ {
+ "emoji": "🍲",
+ "aliases": [
+ "stew"
+ ]
+ },
+ {
+ "emoji": "⏹️",
+ "aliases": [
+ "stop_button"
+ ]
+ },
+ {
+ "emoji": "🛑",
+ "aliases": [
+ "stop_sign"
+ ]
+ },
+ {
+ "emoji": "⏱️",
+ "aliases": [
+ "stopwatch"
+ ]
+ },
+ {
+ "emoji": "📏",
+ "aliases": [
+ "straight_ruler"
+ ]
+ },
+ {
+ "emoji": "🍓",
+ "aliases": [
+ "strawberry"
+ ]
+ },
+ {
+ "emoji": "😛",
+ "aliases": [
+ "stuck_out_tongue"
+ ]
+ },
+ {
+ "emoji": "😝",
+ "aliases": [
+ "stuck_out_tongue_closed_eyes"
+ ]
+ },
+ {
+ "emoji": "😜",
+ "aliases": [
+ "stuck_out_tongue_winking_eye"
+ ]
+ },
+ {
+ "emoji": "🧑🎓",
+ "aliases": [
+ "student"
+ ]
+ },
+ {
+ "emoji": "🎙️",
+ "aliases": [
+ "studio_microphone"
+ ]
+ },
+ {
+ "emoji": "🥙",
+ "aliases": [
+ "stuffed_flatbread"
+ ]
+ },
+ {
+ "emoji": "🇸🇩",
+ "aliases": [
+ "sudan"
+ ]
+ },
+ {
+ "emoji": "🌥️",
+ "aliases": [
+ "sun_behind_large_cloud"
+ ]
+ },
+ {
+ "emoji": "🌦️",
+ "aliases": [
+ "sun_behind_rain_cloud"
+ ]
+ },
+ {
+ "emoji": "🌤️",
+ "aliases": [
+ "sun_behind_small_cloud"
+ ]
+ },
+ {
+ "emoji": "🌞",
+ "aliases": [
+ "sun_with_face"
+ ]
+ },
+ {
+ "emoji": "🌻",
+ "aliases": [
+ "sunflower"
+ ]
+ },
+ {
+ "emoji": "😎",
+ "aliases": [
+ "sunglasses"
+ ]
+ },
+ {
+ "emoji": "☀️",
+ "aliases": [
+ "sunny"
+ ]
+ },
+ {
+ "emoji": "🌅",
+ "aliases": [
+ "sunrise"
+ ]
+ },
+ {
+ "emoji": "🌄",
+ "aliases": [
+ "sunrise_over_mountains"
+ ]
+ },
+ {
+ "emoji": "🦸",
+ "aliases": [
+ "superhero"
+ ]
+ },
+ {
+ "emoji": "🦸♂️",
+ "aliases": [
+ "superhero_man"
+ ]
+ },
+ {
+ "emoji": "🦸♀️",
+ "aliases": [
+ "superhero_woman"
+ ]
+ },
+ {
+ "emoji": "🦹",
+ "aliases": [
+ "supervillain"
+ ]
+ },
+ {
+ "emoji": "🦹♂️",
+ "aliases": [
+ "supervillain_man"
+ ]
+ },
+ {
+ "emoji": "🦹♀️",
+ "aliases": [
+ "supervillain_woman"
+ ]
+ },
+ {
+ "emoji": "🏄",
+ "aliases": [
+ "surfer"
+ ]
+ },
+ {
+ "emoji": "🏄♂️",
+ "aliases": [
+ "surfing_man"
+ ]
+ },
+ {
+ "emoji": "🏄♀️",
+ "aliases": [
+ "surfing_woman"
+ ]
+ },
+ {
+ "emoji": "🇸🇷",
+ "aliases": [
+ "suriname"
+ ]
+ },
+ {
+ "emoji": "🍣",
+ "aliases": [
+ "sushi"
+ ]
+ },
+ {
+ "emoji": "🚟",
+ "aliases": [
+ "suspension_railway"
+ ]
+ },
+ {
+ "emoji": "🇸🇯",
+ "aliases": [
+ "svalbard_jan_mayen"
+ ]
+ },
+ {
+ "emoji": "🦢",
+ "aliases": [
+ "swan"
+ ]
+ },
+ {
+ "emoji": "🇸🇿",
+ "aliases": [
+ "swaziland"
+ ]
+ },
+ {
+ "emoji": "😓",
+ "aliases": [
+ "sweat"
+ ]
+ },
+ {
+ "emoji": "💦",
+ "aliases": [
+ "sweat_drops"
+ ]
+ },
+ {
+ "emoji": "😅",
+ "aliases": [
+ "sweat_smile"
+ ]
+ },
+ {
+ "emoji": "🇸🇪",
+ "aliases": [
+ "sweden"
+ ]
+ },
+ {
+ "emoji": "🍠",
+ "aliases": [
+ "sweet_potato"
+ ]
+ },
+ {
+ "emoji": "🩲",
+ "aliases": [
+ "swim_brief"
+ ]
+ },
+ {
+ "emoji": "🏊",
+ "aliases": [
+ "swimmer"
+ ]
+ },
+ {
+ "emoji": "🏊♂️",
+ "aliases": [
+ "swimming_man"
+ ]
+ },
+ {
+ "emoji": "🏊♀️",
+ "aliases": [
+ "swimming_woman"
+ ]
+ },
+ {
+ "emoji": "🇨🇭",
+ "aliases": [
+ "switzerland"
+ ]
+ },
+ {
+ "emoji": "🔣",
+ "aliases": [
+ "symbols"
+ ]
+ },
+ {
+ "emoji": "🕍",
+ "aliases": [
+ "synagogue"
+ ]
+ },
+ {
+ "emoji": "🇸🇾",
+ "aliases": [
+ "syria"
+ ]
+ },
+ {
+ "emoji": "💉",
+ "aliases": [
+ "syringe"
+ ]
+ },
+ {
+ "emoji": "🦖",
+ "aliases": [
+ "t-rex"
+ ]
+ },
+ {
+ "emoji": "🌮",
+ "aliases": [
+ "taco"
+ ]
+ },
+ {
+ "emoji": "🎉",
+ "aliases": [
+ "tada",
+ "hooray"
+ ]
+ },
+ {
+ "emoji": "🇹🇼",
+ "aliases": [
+ "taiwan"
+ ]
+ },
+ {
+ "emoji": "🇹🇯",
+ "aliases": [
+ "tajikistan"
+ ]
+ },
+ {
+ "emoji": "🥡",
+ "aliases": [
+ "takeout_box"
+ ]
+ },
+ {
+ "emoji": "🫔",
+ "aliases": [
+ "tamale"
+ ]
+ },
+ {
+ "emoji": "🎋",
+ "aliases": [
+ "tanabata_tree"
+ ]
+ },
+ {
+ "emoji": "🍊",
+ "aliases": [
+ "tangerine",
+ "orange",
+ "mandarin"
+ ]
+ },
+ {
+ "emoji": "🇹🇿",
+ "aliases": [
+ "tanzania"
+ ]
+ },
+ {
+ "emoji": "♉",
+ "aliases": [
+ "taurus"
+ ]
+ },
+ {
+ "emoji": "🚕",
+ "aliases": [
+ "taxi"
+ ]
+ },
+ {
+ "emoji": "🍵",
+ "aliases": [
+ "tea"
+ ]
+ },
+ {
+ "emoji": "🧑🏫",
+ "aliases": [
+ "teacher"
+ ]
+ },
+ {
+ "emoji": "🫖",
+ "aliases": [
+ "teapot"
+ ]
+ },
+ {
+ "emoji": "🧑💻",
+ "aliases": [
+ "technologist"
+ ]
+ },
+ {
+ "emoji": "🧸",
+ "aliases": [
+ "teddy_bear"
+ ]
+ },
+ {
+ "emoji": "📞",
+ "aliases": [
+ "telephone_receiver"
+ ]
+ },
+ {
+ "emoji": "🔭",
+ "aliases": [
+ "telescope"
+ ]
+ },
+ {
+ "emoji": "🎾",
+ "aliases": [
+ "tennis"
+ ]
+ },
+ {
+ "emoji": "⛺",
+ "aliases": [
+ "tent"
+ ]
+ },
+ {
+ "emoji": "🧪",
+ "aliases": [
+ "test_tube"
+ ]
+ },
+ {
+ "emoji": "🇹🇭",
+ "aliases": [
+ "thailand"
+ ]
+ },
+ {
+ "emoji": "🌡️",
+ "aliases": [
+ "thermometer"
+ ]
+ },
+ {
+ "emoji": "🤔",
+ "aliases": [
+ "thinking"
+ ]
+ },
+ {
+ "emoji": "🩴",
+ "aliases": [
+ "thong_sandal"
+ ]
+ },
+ {
+ "emoji": "💭",
+ "aliases": [
+ "thought_balloon"
+ ]
+ },
+ {
+ "emoji": "🧵",
+ "aliases": [
+ "thread"
+ ]
+ },
+ {
+ "emoji": "3️⃣",
+ "aliases": [
+ "three"
+ ]
+ },
+ {
+ "emoji": "🎫",
+ "aliases": [
+ "ticket"
+ ]
+ },
+ {
+ "emoji": "🎟️",
+ "aliases": [
+ "tickets"
+ ]
+ },
+ {
+ "emoji": "🐯",
+ "aliases": [
+ "tiger"
+ ]
+ },
+ {
+ "emoji": "🐅",
+ "aliases": [
+ "tiger2"
+ ]
+ },
+ {
+ "emoji": "⏲️",
+ "aliases": [
+ "timer_clock"
+ ]
+ },
+ {
+ "emoji": "🇹🇱",
+ "aliases": [
+ "timor_leste"
+ ]
+ },
+ {
+ "emoji": "💁♂️",
+ "aliases": [
+ "tipping_hand_man",
+ "sassy_man"
+ ]
+ },
+ {
+ "emoji": "💁",
+ "aliases": [
+ "tipping_hand_person",
+ "information_desk_person"
+ ]
+ },
+ {
+ "emoji": "💁♀️",
+ "aliases": [
+ "tipping_hand_woman",
+ "sassy_woman"
+ ]
+ },
+ {
+ "emoji": "😫",
+ "aliases": [
+ "tired_face"
+ ]
+ },
+ {
+ "emoji": "™️",
+ "aliases": [
+ "tm"
+ ]
+ },
+ {
+ "emoji": "🇹🇬",
+ "aliases": [
+ "togo"
+ ]
+ },
+ {
+ "emoji": "🚽",
+ "aliases": [
+ "toilet"
+ ]
+ },
+ {
+ "emoji": "🇹🇰",
+ "aliases": [
+ "tokelau"
+ ]
+ },
+ {
+ "emoji": "🗼",
+ "aliases": [
+ "tokyo_tower"
+ ]
+ },
+ {
+ "emoji": "🍅",
+ "aliases": [
+ "tomato"
+ ]
+ },
+ {
+ "emoji": "🇹🇴",
+ "aliases": [
+ "tonga"
+ ]
+ },
+ {
+ "emoji": "👅",
+ "aliases": [
+ "tongue"
+ ]
+ },
+ {
+ "emoji": "🧰",
+ "aliases": [
+ "toolbox"
+ ]
+ },
+ {
+ "emoji": "🦷",
+ "aliases": [
+ "tooth"
+ ]
+ },
+ {
+ "emoji": "🪥",
+ "aliases": [
+ "toothbrush"
+ ]
+ },
+ {
+ "emoji": "🔝",
+ "aliases": [
+ "top"
+ ]
+ },
+ {
+ "emoji": "🎩",
+ "aliases": [
+ "tophat"
+ ]
+ },
+ {
+ "emoji": "🌪️",
+ "aliases": [
+ "tornado"
+ ]
+ },
+ {
+ "emoji": "🇹🇷",
+ "aliases": [
+ "tr"
+ ]
+ },
+ {
+ "emoji": "🖲️",
+ "aliases": [
+ "trackball"
+ ]
+ },
+ {
+ "emoji": "🚜",
+ "aliases": [
+ "tractor"
+ ]
+ },
+ {
+ "emoji": "🚥",
+ "aliases": [
+ "traffic_light"
+ ]
+ },
+ {
+ "emoji": "🚋",
+ "aliases": [
+ "train"
+ ]
+ },
+ {
+ "emoji": "🚆",
+ "aliases": [
+ "train2"
+ ]
+ },
+ {
+ "emoji": "🚊",
+ "aliases": [
+ "tram"
+ ]
+ },
+ {
+ "emoji": "🏳️⚧️",
+ "aliases": [
+ "transgender_flag"
+ ]
+ },
+ {
+ "emoji": "⚧️",
+ "aliases": [
+ "transgender_symbol"
+ ]
+ },
+ {
+ "emoji": "🚩",
+ "aliases": [
+ "triangular_flag_on_post"
+ ]
+ },
+ {
+ "emoji": "📐",
+ "aliases": [
+ "triangular_ruler"
+ ]
+ },
+ {
+ "emoji": "🔱",
+ "aliases": [
+ "trident"
+ ]
+ },
+ {
+ "emoji": "🇹🇹",
+ "aliases": [
+ "trinidad_tobago"
+ ]
+ },
+ {
+ "emoji": "🇹🇦",
+ "aliases": [
+ "tristan_da_cunha"
+ ]
+ },
+ {
+ "emoji": "😤",
+ "aliases": [
+ "triumph"
+ ]
+ },
+ {
+ "emoji": "🧌",
+ "aliases": [
+ "troll"
+ ]
+ },
+ {
+ "emoji": "🚎",
+ "aliases": [
+ "trolleybus"
+ ]
+ },
+ {
+ "emoji": "🏆",
+ "aliases": [
+ "trophy"
+ ]
+ },
+ {
+ "emoji": "🍹",
+ "aliases": [
+ "tropical_drink"
+ ]
+ },
+ {
+ "emoji": "🐠",
+ "aliases": [
+ "tropical_fish"
+ ]
+ },
+ {
+ "emoji": "🚚",
+ "aliases": [
+ "truck"
+ ]
+ },
+ {
+ "emoji": "🎺",
+ "aliases": [
+ "trumpet"
+ ]
+ },
+ {
+ "emoji": "🌷",
+ "aliases": [
+ "tulip"
+ ]
+ },
+ {
+ "emoji": "🥃",
+ "aliases": [
+ "tumbler_glass"
+ ]
+ },
+ {
+ "emoji": "🇹🇳",
+ "aliases": [
+ "tunisia"
+ ]
+ },
+ {
+ "emoji": "🦃",
+ "aliases": [
+ "turkey"
+ ]
+ },
+ {
+ "emoji": "🇹🇲",
+ "aliases": [
+ "turkmenistan"
+ ]
+ },
+ {
+ "emoji": "🇹🇨",
+ "aliases": [
+ "turks_caicos_islands"
+ ]
+ },
+ {
+ "emoji": "🐢",
+ "aliases": [
+ "turtle"
+ ]
+ },
+ {
+ "emoji": "🇹🇻",
+ "aliases": [
+ "tuvalu"
+ ]
+ },
+ {
+ "emoji": "📺",
+ "aliases": [
+ "tv"
+ ]
+ },
+ {
+ "emoji": "🔀",
+ "aliases": [
+ "twisted_rightwards_arrows"
+ ]
+ },
+ {
+ "emoji": "2️⃣",
+ "aliases": [
+ "two"
+ ]
+ },
+ {
+ "emoji": "💕",
+ "aliases": [
+ "two_hearts"
+ ]
+ },
+ {
+ "emoji": "👬",
+ "aliases": [
+ "two_men_holding_hands"
+ ]
+ },
+ {
+ "emoji": "👭",
+ "aliases": [
+ "two_women_holding_hands"
+ ]
+ },
+ {
+ "emoji": "🈹",
+ "aliases": [
+ "u5272"
+ ]
+ },
+ {
+ "emoji": "🈴",
+ "aliases": [
+ "u5408"
+ ]
+ },
+ {
+ "emoji": "🈺",
+ "aliases": [
+ "u55b6"
+ ]
+ },
+ {
+ "emoji": "🈯",
+ "aliases": [
+ "u6307"
+ ]
+ },
+ {
+ "emoji": "🈷️",
+ "aliases": [
+ "u6708"
+ ]
+ },
+ {
+ "emoji": "🈶",
+ "aliases": [
+ "u6709"
+ ]
+ },
+ {
+ "emoji": "🈵",
+ "aliases": [
+ "u6e80"
+ ]
+ },
+ {
+ "emoji": "🈚",
+ "aliases": [
+ "u7121"
+ ]
+ },
+ {
+ "emoji": "🈸",
+ "aliases": [
+ "u7533"
+ ]
+ },
+ {
+ "emoji": "🈲",
+ "aliases": [
+ "u7981"
+ ]
+ },
+ {
+ "emoji": "🈳",
+ "aliases": [
+ "u7a7a"
+ ]
+ },
+ {
+ "emoji": "🇺🇬",
+ "aliases": [
+ "uganda"
+ ]
+ },
+ {
+ "emoji": "🇺🇦",
+ "aliases": [
+ "ukraine"
+ ]
+ },
+ {
+ "emoji": "☔",
+ "aliases": [
+ "umbrella"
+ ]
+ },
+ {
+ "emoji": "😒",
+ "aliases": [
+ "unamused"
+ ]
+ },
+ {
+ "emoji": "🔞",
+ "aliases": [
+ "underage"
+ ]
+ },
+ {
+ "emoji": "🦄",
+ "aliases": [
+ "unicorn"
+ ]
+ },
+ {
+ "emoji": "🇦🇪",
+ "aliases": [
+ "united_arab_emirates"
+ ]
+ },
+ {
+ "emoji": "🇺🇳",
+ "aliases": [
+ "united_nations"
+ ]
+ },
+ {
+ "emoji": "🔓",
+ "aliases": [
+ "unlock"
+ ]
+ },
+ {
+ "emoji": "🆙",
+ "aliases": [
+ "up"
+ ]
+ },
+ {
+ "emoji": "🙃",
+ "aliases": [
+ "upside_down_face"
+ ]
+ },
+ {
+ "emoji": "🇺🇾",
+ "aliases": [
+ "uruguay"
+ ]
+ },
+ {
+ "emoji": "🇺🇸",
+ "aliases": [
+ "us"
+ ]
+ },
+ {
+ "emoji": "🇺🇲",
+ "aliases": [
+ "us_outlying_islands"
+ ]
+ },
+ {
+ "emoji": "🇻🇮",
+ "aliases": [
+ "us_virgin_islands"
+ ]
+ },
+ {
+ "emoji": "🇺🇿",
+ "aliases": [
+ "uzbekistan"
+ ]
+ },
+ {
+ "emoji": "✌️",
+ "aliases": [
+ "v"
+ ]
+ },
+ {
+ "emoji": "🧛",
+ "aliases": [
+ "vampire"
+ ]
+ },
+ {
+ "emoji": "🧛♂️",
+ "aliases": [
+ "vampire_man"
+ ]
+ },
+ {
+ "emoji": "🧛♀️",
+ "aliases": [
+ "vampire_woman"
+ ]
+ },
+ {
+ "emoji": "🇻🇺",
+ "aliases": [
+ "vanuatu"
+ ]
+ },
+ {
+ "emoji": "🇻🇦",
+ "aliases": [
+ "vatican_city"
+ ]
+ },
+ {
+ "emoji": "🇻🇪",
+ "aliases": [
+ "venezuela"
+ ]
+ },
+ {
+ "emoji": "🚦",
+ "aliases": [
+ "vertical_traffic_light"
+ ]
+ },
+ {
+ "emoji": "📼",
+ "aliases": [
+ "vhs"
+ ]
+ },
+ {
+ "emoji": "📳",
+ "aliases": [
+ "vibration_mode"
+ ]
+ },
+ {
+ "emoji": "📹",
+ "aliases": [
+ "video_camera"
+ ]
+ },
+ {
+ "emoji": "🎮",
+ "aliases": [
+ "video_game"
+ ]
+ },
+ {
+ "emoji": "🇻🇳",
+ "aliases": [
+ "vietnam"
+ ]
+ },
+ {
+ "emoji": "🎻",
+ "aliases": [
+ "violin"
+ ]
+ },
+ {
+ "emoji": "♍",
+ "aliases": [
+ "virgo"
+ ]
+ },
+ {
+ "emoji": "🌋",
+ "aliases": [
+ "volcano"
+ ]
+ },
+ {
+ "emoji": "🏐",
+ "aliases": [
+ "volleyball"
+ ]
+ },
+ {
+ "emoji": "🤮",
+ "aliases": [
+ "vomiting_face"
+ ]
+ },
+ {
+ "emoji": "🆚",
+ "aliases": [
+ "vs"
+ ]
+ },
+ {
+ "emoji": "🖖",
+ "aliases": [
+ "vulcan_salute"
+ ]
+ },
+ {
+ "emoji": "🧇",
+ "aliases": [
+ "waffle"
+ ]
+ },
+ {
+ "emoji": "🏴",
+ "aliases": [
+ "wales"
+ ]
+ },
+ {
+ "emoji": "🚶",
+ "aliases": [
+ "walking"
+ ]
+ },
+ {
+ "emoji": "🚶♂️",
+ "aliases": [
+ "walking_man"
+ ]
+ },
+ {
+ "emoji": "🚶♀️",
+ "aliases": [
+ "walking_woman"
+ ]
+ },
+ {
+ "emoji": "🇼🇫",
+ "aliases": [
+ "wallis_futuna"
+ ]
+ },
+ {
+ "emoji": "🌘",
+ "aliases": [
+ "waning_crescent_moon"
+ ]
+ },
+ {
+ "emoji": "🌖",
+ "aliases": [
+ "waning_gibbous_moon"
+ ]
+ },
+ {
+ "emoji": "⚠️",
+ "aliases": [
+ "warning"
+ ]
+ },
+ {
+ "emoji": "🗑️",
+ "aliases": [
+ "wastebasket"
+ ]
+ },
+ {
+ "emoji": "⌚",
+ "aliases": [
+ "watch"
+ ]
+ },
+ {
+ "emoji": "🐃",
+ "aliases": [
+ "water_buffalo"
+ ]
+ },
+ {
+ "emoji": "🤽",
+ "aliases": [
+ "water_polo"
+ ]
+ },
+ {
+ "emoji": "🍉",
+ "aliases": [
+ "watermelon"
+ ]
+ },
+ {
+ "emoji": "👋",
+ "aliases": [
+ "wave"
+ ]
+ },
+ {
+ "emoji": "〰️",
+ "aliases": [
+ "wavy_dash"
+ ]
+ },
+ {
+ "emoji": "🌒",
+ "aliases": [
+ "waxing_crescent_moon"
+ ]
+ },
+ {
+ "emoji": "🚾",
+ "aliases": [
+ "wc"
+ ]
+ },
+ {
+ "emoji": "😩",
+ "aliases": [
+ "weary"
+ ]
+ },
+ {
+ "emoji": "💒",
+ "aliases": [
+ "wedding"
+ ]
+ },
+ {
+ "emoji": "🏋️",
+ "aliases": [
+ "weight_lifting"
+ ]
+ },
+ {
+ "emoji": "🏋️♂️",
+ "aliases": [
+ "weight_lifting_man"
+ ]
+ },
+ {
+ "emoji": "🏋️♀️",
+ "aliases": [
+ "weight_lifting_woman"
+ ]
+ },
+ {
+ "emoji": "🇪🇭",
+ "aliases": [
+ "western_sahara"
+ ]
+ },
+ {
+ "emoji": "🐳",
+ "aliases": [
+ "whale"
+ ]
+ },
+ {
+ "emoji": "🐋",
+ "aliases": [
+ "whale2"
+ ]
+ },
+ {
+ "emoji": "🛞",
+ "aliases": [
+ "wheel"
+ ]
+ },
+ {
+ "emoji": "☸️",
+ "aliases": [
+ "wheel_of_dharma"
+ ]
+ },
+ {
+ "emoji": "♿",
+ "aliases": [
+ "wheelchair"
+ ]
+ },
+ {
+ "emoji": "✅",
+ "aliases": [
+ "white_check_mark"
+ ]
+ },
+ {
+ "emoji": "⚪",
+ "aliases": [
+ "white_circle"
+ ]
+ },
+ {
+ "emoji": "🏳️",
+ "aliases": [
+ "white_flag"
+ ]
+ },
+ {
+ "emoji": "💮",
+ "aliases": [
+ "white_flower"
+ ]
+ },
+ {
+ "emoji": "👨🦳",
+ "aliases": [
+ "white_haired_man"
+ ]
+ },
+ {
+ "emoji": "👩🦳",
+ "aliases": [
+ "white_haired_woman"
+ ]
+ },
+ {
+ "emoji": "🤍",
+ "aliases": [
+ "white_heart"
+ ]
+ },
+ {
+ "emoji": "⬜",
+ "aliases": [
+ "white_large_square"
+ ]
+ },
+ {
+ "emoji": "◽",
+ "aliases": [
+ "white_medium_small_square"
+ ]
+ },
+ {
+ "emoji": "◻️",
+ "aliases": [
+ "white_medium_square"
+ ]
+ },
+ {
+ "emoji": "▫️",
+ "aliases": [
+ "white_small_square"
+ ]
+ },
+ {
+ "emoji": "🔳",
+ "aliases": [
+ "white_square_button"
+ ]
+ },
+ {
+ "emoji": "🥀",
+ "aliases": [
+ "wilted_flower"
+ ]
+ },
+ {
+ "emoji": "🎐",
+ "aliases": [
+ "wind_chime"
+ ]
+ },
+ {
+ "emoji": "🌬️",
+ "aliases": [
+ "wind_face"
+ ]
+ },
+ {
+ "emoji": "🪟",
+ "aliases": [
+ "window"
+ ]
+ },
+ {
+ "emoji": "🍷",
+ "aliases": [
+ "wine_glass"
+ ]
+ },
+ {
+ "emoji": "🪽",
+ "aliases": [
+ "wing"
+ ]
+ },
+ {
+ "emoji": "😉",
+ "aliases": [
+ "wink"
+ ]
+ },
+ {
+ "emoji": "🛜",
+ "aliases": [
+ "wireless"
+ ]
+ },
+ {
+ "emoji": "🐺",
+ "aliases": [
+ "wolf"
+ ]
+ },
+ {
+ "emoji": "👩",
+ "aliases": [
+ "woman"
+ ]
+ },
+ {
+ "emoji": "👩🎨",
+ "aliases": [
+ "woman_artist"
+ ]
+ },
+ {
+ "emoji": "👩🚀",
+ "aliases": [
+ "woman_astronaut"
+ ]
+ },
+ {
+ "emoji": "🧔♀️",
+ "aliases": [
+ "woman_beard"
+ ]
+ },
+ {
+ "emoji": "🤸♀️",
+ "aliases": [
+ "woman_cartwheeling"
+ ]
+ },
+ {
+ "emoji": "👩🍳",
+ "aliases": [
+ "woman_cook"
+ ]
+ },
+ {
+ "emoji": "💃",
+ "aliases": [
+ "woman_dancing",
+ "dancer"
+ ]
+ },
+ {
+ "emoji": "🤦♀️",
+ "aliases": [
+ "woman_facepalming"
+ ]
+ },
+ {
+ "emoji": "👩🏭",
+ "aliases": [
+ "woman_factory_worker"
+ ]
+ },
+ {
+ "emoji": "👩🌾",
+ "aliases": [
+ "woman_farmer"
+ ]
+ },
+ {
+ "emoji": "👩🍼",
+ "aliases": [
+ "woman_feeding_baby"
+ ]
+ },
+ {
+ "emoji": "👩🚒",
+ "aliases": [
+ "woman_firefighter"
+ ]
+ },
+ {
+ "emoji": "👩⚕️",
+ "aliases": [
+ "woman_health_worker"
+ ]
+ },
+ {
+ "emoji": "👩🦽",
+ "aliases": [
+ "woman_in_manual_wheelchair"
+ ]
+ },
+ {
+ "emoji": "👩🦽➡️",
+ "aliases": [
+ "woman_in_manual_wheelchair_facing_right"
+ ]
+ },
+ {
+ "emoji": "👩🦼",
+ "aliases": [
+ "woman_in_motorized_wheelchair"
+ ]
+ },
+ {
+ "emoji": "👩🦼➡️",
+ "aliases": [
+ "woman_in_motorized_wheelchair_facing_right"
+ ]
+ },
+ {
+ "emoji": "🤵♀️",
+ "aliases": [
+ "woman_in_tuxedo"
+ ]
+ },
+ {
+ "emoji": "👩⚖️",
+ "aliases": [
+ "woman_judge"
+ ]
+ },
+ {
+ "emoji": "🤹♀️",
+ "aliases": [
+ "woman_juggling"
+ ]
+ },
+ {
+ "emoji": "🧎♀️➡️",
+ "aliases": [
+ "woman_kneeling_facing_right"
+ ]
+ },
+ {
+ "emoji": "👩🔧",
+ "aliases": [
+ "woman_mechanic"
+ ]
+ },
+ {
+ "emoji": "👩💼",
+ "aliases": [
+ "woman_office_worker"
+ ]
+ },
+ {
+ "emoji": "👩✈️",
+ "aliases": [
+ "woman_pilot"
+ ]
+ },
+ {
+ "emoji": "🤾♀️",
+ "aliases": [
+ "woman_playing_handball"
+ ]
+ },
+ {
+ "emoji": "🤽♀️",
+ "aliases": [
+ "woman_playing_water_polo"
+ ]
+ },
+ {
+ "emoji": "🏃♀️➡️",
+ "aliases": [
+ "woman_running_facing_right"
+ ]
+ },
+ {
+ "emoji": "👩🔬",
+ "aliases": [
+ "woman_scientist"
+ ]
+ },
+ {
+ "emoji": "🤷♀️",
+ "aliases": [
+ "woman_shrugging"
+ ]
+ },
+ {
+ "emoji": "👩🎤",
+ "aliases": [
+ "woman_singer"
+ ]
+ },
+ {
+ "emoji": "👩🎓",
+ "aliases": [
+ "woman_student"
+ ]
+ },
+ {
+ "emoji": "👩🏫",
+ "aliases": [
+ "woman_teacher"
+ ]
+ },
+ {
+ "emoji": "👩💻",
+ "aliases": [
+ "woman_technologist"
+ ]
+ },
+ {
+ "emoji": "🚶♀️➡️",
+ "aliases": [
+ "woman_walking_facing_right"
+ ]
+ },
+ {
+ "emoji": "🧕",
+ "aliases": [
+ "woman_with_headscarf"
+ ]
+ },
+ {
+ "emoji": "👩🦯",
+ "aliases": [
+ "woman_with_probing_cane"
+ ]
+ },
+ {
+ "emoji": "👳♀️",
+ "aliases": [
+ "woman_with_turban"
+ ]
+ },
+ {
+ "emoji": "👰♀️",
+ "aliases": [
+ "woman_with_veil",
+ "bride_with_veil"
+ ]
+ },
+ {
+ "emoji": "👩🦯➡️",
+ "aliases": [
+ "woman_with_white_cane_facing_right"
+ ]
+ },
+ {
+ "emoji": "👚",
+ "aliases": [
+ "womans_clothes"
+ ]
+ },
+ {
+ "emoji": "👒",
+ "aliases": [
+ "womans_hat"
+ ]
+ },
+ {
+ "emoji": "🤼♀️",
+ "aliases": [
+ "women_wrestling"
+ ]
+ },
+ {
+ "emoji": "🚺",
+ "aliases": [
+ "womens"
+ ]
+ },
+ {
+ "emoji": "🪵",
+ "aliases": [
+ "wood"
+ ]
+ },
+ {
+ "emoji": "🥴",
+ "aliases": [
+ "woozy_face"
+ ]
+ },
+ {
+ "emoji": "🗺️",
+ "aliases": [
+ "world_map"
+ ]
+ },
+ {
+ "emoji": "🪱",
+ "aliases": [
+ "worm"
+ ]
+ },
+ {
+ "emoji": "😟",
+ "aliases": [
+ "worried"
+ ]
+ },
+ {
+ "emoji": "🔧",
+ "aliases": [
+ "wrench"
+ ]
+ },
+ {
+ "emoji": "🤼",
+ "aliases": [
+ "wrestling"
+ ]
+ },
+ {
+ "emoji": "✍️",
+ "aliases": [
+ "writing_hand"
+ ]
+ },
+ {
+ "emoji": "❌",
+ "aliases": [
+ "x"
+ ]
+ },
+ {
+ "emoji": "🩻",
+ "aliases": [
+ "x_ray"
+ ]
+ },
+ {
+ "emoji": "🧶",
+ "aliases": [
+ "yarn"
+ ]
+ },
+ {
+ "emoji": "🥱",
+ "aliases": [
+ "yawning_face"
+ ]
+ },
+ {
+ "emoji": "🟡",
+ "aliases": [
+ "yellow_circle"
+ ]
+ },
+ {
+ "emoji": "💛",
+ "aliases": [
+ "yellow_heart"
+ ]
+ },
+ {
+ "emoji": "🟨",
+ "aliases": [
+ "yellow_square"
+ ]
+ },
+ {
+ "emoji": "🇾🇪",
+ "aliases": [
+ "yemen"
+ ]
+ },
+ {
+ "emoji": "💴",
+ "aliases": [
+ "yen"
+ ]
+ },
+ {
+ "emoji": "☯️",
+ "aliases": [
+ "yin_yang"
+ ]
+ },
+ {
+ "emoji": "🪀",
+ "aliases": [
+ "yo_yo"
+ ]
+ },
+ {
+ "emoji": "😋",
+ "aliases": [
+ "yum"
+ ]
+ },
+ {
+ "emoji": "🇿🇲",
+ "aliases": [
+ "zambia"
+ ]
+ },
+ {
+ "emoji": "🤪",
+ "aliases": [
+ "zany_face"
+ ]
+ },
+ {
+ "emoji": "⚡",
+ "aliases": [
+ "zap"
+ ]
+ },
+ {
+ "emoji": "🦓",
+ "aliases": [
+ "zebra"
+ ]
+ },
+ {
+ "emoji": "0️⃣",
+ "aliases": [
+ "zero"
+ ]
+ },
+ {
+ "emoji": "🇿🇼",
+ "aliases": [
+ "zimbabwe"
+ ]
+ },
+ {
+ "emoji": "🤐",
+ "aliases": [
+ "zipper_mouth_face"
+ ]
+ },
+ {
+ "emoji": "🧟",
+ "aliases": [
+ "zombie"
+ ]
+ },
+ {
+ "emoji": "🧟♂️",
+ "aliases": [
+ "zombie_man"
+ ]
+ },
+ {
+ "emoji": "🧟♀️",
+ "aliases": [
+ "zombie_woman"
+ ]
+ },
+ {
+ "emoji": "💤",
+ "aliases": [
+ "zzz"
+ ]
+ }
+]
diff --git a/tools/misspellings.csv b/assets/misspellings.csv
similarity index 100%
rename from tools/misspellings.csv
rename to assets/misspellings.csv
diff --git a/build.go b/build.go
deleted file mode 100644
index e81ba54690..0000000000
--- a/build.go
+++ /dev/null
@@ -1,14 +0,0 @@
-// Copyright 2020 The Gitea Authors. All rights reserved.
-// SPDX-License-Identifier: MIT
-
-//go:build vendor
-
-package main
-
-// Libraries that are included to vendor utilities used during Makefile build.
-// These libraries will not be included in a normal compilation.
-
-import (
- // for vet
- _ "code.gitea.io/gitea-vet"
-)
diff --git a/build/backport-locales.go b/build/backport-locales.go
deleted file mode 100644
index d112dd72bd..0000000000
--- a/build/backport-locales.go
+++ /dev/null
@@ -1,115 +0,0 @@
-// Copyright 2023 The Gitea Authors. All rights reserved.
-// SPDX-License-Identifier: MIT
-
-//go:build ignore
-
-package main
-
-import (
- "fmt"
- "os"
- "os/exec"
- "path/filepath"
- "strings"
-
- "code.gitea.io/gitea/modules/container"
- "code.gitea.io/gitea/modules/setting"
-)
-
-func main() {
- if len(os.Args) != 2 {
- println("usage: backport-locales ")
- println("eg: backport-locales release/v1.19")
- os.Exit(1)
- }
-
- mustNoErr := func(err error) {
- if err != nil {
- panic(err)
- }
- }
- collectInis := func(ref string) map[string]setting.ConfigProvider {
- inis := map[string]setting.ConfigProvider{}
- err := filepath.WalkDir("options/locale", func(path string, d os.DirEntry, err error) error {
- if err != nil {
- return err
- }
- if d.IsDir() || !strings.HasSuffix(d.Name(), ".ini") {
- return nil
- }
- cfg, err := setting.NewConfigProviderForLocale(path)
- mustNoErr(err)
- inis[path] = cfg
- fmt.Printf("collecting: %s @ %s\n", path, ref)
- return nil
- })
- mustNoErr(err)
- return inis
- }
-
- // collect new locales from current working directory
- inisNew := collectInis("HEAD")
-
- // switch to the target ref, and collect the old locales
- cmd := exec.Command("git", "checkout", os.Args[1])
- cmd.Stdout = os.Stdout
- cmd.Stderr = os.Stderr
- mustNoErr(cmd.Run())
- inisOld := collectInis(os.Args[1])
-
- // use old en-US as the base, and copy the new translations to the old locales
- enUsOld := inisOld["options/locale/locale_en-US.ini"]
- brokenWarned := make(container.Set[string])
- for path, iniOld := range inisOld {
- if iniOld == enUsOld {
- continue
- }
- iniNew := inisNew[path]
- if iniNew == nil {
- continue
- }
- for _, secEnUS := range enUsOld.Sections() {
- secOld := iniOld.Section(secEnUS.Name())
- secNew := iniNew.Section(secEnUS.Name())
- for _, keyEnUs := range secEnUS.Keys() {
- if secNew.HasKey(keyEnUs.Name()) {
- oldStr := secOld.Key(keyEnUs.Name()).String()
- newStr := secNew.Key(keyEnUs.Name()).String()
- broken := oldStr != "" && strings.Count(oldStr, "%") != strings.Count(newStr, "%")
- broken = broken || strings.Contains(oldStr, "\n") || strings.Contains(oldStr, "\n")
- if broken {
- brokenWarned.Add(secOld.Name() + "." + keyEnUs.Name())
- fmt.Println("----")
- fmt.Printf("WARNING: skip broken locale: %s , [%s] %s\n", path, secEnUS.Name(), keyEnUs.Name())
- fmt.Printf("\told: %s\n", strings.ReplaceAll(oldStr, "\n", "\\n"))
- fmt.Printf("\tnew: %s\n", strings.ReplaceAll(newStr, "\n", "\\n"))
- continue
- }
- secOld.Key(keyEnUs.Name()).SetValue(newStr)
- }
- }
- }
- mustNoErr(iniOld.SaveTo(path))
- }
-
- fmt.Println("========")
-
- for path, iniNew := range inisNew {
- for _, sec := range iniNew.Sections() {
- for _, key := range sec.Keys() {
- str := sec.Key(key.Name()).String()
- broken := strings.Contains(str, "\n")
- broken = broken || strings.HasPrefix(str, "`") != strings.HasSuffix(str, "`")
- broken = broken || strings.HasPrefix(str, "\"`")
- broken = broken || strings.HasPrefix(str, "`\"")
- broken = broken || strings.Count(str, `"`)%2 == 1
- broken = broken || strings.Count(str, "`")%2 == 1
- if broken && !brokenWarned.Contains(sec.Name()+"."+key.Name()) {
- fmt.Printf("WARNING: found broken locale: %s , [%s] %s\n", path, sec.Name(), key.Name())
- fmt.Printf("\tstr: %s\n", strings.ReplaceAll(str, "\n", "\\n"))
- fmt.Println("----")
- }
- }
- }
- }
-}
diff --git a/build/generate-emoji.go b/build/generate-emoji.go
index 446ab5f440..cbc1be2139 100644
--- a/build/generate-emoji.go
+++ b/build/generate-emoji.go
@@ -24,8 +24,8 @@ import (
)
const (
- gemojiURL = "https://raw.githubusercontent.com/github/gemoji/master/db/emoji.json"
- maxUnicodeVersion = 15
+ gemojiURL = "https://raw.githubusercontent.com/rhysd/gemoji/537ff2d7e0496e9964824f7f73ec7ece88c9765a/db/emoji.json"
+ maxUnicodeVersion = 16
)
var flagOut = flag.String("o", "modules/emoji/emoji_data.go", "out")
@@ -149,8 +149,8 @@ func generate() ([]byte, error) {
}
// write a JSON file to use with tribute (write before adding skin tones since we can't support them there yet)
- file, _ := json.Marshal(data)
- _ = os.WriteFile("assets/emoji.json", file, 0o644)
+ file, _ := json.MarshalIndent(data, "", " ")
+ _ = os.WriteFile("assets/emoji.json", append(file, '\n'), 0o644)
// Add skin tones to emoji that support it
var (
diff --git a/build/generate-go-licenses.go b/build/generate-go-licenses.go
index 84ba39025c..057e6a6e49 100644
--- a/build/generate-go-licenses.go
+++ b/build/generate-go-licenses.go
@@ -8,99 +8,220 @@ package main
import (
"encoding/json"
"fmt"
- "io/fs"
"os"
- "path"
+ "os/exec"
"path/filepath"
"regexp"
+ "slices"
"sort"
"strings"
-
- "code.gitea.io/gitea/modules/container"
)
// regexp is based on go-license, excluding README and NOTICE
// https://github.com/google/go-licenses/blob/master/licenses/find.go
+// also defined in vite.config.ts
var licenseRe = regexp.MustCompile(`^(?i)((UN)?LICEN(S|C)E|COPYING).*$`)
+// primaryLicenseRe matches exact primary license filenames without suffixes.
+// When a directory has both primary and variant files (e.g. LICENSE and
+// LICENSE.docs), only the primary files are kept.
+var primaryLicenseRe = regexp.MustCompile(`^(?i)(LICEN[SC]E|COPYING)$`)
+
+// ignoredNames are LicenseEntry.Name values to exclude from the output.
+var ignoredNames = map[string]bool{
+ "code.gitea.io/gitea": true,
+ "code.gitea.io/gitea/options/license": true,
+}
+
+var excludedExt = map[string]bool{
+ ".gitignore": true,
+ ".go": true,
+ ".mod": true,
+ ".sum": true,
+ ".toml": true,
+ ".yaml": true,
+ ".yml": true,
+}
+
+type ModuleInfo struct {
+ Path string
+ Dir string
+ PkgDirs []string // directories of packages imported from this module
+}
+
type LicenseEntry struct {
Name string `json:"name"`
Path string `json:"path"`
LicenseText string `json:"licenseText"`
}
-func main() {
- if len(os.Args) != 3 {
- fmt.Println("usage: go run generate-go-licenses.go ")
+// getModules returns all dependency modules with their local directory paths
+// and the package directories used from each module.
+func getModules(goCmd string) []ModuleInfo {
+ cmd := exec.Command(goCmd, "list", "-deps", "-f",
+ "{{if .Module}}{{.Module.Path}}\t{{.Module.Dir}}\t{{.Dir}}{{end}}", "./...")
+ cmd.Stderr = os.Stderr
+ // Use GOOS=linux with CGO to ensure we capture all platform-specific
+ // dependencies, matching the CI environment.
+ cmd.Env = append(os.Environ(), "GOOS=linux", "GOARCH=amd64", "CGO_ENABLED=1")
+ output, err := cmd.Output()
+ if err != nil {
+ fmt.Fprintf(os.Stderr, "failed to run 'go list -deps': %v\n", err)
os.Exit(1)
}
- base, out := os.Args[1], os.Args[2]
-
- // Add ext for excluded files because license_test.go will be included for some reason.
- // And there are more files that should be excluded, check with:
- //
- // go run github.com/google/go-licenses@v1.6.0 save . --force --save_path=.go-licenses 2>/dev/null
- // find .go-licenses -type f | while read FILE; do echo "${$(basename $FILE)##*.}"; done | sort -u
- // AUTHORS
- // COPYING
- // LICENSE
- // Makefile
- // NOTICE
- // gitignore
- // go
- // md
- // mod
- // sum
- // toml
- // txt
- // yml
- //
- // It could be removed once we have a better regex.
- excludedExt := container.SetOf(".gitignore", ".go", ".mod", ".sum", ".toml", ".yml")
-
- var paths []string
- err := filepath.WalkDir(base, func(path string, entry fs.DirEntry, err error) error {
- if err != nil {
- return err
+ var modules []ModuleInfo
+ seen := make(map[string]int) // module path -> index in modules
+ for _, line := range strings.Split(string(output), "\n") {
+ line = strings.TrimSpace(line)
+ if line == "" {
+ continue
}
- if entry.IsDir() || !licenseRe.MatchString(entry.Name()) || excludedExt.Contains(filepath.Ext(entry.Name())) {
- return nil
+ parts := strings.Split(line, "\t")
+ if len(parts) != 3 {
+ continue
+ }
+ modPath, modDir, pkgDir := parts[0], parts[1], parts[2]
+ if idx, ok := seen[modPath]; ok {
+ modules[idx].PkgDirs = append(modules[idx].PkgDirs, pkgDir)
+ } else {
+ seen[modPath] = len(modules)
+ modules = append(modules, ModuleInfo{
+ Path: modPath,
+ Dir: modDir,
+ PkgDirs: []string{pkgDir},
+ })
}
- paths = append(paths, path)
- return nil
- })
- if err != nil {
- panic(err)
}
+ return modules
+}
- sort.Strings(paths)
-
+// findLicenseFiles scans a module's root directory and its used package
+// directories for license files. It also walks up from each package directory
+// to the module root, scanning intermediate directories. Subdirectory licenses
+// are only included if their text differs from the root license(s).
+func findLicenseFiles(mod ModuleInfo) []LicenseEntry {
var entries []LicenseEntry
- for _, filePath := range paths {
- licenseText, err := os.ReadFile(filePath)
- if err != nil {
- panic(err)
+ seenTexts := make(map[string]bool)
+
+ // First, collect root-level license files.
+ entries = append(entries, scanDirForLicenses(mod.Dir, mod.Path, "")...)
+ for _, e := range entries {
+ seenTexts[e.LicenseText] = true
+ }
+
+ // Then check each package directory and all intermediate parent directories
+ // up to the module root for license files with unique text.
+ seenDirs := map[string]bool{mod.Dir: true}
+ for _, pkgDir := range mod.PkgDirs {
+ for dir := pkgDir; dir != mod.Dir && strings.HasPrefix(dir, mod.Dir); dir = filepath.Dir(dir) {
+ if seenDirs[dir] {
+ continue
+ }
+ seenDirs[dir] = true
+ for _, e := range scanDirForLicenses(dir, mod.Path, mod.Dir) {
+ if !seenTexts[e.LicenseText] {
+ seenTexts[e.LicenseText] = true
+ entries = append(entries, e)
+ }
+ }
}
+ }
+ return entries
+}
- pkgPath := filepath.ToSlash(filePath)
- pkgPath = strings.TrimPrefix(pkgPath, base+"/")
- pkgName := path.Dir(pkgPath)
+// scanDirForLicenses reads a single directory for license files and returns entries.
+// If moduleRoot is non-empty, paths are made relative to it.
+func scanDirForLicenses(dir, modulePath, moduleRoot string) []LicenseEntry {
+ dirEntries, err := os.ReadDir(dir)
+ if err != nil {
+ return nil
+ }
- // There might be a bug somewhere in go-licenses that sometimes interprets the
- // root package as "." and sometimes as "code.gitea.io/gitea". Workaround by
- // removing both of them for the sake of stable output.
- if pkgName == "." || pkgName == "code.gitea.io/gitea" {
+ var entries []LicenseEntry
+ for _, entry := range dirEntries {
+ if entry.IsDir() {
+ continue
+ }
+ name := entry.Name()
+ if !licenseRe.MatchString(name) {
+ continue
+ }
+ if excludedExt[strings.ToLower(filepath.Ext(name))] {
+ continue
+ }
+
+ content, err := os.ReadFile(filepath.Join(dir, name))
+ if err != nil {
continue
}
+ entryName := modulePath
+ entryPath := modulePath + "/" + name
+ if moduleRoot != "" {
+ rel, _ := filepath.Rel(moduleRoot, dir)
+ if rel != "." {
+ relSlash := filepath.ToSlash(rel)
+ entryName = modulePath + "/" + relSlash
+ entryPath = modulePath + "/" + relSlash + "/" + name
+ }
+ }
+
entries = append(entries, LicenseEntry{
- Name: pkgName,
- Path: pkgPath,
- LicenseText: string(licenseText),
+ Name: entryName,
+ Path: entryPath,
+ LicenseText: string(content),
})
}
+ // When multiple license files exist, prefer primary files (e.g. LICENSE)
+ // over variants with suffixes (e.g. LICENSE.docs, LICENSE-2.0.txt).
+ // If no primary file exists, keep only the first variant.
+ if len(entries) > 1 {
+ var primary []LicenseEntry
+ for _, e := range entries {
+ fileName := e.Path[strings.LastIndex(e.Path, "/")+1:]
+ if primaryLicenseRe.MatchString(fileName) {
+ primary = append(primary, e)
+ }
+ }
+ if len(primary) > 0 {
+ return primary
+ }
+ return entries[:1]
+ }
+
+ return entries
+}
+
+func main() {
+ if len(os.Args) != 2 {
+ fmt.Println("usage: go run generate-go-licenses.go ")
+ os.Exit(1)
+ }
+
+ out := os.Args[1]
+
+ goCmd := "go"
+ if env := os.Getenv("GO"); env != "" {
+ goCmd = env
+ }
+
+ modules := getModules(goCmd)
+
+ var entries []LicenseEntry
+ for _, mod := range modules {
+ entries = append(entries, findLicenseFiles(mod)...)
+ }
+
+ entries = slices.DeleteFunc(entries, func(e LicenseEntry) bool {
+ return ignoredNames[e.Name]
+ })
+
+ sort.Slice(entries, func(i, j int) bool {
+ return entries[i].Path < entries[j].Path
+ })
+
jsonBytes, err := json.MarshalIndent(entries, "", " ")
if err != nil {
panic(err)
diff --git a/build/update-locales.sh b/build/update-locales.sh
index 6f9ee334be..5316746f30 100755
--- a/build/update-locales.sh
+++ b/build/update-locales.sh
@@ -1,52 +1,22 @@
#!/bin/sh
# this script runs in alpine image which only has `sh` shell
-
-set +e
-if sed --version 2>/dev/null | grep -q GNU; then
- SED_INPLACE="sed -i"
-else
- SED_INPLACE="sed -i ''"
-fi
-set -e
-
-if [ ! -f ./options/locale/locale_en-US.ini ]; then
+if [ ! -f ./options/locale/locale_en-US.json ]; then
echo "please run this script in the root directory of the project"
exit 1
fi
-mv ./options/locale/locale_en-US.ini ./options/
-
-# the "ini" library for locale has many quirks, its behavior is different from Crowdin.
-# see i18n_test.go for more details
-
-# this script helps to unquote the Crowdin outputs for the quirky ini library
-# * find all `key="...\"..."` lines
-# * remove the leading quote
-# * remove the trailing quote
-# * unescape the quotes
-# * eg: key="...\"..." => key=..."...
-$SED_INPLACE -r -e '/^[-.A-Za-z0-9_]+[ ]*=[ ]*".*"$/ {
- s/^([-.A-Za-z0-9_]+)[ ]*=[ ]*"/\1=/
- s/"$//
- s/\\"/"/g
- }' ./options/locale/*.ini
-
-# * if the escaped line is incomplete like `key="...` or `key=..."`, quote it with backticks
-# * eg: key="... => key=`"...`
-# * eg: key=..." => key=`..."`
-$SED_INPLACE -r -e 's/^([-.A-Za-z0-9_]+)[ ]*=[ ]*(".*[^"])$/\1=`\2`/' ./options/locale/*.ini
-$SED_INPLACE -r -e 's/^([-.A-Za-z0-9_]+)[ ]*=[ ]*([^"].*")$/\1=`\2`/' ./options/locale/*.ini
+mv ./options/locale/locale_en-US.json ./options/
# Remove translation under 25% of en_us
-baselines=$(wc -l "./options/locale_en-US.ini" | cut -d" " -f1)
+baselines=$(cat "./options/locale_en-US.json" | wc -l)
baselines=$((baselines / 4))
-for filename in ./options/locale/*.ini; do
- lines=$(wc -l "$filename" | cut -d" " -f1)
- if [ $lines -lt $baselines ]; then
+for filename in ./options/locale/*.json; do
+ lines=$(cat "$filename" | wc -l)
+ if [ "$lines" -lt "$baselines" ]; then
echo "Removing $filename: $lines/$baselines"
rm "$filename"
fi
done
-mv ./options/locale_en-US.ini ./options/locale/
+mv ./options/locale_en-US.json ./options/locale/
diff --git a/cmd/actions.go b/cmd/actions.go
index 2c51c6a1bc..44b6b7b54c 100644
--- a/cmd/actions.go
+++ b/cmd/actions.go
@@ -13,17 +13,18 @@ import (
"github.com/urfave/cli/v3"
)
-var (
- // CmdActions represents the available actions sub-commands.
- CmdActions = &cli.Command{
+func newActionsCommand() *cli.Command {
+ return &cli.Command{
Name: "actions",
Usage: "Manage Gitea Actions",
Commands: []*cli.Command{
- subcmdActionsGenRunnerToken,
+ newActionsGenerateRunnerTokenCommand(),
},
}
+}
- subcmdActionsGenRunnerToken = &cli.Command{
+func newActionsGenerateRunnerTokenCommand() *cli.Command {
+ return &cli.Command{
Name: "generate-runner-token",
Usage: "Generate a new token for a runner to use to register with the server",
Action: runGenerateActionsRunnerToken,
@@ -37,7 +38,7 @@ var (
},
},
}
-)
+}
func runGenerateActionsRunnerToken(ctx context.Context, c *cli.Command) error {
setting.MustInstalled()
diff --git a/cmd/admin.go b/cmd/admin.go
index 5c58a40ca2..c0e21731cb 100644
--- a/cmd/admin.go
+++ b/cmd/admin.go
@@ -18,36 +18,41 @@ import (
"github.com/urfave/cli/v3"
)
-var (
- // CmdAdmin represents the available admin sub-command.
- CmdAdmin = &cli.Command{
+func newAdminCommand() *cli.Command {
+ return &cli.Command{
Name: "admin",
Usage: "Perform common administrative operations",
Commands: []*cli.Command{
- subcmdUser,
- subcmdRepoSyncReleases,
- subcmdRegenerate,
- subcmdAuth,
- subcmdSendMail,
+ newUserCommand(),
+ newRepoSyncReleasesCommand(),
+ newRegenerateCommand(),
+ newAuthCommand(),
+ newSendMailCommand(),
},
}
+}
- subcmdRepoSyncReleases = &cli.Command{
+func newRepoSyncReleasesCommand() *cli.Command {
+ return &cli.Command{
Name: "repo-sync-releases",
Usage: "Synchronize repository releases with tags",
Action: runRepoSyncReleases,
}
+}
- subcmdRegenerate = &cli.Command{
+func newRegenerateCommand() *cli.Command {
+ return &cli.Command{
Name: "regenerate",
Usage: "Regenerate specific files",
Commands: []*cli.Command{
- microcmdRegenHooks,
- microcmdRegenKeys,
+ newRegenerateHooksCommand(),
+ newRegenerateKeysCommand(),
},
}
+}
- subcmdAuth = &cli.Command{
+func newAuthCommand() *cli.Command {
+ return &cli.Command{
Name: "auth",
Usage: "Modify external auth providers",
Commands: []*cli.Command{
@@ -59,12 +64,14 @@ var (
microcmdAuthUpdateLdapSimpleAuth(),
microcmdAuthAddSMTP(),
microcmdAuthUpdateSMTP(),
- microcmdAuthList,
- microcmdAuthDelete,
+ newAuthListCommand(),
+ newAuthDeleteCommand(),
},
}
+}
- subcmdSendMail = &cli.Command{
+func newSendMailCommand() *cli.Command {
+ return &cli.Command{
Name: "sendmail",
Usage: "Send a message to all users",
Action: runSendMail,
@@ -86,7 +93,7 @@ var (
},
},
}
-)
+}
func idFlag() *cli.Int64Flag {
return &cli.Int64Flag{
@@ -121,7 +128,7 @@ func runRepoSyncReleases(ctx context.Context, _ *cli.Command) error {
}
log.Trace("Processing next %d repos of %d", len(repos), count)
for _, repo := range repos {
- log.Trace("Synchronizing repo %s with path %s", repo.FullName(), repo.RepoPath())
+ log.Trace("Synchronizing repo %s with path %s", repo.FullName(), repo.RelativePath())
gitRepo, err := gitrepo.OpenRepository(ctx, repo)
if err != nil {
log.Warn("OpenRepository: %v", err)
@@ -134,7 +141,7 @@ func runRepoSyncReleases(ctx context.Context, _ *cli.Command) error {
}
log.Trace(" currentNumReleases is %d, running SyncReleasesWithTags", oldnum)
- if err = repo_module.SyncReleasesWithTags(ctx, repo, gitRepo); err != nil {
+ if _, err = repo_module.SyncReleasesWithTags(ctx, repo, gitRepo); err != nil {
log.Warn(" SyncReleasesWithTags: %v", err)
gitRepo.Close()
continue
@@ -147,7 +154,7 @@ func runRepoSyncReleases(ctx context.Context, _ *cli.Command) error {
continue
}
- log.Trace(" repo %s releases synchronized to tags: from %d to %d",
+ log.Trace("repo %s releases synchronized to tags: from %d to %d",
repo.FullName(), oldnum, count)
gitRepo.Close()
}
diff --git a/cmd/admin_auth.go b/cmd/admin_auth.go
index 1a09366722..b55bb1481c 100644
--- a/cmd/admin_auth.go
+++ b/cmd/admin_auth.go
@@ -17,14 +17,17 @@ import (
"github.com/urfave/cli/v3"
)
-var (
- microcmdAuthDelete = &cli.Command{
+func newAuthDeleteCommand() *cli.Command {
+ return &cli.Command{
Name: "delete",
Usage: "Delete specific auth source",
Flags: []cli.Flag{idFlag()},
Action: runDeleteAuth,
}
- microcmdAuthList = &cli.Command{
+}
+
+func newAuthListCommand() *cli.Command {
+ return &cli.Command{
Name: "list",
Usage: "List auth sources",
Action: runListAuth,
@@ -55,7 +58,7 @@ var (
},
},
}
-)
+}
func runListAuth(ctx context.Context, c *cli.Command) error {
if err := initDB(ctx); err != nil {
diff --git a/cmd/admin_auth_ldap.go b/cmd/admin_auth_ldap.go
index 069ad6600c..c9be5abb37 100644
--- a/cmd/admin_auth_ldap.go
+++ b/cmd/admin_auth_ldap.go
@@ -94,6 +94,10 @@ func commonLdapCLIFlags() []cli.Flag {
Name: "public-ssh-key-attribute",
Usage: "The attribute of the user’s LDAP record containing the user’s public ssh key.",
},
+ &cli.BoolFlag{
+ Name: "ssh-keys-are-verified",
+ Usage: "Set to true to automatically flag SSH keys in LDAP as verified.",
+ },
&cli.BoolFlag{
Name: "skip-local-2fa",
Usage: "Set to true to skip local 2fa for users authenticated by this source",
@@ -294,6 +298,9 @@ func parseLdapConfig(c *cli.Command, config *ldap.Source) error {
if c.IsSet("public-ssh-key-attribute") {
config.AttributeSSHPublicKey = c.String("public-ssh-key-attribute")
}
+ if c.IsSet("ssh-keys-are-verified") {
+ config.SSHKeysAreVerified = c.Bool("ssh-keys-are-verified")
+ }
if c.IsSet("avatar-attribute") {
config.AttributeAvatar = c.String("avatar-attribute")
}
diff --git a/cmd/admin_auth_ldap_test.go b/cmd/admin_auth_ldap_test.go
index 2da7ebc573..0e3e465e81 100644
--- a/cmd/admin_auth_ldap_test.go
+++ b/cmd/admin_auth_ldap_test.go
@@ -233,7 +233,7 @@ func TestAddLdapBindDn(t *testing.T) {
},
getAuthSourceByID: func(ctx context.Context, id int64) (*auth.Source, error) {
assert.FailNow(t, "getAuthSourceByID called", "case %d: should not call getAuthSourceByID", n)
- return nil, nil
+ return nil, nil //nolint:nilnil // mock function covering improper behavior
},
}
@@ -463,7 +463,7 @@ func TestAddLdapSimpleAuth(t *testing.T) {
},
getAuthSourceByID: func(ctx context.Context, id int64) (*auth.Source, error) {
assert.FailNow(t, "getAuthSourceById called", "case %d: should not call getAuthSourceByID", n)
- return nil, nil
+ return nil, nil //nolint:nilnil // mock function covering improper behavior
},
}
diff --git a/cmd/admin_regenerate.go b/cmd/admin_regenerate.go
index a5f1bd5105..aa235441ba 100644
--- a/cmd/admin_regenerate.go
+++ b/cmd/admin_regenerate.go
@@ -13,19 +13,21 @@ import (
"github.com/urfave/cli/v3"
)
-var (
- microcmdRegenHooks = &cli.Command{
+func newRegenerateHooksCommand() *cli.Command {
+ return &cli.Command{
Name: "hooks",
Usage: "Regenerate git-hooks",
Action: runRegenerateHooks,
}
+}
- microcmdRegenKeys = &cli.Command{
+func newRegenerateKeysCommand() *cli.Command {
+ return &cli.Command{
Name: "keys",
Usage: "Regenerate authorized_keys file",
Action: runRegenerateKeys,
}
-)
+}
func runRegenerateHooks(ctx context.Context, _ *cli.Command) error {
if err := initDB(ctx); err != nil {
diff --git a/cmd/admin_user.go b/cmd/admin_user.go
index 3a24c3e56f..8dd8bb4eca 100644
--- a/cmd/admin_user.go
+++ b/cmd/admin_user.go
@@ -7,15 +7,17 @@ import (
"github.com/urfave/cli/v3"
)
-var subcmdUser = &cli.Command{
- Name: "user",
- Usage: "Modify users",
- Commands: []*cli.Command{
- microcmdUserCreate(),
- microcmdUserList,
- microcmdUserChangePassword(),
- microcmdUserDelete(),
- microcmdUserGenerateAccessToken,
- microcmdUserMustChangePassword(),
- },
+func newUserCommand() *cli.Command {
+ return &cli.Command{
+ Name: "user",
+ Usage: "Modify users",
+ Commands: []*cli.Command{
+ microcmdUserCreate(),
+ newUserListCommand(),
+ microcmdUserChangePassword(),
+ microcmdUserDelete(),
+ newUserGenerateAccessTokenCommand(),
+ microcmdUserMustChangePassword(),
+ },
+ }
}
diff --git a/cmd/admin_user_create.go b/cmd/admin_user_create.go
index cbdb5f90e2..7e5675cf58 100644
--- a/cmd/admin_user_create.go
+++ b/cmd/admin_user_create.go
@@ -151,6 +151,7 @@ func runCreateUser(ctx context.Context, c *cli.Command) error {
if err != nil {
return err
}
+ // codeql[disable-next-line=go/clear-text-logging]
fmt.Printf("generated random password is '%s'\n", password)
} else if userType == user_model.UserTypeIndividual {
return errors.New("must set either password or random-password flag")
diff --git a/cmd/admin_user_generate_access_token.go b/cmd/admin_user_generate_access_token.go
index 61064fdef4..7f8330ff7e 100644
--- a/cmd/admin_user_generate_access_token.go
+++ b/cmd/admin_user_generate_access_token.go
@@ -14,32 +14,34 @@ import (
"github.com/urfave/cli/v3"
)
-var microcmdUserGenerateAccessToken = &cli.Command{
- Name: "generate-access-token",
- Usage: "Generate an access token for a specific user",
- Flags: []cli.Flag{
- &cli.StringFlag{
- Name: "username",
- Aliases: []string{"u"},
- Usage: "Username",
+func newUserGenerateAccessTokenCommand() *cli.Command {
+ return &cli.Command{
+ Name: "generate-access-token",
+ Usage: "Generate an access token for a specific user",
+ Flags: []cli.Flag{
+ &cli.StringFlag{
+ Name: "username",
+ Aliases: []string{"u"},
+ Usage: "Username",
+ },
+ &cli.StringFlag{
+ Name: "token-name",
+ Aliases: []string{"t"},
+ Usage: "Token name",
+ Value: "gitea-admin",
+ },
+ &cli.BoolFlag{
+ Name: "raw",
+ Usage: "Display only the token value",
+ },
+ &cli.StringFlag{
+ Name: "scopes",
+ Value: "all",
+ Usage: `Comma separated list of scopes to apply to access token, examples: "all", "public-only,read:issue", "write:repository,write:user"`,
+ },
},
- &cli.StringFlag{
- Name: "token-name",
- Aliases: []string{"t"},
- Usage: "Token name",
- Value: "gitea-admin",
- },
- &cli.BoolFlag{
- Name: "raw",
- Usage: "Display only the token value",
- },
- &cli.StringFlag{
- Name: "scopes",
- Value: "all",
- Usage: `Comma separated list of scopes to apply to access token, examples: "all", "public-only,read:issue", "write:repository,write:user"`,
- },
- },
- Action: runGenerateAccessToken,
+ Action: runGenerateAccessToken,
+ }
}
func runGenerateAccessToken(ctx context.Context, c *cli.Command) error {
diff --git a/cmd/admin_user_list.go b/cmd/admin_user_list.go
index e3d345e2f2..2958fe0cc8 100644
--- a/cmd/admin_user_list.go
+++ b/cmd/admin_user_list.go
@@ -14,16 +14,18 @@ import (
"github.com/urfave/cli/v3"
)
-var microcmdUserList = &cli.Command{
- Name: "list",
- Usage: "List users",
- Action: runListUsers,
- Flags: []cli.Flag{
- &cli.BoolFlag{
- Name: "admin",
- Usage: "List only admin users",
+func newUserListCommand() *cli.Command {
+ return &cli.Command{
+ Name: "list",
+ Usage: "List users",
+ Action: runListUsers,
+ Flags: []cli.Flag{
+ &cli.BoolFlag{
+ Name: "admin",
+ Usage: "List only admin users",
+ },
},
- },
+ }
}
func runListUsers(ctx context.Context, c *cli.Command) error {
diff --git a/cmd/admin_user_must_change_password.go b/cmd/admin_user_must_change_password.go
index 8521853dc1..468d462b74 100644
--- a/cmd/admin_user_must_change_password.go
+++ b/cmd/admin_user_must_change_password.go
@@ -58,6 +58,7 @@ func runMustChangePassword(ctx context.Context, c *cli.Command) error {
return err
}
+ // codeql[disable-next-line=go/clear-text-logging]
fmt.Printf("Updated %d users setting MustChangePassword to %t\n", n, mustChangePassword)
return nil
}
diff --git a/cmd/config.go b/cmd/config.go
new file mode 100644
index 0000000000..5303b0e1e0
--- /dev/null
+++ b/cmd/config.go
@@ -0,0 +1,156 @@
+// Copyright 2025 The Gitea Authors. All rights reserved.
+// SPDX-License-Identifier: MIT
+
+package cmd
+
+import (
+ "context"
+ "errors"
+ "fmt"
+ "os"
+
+ "code.gitea.io/gitea/modules/setting"
+
+ "github.com/urfave/cli/v3"
+)
+
+func cmdConfig() *cli.Command {
+ subcmdConfigEditIni := &cli.Command{
+ Name: "edit-ini",
+ Usage: "Load an existing INI file, apply environment variables, keep specified keys, and output to a new INI file.",
+ Description: `
+Help users to edit the Gitea configuration INI file.
+
+# Keep Specified Keys
+
+If you need to re-create the configuration file with only a subset of keys,
+you can provide an INI template file for the kept keys and use the "--config-keep-keys" flag.
+For example, if a helm chart needs to reset the settings and only keep SECRET_KEY,
+it can use a template file (only keys take effect, values are ignored):
+
+ [security]
+ SECRET_KEY=
+
+$ ./gitea config edit-ini --config app-old.ini --config-keep-keys app-keys.ini --out app-new.ini
+
+# Map Environment Variables to INI Configuration
+
+Environment variables of the form "GITEA__section_name__KEY_NAME"
+will be mapped to the ini section "[section_name]" and the key
+"KEY_NAME" with the value as provided.
+
+Environment variables of the form "GITEA__section_name__KEY_NAME__FILE"
+will be mapped to the ini section "[section_name]" and the key
+"KEY_NAME" with the value loaded from the specified file.
+
+Environment variable keys can only contain characters "0-9A-Z_",
+if a section or key name contains dot ".", it needs to be escaped as _0x2E_.
+For example, to apply this config:
+
+ [git.config]
+ foo.bar=val
+
+$ export GITEA__git_0x2E_config__foo_0x2E_bar=val
+
+# Put All Together
+
+$ ./gitea config edit-ini --config app.ini --config-keep-keys app-keys.ini --apply-env {--in-place|--out app-new.ini}
+`,
+ Flags: []cli.Flag{
+ // "--config" flag is provided by global flags, and this flag is also used by "environment-to-ini" script wrapper
+ // "--in-place" is also used by "environment-to-ini" script wrapper for its old behavior: always overwrite the existing config file
+ &cli.BoolFlag{
+ Name: "in-place",
+ Usage: "Output to the same config file as input. This flag will be ignored if --out is set.",
+ },
+ &cli.StringFlag{
+ Name: "config-keep-keys",
+ Usage: "An INI template file containing keys for keeping. Only the keys defined in the INI template will be kept from old config. If not set, all keys will be kept.",
+ },
+ &cli.BoolFlag{
+ Name: "apply-env",
+ Usage: "Apply all GITEA__* variables from the environment to the config.",
+ },
+ &cli.StringFlag{
+ Name: "out",
+ Usage: "Destination config file to write to.",
+ },
+ },
+ Action: runConfigEditIni,
+ }
+
+ return &cli.Command{
+ Name: "config",
+ Usage: "Manage Gitea configuration",
+ Commands: []*cli.Command{
+ subcmdConfigEditIni,
+ },
+ }
+}
+
+func runConfigEditIni(_ context.Context, c *cli.Command) error {
+ // the config system may change the environment variables, so get a copy first, to be used later
+ env := append([]string{}, os.Environ()...)
+
+ // don't use the guessed setting.CustomConf, instead, require the user to provide --config explicitly
+ if !c.IsSet("config") {
+ return errors.New("flag is required but not set: --config")
+ }
+ configFileIn := c.String("config")
+
+ cfgIn, err := setting.NewConfigProviderFromFile(configFileIn)
+ if err != nil {
+ return fmt.Errorf("failed to load config file %q: %v", configFileIn, err)
+ }
+
+ // determine output config file: use "--out" flag or use "--in-place" flag to overwrite input file
+ inPlace := c.Bool("in-place")
+ configFileOut := c.String("out")
+ if configFileOut == "" {
+ if !inPlace {
+ return errors.New("either --in-place or --out must be specified")
+ }
+ configFileOut = configFileIn // in-place edit
+ }
+
+ needWriteOut := configFileOut != configFileIn
+
+ cfgOut := cfgIn
+ configKeepKeys := c.String("config-keep-keys")
+ if configKeepKeys != "" {
+ needWriteOut = true
+ cfgOut, err = setting.NewConfigProviderFromFile(configKeepKeys)
+ if err != nil {
+ return fmt.Errorf("failed to load config-keep-keys template file %q: %v", configKeepKeys, err)
+ }
+
+ for _, secOut := range cfgOut.Sections() {
+ for _, keyOut := range secOut.Keys() {
+ secIn := cfgIn.Section(secOut.Name())
+ keyIn := setting.ConfigSectionKey(secIn, keyOut.Name())
+ if keyIn != nil {
+ keyOut.SetValue(keyIn.String())
+ } else {
+ secOut.DeleteKey(keyOut.Name())
+ }
+ }
+ if len(secOut.Keys()) == 0 {
+ cfgOut.DeleteSection(secOut.Name())
+ }
+ }
+ }
+
+ if c.Bool("apply-env") {
+ if setting.EnvironmentToConfig(cfgOut, env) {
+ needWriteOut = true
+ }
+ }
+
+ if needWriteOut {
+ err = cfgOut.SaveTo(configFileOut)
+ if err != nil {
+ return err
+ }
+ }
+ return nil
+}
diff --git a/cmd/config_test.go b/cmd/config_test.go
new file mode 100644
index 0000000000..d123daa617
--- /dev/null
+++ b/cmd/config_test.go
@@ -0,0 +1,85 @@
+// Copyright 2025 The Gitea Authors. All rights reserved.
+// SPDX-License-Identifier: MIT
+
+package cmd
+
+import (
+ "os"
+ "testing"
+
+ "github.com/stretchr/testify/require"
+)
+
+func TestConfigEdit(t *testing.T) {
+ tmpDir := t.TempDir()
+ configOld := tmpDir + "/app-old.ini"
+ configTemplate := tmpDir + "/app-template.ini"
+ _ = os.WriteFile(configOld, []byte(`
+[sec]
+k1=v1
+k2=v2
+`), os.ModePerm)
+
+ _ = os.WriteFile(configTemplate, []byte(`
+[sec]
+k1=in-template
+
+[sec2]
+k3=v3
+`), os.ModePerm)
+
+ t.Setenv("GITEA__EnV__KeY", "val")
+
+ t.Run("OutputToNewWithEnv", func(t *testing.T) {
+ configNew := tmpDir + "/app-new.ini"
+ err := NewMainApp(AppVersion{}).Run(t.Context(), []string{
+ "./gitea", "--config", configOld,
+ "config", "edit-ini",
+ "--apply-env",
+ "--config-keep-keys", configTemplate,
+ "--out", configNew,
+ })
+ require.NoError(t, err)
+
+ // "k1" old value is kept because its key is in the template
+ // "k2" is removed because it isn't in the template
+ // "k3" isn't in new config because it isn't in the old config
+ // [env] is applied from environment variable
+ data, _ := os.ReadFile(configNew)
+ require.Equal(t, `[sec]
+k1 = v1
+
+[env]
+KeY = val
+`, string(data))
+ })
+
+ t.Run("OutputToExisting(environment-to-ini)", func(t *testing.T) {
+ // the legacy "environment-to-ini" (now a wrapper script) behavior:
+ // if no "--out", then "--in-place" must be used to overwrite the existing "--config" file
+ err := NewMainApp(AppVersion{}).Run(t.Context(), []string{
+ "./gitea", "config", "edit-ini",
+ "--apply-env",
+ "--config", configOld,
+ })
+ require.ErrorContains(t, err, "either --in-place or --out must be specified")
+
+ // simulate the "environment-to-ini" behavior with "--in-place"
+ err = NewMainApp(AppVersion{}).Run(t.Context(), []string{
+ "./gitea", "config", "edit-ini",
+ "--in-place",
+ "--apply-env",
+ "--config", configOld,
+ })
+ require.NoError(t, err)
+
+ data, _ := os.ReadFile(configOld)
+ require.Equal(t, `[sec]
+k1 = v1
+k2 = v2
+
+[env]
+KeY = val
+`, string(data))
+ })
+}
diff --git a/cmd/docs.go b/cmd/docs.go
index 098c0e9a8a..8e0f9428df 100644
--- a/cmd/docs.go
+++ b/cmd/docs.go
@@ -13,23 +13,24 @@ import (
"github.com/urfave/cli/v3"
)
-// CmdDocs represents the available docs sub-command.
-var CmdDocs = &cli.Command{
- Name: "docs",
- Usage: "Output CLI documentation",
- Description: "A command to output Gitea's CLI documentation, optionally to a file.",
- Action: runDocs,
- Flags: []cli.Flag{
- &cli.BoolFlag{
- Name: "man",
- Usage: "Output man pages instead",
+func newDocsCommand() *cli.Command {
+ return &cli.Command{
+ Name: "docs",
+ Usage: "Output CLI documentation",
+ Description: "A command to output Gitea's CLI documentation, optionally to a file.",
+ Action: runDocs,
+ Flags: []cli.Flag{
+ &cli.BoolFlag{
+ Name: "man",
+ Usage: "Output man pages instead",
+ },
+ &cli.StringFlag{
+ Name: "output",
+ Aliases: []string{"o"},
+ Usage: "Path to output to instead of stdout (will overwrite if exists)",
+ },
},
- &cli.StringFlag{
- Name: "output",
- Aliases: []string{"o"},
- Usage: "Path to output to instead of stdout (will overwrite if exists)",
- },
- },
+ }
}
func runDocs(_ context.Context, cmd *cli.Command) error {
diff --git a/cmd/doctor.go b/cmd/doctor.go
index 596dd61178..188740dbce 100644
--- a/cmd/doctor.go
+++ b/cmd/doctor.go
@@ -24,73 +24,77 @@ import (
"xorm.io/xorm"
)
-// CmdDoctor represents the available doctor sub-command.
-var CmdDoctor = &cli.Command{
- Name: "doctor",
- Usage: "Diagnose and optionally fix problems, convert or re-create database tables",
- Description: "A command to diagnose problems with the current Gitea instance according to the given configuration. Some problems can optionally be fixed by modifying the database or data storage.",
-
- Commands: []*cli.Command{
- cmdDoctorCheck,
- cmdRecreateTable,
- cmdDoctorConvert,
- },
+func newDoctorCommand() *cli.Command {
+ return &cli.Command{
+ Name: "doctor",
+ Usage: "Diagnose and optionally fix problems, convert or re-create database tables",
+ Description: "A command to diagnose problems with the current Gitea instance according to the given configuration. Some problems can optionally be fixed by modifying the database or data storage.",
+ Commands: []*cli.Command{
+ newDoctorCheckCommand(),
+ newRecreateTableCommand(),
+ newDoctorConvertCommand(),
+ },
+ }
}
-var cmdDoctorCheck = &cli.Command{
- Name: "check",
- Usage: "Diagnose and optionally fix problems",
- Description: "A command to diagnose problems with the current Gitea instance according to the given configuration. Some problems can optionally be fixed by modifying the database or data storage.",
- Action: runDoctorCheck,
- Flags: []cli.Flag{
- &cli.BoolFlag{
- Name: "list",
- Usage: "List the available checks",
- },
- &cli.BoolFlag{
- Name: "default",
- Usage: "Run the default checks (if neither --run or --all is set, this is the default behaviour)",
- },
- &cli.StringSliceFlag{
- Name: "run",
- Usage: "Run the provided checks - (if --default is set, the default checks will also run)",
- },
- &cli.BoolFlag{
- Name: "all",
- Usage: "Run all the available checks",
+func newDoctorCheckCommand() *cli.Command {
+ return &cli.Command{
+ Name: "check",
+ Usage: "Diagnose and optionally fix problems",
+ Description: "A command to diagnose problems with the current Gitea instance according to the given configuration. Some problems can optionally be fixed by modifying the database or data storage.",
+ Action: runDoctorCheck,
+ Flags: []cli.Flag{
+ &cli.BoolFlag{
+ Name: "list",
+ Usage: "List the available checks",
+ },
+ &cli.BoolFlag{
+ Name: "default",
+ Usage: "Run the default checks (if neither --run or --all is set, this is the default behaviour)",
+ },
+ &cli.StringSliceFlag{
+ Name: "run",
+ Usage: "Run the provided checks - (if --default is set, the default checks will also run)",
+ },
+ &cli.BoolFlag{
+ Name: "all",
+ Usage: "Run all the available checks",
+ },
+ &cli.BoolFlag{
+ Name: "fix",
+ Usage: "Automatically fix what we can",
+ },
+ &cli.StringFlag{
+ Name: "log-file",
+ Usage: `Name of the log file (no verbose log output by default). Set to "-" to output to stdout`,
+ },
+ &cli.BoolFlag{
+ Name: "color",
+ Aliases: []string{"H"},
+ Usage: "Use color for outputted information",
+ },
},
- &cli.BoolFlag{
- Name: "fix",
- Usage: "Automatically fix what we can",
- },
- &cli.StringFlag{
- Name: "log-file",
- Usage: `Name of the log file (no verbose log output by default). Set to "-" to output to stdout`,
- },
- &cli.BoolFlag{
- Name: "color",
- Aliases: []string{"H"},
- Usage: "Use color for outputted information",
- },
- },
+ }
}
-var cmdRecreateTable = &cli.Command{
- Name: "recreate-table",
- Usage: "Recreate tables from XORM definitions and copy the data.",
- ArgsUsage: "[TABLE]... : (TABLEs to recreate - leave blank for all)",
- Flags: []cli.Flag{
- &cli.BoolFlag{
- Name: "debug",
- Usage: "Print SQL commands sent",
+func newRecreateTableCommand() *cli.Command {
+ return &cli.Command{
+ Name: "recreate-table",
+ Usage: "Recreate tables from XORM definitions and copy the data.",
+ ArgsUsage: "[TABLE]... : (TABLEs to recreate - leave blank for all)",
+ Flags: []cli.Flag{
+ &cli.BoolFlag{
+ Name: "debug",
+ Usage: "Print SQL commands sent",
+ },
},
- },
- Description: `The database definitions Gitea uses change across versions, sometimes changing default values and leaving old unused columns.
+ Description: `The database definitions Gitea uses change across versions, sometimes changing default values and leaving old unused columns.
This command will cause Xorm to recreate tables, copying over the data and deleting the old table.
You should back-up your database before doing this and ensure that your database is up-to-date first.`,
- Action: runRecreateTable,
+ Action: runRecreateTable,
+ }
}
func runRecreateTable(ctx context.Context, cmd *cli.Command) error {
diff --git a/cmd/doctor_convert.go b/cmd/doctor_convert.go
index 8cb718d383..f4867912ab 100644
--- a/cmd/doctor_convert.go
+++ b/cmd/doctor_convert.go
@@ -14,12 +14,13 @@ import (
"github.com/urfave/cli/v3"
)
-// cmdDoctorConvert represents the available convert sub-command.
-var cmdDoctorConvert = &cli.Command{
- Name: "convert",
- Usage: "Convert the database",
- Description: "A command to convert an existing MySQL database from utf8 to utf8mb4 or MSSQL database from varchar to nvarchar",
- Action: runDoctorConvert,
+func newDoctorConvertCommand() *cli.Command {
+ return &cli.Command{
+ Name: "convert",
+ Usage: "Convert the database",
+ Description: "A command to convert an existing MySQL database from utf8 to utf8mb4 or MSSQL database from varchar to nvarchar",
+ Action: runDoctorConvert,
+ }
}
func runDoctorConvert(ctx context.Context, cmd *cli.Command) error {
diff --git a/cmd/doctor_test.go b/cmd/doctor_test.go
index da942b38b6..7d2f358947 100644
--- a/cmd/doctor_test.go
+++ b/cmd/doctor_test.go
@@ -23,7 +23,7 @@ func TestDoctorRun(t *testing.T) {
SkipDatabaseInitialization: true,
})
app := &cli.Command{
- Commands: []*cli.Command{cmdDoctorCheck},
+ Commands: []*cli.Command{newDoctorCheckCommand()},
}
err := app.Run(t.Context(), []string{"./gitea", "check", "--run", "test-check"})
assert.NoError(t, err)
diff --git a/cmd/dump.go b/cmd/dump.go
index 7f0b23ed98..49f4d9e894 100644
--- a/cmd/dump.go
+++ b/cmd/dump.go
@@ -23,78 +23,79 @@ import (
"github.com/urfave/cli/v3"
)
-// CmdDump represents the available dump sub-command.
-var CmdDump = &cli.Command{
- Name: "dump",
- Usage: "Dump Gitea files and database",
- Description: `Dump compresses all related files and database into zip file. It can be used for backup and capture Gitea server image to send to maintainer`,
- Action: runDump,
- Flags: []cli.Flag{
- &cli.StringFlag{
- Name: "file",
- Aliases: []string{"f"},
- Usage: `Name of the dump file which will be created, default to "gitea-dump-{time}.zip". Supply '-' for stdout. See type for available types.`,
+func newDumpCommand() *cli.Command {
+ return &cli.Command{
+ Name: "dump",
+ Usage: "Dump Gitea files and database",
+ Description: `Dump compresses all related files and database into zip file. It can be used for backup and capture Gitea server image to send to maintainer`,
+ Action: runDump,
+ Flags: []cli.Flag{
+ &cli.StringFlag{
+ Name: "file",
+ Aliases: []string{"f"},
+ Usage: `Name of the dump file which will be created, default to "gitea-dump-{time}.zip". Supply '-' for stdout. See type for available types.`,
+ },
+ &cli.BoolFlag{
+ Name: "verbose",
+ Aliases: []string{"V"},
+ Usage: "Show process details",
+ },
+ &cli.BoolFlag{
+ Name: "quiet",
+ Aliases: []string{"q"},
+ Usage: "Only display warnings and errors",
+ },
+ &cli.StringFlag{
+ Name: "tempdir",
+ Aliases: []string{"t"},
+ Value: os.TempDir(),
+ Usage: "Temporary dir path",
+ },
+ &cli.StringFlag{
+ Name: "database",
+ Aliases: []string{"d"},
+ Usage: "Specify the database SQL syntax: sqlite3, mysql, mssql, postgres",
+ },
+ &cli.BoolFlag{
+ Name: "skip-repository",
+ Aliases: []string{"R"},
+ Usage: "Skip the repository dumping",
+ },
+ &cli.BoolFlag{
+ Name: "skip-log",
+ Aliases: []string{"L"},
+ Usage: "Skip the log dumping",
+ },
+ &cli.BoolFlag{
+ Name: "skip-custom-dir",
+ Usage: "Skip custom directory",
+ },
+ &cli.BoolFlag{
+ Name: "skip-lfs-data",
+ Usage: "Skip LFS data",
+ },
+ &cli.BoolFlag{
+ Name: "skip-attachment-data",
+ Usage: "Skip attachment data",
+ },
+ &cli.BoolFlag{
+ Name: "skip-package-data",
+ Usage: "Skip package data",
+ },
+ &cli.BoolFlag{
+ Name: "skip-index",
+ Usage: "Skip bleve index data",
+ },
+ &cli.BoolFlag{
+ Name: "skip-db",
+ Usage: "Skip database",
+ },
+ &cli.StringFlag{
+ Name: "type",
+ Usage: `Dump output format, default to "zip", supported types: ` + strings.Join(dump.SupportedOutputTypes, ", "),
+ },
},
- &cli.BoolFlag{
- Name: "verbose",
- Aliases: []string{"V"},
- Usage: "Show process details",
- },
- &cli.BoolFlag{
- Name: "quiet",
- Aliases: []string{"q"},
- Usage: "Only display warnings and errors",
- },
- &cli.StringFlag{
- Name: "tempdir",
- Aliases: []string{"t"},
- Value: os.TempDir(),
- Usage: "Temporary dir path",
- },
- &cli.StringFlag{
- Name: "database",
- Aliases: []string{"d"},
- Usage: "Specify the database SQL syntax: sqlite3, mysql, mssql, postgres",
- },
- &cli.BoolFlag{
- Name: "skip-repository",
- Aliases: []string{"R"},
- Usage: "Skip the repository dumping",
- },
- &cli.BoolFlag{
- Name: "skip-log",
- Aliases: []string{"L"},
- Usage: "Skip the log dumping",
- },
- &cli.BoolFlag{
- Name: "skip-custom-dir",
- Usage: "Skip custom directory",
- },
- &cli.BoolFlag{
- Name: "skip-lfs-data",
- Usage: "Skip LFS data",
- },
- &cli.BoolFlag{
- Name: "skip-attachment-data",
- Usage: "Skip attachment data",
- },
- &cli.BoolFlag{
- Name: "skip-package-data",
- Usage: "Skip package data",
- },
- &cli.BoolFlag{
- Name: "skip-index",
- Usage: "Skip bleve index data",
- },
- &cli.BoolFlag{
- Name: "skip-db",
- Usage: "Skip database",
- },
- &cli.StringFlag{
- Name: "type",
- Usage: `Dump output format, default to "zip", supported types: ` + strings.Join(dump.SupportedOutputTypes, ", "),
- },
- },
+ }
}
func fatal(format string, args ...any) {
diff --git a/cmd/dump_repo.go b/cmd/dump_repo.go
index beda305c85..367454366e 100644
--- a/cmd/dump_repo.go
+++ b/cmd/dump_repo.go
@@ -22,61 +22,62 @@ import (
"github.com/urfave/cli/v3"
)
-// CmdDumpRepository represents the available dump repository sub-command.
-var CmdDumpRepository = &cli.Command{
- Name: "dump-repo",
- Usage: "Dump the repository from git/github/gitea/gitlab",
- Description: "This is a command for dumping the repository data.",
- Action: runDumpRepository,
- Flags: []cli.Flag{
- &cli.StringFlag{
- Name: "git_service",
- Value: "",
- Usage: "Git service, git, github, gitea, gitlab. If clone_addr could be recognized, this could be ignored.",
- },
- &cli.StringFlag{
- Name: "repo_dir",
- Aliases: []string{"r"},
- Value: "./data",
- Usage: "Repository dir path to store the data",
- },
- &cli.StringFlag{
- Name: "clone_addr",
- Value: "",
- Usage: "The URL will be clone, currently could be a git/github/gitea/gitlab http/https URL",
- },
- &cli.StringFlag{
- Name: "auth_username",
- Value: "",
- Usage: "The username to visit the clone_addr",
- },
- &cli.StringFlag{
- Name: "auth_password",
- Value: "",
- Usage: "The password to visit the clone_addr",
- },
- &cli.StringFlag{
- Name: "auth_token",
- Value: "",
- Usage: "The personal token to visit the clone_addr",
- },
- &cli.StringFlag{
- Name: "owner_name",
- Value: "",
- Usage: "The data will be stored on a directory with owner name if not empty",
- },
- &cli.StringFlag{
- Name: "repo_name",
- Value: "",
- Usage: "The data will be stored on a directory with repository name if not empty",
- },
- &cli.StringFlag{
- Name: "units",
- Value: "",
- Usage: `Which items will be migrated, one or more units should be separated as comma.
+func newDumpRepositoryCommand() *cli.Command {
+ return &cli.Command{
+ Name: "dump-repo",
+ Usage: "Dump the repository from git/github/gitea/gitlab",
+ Description: "This is a command for dumping the repository data.",
+ Action: runDumpRepository,
+ Flags: []cli.Flag{
+ &cli.StringFlag{
+ Name: "git_service",
+ Value: "",
+ Usage: "Git service, git, github, gitea, gitlab. If clone_addr could be recognized, this could be ignored.",
+ },
+ &cli.StringFlag{
+ Name: "repo_dir",
+ Aliases: []string{"r"},
+ Value: "./data",
+ Usage: "Repository dir path to store the data",
+ },
+ &cli.StringFlag{
+ Name: "clone_addr",
+ Value: "",
+ Usage: "The URL will be clone, currently could be a git/github/gitea/gitlab http/https URL",
+ },
+ &cli.StringFlag{
+ Name: "auth_username",
+ Value: "",
+ Usage: "The username to visit the clone_addr",
+ },
+ &cli.StringFlag{
+ Name: "auth_password",
+ Value: "",
+ Usage: "The password to visit the clone_addr",
+ },
+ &cli.StringFlag{
+ Name: "auth_token",
+ Value: "",
+ Usage: "The personal token to visit the clone_addr",
+ },
+ &cli.StringFlag{
+ Name: "owner_name",
+ Value: "",
+ Usage: "The data will be stored on a directory with owner name if not empty",
+ },
+ &cli.StringFlag{
+ Name: "repo_name",
+ Value: "",
+ Usage: "The data will be stored on a directory with repository name if not empty",
+ },
+ &cli.StringFlag{
+ Name: "units",
+ Value: "",
+ Usage: `Which items will be migrated, one or more units should be separated as comma.
wiki, issues, labels, releases, release_assets, milestones, pull_requests, comments are allowed. Empty means all units.`,
+ },
},
- },
+ }
}
func runDumpRepository(ctx context.Context, cmd *cli.Command) error {
diff --git a/cmd/embedded.go b/cmd/embedded.go
index 9180407fd1..e2110756b8 100644
--- a/cmd/embedded.go
+++ b/cmd/embedded.go
@@ -23,20 +23,23 @@ import (
"github.com/urfave/cli/v3"
)
-// CmdEmbedded represents the available extract sub-command.
-var (
- CmdEmbedded = &cli.Command{
+var matchedAssetFiles []assetFile
+
+func newEmbeddedCommand() *cli.Command {
+ return &cli.Command{
Name: "embedded",
Usage: "Extract embedded resources",
Description: "A command for extracting embedded resources, like templates and images",
Commands: []*cli.Command{
- subcmdList,
- subcmdView,
- subcmdExtract,
+ newEmbeddedListCommand(),
+ newEmbeddedViewCommand(),
+ newEmbeddedExtractCommand(),
},
}
+}
- subcmdList = &cli.Command{
+func newEmbeddedListCommand() *cli.Command {
+ return &cli.Command{
Name: "list",
Usage: "List files matching the given pattern",
Action: runList,
@@ -48,8 +51,10 @@ var (
},
},
}
+}
- subcmdView = &cli.Command{
+func newEmbeddedViewCommand() *cli.Command {
+ return &cli.Command{
Name: "view",
Usage: "View a file matching the given pattern",
Action: runView,
@@ -61,8 +66,10 @@ var (
},
},
}
+}
- subcmdExtract = &cli.Command{
+func newEmbeddedExtractCommand() *cli.Command {
+ return &cli.Command{
Name: "extract",
Usage: "Extract resources",
Action: runExtract,
@@ -91,9 +98,7 @@ var (
},
},
}
-
- matchedAssetFiles []assetFile
-)
+}
type assetFile struct {
fs *assetfs.LayeredFS
diff --git a/cmd/generate.go b/cmd/generate.go
index cf491604ef..21f8b42bff 100644
--- a/cmd/generate.go
+++ b/cmd/generate.go
@@ -15,45 +15,52 @@ import (
"github.com/urfave/cli/v3"
)
-var (
- // CmdGenerate represents the available generate sub-command.
- CmdGenerate = &cli.Command{
+func newGenerateCommand() *cli.Command {
+ return &cli.Command{
Name: "generate",
Usage: "Generate Gitea's secrets/keys/tokens",
Commands: []*cli.Command{
- subcmdSecret,
+ newGenerateSecretCommand(),
},
}
+}
- subcmdSecret = &cli.Command{
+func newGenerateSecretCommand() *cli.Command {
+ return &cli.Command{
Name: "secret",
Usage: "Generate a secret token",
Commands: []*cli.Command{
- microcmdGenerateInternalToken,
- microcmdGenerateLfsJwtSecret,
- microcmdGenerateSecretKey,
+ newGenerateInternalTokenCommand(),
+ newGenerateLfsJWTSecretCommand(),
+ newGenerateSecretKeyCommand(),
},
}
+}
- microcmdGenerateInternalToken = &cli.Command{
+func newGenerateInternalTokenCommand() *cli.Command {
+ return &cli.Command{
Name: "INTERNAL_TOKEN",
Usage: "Generate a new INTERNAL_TOKEN",
Action: runGenerateInternalToken,
}
+}
- microcmdGenerateLfsJwtSecret = &cli.Command{
+func newGenerateLfsJWTSecretCommand() *cli.Command {
+ return &cli.Command{
Name: "JWT_SECRET",
Aliases: []string{"LFS_JWT_SECRET"},
Usage: "Generate a new JWT_SECRET",
Action: runGenerateLfsJwtSecret,
}
+}
- microcmdGenerateSecretKey = &cli.Command{
+func newGenerateSecretKeyCommand() *cli.Command {
+ return &cli.Command{
Name: "SECRET_KEY",
Usage: "Generate a new SECRET_KEY",
Action: runGenerateSecretKey,
}
-)
+}
func runGenerateInternalToken(_ context.Context, c *cli.Command) error {
internalToken, err := generate.NewInternalToken()
@@ -71,11 +78,7 @@ func runGenerateInternalToken(_ context.Context, c *cli.Command) error {
}
func runGenerateLfsJwtSecret(_ context.Context, c *cli.Command) error {
- _, jwtSecretBase64, err := generate.NewJwtSecretWithBase64()
- if err != nil {
- return err
- }
-
+ _, jwtSecretBase64 := generate.NewJwtSecretWithBase64()
fmt.Printf("%s", jwtSecretBase64)
if isatty.IsTerminal(os.Stdout.Fd()) {
@@ -91,6 +94,7 @@ func runGenerateSecretKey(_ context.Context, c *cli.Command) error {
return err
}
+ // codeql[disable-next-line=go/clear-text-logging]
fmt.Printf("%s", secretKey)
if isatty.IsTerminal(os.Stdout.Fd()) {
diff --git a/cmd/hook.go b/cmd/hook.go
index 2f866dd396..4a6c7c2905 100644
--- a/cmd/hook.go
+++ b/cmd/hook.go
@@ -28,23 +28,24 @@ const (
hookBatchSize = 500
)
-var (
- // CmdHook represents the available hooks sub-command.
- CmdHook = &cli.Command{
+func newHookCommand() *cli.Command {
+ return &cli.Command{
Name: "hook",
Usage: "(internal) Should only be called by Git",
Hidden: true, // internal commands shouldn't be visible
Description: "Delegate commands to corresponding Git hooks",
Before: PrepareConsoleLoggerLevel(log.FATAL),
Commands: []*cli.Command{
- subcmdHookPreReceive,
- subcmdHookUpdate,
- subcmdHookPostReceive,
- subcmdHookProcReceive,
+ newHookPreReceiveCommand(),
+ newHookUpdateCommand(),
+ newHookPostReceiveCommand(),
+ newHookProcReceiveCommand(),
},
}
+}
- subcmdHookPreReceive = &cli.Command{
+func newHookPreReceiveCommand() *cli.Command {
+ return &cli.Command{
Name: "pre-receive",
Usage: "Delegate pre-receive Git hook",
Description: "This command should only be called by Git",
@@ -55,7 +56,10 @@ var (
},
},
}
- subcmdHookUpdate = &cli.Command{
+}
+
+func newHookUpdateCommand() *cli.Command {
+ return &cli.Command{
Name: "update",
Usage: "Delegate update Git hook",
Description: "This command should only be called by Git",
@@ -66,7 +70,10 @@ var (
},
},
}
- subcmdHookPostReceive = &cli.Command{
+}
+
+func newHookPostReceiveCommand() *cli.Command {
+ return &cli.Command{
Name: "post-receive",
Usage: "Delegate post-receive Git hook",
Description: "This command should only be called by Git",
@@ -77,8 +84,11 @@ var (
},
},
}
- // Note: new hook since git 2.29
- subcmdHookProcReceive = &cli.Command{
+}
+
+// Note: new hook since git 2.29
+func newHookProcReceiveCommand() *cli.Command {
+ return &cli.Command{
Name: "proc-receive",
Usage: "Delegate proc-receive Git hook",
Description: "This command should only be called by Git",
@@ -89,7 +99,7 @@ var (
},
},
}
-)
+}
type delayWriter struct {
internal io.Writer
@@ -163,6 +173,14 @@ func (n *nilWriter) WriteString(s string) (int, error) {
return len(s), nil
}
+func parseGitHookCommitRefLine(line string) (oldCommitID, newCommitID string, refFullName git.RefName, ok bool) {
+ fields := strings.Split(line, " ")
+ if len(fields) != 3 {
+ return "", "", "", false
+ }
+ return fields[0], fields[1], git.RefName(fields[2]), true
+}
+
func runHookPreReceive(ctx context.Context, c *cli.Command) error {
if isInternal, _ := strconv.ParseBool(os.Getenv(repo_module.EnvIsInternal)); isInternal {
return nil
@@ -186,7 +204,7 @@ Gitea or set your environment appropriately.`, "")
userID, _ := strconv.ParseInt(os.Getenv(repo_module.EnvPusherID), 10, 64)
prID, _ := strconv.ParseInt(os.Getenv(repo_module.EnvPRID), 10, 64)
deployKeyID, _ := strconv.ParseInt(os.Getenv(repo_module.EnvDeployKeyID), 10, 64)
- actionPerm, _ := strconv.ParseInt(os.Getenv(repo_module.EnvActionPerm), 10, 64)
+ actionsTaskID, _ := strconv.ParseInt(os.Getenv(repo_module.EnvActionsTaskID), 10, 64)
hookOptions := private.HookOptions{
UserID: userID,
@@ -196,7 +214,8 @@ Gitea or set your environment appropriately.`, "")
GitPushOptions: pushOptions(),
PullRequestID: prID,
DeployKeyID: deployKeyID,
- ActionPerm: int(actionPerm),
+ ActionsTaskID: actionsTaskID,
+ IsWiki: isWiki,
}
scanner := bufio.NewScanner(os.Stdin)
@@ -228,14 +247,11 @@ Gitea or set your environment appropriately.`, "")
continue
}
- fields := bytes.Fields(scanner.Bytes())
- if len(fields) != 3 {
+ oldCommitID, newCommitID, refFullName, ok := parseGitHookCommitRefLine(scanner.Text())
+ if !ok {
continue
}
- oldCommitID := string(fields[0])
- newCommitID := string(fields[1])
- refFullName := git.RefName(fields[2])
total++
lastline++
@@ -270,6 +286,9 @@ Gitea or set your environment appropriately.`, "")
lastline = 0
}
}
+ if err := scanner.Err(); err != nil {
+ return fail(ctx, "Hook failed: stdin read error", "scanner error: %v", err)
+ }
if count > 0 {
hookOptions.OldCommitIDs = oldCommitIDs[:count]
@@ -313,7 +332,7 @@ func runHookPostReceive(ctx context.Context, c *cli.Command) error {
setup(ctx, c.Bool("debug"))
// First of all run update-server-info no matter what
- if _, _, err := gitcmd.NewCommand("update-server-info").RunStdString(ctx, nil); err != nil {
+ if err := gitcmd.NewCommand("update-server-info").RunWithStderr(ctx); err != nil {
return fmt.Errorf("failed to call 'git update-server-info': %w", err)
}
@@ -361,6 +380,7 @@ Gitea or set your environment appropriately.`, "")
GitPushOptions: pushOptions(),
PullRequestID: prID,
PushTrigger: repo_module.PushTrigger(os.Getenv(repo_module.EnvPushTrigger)),
+ IsWiki: isWiki,
}
oldCommitIDs := make([]string, hookBatchSize)
newCommitIDs := make([]string, hookBatchSize)
@@ -378,16 +398,13 @@ Gitea or set your environment appropriately.`, "")
continue
}
- fields := bytes.Fields(scanner.Bytes())
- if len(fields) != 3 {
+ var ok bool
+ oldCommitIDs[count], newCommitIDs[count], refFullNames[count], ok = parseGitHookCommitRefLine(scanner.Text())
+ if !ok {
continue
}
fmt.Fprintf(out, ".")
- oldCommitIDs[count] = string(fields[0])
- newCommitIDs[count] = string(fields[1])
- refFullNames[count] = git.RefName(fields[2])
-
commitID, _ := git.NewIDFromString(newCommitIDs[count])
if refFullNames[count] == git.BranchPrefix+"master" && !commitID.IsZero() && count == total {
masterPushed = true
@@ -411,6 +428,11 @@ Gitea or set your environment appropriately.`, "")
count = 0
}
}
+ if err := scanner.Err(); err != nil {
+ _ = dWriter.Close()
+ hookPrintResults(results)
+ return fail(ctx, "Hook failed: stdin read error", "scanner error: %v", err)
+ }
if count == 0 {
if wasEmpty && masterPushed {
@@ -511,6 +533,7 @@ Gitea or set your environment appropriately.`, "")
reader := bufio.NewReader(os.Stdin)
repoUser := os.Getenv(repo_module.EnvRepoUsername)
+ isWiki, _ := strconv.ParseBool(os.Getenv(repo_module.EnvRepoIsWiki))
repoName := os.Getenv(repo_module.EnvRepoName)
pusherID, _ := strconv.ParseInt(os.Getenv(repo_module.EnvPusherID), 10, 64)
pusherName := os.Getenv(repo_module.EnvPusherName)
@@ -588,14 +611,15 @@ Gitea or set your environment appropriately.`, "")
UserName: pusherName,
UserID: pusherID,
GitPushOptions: make(map[string]string),
+ IsWiki: isWiki,
}
hookOptions.OldCommitIDs = make([]string, 0, hookBatchSize)
hookOptions.NewCommitIDs = make([]string, 0, hookBatchSize)
hookOptions.RefFullNames = make([]git.RefName, 0, hookBatchSize)
for {
- // note: pktLineTypeUnknow means pktLineTypeFlush and pktLineTypeData all allowed
- rs, err = readPktLine(ctx, reader, pktLineTypeUnknow)
+ // note: pktLineTypeUnknown means pktLineTypeFlush and pktLineTypeData all allowed
+ rs, err = readPktLine(ctx, reader, pktLineTypeUnknown)
if err != nil {
return err
}
@@ -614,7 +638,7 @@ Gitea or set your environment appropriately.`, "")
if hasPushOptions {
for {
- rs, err = readPktLine(ctx, reader, pktLineTypeUnknow)
+ rs, err = readPktLine(ctx, reader, pktLineTypeUnknown)
if err != nil {
return err
}
@@ -711,8 +735,8 @@ Gitea or set your environment appropriately.`, "")
type pktLineType int64
const (
- // UnKnow type
- pktLineTypeUnknow pktLineType = 0
+ // Unknown type
+ pktLineTypeUnknown pktLineType = 0
// flush-pkt "0000"
pktLineTypeFlush pktLineType = iota
// data line
diff --git a/cmd/hook_test.go b/cmd/hook_test.go
index 86cd4834f2..fefc33c01c 100644
--- a/cmd/hook_test.go
+++ b/cmd/hook_test.go
@@ -39,3 +39,17 @@ func TestPktLine(t *testing.T) {
assert.NoError(t, err)
assert.Equal(t, []byte("0007a\nb"), w.Bytes())
}
+
+func TestParseGitHookCommitRefLine(t *testing.T) {
+ oldCommitID, newCommitID, refName, ok := parseGitHookCommitRefLine("a b c")
+ assert.True(t, ok)
+ assert.Equal(t, "a", oldCommitID)
+ assert.Equal(t, "b", newCommitID)
+ assert.Equal(t, "c", string(refName))
+
+ _, _, _, ok = parseGitHookCommitRefLine("a\tb\tc")
+ assert.False(t, ok)
+
+ _, _, _, ok = parseGitHookCommitRefLine("a b")
+ assert.False(t, ok)
+}
diff --git a/cmd/keys.go b/cmd/keys.go
index 035d39bfb8..912cf25091 100644
--- a/cmd/keys.go
+++ b/cmd/keys.go
@@ -15,40 +15,42 @@ import (
"github.com/urfave/cli/v3"
)
-// CmdKeys represents the available keys sub-command
-var CmdKeys = &cli.Command{
- Name: "keys",
- Usage: "(internal) Should only be called by SSH server",
- Hidden: true, // internal commands shouldn't be visible
- Description: "Queries the Gitea database to get the authorized command for a given ssh key fingerprint",
- Before: PrepareConsoleLoggerLevel(log.FATAL),
- Action: runKeys,
- Flags: []cli.Flag{
- &cli.StringFlag{
- Name: "expected",
- Aliases: []string{"e"},
- Value: "git",
- Usage: "Expected user for whom provide key commands",
+// NewKeysCommand returns the internal SSH key lookup sub-command.
+func NewKeysCommand() *cli.Command {
+ return &cli.Command{
+ Name: "keys",
+ Usage: "(internal) Should only be called by SSH server",
+ Hidden: true, // internal commands shouldn't be visible
+ Description: "Queries the Gitea database to get the authorized command for a given ssh key fingerprint",
+ Before: PrepareConsoleLoggerLevel(log.FATAL),
+ Action: runKeys,
+ Flags: []cli.Flag{
+ &cli.StringFlag{
+ Name: "expected",
+ Aliases: []string{"e"},
+ Value: "git",
+ Usage: "Expected user for whom provide key commands",
+ },
+ &cli.StringFlag{
+ Name: "username",
+ Aliases: []string{"u"},
+ Value: "",
+ Usage: "Username trying to log in by SSH",
+ },
+ &cli.StringFlag{
+ Name: "type",
+ Aliases: []string{"t"},
+ Value: "",
+ Usage: "Type of the SSH key provided to the SSH Server (requires content to be provided too)",
+ },
+ &cli.StringFlag{
+ Name: "content",
+ Aliases: []string{"k"},
+ Value: "",
+ Usage: "Base64 encoded content of the SSH key provided to the SSH Server (requires type to be provided too)",
+ },
},
- &cli.StringFlag{
- Name: "username",
- Aliases: []string{"u"},
- Value: "",
- Usage: "Username trying to log in by SSH",
- },
- &cli.StringFlag{
- Name: "type",
- Aliases: []string{"t"},
- Value: "",
- Usage: "Type of the SSH key provided to the SSH Server (requires content to be provided too)",
- },
- &cli.StringFlag{
- Name: "content",
- Aliases: []string{"k"},
- Value: "",
- Usage: "Base64 encoded content of the SSH key provided to the SSH Server (requires type to be provided too)",
- },
- },
+ }
}
func runKeys(ctx context.Context, c *cli.Command) error {
diff --git a/cmd/mailer.go b/cmd/mailer.go
index 72bd8e5601..a7dbd68e20 100644
--- a/cmd/mailer.go
+++ b/cmd/mailer.go
@@ -17,10 +17,10 @@ func runSendMail(ctx context.Context, c *cli.Command) error {
setting.MustInstalled()
subject := c.String("title")
- confirmSkiped := c.Bool("force")
+ confirmSkipped := c.Bool("force")
body := c.String("content")
- if !confirmSkiped {
+ if !confirmSkipped {
if len(body) == 0 {
fmt.Print("warning: Content is empty")
}
diff --git a/cmd/main.go b/cmd/main.go
index da979ee511..a6b89a6fad 100644
--- a/cmd/main.go
+++ b/cmd/main.go
@@ -112,34 +112,36 @@ func NewMainApp(appVer AppVersion) *cli.Command {
Usage: "Set custom path (defaults to '{WorkPath}/custom')",
},
}
+ webCmd := newWebCommand()
// these sub-commands need to use a config file
subCmdWithConfig := []*cli.Command{
- CmdWeb,
- CmdServ,
- CmdHook,
- CmdKeys,
- CmdDump,
- CmdAdmin,
- CmdMigrate,
- CmdDoctor,
- CmdManager,
- CmdEmbedded,
- CmdMigrateStorage,
- CmdDumpRepository,
- CmdRestoreRepository,
- CmdActions,
+ webCmd,
+ newServCommand(),
+ newHookCommand(),
+ NewKeysCommand(),
+ newDumpCommand(),
+ newAdminCommand(),
+ newMigrateCommand(),
+ newDoctorCommand(),
+ newManagerCommand(),
+ newEmbeddedCommand(),
+ newMigrateStorageCommand(),
+ newDumpRepositoryCommand(),
+ newRestoreRepositoryCommand(),
+ newActionsCommand(),
}
// these sub-commands do not need the config file, and they do not depend on any path or environment variable.
subCmdStandalone := []*cli.Command{
+ cmdConfig(),
cmdCert(),
- CmdGenerate,
- CmdDocs,
+ newGenerateCommand(),
+ newDocsCommand(),
}
// TODO: we should eventually drop the default command,
// but not sure whether it would break Windows users who used to double-click the EXE to run.
- app.DefaultCommand = CmdWeb.Name
+ app.DefaultCommand = webCmd.Name
app.Before = PrepareConsoleLoggerLevel(log.INFO)
for i := range subCmdWithConfig {
@@ -148,7 +150,7 @@ func NewMainApp(appVer AppVersion) *cli.Command {
app.Commands = append(app.Commands, subCmdWithConfig...)
app.Commands = append(app.Commands, subCmdStandalone...)
- setting.InitGiteaEnvVars()
+ setting.UnsetUnnecessaryEnvVars()
return app
}
diff --git a/cmd/main_test.go b/cmd/main_test.go
index 69ea1237c6..b1f6bb3ba9 100644
--- a/cmd/main_test.go
+++ b/cmd/main_test.go
@@ -157,6 +157,7 @@ func TestCliCmd(t *testing.T) {
for _, c := range cases {
t.Run(c.cmd, func(t *testing.T) {
+ defer test.MockVariableValue(&setting.InstallLock, false)()
app := newTestApp(cli.Command{
Action: func(ctx context.Context, cmd *cli.Command) error {
_, _ = fmt.Fprint(cmd.Root().Writer, makePathOutput(setting.AppWorkPath, setting.CustomPath, setting.CustomConf))
@@ -170,7 +171,10 @@ func TestCliCmd(t *testing.T) {
r, err := runTestApp(app, args...)
assert.NoError(t, err, c.cmd)
assert.NotEmpty(t, c.exp, c.cmd)
- assert.Contains(t, r.Stdout, c.exp, c.cmd)
+ if !assert.Contains(t, r.Stdout, c.exp, c.cmd) {
+ t.Log("Full output:\n" + r.Stdout)
+ t.Log("Expected:\n" + c.exp)
+ }
})
}
}
diff --git a/cmd/manager.go b/cmd/manager.go
index f0935ea065..586c65990b 100644
--- a/cmd/manager.go
+++ b/cmd/manager.go
@@ -13,22 +13,24 @@ import (
"github.com/urfave/cli/v3"
)
-var (
- // CmdManager represents the manager command
- CmdManager = &cli.Command{
+func newManagerCommand() *cli.Command {
+ return &cli.Command{
Name: "manager",
Usage: "Manage the running gitea process",
Description: "This is a command for managing the running gitea process",
Commands: []*cli.Command{
- subcmdShutdown,
- subcmdRestart,
- subcmdReloadTemplates,
- subcmdFlushQueues,
- subcmdLogging,
- subCmdProcesses,
+ newShutdownCommand(),
+ newRestartCommand(),
+ newReloadTemplatesCommand(),
+ newFlushQueuesCommand(),
+ newLoggingCommand(),
+ newProcessesCommand(),
},
}
- subcmdShutdown = &cli.Command{
+}
+
+func newShutdownCommand() *cli.Command {
+ return &cli.Command{
Name: "shutdown",
Usage: "Gracefully shutdown the running process",
Flags: []cli.Flag{
@@ -38,7 +40,10 @@ var (
},
Action: runShutdown,
}
- subcmdRestart = &cli.Command{
+}
+
+func newRestartCommand() *cli.Command {
+ return &cli.Command{
Name: "restart",
Usage: "Gracefully restart the running process - (not implemented for windows servers)",
Flags: []cli.Flag{
@@ -48,7 +53,10 @@ var (
},
Action: runRestart,
}
- subcmdReloadTemplates = &cli.Command{
+}
+
+func newReloadTemplatesCommand() *cli.Command {
+ return &cli.Command{
Name: "reload-templates",
Usage: "Reload template files in the running process",
Flags: []cli.Flag{
@@ -58,7 +66,10 @@ var (
},
Action: runReloadTemplates,
}
- subcmdFlushQueues = &cli.Command{
+}
+
+func newFlushQueuesCommand() *cli.Command {
+ return &cli.Command{
Name: "flush-queues",
Usage: "Flush queues in the running process",
Action: runFlushQueues,
@@ -77,7 +88,10 @@ var (
},
},
}
- subCmdProcesses = &cli.Command{
+}
+
+func newProcessesCommand() *cli.Command {
+ return &cli.Command{
Name: "processes",
Usage: "Display running processes within the current process",
Action: runProcesses,
@@ -107,7 +121,7 @@ var (
},
},
}
-)
+}
func runShutdown(ctx context.Context, c *cli.Command) error {
setup(ctx, c.Bool("debug"))
diff --git a/cmd/manager_logging.go b/cmd/manager_logging.go
index ac29e7d3e5..5812e707e2 100644
--- a/cmd/manager_logging.go
+++ b/cmd/manager_logging.go
@@ -15,8 +15,8 @@ import (
"github.com/urfave/cli/v3"
)
-var (
- defaultLoggingFlags = []cli.Flag{
+func defaultLoggingFlags() []cli.Flag {
+ return []cli.Flag{
&cli.StringFlag{
Name: "logger",
Usage: `Logger name - will default to "default"`,
@@ -57,8 +57,10 @@ var (
Name: "debug",
},
}
+}
- subcmdLogging = &cli.Command{
+func newLoggingCommand() *cli.Command {
+ return &cli.Command{
Name: "logging",
Usage: "Adjust logging commands",
Commands: []*cli.Command{
@@ -109,7 +111,7 @@ var (
{
Name: "file",
Usage: "Add a file logger",
- Flags: append(defaultLoggingFlags, []cli.Flag{
+ Flags: append(defaultLoggingFlags(), []cli.Flag{
&cli.StringFlag{
Name: "filename",
Aliases: []string{"f"},
@@ -150,7 +152,7 @@ var (
}, {
Name: "conn",
Usage: "Add a net conn logger",
- Flags: append(defaultLoggingFlags, []cli.Flag{
+ Flags: append(defaultLoggingFlags(), []cli.Flag{
&cli.BoolFlag{
Name: "reconnect-on-message",
Aliases: []string{"R"},
@@ -191,7 +193,7 @@ var (
},
},
}
-)
+}
func runRemoveLogger(ctx context.Context, c *cli.Command) error {
setup(ctx, c.Bool("debug"))
diff --git a/cmd/migrate.go b/cmd/migrate.go
index e24dc9e572..016f8a0db5 100644
--- a/cmd/migrate.go
+++ b/cmd/migrate.go
@@ -14,12 +14,13 @@ import (
"github.com/urfave/cli/v3"
)
-// CmdMigrate represents the available migrate sub-command.
-var CmdMigrate = &cli.Command{
- Name: "migrate",
- Usage: "Migrate the database",
- Description: `This is a command for migrating the database, so that you can run "gitea admin create user" before starting the server.`,
- Action: runMigrate,
+func newMigrateCommand() *cli.Command {
+ return &cli.Command{
+ Name: "migrate",
+ Usage: "Migrate the database",
+ Description: `This is a command for migrating the database, so that you can run "gitea admin create user" before starting the server.`,
+ Action: runMigrate,
+ }
}
func runMigrate(ctx context.Context, c *cli.Command) error {
diff --git a/cmd/migrate_storage.go b/cmd/migrate_storage.go
index 2c63e15f50..c9b82055c1 100644
--- a/cmd/migrate_storage.go
+++ b/cmd/migrate_storage.go
@@ -25,107 +25,108 @@ import (
"github.com/urfave/cli/v3"
)
-// CmdMigrateStorage represents the available migrate storage sub-command.
-var CmdMigrateStorage = &cli.Command{
- Name: "migrate-storage",
- Usage: "Migrate the storage",
- Description: "Copies stored files from storage configured in app.ini to parameter-configured storage",
- Action: runMigrateStorage,
- Flags: []cli.Flag{
- &cli.StringFlag{
- Name: "type",
- Aliases: []string{"t"},
- Value: "",
- Usage: "Type of stored files to copy. Allowed types: 'attachments', 'lfs', 'avatars', 'repo-avatars', 'repo-archivers', 'packages', 'actions-log', 'actions-artifacts",
+func newMigrateStorageCommand() *cli.Command {
+ return &cli.Command{
+ Name: "migrate-storage",
+ Usage: "Migrate the storage",
+ Description: "Copies stored files from storage configured in app.ini to parameter-configured storage",
+ Action: runMigrateStorage,
+ Flags: []cli.Flag{
+ &cli.StringFlag{
+ Name: "type",
+ Aliases: []string{"t"},
+ Value: "",
+ Usage: "Type of stored files to copy. Allowed types: 'attachments', 'lfs', 'avatars', 'repo-avatars', 'repo-archivers', 'packages', 'actions-log', 'actions-artifacts'",
+ },
+ &cli.StringFlag{
+ Name: "storage",
+ Aliases: []string{"s"},
+ Value: "",
+ Usage: "New storage type: local (default), minio or azureblob",
+ },
+ &cli.StringFlag{
+ Name: "path",
+ Aliases: []string{"p"},
+ Value: "",
+ Usage: "New storage placement if store is local (leave blank for default)",
+ },
+ // Minio Storage special configurations
+ &cli.StringFlag{
+ Name: "minio-endpoint",
+ Value: "",
+ Usage: "Minio storage endpoint",
+ },
+ &cli.StringFlag{
+ Name: "minio-access-key-id",
+ Value: "",
+ Usage: "Minio storage accessKeyID",
+ },
+ &cli.StringFlag{
+ Name: "minio-secret-access-key",
+ Value: "",
+ Usage: "Minio storage secretAccessKey",
+ },
+ &cli.StringFlag{
+ Name: "minio-bucket",
+ Value: "",
+ Usage: "Minio storage bucket",
+ },
+ &cli.StringFlag{
+ Name: "minio-location",
+ Value: "",
+ Usage: "Minio storage location to create bucket",
+ },
+ &cli.StringFlag{
+ Name: "minio-base-path",
+ Value: "",
+ Usage: "Minio storage base path on the bucket",
+ },
+ &cli.BoolFlag{
+ Name: "minio-use-ssl",
+ Usage: "Enable SSL for minio",
+ },
+ &cli.BoolFlag{
+ Name: "minio-insecure-skip-verify",
+ Usage: "Skip SSL verification",
+ },
+ &cli.StringFlag{
+ Name: "minio-checksum-algorithm",
+ Value: "",
+ Usage: "Minio checksum algorithm (default/md5)",
+ },
+ &cli.StringFlag{
+ Name: "minio-bucket-lookup-type",
+ Value: "",
+ Usage: "Minio bucket lookup type",
+ },
+ // Azure Blob Storage special configurations
+ &cli.StringFlag{
+ Name: "azureblob-endpoint",
+ Value: "",
+ Usage: "Azure Blob storage endpoint",
+ },
+ &cli.StringFlag{
+ Name: "azureblob-account-name",
+ Value: "",
+ Usage: "Azure Blob storage account name",
+ },
+ &cli.StringFlag{
+ Name: "azureblob-account-key",
+ Value: "",
+ Usage: "Azure Blob storage account key",
+ },
+ &cli.StringFlag{
+ Name: "azureblob-container",
+ Value: "",
+ Usage: "Azure Blob storage container",
+ },
+ &cli.StringFlag{
+ Name: "azureblob-base-path",
+ Value: "",
+ Usage: "Azure Blob storage base path",
+ },
},
- &cli.StringFlag{
- Name: "storage",
- Aliases: []string{"s"},
- Value: "",
- Usage: "New storage type: local (default), minio or azureblob",
- },
- &cli.StringFlag{
- Name: "path",
- Aliases: []string{"p"},
- Value: "",
- Usage: "New storage placement if store is local (leave blank for default)",
- },
- // Minio Storage special configurations
- &cli.StringFlag{
- Name: "minio-endpoint",
- Value: "",
- Usage: "Minio storage endpoint",
- },
- &cli.StringFlag{
- Name: "minio-access-key-id",
- Value: "",
- Usage: "Minio storage accessKeyID",
- },
- &cli.StringFlag{
- Name: "minio-secret-access-key",
- Value: "",
- Usage: "Minio storage secretAccessKey",
- },
- &cli.StringFlag{
- Name: "minio-bucket",
- Value: "",
- Usage: "Minio storage bucket",
- },
- &cli.StringFlag{
- Name: "minio-location",
- Value: "",
- Usage: "Minio storage location to create bucket",
- },
- &cli.StringFlag{
- Name: "minio-base-path",
- Value: "",
- Usage: "Minio storage base path on the bucket",
- },
- &cli.BoolFlag{
- Name: "minio-use-ssl",
- Usage: "Enable SSL for minio",
- },
- &cli.BoolFlag{
- Name: "minio-insecure-skip-verify",
- Usage: "Skip SSL verification",
- },
- &cli.StringFlag{
- Name: "minio-checksum-algorithm",
- Value: "",
- Usage: "Minio checksum algorithm (default/md5)",
- },
- &cli.StringFlag{
- Name: "minio-bucket-lookup-type",
- Value: "",
- Usage: "Minio bucket lookup type",
- },
- // Azure Blob Storage special configurations
- &cli.StringFlag{
- Name: "azureblob-endpoint",
- Value: "",
- Usage: "Azure Blob storage endpoint",
- },
- &cli.StringFlag{
- Name: "azureblob-account-name",
- Value: "",
- Usage: "Azure Blob storage account name",
- },
- &cli.StringFlag{
- Name: "azureblob-account-key",
- Value: "",
- Usage: "Azure Blob storage account key",
- },
- &cli.StringFlag{
- Name: "azureblob-container",
- Value: "",
- Usage: "Azure Blob storage container",
- },
- &cli.StringFlag{
- Name: "azureblob-base-path",
- Value: "",
- Usage: "Azure Blob storage base path",
- },
- },
+ }
}
func migrateAttachments(ctx context.Context, dstStorage storage.ObjectStorage) error {
diff --git a/cmd/restore_repo.go b/cmd/restore_repo.go
index c61f5a582e..26b4682f13 100644
--- a/cmd/restore_repo.go
+++ b/cmd/restore_repo.go
@@ -13,40 +13,41 @@ import (
"github.com/urfave/cli/v3"
)
-// CmdRestoreRepository represents the available restore a repository sub-command.
-var CmdRestoreRepository = &cli.Command{
- Name: "restore-repo",
- Usage: "Restore the repository from disk",
- Description: "This is a command for restoring the repository data.",
- Action: runRestoreRepository,
- Flags: []cli.Flag{
- &cli.StringFlag{
- Name: "repo_dir",
- Aliases: []string{"r"},
- Value: "./data",
- Usage: "Repository dir path to restore from",
- },
- &cli.StringFlag{
- Name: "owner_name",
- Value: "",
- Usage: "Restore destination owner name",
- },
- &cli.StringFlag{
- Name: "repo_name",
- Value: "",
- Usage: "Restore destination repository name",
- },
- &cli.StringFlag{
- Name: "units",
- Value: "",
- Usage: `Which items will be restored, one or more units should be separated as comma.
+func newRestoreRepositoryCommand() *cli.Command {
+ return &cli.Command{
+ Name: "restore-repo",
+ Usage: "Restore the repository from disk",
+ Description: "This is a command for restoring the repository data.",
+ Action: runRestoreRepository,
+ Flags: []cli.Flag{
+ &cli.StringFlag{
+ Name: "repo_dir",
+ Aliases: []string{"r"},
+ Value: "./data",
+ Usage: "Repository dir path to restore from",
+ },
+ &cli.StringFlag{
+ Name: "owner_name",
+ Value: "",
+ Usage: "Restore destination owner name",
+ },
+ &cli.StringFlag{
+ Name: "repo_name",
+ Value: "",
+ Usage: "Restore destination repository name",
+ },
+ &cli.StringFlag{
+ Name: "units",
+ Value: "",
+ Usage: `Which items will be restored, one or more units should be separated as comma.
wiki, issues, labels, releases, release_assets, milestones, pull_requests, comments are allowed. Empty means all units.`,
+ },
+ &cli.BoolFlag{
+ Name: "validation",
+ Usage: "Sanity check the content of the files before trying to load them",
+ },
},
- &cli.BoolFlag{
- Name: "validation",
- Usage: "Sanity check the content of the files before trying to load them",
- },
- },
+ }
}
func runRestoreRepository(ctx context.Context, c *cli.Command) error {
diff --git a/cmd/serv.go b/cmd/serv.go
index 4110fda0d5..a35d476c86 100644
--- a/cmd/serv.go
+++ b/cmd/serv.go
@@ -35,22 +35,23 @@ import (
"github.com/urfave/cli/v3"
)
-// CmdServ represents the available serv sub-command.
-var CmdServ = &cli.Command{
- Name: "serv",
- Usage: "(internal) Should only be called by SSH shell",
- Description: "Serv provides access auth for repositories",
- Hidden: true, // Internal commands shouldn't be visible in help
- Before: PrepareConsoleLoggerLevel(log.FATAL),
- Action: runServ,
- Flags: []cli.Flag{
- &cli.BoolFlag{
- Name: "enable-pprof",
+func newServCommand() *cli.Command {
+ return &cli.Command{
+ Name: "serv",
+ Usage: "(internal) Should only be called by SSH shell",
+ Description: "Serv provides access auth for repositories",
+ Hidden: true, // Internal commands shouldn't be visible in help
+ Before: PrepareConsoleLoggerLevel(log.FATAL),
+ Action: runServ,
+ Flags: []cli.Flag{
+ &cli.BoolFlag{
+ Name: "enable-pprof",
+ },
+ &cli.BoolFlag{
+ Name: "debug",
+ },
},
- &cli.BoolFlag{
- Name: "debug",
- },
- },
+ }
}
func setup(ctx context.Context, debug bool) {
diff --git a/cmd/web.go b/cmd/web.go
index 4723ddbbdd..994c481fc0 100644
--- a/cmd/web.go
+++ b/cmd/web.go
@@ -8,14 +8,13 @@ import (
"fmt"
"net"
"net/http"
+ "net/http/pprof"
"os"
"path/filepath"
"strconv"
"strings"
"time"
- _ "net/http/pprof" // Used for debugging if enabled and a web server is running
-
"code.gitea.io/gitea/modules/container"
"code.gitea.io/gitea/modules/graceful"
"code.gitea.io/gitea/modules/gtprof"
@@ -23,6 +22,7 @@ import (
"code.gitea.io/gitea/modules/process"
"code.gitea.io/gitea/modules/public"
"code.gitea.io/gitea/modules/setting"
+ "code.gitea.io/gitea/modules/templates"
"code.gitea.io/gitea/modules/util"
"code.gitea.io/gitea/routers"
"code.gitea.io/gitea/routers/install"
@@ -34,42 +34,43 @@ import (
// PIDFile could be set from build tag
var PIDFile = "/run/gitea.pid"
-// CmdWeb represents the available web sub-command.
-var CmdWeb = &cli.Command{
- Name: "web",
- Usage: "Start Gitea web server",
- Description: `Gitea web server is the only thing you need to run,
+func newWebCommand() *cli.Command {
+ return &cli.Command{
+ Name: "web",
+ Usage: "Start Gitea web server",
+ Description: `Gitea web server is the only thing you need to run,
and it takes care of all the other things for you`,
- Before: PrepareConsoleLoggerLevel(log.INFO),
- Action: runWeb,
- Flags: []cli.Flag{
- &cli.StringFlag{
- Name: "port",
- Aliases: []string{"p"},
- Value: "3000",
- Usage: "Temporary port number to prevent conflict",
- },
- &cli.StringFlag{
- Name: "install-port",
- Value: "3000",
- Usage: "Temporary port number to run the install page on to prevent conflict",
- },
- &cli.StringFlag{
- Name: "pid",
- Aliases: []string{"P"},
- Value: PIDFile,
- Usage: "Custom pid file path",
- },
- &cli.BoolFlag{
- Name: "quiet",
- Aliases: []string{"q"},
- Usage: "Only display Fatal logging errors until logging is set-up",
- },
- &cli.BoolFlag{
- Name: "verbose",
- Usage: "Set initial logging to TRACE level until logging is properly set-up",
+ Before: PrepareConsoleLoggerLevel(log.INFO),
+ Action: runWeb,
+ Flags: []cli.Flag{
+ &cli.StringFlag{
+ Name: "port",
+ Aliases: []string{"p"},
+ Value: "3000",
+ Usage: "Temporary port number to prevent conflict",
+ },
+ &cli.StringFlag{
+ Name: "install-port",
+ Value: "3000",
+ Usage: "Temporary port number to run the install page on to prevent conflict",
+ },
+ &cli.StringFlag{
+ Name: "pid",
+ Aliases: []string{"P"},
+ Value: PIDFile,
+ Usage: "Custom pid file path",
+ },
+ &cli.BoolFlag{
+ Name: "quiet",
+ Aliases: []string{"q"},
+ Usage: "Only display Fatal logging errors until logging is set-up",
+ },
+ &cli.BoolFlag{
+ Name: "verbose",
+ Usage: "Set initial logging to TRACE level until logging is properly set-up",
+ },
},
- },
+ }
}
func runHTTPRedirector() {
@@ -156,7 +157,6 @@ func serveInstall(cmd *cli.Command) error {
case <-graceful.GetManager().IsShutdown():
<-graceful.GetManager().Done()
log.Info("PID: %d Gitea Web Finished", os.Getpid())
- log.GetManager().Close()
return err
default:
}
@@ -164,8 +164,6 @@ func serveInstall(cmd *cli.Command) error {
}
func serveInstalled(c *cli.Command) error {
- setting.InitCfgProvider(setting.CustomConf)
- setting.LoadCommonSettings()
setting.MustInstalled()
showWebStartupMessage("Prepare to run web server")
@@ -231,27 +229,26 @@ func serveInstalled(c *cli.Command) error {
err := listen(webRoutes, true)
<-graceful.GetManager().Done()
log.Info("PID: %d Gitea Web Finished", os.Getpid())
- log.GetManager().Close()
return err
}
func servePprof() {
- // FIXME: it shouldn't use the global DefaultServeMux, and it should use a proper context
- http.DefaultServeMux.Handle("/debug/fgprof", fgprof.Handler())
+ mux := http.NewServeMux()
+ mux.HandleFunc("/debug/pprof/", pprof.Index)
+ mux.HandleFunc("/debug/pprof/cmdline", pprof.Cmdline)
+ mux.HandleFunc("/debug/pprof/profile", pprof.Profile)
+ mux.HandleFunc("/debug/pprof/symbol", pprof.Symbol)
+ mux.HandleFunc("/debug/pprof/trace", pprof.Trace)
+ mux.Handle("/debug/fgprof", fgprof.Handler())
+ // FIXME: it should use a proper context
_, _, finished := process.GetManager().AddTypedContext(context.TODO(), "Web: PProf Server", process.SystemProcessType, true)
// The pprof server is for debug purpose only, it shouldn't be exposed on public network. At the moment, it's not worth introducing a configurable option for it.
log.Info("Starting pprof server on localhost:6060")
- log.Info("Stopped pprof server: %v", http.ListenAndServe("localhost:6060", nil))
+ log.Info("Stopped pprof server: %v", http.ListenAndServe("localhost:6060", mux))
finished()
}
func runWeb(ctx context.Context, cmd *cli.Command) error {
- defer func() {
- if panicked := recover(); panicked != nil {
- log.Fatal("PANIC: %v\n%s", panicked, log.Stack(2))
- }
- }()
-
if subCmdName, valid := isValidDefaultSubCommand(cmd); !valid {
return fmt.Errorf("unknown command: %s", subCmdName)
}
@@ -271,6 +268,10 @@ func runWeb(ctx context.Context, cmd *cli.Command) error {
createPIDFile(cmd.String("pid"))
}
+ // init the HTML renderer and load templates, if error happens, it will report the error immediately and exit with error log
+ // in dev mode, it won't exit, but watch the template files for changes
+ _ = templates.PageRenderer()
+
if !setting.InstallLock {
if err := serveInstall(cmd); err != nil {
return err
diff --git a/cmd/web_acme.go b/cmd/web_acme.go
index 5f7a308334..a2e14638f8 100644
--- a/cmd/web_acme.go
+++ b/cmd/web_acme.go
@@ -7,6 +7,7 @@ import (
"crypto/x509"
"encoding/pem"
"fmt"
+ "net"
"net/http"
"os"
"strconv"
@@ -124,8 +125,8 @@ func runACME(listenAddr string, m http.Handler) error {
defer finished()
log.Info("Running Let's Encrypt handler on %s", setting.HTTPAddr+":"+setting.PortToRedirect)
- // all traffic coming into HTTP will be redirect to HTTPS automatically (LE HTTP-01 validation happens here)
- err := runHTTP("tcp", setting.HTTPAddr+":"+setting.PortToRedirect, "Let's Encrypt HTTP Challenge", myACME.HTTPChallengeHandler(http.HandlerFunc(runLetsEncryptFallbackHandler)), setting.RedirectorUseProxyProtocol)
+ // all traffic coming into HTTP will be redirected to HTTPS automatically (LE HTTP-01 validation happens here)
+ err := runHTTP("tcp", net.JoinHostPort(setting.HTTPAddr, setting.PortToRedirect), "Let's Encrypt HTTP Challenge", myACME.HTTPChallengeHandler(http.HandlerFunc(runLetsEncryptFallbackHandler)), setting.RedirectorUseProxyProtocol)
if err != nil {
log.Fatal("Failed to start the Let's Encrypt handler on port %s: %v", setting.PortToRedirect, err)
}
diff --git a/contrib/backport/backport.go b/contrib/backport/backport.go
index 5811291b42..2af980e5e3 100644
--- a/contrib/backport/backport.go
+++ b/contrib/backport/backport.go
@@ -16,7 +16,7 @@ import (
"strconv"
"strings"
- "github.com/google/go-github/v74/github"
+ "github.com/google/go-github/v84/github"
"github.com/urfave/cli/v3"
"gopkg.in/yaml.v3"
)
diff --git a/contrib/environment-to-ini/README b/contrib/environment-to-ini/README
deleted file mode 100644
index f1d3f2ae83..0000000000
--- a/contrib/environment-to-ini/README
+++ /dev/null
@@ -1,47 +0,0 @@
-Environment To Ini
-==================
-
-Multiple docker users have requested that the Gitea docker is changed
-to permit arbitrary configuration via environment variables.
-
-Gitea needs to use an ini file for configuration because the running
-environment that starts the docker may not be the same as that used
-by the hooks. An ini file also gives a good default and means that
-users do not have to completely provide a full environment.
-
-With those caveats above, this command provides a generic way of
-converting suitably structured environment variables into any ini
-value.
-
-To use the command is very simple just run it and the default gitea
-app.ini will be rewritten to take account of the variables provided,
-however there are various options to give slightly different
-behavior and these can be interrogated with the `-h` option.
-
-The environment variables should be of the form:
-
- GITEA__SECTION_NAME__KEY_NAME
-
-Note, SECTION_NAME in the notation above is case-insensitive.
-
-Environment variables are usually restricted to a reduced character
-set "0-9A-Z_" - in order to allow the setting of sections with
-characters outside of that set, they should be escaped as following:
-"_0X2E_" for "." and "_0X2D_" for "-". The entire section and key names
-can be escaped as a UTF8 byte string if necessary. E.g. to configure:
-
- """
- ...
- [log.console]
- COLORIZE=false
- STDERR=true
- ...
- """
-
-You would set the environment variables: "GITEA__LOG_0x2E_CONSOLE__COLORIZE=false"
-and "GITEA__LOG_0x2E_CONSOLE__STDERR=false". Other examples can be found
-on the configuration cheat sheet.
-
-To build locally, run:
-
- go build contrib/environment-to-ini/environment-to-ini.go
diff --git a/contrib/environment-to-ini/environment-to-ini.go b/contrib/environment-to-ini/environment-to-ini.go
deleted file mode 100644
index 5eb576c6fe..0000000000
--- a/contrib/environment-to-ini/environment-to-ini.go
+++ /dev/null
@@ -1,112 +0,0 @@
-// Copyright 2019 The Gitea Authors. All rights reserved.
-// SPDX-License-Identifier: MIT
-
-package main
-
-import (
- "context"
- "os"
-
- "code.gitea.io/gitea/modules/log"
- "code.gitea.io/gitea/modules/setting"
-
- "github.com/urfave/cli/v3"
-)
-
-func main() {
- app := cli.Command{}
- app.Name = "environment-to-ini"
- app.Usage = "Use provided environment to update configuration ini"
- app.Description = `As a helper to allow docker users to update the gitea configuration
- through the environment, this command allows environment variables to
- be mapped to values in the ini.
-
- Environment variables of the form "GITEA__SECTION_NAME__KEY_NAME"
- will be mapped to the ini section "[section_name]" and the key
- "KEY_NAME" with the value as provided.
-
- Environment variables of the form "GITEA__SECTION_NAME__KEY_NAME__FILE"
- will be mapped to the ini section "[section_name]" and the key
- "KEY_NAME" with the value loaded from the specified file.
-
- Environment variables are usually restricted to a reduced character
- set "0-9A-Z_" - in order to allow the setting of sections with
- characters outside of that set, they should be escaped as following:
- "_0X2E_" for ".". The entire section and key names can be escaped as
- a UTF8 byte string if necessary. E.g. to configure:
-
- """
- ...
- [log.console]
- COLORIZE=false
- STDERR=true
- ...
- """
-
- You would set the environment variables: "GITEA__LOG_0x2E_CONSOLE__COLORIZE=false"
- and "GITEA__LOG_0x2E_CONSOLE__STDERR=false". Other examples can be found
- on the configuration cheat sheet.`
- app.Flags = []cli.Flag{
- &cli.StringFlag{
- Name: "custom-path",
- Aliases: []string{"C"},
- Value: setting.CustomPath,
- Usage: "Custom path file path",
- },
- &cli.StringFlag{
- Name: "config",
- Aliases: []string{"c"},
- Value: setting.CustomConf,
- Usage: "Custom configuration file path",
- },
- &cli.StringFlag{
- Name: "work-path",
- Aliases: []string{"w"},
- Value: setting.AppWorkPath,
- Usage: "Set the gitea working path",
- },
- &cli.StringFlag{
- Name: "out",
- Aliases: []string{"o"},
- Value: "",
- Usage: "Destination file to write to",
- },
- }
- app.Action = runEnvironmentToIni
- err := app.Run(context.Background(), os.Args)
- if err != nil {
- log.Fatal("Failed to run app with %s: %v", os.Args, err)
- }
-}
-
-func runEnvironmentToIni(_ context.Context, c *cli.Command) error {
- // the config system may change the environment variables, so get a copy first, to be used later
- env := append([]string{}, os.Environ()...)
- setting.InitWorkPathAndCfgProvider(os.Getenv, setting.ArgWorkPathAndCustomConf{
- WorkPath: c.String("work-path"),
- CustomPath: c.String("custom-path"),
- CustomConf: c.String("config"),
- })
-
- cfg, err := setting.NewConfigProviderFromFile(setting.CustomConf)
- if err != nil {
- log.Fatal("Failed to load custom conf '%s': %v", setting.CustomConf, err)
- }
-
- changed := setting.EnvironmentToConfig(cfg, env)
-
- // try to save the config file
- destination := c.String("out")
- if len(destination) == 0 {
- destination = setting.CustomConf
- }
- if destination != setting.CustomConf || changed {
- log.Info("Settings saved to: %q", destination)
- err = cfg.SaveTo(destination)
- if err != nil {
- return err
- }
- }
-
- return nil
-}
diff --git a/contrib/upgrade.sh b/contrib/upgrade.sh
index e5e296ea8b..2593d24509 100755
--- a/contrib/upgrade.sh
+++ b/contrib/upgrade.sh
@@ -108,7 +108,9 @@ curl --connect-timeout 10 --silent --show-error --fail --location -O "$binurl{,.
sha256sum -c "${binname}.xz.sha256"
if [[ -z "${ignore_gpg:-}" ]]; then
require gpg
- gpg --keyserver keys.openpgp.org --recv 7C9E68152594688862D62AF62D9AE806EC1592E2
+ # try to use curl first, it uses standard tcp 443 port and works better behind strict firewall rules
+ curl -fsSL --connect-timeout 10 "https://keys.openpgp.org/vks/v1/by-fingerprint/7C9E68152594688862D62AF62D9AE806EC1592E2" | gpg --import \
+ || gpg --keyserver keys.openpgp.org --recv 7C9E68152594688862D62AF62D9AE806EC1592E2
gpg --verify "${binname}.xz.asc" "${binname}.xz" || { echo 'Signature does not match'; exit 1; }
fi
rm "${binname}".xz.{sha256,asc}
@@ -127,6 +129,8 @@ echo "Creating backup in $giteahome"
giteacmd dump $backupopts
echo "Updating binary at $giteabin"
cp -f "$giteabin" "$giteabin.bak" && mv -f "$binname" "$giteabin"
+# Restore SELinux context if applicable (e.g. RHEL/Fedora)
+command -v restorecon &>/dev/null && restorecon -v "$giteabin" || true
$service_start
$service_status
diff --git a/crowdin.yml b/crowdin.yml
index 35a38d768c..d14d484cf8 100644
--- a/crowdin.yml
+++ b/crowdin.yml
@@ -4,9 +4,9 @@ base_path: "."
base_url: "https://api.crowdin.com"
preserve_hierarchy: true
files:
- - source: "/options/locale/locale_en-US.ini"
- translation: "/options/locale/locale_%locale%.ini"
- type: "ini"
+ - source: "/options/locale/locale_en-US.json"
+ translation: "/options/locale/locale_%locale%.json"
+ type: "json"
skip_untranslated_strings: true
export_only_approved: true
update_option: "update_as_unapproved"
diff --git a/custom/conf/app.example.ini b/custom/conf/app.example.ini
index 33bfe752a0..0a30925572 100644
--- a/custom/conf/app.example.ini
+++ b/custom/conf/app.example.ini
@@ -41,10 +41,10 @@
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;;
;; App name that shows in every page title
-APP_NAME = ; Gitea: Git with a cup of tea
+;APP_NAME = Gitea: Git with a cup of tea
;;
;; RUN_USER will automatically detect the current user - but you can set it here change it if you run locally
-RUN_USER = ; git
+;RUN_USER =
;;
;; Application run mode, affects performance and debugging: "dev" or "prod", default is "prod"
;; Mode "dev" makes Gitea easier to develop and debug, values other than "dev" are treated as "prod" which is for production use.
@@ -69,12 +69,12 @@ RUN_USER = ; git
;; Most users should set it to the real website URL of their Gitea instance when there is a reverse proxy.
;ROOT_URL =
;;
-;; Controls how to detect the public URL.
-;; Although it defaults to "legacy" (to avoid breaking existing users), most instances should use the "auto" behavior,
+;; Controls how to detect the public URL. Most instances should use the "auto" behavior,
;; especially when the Gitea instance needs to be accessed in a container network.
-;; * legacy: detect the public URL from "Host" header if "X-Forwarded-Proto" header exists, otherwise use "ROOT_URL".
-;; * auto: always use "Host" header, and also use "X-Forwarded-Proto" header if it exists. If no "Host" header, use "ROOT_URL".
-;PUBLIC_URL_DETECTION = legacy
+;; * legacy: (default <= 1.25) detect the public URL from "Host" header if "X-Forwarded-Proto" header exists, otherwise use "ROOT_URL".
+;; * auto: (default >= 1.26) always use "Host" header, and also use "X-Forwarded-Proto" header if it exists. If no "Host" header, use "ROOT_URL".
+;; * never: always use "ROOT_URL", never detect from request headers.
+;PUBLIC_URL_DETECTION = auto
;;
;; For development purpose only. It makes Gitea handle sub-path ("/sub-path/owner/repo/...") directly when debugging without a reverse proxy.
;; DO NOT USE IT IN PRODUCTION!!!
@@ -175,14 +175,15 @@ RUN_USER = ; git
;; The port number the builtin SSH server should listen on, defaults to SSH_PORT
;SSH_LISTEN_PORT =
;;
-;; Root path of SSH directory, default is '~/.ssh', but you have to use '/home/git/.ssh'.
+;; Root path of SSH user directory for the system's standalone SSH server if Gitea is not using its builtin SSH server.
+;; Default is the '.ssh' directory in the run user's home directory.
;SSH_ROOT_PATH =
;;
-;; Gitea will create a authorized_keys file by default when it is not using the internal ssh server
+;; Gitea will create an authorized_keys file by default when it is not using the builtin SSH server
;; If you intend to use the AuthorizedKeysCommand functionality then you should turn this off.
;SSH_CREATE_AUTHORIZED_KEYS_FILE = true
;;
-;; Gitea will create a authorized_principals file by default when it is not using the internal ssh server
+;; Gitea will create an authorized_principals file by default when it is not using the builtin SSH server
;; If you intend to use the AuthorizedPrincipalsCommand functionality then you should turn this off.
;SSH_CREATE_AUTHORIZED_PRINCIPALS_FILE = true
;;
@@ -238,9 +239,6 @@ RUN_USER = ; git
;; Indicate whether to check minimum key size with corresponding type
;MINIMUM_KEY_SIZE_CHECK = false
;;
-;; Disable CDN even in "prod" mode
-;OFFLINE_MODE = true
-;;
;; TLS Settings: Either ACME or manual
;; (Other common TLS configuration are found before)
;ENABLE_ACME = false
@@ -463,6 +461,11 @@ INTERNAL_TOKEN =
;; Name of cookie used to store authentication information.
;COOKIE_REMEMBER_NAME = gitea_incredible
;;
+;; URL or path that Gitea should redirect users to *after* performing its own logout.
+;; Use this, if needed, when authentication is handled by a reverse proxy or SSO.
+;; For example: "/my-sso/logout?return=/my-sso/home"
+;REVERSE_PROXY_LOGOUT_REDIRECT =
+;;
;; Reverse proxy authentication header name of user name, email, and full name
;REVERSE_PROXY_AUTHENTICATION_USER = X-WEBAUTH-USER
;REVERSE_PROXY_AUTHENTICATION_EMAIL = X-WEBAUTH-EMAIL
@@ -503,9 +506,6 @@ INTERNAL_TOKEN =
;; Password Hash algorithm, either "argon2", "pbkdf2", "scrypt" or "bcrypt"
;PASSWORD_HASH_ALGO = pbkdf2
;;
-;; Set false to allow JavaScript to read CSRF cookie
-;CSRF_COOKIE_HTTP_ONLY = true
-;;
;; Validate against https://haveibeenpwned.com/Passwords to see if a password has been exposed
;PASSWORD_CHECK_PWN = false
;;
@@ -524,6 +524,9 @@ INTERNAL_TOKEN =
;; Set the two-factor auth behavior.
;; Set to "enforced", to force users to enroll into Two-Factor Authentication, users without 2FA have no access to repositories via API or web.
;TWO_FACTOR_AUTH =
+;;
+;; The value of the X-Frame-Options HTTP header for HTML responses. Use "unset" to remove the header.
+;X_FRAME_OPTIONS = SAMEORIGIN
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
@@ -733,15 +736,15 @@ LEVEL = Info
;DISABLE_CORE_PROTECT_NTFS=false
;; Disable the usage of using partial clones for git.
;DISABLE_PARTIAL_CLONE = false
+;; Set the similarity threshold passed to git commands via `--find-renames=`.
+;; Default is 50%, the same as git. Must be a integer percentage between 0% and 100%.
+;DIFF_RENAME_SIMILARITY_THRESHOLD = 50%
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;; Git Operation timeout in seconds
;[git.timeout]
-;DEFAULT = 360
;MIGRATE = 600
;MIRROR = 300
-;CLONE = 300
-;PULL = 300
;GC = 60
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
@@ -1155,15 +1158,20 @@ LEVEL = Info
;; Add co-authored-by and co-committed-by trailers if committer does not match author
;ADD_CO_COMMITTER_TRAILERS = true
;;
-;; In addition to testing patches using the three-way merge method, re-test conflicting patches with git apply
-;TEST_CONFLICTING_PATCHES_WITH_GIT_APPLY = false
-;;
;; Retarget child pull requests to the parent pull request branch target on merge of parent pull request. It only works on merged PRs where the head and base branch target the same repo.
;RETARGET_CHILDREN_ON_MERGE = true
;;
+;; Default source for the pull request title when opening a new PR.
+;; "first-commit" uses the oldest commit's summary.
+;; "auto" uses commit's summary if the PR only has one commit, normalizes the branch name if multiple commits.
+;DEFAULT_TITLE_SOURCE = auto
+;;
;; Delay mergeable check until page view or API access, for pull requests that have not been updated in the specified days when their base branches get updated.
;; Use "-1" to always check all pull requests (old behavior). Use "0" to always delay the checks.
;DELAY_CHECK_FOR_INACTIVE_DAYS = 7
+;;
+;; Set the default value for "Delete pull request branch after merge by default" for new repositories
+;DEFAULT_DELETE_BRANCH_AFTER_MERGE = false
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
@@ -1181,9 +1189,17 @@ LEVEL = Info
;[repository.release]
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
-;; Comma-separated list of allowed file extensions (`.zip`), mime types (`text/plain`) or wildcard type (`image/*`, `audio/*`, `video/*`). Empty value or `*/*` allows all types.
+;; Comma-separated list of allowed release attachment file extensions (`.zip`), mime types (`text/plain`) or wildcard type (`image/*`, `audio/*`, `video/*`). Empty value or `*/*` allows all types.
;ALLOWED_TYPES =
+;;
+;; Number of releases that are displayed on release page
;DEFAULT_PAGING_NUM = 10
+;;
+;; Max size of each release attachment file in megabytes. Defaults to 2GB
+;FILE_MAX_SIZE = 2048
+;;
+;; Max number of release attachment files per upload. Defaults to 5
+;MAX_FILES = 5
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
@@ -1285,9 +1301,6 @@ LEVEL = Info
;;
;; headers to permit
;HEADERS = Content-Type,User-Agent
-;;
-;; set X-FRAME-OPTIONS header
-;X_FRAME_OPTIONS = SAMEORIGIN
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
@@ -1332,9 +1345,12 @@ LEVEL = Info
;; Leave it empty to allow users to select any theme from "{CustomPath}/public/assets/css/theme-*.css"
;THEMES =
;;
-;; The icons for file list (basic/material), this is a temporary option which will be replaced by a user setting in the future.
+;; The icon theme for files (basic/material)
;FILE_ICON_THEME = material
;;
+;; The icon theme for folders (basic/material)
+;FOLDER_ICON_THEME = basic
+;;
;; All available reactions users can choose on issues/prs and comments.
;; Values can be emoji alias (:smile:) or a unicode emoji.
;; For custom reactions, add a tightly cropped square image to public/assets/img/emoji/reaction_name.png
@@ -1975,12 +1991,12 @@ LEVEL = Info
;; or a custom avatar source, like: http://cn.gravatar.com/avatar/
;GRAVATAR_SOURCE = gravatar
;;
-;; This value will always be true in offline mode.
+;; Deprecated, see Web UI Admin Panel -> Config -> Settings
;DISABLE_GRAVATAR = false
;;
;; Federated avatar lookup uses DNS to discover avatar associated
;; with emails, see https://www.libravatar.org
-;; This value will always be false in offline mode or when Gravatar is disabled.
+;; Deprecated, see Web UI Admin Panel -> Config -> Settings
;ENABLE_FEDERATED_AVATAR = false
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
@@ -1989,16 +2005,18 @@ LEVEL = Info
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;;
-;; Whether issue and pull request attachments are enabled. Defaults to `true`
+;; Whether issue, pull-request and release attachments are enabled. Defaults to `true`
+;; ALLOWED_TYPES/MAX_SIZE/MAX_FILES in this section only affect issue and pull-request attachments, not release attachments.
+;; Release attachment has its own config options in [repository.release] section.
;ENABLED = true
;;
-;; Comma-separated list of allowed file extensions (`.zip`), mime types (`text/plain`) or wildcard type (`image/*`, `audio/*`, `video/*`). Empty value or `*/*` allows all types.
+;; Comma-separated list of allowed issue/pull-request attachment file extensions (`.zip`), mime types (`text/plain`) or wildcard type (`image/*`, `audio/*`, `video/*`). Empty value or `*/*` allows all types.
;ALLOWED_TYPES = .avif,.cpuprofile,.csv,.dmp,.docx,.fodg,.fodp,.fods,.fodt,.gif,.gz,.jpeg,.jpg,.json,.jsonc,.log,.md,.mov,.mp4,.odf,.odg,.odp,.ods,.odt,.patch,.pdf,.png,.pptx,.svg,.tgz,.txt,.webm,.webp,.xls,.xlsx,.zip
;;
-;; Max size of each file. Defaults to 2048MB
-;MAX_SIZE = 2048
+;; Max size of each issue/pull-request attachment file. Defaults to 100MB
+;MAX_SIZE = 100
;;
-;; Max number of files per upload. Defaults to 5
+;; Max number of issue/pull-request attachment files per upload. Defaults to 5
;MAX_FILES = 5
;;
;; Storage type for attachments, `local` for local disk or `minio` for s3 compatible
@@ -2271,6 +2289,22 @@ LEVEL = Info
;; Unreferenced blobs created more than OLDER_THAN ago are subject to deletion
;OLDER_THAN = 24h
+;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
+;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
+;; Synchronize repository licenses
+;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
+;[cron.sync_repo_licenses]
+;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
+;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
+;; Whether to enable the job
+;ENABLED = false
+;; Whether to always run at least once at start up time (if ENABLED)
+;RUN_AT_START = false
+;; Whether to emit notice on successful execution too
+;NOTICE_ON_SUCCESS = false
+;; Time interval for job to run
+;SCHEDULE = @annually
+
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
@@ -2334,7 +2368,19 @@ LEVEL = Info
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
-;; Resynchronize pre-receive, update and post-receive hooks of all repositories.
+;; Update the '.ssh/authorized_principals' file
+;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
+;[cron.resync_all_sshprincipals]
+;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
+;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
+;ENABLED = false
+;RUN_AT_START = false
+;NOTICE_ON_SUCCESS = false
+;SCHEDULE = @every 72h
+
+;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
+;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
+;; Resynchronize git hooks of all repositories (pre-receive, update, post-receive, proc-receive, ...)
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;[cron.resync_all_hooks]
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
@@ -2440,6 +2486,70 @@ LEVEL = Info
;Check at least this proportion of LFSMetaObjects per repo. (This may cause all stale LFSMetaObjects to be checked.)
;PROPORTION_TO_CHECK_PER_REPO = 0.6
+;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
+;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
+;; Rebuild issue index
+;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
+;[cron.rebuild_issue_indexer]
+;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
+;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
+;ENABLED = false
+;RUN_AT_START = false
+;NO_SUCCESS_NOTICE = false
+;SCHEDULE = @annually
+
+;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
+;; Actions cron tasks
+;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
+
+;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
+;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
+;; Stop running tasks which haven't been updated for a long time
+;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
+;[cron.stop_zombie_tasks]
+;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
+;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
+;ENABLED = true
+;RUN_AT_START = true
+;NO_SUCCESS_NOTICE = false
+;SCHEDULE = @every 5m
+
+;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
+;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
+;; Stop running tasks which have running status and continuous updates but don't end for a long time
+;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
+;[cron.stop_endless_tasks]
+;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
+;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
+;ENABLED = true
+;RUN_AT_START = true
+;NO_SUCCESS_NOTICE = false
+;SCHEDULE = @every 30m
+
+;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
+;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
+;; Cancel jobs which haven't been picked up for a long time
+;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
+;[cron.cancel_abandoned_jobs]
+;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
+;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
+;ENABLED = true
+;RUN_AT_START = false
+;NO_SUCCESS_NOTICE = false
+;SCHEDULE = @every 6h
+
+;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
+;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
+;; Start cron based actions
+;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
+;[cron.start_schedule_tasks]
+;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
+;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
+;ENABLED = true
+;RUN_AT_START = false
+;NO_SUCCESS_NOTICE = false
+;SCHEDULE = @every 1m
+
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;[mirror]
@@ -2488,8 +2598,9 @@ LEVEL = Info
;[highlight.mapping]
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
-;; Extension mapping to highlight class
-;; e.g. .toml=ini
+;; Extension mapping to highlight class, for example:
+;; .toml = ini
+;; .my-js = JavaScript
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
@@ -2692,6 +2803,8 @@ LEVEL = Info
;LIMIT_SIZE_SWIFT = -1
;; Maximum size of a Vagrant upload (`-1` means no limits, format `1000`, `1 MB`, `1 GiB`)
;LIMIT_SIZE_VAGRANT = -1
+;; Maximum size of a Terraform state upload (`-1` means no limits, format `1000`, `1 MB`, `1 GiB`)
+;LIMIT_SIZE_TERRAFORM_STATE = -1
;; Enable RPM re-signing by default. (It will overwrite the old signature ,using v4 format, not compatible with CentOS 6 or older)
;DEFAULT_RPM_SIGN_ENABLED = false
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
@@ -2857,6 +2970,9 @@ LEVEL = Info
;ABANDONED_JOB_TIMEOUT = 24h
;; Strings committers can place inside a commit message or PR title to skip executing the corresponding actions workflow
;SKIP_WORKFLOW_STRINGS = [skip ci],[ci skip],[no ci],[skip actions],[actions skip]
+;; Comma-separated list of workflow directories, the first one to exist
+;; in a repo is used to find Actions workflow files
+;WORKFLOW_DIRS = .gitea/workflows,.github/workflows
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
diff --git a/docker/root/etc/s6/openssh/finish b/docker/root/etc/s6/openssh/finish
index 06bd986563..8e89b35c51 100755
--- a/docker/root/etc/s6/openssh/finish
+++ b/docker/root/etc/s6/openssh/finish
@@ -1,2 +1,8 @@
#!/bin/bash
+# $1 = exit code of the run script, $2 = signal
+if [ "$1" -ne 0 ]; then
+ # avoid immediately restarting the sshd service, which may cause CPU 100% if the error (permission, configuration) is not fixed
+ echo "openssh failed with exit code $1 - waiting a short delay before attempting a restart"
+ sleep 3
+fi
exit 0
diff --git a/docker/root/usr/local/bin/environment-to-ini b/docker/root/usr/local/bin/environment-to-ini
new file mode 100644
index 0000000000..bb0c540685
--- /dev/null
+++ b/docker/root/usr/local/bin/environment-to-ini
@@ -0,0 +1,2 @@
+#!/bin/bash
+exec /app/gitea/gitea config edit-ini --in-place --apply-env "$@"
diff --git a/docker/rootless/usr/local/bin/environment-to-ini b/docker/rootless/usr/local/bin/environment-to-ini
new file mode 100644
index 0000000000..bb0c540685
--- /dev/null
+++ b/docker/rootless/usr/local/bin/environment-to-ini
@@ -0,0 +1,2 @@
+#!/bin/bash
+exec /app/gitea/gitea config edit-ini --in-place --apply-env "$@"
diff --git a/eslint.config.ts b/eslint.config.ts
index 678a49647c..c75f88a5ca 100644
--- a/eslint.config.ts
+++ b/eslint.config.ts
@@ -1,9 +1,9 @@
import arrayFunc from 'eslint-plugin-array-func';
import comments from '@eslint-community/eslint-plugin-eslint-comments';
+import deMorgan from 'eslint-plugin-de-morgan';
import github from 'eslint-plugin-github';
import globals from 'globals';
import importPlugin from 'eslint-plugin-import-x';
-import noUseExtendNative from 'eslint-plugin-no-use-extend-native';
import playwright from 'eslint-plugin-playwright';
import regexp from 'eslint-plugin-regexp';
import sonarjs from 'eslint-plugin-sonarjs';
@@ -16,10 +16,22 @@ import vue from 'eslint-plugin-vue';
import vueScopedCss from 'eslint-plugin-vue-scoped-css';
import wc from 'eslint-plugin-wc';
import {defineConfig, globalIgnores} from 'eslint/config';
+import type {ESLint} from 'eslint';
const jsExts = ['js', 'mjs', 'cjs'] as const;
const tsExts = ['ts', 'mts', 'cts'] as const;
-const restrictedSyntax = ['WithStatement', 'ForInStatement', 'LabeledStatement', 'SequenceExpression'];
+
+const restrictedGlobals = [
+ {name: 'localStorage', message: 'Use `modules/user-settings.ts` instead.'},
+ {name: 'fetch', message: 'Use `modules/fetch.ts` instead.'},
+];
+
+const restrictedProperties = [
+ {object: 'window', property: 'localStorage', message: 'Use `modules/user-settings.ts` instead.'},
+ {object: 'globalThis', property: 'localStorage', message: 'Use `modules/user-settings.ts` instead.'},
+ {object: 'window', property: 'fetch', message: 'Use `modules/fetch.ts` instead.'},
+ {object: 'globalThis', property: 'fetch', message: 'Use `modules/fetch.ts` instead.'},
+];
export default defineConfig([
globalIgnores([
@@ -33,10 +45,6 @@ export default defineConfig([
languageOptions: {
ecmaVersion: 'latest',
sourceType: 'module',
- globals: {
- ...globals.browser,
- ...globals.node,
- },
parser: typescriptParser,
parserOptions: {
sourceType: 'module',
@@ -49,24 +57,19 @@ export default defineConfig([
},
linterOptions: {
reportUnusedDisableDirectives: 2,
+ reportUnusedInlineConfigs: 2,
},
plugins: {
'@eslint-community/eslint-comments': comments,
- // @ts-expect-error
'@stylistic': stylistic,
'@typescript-eslint': typescriptPlugin.plugin,
'array-func': arrayFunc,
- // @ts-expect-error -- https://github.com/un-ts/eslint-plugin-import-x/issues/203
- 'import-x': importPlugin,
- 'no-use-extend-native': noUseExtendNative,
- // @ts-expect-error
+ 'de-morgan': deMorgan,
+ 'import-x': importPlugin as unknown as ESLint.Plugin, // https://github.com/un-ts/eslint-plugin-import-x/issues/203
regexp,
- // @ts-expect-error
sonarjs,
- // @ts-expect-error
unicorn,
github,
- // @ts-expect-error
wc,
},
settings: {
@@ -75,7 +78,7 @@ export default defineConfig([
'import-x/resolver': {'typescript': true},
},
rules: {
- '@eslint-community/eslint-comments/disable-enable-pair': [2],
+ '@eslint-community/eslint-comments/disable-enable-pair': [0],
'@eslint-community/eslint-comments/no-aggregating-enable': [2],
'@eslint-community/eslint-comments/no-duplicate-disable': [2],
'@eslint-community/eslint-comments/no-restricted-disable': [0],
@@ -155,11 +158,11 @@ export default defineConfig([
'@typescript-eslint/adjacent-overload-signatures': [0],
'@typescript-eslint/array-type': [0],
'@typescript-eslint/await-thenable': [2],
- '@typescript-eslint/ban-ts-comment': [2, {'ts-expect-error': false, 'ts-ignore': true, 'ts-nocheck': false, 'ts-check': false}],
+ '@typescript-eslint/ban-ts-comment': [2, {'ts-expect-error': true, 'ts-ignore': true, 'ts-nocheck': false, 'ts-check': false}],
'@typescript-eslint/ban-tslint-comment': [0],
'@typescript-eslint/class-literal-property-style': [0],
'@typescript-eslint/class-methods-use-this': [0],
- '@typescript-eslint/consistent-generic-constructors': [0],
+ '@typescript-eslint/consistent-generic-constructors': [2, 'constructor'],
'@typescript-eslint/consistent-indexed-object-style': [0],
'@typescript-eslint/consistent-return': [0],
'@typescript-eslint/consistent-type-assertions': [2, {assertionStyle: 'as', objectLiteralTypeAssertions: 'allow'}],
@@ -178,7 +181,7 @@ export default defineConfig([
'@typescript-eslint/naming-convention': [0],
'@typescript-eslint/no-array-constructor': [2],
'@typescript-eslint/no-array-delete': [2],
- '@typescript-eslint/no-base-to-string': [0],
+ '@typescript-eslint/no-base-to-string': [2],
'@typescript-eslint/no-confusing-non-null-assertion': [2],
'@typescript-eslint/no-confusing-void-expression': [0],
'@typescript-eslint/no-deprecated': [2],
@@ -210,7 +213,7 @@ export default defineConfig([
'@typescript-eslint/no-non-null-asserted-nullish-coalescing': [0],
'@typescript-eslint/no-non-null-asserted-optional-chain': [2],
'@typescript-eslint/no-non-null-assertion': [0],
- '@typescript-eslint/no-redeclare': [0],
+ '@typescript-eslint/no-redeclare': [2],
'@typescript-eslint/no-redundant-type-constituents': [2],
'@typescript-eslint/no-require-imports': [2],
'@typescript-eslint/no-restricted-imports': [0],
@@ -221,7 +224,7 @@ export default defineConfig([
'@typescript-eslint/no-unnecessary-condition': [0],
'@typescript-eslint/no-unnecessary-qualifier': [0],
'@typescript-eslint/no-unnecessary-template-expression': [0],
- '@typescript-eslint/no-unnecessary-type-arguments': [0],
+ '@typescript-eslint/no-unnecessary-type-arguments': [2],
'@typescript-eslint/no-unnecessary-type-assertion': [2],
'@typescript-eslint/no-unnecessary-type-constraint': [2],
'@typescript-eslint/no-unnecessary-type-conversion': [2],
@@ -234,10 +237,12 @@ export default defineConfig([
'@typescript-eslint/no-unsafe-member-access': [0],
'@typescript-eslint/no-unsafe-return': [0],
'@typescript-eslint/no-unsafe-unary-minus': [2],
- '@typescript-eslint/no-unused-expressions': [0],
+ '@typescript-eslint/no-unused-expressions': [2],
+ '@typescript-eslint/no-unused-private-class-members': [2],
'@typescript-eslint/no-unused-vars': [2, {vars: 'all', args: 'all', caughtErrors: 'all', ignoreRestSiblings: false, argsIgnorePattern: '^_', varsIgnorePattern: '^_', caughtErrorsIgnorePattern: '^_', destructuredArrayIgnorePattern: '^_'}],
'@typescript-eslint/no-use-before-define': [2, {functions: false, classes: true, variables: true, allowNamedExports: true, typedefs: false, enums: false, ignoreTypeReferences: true}],
'@typescript-eslint/no-useless-constructor': [0],
+ '@typescript-eslint/no-useless-default-assignment': [2],
'@typescript-eslint/no-useless-empty-export': [0],
'@typescript-eslint/no-wrapper-object-types': [2],
'@typescript-eslint/non-nullable-type-assertion-style': [0],
@@ -251,10 +256,10 @@ export default defineConfig([
'@typescript-eslint/prefer-function-type': [2],
'@typescript-eslint/prefer-includes': [2],
'@typescript-eslint/prefer-literal-enum-member': [0],
- '@typescript-eslint/prefer-namespace-keyword': [0],
+ '@typescript-eslint/prefer-namespace-keyword': [2],
'@typescript-eslint/prefer-nullish-coalescing': [0],
'@typescript-eslint/prefer-optional-chain': [2, {requireNullish: true}],
- '@typescript-eslint/prefer-promise-reject-errors': [0],
+ '@typescript-eslint/prefer-promise-reject-errors': [2],
'@typescript-eslint/prefer-readonly': [0],
'@typescript-eslint/prefer-readonly-parameter-types': [0],
'@typescript-eslint/prefer-reduce-type-parameter': [0],
@@ -265,9 +270,10 @@ export default defineConfig([
'@typescript-eslint/require-array-sort-compare': [0],
'@typescript-eslint/require-await': [0],
'@typescript-eslint/restrict-plus-operands': [2],
- '@typescript-eslint/restrict-template-expressions': [0],
+ '@typescript-eslint/restrict-template-expressions': [2],
'@typescript-eslint/return-await': [0],
'@typescript-eslint/strict-boolean-expressions': [0],
+ '@typescript-eslint/strict-void-return': [0],
'@typescript-eslint/switch-exhaustiveness-check': [0],
'@typescript-eslint/triple-slash-reference': [2],
'@typescript-eslint/typedef': [0],
@@ -291,6 +297,8 @@ export default defineConfig([
'consistent-this': [0],
'constructor-super': [2],
'curly': [0],
+ 'de-morgan/no-negated-conjunction': [2],
+ 'de-morgan/no-negated-disjunction': [2],
'default-case-last': [2],
'default-case': [0],
'default-param-last': [0],
@@ -321,7 +329,7 @@ export default defineConfig([
'github/no-innerText': [2],
'github/no-then': [2],
'github/no-useless-passive': [2],
- 'github/prefer-observers': [2],
+ 'github/prefer-observers': [0],
'github/require-passive-events': [2],
'github/unescaped-html-literal': [2],
'grouped-accessor-pairs': [2],
@@ -338,7 +346,7 @@ export default defineConfig([
'import-x/first': [2],
'import-x/group-exports': [0],
'import-x/max-dependencies': [0],
- 'import-x/named': [2],
+ 'import-x/named': [0],
'import-x/namespace': [0],
'import-x/newline-after-import': [0],
'import-x/no-absolute-path': [0],
@@ -366,7 +374,7 @@ export default defineConfig([
'import-x/no-self-import': [2],
'import-x/no-unassigned-import': [0],
'import-x/no-unresolved': [2, {commonjs: true, ignore: ['\\?.+$']}],
- // 'import-x/no-unused-modules': [2, {unusedExports: true}], // not compatible with eslint 9
+ 'import-x/no-unused-modules': [0], // incompatible with eslint 9
'import-x/no-useless-path-segments': [2, {commonjs: true}],
'import-x/no-webpack-loader-syntax': [2],
'import-x/order': [0],
@@ -433,7 +441,7 @@ export default defineConfig([
'no-import-assign': [2],
'no-inline-comments': [0],
'no-inner-declarations': [2],
- 'no-invalid-regexp': [2],
+ 'no-invalid-regexp': [0], // handled by regexp/no-invalid-regexp
'no-invalid-this': [0],
'no-irregular-whitespace': [2],
'no-iterator': [2],
@@ -547,7 +555,7 @@ export default defineConfig([
'no-new-func': [0], // handled by @typescript-eslint/no-implied-eval
'no-new-native-nonconstructor': [2],
'no-new-object': [2],
- 'no-new-symbol': [2],
+ 'no-new-symbol': [0], // handled by no-new-native-nonconstructor
'no-new-wrappers': [2],
'no-new': [0],
'no-nonoctal-decimal-escape': [2],
@@ -562,9 +570,14 @@ export default defineConfig([
'no-redeclare': [0], // must be disabled for typescript overloads
'no-regex-spaces': [2],
'no-restricted-exports': [0],
- 'no-restricted-globals': [2, 'addEventListener', 'blur', 'close', 'closed', 'confirm', 'defaultStatus', 'defaultstatus', 'error', 'event', 'external', 'find', 'focus', 'frameElement', 'frames', 'history', 'innerHeight', 'innerWidth', 'isFinite', 'isNaN', 'length', 'locationbar', 'menubar', 'moveBy', 'moveTo', 'name', 'onblur', 'onerror', 'onfocus', 'onload', 'onresize', 'onunload', 'open', 'opener', 'opera', 'outerHeight', 'outerWidth', 'pageXOffset', 'pageYOffset', 'parent', 'print', 'removeEventListener', 'resizeBy', 'resizeTo', 'screen', 'screenLeft', 'screenTop', 'screenX', 'screenY', 'scroll', 'scrollbars', 'scrollBy', 'scrollTo', 'scrollX', 'scrollY', 'status', 'statusbar', 'stop', 'toolbar', 'top'],
- 'no-restricted-imports': [0],
- 'no-restricted-syntax': [2, ...restrictedSyntax, {selector: 'CallExpression[callee.name="fetch"]', message: 'use modules/fetch.ts instead'}],
+ 'no-restricted-globals': [2, ...restrictedGlobals],
+ 'no-restricted-properties': [2, ...restrictedProperties],
+ 'no-restricted-imports': [2, {paths: [
+ {name: 'jquery', message: 'Use the global $ instead', allowTypeImports: true},
+ {name: 'htmx.org', message: 'Use the global htmx instead', allowTypeImports: true},
+ {name: 'idiomorph/htmx', message: 'Loaded in globals.ts', allowTypeImports: true},
+ ]}],
+ 'no-restricted-syntax': [2, 'WithStatement', 'ForInStatement', 'LabeledStatement', 'SequenceExpression'],
'no-return-assign': [0],
'no-script-url': [2],
'no-self-assign': [2, {props: true}],
@@ -577,10 +590,11 @@ export default defineConfig([
'no-template-curly-in-string': [2],
'no-ternary': [0],
'no-this-before-super': [2],
- 'no-throw-literal': [2],
+ 'no-throw-literal': [0], // handled by @typescript-eslint/only-throw-error
'no-undef-init': [2],
'no-undef': [2], // it is still needed by eslint & IDE to prompt undefined names in real time
'no-undefined': [0],
+ 'no-unassigned-vars': [2],
'no-underscore-dangle': [0],
'no-unexpected-multiline': [2],
'no-unmodified-loop-condition': [2],
@@ -589,13 +603,13 @@ export default defineConfig([
'no-unreachable': [2],
'no-unsafe-finally': [2],
'no-unsafe-negation': [2],
- 'no-unused-expressions': [2],
+ 'no-unused-expressions': [0], // handled by @typescript-eslint/no-unused-expressions
'no-unused-labels': [2],
- 'no-unused-private-class-members': [2],
+ 'no-unused-private-class-members': [0], // handled by @typescript-eslint/no-unused-private-class-members
'no-unused-vars': [0], // handled by @typescript-eslint/no-unused-vars
'no-use-before-define': [0], // handled by @typescript-eslint/no-use-before-define
- 'no-use-extend-native/no-use-extend-native': [2],
- 'no-useless-backreference': [2],
+ 'no-useless-assignment': [2],
+ 'no-useless-backreference': [0], // handled by regexp/no-useless-backreference
'no-useless-call': [2],
'no-useless-catch': [2],
'no-useless-computed-key': [2],
@@ -603,7 +617,7 @@ export default defineConfig([
'no-useless-constructor': [2],
'no-useless-escape': [2],
'no-useless-rename': [2],
- 'no-useless-return': [2],
+ 'no-useless-return': [0], // handled by sonarjs/no-redundant-jump
'no-var': [2],
'no-void': [2],
'no-warning-comments': [0],
@@ -612,7 +626,7 @@ export default defineConfig([
'one-var-declaration-per-line': [0],
'one-var': [0],
'operator-assignment': [2, 'always'],
- 'operator-linebreak': [2, 'after'],
+ 'operator-linebreak': [0], // handled by @stylistic/operator-linebreak
'prefer-arrow-callback': [2, {allowNamedFunctions: true, allowUnboundThis: true}],
'prefer-const': [2, {destructuring: 'all', ignoreReadBeforeAssign: true}],
'prefer-destructuring': [0],
@@ -621,19 +635,20 @@ export default defineConfig([
'prefer-numeric-literals': [2],
'prefer-object-has-own': [2],
'prefer-object-spread': [2],
- 'prefer-promise-reject-errors': [2, {allowEmptyReject: false}],
+ 'prefer-promise-reject-errors': [0], // handled by @typescript-eslint/prefer-promise-reject-errors
'prefer-regex-literals': [2],
'prefer-rest-params': [2],
'prefer-spread': [2],
'prefer-template': [2],
- 'radix': [2, 'as-needed'],
+ 'preserve-caught-error': [0],
+ 'radix': [0],
'regexp/confusing-quantifier': [2],
'regexp/control-character-escape': [2],
'regexp/hexadecimal-escape': [0],
'regexp/letter-case': [0],
'regexp/match-any': [2],
'regexp/negation': [2],
- 'regexp/no-contradiction-with-assertion': [0],
+ 'regexp/no-contradiction-with-assertion': [2],
'regexp/no-control-character': [0],
'regexp/no-dupe-characters-character-class': [2],
'regexp/no-dupe-disjunctions': [2],
@@ -649,8 +664,8 @@ export default defineConfig([
'regexp/no-invisible-character': [2],
'regexp/no-lazy-ends': [2],
'regexp/no-legacy-features': [2],
- 'regexp/no-misleading-capturing-group': [0],
- 'regexp/no-misleading-unicode-character': [0],
+ 'regexp/no-misleading-capturing-group': [2],
+ 'regexp/no-misleading-unicode-character': [2],
'regexp/no-missing-g-flag': [2],
'regexp/no-non-standard-flag': [2],
'regexp/no-obscure-range': [2],
@@ -692,7 +707,7 @@ export default defineConfig([
'regexp/prefer-question-quantifier': [2],
'regexp/prefer-range': [2],
'regexp/prefer-regexp-exec': [2],
- 'regexp/prefer-regexp-test': [2],
+ 'regexp/prefer-regexp-test': [0], // handled by unicorn/prefer-regexp-test
'regexp/prefer-result-array-groups': [0],
'regexp/prefer-set-operation': [2],
'regexp/prefer-star-quantifier': [2],
@@ -722,7 +737,7 @@ export default defineConfig([
'sonarjs/no-empty-collection': [2],
'sonarjs/no-extra-arguments': [2],
'sonarjs/no-gratuitous-expressions': [2],
- 'sonarjs/no-identical-conditions': [2],
+ 'sonarjs/no-identical-conditions': [0], // handled by no-dupe-else-if
'sonarjs/no-identical-expressions': [2],
'sonarjs/no-identical-functions': [2, 5],
'sonarjs/no-ignored-return': [2],
@@ -735,7 +750,7 @@ export default defineConfig([
'sonarjs/no-small-switch': [0],
'sonarjs/no-unused-collection': [2],
'sonarjs/no-use-of-empty-return-value': [2],
- 'sonarjs/no-useless-catch': [2],
+ 'sonarjs/no-useless-catch': [0], // handled by no-useless-catch
'sonarjs/non-existent-operator': [2],
'sonarjs/prefer-immediate-return': [0],
'sonarjs/prefer-object-literal': [0],
@@ -751,6 +766,7 @@ export default defineConfig([
'unicorn/catch-error-name': [0],
'unicorn/consistent-destructuring': [2],
'unicorn/consistent-empty-array-spread': [2],
+ 'unicorn/consistent-template-literal-escape': [2],
'unicorn/consistent-existence-index-check': [0],
'unicorn/consistent-function-scoping': [0],
'unicorn/custom-error-definition': [0],
@@ -762,6 +778,7 @@ export default defineConfig([
'unicorn/filename-case': [0],
'unicorn/import-index': [0],
'unicorn/import-style': [0],
+ 'unicorn/isolated-functions': [2, {functions: []}],
'unicorn/new-for-builtins': [2],
'unicorn/no-abusive-eslint-disable': [0],
'unicorn/no-anonymous-default-export': [0],
@@ -777,6 +794,7 @@ export default defineConfig([
'unicorn/no-empty-file': [2],
'unicorn/no-for-loop': [0],
'unicorn/no-hex-escape': [0],
+ 'unicorn/no-immediate-mutation': [0],
'unicorn/no-instanceof-array': [0],
'unicorn/no-invalid-fetch-options': [2],
'unicorn/no-invalid-remove-event-listener': [2],
@@ -800,9 +818,11 @@ export default defineConfig([
'unicorn/no-unnecessary-await': [2],
'unicorn/no-unnecessary-polyfills': [2],
'unicorn/no-unreadable-array-destructuring': [0],
- 'unicorn/no-unreadable-iife': [2],
+ 'unicorn/no-unreadable-iife': [0],
'unicorn/no-unused-properties': [2],
+ 'unicorn/no-useless-collection-argument': [2],
'unicorn/no-useless-fallback-in-spread': [2],
+ 'unicorn/no-useless-iterator-to-array': [2],
'unicorn/no-useless-length-check': [2],
'unicorn/no-useless-promise-resolve-reject': [2],
'unicorn/no-useless-spread': [2],
@@ -812,9 +832,9 @@ export default defineConfig([
'unicorn/number-literal-case': [0],
'unicorn/numeric-separators-style': [0],
'unicorn/prefer-add-event-listener': [2],
- 'unicorn/prefer-array-find': [2],
- 'unicorn/prefer-array-flat-map': [2],
+ 'unicorn/prefer-array-find': [0], // handled by @typescript-eslint/prefer-find
'unicorn/prefer-array-flat': [2],
+ 'unicorn/prefer-array-flat-map': [2],
'unicorn/prefer-array-index-of': [2],
'unicorn/prefer-array-some': [2],
'unicorn/prefer-at': [0],
@@ -829,7 +849,7 @@ export default defineConfig([
'unicorn/prefer-event-target': [2],
'unicorn/prefer-export-from': [0],
'unicorn/prefer-global-this': [0],
- 'unicorn/prefer-includes': [2],
+ 'unicorn/prefer-includes': [0], // handled by @typescript-eslint/prefer-includes
'unicorn/prefer-json-parse-buffer': [0],
'unicorn/prefer-keyboard-event-key': [2],
'unicorn/prefer-logical-operator-over-ternary': [2],
@@ -849,13 +869,15 @@ export default defineConfig([
'unicorn/prefer-query-selector': [2],
'unicorn/prefer-reflect-apply': [0],
'unicorn/prefer-regexp-test': [2],
+ 'unicorn/prefer-response-static-json': [2],
'unicorn/prefer-set-has': [0],
'unicorn/prefer-set-size': [2],
+ 'unicorn/prefer-simple-condition-first': [0],
'unicorn/prefer-spread': [0],
'unicorn/prefer-string-raw': [0],
'unicorn/prefer-string-replace-all': [0],
'unicorn/prefer-string-slice': [0],
- 'unicorn/prefer-string-starts-ends-with': [2],
+ 'unicorn/prefer-string-starts-ends-with': [0], // handled by @typescript-eslint/prefer-string-starts-ends-with
'unicorn/prefer-string-trim-start-end': [2],
'unicorn/prefer-structured-clone': [2],
'unicorn/prefer-switch': [0],
@@ -869,6 +891,7 @@ export default defineConfig([
'unicorn/require-post-message-target-origin': [0],
'unicorn/string-content': [0],
'unicorn/switch-case-braces': [0],
+ 'unicorn/switch-case-break-position': [2],
'unicorn/template-indent': [2],
'unicorn/text-encoding-identifier-case': [0],
'unicorn/throw-new-error': [2],
@@ -900,12 +923,13 @@ export default defineConfig([
'yoda': [2, 'never'],
},
},
- // @ts-expect-error
{
...playwright.configs['flat/recommended'],
- files: ['tests/e2e/**'],
+ files: ['tests/e2e/**/*.test.ts'],
+ languageOptions: {globals: {...globals.nodeBuiltin, ...globals.browser}},
rules: {
...playwright.configs['flat/recommended'].rules,
+ 'playwright/expect-expect': [0],
},
},
{
@@ -916,27 +940,19 @@ export default defineConfig([
},
},
extends: [
- // @ts-expect-error
vue.configs['flat/recommended'],
- // @ts-expect-error
- vueScopedCss.configs['flat/recommended'],
+ vueScopedCss.configs.recommended as any,
],
rules: {
'vue/attributes-order': [0],
'vue/html-closing-bracket-spacing': [2, {startTag: 'never', endTag: 'never', selfClosingTag: 'never'}],
'vue/max-attributes-per-line': [0],
'vue/singleline-html-element-content-newline': [0],
- },
- },
- {
- files: ['web_src/js/modules/fetch.ts', 'web_src/js/standalone/**/*'],
- rules: {
- 'no-restricted-syntax': [2, ...restrictedSyntax],
+ 'vue/require-typed-ref': [2],
},
},
{
files: ['**/*.test.ts', 'web_src/js/test/setup.ts'],
- // @ts-expect-error - https://github.com/vitest-dev/eslint-plugin-vitest/issues/737
plugins: {vitest},
languageOptions: {globals: globals.vitest},
rules: {
@@ -960,6 +976,7 @@ export default defineConfig([
'vitest/no-interpolation-in-snapshots': [0],
'vitest/no-large-snapshots': [0],
'vitest/no-mocks-import': [0],
+ 'vitest/no-importing-vitest-globals': [2],
'vitest/no-restricted-matchers': [0],
'vitest/no-restricted-vi-methods': [0],
'vitest/no-standalone-expect': [0],
@@ -988,42 +1005,24 @@ export default defineConfig([
'vitest/require-to-throw-message': [0],
'vitest/require-top-level-describe': [0],
'vitest/valid-describe-callback': [2],
- 'vitest/valid-expect': [2],
+ 'vitest/valid-expect': [2, {maxArgs: 2}],
+ 'vitest/valid-expect-in-promise': [2],
'vitest/valid-title': [2],
},
},
- {
- files: ['web_src/js/types.ts'],
- rules: {
- 'import-x/no-unused-modules': [0],
- },
- },
{
files: ['**/*.d.ts'],
rules: {
- 'import-x/no-unused-modules': [0],
'@typescript-eslint/consistent-type-definitions': [0],
'@typescript-eslint/consistent-type-imports': [0],
},
},
{
- files: ['*.config.*'],
- rules: {
- 'import-x/no-unused-modules': [0],
- },
- },
- {
- files: ['web_src/**/*', 'docs/**/*'],
- languageOptions: {globals: globals.browser},
+ files: ['*', 'tools/**/*', 'tests/**/*'],
+ languageOptions: {globals: globals.nodeBuiltin},
},
{
files: ['web_src/**/*'],
- languageOptions: {
- globals: {
- ...globals.browser,
- __webpack_public_path__: true,
- process: false, // https://github.com/webpack/webpack/issues/15833
- },
- },
+ languageOptions: {globals: {...globals.browser, ...globals.jquery, htmx: false}},
},
]);
diff --git a/eslint.json.config.ts b/eslint.json.config.ts
new file mode 100644
index 0000000000..45696fb79c
--- /dev/null
+++ b/eslint.json.config.ts
@@ -0,0 +1,30 @@
+import {defineConfig, globalIgnores} from 'eslint/config';
+import json from '@eslint/json';
+
+export default defineConfig([
+ globalIgnores([
+ '**/.venv',
+ '**/node_modules',
+ '**/public',
+ ]),
+ {
+ files: ['**/*.json'],
+ plugins: {json},
+ language: 'json/json',
+ extends: ['json/recommended'],
+ },
+ {
+ files: [
+ 'tsconfig.json',
+ '.devcontainer/*.json',
+ '.vscode/*.json',
+ 'contrib/ide/vscode/*.json',
+ ],
+ plugins: {json},
+ language: 'json/jsonc',
+ languageOptions: {
+ allowTrailingCommas: true,
+ },
+ extends: ['json/recommended'],
+ },
+]);
diff --git a/flake.lock b/flake.lock
index 16a487ba13..25ce7939b3 100644
--- a/flake.lock
+++ b/flake.lock
@@ -1,30 +1,12 @@
{
"nodes": {
- "flake-utils": {
- "inputs": {
- "systems": "systems"
- },
- "locked": {
- "lastModified": 1731533236,
- "narHash": "sha256-l0KFg5HjrsfsO/JpG+r7fRrqm12kzFHyUHqHCVpMMbI=",
- "owner": "numtide",
- "repo": "flake-utils",
- "rev": "11707dc2f618dd54ca8739b309ec4fc024de578b",
- "type": "github"
- },
- "original": {
- "owner": "numtide",
- "repo": "flake-utils",
- "type": "github"
- }
- },
"nixpkgs": {
"locked": {
- "lastModified": 1755186698,
- "narHash": "sha256-wNO3+Ks2jZJ4nTHMuks+cxAiVBGNuEBXsT29Bz6HASo=",
+ "lastModified": 1775036866,
+ "narHash": "sha256-ZojAnPuCdy657PbTq5V0Y+AHKhZAIwSIT2cb8UgAz/U=",
"owner": "nixos",
"repo": "nixpkgs",
- "rev": "fbcf476f790d8a217c3eab4e12033dc4a0f6d23c",
+ "rev": "6201e203d09599479a3b3450ed24fa81537ebc4e",
"type": "github"
},
"original": {
@@ -36,24 +18,8 @@
},
"root": {
"inputs": {
- "flake-utils": "flake-utils",
"nixpkgs": "nixpkgs"
}
- },
- "systems": {
- "locked": {
- "lastModified": 1681028828,
- "narHash": "sha256-Vy1rq5AaRuLzOxct8nz4T6wlgyUR7zLU309k9mBC768=",
- "owner": "nix-systems",
- "repo": "default",
- "rev": "da67096a3b9bf56a91d16901293e51ba5b49a27e",
- "type": "github"
- },
- "original": {
- "owner": "nix-systems",
- "repo": "default",
- "type": "github"
- }
}
},
"root": "root",
diff --git a/flake.nix b/flake.nix
index 588f608ffc..7b9fbb193c 100644
--- a/flake.nix
+++ b/flake.nix
@@ -1,73 +1,94 @@
{
inputs = {
nixpkgs.url = "github:nixos/nixpkgs?ref=nixos-unstable";
- flake-utils.url = "github:numtide/flake-utils";
};
outputs =
- { nixpkgs, flake-utils, ... }:
- flake-utils.lib.eachDefaultSystem (
- system:
- let
- pkgs = nixpkgs.legacyPackages.${system};
- in
- {
- devShells.default =
- with pkgs;
- let
- # only bump toolchain versions here
- go = go_1_25;
- nodejs = nodejs_24;
- python3 = python312;
- pnpm = pnpm_10;
-
- # Platform-specific dependencies
- linuxOnlyInputs = lib.optionals pkgs.stdenv.isLinux [
- glibc.static
- ];
+ { nixpkgs, ... }:
+ let
+ supportedSystems = [
+ "aarch64-darwin"
+ "aarch64-linux"
+ "x86_64-darwin"
+ "x86_64-linux"
+ ];
- linuxOnlyEnv = lib.optionalAttrs pkgs.stdenv.isLinux {
- CFLAGS = "-I${glibc.static.dev}/include";
- LDFLAGS = "-L ${glibc.static}/lib";
+ forEachSupportedSystem =
+ f:
+ nixpkgs.lib.genAttrs supportedSystems (
+ system:
+ let
+ pkgs = import nixpkgs {
+ inherit system;
};
in
- pkgs.mkShell (
- {
- buildInputs = [
- # generic
- git
- git-lfs
- gnumake
- gnused
- gnutar
- gzip
- zip
+ f { inherit pkgs; }
+ );
+ in
+ {
+ devShells = forEachSupportedSystem (
+ { pkgs, ... }:
+ {
+ default =
+ let
+ inherit (pkgs) lib;
+
+ # only bump toolchain versions here
+ go = pkgs.go_1_26;
+ nodejs = pkgs.nodejs_24;
+ python3 = pkgs.python314;
+ pnpm = pkgs.pnpm_10;
- # frontend
- nodejs
- pnpm
- cairo
- pixman
- pkg-config
+ # Platform-specific dependencies
+ linuxOnlyInputs = lib.optionals pkgs.stdenv.isLinux [
+ pkgs.glibc.static
+ ];
- # linting
- python3
- uv
+ linuxOnlyEnv = lib.optionalAttrs pkgs.stdenv.isLinux {
+ CFLAGS = "-I${pkgs.glibc.static.dev}/include";
+ LDFLAGS = "-L ${pkgs.glibc.static}/lib";
+ };
+ in
+ pkgs.mkShell {
+ packages =
+ with pkgs;
+ [
+ # generic
+ git
+ git-lfs
+ gnumake
+ gnused
+ gnutar
+ gzip
+ zip
- # backend
- go
- gofumpt
- sqlite
- ]
- ++ linuxOnlyInputs;
+ # frontend
+ nodejs
+ pnpm
+ cairo
+ pixman
+ pkg-config
- GO = "${go}/bin/go";
- GOROOT = "${go}/share/go";
+ # linting
+ python3
+ uv
- TAGS = "sqlite sqlite_unlock_notify";
- STATIC = "true";
- }
- // linuxOnlyEnv
- );
- }
- );
+ # backend
+ go
+ gofumpt
+ sqlite
+ ]
+ ++ linuxOnlyInputs;
+
+ env = {
+ GO = "${go}/bin/go";
+ GOROOT = "${go}/share/go";
+
+ TAGS = "sqlite sqlite_unlock_notify";
+ STATIC = "true";
+ }
+ // linuxOnlyEnv;
+ };
+ }
+ );
+ };
}
diff --git a/main.go b/main.go
index 2c25bac4e3..fcfbb73371 100644
--- a/main.go
+++ b/main.go
@@ -26,9 +26,8 @@ import (
// these flags will be set by the build flags
var (
- Version = "development" // program version for this build
- Tags = "" // the Golang build tags
- MakeVersion = "" // "make" program version if built with make
+ Version = "development" // program version for this build
+ Tags = "" // the Golang build tags
)
func init() {
@@ -44,14 +43,12 @@ func main() {
}
app := cmd.NewMainApp(cmd.AppVersion{Version: Version, Extra: formatBuiltWith()})
_ = cmd.RunMainApp(app, os.Args...) // all errors should have been handled by the RunMainApp
+ // flush the queued logs before exiting, it is a MUST, otherwise there will be log loss
log.GetManager().Close()
}
func formatBuiltWith() string {
version := runtime.Version()
- if len(MakeVersion) > 0 {
- version = MakeVersion + ", " + runtime.Version()
- }
if len(Tags) == 0 {
return " built with " + version
}
diff --git a/models/actions/artifact.go b/models/actions/artifact.go
index 757bd13acd..d61afb2aed 100644
--- a/models/actions/artifact.go
+++ b/models/actions/artifact.go
@@ -53,6 +53,11 @@ func init() {
db.RegisterModel(new(ActionArtifact))
}
+const (
+ ContentEncodingV3Gzip = "gzip"
+ ContentTypeZip = "application/zip"
+)
+
// ActionArtifact is a file that is stored in the artifact storage.
type ActionArtifact struct {
ID int64 `xorm:"pk autoincr"`
@@ -61,16 +66,26 @@ type ActionArtifact struct {
RepoID int64 `xorm:"index"`
OwnerID int64
CommitSHA string
- StoragePath string // The path to the artifact in the storage
- FileSize int64 // The size of the artifact in bytes
- FileCompressedSize int64 // The size of the artifact in bytes after gzip compression
- ContentEncoding string // The content encoding of the artifact
- ArtifactPath string `xorm:"index unique(runid_name_path)"` // The path to the artifact when runner uploads it
- ArtifactName string `xorm:"index unique(runid_name_path)"` // The name of the artifact when runner uploads it
- Status ArtifactStatus `xorm:"index"` // The status of the artifact, uploading, expired or need-delete
- CreatedUnix timeutil.TimeStamp `xorm:"created"`
- UpdatedUnix timeutil.TimeStamp `xorm:"updated index"`
- ExpiredUnix timeutil.TimeStamp `xorm:"index"` // The time when the artifact will be expired
+ StoragePath string // The path to the artifact in the storage
+ FileSize int64 // The size of the artifact in bytes
+ FileCompressedSize int64 // The size of the artifact in bytes after gzip compression
+
+ // The content encoding or content type of the artifact
+ // * empty or null: legacy (v3) uncompressed content
+ // * magic string "gzip" (ContentEncodingV3Gzip): v3 gzip compressed content
+ // * requires gzip decoding before storing in a zip for download
+ // * requires gzip content-encoding header when downloaded single files within a workflow
+ // * mime type for "Content-Type":
+ // * "application/zip" (ContentTypeZip), seems to be an abuse, fortunately there is no conflict, and it won't cause problems?
+ // * "application/pdf", "text/html", etc.: real content type of the artifact
+ ContentEncodingOrType string `xorm:"content_encoding"`
+
+ ArtifactPath string `xorm:"index unique(runid_name_path)"` // The path to the artifact when runner uploads it
+ ArtifactName string `xorm:"index unique(runid_name_path)"` // The name of the artifact when runner uploads it
+ Status ArtifactStatus `xorm:"index"` // The status of the artifact, uploading, expired or need-delete
+ CreatedUnix timeutil.TimeStamp `xorm:"created"`
+ UpdatedUnix timeutil.TimeStamp `xorm:"updated index"`
+ ExpiredUnix timeutil.TimeStamp `xorm:"index"` // The time when the artifact will be expired
}
func CreateArtifact(ctx context.Context, t *ActionTask, artifactName, artifactPath string, expiredDays int64) (*ActionArtifact, error) {
@@ -156,7 +171,8 @@ func (opts FindArtifactsOptions) ToConds() builder.Cond {
}
if opts.FinalizedArtifactsV4 {
cond = cond.And(builder.Eq{"status": ArtifactStatusUploadConfirmed}.Or(builder.Eq{"status": ArtifactStatusExpired}))
- cond = cond.And(builder.Eq{"content_encoding": "application/zip"})
+ // see the comment of ActionArtifact.ContentEncodingOrType: "*/*" means the field is a content type
+ cond = cond.And(builder.Like{"content_encoding", "%/%"})
}
return cond
@@ -170,10 +186,10 @@ type ActionArtifactMeta struct {
}
// ListUploadedArtifactsMeta returns all uploaded artifacts meta of a run
-func ListUploadedArtifactsMeta(ctx context.Context, runID int64) ([]*ActionArtifactMeta, error) {
+func ListUploadedArtifactsMeta(ctx context.Context, repoID, runID int64) ([]*ActionArtifactMeta, error) {
arts := make([]*ActionArtifactMeta, 0, 10)
return arts, db.GetEngine(ctx).Table("action_artifact").
- Where("run_id=? AND (status=? OR status=?)", runID, ArtifactStatusUploadConfirmed, ArtifactStatusExpired).
+ Where("repo_id=? AND run_id=? AND (status=? OR status=?)", repoID, runID, ArtifactStatusUploadConfirmed, ArtifactStatusExpired).
GroupBy("artifact_name").
Select("artifact_name, sum(file_size) as file_size, max(status) as status").
Find(&arts)
diff --git a/models/actions/config.go b/models/actions/config.go
new file mode 100644
index 0000000000..4f5357c560
--- /dev/null
+++ b/models/actions/config.go
@@ -0,0 +1,74 @@
+// Copyright 2026 The Gitea Authors. All rights reserved.
+// SPDX-License-Identifier: MIT
+
+package actions
+
+import (
+ "context"
+
+ "code.gitea.io/gitea/models/perm"
+ repo_model "code.gitea.io/gitea/models/repo"
+ user_model "code.gitea.io/gitea/models/user"
+ "code.gitea.io/gitea/modules/json"
+ "code.gitea.io/gitea/modules/util"
+
+ "xorm.io/xorm/convert"
+)
+
+// OwnerActionsConfig defines the Actions configuration for a user or organization
+type OwnerActionsConfig struct {
+ // TokenPermissionMode defines the default permission mode (permissive, restricted)
+ TokenPermissionMode repo_model.ActionsTokenPermissionMode `json:"token_permission_mode,omitempty"`
+
+ // MaxTokenPermissions defines the absolute maximum permissions any token can have in this context.
+ MaxTokenPermissions *repo_model.ActionsTokenPermissions `json:"max_token_permissions,omitempty"`
+
+ // AllowedCrossRepoIDs is a list of specific repo IDs that can be accessed cross-repo
+ AllowedCrossRepoIDs []int64 `json:"allowed_cross_repo_ids,omitempty"`
+}
+
+var _ convert.ConversionFrom = (*OwnerActionsConfig)(nil)
+
+func (cfg *OwnerActionsConfig) FromDB(bytes []byte) error {
+ _ = json.Unmarshal(bytes, cfg)
+ cfg.TokenPermissionMode, _ = util.EnumValue(cfg.TokenPermissionMode)
+ return nil
+}
+
+// GetOwnerActionsConfig loads the OwnerActionsConfig for a user or organization from user settings
+// It returns a default config if no setting is found
+func GetOwnerActionsConfig(ctx context.Context, userID int64) (ret OwnerActionsConfig, err error) {
+ return user_model.GetUserSettingJSON(ctx, userID, user_model.SettingsKeyActionsConfig, ret)
+}
+
+// SetOwnerActionsConfig saves the OwnerActionsConfig for a user or organization to user settings
+func SetOwnerActionsConfig(ctx context.Context, userID int64, cfg OwnerActionsConfig) error {
+ return user_model.SetUserSettingJSON(ctx, userID, user_model.SettingsKeyActionsConfig, cfg)
+}
+
+// GetDefaultTokenPermissions returns the default token permissions by its TokenPermissionMode.
+func (cfg *OwnerActionsConfig) GetDefaultTokenPermissions() repo_model.ActionsTokenPermissions {
+ switch cfg.TokenPermissionMode {
+ case repo_model.ActionsTokenPermissionModeRestricted:
+ return repo_model.MakeRestrictedPermissions()
+ case repo_model.ActionsTokenPermissionModePermissive:
+ return repo_model.MakeActionsTokenPermissions(perm.AccessModeWrite)
+ default:
+ return repo_model.MakeActionsTokenPermissions(perm.AccessModeNone)
+ }
+}
+
+// GetMaxTokenPermissions returns the maximum allowed permissions
+func (cfg *OwnerActionsConfig) GetMaxTokenPermissions() repo_model.ActionsTokenPermissions {
+ if cfg.MaxTokenPermissions != nil {
+ return *cfg.MaxTokenPermissions
+ }
+ // Default max is write for everything
+ return repo_model.MakeActionsTokenPermissions(perm.AccessModeWrite)
+}
+
+// ClampPermissions ensures that the given permissions don't exceed the maximum
+func (cfg *OwnerActionsConfig) ClampPermissions(perms repo_model.ActionsTokenPermissions) repo_model.ActionsTokenPermissions {
+ maxPerms := cfg.GetMaxTokenPermissions()
+ return repo_model.ClampActionsTokenPermissions(perms, maxPerms)
+}
diff --git a/models/actions/run_job.go b/models/actions/run_job.go
index e7fa21270c..d1e5d1e938 100644
--- a/models/actions/run_job.go
+++ b/models/actions/run_job.go
@@ -11,34 +11,60 @@ import (
"code.gitea.io/gitea/models/db"
repo_model "code.gitea.io/gitea/models/repo"
+ "code.gitea.io/gitea/modules/actions/jobparser"
"code.gitea.io/gitea/modules/timeutil"
"code.gitea.io/gitea/modules/util"
"xorm.io/builder"
)
+// MaxJobNumPerRun is the maximum number of jobs in a single run.
+// https://docs.github.com/en/actions/reference/limits#existing-system-limits
+// TODO: check this limit when creating jobs
+const MaxJobNumPerRun = 256
+
// ActionRunJob represents a job of a run
type ActionRunJob struct {
ID int64
RunID int64 `xorm:"index"`
Run *ActionRun `xorm:"-"`
- RepoID int64 `xorm:"index"`
+ RepoID int64 `xorm:"index(repo_concurrency)"`
Repo *repo_model.Repository `xorm:"-"`
OwnerID int64 `xorm:"index"`
CommitSHA string `xorm:"index"`
IsForkPullRequest bool
Name string `xorm:"VARCHAR(255)"`
Attempt int64
- WorkflowPayload []byte
- JobID string `xorm:"VARCHAR(255)"` // job id in workflow, not job's id
- Needs []string `xorm:"JSON TEXT"`
- RunsOn []string `xorm:"JSON TEXT"`
- TaskID int64 // the latest task of the job
- Status Status `xorm:"index"`
- Started timeutil.TimeStamp
- Stopped timeutil.TimeStamp
- Created timeutil.TimeStamp `xorm:"created"`
- Updated timeutil.TimeStamp `xorm:"updated index"`
+
+ // WorkflowPayload is act/jobparser.SingleWorkflow for act/jobparser.Parse
+ // it should contain exactly one job with global workflow fields for this model
+ WorkflowPayload []byte
+
+ JobID string `xorm:"VARCHAR(255)"` // job id in workflow, not job's id
+ Needs []string `xorm:"JSON TEXT"`
+ RunsOn []string `xorm:"JSON TEXT"`
+ TaskID int64 // the latest task of the job
+ Status Status `xorm:"index"`
+
+ RawConcurrency string // raw concurrency from job YAML's "concurrency" section
+
+ // IsConcurrencyEvaluated is only valid/needed when this job's RawConcurrency is not empty.
+ // If RawConcurrency can't be evaluated (e.g. depend on other job's outputs or have errors), this field will be false.
+ // If RawConcurrency has been successfully evaluated, this field will be true, ConcurrencyGroup and ConcurrencyCancel are also set.
+ IsConcurrencyEvaluated bool
+
+ ConcurrencyGroup string `xorm:"index(repo_concurrency) NOT NULL DEFAULT ''"` // evaluated concurrency.group
+ ConcurrencyCancel bool `xorm:"NOT NULL DEFAULT FALSE"` // evaluated concurrency.cancel-in-progress
+
+ // TokenPermissions stores the explicit permissions from workflow/job YAML (no org/repo clamps applied).
+ // Org/repo clamps are enforced when the token is used at runtime.
+ // It is JSON-encoded repo_model.ActionsTokenPermissions and may be empty if not specified.
+ TokenPermissions *repo_model.ActionsTokenPermissions `xorm:"JSON TEXT"`
+
+ Started timeutil.TimeStamp
+ Stopped timeutil.TimeStamp
+ Created timeutil.TimeStamp `xorm:"created"`
+ Updated timeutil.TimeStamp `xorm:"updated index"`
}
func init() {
@@ -46,7 +72,7 @@ func init() {
}
func (job *ActionRunJob) Duration() time.Duration {
- return calculateDuration(job.Started, job.Stopped, job.Status)
+ return calculateDuration(job.Started, job.Stopped, job.Status, job.Updated)
}
func (job *ActionRunJob) LoadRun(ctx context.Context) error {
@@ -84,13 +110,43 @@ func (job *ActionRunJob) LoadAttributes(ctx context.Context) error {
return job.Run.LoadAttributes(ctx)
}
-func GetRunJobByID(ctx context.Context, id int64) (*ActionRunJob, error) {
+// ParseJob parses the job structure from the ActionRunJob.WorkflowPayload
+func (job *ActionRunJob) ParseJob() (*jobparser.Job, error) {
+ // job.WorkflowPayload is a SingleWorkflow created from an ActionRun's workflow, which exactly contains this job's YAML definition.
+ // Ideally it shouldn't be called "Workflow", it is just a job with global workflow fields + trigger
+ parsedWorkflows, err := jobparser.Parse(job.WorkflowPayload)
+ if err != nil {
+ return nil, fmt.Errorf("job %d single workflow: unable to parse: %w", job.ID, err)
+ } else if len(parsedWorkflows) != 1 {
+ return nil, fmt.Errorf("job %d single workflow: not single workflow", job.ID)
+ }
+ _, workflowJob := parsedWorkflows[0].Job()
+ if workflowJob == nil {
+ // it shouldn't happen, and since the callers don't check nil, so return an error instead of nil
+ return nil, util.ErrorWrap(util.ErrNotExist, "job %d single workflow: payload doesn't contain a job", job.ID)
+ }
+ return workflowJob, nil
+}
+
+func GetRunJobByRepoAndID(ctx context.Context, repoID, jobID int64) (*ActionRunJob, error) {
+ var job ActionRunJob
+ has, err := db.GetEngine(ctx).Where("id=? AND repo_id=?", jobID, repoID).Get(&job)
+ if err != nil {
+ return nil, err
+ } else if !has {
+ return nil, fmt.Errorf("run job with id %d: %w", jobID, util.ErrNotExist)
+ }
+
+ return &job, nil
+}
+
+func GetRunJobByRunAndID(ctx context.Context, runID, jobID int64) (*ActionRunJob, error) {
var job ActionRunJob
- has, err := db.GetEngine(ctx).Where("id=?", id).Get(&job)
+ has, err := db.GetEngine(ctx).Where("id=? AND run_id=?", jobID, runID).Get(&job)
if err != nil {
return nil, err
} else if !has {
- return nil, fmt.Errorf("run job with id %d: %w", id, util.ErrNotExist)
+ return nil, fmt.Errorf("run job with id %d: %w", jobID, util.ErrNotExist)
}
return &job, nil
@@ -125,7 +181,7 @@ func UpdateRunJob(ctx context.Context, job *ActionRunJob, cond builder.Cond, col
return affected, nil
}
- if affected != 0 && slices.Contains(cols, "status") && job.Status.IsWaiting() {
+ if slices.Contains(cols, "status") && job.Status.IsWaiting() {
// if the status of job changes to waiting again, increase tasks version.
if err := IncreaseTaskVersion(ctx, job.OwnerID, job.RepoID); err != nil {
return 0, err
@@ -134,7 +190,7 @@ func UpdateRunJob(ctx context.Context, job *ActionRunJob, cond builder.Cond, col
if job.RunID == 0 {
var err error
- if job, err = GetRunJobByID(ctx, job.ID); err != nil {
+ if job, err = GetRunJobByRepoAndID(ctx, job.RepoID, job.ID); err != nil {
return 0, err
}
}
@@ -197,3 +253,39 @@ func AggregateJobStatus(jobs []*ActionRunJob) Status {
return StatusUnknown // it shouldn't happen
}
}
+
+func CancelPreviousJobsByJobConcurrency(ctx context.Context, job *ActionRunJob) (jobsToCancel []*ActionRunJob, _ error) {
+ if job.RawConcurrency == "" {
+ return nil, nil
+ }
+ if !job.IsConcurrencyEvaluated {
+ return nil, nil
+ }
+ if job.ConcurrencyGroup == "" {
+ return nil, nil
+ }
+
+ statusFindOption := []Status{StatusWaiting, StatusBlocked}
+ if job.ConcurrencyCancel {
+ statusFindOption = append(statusFindOption, StatusRunning)
+ }
+ runs, jobs, err := GetConcurrentRunsAndJobs(ctx, job.RepoID, job.ConcurrencyGroup, statusFindOption)
+ if err != nil {
+ return nil, fmt.Errorf("find concurrent runs and jobs: %w", err)
+ }
+ jobs = slices.DeleteFunc(jobs, func(j *ActionRunJob) bool { return j.ID == job.ID })
+ jobsToCancel = append(jobsToCancel, jobs...)
+
+ // cancel runs in the same concurrency group
+ for _, run := range runs {
+ jobs, err := db.Find[ActionRunJob](ctx, FindRunJobOptions{
+ RunID: run.ID,
+ })
+ if err != nil {
+ return nil, fmt.Errorf("find run %d jobs: %w", run.ID, err)
+ }
+ jobsToCancel = append(jobsToCancel, jobs...)
+ }
+
+ return CancelJobs(ctx, jobsToCancel)
+}
diff --git a/models/actions/run_job_list.go b/models/actions/run_job_list.go
index 5f7bb62878..10f76d3641 100644
--- a/models/actions/run_job_list.go
+++ b/models/actions/run_job_list.go
@@ -69,12 +69,13 @@ func (jobs ActionJobList) LoadAttributes(ctx context.Context, withRepo bool) err
type FindRunJobOptions struct {
db.ListOptions
- RunID int64
- RepoID int64
- OwnerID int64
- CommitSHA string
- Statuses []Status
- UpdatedBefore timeutil.TimeStamp
+ RunID int64
+ RepoID int64
+ OwnerID int64
+ CommitSHA string
+ Statuses []Status
+ UpdatedBefore timeutil.TimeStamp
+ ConcurrencyGroup string
}
func (opts FindRunJobOptions) ToConds() builder.Cond {
@@ -94,6 +95,12 @@ func (opts FindRunJobOptions) ToConds() builder.Cond {
if opts.UpdatedBefore > 0 {
cond = cond.And(builder.Lt{"`action_run_job`.updated": opts.UpdatedBefore})
}
+ if opts.ConcurrencyGroup != "" {
+ if opts.RepoID == 0 {
+ panic("Invalid FindRunJobOptions: repo_id is required")
+ }
+ cond = cond.And(builder.Eq{"`action_run_job`.concurrency_group": opts.ConcurrencyGroup})
+ }
return cond
}
diff --git a/models/actions/run_list.go b/models/actions/run_list.go
index 12c55e538e..2628c4712f 100644
--- a/models/actions/run_list.go
+++ b/models/actions/run_list.go
@@ -64,15 +64,16 @@ func (runs RunList) LoadRepos(ctx context.Context) error {
type FindRunOptions struct {
db.ListOptions
- RepoID int64
- OwnerID int64
- WorkflowID string
- Ref string // the commit/tag/… that caused this workflow
- TriggerUserID int64
- TriggerEvent webhook_module.HookEventType
- Approved bool // not util.OptionalBool, it works only when it's true
- Status []Status
- CommitSHA string
+ RepoID int64
+ OwnerID int64
+ WorkflowID string
+ Ref string // the commit/tag/… that caused this workflow
+ TriggerUserID int64
+ TriggerEvent webhook_module.HookEventType
+ Approved bool // not util.OptionalBool, it works only when it's true
+ Status []Status
+ ConcurrencyGroup string
+ CommitSHA string
}
func (opts FindRunOptions) ToConds() builder.Cond {
@@ -101,6 +102,12 @@ func (opts FindRunOptions) ToConds() builder.Cond {
if opts.CommitSHA != "" {
cond = cond.And(builder.Eq{"`action_run`.commit_sha": opts.CommitSHA})
}
+ if len(opts.ConcurrencyGroup) > 0 {
+ if opts.RepoID == 0 {
+ panic("Invalid FindRunOptions: repo_id is required")
+ }
+ cond = cond.And(builder.Eq{"`action_run`.concurrency_group": opts.ConcurrencyGroup})
+ }
return cond
}
diff --git a/models/actions/runner.go b/models/actions/runner.go
index 81d4249ae0..f5d40ca7d6 100644
--- a/models/actions/runner.go
+++ b/models/actions/runner.go
@@ -14,6 +14,7 @@ import (
repo_model "code.gitea.io/gitea/models/repo"
"code.gitea.io/gitea/models/shared/types"
user_model "code.gitea.io/gitea/models/user"
+ "code.gitea.io/gitea/modules/container"
"code.gitea.io/gitea/modules/optional"
"code.gitea.io/gitea/modules/setting"
"code.gitea.io/gitea/modules/timeutil"
@@ -61,6 +62,8 @@ type ActionRunner struct {
AgentLabels []string `xorm:"TEXT"`
// Store if this is a runner that only ever get one single job assigned
Ephemeral bool `xorm:"ephemeral NOT NULL DEFAULT false"`
+ // Store if this runner is disabled and should not pick up new jobs
+ IsDisabled bool `xorm:"is_disabled NOT NULL DEFAULT false"`
Created timeutil.TimeStamp `xorm:"created"`
Updated timeutil.TimeStamp `xorm:"updated"`
@@ -173,6 +176,13 @@ func (r *ActionRunner) GenerateToken() (err error) {
return err
}
+// CanMatchLabels checks whether the runner's labels can match a job's "runs-on"
+// See https://docs.github.com/en/actions/reference/workflows-and-actions/workflow-syntax#jobsjob_idruns-on
+func (r *ActionRunner) CanMatchLabels(jobRunsOn []string) bool {
+ runnerLabelSet := container.SetOf(r.AgentLabels...)
+ return runnerLabelSet.Contains(jobRunsOn...) // match all labels
+}
+
func init() {
db.RegisterModel(&ActionRunner{})
}
@@ -191,6 +201,7 @@ type FindRunnerOptions struct {
Sort string
Filter string
IsOnline optional.Option[bool]
+ IsDisabled optional.Option[bool]
WithAvailable bool // not only runners belong to, but also runners can be used
}
@@ -231,6 +242,10 @@ func (opts FindRunnerOptions) ToConds() builder.Cond {
cond = cond.And(builder.Lte{"last_online": time.Now().Add(-RunnerOfflineTime).Unix()})
}
}
+
+ if opts.IsDisabled.Has() {
+ cond = cond.And(builder.Eq{"is_disabled": opts.IsDisabled.Value()})
+ }
return cond
}
@@ -289,6 +304,20 @@ func UpdateRunner(ctx context.Context, r *ActionRunner, cols ...string) error {
return err
}
+func SetRunnerDisabled(ctx context.Context, runner *ActionRunner, isDisabled bool) error {
+ if runner.IsDisabled == isDisabled {
+ return nil
+ }
+
+ return db.WithTx(ctx, func(ctx context.Context) error {
+ runner.IsDisabled = isDisabled
+ if err := UpdateRunner(ctx, runner, "is_disabled"); err != nil {
+ return err
+ }
+ return IncreaseTaskVersion(ctx, runner.OwnerID, runner.RepoID)
+ })
+}
+
// DeleteRunner deletes a runner by given ID.
func DeleteRunner(ctx context.Context, id int64) error {
if _, err := GetRunnerByID(ctx, id); err != nil {
diff --git a/models/actions/task.go b/models/actions/task.go
index c1306a8418..77139ddcea 100644
--- a/models/actions/task.go
+++ b/models/actions/task.go
@@ -8,12 +8,13 @@ import (
"crypto/subtle"
"errors"
"fmt"
+ "strings"
"time"
auth_model "code.gitea.io/gitea/models/auth"
"code.gitea.io/gitea/models/db"
"code.gitea.io/gitea/models/unit"
- "code.gitea.io/gitea/modules/container"
+ "code.gitea.io/gitea/modules/actions/jobparser"
"code.gitea.io/gitea/modules/log"
"code.gitea.io/gitea/modules/setting"
"code.gitea.io/gitea/modules/timeutil"
@@ -21,7 +22,6 @@ import (
runnerv1 "code.gitea.io/actions-proto-go/runner/v1"
lru "github.com/hashicorp/golang-lru/v2"
- "github.com/nektos/act/pkg/jobparser"
"google.golang.org/protobuf/types/known/timestamppb"
"xorm.io/builder"
)
@@ -77,7 +77,7 @@ func init() {
}
func (task *ActionTask) Duration() time.Duration {
- return calculateDuration(task.Started, task.Stopped, task.Status)
+ return calculateDuration(task.Started, task.Stopped, task.Status, task.Updated)
}
func (task *ActionTask) IsStopped() bool {
@@ -114,7 +114,7 @@ func (task *ActionTask) GetRepoLink() string {
func (task *ActionTask) LoadJob(ctx context.Context) error {
if task.Job == nil {
- job, err := GetRunJobByID(ctx, task.JobID)
+ job, err := GetRunJobByRepoAndID(ctx, task.RepoID, task.JobID)
if err != nil {
return err
}
@@ -216,6 +216,20 @@ func GetRunningTaskByToken(ctx context.Context, token string) (*ActionTask, erro
return nil, errNotExist
}
+func makeTaskStepDisplayName(step *jobparser.Step, limit int) (name string) {
+ if step.Name != "" {
+ name = step.Name // the step has an explicit name
+ } else {
+ // for unnamed step, its "String()" method tries to get a display name by its "name", "uses",
+ // "run" or "id" (last fallback), we add the "Run " prefix for unnamed steps for better display
+ // for multi-line "run" scripts, only use the first line to match GitHub's behavior
+ // https://github.com/actions/runner/blob/66800900843747f37591b077091dd2c8cf2c1796/src/Runner.Worker/Handlers/ScriptHandler.cs#L45-L58
+ runStr, _, _ := strings.Cut(strings.TrimSpace(step.Run), "\n")
+ name = "Run " + util.IfZero(strings.TrimSpace(runStr), step.String())
+ }
+ return util.EllipsisDisplayString(name, limit) // database column has a length limit
+}
+
func CreateTaskForRunner(ctx context.Context, runner *ActionRunner) (*ActionTask, bool, error) {
ctx, committer, err := db.TxContext(ctx)
if err != nil {
@@ -246,7 +260,7 @@ func CreateTaskForRunner(ctx context.Context, runner *ActionRunner) (*ActionTask
var job *ActionRunJob
log.Trace("runner labels: %v", runner.AgentLabels)
for _, v := range jobs {
- if isSubset(runner.AgentLabels, v.RunsOn) {
+ if runner.CanMatchLabels(v.RunsOn) {
job = v
break
}
@@ -278,13 +292,10 @@ func CreateTaskForRunner(ctx context.Context, runner *ActionRunner) (*ActionTask
return nil, false, err
}
- parsedWorkflows, err := jobparser.Parse(job.WorkflowPayload)
+ workflowJob, err := job.ParseJob()
if err != nil {
- return nil, false, fmt.Errorf("parse workflow of job %d: %w", job.ID, err)
- } else if len(parsedWorkflows) != 1 {
- return nil, false, fmt.Errorf("workflow of job %d: not single workflow", job.ID)
+ return nil, false, fmt.Errorf("load job %d: %w", job.ID, err)
}
- _, workflowJob := parsedWorkflows[0].Job()
if _, err := e.Insert(task); err != nil {
return nil, false, err
@@ -298,9 +309,8 @@ func CreateTaskForRunner(ctx context.Context, runner *ActionRunner) (*ActionTask
if len(workflowJob.Steps) > 0 {
steps := make([]*ActionTaskStep, len(workflowJob.Steps))
for i, v := range workflowJob.Steps {
- name := util.EllipsisDisplayString(v.String(), 255)
steps[i] = &ActionTaskStep{
- Name: name,
+ Name: makeTaskStepDisplayName(v, 255),
TaskID: task.ID,
Index: int64(i),
RepoID: task.RepoID,
@@ -378,6 +388,7 @@ func UpdateTaskByState(ctx context.Context, runnerID int64, state *runnerv1.Task
}
if _, err := UpdateRunJob(ctx, &ActionRunJob{
ID: task.JobID,
+ RepoID: task.RepoID,
Status: task.Status,
Stopped: task.Stopped,
}, nil); err != nil {
@@ -439,6 +450,7 @@ func StopTask(ctx context.Context, taskID int64, status Status) error {
task.Stopped = now
if _, err := UpdateRunJob(ctx, &ActionRunJob{
ID: task.JobID,
+ RepoID: task.RepoID,
Status: task.Status,
Stopped: task.Stopped,
}, nil); err != nil {
@@ -479,20 +491,6 @@ func FindOldTasksToExpire(ctx context.Context, olderThan timeutil.TimeStamp, lim
Find(&tasks)
}
-func isSubset(set, subset []string) bool {
- m := make(container.Set[string], len(set))
- for _, v := range set {
- m.Add(v)
- }
-
- for _, v := range subset {
- if !m.Contains(v) {
- return false
- }
- }
- return true
-}
-
func convertTimestamp(timestamp *timestamppb.Timestamp) timeutil.TimeStamp {
if timestamp.GetSeconds() == 0 && timestamp.GetNanos() == 0 {
return timeutil.TimeStamp(0)
diff --git a/models/actions/task_step.go b/models/actions/task_step.go
index 3af1fe3f5a..3b477d8483 100644
--- a/models/actions/task_step.go
+++ b/models/actions/task_step.go
@@ -14,7 +14,7 @@ import (
// ActionTaskStep represents a step of ActionTask
type ActionTaskStep struct {
ID int64
- Name string `xorm:"VARCHAR(255)"`
+ Name string `xorm:"VARCHAR(255)"` // the step name, for display purpose only, it will be truncated if it is too long
TaskID int64 `xorm:"index unique(task_index)"`
Index int64 `xorm:"index unique(task_index)"`
RepoID int64 `xorm:"index"`
@@ -28,7 +28,7 @@ type ActionTaskStep struct {
}
func (step *ActionTaskStep) Duration() time.Duration {
- return calculateDuration(step.Started, step.Stopped, step.Status)
+ return calculateDuration(step.Started, step.Stopped, step.Status, step.Updated)
}
func init() {
diff --git a/models/actions/task_test.go b/models/actions/task_test.go
new file mode 100644
index 0000000000..cbfc6f7636
--- /dev/null
+++ b/models/actions/task_test.go
@@ -0,0 +1,77 @@
+// Copyright 2026 The Gitea Authors. All rights reserved.
+// SPDX-License-Identifier: MIT
+
+package actions
+
+import (
+ "strings"
+ "testing"
+
+ "code.gitea.io/gitea/modules/actions/jobparser"
+
+ "github.com/stretchr/testify/assert"
+)
+
+func TestMakeTaskStepDisplayName(t *testing.T) {
+ tests := []struct {
+ name string
+ jobStep *jobparser.Step
+ expected string
+ }{
+ {
+ name: "explicit name",
+ jobStep: &jobparser.Step{
+ Name: "Test Step",
+ },
+ expected: "Test Step",
+ },
+ {
+ name: "uses step",
+ jobStep: &jobparser.Step{
+ Uses: "actions/checkout@v4",
+ },
+ expected: "Run actions/checkout@v4",
+ },
+ {
+ name: "single-line run",
+ jobStep: &jobparser.Step{
+ Run: "echo hello",
+ },
+ expected: "Run echo hello",
+ },
+ {
+ name: "multi-line run block scalar",
+ jobStep: &jobparser.Step{
+ Run: "\n echo hello \r\n echo world \n ",
+ },
+ expected: "Run echo hello",
+ },
+ {
+ name: "fallback to id",
+ jobStep: &jobparser.Step{
+ ID: "step-id",
+ },
+ expected: "Run step-id",
+ },
+ {
+ name: "very long name truncated",
+ jobStep: &jobparser.Step{
+ Name: strings.Repeat("a", 300),
+ },
+ expected: strings.Repeat("a", 252) + "…",
+ },
+ {
+ name: "very long run truncated",
+ jobStep: &jobparser.Step{
+ Run: strings.Repeat("a", 300),
+ },
+ expected: "Run " + strings.Repeat("a", 248) + "…",
+ },
+ }
+ for _, tt := range tests {
+ t.Run(tt.name, func(t *testing.T) {
+ result := makeTaskStepDisplayName(tt.jobStep, 255)
+ assert.Equal(t, tt.expected, result)
+ })
+ }
+}
diff --git a/models/actions/token_permissions.go b/models/actions/token_permissions.go
new file mode 100644
index 0000000000..985f6cc97b
--- /dev/null
+++ b/models/actions/token_permissions.go
@@ -0,0 +1,60 @@
+// Copyright 2026 The Gitea Authors. All rights reserved.
+// SPDX-License-Identifier: MIT
+
+package actions
+
+import (
+ "context"
+
+ repo_model "code.gitea.io/gitea/models/repo"
+ "code.gitea.io/gitea/models/unit"
+)
+
+// ComputeTaskTokenPermissions computes the effective permissions for a job token against the target repository.
+// It uses the job's stored permissions (if any), then applies org/repo clamps and fork/cross-repo restrictions.
+// Note: target repository access policy checks are enforced in GetActionsUserRepoPermission; this function only computes the job token's effective permission ceiling.
+func ComputeTaskTokenPermissions(ctx context.Context, task *ActionTask, targetRepo *repo_model.Repository) (ret repo_model.ActionsTokenPermissions, err error) {
+ if err := task.LoadJob(ctx); err != nil {
+ return ret, err
+ }
+ if err := task.Job.LoadRepo(ctx); err != nil {
+ return ret, err
+ }
+ runRepo := task.Job.Repo
+
+ if err := runRepo.LoadOwner(ctx); err != nil {
+ return ret, err
+ }
+
+ repoActionsCfg := runRepo.MustGetUnit(ctx, unit.TypeActions).ActionsConfig()
+ ownerActionsCfg, err := GetOwnerActionsConfig(ctx, runRepo.OwnerID)
+ if err != nil {
+ return ret, err
+ }
+
+ var jobDeclaredPerms repo_model.ActionsTokenPermissions
+ if task.Job.TokenPermissions != nil {
+ jobDeclaredPerms = *task.Job.TokenPermissions
+ } else if repoActionsCfg.OverrideOwnerConfig {
+ jobDeclaredPerms = repoActionsCfg.GetDefaultTokenPermissions()
+ } else {
+ jobDeclaredPerms = ownerActionsCfg.GetDefaultTokenPermissions()
+ }
+
+ var effectivePerms repo_model.ActionsTokenPermissions
+ if repoActionsCfg.OverrideOwnerConfig {
+ effectivePerms = repoActionsCfg.ClampPermissions(jobDeclaredPerms)
+ } else {
+ effectivePerms = ownerActionsCfg.ClampPermissions(jobDeclaredPerms)
+ }
+
+ // Cross-repository access and fork pull requests are strictly read-only for security.
+ // This ensures a "task repo" cannot gain write access to other repositories via CrossRepoAccess settings.
+ isSameRepo := task.Job.RepoID == targetRepo.ID
+ restrictCrossRepoAccess := task.IsForkPullRequest || !isSameRepo
+ if restrictCrossRepoAccess {
+ effectivePerms = repo_model.ClampActionsTokenPermissions(effectivePerms, repo_model.MakeRestrictedPermissions())
+ }
+
+ return effectivePerms, nil
+}
diff --git a/models/actions/utils.go b/models/actions/utils.go
index f6ba661ae3..1101a36cfc 100644
--- a/models/actions/utils.go
+++ b/models/actions/utils.go
@@ -13,6 +13,7 @@ import (
"time"
auth_model "code.gitea.io/gitea/models/auth"
+ "code.gitea.io/gitea/modules/log"
"code.gitea.io/gitea/modules/timeutil"
"code.gitea.io/gitea/modules/util"
)
@@ -72,13 +73,25 @@ func (indexes *LogIndexes) ToDB() ([]byte, error) {
var timeSince = time.Since
-func calculateDuration(started, stopped timeutil.TimeStamp, status Status) time.Duration {
+// calculateDuration computes wall time for a run, job, task, or step. When status is terminal
+// but stopped is missing or inconsistent with started, fallbackEnd (typically the row Updated
+// time) is used so duration still reflects approximate elapsed time instead of 0 or a negative.
+func calculateDuration(started, stopped timeutil.TimeStamp, status Status, fallbackEnd timeutil.TimeStamp) time.Duration {
if started == 0 {
return 0
}
s := started.AsTime()
if status.IsDone() {
- return stopped.AsTime().Sub(s)
+ end := stopped
+ if stopped.IsZero() || stopped < started {
+ if !fallbackEnd.IsZero() && fallbackEnd >= started {
+ end = fallbackEnd
+ } else {
+ log.Trace("actions: invalid duration timestamps (started=%d, stopped=%d, fallbackEnd=%d, status=%s)", started, stopped, fallbackEnd, status)
+ return 0
+ }
+ }
+ return end.AsTime().Sub(s)
}
return timeSince(s).Truncate(time.Second)
}
diff --git a/models/actions/utils_test.go b/models/actions/utils_test.go
index 98c048d4ef..2f7e7da360 100644
--- a/models/actions/utils_test.go
+++ b/models/actions/utils_test.go
@@ -45,9 +45,10 @@ func Test_calculateDuration(t *testing.T) {
return timeutil.TimeStamp(1000).AsTime().Sub(t)
}
type args struct {
- started timeutil.TimeStamp
- stopped timeutil.TimeStamp
- status Status
+ started timeutil.TimeStamp
+ stopped timeutil.TimeStamp
+ status Status
+ fallbackEnd timeutil.TimeStamp
}
tests := []struct {
name string
@@ -81,10 +82,48 @@ func Test_calculateDuration(t *testing.T) {
},
want: 100 * time.Second,
},
+ {
+ name: "done_stopped_zero_no_fallback",
+ args: args{
+ started: 500,
+ stopped: 0,
+ status: StatusSuccess,
+ },
+ want: 0,
+ },
+ {
+ name: "done_stopped_zero_uses_fallback",
+ args: args{
+ started: 500,
+ stopped: 0,
+ status: StatusSuccess,
+ fallbackEnd: 600,
+ },
+ want: 100 * time.Second,
+ },
+ {
+ name: "done_stopped_before_started_no_fallback",
+ args: args{
+ started: 600,
+ stopped: 550,
+ status: StatusSuccess,
+ },
+ want: 0,
+ },
+ {
+ name: "done_stopped_before_started_uses_fallback",
+ args: args{
+ started: 600,
+ stopped: 550,
+ status: StatusSuccess,
+ fallbackEnd: 650,
+ },
+ want: 50 * time.Second,
+ },
}
for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) {
- assert.Equalf(t, tt.want, calculateDuration(tt.args.started, tt.args.stopped, tt.args.status), "calculateDuration(%v, %v, %v)", tt.args.started, tt.args.stopped, tt.args.status)
+ assert.Equalf(t, tt.want, calculateDuration(tt.args.started, tt.args.stopped, tt.args.status, tt.args.fallbackEnd), "calculateDuration(%v, %v, %v, %v)", tt.args.started, tt.args.stopped, tt.args.status, tt.args.fallbackEnd)
})
}
}
diff --git a/models/activities/action.go b/models/activities/action.go
index 8e589eda88..97388402d4 100644
--- a/models/activities/action.go
+++ b/models/activities/action.go
@@ -186,15 +186,7 @@ func (a *Action) LoadActUser(ctx context.Context) {
if a.ActUser != nil {
return
}
- var err error
- a.ActUser, err = user_model.GetPossibleUserByID(ctx, a.ActUserID)
- if err == nil {
- return
- } else if user_model.IsErrUserNotExist(err) {
- a.ActUser = user_model.NewGhostUser()
- } else {
- log.Error("GetUserByID(%d): %v", a.ActUserID, err)
- }
+ a.ActUserID, a.ActUser, _ = user_model.GetPossibleUserByID(ctx, a.ActUserID)
}
func (a *Action) LoadRepo(ctx context.Context) error {
@@ -444,6 +436,12 @@ type GetFeedsOptions struct {
DontCount bool // do counting in GetFeeds
}
+func (opts *GetFeedsOptions) ApplyPublicOnly(publicOnly bool) {
+ if publicOnly {
+ opts.IncludePrivate = false
+ }
+}
+
// ActivityReadable return whether doer can read activities of user
func ActivityReadable(user, doer *user_model.User) bool {
return !user.KeepActivityPrivate ||
diff --git a/models/activities/action_list.go b/models/activities/action_list.go
index b52cf7ee49..29ff2fdf7a 100644
--- a/models/activities/action_list.go
+++ b/models/activities/action_list.go
@@ -30,7 +30,7 @@ func (actions ActionList) getUserIDs() []int64 {
func (actions ActionList) LoadActUsers(ctx context.Context) (map[int64]*user_model.User, error) {
if len(actions) == 0 {
- return nil, nil
+ return nil, nil //nolint:nilnil // returns nil when there are no actions
}
userIDs := actions.getUserIDs()
diff --git a/models/activities/notification_list.go b/models/activities/notification_list.go
index 6539e14ea2..d38758bc41 100644
--- a/models/activities/notification_list.go
+++ b/models/activities/notification_list.go
@@ -113,7 +113,7 @@ func createOrUpdateIssueNotifications(ctx context.Context, issueID, commentID, n
}
toNotify.AddMultiple(issueParticipants...)
- // dont notify user who cause notification
+ // don't notify user who cause notification
delete(toNotify, notificationAuthorID)
// explicit unwatch on issue
issueUnWatches, err := issues_model.GetIssueWatchersIDs(ctx, issueID, false)
diff --git a/models/activities/user_heatmap.go b/models/activities/user_heatmap.go
index ef67838be7..e24d44c519 100644
--- a/models/activities/user_heatmap.go
+++ b/models/activities/user_heatmap.go
@@ -19,14 +19,14 @@ type UserHeatmapData struct {
Contributions int64 `json:"contributions"`
}
-// GetUserHeatmapDataByUser returns an array of UserHeatmapData
+// GetUserHeatmapDataByUser returns an array of UserHeatmapData, it checks whether doer can access user's activity
func GetUserHeatmapDataByUser(ctx context.Context, user, doer *user_model.User) ([]*UserHeatmapData, error) {
return getUserHeatmapData(ctx, user, nil, doer)
}
-// GetUserHeatmapDataByUserTeam returns an array of UserHeatmapData
-func GetUserHeatmapDataByUserTeam(ctx context.Context, user *user_model.User, team *organization.Team, doer *user_model.User) ([]*UserHeatmapData, error) {
- return getUserHeatmapData(ctx, user, team, doer)
+// GetUserHeatmapDataByOrgTeam returns an array of UserHeatmapData, it checks whether doer can access org's activity
+func GetUserHeatmapDataByOrgTeam(ctx context.Context, org *organization.Organization, team *organization.Team, doer *user_model.User) ([]*UserHeatmapData, error) {
+ return getUserHeatmapData(ctx, org.AsUser(), team, doer)
}
func getUserHeatmapData(ctx context.Context, user *user_model.User, team *organization.Team, doer *user_model.User) ([]*UserHeatmapData, error) {
@@ -71,12 +71,3 @@ func getUserHeatmapData(ctx context.Context, user *user_model.User, team *organi
OrderBy("timestamp").
Find(&hdata)
}
-
-// GetTotalContributionsInHeatmap returns the total number of contributions in a heatmap
-func GetTotalContributionsInHeatmap(hdata []*UserHeatmapData) int64 {
- var total int64
- for _, v := range hdata {
- total += v.Contributions
- }
- return total
-}
diff --git a/models/admin/task.go b/models/admin/task.go
index 5d2b9bbff6..7056a8359e 100644
--- a/models/admin/task.go
+++ b/models/admin/task.go
@@ -137,6 +137,11 @@ func (task *Task) MigrateConfig() (*migration.MigrateOptions, error) {
log.Error("Unable to decrypt AuthToken, maybe SECRET_KEY is wrong: %v", err)
}
}
+ if opts.AWSSecretAccessKeyEncrypted != "" {
+ if opts.AWSSecretAccessKey, err = secret.DecryptSecret(setting.SecretKey, opts.AWSSecretAccessKeyEncrypted); err != nil {
+ log.Error("Unable to decrypt AWSSecretAccessKey, maybe SECRET_KEY is wrong: %v", err)
+ }
+ }
return &opts, nil
}
@@ -201,6 +206,8 @@ func FinishMigrateTask(ctx context.Context, task *Task) error {
conf.AuthPasswordEncrypted = ""
conf.AuthTokenEncrypted = ""
conf.CloneAddrEncrypted = ""
+ conf.AWSSecretAccessKey = ""
+ conf.AWSSecretAccessKeyEncrypted = ""
confBytes, err := json.Marshal(conf)
if err != nil {
return err
diff --git a/models/asymkey/gpg_key_commit_verification.go b/models/asymkey/gpg_key_commit_verification.go
index 375b703f7b..ae5192de9f 100644
--- a/models/asymkey/gpg_key_commit_verification.go
+++ b/models/asymkey/gpg_key_commit_verification.go
@@ -70,7 +70,7 @@ func hashAndVerify(sig *packet.Signature, payload string, k *GPGKey) (*GPGKey, e
// We will ignore errors in verification as they don't need to be propagated up
err = verifySign(sig, hash, k)
if err != nil {
- return nil, nil
+ return nil, nil //nolint:nilnil // verification failed, not an error
}
return k, nil
}
@@ -86,7 +86,7 @@ func hashAndVerifyWithSubKeys(sig *packet.Signature, payload string, k *GPGKey)
return verified, err
}
}
- return nil, nil
+ return nil, nil //nolint:nilnil // verification failed, not an error
}
func HashAndVerifyWithSubKeysCommitVerification(sig *packet.Signature, payload string, k *GPGKey, committer, signer *user_model.User, email string) *CommitVerification {
diff --git a/models/asymkey/gpg_key_test.go b/models/asymkey/gpg_key_test.go
index 4621337f11..e6656cb70d 100644
--- a/models/asymkey/gpg_key_test.go
+++ b/models/asymkey/gpg_key_test.go
@@ -11,7 +11,6 @@ import (
"code.gitea.io/gitea/models/unittest"
user_model "code.gitea.io/gitea/models/user"
"code.gitea.io/gitea/modules/timeutil"
- "code.gitea.io/gitea/modules/util"
"github.com/ProtonMail/go-crypto/openpgp"
"github.com/ProtonMail/go-crypto/openpgp/packet"
@@ -398,7 +397,7 @@ epiDVQ==
func TestTryGetKeyIDFromSignature(t *testing.T) {
assert.Empty(t, TryGetKeyIDFromSignature(&packet.Signature{}))
assert.Equal(t, "038D1A3EADDBEA9C", TryGetKeyIDFromSignature(&packet.Signature{
- IssuerKeyId: util.ToPointer(uint64(0x38D1A3EADDBEA9C)),
+ IssuerKeyId: new(uint64(0x38D1A3EADDBEA9C)),
}))
assert.Equal(t, "038D1A3EADDBEA9C", TryGetKeyIDFromSignature(&packet.Signature{
IssuerFingerprint: []uint8{0xb, 0x23, 0x24, 0xc7, 0xe6, 0xfe, 0x4f, 0x3a, 0x6, 0x26, 0xc1, 0x21, 0x3, 0x8d, 0x1a, 0x3e, 0xad, 0xdb, 0xea, 0x9c},
@@ -419,7 +418,7 @@ func TestParseGPGKey(t *testing.T) {
// then revoke the key
for _, id := range e.Identities {
- id.Revocations = append(id.Revocations, &packet.Signature{RevocationReason: util.ToPointer(packet.KeyCompromised)})
+ id.Revocations = append(id.Revocations, &packet.Signature{RevocationReason: new(packet.KeyCompromised)})
}
k, err = parseGPGKey(t.Context(), 1, e, true)
require.NoError(t, err)
diff --git a/models/asymkey/ssh_key_authorized_keys_test.go b/models/asymkey/ssh_key_authorized_keys_test.go
new file mode 100644
index 0000000000..36ed57a653
--- /dev/null
+++ b/models/asymkey/ssh_key_authorized_keys_test.go
@@ -0,0 +1,90 @@
+// Copyright 2025 The Gitea Authors. All rights reserved.
+// SPDX-License-Identifier: MIT
+
+package asymkey
+
+import (
+ "strings"
+ "testing"
+
+ "code.gitea.io/gitea/modules/setting"
+ "code.gitea.io/gitea/modules/test"
+
+ "github.com/stretchr/testify/assert"
+)
+
+func TestWriteAuthorizedStringForKey(t *testing.T) {
+ defer test.MockVariableValue(&setting.AppPath, "/tmp/gitea")()
+ defer test.MockVariableValue(&setting.CustomConf, "/tmp/app.ini")()
+ writeKey := func(t *testing.T, key *PublicKey) (bool, string, error) {
+ sb := &strings.Builder{}
+ valid, err := writeAuthorizedStringForKey(key, sb)
+ return valid, sb.String(), err
+ }
+ const validKeyContent = `ssh-ed25519 AAAAC3NzaC1lZDI1NTE5AAAAICV0MGX/W9IvLA4FXpIuUcdDcbj5KX4syHgsTy7soVgf`
+
+ testValid := func(t *testing.T, key *PublicKey, expected string) {
+ valid, content, err := writeKey(t, key)
+ assert.True(t, valid)
+ assert.Equal(t, expected, content)
+ assert.NoError(t, err)
+ }
+
+ testInvalid := func(t *testing.T, key *PublicKey) {
+ valid, content, err := writeKey(t, key)
+ assert.False(t, valid)
+ assert.Empty(t, content)
+ assert.Error(t, err)
+ }
+
+ t.Run("PublicKey", func(t *testing.T) {
+ testValid(t, &PublicKey{
+ OwnerID: 123,
+ Content: validKeyContent + " any-comment",
+ Type: KeyTypeUser,
+ }, `# gitea public key
+command="/tmp/gitea --config=/tmp/app.ini serv key-0",no-port-forwarding,no-X11-forwarding,no-agent-forwarding,no-pty,no-user-rc,restrict ssh-ed25519 AAAAC3NzaC1lZDI1NTE5AAAAICV0MGX/W9IvLA4FXpIuUcdDcbj5KX4syHgsTy7soVgf user-123
+`)
+ })
+
+ t.Run("PublicKeyWithNewLine", func(t *testing.T) {
+ testValid(t, &PublicKey{
+ OwnerID: 123,
+ Content: validKeyContent + "\nany-more", // the new line should be ignored
+ Type: KeyTypeUser,
+ }, `# gitea public key
+command="/tmp/gitea --config=/tmp/app.ini serv key-0",no-port-forwarding,no-X11-forwarding,no-agent-forwarding,no-pty,no-user-rc,restrict ssh-ed25519 AAAAC3NzaC1lZDI1NTE5AAAAICV0MGX/W9IvLA4FXpIuUcdDcbj5KX4syHgsTy7soVgf user-123
+`)
+ })
+
+ t.Run("PublicKeyInvalid", func(t *testing.T) {
+ testInvalid(t, &PublicKey{
+ OwnerID: 123,
+ Content: validKeyContent + "any-more",
+ Type: KeyTypeUser,
+ })
+ })
+
+ t.Run("Principal", func(t *testing.T) {
+ testValid(t, &PublicKey{
+ OwnerID: 123,
+ Content: "any-content",
+ Type: KeyTypePrincipal,
+ }, `# gitea public key
+command="/tmp/gitea --config=/tmp/app.ini serv key-0",no-port-forwarding,no-X11-forwarding,no-agent-forwarding,no-pty,no-user-rc,restrict any-content # user-123
+`)
+ })
+
+ t.Run("PrincipalInvalid", func(t *testing.T) {
+ testInvalid(t, &PublicKey{
+ OwnerID: 123,
+ Content: "a b",
+ Type: KeyTypePrincipal,
+ })
+ testInvalid(t, &PublicKey{
+ OwnerID: 123,
+ Content: "a\nb",
+ Type: KeyTypePrincipal,
+ })
+ })
+}
diff --git a/models/asymkey/ssh_key_principals.go b/models/asymkey/ssh_key_principals.go
index e8b97d306e..2d4c74740d 100644
--- a/models/asymkey/ssh_key_principals.go
+++ b/models/asymkey/ssh_key_principals.go
@@ -40,7 +40,7 @@ func CheckPrincipalKeyString(ctx context.Context, user *user_model.User, content
if !email.IsActivated {
continue
}
- if content == email.Email {
+ if strings.EqualFold(content, email.LowerEmail) {
return content, nil
}
}
diff --git a/models/auth/oauth2.go b/models/auth/oauth2.go
index d664841306..83048c1152 100644
--- a/models/auth/oauth2.go
+++ b/models/auth/oauth2.go
@@ -5,15 +5,15 @@ package auth
import (
"context"
- "crypto/sha256"
+ "crypto/subtle"
"encoding/base32"
- "encoding/base64"
"errors"
"fmt"
"net"
"net/url"
"slices"
"strings"
+ "time"
"code.gitea.io/gitea/models/db"
"code.gitea.io/gitea/modules/container"
@@ -23,10 +23,19 @@ import (
uuid "github.com/google/uuid"
"golang.org/x/crypto/bcrypt"
+ "golang.org/x/oauth2"
"xorm.io/builder"
"xorm.io/xorm"
)
+// Authorization codes should expire within 10 minutes per https://datatracker.ietf.org/doc/html/rfc6749#section-4.1.2
+const oauth2AuthorizationCodeValidity = 10 * time.Minute
+
+var (
+ ErrOAuth2AuthorizationCodeInvalidated = errors.New("oauth2 authorization code already invalidated")
+ ErrOAuth2GrantStaleCounter = errors.New("oauth2 grant state changed during token refresh")
+)
+
// OAuth2Application represents an OAuth2 client (RFC 6749)
type OAuth2Application struct {
ID int64 `xorm:"pk autoincr"`
@@ -145,30 +154,40 @@ func (app *OAuth2Application) ContainsRedirectURI(redirectURI string) bool {
// https://www.rfc-editor.org/rfc/rfc6819#section-5.2.3.3
// https://openid.net/specs/openid-connect-core-1_0.html#AuthRequest
// https://datatracker.ietf.org/doc/html/draft-ietf-oauth-security-topics-12#section-3.1
- contains := func(s string) bool {
- s = strings.TrimSuffix(strings.ToLower(s), "/")
- for _, u := range app.RedirectURIs {
- if strings.TrimSuffix(strings.ToLower(u), "/") == s {
- return true
- }
+ redirectCandidates := []string{redirectURI}
+ if !app.ConfidentialClient {
+ loopbackRedirect, ok := normalizePublicClientRedirectURI(redirectURI)
+ if ok {
+ redirectCandidates = append(redirectCandidates, loopbackRedirect)
}
- return false
}
- if !app.ConfidentialClient {
- uri, err := url.Parse(redirectURI)
- // ignore port for http loopback uris following https://datatracker.ietf.org/doc/html/rfc8252#section-7.3
- if err == nil && uri.Scheme == "http" && uri.Port() != "" {
- ip := net.ParseIP(uri.Hostname())
- if ip != nil && ip.IsLoopback() {
- // strip port
- uri.Host = uri.Hostname()
- if contains(uri.String()) {
- return true
- }
+
+ for _, candidate := range redirectCandidates {
+ normalizedCandidate := normalizeRedirectURIForComparison(candidate)
+ for _, registeredURI := range app.RedirectURIs {
+ if normalizeRedirectURIForComparison(registeredURI) == normalizedCandidate {
+ return true
}
}
}
- return contains(redirectURI)
+
+ return false
+}
+
+func normalizeRedirectURIForComparison(redirectURI string) string {
+ return strings.TrimSuffix(util.ToLowerASCII(redirectURI), "/")
+}
+
+func normalizePublicClientRedirectURI(redirectURI string) (string, bool) {
+ parsedURI, err := url.Parse(redirectURI)
+ if err != nil || parsedURI.Scheme != "http" || parsedURI.Port() == "" {
+ return "", false
+ }
+ if ip := net.ParseIP(parsedURI.Hostname()); ip == nil || !ip.IsLoopback() {
+ return "", false
+ }
+ parsedURI.Host = parsedURI.Hostname()
+ return parsedURI.String(), true
}
// Base32 characters, but lowercased.
@@ -209,7 +228,7 @@ func (app *OAuth2Application) GetGrantByUserID(ctx context.Context, userID int64
if has, err := db.GetEngine(ctx).Where("user_id = ? AND application_id = ?", userID, app.ID).Get(grant); err != nil {
return nil, err
} else if !has {
- return nil, nil
+ return nil, nil //nolint:nilnil // return nil to indicate that the object does not exist
}
return grant, nil
}
@@ -386,6 +405,14 @@ func (code *OAuth2AuthorizationCode) TableName() string {
return "oauth2_authorization_code"
}
+// IsExpired reports whether the authorization code is expired.
+func (code *OAuth2AuthorizationCode) IsExpired() bool {
+ if code.ValidUntil.IsZero() {
+ return true
+ }
+ return code.ValidUntil <= timeutil.TimeStampNow()
+}
+
// GenerateRedirectURI generates a redirect URI for a successful authorization request. State will be used if not empty.
func (code *OAuth2AuthorizationCode) GenerateRedirectURI(state string) (*url.URL, error) {
redirect, err := url.Parse(code.RedirectURI)
@@ -403,26 +430,44 @@ func (code *OAuth2AuthorizationCode) GenerateRedirectURI(state string) (*url.URL
// Invalidate deletes the auth code from the database to invalidate this code
func (code *OAuth2AuthorizationCode) Invalidate(ctx context.Context) error {
- _, err := db.GetEngine(ctx).ID(code.ID).NoAutoCondition().Delete(code)
- return err
+ affected, err := db.GetEngine(ctx).ID(code.ID).NoAutoCondition().Delete(code)
+ if err != nil {
+ return err
+ }
+ if affected == 0 {
+ return ErrOAuth2AuthorizationCodeInvalidated
+ }
+ return nil
}
-// ValidateCodeChallenge validates the given verifier against the saved code challenge. This is part of the PKCE implementation.
-func (code *OAuth2AuthorizationCode) ValidateCodeChallenge(verifier string) bool {
- switch code.CodeChallengeMethod {
+func (code *OAuth2AuthorizationCode) requiresCodeVerifier() bool {
+ return code.CodeChallengeMethod != "" || code.CodeChallenge != ""
+}
+
+func deriveCodeChallenge(method, verifier string) (string, bool) {
+ switch method {
case "S256":
- // base64url(SHA256(verifier)) see https://tools.ietf.org/html/rfc7636#section-4.6
- h := sha256.Sum256([]byte(verifier))
- hashedVerifier := base64.RawURLEncoding.EncodeToString(h[:])
- return hashedVerifier == code.CodeChallenge
+ return oauth2.S256ChallengeFromVerifier(verifier), true
case "plain":
- return verifier == code.CodeChallenge
- case "":
- return true
+ return verifier, true
default:
- // unsupported method -> return false
+ return "", false
+ }
+}
+
+// ValidateCodeChallenge validates the given verifier against the saved code challenge. This is part of the PKCE implementation.
+func (code *OAuth2AuthorizationCode) ValidateCodeChallenge(verifier string) bool {
+ if !code.requiresCodeVerifier() {
+ return true
+ }
+ if verifier == "" || code.CodeChallengeMethod == "" {
+ return false
+ }
+ expectedChallenge, ok := deriveCodeChallenge(code.CodeChallengeMethod, verifier)
+ if !ok {
return false
}
+ return subtle.ConstantTimeCompare([]byte(expectedChallenge), []byte(code.CodeChallenge)) == 1
}
// GetOAuth2AuthorizationByCode returns an authorization by its code
@@ -431,13 +476,13 @@ func GetOAuth2AuthorizationByCode(ctx context.Context, code string) (auth *OAuth
if has, err := db.GetEngine(ctx).Where("code = ?", code).Get(auth); err != nil {
return nil, err
} else if !has {
- return nil, nil
+ return nil, nil //nolint:nilnil // return nil to indicate that the object does not exist
}
auth.Grant = new(OAuth2Grant)
if has, err := db.GetEngine(ctx).ID(auth.GrantID).Get(auth.Grant); err != nil {
return nil, err
} else if !has {
- return nil, nil
+ return nil, nil //nolint:nilnil // return nil to indicate that the object does not exist
}
return auth, nil
}
@@ -472,6 +517,7 @@ func (grant *OAuth2Grant) GenerateNewAuthorizationCode(ctx context.Context, redi
// for code scanners to grab sensitive tokens.
codeSecret := "gta_" + base32Lower.EncodeToString(rBytes)
+ validUntil := time.Now().Add(oauth2AuthorizationCodeValidity)
code = &OAuth2AuthorizationCode{
Grant: grant,
GrantID: grant.ID,
@@ -479,6 +525,7 @@ func (grant *OAuth2Grant) GenerateNewAuthorizationCode(ctx context.Context, redi
Code: codeSecret,
CodeChallenge: codeChallenge,
CodeChallengeMethod: codeChallengeMethod,
+ ValidUntil: timeutil.TimeStamp(validUntil.Unix()),
}
if err := db.Insert(ctx, code); err != nil {
return nil, err
@@ -488,15 +535,18 @@ func (grant *OAuth2Grant) GenerateNewAuthorizationCode(ctx context.Context, redi
// IncreaseCounter increases the counter and updates the grant
func (grant *OAuth2Grant) IncreaseCounter(ctx context.Context) error {
- _, err := db.GetEngine(ctx).ID(grant.ID).Incr("counter").Update(new(OAuth2Grant))
+ affected, err := db.GetEngine(ctx).
+ Where("id = ?", grant.ID).
+ And("counter = ?", grant.Counter).
+ Incr("counter").
+ Update(new(OAuth2Grant))
if err != nil {
return err
}
- updatedGrant, err := GetOAuth2GrantByID(ctx, grant.ID)
- if err != nil {
- return err
+ if affected == 0 {
+ return ErrOAuth2GrantStaleCounter
}
- grant.Counter = updatedGrant.Counter
+ grant.Counter++
return nil
}
@@ -521,7 +571,7 @@ func GetOAuth2GrantByID(ctx context.Context, id int64) (grant *OAuth2Grant, err
if has, err := db.GetEngine(ctx).ID(id).Get(grant); err != nil {
return nil, err
} else if !has {
- return nil, nil
+ return nil, nil //nolint:nilnil // return nil to indicate that the object does not exist
}
return grant, err
}
@@ -611,7 +661,7 @@ func GetActiveOAuth2SourceByAuthName(ctx context.Context, name string) (*Source,
}
if !has {
- return nil, fmt.Errorf("oauth2 source not found, name: %q", name)
+ return nil, util.NewNotExistErrorf("oauth2 source not found, name: %q", name)
}
return authSource, nil
diff --git a/models/auth/oauth2_test.go b/models/auth/oauth2_test.go
index 97f750755a..d87ffdaaae 100644
--- a/models/auth/oauth2_test.go
+++ b/models/auth/oauth2_test.go
@@ -5,13 +5,46 @@ package auth_test
import (
"testing"
+ "time"
auth_model "code.gitea.io/gitea/models/auth"
"code.gitea.io/gitea/models/unittest"
+ "code.gitea.io/gitea/modules/timeutil"
"github.com/stretchr/testify/assert"
+ "golang.org/x/oauth2"
)
+func TestOAuth2AuthorizationCodeValidity(t *testing.T) {
+ assert.NoError(t, unittest.PrepareTestDatabase())
+
+ t.Run("GenerateSetsValidUntil", func(t *testing.T) {
+ grant := unittest.AssertExistsAndLoadBean(t, &auth_model.OAuth2Grant{ID: 1})
+ expectedValidUntil := timeutil.TimeStamp(time.Now().Unix() + 600)
+ code, err := grant.GenerateNewAuthorizationCode(t.Context(), "http://127.0.0.1/", "", "")
+ assert.NoError(t, err)
+ assert.Equal(t, expectedValidUntil, code.ValidUntil)
+ assert.False(t, code.IsExpired())
+ assert.NoError(t, code.Invalidate(t.Context()))
+ })
+
+ t.Run("Expired", func(t *testing.T) {
+ defer timeutil.MockSet(time.Unix(2, 0).UTC())()
+
+ code := &auth_model.OAuth2AuthorizationCode{ValidUntil: timeutil.TimeStamp(1)}
+ assert.True(t, code.IsExpired())
+ })
+
+ t.Run("InvalidateTwice", func(t *testing.T) {
+ code, err := auth_model.GetOAuth2AuthorizationByCode(t.Context(), "authcode")
+ assert.NoError(t, err)
+ if assert.NotNil(t, code) {
+ assert.NoError(t, code.Invalidate(t.Context()))
+ assert.ErrorIs(t, code.Invalidate(t.Context()), auth_model.ErrOAuth2AuthorizationCodeInvalidated)
+ }
+ })
+}
+
func TestOAuth2Application_GenerateClientSecret(t *testing.T) {
assert.NoError(t, unittest.PrepareTestDatabase())
app := unittest.AssertExistsAndLoadBean(t, &auth_model.OAuth2Application{ID: 1})
@@ -72,6 +105,47 @@ func TestOAuth2Application_ContainsRedirect_Slash(t *testing.T) {
assert.False(t, app.ContainsRedirectURI("http://127.0.0.1/other"))
}
+func TestOAuth2Application_ContainsRedirectURI_ASCIIOnlyNormalization(t *testing.T) {
+ testCases := []struct {
+ name string
+ registered []string
+ redirectURI string
+ allowed bool
+ }{
+ {
+ name: "exact-match",
+ registered: []string{"https://signin.example.test/callback"},
+ redirectURI: "https://signin.example.test/callback",
+ allowed: true,
+ },
+ {
+ name: "ascii-case-insensitive",
+ registered: []string{"https://signin.example.test/callback"},
+ redirectURI: "https://signIN.example.test/callback",
+ allowed: true,
+ },
+ {
+ name: "non-ascii-not-folded",
+ registered: []string{"https://signin.example.test/callback"},
+ redirectURI: "https://signİn.example.test/callback",
+ allowed: false,
+ },
+ {
+ name: "loopback-strips-port",
+ registered: []string{"http://127.0.0.1/callback"},
+ redirectURI: "http://127.0.0.1:12345/callback",
+ allowed: true,
+ },
+ }
+
+ for _, tc := range testCases {
+ t.Run(tc.name, func(t *testing.T) {
+ app := &auth_model.OAuth2Application{RedirectURIs: tc.registered}
+ assert.Equal(t, tc.allowed, app.ContainsRedirectURI(tc.redirectURI))
+ })
+ }
+}
+
func TestOAuth2Application_ValidateClientSecret(t *testing.T) {
assert.NoError(t, unittest.PrepareTestDatabase())
app := unittest.AssertExistsAndLoadBean(t, &auth_model.OAuth2Application{ID: 1})
@@ -149,6 +223,16 @@ func TestOAuth2Grant_IncreaseCounter(t *testing.T) {
unittest.AssertExistsAndLoadBean(t, &auth_model.OAuth2Grant{ID: 1, Counter: 2})
}
+func TestOAuth2Grant_IncreaseCounterRejectsStaleCounter(t *testing.T) {
+ assert.NoError(t, unittest.PrepareTestDatabase())
+ grant := unittest.AssertExistsAndLoadBean(t, &auth_model.OAuth2Grant{ID: 1, Counter: 1})
+ stale := *grant
+
+ assert.NoError(t, grant.IncreaseCounter(t.Context()))
+ err := stale.IncreaseCounter(t.Context())
+ assert.ErrorIs(t, err, auth_model.ErrOAuth2GrantStaleCounter)
+}
+
func TestOAuth2Grant_ScopeContains(t *testing.T) {
assert.NoError(t, unittest.PrepareTestDatabase())
grant := unittest.AssertExistsAndLoadBean(t, &auth_model.OAuth2Grant{ID: 1, Scope: "openid profile"})
@@ -206,35 +290,38 @@ func TestGetOAuth2AuthorizationByCode(t *testing.T) {
}
func TestOAuth2AuthorizationCode_ValidateCodeChallenge(t *testing.T) {
- // test plain
- code := &auth_model.OAuth2AuthorizationCode{
- CodeChallengeMethod: "plain",
- CodeChallenge: "test123",
- }
- assert.True(t, code.ValidateCodeChallenge("test123"))
- assert.False(t, code.ValidateCodeChallenge("ierwgjoergjio"))
-
- // test S256
- code = &auth_model.OAuth2AuthorizationCode{
- CodeChallengeMethod: "S256",
- CodeChallenge: "CjvyTLSdR47G5zYenDA-eDWW4lRrO8yvjcWwbD_deOg",
- }
- assert.True(t, code.ValidateCodeChallenge("N1Zo9-8Rfwhkt68r1r29ty8YwIraXR8eh_1Qwxg7yQXsonBt"))
- assert.False(t, code.ValidateCodeChallenge("wiogjerogorewngoenrgoiuenorg"))
-
- // test unknown
- code = &auth_model.OAuth2AuthorizationCode{
- CodeChallengeMethod: "monkey",
- CodeChallenge: "foiwgjioriogeiogjerger",
+ s256Verifier := "s256-verifier"
+ s256Challenge := oauth2.S256ChallengeFromVerifier(s256Verifier)
+ missingVerifierChallenge := oauth2.S256ChallengeFromVerifier("verifier-not-supplied")
+
+ testCases := []struct {
+ name string
+ method string
+ challenge string
+ verifier string
+ valid bool
+ }{
+ {"plain-success", "plain", "plain-secret", "plain-secret", true},
+ {"plain-failure", "plain", "plain-secret", "ierwgjoergjio", false},
+ {"s256-success", "S256", s256Challenge, s256Verifier, true},
+ {"s256-failure", "S256", s256Challenge, "wiogjerogorewngoenrgoiuenorg", false},
+ {"unsupported-method", "monkey", "foiwgjioriogeiogjerger", "foiwgjioriogeiogjerger", false},
+ {"no-pkce-configured", "", "", "", true},
+ {"s256-missing-verifier", "S256", missingVerifierChallenge, "", false},
+ {"plain-missing-verifier", "plain", "plain-secret", "", false},
+ {"missing-method-with-challenge", "", "foierjiogerogerg", "", false},
+ {"missing-method-rejects-even-matching-verifier", "", "foierjiogerogerg", "foierjiogerogerg", false},
}
- assert.False(t, code.ValidateCodeChallenge("foiwgjioriogeiogjerger"))
- // test no code challenge
- code = &auth_model.OAuth2AuthorizationCode{
- CodeChallengeMethod: "",
- CodeChallenge: "foierjiogerogerg",
+ for _, tc := range testCases {
+ t.Run(tc.name, func(t *testing.T) {
+ code := &auth_model.OAuth2AuthorizationCode{
+ CodeChallengeMethod: tc.method,
+ CodeChallenge: tc.challenge,
+ }
+ assert.Equal(t, tc.valid, code.ValidateCodeChallenge(tc.verifier))
+ })
}
- assert.True(t, code.ValidateCodeChallenge(""))
}
func TestOAuth2AuthorizationCode_GenerateRedirectURI(t *testing.T) {
diff --git a/models/auth/source.go b/models/auth/source.go
index 08cfc9615b..7a008f08a8 100644
--- a/models/auth/source.go
+++ b/models/auth/source.go
@@ -12,6 +12,7 @@ import (
"code.gitea.io/gitea/models/db"
"code.gitea.io/gitea/modules/log"
"code.gitea.io/gitea/modules/optional"
+ "code.gitea.io/gitea/modules/setting"
"code.gitea.io/gitea/modules/timeutil"
"code.gitea.io/gitea/modules/util"
@@ -117,7 +118,7 @@ func RegisterTypeConfig(typ Type, exemplar Config) {
type Source struct {
ID int64 `xorm:"pk autoincr"`
Type Type
- Name string `xorm:"UNIQUE"`
+ Name string `xorm:"UNIQUE"` // it can be the OIDC's provider name, see services/auth/source/oauth2/source_register.go: RegisterSource
IsActive bool `xorm:"INDEX NOT NULL DEFAULT false"`
IsSyncEnabled bool `xorm:"INDEX NOT NULL DEFAULT false"`
TwoFactorPolicy string `xorm:"two_factor_policy NOT NULL DEFAULT ''"`
@@ -139,7 +140,10 @@ func init() {
// BeforeSet is invoked from XORM before setting the value of a field of this object.
func (source *Source) BeforeSet(colName string, val xorm.Cell) {
if colName == "type" {
- typ := Type(db.Cell2Int64(val))
+ typ, _, err := db.CellToInt(val, NoType)
+ if err != nil {
+ setting.PanicInDevOrTesting("Unable to convert login source (id=%d) type: %v", source.ID, err)
+ }
constructor, ok := registeredConfigs[typ]
if !ok {
return
diff --git a/models/auth/source_test.go b/models/auth/source_test.go
index ebc462c581..fbd663a64f 100644
--- a/models/auth/source_test.go
+++ b/models/auth/source_test.go
@@ -17,13 +17,9 @@ import (
)
type TestSource struct {
- auth_model.ConfigBase
+ auth_model.ConfigBase `json:"-"`
- Provider string
- ClientID string
- ClientSecret string
- OpenIDConnectAutoDiscoveryURL string
- IconURL string
+ TestField string
}
// FromDB fills up a LDAPConfig from serialized format.
@@ -37,27 +33,23 @@ func (source *TestSource) ToDB() ([]byte, error) {
}
func TestDumpAuthSource(t *testing.T) {
- assert.NoError(t, unittest.PrepareTestDatabase())
+ require.NoError(t, unittest.PrepareTestDatabase())
authSourceSchema, err := unittest.GetXORMEngine().TableInfo(new(auth_model.Source))
- assert.NoError(t, err)
+ require.NoError(t, err)
auth_model.RegisterTypeConfig(auth_model.OAuth2, new(TestSource))
-
- auth_model.CreateSource(t.Context(), &auth_model.Source{
- Type: auth_model.OAuth2,
- Name: "TestSource",
- IsActive: false,
- Cfg: &TestSource{
- Provider: "ConvertibleSourceName",
- ClientID: "42",
- },
- })
-
- sb := new(strings.Builder)
-
- // TODO: this test is quite hacky, it should use a low-level "select" (without model processors) but not a database dump
- engine := unittest.GetXORMEngine()
- require.NoError(t, engine.DumpTables([]*schemas.Table{authSourceSchema}, sb))
- assert.Contains(t, sb.String(), `"Provider":"ConvertibleSourceName"`)
+ source := &auth_model.Source{
+ Type: auth_model.OAuth2,
+ Name: "TestSource",
+ Cfg: &TestSource{TestField: "TestValue"},
+ }
+ require.NoError(t, auth_model.CreateSource(t.Context(), source))
+
+ // intentionally test the "dump" to make sure the dumped JSON is correct: https://github.com/go-gitea/gitea/pull/16847
+ sb := &strings.Builder{}
+ require.NoError(t, unittest.GetXORMEngine().DumpTables([]*schemas.Table{authSourceSchema}, sb))
+ // the dumped SQL is something like:
+ // INSERT INTO `login_source` (`id`, `type`, `name`, `is_active`, `is_sync_enabled`, `two_factor_policy`, `cfg`, `created_unix`, `updated_unix`) VALUES (1,6,'TestSource',0,0,'','{"TestField":"TestValue"}',1774179784,1774179784);
+ assert.Contains(t, sb.String(), `'{"TestField":"TestValue"}'`)
}
diff --git a/models/db/collation.go b/models/db/collation.go
index 79ade87380..203f7cbfe4 100644
--- a/models/db/collation.go
+++ b/models/db/collation.go
@@ -98,7 +98,7 @@ func CheckCollations(x *xorm.Engine) (*CheckCollationsResult, error) {
return nil, err
}
} else {
- return nil, nil
+ return nil, nil //nolint:nilnil // return nil for unsupported database types
}
if res.DatabaseCollation == "" {
diff --git a/models/db/common.go b/models/db/common.go
index ea628bf2a0..b3c43f8b62 100644
--- a/models/db/common.go
+++ b/models/db/common.go
@@ -12,30 +12,30 @@ import (
"xorm.io/builder"
)
-// BuildCaseInsensitiveLike returns a condition to check if the given value is like the given key case-insensitively.
-// Handles especially SQLite correctly as UPPER there only transforms ASCII letters.
+// BuildCaseInsensitiveLike returns a case-insensitive LIKE condition for the given key and value.
+// Cast the search value and the database column value to the same case for case-insensitive matching.
+// * SQLite: only cast ASCII chars because it doesn't handle complete Unicode case folding
+// * Other databases: use database's string function, assuming that they are able to handle complete Unicode case folding correctly
func BuildCaseInsensitiveLike(key, value string) builder.Cond {
+ // ToLowerASCII is about 7% faster than ToUpperASCII (according to Golang's benchmark)
if setting.Database.Type.IsSQLite3() {
- return builder.Like{"UPPER(" + key + ")", util.ToUpperASCII(value)}
+ return builder.Like{"LOWER(" + key + ")", util.ToLowerASCII(value)}
}
- return builder.Like{"UPPER(" + key + ")", strings.ToUpper(value)}
+ return builder.Like{"LOWER(" + key + ")", strings.ToLower(value)}
}
// BuildCaseInsensitiveIn returns a condition to check if the given value is in the given values case-insensitively.
-// Handles especially SQLite correctly as UPPER there only transforms ASCII letters.
+// See BuildCaseInsensitiveLike for more details
func BuildCaseInsensitiveIn(key string, values []string) builder.Cond {
- uppers := make([]string, 0, len(values))
+ incaseValues := make([]string, len(values))
+ caseCast := strings.ToLower
if setting.Database.Type.IsSQLite3() {
- for _, value := range values {
- uppers = append(uppers, util.ToUpperASCII(value))
- }
- } else {
- for _, value := range values {
- uppers = append(uppers, strings.ToUpper(value))
- }
+ caseCast = util.ToLowerASCII
}
-
- return builder.In("UPPER("+key+")", uppers)
+ for i, value := range values {
+ incaseValues[i] = caseCast(value)
+ }
+ return builder.In("LOWER("+key+")", incaseValues)
}
// BuilderDialect returns the xorm.Builder dialect of the engine
diff --git a/models/db/convert.go b/models/db/convert.go
index 80b0f7b04b..374dbfd8a8 100644
--- a/models/db/convert.go
+++ b/models/db/convert.go
@@ -5,12 +5,11 @@ package db
import (
"fmt"
- "strconv"
- "code.gitea.io/gitea/modules/log"
"code.gitea.io/gitea/modules/setting"
"xorm.io/xorm"
+ "xorm.io/xorm/convert"
"xorm.io/xorm/schemas"
)
@@ -74,15 +73,14 @@ WHERE ST.name ='varchar'`)
return err
}
-// Cell2Int64 converts a xorm.Cell type to int64,
-// and handles possible irregular cases.
-func Cell2Int64(val xorm.Cell) int64 {
- switch (*val).(type) {
- case []uint8:
- log.Trace("Cell2Int64 ([]uint8): %v", *val)
-
- v, _ := strconv.ParseInt(string((*val).([]uint8)), 10, 64)
- return v
+// CellToInt converts a xorm.Cell field value to an int value
+func CellToInt[T ~int | int64](cell xorm.Cell, def T) (ret T, has bool, err error) {
+ if *cell == nil {
+ return def, false, nil
+ }
+ val, err := convert.AsInt64(*cell)
+ if err != nil {
+ return def, false, err
}
- return (*val).(int64)
+ return T(val), true, err
}
diff --git a/models/db/engine_init.go b/models/db/engine_init.go
index f26189b805..ef5db3ff5e 100644
--- a/models/db/engine_init.go
+++ b/models/db/engine_init.go
@@ -57,7 +57,7 @@ func InitEngine(ctx context.Context) error {
xe, err := newXORMEngine()
if err != nil {
if strings.Contains(err.Error(), "SQLite3 support") {
- return fmt.Errorf(`sqlite3 requires: -tags sqlite,sqlite_unlock_notify%s%w`, "\n", err)
+ return fmt.Errorf("sqlite3 requires: -tags sqlite,sqlite_unlock_notify\n%w", err)
}
return fmt.Errorf("failed to connect to database: %w", err)
}
diff --git a/models/dbfs/dbfile.go b/models/dbfs/dbfile.go
index eaf506fbe6..a6981cb7d6 100644
--- a/models/dbfs/dbfile.go
+++ b/models/dbfs/dbfile.go
@@ -75,7 +75,7 @@ func (f *file) readAt(fileMeta *dbfsMeta, offset int64, p []byte) (n int, err er
}
func (f *file) Read(p []byte) (n int, err error) {
- if f.metaID == 0 || !f.allowRead {
+ if !f.allowRead {
return 0, os.ErrInvalid
}
@@ -89,7 +89,7 @@ func (f *file) Read(p []byte) (n int, err error) {
}
func (f *file) Write(p []byte) (n int, err error) {
- if f.metaID == 0 || !f.allowWrite {
+ if !f.allowWrite {
return 0, os.ErrInvalid
}
@@ -184,10 +184,6 @@ func (f *file) Close() error {
}
func (f *file) Stat() (os.FileInfo, error) {
- if f.metaID == 0 {
- return nil, os.ErrInvalid
- }
-
fileMeta, err := findFileMetaByID(f.ctx, f.metaID)
if err != nil {
return nil, err
@@ -232,15 +228,17 @@ func (f *file) open(flag int) (err error) {
if f.metaID != 0 {
return os.ErrExist
}
- } else {
- // create a new file if none exists.
- if f.metaID == 0 {
- if err = f.createEmpty(); err != nil {
- return err
- }
+ }
+ // create a new file if not exists.
+ if f.metaID == 0 {
+ if err = f.createEmpty(); err != nil {
+ return err
}
}
}
+ if f.metaID == 0 {
+ return os.ErrNotExist
+ }
if flag&os.O_TRUNC != 0 {
if err = f.truncate(); err != nil {
return err
@@ -252,7 +250,7 @@ func (f *file) open(flag int) (err error) {
}
}
return nil
- }
+ } // end if: allowWrite
// read only mode
if f.metaID == 0 {
@@ -322,9 +320,6 @@ func (f *file) delete() error {
}
func (f *file) size() (int64, error) {
- if f.metaID == 0 {
- return 0, os.ErrNotExist
- }
fileMeta, err := findFileMetaByID(f.ctx, f.metaID)
if err != nil {
return 0, err
@@ -339,7 +334,7 @@ func findFileMetaByID(ctx context.Context, metaID int64) (*dbfsMeta, error) {
} else if ok {
return &fileMeta, nil
}
- return nil, nil
+ return nil, os.ErrNotExist
}
func buildPath(path string) string {
diff --git a/models/dbfs/dbfs.go b/models/dbfs/dbfs.go
index f68b4a2b70..3f768b5339 100644
--- a/models/dbfs/dbfs.go
+++ b/models/dbfs/dbfs.go
@@ -40,6 +40,9 @@ The DBFS solution:
* In the future, when Gitea action needs to limit the log size (other CI/CD services also do so), it's easier to calculate the log file size.
* Even sometimes the UI needs to render the tailing lines, the tailing lines can be found be counting the "\n" from the end of the file by seek.
The seeking and finding is not the fastest way, but it's still acceptable and won't affect the performance too much.
+
+Limitations of the DBFS solution:
+* Not fully POSIX-compliant, some behaviors may be different from the real filesystem, especially for concurrent read/write
*/
type dbfsMeta struct {
diff --git a/models/dbfs/dbfs_test.go b/models/dbfs/dbfs_test.go
index e1ecd871e4..ca57ebe171 100644
--- a/models/dbfs/dbfs_test.go
+++ b/models/dbfs/dbfs_test.go
@@ -9,19 +9,14 @@ import (
"os"
"testing"
+ "code.gitea.io/gitea/modules/test"
+
"github.com/stretchr/testify/assert"
+ "github.com/stretchr/testify/require"
)
-func changeDefaultFileBlockSize(n int64) (restore func()) {
- old := defaultFileBlockSize
- defaultFileBlockSize = n
- return func() {
- defaultFileBlockSize = old
- }
-}
-
func TestDbfsBasic(t *testing.T) {
- defer changeDefaultFileBlockSize(4)()
+ defer test.MockVariableValue(&defaultFileBlockSize, 4)()
// test basic write/read
f, err := OpenFile(t.Context(), "test.txt", os.O_RDWR|os.O_CREATE)
@@ -122,10 +117,55 @@ func TestDbfsBasic(t *testing.T) {
stat, err = f.Stat()
assert.NoError(t, err)
assert.EqualValues(t, 10, stat.Size())
+
+ t.Run("NonExisting", func(t *testing.T) {
+ f, err := OpenFile(t.Context(), "non-existing.txt", os.O_RDONLY)
+ assert.ErrorIs(t, err, os.ErrNotExist)
+ assert.Nil(t, f)
+
+ f, err = OpenFile(t.Context(), "non-existing.txt", os.O_WRONLY)
+ assert.ErrorIs(t, err, os.ErrNotExist)
+ assert.Nil(t, f)
+
+ f, err = OpenFile(t.Context(), "non-existing.txt", os.O_WRONLY|os.O_APPEND|os.O_TRUNC)
+ assert.ErrorIs(t, err, os.ErrNotExist)
+ assert.Nil(t, f)
+ })
+
+ t.Run("Existing", func(t *testing.T) {
+ assertFileContent := func(f File, expected string) {
+ _, err := f.Seek(0, io.SeekStart)
+ require.NoError(t, err)
+ buf, err := io.ReadAll(f)
+ require.NoError(t, err)
+ assert.Equal(t, expected, string(buf))
+ }
+
+ f, err := OpenFile(t.Context(), "existing.txt", os.O_RDWR|os.O_CREATE)
+ require.NoError(t, err)
+ _, _ = f.Write([]byte("test"))
+ assertFileContent(f, "test")
+ assert.NoError(t, f.Close())
+
+ f, err = OpenFile(t.Context(), "existing.txt", os.O_RDWR|os.O_CREATE|os.O_APPEND)
+ require.NoError(t, err)
+ _, _ = f.Write([]byte("\nnew"))
+ assertFileContent(f, "test\nnew")
+ assert.NoError(t, f.Close())
+
+ f, err = OpenFile(t.Context(), "existing.txt", os.O_RDWR|os.O_TRUNC)
+ require.NoError(t, err)
+ assertFileContent(f, "")
+ assert.NoError(t, f.Close())
+
+ f, err = OpenFile(t.Context(), "existing.txt", os.O_RDWR|os.O_CREATE|os.O_EXCL)
+ assert.ErrorIs(t, err, os.ErrExist)
+ assert.Nil(t, f)
+ })
}
func TestDbfsReadWrite(t *testing.T) {
- defer changeDefaultFileBlockSize(4)()
+ defer test.MockVariableValue(&defaultFileBlockSize, 4)()
f1, err := OpenFile(t.Context(), "test.log", os.O_RDWR|os.O_CREATE)
assert.NoError(t, err)
@@ -157,30 +197,32 @@ func TestDbfsReadWrite(t *testing.T) {
}
func TestDbfsSeekWrite(t *testing.T) {
- defer changeDefaultFileBlockSize(4)()
+ defer test.MockVariableValue(&defaultFileBlockSize, 4)()
- f, err := OpenFile(t.Context(), "test2.log", os.O_RDWR|os.O_CREATE)
- assert.NoError(t, err)
- defer f.Close()
+ // write something
+ fw, err := OpenFile(t.Context(), "test2.log", os.O_RDWR|os.O_CREATE)
+ require.NoError(t, err)
+ defer fw.Close()
- n, err := f.Write([]byte("111"))
+ n, err := fw.Write([]byte("111"))
assert.NoError(t, err)
- _, err = f.Seek(int64(n), io.SeekStart)
+ _, err = fw.Seek(int64(n), io.SeekStart)
assert.NoError(t, err)
- _, err = f.Write([]byte("222"))
+ _, err = fw.Write([]byte("222"))
assert.NoError(t, err)
- _, err = f.Seek(int64(n), io.SeekStart)
+ _, err = fw.Seek(int64(n), io.SeekStart)
assert.NoError(t, err)
- _, err = f.Write([]byte("333"))
+ _, err = fw.Write([]byte("333"))
assert.NoError(t, err)
+ // then read it
fr, err := OpenFile(t.Context(), "test2.log", os.O_RDONLY)
- assert.NoError(t, err)
- defer f.Close()
+ require.NoError(t, err)
+ defer fr.Close()
buf, err := io.ReadAll(fr)
assert.NoError(t, err)
diff --git a/models/fixtures/action_artifact.yml b/models/fixtures/action_artifact.yml
index ee8ef0d5ce..a25dfc205c 100644
--- a/models/fixtures/action_artifact.yml
+++ b/models/fixtures/action_artifact.yml
@@ -141,3 +141,39 @@
created_unix: 1730330775
updated_unix: 1730330775
expired_unix: 1738106775
+
+-
+ id: 26
+ run_id: 792
+ runner_id: 1
+ repo_id: 4
+ owner_id: 1
+ commit_sha: c2d72f548424103f01ee1dc02889c1e2bff816b0
+ storage_path: "27/5/1730330775594233150.chunk"
+ file_size: 1024
+ file_compressed_size: 1024
+ content_encoding: "application/pdf"
+ artifact_path: "report.pdf"
+ artifact_name: "report.pdf"
+ status: 2
+ created_unix: 1730330775
+ updated_unix: 1730330775
+ expired_unix: 1738106775
+
+-
+ id: 27
+ run_id: 792
+ runner_id: 1
+ repo_id: 4
+ owner_id: 1
+ commit_sha: c2d72f548424103f01ee1dc02889c1e2bff816b0
+ storage_path: "27/5/1730330775594233150.chunk"
+ file_size: 1024
+ file_compressed_size: 1024
+ content_encoding: "application/html"
+ artifact_path: "report.html"
+ artifact_name: "report.html"
+ status: 2
+ created_unix: 1730330775
+ updated_unix: 1730330775
+ expired_unix: 1738106775
diff --git a/models/fixtures/attachment.yml b/models/fixtures/attachment.yml
index 7882d8bff2..570d4a27da 100644
--- a/models/fixtures/attachment.yml
+++ b/models/fixtures/attachment.yml
@@ -153,3 +153,16 @@
download_count: 0
size: 0
created_unix: 946684800
+
+-
+ id: 13
+ uuid: a0eebc99-9c0b-4ef8-bb6d-6bb9bd380a23
+ repo_id: 1
+ issue_id: 0
+ release_id: 4
+ uploader_id: 2
+ comment_id: 0
+ name: draft-attach
+ download_count: 0
+ size: 0
+ created_unix: 946684800
diff --git a/models/fixtures/badge.yml b/models/fixtures/badge.yml
new file mode 100644
index 0000000000..438cd0ca5d
--- /dev/null
+++ b/models/fixtures/badge.yml
@@ -0,0 +1,5 @@
+-
+ id: 1
+ slug: badge1
+ description: just a test badge
+ image_url: badge1.png
diff --git a/models/fixtures/branch.yml b/models/fixtures/branch.yml
index 717230149b..a17999091e 100644
--- a/models/fixtures/branch.yml
+++ b/models/fixtures/branch.yml
@@ -225,3 +225,27 @@
is_deleted: false
deleted_by_id: 0
deleted_unix: 0
+
+-
+ id: 27
+ repo_id: 1
+ name: 'DefaultBranch'
+ commit_id: '90c1019714259b24fb81711d4416ac0f18667dfa'
+ commit_message: 'add license'
+ commit_time: 1709345946
+ pusher_id: 1
+ is_deleted: false
+ deleted_by_id: 0
+ deleted_unix: 0
+
+-
+ id: 28
+ repo_id: 1
+ name: 'sub-home-md-img-check'
+ commit_id: '4649299398e4d39a5c09eb4f534df6f1e1eb87cc'
+ commit_message: "Test how READMEs render images when found in a subfolder"
+ commit_time: 1678403550
+ pusher_id: 1
+ is_deleted: false
+ deleted_by_id: 0
+ deleted_unix: 0
diff --git a/models/git/branch.go b/models/git/branch.go
index 7fef9f5ca3..698c43f147 100644
--- a/models/git/branch.go
+++ b/models/git/branch.go
@@ -247,7 +247,7 @@ func DeleteBranches(ctx context.Context, repoID, doerID int64, branchIDs []int64
return err
}
for _, branch := range branches {
- if err := AddDeletedBranch(ctx, repoID, branch.Name, doerID); err != nil {
+ if err := MarkBranchAsDeleted(ctx, repoID, branch.Name, doerID); err != nil {
return err
}
}
@@ -268,8 +268,8 @@ func UpdateBranch(ctx context.Context, repoID, pusherID int64, branchName string
})
}
-// AddDeletedBranch adds a deleted branch to the database
-func AddDeletedBranch(ctx context.Context, repoID int64, branchName string, deletedByID int64) error {
+// MarkBranchAsDeleted marks branch as deleted
+func MarkBranchAsDeleted(ctx context.Context, repoID int64, branchName string, deletedByID int64) error {
branch, err := GetBranch(ctx, repoID, branchName)
if err != nil {
return err
@@ -397,10 +397,16 @@ func RenameBranch(ctx context.Context, repo *repo_model.Repository, from, to str
if protectedBranch != nil {
// there is a protect rule for this branch
- protectedBranch.RuleName = to
- if _, err = sess.ID(protectedBranch.ID).Cols("branch_name").Update(protectedBranch); err != nil {
+ existingRule, err := GetProtectedBranchRuleByName(ctx, repo.ID, to)
+ if err != nil {
return err
}
+ if existingRule == nil || existingRule.ID == protectedBranch.ID {
+ protectedBranch.RuleName = to
+ if _, err = sess.ID(protectedBranch.ID).Cols("branch_name").Update(protectedBranch); err != nil {
+ return err
+ }
+ }
} else {
// some glob protect rules may match this branch
protected, err := IsBranchProtected(ctx, repo.ID, from)
@@ -444,7 +450,7 @@ func RenameBranch(ctx context.Context, repo *repo_model.Repository, from, to str
type FindRecentlyPushedNewBranchesOptions struct {
Repo *repo_model.Repository
BaseRepo *repo_model.Repository
- CommitAfterUnix int64
+ PushedAfterUnix int64
MaxCount int
}
@@ -454,11 +460,11 @@ type RecentlyPushedNewBranch struct {
BranchDisplayName string
BranchLink string
BranchCompareURL string
- CommitTime timeutil.TimeStamp
+ PushedTime timeutil.TimeStamp
}
// FindRecentlyPushedNewBranches return at most 2 new branches pushed by the user in 2 hours which has no opened PRs created
-// if opts.CommitAfterUnix is 0, we will find the branches that were committed to in the last 2 hours
+// if opts.PushedAfterUnix is 0, we will find the branches that were pushed in the last 2 hours
// if opts.ListOptions is not set, we will only display top 2 latest branches.
// Protected branches will be skipped since they are unlikely to be used to create new PRs.
func FindRecentlyPushedNewBranches(ctx context.Context, doer *user_model.User, opts FindRecentlyPushedNewBranchesOptions) ([]*RecentlyPushedNewBranch, error) {
@@ -486,16 +492,29 @@ func FindRecentlyPushedNewBranches(ctx context.Context, doer *user_model.User, o
}
repoIDs := builder.Select("id").From("repository").Where(repoCond)
- if opts.CommitAfterUnix == 0 {
- opts.CommitAfterUnix = time.Now().Add(-time.Hour * 2).Unix()
+ if opts.PushedAfterUnix == 0 {
+ opts.PushedAfterUnix = time.Now().Add(-time.Hour * 2).Unix()
}
- baseBranch, err := GetBranch(ctx, opts.BaseRepo.ID, opts.BaseRepo.DefaultBranch)
+ var ignoredCommitIDs []string
+ baseDefaultBranch, err := GetBranch(ctx, opts.BaseRepo.ID, opts.BaseRepo.DefaultBranch)
if err != nil {
- return nil, err
+ log.Warn("GetBranch:DefaultBranch: %v", err)
+ } else {
+ ignoredCommitIDs = append(ignoredCommitIDs, baseDefaultBranch.CommitID)
+ }
+
+ baseDefaultTargetBranchName := opts.BaseRepo.MustGetUnit(ctx, unit.TypePullRequests).PullRequestsConfig().DefaultTargetBranch
+ if baseDefaultTargetBranchName != "" && baseDefaultTargetBranchName != opts.BaseRepo.DefaultBranch {
+ baseDefaultTargetBranch, err := GetBranch(ctx, opts.BaseRepo.ID, baseDefaultTargetBranchName)
+ if err != nil {
+ log.Warn("GetBranch:DefaultTargetBranch: %v", err)
+ } else {
+ ignoredCommitIDs = append(ignoredCommitIDs, baseDefaultTargetBranch.CommitID)
+ }
}
- // find all related branches, these branches may already created PRs, we will check later
+ // find all related branches, these branches may already have PRs, we will check later
var branches []*Branch
if err := db.GetEngine(ctx).
Where(builder.And(
@@ -503,10 +522,10 @@ func FindRecentlyPushedNewBranches(ctx context.Context, doer *user_model.User, o
"pusher_id": doer.ID,
"is_deleted": false,
},
- builder.Gte{"commit_time": opts.CommitAfterUnix},
+ builder.Gte{"updated_unix": opts.PushedAfterUnix},
builder.In("repo_id", repoIDs),
// newly created branch have no changes, so skip them
- builder.Neq{"commit_id": baseBranch.CommitID},
+ builder.NotIn("commit_id", ignoredCommitIDs),
)).
OrderBy(db.SearchOrderByRecentUpdated.String()).
Find(&branches); err != nil {
@@ -514,10 +533,8 @@ func FindRecentlyPushedNewBranches(ctx context.Context, doer *user_model.User, o
}
newBranches := make([]*RecentlyPushedNewBranch, 0, len(branches))
- if opts.MaxCount == 0 {
- // by default we display 2 recently pushed new branch
- opts.MaxCount = 2
- }
+ opts.MaxCount = util.IfZero(opts.MaxCount, 2) // by default, we display 2 recently pushed new branch
+ baseTargetBranchName := opts.BaseRepo.GetPullRequestTargetBranch(ctx)
for _, branch := range branches {
// whether the branch is protected
protected, err := IsBranchProtected(ctx, branch.RepoID, branch.Name)
@@ -555,8 +572,8 @@ func FindRecentlyPushedNewBranches(ctx context.Context, doer *user_model.User, o
BranchDisplayName: branchDisplayName,
BranchName: branch.Name,
BranchLink: fmt.Sprintf("%s/src/branch/%s", branch.Repo.Link(), util.PathEscapeSegments(branch.Name)),
- BranchCompareURL: branch.Repo.ComposeBranchCompareURL(opts.BaseRepo, branch.Name),
- CommitTime: branch.CommitTime,
+ BranchCompareURL: branch.Repo.ComposeBranchCompareURL(opts.BaseRepo, baseTargetBranchName, branch.Name),
+ PushedTime: branch.UpdatedUnix,
})
}
if len(newBranches) == opts.MaxCount {
@@ -566,3 +583,12 @@ func FindRecentlyPushedNewBranches(ctx context.Context, doer *user_model.User, o
return newBranches, nil
}
+
+// CountBranches returns the number of branches in the repository
+func CountBranches(ctx context.Context, repoID int64, includeDeleted bool) (int64, error) {
+ sess := db.GetEngine(ctx).Where("repo_id=?", repoID)
+ if !includeDeleted {
+ sess.And("is_deleted=?", false)
+ }
+ return sess.Count(new(Branch))
+}
diff --git a/models/git/branch_test.go b/models/git/branch_test.go
index 5be435172b..3832df9350 100644
--- a/models/git/branch_test.go
+++ b/models/git/branch_test.go
@@ -6,14 +6,17 @@ package git_test
import (
"context"
"testing"
+ "time"
"code.gitea.io/gitea/models/db"
git_model "code.gitea.io/gitea/models/git"
issues_model "code.gitea.io/gitea/models/issues"
repo_model "code.gitea.io/gitea/models/repo"
"code.gitea.io/gitea/models/unittest"
+ user_model "code.gitea.io/gitea/models/user"
"code.gitea.io/gitea/modules/git"
"code.gitea.io/gitea/modules/optional"
+ "code.gitea.io/gitea/modules/timeutil"
"github.com/stretchr/testify/assert"
)
@@ -25,8 +28,8 @@ func TestAddDeletedBranch(t *testing.T) {
firstBranch := unittest.AssertExistsAndLoadBean(t, &git_model.Branch{ID: 1})
assert.True(t, firstBranch.IsDeleted)
- assert.NoError(t, git_model.AddDeletedBranch(t.Context(), repo.ID, firstBranch.Name, firstBranch.DeletedByID))
- assert.NoError(t, git_model.AddDeletedBranch(t.Context(), repo.ID, "branch2", int64(1)))
+ assert.NoError(t, git_model.MarkBranchAsDeleted(t.Context(), repo.ID, firstBranch.Name, firstBranch.DeletedByID))
+ assert.NoError(t, git_model.MarkBranchAsDeleted(t.Context(), repo.ID, "branch2", int64(1)))
secondBranch := unittest.AssertExistsAndLoadBean(t, &git_model.Branch{RepoID: repo.ID, Name: "branch2"})
assert.True(t, secondBranch.IsDeleted)
@@ -63,6 +66,36 @@ func TestGetDeletedBranch(t *testing.T) {
assert.NotNil(t, getDeletedBranch(t, firstBranch))
}
+func TestFindRecentlyPushedNewBranchesUsesPushTime(t *testing.T) {
+ assert.NoError(t, unittest.PrepareTestDatabase())
+
+ repo := unittest.AssertExistsAndLoadBean(t, &repo_model.Repository{ID: 10})
+ doer := unittest.AssertExistsAndLoadBean(t, &user_model.User{ID: 12})
+ branch := unittest.AssertExistsAndLoadBean(t, &git_model.Branch{RepoID: repo.ID, Name: "outdated-new-branch"})
+
+ commitUnix := time.Now().Add(-3 * time.Hour).Unix()
+ pushUnix := time.Now().Add(-30 * time.Minute).Unix()
+ _, err := db.GetEngine(t.Context()).Exec(
+ "UPDATE branch SET commit_time = ?, updated_unix = ? WHERE id = ?",
+ commitUnix,
+ pushUnix,
+ branch.ID,
+ )
+ assert.NoError(t, err)
+
+ branches, err := git_model.FindRecentlyPushedNewBranches(t.Context(), doer, git_model.FindRecentlyPushedNewBranchesOptions{
+ Repo: repo,
+ BaseRepo: repo,
+ PushedAfterUnix: time.Now().Add(-time.Hour).Unix(),
+ MaxCount: 1,
+ })
+ assert.NoError(t, err)
+ if assert.Len(t, branches, 1) {
+ assert.Equal(t, branch.Name, branches[0].BranchName)
+ assert.Equal(t, timeutil.TimeStamp(pushUnix), branches[0].PushedTime)
+ }
+}
+
func TestDeletedBranchLoadUser(t *testing.T) {
assert.NoError(t, unittest.PrepareTestDatabase())
@@ -114,7 +147,7 @@ func TestFindRenamedBranch(t *testing.T) {
assert.True(t, exist)
assert.Equal(t, "master", branch.To)
- _, exist, err = git_model.FindRenamedBranch(t.Context(), 1, "unknow")
+ _, exist, err = git_model.FindRenamedBranch(t.Context(), 1, "unknown")
assert.NoError(t, err)
assert.False(t, exist)
}
@@ -159,6 +192,53 @@ func TestRenameBranch(t *testing.T) {
})
}
+func TestRenameBranchProtectedRuleConflict(t *testing.T) {
+ assert.NoError(t, unittest.PrepareTestDatabase())
+ repo1 := unittest.AssertExistsAndLoadBean(t, &repo_model.Repository{ID: 1})
+ master := unittest.AssertExistsAndLoadBean(t, &git_model.Branch{RepoID: repo1.ID, Name: "master"})
+
+ devBranch := &git_model.Branch{
+ RepoID: repo1.ID,
+ Name: "dev",
+ CommitID: master.CommitID,
+ CommitMessage: master.CommitMessage,
+ CommitTime: master.CommitTime,
+ PusherID: master.PusherID,
+ }
+ assert.NoError(t, db.Insert(t.Context(), devBranch))
+
+ pbDev := git_model.ProtectedBranch{
+ RepoID: repo1.ID,
+ RuleName: "dev",
+ CanPush: true,
+ }
+ assert.NoError(t, git_model.UpdateProtectBranch(t.Context(), repo1, &pbDev, git_model.WhitelistOptions{}))
+
+ pbMain := git_model.ProtectedBranch{
+ RepoID: repo1.ID,
+ RuleName: "main",
+ CanPush: true,
+ }
+ assert.NoError(t, git_model.UpdateProtectBranch(t.Context(), repo1, &pbMain, git_model.WhitelistOptions{}))
+
+ assert.NoError(t, git_model.RenameBranch(t.Context(), repo1, "dev", "main", func(ctx context.Context, isDefault bool) error {
+ return nil
+ }))
+
+ unittest.AssertNotExistsBean(t, &git_model.Branch{RepoID: repo1.ID, Name: "dev"})
+ unittest.AssertExistsAndLoadBean(t, &git_model.Branch{RepoID: repo1.ID, Name: "main"})
+
+ protectedDev, err := git_model.GetProtectedBranchRuleByName(t.Context(), repo1.ID, "dev")
+ assert.NoError(t, err)
+ assert.NotNil(t, protectedDev)
+ assert.Equal(t, "dev", protectedDev.RuleName)
+
+ protectedMainByID, err := git_model.GetProtectedBranchRuleByID(t.Context(), repo1.ID, pbMain.ID)
+ assert.NoError(t, err)
+ assert.NotNil(t, protectedMainByID)
+ assert.Equal(t, "main", protectedMainByID.RuleName)
+}
+
func TestOnlyGetDeletedBranchOnCorrectRepo(t *testing.T) {
assert.NoError(t, unittest.PrepareTestDatabase())
@@ -183,3 +263,25 @@ func TestOnlyGetDeletedBranchOnCorrectRepo(t *testing.T) {
assert.NoError(t, err)
assert.NotNil(t, deletedBranch)
}
+
+func TestCountBranches(t *testing.T) {
+ // 1. Setup - Exactly like TestAddDeletedBranch
+ assert.NoError(t, unittest.PrepareTestDatabase())
+ repo := unittest.AssertExistsAndLoadBean(t, &repo_model.Repository{ID: 1})
+
+ // 2. Execution - Using t.Context() to match the rest of the file
+ initialCount, err := git_model.CountBranches(t.Context(), repo.ID, false)
+ assert.NoError(t, err)
+
+ // 3. Database Action - Using t.Context()
+ err = db.Insert(t.Context(), &git_model.Branch{
+ RepoID: repo.ID,
+ Name: "test-branch-for-counting",
+ })
+ assert.NoError(t, err)
+
+ // 4. Verification
+ newCount, err := git_model.CountBranches(t.Context(), repo.ID, false)
+ assert.NoError(t, err)
+ assert.Equal(t, initialCount+1, newCount)
+}
diff --git a/models/git/commit_status.go b/models/git/commit_status.go
index e255bca5d0..2ae5937a3d 100644
--- a/models/git/commit_status.go
+++ b/models/git/commit_status.go
@@ -30,17 +30,21 @@ import (
// CommitStatus holds a single Status of a single Commit
type CommitStatus struct {
- ID int64 `xorm:"pk autoincr"`
- Index int64 `xorm:"INDEX UNIQUE(repo_sha_index)"`
- RepoID int64 `xorm:"INDEX UNIQUE(repo_sha_index)"`
- Repo *repo_model.Repository `xorm:"-"`
- State commitstatus.CommitStatusState `xorm:"VARCHAR(7) NOT NULL"`
- SHA string `xorm:"VARCHAR(64) NOT NULL INDEX UNIQUE(repo_sha_index)"`
- TargetURL string `xorm:"TEXT"`
- Description string `xorm:"TEXT"`
- ContextHash string `xorm:"VARCHAR(64) index"`
- Context string `xorm:"TEXT"`
- Creator *user_model.User `xorm:"-"`
+ ID int64 `xorm:"pk autoincr"`
+ Index int64 `xorm:"INDEX UNIQUE(repo_sha_index)"`
+ RepoID int64 `xorm:"INDEX UNIQUE(repo_sha_index)"`
+ Repo *repo_model.Repository `xorm:"-"`
+ State commitstatus.CommitStatusState `xorm:"VARCHAR(7) NOT NULL"`
+ SHA string `xorm:"VARCHAR(64) NOT NULL INDEX UNIQUE(repo_sha_index)"`
+
+ // TargetURL points to the commit status page reported by a CI system
+ // If Gitea Actions is used, it is a relative link like "{RepoLink}/actions/runs/{RunID}/jobs{JobID}"
+ TargetURL string `xorm:"TEXT"`
+
+ Description string `xorm:"TEXT"`
+ ContextHash string `xorm:"VARCHAR(64) index"`
+ Context string `xorm:"TEXT"`
+ Creator *user_model.User `xorm:"-"`
CreatorID int64
CreatedUnix timeutil.TimeStamp `xorm:"INDEX created"`
@@ -211,21 +215,45 @@ func (status *CommitStatus) LocaleString(lang translation.Locale) string {
// HideActionsURL set `TargetURL` to an empty string if the status comes from Gitea Actions
func (status *CommitStatus) HideActionsURL(ctx context.Context) {
+ if _, ok := status.cutTargetURLGiteaActionsPrefix(ctx); ok {
+ status.TargetURL = ""
+ }
+}
+
+func (status *CommitStatus) cutTargetURLGiteaActionsPrefix(ctx context.Context) (string, bool) {
if status.RepoID == 0 {
- return
+ return "", false
}
if status.Repo == nil {
if err := status.loadRepository(ctx); err != nil {
log.Error("loadRepository: %v", err)
- return
+ return "", false
}
}
prefix := status.Repo.Link() + "/actions"
- if strings.HasPrefix(status.TargetURL, prefix) {
- status.TargetURL = ""
+ return strings.CutPrefix(status.TargetURL, prefix)
+}
+
+// ParseGiteaActionsTargetURL parses the commit status target URL as Gitea Actions link
+func (status *CommitStatus) ParseGiteaActionsTargetURL(ctx context.Context) (runID, jobID int64, ok bool) {
+ s, ok := status.cutTargetURLGiteaActionsPrefix(ctx)
+ if !ok {
+ return 0, 0, false
+ }
+
+ parts := strings.Split(s, "/") // expect: /runs/{runID}/jobs/{jobID}
+ if len(parts) < 5 || parts[1] != "runs" || parts[3] != "jobs" {
+ return 0, 0, false
+ }
+
+ runID, err1 := strconv.ParseInt(parts[2], 10, 64)
+ jobID, err2 := strconv.ParseInt(parts[4], 10, 64)
+ if err1 != nil || err2 != nil {
+ return 0, 0, false
}
+ return runID, jobID, true
}
// CalcCommitStatus returns commit status state via some status, the commit statues should order by id desc
diff --git a/models/git/commit_status_test.go b/models/git/commit_status_test.go
index d1b9dfc3bf..f18d3470b0 100644
--- a/models/git/commit_status_test.go
+++ b/models/git/commit_status_test.go
@@ -139,7 +139,7 @@ func Test_CalcCommitStatus(t *testing.T) {
},
},
expected: &git_model.CommitStatus{
- State: commitstatus.CommitStatusPending,
+ State: commitstatus.CommitStatusFailure,
},
},
{
@@ -243,7 +243,7 @@ func TestCommitStatusesHideActionsURL(t *testing.T) {
statuses := []*git_model.CommitStatus{
{
RepoID: repo.ID,
- TargetURL: fmt.Sprintf("%s/jobs/%d", run.Link(), run.Index),
+ TargetURL: fmt.Sprintf("%s/jobs/%d", run.Link(), run.ID),
},
{
RepoID: repo.ID,
diff --git a/models/git/lfs.go b/models/git/lfs.go
index 8bba060ff9..1f3d086ac2 100644
--- a/models/git/lfs.go
+++ b/models/git/lfs.go
@@ -8,7 +8,6 @@ import (
"fmt"
"code.gitea.io/gitea/models/db"
- "code.gitea.io/gitea/models/perm"
repo_model "code.gitea.io/gitea/models/repo"
"code.gitea.io/gitea/models/unit"
user_model "code.gitea.io/gitea/models/user"
@@ -42,30 +41,6 @@ func (err ErrLFSLockNotExist) Unwrap() error {
return util.ErrNotExist
}
-// ErrLFSUnauthorizedAction represents a "LFSUnauthorizedAction" kind of error.
-type ErrLFSUnauthorizedAction struct {
- RepoID int64
- UserName string
- Mode perm.AccessMode
-}
-
-// IsErrLFSUnauthorizedAction checks if an error is a ErrLFSUnauthorizedAction.
-func IsErrLFSUnauthorizedAction(err error) bool {
- _, ok := err.(ErrLFSUnauthorizedAction)
- return ok
-}
-
-func (err ErrLFSUnauthorizedAction) Error() string {
- if err.Mode == perm.AccessModeWrite {
- return fmt.Sprintf("User %s doesn't have write access for lfs lock [rid: %d]", err.UserName, err.RepoID)
- }
- return fmt.Sprintf("User %s doesn't have read access for lfs lock [rid: %d]", err.UserName, err.RepoID)
-}
-
-func (err ErrLFSUnauthorizedAction) Unwrap() error {
- return util.ErrPermissionDenied
-}
-
// ErrLFSLockAlreadyExist represents a "LFSLockAlreadyExist" kind of error.
type ErrLFSLockAlreadyExist struct {
RepoID int64
@@ -93,12 +68,6 @@ type ErrLFSFileLocked struct {
UserName string
}
-// IsErrLFSFileLocked checks if an error is a ErrLFSFileLocked.
-func IsErrLFSFileLocked(err error) bool {
- _, ok := err.(ErrLFSFileLocked)
- return ok
-}
-
func (err ErrLFSFileLocked) Error() string {
return fmt.Sprintf("File is lfs locked [repo: %d, locked by: %s, path: %s]", err.RepoID, err.UserName, err.Path)
}
@@ -343,15 +312,12 @@ func IterateRepositoryIDsWithLFSMetaObjects(ctx context.Context, f func(ctx cont
// IterateLFSMetaObjectsForRepoOptions provides options for IterateLFSMetaObjectsForRepo
type IterateLFSMetaObjectsForRepoOptions struct {
- OlderThan timeutil.TimeStamp
- UpdatedLessRecentlyThan timeutil.TimeStamp
- OrderByUpdated bool
- LoopFunctionAlwaysUpdates bool
+ OlderThan timeutil.TimeStamp
+ UpdatedLessRecentlyThan timeutil.TimeStamp
}
// IterateLFSMetaObjectsForRepo provides a iterator for LFSMetaObjects per Repo
func IterateLFSMetaObjectsForRepo(ctx context.Context, repoID int64, f func(context.Context, *LFSMetaObject, int64) error, opts *IterateLFSMetaObjectsForRepoOptions) error {
- var start int
batchSize := setting.Database.IterateBufferSize
engine := db.GetEngine(ctx)
type CountLFSMetaObject struct {
@@ -359,7 +325,7 @@ func IterateLFSMetaObjectsForRepo(ctx context.Context, repoID int64, f func(cont
LFSMetaObject `xorm:"extends"`
}
- id := int64(0)
+ lastID := int64(0)
for {
beans := make([]*CountLFSMetaObject, 0, batchSize)
@@ -372,29 +338,23 @@ func IterateLFSMetaObjectsForRepo(ctx context.Context, repoID int64, f func(cont
if !opts.UpdatedLessRecentlyThan.IsZero() {
sess.And("`lfs_meta_object`.updated_unix < ?", opts.UpdatedLessRecentlyThan)
}
- sess.GroupBy("`lfs_meta_object`.id")
- if opts.OrderByUpdated {
- sess.OrderBy("`lfs_meta_object`.updated_unix ASC")
- } else {
- sess.And("`lfs_meta_object`.id > ?", id)
- sess.OrderBy("`lfs_meta_object`.id ASC")
- }
- if err := sess.Limit(batchSize, start).Find(&beans); err != nil {
+ sess.GroupBy("`lfs_meta_object`.id").
+ And("`lfs_meta_object`.id > ?", lastID).
+ OrderBy("`lfs_meta_object`.id ASC")
+
+ if err := sess.Limit(batchSize).Find(&beans); err != nil {
return err
}
if len(beans) == 0 {
return nil
}
- if !opts.LoopFunctionAlwaysUpdates {
- start += len(beans)
- }
for _, bean := range beans {
if err := f(ctx, &bean.LFSMetaObject, bean.Count); err != nil {
return err
}
}
- id = beans[len(beans)-1].ID
+ lastID = beans[len(beans)-1].ID
}
}
diff --git a/models/git/lfs_lock.go b/models/git/lfs_lock.go
index c5f9a4e6de..8e63598fb2 100644
--- a/models/git/lfs_lock.go
+++ b/models/git/lfs_lock.go
@@ -11,10 +11,7 @@ import (
"time"
"code.gitea.io/gitea/models/db"
- "code.gitea.io/gitea/models/perm"
- access_model "code.gitea.io/gitea/models/perm/access"
repo_model "code.gitea.io/gitea/models/repo"
- "code.gitea.io/gitea/models/unit"
user_model "code.gitea.io/gitea/models/user"
"code.gitea.io/gitea/modules/setting"
"code.gitea.io/gitea/modules/util"
@@ -71,10 +68,6 @@ func (l *LFSLock) LoadOwner(ctx context.Context) error {
// CreateLFSLock creates a new lock.
func CreateLFSLock(ctx context.Context, repo *repo_model.Repository, lock *LFSLock) (*LFSLock, error) {
return db.WithTx2(ctx, func(ctx context.Context) (*LFSLock, error) {
- if err := CheckLFSAccessForRepo(ctx, lock.OwnerID, repo, perm.AccessModeWrite); err != nil {
- return nil, err
- }
-
lock.Path = util.PathJoinRel(lock.Path)
lock.RepoID = repo.ID
@@ -108,10 +101,10 @@ func GetLFSLock(ctx context.Context, repo *repo_model.Repository, path string) (
return rel, nil
}
-// GetLFSLockByID returns release by given id.
-func GetLFSLockByID(ctx context.Context, id int64) (*LFSLock, error) {
+// GetLFSLockByIDAndRepo returns lfs lock by given id and repository id.
+func GetLFSLockByIDAndRepo(ctx context.Context, id, repoID int64) (*LFSLock, error) {
lock := new(LFSLock)
- has, err := db.GetEngine(ctx).ID(id).Get(lock)
+ has, err := db.GetEngine(ctx).ID(id).And("repo_id = ?", repoID).Get(lock)
if err != nil {
return nil, err
} else if !has {
@@ -137,7 +130,7 @@ func GetLFSLockByRepoID(ctx context.Context, repoID int64, page, pageSize int) (
// GetTreePathLock returns LSF lock for the treePath
func GetTreePathLock(ctx context.Context, repoID int64, treePath string) (*LFSLock, error) {
if !setting.LFS.StartServer {
- return nil, nil
+ return nil, nil //nolint:nilnil // return nil when LFS is not started
}
locks, err := GetLFSLockByRepoID(ctx, repoID, 0, 0)
@@ -149,7 +142,7 @@ func GetTreePathLock(ctx context.Context, repoID int64, treePath string) (*LFSLo
return lock, nil
}
}
- return nil, nil
+ return nil, nil //nolint:nilnil // return nil to indicate that the object does not exist
}
// CountLFSLockByRepoID returns a count of all LFSLocks associated with a repository.
@@ -160,15 +153,11 @@ func CountLFSLockByRepoID(ctx context.Context, repoID int64) (int64, error) {
// DeleteLFSLockByID deletes a lock by given ID.
func DeleteLFSLockByID(ctx context.Context, id int64, repo *repo_model.Repository, u *user_model.User, force bool) (*LFSLock, error) {
return db.WithTx2(ctx, func(ctx context.Context) (*LFSLock, error) {
- lock, err := GetLFSLockByID(ctx, id)
+ lock, err := GetLFSLockByIDAndRepo(ctx, id, repo.ID)
if err != nil {
return nil, err
}
- if err := CheckLFSAccessForRepo(ctx, u.ID, repo, perm.AccessModeWrite); err != nil {
- return nil, err
- }
-
if !force && u.ID != lock.OwnerID {
return nil, errors.New("user doesn't own lock and force flag is not set")
}
@@ -180,22 +169,3 @@ func DeleteLFSLockByID(ctx context.Context, id int64, repo *repo_model.Repositor
return lock, nil
})
}
-
-// CheckLFSAccessForRepo check needed access mode base on action
-func CheckLFSAccessForRepo(ctx context.Context, ownerID int64, repo *repo_model.Repository, mode perm.AccessMode) error {
- if ownerID == 0 {
- return ErrLFSUnauthorizedAction{repo.ID, "undefined", mode}
- }
- u, err := user_model.GetUserByID(ctx, ownerID)
- if err != nil {
- return err
- }
- perm, err := access_model.GetUserRepoPermission(ctx, repo, u)
- if err != nil {
- return err
- }
- if !perm.CanAccess(mode, unit.TypeCode) {
- return ErrLFSUnauthorizedAction{repo.ID, u.DisplayName(), mode}
- }
- return nil
-}
diff --git a/models/git/lfs_lock_test.go b/models/git/lfs_lock_test.go
new file mode 100644
index 0000000000..c88e89be47
--- /dev/null
+++ b/models/git/lfs_lock_test.go
@@ -0,0 +1,82 @@
+// Copyright 2026 The Gitea Authors. All rights reserved.
+// SPDX-License-Identifier: MIT
+
+package git
+
+import (
+ "fmt"
+ "testing"
+ "time"
+
+ repo_model "code.gitea.io/gitea/models/repo"
+ "code.gitea.io/gitea/models/unittest"
+ user_model "code.gitea.io/gitea/models/user"
+
+ "github.com/stretchr/testify/assert"
+ "github.com/stretchr/testify/require"
+)
+
+func createTestLock(t *testing.T, repo *repo_model.Repository, owner *user_model.User) *LFSLock {
+ t.Helper()
+
+ path := fmt.Sprintf("%s-%d-%d", t.Name(), repo.ID, time.Now().UnixNano())
+ lock, err := CreateLFSLock(t.Context(), repo, &LFSLock{
+ OwnerID: owner.ID,
+ Path: path,
+ })
+ require.NoError(t, err)
+ return lock
+}
+
+func TestGetLFSLockByIDAndRepo(t *testing.T) {
+ require.NoError(t, unittest.PrepareTestDatabase())
+
+ repo1 := unittest.AssertExistsAndLoadBean(t, &repo_model.Repository{ID: 1})
+ repo3 := unittest.AssertExistsAndLoadBean(t, &repo_model.Repository{ID: 3})
+ user2 := unittest.AssertExistsAndLoadBean(t, &user_model.User{ID: 2})
+ user4 := unittest.AssertExistsAndLoadBean(t, &user_model.User{ID: 4})
+
+ lockRepo1 := createTestLock(t, repo1, user2)
+ lockRepo3 := createTestLock(t, repo3, user4)
+
+ fetched, err := GetLFSLockByIDAndRepo(t.Context(), lockRepo1.ID, repo1.ID)
+ require.NoError(t, err)
+ assert.Equal(t, lockRepo1.ID, fetched.ID)
+ assert.Equal(t, repo1.ID, fetched.RepoID)
+
+ _, err = GetLFSLockByIDAndRepo(t.Context(), lockRepo1.ID, repo3.ID)
+ assert.Error(t, err)
+ assert.True(t, IsErrLFSLockNotExist(err))
+
+ _, err = GetLFSLockByIDAndRepo(t.Context(), lockRepo3.ID, repo1.ID)
+ assert.Error(t, err)
+ assert.True(t, IsErrLFSLockNotExist(err))
+}
+
+func TestDeleteLFSLockByIDRequiresRepoMatch(t *testing.T) {
+ require.NoError(t, unittest.PrepareTestDatabase())
+
+ repo1 := unittest.AssertExistsAndLoadBean(t, &repo_model.Repository{ID: 1})
+ repo3 := unittest.AssertExistsAndLoadBean(t, &repo_model.Repository{ID: 3})
+ user2 := unittest.AssertExistsAndLoadBean(t, &user_model.User{ID: 2})
+ user4 := unittest.AssertExistsAndLoadBean(t, &user_model.User{ID: 4})
+
+ lockRepo1 := createTestLock(t, repo1, user2)
+ lockRepo3 := createTestLock(t, repo3, user4)
+
+ _, err := DeleteLFSLockByID(t.Context(), lockRepo3.ID, repo1, user2, true)
+ assert.Error(t, err)
+ assert.True(t, IsErrLFSLockNotExist(err))
+
+ existing, err := GetLFSLockByIDAndRepo(t.Context(), lockRepo3.ID, repo3.ID)
+ require.NoError(t, err)
+ assert.Equal(t, lockRepo3.ID, existing.ID)
+
+ deleted, err := DeleteLFSLockByID(t.Context(), lockRepo3.ID, repo3, user4, true)
+ require.NoError(t, err)
+ assert.Equal(t, lockRepo3.ID, deleted.ID)
+
+ deleted, err = DeleteLFSLockByID(t.Context(), lockRepo1.ID, repo1, user2, false)
+ require.NoError(t, err)
+ assert.Equal(t, lockRepo1.ID, deleted.ID)
+}
diff --git a/models/git/lfs_test.go b/models/git/lfs_test.go
new file mode 100644
index 0000000000..4c0242f439
--- /dev/null
+++ b/models/git/lfs_test.go
@@ -0,0 +1,61 @@
+// Copyright 2026 The Gitea Authors. All rights reserved.
+// SPDX-License-Identifier: MIT
+
+package git_test
+
+import (
+ "bytes"
+ "context"
+ "strconv"
+ "testing"
+ "time"
+
+ "code.gitea.io/gitea/models/db"
+ git_model "code.gitea.io/gitea/models/git"
+ repo_model "code.gitea.io/gitea/models/repo"
+ "code.gitea.io/gitea/models/unittest"
+ "code.gitea.io/gitea/modules/lfs"
+ "code.gitea.io/gitea/modules/setting"
+ "code.gitea.io/gitea/modules/test"
+ "code.gitea.io/gitea/modules/timeutil"
+
+ "github.com/stretchr/testify/assert"
+)
+
+func TestIterateLFSMetaObjectsForRepoUpdatesDoNotSkip(t *testing.T) {
+ assert.NoError(t, unittest.PrepareTestDatabase())
+
+ ctx := t.Context()
+ repo, err := repo_model.GetRepositoryByOwnerAndName(ctx, "user2", "repo1")
+ assert.NoError(t, err)
+
+ defer test.MockVariableValue(&setting.Database.IterateBufferSize, 1)()
+
+ created := make([]*git_model.LFSMetaObject, 0, 3)
+ for i := range 3 {
+ content := []byte("gitea-lfs-" + strconv.Itoa(i))
+ pointer, err := lfs.GeneratePointer(bytes.NewReader(content))
+ assert.NoError(t, err)
+
+ meta, err := git_model.NewLFSMetaObject(ctx, repo.ID, pointer)
+ assert.NoError(t, err)
+ created = append(created, meta)
+ }
+
+ iterated := make([]int64, 0, len(created))
+ cutoff := time.Now().Add(24 * time.Hour)
+ iterErr := git_model.IterateLFSMetaObjectsForRepo(ctx, repo.ID, func(ctx context.Context, meta *git_model.LFSMetaObject, count int64) error {
+ iterated = append(iterated, meta.ID)
+ _, err := db.GetEngine(ctx).ID(meta.ID).Cols("updated_unix").Update(&git_model.LFSMetaObject{
+ UpdatedUnix: timeutil.TimeStamp(time.Now().Unix()),
+ })
+ return err
+ }, &git_model.IterateLFSMetaObjectsForRepoOptions{
+ OlderThan: timeutil.TimeStamp(cutoff.Unix()),
+ UpdatedLessRecentlyThan: timeutil.TimeStamp(cutoff.Unix()),
+ })
+ assert.NoError(t, iterErr)
+
+ expected := []int64{created[0].ID, created[1].ID, created[2].ID}
+ assert.Equal(t, expected, iterated)
+}
diff --git a/models/git/protected_branch.go b/models/git/protected_branch.go
index 1085c14cae..f242f94f7b 100644
--- a/models/git/protected_branch.go
+++ b/models/git/protected_branch.go
@@ -318,7 +318,7 @@ func GetProtectedBranchRuleByName(ctx context.Context, repoID int64, ruleName st
if err != nil {
return nil, err
} else if !exist {
- return nil, nil
+ return nil, nil //nolint:nilnil // return nil to indicate that the object does not exist
}
return rel, nil
}
@@ -329,7 +329,7 @@ func GetProtectedBranchRuleByID(ctx context.Context, repoID, ruleID int64) (*Pro
if err != nil {
return nil, err
} else if !exist {
- return nil, nil
+ return nil, nil //nolint:nilnil // return nil to indicate that the object does not exist
}
return rel, nil
}
@@ -495,9 +495,9 @@ func updateUserWhitelist(ctx context.Context, repo *repo_model.Repository, curre
if err != nil {
return nil, fmt.Errorf("GetUserByID [user_id: %d, repo_id: %d]: %v", userID, repo.ID, err)
}
- perm, err := access_model.GetUserRepoPermission(ctx, repo, user)
+ perm, err := access_model.GetIndividualUserRepoPermission(ctx, repo, user)
if err != nil {
- return nil, fmt.Errorf("GetUserRepoPermission [user_id: %d, repo_id: %d]: %v", userID, repo.ID, err)
+ return nil, fmt.Errorf("GetIndividualUserRepoPermission [user_id: %d, repo_id: %d]: %v", userID, repo.ID, err)
}
if !perm.CanWrite(unit.TypeCode) {
diff --git a/models/git/protected_tag.go b/models/git/protected_tag.go
index 95642df593..dc38daf981 100644
--- a/models/git/protected_tag.go
+++ b/models/git/protected_tag.go
@@ -104,7 +104,7 @@ func GetProtectedTagByID(ctx context.Context, id int64) (*ProtectedTag, error) {
return nil, err
}
if !has {
- return nil, nil
+ return nil, nil //nolint:nilnil // return nil to indicate that the object does not exist
}
return tag, nil
}
@@ -117,7 +117,7 @@ func GetProtectedTagByNamePattern(ctx context.Context, repoID int64, pattern str
return nil, err
}
if !has {
- return nil, nil
+ return nil, nil //nolint:nilnil // return nil to indicate that the object does not exist
}
return tag, nil
}
diff --git a/models/issues/comment.go b/models/issues/comment.go
index fd0500833e..b667666772 100644
--- a/models/issues/comment.go
+++ b/models/issues/comment.go
@@ -7,6 +7,7 @@ package issues
import (
"context"
+ "errors"
"fmt"
"html/template"
"slices"
@@ -20,6 +21,8 @@ import (
repo_model "code.gitea.io/gitea/models/repo"
user_model "code.gitea.io/gitea/models/user"
"code.gitea.io/gitea/modules/container"
+ "code.gitea.io/gitea/modules/htmlutil"
+ "code.gitea.io/gitea/modules/json"
"code.gitea.io/gitea/modules/log"
"code.gitea.io/gitea/modules/optional"
"code.gitea.io/gitea/modules/references"
@@ -233,11 +236,17 @@ func (r RoleInRepo) LocaleHelper(lang translation.Locale) string {
return lang.TrString("repo.issues.role." + string(r) + "_helper")
}
+type SpecialDoerNameType string
+
+const SpecialDoerNameCodeOwners SpecialDoerNameType = "CODEOWNERS"
+
// CommentMetaData stores metadata for a comment, these data will not be changed once inserted into database
type CommentMetaData struct {
ProjectColumnID int64 `json:"project_column_id,omitempty"`
ProjectColumnTitle string `json:"project_column_title,omitempty"`
ProjectTitle string `json:"project_title,omitempty"`
+
+ SpecialDoerName SpecialDoerNameType `json:"special_doer_name,omitempty"` // e.g. "CODEOWNERS" for CODEOWNERS-triggered review requests
}
// Comment represents a comment in commit and issue page.
@@ -319,21 +328,34 @@ type Comment struct {
RefIssue *Issue `xorm:"-"`
RefComment *Comment `xorm:"-"`
- Commits []*git_model.SignCommitWithStatuses `xorm:"-"`
- OldCommit string `xorm:"-"`
- NewCommit string `xorm:"-"`
- CommitsNum int64 `xorm:"-"`
- IsForcePush bool `xorm:"-"`
+ Commits []*git_model.SignCommitWithStatuses `xorm:"-"`
+ OldCommit string `xorm:"-"`
+ NewCommit string `xorm:"-"`
+ CommitsNum int64 `xorm:"-"`
+
+ // Templates still use it. It is not persisted in database, it is only set when creating or loading
+ IsForcePush bool `xorm:"-"`
}
func init() {
db.RegisterModel(new(Comment))
}
-// PushActionContent is content of push pull comment
+// PushActionContent is content of pull request's push comment
type PushActionContent struct {
- IsForcePush bool `json:"is_force_push"`
- CommitIDs []string `json:"commit_ids"`
+ IsForcePush bool `json:"is_force_push"`
+ // if IsForcePush=true, CommitIDs contains the commit pair [old head, new head]
+ // if IsForcePush=false, CommitIDs contains the new commits newly pushed to the head branch
+ CommitIDs []string `json:"commit_ids"`
+}
+
+func (c *Comment) GetPushActionContent() (*PushActionContent, error) {
+ if c.Type != CommentTypePullRequestPush {
+ return nil, errors.New("not a pull request push comment")
+ }
+ var data PushActionContent
+ _ = json.Unmarshal(util.UnsafeStringToBytes(c.Content), &data)
+ return &data, nil
}
// LoadIssue loads the issue reference for the comment
@@ -377,16 +399,7 @@ func (c *Comment) LoadPoster(ctx context.Context) (err error) {
if c.Poster != nil {
return nil
}
-
- c.Poster, err = user_model.GetPossibleUserByID(ctx, c.PosterID)
- if err != nil {
- if user_model.IsErrUserNotExist(err) {
- c.PosterID = user_model.GhostUserID
- c.Poster = user_model.NewGhostUser()
- } else {
- log.Error("getUserByID[%d]: %v", c.ID, err)
- }
- }
+ c.PosterID, c.Poster, err = user_model.GetPossibleUserByID(ctx, c.PosterID)
return err
}
@@ -692,7 +705,7 @@ func (c *Comment) LoadTime(ctx context.Context) error {
return nil
}
var err error
- c.Time, err = GetTrackedTimeByID(ctx, c.TimeID)
+ c.Time, err = GetTrackedTimeByID(ctx, c.IssueID, c.TimeID)
return err
}
@@ -764,6 +777,37 @@ func (c *Comment) CodeCommentLink(ctx context.Context) string {
return fmt.Sprintf("%s/files#%s", c.Issue.Link(), c.HashTag())
}
+func (c *Comment) MetaSpecialDoerTr(locale translation.Locale) template.HTML {
+ if c.CommentMetaData == nil {
+ return ""
+ }
+ if c.CommentMetaData.SpecialDoerName == SpecialDoerNameCodeOwners {
+ return locale.Tr("repo.issues.review.codeowners_rules")
+ }
+ return htmlutil.HTMLFormat("%s", c.CommentMetaData.SpecialDoerName)
+}
+
+func (c *Comment) TimelineRequestedReviewTr(locale translation.Locale, createdStr template.HTML) template.HTML {
+ if c.AssigneeID > 0 {
+ // it guarantees LoadAssigneeUserAndTeam has been called, and c.Assignee is Ghost user but not nil if the user doesn't exist
+ if c.RemovedAssignee {
+ if c.PosterID == c.AssigneeID {
+ return locale.Tr("repo.issues.review.remove_review_request_self", createdStr)
+ }
+ return locale.Tr("repo.issues.review.remove_review_request", c.Assignee.GetDisplayName(), createdStr)
+ }
+ return locale.Tr("repo.issues.review.add_review_request", c.Assignee.GetDisplayName(), createdStr)
+ }
+ teamName := "Ghost Team"
+ if c.AssigneeTeam != nil {
+ teamName = c.AssigneeTeam.Name
+ }
+ if c.RemovedAssignee {
+ return locale.Tr("repo.issues.review.remove_review_request", teamName, createdStr)
+ }
+ return locale.Tr("repo.issues.review.add_review_request", teamName, createdStr)
+}
+
// CreateComment creates comment with context
func CreateComment(ctx context.Context, opts *CreateCommentOptions) (_ *Comment, err error) {
return db.WithTx2(ctx, func(ctx context.Context) (*Comment, error) {
@@ -780,6 +824,11 @@ func CreateComment(ctx context.Context, opts *CreateCommentOptions) (_ *Comment,
ProjectTitle: opts.ProjectTitle,
}
}
+ if opts.SpecialDoerName != "" {
+ commentMetaData = &CommentMetaData{
+ SpecialDoerName: opts.SpecialDoerName,
+ }
+ }
comment := &Comment{
Type: opts.Type,
@@ -976,6 +1025,7 @@ type CreateCommentOptions struct {
RefIsPull bool
IsForcePush bool
Invalidated bool
+ SpecialDoerName SpecialDoerNameType // e.g. "CODEOWNERS" for CODEOWNERS-triggered review requests
}
// GetCommentByID returns the comment by given ID.
@@ -990,6 +1040,20 @@ func GetCommentByID(ctx context.Context, id int64) (*Comment, error) {
return c, nil
}
+func GetCommentWithRepoID(ctx context.Context, repoID, commentID int64) (*Comment, error) {
+ c, err := GetCommentByID(ctx, commentID)
+ if err != nil {
+ return nil, err
+ }
+ if err := c.LoadIssue(ctx); err != nil {
+ return nil, err
+ }
+ if c.Issue.RepoID != repoID {
+ return nil, ErrCommentNotExist{commentID, 0}
+ }
+ return c, nil
+}
+
// FindCommentsOptions describes the conditions to Find comments
type FindCommentsOptions struct {
db.ListOptions
diff --git a/models/issues/comment_code.go b/models/issues/comment_code.go
index 55e67a1243..8de52f815a 100644
--- a/models/issues/comment_code.go
+++ b/models/issues/comment_code.go
@@ -102,6 +102,7 @@ func findCodeComments(ctx context.Context, opts FindCommentsOptions, issue *Issu
continue
}
comment.Review = re
+ comment.Issue = issue
}
comments[n] = comment
n++
diff --git a/models/issues/issue.go b/models/issues/issue.go
index 053b96dceb..d3e7cb23c2 100644
--- a/models/issues/issue.go
+++ b/models/issues/issue.go
@@ -190,17 +190,10 @@ func (issue *Issue) IsTimetrackerEnabled(ctx context.Context) bool {
// LoadPoster loads poster
func (issue *Issue) LoadPoster(ctx context.Context) (err error) {
- if issue.Poster == nil && issue.PosterID != 0 {
- issue.Poster, err = user_model.GetPossibleUserByID(ctx, issue.PosterID)
- if err != nil {
- issue.PosterID = user_model.GhostUserID
- issue.Poster = user_model.NewGhostUser()
- if !user_model.IsErrUserNotExist(err) {
- return fmt.Errorf("getUserByID.(poster) [%d]: %w", issue.PosterID, err)
- }
- return nil
- }
+ if issue.Poster != nil {
+ return nil
}
+ issue.PosterID, issue.Poster, err = user_model.GetPossibleUserByID(ctx, issue.PosterID)
return err
}
@@ -498,7 +491,7 @@ func (issue *Issue) GetLastComment(ctx context.Context) (*Comment, error) {
return nil, err
}
if !exist {
- return nil, nil
+ return nil, nil //nolint:nilnil // return nil to indicate that the object does not exist
}
return &c, nil
}
@@ -682,7 +675,7 @@ func (issue *Issue) GetParticipantIDsByIssue(ctx context.Context) ([]int64, erro
}
// BlockedByDependencies finds all Dependencies an issue is blocked by
-func (issue *Issue) BlockedByDependencies(ctx context.Context, opts db.ListOptions) (issueDeps []*DependencyInfo, err error) {
+func (issue *Issue) BlockedByDependencies(ctx context.Context, opts db.ListOptions) (issueDeps []*DependencyInfo, total int64, err error) {
sess := db.GetEngine(ctx).
Table("issue").
Join("INNER", "repository", "repository.id = issue.repo_id").
@@ -693,13 +686,13 @@ func (issue *Issue) BlockedByDependencies(ctx context.Context, opts db.ListOptio
if opts.Page > 0 {
sess = db.SetSessionPagination(sess, &opts)
}
- err = sess.Find(&issueDeps)
+ total, err = sess.FindAndCount(&issueDeps)
for _, depInfo := range issueDeps {
depInfo.Issue.Repo = &depInfo.Repository
}
- return issueDeps, err
+ return issueDeps, total, err
}
// BlockingDependencies returns all blocking dependencies, aka all other issues a given issue blocks
diff --git a/models/issues/issue_label.go b/models/issues/issue_label.go
index 151469a9b8..697448cf5e 100644
--- a/models/issues/issue_label.go
+++ b/models/issues/issue_label.go
@@ -356,7 +356,7 @@ func ClearIssueLabels(ctx context.Context, issue *Issue, doer *user_model.User)
return err
}
- perm, err := access_model.GetUserRepoPermission(ctx, issue.Repo, doer)
+ perm, err := access_model.GetDoerRepoPermission(ctx, issue.Repo, doer)
if err != nil {
return err
}
diff --git a/models/issues/issue_project.go b/models/issues/issue_project.go
index 0185244783..3bb0936301 100644
--- a/models/issues/issue_project.go
+++ b/models/issues/issue_project.go
@@ -64,36 +64,6 @@ func LoadProjectIssueColumnMap(ctx context.Context, projectID, defaultColumnID i
return result, nil
}
-// LoadIssuesFromColumn load issues assigned to this column
-func LoadIssuesFromColumn(ctx context.Context, b *project_model.Column, opts *IssuesOptions) (IssueList, error) {
- issueList, err := Issues(ctx, opts.Copy(func(o *IssuesOptions) {
- o.ProjectColumnID = b.ID
- o.ProjectID = b.ProjectID
- o.SortType = "project-column-sorting"
- }))
- if err != nil {
- return nil, err
- }
-
- if b.Default {
- issues, err := Issues(ctx, opts.Copy(func(o *IssuesOptions) {
- o.ProjectColumnID = db.NoConditionID
- o.ProjectID = b.ProjectID
- o.SortType = "project-column-sorting"
- }))
- if err != nil {
- return nil, err
- }
- issueList = append(issueList, issues...)
- }
-
- if err := issueList.LoadComments(ctx); err != nil {
- return nil, err
- }
-
- return issueList, nil
-}
-
// IssueAssignOrRemoveProject changes the project associated with an issue
// If newProjectID is 0, the issue is removed from the project
func IssueAssignOrRemoveProject(ctx context.Context, issue *Issue, doer *user_model.User, newProjectID, newColumnID int64) error {
diff --git a/models/issues/issue_update.go b/models/issues/issue_update.go
index 0a320ffc56..01a3eb9a2a 100644
--- a/models/issues/issue_update.go
+++ b/models/issues/issue_update.go
@@ -665,9 +665,9 @@ func ResolveIssueMentionsByVisibility(ctx context.Context, issue *Issue, doer *u
continue
}
// Normal users must have read access to the referencing issue
- perm, err := access_model.GetUserRepoPermission(ctx, issue.Repo, user)
+ perm, err := access_model.GetIndividualUserRepoPermission(ctx, issue.Repo, user)
if err != nil {
- return nil, fmt.Errorf("GetUserRepoPermission [%d]: %w", user.ID, err)
+ return nil, fmt.Errorf("GetIndividualUserRepoPermission [%d]: %w", user.ID, err)
}
if !perm.CanReadIssuesOrPulls(issue.IsPull) {
continue
diff --git a/models/issues/issue_xref.go b/models/issues/issue_xref.go
index f8495929cf..41a867c892 100644
--- a/models/issues/issue_xref.go
+++ b/models/issues/issue_xref.go
@@ -207,7 +207,7 @@ func (issue *Issue) verifyReferencedIssue(stdCtx context.Context, ctx *crossRefe
// Check doer permissions; set action to None if the doer can't change the destination
if refIssue.RepoID != ctx.OrigIssue.RepoID || ref.Action != references.XRefActionNone {
- perm, err := access_model.GetUserRepoPermission(stdCtx, refIssue.Repo, ctx.Doer)
+ perm, err := access_model.GetDoerRepoPermission(stdCtx, refIssue.Repo, ctx.Doer)
if err != nil {
return nil, references.XRefActionNone, err
}
diff --git a/models/issues/label_test.go b/models/issues/label_test.go
index 50393855d9..42f774e750 100644
--- a/models/issues/label_test.go
+++ b/models/issues/label_test.go
@@ -254,7 +254,7 @@ func TestGetLabelsByIssueID(t *testing.T) {
func TestUpdateLabel(t *testing.T) {
assert.NoError(t, unittest.PrepareTestDatabase())
label := unittest.AssertExistsAndLoadBean(t, &issues_model.Label{ID: 1})
- // make sure update wont overwrite it
+ // make sure update won't overwrite it
update := &issues_model.Label{
ID: label.ID,
Color: "#ffff00",
diff --git a/models/issues/milestone.go b/models/issues/milestone.go
index 82a82ac913..1dd8630276 100644
--- a/models/issues/milestone.go
+++ b/models/issues/milestone.go
@@ -75,6 +75,8 @@ func init() {
func (m *Milestone) BeforeUpdate() {
if m.NumIssues > 0 {
m.Completeness = m.NumClosedIssues * 100 / m.NumIssues
+ } else if m.IsClosed {
+ m.Completeness = 100
} else {
m.Completeness = 0
}
@@ -195,8 +197,8 @@ func UpdateMilestoneCounters(ctx context.Context, id int64) error {
if err != nil {
return err
}
- _, err = e.Exec("UPDATE `milestone` SET completeness=100*num_closed_issues/(CASE WHEN num_issues > 0 THEN num_issues ELSE 1 END) WHERE id=?",
- id,
+ _, err = e.Exec("UPDATE `milestone` SET completeness=(CASE WHEN is_closed = ? AND num_issues = 0 THEN 100 ELSE 100*num_closed_issues/(CASE WHEN num_issues > 0 THEN num_issues ELSE 1 END) END) WHERE id=?",
+ true, id,
)
return err
}
@@ -240,6 +242,11 @@ func changeMilestoneStatus(ctx context.Context, m *Milestone, isClosed bool) err
if count < 1 {
return nil
}
+
+ if err := UpdateMilestoneCounters(ctx, m.ID); err != nil {
+ return err
+ }
+
return updateRepoMilestoneNum(ctx, m.RepoID)
}
diff --git a/models/issues/milestone_list.go b/models/issues/milestone_list.go
index 955ab2356d..021b8beb9e 100644
--- a/models/issues/milestone_list.go
+++ b/models/issues/milestone_list.go
@@ -24,6 +24,18 @@ func (milestones MilestoneList) getMilestoneIDs() []int64 {
return ids
}
+// SplitByOpenClosed splits the milestone list into open and closed milestones
+func (milestones MilestoneList) SplitByOpenClosed() (open, closed MilestoneList) {
+ for _, m := range milestones {
+ if m.IsClosed {
+ closed = append(closed, m)
+ } else {
+ open = append(open, m)
+ }
+ }
+ return open, closed
+}
+
// FindMilestoneOptions contain options to get milestones
type FindMilestoneOptions struct {
db.ListOptions
diff --git a/models/issues/pull.go b/models/issues/pull.go
index 5669bed61e..1b883f2981 100644
--- a/models/issues/pull.go
+++ b/models/issues/pull.go
@@ -9,7 +9,6 @@ import (
"errors"
"fmt"
"io"
- "regexp"
"strings"
"code.gitea.io/gitea/models/db"
@@ -24,6 +23,7 @@ import (
"code.gitea.io/gitea/modules/timeutil"
"code.gitea.io/gitea/modules/util"
+ "github.com/dlclark/regexp2"
"xorm.io/builder"
)
@@ -417,10 +417,6 @@ func (pr *PullRequest) GetGitHeadRefName() string {
return fmt.Sprintf("%s%d/head", git.PullPrefix, pr.Index)
}
-func (pr *PullRequest) GetGitHeadBranchRefName() string {
- return fmt.Sprintf("%s%s", git.BranchPrefix, pr.HeadBranch)
-}
-
// GetReviewCommentsCount returns the number of review comments made on the diff of a PR review (not including comments on commits or issues in a PR)
func (pr *PullRequest) GetReviewCommentsCount(ctx context.Context) int {
opts := FindCommentsOptions{
@@ -646,9 +642,8 @@ func (pr *PullRequest) UpdateCols(ctx context.Context, cols ...string) error {
}
// UpdateColsIfNotMerged updates specific fields of a pull request if it has not been merged
-func (pr *PullRequest) UpdateColsIfNotMerged(ctx context.Context, cols ...string) error {
- _, err := db.GetEngine(ctx).Where("id = ? AND has_merged = ?", pr.ID, false).Cols(cols...).Update(pr)
- return err
+func (pr *PullRequest) UpdateColsIfNotMerged(ctx context.Context, cols ...string) (int64, error) {
+ return db.GetEngine(ctx).Where("id = ? AND has_merged = ?", pr.ID, false).Cols(cols...).Update(pr)
}
// IsWorkInProgress determine if the Pull Request is a Work In Progress by its title
@@ -663,17 +658,24 @@ func (pr *PullRequest) IsWorkInProgress(ctx context.Context) bool {
// HasWorkInProgressPrefix determines if the given PR title has a Work In Progress prefix
func HasWorkInProgressPrefix(title string) bool {
+ _, ok := CutWorkInProgressPrefix(title)
+ return ok
+}
+
+func CutWorkInProgressPrefix(title string) (origTitle string, ok bool) {
for _, prefix := range setting.Repository.PullRequest.WorkInProgressPrefixes {
- if strings.HasPrefix(strings.ToUpper(title), strings.ToUpper(prefix)) {
- return true
+ prefixLen := len(prefix)
+ if prefixLen <= len(title) && util.AsciiEqualFold(title[:prefixLen], prefix) {
+ return title[len(prefix):], true
}
}
- return false
+ return title, false
}
-// IsFilesConflicted determines if the Pull Request has changes conflicting with the target branch.
+// IsFilesConflicted determines if the Pull Request has changes conflicting with the target branch.
+// Sometimes a conflict may not list any files
func (pr *PullRequest) IsFilesConflicted() bool {
- return len(pr.ConflictedFiles) > 0
+ return pr.Status == PullRequestStatusConflict
}
// GetWorkInProgressPrefix returns the prefix used to mark the pull request as a work in progress.
@@ -859,7 +861,7 @@ func GetCodeOwnersFromContent(ctx context.Context, data string) ([]*CodeOwnerRul
}
type CodeOwnerRule struct {
- Rule *regexp.Regexp
+ Rule *regexp2.Regexp // it supports negative lookahead, does better for end users
Negative bool
Users []*user_model.User
Teams []*org_model.Team
@@ -875,7 +877,13 @@ func ParseCodeOwnersLine(ctx context.Context, tokens []string) (*CodeOwnerRule,
warnings := make([]string, 0)
- rule.Rule, err = regexp.Compile(fmt.Sprintf("^%s$", strings.TrimPrefix(tokens[0], "!")))
+ // Strip leading "!" for negative rules, then strip leading "/" since
+ // git returns relative paths (e.g. "docs/foo.md" not "/docs/foo.md")
+ // and the regex is already anchored with ^...$, so the "/" is redundant.
+ pattern := strings.TrimPrefix(tokens[0], "!")
+ pattern = strings.TrimPrefix(pattern, "/")
+ expr := fmt.Sprintf("^%s$", pattern)
+ rule.Rule, err = regexp2.Compile(expr, regexp2.None)
if err != nil {
warnings = append(warnings, fmt.Sprintf("incorrect codeowner regexp: %s", err))
return nil, warnings
diff --git a/models/issues/pull_list.go b/models/issues/pull_list.go
index 84f9f6166d..6a6abca970 100644
--- a/models/issues/pull_list.go
+++ b/models/issues/pull_list.go
@@ -14,6 +14,7 @@ import (
user_model "code.gitea.io/gitea/models/user"
"code.gitea.io/gitea/modules/container"
"code.gitea.io/gitea/modules/log"
+ "code.gitea.io/gitea/modules/timeutil"
"code.gitea.io/gitea/modules/util"
"xorm.io/builder"
@@ -70,38 +71,69 @@ func GetUnmergedPullRequestsByHeadInfo(ctx context.Context, repoID int64, branch
}
// CanMaintainerWriteToBranch check whether user is a maintainer and could write to the branch
-func CanMaintainerWriteToBranch(ctx context.Context, p access_model.Permission, branch string, user *user_model.User) bool {
- if p.CanWrite(unit.TypeCode) {
- return true
+func CanMaintainerWriteToBranch(ctx context.Context, headPerm access_model.Permission, headBranch string, doer *user_model.User) bool {
+ can, err := canMaintainerWriteToBranch(ctx, headPerm, headBranch, doer)
+ if err != nil {
+ log.Error("CanMaintainerWriteToBranch: %v", err)
+ return false
+ }
+ return can
+}
+
+func canMaintainerWriteToBranch(ctx context.Context, headPerm access_model.Permission, headBranch string, doer *user_model.User) (bool, error) {
+ if headPerm.CanWrite(unit.TypeCode) {
+ return true, nil
}
// the code below depends on units to get the repository ID, not ideal but just keep it for now
- firstUnitRepoID := p.GetFirstUnitRepoID()
+ firstUnitRepoID := headPerm.GetFirstUnitRepoID()
if firstUnitRepoID == 0 {
- return false
+ return false, nil
}
- prs, err := GetUnmergedPullRequestsByHeadInfo(ctx, firstUnitRepoID, branch)
+ prs, err := GetUnmergedPullRequestsByHeadInfo(ctx, firstUnitRepoID, headBranch)
if err != nil {
- return false
+ return false, err
+ }
+ if _, err := prs.LoadIssues(ctx); err != nil {
+ return false, err
}
-
for _, pr := range prs {
- if pr.AllowMaintainerEdit {
- err = pr.LoadBaseRepo(ctx)
- if err != nil {
- continue
- }
- prPerm, err := access_model.GetUserRepoPermission(ctx, pr.BaseRepo, user)
- if err != nil {
- continue
- }
- if prPerm.CanWrite(unit.TypeCode) {
- return true
- }
+ if !pr.AllowMaintainerEdit {
+ continue
+ }
+
+ // check the PR's poster's permissions
+ // If a "reader" poster created the PR in base repo from head repo, even if it is allowed to be edited by maintainers,
+ // the maintainers should not be allowed to write, because they don't really have "write" permission in the head repo
+ if err := pr.Issue.LoadPoster(ctx); err != nil {
+ return false, err
+ }
+ if err := pr.LoadHeadRepo(ctx); err != nil {
+ return false, err
+ }
+ posterHeadPerm, err := access_model.GetIndividualUserRepoPermission(ctx, pr.HeadRepo, pr.Issue.Poster)
+ if err != nil {
+ return false, err
+ }
+ if !posterHeadPerm.CanWrite(unit.TypeCode) {
+ continue
+ }
+
+ // check the doer's permission
+ // Only allow the doer to edit the PR if they have write access to the base repository
+ if err := pr.LoadBaseRepo(ctx); err != nil {
+ return false, err
+ }
+ doerBasePerm, err := access_model.GetIndividualUserRepoPermission(ctx, pr.BaseRepo, doer)
+ if err != nil {
+ return false, err
+ }
+ if doerBasePerm.CanWrite(unit.TypeCode) {
+ return true, nil
}
}
- return false
+ return false, nil
}
// HasUnmergedPullRequestsByHeadInfo checks if there are open and not merged pull request
@@ -324,12 +356,26 @@ func (prs PullRequestList) LoadReviews(ctx context.Context) (ReviewList, error)
// HasMergedPullRequestInRepo returns whether the user(poster) has merged pull-request in the repo
func HasMergedPullRequestInRepo(ctx context.Context, repoID, posterID int64) (bool, error) {
- return db.GetEngine(ctx).
+ return HasMergedPullRequestInRepoBefore(ctx, repoID, posterID, 0, 0)
+}
+
+// HasMergedPullRequestInRepoBefore returns whether the user has a merged PR before a timestamp (0 = no limit)
+func HasMergedPullRequestInRepoBefore(ctx context.Context, repoID, posterID int64, beforeUnix timeutil.TimeStamp, excludePullID int64) (bool, error) {
+ sess := db.GetEngine(ctx).
Join("INNER", "pull_request", "pull_request.issue_id = issue.id").
Where("repo_id=?", repoID).
And("poster_id=?", posterID).
And("is_pull=?", true).
- And("pull_request.has_merged=?", true).
+ And("pull_request.has_merged=?", true)
+
+ if beforeUnix > 0 {
+ sess.And("pull_request.merged_unix < ?", beforeUnix)
+ }
+ if excludePullID > 0 {
+ sess.And("pull_request.id != ?", excludePullID)
+ }
+
+ return sess.
Select("issue.id").
Limit(1).
Get(new(Issue))
diff --git a/models/issues/pull_list_test.go b/models/issues/pull_list_test.go
index 437830701c..302b2ca0ba 100644
--- a/models/issues/pull_list_test.go
+++ b/models/issues/pull_list_test.go
@@ -6,15 +6,28 @@ package issues_test
import (
"testing"
+ "code.gitea.io/gitea/models/db"
issues_model "code.gitea.io/gitea/models/issues"
+ "code.gitea.io/gitea/models/perm"
+ "code.gitea.io/gitea/models/perm/access"
+ repo_model "code.gitea.io/gitea/models/repo"
"code.gitea.io/gitea/models/unittest"
+ user_model "code.gitea.io/gitea/models/user"
"github.com/stretchr/testify/assert"
+ "github.com/stretchr/testify/require"
+ "xorm.io/builder"
)
-func TestPullRequestList_LoadAttributes(t *testing.T) {
- assert.NoError(t, unittest.PrepareTestDatabase())
+func TestPullRequestList(t *testing.T) {
+ require.NoError(t, unittest.PrepareTestDatabase())
+ t.Run("LoadAttributes", testPullRequestListLoadAttributes)
+ t.Run("LoadReviewCommentsCounts", testPullRequestListLoadReviewCommentsCounts)
+ t.Run("LoadReviews", testPullRequestListLoadReviews)
+ t.Run("CanMaintainerWriteToBranch", testCanMaintainerWriteToBranch)
+}
+func testPullRequestListLoadAttributes(t *testing.T) {
prs := issues_model.PullRequestList{
unittest.AssertExistsAndLoadBean(t, &issues_model.PullRequest{ID: 1}),
unittest.AssertExistsAndLoadBean(t, &issues_model.PullRequest{ID: 2}),
@@ -28,9 +41,7 @@ func TestPullRequestList_LoadAttributes(t *testing.T) {
assert.NoError(t, issues_model.PullRequestList([]*issues_model.PullRequest{}).LoadAttributes(t.Context()))
}
-func TestPullRequestList_LoadReviewCommentsCounts(t *testing.T) {
- assert.NoError(t, unittest.PrepareTestDatabase())
-
+func testPullRequestListLoadReviewCommentsCounts(t *testing.T) {
prs := issues_model.PullRequestList{
unittest.AssertExistsAndLoadBean(t, &issues_model.PullRequest{ID: 1}),
unittest.AssertExistsAndLoadBean(t, &issues_model.PullRequest{ID: 2}),
@@ -43,9 +54,7 @@ func TestPullRequestList_LoadReviewCommentsCounts(t *testing.T) {
}
}
-func TestPullRequestList_LoadReviews(t *testing.T) {
- assert.NoError(t, unittest.PrepareTestDatabase())
-
+func testPullRequestListLoadReviews(t *testing.T) {
prs := issues_model.PullRequestList{
unittest.AssertExistsAndLoadBean(t, &issues_model.PullRequest{ID: 1}),
unittest.AssertExistsAndLoadBean(t, &issues_model.PullRequest{ID: 2}),
@@ -61,3 +70,73 @@ func TestPullRequestList_LoadReviews(t *testing.T) {
assert.EqualValues(t, 10, reviewList[4].ID)
assert.EqualValues(t, 22, reviewList[5].ID)
}
+
+func testCanMaintainerWriteToBranch(t *testing.T) {
+ ctx := t.Context()
+ baseRepo := unittest.AssertExistsAndLoadBean(t, &repo_model.Repository{ID: 10})
+ headRepo := unittest.AssertExistsAndLoadBean(t, &repo_model.Repository{ID: 11})
+
+ _ = baseRepo.LoadOwner(ctx)
+ _ = headRepo.LoadOwner(ctx)
+ user := unittest.AssertExistsAndLoadBean(t, &user_model.User{ID: 2})
+
+ // a PR from header's owner
+ headOwnerPR := &issues_model.PullRequest{
+ Issue: &issues_model.Issue{
+ RepoID: baseRepo.ID,
+ PosterID: headRepo.OwnerID,
+ },
+ HeadRepoID: headRepo.ID,
+ BaseRepoID: baseRepo.ID,
+ HeadBranch: "pr-from-head-owner",
+ BaseBranch: "master",
+ }
+ require.NoError(t, issues_model.NewPullRequest(ctx, baseRepo, headOwnerPR.Issue, nil, nil, headOwnerPR))
+
+ // a PR from a user, they might have or not have "write" permission in the target repo
+ anyUserPR := &issues_model.PullRequest{
+ Issue: &issues_model.Issue{
+ RepoID: baseRepo.ID,
+ PosterID: user.ID,
+ },
+ HeadRepoID: headRepo.ID,
+ BaseRepoID: baseRepo.ID,
+ HeadBranch: "pr-from-head-user",
+ BaseBranch: "master",
+ }
+ require.NoError(t, issues_model.NewPullRequest(ctx, baseRepo, anyUserPR.Issue, nil, nil, anyUserPR))
+
+ doerCanWrite := func(doer *user_model.User, pr *issues_model.PullRequest) bool {
+ headPerm, _ := access.GetIndividualUserRepoPermission(ctx, headRepo, doer)
+ return issues_model.CanMaintainerWriteToBranch(ctx, headPerm, pr.HeadBranch, doer)
+ }
+
+ t.Run("NoAllowMaintainerEdit", func(t *testing.T) {
+ assert.True(t, doerCanWrite(headRepo.Owner, headOwnerPR))
+ assert.False(t, doerCanWrite(baseRepo.Owner, headOwnerPR))
+ assert.False(t, doerCanWrite(baseRepo.Owner, anyUserPR))
+ assert.False(t, doerCanWrite(user, anyUserPR))
+ })
+
+ t.Run("WithAllowMaintainerEdit-HeadPosterReader", func(t *testing.T) {
+ _, err := db.GetEngine(ctx).Where(builder.In("id", []int64{headOwnerPR.ID, anyUserPR.ID})).
+ Cols("allow_maintainer_edit").
+ Update(&issues_model.PullRequest{AllowMaintainerEdit: true})
+ require.NoError(t, err)
+ assert.True(t, doerCanWrite(baseRepo.Owner, headOwnerPR))
+ assert.False(t, doerCanWrite(baseRepo.Owner, anyUserPR)) // poster doesn't have write permission, so maintainer can't write either
+ })
+
+ t.Run("WithAllowMaintainerEdit-HeadPosterWriter", func(t *testing.T) {
+ _, err := db.GetEngine(ctx).Where(builder.In("id", []int64{headOwnerPR.ID, anyUserPR.ID})).
+ Cols("allow_maintainer_edit").
+ Update(&issues_model.PullRequest{AllowMaintainerEdit: true})
+ require.NoError(t, err)
+ err = db.Insert(ctx, &repo_model.Collaboration{RepoID: headRepo.ID, UserID: user.ID, Mode: perm.AccessModeWrite})
+ require.NoError(t, err)
+ err = db.Insert(ctx, &access.Access{RepoID: headRepo.ID, UserID: user.ID, Mode: perm.AccessModeWrite})
+ require.NoError(t, err)
+ assert.True(t, doerCanWrite(baseRepo.Owner, headOwnerPR))
+ assert.True(t, doerCanWrite(baseRepo.Owner, anyUserPR)) // now the poster has the write permission
+ })
+}
diff --git a/models/issues/pull_test.go b/models/issues/pull_test.go
index 7089af253b..79d1f8aa9b 100644
--- a/models/issues/pull_test.go
+++ b/models/issues/pull_test.go
@@ -17,16 +17,43 @@ import (
"github.com/stretchr/testify/require"
)
-func TestPullRequest_LoadAttributes(t *testing.T) {
+func TestPullRequest(t *testing.T) {
assert.NoError(t, unittest.PrepareTestDatabase())
+
+ t.Run("LoadAttributes", testPullRequestLoadAttributes)
+ t.Run("LoadIssue", testPullRequestLoadIssue)
+ t.Run("LoadBaseRepo", testPullRequestLoadBaseRepo)
+ t.Run("LoadHeadRepo", testPullRequestLoadHeadRepo)
+ t.Run("PullRequestsNewest", testPullRequestsNewest)
+ t.Run("PullRequestsOldest", testPullRequestsOldest)
+ t.Run("GetUnmergedPullRequest", testGetUnmergedPullRequest)
+ t.Run("HasUnmergedPullRequestsByHeadInfo", testHasUnmergedPullRequestsByHeadInfo)
+ t.Run("GetUnmergedPullRequestsByHeadInfo", testGetUnmergedPullRequestsByHeadInfo)
+ t.Run("GetUnmergedPullRequestsByBaseInfo", testGetUnmergedPullRequestsByBaseInfo)
+ t.Run("GetPullRequestByIndex", testGetPullRequestByIndex)
+ t.Run("GetPullRequestByID", testGetPullRequestByID)
+ t.Run("GetPullRequestByIssueID", testGetPullRequestByIssueID)
+ t.Run("PullRequest_UpdateCols", testPullRequestUpdateCols)
+ t.Run("PullRequest_IsWorkInProgress", testPullRequestIsWorkInProgress)
+ t.Run("PullRequest_GetWorkInProgressPrefixWorkInProgress", testPullRequestGetWorkInProgressPrefixWorkInProgress)
+ t.Run("DeleteOrphanedObjects", testDeleteOrphanedObjects)
+ t.Run("ParseCodeOwnersLine", testParseCodeOwnersLine)
+ t.Run("CodeOwnerAbsolutePathPatterns", testCodeOwnerAbsolutePathPatterns)
+ t.Run("GetApprovers", testGetApprovers)
+ t.Run("GetPullRequestByMergedCommit", testGetPullRequestByMergedCommit)
+ t.Run("Migrate_InsertPullRequests", testMigrateInsertPullRequests)
+ t.Run("PullRequestsClosedRecentSortType", testPullRequestsClosedRecentSortType)
+ t.Run("LoadRequestedReviewers", testLoadRequestedReviewers)
+}
+
+func testPullRequestLoadAttributes(t *testing.T) {
pr := unittest.AssertExistsAndLoadBean(t, &issues_model.PullRequest{ID: 1})
assert.NoError(t, pr.LoadAttributes(t.Context()))
assert.NotNil(t, pr.Merger)
assert.Equal(t, pr.MergerID, pr.Merger.ID)
}
-func TestPullRequest_LoadIssue(t *testing.T) {
- assert.NoError(t, unittest.PrepareTestDatabase())
+func testPullRequestLoadIssue(t *testing.T) {
pr := unittest.AssertExistsAndLoadBean(t, &issues_model.PullRequest{ID: 1})
assert.NoError(t, pr.LoadIssue(t.Context()))
assert.NotNil(t, pr.Issue)
@@ -36,8 +63,7 @@ func TestPullRequest_LoadIssue(t *testing.T) {
assert.Equal(t, int64(2), pr.Issue.ID)
}
-func TestPullRequest_LoadBaseRepo(t *testing.T) {
- assert.NoError(t, unittest.PrepareTestDatabase())
+func testPullRequestLoadBaseRepo(t *testing.T) {
pr := unittest.AssertExistsAndLoadBean(t, &issues_model.PullRequest{ID: 1})
assert.NoError(t, pr.LoadBaseRepo(t.Context()))
assert.NotNil(t, pr.BaseRepo)
@@ -47,8 +73,7 @@ func TestPullRequest_LoadBaseRepo(t *testing.T) {
assert.Equal(t, pr.BaseRepoID, pr.BaseRepo.ID)
}
-func TestPullRequest_LoadHeadRepo(t *testing.T) {
- assert.NoError(t, unittest.PrepareTestDatabase())
+func testPullRequestLoadHeadRepo(t *testing.T) {
pr := unittest.AssertExistsAndLoadBean(t, &issues_model.PullRequest{ID: 1})
assert.NoError(t, pr.LoadHeadRepo(t.Context()))
assert.NotNil(t, pr.HeadRepo)
@@ -59,8 +84,7 @@ func TestPullRequest_LoadHeadRepo(t *testing.T) {
// TODO TestNewPullRequest
-func TestPullRequestsNewest(t *testing.T) {
- assert.NoError(t, unittest.PrepareTestDatabase())
+func testPullRequestsNewest(t *testing.T) {
prs, count, err := issues_model.PullRequests(t.Context(), 1, &issues_model.PullRequestsOptions{
ListOptions: db.ListOptions{
Page: 1,
@@ -77,7 +101,7 @@ func TestPullRequestsNewest(t *testing.T) {
}
}
-func TestPullRequests_Closed_RecentSortType(t *testing.T) {
+func testPullRequestsClosedRecentSortType(t *testing.T) {
// Issue ID | Closed At. | Updated At
// 2 | 1707270001 | 1707270001
// 3 | 1707271000 | 1707279999
@@ -90,7 +114,6 @@ func TestPullRequests_Closed_RecentSortType(t *testing.T) {
{"recentclose", []int64{11, 3, 2}},
}
- assert.NoError(t, unittest.PrepareTestDatabase())
_, err := db.Exec(t.Context(), "UPDATE issue SET closed_unix = 1707270001, updated_unix = 1707270001, is_closed = true WHERE id = 2")
require.NoError(t, err)
_, err = db.Exec(t.Context(), "UPDATE issue SET closed_unix = 1707271000, updated_unix = 1707279999, is_closed = true WHERE id = 3")
@@ -118,9 +141,7 @@ func TestPullRequests_Closed_RecentSortType(t *testing.T) {
}
}
-func TestLoadRequestedReviewers(t *testing.T) {
- assert.NoError(t, unittest.PrepareTestDatabase())
-
+func testLoadRequestedReviewers(t *testing.T) {
pull := unittest.AssertExistsAndLoadBean(t, &issues_model.PullRequest{ID: 2})
assert.NoError(t, pull.LoadIssue(t.Context()))
issue := pull.Issue
@@ -130,7 +151,7 @@ func TestLoadRequestedReviewers(t *testing.T) {
user1, err := user_model.GetUserByID(t.Context(), 1)
assert.NoError(t, err)
- comment, err := issues_model.AddReviewRequest(t.Context(), issue, user1, &user_model.User{})
+ comment, err := issues_model.AddReviewRequest(t.Context(), issue, user1, &user_model.User{}, false)
assert.NoError(t, err)
assert.NotNil(t, comment)
@@ -146,8 +167,7 @@ func TestLoadRequestedReviewers(t *testing.T) {
assert.Empty(t, pull.RequestedReviewers)
}
-func TestPullRequestsOldest(t *testing.T) {
- assert.NoError(t, unittest.PrepareTestDatabase())
+func testPullRequestsOldest(t *testing.T) {
prs, count, err := issues_model.PullRequests(t.Context(), 1, &issues_model.PullRequestsOptions{
ListOptions: db.ListOptions{
Page: 1,
@@ -164,8 +184,7 @@ func TestPullRequestsOldest(t *testing.T) {
}
}
-func TestGetUnmergedPullRequest(t *testing.T) {
- assert.NoError(t, unittest.PrepareTestDatabase())
+func testGetUnmergedPullRequest(t *testing.T) {
pr, err := issues_model.GetUnmergedPullRequest(t.Context(), 1, 1, "branch2", "master", issues_model.PullRequestFlowGithub)
assert.NoError(t, err)
assert.Equal(t, int64(2), pr.ID)
@@ -175,9 +194,7 @@ func TestGetUnmergedPullRequest(t *testing.T) {
assert.True(t, issues_model.IsErrPullRequestNotExist(err))
}
-func TestHasUnmergedPullRequestsByHeadInfo(t *testing.T) {
- assert.NoError(t, unittest.PrepareTestDatabase())
-
+func testHasUnmergedPullRequestsByHeadInfo(t *testing.T) {
exist, err := issues_model.HasUnmergedPullRequestsByHeadInfo(t.Context(), 1, "branch2")
assert.NoError(t, err)
assert.True(t, exist)
@@ -187,8 +204,7 @@ func TestHasUnmergedPullRequestsByHeadInfo(t *testing.T) {
assert.False(t, exist)
}
-func TestGetUnmergedPullRequestsByHeadInfo(t *testing.T) {
- assert.NoError(t, unittest.PrepareTestDatabase())
+func testGetUnmergedPullRequestsByHeadInfo(t *testing.T) {
prs, err := issues_model.GetUnmergedPullRequestsByHeadInfo(t.Context(), 1, "branch2")
assert.NoError(t, err)
assert.Len(t, prs, 1)
@@ -198,8 +214,7 @@ func TestGetUnmergedPullRequestsByHeadInfo(t *testing.T) {
}
}
-func TestGetUnmergedPullRequestsByBaseInfo(t *testing.T) {
- assert.NoError(t, unittest.PrepareTestDatabase())
+func testGetUnmergedPullRequestsByBaseInfo(t *testing.T) {
prs, err := issues_model.GetUnmergedPullRequestsByBaseInfo(t.Context(), 1, "master")
assert.NoError(t, err)
assert.Len(t, prs, 1)
@@ -209,8 +224,7 @@ func TestGetUnmergedPullRequestsByBaseInfo(t *testing.T) {
assert.Equal(t, "master", pr.BaseBranch)
}
-func TestGetPullRequestByIndex(t *testing.T) {
- assert.NoError(t, unittest.PrepareTestDatabase())
+func testGetPullRequestByIndex(t *testing.T) {
pr, err := issues_model.GetPullRequestByIndex(t.Context(), 1, 2)
assert.NoError(t, err)
assert.Equal(t, int64(1), pr.BaseRepoID)
@@ -225,8 +239,7 @@ func TestGetPullRequestByIndex(t *testing.T) {
assert.True(t, issues_model.IsErrPullRequestNotExist(err))
}
-func TestGetPullRequestByID(t *testing.T) {
- assert.NoError(t, unittest.PrepareTestDatabase())
+func testGetPullRequestByID(t *testing.T) {
pr, err := issues_model.GetPullRequestByID(t.Context(), 1)
assert.NoError(t, err)
assert.Equal(t, int64(1), pr.ID)
@@ -237,8 +250,7 @@ func TestGetPullRequestByID(t *testing.T) {
assert.True(t, issues_model.IsErrPullRequestNotExist(err))
}
-func TestGetPullRequestByIssueID(t *testing.T) {
- assert.NoError(t, unittest.PrepareTestDatabase())
+func testGetPullRequestByIssueID(t *testing.T) {
pr, err := issues_model.GetPullRequestByIssueID(t.Context(), 2)
assert.NoError(t, err)
assert.Equal(t, int64(2), pr.IssueID)
@@ -248,8 +260,7 @@ func TestGetPullRequestByIssueID(t *testing.T) {
assert.True(t, issues_model.IsErrPullRequestNotExist(err))
}
-func TestPullRequest_UpdateCols(t *testing.T) {
- assert.NoError(t, unittest.PrepareTestDatabase())
+func testPullRequestUpdateCols(t *testing.T) {
pr := &issues_model.PullRequest{
ID: 1,
BaseBranch: "baseBranch",
@@ -265,9 +276,7 @@ func TestPullRequest_UpdateCols(t *testing.T) {
// TODO TestAddTestPullRequestTask
-func TestPullRequest_IsWorkInProgress(t *testing.T) {
- assert.NoError(t, unittest.PrepareTestDatabase())
-
+func testPullRequestIsWorkInProgress(t *testing.T) {
pr := unittest.AssertExistsAndLoadBean(t, &issues_model.PullRequest{ID: 2})
pr.LoadIssue(t.Context())
@@ -280,9 +289,7 @@ func TestPullRequest_IsWorkInProgress(t *testing.T) {
assert.True(t, pr.IsWorkInProgress(t.Context()))
}
-func TestPullRequest_GetWorkInProgressPrefixWorkInProgress(t *testing.T) {
- assert.NoError(t, unittest.PrepareTestDatabase())
-
+func testPullRequestGetWorkInProgressPrefixWorkInProgress(t *testing.T) {
pr := unittest.AssertExistsAndLoadBean(t, &issues_model.PullRequest{ID: 2})
pr.LoadIssue(t.Context())
@@ -296,9 +303,7 @@ func TestPullRequest_GetWorkInProgressPrefixWorkInProgress(t *testing.T) {
assert.Equal(t, "[wip]", pr.GetWorkInProgressPrefix(t.Context()))
}
-func TestDeleteOrphanedObjects(t *testing.T) {
- assert.NoError(t, unittest.PrepareTestDatabase())
-
+func testDeleteOrphanedObjects(t *testing.T) {
countBefore, err := db.GetEngine(t.Context()).Count(&issues_model.PullRequest{})
assert.NoError(t, err)
@@ -317,7 +322,7 @@ func TestDeleteOrphanedObjects(t *testing.T) {
assert.Equal(t, countBefore, countAfter)
}
-func TestParseCodeOwnersLine(t *testing.T) {
+func testParseCodeOwnersLine(t *testing.T) {
type CodeOwnerTest struct {
Line string
Tokens []string
@@ -331,6 +336,8 @@ func TestParseCodeOwnersLine(t *testing.T) {
{Line: `docs/(aws|google|azure)/[^/]*\\.(md|txt) @org3 @org2/team2`, Tokens: []string{`docs/(aws|google|azure)/[^/]*\.(md|txt)`, "@org3", "@org2/team2"}},
{Line: `\#path @org3`, Tokens: []string{`#path`, "@org3"}},
{Line: `path\ with\ spaces/ @org3`, Tokens: []string{`path with spaces/`, "@org3"}},
+ {Line: `/docs/.*\\.md @user1`, Tokens: []string{`/docs/.*\.md`, "@user1"}},
+ {Line: `!/assets/.*\\.(bin|exe|msi) @user1`, Tokens: []string{`!/assets/.*\.(bin|exe|msi)`, "@user1"}},
}
for _, g := range given {
@@ -339,8 +346,37 @@ func TestParseCodeOwnersLine(t *testing.T) {
}
}
-func TestGetApprovers(t *testing.T) {
- assert.NoError(t, unittest.PrepareTestDatabase())
+func testCodeOwnerAbsolutePathPatterns(t *testing.T) {
+ type testCase struct {
+ content string
+ file string
+ expected bool
+ }
+
+ cases := []testCase{
+ // Absolute path pattern should match (leading "/" stripped)
+ {content: "/README.md @user5\n", file: "README.md", expected: true},
+ // Absolute path pattern in subdirectory
+ {content: "/docs/.* @user5\n", file: "docs/foo.md", expected: true},
+ // Absolute path should not match nested paths it shouldn't
+ {content: "/docs/.* @user5\n", file: "other/docs/foo.md", expected: false},
+ // Relative path still works
+ {content: "README.md @user5\n", file: "README.md", expected: true},
+ // Negated absolute path pattern
+ {content: "!/.* @user5\n", file: "README.md", expected: false},
+ }
+
+ for _, c := range cases {
+ rules, _ := issues_model.GetCodeOwnersFromContent(t.Context(), c.content)
+ require.NotEmpty(t, rules)
+ rule := rules[0]
+ regexpMatched, _ := rule.Rule.MatchString(c.file)
+ ruleMatched := regexpMatched == !rule.Negative
+ assert.Equal(t, c.expected, ruleMatched, "pattern %q against file %q", c.content, c.file)
+ }
+}
+
+func testGetApprovers(t *testing.T) {
pr := unittest.AssertExistsAndLoadBean(t, &issues_model.PullRequest{ID: 5})
// Official reviews are already deduplicated. Allow unofficial reviews
// to assert that there are no duplicated approvers.
@@ -350,8 +386,7 @@ func TestGetApprovers(t *testing.T) {
assert.Equal(t, expected, approvers)
}
-func TestGetPullRequestByMergedCommit(t *testing.T) {
- assert.NoError(t, unittest.PrepareTestDatabase())
+func testGetPullRequestByMergedCommit(t *testing.T) {
pr, err := issues_model.GetPullRequestByMergedCommit(t.Context(), 1, "1a8823cd1a9549fde083f992f6b9b87a7ab74fb3")
assert.NoError(t, err)
assert.EqualValues(t, 1, pr.ID)
@@ -362,8 +397,7 @@ func TestGetPullRequestByMergedCommit(t *testing.T) {
assert.ErrorAs(t, err, &issues_model.ErrPullRequestNotExist{})
}
-func TestMigrate_InsertPullRequests(t *testing.T) {
- assert.NoError(t, unittest.PrepareTestDatabase())
+func testMigrateInsertPullRequests(t *testing.T) {
reponame := "repo1"
repo := unittest.AssertExistsAndLoadBean(t, &repo_model.Repository{Name: reponame})
owner := unittest.AssertExistsAndLoadBean(t, &user_model.User{ID: repo.OwnerID})
diff --git a/models/issues/review.go b/models/issues/review.go
index b758fa5ffa..ed727f17c1 100644
--- a/models/issues/review.go
+++ b/models/issues/review.go
@@ -176,15 +176,7 @@ func (r *Review) LoadReviewer(ctx context.Context) (err error) {
if r.ReviewerID == 0 || r.Reviewer != nil {
return err
}
- r.Reviewer, err = user_model.GetPossibleUserByID(ctx, r.ReviewerID)
- if err != nil {
- if !user_model.IsErrUserNotExist(err) {
- return fmt.Errorf("GetPossibleUserByID [%d]: %w", r.ReviewerID, err)
- }
- r.ReviewerID = user_model.GhostUserID
- r.Reviewer = user_model.NewGhostUser()
- return nil
- }
+ r.ReviewerID, r.Reviewer, err = user_model.GetPossibleUserByID(ctx, r.ReviewerID)
return err
}
@@ -215,25 +207,25 @@ func (r *Review) LoadAttributes(ctx context.Context) (err error) {
return err
}
-// HTMLTypeColorName returns the color used in the ui indicating the review
-func (r *Review) HTMLTypeColorName() string {
+// HTMLTypeColorClass returns the CSS class used in the ui indicating the review
+func (r *Review) HTMLTypeColorClass() string {
switch r.Type {
case ReviewTypeApprove:
if !r.Official {
- return "grey"
+ return "tw-text-text-light"
}
if r.Stale {
- return "yellow"
+ return "tw-text-yellow"
}
- return "green"
+ return "tw-text-green"
case ReviewTypeComment:
- return "grey"
+ return "tw-text-text-light"
case ReviewTypeReject:
- return "red"
+ return "tw-text-red"
case ReviewTypeRequest:
- return "yellow"
+ return "tw-text-yellow"
}
- return "grey"
+ return "tw-text-text-light"
}
// TooltipContent returns the locale string describing the review type
@@ -384,7 +376,7 @@ func CreateReview(ctx context.Context, opts CreateReviewOptions) (*Review, error
// GetCurrentReview returns the current pending review of reviewer for given issue
func GetCurrentReview(ctx context.Context, reviewer *user_model.User, issue *Issue) (*Review, error) {
if reviewer == nil {
- return nil, nil
+ return nil, nil //nolint:nilnil // return nil when reviewer is nil
}
reviews, err := FindReviews(ctx, FindReviewOptions{
Types: []ReviewType{ReviewTypePending},
@@ -643,7 +635,7 @@ func InsertReviews(ctx context.Context, reviews []*Review) error {
}
// AddReviewRequest add a review request from one reviewer
-func AddReviewRequest(ctx context.Context, issue *Issue, reviewer, doer *user_model.User) (*Comment, error) {
+func AddReviewRequest(ctx context.Context, issue *Issue, reviewer, doer *user_model.User, isCodeOwners bool) (*Comment, error) {
return db.WithTx2(ctx, func(ctx context.Context) (*Comment, error) {
sess := db.GetEngine(ctx)
@@ -702,6 +694,7 @@ func AddReviewRequest(ctx context.Context, issue *Issue, reviewer, doer *user_mo
RemovedAssignee: false, // Use RemovedAssignee as !isRequest
AssigneeID: reviewer.ID, // Use AssigneeID as reviewer ID
ReviewID: review.ID,
+ SpecialDoerName: util.Iif(isCodeOwners, SpecialDoerNameCodeOwners, ""),
})
if err != nil {
return nil, err
@@ -767,7 +760,7 @@ func restoreLatestOfficialReview(ctx context.Context, issueID, reviewerID int64)
}
// AddTeamReviewRequest add a review request from one team
-func AddTeamReviewRequest(ctx context.Context, issue *Issue, reviewer *organization.Team, doer *user_model.User) (*Comment, error) {
+func AddTeamReviewRequest(ctx context.Context, issue *Issue, reviewer *organization.Team, doer *user_model.User, isCodeOwners bool) (*Comment, error) {
return db.WithTx2(ctx, func(ctx context.Context) (*Comment, error) {
review, err := GetTeamReviewerByIssueIDAndTeamID(ctx, issue.ID, reviewer.ID)
if err != nil && !IsErrReviewNotExist(err) {
@@ -812,6 +805,7 @@ func AddTeamReviewRequest(ctx context.Context, issue *Issue, reviewer *organizat
RemovedAssignee: false, // Use RemovedAssignee as !isRequest
AssigneeTeamID: reviewer.ID, // Use AssigneeTeamID as reviewer team ID
ReviewID: review.ID,
+ SpecialDoerName: util.Iif(isCodeOwners, SpecialDoerNameCodeOwners, ""),
})
if err != nil {
return nil, fmt.Errorf("CreateComment(): %w", err)
@@ -917,7 +911,7 @@ func CanMarkConversation(ctx context.Context, issue *Issue, doer *user_model.Use
return false, nil
}
if doer.ID != issue.PosterID {
- p, err := access_model.GetUserRepoPermission(ctx, issue.Repo, doer)
+ p, err := access_model.GetDoerRepoPermission(ctx, issue.Repo, doer)
if err != nil {
return false, err
}
diff --git a/models/issues/review_list.go b/models/issues/review_list.go
index 86b1a2e76e..d0430cd06d 100644
--- a/models/issues/review_list.go
+++ b/models/issues/review_list.go
@@ -173,9 +173,9 @@ func GetReviewsByIssueID(ctx context.Context, issueID int64) (latestReviews, mig
reviewersMap := make(map[int64][]*Review) // key is reviewer id
originalReviewersMap := make(map[int64][]*Review) // key is original author id
reviewTeamsMap := make(map[int64][]*Review) // key is reviewer team id
- countedReivewTypes := []ReviewType{ReviewTypeApprove, ReviewTypeReject, ReviewTypeRequest, ReviewTypeComment}
+ countedReviewTypes := []ReviewType{ReviewTypeApprove, ReviewTypeReject, ReviewTypeRequest, ReviewTypeComment}
for _, review := range reviews {
- if review.ReviewerTeamID == 0 && slices.Contains(countedReivewTypes, review.Type) && !review.Dismissed {
+ if review.ReviewerTeamID == 0 && slices.Contains(countedReviewTypes, review.Type) && !review.Dismissed {
if review.OriginalAuthorID != 0 {
originalReviewersMap[review.OriginalAuthorID] = append(originalReviewersMap[review.OriginalAuthorID], review)
} else {
diff --git a/models/issues/review_test.go b/models/issues/review_test.go
index 6795ea8e66..092d88d174 100644
--- a/models/issues/review_test.go
+++ b/models/issues/review_test.go
@@ -321,14 +321,28 @@ func TestAddReviewRequest(t *testing.T) {
pull.HasMerged = false
assert.NoError(t, pull.UpdateCols(t.Context(), "has_merged"))
issue.IsClosed = true
- _, err = issues_model.AddReviewRequest(t.Context(), issue, reviewer, &user_model.User{})
+ _, err = issues_model.AddReviewRequest(t.Context(), issue, reviewer, &user_model.User{}, false)
assert.Error(t, err)
assert.True(t, issues_model.IsErrReviewRequestOnClosedPR(err))
pull.HasMerged = true
assert.NoError(t, pull.UpdateCols(t.Context(), "has_merged"))
issue.IsClosed = false
- _, err = issues_model.AddReviewRequest(t.Context(), issue, reviewer, &user_model.User{})
+ _, err = issues_model.AddReviewRequest(t.Context(), issue, reviewer, &user_model.User{}, false)
assert.Error(t, err)
assert.True(t, issues_model.IsErrReviewRequestOnClosedPR(err))
+
+ // Test CODEOWNERS review request stores metadata correctly
+ pull2 := unittest.AssertExistsAndLoadBean(t, &issues_model.PullRequest{ID: 2})
+ assert.NoError(t, pull2.LoadIssue(t.Context()))
+ issue2 := pull2.Issue
+ assert.NoError(t, issue2.LoadRepo(t.Context()))
+ reviewer2 := unittest.AssertExistsAndLoadBean(t, &user_model.User{ID: 7})
+ doer := unittest.AssertExistsAndLoadBean(t, &user_model.User{ID: 2})
+
+ comment, err := issues_model.AddReviewRequest(t.Context(), issue2, reviewer2, doer, true)
+ assert.NoError(t, err)
+ assert.NotNil(t, comment)
+ assert.NotNil(t, comment.CommentMetaData)
+ assert.Equal(t, issues_model.SpecialDoerNameCodeOwners, comment.CommentMetaData.SpecialDoerName)
}
diff --git a/models/issues/stopwatch.go b/models/issues/stopwatch.go
index 761b8f91a0..f119951b09 100644
--- a/models/issues/stopwatch.go
+++ b/models/issues/stopwatch.go
@@ -12,6 +12,8 @@ import (
user_model "code.gitea.io/gitea/models/user"
"code.gitea.io/gitea/modules/timeutil"
"code.gitea.io/gitea/modules/util"
+
+ "xorm.io/builder"
)
// Stopwatch represents a stopwatch for time tracking.
@@ -232,3 +234,14 @@ func CancelStopwatch(ctx context.Context, user *user_model.User, issue *Issue) (
})
return ok, err
}
+
+// RemoveStopwatchesByRepoID removes all stopwatches for a user in a specific repository
+// this function should be called before removing all the issues of the repository
+func RemoveStopwatchesByRepoID(ctx context.Context, userID, repoID int64) error {
+ _, err := db.GetEngine(ctx).
+ Where("`stopwatch`.user_id = ?", userID).
+ And(builder.In("`stopwatch`.issue_id",
+ builder.Select("id").From("issue").Where(builder.Eq{"repo_id": repoID}))).
+ Delete(new(Stopwatch))
+ return err
+}
diff --git a/models/issues/tracked_time.go b/models/issues/tracked_time.go
index 9c11881e44..0b5c341f1f 100644
--- a/models/issues/tracked_time.go
+++ b/models/issues/tracked_time.go
@@ -311,13 +311,13 @@ func deleteTime(ctx context.Context, t *TrackedTime) error {
}
// GetTrackedTimeByID returns raw TrackedTime without loading attributes by id
-func GetTrackedTimeByID(ctx context.Context, id int64) (*TrackedTime, error) {
+func GetTrackedTimeByID(ctx context.Context, issueID, trackedTimeID int64) (*TrackedTime, error) {
time := new(TrackedTime)
- has, err := db.GetEngine(ctx).ID(id).Get(time)
+ has, err := db.GetEngine(ctx).ID(trackedTimeID).Where("issue_id = ?", issueID).Get(time)
if err != nil {
return nil, err
} else if !has {
- return nil, db.ErrNotExist{Resource: "tracked_time", ID: id}
+ return nil, db.ErrNotExist{Resource: "tracked_time", ID: trackedTimeID}
}
return time, nil
}
diff --git a/models/migrations/base/db.go b/models/migrations/base/db.go
index 479a46379c..16048c2073 100644
--- a/models/migrations/base/db.go
+++ b/models/migrations/base/db.go
@@ -5,21 +5,14 @@ package base
import (
"context"
- "database/sql"
"errors"
"fmt"
- "os"
- "path"
"reflect"
"regexp"
"strings"
- "time"
- "code.gitea.io/gitea/models/db"
- "code.gitea.io/gitea/models/unittest"
"code.gitea.io/gitea/modules/log"
"code.gitea.io/gitea/modules/setting"
- "code.gitea.io/gitea/modules/util"
"xorm.io/xorm"
"xorm.io/xorm/schemas"
@@ -409,7 +402,7 @@ func DropTableColumns(sess *xorm.Session, tableName string, columnNames ...strin
cols += "DROP COLUMN `" + col + "` CASCADE"
}
if _, err := sess.Exec(fmt.Sprintf("ALTER TABLE `%s` %s", tableName, cols)); err != nil {
- return fmt.Errorf("Drop table `%s` columns %v: %v", tableName, columnNames, err)
+ return fmt.Errorf("drop table `%s` columns %v: %w", tableName, columnNames, err)
}
case setting.Database.Type.IsMySQL():
// Drop indexes on columns first
@@ -437,7 +430,7 @@ func DropTableColumns(sess *xorm.Session, tableName string, columnNames ...strin
cols += "DROP COLUMN `" + col + "`"
}
if _, err := sess.Exec(fmt.Sprintf("ALTER TABLE `%s` %s", tableName, cols)); err != nil {
- return fmt.Errorf("Drop table `%s` columns %v: %v", tableName, columnNames, err)
+ return fmt.Errorf("drop table `%s` columns %v: %w", tableName, columnNames, err)
}
case setting.Database.Type.IsMSSQL():
cols := ""
@@ -451,27 +444,27 @@ func DropTableColumns(sess *xorm.Session, tableName string, columnNames ...strin
tableName, strings.ReplaceAll(cols, "`", "'"))
constraints := make([]string, 0)
if err := sess.SQL(sql).Find(&constraints); err != nil {
- return fmt.Errorf("Find constraints: %v", err)
+ return fmt.Errorf("find constraints: %w", err)
}
for _, constraint := range constraints {
if _, err := sess.Exec(fmt.Sprintf("ALTER TABLE `%s` DROP CONSTRAINT `%s`", tableName, constraint)); err != nil {
- return fmt.Errorf("Drop table `%s` default constraint `%s`: %v", tableName, constraint, err)
+ return fmt.Errorf("drop table `%s` default constraint `%s`: %w", tableName, constraint, err)
}
}
sql = fmt.Sprintf("SELECT DISTINCT Name FROM sys.indexes INNER JOIN sys.index_columns ON indexes.index_id = index_columns.index_id AND indexes.object_id = index_columns.object_id WHERE indexes.object_id = OBJECT_ID('%[1]s') AND index_columns.column_id IN (SELECT column_id FROM sys.columns WHERE LOWER(name) IN (%[2]s) AND object_id = OBJECT_ID('%[1]s'))",
tableName, strings.ReplaceAll(cols, "`", "'"))
constraints = make([]string, 0)
if err := sess.SQL(sql).Find(&constraints); err != nil {
- return fmt.Errorf("Find constraints: %v", err)
+ return fmt.Errorf("find constraints: %w", err)
}
for _, constraint := range constraints {
if _, err := sess.Exec(fmt.Sprintf("DROP INDEX `%[2]s` ON `%[1]s`", tableName, constraint)); err != nil {
- return fmt.Errorf("Drop index `%[2]s` on `%[1]s`: %v", tableName, constraint, err)
+ return fmt.Errorf("drop index `%[2]s` on `%[1]s`: %[3]w", tableName, constraint, err)
}
}
if _, err := sess.Exec(fmt.Sprintf("ALTER TABLE `%s` DROP COLUMN %s", tableName, cols)); err != nil {
- return fmt.Errorf("Drop table `%s` columns %v: %v", tableName, columnNames, err)
+ return fmt.Errorf("drop table `%s` columns %v: %w", tableName, columnNames, err)
}
default:
log.Fatal("Unrecognized DB")
@@ -515,114 +508,3 @@ func ModifyColumn(x *xorm.Engine, tableName string, col *schemas.Column) error {
}
return nil
}
-
-func removeAllWithRetry(dir string) error {
- var err error
- for range 20 {
- err = os.RemoveAll(dir)
- if err == nil {
- break
- }
- time.Sleep(100 * time.Millisecond)
- }
- return err
-}
-
-func newXORMEngine() (*xorm.Engine, error) {
- if err := db.InitEngine(context.Background()); err != nil {
- return nil, err
- }
- x := unittest.GetXORMEngine()
- return x, nil
-}
-
-func deleteDB() error {
- switch {
- case setting.Database.Type.IsSQLite3():
- if err := util.Remove(setting.Database.Path); err != nil {
- return err
- }
- return os.MkdirAll(path.Dir(setting.Database.Path), os.ModePerm)
-
- case setting.Database.Type.IsMySQL():
- db, err := sql.Open("mysql", fmt.Sprintf("%s:%s@tcp(%s)/",
- setting.Database.User, setting.Database.Passwd, setting.Database.Host))
- if err != nil {
- return err
- }
- defer db.Close()
-
- if _, err = db.Exec("DROP DATABASE IF EXISTS " + setting.Database.Name); err != nil {
- return err
- }
-
- if _, err = db.Exec("CREATE DATABASE IF NOT EXISTS " + setting.Database.Name); err != nil {
- return err
- }
- return nil
- case setting.Database.Type.IsPostgreSQL():
- db, err := sql.Open("postgres", fmt.Sprintf("postgres://%s:%s@%s/?sslmode=%s",
- setting.Database.User, setting.Database.Passwd, setting.Database.Host, setting.Database.SSLMode))
- if err != nil {
- return err
- }
- defer db.Close()
-
- if _, err = db.Exec("DROP DATABASE IF EXISTS " + setting.Database.Name); err != nil {
- return err
- }
-
- if _, err = db.Exec("CREATE DATABASE " + setting.Database.Name); err != nil {
- return err
- }
- db.Close()
-
- // Check if we need to setup a specific schema
- if len(setting.Database.Schema) != 0 {
- db, err = sql.Open("postgres", fmt.Sprintf("postgres://%s:%s@%s/%s?sslmode=%s",
- setting.Database.User, setting.Database.Passwd, setting.Database.Host, setting.Database.Name, setting.Database.SSLMode))
- if err != nil {
- return err
- }
- defer db.Close()
-
- schrows, err := db.Query(fmt.Sprintf("SELECT 1 FROM information_schema.schemata WHERE schema_name = '%s'", setting.Database.Schema))
- if err != nil {
- return err
- }
- defer schrows.Close()
-
- if !schrows.Next() {
- // Create and setup a DB schema
- _, err = db.Exec("CREATE SCHEMA " + setting.Database.Schema)
- if err != nil {
- return err
- }
- }
-
- // Make the user's default search path the created schema; this will affect new connections
- _, err = db.Exec(fmt.Sprintf(`ALTER USER "%s" SET search_path = %s`, setting.Database.User, setting.Database.Schema))
- if err != nil {
- return err
- }
- return nil
- }
- case setting.Database.Type.IsMSSQL():
- host, port := setting.ParseMSSQLHostPort(setting.Database.Host)
- db, err := sql.Open("mssql", fmt.Sprintf("server=%s; port=%s; database=%s; user id=%s; password=%s;",
- host, port, "master", setting.Database.User, setting.Database.Passwd))
- if err != nil {
- return err
- }
- defer db.Close()
-
- if _, err = db.Exec(fmt.Sprintf("DROP DATABASE IF EXISTS [%s]", setting.Database.Name)); err != nil {
- return err
- }
- if _, err = db.Exec(fmt.Sprintf("CREATE DATABASE [%s]", setting.Database.Name)); err != nil {
- return err
- }
- }
-
- return nil
-}
diff --git a/models/migrations/base/db_test.go b/models/migrations/base/db_test.go
index 80bf00b22a..00635ca72e 100644
--- a/models/migrations/base/db_test.go
+++ b/models/migrations/base/db_test.go
@@ -11,6 +11,10 @@ import (
"xorm.io/xorm/names"
)
+func TestMain(m *testing.M) {
+ MainTest(m)
+}
+
func Test_DropTableColumns(t *testing.T) {
x, deferable := PrepareTestEnv(t, 0)
if x == nil || t.Failed() {
diff --git a/models/migrations/base/main_test.go b/models/migrations/base/main_test.go
deleted file mode 100644
index c1c789150f..0000000000
--- a/models/migrations/base/main_test.go
+++ /dev/null
@@ -1,12 +0,0 @@
-// Copyright 2021 The Gitea Authors. All rights reserved.
-// SPDX-License-Identifier: MIT
-
-package base
-
-import (
- "testing"
-)
-
-func TestMain(m *testing.M) {
- MainTest(m)
-}
diff --git a/models/migrations/base/tests.go b/models/migrations/base/tests.go
index 3b52a5e7c7..17ea951b5a 100644
--- a/models/migrations/base/tests.go
+++ b/models/migrations/base/tests.go
@@ -4,25 +4,127 @@
package base
import (
+ "database/sql"
"fmt"
"os"
+ "path"
"path/filepath"
- "runtime"
"testing"
+ "code.gitea.io/gitea/models/db"
"code.gitea.io/gitea/models/unittest"
"code.gitea.io/gitea/modules/git"
"code.gitea.io/gitea/modules/setting"
"code.gitea.io/gitea/modules/tempdir"
- "code.gitea.io/gitea/modules/test"
"code.gitea.io/gitea/modules/testlogger"
+ "code.gitea.io/gitea/modules/util"
"github.com/stretchr/testify/require"
"xorm.io/xorm"
+ "xorm.io/xorm/schemas"
)
// FIXME: this file shouldn't be in a normal package, it should only be compiled for tests
+func newXORMEngine(t *testing.T) (*xorm.Engine, error) {
+ if err := db.InitEngine(t.Context()); err != nil {
+ return nil, err
+ }
+ x := unittest.GetXORMEngine()
+ return x, nil
+}
+
+func deleteDB() error {
+ switch {
+ case setting.Database.Type.IsSQLite3():
+ if err := util.Remove(setting.Database.Path); err != nil {
+ return err
+ }
+ return os.MkdirAll(path.Dir(setting.Database.Path), os.ModePerm)
+
+ case setting.Database.Type.IsMySQL():
+ db, err := sql.Open("mysql", fmt.Sprintf("%s:%s@tcp(%s)/",
+ setting.Database.User, setting.Database.Passwd, setting.Database.Host))
+ if err != nil {
+ return err
+ }
+ defer db.Close()
+
+ if _, err = db.Exec("DROP DATABASE IF EXISTS " + setting.Database.Name); err != nil {
+ return err
+ }
+
+ if _, err = db.Exec("CREATE DATABASE IF NOT EXISTS " + setting.Database.Name); err != nil {
+ return err
+ }
+ return nil
+ case setting.Database.Type.IsPostgreSQL():
+ db, err := sql.Open("postgres", fmt.Sprintf("postgres://%s:%s@%s/?sslmode=%s",
+ setting.Database.User, setting.Database.Passwd, setting.Database.Host, setting.Database.SSLMode))
+ if err != nil {
+ return err
+ }
+ defer db.Close()
+
+ if _, err = db.Exec("DROP DATABASE IF EXISTS " + setting.Database.Name); err != nil {
+ return err
+ }
+
+ if _, err = db.Exec("CREATE DATABASE " + setting.Database.Name); err != nil {
+ return err
+ }
+ db.Close()
+
+ // Check if we need to setup a specific schema
+ if len(setting.Database.Schema) != 0 {
+ db, err = sql.Open("postgres", fmt.Sprintf("postgres://%s:%s@%s/%s?sslmode=%s",
+ setting.Database.User, setting.Database.Passwd, setting.Database.Host, setting.Database.Name, setting.Database.SSLMode))
+ if err != nil {
+ return err
+ }
+ defer db.Close()
+
+ schrows, err := db.Query(fmt.Sprintf("SELECT 1 FROM information_schema.schemata WHERE schema_name = '%s'", setting.Database.Schema))
+ if err != nil {
+ return err
+ }
+ defer schrows.Close()
+
+ if !schrows.Next() {
+ // Create and setup a DB schema
+ _, err = db.Exec("CREATE SCHEMA " + setting.Database.Schema)
+ if err != nil {
+ return err
+ }
+ }
+
+ // Make the user's default search path the created schema; this will affect new connections
+ _, err = db.Exec(fmt.Sprintf(`ALTER USER "%s" SET search_path = %s`, setting.Database.User, setting.Database.Schema))
+ if err != nil {
+ return err
+ }
+ return nil
+ }
+ case setting.Database.Type.IsMSSQL():
+ host, port := setting.ParseMSSQLHostPort(setting.Database.Host)
+ db, err := sql.Open("mssql", fmt.Sprintf("server=%s; port=%s; database=%s; user id=%s; password=%s;",
+ host, port, "master", setting.Database.User, setting.Database.Passwd))
+ if err != nil {
+ return err
+ }
+ defer db.Close()
+
+ if _, err = db.Exec(fmt.Sprintf("DROP DATABASE IF EXISTS [%s]", setting.Database.Name)); err != nil {
+ return err
+ }
+ if _, err = db.Exec(fmt.Sprintf("CREATE DATABASE [%s]", setting.Database.Name)); err != nil {
+ return err
+ }
+ }
+
+ return nil
+}
+
// PrepareTestEnv prepares the test environment and reset the database. The skip parameter should usually be 0.
// Provide models to be sync'd with the database - in particular any models you expect fixtures to be loaded from.
//
@@ -39,7 +141,7 @@ func PrepareTestEnv(t *testing.T, skip int, syncModels ...any) (*xorm.Engine, fu
return nil, deferFn
}
- x, err := newXORMEngine()
+ x, err := newXORMEngine(t)
require.NoError(t, err)
if x != nil {
oldDefer := deferFn
@@ -88,51 +190,36 @@ func PrepareTestEnv(t *testing.T, skip int, syncModels ...any) (*xorm.Engine, fu
return x, deferFn
}
-func MainTest(m *testing.M) {
- testlogger.Init()
-
- giteaRoot := test.SetupGiteaRoot()
- giteaBinary := "gitea"
- if runtime.GOOS == "windows" {
- giteaBinary += ".exe"
- }
- setting.AppPath = filepath.Join(giteaRoot, giteaBinary)
- if _, err := os.Stat(setting.AppPath); err != nil {
- testlogger.Fatalf("Could not find gitea binary at %s\n", setting.AppPath)
- }
-
- giteaConf := os.Getenv("GITEA_CONF")
- if giteaConf == "" {
- giteaConf = filepath.Join(filepath.Dir(setting.AppPath), "tests/sqlite.ini")
- _, _ = fmt.Fprintf(os.Stderr, "Environment variable $GITEA_CONF not set - defaulting to %s\n", giteaConf)
+func LoadTableSchemasMap(t *testing.T, x *xorm.Engine) map[string]*schemas.Table {
+ tables, err := x.DBMetas()
+ require.NoError(t, err)
+ tableMap := make(map[string]*schemas.Table)
+ for _, table := range tables {
+ tableMap[table.Name] = table
}
+ return tableMap
+}
- if !filepath.IsAbs(giteaConf) {
- setting.CustomConf = filepath.Join(giteaRoot, giteaConf)
- } else {
- setting.CustomConf = giteaConf
- }
+func mainTest(m *testing.M) int {
+ testlogger.Init()
tmpDataPath, cleanup, err := tempdir.OsTempDir("gitea-test").MkdirTempRandom("data")
if err != nil {
- testlogger.Fatalf("Unable to create temporary data path %v\n", err)
+ testlogger.Panicf("Unable to create temporary data path %v\n", err)
}
defer cleanup()
- setting.CustomPath = filepath.Join(setting.AppWorkPath, "custom")
setting.AppDataPath = tmpDataPath
unittest.InitSettingsForTesting()
if err = git.InitFull(); err != nil {
- testlogger.Fatalf("Unable to InitFull: %v\n", err)
+ testlogger.Panicf("Unable to InitFull: %v\n", err)
}
setting.LoadDBSetting()
setting.InitLoggersForTest()
+ return m.Run()
+}
- exitStatus := m.Run()
-
- if err := removeAllWithRetry(setting.RepoRootPath); err != nil {
- _, _ = fmt.Fprintf(os.Stderr, "os.RemoveAll: %v\n", err)
- }
- os.Exit(exitStatus)
+func MainTest(m *testing.M) {
+ os.Exit(mainTest(m))
}
diff --git a/models/migrations/fixtures/Test_FixCommitStatusTargetURLToUseRunAndJobID/action_run.yml b/models/migrations/fixtures/Test_FixCommitStatusTargetURLToUseRunAndJobID/action_run.yml
new file mode 100644
index 0000000000..49f71ce3fc
--- /dev/null
+++ b/models/migrations/fixtures/Test_FixCommitStatusTargetURLToUseRunAndJobID/action_run.yml
@@ -0,0 +1,29 @@
+# type ActionRun struct {
+# ID int64 `xorm:"pk autoincr"`
+# RepoID int64 `xorm:"index"`
+# Index int64
+# CommitSHA string `xorm:"commit_sha"`
+# Event string
+# TriggerEvent string
+# EventPayload string `xorm:"LONGTEXT"`
+# }
+-
+ id: 990
+ repo_id: 100
+ index: 7
+ commit_sha: merge-sha
+ event: pull_request
+ event_payload: '{"pull_request":{"head":{"sha":"sha-shared"}}}'
+-
+ id: 991
+ repo_id: 100
+ index: 8
+ commit_sha: sha-shared
+ event: push
+ event_payload: '{"head_commit":{"id":"sha-shared"}}'
+-
+ id: 1991
+ repo_id: 100
+ index: 9
+ commit_sha: sha-other
+ event: release
diff --git a/models/migrations/fixtures/Test_FixCommitStatusTargetURLToUseRunAndJobID/action_run_job.yml b/models/migrations/fixtures/Test_FixCommitStatusTargetURLToUseRunAndJobID/action_run_job.yml
new file mode 100644
index 0000000000..addf5e0682
--- /dev/null
+++ b/models/migrations/fixtures/Test_FixCommitStatusTargetURLToUseRunAndJobID/action_run_job.yml
@@ -0,0 +1,16 @@
+# type ActionRunJob struct {
+# ID int64 `xorm:"pk autoincr"`
+# RunID int64 `xorm:"index"`
+# }
+-
+ id: 997
+ run_id: 990
+-
+ id: 998
+ run_id: 990
+-
+ id: 1997
+ run_id: 991
+-
+ id: 1998
+ run_id: 1991
diff --git a/models/migrations/fixtures/Test_FixCommitStatusTargetURLToUseRunAndJobID/commit_status.yml b/models/migrations/fixtures/Test_FixCommitStatusTargetURLToUseRunAndJobID/commit_status.yml
new file mode 100644
index 0000000000..6be1c7ca48
--- /dev/null
+++ b/models/migrations/fixtures/Test_FixCommitStatusTargetURLToUseRunAndJobID/commit_status.yml
@@ -0,0 +1,51 @@
+# type CommitStatus struct {
+# ID int64 `xorm:"pk autoincr"`
+# RepoID int64 `xorm:"index"`
+# SHA string
+# TargetURL string
+# }
+-
+ id: 10010
+ repo_id: 100
+ sha: sha-shared
+ target_url: /testuser/repo1/actions/runs/7/jobs/0
+-
+ id: 10011
+ repo_id: 100
+ sha: sha-shared
+ target_url: /testuser/repo1/actions/runs/7/jobs/1
+-
+ id: 10012
+ repo_id: 100
+ sha: sha-shared
+ target_url: /testuser/repo1/actions/runs/8/jobs/0
+-
+ id: 10013
+ repo_id: 100
+ sha: sha-other
+ target_url: /testuser/repo1/actions/runs/9/jobs/0
+-
+ id: 10014
+ repo_id: 100
+ sha: sha-shared
+ target_url: /otheruser/badrepo/actions/runs/7/jobs/0
+-
+ id: 10015
+ repo_id: 100
+ sha: sha-shared
+ target_url: /testuser/repo1/actions/runs/10/jobs/0
+-
+ id: 10016
+ repo_id: 100
+ sha: sha-shared
+ target_url: /testuser/repo1/actions/runs/7/jobs/3
+-
+ id: 10017
+ repo_id: 100
+ sha: sha-shared
+ target_url: https://ci.example.com/build/123
+-
+ id: 10018
+ repo_id: 100
+ sha: sha-shared
+ target_url: /testuser/repo1/actions/runs/990/jobs/997
diff --git a/models/migrations/fixtures/Test_FixCommitStatusTargetURLToUseRunAndJobID/commit_status_summary.yml b/models/migrations/fixtures/Test_FixCommitStatusTargetURLToUseRunAndJobID/commit_status_summary.yml
new file mode 100644
index 0000000000..3dd846bb36
--- /dev/null
+++ b/models/migrations/fixtures/Test_FixCommitStatusTargetURLToUseRunAndJobID/commit_status_summary.yml
@@ -0,0 +1,19 @@
+# type CommitStatusSummary struct {
+# ID int64 `xorm:"pk autoincr"`
+# RepoID int64 `xorm:"index"`
+# SHA string `xorm:"VARCHAR(64) NOT NULL"`
+# State string `xorm:"VARCHAR(7) NOT NULL"`
+# TargetURL string
+# }
+-
+ id: 10020
+ repo_id: 100
+ sha: sha-shared
+ state: pending
+ target_url: /testuser/repo1/actions/runs/7/jobs/0
+-
+ id: 10021
+ repo_id: 100
+ sha: sha-other
+ state: pending
+ target_url: /testuser/repo1/actions/runs/9/jobs/0
diff --git a/models/migrations/fixtures/Test_FixCommitStatusTargetURLToUseRunAndJobID/repository.yml b/models/migrations/fixtures/Test_FixCommitStatusTargetURLToUseRunAndJobID/repository.yml
new file mode 100644
index 0000000000..46162e7803
--- /dev/null
+++ b/models/migrations/fixtures/Test_FixCommitStatusTargetURLToUseRunAndJobID/repository.yml
@@ -0,0 +1,9 @@
+# type Repository struct {
+# ID int64 `xorm:"pk autoincr"`
+# OwnerName string
+# Name string
+# }
+-
+ id: 100
+ owner_name: testuser
+ name: repo1
diff --git a/models/migrations/migrations.go b/models/migrations/migrations.go
index 1b1558f39d..db74ff78d5 100644
--- a/models/migrations/migrations.go
+++ b/models/migrations/migrations.go
@@ -25,6 +25,7 @@ import (
"code.gitea.io/gitea/models/migrations/v1_23"
"code.gitea.io/gitea/models/migrations/v1_24"
"code.gitea.io/gitea/models/migrations/v1_25"
+ "code.gitea.io/gitea/models/migrations/v1_26"
"code.gitea.io/gitea/models/migrations/v1_6"
"code.gitea.io/gitea/models/migrations/v1_7"
"code.gitea.io/gitea/models/migrations/v1_8"
@@ -379,8 +380,8 @@ func prepareMigrationTasks() []*migration {
newMigration(309, "Improve Notification table indices", v1_23.ImproveNotificationTableIndices),
newMigration(310, "Add Priority to ProtectedBranch", v1_23.AddPriorityToProtectedBranch),
newMigration(311, "Add TimeEstimate to Issue table", v1_23.AddTimeEstimateColumnToIssueTable),
-
// Gitea 1.23.0-rc0 ends at migration ID number 311 (database version 312)
+
newMigration(312, "Add DeleteBranchAfterMerge to AutoMerge", v1_24.AddDeleteBranchAfterMergeForAutoMerge),
newMigration(313, "Move PinOrder from issue table to a new table issue_pin", v1_24.MovePinOrderToTableIssuePin),
newMigration(314, "Update OwnerID as zero for repository level action tables", v1_24.UpdateOwnerIDOfRepoLevelActionsTables),
@@ -390,10 +391,20 @@ func prepareMigrationTasks() []*migration {
newMigration(318, "Add anonymous_access_mode for repo_unit", v1_24.AddRepoUnitAnonymousAccessMode),
newMigration(319, "Add ExclusiveOrder to Label table", v1_24.AddExclusiveOrderColumnToLabelTable),
newMigration(320, "Migrate two_factor_policy to login_source table", v1_24.MigrateSkipTwoFactor),
+ // Gitea 1.24.0 ends at migration ID number 320 (database version 321)
- // Gitea 1.24.0 ends at database version 321
newMigration(321, "Use LONGTEXT for some columns and fix review_state.updated_files column", v1_25.UseLongTextInSomeColumnsAndFixBugs),
newMigration(322, "Extend comment tree_path length limit", v1_25.ExtendCommentTreePathLength),
+ // Gitea 1.25.0 ends at migration ID number 322 (database version 323)
+
+ newMigration(323, "Add support for actions concurrency", v1_26.AddActionsConcurrency),
+ newMigration(324, "Fix closed milestone completeness for milestones with no issues", v1_26.FixClosedMilestoneCompleteness),
+ newMigration(325, "Fix missed repo_id when migrate attachments", v1_26.FixMissedRepoIDWhenMigrateAttachments),
+ newMigration(326, "Partially migrate commit status target URL to use run ID and job ID", v1_26.FixCommitStatusTargetURLToUseRunAndJobID),
+ newMigration(327, "Add disabled state to action runners", v1_26.AddDisabledToActionRunner),
+ newMigration(328, "Add TokenPermissions column to ActionRunJob", v1_26.AddTokenPermissionsToActionRunJob),
+ newMigration(329, "Add unique constraint for user badge", v1_26.AddUniqueIndexForUserBadge),
+ newMigration(330, "Add name column to webhook", v1_26.AddNameToWebhook),
}
return preparedMigrations
}
diff --git a/models/migrations/v1_12/v128.go b/models/migrations/v1_12/v128.go
index 34746dcdc4..ff5b12af18 100644
--- a/models/migrations/v1_12/v128.go
+++ b/models/migrations/v1_12/v128.go
@@ -84,17 +84,17 @@ func FixMergeBase(ctx context.Context, x *xorm.Engine) error {
if !pr.HasMerged {
var err error
- pr.MergeBase, _, err = gitcmd.NewCommand("merge-base").AddDashesAndList(pr.BaseBranch, gitRefName).RunStdString(ctx, &gitcmd.RunOpts{Dir: repoPath})
+ pr.MergeBase, _, err = gitcmd.NewCommand("merge-base").AddDashesAndList(pr.BaseBranch, gitRefName).WithDir(repoPath).RunStdString(ctx)
if err != nil {
var err2 error
- pr.MergeBase, _, err2 = gitcmd.NewCommand("rev-parse").AddDynamicArguments(git.BranchPrefix+pr.BaseBranch).RunStdString(ctx, &gitcmd.RunOpts{Dir: repoPath})
+ pr.MergeBase, _, err2 = gitcmd.NewCommand("rev-parse").AddDynamicArguments(git.BranchPrefix + pr.BaseBranch).WithDir(repoPath).RunStdString(ctx)
if err2 != nil {
log.Error("Unable to get merge base for PR ID %d, Index %d in %s/%s. Error: %v & %v", pr.ID, pr.Index, baseRepo.OwnerName, baseRepo.Name, err, err2)
continue
}
}
} else {
- parentsString, _, err := gitcmd.NewCommand("rev-list", "--parents", "-n", "1").AddDynamicArguments(pr.MergedCommitID).RunStdString(ctx, &gitcmd.RunOpts{Dir: repoPath})
+ parentsString, _, err := gitcmd.NewCommand("rev-list", "--parents", "-n", "1").AddDynamicArguments(pr.MergedCommitID).WithDir(repoPath).RunStdString(ctx)
if err != nil {
log.Error("Unable to get parents for merged PR ID %d, Index %d in %s/%s. Error: %v", pr.ID, pr.Index, baseRepo.OwnerName, baseRepo.Name, err)
continue
@@ -108,7 +108,7 @@ func FixMergeBase(ctx context.Context, x *xorm.Engine) error {
refs = append(refs, gitRefName)
cmd := gitcmd.NewCommand("merge-base").AddDashesAndList(refs...)
- pr.MergeBase, _, err = cmd.RunStdString(ctx, &gitcmd.RunOpts{Dir: repoPath})
+ pr.MergeBase, _, err = cmd.WithDir(repoPath).RunStdString(ctx)
if err != nil {
log.Error("Unable to get merge base for merged PR ID %d, Index %d in %s/%s. Error: %v", pr.ID, pr.Index, baseRepo.OwnerName, baseRepo.Name, err)
continue
diff --git a/models/migrations/v1_12/v134.go b/models/migrations/v1_12/v134.go
index d31cc3abdb..98bb8dbda7 100644
--- a/models/migrations/v1_12/v134.go
+++ b/models/migrations/v1_12/v134.go
@@ -80,7 +80,7 @@ func RefixMergeBase(ctx context.Context, x *xorm.Engine) error {
gitRefName := fmt.Sprintf("refs/pull/%d/head", pr.Index)
- parentsString, _, err := gitcmd.NewCommand("rev-list", "--parents", "-n", "1").AddDynamicArguments(pr.MergedCommitID).RunStdString(ctx, &gitcmd.RunOpts{Dir: repoPath})
+ parentsString, _, err := gitcmd.NewCommand("rev-list", "--parents", "-n", "1").AddDynamicArguments(pr.MergedCommitID).WithDir(repoPath).RunStdString(ctx)
if err != nil {
log.Error("Unable to get parents for merged PR ID %d, Index %d in %s/%s. Error: %v", pr.ID, pr.Index, baseRepo.OwnerName, baseRepo.Name, err)
continue
@@ -95,7 +95,7 @@ func RefixMergeBase(ctx context.Context, x *xorm.Engine) error {
refs = append(refs, gitRefName)
cmd := gitcmd.NewCommand("merge-base").AddDashesAndList(refs...)
- pr.MergeBase, _, err = cmd.RunStdString(ctx, &gitcmd.RunOpts{Dir: repoPath})
+ pr.MergeBase, _, err = cmd.WithDir(repoPath).RunStdString(ctx)
if err != nil {
log.Error("Unable to get merge base for merged PR ID %d, Index %d in %s/%s. Error: %v", pr.ID, pr.Index, baseRepo.OwnerName, baseRepo.Name, err)
continue
diff --git a/models/migrations/v1_12/v136.go b/models/migrations/v1_12/v136.go
index 0f53278b46..20b892b6cc 100644
--- a/models/migrations/v1_12/v136.go
+++ b/models/migrations/v1_12/v136.go
@@ -6,11 +6,10 @@ package v1_12
import (
"fmt"
"math"
- "path/filepath"
- "strings"
"time"
- "code.gitea.io/gitea/modules/git"
+ repo_model "code.gitea.io/gitea/models/repo"
+ "code.gitea.io/gitea/modules/gitrepo"
"code.gitea.io/gitea/modules/graceful"
"code.gitea.io/gitea/modules/log"
"code.gitea.io/gitea/modules/setting"
@@ -85,12 +84,9 @@ func AddCommitDivergenceToPulls(x *xorm.Engine) error {
log.Error("Missing base repo with id %d for PR ID %d", pr.BaseRepoID, pr.ID)
continue
}
- userPath := filepath.Join(setting.RepoRootPath, strings.ToLower(baseRepo.OwnerName))
- repoPath := filepath.Join(userPath, strings.ToLower(baseRepo.Name)+".git")
-
+ repoStore := repo_model.StorageRepo(repo_model.RelativePath(baseRepo.OwnerName, baseRepo.Name))
gitRefName := fmt.Sprintf("refs/pull/%d/head", pr.Index)
-
- divergence, err := git.GetDivergingCommits(graceful.GetManager().HammerContext(), repoPath, pr.BaseBranch, gitRefName)
+ divergence, err := gitrepo.GetDivergingCommits(graceful.GetManager().HammerContext(), repoStore, pr.BaseBranch, gitRefName)
if err != nil {
log.Warn("Could not recalculate Divergence for pull: %d", pr.ID)
pr.CommitsAhead = 0
diff --git a/models/migrations/v1_21/v276.go b/models/migrations/v1_21/v276.go
index 3ab7e22cd0..be24b31902 100644
--- a/models/migrations/v1_21/v276.go
+++ b/models/migrations/v1_21/v276.go
@@ -5,14 +5,10 @@ package v1_21
import (
"context"
- "fmt"
- "path/filepath"
- "strings"
- "code.gitea.io/gitea/modules/git"
- giturl "code.gitea.io/gitea/modules/git/url"
+ repo_model "code.gitea.io/gitea/models/repo"
+ "code.gitea.io/gitea/modules/gitrepo"
"code.gitea.io/gitea/modules/setting"
- "code.gitea.io/gitea/modules/util"
"xorm.io/xorm"
)
@@ -163,16 +159,13 @@ func migratePushMirrors(x *xorm.Engine) error {
}
func getRemoteAddress(ownerName, repoName, remoteName string) (string, error) {
- repoPath := filepath.Join(setting.RepoRootPath, strings.ToLower(ownerName), strings.ToLower(repoName)+".git")
- if exist, _ := util.IsExist(repoPath); !exist {
+ ctx := context.Background()
+ relativePath := repo_model.RelativePath(ownerName, repoName)
+ if exist, _ := gitrepo.IsRepositoryExist(ctx, repo_model.StorageRepo(relativePath)); !exist {
return "", nil
}
- remoteURL, err := git.GetRemoteAddress(context.Background(), repoPath, remoteName)
- if err != nil {
- return "", fmt.Errorf("get remote %s's address of %s/%s failed: %v", remoteName, ownerName, repoName, err)
- }
- u, err := giturl.ParseGitURL(remoteURL)
+ u, err := gitrepo.GitRemoteGetURL(ctx, repo_model.StorageRepo(relativePath), remoteName)
if err != nil {
return "", err
}
diff --git a/models/migrations/v1_25/v321_test.go b/models/migrations/v1_25/v321_test.go
index 4897783fd3..3ef2c68aa3 100644
--- a/models/migrations/v1_25/v321_test.go
+++ b/models/migrations/v1_25/v321_test.go
@@ -11,6 +11,7 @@ import (
"code.gitea.io/gitea/modules/timeutil"
"github.com/stretchr/testify/assert"
+ "github.com/stretchr/testify/require"
)
func Test_UseLongTextInSomeColumnsAndFixBugs(t *testing.T) {
@@ -38,33 +39,26 @@ func Test_UseLongTextInSomeColumnsAndFixBugs(t *testing.T) {
type Notice struct {
ID int64 `xorm:"pk autoincr"`
Type int
- Description string `xorm:"LONGTEXT"`
+ Description string `xorm:"TEXT"`
CreatedUnix timeutil.TimeStamp `xorm:"INDEX created"`
}
// Prepare and load the testing database
- x, deferable := base.PrepareTestEnv(t, 0, new(ReviewState), new(PackageProperty), new(Notice))
- defer deferable()
+ x, deferrable := base.PrepareTestEnv(t, 0, new(ReviewState), new(PackageProperty), new(Notice))
+ defer deferrable()
- assert.NoError(t, UseLongTextInSomeColumnsAndFixBugs(x))
+ require.NoError(t, UseLongTextInSomeColumnsAndFixBugs(x))
- tables, err := x.DBMetas()
- assert.NoError(t, err)
+ tables := base.LoadTableSchemasMap(t, x)
+ table := tables["review_state"]
+ column := table.GetColumn("updated_files")
+ assert.Equal(t, "LONGTEXT", column.SQLType.Name)
- for _, table := range tables {
- switch table.Name {
- case "review_state":
- column := table.GetColumn("updated_files")
- assert.NotNil(t, column)
- assert.Equal(t, "LONGTEXT", column.SQLType.Name)
- case "package_property":
- column := table.GetColumn("value")
- assert.NotNil(t, column)
- assert.Equal(t, "LONGTEXT", column.SQLType.Name)
- case "notice":
- column := table.GetColumn("description")
- assert.NotNil(t, column)
- assert.Equal(t, "LONGTEXT", column.SQLType.Name)
- }
- }
+ table = tables["package_property"]
+ column = table.GetColumn("value")
+ assert.Equal(t, "LONGTEXT", column.SQLType.Name)
+
+ table = tables["notice"]
+ column = table.GetColumn("description")
+ assert.Equal(t, "LONGTEXT", column.SQLType.Name)
}
diff --git a/models/migrations/v1_25/v322_test.go b/models/migrations/v1_25/v322_test.go
new file mode 100644
index 0000000000..78d890704c
--- /dev/null
+++ b/models/migrations/v1_25/v322_test.go
@@ -0,0 +1,34 @@
+// Copyright 2025 The Gitea Authors. All rights reserved.
+// SPDX-License-Identifier: MIT
+
+package v1_25
+
+import (
+ "testing"
+
+ "code.gitea.io/gitea/models/migrations/base"
+ "code.gitea.io/gitea/modules/setting"
+
+ "github.com/stretchr/testify/assert"
+ "github.com/stretchr/testify/require"
+)
+
+func Test_ExtendCommentTreePathLength(t *testing.T) {
+ if setting.Database.Type.IsSQLite3() {
+ t.Skip("For SQLITE, varchar or char will always be represented as TEXT")
+ }
+
+ type Comment struct {
+ ID int64 `xorm:"pk autoincr"`
+ TreePath string `xorm:"VARCHAR(255)"`
+ }
+
+ x, deferrable := base.PrepareTestEnv(t, 0, new(Comment))
+ defer deferrable()
+
+ require.NoError(t, ExtendCommentTreePathLength(x))
+ table := base.LoadTableSchemasMap(t, x)["comment"]
+ column := table.GetColumn("tree_path")
+ assert.Contains(t, []string{"NVARCHAR", "VARCHAR"}, column.SQLType.Name)
+ assert.EqualValues(t, 4000, column.Length)
+}
diff --git a/models/migrations/v1_26/main_test.go b/models/migrations/v1_26/main_test.go
new file mode 100644
index 0000000000..5aa12d553c
--- /dev/null
+++ b/models/migrations/v1_26/main_test.go
@@ -0,0 +1,14 @@
+// Copyright 2025 The Gitea Authors. All rights reserved.
+// SPDX-License-Identifier: MIT
+
+package v1_26
+
+import (
+ "testing"
+
+ "code.gitea.io/gitea/models/migrations/base"
+)
+
+func TestMain(m *testing.M) {
+ base.MainTest(m)
+}
diff --git a/models/migrations/v1_26/v323.go b/models/migrations/v1_26/v323.go
new file mode 100644
index 0000000000..b116f73bf0
--- /dev/null
+++ b/models/migrations/v1_26/v323.go
@@ -0,0 +1,43 @@
+// Copyright 2025 The Gitea Authors. All rights reserved.
+// SPDX-License-Identifier: MIT
+
+package v1_26
+
+import (
+ "xorm.io/xorm"
+)
+
+func AddActionsConcurrency(x *xorm.Engine) error {
+ type ActionRun struct {
+ RepoID int64 `xorm:"index(repo_concurrency)"`
+ RawConcurrency string
+ ConcurrencyGroup string `xorm:"index(repo_concurrency) NOT NULL DEFAULT ''"`
+ ConcurrencyCancel bool `xorm:"NOT NULL DEFAULT FALSE"`
+ }
+
+ if _, err := x.SyncWithOptions(xorm.SyncOptions{
+ IgnoreDropIndices: true,
+ }, new(ActionRun)); err != nil {
+ return err
+ }
+
+ if err := x.Sync(new(ActionRun)); err != nil {
+ return err
+ }
+
+ type ActionRunJob struct {
+ RepoID int64 `xorm:"index(repo_concurrency)"`
+ RawConcurrency string
+ IsConcurrencyEvaluated bool
+ ConcurrencyGroup string `xorm:"index(repo_concurrency) NOT NULL DEFAULT ''"`
+ ConcurrencyCancel bool `xorm:"NOT NULL DEFAULT FALSE"`
+ }
+
+ if _, err := x.SyncWithOptions(xorm.SyncOptions{
+ IgnoreDropIndices: true,
+ }, new(ActionRunJob)); err != nil {
+ return err
+ }
+
+ return nil
+}
diff --git a/models/migrations/v1_26/v324.go b/models/migrations/v1_26/v324.go
new file mode 100644
index 0000000000..5d96bfa3ca
--- /dev/null
+++ b/models/migrations/v1_26/v324.go
@@ -0,0 +1,24 @@
+// Copyright 2025 The Gitea Authors. All rights reserved.
+// SPDX-License-Identifier: MIT
+
+package v1_26
+
+import (
+ "fmt"
+
+ "xorm.io/xorm"
+)
+
+func FixClosedMilestoneCompleteness(x *xorm.Engine) error {
+ // Update all milestones to recalculate completeness with the new logic:
+ // - Closed milestones with 0 issues should show 100%
+ // - All other milestones should calculate based on closed/total ratio
+ _, err := x.Exec("UPDATE `milestone` SET completeness=(CASE WHEN is_closed = ? AND num_issues = 0 THEN 100 ELSE 100*num_closed_issues/(CASE WHEN num_issues > 0 THEN num_issues ELSE 1 END) END)",
+ true,
+ )
+ if err != nil {
+ return fmt.Errorf("error updating milestone completeness: %w", err)
+ }
+
+ return nil
+}
diff --git a/models/migrations/v1_26/v325.go b/models/migrations/v1_26/v325.go
new file mode 100644
index 0000000000..d81540f44e
--- /dev/null
+++ b/models/migrations/v1_26/v325.go
@@ -0,0 +1,18 @@
+// Copyright 2026 The Gitea Authors. All rights reserved.
+// SPDX-License-Identifier: MIT
+
+package v1_26
+
+import (
+ "xorm.io/xorm"
+)
+
+func FixMissedRepoIDWhenMigrateAttachments(x *xorm.Engine) error {
+ _, err := x.Exec("UPDATE `attachment` SET `repo_id` = (SELECT `repo_id` FROM `issue` WHERE `issue`.`id` = `attachment`.`issue_id`) WHERE `issue_id` > 0 AND (`repo_id` IS NULL OR `repo_id` = 0);")
+ if err != nil {
+ return err
+ }
+
+ _, err = x.Exec("UPDATE `attachment` SET `repo_id` = (SELECT `repo_id` FROM `release` WHERE `release`.`id` = `attachment`.`release_id`) WHERE `release_id` > 0 AND (`repo_id` IS NULL OR `repo_id` = 0);")
+ return err
+}
diff --git a/models/migrations/v1_26/v325_test.go b/models/migrations/v1_26/v325_test.go
new file mode 100644
index 0000000000..d4a66fee81
--- /dev/null
+++ b/models/migrations/v1_26/v325_test.go
@@ -0,0 +1,45 @@
+// Copyright 2026 The Gitea Authors. All rights reserved.
+// SPDX-License-Identifier: MIT
+
+package v1_26
+
+import (
+ "testing"
+
+ "code.gitea.io/gitea/models/migrations/base"
+ "code.gitea.io/gitea/modules/timeutil"
+
+ "github.com/stretchr/testify/require"
+)
+
+func Test_FixMissedRepoIDWhenMigrateAttachments(t *testing.T) {
+ type Attachment struct {
+ ID int64 `xorm:"pk autoincr"`
+ UUID string `xorm:"uuid UNIQUE"`
+ RepoID int64 `xorm:"INDEX"` // this should not be zero
+ IssueID int64 `xorm:"INDEX"` // maybe zero when creating
+ ReleaseID int64 `xorm:"INDEX"` // maybe zero when creating
+ UploaderID int64 `xorm:"INDEX DEFAULT 0"` // Notice: will be zero before this column added
+ CommentID int64 `xorm:"INDEX"`
+ Name string
+ DownloadCount int64 `xorm:"DEFAULT 0"`
+ Size int64 `xorm:"DEFAULT 0"`
+ CreatedUnix timeutil.TimeStamp `xorm:"created"`
+ }
+
+ type Issue struct {
+ ID int64 `xorm:"pk autoincr"`
+ RepoID int64 `xorm:"INDEX"`
+ }
+
+ type Release struct {
+ ID int64 `xorm:"pk autoincr"`
+ RepoID int64 `xorm:"INDEX"`
+ }
+
+ // Prepare and load the testing database
+ x, deferrable := base.PrepareTestEnv(t, 0, new(Attachment), new(Issue), new(Release))
+ defer deferrable()
+
+ require.NoError(t, FixMissedRepoIDWhenMigrateAttachments(x))
+}
diff --git a/models/migrations/v1_26/v326.go b/models/migrations/v1_26/v326.go
new file mode 100644
index 0000000000..76532e2f85
--- /dev/null
+++ b/models/migrations/v1_26/v326.go
@@ -0,0 +1,315 @@
+// Copyright 2026 The Gitea Authors. All rights reserved.
+// SPDX-License-Identifier: MIT
+
+package v1_26
+
+import (
+ "errors"
+ "fmt"
+ "net/url"
+ "strconv"
+ "strings"
+
+ "code.gitea.io/gitea/modules/json"
+ "code.gitea.io/gitea/modules/log"
+ "code.gitea.io/gitea/modules/setting"
+ api "code.gitea.io/gitea/modules/structs"
+ webhook_module "code.gitea.io/gitea/modules/webhook"
+
+ "xorm.io/xorm"
+)
+
+const (
+ actionsRunPath = "/actions/runs/"
+
+ // Only commit status target URLs whose resolved run ID is smaller than this threshold are rewritten by this partial migration.
+ // The fixed value 1000 is a conservative cutoff chosen to cover the smaller legacy run indexes that are most likely to be confused with ID-based URLs at runtime.
+ // Larger legacy {run} or {job} numbers are usually easier to disambiguate. For example:
+ // * /actions/runs/1200/jobs/1420 is most likely an ID-based URL, because a run should not contain more than 256 jobs.
+ // * /actions/runs/1500/jobs/3 is most likely an index-based URL, because a job ID cannot be smaller than its run ID.
+ // But URLs with small numbers, such as /actions/runs/5/jobs/6, are much harder to distinguish reliably.
+ // This migration therefore prioritizes rewriting target URLs for runs in that lower range.
+ legacyURLIDThreshold int64 = 1000
+)
+
+type migrationRepository struct {
+ ID int64
+ OwnerName string
+ Name string
+}
+
+type migrationActionRun struct {
+ ID int64
+ RepoID int64
+ Index int64
+ CommitSHA string `xorm:"commit_sha"`
+ Event webhook_module.HookEventType
+ TriggerEvent string
+ EventPayload string
+}
+
+type migrationActionRunJob struct {
+ ID int64
+ RunID int64
+}
+
+type migrationCommitStatus struct {
+ ID int64
+ RepoID int64
+ TargetURL string
+}
+
+type commitSHAAndRuns struct {
+ commitSHA string
+ runs map[int64]*migrationActionRun
+}
+
+// FixCommitStatusTargetURLToUseRunAndJobID partially migrates legacy Actions
+// commit status target URLs to the new run/job ID-based form.
+//
+// Only rows whose resolved run ID is below legacyURLIDThreshold are rewritten.
+// This is because smaller legacy run indexes are more likely to collide with run ID URLs during runtime resolution,
+// so this migration prioritizes that lower range and leaves the remaining legacy target URLs to the web compatibility logic.
+func FixCommitStatusTargetURLToUseRunAndJobID(x *xorm.Engine) error {
+ jobsByRunIDCache := make(map[int64][]int64)
+ repoLinkCache := make(map[int64]string)
+ groups, err := loadLegacyMigrationRunGroups(x)
+ if err != nil {
+ return err
+ }
+
+ for repoID, groupsBySHA := range groups {
+ for _, group := range groupsBySHA {
+ if err := migrateCommitStatusTargetURLForGroup(x, "commit_status", repoID, group.commitSHA, group.runs, jobsByRunIDCache, repoLinkCache); err != nil {
+ return err
+ }
+ if err := migrateCommitStatusTargetURLForGroup(x, "commit_status_summary", repoID, group.commitSHA, group.runs, jobsByRunIDCache, repoLinkCache); err != nil {
+ return err
+ }
+ }
+ }
+ return nil
+}
+
+func loadLegacyMigrationRunGroups(x *xorm.Engine) (map[int64]map[string]*commitSHAAndRuns, error) {
+ var runs []migrationActionRun
+ if err := x.Table("action_run").
+ Where("id < ?", legacyURLIDThreshold).
+ Cols("id", "repo_id", "`index`", "commit_sha", "event", "trigger_event", "event_payload").
+ Find(&runs); err != nil {
+ return nil, fmt.Errorf("query action_run: %w", err)
+ }
+
+ groups := make(map[int64]map[string]*commitSHAAndRuns)
+ for i := range runs {
+ run := runs[i]
+ commitID, err := getCommitStatusCommitID(&run)
+ if err != nil {
+ log.Warn("skip action_run id=%d when resolving commit status commit SHA: %v", run.ID, err)
+ continue
+ }
+ if commitID == "" {
+ // empty commitID means the run didn't create any commit status records, just skip
+ continue
+ }
+ if groups[run.RepoID] == nil {
+ groups[run.RepoID] = make(map[string]*commitSHAAndRuns)
+ }
+ if groups[run.RepoID][commitID] == nil {
+ groups[run.RepoID][commitID] = &commitSHAAndRuns{
+ commitSHA: commitID,
+ runs: make(map[int64]*migrationActionRun),
+ }
+ }
+ groups[run.RepoID][commitID].runs[run.Index] = &run
+ }
+ return groups, nil
+}
+
+func migrateCommitStatusTargetURLForGroup(
+ x *xorm.Engine,
+ table string,
+ repoID int64,
+ sha string,
+ runs map[int64]*migrationActionRun,
+ jobsByRunIDCache map[int64][]int64,
+ repoLinkCache map[int64]string,
+) error {
+ var rows []migrationCommitStatus
+ if err := x.Table(table).
+ Where("repo_id = ?", repoID).
+ And("sha = ?", sha).
+ Cols("id", "repo_id", "target_url").
+ Find(&rows); err != nil {
+ return fmt.Errorf("query %s for repo_id=%d sha=%s: %w", table, repoID, sha, err)
+ }
+
+ for _, row := range rows {
+ repoLink, err := getRepoLinkCached(x, repoLinkCache, row.RepoID)
+ if err != nil || repoLink == "" {
+ if err != nil {
+ log.Warn("convert %s id=%d getRepoLinkCached: %v", table, row.ID, err)
+ } else {
+ log.Warn("convert %s id=%d: repo=%d not found", table, row.ID, row.RepoID)
+ }
+ continue
+ }
+
+ runNum, jobNum, ok := parseTargetURL(row.TargetURL, repoLink)
+ if !ok {
+ continue
+ }
+
+ run, ok := runs[runNum]
+ if !ok {
+ continue
+ }
+
+ jobID, ok, err := getJobIDByIndexCached(x, jobsByRunIDCache, run.ID, jobNum)
+ if err != nil || !ok {
+ if err != nil {
+ log.Warn("convert %s id=%d getJobIDByIndexCached: %v", table, row.ID, err)
+ } else {
+ log.Warn("convert %s id=%d: job not found for run_id=%d job_index=%d", table, row.ID, run.ID, jobNum)
+ }
+ continue
+ }
+
+ oldURL := row.TargetURL
+ newURL := fmt.Sprintf("%s%s%d/jobs/%d", repoLink, actionsRunPath, run.ID, jobID)
+ if oldURL == newURL {
+ continue
+ }
+
+ if _, err := x.Table(table).ID(row.ID).Cols("target_url").Update(&migrationCommitStatus{TargetURL: newURL}); err != nil {
+ return fmt.Errorf("update %s id=%d target_url from %s to %s: %w", table, row.ID, oldURL, newURL, err)
+ }
+ }
+ return nil
+}
+
+func getRepoLinkCached(x *xorm.Engine, cache map[int64]string, repoID int64) (string, error) {
+ if link, ok := cache[repoID]; ok {
+ return link, nil
+ }
+ repo := &migrationRepository{}
+ has, err := x.Table("repository").Where("id=?", repoID).Get(repo)
+ if err != nil {
+ return "", err
+ }
+ if !has {
+ cache[repoID] = ""
+ return "", nil
+ }
+ link := setting.AppSubURL + "/" + url.PathEscape(repo.OwnerName) + "/" + url.PathEscape(repo.Name)
+ cache[repoID] = link
+ return link, nil
+}
+
+func getJobIDByIndexCached(x *xorm.Engine, cache map[int64][]int64, runID, jobIndex int64) (int64, bool, error) {
+ jobIDs, ok := cache[runID]
+ if !ok {
+ var jobs []migrationActionRunJob
+ if err := x.Table("action_run_job").Where("run_id=?", runID).Asc("id").Cols("id").Find(&jobs); err != nil {
+ return 0, false, err
+ }
+ jobIDs = make([]int64, 0, len(jobs))
+ for _, job := range jobs {
+ jobIDs = append(jobIDs, job.ID)
+ }
+ cache[runID] = jobIDs
+ }
+ if jobIndex < 0 || jobIndex >= int64(len(jobIDs)) {
+ return 0, false, nil
+ }
+ return jobIDs[jobIndex], true, nil
+}
+
+func parseTargetURL(targetURL, repoLink string) (runNum, jobNum int64, ok bool) {
+ prefix := repoLink + actionsRunPath
+ if !strings.HasPrefix(targetURL, prefix) {
+ return 0, 0, false
+ }
+ rest := targetURL[len(prefix):]
+
+ parts := strings.Split(rest, "/")
+ if len(parts) == 3 && parts[1] == "jobs" {
+ runNum, err1 := strconv.ParseInt(parts[0], 10, 64)
+ jobNum, err2 := strconv.ParseInt(parts[2], 10, 64)
+ if err1 != nil || err2 != nil {
+ return 0, 0, false
+ }
+ return runNum, jobNum, true
+ }
+
+ return 0, 0, false
+}
+
+func getCommitStatusCommitID(run *migrationActionRun) (string, error) {
+ switch run.Event {
+ case webhook_module.HookEventPush:
+ payload, err := getPushEventPayload(run)
+ if err != nil {
+ return "", fmt.Errorf("getPushEventPayload: %w", err)
+ }
+ if payload.HeadCommit == nil {
+ return "", errors.New("head commit is missing in event payload")
+ }
+ return payload.HeadCommit.ID, nil
+ case webhook_module.HookEventPullRequest,
+ webhook_module.HookEventPullRequestSync,
+ webhook_module.HookEventPullRequestAssign,
+ webhook_module.HookEventPullRequestLabel,
+ webhook_module.HookEventPullRequestReviewRequest,
+ webhook_module.HookEventPullRequestMilestone:
+ payload, err := getPullRequestEventPayload(run)
+ if err != nil {
+ return "", fmt.Errorf("getPullRequestEventPayload: %w", err)
+ }
+ if payload.PullRequest == nil {
+ return "", errors.New("pull request is missing in event payload")
+ } else if payload.PullRequest.Head == nil {
+ return "", errors.New("head of pull request is missing in event payload")
+ }
+ return payload.PullRequest.Head.Sha, nil
+ case webhook_module.HookEventPullRequestReviewApproved,
+ webhook_module.HookEventPullRequestReviewRejected,
+ webhook_module.HookEventPullRequestReviewComment:
+ payload, err := getPullRequestEventPayload(run)
+ if err != nil {
+ return "", fmt.Errorf("getPullRequestEventPayload: %w", err)
+ }
+ if payload.PullRequest == nil {
+ return "", errors.New("pull request is missing in event payload")
+ } else if payload.PullRequest.Head == nil {
+ return "", errors.New("head of pull request is missing in event payload")
+ }
+ return payload.PullRequest.Head.Sha, nil
+ case webhook_module.HookEventRelease:
+ return run.CommitSHA, nil
+ default:
+ return "", nil
+ }
+}
+
+func getPushEventPayload(run *migrationActionRun) (*api.PushPayload, error) {
+ if run.Event != webhook_module.HookEventPush {
+ return nil, fmt.Errorf("event %s is not a push event", run.Event)
+ }
+ var payload api.PushPayload
+ if err := json.Unmarshal([]byte(run.EventPayload), &payload); err != nil {
+ return nil, err
+ }
+ return &payload, nil
+}
+
+func getPullRequestEventPayload(run *migrationActionRun) (*api.PullRequestPayload, error) {
+ if !run.Event.IsPullRequest() && !run.Event.IsPullRequestReview() {
+ return nil, fmt.Errorf("event %s is not a pull request event", run.Event)
+ }
+ var payload api.PullRequestPayload
+ if err := json.Unmarshal([]byte(run.EventPayload), &payload); err != nil {
+ return nil, err
+ }
+ return &payload, nil
+}
diff --git a/models/migrations/v1_26/v326_test.go b/models/migrations/v1_26/v326_test.go
new file mode 100644
index 0000000000..b92eed35f6
--- /dev/null
+++ b/models/migrations/v1_26/v326_test.go
@@ -0,0 +1,113 @@
+// Copyright 2026 The Gitea Authors. All rights reserved.
+// SPDX-License-Identifier: MIT
+
+package v1_26
+
+import (
+ "testing"
+
+ "code.gitea.io/gitea/models/migrations/base"
+ "code.gitea.io/gitea/modules/setting"
+ "code.gitea.io/gitea/modules/test"
+
+ _ "code.gitea.io/gitea/models/actions"
+ _ "code.gitea.io/gitea/models/git"
+ _ "code.gitea.io/gitea/models/repo"
+
+ "github.com/stretchr/testify/require"
+ "xorm.io/xorm"
+)
+
+func Test_FixCommitStatusTargetURLToUseRunAndJobID(t *testing.T) {
+ defer test.MockVariableValue(&setting.AppSubURL, "")()
+
+ type Repository struct {
+ ID int64 `xorm:"pk autoincr"`
+ OwnerName string
+ Name string
+ }
+
+ type ActionRun struct {
+ ID int64 `xorm:"pk autoincr"`
+ RepoID int64 `xorm:"index"`
+ Index int64
+ CommitSHA string `xorm:"commit_sha"`
+ Event string
+ TriggerEvent string
+ EventPayload string `xorm:"LONGTEXT"`
+ }
+
+ type ActionRunJob struct {
+ ID int64 `xorm:"pk autoincr"`
+ RunID int64 `xorm:"index"`
+ }
+
+ type CommitStatus struct {
+ ID int64 `xorm:"pk autoincr"`
+ RepoID int64 `xorm:"index"`
+ SHA string
+ TargetURL string
+ }
+
+ type CommitStatusSummary struct {
+ ID int64 `xorm:"pk autoincr"`
+ RepoID int64 `xorm:"index"`
+ SHA string `xorm:"VARCHAR(64) NOT NULL"`
+ State string `xorm:"VARCHAR(7) NOT NULL"`
+ TargetURL string
+ }
+
+ x, deferable := base.PrepareTestEnv(t, 0,
+ new(Repository),
+ new(ActionRun),
+ new(ActionRunJob),
+ new(CommitStatus),
+ new(CommitStatusSummary),
+ )
+ defer deferable()
+
+ require.NoError(t, FixCommitStatusTargetURLToUseRunAndJobID(x))
+
+ cases := []struct {
+ table string
+ id int64
+ want string
+ }{
+ // Legacy URLs for runs whose resolved run IDs are below the threshold should be rewritten.
+ {table: "commit_status", id: 10010, want: "/testuser/repo1/actions/runs/990/jobs/997"},
+ {table: "commit_status", id: 10011, want: "/testuser/repo1/actions/runs/990/jobs/998"},
+ {table: "commit_status", id: 10012, want: "/testuser/repo1/actions/runs/991/jobs/1997"},
+
+ // Runs whose resolved IDs are above the threshold are intentionally left unchanged.
+ {table: "commit_status", id: 10013, want: "/testuser/repo1/actions/runs/9/jobs/0"},
+
+ // URLs that do not resolve cleanly as legacy Actions URLs should remain untouched.
+ {table: "commit_status", id: 10014, want: "/otheruser/badrepo/actions/runs/7/jobs/0"},
+ {table: "commit_status", id: 10015, want: "/testuser/repo1/actions/runs/10/jobs/0"},
+ {table: "commit_status", id: 10016, want: "/testuser/repo1/actions/runs/7/jobs/3"},
+ {table: "commit_status", id: 10017, want: "https://ci.example.com/build/123"},
+
+ // Already ID-based URLs are valid inputs and should not be rewritten again.
+ {table: "commit_status", id: 10018, want: "/testuser/repo1/actions/runs/990/jobs/997"},
+
+ // The same rewrite rules apply to commit_status_summary rows.
+ {table: "commit_status_summary", id: 10020, want: "/testuser/repo1/actions/runs/990/jobs/997"},
+ {table: "commit_status_summary", id: 10021, want: "/testuser/repo1/actions/runs/9/jobs/0"},
+ }
+
+ for _, tc := range cases {
+ assertTargetURL(t, x, tc.table, tc.id, tc.want)
+ }
+}
+
+func assertTargetURL(t *testing.T, x *xorm.Engine, table string, id int64, want string) {
+ t.Helper()
+
+ var row struct {
+ TargetURL string
+ }
+ has, err := x.Table(table).Where("id=?", id).Cols("target_url").Get(&row)
+ require.NoError(t, err)
+ require.Truef(t, has, "row not found: table=%s id=%d", table, id)
+ require.Equal(t, want, row.TargetURL)
+}
diff --git a/models/migrations/v1_26/v327.go b/models/migrations/v1_26/v327.go
new file mode 100644
index 0000000000..51af567650
--- /dev/null
+++ b/models/migrations/v1_26/v327.go
@@ -0,0 +1,17 @@
+// Copyright 2026 The Gitea Authors. All rights reserved.
+// SPDX-License-Identifier: MIT
+
+package v1_26
+
+import "xorm.io/xorm"
+
+func AddDisabledToActionRunner(x *xorm.Engine) error {
+ type ActionRunner struct {
+ IsDisabled bool `xorm:"is_disabled NOT NULL DEFAULT false"`
+ }
+
+ _, err := x.SyncWithOptions(xorm.SyncOptions{
+ IgnoreDropIndices: true,
+ }, new(ActionRunner))
+ return err
+}
diff --git a/models/migrations/v1_26/v327_test.go b/models/migrations/v1_26/v327_test.go
new file mode 100644
index 0000000000..971707be4f
--- /dev/null
+++ b/models/migrations/v1_26/v327_test.go
@@ -0,0 +1,33 @@
+// Copyright 2026 The Gitea Authors. All rights reserved.
+// SPDX-License-Identifier: MIT
+
+package v1_26
+
+import (
+ "testing"
+
+ "code.gitea.io/gitea/models/migrations/base"
+
+ "github.com/stretchr/testify/require"
+)
+
+func Test_AddDisabledToActionRunner(t *testing.T) {
+ type ActionRunner struct {
+ ID int64 `xorm:"pk autoincr"`
+ Name string
+ }
+
+ x, deferable := base.PrepareTestEnv(t, 0, new(ActionRunner))
+ defer deferable()
+
+ _, err := x.Insert(&ActionRunner{Name: "runner"})
+ require.NoError(t, err)
+
+ require.NoError(t, AddDisabledToActionRunner(x))
+
+ var isDisabled bool
+ has, err := x.SQL("SELECT is_disabled FROM action_runner WHERE id = ?", 1).Get(&isDisabled)
+ require.NoError(t, err)
+ require.True(t, has)
+ require.False(t, isDisabled)
+}
diff --git a/models/migrations/v1_26/v328.go b/models/migrations/v1_26/v328.go
new file mode 100644
index 0000000000..8104730528
--- /dev/null
+++ b/models/migrations/v1_26/v328.go
@@ -0,0 +1,16 @@
+// Copyright 2026 The Gitea Authors. All rights reserved.
+// SPDX-License-Identifier: MIT
+
+package v1_26
+
+import (
+ "xorm.io/xorm"
+)
+
+func AddTokenPermissionsToActionRunJob(x *xorm.Engine) error {
+ type ActionRunJob struct {
+ TokenPermissions string `xorm:"JSON TEXT"`
+ }
+ _, err := x.SyncWithOptions(xorm.SyncOptions{IgnoreDropIndices: true}, new(ActionRunJob))
+ return err
+}
diff --git a/models/migrations/v1_26/v329.go b/models/migrations/v1_26/v329.go
new file mode 100644
index 0000000000..1afd155f05
--- /dev/null
+++ b/models/migrations/v1_26/v329.go
@@ -0,0 +1,62 @@
+// Copyright 2026 The Gitea Authors. All rights reserved.
+// SPDX-License-Identifier: MIT
+
+package v1_26
+
+import (
+ "fmt"
+
+ "xorm.io/xorm"
+ "xorm.io/xorm/schemas"
+)
+
+type UserBadge struct { //revive:disable-line:exported
+ ID int64 `xorm:"pk autoincr"`
+ BadgeID int64
+ UserID int64
+}
+
+// TableIndices implements xorm's TableIndices interface
+func (n *UserBadge) TableIndices() []*schemas.Index {
+ indices := make([]*schemas.Index, 0, 1)
+ ubUnique := schemas.NewIndex("unique_user_badge", schemas.UniqueType)
+ ubUnique.AddColumn("user_id", "badge_id")
+ indices = append(indices, ubUnique)
+ return indices
+}
+
+// AddUniqueIndexForUserBadge adds a compound unique indexes for user badge table
+// and it replaces an old index on user_id
+func AddUniqueIndexForUserBadge(x *xorm.Engine) error {
+ // remove possible duplicated records in table user_badge
+ type result struct {
+ UserID int64
+ BadgeID int64
+ Cnt int
+ }
+ var results []result
+ if err := x.Select("user_id, badge_id, count(*) as cnt").
+ Table("user_badge").
+ GroupBy("user_id, badge_id").
+ Having("count(*) > 1").
+ Find(&results); err != nil {
+ return err
+ }
+ for _, r := range results {
+ if x.Dialect().URI().DBType == schemas.MSSQL {
+ if _, err := x.Exec(fmt.Sprintf("delete from user_badge where id in (SELECT top %d id FROM user_badge WHERE user_id = ? and badge_id = ?)", r.Cnt-1), r.UserID, r.BadgeID); err != nil {
+ return err
+ }
+ } else {
+ var ids []int64
+ if err := x.SQL("SELECT id FROM user_badge WHERE user_id = ? and badge_id = ? limit ?", r.UserID, r.BadgeID, r.Cnt-1).Find(&ids); err != nil {
+ return err
+ }
+ if _, err := x.Table("user_badge").In("id", ids).Delete(); err != nil {
+ return err
+ }
+ }
+ }
+
+ return x.Sync(new(UserBadge))
+}
diff --git a/models/migrations/v1_26/v329_test.go b/models/migrations/v1_26/v329_test.go
new file mode 100644
index 0000000000..cab8e79906
--- /dev/null
+++ b/models/migrations/v1_26/v329_test.go
@@ -0,0 +1,85 @@
+// Copyright 2026 The Gitea Authors. All rights reserved.
+// SPDX-License-Identifier: MIT
+
+package v1_26
+
+import (
+ "testing"
+
+ "code.gitea.io/gitea/models/migrations/base"
+
+ "github.com/stretchr/testify/assert"
+)
+
+type UserBadgeBefore struct {
+ ID int64 `xorm:"pk autoincr"`
+ BadgeID int64
+ UserID int64 `xorm:"INDEX"`
+}
+
+func (UserBadgeBefore) TableName() string {
+ return "user_badge"
+}
+
+func Test_AddUniqueIndexForUserBadge(t *testing.T) {
+ x, deferable := base.PrepareTestEnv(t, 0, new(UserBadgeBefore))
+ defer deferable()
+ if x == nil || t.Failed() {
+ return
+ }
+
+ testData := []*UserBadgeBefore{
+ {UserID: 1, BadgeID: 1},
+ {UserID: 1, BadgeID: 1}, // duplicate
+ {UserID: 2, BadgeID: 1},
+ {UserID: 1, BadgeID: 2},
+ {UserID: 3, BadgeID: 3},
+ {UserID: 3, BadgeID: 3}, // duplicate
+ }
+
+ for _, data := range testData {
+ _, err := x.Insert(data)
+ assert.NoError(t, err)
+ }
+
+ // check that we have duplicates
+ count, err := x.Where("user_id = ? AND badge_id = ?", 1, 1).Count(&UserBadgeBefore{})
+ assert.NoError(t, err)
+ assert.Equal(t, int64(2), count)
+
+ count, err = x.Where("user_id = ? AND badge_id = ?", 3, 3).Count(&UserBadgeBefore{})
+ assert.NoError(t, err)
+ assert.Equal(t, int64(2), count)
+
+ totalCount, err := x.Count(&UserBadgeBefore{})
+ assert.NoError(t, err)
+ assert.Equal(t, int64(6), totalCount)
+
+ // run the migration
+ if err := AddUniqueIndexForUserBadge(x); err != nil {
+ assert.NoError(t, err)
+ return
+ }
+
+ // verify the duplicates were removed
+ count, err = x.Where("user_id = ? AND badge_id = ?", 1, 1).Count(&UserBadgeBefore{})
+ assert.NoError(t, err)
+ assert.Equal(t, int64(1), count)
+
+ count, err = x.Where("user_id = ? AND badge_id = ?", 3, 3).Count(&UserBadgeBefore{})
+ assert.NoError(t, err)
+ assert.Equal(t, int64(1), count)
+
+ // check total count
+ totalCount, err = x.Count(&UserBadgeBefore{})
+ assert.NoError(t, err)
+ assert.Equal(t, int64(4), totalCount)
+
+ // fail to insert a duplicate
+ _, err = x.Insert(&UserBadge{UserID: 1, BadgeID: 1})
+ assert.Error(t, err)
+
+ // succeed adding a non-duplicate
+ _, err = x.Insert(&UserBadge{UserID: 4, BadgeID: 1})
+ assert.NoError(t, err)
+}
diff --git a/models/migrations/v1_26/v330.go b/models/migrations/v1_26/v330.go
new file mode 100644
index 0000000000..9f77331090
--- /dev/null
+++ b/models/migrations/v1_26/v330.go
@@ -0,0 +1,16 @@
+// Copyright 2026 The Gitea Authors. All rights reserved.
+// SPDX-License-Identifier: MIT
+
+package v1_26
+
+import (
+ "xorm.io/xorm"
+)
+
+func AddNameToWebhook(x *xorm.Engine) error {
+ type Webhook struct {
+ Name string `xorm:"VARCHAR(255) NOT NULL DEFAULT ''"`
+ }
+ _, err := x.SyncWithOptions(xorm.SyncOptions{IgnoreDropIndices: true}, new(Webhook))
+ return err
+}
diff --git a/models/migrations/v1_9/v82.go b/models/migrations/v1_9/v82.go
index f0307bf07a..8796b0563d 100644
--- a/models/migrations/v1_9/v82.go
+++ b/models/migrations/v1_9/v82.go
@@ -6,11 +6,10 @@ package v1_9
import (
"context"
"fmt"
- "path/filepath"
- "strings"
+ repo_model "code.gitea.io/gitea/models/repo"
"code.gitea.io/gitea/modules/git"
- "code.gitea.io/gitea/modules/setting"
+ "code.gitea.io/gitea/modules/gitrepo"
"xorm.io/xorm"
)
@@ -34,16 +33,6 @@ func FixReleaseSha1OnReleaseTable(ctx context.Context, x *xorm.Engine) error {
Name string
}
- // UserPath returns the path absolute path of user repositories.
- UserPath := func(userName string) string {
- return filepath.Join(setting.RepoRootPath, strings.ToLower(userName))
- }
-
- // RepoPath returns repository path by given user and repository name.
- RepoPath := func(userName, repoName string) string {
- return filepath.Join(UserPath(userName), strings.ToLower(repoName)+".git")
- }
-
// Update release sha1
const batchSize = 100
sess := x.NewSession()
@@ -99,7 +88,7 @@ func FixReleaseSha1OnReleaseTable(ctx context.Context, x *xorm.Engine) error {
userCache[repo.OwnerID] = user
}
- gitRepo, err = git.OpenRepository(ctx, RepoPath(user.Name, repo.Name))
+ gitRepo, err = gitrepo.OpenRepository(ctx, repo_model.StorageRepo(repo_model.RelativePath(user.Name, repo.Name)))
if err != nil {
return err
}
diff --git a/models/organization/org.go b/models/organization/org.go
index b4d28f5405..10a2c330e5 100644
--- a/models/organization/org.go
+++ b/models/organization/org.go
@@ -178,7 +178,7 @@ func (org *Organization) HomeLink() string {
return org.AsUser().HomeLink()
}
-// FindOrgMembersOpts represensts find org members conditions
+// FindOrgMembersOpts represents find org members conditions
type FindOrgMembersOpts struct {
db.ListOptions
Doer *user_model.User
diff --git a/models/organization/org_list.go b/models/organization/org_list.go
index f37961b5f6..136417d932 100644
--- a/models/organization/org_list.go
+++ b/models/organization/org_list.go
@@ -54,6 +54,12 @@ type FindOrgOptions struct {
IncludeVisibility structs.VisibleType
}
+func (opts *FindOrgOptions) ApplyPublicOnly(publicOnly bool) {
+ if publicOnly {
+ opts.IncludeVisibility = structs.VisibleTypePublic
+ }
+}
+
func queryUserOrgIDs(userID int64, includePrivate bool) *builder.Builder {
cond := builder.Eq{"uid": userID}
if !includePrivate {
diff --git a/models/organization/org_user.go b/models/organization/org_user.go
index 4d7527c15f..627c1c2edf 100644
--- a/models/organization/org_user.go
+++ b/models/organization/org_user.go
@@ -8,10 +8,7 @@ import (
"fmt"
"code.gitea.io/gitea/models/db"
- "code.gitea.io/gitea/models/perm"
- "code.gitea.io/gitea/models/unit"
user_model "code.gitea.io/gitea/models/user"
- "code.gitea.io/gitea/modules/container"
"code.gitea.io/gitea/modules/log"
"xorm.io/builder"
@@ -129,58 +126,15 @@ func IsUserOrgOwner(ctx context.Context, users user_model.UserList, orgID int64)
return results
}
-// GetOrgAssignees returns all users that have write access and can be assigned to issues
-// of the any repository in the organization.
-func GetOrgAssignees(ctx context.Context, orgID int64) (_ []*user_model.User, err error) {
- e := db.GetEngine(ctx)
- userIDs := make([]int64, 0, 10)
- if err = e.Table("access").
- Join("INNER", "repository", "`repository`.id = `access`.repo_id").
- Where("`repository`.owner_id = ? AND `access`.mode >= ?", orgID, perm.AccessModeWrite).
- Select("user_id").
- Find(&userIDs); err != nil {
- return nil, err
- }
-
- additionalUserIDs := make([]int64, 0, 10)
- if err = e.Table("team_user").
- Join("INNER", "team_repo", "`team_repo`.team_id = `team_user`.team_id").
- Join("INNER", "team_unit", "`team_unit`.team_id = `team_user`.team_id").
- Join("INNER", "repository", "`repository`.id = `team_repo`.repo_id").
- Where("`repository`.owner_id = ? AND (`team_unit`.access_mode >= ? OR (`team_unit`.access_mode = ? AND `team_unit`.`type` = ?))",
- orgID, perm.AccessModeWrite, perm.AccessModeRead, unit.TypePullRequests).
- Distinct("`team_user`.uid").
- Select("`team_user`.uid").
- Find(&additionalUserIDs); err != nil {
- return nil, err
- }
-
- uniqueUserIDs := make(container.Set[int64])
- uniqueUserIDs.AddMultiple(userIDs...)
- uniqueUserIDs.AddMultiple(additionalUserIDs...)
-
- users := make([]*user_model.User, 0, len(uniqueUserIDs))
- if len(userIDs) > 0 {
- if err = e.In("id", uniqueUserIDs.Values()).
- Where(builder.Eq{"`user`.is_active": true}).
- OrderBy(user_model.GetOrderByName()).
- Find(&users); err != nil {
- return nil, err
- }
- }
-
- return users, nil
-}
-
func loadOrganizationOwners(ctx context.Context, users user_model.UserList, orgID int64) (map[int64]*TeamUser, error) {
if len(users) == 0 {
- return nil, nil
+ return nil, nil //nolint:nilnil // return nil when there are no users
}
ownerTeam, err := GetOwnerTeam(ctx, orgID)
if err != nil {
if IsErrTeamNotExist(err) {
log.Error("Organization does not have owner team: %d", orgID)
- return nil, nil
+ return nil, nil //nolint:nilnil // return nil when owner team does not exist
}
return nil, err
}
diff --git a/models/packages/descriptor.go b/models/packages/descriptor.go
index ea0e0d5e73..2ef27051ee 100644
--- a/models/packages/descriptor.go
+++ b/models/packages/descriptor.go
@@ -9,6 +9,7 @@ import (
"fmt"
"net/url"
+ "code.gitea.io/gitea/models/db"
repo_model "code.gitea.io/gitea/models/repo"
user_model "code.gitea.io/gitea/models/user"
"code.gitea.io/gitea/modules/cache"
@@ -53,8 +54,11 @@ func (l PackagePropertyList) GetByName(name string) string {
// PackageDescriptor describes a package
type PackageDescriptor struct {
- Package *Package
- Owner *user_model.User
+ // basic package info
+ Package *Package
+ Owner *user_model.User
+
+ // package version info
Repository *repo_model.Repository
Version *PackageVersion
SemVer *version.Version
@@ -77,6 +81,11 @@ func (pd *PackageDescriptor) PackageWebLink() string {
return fmt.Sprintf("%s/-/packages/%s/%s", pd.Owner.HomeLink(), string(pd.Package.Type), url.PathEscape(pd.Package.LowerName))
}
+// PackageSettingsLink returns the relative package settings link
+func (pd *PackageDescriptor) PackageSettingsLink() string {
+ return fmt.Sprintf("%s/-/packages/settings/%s/%s", pd.Owner.HomeLink(), string(pd.Package.Type), url.PathEscape(pd.Package.LowerName))
+}
+
// VersionWebLink returns the relative package version web link
func (pd *PackageDescriptor) VersionWebLink() string {
return fmt.Sprintf("%s/%s", pd.PackageWebLink(), url.PathEscape(pd.Version.LowerVersion))
@@ -203,6 +212,8 @@ func GetPackageDescriptorWithCache(ctx context.Context, pv *PackageVersion, c *c
metadata = &rubygems.Metadata{}
case TypeSwift:
metadata = &swift.Metadata{}
+ case TypeTerraformState:
+ // terraform packages have no metadata
case TypeVagrant:
metadata = &vagrant.Metadata{}
default:
@@ -267,6 +278,15 @@ func GetPackageDescriptors(ctx context.Context, pvs []*PackageVersion) ([]*Packa
return getPackageDescriptors(ctx, pvs, cache.NewEphemeralCache())
}
+// GetAllPackageDescriptors gets all package descriptors for a package
+func GetAllPackageDescriptors(ctx context.Context, p *Package) ([]*PackageDescriptor, error) {
+ pvs := make([]*PackageVersion, 0, 10)
+ if err := db.GetEngine(ctx).Where("package_id = ?", p.ID).Find(&pvs); err != nil {
+ return nil, err
+ }
+ return getPackageDescriptors(ctx, pvs, cache.NewEphemeralCache())
+}
+
func getPackageDescriptors(ctx context.Context, pvs []*PackageVersion, c *cache.EphemeralCache) ([]*PackageDescriptor, error) {
pds := make([]*PackageDescriptor, 0, len(pvs))
for _, pv := range pvs {
diff --git a/models/packages/package.go b/models/packages/package.go
index 38d1cdcf66..17e5d4eee3 100644
--- a/models/packages/package.go
+++ b/models/packages/package.go
@@ -30,28 +30,29 @@ type Type string
// List of supported packages
const (
- TypeAlpine Type = "alpine"
- TypeArch Type = "arch"
- TypeCargo Type = "cargo"
- TypeChef Type = "chef"
- TypeComposer Type = "composer"
- TypeConan Type = "conan"
- TypeConda Type = "conda"
- TypeContainer Type = "container"
- TypeCran Type = "cran"
- TypeDebian Type = "debian"
- TypeGeneric Type = "generic"
- TypeGo Type = "go"
- TypeHelm Type = "helm"
- TypeMaven Type = "maven"
- TypeNpm Type = "npm"
- TypeNuGet Type = "nuget"
- TypePub Type = "pub"
- TypePyPI Type = "pypi"
- TypeRpm Type = "rpm"
- TypeRubyGems Type = "rubygems"
- TypeSwift Type = "swift"
- TypeVagrant Type = "vagrant"
+ TypeAlpine Type = "alpine"
+ TypeArch Type = "arch"
+ TypeCargo Type = "cargo"
+ TypeChef Type = "chef"
+ TypeComposer Type = "composer"
+ TypeConan Type = "conan"
+ TypeConda Type = "conda"
+ TypeContainer Type = "container"
+ TypeCran Type = "cran"
+ TypeDebian Type = "debian"
+ TypeGeneric Type = "generic"
+ TypeGo Type = "go"
+ TypeHelm Type = "helm"
+ TypeMaven Type = "maven"
+ TypeNpm Type = "npm"
+ TypeNuGet Type = "nuget"
+ TypePub Type = "pub"
+ TypePyPI Type = "pypi"
+ TypeRpm Type = "rpm"
+ TypeRubyGems Type = "rubygems"
+ TypeSwift Type = "swift"
+ TypeTerraformState Type = "terraform"
+ TypeVagrant Type = "vagrant"
)
var TypeList = []Type{
@@ -76,6 +77,7 @@ var TypeList = []Type{
TypeRpm,
TypeRubyGems,
TypeSwift,
+ TypeTerraformState,
TypeVagrant,
}
@@ -124,6 +126,8 @@ func (pt Type) Name() string {
return "RubyGems"
case TypeSwift:
return "Swift"
+ case TypeTerraformState:
+ return "Terraform State"
case TypeVagrant:
return "Vagrant"
}
@@ -175,6 +179,8 @@ func (pt Type) SVGName() string {
return "gitea-rubygems"
case TypeSwift:
return "gitea-swift"
+ case TypeTerraformState:
+ return "gitea-terraform"
case TypeVagrant:
return "gitea-vagrant"
}
diff --git a/models/packages/package_blob.go b/models/packages/package_blob.go
index d9c30b6533..e765bbf0c2 100644
--- a/models/packages/package_blob.go
+++ b/models/packages/package_blob.go
@@ -43,13 +43,15 @@ func GetOrInsertBlob(ctx context.Context, pb *PackageBlob) (*PackageBlob, bool,
existing := &PackageBlob{}
- has, err := e.Where(builder.Eq{
+ hashCond := builder.Eq{
"size": pb.Size,
"hash_md5": pb.HashMD5,
"hash_sha1": pb.HashSHA1,
"hash_sha256": pb.HashSHA256,
"hash_sha512": pb.HashSHA512,
- }).Get(existing)
+ }
+
+ has, err := e.Where(hashCond).Get(existing)
if err != nil {
return nil, false, err
}
@@ -57,6 +59,11 @@ func GetOrInsertBlob(ctx context.Context, pb *PackageBlob) (*PackageBlob, bool,
return existing, true, nil
}
if _, err = e.Insert(pb); err != nil {
+ // Handle race condition: another request may have inserted the same blob
+ // between our SELECT and INSERT. Retry the SELECT to get the existing blob.
+ if has, _ = e.Where(hashCond).Get(existing); has {
+ return existing, true, nil
+ }
return nil, false, err
}
return pb, false, nil
diff --git a/models/packages/package_blob_test.go b/models/packages/package_blob_test.go
new file mode 100644
index 0000000000..8b636b4ee0
--- /dev/null
+++ b/models/packages/package_blob_test.go
@@ -0,0 +1,51 @@
+// Copyright 2026 The Gitea Authors. All rights reserved.
+// SPDX-License-Identifier: MIT
+
+package packages
+
+import (
+ "testing"
+
+ "code.gitea.io/gitea/models/unittest"
+
+ "github.com/stretchr/testify/assert"
+ "github.com/stretchr/testify/require"
+ "golang.org/x/sync/errgroup"
+)
+
+func TestGetOrInsertBlobConcurrent(t *testing.T) {
+ require.NoError(t, unittest.PrepareTestDatabase())
+
+ testBlob := PackageBlob{
+ Size: 123,
+ HashMD5: "md5",
+ HashSHA1: "sha1",
+ HashSHA256: "sha256",
+ HashSHA512: "sha512",
+ }
+
+ const numGoroutines = 3
+ var wg errgroup.Group
+ results := make([]*PackageBlob, numGoroutines)
+ existed := make([]bool, numGoroutines)
+ for idx := range numGoroutines {
+ wg.Go(func() error {
+ blob := testBlob // Create a copy of the test blob for each goroutine
+ var err error
+ results[idx], existed[idx], err = GetOrInsertBlob(t.Context(), &blob)
+ return err
+ })
+ }
+ require.NoError(t, wg.Wait())
+
+ // then: all GetOrInsertBlob succeeds with the same blob ID, and only one indicates it did not exist before
+ existedCount := 0
+ assert.NotNil(t, results[0])
+ for i := range numGoroutines {
+ assert.Equal(t, results[0].ID, results[i].ID)
+ if existed[i] {
+ existedCount++
+ }
+ }
+ assert.Equal(t, numGoroutines-1, existedCount)
+}
diff --git a/models/packages/package_file.go b/models/packages/package_file.go
index bf877485d6..64bd08f0b2 100644
--- a/models/packages/package_file.go
+++ b/models/packages/package_file.go
@@ -68,7 +68,7 @@ func TryInsertFile(ctx context.Context, pf *PackageFile) (*PackageFile, error) {
// GetFilesByVersionID gets all files of a version
func GetFilesByVersionID(ctx context.Context, versionID int64) ([]*PackageFile, error) {
pfs := make([]*PackageFile, 0, 10)
- return pfs, db.GetEngine(ctx).Where("version_id = ?", versionID).Find(&pfs)
+ return pfs, db.GetEngine(ctx).Where("version_id = ?", versionID).OrderBy("lower_name, created_unix, id").Find(&pfs)
}
// GetFileForVersionByID gets a file of a version by id
@@ -115,6 +115,20 @@ func DeleteFileByID(ctx context.Context, fileID int64) error {
return err
}
+// DeleteFilesByPackageID deletes all files of a specific package
+// Versions must not be deleted prior to this call
+func DeleteFilesByPackageID(ctx context.Context, packageID int64) error {
+ deleteStmt := builder.Delete(builder.In("version_id", builder.Select("package_version.id").From("package_version").Where(builder.Eq{"package_id": packageID}))).From("package_file")
+ _, err := db.GetEngine(ctx).Exec(deleteStmt)
+ return err
+}
+
+// DeleteFilesByVersionID deletes all files of a specific version
+func DeleteFilesByVersionID(ctx context.Context, versionID int64) error {
+ _, err := db.GetEngine(ctx).Where("version_id = ?", versionID).Delete(&PackageFile{})
+ return err
+}
+
func UpdateFile(ctx context.Context, pf *PackageFile, cols []string) error {
_, err := db.GetEngine(ctx).ID(pf.ID).Cols(cols...).Update(pf)
return err
diff --git a/models/packages/package_property.go b/models/packages/package_property.go
index acc05d8d5a..30794ad73c 100644
--- a/models/packages/package_property.go
+++ b/models/packages/package_property.go
@@ -5,6 +5,7 @@ package packages
import (
"context"
+ "errors"
"code.gitea.io/gitea/models/db"
@@ -51,13 +52,13 @@ func InsertProperty(ctx context.Context, refType PropertyType, refID int64, name
// GetProperties gets all properties
func GetProperties(ctx context.Context, refType PropertyType, refID int64) ([]*PackageProperty, error) {
pps := make([]*PackageProperty, 0, 10)
- return pps, db.GetEngine(ctx).Where("ref_type = ? AND ref_id = ?", refType, refID).Find(&pps)
+ return pps, db.GetEngine(ctx).Where("ref_type = ? AND ref_id = ?", refType, refID).OrderBy("id").Find(&pps)
}
// GetPropertiesByName gets all properties with a specific name
func GetPropertiesByName(ctx context.Context, refType PropertyType, refID int64, name string) ([]*PackageProperty, error) {
pps := make([]*PackageProperty, 0, 10)
- return pps, db.GetEngine(ctx).Where("ref_type = ? AND ref_id = ? AND name = ?", refType, refID, name).Find(&pps)
+ return pps, db.GetEngine(ctx).Where("ref_type = ? AND ref_id = ? AND name = ?", refType, refID, name).OrderBy("id").Find(&pps)
}
// UpdateProperty updates a property
@@ -86,6 +87,46 @@ func DeleteAllProperties(ctx context.Context, refType PropertyType, refID int64)
return err
}
+// DeletePropertiesByPackageID deletes properties of a typed linked to the package
+// Use to avoid for loops in mass deletion of properties
+func DeletePropertiesByPackageID(ctx context.Context, refType PropertyType, packageID int64) error {
+ var deleteStmt *builder.Builder
+
+ switch refType {
+ case PropertyTypeFile:
+ deleteStmt = builder.Delete(
+ // Delete all properties that are attached to a file and are in ids from a subquery
+ // which returns ids from the package_file table joined on package_version to link it with package id
+ builder.Eq{"ref_type": PropertyTypeFile}, builder.In("ref_id",
+ builder.Select("package_file.id").From("package_file").
+ LeftJoin("package_version", "package_file.version_id = package_version.id").
+ Where(builder.Eq{"package_version.package_id": packageID}))).From("package_property")
+ case PropertyTypeVersion:
+ // Delete all properties that are attached to a version and are in ids from subquery to the package_version filtered by package id
+ deleteStmt = builder.Delete(
+ builder.Eq{"ref_type": PropertyTypeVersion}, builder.In("ref_id",
+ builder.Select("package_version.id").From("package_version").
+ Where(builder.Eq{"package_version.package_id": packageID}))).From("package_property")
+ case PropertyTypePackage:
+ // Delete all properties that are attached to a package and their reference links to the given package ID
+ deleteStmt = builder.Delete(
+ builder.Eq{"ref_type": PropertyTypePackage}, builder.Eq{"ref_id": packageID}).
+ From("package_property")
+ default:
+ return errors.New("invalid ref type")
+ }
+
+ _, err := db.GetEngine(ctx).Exec(deleteStmt)
+ return err
+}
+
+// DeleteFilePropertiesByVersionID deletes all file properties linked to specific version
+func DeleteFilePropertiesByVersionID(ctx context.Context, versionID int64) error {
+ deleteStmt := builder.Delete(builder.Eq{"ref_type": PropertyTypeFile}, builder.In("ref_id", builder.Select("id").From("package_file").Where(builder.Eq{"version_id": versionID}))).From("package_property")
+ _, err := db.GetEngine(ctx).Exec(deleteStmt)
+ return err
+}
+
// DeletePropertyByID deletes a property
func DeletePropertyByID(ctx context.Context, propertyID int64) error {
_, err := db.GetEngine(ctx).ID(propertyID).Delete(&PackageProperty{})
diff --git a/models/packages/package_version.go b/models/packages/package_version.go
index 0a478c0323..3e0e1899ea 100644
--- a/models/packages/package_version.go
+++ b/models/packages/package_version.go
@@ -157,6 +157,12 @@ func DeleteVersionByID(ctx context.Context, versionID int64) error {
return err
}
+// DeleteVersionsByPackageID deletes all versions of a specific package
+func DeleteVersionsByPackageID(ctx context.Context, packageID int64) error {
+ _, err := db.GetEngine(ctx).Where(builder.Eq{"package_id": packageID}).Delete(&PackageVersion{})
+ return err
+}
+
// HasVersionFileReferences checks if there are associated files
func HasVersionFileReferences(ctx context.Context, versionID int64) (bool, error) {
return db.GetEngine(ctx).Get(&PackageFile{
diff --git a/models/perm/access/access.go b/models/perm/access/access.go
index 6433c4675c..acc34c434e 100644
--- a/models/perm/access/access.go
+++ b/models/perm/access/access.go
@@ -91,43 +91,80 @@ func updateUserAccess(accessMap map[int64]*userAccess, user *user_model.User, mo
}
}
-// FIXME: do cross-comparison so reduce deletions and additions to the minimum?
+// refreshAccesses updates the repository's access records in the database by comparing the provided accessMap
+// with existing records. It minimizes DB operations by performing selective inserts, updates, and deletes
+// instead of removing all existing records and re-adding them.
func refreshAccesses(ctx context.Context, repo *repo_model.Repository, accessMap map[int64]*userAccess) (err error) {
- minMode := perm.AccessModeRead
+ minModeToKeep := perm.AccessModeRead
if err := repo.LoadOwner(ctx); err != nil {
return fmt.Errorf("LoadOwner: %w", err)
}
- // If the repo isn't private and isn't owned by a organization,
+ // If the repo isn't private and isn't owned by an organization,
// increase the minMode to Write.
if !repo.IsPrivate && !repo.Owner.IsOrganization() {
- minMode = perm.AccessModeWrite
+ minModeToKeep = perm.AccessModeWrite
+ }
+
+ // Query existing accesses for cross-comparison
+ var existingAccesses []Access
+ if err := db.GetEngine(ctx).Where(builder.Eq{"repo_id": repo.ID}).Find(&existingAccesses); err != nil {
+ return fmt.Errorf("find existing accesses: %w", err)
}
+ existingMap := make(map[int64]perm.AccessMode, len(existingAccesses))
+ for _, a := range existingAccesses {
+ existingMap[a.UserID] = a.Mode
+ }
+
+ var toDelete []int64
+ var toInsert, toUpdate []Access
- newAccesses := make([]Access, 0, len(accessMap))
+ // Determine changes
for userID, ua := range accessMap {
- if ua.Mode < minMode && !ua.User.IsRestricted {
- continue
+ if ua.Mode < minModeToKeep && !ua.User.IsRestricted {
+ // No explicit access record needed (handled by default permissions, e.g., public repo access)
+ if _, exists := existingMap[userID]; exists {
+ toDelete = append(toDelete, userID)
+ }
+ } else {
+ desiredMode := ua.Mode
+ if existingMode, exists := existingMap[userID]; exists {
+ if existingMode != desiredMode {
+ toUpdate = append(toUpdate, Access{UserID: userID, RepoID: repo.ID, Mode: desiredMode})
+ }
+ } else {
+ toInsert = append(toInsert, Access{UserID: userID, RepoID: repo.ID, Mode: desiredMode})
+ }
}
+ delete(existingMap, userID)
+ }
- newAccesses = append(newAccesses, Access{
- UserID: userID,
- RepoID: repo.ID,
- Mode: ua.Mode,
- })
+ // Remaining in existingMap should be deleted
+ for userID := range existingMap {
+ toDelete = append(toDelete, userID)
}
- // Delete old accesses and insert new ones for repository.
- if _, err = db.DeleteByBean(ctx, &Access{RepoID: repo.ID}); err != nil {
- return fmt.Errorf("delete old accesses: %w", err)
+ // Execute deletions
+ if len(toDelete) > 0 {
+ if _, err = db.GetEngine(ctx).In("user_id", toDelete).And("repo_id = ?", repo.ID).Delete(&Access{}); err != nil {
+ return fmt.Errorf("delete accesses: %w", err)
+ }
}
- if len(newAccesses) == 0 {
- return nil
+
+ // Execute updates
+ for _, u := range toUpdate {
+ if _, err = db.GetEngine(ctx).Where("user_id = ? AND repo_id = ?", u.UserID, repo.ID).Cols("mode").Update(&Access{Mode: u.Mode}); err != nil {
+ return fmt.Errorf("update access for user %d: %w", u.UserID, err)
+ }
}
- if err = db.Insert(ctx, newAccesses); err != nil {
- return fmt.Errorf("insert new accesses: %w", err)
+ // Execute insertions
+ if len(toInsert) > 0 {
+ if err = db.Insert(ctx, toInsert); err != nil {
+ return fmt.Errorf("insert new accesses: %w", err)
+ }
}
+
return nil
}
diff --git a/models/perm/access/access_test.go b/models/perm/access/access_test.go
index 15d18b368c..148a02efa3 100644
--- a/models/perm/access/access_test.go
+++ b/models/perm/access/access_test.go
@@ -15,11 +15,20 @@ import (
"code.gitea.io/gitea/modules/setting"
"github.com/stretchr/testify/assert"
+ "github.com/stretchr/testify/require"
)
-func TestAccessLevel(t *testing.T) {
- assert.NoError(t, unittest.PrepareTestDatabase())
+func TestAccess(t *testing.T) {
+ require.NoError(t, unittest.PrepareTestDatabase())
+ t.Run("AccessLevel", testAccessLevel)
+ t.Run("HasAccess", testHasAccess)
+ t.Run("RecalculateAccesses", testRecalculateAccesses)
+ t.Run("RecalculateAccesses2", testRecalculateAccesses2)
+ t.Run("RecalculateAccessesUpdateMode", testRecalculateAccessesUpdateMode)
+ t.Run("RecalculateAccessesRemoveAccess", testRecalculateAccessesRemoveAccess)
+}
+func testAccessLevel(t *testing.T) {
user2 := unittest.AssertExistsAndLoadBean(t, &user_model.User{ID: 2})
user5 := unittest.AssertExistsAndLoadBean(t, &user_model.User{ID: 5})
user29 := unittest.AssertExistsAndLoadBean(t, &user_model.User{ID: 29})
@@ -75,9 +84,7 @@ func TestAccessLevel(t *testing.T) {
assert.Equal(t, perm_model.AccessModeRead, level)
}
-func TestHasAccess(t *testing.T) {
- assert.NoError(t, unittest.PrepareTestDatabase())
-
+func testHasAccess(t *testing.T) {
user1 := unittest.AssertExistsAndLoadBean(t, &user_model.User{ID: 2})
user2 := unittest.AssertExistsAndLoadBean(t, &user_model.User{ID: 5})
// A public repository owned by User 2
@@ -101,9 +108,8 @@ func TestHasAccess(t *testing.T) {
assert.NoError(t, err)
}
-func TestRepository_RecalculateAccesses(t *testing.T) {
+func testRecalculateAccesses(t *testing.T) {
// test with organization repo
- assert.NoError(t, unittest.PrepareTestDatabase())
repo1 := unittest.AssertExistsAndLoadBean(t, &repo_model.Repository{ID: 3})
assert.NoError(t, repo1.LoadOwner(t.Context()))
@@ -118,9 +124,8 @@ func TestRepository_RecalculateAccesses(t *testing.T) {
assert.Equal(t, perm_model.AccessModeOwner, access.Mode)
}
-func TestRepository_RecalculateAccesses2(t *testing.T) {
+func testRecalculateAccesses2(t *testing.T) {
// test with non-organization repo
- assert.NoError(t, unittest.PrepareTestDatabase())
repo1 := unittest.AssertExistsAndLoadBean(t, &repo_model.Repository{ID: 4})
assert.NoError(t, repo1.LoadOwner(t.Context()))
@@ -132,3 +137,67 @@ func TestRepository_RecalculateAccesses2(t *testing.T) {
assert.NoError(t, err)
assert.False(t, has)
}
+
+func testRecalculateAccessesUpdateMode(t *testing.T) {
+ // Test the update path in refreshAccesses optimization
+ // Scenario: User's access mode changes from Read to Write
+ repo := unittest.AssertExistsAndLoadBean(t, &repo_model.Repository{ID: 4})
+ assert.NoError(t, repo.LoadOwner(t.Context()))
+
+ // Verify initial access mode
+ _ = db.Insert(t.Context(), &repo_model.Collaboration{UserID: 4, RepoID: 4, Mode: perm_model.AccessModeWrite})
+ _ = db.Insert(t.Context(), &access_model.Access{UserID: 4, RepoID: 4, Mode: perm_model.AccessModeWrite})
+ initialAccess := &access_model.Access{UserID: 4, RepoID: 4}
+ has, err := db.GetEngine(t.Context()).Get(initialAccess)
+ assert.NoError(t, err)
+ assert.True(t, has)
+ initialMode := initialAccess.Mode
+
+ // Change collaboration mode to trigger update path
+ newMode := perm_model.AccessModeAdmin
+ assert.NotEqual(t, initialMode, newMode, "New mode should differ from initial mode")
+
+ _, err = db.GetEngine(t.Context()).
+ Where("user_id = ? AND repo_id = ?", 4, 4).
+ Cols("mode").
+ Update(&repo_model.Collaboration{Mode: newMode})
+ assert.NoError(t, err)
+
+ // Recalculate accesses - should UPDATE existing access, not delete+insert
+ assert.NoError(t, access_model.RecalculateAccesses(t.Context(), repo))
+
+ // Verify access was updated, not deleted and re-inserted
+ updatedAccess := &access_model.Access{UserID: 4, RepoID: 4}
+ has, err = db.GetEngine(t.Context()).Get(updatedAccess)
+ assert.NoError(t, err)
+ assert.True(t, has, "Access should still exist")
+ assert.Equal(t, newMode, updatedAccess.Mode, "Access mode should be updated to new collaboration mode")
+}
+
+func testRecalculateAccessesRemoveAccess(t *testing.T) {
+ // Test the delete path in refreshAccesses optimization
+ // Scenario: Remove a user's collaboration, access should be deleted
+ repo := unittest.AssertExistsAndLoadBean(t, &repo_model.Repository{ID: 4})
+ assert.NoError(t, repo.LoadOwner(t.Context()))
+
+ // Verify initial access exists
+ initialAccess := &access_model.Access{UserID: 4, RepoID: 4}
+ has, err := db.GetEngine(t.Context()).Get(initialAccess)
+ assert.NoError(t, err)
+ assert.True(t, has, "Access should exist initially")
+
+ // Remove the collaboration to trigger delete path
+ _, err = db.GetEngine(t.Context()).
+ Where("user_id = ? AND repo_id = ?", 4, 4).
+ Delete(&repo_model.Collaboration{})
+ assert.NoError(t, err)
+
+ // Recalculate accesses - should DELETE the access record
+ assert.NoError(t, access_model.RecalculateAccesses(t.Context(), repo))
+
+ // Verify access was deleted
+ removedAccess := &access_model.Access{UserID: 4, RepoID: 4}
+ has, err = db.GetEngine(t.Context()).Get(removedAccess)
+ assert.NoError(t, err)
+ assert.False(t, has, "Access should be deleted after removing collaboration")
+}
diff --git a/models/perm/access/actions_repo_permission_test.go b/models/perm/access/actions_repo_permission_test.go
new file mode 100644
index 0000000000..442f6cf2fc
--- /dev/null
+++ b/models/perm/access/actions_repo_permission_test.go
@@ -0,0 +1,155 @@
+// Copyright 2026 The Gitea Authors. All rights reserved.
+// SPDX-License-Identifier: MIT
+
+package access
+
+import (
+ "testing"
+
+ actions_model "code.gitea.io/gitea/models/actions"
+ "code.gitea.io/gitea/models/db"
+ perm_model "code.gitea.io/gitea/models/perm"
+ repo_model "code.gitea.io/gitea/models/repo"
+ "code.gitea.io/gitea/models/unit"
+ "code.gitea.io/gitea/models/unittest"
+ user_model "code.gitea.io/gitea/models/user"
+
+ "github.com/stretchr/testify/assert"
+ "github.com/stretchr/testify/require"
+)
+
+func TestGetActionsUserRepoPermission(t *testing.T) {
+ require.NoError(t, unittest.PrepareTestDatabase())
+ ctx := t.Context()
+
+ // Use fixtures for repos and users
+ repo4 := unittest.AssertExistsAndLoadBean(t, &repo_model.Repository{ID: 4}) // Public, Owner 5, has Actions unit
+ repo2 := unittest.AssertExistsAndLoadBean(t, &repo_model.Repository{ID: 2}) // Private, Owner 2, no Actions unit in fixtures
+ repo15 := unittest.AssertExistsAndLoadBean(t, &repo_model.Repository{ID: 15}) // Private, Owner 2, no Actions unit in fixtures
+ owner2 := unittest.AssertExistsAndLoadBean(t, &user_model.User{ID: 2})
+ actionsUser := user_model.NewActionsUser()
+
+ // Ensure repo2 and repo15 have Actions units for testing configuration
+ for _, r := range []*repo_model.Repository{repo2, repo15} {
+ require.NoError(t, db.Insert(ctx, &repo_model.RepoUnit{
+ RepoID: r.ID,
+ Type: unit.TypeActions,
+ Config: &repo_model.ActionsConfig{},
+ }))
+ }
+
+ t.Run("SameRepo_Public", func(t *testing.T) {
+ task47 := unittest.AssertExistsAndLoadBean(t, &actions_model.ActionTask{ID: 47})
+ require.Equal(t, repo4.ID, task47.RepoID)
+
+ perm, err := GetActionsUserRepoPermission(ctx, repo4, actionsUser, task47.ID)
+ require.NoError(t, err)
+
+ // Public repo, bot should have Read access even if not collaborator
+ assert.Equal(t, perm_model.AccessModeNone, perm.AccessMode)
+ assert.True(t, perm.CanRead(unit.TypeCode))
+ })
+
+ t.Run("SameRepo_Private", func(t *testing.T) {
+ // Use Task 53 which is already in Repo 2 (Private)
+ task53 := unittest.AssertExistsAndLoadBean(t, &actions_model.ActionTask{ID: 53})
+ require.Equal(t, repo2.ID, task53.RepoID)
+
+ perm, err := GetActionsUserRepoPermission(ctx, repo2, actionsUser, task53.ID)
+ require.NoError(t, err)
+
+ // Private repo, bot has no base access, but gets Write from effective tokens perms (Permissive by default)
+ assert.Equal(t, perm_model.AccessModeNone, perm.AccessMode)
+ assert.True(t, perm.CanWrite(unit.TypeCode))
+ })
+
+ t.Run("CrossRepo_Denied_None", func(t *testing.T) {
+ task53 := unittest.AssertExistsAndLoadBean(t, &actions_model.ActionTask{ID: 53})
+
+ // Set owner policy to nil allowed repos (None)
+ cfg := actions_model.OwnerActionsConfig{}
+ require.NoError(t, actions_model.SetOwnerActionsConfig(ctx, owner2.ID, cfg))
+
+ perm, err := GetActionsUserRepoPermission(ctx, repo15, actionsUser, task53.ID)
+ require.NoError(t, err)
+
+ // Should NOT have access to the private repo.
+ assert.False(t, perm.CanRead(unit.TypeCode))
+ })
+
+ t.Run("ForkPR_NoCrossRepo", func(t *testing.T) {
+ task53 := unittest.AssertExistsAndLoadBean(t, &actions_model.ActionTask{ID: 53})
+ task53.IsForkPullRequest = true
+ require.NoError(t, actions_model.UpdateTask(ctx, task53, "is_fork_pull_request"))
+
+ // Policy contains repo15
+ cfg := actions_model.OwnerActionsConfig{
+ AllowedCrossRepoIDs: []int64{repo15.ID},
+ }
+ require.NoError(t, actions_model.SetOwnerActionsConfig(ctx, owner2.ID, cfg))
+
+ perm, err := GetActionsUserRepoPermission(ctx, repo15, actionsUser, task53.ID)
+ require.NoError(t, err)
+
+ // Fork PR never gets cross-repo access to other private repos
+ assert.False(t, perm.CanRead(unit.TypeCode))
+ })
+
+ t.Run("Inheritance_And_Clamping", func(t *testing.T) {
+ task53 := unittest.AssertExistsAndLoadBean(t, &actions_model.ActionTask{ID: 53})
+ task53.IsForkPullRequest = false
+ require.NoError(t, actions_model.UpdateTask(ctx, task53, "is_fork_pull_request"))
+
+ // Owner policy: Restricted mode (Read-only Code)
+ ownerCfg := actions_model.OwnerActionsConfig{
+ TokenPermissionMode: repo_model.ActionsTokenPermissionModeRestricted,
+ MaxTokenPermissions: &repo_model.ActionsTokenPermissions{
+ UnitAccessModes: map[unit.Type]perm_model.AccessMode{
+ unit.TypeCode: perm_model.AccessModeRead,
+ },
+ },
+ }
+ require.NoError(t, actions_model.SetOwnerActionsConfig(ctx, owner2.ID, ownerCfg))
+
+ // Repo policy: OverrideOwnerConfig = false (should inherit owner's restricted mode)
+ repo2ActionsUnit := repo2.MustGetUnit(ctx, unit.TypeActions)
+ repo2ActionsCfg := repo2ActionsUnit.ActionsConfig()
+ repo2ActionsCfg.OverrideOwnerConfig = false
+ require.NoError(t, repo_model.UpdateRepoUnitConfig(ctx, repo2ActionsUnit))
+
+ perm, err := GetActionsUserRepoPermission(ctx, repo2, actionsUser, task53.ID)
+ require.NoError(t, err)
+
+ // Should be clamped to Read-only
+ assert.Equal(t, perm_model.AccessModeRead, perm.UnitAccessMode(unit.TypeCode))
+ assert.False(t, perm.CanWrite(unit.TypeCode))
+ })
+
+ t.Run("RepoOverride_Clamping", func(t *testing.T) {
+ task53 := unittest.AssertExistsAndLoadBean(t, &actions_model.ActionTask{ID: 53})
+
+ // Owner policy: Permissive (Write access)
+ ownerCfg := actions_model.OwnerActionsConfig{
+ TokenPermissionMode: repo_model.ActionsTokenPermissionModePermissive,
+ }
+ require.NoError(t, actions_model.SetOwnerActionsConfig(ctx, owner2.ID, ownerCfg))
+
+ // Repo policy: OverrideOwnerConfig = true, MaxTokenPermissions = Read
+ repo2ActionsUnit := repo2.MustGetUnit(ctx, unit.TypeActions)
+ repo2ActionsCfg := repo2ActionsUnit.ActionsConfig()
+ repo2ActionsCfg.OverrideOwnerConfig = true
+ repo2ActionsCfg.TokenPermissionMode = repo_model.ActionsTokenPermissionModeRestricted
+ repo2ActionsCfg.MaxTokenPermissions = &repo_model.ActionsTokenPermissions{
+ UnitAccessModes: map[unit.Type]perm_model.AccessMode{
+ unit.TypeCode: perm_model.AccessModeRead,
+ },
+ }
+ require.NoError(t, repo_model.UpdateRepoUnitConfig(ctx, repo2ActionsUnit))
+
+ perm, err := GetActionsUserRepoPermission(ctx, repo2, actionsUser, task53.ID)
+ require.NoError(t, err)
+
+ // Should be clamped to Read-only
+ assert.Equal(t, perm_model.AccessModeRead, perm.UnitAccessMode(unit.TypeCode))
+ })
+}
diff --git a/models/perm/access/repo_permission.go b/models/perm/access/repo_permission.go
index b663a6c05b..21821f1746 100644
--- a/models/perm/access/repo_permission.go
+++ b/models/perm/access/repo_permission.go
@@ -5,9 +5,13 @@ package access
import (
"context"
+ "errors"
"fmt"
+ "maps"
"slices"
+ "strings"
+ actions_model "code.gitea.io/gitea/models/actions"
"code.gitea.io/gitea/models/db"
"code.gitea.io/gitea/models/organization"
perm_model "code.gitea.io/gitea/models/perm"
@@ -167,7 +171,8 @@ func (p *Permission) ReadableUnitTypes() []unit.Type {
}
func (p *Permission) LogString() string {
- format := ""
- return fmt.Sprintf(format, args...)
+ format.WriteString("\n\t]>")
+ return fmt.Sprintf(format.String(), args...)
}
func applyPublicAccessPermission(unitType unit.Type, accessMode perm_model.AccessMode, modeMap *map[unit.Type]perm_model.AccessMode) {
@@ -254,8 +259,139 @@ func finalProcessRepoUnitPermission(user *user_model.User, perm *Permission) {
}
}
-// GetUserRepoPermission returns the user permissions to the repository
-func GetUserRepoPermission(ctx context.Context, repo *repo_model.Repository, user *user_model.User) (perm Permission, err error) {
+func checkSameOwnerCrossRepoAccess(ctx context.Context, taskRepo, targetRepo *repo_model.Repository, isForkPR bool) bool {
+ if isForkPR {
+ // Fork PRs are never allowed cross-repo access to other private repositories of the owner.
+ return false
+ }
+ if taskRepo.OwnerID != targetRepo.OwnerID {
+ return false
+ }
+ ownerCfg, err := actions_model.GetOwnerActionsConfig(ctx, targetRepo.OwnerID)
+ if err != nil {
+ log.Error("GetOwnerActionsConfig: %v", err)
+ return false
+ }
+
+ return slices.Contains(ownerCfg.AllowedCrossRepoIDs, targetRepo.ID)
+}
+
+// GetActionsUserRepoPermission returns the actions user permissions to the repository
+func GetActionsUserRepoPermission(ctx context.Context, repo *repo_model.Repository, actionsUser *user_model.User, taskID int64) (perm Permission, err error) {
+ if actionsUser.ID != user_model.ActionsUserID {
+ return perm, errors.New("api GetActionsUserRepoPermission can only be called by the actions user")
+ }
+ task, err := actions_model.GetTaskByID(ctx, taskID)
+ if err != nil {
+ return perm, err
+ }
+
+ if err := task.LoadJob(ctx); err != nil {
+ return perm, err
+ }
+
+ var taskRepo *repo_model.Repository
+ if task.RepoID != repo.ID {
+ if err := task.Job.LoadRepo(ctx); err != nil {
+ return perm, err
+ }
+ taskRepo = task.Job.Repo
+ } else {
+ taskRepo = repo
+ }
+
+ // Compute effective permissions for this task against the target repo
+ effectivePerms, err := actions_model.ComputeTaskTokenPermissions(ctx, task, repo)
+ if err != nil {
+ return perm, err
+ }
+ if task.RepoID != repo.ID {
+ // Cross-repo access must also respect the target repo's permission ceiling.
+ targetRepoActionsCfg := repo.MustGetUnit(ctx, unit.TypeActions).ActionsConfig()
+ if targetRepoActionsCfg.OverrideOwnerConfig {
+ effectivePerms = targetRepoActionsCfg.ClampPermissions(effectivePerms)
+ } else {
+ targetRepoOwnerActionsCfg, err := actions_model.GetOwnerActionsConfig(ctx, repo.OwnerID)
+ if err != nil {
+ return perm, err
+ }
+ effectivePerms = targetRepoOwnerActionsCfg.ClampPermissions(effectivePerms)
+ }
+ }
+
+ if err := repo.LoadUnits(ctx); err != nil {
+ return perm, err
+ }
+
+ var maxPerm Permission
+
+ // Set up per-unit access modes based on configured permissions
+ maxPerm.units = repo.Units
+ maxPerm.unitsMode = maps.Clone(effectivePerms.UnitAccessModes)
+
+ // Check permission like simple user but limit to read-only (PR #36095)
+ // Enhanced to also grant read-only access if isSameRepo is true and target repository is public
+ botPerm, err := GetIndividualUserRepoPermission(ctx, repo, user_model.NewActionsUser())
+ if err != nil {
+ return perm, err
+ }
+ if botPerm.AccessMode >= perm_model.AccessModeRead {
+ // Public repo allows read access, increase permissions to at least read
+ // Otherwise you cannot access your own repository if your permissions are set to none but the repository is public
+ for _, u := range repo.Units {
+ if botPerm.CanRead(u.Type) {
+ maxPerm.unitsMode[u.Type] = max(maxPerm.unitsMode[u.Type], perm_model.AccessModeRead)
+ }
+ }
+ }
+
+ if task.RepoID == repo.ID {
+ return maxPerm, nil
+ }
+
+ if checkSameOwnerCrossRepoAccess(ctx, taskRepo, repo, task.IsForkPullRequest) {
+ // Access allowed by owner policy (grants access to private repos).
+ // Note: maxPerm has already been restricted to Read-Only in ComputeTaskTokenPermissions
+ // because isSameRepo is false.
+ return maxPerm, nil
+ }
+
+ // Fall through to allow public repository read access via botPerm check below
+
+ // Check if the repo is public or the Bot has explicit access
+ if botPerm.AccessMode >= perm_model.AccessModeRead {
+ return maxPerm, nil
+ }
+
+ // Check Collaborative Owner and explicit Bot permissions
+ // We allow access if:
+ // 1. It's a collaborative owner relationship
+ // 2. The Actions Bot user has been explicitly granted access and repository is private
+ // 3. The repository is public (handled by botPerm above)
+
+ if taskRepo.IsPrivate {
+ actionsUnit := repo.MustGetUnit(ctx, unit.TypeActions)
+ if actionsUnit.ActionsConfig().IsCollaborativeOwner(taskRepo.OwnerID) {
+ return maxPerm, nil
+ }
+ }
+
+ return perm, nil
+}
+
+// GetDoerRepoPermission returns the repository permission for the current actor,
+// dispatching to GetActionsUserRepoPermission when the actor is an Actions token user.
+func GetDoerRepoPermission(ctx context.Context, repo *repo_model.Repository, user *user_model.User) (Permission, error) {
+ if taskID, ok := user_model.GetActionsUserTaskID(user); ok {
+ return GetActionsUserRepoPermission(ctx, repo, user, taskID)
+ }
+ return GetIndividualUserRepoPermission(ctx, repo, user)
+}
+
+// GetIndividualUserRepoPermission returns the permissions for an explicit user identity.
+// In most request paths, callers should use GetDoerRepoPermission instead.
+// Unlike GetDoerRepoPermission, this helper does not resolve Actions task users.
+func GetIndividualUserRepoPermission(ctx context.Context, repo *repo_model.Repository, user *user_model.User) (perm Permission, err error) {
defer func() {
if err == nil {
finalProcessRepoUnitPermission(user, &perm)
@@ -414,8 +550,9 @@ func AccessLevel(ctx context.Context, user *user_model.User, repo *repo_model.Re
// AccessLevelUnit returns the Access a user has to a repository's. Will return NoneAccess if the
// user does not have access.
+// This helper only supports explicit user identities and does not resolve Actions task users.
func AccessLevelUnit(ctx context.Context, user *user_model.User, repo *repo_model.Repository, unitType unit.Type) (perm_model.AccessMode, error) { //nolint:revive // export stutter
- perm, err := GetUserRepoPermission(ctx, repo, user)
+ perm, err := GetIndividualUserRepoPermission(ctx, repo, user)
if err != nil {
return perm_model.AccessModeNone, err
}
@@ -434,7 +571,7 @@ func CanBeAssigned(ctx context.Context, user *user_model.User, repo *repo_model.
if user.IsOrganization() {
return false, fmt.Errorf("organization can't be added as assignee [user_id: %d, repo_id: %d]", user.ID, repo.ID)
}
- perm, err := GetUserRepoPermission(ctx, repo, user)
+ perm, err := GetIndividualUserRepoPermission(ctx, repo, user)
if err != nil {
return false, err
}
@@ -443,6 +580,7 @@ func CanBeAssigned(ctx context.Context, user *user_model.User, repo *repo_model.
}
// HasAnyUnitAccess see the comment of "perm.HasAnyUnitAccess"
+// This helper only supports explicit user identities and does not resolve Actions task users.
func HasAnyUnitAccess(ctx context.Context, userID int64, repo *repo_model.Repository) (bool, error) {
var user *user_model.User
var err error
@@ -452,7 +590,7 @@ func HasAnyUnitAccess(ctx context.Context, userID int64, repo *repo_model.Reposi
return false, err
}
}
- perm, err := GetUserRepoPermission(ctx, repo, user)
+ perm, err := GetIndividualUserRepoPermission(ctx, repo, user)
if err != nil {
return false, err
}
@@ -500,13 +638,14 @@ func GetUserIDsWithUnitAccess(ctx context.Context, repo *repo_model.Repository,
}
// CheckRepoUnitUser check whether user could visit the unit of this repository
+// This helper only supports explicit user identities and does not resolve Actions task users.
func CheckRepoUnitUser(ctx context.Context, repo *repo_model.Repository, user *user_model.User, unitType unit.Type) bool {
if user != nil && user.IsAdmin {
return true
}
- perm, err := GetUserRepoPermission(ctx, repo, user)
+ perm, err := GetIndividualUserRepoPermission(ctx, repo, user)
if err != nil {
- log.Error("GetUserRepoPermission: %w", err)
+ log.Error("GetIndividualUserRepoPermission: %w", err)
return false
}
diff --git a/models/perm/access/repo_permission_test.go b/models/perm/access/repo_permission_test.go
index a36be213ec..29a8dac71d 100644
--- a/models/perm/access/repo_permission_test.go
+++ b/models/perm/access/repo_permission_test.go
@@ -6,6 +6,7 @@ package access
import (
"testing"
+ actions_model "code.gitea.io/gitea/models/actions"
"code.gitea.io/gitea/models/db"
"code.gitea.io/gitea/models/organization"
perm_model "code.gitea.io/gitea/models/perm"
@@ -157,8 +158,13 @@ func TestUnitAccessMode(t *testing.T) {
assert.Equal(t, perm_model.AccessModeRead, perm.UnitAccessMode(unit.TypeWiki), "has unit, and map, use map")
}
-func TestGetUserRepoPermission(t *testing.T) {
- assert.NoError(t, unittest.PrepareTestDatabase())
+func TestGetRepoPermission(t *testing.T) {
+ require.NoError(t, unittest.PrepareTestDatabase())
+ t.Run("GetIndividualUserRepoPermission", testGetIndividualUserRepoPermission)
+ t.Run("GetDoerRepoPermission", testGetDoerRepoPermission)
+}
+
+func testGetIndividualUserRepoPermission(t *testing.T) {
ctx := t.Context()
repo32 := unittest.AssertExistsAndLoadBean(t, &repo_model.Repository{ID: 32}) // org public repo
require.NoError(t, repo32.LoadOwner(ctx))
@@ -172,7 +178,7 @@ func TestGetUserRepoPermission(t *testing.T) {
require.NoError(t, db.Insert(ctx, &organization.TeamUser{OrgID: org.ID, TeamID: team.ID, UID: user.ID}))
t.Run("DoerInTeamWithNoRepo", func(t *testing.T) {
- perm, err := GetUserRepoPermission(ctx, repo32, user)
+ perm, err := GetIndividualUserRepoPermission(ctx, repo32, user)
require.NoError(t, err)
assert.Equal(t, perm_model.AccessModeRead, perm.AccessMode)
assert.Nil(t, perm.unitsMode) // doer in the team, but has no access to the repo
@@ -181,7 +187,7 @@ func TestGetUserRepoPermission(t *testing.T) {
require.NoError(t, db.Insert(ctx, &organization.TeamRepo{OrgID: org.ID, TeamID: team.ID, RepoID: repo32.ID}))
require.NoError(t, db.Insert(ctx, &organization.TeamUnit{OrgID: org.ID, TeamID: team.ID, Type: unit.TypeCode, AccessMode: perm_model.AccessModeNone}))
t.Run("DoerWithTeamUnitAccessNone", func(t *testing.T) {
- perm, err := GetUserRepoPermission(ctx, repo32, user)
+ perm, err := GetIndividualUserRepoPermission(ctx, repo32, user)
require.NoError(t, err)
assert.Equal(t, perm_model.AccessModeRead, perm.AccessMode)
assert.Equal(t, perm_model.AccessModeRead, perm.unitsMode[unit.TypeCode])
@@ -191,7 +197,7 @@ func TestGetUserRepoPermission(t *testing.T) {
require.NoError(t, db.TruncateBeans(ctx, &organization.TeamUnit{}))
require.NoError(t, db.Insert(ctx, &organization.TeamUnit{OrgID: org.ID, TeamID: team.ID, Type: unit.TypeCode, AccessMode: perm_model.AccessModeWrite}))
t.Run("DoerWithTeamUnitAccessWrite", func(t *testing.T) {
- perm, err := GetUserRepoPermission(ctx, repo32, user)
+ perm, err := GetIndividualUserRepoPermission(ctx, repo32, user)
require.NoError(t, err)
assert.Equal(t, perm_model.AccessModeRead, perm.AccessMode)
assert.Equal(t, perm_model.AccessModeWrite, perm.unitsMode[unit.TypeCode])
@@ -204,7 +210,7 @@ func TestGetUserRepoPermission(t *testing.T) {
require.NoError(t, db.TruncateBeans(ctx, &organization.TeamUnit{}, &Access{})) // The user has access set of that repo, remove it, it is useless for our test
require.NoError(t, db.Insert(ctx, &organization.TeamRepo{OrgID: org.ID, TeamID: team.ID, RepoID: repo3.ID}))
t.Run("DoerWithNoopTeamOnPrivateRepo", func(t *testing.T) {
- perm, err := GetUserRepoPermission(ctx, repo3, user)
+ perm, err := GetIndividualUserRepoPermission(ctx, repo3, user)
require.NoError(t, err)
assert.Equal(t, perm_model.AccessModeNone, perm.AccessMode)
assert.Equal(t, perm_model.AccessModeNone, perm.unitsMode[unit.TypeCode])
@@ -214,7 +220,7 @@ func TestGetUserRepoPermission(t *testing.T) {
require.NoError(t, db.Insert(ctx, &organization.TeamUnit{OrgID: org.ID, TeamID: team.ID, Type: unit.TypeCode, AccessMode: perm_model.AccessModeNone}))
require.NoError(t, db.Insert(ctx, &organization.TeamUnit{OrgID: org.ID, TeamID: team.ID, Type: unit.TypeIssues, AccessMode: perm_model.AccessModeRead}))
t.Run("DoerWithReadIssueTeamOnPrivateRepo", func(t *testing.T) {
- perm, err := GetUserRepoPermission(ctx, repo3, user)
+ perm, err := GetIndividualUserRepoPermission(ctx, repo3, user)
require.NoError(t, err)
assert.Equal(t, perm_model.AccessModeNone, perm.AccessMode)
assert.Equal(t, perm_model.AccessModeNone, perm.unitsMode[unit.TypeCode])
@@ -233,7 +239,7 @@ func TestGetUserRepoPermission(t *testing.T) {
require.NoError(t, db.Insert(ctx, repo_model.Collaboration{RepoID: repo3.ID, UserID: user.ID, Mode: perm_model.AccessModeWrite}))
require.NoError(t, db.Insert(ctx, Access{RepoID: repo3.ID, UserID: user.ID, Mode: perm_model.AccessModeWrite}))
t.Run("DoerWithReadIssueTeamAndWriteCollaboratorOnPrivateRepo", func(t *testing.T) {
- perm, err := GetUserRepoPermission(ctx, repo3, user)
+ perm, err := GetIndividualUserRepoPermission(ctx, repo3, user)
require.NoError(t, err)
assert.Equal(t, perm_model.AccessModeWrite, perm.AccessMode)
assert.Equal(t, perm_model.AccessModeWrite, perm.unitsMode[unit.TypeCode])
@@ -245,3 +251,25 @@ func TestGetUserRepoPermission(t *testing.T) {
assert.Equal(t, user.ID, users[0].ID)
})
}
+
+func testGetDoerRepoPermission(t *testing.T) {
+ ctx := t.Context()
+
+ repo4 := unittest.AssertExistsAndLoadBean(t, &repo_model.Repository{ID: 4})
+ repo1 := unittest.AssertExistsAndLoadBean(t, &repo_model.Repository{ID: 1})
+ task47 := unittest.AssertExistsAndLoadBean(t, &actions_model.ActionTask{ID: 47})
+ actionsDoer := user_model.NewActionsUserWithTaskID(task47.ID)
+ regularUser := unittest.AssertExistsAndLoadBean(t, &user_model.User{ID: 2})
+
+ actionsPerm, err := GetDoerRepoPermission(ctx, repo4, actionsDoer)
+ require.NoError(t, err)
+ directPerm, err := GetActionsUserRepoPermission(ctx, repo4, actionsDoer, task47.ID)
+ require.NoError(t, err)
+ assert.Equal(t, directPerm, actionsPerm)
+
+ doerPerm, err := GetDoerRepoPermission(ctx, repo1, regularUser)
+ require.NoError(t, err)
+ individualPerm, err := GetIndividualUserRepoPermission(ctx, repo1, regularUser)
+ require.NoError(t, err)
+ assert.Equal(t, individualPerm, doerPerm)
+}
diff --git a/models/project/column.go b/models/project/column.go
index 9b9d874997..7365204f18 100644
--- a/models/project/column.go
+++ b/models/project/column.go
@@ -213,6 +213,18 @@ func GetColumn(ctx context.Context, columnID int64) (*Column, error) {
return column, nil
}
+func GetColumnByIDAndProjectID(ctx context.Context, columnID, projectID int64) (*Column, error) {
+ column := new(Column)
+ has, err := db.GetEngine(ctx).ID(columnID).And("project_id=?", projectID).Get(column)
+ if err != nil {
+ return nil, err
+ } else if !has {
+ return nil, ErrProjectColumnNotExist{ColumnID: columnID}
+ }
+
+ return column, nil
+}
+
// UpdateColumn updates a project column
func UpdateColumn(ctx context.Context, column *Column) error {
var fieldToUpdate []string
@@ -245,9 +257,12 @@ func (p *Project) GetColumns(ctx context.Context) (ColumnList, error) {
return columns, nil
}
-// getDefaultColumn return default column and ensure only one exists
-func (p *Project) getDefaultColumn(ctx context.Context) (*Column, error) {
+// getDefaultColumnWithFallback return default column if one exists
+// otherwise return the first column by sorting and set it as default column
+func (p *Project) getDefaultColumnWithFallback(ctx context.Context) (*Column, error) {
var column Column
+
+ // try to find a column "default=true"
has, err := db.GetEngine(ctx).
Where("project_id=? AND `default` = ?", p.ID, true).
Desc("id").Get(&column)
@@ -258,14 +273,29 @@ func (p *Project) getDefaultColumn(ctx context.Context) (*Column, error) {
if has {
return &column, nil
}
+
+ // try to find the first column by sorting
+ has, err = db.GetEngine(ctx).Where("project_id=?", p.ID).OrderBy("sorting, id").Get(&column)
+ if err != nil {
+ return nil, err
+ }
+ if has {
+ column.Default = true
+ if _, err := db.GetEngine(ctx).ID(column.ID).Cols("`default`").Update(&column); err != nil {
+ return nil, err
+ }
+ return &column, nil
+ }
+
return nil, ErrProjectColumnNotExist{ColumnID: 0}
}
// MustDefaultColumn returns the default column for a project.
// If one exists, it is returned
// If none exists, the first column will be elevated to the default column of this project
+// If there is no column, it creates a default column and returns it
func (p *Project) MustDefaultColumn(ctx context.Context) (*Column, error) {
- c, err := p.getDefaultColumn(ctx)
+ c, err := p.getDefaultColumnWithFallback(ctx)
if err != nil && !IsErrProjectColumnNotExist(err) {
return nil, err
}
@@ -273,21 +303,8 @@ func (p *Project) MustDefaultColumn(ctx context.Context) (*Column, error) {
return c, nil
}
- var column Column
- has, err := db.GetEngine(ctx).Where("project_id=?", p.ID).OrderBy("sorting, id").Get(&column)
- if err != nil {
- return nil, err
- }
- if has {
- column.Default = true
- if _, err := db.GetEngine(ctx).ID(column.ID).Cols("`default`").Update(&column); err != nil {
- return nil, err
- }
- return &column, nil
- }
-
// create a default column if none is found
- column = Column{
+ column := Column{
ProjectID: p.ID,
Default: true,
Title: "Uncategorized",
diff --git a/models/project/project.go b/models/project/project.go
index c003664fa3..7646c3dd71 100644
--- a/models/project/project.go
+++ b/models/project/project.go
@@ -302,6 +302,18 @@ func GetProjectByID(ctx context.Context, id int64) (*Project, error) {
return p, nil
}
+func GetProjectByIDAndOwner(ctx context.Context, id, ownerID int64) (*Project, error) {
+ p := new(Project)
+ has, err := db.GetEngine(ctx).ID(id).And("owner_id = ?", ownerID).Get(p)
+ if err != nil {
+ return nil, err
+ } else if !has {
+ return nil, ErrProjectNotExist{ID: id}
+ }
+
+ return p, nil
+}
+
// GetProjectForRepoByID returns the projects in a repository
func GetProjectForRepoByID(ctx context.Context, repoID, id int64) (*Project, error) {
p := new(Project)
diff --git a/models/pull/automerge.go b/models/pull/automerge.go
index 7f940a9849..d32dc847d2 100644
--- a/models/pull/automerge.go
+++ b/models/pull/automerge.go
@@ -5,14 +5,12 @@ package pull
import (
"context"
- "errors"
"fmt"
"code.gitea.io/gitea/models/db"
repo_model "code.gitea.io/gitea/models/repo"
user_model "code.gitea.io/gitea/models/user"
"code.gitea.io/gitea/modules/timeutil"
- "code.gitea.io/gitea/modules/util"
)
// AutoMerge represents a pull request scheduled for merging when checks succeed
@@ -78,16 +76,8 @@ func GetScheduledMergeByPullID(ctx context.Context, pullID int64) (bool, *AutoMe
return false, nil, err
}
- doer, err := user_model.GetPossibleUserByID(ctx, scheduledPRM.DoerID)
- if errors.Is(err, util.ErrNotExist) {
- doer, err = user_model.NewGhostUser(), nil
- }
- if err != nil {
- return false, nil, err
- }
-
- scheduledPRM.Doer = doer
- return true, scheduledPRM, nil
+ scheduledPRM.DoerID, scheduledPRM.Doer, err = user_model.GetPossibleUserByID(ctx, scheduledPRM.DoerID)
+ return true, scheduledPRM, err
}
// DeleteScheduledAutoMerge delete a scheduled pull request
diff --git a/models/renderhelper/repo_file.go b/models/renderhelper/repo_file.go
index e0375ed280..5d0bfd6c80 100644
--- a/models/renderhelper/repo_file.go
+++ b/models/renderhelper/repo_file.go
@@ -50,8 +50,8 @@ type RepoFileOptions struct {
DeprecatedRepoName string // it is only a patch for the non-standard "markup" api
DeprecatedOwnerName string // it is only a patch for the non-standard "markup" api
- CurrentRefPath string // eg: "branch/main"
- CurrentTreePath string // eg: "path/to/file" in the repo
+ CurrentRefPath string // eg: "branch/main", it is a sub URL path escaped by callers, TODO: rename to CurrentRefSubURL
+ CurrentTreePath string // eg: "path/to/file" in the repo, it is the tree path without URL path escaping
}
func NewRenderContextRepoFile(ctx context.Context, repo *repo_model.Repository, opts ...RepoFileOptions) *markup.RenderContext {
@@ -70,6 +70,10 @@ func NewRenderContextRepoFile(ctx context.Context, repo *repo_model.Repository,
"repo": helper.opts.DeprecatedRepoName,
})
}
- rctx = rctx.WithHelper(helper)
+ // External render's iframe needs this to generate correct links
+ // TODO: maybe need to make it access "CurrentRefPath" directly (but impossible at the moment due to cycle-import)
+ // CurrentRefPath is already path-escaped by callers
+ rctx.RenderOptions.Metas["RefTypeNameSubURL"] = helper.opts.CurrentRefPath
+ rctx = rctx.WithHelper(helper).WithEnableHeadingIDGeneration(true)
return rctx
}
diff --git a/models/renderhelper/repo_wiki.go b/models/renderhelper/repo_wiki.go
index b75f1b9701..218b1e4a67 100644
--- a/models/renderhelper/repo_wiki.go
+++ b/models/renderhelper/repo_wiki.go
@@ -71,7 +71,7 @@ func NewRenderContextRepoWiki(ctx context.Context, repo *repo_model.Repository,
"markupAllowShortIssuePattern": "true",
})
}
- rctx = rctx.WithHelper(helper)
+ rctx = rctx.WithHelper(helper).WithEnableHeadingIDGeneration(true)
helper.ctx = rctx
return rctx
}
diff --git a/models/repo.go b/models/repo.go
index 522debb9fe..c5c5364da0 100644
--- a/models/repo.go
+++ b/models/repo.go
@@ -7,6 +7,7 @@ package models
import (
"context"
"strconv"
+ "strings"
_ "image/jpeg" // Needed for jpeg support
@@ -86,11 +87,20 @@ func labelStatsCorrectNumClosedIssuesRepo(ctx context.Context, id int64) error {
return err
}
-var milestoneStatsQueryNumIssues = "SELECT `milestone`.id FROM `milestone` WHERE `milestone`.num_closed_issues!=(SELECT COUNT(*) FROM `issue` WHERE `issue`.milestone_id=`milestone`.id AND `issue`.is_closed=?) OR `milestone`.num_issues!=(SELECT COUNT(*) FROM `issue` WHERE `issue`.milestone_id=`milestone`.id)"
+func milestoneStatsQueryNumIssuesSQL() string {
+ sql := `
+SELECT "milestone".id FROM "milestone"
+WHERE (
+ "milestone".num_closed_issues != (SELECT COUNT(*) FROM "issue" WHERE "issue".milestone_id="milestone".id AND "issue".is_closed=?)
+ OR "milestone".num_issues != (SELECT COUNT(*) FROM "issue" WHERE "issue".milestone_id="milestone".id)
+)
+`
+ return strings.TrimSpace(strings.ReplaceAll(sql, "\"", "`"))
+}
func milestoneStatsCorrectNumIssuesRepo(ctx context.Context, id int64) error {
e := db.GetEngine(ctx)
- results, err := e.Query(milestoneStatsQueryNumIssues+" AND `milestone`.repo_id = ?", true, id)
+ results, err := e.Query(milestoneStatsQueryNumIssuesSQL()+" AND `milestone`.repo_id = ?", true, id)
if err != nil {
return err
}
@@ -192,7 +202,7 @@ func CheckRepoStats(ctx context.Context) error {
},
// Milestone.Num{,Closed}Issues
{
- statsQuery(milestoneStatsQueryNumIssues, true),
+ statsQuery(milestoneStatsQueryNumIssuesSQL(), true),
issues_model.UpdateMilestoneCounters,
"milestone count 'num_closed_issues' and 'num_issues'",
},
diff --git a/modules/git/repo_archive_test.go b/models/repo/archive_test.go
similarity index 98%
rename from modules/git/repo_archive_test.go
rename to models/repo/archive_test.go
index ff7e2dfce1..bb6c1bf9bc 100644
--- a/modules/git/repo_archive_test.go
+++ b/models/repo/archive_test.go
@@ -1,7 +1,7 @@
// Copyright 2025 The Gitea Authors. All rights reserved.
// SPDX-License-Identifier: MIT
-package git
+package repo
import (
"testing"
diff --git a/models/repo/archiver.go b/models/repo/archiver.go
index d06e94e5ac..ca981a178c 100644
--- a/models/repo/archiver.go
+++ b/models/repo/archiver.go
@@ -11,7 +11,6 @@ import (
"time"
"code.gitea.io/gitea/models/db"
- "code.gitea.io/gitea/modules/git"
"code.gitea.io/gitea/modules/timeutil"
"code.gitea.io/gitea/modules/util"
@@ -27,11 +26,46 @@ const (
ArchiverReady // it's ready
)
+// ArchiveType archive types
+type ArchiveType int
+
+const (
+ ArchiveUnknown ArchiveType = iota
+ ArchiveZip // 1
+ ArchiveTarGz // 2
+ ArchiveBundle // 3
+)
+
+// String converts an ArchiveType to string: the extension of the archive file without prefix dot
+func (a ArchiveType) String() string {
+ switch a {
+ case ArchiveZip:
+ return "zip"
+ case ArchiveTarGz:
+ return "tar.gz"
+ case ArchiveBundle:
+ return "bundle"
+ }
+ return "unknown"
+}
+
+func SplitArchiveNameType(s string) (string, ArchiveType) {
+ switch {
+ case strings.HasSuffix(s, ".zip"):
+ return strings.TrimSuffix(s, ".zip"), ArchiveZip
+ case strings.HasSuffix(s, ".tar.gz"):
+ return strings.TrimSuffix(s, ".tar.gz"), ArchiveTarGz
+ case strings.HasSuffix(s, ".bundle"):
+ return strings.TrimSuffix(s, ".bundle"), ArchiveBundle
+ }
+ return s, ArchiveUnknown
+}
+
// RepoArchiver represents all archivers
type RepoArchiver struct { //revive:disable-line:exported
- ID int64 `xorm:"pk autoincr"`
- RepoID int64 `xorm:"index unique(s)"`
- Type git.ArchiveType `xorm:"unique(s)"`
+ ID int64 `xorm:"pk autoincr"`
+ RepoID int64 `xorm:"index unique(s)"`
+ Type ArchiveType `xorm:"unique(s)"`
Status ArchiverStatus
CommitID string `xorm:"VARCHAR(64) unique(s)"`
CreatedUnix timeutil.TimeStamp `xorm:"INDEX NOT NULL created"`
@@ -56,15 +90,15 @@ func repoArchiverForRelativePath(relativePath string) (*RepoArchiver, error) {
if err != nil {
return nil, util.NewInvalidArgumentErrorf("invalid storage path: invalid repo id")
}
- commitID, archiveType := git.SplitArchiveNameType(parts[2])
- if archiveType == git.ArchiveUnknown {
+ commitID, archiveType := SplitArchiveNameType(parts[2])
+ if archiveType == ArchiveUnknown {
return nil, util.NewInvalidArgumentErrorf("invalid storage path: invalid archive type")
}
return &RepoArchiver{RepoID: repoID, CommitID: commitID, Type: archiveType}, nil
}
// GetRepoArchiver get an archiver
-func GetRepoArchiver(ctx context.Context, repoID int64, tp git.ArchiveType, commitID string) (*RepoArchiver, error) {
+func GetRepoArchiver(ctx context.Context, repoID int64, tp ArchiveType, commitID string) (*RepoArchiver, error) {
var archiver RepoArchiver
has, err := db.GetEngine(ctx).Where("repo_id=?", repoID).And("`type`=?", tp).And("commit_id=?", commitID).Get(&archiver)
if err != nil {
@@ -73,7 +107,7 @@ func GetRepoArchiver(ctx context.Context, repoID int64, tp git.ArchiveType, comm
if has {
return &archiver, nil
}
- return nil, nil
+ return nil, nil //nolint:nilnil // return nil to indicate that the object does not exist
}
// ExistsRepoArchiverWithStoragePath checks if there is a RepoArchiver for a given storage path
diff --git a/models/repo/attachment.go b/models/repo/attachment.go
index 835bee5402..27856f2d2e 100644
--- a/models/repo/attachment.go
+++ b/models/repo/attachment.go
@@ -166,6 +166,11 @@ func GetAttachmentByReleaseIDFileName(ctx context.Context, releaseID int64, file
return attach, nil
}
+func GetUnlinkedAttachmentsByUserID(ctx context.Context, userID int64) ([]*Attachment, error) {
+ attachments := make([]*Attachment, 0, 10)
+ return attachments, db.GetEngine(ctx).Where("uploader_id = ? AND issue_id = 0 AND release_id = 0 AND comment_id = 0", userID).Find(&attachments)
+}
+
// DeleteAttachment deletes the given attachment and optionally the associated file.
func DeleteAttachment(ctx context.Context, a *Attachment, remove bool) error {
_, err := DeleteAttachments(ctx, []*Attachment{a}, remove)
diff --git a/models/repo/attachment_test.go b/models/repo/attachment_test.go
index d41008344d..07f4c587a7 100644
--- a/models/repo/attachment_test.go
+++ b/models/repo/attachment_test.go
@@ -101,3 +101,19 @@ func TestGetAttachmentsByUUIDs(t *testing.T) {
assert.Equal(t, int64(1), attachList[0].IssueID)
assert.Equal(t, int64(5), attachList[1].IssueID)
}
+
+func TestGetUnlinkedAttachmentsByUserID(t *testing.T) {
+ assert.NoError(t, unittest.PrepareTestDatabase())
+
+ attachments, err := repo_model.GetUnlinkedAttachmentsByUserID(t.Context(), 8)
+ assert.NoError(t, err)
+ assert.Len(t, attachments, 1)
+ assert.Equal(t, int64(10), attachments[0].ID)
+ assert.Zero(t, attachments[0].IssueID)
+ assert.Zero(t, attachments[0].ReleaseID)
+ assert.Zero(t, attachments[0].CommentID)
+
+ attachments, err = repo_model.GetUnlinkedAttachmentsByUserID(t.Context(), 1)
+ assert.NoError(t, err)
+ assert.Empty(t, attachments)
+}
diff --git a/models/repo/avatar.go b/models/repo/avatar.go
index eff64bd239..bfb08d9982 100644
--- a/models/repo/avatar.go
+++ b/models/repo/avatar.go
@@ -41,20 +41,14 @@ func generateRandomAvatar(ctx context.Context, repo *Repository) error {
idToString := strconv.FormatInt(repo.ID, 10)
seed := idToString
- img, err := avatar.RandomImage([]byte(seed))
- if err != nil {
- return fmt.Errorf("RandomImage: %w", err)
- }
+ img := avatar.RandomImageDefaultSize([]byte(seed))
repo.Avatar = idToString
if err := storage.SaveFrom(storage.RepoAvatars, repo.CustomAvatarRelativePath(), func(w io.Writer) error {
- if err := png.Encode(w, img); err != nil {
- log.Error("Encode: %v", err)
- }
- return err
+ return png.Encode(w, img)
}); err != nil {
- return fmt.Errorf("Failed to create dir %s: %w", repo.CustomAvatarRelativePath(), err)
+ return fmt.Errorf("failed to create dir %s: %w", repo.CustomAvatarRelativePath(), err)
}
log.Info("New random avatar created for repository: %d", repo.ID)
diff --git a/models/repo/fork.go b/models/repo/fork.go
index 1c75e86458..80b3e5634e 100644
--- a/models/repo/fork.go
+++ b/models/repo/fork.go
@@ -49,7 +49,7 @@ func GetUserFork(ctx context.Context, repoID, userID int64) (*Repository, error)
return nil, err
}
if !has {
- return nil, nil
+ return nil, nil //nolint:nilnil // return nil to indicate that the object does not exist
}
return &forkedRepo, nil
}
diff --git a/models/repo/pull_request_default.go b/models/repo/pull_request_default.go
new file mode 100644
index 0000000000..89f8eb6a2c
--- /dev/null
+++ b/models/repo/pull_request_default.go
@@ -0,0 +1,16 @@
+// Copyright 2026 The Gitea Authors. All rights reserved.
+// SPDX-License-Identifier: MIT
+
+package repo
+
+import (
+ "context"
+
+ "code.gitea.io/gitea/models/unit"
+ "code.gitea.io/gitea/modules/util"
+)
+
+func (repo *Repository) GetPullRequestTargetBranch(ctx context.Context) string {
+ unitPRConfig := repo.MustGetUnit(ctx, unit.TypePullRequests).PullRequestsConfig()
+ return util.IfZero(unitPRConfig.DefaultTargetBranch, repo.DefaultBranch)
+}
diff --git a/models/repo/pull_request_default_test.go b/models/repo/pull_request_default_test.go
new file mode 100644
index 0000000000..b1653f2f1a
--- /dev/null
+++ b/models/repo/pull_request_default_test.go
@@ -0,0 +1,32 @@
+// Copyright 2026 The Gitea Authors. All rights reserved.
+// SPDX-License-Identifier: MIT
+
+package repo
+
+import (
+ "testing"
+
+ "code.gitea.io/gitea/models/unit"
+ "code.gitea.io/gitea/models/unittest"
+
+ "github.com/stretchr/testify/assert"
+)
+
+func TestDefaultTargetBranchSelection(t *testing.T) {
+ assert.NoError(t, unittest.PrepareTestDatabase())
+
+ ctx := t.Context()
+ repo := unittest.AssertExistsAndLoadBean(t, &Repository{ID: 1})
+
+ assert.Equal(t, repo.DefaultBranch, repo.GetPullRequestTargetBranch(ctx))
+
+ repo.Units = nil
+ prUnit, err := repo.GetUnit(ctx, unit.TypePullRequests)
+ assert.NoError(t, err)
+ prConfig := prUnit.PullRequestsConfig()
+ prConfig.DefaultTargetBranch = "branch2"
+ prUnit.Config = prConfig
+ assert.NoError(t, UpdateRepoUnitConfig(ctx, prUnit))
+ repo.Units = nil
+ assert.Equal(t, "branch2", repo.GetPullRequestTargetBranch(ctx))
+}
diff --git a/models/repo/release.go b/models/repo/release.go
index 67aa390e6d..e2010c8a38 100644
--- a/models/repo/release.go
+++ b/models/repo/release.go
@@ -93,15 +93,25 @@ func init() {
db.RegisterModel(new(Release))
}
+// LegacyAttachmentMissingRepoIDCutoff marks the date when repo_id started to be written during uploads
+// (2026-01-16T00:00:00Z). Older rows might have repo_id=0 and should be tolerated once.
+const LegacyAttachmentMissingRepoIDCutoff timeutil.TimeStamp = 1768521600
+
+func (r *Release) LoadRepo(ctx context.Context) (err error) {
+ if r.Repo != nil {
+ return nil
+ }
+
+ r.Repo, err = GetRepositoryByID(ctx, r.RepoID)
+ return err
+}
+
// LoadAttributes load repo and publisher attributes for a release
-func (r *Release) LoadAttributes(ctx context.Context) error {
- var err error
- if r.Repo == nil {
- r.Repo, err = GetRepositoryByID(ctx, r.RepoID)
- if err != nil {
- return err
- }
+func (r *Release) LoadAttributes(ctx context.Context) (err error) {
+ if err := r.LoadRepo(ctx); err != nil {
+ return err
}
+
if r.Publisher == nil {
r.Publisher, err = user_model.GetUserByID(ctx, r.PublisherID)
if err != nil {
@@ -168,6 +178,11 @@ func UpdateReleaseNumCommits(ctx context.Context, rel *Release) error {
// AddReleaseAttachments adds a release attachments
func AddReleaseAttachments(ctx context.Context, releaseID int64, attachmentUUIDs []string) (err error) {
+ rel, err := GetReleaseByID(ctx, releaseID)
+ if err != nil {
+ return err
+ }
+
// Check attachments
attachments, err := GetAttachmentsByUUIDs(ctx, attachmentUUIDs)
if err != nil {
@@ -175,6 +190,17 @@ func AddReleaseAttachments(ctx context.Context, releaseID int64, attachmentUUIDs
}
for i := range attachments {
+ if attachments[i].RepoID == 0 && attachments[i].CreatedUnix < LegacyAttachmentMissingRepoIDCutoff {
+ attachments[i].RepoID = rel.RepoID
+ if _, err = db.GetEngine(ctx).ID(attachments[i].ID).Cols("repo_id").Update(attachments[i]); err != nil {
+ return fmt.Errorf("update attachment repo_id [%d]: %w", attachments[i].ID, err)
+ }
+ }
+
+ if attachments[i].RepoID != rel.RepoID {
+ return util.NewPermissionDeniedErrorf("attachment belongs to different repository")
+ }
+
if attachments[i].ReleaseID != 0 {
return util.NewPermissionDeniedErrorf("release permission denied")
}
diff --git a/models/repo/release_test.go b/models/repo/release_test.go
index 01f0fb3cff..2a09ffb36d 100644
--- a/models/repo/release_test.go
+++ b/models/repo/release_test.go
@@ -6,7 +6,9 @@ package repo
import (
"testing"
+ "code.gitea.io/gitea/models/db"
"code.gitea.io/gitea/models/unittest"
+ "code.gitea.io/gitea/modules/util"
"github.com/stretchr/testify/assert"
)
@@ -37,3 +39,54 @@ func Test_FindTagsByCommitIDs(t *testing.T) {
assert.Equal(t, "delete-tag", rels[1].TagName)
assert.Equal(t, "v1.0", rels[2].TagName)
}
+
+func TestAddReleaseAttachmentsRejectsDifferentRepo(t *testing.T) {
+ assert.NoError(t, unittest.PrepareTestDatabase())
+
+ uuid := "a0eebc99-9c0b-4ef8-bb6d-6bb9bd380a12" // attachment 2 belongs to repo 2
+ err := AddReleaseAttachments(t.Context(), 1, []string{uuid})
+ assert.Error(t, err)
+ assert.ErrorIs(t, err, util.ErrPermissionDenied)
+
+ attach, err := GetAttachmentByUUID(t.Context(), uuid)
+ assert.NoError(t, err)
+ assert.Zero(t, attach.ReleaseID, "attachment should not be linked to release on failure")
+}
+
+func TestAddReleaseAttachmentsAllowsLegacyMissingRepoID(t *testing.T) {
+ assert.NoError(t, unittest.PrepareTestDatabase())
+
+ legacyUUID := "a0eebc99-9c0b-4ef8-bb6d-6bb9bd380a20" // attachment 10 has repo_id 0
+ err := AddReleaseAttachments(t.Context(), 1, []string{legacyUUID})
+ assert.NoError(t, err)
+
+ attach, err := GetAttachmentByUUID(t.Context(), legacyUUID)
+ assert.NoError(t, err)
+ assert.EqualValues(t, 1, attach.RepoID)
+ assert.EqualValues(t, 1, attach.ReleaseID)
+}
+
+func TestAddReleaseAttachmentsRejectsRecentZeroRepoID(t *testing.T) {
+ assert.NoError(t, unittest.PrepareTestDatabase())
+
+ recentUUID := "a0eebc99-9c0b-4ef8-bb6d-6bb9bd3800aa"
+ attachment := &Attachment{
+ UUID: recentUUID,
+ RepoID: 0,
+ IssueID: 0,
+ ReleaseID: 0,
+ CommentID: 0,
+ Name: "recent-zero",
+ CreatedUnix: LegacyAttachmentMissingRepoIDCutoff + 1,
+ }
+ assert.NoError(t, db.Insert(t.Context(), attachment))
+
+ err := AddReleaseAttachments(t.Context(), 1, []string{recentUUID})
+ assert.Error(t, err)
+ assert.ErrorIs(t, err, util.ErrPermissionDenied)
+
+ attach, err := GetAttachmentByUUID(t.Context(), recentUUID)
+ assert.NoError(t, err)
+ assert.Zero(t, attach.ReleaseID)
+ assert.Zero(t, attach.RepoID)
+}
diff --git a/models/repo/repo.go b/models/repo/repo.go
index 8237a429e5..25207cc28b 100644
--- a/models/repo/repo.go
+++ b/models/repo/repo.go
@@ -229,10 +229,6 @@ func RelativePath(ownerName, repoName string) string {
return strings.ToLower(ownerName) + "/" + strings.ToLower(repoName) + ".git"
}
-func RelativeWikiPath(ownerName, repoName string) string {
- return strings.ToLower(ownerName) + "/" + strings.ToLower(repoName) + ".wiki.git"
-}
-
// RelativePath should be an unix style path like username/reponame.git
func (repo *Repository) RelativePath() string {
return RelativePath(repo.OwnerName, repo.Name)
@@ -245,12 +241,6 @@ func (sr StorageRepo) RelativePath() string {
return string(sr)
}
-// WikiStorageRepo returns the storage repo for the wiki
-// The wiki repository should have the same object format as the code repository
-func (repo *Repository) WikiStorageRepo() StorageRepo {
- return StorageRepo(RelativeWikiPath(repo.OwnerName, repo.Name))
-}
-
// SanitizedOriginalURL returns a sanitized OriginalURL
func (repo *Repository) SanitizedOriginalURL() string {
if repo.OriginalURL == "" {
@@ -291,7 +281,7 @@ func (repo *Repository) SizeDetailsString() string {
var str strings.Builder
sizeDetails := repo.SizeDetails()
for _, detail := range sizeDetails {
- str.WriteString(fmt.Sprintf("%s: %s, ", detail.Name, base.FileSize(detail.Size)))
+ fmt.Fprintf(&str, "%s: %s, ", detail.Name, base.FileSize(detail.Size))
}
return strings.TrimSuffix(str.String(), ", ")
}
@@ -432,52 +422,37 @@ func (repo *Repository) UnitEnabled(ctx context.Context, tp unit.Type) bool {
return false
}
-// MustGetUnit always returns a RepoUnit object
+// MustGetUnit always returns a RepoUnit object even if the unit doesn't exist (not enabled)
func (repo *Repository) MustGetUnit(ctx context.Context, tp unit.Type) *RepoUnit {
ru, err := repo.GetUnit(ctx, tp)
if err == nil {
return ru
}
-
+ if !errors.Is(err, util.ErrNotExist) {
+ setting.PanicInDevOrTesting("Failed to get unit %v for repository %d: %v", tp, repo.ID, err)
+ }
+ ru = &RepoUnit{RepoID: repo.ID, Type: tp}
switch tp {
case unit.TypeExternalWiki:
- return &RepoUnit{
- Type: tp,
- Config: new(ExternalWikiConfig),
- }
+ ru.Config = new(ExternalWikiConfig)
case unit.TypeExternalTracker:
- return &RepoUnit{
- Type: tp,
- Config: new(ExternalTrackerConfig),
- }
+ ru.Config = new(ExternalTrackerConfig)
case unit.TypePullRequests:
- return &RepoUnit{
- Type: tp,
- Config: new(PullRequestsConfig),
- }
+ ru.Config = new(PullRequestsConfig)
case unit.TypeIssues:
- return &RepoUnit{
- Type: tp,
- Config: new(IssuesConfig),
- }
+ ru.Config = new(IssuesConfig)
case unit.TypeActions:
- return &RepoUnit{
- Type: tp,
- Config: new(ActionsConfig),
- }
+ ru.Config = new(ActionsConfig)
case unit.TypeProjects:
- cfg := new(ProjectsConfig)
- cfg.ProjectsMode = ProjectsModeNone
- return &RepoUnit{
- Type: tp,
- Config: cfg,
- }
+ ru.Config = new(ProjectsConfig)
+ default: // other units don't have config
}
-
- return &RepoUnit{
- Type: tp,
- Config: new(UnitConfig),
+ if ru.Config != nil {
+ if err = ru.Config.FromDB(nil); err != nil {
+ setting.PanicInDevOrTesting("Failed to load default config for unit %v of repository %d: %v", tp, repo.ID, err)
+ }
}
+ return ru
}
// GetUnit returns a RepoUnit object
@@ -605,7 +580,7 @@ func (repo *Repository) IsGenerated() bool {
// RepoPath returns repository path by given user and repository name.
func RepoPath(userName, repoName string) string { //revive:disable-line:exported
- return filepath.Join(user_model.UserPath(userName), strings.ToLower(repoName)+".git")
+ return filepath.Join(setting.RepoRootPath, filepath.Clean(strings.ToLower(userName)), filepath.Clean(strings.ToLower(repoName)+".git"))
}
// RepoPath returns the repository path
@@ -623,16 +598,13 @@ func (repo *Repository) ComposeCompareURL(oldCommitID, newCommitID string) strin
return fmt.Sprintf("%s/%s/compare/%s...%s", url.PathEscape(repo.OwnerName), url.PathEscape(repo.Name), util.PathEscapeSegments(oldCommitID), util.PathEscapeSegments(newCommitID))
}
-func (repo *Repository) ComposeBranchCompareURL(baseRepo *Repository, branchName string) string {
- if baseRepo == nil {
- baseRepo = repo
- }
+func (repo *Repository) ComposeBranchCompareURL(baseRepo *Repository, baseBranch, branchName string) string {
var cmpBranchEscaped string
if repo.ID != baseRepo.ID {
cmpBranchEscaped = fmt.Sprintf("%s/%s:", url.PathEscape(repo.OwnerName), url.PathEscape(repo.Name))
}
cmpBranchEscaped = fmt.Sprintf("%s%s", cmpBranchEscaped, util.PathEscapeSegments(branchName))
- return fmt.Sprintf("%s/compare/%s...%s", baseRepo.Link(), util.PathEscapeSegments(baseRepo.DefaultBranch), cmpBranchEscaped)
+ return fmt.Sprintf("%s/compare/%s...%s", baseRepo.Link(), util.PathEscapeSegments(baseBranch), cmpBranchEscaped)
}
// IsOwnedBy returns true when user owns this repository
@@ -879,16 +851,6 @@ func GetRepositoriesMapByIDs(ctx context.Context, ids []int64) (map[int64]*Repos
return repos, db.GetEngine(ctx).In("id", ids).Find(&repos)
}
-// IsRepositoryModelOrDirExist returns true if the repository with given name under user has already existed.
-func IsRepositoryModelOrDirExist(ctx context.Context, u *user_model.User, repoName string) (bool, error) {
- has, err := IsRepositoryModelExist(ctx, u, repoName)
- if err != nil {
- return false, err
- }
- isDir, err := util.IsDir(RepoPath(u.Name, repoName))
- return has || isDir, err
-}
-
func IsRepositoryModelExist(ctx context.Context, u *user_model.User, repoName string) (bool, error) {
return db.GetEngine(ctx).Get(&Repository{
OwnerID: u.ID,
@@ -901,7 +863,7 @@ func IsRepositoryModelExist(ctx context.Context, u *user_model.User, repoName st
// non-generated repositories, and TemplateRepo will be left untouched)
func GetTemplateRepo(ctx context.Context, repo *Repository) (*Repository, error) {
if !repo.IsGenerated() {
- return nil, nil
+ return nil, nil //nolint:nilnil // return nil for non-generated repositories
}
return GetRepositoryByID(ctx, repo.TemplateID)
diff --git a/models/repo/repo_list.go b/models/repo/repo_list.go
index 811f83c999..25dee1bf0e 100644
--- a/models/repo/repo_list.go
+++ b/models/repo/repo_list.go
@@ -212,6 +212,13 @@ type SearchRepoOptions struct {
OnlyShowRelevant bool
}
+func (opts *SearchRepoOptions) ApplyPublicOnly(publicOnly bool) {
+ if publicOnly {
+ opts.Private = false
+ opts.AllLimited = false
+ }
+}
+
// UserOwnedRepoCond returns user ownered repositories
func UserOwnedRepoCond(userID int64) builder.Cond {
return builder.Eq{
@@ -778,3 +785,11 @@ func GetUserRepositories(ctx context.Context, opts SearchRepoOptions) (Repositor
repos := make(RepositoryList, 0, opts.PageSize)
return repos, count, db.SetSessionPagination(sess, &opts).Find(&repos)
}
+
+func GetOwnerRepositoriesByIDs(ctx context.Context, ownerID int64, repoIDs []int64) (RepositoryList, error) {
+ if len(repoIDs) == 0 {
+ return RepositoryList{}, nil
+ }
+ repos := make(RepositoryList, 0, len(repoIDs))
+ return repos, db.GetEngine(ctx).Where(builder.Eq{"owner_id": ownerID}).In("id", repoIDs).Find(&repos)
+}
diff --git a/models/repo/repo_unit.go b/models/repo/repo_unit.go
index a5207bc22a..c32adbbcd4 100644
--- a/models/repo/repo_unit.go
+++ b/models/repo/repo_unit.go
@@ -5,8 +5,6 @@ package repo
import (
"context"
- "slices"
- "strings"
"code.gitea.io/gitea/models/db"
"code.gitea.io/gitea/models/perm"
@@ -131,12 +129,29 @@ type PullRequestsConfig struct {
DefaultDeleteBranchAfterMerge bool
DefaultMergeStyle MergeStyle
DefaultAllowMaintainerEdit bool
+ DefaultTargetBranch string
+}
+
+func DefaultPullRequestsConfig() *PullRequestsConfig {
+ cfg := &PullRequestsConfig{
+ AllowMerge: true,
+ AllowRebase: true,
+ AllowRebaseMerge: true,
+ AllowSquash: true,
+ AllowFastForwardOnly: true,
+ AllowRebaseUpdate: true,
+ DefaultAllowMaintainerEdit: true,
+ }
+ cfg.DefaultDeleteBranchAfterMerge = setting.Repository.PullRequest.DefaultDeleteBranchAfterMerge
+ cfg.DefaultMergeStyle = MergeStyle(setting.Repository.PullRequest.DefaultMergeStyle)
+ cfg.DefaultMergeStyle = util.IfZero(cfg.DefaultMergeStyle, MergeStyleMerge)
+ return cfg
}
// FromDB fills up a PullRequestsConfig from serialized format.
func (cfg *PullRequestsConfig) FromDB(bs []byte) error {
- // AllowRebaseUpdate = true as default for existing PullRequestConfig in DB
- cfg.AllowRebaseUpdate = true
+ // set default values for existing PullRequestConfig in DB
+ *cfg = *DefaultPullRequestsConfig()
return json.UnmarshalHandleDoubleEncode(bs, &cfg)
}
@@ -155,51 +170,8 @@ func (cfg *PullRequestsConfig) IsMergeStyleAllowed(mergeStyle MergeStyle) bool {
mergeStyle == MergeStyleManuallyMerged && cfg.AllowManualMerge
}
-// GetDefaultMergeStyle returns the default merge style for this pull request
-func (cfg *PullRequestsConfig) GetDefaultMergeStyle() MergeStyle {
- if len(cfg.DefaultMergeStyle) != 0 {
- return cfg.DefaultMergeStyle
- }
-
- if setting.Repository.PullRequest.DefaultMergeStyle != "" {
- return MergeStyle(setting.Repository.PullRequest.DefaultMergeStyle)
- }
-
- return MergeStyleMerge
-}
-
-type ActionsConfig struct {
- DisabledWorkflows []string
-}
-
-func (cfg *ActionsConfig) EnableWorkflow(file string) {
- cfg.DisabledWorkflows = util.SliceRemoveAll(cfg.DisabledWorkflows, file)
-}
-
-func (cfg *ActionsConfig) ToString() string {
- return strings.Join(cfg.DisabledWorkflows, ",")
-}
-
-func (cfg *ActionsConfig) IsWorkflowDisabled(file string) bool {
- return slices.Contains(cfg.DisabledWorkflows, file)
-}
-
-func (cfg *ActionsConfig) DisableWorkflow(file string) {
- if slices.Contains(cfg.DisabledWorkflows, file) {
- return
- }
-
- cfg.DisabledWorkflows = append(cfg.DisabledWorkflows, file)
-}
-
-// FromDB fills up a ActionsConfig from serialized format.
-func (cfg *ActionsConfig) FromDB(bs []byte) error {
- return json.UnmarshalHandleDoubleEncode(bs, &cfg)
-}
-
-// ToDB exports a ActionsConfig to a serialized format.
-func (cfg *ActionsConfig) ToDB() ([]byte, error) {
- return json.Marshal(cfg)
+func DefaultPullRequestsUnit(repoID int64) RepoUnit {
+ return RepoUnit{RepoID: repoID, Type: unit.TypePullRequests, Config: DefaultPullRequestsConfig()}
}
// ProjectsMode represents the projects enabled for a repository
@@ -223,6 +195,8 @@ type ProjectsConfig struct {
// FromDB fills up a ProjectsConfig from serialized format.
func (cfg *ProjectsConfig) FromDB(bs []byte) error {
+ // TODO: remove GetProjectsMode, only use ProjectsMode
+ cfg.ProjectsMode = ProjectsModeAll
return json.UnmarshalHandleDoubleEncode(bs, &cfg)
}
@@ -253,7 +227,12 @@ func (cfg *ProjectsConfig) IsProjectsAllowed(m ProjectsMode) bool {
func (r *RepoUnit) BeforeSet(colName string, val xorm.Cell) {
switch colName {
case "type":
- switch unit.Type(db.Cell2Int64(val)) {
+ var err error
+ r.Type, _, err = db.CellToInt(val, unit.TypeInvalid)
+ if err != nil {
+ setting.PanicInDevOrTesting("Unable to convert repo unit (id=%d) type: %v", r.ID, err)
+ }
+ switch r.Type {
case unit.TypeExternalWiki:
r.Config = new(ExternalWikiConfig)
case unit.TypeExternalTracker:
@@ -271,6 +250,11 @@ func (r *RepoUnit) BeforeSet(colName string, val xorm.Cell) {
default:
r.Config = new(UnitConfig)
}
+ case "config":
+ if *val == nil {
+ // XROM doesn't call FromDB if the value is nil, but we need to set default values for the config fields
+ _ = r.Config.FromDB(nil)
+ }
}
}
@@ -334,9 +318,9 @@ func getUnitsByRepoID(ctx context.Context, repoID int64) (units []*RepoUnit, err
return units, nil
}
-// UpdateRepoUnit updates the provided repo unit
-func UpdateRepoUnit(ctx context.Context, unit *RepoUnit) error {
- _, err := db.GetEngine(ctx).ID(unit.ID).Update(unit)
+// UpdateRepoUnitConfig updates the config of the provided repo unit
+func UpdateRepoUnitConfig(ctx context.Context, unit *RepoUnit) error {
+ _, err := db.GetEngine(ctx).ID(unit.ID).Cols("config").Update(unit)
return err
}
diff --git a/models/repo/repo_unit_actions.go b/models/repo/repo_unit_actions.go
new file mode 100644
index 0000000000..50e2925792
--- /dev/null
+++ b/models/repo/repo_unit_actions.go
@@ -0,0 +1,153 @@
+// Copyright 2026 The Gitea Authors. All rights reserved.
+// SPDX-License-Identifier: MIT
+
+package repo
+
+import (
+ "slices"
+
+ "code.gitea.io/gitea/models/perm"
+ "code.gitea.io/gitea/models/unit"
+ "code.gitea.io/gitea/modules/json"
+ "code.gitea.io/gitea/modules/util"
+)
+
+// ActionsTokenPermissionMode defines the default permission mode for Actions tokens
+type ActionsTokenPermissionMode string
+
+const (
+ // ActionsTokenPermissionModePermissive - write access by default (current behavior, backwards compatible)
+ ActionsTokenPermissionModePermissive ActionsTokenPermissionMode = "permissive"
+ // ActionsTokenPermissionModeRestricted - read access by default
+ ActionsTokenPermissionModeRestricted ActionsTokenPermissionMode = "restricted"
+)
+
+func (ActionsTokenPermissionMode) EnumValues() []ActionsTokenPermissionMode {
+ return []ActionsTokenPermissionMode{ActionsTokenPermissionModePermissive /* default */, ActionsTokenPermissionModeRestricted}
+}
+
+// ActionsTokenPermissions defines the permissions for different repository units
+type ActionsTokenPermissions struct {
+ UnitAccessModes map[unit.Type]perm.AccessMode `json:"unit_access_modes,omitempty"`
+}
+
+var ActionsTokenUnitTypes = []unit.Type{
+ unit.TypeCode,
+ unit.TypeIssues,
+ unit.TypePullRequests,
+ unit.TypePackages,
+ unit.TypeActions,
+ unit.TypeWiki,
+ unit.TypeReleases,
+ unit.TypeProjects,
+}
+
+func MakeActionsTokenPermissions(unitAccessMode perm.AccessMode) (ret ActionsTokenPermissions) {
+ ret.UnitAccessModes = make(map[unit.Type]perm.AccessMode)
+ for _, u := range ActionsTokenUnitTypes {
+ ret.UnitAccessModes[u] = unitAccessMode
+ }
+ return ret
+}
+
+// ClampActionsTokenPermissions ensures that the given permissions don't exceed the maximum
+func ClampActionsTokenPermissions(p1, p2 ActionsTokenPermissions) (ret ActionsTokenPermissions) {
+ ret.UnitAccessModes = make(map[unit.Type]perm.AccessMode)
+ for _, ut := range ActionsTokenUnitTypes {
+ ret.UnitAccessModes[ut] = min(p1.UnitAccessModes[ut], p2.UnitAccessModes[ut])
+ }
+ return ret
+}
+
+// MakeRestrictedPermissions returns the restricted permissions
+func MakeRestrictedPermissions() ActionsTokenPermissions {
+ ret := MakeActionsTokenPermissions(perm.AccessModeNone)
+ ret.UnitAccessModes[unit.TypeCode] = perm.AccessModeRead
+ ret.UnitAccessModes[unit.TypePackages] = perm.AccessModeRead
+ ret.UnitAccessModes[unit.TypeReleases] = perm.AccessModeRead
+ return ret
+}
+
+type ActionsConfig struct {
+ DisabledWorkflows []string
+ // CollaborativeOwnerIDs is a list of owner IDs used to share actions from private repos.
+ // Only workflows from the private repos whose owners are in CollaborativeOwnerIDs can access the current repo's actions.
+ CollaborativeOwnerIDs []int64
+ // TokenPermissionMode defines the default permission mode (permissive, restricted, or custom)
+ TokenPermissionMode ActionsTokenPermissionMode `json:"token_permission_mode,omitempty"`
+ // MaxTokenPermissions defines the absolute maximum permissions any token can have in this context.
+ // Workflow YAML "permissions" keywords can reduce permissions but never exceed this ceiling.
+ MaxTokenPermissions *ActionsTokenPermissions `json:"max_token_permissions,omitempty"`
+ // OverrideOwnerConfig indicates if this repository should override the owner-level configuration (User or Org)
+ OverrideOwnerConfig bool `json:"override_owner_config,omitempty"`
+}
+
+func (cfg *ActionsConfig) EnableWorkflow(file string) {
+ cfg.DisabledWorkflows = util.SliceRemoveAll(cfg.DisabledWorkflows, file)
+}
+
+func (cfg *ActionsConfig) IsWorkflowDisabled(file string) bool {
+ return slices.Contains(cfg.DisabledWorkflows, file)
+}
+
+func (cfg *ActionsConfig) DisableWorkflow(file string) {
+ if slices.Contains(cfg.DisabledWorkflows, file) {
+ return
+ }
+
+ cfg.DisabledWorkflows = append(cfg.DisabledWorkflows, file)
+}
+
+func (cfg *ActionsConfig) AddCollaborativeOwner(ownerID int64) {
+ if !slices.Contains(cfg.CollaborativeOwnerIDs, ownerID) {
+ cfg.CollaborativeOwnerIDs = append(cfg.CollaborativeOwnerIDs, ownerID)
+ }
+}
+
+func (cfg *ActionsConfig) RemoveCollaborativeOwner(ownerID int64) {
+ cfg.CollaborativeOwnerIDs = util.SliceRemoveAll(cfg.CollaborativeOwnerIDs, ownerID)
+}
+
+func (cfg *ActionsConfig) IsCollaborativeOwner(ownerID int64) bool {
+ return slices.Contains(cfg.CollaborativeOwnerIDs, ownerID)
+}
+
+// GetDefaultTokenPermissions returns the default token permissions by its TokenPermissionMode.
+// It does not apply MaxTokenPermissions; callers must clamp if needed.
+func (cfg *ActionsConfig) GetDefaultTokenPermissions() ActionsTokenPermissions {
+ switch cfg.TokenPermissionMode {
+ case ActionsTokenPermissionModeRestricted:
+ return MakeRestrictedPermissions()
+ case ActionsTokenPermissionModePermissive:
+ return MakeActionsTokenPermissions(perm.AccessModeWrite)
+ default:
+ return ActionsTokenPermissions{}
+ }
+}
+
+// GetMaxTokenPermissions returns the maximum allowed permissions
+func (cfg *ActionsConfig) GetMaxTokenPermissions() ActionsTokenPermissions {
+ if cfg.MaxTokenPermissions != nil {
+ return *cfg.MaxTokenPermissions
+ }
+ // Default max is write for everything
+ return MakeActionsTokenPermissions(perm.AccessModeWrite)
+}
+
+// ClampPermissions ensures that the given permissions don't exceed the maximum
+func (cfg *ActionsConfig) ClampPermissions(perms ActionsTokenPermissions) ActionsTokenPermissions {
+ maxPerms := cfg.GetMaxTokenPermissions()
+ return ClampActionsTokenPermissions(perms, maxPerms)
+}
+
+// FromDB fills up a ActionsConfig from serialized format.
+func (cfg *ActionsConfig) FromDB(bs []byte) error {
+ _ = json.UnmarshalHandleDoubleEncode(bs, &cfg)
+ cfg.TokenPermissionMode, _ = util.EnumValue(cfg.TokenPermissionMode)
+ return nil
+}
+
+// ToDB exports a ActionsConfig to a serialized format.
+func (cfg *ActionsConfig) ToDB() ([]byte, error) {
+ return json.Marshal(cfg)
+}
diff --git a/models/repo/repo_unit_test.go b/models/repo/repo_unit_test.go
index 56dda5672d..08f9ac2cd4 100644
--- a/models/repo/repo_unit_test.go
+++ b/models/repo/repo_unit_test.go
@@ -4,8 +4,12 @@
package repo
import (
+ "strings"
"testing"
+ "code.gitea.io/gitea/models/perm"
+ "code.gitea.io/gitea/models/unit"
+
"github.com/stretchr/testify/assert"
)
@@ -26,5 +30,75 @@ func TestActionsConfig(t *testing.T) {
cfg.DisableWorkflow("test1.yaml")
cfg.DisableWorkflow("test2.yaml")
cfg.DisableWorkflow("test3.yaml")
- assert.Equal(t, "test1.yaml,test2.yaml,test3.yaml", cfg.ToString())
+ assert.Equal(t, "test1.yaml,test2.yaml,test3.yaml", strings.Join(cfg.DisabledWorkflows, ","))
+}
+
+func TestActionsConfigTokenPermissions(t *testing.T) {
+ t.Run("Default Permission Mode", func(t *testing.T) {
+ cfg := &ActionsConfig{TokenPermissionMode: "invalid-value"}
+ _ = cfg.FromDB(nil)
+ assert.Equal(t, ActionsTokenPermissionModePermissive, cfg.TokenPermissionMode)
+ assert.Equal(t, perm.AccessModeWrite, cfg.GetDefaultTokenPermissions().UnitAccessModes[unit.TypeCode])
+ })
+
+ t.Run("Explicit Permission Mode", func(t *testing.T) {
+ cfg := &ActionsConfig{
+ TokenPermissionMode: ActionsTokenPermissionModeRestricted,
+ }
+ assert.Equal(t, ActionsTokenPermissionModeRestricted, cfg.TokenPermissionMode)
+ })
+
+ t.Run("Effective Permissions - Permissive Mode", func(t *testing.T) {
+ cfg := &ActionsConfig{
+ TokenPermissionMode: ActionsTokenPermissionModePermissive,
+ }
+ defaultPerms := cfg.GetDefaultTokenPermissions()
+ perms := cfg.ClampPermissions(defaultPerms)
+ assert.Equal(t, perm.AccessModeWrite, perms.UnitAccessModes[unit.TypeCode])
+ assert.Equal(t, perm.AccessModeWrite, perms.UnitAccessModes[unit.TypeIssues])
+ assert.Equal(t, perm.AccessModeWrite, perms.UnitAccessModes[unit.TypePackages])
+ })
+
+ t.Run("Effective Permissions - Restricted Mode", func(t *testing.T) {
+ cfg := &ActionsConfig{
+ TokenPermissionMode: ActionsTokenPermissionModeRestricted,
+ }
+ defaultPerms := cfg.GetDefaultTokenPermissions()
+ perms := cfg.ClampPermissions(defaultPerms)
+ assert.Equal(t, perm.AccessModeRead, perms.UnitAccessModes[unit.TypeCode])
+ assert.Equal(t, perm.AccessModeNone, perms.UnitAccessModes[unit.TypeIssues])
+ assert.Equal(t, perm.AccessModeRead, perms.UnitAccessModes[unit.TypePackages])
+ })
+
+ t.Run("Clamp Permissions", func(t *testing.T) {
+ cfg := &ActionsConfig{
+ MaxTokenPermissions: &ActionsTokenPermissions{
+ UnitAccessModes: map[unit.Type]perm.AccessMode{
+ unit.TypeCode: perm.AccessModeRead,
+ unit.TypeIssues: perm.AccessModeWrite,
+ unit.TypePullRequests: perm.AccessModeRead,
+ unit.TypePackages: perm.AccessModeRead,
+ unit.TypeActions: perm.AccessModeNone,
+ unit.TypeWiki: perm.AccessModeWrite,
+ },
+ },
+ }
+ input := ActionsTokenPermissions{
+ UnitAccessModes: map[unit.Type]perm.AccessMode{
+ unit.TypeCode: perm.AccessModeWrite, // Should be clamped to Read
+ unit.TypeIssues: perm.AccessModeWrite, // Should stay Write
+ unit.TypePullRequests: perm.AccessModeWrite, // Should be clamped to Read
+ unit.TypePackages: perm.AccessModeWrite, // Should be clamped to Read
+ unit.TypeActions: perm.AccessModeRead, // Should be clamped to None
+ unit.TypeWiki: perm.AccessModeRead, // Should stay Read
+ },
+ }
+ clamped := cfg.ClampPermissions(input)
+ assert.Equal(t, perm.AccessModeRead, clamped.UnitAccessModes[unit.TypeCode])
+ assert.Equal(t, perm.AccessModeWrite, clamped.UnitAccessModes[unit.TypeIssues])
+ assert.Equal(t, perm.AccessModeRead, clamped.UnitAccessModes[unit.TypePullRequests])
+ assert.Equal(t, perm.AccessModeRead, clamped.UnitAccessModes[unit.TypePackages])
+ assert.Equal(t, perm.AccessModeNone, clamped.UnitAccessModes[unit.TypeActions])
+ assert.Equal(t, perm.AccessModeRead, clamped.UnitAccessModes[unit.TypeWiki])
+ })
}
diff --git a/models/repo/topic.go b/models/repo/topic.go
index f8f706fc1a..6d5209d821 100644
--- a/models/repo/topic.go
+++ b/models/repo/topic.go
@@ -257,7 +257,7 @@ func DeleteTopic(ctx context.Context, repoID int64, topicName string) (*Topic, e
}
if topic == nil {
// Repo doesn't have topic, can't be removed
- return nil, nil
+ return nil, nil //nolint:nilnil // return nil to indicate that the topic does not exist
}
return db.WithTx2(ctx, func(ctx context.Context) (*Topic, error) {
diff --git a/models/repo/update.go b/models/repo/update.go
index 3228ae11a4..bf560cf695 100644
--- a/models/repo/update.go
+++ b/models/repo/update.go
@@ -9,8 +9,6 @@ import (
"time"
"code.gitea.io/gitea/models/db"
- user_model "code.gitea.io/gitea/models/user"
- "code.gitea.io/gitea/modules/log"
"code.gitea.io/gitea/modules/util"
)
@@ -106,35 +104,6 @@ func (err ErrRepoFilesAlreadyExist) Unwrap() error {
return util.ErrAlreadyExist
}
-// CheckCreateRepository check if doer could create a repository in new owner
-func CheckCreateRepository(ctx context.Context, doer, owner *user_model.User, name string, overwriteOrAdopt bool) error {
- if !doer.CanCreateRepoIn(owner) {
- return ErrReachLimitOfRepo{owner.MaxRepoCreation}
- }
-
- if err := IsUsableRepoName(name); err != nil {
- return err
- }
-
- has, err := IsRepositoryModelOrDirExist(ctx, owner, name)
- if err != nil {
- return fmt.Errorf("IsRepositoryExist: %w", err)
- } else if has {
- return ErrRepoAlreadyExist{owner.Name, name}
- }
-
- repoPath := RepoPath(owner.Name, name)
- isExist, err := util.IsExist(repoPath)
- if err != nil {
- log.Error("Unable to check if %s exists. Error: %v", repoPath, err)
- return err
- }
- if !overwriteOrAdopt && isExist {
- return ErrRepoFilesAlreadyExist{owner.Name, name}
- }
- return nil
-}
-
// UpdateRepoSize updates the repository size, calculating it using getDirectorySize
func UpdateRepoSize(ctx context.Context, repoID, gitSize, lfsSize int64) error {
_, err := db.GetEngine(ctx).ID(repoID).Cols("size", "git_size", "lfs_size").NoAutoTime().Update(&Repository{
diff --git a/models/repo/user_repo.go b/models/repo/user_repo.go
index 232087d865..e4b0a1b067 100644
--- a/models/repo/user_repo.go
+++ b/models/repo/user_repo.go
@@ -8,6 +8,7 @@ import (
"strings"
"code.gitea.io/gitea/models/db"
+ "code.gitea.io/gitea/models/organization"
"code.gitea.io/gitea/models/perm"
"code.gitea.io/gitea/models/unit"
user_model "code.gitea.io/gitea/models/user"
@@ -23,6 +24,12 @@ type StarredReposOptions struct {
IncludePrivate bool
}
+func (opts *StarredReposOptions) ApplyPublicOnly(publicOnly bool) {
+ if publicOnly {
+ opts.IncludePrivate = false
+ }
+}
+
func (opts *StarredReposOptions) ToConds() builder.Cond {
var cond builder.Cond = builder.Eq{
"star.uid": opts.StarrerID,
@@ -61,6 +68,12 @@ type WatchedReposOptions struct {
IncludePrivate bool
}
+func (opts *WatchedReposOptions) ApplyPublicOnly(publicOnly bool) {
+ if publicOnly {
+ opts.IncludePrivate = false
+ }
+}
+
func (opts *WatchedReposOptions) ToConds() builder.Cond {
var cond builder.Cond = builder.Eq{
"watch.user_id": opts.WatcherID,
@@ -94,8 +107,7 @@ func GetWatchedRepos(ctx context.Context, opts *WatchedReposOptions) ([]*Reposit
return db.FindAndCount[Repository](ctx, opts)
}
-// GetRepoAssignees returns all users that have write access and can be assigned to issues
-// of the repository,
+// GetRepoAssignees returns all users that have write access and can be assigned to issues or pull-requests of the repository,
func GetRepoAssignees(ctx context.Context, repo *Repository) (_ []*user_model.User, err error) {
if err = repo.LoadOwner(ctx); err != nil {
return nil, err
@@ -114,15 +126,9 @@ func GetRepoAssignees(ctx context.Context, repo *Repository) (_ []*user_model.Us
uniqueUserIDs.AddMultiple(userIDs...)
if repo.Owner.IsOrganization() {
- additionalUserIDs := make([]int64, 0, 10)
- if err = e.Table("team_user").
- Join("INNER", "team_repo", "`team_repo`.team_id = `team_user`.team_id").
- Join("INNER", "team_unit", "`team_unit`.team_id = `team_user`.team_id").
- Where("`team_repo`.repo_id = ? AND (`team_unit`.access_mode >= ? OR (`team_unit`.access_mode = ? AND `team_unit`.`type` = ?))",
- repo.ID, perm.AccessModeWrite, perm.AccessModeRead, unit.TypePullRequests).
- Distinct("`team_user`.uid").
- Select("`team_user`.uid").
- Find(&additionalUserIDs); err != nil {
+ // issues and pull requests both need "assignee list"
+ additionalUserIDs, err := organization.GetTeamUserIDsWithAccessToAnyRepoUnit(ctx, repo.OwnerID, repo.ID, perm.AccessModeRead, unit.TypeIssues, unit.TypePullRequests)
+ if err != nil {
return nil, err
}
uniqueUserIDs.AddMultiple(additionalUserIDs...)
@@ -147,19 +153,21 @@ func GetRepoAssignees(ctx context.Context, repo *Repository) (_ []*user_model.Us
}
// GetIssuePostersWithSearch returns users with limit of 30 whose username started with prefix that have authored an issue/pull request for the given repository
-// If isShowFullName is set to true, also include full name prefix search
-func GetIssuePostersWithSearch(ctx context.Context, repo *Repository, isPull bool, search string, isShowFullName bool) ([]*user_model.User, error) {
+// It searches with the "user.name" and "user.full_name" fields case-insensitively.
+func GetIssuePostersWithSearch(ctx context.Context, repo *Repository, isPull bool, search string) ([]*user_model.User, error) {
users := make([]*user_model.User, 0, 30)
- var prefixCond builder.Cond = builder.Like{"lower_name", strings.ToLower(search) + "%"}
- if isShowFullName {
- prefixCond = prefixCond.Or(db.BuildCaseInsensitiveLike("full_name", "%"+search+"%"))
- }
cond := builder.In("`user`.id",
builder.Select("poster_id").From("issue").Where(
builder.Eq{"repo_id": repo.ID}.
And(builder.Eq{"is_pull": isPull}),
- ).GroupBy("poster_id")).And(prefixCond)
+ ).GroupBy("poster_id"))
+
+ if search != "" {
+ var prefixCond builder.Cond = builder.Like{"lower_name", strings.ToLower(search) + "%"}
+ prefixCond = prefixCond.Or(db.BuildCaseInsensitiveLike("full_name", "%"+search+"%"))
+ cond = cond.And(prefixCond)
+ }
return users, db.GetEngine(ctx).
Where(cond).
diff --git a/models/repo/user_repo_test.go b/models/repo/user_repo_test.go
index a53cf39dc4..cd45db61d0 100644
--- a/models/repo/user_repo_test.go
+++ b/models/repo/user_repo_test.go
@@ -6,7 +6,12 @@ package repo_test
import (
"testing"
+ "code.gitea.io/gitea/models/db"
+ "code.gitea.io/gitea/models/organization"
+ perm_model "code.gitea.io/gitea/models/perm"
+ access_model "code.gitea.io/gitea/models/perm/access"
repo_model "code.gitea.io/gitea/models/repo"
+ "code.gitea.io/gitea/models/unit"
"code.gitea.io/gitea/models/unittest"
user_model "code.gitea.io/gitea/models/user"
@@ -14,9 +19,14 @@ import (
"github.com/stretchr/testify/require"
)
-func TestRepoAssignees(t *testing.T) {
- assert.NoError(t, unittest.PrepareTestDatabase())
+func TestUserRepo(t *testing.T) {
+ require.NoError(t, unittest.PrepareTestDatabase())
+ t.Run("GetIssuePostersWithSearch", testUserRepoGetIssuePostersWithSearch)
+ t.Run("Assignees", testUserRepoAssignees)
+ t.Run("AssigneesNoTeamUnit", testRepoAssigneesNoTeamUnit)
+}
+func testUserRepoAssignees(t *testing.T) {
repo2 := unittest.AssertExistsAndLoadBean(t, &repo_model.Repository{ID: 2})
users, err := repo_model.GetRepoAssignees(t.Context(), repo2)
assert.NoError(t, err)
@@ -39,17 +49,37 @@ func TestRepoAssignees(t *testing.T) {
}
}
-func TestGetIssuePostersWithSearch(t *testing.T) {
- assert.NoError(t, unittest.PrepareTestDatabase())
+func testRepoAssigneesNoTeamUnit(t *testing.T) {
+ ctx := t.Context()
+
+ repo := unittest.AssertExistsAndLoadBean(t, &repo_model.Repository{ID: 32})
+ require.NoError(t, repo.LoadOwner(ctx))
+ require.True(t, repo.Owner.IsOrganization())
+
+ require.NoError(t, db.TruncateBeans(ctx, &organization.Team{}, &organization.TeamUser{}, &organization.TeamRepo{}, &organization.TeamUnit{}, &access_model.Access{}))
+
+ user := unittest.AssertExistsAndLoadBean(t, &user_model.User{ID: 4})
+ team := &organization.Team{OrgID: repo.OwnerID, LowerName: "admin-team", AccessMode: perm_model.AccessModeAdmin}
+ require.NoError(t, db.Insert(ctx, team))
+ require.NoError(t, db.Insert(ctx, &organization.TeamUser{OrgID: repo.OwnerID, TeamID: team.ID, UID: user.ID}))
+ require.NoError(t, db.Insert(ctx, &organization.TeamRepo{OrgID: repo.OwnerID, TeamID: team.ID, RepoID: repo.ID}))
+ require.NoError(t, db.Insert(ctx, &organization.TeamUnit{OrgID: repo.OwnerID, TeamID: team.ID, Type: unit.TypePullRequests, AccessMode: perm_model.AccessModeNone}))
+
+ users, err := repo_model.GetRepoAssignees(ctx, repo)
+ require.NoError(t, err)
+ require.Len(t, users, 1)
+ assert.ElementsMatch(t, []int64{4}, []int64{users[0].ID})
+}
+func testUserRepoGetIssuePostersWithSearch(t *testing.T) {
repo2 := unittest.AssertExistsAndLoadBean(t, &repo_model.Repository{ID: 2})
- users, err := repo_model.GetIssuePostersWithSearch(t.Context(), repo2, false, "USER", false /* full name */)
+ users, err := repo_model.GetIssuePostersWithSearch(t.Context(), repo2, false, "USER")
require.NoError(t, err)
require.Len(t, users, 1)
assert.Equal(t, "user2", users[0].Name)
- users, err = repo_model.GetIssuePostersWithSearch(t.Context(), repo2, false, "TW%O", true /* full name */)
+ users, err = repo_model.GetIssuePostersWithSearch(t.Context(), repo2, false, "TW%O")
require.NoError(t, err)
require.Len(t, users, 1)
assert.Equal(t, "user2", users[0].Name)
diff --git a/models/repo/watch.go b/models/repo/watch.go
index a616544cae..1e63d5c3d2 100644
--- a/models/repo/watch.go
+++ b/models/repo/watch.go
@@ -176,3 +176,13 @@ func WatchIfAuto(ctx context.Context, userID, repoID int64, isWrite bool) error
}
return watchRepoMode(ctx, watch, WatchModeAuto)
}
+
+// ClearRepoWatches clears all watches for a repository and from the user that watched it.
+// Used when a repository is set to private.
+func ClearRepoWatches(ctx context.Context, repoID int64) error {
+ if _, err := db.Exec(ctx, "UPDATE `repository` SET num_watches = 0 WHERE id = ?", repoID); err != nil {
+ return err
+ }
+
+ return db.DeleteBeans(ctx, Watch{RepoID: repoID})
+}
diff --git a/models/repo/watch_test.go b/models/repo/watch_test.go
index 19e363f6b0..97576fb787 100644
--- a/models/repo/watch_test.go
+++ b/models/repo/watch_test.go
@@ -13,6 +13,7 @@ import (
"code.gitea.io/gitea/modules/setting"
"github.com/stretchr/testify/assert"
+ "github.com/stretchr/testify/require"
)
func TestIsWatching(t *testing.T) {
@@ -119,3 +120,21 @@ func TestWatchIfAuto(t *testing.T) {
assert.NoError(t, err)
assert.Len(t, watchers, prevCount)
}
+
+func TestClearRepoWatches(t *testing.T) {
+ assert.NoError(t, unittest.PrepareTestDatabase())
+
+ const repoID int64 = 1
+ watchers, err := repo_model.GetRepoWatchersIDs(t.Context(), repoID)
+ require.NoError(t, err)
+ require.NotEmpty(t, watchers)
+
+ assert.NoError(t, repo_model.ClearRepoWatches(t.Context(), repoID))
+
+ watchers, err = repo_model.GetRepoWatchersIDs(t.Context(), repoID)
+ assert.NoError(t, err)
+ assert.Empty(t, watchers)
+
+ repo := unittest.AssertExistsAndLoadBean(t, &repo_model.Repository{ID: repoID})
+ assert.Zero(t, repo.NumWatches)
+}
diff --git a/models/repo/wiki.go b/models/repo/wiki.go
index 9f41445bf8..47c8fa43ab 100644
--- a/models/repo/wiki.go
+++ b/models/repo/wiki.go
@@ -7,7 +7,6 @@ package repo
import (
"context"
"fmt"
- "path/filepath"
"strings"
user_model "code.gitea.io/gitea/models/user"
@@ -76,12 +75,12 @@ func (repo *Repository) WikiCloneLink(ctx context.Context, doer *user_model.User
return repo.cloneLink(ctx, doer, repo.Name+".wiki")
}
-// WikiPath returns wiki data path by given user and repository name.
-func WikiPath(userName, repoName string) string {
- return filepath.Join(user_model.UserPath(userName), strings.ToLower(repoName)+".wiki.git")
+func RelativeWikiPath(ownerName, repoName string) string {
+ return strings.ToLower(ownerName) + "/" + strings.ToLower(repoName) + ".wiki.git"
}
-// WikiPath returns wiki data path for given repository.
-func (repo *Repository) WikiPath() string {
- return WikiPath(repo.OwnerName, repo.Name)
+// WikiStorageRepo returns the storage repo for the wiki
+// The wiki repository should have the same object format as the code repository
+func (repo *Repository) WikiStorageRepo() StorageRepo {
+ return StorageRepo(RelativeWikiPath(repo.OwnerName, repo.Name))
}
diff --git a/models/repo/wiki_test.go b/models/repo/wiki_test.go
index 41e53d93d9..636c78009b 100644
--- a/models/repo/wiki_test.go
+++ b/models/repo/wiki_test.go
@@ -4,12 +4,10 @@
package repo_test
import (
- "path/filepath"
"testing"
repo_model "code.gitea.io/gitea/models/repo"
"code.gitea.io/gitea/models/unittest"
- "code.gitea.io/gitea/modules/setting"
"github.com/stretchr/testify/assert"
)
@@ -23,15 +21,10 @@ func TestRepository_WikiCloneLink(t *testing.T) {
assert.Equal(t, "https://try.gitea.io/user2/repo1.wiki.git", cloneLink.HTTPS)
}
-func TestWikiPath(t *testing.T) {
+func TestRepository_RelativeWikiPath(t *testing.T) {
assert.NoError(t, unittest.PrepareTestDatabase())
- expected := filepath.Join(setting.RepoRootPath, "user2/repo1.wiki.git")
- assert.Equal(t, expected, repo_model.WikiPath("user2", "repo1"))
-}
-func TestRepository_WikiPath(t *testing.T) {
- assert.NoError(t, unittest.PrepareTestDatabase())
repo := unittest.AssertExistsAndLoadBean(t, &repo_model.Repository{ID: 1})
- expected := filepath.Join(setting.RepoRootPath, "user2/repo1.wiki.git")
- assert.Equal(t, expected, repo.WikiPath())
+ assert.Equal(t, "user2/repo1.wiki.git", repo_model.RelativeWikiPath(repo.OwnerName, repo.Name))
+ assert.Equal(t, "user2/repo1.wiki.git", repo.WikiStorageRepo().RelativePath())
}
diff --git a/models/unittest/fixtures_loader.go b/models/unittest/fixtures_loader.go
index d92b0cdb14..5b79cb5643 100644
--- a/models/unittest/fixtures_loader.go
+++ b/models/unittest/fixtures_loader.go
@@ -169,7 +169,7 @@ func (f *fixturesLoaderInternal) Load() error {
func FixturesFileFullPaths(dir string, files []string) (map[string]*FixtureItem, error) {
if files != nil && len(files) == 0 {
- return nil, nil // load nothing
+ return nil, nil //nolint:nilnil // load nothing
}
files = slices.Clone(files)
if len(files) == 0 {
diff --git a/models/unittest/fixtures_test.go b/models/unittest/fixtures_test.go
index 8a4c5f1793..72944ec0db 100644
--- a/models/unittest/fixtures_test.go
+++ b/models/unittest/fixtures_test.go
@@ -4,19 +4,20 @@
package unittest_test
import (
+ "os"
"path/filepath"
"testing"
"code.gitea.io/gitea/models/unittest"
user_model "code.gitea.io/gitea/models/user"
- "code.gitea.io/gitea/modules/test"
+ "code.gitea.io/gitea/modules/setting"
"github.com/stretchr/testify/require"
"xorm.io/xorm"
)
var NewFixturesLoaderVendor = func(e *xorm.Engine, opts unittest.FixturesOptions) (unittest.FixturesLoader, error) {
- return nil, nil
+ return nil, nil //nolint:nilnil // no vendor fixtures loader configured
}
/*
@@ -58,9 +59,15 @@ func NewFixturesLoaderVendorGoTestfixtures(e *xorm.Engine, opts unittest.Fixture
}
*/
+func TestMain(m *testing.M) {
+ setting.SetupGiteaTestEnv()
+ os.Exit(m.Run())
+}
+
func prepareTestFixturesLoaders(t testing.TB) unittest.FixturesOptions {
_ = user_model.User{}
- opts := unittest.FixturesOptions{Dir: filepath.Join(test.SetupGiteaRoot(), "models", "fixtures"), Files: []string{
+ giteaRoot := setting.GetGiteaTestSourceRoot()
+ opts := unittest.FixturesOptions{Dir: filepath.Join(giteaRoot, "models", "fixtures"), Files: []string{
"user.yml",
}}
require.NoError(t, unittest.CreateTestEngine(opts))
diff --git a/models/unittest/fscopy.go b/models/unittest/fscopy.go
index 98b01815bd..cddb7a3f77 100644
--- a/models/unittest/fscopy.go
+++ b/models/unittest/fscopy.go
@@ -4,10 +4,12 @@
package unittest
import (
+ "errors"
"os"
"path/filepath"
"strings"
+ "code.gitea.io/gitea/modules/setting"
"code.gitea.io/gitea/modules/util"
)
@@ -39,7 +41,20 @@ func SyncFile(srcPath, destPath string) error {
// SyncDirs synchronizes files recursively from source to target directory.
// It returns error when error occurs in underlying functions.
func SyncDirs(srcPath, destPath string) error {
- err := os.MkdirAll(destPath, os.ModePerm)
+ destPath = filepath.Clean(destPath)
+ destPathAbs, err := filepath.Abs(destPath)
+ if err != nil {
+ return err
+ }
+ devDataPathAbs, err := filepath.Abs(filepath.Join(setting.GetGiteaTestSourceRoot(), "data"))
+ if err != nil {
+ return err
+ }
+ if strings.HasPrefix(destPathAbs+string(filepath.Separator), devDataPathAbs+string(filepath.Separator)) {
+ return errors.New("destination path should not be inside Gitea data directory, otherwise your data for dev mode will be removed")
+ }
+
+ err = os.MkdirAll(destPath, os.ModePerm)
if err != nil {
return err
}
diff --git a/models/unittest/testdb.go b/models/unittest/testdb.go
index 4611a079ec..63c9a3a999 100644
--- a/models/unittest/testdb.go
+++ b/models/unittest/testdb.go
@@ -21,7 +21,7 @@ import (
"code.gitea.io/gitea/modules/setting/config"
"code.gitea.io/gitea/modules/storage"
"code.gitea.io/gitea/modules/tempdir"
- "code.gitea.io/gitea/modules/test"
+ "code.gitea.io/gitea/modules/testlogger"
"code.gitea.io/gitea/modules/util"
"github.com/stretchr/testify/assert"
@@ -29,16 +29,10 @@ import (
"xorm.io/xorm/names"
)
-var giteaRoot string
-
-func fatalTestError(fmtStr string, args ...any) {
- _, _ = fmt.Fprintf(os.Stderr, fmtStr, args...)
- os.Exit(1)
-}
-
// InitSettingsForTesting initializes config provider and load common settings for tests
func InitSettingsForTesting() {
- setting.IsInTesting = true
+ setting.SetupGiteaTestEnv()
+
log.OsExiter = func(code int) {
if code != 0 {
// non-zero exit code (log.Fatal) shouldn't occur during testing, if it happens, show a full stacktrace for more details
@@ -50,8 +44,12 @@ func InitSettingsForTesting() {
setting.CustomConf = filepath.Join(setting.CustomPath, "conf/app-unittest-tmp.ini")
_ = os.Remove(setting.CustomConf)
}
- setting.InitCfgProvider(setting.CustomConf)
- setting.LoadCommonSettings()
+
+ // init paths and config system for testing
+ getTestEnv := func(key string) string {
+ return ""
+ }
+ setting.InitWorkPathAndCommonConfig(getTestEnv, setting.ArgWorkPathAndCustomConf{CustomConf: setting.CustomConf})
if err := setting.PrepareAppDataPath(); err != nil {
log.Fatal("Can not prepare APP_DATA_PATH: %v", err)
@@ -60,7 +58,6 @@ func InitSettingsForTesting() {
_ = hash.Register("dummy", hash.NewDummyHasher)
setting.PasswordHashAlgo, _ = hash.SetDefaultPasswordHashAlgorithm("dummy")
- setting.InitGiteaEnvVarsForTesting()
}
// TestOptions represents test options
@@ -73,17 +70,18 @@ type TestOptions struct {
// MainTest a reusable TestMain(..) function for unit tests that need to use a
// test database. Creates the test database, and sets necessary settings.
func MainTest(m *testing.M, testOptsArg ...*TestOptions) {
+ os.Exit(mainTest(m, testOptsArg...))
+}
+
+func mainTest(m *testing.M, testOptsArg ...*TestOptions) int {
testOpts := util.OptionalArg(testOptsArg, &TestOptions{})
- giteaRoot = test.SetupGiteaRoot()
- setting.CustomPath = filepath.Join(giteaRoot, "custom")
InitSettingsForTesting()
-
+ giteaRoot := setting.GetGiteaTestSourceRoot()
fixturesOpts := FixturesOptions{Dir: filepath.Join(giteaRoot, "models", "fixtures"), Files: testOpts.FixtureFiles}
if err := CreateTestEngine(fixturesOpts); err != nil {
- fatalTestError("Error creating test engine: %v\n", err)
+ testlogger.Panicf("Error creating test engine: %v\n", err)
}
- setting.IsInTesting = true
setting.AppURL = "https://try.gitea.io/"
setting.Domain = "try.gitea.io"
setting.RunUser = "runuser"
@@ -95,20 +93,18 @@ func MainTest(m *testing.M, testOptsArg ...*TestOptions) {
setting.Repository.DefaultBranch = "master" // many test code still assume that default branch is called "master"
repoRootPath, cleanup1, err := tempdir.OsTempDir("gitea-test").MkdirTempRandom("repos")
if err != nil {
- fatalTestError("TempDir: %v\n", err)
+ testlogger.Panicf("TempDir: %v\n", err)
}
defer cleanup1()
setting.RepoRootPath = repoRootPath
appDataPath, cleanup2, err := tempdir.OsTempDir("gitea-test").MkdirTempRandom("appdata")
if err != nil {
- fatalTestError("TempDir: %v\n", err)
+ testlogger.Panicf("TempDir: %v\n", err)
}
defer cleanup2()
setting.AppDataPath = appDataPath
- setting.AppWorkPath = giteaRoot
- setting.StaticRootPath = giteaRoot
setting.GravatarSource = "https://secure.gravatar.com/avatar/"
setting.Attachment.Storage.Path = filepath.Join(setting.AppDataPath, "attachments")
@@ -132,22 +128,22 @@ func MainTest(m *testing.M, testOptsArg ...*TestOptions) {
config.SetDynGetter(system.NewDatabaseDynKeyGetter())
if err = cache.Init(); err != nil {
- fatalTestError("cache.Init: %v\n", err)
+ testlogger.Panicf("cache.Init: %v\n", err)
}
if err = storage.Init(); err != nil {
- fatalTestError("storage.Init: %v\n", err)
+ testlogger.Panicf("storage.Init: %v\n", err)
}
if err = SyncDirs(filepath.Join(giteaRoot, "tests", "gitea-repositories-meta"), setting.RepoRootPath); err != nil {
- fatalTestError("util.SyncDirs: %v\n", err)
+ testlogger.Panicf("util.SyncDirs: %v\n", err)
}
if err = git.InitFull(); err != nil {
- fatalTestError("git.Init: %v\n", err)
+ testlogger.Panicf("git.Init: %v\n", err)
}
if testOpts.SetUp != nil {
if err := testOpts.SetUp(); err != nil {
- fatalTestError("set up failed: %v\n", err)
+ testlogger.Panicf("set up failed: %v\n", err)
}
}
@@ -155,10 +151,10 @@ func MainTest(m *testing.M, testOptsArg ...*TestOptions) {
if testOpts.TearDown != nil {
if err := testOpts.TearDown(); err != nil {
- fatalTestError("tear down failed: %v\n", err)
+ testlogger.Panicf("tear down failed: %v\n", err)
}
}
- os.Exit(exitStatus)
+ return exitStatus
}
// FixturesOptions fixtures needs to be loaded options
@@ -172,7 +168,7 @@ func CreateTestEngine(opts FixturesOptions) error {
x, err := xorm.NewEngine("sqlite3", "file::memory:?cache=shared&_txlock=immediate")
if err != nil {
if strings.Contains(err.Error(), "unknown driver") {
- return fmt.Errorf(`sqlite3 requires: -tags sqlite,sqlite_unlock_notify%s%w`, "\n", err)
+ return fmt.Errorf("sqlite3 requires: -tags sqlite,sqlite_unlock_notify\n%w", err)
}
return err
}
@@ -182,7 +178,7 @@ func CreateTestEngine(opts FixturesOptions) error {
if err = db.SyncAllTables(); err != nil {
return err
}
- switch os.Getenv("GITEA_UNIT_TESTS_LOG_SQL") {
+ switch os.Getenv("GITEA_TEST_LOG_SQL") {
case "true", "1":
x.ShowSQL(true)
}
@@ -199,7 +195,6 @@ func PrepareTestDatabase() error {
// by tests that use the above MainTest(..) function.
func PrepareTestEnv(t testing.TB) {
assert.NoError(t, PrepareTestDatabase())
- metaPath := filepath.Join(giteaRoot, "tests", "gitea-repositories-meta")
+ metaPath := filepath.Join(setting.GetGiteaTestSourceRoot(), "tests", "gitea-repositories-meta")
assert.NoError(t, SyncDirs(metaPath, setting.RepoRootPath))
- test.SetupGiteaRoot() // Makes sure GITEA_ROOT is set
}
diff --git a/models/user/avatar.go b/models/user/avatar.go
index 542bd93b98..5811d85911 100644
--- a/models/user/avatar.go
+++ b/models/user/avatar.go
@@ -30,22 +30,16 @@ func GenerateRandomAvatar(ctx context.Context, u *User) error {
seed = u.Name
}
- img, err := avatar.RandomImage([]byte(seed))
- if err != nil {
- return fmt.Errorf("RandomImage: %w", err)
- }
+ img := avatar.RandomImageDefaultSize([]byte(seed))
u.Avatar = avatars.HashEmail(seed)
- _, err = storage.Avatars.Stat(u.CustomAvatarRelativePath())
+ _, err := storage.Avatars.Stat(u.CustomAvatarRelativePath())
if err != nil {
// If unable to Stat the avatar file (usually it means non-existing), then try to save a new one
// Don't share the images so that we can delete them easily
if err := storage.SaveFrom(storage.Avatars, u.CustomAvatarRelativePath(), func(w io.Writer) error {
- if err := png.Encode(w, img); err != nil {
- log.Error("Encode: %v", err)
- }
- return nil
+ return png.Encode(w, img)
}); err != nil {
return fmt.Errorf("failed to save avatar %s: %w", u.CustomAvatarRelativePath(), err)
}
@@ -74,7 +68,7 @@ func (u *User) AvatarLinkWithSize(ctx context.Context, size int) string {
switch {
case u.UseCustomAvatar:
useLocalAvatar = true
- case disableGravatar, setting.OfflineMode:
+ case disableGravatar:
useLocalAvatar = true
autoGenerateAvatar = true
}
diff --git a/models/user/badge.go b/models/user/badge.go
index e475ceb748..a2a5bc38cc 100644
--- a/models/user/badge.go
+++ b/models/user/badge.go
@@ -5,9 +5,12 @@ package user
import (
"context"
- "fmt"
"code.gitea.io/gitea/models/db"
+ "code.gitea.io/gitea/modules/util"
+
+ "xorm.io/builder"
+ "xorm.io/xorm/schemas"
)
// Badge represents a user badge
@@ -22,7 +25,16 @@ type Badge struct {
type UserBadge struct { //nolint:revive // export stutter
ID int64 `xorm:"pk autoincr"`
BadgeID int64
- UserID int64 `xorm:"INDEX"`
+ UserID int64
+}
+
+// TableIndices implements xorm's TableIndices interface
+func (n *UserBadge) TableIndices() []*schemas.Index {
+ indices := make([]*schemas.Index, 0, 1)
+ ubUnique := schemas.NewIndex("unique_user_badge", schemas.UniqueType)
+ ubUnique.AddColumn("user_id", "badge_id")
+ indices = append(indices, ubUnique)
+ return indices
}
func init() {
@@ -42,32 +54,85 @@ func GetUserBadges(ctx context.Context, u *User) ([]*Badge, int64, error) {
return badges, count, err
}
+// GetBadgeUsersOptions contains options for getting users with a specific badge
+type GetBadgeUsersOptions struct {
+ db.ListOptions
+ BadgeSlug string
+}
+
+// GetBadgeUsers returns the users that have a specific badge with pagination support.
+func GetBadgeUsers(ctx context.Context, opts *GetBadgeUsersOptions) ([]*User, int64, error) {
+ sess := db.GetEngine(ctx).
+ Select("`user`.*").
+ Join("INNER", "user_badge", "`user_badge`.user_id=`user`.id").
+ Join("INNER", "badge", "`user_badge`.badge_id=badge.id").
+ Where("badge.slug=?", opts.BadgeSlug)
+
+ if opts.Page > 0 {
+ sess = db.SetSessionPagination(sess, opts)
+ }
+
+ users := make([]*User, 0, opts.PageSize)
+ count, err := sess.FindAndCount(&users)
+ return users, count, err
+}
+
// CreateBadge creates a new badge.
func CreateBadge(ctx context.Context, badge *Badge) error {
- _, err := db.GetEngine(ctx).Insert(badge)
- return err
+ exists, err := db.GetEngine(ctx).Where("slug = ?", badge.Slug).Exist(new(Badge))
+ if err != nil {
+ return err
+ }
+ if exists {
+ return util.NewAlreadyExistErrorf("badge already exists [slug: %s]", badge.Slug)
+ }
+
+ if _, err := db.GetEngine(ctx).Insert(badge); err != nil {
+ // Handle race between existence check and insert.
+ exists, existErr := db.GetEngine(ctx).Where("slug = ?", badge.Slug).Exist(new(Badge))
+ if existErr == nil && exists {
+ return util.NewAlreadyExistErrorf("badge already exists [slug: %s]", badge.Slug)
+ }
+ return err
+ }
+ return nil
}
-// GetBadge returns a badge
+// GetBadge returns a specific badge
func GetBadge(ctx context.Context, slug string) (*Badge, error) {
badge := new(Badge)
has, err := db.GetEngine(ctx).Where("slug=?", slug).Get(badge)
- if !has {
+ if err != nil {
return nil, err
}
- return badge, err
+ if !has {
+ return nil, util.NewNotExistErrorf("badge does not exist [slug: %s]", slug)
+ }
+ return badge, nil
}
// UpdateBadge updates a badge based on its slug.
func UpdateBadge(ctx context.Context, badge *Badge) error {
- _, err := db.GetEngine(ctx).Where("slug=?", badge.Slug).Update(badge)
+ _, err := db.GetEngine(ctx).Where("slug=?", badge.Slug).Cols("description", "image_url").Update(badge)
return err
}
-// DeleteBadge deletes a badge.
+// DeleteBadge deletes a badge and all associated user_badge entries.
func DeleteBadge(ctx context.Context, badge *Badge) error {
- _, err := db.GetEngine(ctx).Where("slug=?", badge.Slug).Delete(badge)
- return err
+ return db.WithTx(ctx, func(ctx context.Context) error {
+ // First delete all user_badge entries for this badge
+ if _, err := db.GetEngine(ctx).
+ Where("badge_id = ?", badge.ID).
+ Delete(&UserBadge{}); err != nil {
+ return err
+ }
+
+ // Then delete the badge itself
+ if _, err := db.GetEngine(ctx).Where("slug=?", badge.Slug).Delete(badge); err != nil {
+ return err
+ }
+ return nil
+ })
}
// AddUserBadge adds a badge to a user.
@@ -84,12 +149,25 @@ func AddUserBadges(ctx context.Context, u *User, badges []*Badge) error {
if err != nil {
return err
} else if !has {
- return fmt.Errorf("badge with slug %s doesn't exist", badge.Slug)
+ return util.NewNotExistErrorf("badge does not exist [slug: %s]", badge.Slug)
+ }
+
+ exists, err := db.GetEngine(ctx).Where("badge_id = ? AND user_id = ?", badge.ID, u.ID).Exist(new(UserBadge))
+ if err != nil {
+ return err
+ }
+ if exists {
+ return util.NewAlreadyExistErrorf("user badge already exists [user_id: %d, badge_id: %d]", u.ID, badge.ID)
}
+
if err := db.Insert(ctx, &UserBadge{
BadgeID: badge.ID,
UserID: u.ID,
}); err != nil {
+ exists, existErr := db.GetEngine(ctx).Where("badge_id = ? AND user_id = ?", badge.ID, u.ID).Exist(new(UserBadge))
+ if existErr == nil && exists {
+ return util.NewAlreadyExistErrorf("user badge already exists [user_id: %d, badge_id: %d]", u.ID, badge.ID)
+ }
return err
}
}
@@ -102,16 +180,33 @@ func RemoveUserBadge(ctx context.Context, u *User, badge *Badge) error {
return RemoveUserBadges(ctx, u, []*Badge{badge})
}
-// RemoveUserBadges removes badges from a user.
+// RemoveUserBadges removes specific badges from a user.
func RemoveUserBadges(ctx context.Context, u *User, badges []*Badge) error {
return db.WithTx(ctx, func(ctx context.Context) error {
+ if len(badges) == 0 {
+ return nil
+ }
+
+ badgeSlugs := make([]string, 0, len(badges))
for _, badge := range badges {
- if _, err := db.GetEngine(ctx).
- Join("INNER", "badge", "badge.id = `user_badge`.badge_id").
- Where("`user_badge`.user_id=? AND `badge`.slug=?", u.ID, badge.Slug).
- Delete(&UserBadge{}); err != nil {
- return err
- }
+ badgeSlugs = append(badgeSlugs, badge.Slug)
+ }
+ var userBadges []UserBadge
+ if err := db.GetEngine(ctx).Table("user_badge").
+ Join("INNER", "badge", "badge.id = `user_badge`.badge_id").
+ Where("`user_badge`.user_id = ?", u.ID).In("`badge`.slug", badgeSlugs).
+ Find(&userBadges); err != nil {
+ return err
+ }
+ userBadgeIDs := make([]int64, 0, len(userBadges))
+ for _, ub := range userBadges {
+ userBadgeIDs = append(userBadgeIDs, ub.ID)
+ }
+ if len(userBadgeIDs) == 0 {
+ return nil
+ }
+ if _, err := db.GetEngine(ctx).Table("user_badge").In("id", userBadgeIDs).Delete(); err != nil {
+ return err
}
return nil
})
@@ -122,3 +217,57 @@ func RemoveAllUserBadges(ctx context.Context, u *User) error {
_, err := db.GetEngine(ctx).Where("user_id=?", u.ID).Delete(&UserBadge{})
return err
}
+
+// SearchBadgeOptions represents the options when finding badges
+type SearchBadgeOptions struct {
+ db.ListOptions
+
+ Keyword string
+ Slug string
+ ID int64
+ OrderBy db.SearchOrderBy
+}
+
+func (opts *SearchBadgeOptions) ToConds() builder.Cond {
+ cond := builder.NewCond()
+
+ if opts.Keyword != "" {
+ keywordCond := builder.Or(
+ db.BuildCaseInsensitiveLike("badge.slug", opts.Keyword),
+ db.BuildCaseInsensitiveLike("badge.description", opts.Keyword),
+ )
+ cond = cond.And(keywordCond)
+ }
+
+ if opts.ID > 0 {
+ cond = cond.And(builder.Eq{"badge.id": opts.ID})
+ }
+
+ if len(opts.Slug) > 0 {
+ cond = cond.And(builder.Eq{"badge.slug": opts.Slug})
+ }
+
+ return cond
+}
+
+func (opts *SearchBadgeOptions) ToOrders() string {
+ return opts.OrderBy.String()
+}
+
+// SearchBadges returns badges based on the provided SearchBadgeOptions options
+func SearchBadges(ctx context.Context, opts *SearchBadgeOptions) ([]*Badge, int64, error) {
+ return db.FindAndCount[Badge](ctx, opts)
+}
+
+// GetBadgeByID returns a specific badge by ID
+func GetBadgeByID(ctx context.Context, id int64) (*Badge, error) {
+ badge := new(Badge)
+ has, err := db.GetEngine(ctx).ID(id).Get(badge)
+ if err != nil {
+ return nil, err
+ }
+ if !has {
+ return nil, util.NewNotExistErrorf("badge does not exist [id: %d]", id)
+ }
+ return badge, nil
+}
diff --git a/models/user/badge_test.go b/models/user/badge_test.go
new file mode 100644
index 0000000000..04979a9caf
--- /dev/null
+++ b/models/user/badge_test.go
@@ -0,0 +1,185 @@
+// Copyright 2026 The Gitea Authors. All rights reserved.
+// SPDX-License-Identifier: MIT
+
+package user_test
+
+import (
+ "testing"
+
+ "code.gitea.io/gitea/models/db"
+ "code.gitea.io/gitea/models/unittest"
+ user_model "code.gitea.io/gitea/models/user"
+ "code.gitea.io/gitea/modules/util"
+
+ "github.com/stretchr/testify/assert"
+)
+
+func TestBadge(t *testing.T) {
+ assert.NoError(t, unittest.PrepareTestDatabase())
+
+ t.Run("GetBadgeNotExist", testGetBadgeNotExist)
+ t.Run("CreateBadgeAlreadyExists", testCreateBadgeAlreadyExists)
+ t.Run("GetBadgeUsers", testGetBadgeUsers)
+ t.Run("AddAndRemoveUserBadges", testAddAndRemoveUserBadges)
+ t.Run("SearchBadgesOrderingAndKeyword", testSearchBadgesOrderingAndKeyword)
+}
+
+func testGetBadgeNotExist(t *testing.T) {
+ badge, err := user_model.GetBadge(t.Context(), "does-not-exist")
+ assert.Nil(t, badge)
+ assert.Error(t, err)
+ assert.ErrorIs(t, err, util.ErrNotExist)
+}
+
+func testCreateBadgeAlreadyExists(t *testing.T) {
+ badge := &user_model.Badge{
+ Slug: "duplicate-badge-slug",
+ Description: "First",
+ }
+ assert.NoError(t, user_model.CreateBadge(t.Context(), badge))
+
+ err := user_model.CreateBadge(t.Context(), &user_model.Badge{
+ Slug: "duplicate-badge-slug",
+ Description: "Second",
+ })
+ assert.Error(t, err)
+ assert.ErrorIs(t, err, util.ErrAlreadyExist)
+}
+
+func testGetBadgeUsers(t *testing.T) {
+ // Create a test badge
+ badge := &user_model.Badge{
+ Slug: "test-badge-users",
+ Description: "Test Badge",
+ ImageURL: "test.png",
+ }
+ assert.NoError(t, user_model.CreateBadge(t.Context(), badge))
+
+ // Create test users and assign badges
+ user1 := unittest.AssertExistsAndLoadBean(t, &user_model.User{ID: 1})
+ user2 := unittest.AssertExistsAndLoadBean(t, &user_model.User{ID: 2})
+
+ assert.NoError(t, user_model.AddUserBadge(t.Context(), user1, badge))
+ assert.NoError(t, user_model.AddUserBadge(t.Context(), user2, badge))
+ defer func() {
+ assert.NoError(t, user_model.RemoveUserBadge(t.Context(), user1, badge))
+ assert.NoError(t, user_model.RemoveUserBadge(t.Context(), user2, badge))
+ }()
+
+ // Test getting users with pagination
+ opts := &user_model.GetBadgeUsersOptions{
+ BadgeSlug: badge.Slug,
+ ListOptions: db.ListOptions{
+ Page: 1,
+ PageSize: 1,
+ },
+ }
+
+ users, count, err := user_model.GetBadgeUsers(t.Context(), opts)
+ assert.NoError(t, err)
+ assert.EqualValues(t, 2, count)
+ assert.Len(t, users, 1)
+
+ // Test second page
+ opts.Page = 2
+ users, count, err = user_model.GetBadgeUsers(t.Context(), opts)
+ assert.NoError(t, err)
+ assert.EqualValues(t, 2, count)
+ assert.Len(t, users, 1)
+
+ // Test with non-existent badge
+ opts.BadgeSlug = "non-existent"
+ users, count, err = user_model.GetBadgeUsers(t.Context(), opts)
+ assert.NoError(t, err)
+ assert.EqualValues(t, 0, count)
+ assert.Empty(t, users)
+}
+
+func testAddAndRemoveUserBadges(t *testing.T) {
+ badge1 := unittest.AssertExistsAndLoadBean(t, &user_model.Badge{ID: 1})
+ user1 := unittest.AssertExistsAndLoadBean(t, &user_model.User{ID: 1})
+
+ // Add a badge to user and verify that it is returned in the list
+ assert.NoError(t, user_model.AddUserBadge(t.Context(), user1, badge1))
+ badges, count, err := user_model.GetUserBadges(t.Context(), user1)
+ assert.Equal(t, int64(1), count)
+ assert.Equal(t, badge1.Slug, badges[0].Slug)
+ assert.NoError(t, err)
+
+ // Confirm that it is impossible to duplicate the same badge
+ err = user_model.AddUserBadge(t.Context(), user1, badge1)
+ assert.Error(t, err)
+ assert.ErrorIs(t, err, util.ErrAlreadyExist)
+
+ // Nothing happened to the existing badge
+ badges, count, err = user_model.GetUserBadges(t.Context(), user1)
+ assert.Equal(t, int64(1), count)
+ assert.Equal(t, badge1.Slug, badges[0].Slug)
+ assert.NoError(t, err)
+
+ // Remove a badge from user and verify that it is no longer in the list
+ assert.NoError(t, user_model.RemoveUserBadge(t.Context(), user1, badge1))
+ _, count, err = user_model.GetUserBadges(t.Context(), user1)
+ assert.Equal(t, int64(0), count)
+ assert.NoError(t, err)
+
+ // Removing empty or missing badge selections should be a no-op.
+ assert.NoError(t, user_model.RemoveUserBadges(t.Context(), user1, nil))
+ assert.NoError(t, user_model.RemoveUserBadges(t.Context(), user1, []*user_model.Badge{{Slug: "does-not-exist"}}))
+}
+
+func testSearchBadgesOrderingAndKeyword(t *testing.T) {
+ createdBadges := []*user_model.Badge{
+ {Slug: "badge-sort-b", Description: "Badge Sort B"},
+ {Slug: "badge-sort-c", Description: "Badge Sort C"},
+ {Slug: "badge-sort-a", Description: "Badge Sort A"},
+ {Slug: "badge-sort-case", Description: "MiXeDCaSeKeyword"},
+ }
+ for _, badge := range createdBadges {
+ assert.NoError(t, user_model.CreateBadge(t.Context(), badge))
+ }
+
+ opts := &user_model.SearchBadgeOptions{
+ ListOptions: db.ListOptions{ListAll: true},
+ Keyword: "badge-sort-",
+ OrderBy: db.SearchOrderBy("`badge`.id ASC"),
+ }
+
+ oldestFirst, count, err := user_model.SearchBadges(t.Context(), opts)
+ assert.NoError(t, err)
+ assert.EqualValues(t, 4, count)
+ assert.Equal(t, []string{"badge-sort-b", "badge-sort-c", "badge-sort-a", "badge-sort-case"}, collectBadgeSlugs(oldestFirst))
+
+ opts.OrderBy = db.SearchOrderBy("`badge`.id DESC")
+ newestFirst, count, err := user_model.SearchBadges(t.Context(), opts)
+ assert.NoError(t, err)
+ assert.EqualValues(t, 4, count)
+ assert.Equal(t, []string{"badge-sort-case", "badge-sort-a", "badge-sort-c", "badge-sort-b"}, collectBadgeSlugs(newestFirst))
+
+ opts.OrderBy = db.SearchOrderBy("`badge`.slug ASC")
+ alpha, count, err := user_model.SearchBadges(t.Context(), opts)
+ assert.NoError(t, err)
+ assert.EqualValues(t, 4, count)
+ assert.Equal(t, []string{"badge-sort-a", "badge-sort-b", "badge-sort-c", "badge-sort-case"}, collectBadgeSlugs(alpha))
+
+ opts.OrderBy = db.SearchOrderBy("`badge`.slug DESC")
+ reverseAlpha, count, err := user_model.SearchBadges(t.Context(), opts)
+ assert.NoError(t, err)
+ assert.EqualValues(t, 4, count)
+ assert.Equal(t, []string{"badge-sort-case", "badge-sort-c", "badge-sort-b", "badge-sort-a"}, collectBadgeSlugs(reverseAlpha))
+
+ opts.Keyword = "mixedcasekeyword"
+ opts.OrderBy = db.SearchOrderBy("`badge`.slug ASC")
+ caseInsensitive, count, err := user_model.SearchBadges(t.Context(), opts)
+ assert.NoError(t, err)
+ assert.EqualValues(t, 1, count)
+ assert.Equal(t, []string{"badge-sort-case"}, collectBadgeSlugs(caseInsensitive))
+}
+
+func collectBadgeSlugs(badges []*user_model.Badge) []string {
+ slugs := make([]string, 0, len(badges))
+ for _, badge := range badges {
+ slugs = append(slugs, badge.Slug)
+ }
+ return slugs
+}
diff --git a/models/user/block.go b/models/user/block.go
index 5f2b65a199..f4afd47d0f 100644
--- a/models/user/block.go
+++ b/models/user/block.go
@@ -90,7 +90,7 @@ func GetBlocking(ctx context.Context, blockerID, blockeeID int64) (*Blocking, er
return nil, err
}
if len(blocks) == 0 {
- return nil, nil
+ return nil, nil //nolint:nilnil // return nil to indicate that the object does not exist
}
return blocks[0], nil
}
diff --git a/models/user/email_address.go b/models/user/email_address.go
index 67aa1bdd82..aa483d5f00 100644
--- a/models/user/email_address.go
+++ b/models/user/email_address.go
@@ -215,7 +215,7 @@ func GetEmailAddressByID(ctx context.Context, uid, id int64) (*EmailAddress, err
if has, err := db.GetEngine(ctx).ID(id).Get(email); err != nil {
return nil, err
} else if !has {
- return nil, nil
+ return nil, nil //nolint:nilnil // return nil to indicate that the object does not exist
}
return email, nil
}
@@ -276,17 +276,22 @@ func updateActivation(ctx context.Context, email *EmailAddress, activate bool) e
return UpdateUserCols(ctx, user, "rands")
}
-func MakeActiveEmailPrimary(ctx context.Context, emailID int64) error {
- return makeEmailPrimaryInternal(ctx, emailID, true)
+func MakeActiveEmailPrimary(ctx context.Context, ownerID, emailID int64) error {
+ return makeEmailPrimaryInternal(ctx, ownerID, emailID, true)
}
-func MakeInactiveEmailPrimary(ctx context.Context, emailID int64) error {
- return makeEmailPrimaryInternal(ctx, emailID, false)
+func MakeInactiveEmailPrimary(ctx context.Context, ownerID, emailID int64) error {
+ return makeEmailPrimaryInternal(ctx, ownerID, emailID, false)
}
-func makeEmailPrimaryInternal(ctx context.Context, emailID int64, isActive bool) error {
+func makeEmailPrimaryInternal(ctx context.Context, ownerID, emailID int64, isActive bool) error {
email := &EmailAddress{}
- if has, err := db.GetEngine(ctx).ID(emailID).Where(builder.Eq{"is_activated": isActive}).Get(email); err != nil {
+ if has, err := db.GetEngine(ctx).ID(emailID).
+ Where(builder.Eq{
+ "uid": ownerID,
+ "is_activated": isActive,
+ }).
+ Get(email); err != nil {
return err
} else if !has {
return ErrEmailAddressNotExist{}
@@ -336,7 +341,7 @@ func ChangeInactivePrimaryEmail(ctx context.Context, uid int64, oldEmailAddr, ne
if err != nil {
return err
}
- return MakeInactiveEmailPrimary(ctx, newEmail.ID)
+ return MakeInactiveEmailPrimary(ctx, uid, newEmail.ID)
})
}
diff --git a/models/user/email_address_test.go b/models/user/email_address_test.go
index 6ef18fb0f6..4167aaac0d 100644
--- a/models/user/email_address_test.go
+++ b/models/user/email_address_test.go
@@ -46,22 +46,22 @@ func TestIsEmailUsed(t *testing.T) {
func TestMakeEmailPrimary(t *testing.T) {
assert.NoError(t, unittest.PrepareTestDatabase())
- err := user_model.MakeActiveEmailPrimary(t.Context(), 9999999)
+ err := user_model.MakeActiveEmailPrimary(t.Context(), 1, 9999999)
assert.Error(t, err)
assert.ErrorIs(t, err, user_model.ErrEmailAddressNotExist{})
email := unittest.AssertExistsAndLoadBean(t, &user_model.EmailAddress{Email: "user11@example.com"})
- err = user_model.MakeActiveEmailPrimary(t.Context(), email.ID)
+ err = user_model.MakeActiveEmailPrimary(t.Context(), email.UID, email.ID)
assert.Error(t, err)
assert.ErrorIs(t, err, user_model.ErrEmailAddressNotExist{}) // inactive email is considered as not exist for "MakeActiveEmailPrimary"
email = unittest.AssertExistsAndLoadBean(t, &user_model.EmailAddress{Email: "user9999999@example.com"})
- err = user_model.MakeActiveEmailPrimary(t.Context(), email.ID)
+ err = user_model.MakeActiveEmailPrimary(t.Context(), email.UID, email.ID)
assert.Error(t, err)
assert.True(t, user_model.IsErrUserNotExist(err))
email = unittest.AssertExistsAndLoadBean(t, &user_model.EmailAddress{Email: "user101@example.com"})
- err = user_model.MakeActiveEmailPrimary(t.Context(), email.ID)
+ err = user_model.MakeActiveEmailPrimary(t.Context(), email.UID, email.ID)
assert.NoError(t, err)
user, _ := user_model.GetUserByID(t.Context(), int64(10))
diff --git a/models/user/list.go b/models/user/list.go
index ca589d1e02..aaaa7965c8 100644
--- a/models/user/list.go
+++ b/models/user/list.go
@@ -24,7 +24,7 @@ func (users UserList) GetUserIDs() []int64 {
return userIDs
}
-// GetTwoFaStatus return state of 2FA enrollement
+// GetTwoFaStatus return state of 2FA enrollment
func (users UserList) GetTwoFaStatus(ctx context.Context) map[int64]bool {
results := make(map[int64]bool, len(users))
for _, user := range users {
@@ -48,7 +48,7 @@ func (users UserList) GetTwoFaStatus(ctx context.Context) map[int64]bool {
func (users UserList) loadTwoFactorStatus(ctx context.Context) (map[int64]*auth.TwoFactor, error) {
if len(users) == 0 {
- return nil, nil
+ return nil, nil //nolint:nilnil // returns nil when there are no users
}
userIDs := users.GetUserIDs()
diff --git a/models/user/openid.go b/models/user/openid.go
index 420c67ca18..5baa48c824 100644
--- a/models/user/openid.go
+++ b/models/user/openid.go
@@ -102,7 +102,13 @@ func DeleteUserOpenID(ctx context.Context, openid *UserOpenID) (err error) {
}
// ToggleUserOpenIDVisibility toggles visibility of an openid address of given user.
-func ToggleUserOpenIDVisibility(ctx context.Context, id int64) (err error) {
- _, err = db.GetEngine(ctx).Exec("update `user_open_id` set `show` = not `show` where `id` = ?", id)
- return err
+func ToggleUserOpenIDVisibility(ctx context.Context, id int64, user *User) error {
+ affected, err := db.GetEngine(ctx).Exec("update `user_open_id` set `show` = not `show` where `id` = ? AND uid = ?", id, user.ID)
+ if err != nil {
+ return err
+ }
+ if n, _ := affected.RowsAffected(); n != 1 {
+ return util.NewNotExistErrorf("OpenID is unknown")
+ }
+ return nil
}
diff --git a/models/user/openid_test.go b/models/user/openid_test.go
index fa260e7a9e..6d2260324f 100644
--- a/models/user/openid_test.go
+++ b/models/user/openid_test.go
@@ -8,6 +8,7 @@ import (
"code.gitea.io/gitea/models/unittest"
user_model "code.gitea.io/gitea/models/user"
+ "code.gitea.io/gitea/modules/util"
"github.com/stretchr/testify/assert"
"github.com/stretchr/testify/require"
@@ -33,12 +34,14 @@ func TestGetUserOpenIDs(t *testing.T) {
func TestToggleUserOpenIDVisibility(t *testing.T) {
assert.NoError(t, unittest.PrepareTestDatabase())
+ user, err := user_model.GetUserByID(t.Context(), int64(2))
+ require.NoError(t, err)
oids, err := user_model.GetUserOpenIDs(t.Context(), int64(2))
require.NoError(t, err)
require.Len(t, oids, 1)
assert.True(t, oids[0].Show)
- err = user_model.ToggleUserOpenIDVisibility(t.Context(), oids[0].ID)
+ err = user_model.ToggleUserOpenIDVisibility(t.Context(), oids[0].ID, user)
require.NoError(t, err)
oids, err = user_model.GetUserOpenIDs(t.Context(), int64(2))
@@ -46,7 +49,7 @@ func TestToggleUserOpenIDVisibility(t *testing.T) {
require.Len(t, oids, 1)
assert.False(t, oids[0].Show)
- err = user_model.ToggleUserOpenIDVisibility(t.Context(), oids[0].ID)
+ err = user_model.ToggleUserOpenIDVisibility(t.Context(), oids[0].ID, user)
require.NoError(t, err)
oids, err = user_model.GetUserOpenIDs(t.Context(), int64(2))
@@ -55,3 +58,13 @@ func TestToggleUserOpenIDVisibility(t *testing.T) {
assert.True(t, oids[0].Show)
}
}
+
+func TestToggleUserOpenIDVisibilityRequiresOwnership(t *testing.T) {
+ assert.NoError(t, unittest.PrepareTestDatabase())
+ unauthorizedUser, err := user_model.GetUserByID(t.Context(), int64(2))
+ require.NoError(t, err)
+
+ err = user_model.ToggleUserOpenIDVisibility(t.Context(), int64(1), unauthorizedUser)
+ require.Error(t, err)
+ assert.ErrorIs(t, err, util.ErrNotExist)
+}
diff --git a/models/user/search.go b/models/user/search.go
index cfd0d011bc..55feef6af2 100644
--- a/models/user/search.go
+++ b/models/user/search.go
@@ -6,6 +6,7 @@ package user
import (
"context"
"fmt"
+ "slices"
"strings"
"code.gitea.io/gitea/models/db"
@@ -17,12 +18,29 @@ import (
"xorm.io/xorm"
)
+// AdminUserOrderByMap represents all possible admin user search orders
+// This should only be used for admin API endpoints as we should not expose "updated" ordering which could expose recent user activity including logins.
+var AdminUserOrderByMap = map[string]map[string]db.SearchOrderBy{
+ "asc": {
+ "name": db.SearchOrderByAlphabetically,
+ "created": db.SearchOrderByOldest,
+ "updated": db.SearchOrderByLeastUpdated,
+ "id": db.SearchOrderByID,
+ },
+ "desc": {
+ "name": db.SearchOrderByAlphabeticallyReverse,
+ "created": db.SearchOrderByNewest,
+ "updated": db.SearchOrderByRecentUpdated,
+ "id": db.SearchOrderByIDReverse,
+ },
+}
+
// SearchUserOptions contains the options for searching
type SearchUserOptions struct {
db.ListOptions
Keyword string
- Type UserType
+ Types []UserType
UID int64
LoginName string // this option should be used only for admin user
SourceID int64 // this option should be used only for admin user
@@ -41,18 +59,24 @@ type SearchUserOptions struct {
IncludeReserved bool
}
+func (opts *SearchUserOptions) ApplyPublicOnly(publicOnly bool) {
+ if publicOnly {
+ opts.Visible = []structs.VisibleType{structs.VisibleTypePublic}
+ }
+}
+
func (opts *SearchUserOptions) toSearchQueryBase(ctx context.Context) *xorm.Session {
var cond builder.Cond
- cond = builder.Eq{"type": opts.Type}
+ cond = builder.In("type", opts.Types)
if opts.IncludeReserved {
- switch opts.Type {
- case UserTypeIndividual:
+ switch {
+ case slices.Contains(opts.Types, UserTypeIndividual):
cond = cond.Or(builder.Eq{"type": UserTypeUserReserved}).Or(
builder.Eq{"type": UserTypeBot},
).Or(
builder.Eq{"type": UserTypeRemoteUser},
)
- case UserTypeOrganization:
+ case slices.Contains(opts.Types, UserTypeOrganization):
cond = cond.Or(builder.Eq{"type": UserTypeOrganizationReserved})
}
}
diff --git a/models/user/setting.go b/models/user/setting.go
index c65afae76c..a16fc86e55 100644
--- a/models/user/setting.go
+++ b/models/user/setting.go
@@ -11,10 +11,12 @@ import (
"code.gitea.io/gitea/models/db"
"code.gitea.io/gitea/modules/cache"
+ "code.gitea.io/gitea/modules/json"
setting_module "code.gitea.io/gitea/modules/setting"
"code.gitea.io/gitea/modules/util"
"xorm.io/builder"
+ "xorm.io/xorm/convert"
)
// Setting is a key value store of user settings
@@ -211,3 +213,44 @@ func upsertUserSettingValue(ctx context.Context, userID int64, key, value string
return err
})
}
+
+func GetUserSettingJSON[T any](ctx context.Context, userID int64, key string, def T) (ret T, _ error) {
+ ret = def
+ str, err := GetUserSetting(ctx, userID, key)
+ if err != nil {
+ return ret, err
+ }
+
+ conv, ok := any(&ret).(convert.ConversionFrom)
+ if !ok {
+ conv, ok = any(ret).(convert.ConversionFrom)
+ }
+ if ok {
+ if err := conv.FromDB(util.UnsafeStringToBytes(str)); err != nil {
+ return ret, err
+ }
+ } else {
+ if str == "" {
+ return ret, nil
+ }
+ err = json.Unmarshal(util.UnsafeStringToBytes(str), &ret)
+ }
+ return ret, err
+}
+
+func SetUserSettingJSON[T any](ctx context.Context, userID int64, key string, val T) (err error) {
+ conv, ok := any(&val).(convert.ConversionTo)
+ if !ok {
+ conv, ok = any(val).(convert.ConversionTo)
+ }
+ var bs []byte
+ if ok {
+ bs, err = conv.ToDB()
+ } else {
+ bs, err = json.Marshal(val)
+ }
+ if err != nil {
+ return err
+ }
+ return SetUserSetting(ctx, userID, key, util.UnsafeBytesToString(bs))
+}
diff --git a/models/user/setting_options.go b/models/user/setting_options.go
index 6d37ef63d5..5867b908d1 100644
--- a/models/user/setting_options.go
+++ b/models/user/setting_options.go
@@ -11,10 +11,6 @@ const (
// SettingsKeyShowOutdatedComments is the setting key whether or not to show outdated comments in PRs
SettingsKeyShowOutdatedComments = "comment_code.show_outdated"
- // UserActivityPubPrivPem is user's private key
- UserActivityPubPrivPem = "activitypub.priv_pem"
- // UserActivityPubPubPem is user's public key
- UserActivityPubPubPem = "activitypub.pub_pem"
// SignupIP is the IP address that the user signed up with
SignupIP = "signup.ip"
// SignupUserAgent is the user agent that the user signed up with
@@ -26,4 +22,6 @@ const (
SettingEmailNotificationGiteaActionsAll = "all"
SettingEmailNotificationGiteaActionsFailureOnly = "failure-only" // Default for actions email preference
SettingEmailNotificationGiteaActionsDisabled = "disabled"
+
+ SettingsKeyActionsConfig = "actions.config"
)
diff --git a/models/user/user.go b/models/user/user.go
index b4bd8694bf..0e0700bb28 100644
--- a/models/user/user.go
+++ b/models/user/user.go
@@ -7,12 +7,15 @@ package user
import (
"context"
"encoding/hex"
+ "errors"
"fmt"
+ "html/template"
"mime"
"net/mail"
"net/url"
"path/filepath"
"regexp"
+ "strconv"
"strings"
"sync"
"time"
@@ -27,6 +30,7 @@ import (
"code.gitea.io/gitea/modules/base"
"code.gitea.io/gitea/modules/container"
"code.gitea.io/gitea/modules/git"
+ "code.gitea.io/gitea/modules/htmlutil"
"code.gitea.io/gitea/modules/httplib"
"code.gitea.io/gitea/modules/log"
"code.gitea.io/gitea/modules/optional"
@@ -184,7 +188,7 @@ func (u *User) BeforeUpdate() {
}
// FIXME: this email doesn't need to be in lowercase, because the emails are mainly managed by the email table with lower_email field
- // This trick could be removed in new releases to display the user inputed email as-is.
+ // This trick could be removed in new releases to display the user inputted email as-is.
u.Email = strings.ToLower(u.Email)
if !u.IsOrganization() {
if len(u.AvatarEmail) == 0 {
@@ -212,7 +216,7 @@ func (u *User) SetLastLogin() {
// GetPlaceholderEmail returns an noreply email
func (u *User) GetPlaceholderEmail() string {
- return fmt.Sprintf("%s@%s", u.LowerName, setting.Service.NoReplyAddress)
+ return fmt.Sprintf("%d+%s@%s", u.ID, u.LowerName, setting.Service.NoReplyAddress)
}
// GetEmail returns a noreply email, if the user has set to keep his
@@ -249,8 +253,13 @@ func (u *User) MaxCreationLimit() int {
}
// CanCreateRepoIn checks whether the doer(u) can create a repository in the owner
-// NOTE: functions calling this assume a failure due to repository count limit; it ONLY checks the repo number LIMIT, if new checks are added, those functions should be revised
+// NOTE: functions calling this assume a failure due to repository count limit, or the owner is not a real user.
+// It ONLY checks the repo number LIMIT or whether owner user is real. If new checks are added, those functions should be revised.
+// TODO: the callers can only return ErrReachLimitOfRepo, need to fine tune to support other error types in the future.
func (u *User) CanCreateRepoIn(owner *User) bool {
+ if u.ID <= 0 || owner.ID <= 0 {
+ return false // fake user like Ghost or Actions user
+ }
if u.IsAdmin {
return true
}
@@ -298,6 +307,13 @@ func (u *User) DashboardLink() string {
return setting.AppSubURL + "/"
}
+func (u *User) SettingsLink() string {
+ if u.IsOrganization() {
+ return u.OrganisationLink() + "/settings"
+ }
+ return setting.AppSubURL + "/user/settings"
+}
+
// HomeLink returns the user or organization home page link.
func (u *User) HomeLink() string {
return setting.AppSubURL + "/" + url.PathEscape(u.Name)
@@ -411,16 +427,6 @@ func (u *User) IsTokenAccessAllowed() bool {
return u.Type == UserTypeIndividual || u.Type == UserTypeBot
}
-// DisplayName returns full name if it's not empty,
-// returns username otherwise.
-func (u *User) DisplayName() string {
- trimmed := strings.TrimSpace(u.FullName)
- if len(trimmed) > 0 {
- return trimmed
- }
- return u.Name
-}
-
// EmailTo returns a string suitable to be put into a e-mail `To:` header.
func (u *User) EmailTo() string {
sanitizedDisplayName := globalVars().emailToReplacer.Replace(u.DisplayName())
@@ -439,27 +445,45 @@ func (u *User) EmailTo() string {
return fmt.Sprintf("%s <%s>", mime.QEncoding.Encode("utf-8", add.Name), add.Address)
}
-// GetDisplayName returns full name if it's not empty and DEFAULT_SHOW_FULL_NAME is set,
-// returns username otherwise.
+// TODO: DefaultShowFullName causes messy logic, there are already too many methods to display a user's "display name", need to refactor them
+// * user.Name / user.FullName: directly used in templates
+// * user.DisplayName(): always show FullName if it's not empty, otherwise show Name
+// * user.GetDisplayName(): show FullName if it's not empty and DefaultShowFullName is set, otherwise show Name
+// * user.ShortName(): used a lot in templates, but it should be removed and let frontend use "ellipsis" styles
+// * activity action.ShortActUserName/GetActDisplayName/GetActDisplayNameTitle, etc: duplicate and messy
+
+// DisplayName returns full name if it's not empty, returns username otherwise.
+func (u *User) DisplayName() string {
+ fullName := strings.TrimSpace(u.FullName)
+ if fullName != "" {
+ return fullName
+ }
+ return u.Name
+}
+
+// GetDisplayName returns full name if it's not empty and DEFAULT_SHOW_FULL_NAME is set, otherwise, username.
func (u *User) GetDisplayName() string {
if setting.UI.DefaultShowFullName {
- trimmed := strings.TrimSpace(u.FullName)
- if len(trimmed) > 0 {
- return trimmed
+ fullName := strings.TrimSpace(u.FullName)
+ if fullName != "" {
+ return fullName
}
}
return u.Name
}
-// GetCompleteName returns the full name and username in the form of
-// "Full Name (username)" if full name is not empty, otherwise it returns
-// "username".
-func (u *User) GetCompleteName() string {
- trimmedFullName := strings.TrimSpace(u.FullName)
- if len(trimmedFullName) > 0 {
- return fmt.Sprintf("%s (%s)", trimmedFullName, u.Name)
+// ShortName ellipses username to length (still used by many templates), it calls GetDisplayName and respects DEFAULT_SHOW_FULL_NAME
+func (u *User) ShortName(length int) string {
+ return util.EllipsisDisplayString(u.GetDisplayName(), length)
+}
+
+func (u *User) GetShortDisplayNameLinkHTML() template.HTML {
+ fullName := strings.TrimSpace(u.FullName)
+ displayName, displayTooltip := u.Name, fullName
+ if setting.UI.DefaultShowFullName && fullName != "" {
+ displayName, displayTooltip = fullName, u.Name
}
- return u.Name
+ return htmlutil.HTMLFormat(`%s `, u.HomeLink(), displayTooltip, displayName)
}
func gitSafeName(name string) string {
@@ -482,18 +506,10 @@ func (u *User) GitName() string {
return fmt.Sprintf("user-%d", u.ID)
}
-// ShortName ellipses username to length
-func (u *User) ShortName(length int) string {
- if setting.UI.DefaultShowFullName && len(u.FullName) > 0 {
- return util.EllipsisDisplayString(u.FullName, length)
- }
- return util.EllipsisDisplayString(u.Name, length)
-}
-
-// IsMailable checks if a user is eligible
-// to receive emails.
+// IsMailable checks if a user is eligible to receive emails.
+// System users like Ghost and Gitea Actions are excluded.
func (u *User) IsMailable() bool {
- return u.IsActive
+ return u.IsActive && !u.IsGiteaActions() && !u.IsGhost()
}
// IsUserExist checks if given username exist,
@@ -980,7 +996,7 @@ func GetInactiveUsers(ctx context.Context, olderThan time.Duration) ([]*User, er
// UserPath returns the path absolute path of user repositories.
func UserPath(userName string) string { //revive:disable-line:exported
- return filepath.Join(setting.RepoRootPath, strings.ToLower(userName))
+ return filepath.Join(setting.RepoRootPath, filepath.Clean(strings.ToLower(userName)))
}
// GetUserByID returns the user object by given ID if exists.
@@ -1008,17 +1024,22 @@ func GetUserByIDs(ctx context.Context, ids []int64) ([]*User, error) {
return users, err
}
-// GetPossibleUserByID returns the user if id > 0 or returns system user if id < 0
-func GetPossibleUserByID(ctx context.Context, id int64) (*User, error) {
+// GetPossibleUserByID returns the possible user and its ID. If the user doesn't exist, it returns Ghost user
+func GetPossibleUserByID(ctx context.Context, id int64) (_ int64, u *User, err error) {
if id < 0 {
if newFunc, ok := globalVars().systemUserNewFuncs[id]; ok {
- return newFunc(), nil
+ u = newFunc()
+ }
+ }
+ if u == nil {
+ u, err = GetUserByID(ctx, id)
+ if errors.Is(err, util.ErrNotExist) {
+ u = NewGhostUser()
+ } else if err != nil {
+ return 0, nil, err
}
- return nil, ErrUserNotExist{UID: id}
- } else if id == 0 {
- return nil, ErrUserNotExist{}
}
- return GetUserByID(ctx, id)
+ return u.ID, u, nil
}
// GetPossibleUserByIDs returns the users if id > 0 or returns system users if id < 0
@@ -1039,13 +1060,13 @@ func GetPossibleUserByIDs(ctx context.Context, ids []int64) ([]*User, error) {
return users, nil
}
-// GetUserByName returns user by given name.
-func GetUserByName(ctx context.Context, name string) (*User, error) {
- if len(name) == 0 {
- return nil, ErrUserNotExist{Name: name}
+func getUserByNameWithTypes(ctx context.Context, name string, types ...UserType) (*User, error) {
+ u := &User{}
+ sess := db.GetEngine(ctx).Where(builder.Eq{"lower_name": strings.ToLower(name)})
+ if len(types) > 0 {
+ sess.In("`type`", types)
}
- u := &User{LowerName: strings.ToLower(name), Type: UserTypeIndividual}
- has, err := db.GetEngine(ctx).Get(u)
+ has, err := sess.Get(u)
if err != nil {
return nil, err
} else if !has {
@@ -1054,6 +1075,15 @@ func GetUserByName(ctx context.Context, name string) (*User, error) {
return u, nil
}
+// GetUserByName returns the user object by given name, any user type.
+func GetUserByName(ctx context.Context, name string) (*User, error) {
+ return getUserByNameWithTypes(ctx, name)
+}
+
+func GetIndividualUserByName(ctx context.Context, name string) (*User, error) {
+ return getUserByNameWithTypes(ctx, name, UserTypeIndividual)
+}
+
// GetUserEmailsByNames returns a list of e-mails corresponds to names of users
// that have their email notifications set to enabled or onmention.
func GetUserEmailsByNames(ctx context.Context, names []string) []string {
@@ -1096,19 +1126,6 @@ func GetMailableUsersByIDs(ctx context.Context, ids []int64, isMention bool) ([]
Find(&ous)
}
-// GetUserNameByID returns username for the id
-func GetUserNameByID(ctx context.Context, id int64) (string, error) {
- var name string
- has, err := db.GetEngine(ctx).Table("user").Where("id = ?", id).Cols("name").Get(&name)
- if err != nil {
- return "", err
- }
- if has {
- return name, nil
- }
- return "", nil
-}
-
// GetUserIDsByNames returns a slice of ids corresponds to names.
func GetUserIDsByNames(ctx context.Context, names []string, ignoreNonExistent bool) ([]int64, error) {
ids := make([]int64, 0, len(names))
@@ -1187,19 +1204,23 @@ func (eum *EmailUserMap) GetByEmail(email string) *User {
func GetUsersByEmails(ctx context.Context, emails []string) (*EmailUserMap, error) {
if len(emails) == 0 {
- return nil, nil
+ return nil, nil //nolint:nilnil // return nil when there are no emails to look up
}
needCheckEmails := make(container.Set[string])
needCheckUserNames := make(container.Set[string])
+ needCheckUserIDs := make(container.Set[int64])
noReplyAddressSuffix := "@" + strings.ToLower(setting.Service.NoReplyAddress)
for _, email := range emails {
emailLower := strings.ToLower(email)
- if noReplyUserNameLower, ok := strings.CutSuffix(emailLower, noReplyAddressSuffix); ok {
- needCheckUserNames.Add(noReplyUserNameLower)
- needCheckEmails.Add(emailLower)
- } else {
- needCheckEmails.Add(emailLower)
+ needCheckEmails.Add(emailLower)
+ if localPart, ok := strings.CutSuffix(emailLower, noReplyAddressSuffix); ok {
+ name, id := parseLocalPartToNameID(localPart)
+ if id != 0 {
+ needCheckUserIDs.Add(id)
+ } else if name != "" {
+ needCheckUserNames.Add(name)
+ }
}
}
@@ -1229,16 +1250,59 @@ func GetUsersByEmails(ctx context.Context, emails []string) (*EmailUserMap, erro
}
}
- users := make(map[int64]*User, len(needCheckUserNames))
- if err := db.GetEngine(ctx).In("lower_name", needCheckUserNames.Values()).Find(&users); err != nil {
- return nil, err
+ usersByIDs := make(map[int64]*User)
+ if len(needCheckUserIDs) > 0 || len(needCheckUserNames) > 0 {
+ cond := builder.NewCond()
+ if len(needCheckUserIDs) > 0 {
+ cond = cond.Or(builder.In("id", needCheckUserIDs.Values()))
+ }
+ if len(needCheckUserNames) > 0 {
+ cond = cond.Or(builder.In("lower_name", needCheckUserNames.Values()))
+ }
+ if err := db.GetEngine(ctx).Where(cond).Find(&usersByIDs); err != nil {
+ return nil, err
+ }
+ }
+
+ usersByName := make(map[string]*User)
+ for _, user := range usersByIDs {
+ usersByName[user.LowerName] = user
}
- for _, user := range users {
- results[strings.ToLower(user.GetPlaceholderEmail())] = user
+
+ for _, email := range emails {
+ emailLower := strings.ToLower(email)
+ if _, ok := results[emailLower]; ok {
+ continue
+ }
+
+ localPart, ok := strings.CutSuffix(emailLower, noReplyAddressSuffix)
+ if !ok {
+ continue
+ }
+ name, id := parseLocalPartToNameID(localPart)
+ if user, ok := usersByIDs[id]; ok {
+ results[emailLower] = user
+ } else if user, ok := usersByName[name]; ok {
+ results[emailLower] = user
+ }
}
+
return &EmailUserMap{results}, nil
}
+// parseLocalPartToNameID attempts to unparse local-part of email that's in format id+user
+// returns user and id if possible
+func parseLocalPartToNameID(localPart string) (string, int64) {
+ var id int64
+ idstr, name, hasPlus := strings.Cut(localPart, "+")
+ if hasPlus {
+ id, _ = strconv.ParseInt(idstr, 10, 64)
+ } else {
+ name = idstr
+ }
+ return name, id
+}
+
// GetUserByEmail returns the user object by given e-mail if exists.
func GetUserByEmail(ctx context.Context, email string) (*User, error) {
if len(email) == 0 {
@@ -1257,24 +1321,24 @@ func GetUserByEmail(ctx context.Context, email string) (*User, error) {
}
// Finally, if email address is the protected email address:
- if strings.HasSuffix(email, "@"+setting.Service.NoReplyAddress) {
- username := strings.TrimSuffix(email, "@"+setting.Service.NoReplyAddress)
- user := &User{}
- has, err := db.GetEngine(ctx).Where("lower_name=?", username).Get(user)
- if err != nil {
- return nil, err
- }
- if has {
- return user, nil
+ if localPart, ok := strings.CutSuffix(email, strings.ToLower("@"+setting.Service.NoReplyAddress)); ok {
+ name, id := parseLocalPartToNameID(localPart)
+ if id != 0 {
+ return GetUserByID(ctx, id)
}
+ return GetIndividualUserByName(ctx, name)
}
return nil, ErrUserNotExist{Name: email}
}
-// GetUser checks if a user already exists
-func GetUser(ctx context.Context, user *User) (bool, error) {
- return db.GetEngine(ctx).Get(user)
+func GetIndividualUser(ctx context.Context, user *User) (bool, error) {
+ // FIXME: the design is wrong, empty User fields won't apply, this function should be removed in the future
+ has, err := db.GetEngine(ctx).Get(user)
+ if has && user.Type != UserTypeIndividual {
+ has = false
+ }
+ return has, err
}
// GetUserByOpenID returns the user object by given OpenID if exists.
diff --git a/models/user/user_system.go b/models/user/user_system.go
index e07274d291..cf4306df25 100644
--- a/models/user/user_system.go
+++ b/models/user/user_system.go
@@ -4,6 +4,7 @@
package user
import (
+ "strconv"
"strings"
"code.gitea.io/gitea/modules/structs"
@@ -23,10 +24,6 @@ func NewGhostUser() *User {
}
}
-func IsGhostUserName(name string) bool {
- return strings.EqualFold(name, GhostUserName)
-}
-
// IsGhost check if user is fake user for a deleted account
func (u *User) IsGhost() bool {
if u == nil {
@@ -41,25 +38,41 @@ const (
ActionsUserEmail = "teabot@gitea.io"
)
-func IsGiteaActionsUserName(name string) bool {
- return strings.EqualFold(name, ActionsUserName)
-}
-
// NewActionsUser creates and returns a fake user for running the actions.
func NewActionsUser() *User {
return &User{
- ID: ActionsUserID,
- Name: ActionsUserName,
- LowerName: ActionsUserName,
- IsActive: true,
- FullName: "Gitea Actions",
- Email: ActionsUserEmail,
- KeepEmailPrivate: true,
- LoginName: ActionsUserName,
- Type: UserTypeBot,
- AllowCreateOrganization: true,
- Visibility: structs.VisibleTypePublic,
+ ID: ActionsUserID,
+ Name: ActionsUserName,
+ LowerName: ActionsUserName,
+ IsActive: true,
+ FullName: "Gitea Actions",
+ Email: ActionsUserEmail,
+ KeepEmailPrivate: true,
+ LoginName: ActionsUserName,
+ Type: UserTypeBot,
+ Visibility: structs.VisibleTypePublic,
+ }
+}
+
+func NewActionsUserWithTaskID(id int64) *User {
+ u := NewActionsUser()
+ // LoginName is for only internal usage in this case, so it can be moved to other fields in the future
+ u.LoginSource = -1
+ u.LoginName = "@" + ActionsUserName + "/" + strconv.FormatInt(id, 10)
+ return u
+}
+
+func GetActionsUserTaskID(u *User) (int64, bool) {
+ if u == nil || u.ID != ActionsUserID {
+ return 0, false
+ }
+ prefix, payload, _ := strings.Cut(u.LoginName, "/")
+ if prefix != "@"+ActionsUserName {
+ return 0, false
+ } else if taskID, err := strconv.ParseInt(payload, 10, 64); err == nil {
+ return taskID, true
}
+ return 0, false
}
func (u *User) IsGiteaActions() bool {
@@ -67,10 +80,10 @@ func (u *User) IsGiteaActions() bool {
}
func GetSystemUserByName(name string) *User {
- if IsGhostUserName(name) {
+ if strings.EqualFold(name, GhostUserName) {
return NewGhostUser()
}
- if IsGiteaActionsUserName(name) {
+ if strings.EqualFold(name, ActionsUserName) {
return NewActionsUser()
}
return nil
diff --git a/models/user/user_system_test.go b/models/user/user_system_test.go
index 5aa3fa463c..3ae9c6e366 100644
--- a/models/user/user_system_test.go
+++ b/models/user/user_system_test.go
@@ -11,20 +11,30 @@ import (
)
func TestSystemUser(t *testing.T) {
- u, err := GetPossibleUserByID(t.Context(), -1)
+ uid, u, err := GetPossibleUserByID(t.Context(), -1)
require.NoError(t, err)
+ assert.Equal(t, int64(-1), uid)
assert.Equal(t, "Ghost", u.Name)
assert.Equal(t, "ghost", u.LowerName)
assert.True(t, u.IsGhost())
- assert.True(t, IsGhostUserName("gHost"))
- u, err = GetPossibleUserByID(t.Context(), -2)
+ u = GetSystemUserByName("gHost")
+ require.NotNil(t, u)
+ assert.Equal(t, "Ghost", u.Name)
+
+ uid, u, err = GetPossibleUserByID(t.Context(), -2)
require.NoError(t, err)
+ assert.Equal(t, int64(-2), uid)
assert.Equal(t, "gitea-actions", u.Name)
assert.Equal(t, "gitea-actions", u.LowerName)
assert.True(t, u.IsGiteaActions())
- assert.True(t, IsGiteaActionsUserName("Gitea-actionS"))
- _, err = GetPossibleUserByID(t.Context(), -3)
- require.Error(t, err)
+ u = GetSystemUserByName("Gitea-actionS")
+ require.NotNil(t, u)
+ assert.Equal(t, "Gitea Actions", u.FullName)
+
+ uid, u, err = GetPossibleUserByID(t.Context(), 999999)
+ require.NoError(t, err)
+ assert.Equal(t, int64(-1), uid)
+ assert.Equal(t, "Ghost", u.Name)
}
diff --git a/models/user/user_test.go b/models/user/user_test.go
index 4201ec4816..956eaeafb4 100644
--- a/models/user/user_test.go
+++ b/models/user/user_test.go
@@ -51,12 +51,27 @@ func TestOAuth2Application_LoadUser(t *testing.T) {
func TestUserEmails(t *testing.T) {
assert.NoError(t, unittest.PrepareTestDatabase())
+ defer test.MockVariableValue(&setting.Service.NoReplyAddress, "NoReply.gitea.internal")()
t.Run("GetUserEmailsByNames", func(t *testing.T) {
- // ignore none active user email
+ // ignore not active user email
assert.ElementsMatch(t, []string{"user8@example.com"}, user_model.GetUserEmailsByNames(t.Context(), []string{"user8", "user9"}))
assert.ElementsMatch(t, []string{"user8@example.com", "user5@example.com"}, user_model.GetUserEmailsByNames(t.Context(), []string{"user8", "user5"}))
assert.ElementsMatch(t, []string{"user8@example.com"}, user_model.GetUserEmailsByNames(t.Context(), []string{"user8", "org7"}))
})
+
+ cases := []struct {
+ Email string
+ UID int64
+ }{
+ {"UseR1@example.com", 1},
+ {"user1-2@example.COM", 1},
+ {"USER2@" + setting.Service.NoReplyAddress, 2},
+ {"2+user2@" + setting.Service.NoReplyAddress, 2},
+ {"2+oldUser2UsernameWhichDoesNotMatterForQuery@" + setting.Service.NoReplyAddress, 2},
+ {"99999+badUser@" + setting.Service.NoReplyAddress, 0},
+ {"user4@example.com", 4},
+ {"no-such", 0},
+ }
t.Run("GetUsersByEmails", func(t *testing.T) {
defer test.MockVariableValue(&setting.Service.NoReplyAddress, "NoReply.gitea.internal")()
testGetUserByEmail := func(t *testing.T, email string, uid int64) {
@@ -70,15 +85,27 @@ func TestUserEmails(t *testing.T) {
require.NotNil(t, user)
assert.Equal(t, uid, user.ID)
}
- cases := []struct {
- Email string
- UID int64
- }{
- {"UseR1@example.com", 1},
- {"user1-2@example.COM", 1},
- {"USER2@" + setting.Service.NoReplyAddress, 2},
- {"user4@example.com", 4},
- {"no-such", 0},
+ for _, c := range cases {
+ t.Run(c.Email, func(t *testing.T) {
+ testGetUserByEmail(t, c.Email, c.UID)
+ })
+ }
+
+ t.Run("NoReplyConflict", func(t *testing.T) {
+ setting.Service.NoReplyAddress = "example.com"
+ testGetUserByEmail(t, "user1-2@example.COM", 1)
+ })
+ })
+ t.Run("GetUserByEmail", func(t *testing.T) {
+ testGetUserByEmail := func(t *testing.T, email string, uid int64) {
+ user, err := user_model.GetUserByEmail(t.Context(), email)
+ if uid == 0 {
+ require.Error(t, err)
+ assert.Nil(t, user)
+ } else {
+ require.NotNil(t, user)
+ assert.Equal(t, uid, user.ID)
+ }
}
for _, c := range cases {
t.Run(c.Email, func(t *testing.T) {
@@ -126,7 +153,7 @@ func TestSearchUsers(t *testing.T) {
// test orgs
testOrgSuccess := func(opts user_model.SearchUserOptions, expectedOrgIDs []int64) {
- opts.Type = user_model.UserTypeOrganization
+ opts.Types = []user_model.UserType{user_model.UserTypeOrganization}
testSuccess(opts, expectedOrgIDs)
}
@@ -150,7 +177,7 @@ func TestSearchUsers(t *testing.T) {
// test users
testUserSuccess := func(opts user_model.SearchUserOptions, expectedUserIDs []int64) {
- opts.Type = user_model.UserTypeIndividual
+ opts.Types = []user_model.UserType{user_model.UserTypeIndividual}
testSuccess(opts, expectedUserIDs)
}
@@ -648,33 +675,36 @@ func TestGetInactiveUsers(t *testing.T) {
func TestCanCreateRepo(t *testing.T) {
defer test.MockVariableValue(&setting.Repository.MaxCreationLimit)()
const noLimit = -1
- doerNormal := &user_model.User{}
- doerAdmin := &user_model.User{IsAdmin: true}
+ doerActions := user_model.NewActionsUser()
+ doerNormal := &user_model.User{ID: 2}
+ doerAdmin := &user_model.User{ID: 1, IsAdmin: true}
t.Run("NoGlobalLimit", func(t *testing.T) {
setting.Repository.MaxCreationLimit = noLimit
- assert.True(t, doerNormal.CanCreateRepoIn(&user_model.User{NumRepos: 10, MaxRepoCreation: noLimit}))
- assert.False(t, doerNormal.CanCreateRepoIn(&user_model.User{NumRepos: 10, MaxRepoCreation: 0}))
- assert.True(t, doerNormal.CanCreateRepoIn(&user_model.User{NumRepos: 10, MaxRepoCreation: 100}))
+ assert.False(t, doerNormal.CanCreateRepoIn(&user_model.User{ID: 2, NumRepos: 10, MaxRepoCreation: 0}))
+ assert.True(t, doerNormal.CanCreateRepoIn(&user_model.User{ID: 2, NumRepos: 10, MaxRepoCreation: 100}))
+ assert.True(t, doerNormal.CanCreateRepoIn(&user_model.User{ID: 2, NumRepos: 10, MaxRepoCreation: noLimit}))
- assert.True(t, doerAdmin.CanCreateRepoIn(&user_model.User{NumRepos: 10, MaxRepoCreation: noLimit}))
- assert.True(t, doerAdmin.CanCreateRepoIn(&user_model.User{NumRepos: 10, MaxRepoCreation: 0}))
- assert.True(t, doerAdmin.CanCreateRepoIn(&user_model.User{NumRepos: 10, MaxRepoCreation: 100}))
+ assert.True(t, doerAdmin.CanCreateRepoIn(&user_model.User{ID: 2, NumRepos: 10, MaxRepoCreation: 0}))
+ assert.True(t, doerAdmin.CanCreateRepoIn(&user_model.User{ID: 2, NumRepos: 10, MaxRepoCreation: 100}))
+ assert.True(t, doerAdmin.CanCreateRepoIn(&user_model.User{ID: 2, NumRepos: 10, MaxRepoCreation: noLimit}))
+ assert.False(t, doerActions.CanCreateRepoIn(&user_model.User{ID: 2, NumRepos: 10, MaxRepoCreation: noLimit}))
+ assert.False(t, doerAdmin.CanCreateRepoIn(doerActions))
})
t.Run("GlobalLimit50", func(t *testing.T) {
setting.Repository.MaxCreationLimit = 50
- assert.True(t, doerNormal.CanCreateRepoIn(&user_model.User{NumRepos: 10, MaxRepoCreation: noLimit}))
- assert.False(t, doerNormal.CanCreateRepoIn(&user_model.User{NumRepos: 60, MaxRepoCreation: noLimit})) // limited by global limit
- assert.False(t, doerNormal.CanCreateRepoIn(&user_model.User{NumRepos: 10, MaxRepoCreation: 0}))
- assert.True(t, doerNormal.CanCreateRepoIn(&user_model.User{NumRepos: 10, MaxRepoCreation: 100}))
- assert.True(t, doerNormal.CanCreateRepoIn(&user_model.User{NumRepos: 60, MaxRepoCreation: 100}))
-
- assert.True(t, doerAdmin.CanCreateRepoIn(&user_model.User{NumRepos: 10, MaxRepoCreation: noLimit}))
- assert.True(t, doerAdmin.CanCreateRepoIn(&user_model.User{NumRepos: 60, MaxRepoCreation: noLimit}))
- assert.True(t, doerAdmin.CanCreateRepoIn(&user_model.User{NumRepos: 10, MaxRepoCreation: 0}))
- assert.True(t, doerAdmin.CanCreateRepoIn(&user_model.User{NumRepos: 10, MaxRepoCreation: 100}))
- assert.True(t, doerAdmin.CanCreateRepoIn(&user_model.User{NumRepos: 60, MaxRepoCreation: 100}))
+ assert.True(t, doerNormal.CanCreateRepoIn(&user_model.User{ID: 2, NumRepos: 10, MaxRepoCreation: noLimit}))
+ assert.False(t, doerNormal.CanCreateRepoIn(&user_model.User{ID: 2, NumRepos: 60, MaxRepoCreation: noLimit})) // limited by global limit
+ assert.False(t, doerNormal.CanCreateRepoIn(&user_model.User{ID: 2, NumRepos: 10, MaxRepoCreation: 0}))
+ assert.True(t, doerNormal.CanCreateRepoIn(&user_model.User{ID: 2, NumRepos: 10, MaxRepoCreation: 100}))
+ assert.True(t, doerNormal.CanCreateRepoIn(&user_model.User{ID: 2, NumRepos: 60, MaxRepoCreation: 100}))
+
+ assert.True(t, doerAdmin.CanCreateRepoIn(&user_model.User{ID: 2, NumRepos: 10, MaxRepoCreation: noLimit}))
+ assert.True(t, doerAdmin.CanCreateRepoIn(&user_model.User{ID: 2, NumRepos: 60, MaxRepoCreation: noLimit}))
+ assert.True(t, doerAdmin.CanCreateRepoIn(&user_model.User{ID: 2, NumRepos: 10, MaxRepoCreation: 0}))
+ assert.True(t, doerAdmin.CanCreateRepoIn(&user_model.User{ID: 2, NumRepos: 10, MaxRepoCreation: 100}))
+ assert.True(t, doerAdmin.CanCreateRepoIn(&user_model.User{ID: 2, NumRepos: 60, MaxRepoCreation: 100}))
})
}
diff --git a/models/webhook/webhook.go b/models/webhook/webhook.go
index 7d4b2e2237..5144c0eca6 100644
--- a/models/webhook/webhook.go
+++ b/models/webhook/webhook.go
@@ -126,6 +126,7 @@ type Webhook struct {
OwnerID int64 `xorm:"INDEX"`
IsSystemWebhook bool
URL string `xorm:"url TEXT"`
+ Name string `xorm:"VARCHAR(255) NOT NULL DEFAULT ''"`
HTTPMethod string `xorm:"http_method"`
ContentType HookContentType
Secret string `xorm:"TEXT"`
diff --git a/models/webhook/webhook_system.go b/models/webhook/webhook_system.go
index 58d9d4a5c1..e8b5040c96 100644
--- a/models/webhook/webhook_system.go
+++ b/models/webhook/webhook_system.go
@@ -9,19 +9,32 @@ import (
"code.gitea.io/gitea/models/db"
"code.gitea.io/gitea/modules/optional"
+
+ "xorm.io/builder"
)
-// GetSystemOrDefaultWebhooks returns webhooks by given argument or all if argument is missing.
-func GetSystemOrDefaultWebhooks(ctx context.Context, isSystemWebhook optional.Option[bool]) ([]*Webhook, error) {
- webhooks := make([]*Webhook, 0, 5)
- if !isSystemWebhook.Has() {
- return webhooks, db.GetEngine(ctx).Where("repo_id=? AND owner_id=?", 0, 0).
- Find(&webhooks)
+// ListSystemWebhookOptions options for listing system or default webhooks
+type ListSystemWebhookOptions struct {
+ db.ListOptions
+ IsActive optional.Option[bool]
+ IsSystem optional.Option[bool]
+}
+
+func (opts ListSystemWebhookOptions) ToConds() builder.Cond {
+ cond := builder.NewCond()
+ cond = cond.And(builder.Eq{"webhook.repo_id": 0}, builder.Eq{"webhook.owner_id": 0})
+ if opts.IsActive.Has() {
+ cond = cond.And(builder.Eq{"webhook.is_active": opts.IsActive.Value()})
}
+ if opts.IsSystem.Has() {
+ cond = cond.And(builder.Eq{"is_system_webhook": opts.IsSystem.Value()})
+ }
+ return cond
+}
- return webhooks, db.GetEngine(ctx).
- Where("repo_id=? AND owner_id=? AND is_system_webhook=?", 0, 0, isSystemWebhook.Value()).
- Find(&webhooks)
+// GetGlobalWebhooks returns global (default and/or system) webhooks
+func GetGlobalWebhooks(ctx context.Context, opts *ListSystemWebhookOptions) ([]*Webhook, int64, error) {
+ return db.FindAndCount[Webhook](ctx, opts)
}
// GetDefaultWebhooks returns all admin-default webhooks.
diff --git a/models/webhook/webhook_system_test.go b/models/webhook/webhook_system_test.go
index 8aac693995..d0013c6873 100644
--- a/models/webhook/webhook_system_test.go
+++ b/models/webhook/webhook_system_test.go
@@ -12,23 +12,24 @@ import (
"github.com/stretchr/testify/assert"
)
-func TestGetSystemOrDefaultWebhooks(t *testing.T) {
+func TestListSystemWebhookOptions(t *testing.T) {
assert.NoError(t, unittest.PrepareTestDatabase())
-
- hooks, err := GetSystemOrDefaultWebhooks(t.Context(), optional.None[bool]())
+ opts := ListSystemWebhookOptions{IsSystem: optional.None[bool]()}
+ hooks, _, err := GetGlobalWebhooks(t.Context(), &opts)
assert.NoError(t, err)
if assert.Len(t, hooks, 2) {
assert.Equal(t, int64(5), hooks[0].ID)
assert.Equal(t, int64(6), hooks[1].ID)
}
-
- hooks, err = GetSystemOrDefaultWebhooks(t.Context(), optional.Some(true))
+ opts.IsSystem = optional.Some(true)
+ hooks, _, err = GetGlobalWebhooks(t.Context(), &opts)
assert.NoError(t, err)
if assert.Len(t, hooks, 1) {
assert.Equal(t, int64(5), hooks[0].ID)
}
- hooks, err = GetSystemOrDefaultWebhooks(t.Context(), optional.Some(false))
+ opts.IsSystem = optional.Some(false)
+ hooks, _, err = GetGlobalWebhooks(t.Context(), &opts)
assert.NoError(t, err)
if assert.Len(t, hooks, 1) {
assert.Equal(t, int64(6), hooks[0].ID)
diff --git a/modules/actions/artifacts.go b/modules/actions/artifacts.go
index d28726e899..fcf24dbf5f 100644
--- a/modules/actions/artifacts.go
+++ b/modules/actions/artifacts.go
@@ -4,45 +4,82 @@
package actions
import (
+ "crypto/hmac"
+ "crypto/sha256"
+ "encoding/binary"
+ "io"
"net/http"
+ "strings"
actions_model "code.gitea.io/gitea/models/actions"
+ "code.gitea.io/gitea/modules/httplib"
+ "code.gitea.io/gitea/modules/log"
"code.gitea.io/gitea/modules/setting"
"code.gitea.io/gitea/modules/storage"
"code.gitea.io/gitea/services/context"
)
-// Artifacts using the v4 backend are stored as a single combined zip file per artifact on the backend
-// The v4 backend ensures ContentEncoding is set to "application/zip", which is not the case for the old backend
+type tagType string
+
+// BuildSignature builds a hmac signature for the input values.
+// "tag" is an internal pre-defined static string to distinguish the signatures for different purpose.
+func BuildSignature(tag tagType, vals ...string) []byte {
+ m := hmac.New(sha256.New, setting.GetGeneralTokenSigningSecret())
+ _, _ = io.WriteString(m, string(tag))
+ var buf8 [8]byte
+ for _, v := range vals {
+ binary.LittleEndian.PutUint64(buf8[:], uint64(len(v)))
+ _, _ = m.Write(buf8[:])
+ _, _ = io.WriteString(m, v)
+ }
+ return m.Sum(nil)
+}
+
+// IsArtifactV4 detects whether the artifact is likely from v4.
+// V4 backend stores the files as a single combined zip file per artifact, and ensures ContentEncoding contains a slash
+// (otherwise this uses application/zip instead of the custom mime type), which is not the case for the old backend.
func IsArtifactV4(art *actions_model.ActionArtifact) bool {
- return art.ArtifactName+".zip" == art.ArtifactPath && art.ContentEncoding == "application/zip"
+ return strings.Contains(art.ContentEncodingOrType, "/")
}
-func DownloadArtifactV4ServeDirectOnly(ctx *context.Base, art *actions_model.ActionArtifact) (bool, error) {
- if setting.Actions.ArtifactStorage.ServeDirect() {
- u, err := storage.ActionsArtifacts.URL(art.StoragePath, art.ArtifactPath, ctx.Req.Method, nil)
- if u != nil && err == nil {
- ctx.Redirect(u.String(), http.StatusFound)
- return true, nil
- }
+func GetArtifactV4ServeDirectURL(art *actions_model.ActionArtifact, method string) (string, error) {
+ contentType := art.ContentEncodingOrType
+ u, err := storage.ActionsArtifacts.ServeDirectURL(art.StoragePath, art.ArtifactPath, method, &storage.ServeDirectOptions{ContentType: contentType})
+ if err != nil {
+ return "", err
}
- return false, nil
+ return u.String(), nil
}
-func DownloadArtifactV4Fallback(ctx *context.Base, art *actions_model.ActionArtifact) error {
+func DownloadArtifactV4ServeDirect(ctx *context.Base, art *actions_model.ActionArtifact) bool {
+ if !setting.Actions.ArtifactStorage.ServeDirect() {
+ return false
+ }
+ u, err := GetArtifactV4ServeDirectURL(art, ctx.Req.Method)
+ if err != nil {
+ log.Error("GetArtifactV4ServeDirectURL: %v", err)
+ return false
+ }
+ ctx.Redirect(u, http.StatusFound)
+ return true
+}
+
+func DownloadArtifactV4ReadStorage(ctx *context.Base, art *actions_model.ActionArtifact) error {
f, err := storage.ActionsArtifacts.Open(art.StoragePath)
if err != nil {
return err
}
defer f.Close()
- http.ServeContent(ctx.Resp, ctx.Req, art.ArtifactName+".zip", art.CreatedUnix.AsLocalTime(), f)
+ httplib.ServeUserContentByFile(ctx.Req, ctx.Resp, f, httplib.ServeHeaderOptions{
+ Filename: art.ArtifactPath,
+ ContentType: art.ContentEncodingOrType, // v4 guarantees that the field is Content-Type
+ })
return nil
}
func DownloadArtifactV4(ctx *context.Base, art *actions_model.ActionArtifact) error {
- ok, err := DownloadArtifactV4ServeDirectOnly(ctx, art)
- if ok || err != nil {
- return err
+ if DownloadArtifactV4ServeDirect(ctx, art) {
+ return nil
}
- return DownloadArtifactV4Fallback(ctx, art)
+ return DownloadArtifactV4ReadStorage(ctx, art)
}
diff --git a/modules/actions/artifacts_test.go b/modules/actions/artifacts_test.go
new file mode 100644
index 0000000000..4c03843653
--- /dev/null
+++ b/modules/actions/artifacts_test.go
@@ -0,0 +1,36 @@
+// Copyright 2026 The Gitea Authors. All rights reserved.
+// SPDX-License-Identifier: MIT
+
+package actions
+
+import (
+ "testing"
+
+ "github.com/stretchr/testify/assert"
+)
+
+func TestBuildSignature(t *testing.T) {
+ a := BuildSignature("v0", "x")
+ b := BuildSignature("v0", "x")
+ assert.Equal(t, a, b)
+
+ a = BuildSignature("v0", "x", "yz")
+ b = BuildSignature("v0", "xy", "z")
+ assert.NotEqual(t, a, b)
+
+ a = BuildSignature("v1", "x")
+ b = BuildSignature("v2", "x")
+ assert.NotEqual(t, a, b)
+
+ a = BuildSignature("v0", "x")
+ b = BuildSignature("v0x")
+ assert.NotEqual(t, a, b)
+
+ a = BuildSignature("v0", "", "x")
+ b = BuildSignature("v0", "x", "")
+ assert.NotEqual(t, a, b)
+
+ a = BuildSignature("v0")
+ b = BuildSignature("v0")
+ assert.Equal(t, a, b)
+}
diff --git a/modules/actions/github.go b/modules/actions/github.go
index 68116ec83a..b7f475aa91 100644
--- a/modules/actions/github.go
+++ b/modules/actions/github.go
@@ -59,6 +59,10 @@ func IsDefaultBranchWorkflow(triggedEvent webhook_module.HookEventType) bool {
// Github "issues" event
// https://docs.github.com/en/actions/using-workflows/events-that-trigger-workflows#issues
return true
+ case webhook_module.HookEventWorkflowRun:
+ // GitHub "workflow_run" event
+ // https://docs.github.com/en/actions/using-workflows/events-that-trigger-workflows#workflow_run
+ return true
}
return false
diff --git a/modules/actions/jobparser/evaluator.go b/modules/actions/jobparser/evaluator.go
new file mode 100644
index 0000000000..b320095071
--- /dev/null
+++ b/modules/actions/jobparser/evaluator.go
@@ -0,0 +1,189 @@
+// Copyright 2026 The Gitea Authors. All rights reserved.
+// SPDX-License-Identifier: MIT
+
+package jobparser
+
+import (
+ "errors"
+ "fmt"
+ "regexp"
+ "strings"
+
+ "github.com/nektos/act/pkg/exprparser"
+ "go.yaml.in/yaml/v4"
+)
+
+// ExpressionEvaluator is copied from runner.expressionEvaluator,
+// to avoid unnecessary dependencies
+type ExpressionEvaluator struct {
+ interpreter exprparser.Interpreter
+}
+
+func NewExpressionEvaluator(interpreter exprparser.Interpreter) *ExpressionEvaluator {
+ return &ExpressionEvaluator{interpreter: interpreter}
+}
+
+func (ee ExpressionEvaluator) evaluate(in string, defaultStatusCheck exprparser.DefaultStatusCheck) (any, error) {
+ evaluated, err := ee.interpreter.Evaluate(in, defaultStatusCheck)
+
+ return evaluated, err
+}
+
+func (ee ExpressionEvaluator) evaluateScalarYamlNode(node *yaml.Node) error {
+ var in string
+ if err := node.Decode(&in); err != nil {
+ return err
+ }
+ if !strings.Contains(in, "${{") || !strings.Contains(in, "}}") {
+ return nil
+ }
+ expr, _ := rewriteSubExpression(in, false)
+ res, err := ee.evaluate(expr, exprparser.DefaultStatusCheckNone)
+ if err != nil {
+ return err
+ }
+ return node.Encode(res)
+}
+
+func (ee ExpressionEvaluator) evaluateMappingYamlNode(node *yaml.Node) error {
+ // GitHub has this undocumented feature to merge maps, called insert directive
+ insertDirective := regexp.MustCompile(`\${{\s*insert\s*}}`)
+ for i := 0; i < len(node.Content)/2; {
+ k := node.Content[i*2]
+ v := node.Content[i*2+1]
+ if err := ee.EvaluateYamlNode(v); err != nil {
+ return err
+ }
+ var sk string
+ // Merge the nested map of the insert directive
+ if k.Decode(&sk) == nil && insertDirective.MatchString(sk) {
+ node.Content = append(append(node.Content[:i*2], v.Content...), node.Content[(i+1)*2:]...)
+ i += len(v.Content) / 2
+ } else {
+ if err := ee.EvaluateYamlNode(k); err != nil {
+ return err
+ }
+ i++
+ }
+ }
+ return nil
+}
+
+func (ee ExpressionEvaluator) evaluateSequenceYamlNode(node *yaml.Node) error {
+ for i := 0; i < len(node.Content); {
+ v := node.Content[i]
+ // Preserve nested sequences
+ wasseq := v.Kind == yaml.SequenceNode
+ if err := ee.EvaluateYamlNode(v); err != nil {
+ return err
+ }
+ // GitHub has this undocumented feature to merge sequences / arrays
+ // We have a nested sequence via evaluation, merge the arrays
+ if v.Kind == yaml.SequenceNode && !wasseq {
+ node.Content = append(append(node.Content[:i], v.Content...), node.Content[i+1:]...)
+ i += len(v.Content)
+ } else {
+ i++
+ }
+ }
+ return nil
+}
+
+func (ee ExpressionEvaluator) EvaluateYamlNode(node *yaml.Node) error {
+ switch node.Kind {
+ case yaml.ScalarNode:
+ return ee.evaluateScalarYamlNode(node)
+ case yaml.MappingNode:
+ return ee.evaluateMappingYamlNode(node)
+ case yaml.SequenceNode:
+ return ee.evaluateSequenceYamlNode(node)
+ default:
+ return nil
+ }
+}
+
+func (ee ExpressionEvaluator) Interpolate(in string) string {
+ if !strings.Contains(in, "${{") || !strings.Contains(in, "}}") {
+ return in
+ }
+
+ expr, _ := rewriteSubExpression(in, true)
+ evaluated, err := ee.evaluate(expr, exprparser.DefaultStatusCheckNone)
+ if err != nil {
+ return ""
+ }
+
+ value, ok := evaluated.(string)
+ if !ok {
+ panic(fmt.Sprintf("Expression %s did not evaluate to a string", expr))
+ }
+
+ return value
+}
+
+func escapeFormatString(in string) string {
+ return strings.ReplaceAll(strings.ReplaceAll(in, "{", "{{"), "}", "}}")
+}
+
+func rewriteSubExpression(in string, forceFormat bool) (string, error) {
+ if !strings.Contains(in, "${{") || !strings.Contains(in, "}}") {
+ return in, nil
+ }
+
+ strPattern := regexp.MustCompile("(?:''|[^'])*'")
+ pos := 0
+ exprStart := -1
+ strStart := -1
+ var results []string
+ var formatOut strings.Builder
+ for pos < len(in) {
+ if strStart > -1 {
+ matches := strPattern.FindStringIndex(in[pos:])
+ if matches == nil {
+ return "", errors.New("unclosed string")
+ }
+
+ strStart = -1
+ pos += matches[1]
+ } else if exprStart > -1 {
+ exprEnd := strings.Index(in[pos:], "}}")
+ strStart = strings.Index(in[pos:], "'")
+
+ if exprEnd > -1 && strStart > -1 {
+ if exprEnd < strStart {
+ strStart = -1
+ } else {
+ exprEnd = -1
+ }
+ }
+
+ if exprEnd > -1 {
+ fmt.Fprintf(&formatOut, "{%d}", len(results))
+ results = append(results, strings.TrimSpace(in[exprStart:pos+exprEnd]))
+ pos += exprEnd + 2
+ exprStart = -1
+ } else if strStart > -1 {
+ pos += strStart + 1
+ } else {
+ panic("unclosed expression.")
+ }
+ } else {
+ exprStart = strings.Index(in[pos:], "${{")
+ if exprStart != -1 {
+ formatOut.WriteString(escapeFormatString(in[pos : pos+exprStart]))
+ exprStart = pos + exprStart + 3
+ pos = exprStart
+ } else {
+ formatOut.WriteString(escapeFormatString(in[pos:]))
+ pos = len(in)
+ }
+ }
+ }
+
+ if len(results) == 1 && formatOut.String() == "{0}" && !forceFormat {
+ return in, nil
+ }
+
+ out := fmt.Sprintf("format('%s', %s)", strings.ReplaceAll(formatOut.String(), "'", "''"), strings.Join(results, ", "))
+ return out, nil
+}
diff --git a/modules/actions/jobparser/interpeter.go b/modules/actions/jobparser/interpeter.go
new file mode 100644
index 0000000000..512b6f02ab
--- /dev/null
+++ b/modules/actions/jobparser/interpeter.go
@@ -0,0 +1,87 @@
+// Copyright 2026 The Gitea Authors. All rights reserved.
+// SPDX-License-Identifier: MIT
+
+package jobparser
+
+import (
+ "github.com/nektos/act/pkg/exprparser"
+ "github.com/nektos/act/pkg/model"
+ "go.yaml.in/yaml/v4"
+)
+
+// NewInterpeter returns an interpeter used in the server,
+// need github, needs, strategy, matrix, inputs context only,
+// see https://docs.github.com/en/actions/learn-github-actions/contexts#context-availability
+func NewInterpeter(
+ jobID string,
+ job *model.Job,
+ matrix map[string]any,
+ gitCtx *model.GithubContext,
+ results map[string]*JobResult,
+ vars map[string]string,
+ inputs map[string]any,
+) exprparser.Interpreter {
+ strategy := make(map[string]any)
+ if job.Strategy != nil {
+ strategy["fail-fast"] = job.Strategy.FailFast
+ strategy["max-parallel"] = job.Strategy.MaxParallel
+ }
+
+ run := &model.Run{
+ Workflow: &model.Workflow{
+ Jobs: map[string]*model.Job{},
+ },
+ JobID: jobID,
+ }
+ for id, result := range results {
+ need := yaml.Node{}
+ _ = need.Encode(result.Needs)
+ run.Workflow.Jobs[id] = &model.Job{
+ RawNeeds: need,
+ Result: result.Result,
+ Outputs: result.Outputs,
+ }
+ }
+
+ jobs := run.Workflow.Jobs
+ jobNeeds := run.Job().Needs()
+
+ using := map[string]exprparser.Needs{}
+ for _, need := range jobNeeds {
+ if v, ok := jobs[need]; ok {
+ using[need] = exprparser.Needs{
+ Outputs: v.Outputs,
+ Result: v.Result,
+ }
+ }
+ }
+
+ ee := &exprparser.EvaluationEnvironment{
+ Github: gitCtx,
+ Env: nil, // no need
+ Job: nil, // no need
+ Steps: nil, // no need
+ Runner: nil, // no need
+ Secrets: nil, // no need
+ Strategy: strategy,
+ Matrix: matrix,
+ Needs: using,
+ Inputs: inputs,
+ Vars: vars,
+ }
+
+ config := exprparser.Config{
+ Run: run,
+ WorkingDir: "", // WorkingDir is used for the function hashFiles, but it's not needed in the server
+ Context: "job",
+ }
+
+ return exprparser.NewInterpeter(ee, config)
+}
+
+// JobResult is the minimum requirement of job results for Interpeter
+type JobResult struct {
+ Needs []string
+ Result string
+ Outputs map[string]string
+}
diff --git a/modules/actions/jobparser/jobparser.go b/modules/actions/jobparser/jobparser.go
new file mode 100644
index 0000000000..e3a99b95ac
--- /dev/null
+++ b/modules/actions/jobparser/jobparser.go
@@ -0,0 +1,180 @@
+// Copyright 2026 The Gitea Authors. All rights reserved.
+// SPDX-License-Identifier: MIT
+
+package jobparser
+
+import (
+ "bytes"
+ "fmt"
+ "sort"
+ "strings"
+
+ "github.com/nektos/act/pkg/exprparser"
+ "github.com/nektos/act/pkg/model"
+ "go.yaml.in/yaml/v4"
+)
+
+func Parse(content []byte, options ...ParseOption) ([]*SingleWorkflow, error) {
+ origin, err := model.ReadWorkflow(bytes.NewReader(content))
+ if err != nil {
+ return nil, fmt.Errorf("model.ReadWorkflow: %w", err)
+ }
+
+ workflow := &SingleWorkflow{}
+ if err := yaml.Unmarshal(content, workflow); err != nil {
+ return nil, fmt.Errorf("yaml.Unmarshal: %w", err)
+ }
+
+ pc := &parseContext{}
+ for _, o := range options {
+ o(pc)
+ }
+ results := map[string]*JobResult{}
+ for id, job := range origin.Jobs {
+ if job == nil {
+ return nil, fmt.Errorf("needed job not found: %q", id)
+ }
+ results[id] = &JobResult{
+ Needs: job.Needs(),
+ Result: pc.jobResults[id],
+ Outputs: nil, // not supported yet
+ }
+ }
+
+ var ret []*SingleWorkflow
+ ids, jobs, err := workflow.jobs()
+ if err != nil {
+ return nil, fmt.Errorf("invalid jobs: %w", err)
+ }
+
+ evaluator := NewExpressionEvaluator(exprparser.NewInterpeter(&exprparser.EvaluationEnvironment{Github: pc.gitContext, Vars: pc.vars, Inputs: pc.inputs}, exprparser.Config{}))
+ workflow.RunName = evaluator.Interpolate(workflow.RunName)
+
+ for i, id := range ids {
+ job := jobs[i]
+ matricxes, err := getMatrixes(origin.GetJob(id))
+ if err != nil {
+ return nil, fmt.Errorf("getMatrixes: %w", err)
+ }
+ for _, matrix := range matricxes {
+ job := job.Clone()
+ if job.Name == "" {
+ job.Name = id
+ }
+ job.Strategy.RawMatrix = encodeMatrix(matrix)
+ evaluator := NewExpressionEvaluator(NewInterpeter(id, origin.GetJob(id), matrix, pc.gitContext, results, pc.vars, pc.inputs))
+ job.Name = nameWithMatrix(job.Name, matrix, evaluator)
+ runsOn := origin.GetJob(id).RunsOn()
+ for i, v := range runsOn {
+ runsOn[i] = evaluator.Interpolate(v)
+ }
+ job.RawRunsOn = encodeRunsOn(runsOn)
+ swf := &SingleWorkflow{
+ Name: workflow.Name,
+ RawOn: workflow.RawOn,
+ Env: workflow.Env,
+ Defaults: workflow.Defaults,
+ RawPermissions: workflow.RawPermissions,
+ RunName: workflow.RunName,
+ }
+ if err := swf.SetJob(id, job); err != nil {
+ return nil, fmt.Errorf("SetJob: %w", err)
+ }
+ ret = append(ret, swf)
+ }
+ }
+ return ret, nil
+}
+
+func WithJobResults(results map[string]string) ParseOption {
+ return func(c *parseContext) {
+ c.jobResults = results
+ }
+}
+
+func WithGitContext(context *model.GithubContext) ParseOption {
+ return func(c *parseContext) {
+ c.gitContext = context
+ }
+}
+
+func WithVars(vars map[string]string) ParseOption {
+ return func(c *parseContext) {
+ c.vars = vars
+ }
+}
+
+func WithInputs(inputs map[string]any) ParseOption {
+ return func(c *parseContext) {
+ c.inputs = inputs
+ }
+}
+
+type parseContext struct {
+ jobResults map[string]string
+ gitContext *model.GithubContext
+ vars map[string]string
+ inputs map[string]any
+}
+
+type ParseOption func(c *parseContext)
+
+func getMatrixes(job *model.Job) ([]map[string]any, error) {
+ ret, err := job.GetMatrixes()
+ if err != nil {
+ return nil, fmt.Errorf("GetMatrixes: %w", err)
+ }
+ sort.Slice(ret, func(i, j int) bool {
+ return matrixName(ret[i]) < matrixName(ret[j])
+ })
+ return ret, nil
+}
+
+func encodeMatrix(matrix map[string]any) yaml.Node {
+ if len(matrix) == 0 {
+ return yaml.Node{}
+ }
+ value := map[string][]any{}
+ for k, v := range matrix {
+ value[k] = []any{v}
+ }
+ node := yaml.Node{}
+ _ = node.Encode(value)
+ return node
+}
+
+func encodeRunsOn(runsOn []string) yaml.Node {
+ node := yaml.Node{}
+ if len(runsOn) == 1 {
+ _ = node.Encode(runsOn[0])
+ } else {
+ _ = node.Encode(runsOn)
+ }
+ return node
+}
+
+func nameWithMatrix(name string, m map[string]any, evaluator *ExpressionEvaluator) string {
+ if len(m) == 0 {
+ return name
+ }
+
+ if !strings.Contains(name, "${{") || !strings.Contains(name, "}}") {
+ return name + " " + matrixName(m)
+ }
+
+ return evaluator.Interpolate(name)
+}
+
+func matrixName(m map[string]any) string {
+ ks := make([]string, 0, len(m))
+ for k := range m {
+ ks = append(ks, k)
+ }
+ sort.Strings(ks)
+ vs := make([]string, 0, len(m))
+ for _, v := range ks {
+ vs = append(vs, fmt.Sprint(m[v]))
+ }
+
+ return fmt.Sprintf("(%s)", strings.Join(vs, ", "))
+}
diff --git a/modules/actions/jobparser/jobparser_test.go b/modules/actions/jobparser/jobparser_test.go
new file mode 100644
index 0000000000..e74f0644f8
--- /dev/null
+++ b/modules/actions/jobparser/jobparser_test.go
@@ -0,0 +1,104 @@
+// Copyright 2026 The Gitea Authors. All rights reserved.
+// SPDX-License-Identifier: MIT
+
+package jobparser
+
+import (
+ "strings"
+ "testing"
+
+ "github.com/stretchr/testify/assert"
+ "github.com/stretchr/testify/require"
+ "go.yaml.in/yaml/v4"
+)
+
+func TestParse(t *testing.T) {
+ tests := []struct {
+ name string
+ options []ParseOption
+ wantErr bool
+ }{
+ {
+ name: "multiple_jobs",
+ options: nil,
+ wantErr: false,
+ },
+ {
+ name: "multiple_matrix",
+ options: nil,
+ wantErr: false,
+ },
+ {
+ name: "has_needs",
+ options: nil,
+ wantErr: false,
+ },
+ {
+ name: "has_with",
+ options: nil,
+ wantErr: false,
+ },
+ {
+ name: "has_secrets",
+ options: nil,
+ wantErr: false,
+ },
+ {
+ name: "empty_step",
+ options: nil,
+ wantErr: false,
+ },
+ {
+ name: "job_name_with_matrix",
+ options: nil,
+ wantErr: false,
+ },
+ {
+ name: "prefixed_newline",
+ options: nil,
+ wantErr: false,
+ },
+ }
+ invalidFileTests := []struct {
+ name string
+ }{
+ {name: "null_job_implicit"},
+ {name: "null_job_explicit"},
+ }
+
+ for _, tt := range tests {
+ t.Run(tt.name, func(t *testing.T) {
+ content := ReadTestdata(t, tt.name+".in.yaml")
+ want := ReadTestdata(t, tt.name+".out.yaml")
+ got, err := Parse(content, tt.options...)
+ if tt.wantErr {
+ require.Error(t, err)
+ }
+ require.NoError(t, err)
+
+ builder := &strings.Builder{}
+ for _, v := range got {
+ if builder.Len() > 0 {
+ builder.WriteString("---\n")
+ }
+ encoder := yaml.NewEncoder(builder)
+ encoder.SetIndent(2)
+ require.NoError(t, encoder.Encode(v))
+ id, job := v.Job()
+ assert.NotEmpty(t, id)
+ assert.NotNil(t, job)
+ }
+ assert.Equal(t, string(want), builder.String())
+ })
+ }
+
+ for _, tt := range invalidFileTests {
+ t.Run(tt.name, func(t *testing.T) {
+ content := ReadTestdata(t, tt.name+".in.yaml")
+ require.NotPanics(t, func() {
+ _, err := Parse(content)
+ require.Error(t, err)
+ })
+ })
+ }
+}
diff --git a/modules/actions/jobparser/model.go b/modules/actions/jobparser/model.go
new file mode 100644
index 0000000000..7132c278e9
--- /dev/null
+++ b/modules/actions/jobparser/model.go
@@ -0,0 +1,497 @@
+// Copyright 2026 The Gitea Authors. All rights reserved.
+// SPDX-License-Identifier: MIT
+
+package jobparser
+
+import (
+ "bytes"
+ "errors"
+ "fmt"
+
+ "github.com/nektos/act/pkg/model"
+ "go.yaml.in/yaml/v4"
+)
+
+// SingleWorkflow is a workflow with single job and single matrix
+type SingleWorkflow struct {
+ Name string `yaml:"name,omitempty"`
+ RawOn yaml.Node `yaml:"on,omitempty"`
+ Env map[string]string `yaml:"env,omitempty"`
+ RawJobs yaml.Node `yaml:"jobs,omitempty"`
+ Defaults Defaults `yaml:"defaults,omitempty"`
+ RawPermissions yaml.Node `yaml:"permissions,omitempty"`
+ RunName string `yaml:"run-name,omitempty"`
+}
+
+func (w *SingleWorkflow) Job() (string, *Job) {
+ ids, jobs, _ := w.jobs()
+ if len(ids) >= 1 {
+ return ids[0], jobs[0]
+ }
+ return "", nil
+}
+
+func (w *SingleWorkflow) jobs() ([]string, []*Job, error) {
+ ids, jobs, err := parseMappingNode[*Job](&w.RawJobs)
+ if err != nil {
+ return nil, nil, err
+ }
+
+ for _, job := range jobs {
+ steps := make([]*Step, 0, len(job.Steps))
+ for _, s := range job.Steps {
+ if s != nil {
+ steps = append(steps, s)
+ }
+ }
+ job.Steps = steps
+ }
+
+ return ids, jobs, nil
+}
+
+func (w *SingleWorkflow) SetJob(id string, job *Job) error {
+ m := map[string]*Job{
+ id: job,
+ }
+ var buf bytes.Buffer
+ encoder := yaml.NewEncoder(&buf)
+ encoder.SetIndent(2)
+ if err := encoder.Encode(m); err != nil {
+ return err
+ }
+ encoder.Close()
+
+ node := yaml.Node{}
+ if err := yaml.Unmarshal(buf.Bytes(), &node); err != nil {
+ return err
+ }
+ if len(node.Content) != 1 || node.Content[0].Kind != yaml.MappingNode {
+ return fmt.Errorf("can not set job: %s", buf.String())
+ }
+ w.RawJobs = *node.Content[0]
+ return nil
+}
+
+func (w *SingleWorkflow) Marshal() ([]byte, error) {
+ return yaml.Marshal(w)
+}
+
+type Job struct {
+ Name string `yaml:"name,omitempty"`
+ RawNeeds yaml.Node `yaml:"needs,omitempty"`
+ RawRunsOn yaml.Node `yaml:"runs-on,omitempty"`
+ Env yaml.Node `yaml:"env,omitempty"`
+ If yaml.Node `yaml:"if,omitempty"`
+ Steps []*Step `yaml:"steps,omitempty"`
+ TimeoutMinutes string `yaml:"timeout-minutes,omitempty"`
+ Services map[string]*ContainerSpec `yaml:"services,omitempty"`
+ Strategy Strategy `yaml:"strategy,omitempty"`
+ RawContainer yaml.Node `yaml:"container,omitempty"`
+ Defaults Defaults `yaml:"defaults,omitempty"`
+ Outputs map[string]string `yaml:"outputs,omitempty"`
+ Uses string `yaml:"uses,omitempty"`
+ With map[string]any `yaml:"with,omitempty"`
+ RawSecrets yaml.Node `yaml:"secrets,omitempty"`
+ RawConcurrency *model.RawConcurrency `yaml:"concurrency,omitempty"`
+ RawPermissions yaml.Node `yaml:"permissions,omitempty"`
+}
+
+func (j *Job) Clone() *Job {
+ if j == nil {
+ return nil
+ }
+ return &Job{
+ Name: j.Name,
+ RawNeeds: j.RawNeeds,
+ RawRunsOn: j.RawRunsOn,
+ Env: j.Env,
+ If: j.If,
+ Steps: j.Steps,
+ TimeoutMinutes: j.TimeoutMinutes,
+ Services: j.Services,
+ Strategy: j.Strategy,
+ RawContainer: j.RawContainer,
+ Defaults: j.Defaults,
+ Outputs: j.Outputs,
+ Uses: j.Uses,
+ With: j.With,
+ RawSecrets: j.RawSecrets,
+ RawConcurrency: j.RawConcurrency,
+ RawPermissions: j.RawPermissions,
+ }
+}
+
+func (j *Job) Needs() []string {
+ return (&model.Job{RawNeeds: j.RawNeeds}).Needs()
+}
+
+func (j *Job) EraseNeeds() *Job {
+ j.RawNeeds = yaml.Node{}
+ return j
+}
+
+func (j *Job) RunsOn() []string {
+ return (&model.Job{RawRunsOn: j.RawRunsOn}).RunsOn()
+}
+
+type Step struct {
+ ID string `yaml:"id,omitempty"`
+ If yaml.Node `yaml:"if,omitempty"`
+ Name string `yaml:"name,omitempty"`
+ Uses string `yaml:"uses,omitempty"`
+ Run string `yaml:"run,omitempty"`
+ WorkingDirectory string `yaml:"working-directory,omitempty"`
+ Shell string `yaml:"shell,omitempty"`
+ Env yaml.Node `yaml:"env,omitempty"`
+ With map[string]string `yaml:"with,omitempty"`
+ ContinueOnError bool `yaml:"continue-on-error,omitempty"`
+ TimeoutMinutes string `yaml:"timeout-minutes,omitempty"`
+}
+
+// String gets the name of step
+func (s *Step) String() string {
+ if s == nil {
+ return ""
+ }
+ return (&model.Step{
+ ID: s.ID,
+ Name: s.Name,
+ Uses: s.Uses,
+ Run: s.Run,
+ }).String()
+}
+
+type ContainerSpec struct {
+ Image string `yaml:"image,omitempty"`
+ Env map[string]string `yaml:"env,omitempty"`
+ Ports []string `yaml:"ports,omitempty"`
+ Volumes []string `yaml:"volumes,omitempty"`
+ Options string `yaml:"options,omitempty"`
+ Credentials map[string]string `yaml:"credentials,omitempty"`
+ Cmd []string `yaml:"cmd,omitempty"`
+}
+
+type Strategy struct {
+ FailFastString string `yaml:"fail-fast,omitempty"`
+ MaxParallelString string `yaml:"max-parallel,omitempty"`
+ RawMatrix yaml.Node `yaml:"matrix,omitempty"`
+}
+
+type Defaults struct {
+ Run RunDefaults `yaml:"run,omitempty"`
+}
+
+type RunDefaults struct {
+ Shell string `yaml:"shell,omitempty"`
+ WorkingDirectory string `yaml:"working-directory,omitempty"`
+}
+
+type WorkflowDispatchInput struct {
+ Name string `yaml:"name"`
+ Description string `yaml:"description"`
+ Required bool `yaml:"required"`
+ Default string `yaml:"default"`
+ Type string `yaml:"type"`
+ Options []string `yaml:"options"`
+}
+
+type Event struct {
+ Name string
+ acts map[string][]string
+ schedules []map[string]string
+ inputs []WorkflowDispatchInput
+}
+
+func (evt *Event) IsSchedule() bool {
+ return evt.schedules != nil
+}
+
+func (evt *Event) Acts() map[string][]string {
+ return evt.acts
+}
+
+func (evt *Event) Schedules() []map[string]string {
+ return evt.schedules
+}
+
+func (evt *Event) Inputs() []WorkflowDispatchInput {
+ return evt.inputs
+}
+
+func ReadWorkflowRawConcurrency(content []byte) (*model.RawConcurrency, error) {
+ w := new(model.Workflow)
+ err := yaml.NewDecoder(bytes.NewReader(content)).Decode(w)
+ return w.RawConcurrency, err
+}
+
+func EvaluateConcurrency(rc *model.RawConcurrency, jobID string, job *Job, gitCtx map[string]any, results map[string]*JobResult, vars map[string]string, inputs map[string]any) (string, bool, error) {
+ actJob := &model.Job{}
+ if job != nil {
+ actJob.Strategy = &model.Strategy{
+ FailFastString: job.Strategy.FailFastString,
+ MaxParallelString: job.Strategy.MaxParallelString,
+ RawMatrix: job.Strategy.RawMatrix,
+ }
+ actJob.Strategy.FailFast = actJob.Strategy.GetFailFast()
+ actJob.Strategy.MaxParallel = actJob.Strategy.GetMaxParallel()
+ }
+
+ matrix := make(map[string]any)
+ matrixes, err := actJob.GetMatrixes()
+ if err != nil {
+ return "", false, err
+ }
+ if len(matrixes) > 0 {
+ matrix = matrixes[0]
+ }
+
+ evaluator := NewExpressionEvaluator(NewInterpeter(jobID, actJob, matrix, toGitContext(gitCtx), results, vars, inputs))
+ var node yaml.Node
+ if err := node.Encode(rc); err != nil {
+ return "", false, fmt.Errorf("failed to encode concurrency: %w", err)
+ }
+ if err := evaluator.EvaluateYamlNode(&node); err != nil {
+ return "", false, fmt.Errorf("failed to evaluate concurrency: %w", err)
+ }
+ var evaluated model.RawConcurrency
+ if err := node.Decode(&evaluated); err != nil {
+ return "", false, fmt.Errorf("failed to unmarshal evaluated concurrency: %w", err)
+ }
+ if evaluated.RawExpression != "" {
+ return evaluated.RawExpression, false, nil
+ }
+ return evaluated.Group, evaluated.CancelInProgress == "true", nil
+}
+
+func toGitContext(input map[string]any) *model.GithubContext {
+ gitContext := &model.GithubContext{
+ EventPath: asString(input["event_path"]),
+ Workflow: asString(input["workflow"]),
+ RunID: asString(input["run_id"]),
+ RunNumber: asString(input["run_number"]),
+ Actor: asString(input["actor"]),
+ Repository: asString(input["repository"]),
+ EventName: asString(input["event_name"]),
+ Sha: asString(input["sha"]),
+ Ref: asString(input["ref"]),
+ RefName: asString(input["ref_name"]),
+ RefType: asString(input["ref_type"]),
+ HeadRef: asString(input["head_ref"]),
+ BaseRef: asString(input["base_ref"]),
+ Token: asString(input["token"]),
+ Workspace: asString(input["workspace"]),
+ Action: asString(input["action"]),
+ ActionPath: asString(input["action_path"]),
+ ActionRef: asString(input["action_ref"]),
+ ActionRepository: asString(input["action_repository"]),
+ Job: asString(input["job"]),
+ RepositoryOwner: asString(input["repository_owner"]),
+ RetentionDays: asString(input["retention_days"]),
+ }
+
+ event, ok := input["event"].(map[string]any)
+ if ok {
+ gitContext.Event = event
+ }
+
+ return gitContext
+}
+
+func ParseRawOn(rawOn *yaml.Node) ([]*Event, error) {
+ switch rawOn.Kind {
+ case yaml.ScalarNode:
+ var val string
+ err := rawOn.Decode(&val)
+ if err != nil {
+ return nil, err
+ }
+ return []*Event{
+ {Name: val},
+ }, nil
+ case yaml.SequenceNode:
+ var val []any
+ err := rawOn.Decode(&val)
+ if err != nil {
+ return nil, err
+ }
+ res := make([]*Event, 0, len(val))
+ for _, v := range val {
+ switch t := v.(type) {
+ case string:
+ res = append(res, &Event{Name: t})
+ default:
+ return nil, fmt.Errorf("invalid type %T", t)
+ }
+ }
+ return res, nil
+ case yaml.MappingNode:
+ events, triggers, err := parseMappingNode[yaml.Node](rawOn)
+ if err != nil {
+ return nil, err
+ }
+ res := make([]*Event, 0, len(events))
+ for i, k := range events {
+ v := triggers[i]
+ switch v.Kind {
+ case yaml.ScalarNode:
+ res = append(res, &Event{
+ Name: k,
+ })
+ case yaml.SequenceNode:
+ var t []any
+ err := v.Decode(&t)
+ if err != nil {
+ return nil, err
+ }
+ schedules := make([]map[string]string, len(t))
+ if k == "schedule" {
+ for i, tt := range t {
+ vv, ok := tt.(map[string]any)
+ if !ok {
+ return nil, fmt.Errorf("unknown on type(schedule): %#v", v)
+ }
+ schedules[i] = make(map[string]string, len(vv))
+ for k, vvv := range vv {
+ var ok bool
+ if schedules[i][k], ok = vvv.(string); !ok {
+ return nil, fmt.Errorf("unknown on type(schedule): %#v", v)
+ }
+ }
+ }
+ }
+
+ if len(schedules) == 0 {
+ schedules = nil
+ }
+ res = append(res, &Event{
+ Name: k,
+ schedules: schedules,
+ })
+ case yaml.MappingNode:
+ acts := make(map[string][]string, len(v.Content)/2)
+ var inputs []WorkflowDispatchInput
+ expectedKey := true
+ var act string
+ for _, content := range v.Content {
+ if expectedKey {
+ if content.Kind != yaml.ScalarNode {
+ return nil, fmt.Errorf("key type not string: %#v", content)
+ }
+ act = ""
+ err := content.Decode(&act)
+ if err != nil {
+ return nil, err
+ }
+ } else {
+ switch content.Kind {
+ case yaml.SequenceNode:
+ var t []string
+ err := content.Decode(&t)
+ if err != nil {
+ return nil, err
+ }
+ acts[act] = t
+ case yaml.ScalarNode:
+ var t string
+ err := content.Decode(&t)
+ if err != nil {
+ return nil, err
+ }
+ acts[act] = []string{t}
+ case yaml.MappingNode:
+ if k != "workflow_dispatch" || act != "inputs" {
+ return nil, fmt.Errorf("map should only for workflow_dispatch but %s: %#v", act, content)
+ }
+
+ var key string
+ for i, vv := range content.Content {
+ if i%2 == 0 {
+ if vv.Kind != yaml.ScalarNode {
+ return nil, fmt.Errorf("key type not string: %#v", vv)
+ }
+ key = ""
+ if err := vv.Decode(&key); err != nil {
+ return nil, err
+ }
+ } else {
+ if vv.Kind != yaml.MappingNode {
+ return nil, fmt.Errorf("key type not map(%s): %#v", key, vv)
+ }
+
+ input := WorkflowDispatchInput{}
+ if err := vv.Decode(&input); err != nil {
+ return nil, err
+ }
+ input.Name = key
+ inputs = append(inputs, input)
+ }
+ }
+ default:
+ return nil, fmt.Errorf("unknown on type: %#v", content)
+ }
+ }
+ expectedKey = !expectedKey
+ }
+ if len(inputs) == 0 {
+ inputs = nil
+ }
+ if len(acts) == 0 {
+ acts = nil
+ }
+ res = append(res, &Event{
+ Name: k,
+ acts: acts,
+ inputs: inputs,
+ })
+ default:
+ return nil, fmt.Errorf("unknown on type: %v", v.Kind)
+ }
+ }
+ return res, nil
+ default:
+ return nil, fmt.Errorf("unknown on type: %v", rawOn.Kind)
+ }
+}
+
+// parseMappingNode parse a mapping node and preserve order.
+func parseMappingNode[T any](node *yaml.Node) ([]string, []T, error) {
+ if node.Kind != yaml.MappingNode {
+ return nil, nil, errors.New("input node is not a mapping node")
+ }
+
+ var scalars []string
+ var datas []T
+ expectKey := true
+ for _, item := range node.Content {
+ if expectKey {
+ if item.Kind != yaml.ScalarNode {
+ return nil, nil, fmt.Errorf("not a valid scalar node: %v", item.Value)
+ }
+ scalars = append(scalars, item.Value)
+ expectKey = false
+ } else {
+ var val T
+ if err := item.Decode(&val); err != nil {
+ return nil, nil, err
+ }
+ datas = append(datas, val)
+ expectKey = true
+ }
+ }
+
+ if len(scalars) != len(datas) {
+ return nil, nil, fmt.Errorf("invalid definition of on: %v", node.Value)
+ }
+
+ return scalars, datas, nil
+}
+
+func asString(v any) string {
+ if v == nil {
+ return ""
+ } else if s, ok := v.(string); ok {
+ return s
+ }
+ return ""
+}
diff --git a/modules/actions/jobparser/model_test.go b/modules/actions/jobparser/model_test.go
new file mode 100644
index 0000000000..d0e8204161
--- /dev/null
+++ b/modules/actions/jobparser/model_test.go
@@ -0,0 +1,373 @@
+// Copyright 2026 The Gitea Authors. All rights reserved.
+// SPDX-License-Identifier: MIT
+
+package jobparser
+
+import (
+ "strings"
+ "testing"
+
+ "github.com/nektos/act/pkg/model"
+ "github.com/stretchr/testify/assert"
+ "github.com/stretchr/testify/require"
+ "go.yaml.in/yaml/v4"
+)
+
+func TestParseRawOn(t *testing.T) {
+ kases := []struct {
+ input string
+ result []*Event
+ }{
+ {
+ input: "on: issue_comment",
+ result: []*Event{
+ {
+ Name: "issue_comment",
+ },
+ },
+ },
+ {
+ input: "on:\n push",
+ result: []*Event{
+ {
+ Name: "push",
+ },
+ },
+ },
+
+ {
+ input: "on:\n - push\n - pull_request",
+ result: []*Event{
+ {
+ Name: "push",
+ },
+ {
+ Name: "pull_request",
+ },
+ },
+ },
+ {
+ input: "on:\n push:\n branches:\n - master",
+ result: []*Event{
+ {
+ Name: "push",
+ acts: map[string][]string{
+ "branches": {
+ "master",
+ },
+ },
+ },
+ },
+ },
+ {
+ input: "on:\n push:\n branches: main",
+ result: []*Event{
+ {
+ Name: "push",
+ acts: map[string][]string{
+ "branches": {
+ "main",
+ },
+ },
+ },
+ },
+ },
+ {
+ input: "on:\n branch_protection_rule:\n types: [created, deleted]",
+ result: []*Event{
+ {
+ Name: "branch_protection_rule",
+ acts: map[string][]string{
+ "types": {
+ "created",
+ "deleted",
+ },
+ },
+ },
+ },
+ },
+ {
+ input: "on:\n project:\n types: [created, deleted]\n milestone:\n types: [opened, deleted]",
+ result: []*Event{
+ {
+ Name: "project",
+ acts: map[string][]string{
+ "types": {
+ "created",
+ "deleted",
+ },
+ },
+ },
+ {
+ Name: "milestone",
+ acts: map[string][]string{
+ "types": {
+ "opened",
+ "deleted",
+ },
+ },
+ },
+ },
+ },
+ {
+ input: "on:\n pull_request:\n types:\n - opened\n branches:\n - 'releases/**'",
+ result: []*Event{
+ {
+ Name: "pull_request",
+ acts: map[string][]string{
+ "types": {
+ "opened",
+ },
+ "branches": {
+ "releases/**",
+ },
+ },
+ },
+ },
+ },
+ {
+ input: "on:\n push:\n branches:\n - main\n pull_request:\n types:\n - opened\n branches:\n - '**'",
+ result: []*Event{
+ {
+ Name: "push",
+ acts: map[string][]string{
+ "branches": {
+ "main",
+ },
+ },
+ },
+ {
+ Name: "pull_request",
+ acts: map[string][]string{
+ "types": {
+ "opened",
+ },
+ "branches": {
+ "**",
+ },
+ },
+ },
+ },
+ },
+ {
+ input: "on:\n push:\n branches:\n - 'main'\n - 'releases/**'",
+ result: []*Event{
+ {
+ Name: "push",
+ acts: map[string][]string{
+ "branches": {
+ "main",
+ "releases/**",
+ },
+ },
+ },
+ },
+ },
+ {
+ input: "on:\n push:\n tags:\n - v1.**",
+ result: []*Event{
+ {
+ Name: "push",
+ acts: map[string][]string{
+ "tags": {
+ "v1.**",
+ },
+ },
+ },
+ },
+ },
+ {
+ input: "on: [pull_request, workflow_dispatch]",
+ result: []*Event{
+ {
+ Name: "pull_request",
+ },
+ {
+ Name: "workflow_dispatch",
+ },
+ },
+ },
+ {
+ input: "on:\n schedule:\n - cron: '20 6 * * *'",
+ result: []*Event{
+ {
+ Name: "schedule",
+ schedules: []map[string]string{
+ {
+ "cron": "20 6 * * *",
+ },
+ },
+ },
+ },
+ },
+ {
+ input: `on:
+ workflow_dispatch:
+ inputs:
+ logLevel:
+ description: 'Log level'
+ required: true
+ default: 'warning'
+ type: choice
+ options:
+ - info
+ - warning
+ - debug
+ tags:
+ description: 'Test scenario tags'
+ required: false
+ type: boolean
+ environment:
+ description: 'Environment to run tests against'
+ type: environment
+ required: true
+ push:
+`,
+ result: []*Event{
+ {
+ Name: "workflow_dispatch",
+ inputs: []WorkflowDispatchInput{
+ {
+ Name: "logLevel",
+ Description: "Log level",
+ Required: true,
+ Default: "warning",
+ Type: "choice",
+ Options: []string{"info", "warning", "debug"},
+ },
+ {
+ Name: "tags",
+ Description: "Test scenario tags",
+ Required: false,
+ Type: "boolean",
+ },
+ {
+ Name: "environment",
+ Description: "Environment to run tests against",
+ Type: "environment",
+ Required: true,
+ },
+ },
+ },
+ {
+ Name: "push",
+ },
+ },
+ },
+ }
+ for _, kase := range kases {
+ t.Run(kase.input, func(t *testing.T) {
+ origin, err := model.ReadWorkflow(strings.NewReader(kase.input))
+ assert.NoError(t, err)
+
+ events, err := ParseRawOn(&origin.RawOn)
+ assert.NoError(t, err)
+ assert.Equal(t, kase.result, events, events)
+ })
+ }
+}
+
+func TestSingleWorkflow_SetJob(t *testing.T) {
+ t.Run("erase needs", func(t *testing.T) {
+ content := ReadTestdata(t, "erase_needs.in.yaml")
+ want := ReadTestdata(t, "erase_needs.out.yaml")
+ swf, err := Parse(content)
+ require.NoError(t, err)
+ builder := &strings.Builder{}
+ for _, v := range swf {
+ id, job := v.Job()
+ require.NoError(t, v.SetJob(id, job.EraseNeeds()))
+
+ if builder.Len() > 0 {
+ builder.WriteString("---\n")
+ }
+ encoder := yaml.NewEncoder(builder)
+ encoder.SetIndent(2)
+ require.NoError(t, encoder.Encode(v))
+ }
+ assert.Equal(t, string(want), builder.String())
+ })
+}
+
+func TestParseMappingNode(t *testing.T) {
+ tests := []struct {
+ input string
+ scalars []string
+ datas []any
+ }{
+ {
+ input: "on:\n push:\n branches:\n - master",
+ scalars: []string{"push"},
+ datas: []any{
+ map[string]any{
+ "branches": []any{"master"},
+ },
+ },
+ },
+ {
+ input: "on:\n branch_protection_rule:\n types: [created, deleted]",
+ scalars: []string{"branch_protection_rule"},
+ datas: []any{
+ map[string]any{
+ "types": []any{"created", "deleted"},
+ },
+ },
+ },
+ {
+ input: "on:\n project:\n types: [created, deleted]\n milestone:\n types: [opened, deleted]",
+ scalars: []string{"project", "milestone"},
+ datas: []any{
+ map[string]any{
+ "types": []any{"created", "deleted"},
+ },
+ map[string]any{
+ "types": []any{"opened", "deleted"},
+ },
+ },
+ },
+ {
+ input: "on:\n pull_request:\n types:\n - opened\n branches:\n - 'releases/**'",
+ scalars: []string{"pull_request"},
+ datas: []any{
+ map[string]any{
+ "types": []any{"opened"},
+ "branches": []any{"releases/**"},
+ },
+ },
+ },
+ {
+ input: "on:\n push:\n branches:\n - main\n pull_request:\n types:\n - opened\n branches:\n - '**'",
+ scalars: []string{"push", "pull_request"},
+ datas: []any{
+ map[string]any{
+ "branches": []any{"main"},
+ },
+ map[string]any{
+ "types": []any{"opened"},
+ "branches": []any{"**"},
+ },
+ },
+ },
+ {
+ input: "on:\n schedule:\n - cron: '20 6 * * *'",
+ scalars: []string{"schedule"},
+ datas: []any{
+ []any{map[string]any{
+ "cron": "20 6 * * *",
+ }},
+ },
+ },
+ }
+
+ for _, test := range tests {
+ t.Run(test.input, func(t *testing.T) {
+ workflow, err := model.ReadWorkflow(strings.NewReader(test.input))
+ assert.NoError(t, err)
+
+ scalars, datas, err := parseMappingNode[any](&workflow.RawOn)
+ assert.NoError(t, err)
+ assert.Equal(t, test.scalars, scalars, scalars)
+ assert.Equal(t, test.datas, datas, datas)
+ })
+ }
+}
diff --git a/modules/actions/jobparser/testdata/empty_step.in.yaml b/modules/actions/jobparser/testdata/empty_step.in.yaml
new file mode 100644
index 0000000000..737ac0b2c6
--- /dev/null
+++ b/modules/actions/jobparser/testdata/empty_step.in.yaml
@@ -0,0 +1,8 @@
+name: test
+jobs:
+ job1:
+ name: job1
+ runs-on: linux
+ steps:
+ - run: echo job-1
+ -
diff --git a/modules/actions/jobparser/testdata/empty_step.out.yaml b/modules/actions/jobparser/testdata/empty_step.out.yaml
new file mode 100644
index 0000000000..06828e0ed7
--- /dev/null
+++ b/modules/actions/jobparser/testdata/empty_step.out.yaml
@@ -0,0 +1,7 @@
+name: test
+jobs:
+ job1:
+ name: job1
+ runs-on: linux
+ steps:
+ - run: echo job-1
diff --git a/modules/actions/jobparser/testdata/erase_needs.in.yaml b/modules/actions/jobparser/testdata/erase_needs.in.yaml
new file mode 100644
index 0000000000..a7d1f9b631
--- /dev/null
+++ b/modules/actions/jobparser/testdata/erase_needs.in.yaml
@@ -0,0 +1,16 @@
+name: test
+jobs:
+ job1:
+ runs-on: linux
+ steps:
+ - run: uname -a
+ job2:
+ runs-on: linux
+ steps:
+ - run: uname -a
+ needs: job1
+ job3:
+ runs-on: linux
+ steps:
+ - run: uname -a
+ needs: [job1, job2]
diff --git a/modules/actions/jobparser/testdata/erase_needs.out.yaml b/modules/actions/jobparser/testdata/erase_needs.out.yaml
new file mode 100644
index 0000000000..959960d62d
--- /dev/null
+++ b/modules/actions/jobparser/testdata/erase_needs.out.yaml
@@ -0,0 +1,23 @@
+name: test
+jobs:
+ job1:
+ name: job1
+ runs-on: linux
+ steps:
+ - run: uname -a
+---
+name: test
+jobs:
+ job2:
+ name: job2
+ runs-on: linux
+ steps:
+ - run: uname -a
+---
+name: test
+jobs:
+ job3:
+ name: job3
+ runs-on: linux
+ steps:
+ - run: uname -a
diff --git a/modules/actions/jobparser/testdata/has_needs.in.yaml b/modules/actions/jobparser/testdata/has_needs.in.yaml
new file mode 100644
index 0000000000..a7d1f9b631
--- /dev/null
+++ b/modules/actions/jobparser/testdata/has_needs.in.yaml
@@ -0,0 +1,16 @@
+name: test
+jobs:
+ job1:
+ runs-on: linux
+ steps:
+ - run: uname -a
+ job2:
+ runs-on: linux
+ steps:
+ - run: uname -a
+ needs: job1
+ job3:
+ runs-on: linux
+ steps:
+ - run: uname -a
+ needs: [job1, job2]
diff --git a/modules/actions/jobparser/testdata/has_needs.out.yaml b/modules/actions/jobparser/testdata/has_needs.out.yaml
new file mode 100644
index 0000000000..a544aa2223
--- /dev/null
+++ b/modules/actions/jobparser/testdata/has_needs.out.yaml
@@ -0,0 +1,25 @@
+name: test
+jobs:
+ job1:
+ name: job1
+ runs-on: linux
+ steps:
+ - run: uname -a
+---
+name: test
+jobs:
+ job2:
+ name: job2
+ needs: job1
+ runs-on: linux
+ steps:
+ - run: uname -a
+---
+name: test
+jobs:
+ job3:
+ name: job3
+ needs: [job1, job2]
+ runs-on: linux
+ steps:
+ - run: uname -a
diff --git a/modules/actions/jobparser/testdata/has_secrets.in.yaml b/modules/actions/jobparser/testdata/has_secrets.in.yaml
new file mode 100644
index 0000000000..64b9f69f08
--- /dev/null
+++ b/modules/actions/jobparser/testdata/has_secrets.in.yaml
@@ -0,0 +1,14 @@
+name: test
+jobs:
+ job1:
+ name: job1
+ runs-on: linux
+ uses: .gitea/workflows/build.yml
+ secrets:
+ secret: hideme
+
+ job2:
+ name: job2
+ runs-on: linux
+ uses: .gitea/workflows/build.yml
+ secrets: inherit
diff --git a/modules/actions/jobparser/testdata/has_secrets.out.yaml b/modules/actions/jobparser/testdata/has_secrets.out.yaml
new file mode 100644
index 0000000000..23dfb80367
--- /dev/null
+++ b/modules/actions/jobparser/testdata/has_secrets.out.yaml
@@ -0,0 +1,16 @@
+name: test
+jobs:
+ job1:
+ name: job1
+ runs-on: linux
+ uses: .gitea/workflows/build.yml
+ secrets:
+ secret: hideme
+---
+name: test
+jobs:
+ job2:
+ name: job2
+ runs-on: linux
+ uses: .gitea/workflows/build.yml
+ secrets: inherit
diff --git a/modules/actions/jobparser/testdata/has_with.in.yaml b/modules/actions/jobparser/testdata/has_with.in.yaml
new file mode 100644
index 0000000000..4e3dc7451c
--- /dev/null
+++ b/modules/actions/jobparser/testdata/has_with.in.yaml
@@ -0,0 +1,15 @@
+name: test
+jobs:
+ job1:
+ name: job1
+ runs-on: linux
+ uses: .gitea/workflows/build.yml
+ with:
+ package: service
+
+ job2:
+ name: job2
+ runs-on: linux
+ uses: .gitea/workflows/build.yml
+ with:
+ package: module
diff --git a/modules/actions/jobparser/testdata/has_with.out.yaml b/modules/actions/jobparser/testdata/has_with.out.yaml
new file mode 100644
index 0000000000..de79b80312
--- /dev/null
+++ b/modules/actions/jobparser/testdata/has_with.out.yaml
@@ -0,0 +1,17 @@
+name: test
+jobs:
+ job1:
+ name: job1
+ runs-on: linux
+ uses: .gitea/workflows/build.yml
+ with:
+ package: service
+---
+name: test
+jobs:
+ job2:
+ name: job2
+ runs-on: linux
+ uses: .gitea/workflows/build.yml
+ with:
+ package: module
diff --git a/modules/actions/jobparser/testdata/job_name_with_matrix.in.yaml b/modules/actions/jobparser/testdata/job_name_with_matrix.in.yaml
new file mode 100644
index 0000000000..72c700da05
--- /dev/null
+++ b/modules/actions/jobparser/testdata/job_name_with_matrix.in.yaml
@@ -0,0 +1,14 @@
+name: test
+jobs:
+ job1:
+ strategy:
+ matrix:
+ os: [ubuntu-22.04, ubuntu-20.04]
+ version: [1.17, 1.18, 1.19]
+ runs-on: ${{ matrix.os }}
+ name: test_version_${{ matrix.version }}_on_${{ matrix.os }}
+ steps:
+ - uses: actions/setup-go@v3
+ with:
+ go-version: ${{ matrix.version }}
+ - run: uname -a && go version
diff --git a/modules/actions/jobparser/testdata/job_name_with_matrix.out.yaml b/modules/actions/jobparser/testdata/job_name_with_matrix.out.yaml
new file mode 100644
index 0000000000..081e8d4abd
--- /dev/null
+++ b/modules/actions/jobparser/testdata/job_name_with_matrix.out.yaml
@@ -0,0 +1,101 @@
+name: test
+jobs:
+ job1:
+ name: test_version_1.17_on_ubuntu-20.04
+ runs-on: ubuntu-20.04
+ steps:
+ - uses: actions/setup-go@v3
+ with:
+ go-version: ${{ matrix.version }}
+ - run: uname -a && go version
+ strategy:
+ matrix:
+ os:
+ - ubuntu-20.04
+ version:
+ - 1.17
+---
+name: test
+jobs:
+ job1:
+ name: test_version_1.18_on_ubuntu-20.04
+ runs-on: ubuntu-20.04
+ steps:
+ - uses: actions/setup-go@v3
+ with:
+ go-version: ${{ matrix.version }}
+ - run: uname -a && go version
+ strategy:
+ matrix:
+ os:
+ - ubuntu-20.04
+ version:
+ - 1.18
+---
+name: test
+jobs:
+ job1:
+ name: test_version_1.19_on_ubuntu-20.04
+ runs-on: ubuntu-20.04
+ steps:
+ - uses: actions/setup-go@v3
+ with:
+ go-version: ${{ matrix.version }}
+ - run: uname -a && go version
+ strategy:
+ matrix:
+ os:
+ - ubuntu-20.04
+ version:
+ - 1.19
+---
+name: test
+jobs:
+ job1:
+ name: test_version_1.17_on_ubuntu-22.04
+ runs-on: ubuntu-22.04
+ steps:
+ - uses: actions/setup-go@v3
+ with:
+ go-version: ${{ matrix.version }}
+ - run: uname -a && go version
+ strategy:
+ matrix:
+ os:
+ - ubuntu-22.04
+ version:
+ - 1.17
+---
+name: test
+jobs:
+ job1:
+ name: test_version_1.18_on_ubuntu-22.04
+ runs-on: ubuntu-22.04
+ steps:
+ - uses: actions/setup-go@v3
+ with:
+ go-version: ${{ matrix.version }}
+ - run: uname -a && go version
+ strategy:
+ matrix:
+ os:
+ - ubuntu-22.04
+ version:
+ - 1.18
+---
+name: test
+jobs:
+ job1:
+ name: test_version_1.19_on_ubuntu-22.04
+ runs-on: ubuntu-22.04
+ steps:
+ - uses: actions/setup-go@v3
+ with:
+ go-version: ${{ matrix.version }}
+ - run: uname -a && go version
+ strategy:
+ matrix:
+ os:
+ - ubuntu-22.04
+ version:
+ - 1.19
diff --git a/modules/actions/jobparser/testdata/multiple_jobs.in.yaml b/modules/actions/jobparser/testdata/multiple_jobs.in.yaml
new file mode 100644
index 0000000000..266ede847a
--- /dev/null
+++ b/modules/actions/jobparser/testdata/multiple_jobs.in.yaml
@@ -0,0 +1,22 @@
+name: test
+jobs:
+ zzz:
+ runs-on: linux
+ steps:
+ - run: echo zzz
+ job1:
+ runs-on: linux
+ steps:
+ - run: uname -a && go version
+ job2:
+ runs-on: linux
+ steps:
+ - run: uname -a && go version
+ job3:
+ runs-on: linux
+ steps:
+ - run: uname -a && go version
+ aaa:
+ runs-on: linux
+ steps:
+ - run: uname -a && go version
diff --git a/modules/actions/jobparser/testdata/multiple_jobs.out.yaml b/modules/actions/jobparser/testdata/multiple_jobs.out.yaml
new file mode 100644
index 0000000000..ea2235001c
--- /dev/null
+++ b/modules/actions/jobparser/testdata/multiple_jobs.out.yaml
@@ -0,0 +1,39 @@
+name: test
+jobs:
+ zzz:
+ name: zzz
+ runs-on: linux
+ steps:
+ - run: echo zzz
+---
+name: test
+jobs:
+ job1:
+ name: job1
+ runs-on: linux
+ steps:
+ - run: uname -a && go version
+---
+name: test
+jobs:
+ job2:
+ name: job2
+ runs-on: linux
+ steps:
+ - run: uname -a && go version
+---
+name: test
+jobs:
+ job3:
+ name: job3
+ runs-on: linux
+ steps:
+ - run: uname -a && go version
+---
+name: test
+jobs:
+ aaa:
+ name: aaa
+ runs-on: linux
+ steps:
+ - run: uname -a && go version
diff --git a/modules/actions/jobparser/testdata/multiple_matrix.in.yaml b/modules/actions/jobparser/testdata/multiple_matrix.in.yaml
new file mode 100644
index 0000000000..8b9360c327
--- /dev/null
+++ b/modules/actions/jobparser/testdata/multiple_matrix.in.yaml
@@ -0,0 +1,13 @@
+name: test
+jobs:
+ job1:
+ strategy:
+ matrix:
+ os: [ubuntu-22.04, ubuntu-20.04]
+ version: [1.17, 1.18, 1.19]
+ runs-on: ${{ matrix.os }}
+ steps:
+ - uses: actions/setup-go@v3
+ with:
+ go-version: ${{ matrix.version }}
+ - run: uname -a && go version
diff --git a/modules/actions/jobparser/testdata/multiple_matrix.out.yaml b/modules/actions/jobparser/testdata/multiple_matrix.out.yaml
new file mode 100644
index 0000000000..e277cdd0ee
--- /dev/null
+++ b/modules/actions/jobparser/testdata/multiple_matrix.out.yaml
@@ -0,0 +1,101 @@
+name: test
+jobs:
+ job1:
+ name: job1 (ubuntu-20.04, 1.17)
+ runs-on: ubuntu-20.04
+ steps:
+ - uses: actions/setup-go@v3
+ with:
+ go-version: ${{ matrix.version }}
+ - run: uname -a && go version
+ strategy:
+ matrix:
+ os:
+ - ubuntu-20.04
+ version:
+ - 1.17
+---
+name: test
+jobs:
+ job1:
+ name: job1 (ubuntu-20.04, 1.18)
+ runs-on: ubuntu-20.04
+ steps:
+ - uses: actions/setup-go@v3
+ with:
+ go-version: ${{ matrix.version }}
+ - run: uname -a && go version
+ strategy:
+ matrix:
+ os:
+ - ubuntu-20.04
+ version:
+ - 1.18
+---
+name: test
+jobs:
+ job1:
+ name: job1 (ubuntu-20.04, 1.19)
+ runs-on: ubuntu-20.04
+ steps:
+ - uses: actions/setup-go@v3
+ with:
+ go-version: ${{ matrix.version }}
+ - run: uname -a && go version
+ strategy:
+ matrix:
+ os:
+ - ubuntu-20.04
+ version:
+ - 1.19
+---
+name: test
+jobs:
+ job1:
+ name: job1 (ubuntu-22.04, 1.17)
+ runs-on: ubuntu-22.04
+ steps:
+ - uses: actions/setup-go@v3
+ with:
+ go-version: ${{ matrix.version }}
+ - run: uname -a && go version
+ strategy:
+ matrix:
+ os:
+ - ubuntu-22.04
+ version:
+ - 1.17
+---
+name: test
+jobs:
+ job1:
+ name: job1 (ubuntu-22.04, 1.18)
+ runs-on: ubuntu-22.04
+ steps:
+ - uses: actions/setup-go@v3
+ with:
+ go-version: ${{ matrix.version }}
+ - run: uname -a && go version
+ strategy:
+ matrix:
+ os:
+ - ubuntu-22.04
+ version:
+ - 1.18
+---
+name: test
+jobs:
+ job1:
+ name: job1 (ubuntu-22.04, 1.19)
+ runs-on: ubuntu-22.04
+ steps:
+ - uses: actions/setup-go@v3
+ with:
+ go-version: ${{ matrix.version }}
+ - run: uname -a && go version
+ strategy:
+ matrix:
+ os:
+ - ubuntu-22.04
+ version:
+ - 1.19
diff --git a/modules/actions/jobparser/testdata/null_job_explicit.in.yaml b/modules/actions/jobparser/testdata/null_job_explicit.in.yaml
new file mode 100644
index 0000000000..6731507a32
--- /dev/null
+++ b/modules/actions/jobparser/testdata/null_job_explicit.in.yaml
@@ -0,0 +1,9 @@
+# null_job_explicit.in.yaml
+on: push
+jobs:
+ empty: null
+ notempty:
+ needs: empty
+ runs-on: ubuntu-latest
+ steps:
+ - run: echo ok
diff --git a/modules/actions/jobparser/testdata/null_job_implicit.in.yaml b/modules/actions/jobparser/testdata/null_job_implicit.in.yaml
new file mode 100644
index 0000000000..26591aadcd
--- /dev/null
+++ b/modules/actions/jobparser/testdata/null_job_implicit.in.yaml
@@ -0,0 +1,9 @@
+# null_job_implicit.in.yaml
+on: push
+jobs:
+ empty:
+ notempty:
+ needs: empty
+ runs-on: ubuntu-latest
+ steps:
+ - run: echo ok
diff --git a/modules/actions/jobparser/testdata/prefixed_newline.in.yaml b/modules/actions/jobparser/testdata/prefixed_newline.in.yaml
new file mode 100644
index 0000000000..91f8530288
--- /dev/null
+++ b/modules/actions/jobparser/testdata/prefixed_newline.in.yaml
@@ -0,0 +1,14 @@
+name: Step with leading new line
+
+on:
+ push:
+
+jobs:
+ test:
+ runs-on: ubuntu-latest
+ steps:
+ - name: "\nExtract tag for variant"
+ id: extract_tag
+ run: |
+
+ echo Test
diff --git a/modules/actions/jobparser/testdata/prefixed_newline.out.yaml b/modules/actions/jobparser/testdata/prefixed_newline.out.yaml
new file mode 100644
index 0000000000..027e9dfa1a
--- /dev/null
+++ b/modules/actions/jobparser/testdata/prefixed_newline.out.yaml
@@ -0,0 +1,15 @@
+name: Step with leading new line
+"on":
+ push:
+jobs:
+ test:
+ name: test
+ runs-on: ubuntu-latest
+ steps:
+ - id: extract_tag
+ name: |2-
+
+ Extract tag for variant
+ run: |2
+
+ echo Test
diff --git a/modules/actions/jobparser/testdata_test.go b/modules/actions/jobparser/testdata_test.go
new file mode 100644
index 0000000000..872484e25e
--- /dev/null
+++ b/modules/actions/jobparser/testdata_test.go
@@ -0,0 +1,21 @@
+// Copyright 2026 The Gitea Authors. All rights reserved.
+// SPDX-License-Identifier: MIT
+
+package jobparser
+
+import (
+ "embed"
+ "path/filepath"
+ "testing"
+
+ "github.com/stretchr/testify/require"
+)
+
+//go:embed testdata
+var testdata embed.FS
+
+func ReadTestdata(t *testing.T, name string) []byte {
+ content, err := testdata.ReadFile(filepath.Join("testdata", name))
+ require.NoError(t, err)
+ return content
+}
diff --git a/modules/actions/log.go b/modules/actions/log.go
index 5a1425e031..3fb56b402a 100644
--- a/modules/actions/log.go
+++ b/modules/actions/log.go
@@ -33,21 +33,22 @@ const (
// It doesn't respect the file format in the filename like ".zst", since it's difficult to reopen a closed compressed file and append new content.
// Why doesn't it store logs in object storage directly? Because it's not efficient to append content to object storage.
func WriteLogs(ctx context.Context, filename string, offset int64, rows []*runnerv1.LogRow) ([]int, error) {
- flag := os.O_WRONLY
+ flag, openFileFor := os.O_WRONLY, "write-only"
if offset == 0 {
- // Create file only if offset is 0, or it could result in content holes if the file doesn't exist.
- flag |= os.O_CREATE
+ // Only allow to create file if offset is 0 (the first write), see #25560.
+ // Otherwise, it might result in content holes if the file has been deleted after transferred (actions.TransferLogs).
+ flag, openFileFor = os.O_WRONLY|os.O_CREATE, "write-create"
}
name := DBFSPrefix + filename
f, err := dbfs.OpenFile(ctx, name, flag)
if err != nil {
- return nil, fmt.Errorf("dbfs OpenFile %q: %w", name, err)
+ return nil, fmt.Errorf("dbfs.OpenFile %q for %s: %w", name, openFileFor, err)
}
defer f.Close()
stat, err := f.Stat()
if err != nil {
- return nil, fmt.Errorf("dbfs Stat %q: %w", name, err)
+ return nil, fmt.Errorf("dbfs.Stat %q: %w", name, err)
}
if stat.Size() < offset {
// If the size is less than offset, refuse to write, or it could result in content holes.
@@ -56,7 +57,7 @@ func WriteLogs(ctx context.Context, filename string, offset int64, rows []*runne
}
if _, err := f.Seek(offset, io.SeekStart); err != nil {
- return nil, fmt.Errorf("dbfs Seek %q: %w", name, err)
+ return nil, fmt.Errorf("dbfs.Seek %q: %w", name, err)
}
writer := bufio.NewWriterSize(f, defaultBufSize)
@@ -121,16 +122,17 @@ const (
// TransferLogs transfers logs from DBFS to object storage.
// It happens when the file is complete and no more logs will be appended.
// It respects the file format in the filename like ".zst", and compresses the content if needed.
+// The task log file must be marked as "log_in_storage=true" after the transfer.
func TransferLogs(ctx context.Context, filename string) (func(), error) {
name := DBFSPrefix + filename
remove := func() {
if err := dbfs.Remove(ctx, name); err != nil {
- log.Warn("dbfs remove %q: %v", name, err)
+ log.Warn("dbfs.Remove %q: %v", name, err)
}
}
f, err := dbfs.Open(ctx, name)
if err != nil {
- return nil, fmt.Errorf("dbfs open %q: %w", name, err)
+ return nil, fmt.Errorf("dbfs.Open %q: %w", name, err)
}
defer f.Close()
@@ -164,7 +166,7 @@ func RemoveLogs(ctx context.Context, inStorage bool, filename string) error {
name := DBFSPrefix + filename
err := dbfs.Remove(ctx, name)
if err != nil {
- return fmt.Errorf("dbfs remove %q: %w", name, err)
+ return fmt.Errorf("dbfs.Remove %q: %w", name, err)
}
return nil
}
@@ -180,7 +182,7 @@ func OpenLogs(ctx context.Context, inStorage bool, filename string) (io.ReadSeek
name := DBFSPrefix + filename
f, err := dbfs.Open(ctx, name)
if err != nil {
- return nil, fmt.Errorf("dbfs open %q: %w", name, err)
+ return nil, fmt.Errorf("dbfs.Open %q: %w", name, err)
}
return f, nil
}
diff --git a/modules/actions/workflows.go b/modules/actions/workflows.go
index 26a6ebc370..ba1aee7d72 100644
--- a/modules/actions/workflows.go
+++ b/modules/actions/workflows.go
@@ -8,17 +8,18 @@ import (
"slices"
"strings"
+ "code.gitea.io/gitea/modules/actions/jobparser"
"code.gitea.io/gitea/modules/git"
"code.gitea.io/gitea/modules/glob"
"code.gitea.io/gitea/modules/log"
+ "code.gitea.io/gitea/modules/setting"
api "code.gitea.io/gitea/modules/structs"
"code.gitea.io/gitea/modules/util"
webhook_module "code.gitea.io/gitea/modules/webhook"
- "github.com/nektos/act/pkg/jobparser"
"github.com/nektos/act/pkg/model"
"github.com/nektos/act/pkg/workflowpattern"
- "gopkg.in/yaml.v3"
+ "go.yaml.in/yaml/v4"
)
type DetectedWorkflow struct {
@@ -41,22 +42,30 @@ func IsWorkflow(path string) bool {
return false
}
- return strings.HasPrefix(path, ".gitea/workflows") || strings.HasPrefix(path, ".github/workflows")
+ for _, workflowDir := range setting.Actions.WorkflowDirs {
+ if strings.HasPrefix(path, workflowDir+"/") {
+ return true
+ }
+ }
+ return false
}
func ListWorkflows(commit *git.Commit) (string, git.Entries, error) {
- rpath := ".gitea/workflows"
- tree, err := commit.SubTree(rpath)
- if _, ok := err.(git.ErrNotExist); ok {
- rpath = ".github/workflows"
- tree, err = commit.SubTree(rpath)
+ var tree *git.Tree
+ var err error
+ var workflowDir string
+ for _, workflowDir = range setting.Actions.WorkflowDirs {
+ tree, err = commit.SubTree(workflowDir)
+ if err == nil {
+ break
+ }
+ if !git.IsErrNotExist(err) {
+ return "", nil, err
+ }
}
- if _, ok := err.(git.ErrNotExist); ok {
+ if tree == nil {
return "", nil, nil
}
- if err != nil {
- return "", nil, err
- }
entries, err := tree.ListEntriesRecursiveFast()
if err != nil {
@@ -69,7 +78,7 @@ func ListWorkflows(commit *git.Commit) (string, git.Entries, error) {
ret = append(ret, entry)
}
}
- return rpath, ret, nil
+ return workflowDir, ret, nil
}
func GetContentFromEntry(entry *git.TreeEntry) ([]byte, error) {
@@ -94,10 +103,20 @@ func GetEventsFromContent(content []byte) ([]*jobparser.Event, error) {
if err != nil {
return nil, err
}
+ if err := ValidateWorkflowContent(content); err != nil {
+ return nil, err
+ }
return events, nil
}
+// ValidateWorkflowContent catches structural errors (e.g. blank lines in run: | blocks)
+// that model.ReadWorkflow alone does not detect.
+func ValidateWorkflowContent(content []byte) error {
+ _, err := jobparser.Parse(content)
+ return err
+}
+
func DetectWorkflows(
gitRepo *git.Repository,
commit *git.Commit,
diff --git a/modules/actions/workflows_test.go b/modules/actions/workflows_test.go
index 89620fb698..cda2de13e2 100644
--- a/modules/actions/workflows_test.go
+++ b/modules/actions/workflows_test.go
@@ -7,12 +7,93 @@ import (
"testing"
"code.gitea.io/gitea/modules/git"
+ "code.gitea.io/gitea/modules/setting"
api "code.gitea.io/gitea/modules/structs"
+ "code.gitea.io/gitea/modules/test"
webhook_module "code.gitea.io/gitea/modules/webhook"
"github.com/stretchr/testify/assert"
)
+func fullWorkflowContent(part string) []byte {
+ return []byte(`
+name: test
+` + part + `
+jobs:
+ test:
+ runs-on: ubuntu-latest
+ steps:
+ - run: echo hello
+`)
+}
+
+func TestIsWorkflow(t *testing.T) {
+ defer test.MockVariableValue(&setting.Actions.WorkflowDirs)()
+
+ tests := []struct {
+ name string
+ dirs []string
+ path string
+ expected bool
+ }{
+ {
+ name: "default with yml extension",
+ dirs: []string{".gitea/workflows", ".github/workflows"},
+ path: ".gitea/workflows/test.yml",
+ expected: true,
+ },
+ {
+ name: "default with yaml extension",
+ dirs: []string{".gitea/workflows", ".github/workflows"},
+ path: ".github/workflows/test.yaml",
+ expected: true,
+ },
+ {
+ name: "only gitea configured, github path rejected",
+ dirs: []string{".gitea/workflows"},
+ path: ".github/workflows/test.yml",
+ expected: false,
+ },
+ {
+ name: "only github configured, gitea path rejected",
+ dirs: []string{".github/workflows"},
+ path: ".gitea/workflows/test.yml",
+ expected: false,
+ },
+ {
+ name: "custom workflow dir",
+ dirs: []string{".custom/workflows"},
+ path: ".custom/workflows/deploy.yml",
+ expected: true,
+ },
+ {
+ name: "non-workflow file",
+ dirs: []string{".gitea/workflows", ".github/workflows"},
+ path: ".gitea/workflows/readme.md",
+ expected: false,
+ },
+ {
+ name: "directory boundary",
+ dirs: []string{".gitea/workflows"},
+ path: ".gitea/workflows2/test.yml",
+ expected: false,
+ },
+ {
+ name: "unrelated path",
+ dirs: []string{".gitea/workflows", ".github/workflows"},
+ path: "src/main.go",
+ expected: false,
+ },
+ }
+
+ for _, tt := range tests {
+ t.Run(tt.name, func(t *testing.T) {
+ setting.Actions.WorkflowDirs = tt.dirs
+ assert.Equal(t, tt.expected, IsWorkflow(tt.path))
+ })
+ }
+}
+
func TestDetectMatched(t *testing.T) {
testCases := []struct {
desc string
@@ -119,7 +200,7 @@ func TestDetectMatched(t *testing.T) {
expected: true,
},
{
- desc: "HookEventSchedue(schedule) matches GithubEventSchedule(schedule)",
+ desc: "HookEventSchedule(schedule) matches GithubEventSchedule(schedule)",
triggedEvent: webhook_module.HookEventSchedule,
payload: nil,
yamlOn: "on: schedule",
@@ -147,7 +228,7 @@ func TestDetectMatched(t *testing.T) {
for _, tc := range testCases {
t.Run(tc.desc, func(t *testing.T) {
- evts, err := GetEventsFromContent([]byte(tc.yamlOn))
+ evts, err := GetEventsFromContent(fullWorkflowContent(tc.yamlOn))
assert.NoError(t, err)
assert.Len(t, evts, 1)
assert.Equal(t, tc.expected, detectMatched(nil, tc.commit, tc.triggedEvent, tc.payload, evts[0]))
@@ -302,7 +383,7 @@ func TestMatchIssuesEvent(t *testing.T) {
for _, tc := range testCases {
t.Run(tc.desc, func(t *testing.T) {
- evts, err := GetEventsFromContent([]byte(tc.yamlOn))
+ evts, err := GetEventsFromContent(fullWorkflowContent(tc.yamlOn))
assert.NoError(t, err)
assert.Len(t, evts, 1)
diff --git a/modules/activitypub/client.go b/modules/activitypub/client.go
deleted file mode 100644
index a9941f9b75..0000000000
--- a/modules/activitypub/client.go
+++ /dev/null
@@ -1,124 +0,0 @@
-// Copyright 2022 The Gitea Authors. All rights reserved.
-// SPDX-License-Identifier: MIT
-
-package activitypub
-
-import (
- "bytes"
- "context"
- "crypto/rsa"
- "crypto/x509"
- "encoding/pem"
- "fmt"
- "net/http"
- "strings"
- "time"
-
- user_model "code.gitea.io/gitea/models/user"
- "code.gitea.io/gitea/modules/proxy"
- "code.gitea.io/gitea/modules/setting"
-
- "github.com/42wim/httpsig"
-)
-
-const (
- // ActivityStreamsContentType const
- ActivityStreamsContentType = `application/ld+json; profile="https://www.w3.org/ns/activitystreams"`
- httpsigExpirationTime = 60
-)
-
-// Gets the current time as an RFC 2616 formatted string
-// RFC 2616 requires RFC 1123 dates but with GMT instead of UTC
-func CurrentTime() string {
- return strings.ReplaceAll(time.Now().UTC().Format(time.RFC1123), "UTC", "GMT")
-}
-
-func containsRequiredHTTPHeaders(method string, headers []string) error {
- var hasRequestTarget, hasDate, hasDigest bool
- for _, header := range headers {
- hasRequestTarget = hasRequestTarget || header == httpsig.RequestTarget
- hasDate = hasDate || header == "Date"
- hasDigest = hasDigest || header == "Digest"
- }
- if !hasRequestTarget {
- return fmt.Errorf("missing http header for %s: %s", method, httpsig.RequestTarget)
- } else if !hasDate {
- return fmt.Errorf("missing http header for %s: Date", method)
- } else if !hasDigest && method != http.MethodGet {
- return fmt.Errorf("missing http header for %s: Digest", method)
- }
- return nil
-}
-
-// Client struct
-type Client struct {
- client *http.Client
- algs []httpsig.Algorithm
- digestAlg httpsig.DigestAlgorithm
- getHeaders []string
- postHeaders []string
- priv *rsa.PrivateKey
- pubID string
-}
-
-// NewClient function
-func NewClient(ctx context.Context, user *user_model.User, pubID string) (c *Client, err error) {
- if err = containsRequiredHTTPHeaders(http.MethodGet, setting.Federation.GetHeaders); err != nil {
- return nil, err
- } else if err = containsRequiredHTTPHeaders(http.MethodPost, setting.Federation.PostHeaders); err != nil {
- return nil, err
- }
-
- priv, err := GetPrivateKey(ctx, user)
- if err != nil {
- return nil, err
- }
- privPem, _ := pem.Decode([]byte(priv))
- privParsed, err := x509.ParsePKCS1PrivateKey(privPem.Bytes)
- if err != nil {
- return nil, err
- }
-
- c = &Client{
- client: &http.Client{
- Transport: &http.Transport{
- Proxy: proxy.Proxy(),
- },
- },
- algs: setting.HttpsigAlgs,
- digestAlg: httpsig.DigestAlgorithm(setting.Federation.DigestAlgorithm),
- getHeaders: setting.Federation.GetHeaders,
- postHeaders: setting.Federation.PostHeaders,
- priv: privParsed,
- pubID: pubID,
- }
- return c, err
-}
-
-// NewRequest function
-func (c *Client) NewRequest(b []byte, to string) (req *http.Request, err error) {
- buf := bytes.NewBuffer(b)
- req, err = http.NewRequest(http.MethodPost, to, buf)
- if err != nil {
- return nil, err
- }
- req.Header.Add("Content-Type", ActivityStreamsContentType)
- req.Header.Add("Date", CurrentTime())
- req.Header.Add("User-Agent", "Gitea/"+setting.AppVer)
- signer, _, err := httpsig.NewSigner(c.algs, c.digestAlg, c.postHeaders, httpsig.Signature, httpsigExpirationTime)
- if err != nil {
- return nil, err
- }
- err = signer.SignRequest(c.priv, c.pubID, req, b)
- return req, err
-}
-
-// Post function
-func (c *Client) Post(b []byte, to string) (resp *http.Response, err error) {
- var req *http.Request
- if req, err = c.NewRequest(b, to); err != nil {
- return nil, err
- }
- resp, err = c.client.Do(req)
- return resp, err
-}
diff --git a/modules/activitypub/client_test.go b/modules/activitypub/client_test.go
deleted file mode 100644
index 361270a800..0000000000
--- a/modules/activitypub/client_test.go
+++ /dev/null
@@ -1,45 +0,0 @@
-// Copyright 2022 The Gitea Authors. All rights reserved.
-// SPDX-License-Identifier: MIT
-
-package activitypub
-
-import (
- "fmt"
- "io"
- "net/http"
- "net/http/httptest"
- "testing"
-
- "code.gitea.io/gitea/models/unittest"
- user_model "code.gitea.io/gitea/models/user"
- "code.gitea.io/gitea/modules/setting"
-
- "github.com/stretchr/testify/assert"
-)
-
-func TestActivityPubSignedPost(t *testing.T) {
- assert.NoError(t, unittest.PrepareTestDatabase())
- user := unittest.AssertExistsAndLoadBean(t, &user_model.User{ID: 1})
- pubID := "https://example.com/pubID"
- c, err := NewClient(t.Context(), user, pubID)
- assert.NoError(t, err)
-
- expected := "BODY"
- srv := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
- assert.Regexp(t, "^"+setting.Federation.DigestAlgorithm, r.Header.Get("Digest"))
- assert.Contains(t, r.Header.Get("Signature"), pubID)
- assert.Equal(t, ActivityStreamsContentType, r.Header.Get("Content-Type"))
- body, err := io.ReadAll(r.Body)
- assert.NoError(t, err)
- assert.Equal(t, expected, string(body))
- fmt.Fprint(w, expected)
- }))
- defer srv.Close()
-
- r, err := c.Post([]byte(expected), srv.URL)
- assert.NoError(t, err)
- defer r.Body.Close()
- body, err := io.ReadAll(r.Body)
- assert.NoError(t, err)
- assert.Equal(t, expected, string(body))
-}
diff --git a/modules/activitypub/main_test.go b/modules/activitypub/main_test.go
deleted file mode 100644
index 4591f1fa55..0000000000
--- a/modules/activitypub/main_test.go
+++ /dev/null
@@ -1,18 +0,0 @@
-// Copyright 2022 The Gitea Authors. All rights reserved.
-// SPDX-License-Identifier: MIT
-
-package activitypub
-
-import (
- "testing"
-
- "code.gitea.io/gitea/models/unittest"
-
- _ "code.gitea.io/gitea/models"
- _ "code.gitea.io/gitea/models/actions"
- _ "code.gitea.io/gitea/models/activities"
-)
-
-func TestMain(m *testing.M) {
- unittest.MainTest(m)
-}
diff --git a/modules/activitypub/user_settings.go b/modules/activitypub/user_settings.go
deleted file mode 100644
index 7f939af352..0000000000
--- a/modules/activitypub/user_settings.go
+++ /dev/null
@@ -1,48 +0,0 @@
-// Copyright 2022 The Gitea Authors. All rights reserved.
-// SPDX-License-Identifier: MIT
-
-package activitypub
-
-import (
- "context"
-
- user_model "code.gitea.io/gitea/models/user"
- "code.gitea.io/gitea/modules/util"
-)
-
-const rsaBits = 3072
-
-// GetKeyPair function returns a user's private and public keys
-func GetKeyPair(ctx context.Context, user *user_model.User) (pub, priv string, err error) {
- var settings map[string]*user_model.Setting
- settings, err = user_model.GetSettings(ctx, user.ID, []string{user_model.UserActivityPubPrivPem, user_model.UserActivityPubPubPem})
- if err != nil {
- return pub, priv, err
- } else if len(settings) == 0 {
- if priv, pub, err = util.GenerateKeyPair(rsaBits); err != nil {
- return pub, priv, err
- }
- if err = user_model.SetUserSetting(ctx, user.ID, user_model.UserActivityPubPrivPem, priv); err != nil {
- return pub, priv, err
- }
- if err = user_model.SetUserSetting(ctx, user.ID, user_model.UserActivityPubPubPem, pub); err != nil {
- return pub, priv, err
- }
- return pub, priv, err
- }
- priv = settings[user_model.UserActivityPubPrivPem].SettingValue
- pub = settings[user_model.UserActivityPubPubPem].SettingValue
- return pub, priv, err
-}
-
-// GetPublicKey function returns a user's public key
-func GetPublicKey(ctx context.Context, user *user_model.User) (pub string, err error) {
- pub, _, err = GetKeyPair(ctx, user)
- return pub, err
-}
-
-// GetPrivateKey function returns a user's private key
-func GetPrivateKey(ctx context.Context, user *user_model.User) (priv string, err error) {
- _, priv, err = GetKeyPair(ctx, user)
- return priv, err
-}
diff --git a/modules/activitypub/user_settings_test.go b/modules/activitypub/user_settings_test.go
deleted file mode 100644
index 105d4aedea..0000000000
--- a/modules/activitypub/user_settings_test.go
+++ /dev/null
@@ -1,28 +0,0 @@
-// Copyright 2022 The Gitea Authors. All rights reserved.
-// SPDX-License-Identifier: MIT
-
-package activitypub
-
-import (
- "testing"
-
- "code.gitea.io/gitea/models/unittest"
- user_model "code.gitea.io/gitea/models/user"
-
- _ "code.gitea.io/gitea/models" // https://forum.gitea.com/t/testfixtures-could-not-clean-table-access-no-such-table-access/4137/4
-
- "github.com/stretchr/testify/assert"
-)
-
-func TestUserSettings(t *testing.T) {
- assert.NoError(t, unittest.PrepareTestDatabase())
- user1 := unittest.AssertExistsAndLoadBean(t, &user_model.User{ID: 1})
- pub, priv, err := GetKeyPair(t.Context(), user1)
- assert.NoError(t, err)
- pub1, err := GetPublicKey(t.Context(), user1)
- assert.NoError(t, err)
- assert.Equal(t, pub, pub1)
- priv1, err := GetPrivateKey(t.Context(), user1)
- assert.NoError(t, err)
- assert.Equal(t, priv, priv1)
-}
diff --git a/modules/analyze/code_language.go b/modules/analyze/code_language.go
index 74e7a06d06..d8589861d3 100644
--- a/modules/analyze/code_language.go
+++ b/modules/analyze/code_language.go
@@ -4,12 +4,13 @@
package analyze
import (
- "path/filepath"
+ "path"
"github.com/go-enry/go-enry/v2"
)
// GetCodeLanguage detects code language based on file name and content
+// It can be slow when the content is used for detection
func GetCodeLanguage(filename string, content []byte) string {
if language, ok := enry.GetLanguageByExtension(filename); ok {
return language
@@ -23,5 +24,5 @@ func GetCodeLanguage(filename string, content []byte) string {
return enry.OtherLanguage
}
- return enry.GetLanguage(filepath.Base(filename), content)
+ return enry.GetLanguage(path.Base(filename), content)
}
diff --git a/modules/analyze/vendor.go b/modules/analyze/vendor.go
index adcca923dd..f3e75f535f 100644
--- a/modules/analyze/vendor.go
+++ b/modules/analyze/vendor.go
@@ -4,10 +4,28 @@
package analyze
import (
+ "path"
+ "strings"
+
"github.com/go-enry/go-enry/v2"
)
-// IsVendor returns whether or not path is a vendor path.
-func IsVendor(path string) bool {
- return enry.IsVendor(path)
+// IsVendor returns whether the path is a vendor path.
+// It uses go-enry's IsVendor function but overrides its detection for certain
+// special cases that shouldn't be marked as vendored in the diff view.
+func IsVendor(treePath string) bool {
+ if !enry.IsVendor(treePath) {
+ return false
+ }
+
+ // Override detection for single files
+ basename := path.Base(treePath)
+ switch basename {
+ case ".gitignore", ".gitattributes", ".gitmodules":
+ return false
+ }
+ if strings.HasPrefix(treePath, ".github/") || strings.HasPrefix(treePath, ".gitea/") {
+ return false
+ }
+ return true
}
diff --git a/modules/analyze/vendor_test.go b/modules/analyze/vendor_test.go
index 02a51d4c8f..6efb825de6 100644
--- a/modules/analyze/vendor_test.go
+++ b/modules/analyze/vendor_test.go
@@ -14,6 +14,7 @@ func TestIsVendor(t *testing.T) {
path string
want bool
}{
+ // Original go-enry test cases
{"cache/", true},
{"random/cache/", true},
{"cache", false},
@@ -34,6 +35,14 @@ func TestIsVendor(t *testing.T) {
{"a/docs/_build/", true},
{"a/dasdocs/_build-vsdoc.js", true},
{"a/dasdocs/_build-vsdoc.j", false},
+
+ // Override: Git/GitHub/Gitea-related paths should NOT be detected as vendored
+ {".gitignore", false},
+ {".gitattributes", false},
+ {".gitmodules", false},
+ {"src/.gitignore", false},
+ {".github/workflows/ci.yml", false},
+ {".gitea/workflows/ci.yml", false},
}
for _, tt := range tests {
t.Run(tt.path, func(t *testing.T) {
diff --git a/modules/assetfs/embed.go b/modules/assetfs/embed.go
index 95176372d1..7c90e3aca2 100644
--- a/modules/assetfs/embed.go
+++ b/modules/assetfs/embed.go
@@ -260,7 +260,7 @@ func (fi *embeddedFileInfo) Mode() fs.FileMode {
}
func (fi *embeddedFileInfo) ModTime() time.Time {
- return getExecutableModTime()
+ return GetExecutableModTime()
}
func (fi *embeddedFileInfo) IsDir() bool {
@@ -279,9 +279,9 @@ func (fi *embeddedFileInfo) Info() (fs.FileInfo, error) {
return fi, nil
}
-// getExecutableModTime returns the modification time of the executable file.
+// GetExecutableModTime returns the modification time of the executable file.
// In bindata, we can't use the ModTime of the files because we need to make the build reproducible
-var getExecutableModTime = sync.OnceValue(func() (modTime time.Time) {
+var GetExecutableModTime = sync.OnceValue(func() (modTime time.Time) {
exePath, err := os.Executable()
if err != nil {
return modTime
@@ -365,11 +365,11 @@ func GenerateEmbedBindata(fsRootPath, outputFile string) error {
if err = embedFiles(meta.Root, fsRootPath, ""); err != nil {
return err
}
- jsonBuf, err := json.Marshal(meta) // can't use json.NewEncoder here because it writes extra EOL
+ jsonBuf, err := json.Marshal(meta)
if err != nil {
return err
}
_, _ = output.Write([]byte{'\n'})
- _, err = output.Write(jsonBuf)
+ _, err = output.Write(bytes.TrimSpace(jsonBuf))
return err
}
diff --git a/modules/assetfs/layered.go b/modules/assetfs/layered.go
index ce55475bd9..380c3ac455 100644
--- a/modules/assetfs/layered.go
+++ b/modules/assetfs/layered.go
@@ -6,12 +6,12 @@ package assetfs
import (
"context"
"fmt"
- "io"
"io/fs"
- "net/http"
"os"
"path/filepath"
+ "slices"
"sort"
+ "strings"
"time"
"code.gitea.io/gitea/modules/container"
@@ -25,7 +25,7 @@ import (
// Layer represents a layer in a layered asset file-system. It has a name and works like http.FileSystem
type Layer struct {
name string
- fs http.FileSystem
+ fs fs.FS
localPath string
}
@@ -34,7 +34,7 @@ func (l *Layer) Name() string {
}
// Open opens the named file. The caller is responsible for closing the file.
-func (l *Layer) Open(name string) (http.File, error) {
+func (l *Layer) Open(name string) (fs.File, error) {
return l.fs.Open(name)
}
@@ -48,12 +48,12 @@ func Local(name, base string, sub ...string) *Layer {
panic(fmt.Sprintf("Unable to get absolute path for %q: %v", base, err))
}
root := util.FilePathJoinAbs(base, sub...)
- return &Layer{name: name, fs: http.Dir(root), localPath: root}
+ return &Layer{name: name, fs: os.DirFS(root), localPath: root}
}
// Bindata returns a new Layer with the given name, it serves files from the given bindata asset.
func Bindata(name string, fs fs.FS) *Layer {
- return &Layer{name: name, fs: http.FS(fs)}
+ return &Layer{name: name, fs: fs}
}
// LayeredFS is a layered asset file-system. It works like http.FileSystem, but it can have multiple layers.
@@ -63,13 +63,15 @@ type LayeredFS struct {
layers []*Layer
}
+var _ fs.ReadDirFS = (*LayeredFS)(nil)
+
// Layered returns a new LayeredFS with the given layers. The first layer is the top layer.
func Layered(layers ...*Layer) *LayeredFS {
return &LayeredFS{layers: layers}
}
// Open opens the named file. The caller is responsible for closing the file.
-func (l *LayeredFS) Open(name string) (http.File, error) {
+func (l *LayeredFS) Open(name string) (fs.File, error) {
for _, layer := range l.layers {
f, err := layer.Open(name)
if err == nil || !os.IsNotExist(err) {
@@ -85,44 +87,59 @@ func (l *LayeredFS) ReadFile(elems ...string) ([]byte, error) {
return bs, err
}
+func (l *LayeredFS) ReadDir(name string) (files []fs.DirEntry, _ error) {
+ filesMap := map[string]fs.DirEntry{}
+ for _, layer := range l.layers {
+ entries, err := readDirOptional(layer, name)
+ if err != nil {
+ return nil, err
+ }
+ for _, entry := range entries {
+ entryName := entry.Name()
+ if _, exist := filesMap[entryName]; !exist && shouldInclude(entry) {
+ filesMap[entryName] = entry
+ }
+ }
+ }
+ for _, file := range filesMap {
+ files = append(files, file)
+ }
+ slices.SortFunc(files, func(a, b fs.DirEntry) int { return strings.Compare(a.Name(), b.Name()) })
+ return files, nil
+}
+
// ReadLayeredFile reads the named file, and returns the layer name.
func (l *LayeredFS) ReadLayeredFile(elems ...string) ([]byte, string, error) {
name := util.PathJoinRel(elems...)
for _, layer := range l.layers {
- f, err := layer.Open(name)
+ bs, err := fs.ReadFile(layer, name)
if os.IsNotExist(err) {
continue
} else if err != nil {
return nil, layer.name, err
}
- bs, err := io.ReadAll(f)
- _ = f.Close()
return bs, layer.name, err
}
return nil, "", fs.ErrNotExist
}
-func shouldInclude(info fs.FileInfo, fileMode ...bool) bool {
- if util.IsCommonHiddenFileName(info.Name()) {
+func shouldInclude(dirEntry fs.DirEntry, fileMode ...bool) bool {
+ if util.IsCommonHiddenFileName(dirEntry.Name()) {
return false
}
if len(fileMode) == 0 {
return true
} else if len(fileMode) == 1 {
- return fileMode[0] == !info.Mode().IsDir()
+ return fileMode[0] == !dirEntry.IsDir()
}
panic("too many arguments for fileMode in shouldInclude")
}
-func readDir(layer *Layer, name string) ([]fs.FileInfo, error) {
- f, err := layer.Open(name)
- if os.IsNotExist(err) {
+func readDirOptional(layer *Layer, name string) (entries []fs.DirEntry, err error) {
+ if entries, err = fs.ReadDir(layer, name); os.IsNotExist(err) {
return nil, nil
- } else if err != nil {
- return nil, err
}
- defer f.Close()
- return f.Readdir(-1)
+ return entries, err
}
// ListFiles lists files/directories in the given directory. The fileMode controls the returned files.
@@ -133,13 +150,13 @@ func readDir(layer *Layer, name string) ([]fs.FileInfo, error) {
func (l *LayeredFS) ListFiles(name string, fileMode ...bool) ([]string, error) {
fileSet := make(container.Set[string])
for _, layer := range l.layers {
- infos, err := readDir(layer, name)
+ entries, err := readDirOptional(layer, name)
if err != nil {
return nil, err
}
- for _, info := range infos {
- if shouldInclude(info, fileMode...) {
- fileSet.Add(info.Name())
+ for _, entry := range entries {
+ if shouldInclude(entry, fileMode...) {
+ fileSet.Add(entry.Name())
}
}
}
@@ -163,16 +180,16 @@ func listAllFiles(layers []*Layer, name string, fileMode ...bool) ([]string, err
var list func(dir string) error
list = func(dir string) error {
for _, layer := range layers {
- infos, err := readDir(layer, dir)
+ entries, err := readDirOptional(layer, dir)
if err != nil {
return err
}
- for _, info := range infos {
- path := util.PathJoinRelX(dir, info.Name())
- if shouldInclude(info, fileMode...) {
+ for _, entry := range entries {
+ path := util.PathJoinRelX(dir, entry.Name())
+ if shouldInclude(entry, fileMode...) {
fileSet.Add(path)
}
- if info.IsDir() {
+ if entry.IsDir() {
if err = list(path); err != nil {
return err
}
diff --git a/modules/auth/pam/pam.go b/modules/auth/pam/pam.go
index cca1482b1d..a8b608e6be 100644
--- a/modules/auth/pam/pam.go
+++ b/modules/auth/pam/pam.go
@@ -8,7 +8,7 @@ package pam
import (
"errors"
- "github.com/msteinert/pam"
+ "github.com/msteinert/pam/v2"
)
// Supported is true when built with PAM
@@ -28,6 +28,7 @@ func Auth(serviceName, userName, passwd string) (string, error) {
if err != nil {
return "", err
}
+ defer t.End()
if err = t.Authenticate(0); err != nil {
return "", err
diff --git a/modules/auth/password/hash/argon2.go b/modules/auth/password/hash/argon2.go
index 0cd6472fa1..f4a7497df6 100644
--- a/modules/auth/password/hash/argon2.go
+++ b/modules/auth/password/hash/argon2.go
@@ -61,17 +61,11 @@ func NewArgon2Hasher(config string) *Argon2Hasher {
return nil
}
- parsed, err := parseUIntParam(vals[0], "time", "argon2", config, nil)
- hasher.time = uint32(parsed)
-
- parsed, err = parseUIntParam(vals[1], "memory", "argon2", config, err)
- hasher.memory = uint32(parsed)
-
- parsed, err = parseUIntParam(vals[2], "threads", "argon2", config, err)
- hasher.threads = uint8(parsed)
-
- parsed, err = parseUIntParam(vals[3], "keyLen", "argon2", config, err)
- hasher.keyLen = uint32(parsed)
+ var err error
+ hasher.time, err = parseUintParam[uint32](vals[0], "time", "argon2", config, nil)
+ hasher.memory, err = parseUintParam[uint32](vals[1], "memory", "argon2", config, err)
+ hasher.threads, err = parseUintParam[uint8](vals[2], "threads", "argon2", config, err)
+ hasher.keyLen, err = parseUintParam[uint32](vals[3], "keyLen", "argon2", config, err)
if err != nil {
return nil
}
diff --git a/modules/auth/password/hash/common.go b/modules/auth/password/hash/common.go
index d5e2c34314..1fafc289ed 100644
--- a/modules/auth/password/hash/common.go
+++ b/modules/auth/password/hash/common.go
@@ -7,6 +7,7 @@ import (
"strconv"
"code.gitea.io/gitea/modules/log"
+ "code.gitea.io/gitea/modules/util"
)
func parseIntParam(value, param, algorithmName, config string, previousErr error) (int, error) {
@@ -18,11 +19,12 @@ func parseIntParam(value, param, algorithmName, config string, previousErr error
return parsed, previousErr // <- Keep the previous error as this function should still return an error once everything has been checked if any call failed
}
-func parseUIntParam(value, param, algorithmName, config string, previousErr error) (uint64, error) { //nolint:unparam // algorithmName is always argon2
- parsed, err := strconv.ParseUint(value, 10, 64)
+func parseUintParam[T uint32 | uint8](value, param, algorithmName, config string, previousErr error) (ret T, _ error) {
+ _, isUint32 := any(ret).(uint32)
+ parsed, err := strconv.ParseUint(value, 10, util.Iif(isUint32, 32, 8))
if err != nil {
log.Error("invalid integer for %s representation in %s hash spec %s", param, algorithmName, config)
return 0, err
}
- return parsed, previousErr // <- Keep the previous error as this function should still return an error once everything has been checked if any call failed
+ return T(parsed), previousErr // <- Keep the previous error as this function should still return an error once everything has been checked if any call failed
}
diff --git a/modules/auth/password/hash/setting.go b/modules/auth/password/hash/setting.go
index f0715f31e1..e0caed5ba8 100644
--- a/modules/auth/password/hash/setting.go
+++ b/modules/auth/password/hash/setting.go
@@ -14,7 +14,7 @@ const DefaultHashAlgorithmName = "pbkdf2"
var DefaultHashAlgorithm *PasswordHashAlgorithm
-// aliasAlgorithNames provides a mapping between the value of PASSWORD_HASH_ALGO
+// aliasAlgorithmNames provides a mapping between the value of PASSWORD_HASH_ALGO
// configured in the app.ini and the parameters used within the hashers internally.
//
// If it is necessary to change the default parameters for any hasher in future you
diff --git a/modules/auth/password/pwn/pwn.go b/modules/auth/password/pwn/pwn.go
index 99a6ca6cea..d5ea96c4af 100644
--- a/modules/auth/password/pwn/pwn.go
+++ b/modules/auth/password/pwn/pwn.go
@@ -72,7 +72,7 @@ func newRequest(ctx context.Context, method, url string, body io.ReadCloser) (*h
// Adding padding will make requests more secure, however is also slower
// because artificial responses will be added to the response
// For more information, see https://www.troyhunt.com/enhancing-pwned-passwords-privacy-with-padding/
-func (c *Client) CheckPassword(pw string, padding bool) (int, error) {
+func (c *Client) CheckPassword(pw string, padding bool) (int64, error) {
if pw == "" {
return -1, ErrEmptyPassword
}
@@ -111,7 +111,7 @@ func (c *Client) CheckPassword(pw string, padding bool) (int, error) {
if err != nil {
return -1, err
}
- return int(count), nil
+ return count, nil
}
}
return 0, nil
diff --git a/modules/auth/password/pwn/pwn_test.go b/modules/auth/password/pwn/pwn_test.go
index ae03fabc57..4b760fdf32 100644
--- a/modules/auth/password/pwn/pwn_test.go
+++ b/modules/auth/password/pwn/pwn_test.go
@@ -37,25 +37,25 @@ func TestPassword(t *testing.T) {
count, err := client.CheckPassword("", false)
assert.ErrorIs(t, err, ErrEmptyPassword, "blank input should return ErrEmptyPassword")
- assert.Equal(t, -1, count)
+ assert.EqualValues(t, -1, count)
count, err = client.CheckPassword("pwned", false)
assert.NoError(t, err)
- assert.Equal(t, 1, count)
+ assert.EqualValues(t, 1, count)
count, err = client.CheckPassword("notpwned", false)
assert.NoError(t, err)
- assert.Equal(t, 0, count)
+ assert.EqualValues(t, 0, count)
count, err = client.CheckPassword("paddedpwned", true)
assert.NoError(t, err)
- assert.Equal(t, 1, count)
+ assert.EqualValues(t, 1, count)
count, err = client.CheckPassword("paddednotpwned", true)
assert.NoError(t, err)
- assert.Equal(t, 0, count)
+ assert.EqualValues(t, 0, count)
count, err = client.CheckPassword("paddednotpwnedzero", true)
assert.NoError(t, err)
- assert.Equal(t, 0, count)
+ assert.EqualValues(t, 0, count)
}
diff --git a/modules/auth/webauthn/webauthn.go b/modules/auth/webauthn/webauthn.go
index cbf5279c65..86f55c6b24 100644
--- a/modules/auth/webauthn/webauthn.go
+++ b/modules/auth/webauthn/webauthn.go
@@ -22,7 +22,7 @@ var WebAuthn *webauthn.WebAuthn
// Init initializes the WebAuthn instance from the config.
func Init() {
- gob.Register(&webauthn.SessionData{})
+ gob.Register(&webauthn.SessionData{}) // TODO: CHI-SESSION-GOB-REGISTER.
appURL, _ := protocol.FullyQualifiedOrigin(setting.AppURL)
diff --git a/modules/avatar/avatar.go b/modules/avatar/avatar.go
index 106215ec0b..3b622b99af 100644
--- a/modules/avatar/avatar.go
+++ b/modules/avatar/avatar.go
@@ -28,21 +28,18 @@ import (
// than the size after resizing.
const DefaultAvatarSize = 256
-// RandomImageSize generates and returns a random avatar image unique to input data
+// RandomImageWithSize generates and returns a random avatar image unique to input data
// in custom size (height and width).
-func RandomImageSize(size int, data []byte) (image.Image, error) {
+func RandomImageWithSize(size int, data []byte) image.Image {
// we use white as background, and use dark colors to draw blocks
- imgMaker, err := identicon.New(size, color.White, identicon.DarkColors...)
- if err != nil {
- return nil, fmt.Errorf("identicon.New: %w", err)
- }
- return imgMaker.Make(data), nil
+ imgMaker := identicon.New(size, color.White, identicon.DarkColors)
+ return imgMaker.Make(data)
}
-// RandomImage generates and returns a random avatar image unique to input data
+// RandomImageDefaultSize generates and returns a random avatar image unique to input data
// in default size (height and width).
-func RandomImage(data []byte) (image.Image, error) {
- return RandomImageSize(DefaultAvatarSize*setting.Avatar.RenderedSizeFactor, data)
+func RandomImageDefaultSize(data []byte) image.Image {
+ return RandomImageWithSize(DefaultAvatarSize*setting.Avatar.RenderedSizeFactor, data)
}
// processAvatarImage process the avatar image data, crop and resize it if necessary.
diff --git a/modules/avatar/avatar_test.go b/modules/avatar/avatar_test.go
index a5a1a7c1b0..5414184b6b 100644
--- a/modules/avatar/avatar_test.go
+++ b/modules/avatar/avatar_test.go
@@ -15,19 +15,6 @@ import (
"github.com/stretchr/testify/assert"
)
-func Test_RandomImageSize(t *testing.T) {
- _, err := RandomImageSize(0, []byte("gitea@local"))
- assert.Error(t, err)
-
- _, err = RandomImageSize(64, []byte("gitea@local"))
- assert.NoError(t, err)
-}
-
-func Test_RandomImage(t *testing.T) {
- _, err := RandomImage([]byte("gitea@local"))
- assert.NoError(t, err)
-}
-
func Test_ProcessAvatarPNG(t *testing.T) {
setting.Avatar.MaxWidth = 4096
setting.Avatar.MaxHeight = 4096
@@ -134,3 +121,18 @@ func Test_ProcessAvatarImage(t *testing.T) {
_, err = processAvatarImage(origin, 262144)
assert.ErrorContains(t, err, "image width is too large: 10 > 5")
}
+
+func BenchmarkRandomImage(b *testing.B) {
+ b.Run("size-48", func(b *testing.B) {
+ for b.Loop() {
+ // BenchmarkRandomImage/size-48-12 49549 22899 ns/op
+ RandomImageWithSize(48, []byte("test-content"))
+ }
+ })
+ b.Run("size-96", func(b *testing.B) {
+ for b.Loop() {
+ // BenchmarkRandomImage/size-96-12 13816 88187 ns/op
+ RandomImageWithSize(96, []byte("test-content"))
+ }
+ })
+}
diff --git a/modules/avatar/identicon/identicon.go b/modules/avatar/identicon/identicon.go
index 19f87da85a..a1a0f0d7bf 100644
--- a/modules/avatar/identicon/identicon.go
+++ b/modules/avatar/identicon/identicon.go
@@ -8,13 +8,14 @@ package identicon
import (
"crypto/sha256"
- "errors"
- "fmt"
"image"
"image/color"
)
-const minImageSize = 16
+const (
+ minImageSize = 16
+ maxImageSize = 2048
+)
// Identicon is used to generate pseudo-random avatars
type Identicon struct {
@@ -24,25 +25,17 @@ type Identicon struct {
rect image.Rectangle
}
-// New returns an Identicon struct with the correct settings
-// size image size
-// back background color
-// fore all possible foreground colors. only one foreground color will be picked randomly for one image
-func New(size int, back color.Color, fore ...color.Color) (*Identicon, error) {
- if len(fore) == 0 {
- return nil, errors.New("foreground is not set")
- }
-
- if size < minImageSize {
- return nil, fmt.Errorf("size %d is smaller than min size %d", size, minImageSize)
- }
-
+// New returns an Identicon struct.
+// Only one foreground color will be picked randomly for one image.
+func New(size int, backColor color.Color, foreColors []color.Color) *Identicon {
+ size = max(size, minImageSize)
+ size = min(size, maxImageSize)
return &Identicon{
- foreColors: fore,
- backColor: back,
+ foreColors: foreColors,
+ backColor: backColor,
size: size,
rect: image.Rect(0, 0, size, size),
- }, nil
+ }
}
// Make generates an avatar by data
diff --git a/modules/avatar/identicon/identicon_test.go b/modules/avatar/identicon/identicon_test.go
index 23bcc73e2e..6af4b41cce 100644
--- a/modules/avatar/identicon/identicon_test.go
+++ b/modules/avatar/identicon/identicon_test.go
@@ -23,7 +23,7 @@ func TestGenerate(t *testing.T) {
}
backColor := color.White
- imgMaker, err := New(64, backColor, DarkColors...)
+ imgMaker, err := New(64, backColor, DarkColors)
assert.NoError(t, err)
for i := 0; i < 100; i++ {
s := strconv.Itoa(i)
diff --git a/modules/base/natural_sort.go b/modules/base/natural_sort.go
index acb9002276..d1ee7b04ec 100644
--- a/modules/base/natural_sort.go
+++ b/modules/base/natural_sort.go
@@ -41,8 +41,8 @@ func naturalSortAdvance(str string, pos int) (end int, isNumber bool) {
return end, isNumber
}
-// NaturalSortLess compares two strings so that they could be sorted in natural order
-func NaturalSortLess(s1, s2 string) bool {
+// NaturalSortCompare compares two strings so that they could be sorted in natural order
+func NaturalSortCompare(s1, s2 string) int {
// There is a bug in Golang's collate package: https://github.com/golang/go/issues/67997
// text/collate: CompareString(collate.Numeric) returns wrong result for "0.0" vs "1.0" #67997
// So we need to handle the number parts by ourselves
@@ -55,16 +55,16 @@ func NaturalSortLess(s1, s2 string) bool {
if isNum1 && isNum2 {
if part1 != part2 {
if len(part1) != len(part2) {
- return len(part1) < len(part2)
+ return len(part1) - len(part2)
}
- return part1 < part2
+ return c.CompareString(part1, part2)
}
} else {
if cmp := c.CompareString(part1, part2); cmp != 0 {
- return cmp < 0
+ return cmp
}
}
pos1, pos2 = end1, end2
}
- return len(s1) < len(s2)
+ return len(s1) - len(s2)
}
diff --git a/modules/base/natural_sort_test.go b/modules/base/natural_sort_test.go
index b001bc4ac9..451aba6618 100644
--- a/modules/base/natural_sort_test.go
+++ b/modules/base/natural_sort_test.go
@@ -11,12 +11,10 @@ import (
func TestNaturalSortLess(t *testing.T) {
testLess := func(s1, s2 string) {
- assert.True(t, NaturalSortLess(s1, s2), "s1 0 {
- if table, ok = AmbiguousCharacters[key]; ok {
+ if table, ok = ambiguousTableMap[key]; ok {
break
}
idx := strings.LastIndexAny(key, "-_")
@@ -29,18 +29,18 @@ func AmbiguousTablesForLocale(locale translation.Locale) []*AmbiguousTable {
}
}
if table == nil && (locale.Language() == "zh-CN" || locale.Language() == "zh_CN") {
- table = AmbiguousCharacters["zh-hans"]
+ table = ambiguousTableMap["zh-hans"]
}
if table == nil && strings.HasPrefix(locale.Language(), "zh") {
- table = AmbiguousCharacters["zh-hant"]
+ table = ambiguousTableMap["zh-hant"]
}
if table == nil {
- table = AmbiguousCharacters["_default"]
+ table = ambiguousTableMap["_default"]
}
return []*AmbiguousTable{
table,
- AmbiguousCharacters["_common"],
+ ambiguousTableMap["_common"],
}
}
@@ -52,7 +52,7 @@ func isAmbiguous(r rune, confusableTo *rune, tables ...*AmbiguousTable) bool {
i := sort.Search(len(table.Confusable), func(i int) bool {
return table.Confusable[i] >= r
})
- (*confusableTo) = table.With[i]
+ *confusableTo = table.With[i]
return true
}
return false
diff --git a/modules/charset/ambiguous/generate.go b/modules/charset/ambiguous/generate.go
deleted file mode 100644
index e3fda5be98..0000000000
--- a/modules/charset/ambiguous/generate.go
+++ /dev/null
@@ -1,188 +0,0 @@
-// Copyright 2022 The Gitea Authors. All rights reserved.
-// SPDX-License-Identifier: MIT
-
-package main
-
-import (
- "bytes"
- "flag"
- "fmt"
- "go/format"
- "os"
- "sort"
- "text/template"
- "unicode"
-
- "code.gitea.io/gitea/modules/json"
-
- "golang.org/x/text/unicode/rangetable"
-)
-
-// ambiguous.json provides a one to one mapping of ambiguous characters to other characters
-// See https://github.com/hediet/vscode-unicode-data/blob/main/out/ambiguous.json
-
-type AmbiguousTable struct {
- Confusable []rune
- With []rune
- Locale string
- RangeTable *unicode.RangeTable
-}
-
-type RunePair struct {
- Confusable rune
- With rune
-}
-
-var verbose bool
-
-func main() {
- flag.Usage = func() {
- fmt.Fprintf(os.Stderr, `%s: Generate AmbiguousCharacter
-
-Usage: %[1]s [-v] [-o output.go] ambiguous.json
-`, os.Args[0])
- flag.PrintDefaults()
- }
-
- output := ""
- flag.BoolVar(&verbose, "v", false, "verbose output")
- flag.StringVar(&output, "o", "ambiguous_gen.go", "file to output to")
- flag.Parse()
- input := flag.Arg(0)
- if input == "" {
- input = "ambiguous.json"
- }
-
- bs, err := os.ReadFile(input)
- if err != nil {
- fatalf("Unable to read: %s Err: %v", input, err)
- }
-
- var unwrapped string
- if err := json.Unmarshal(bs, &unwrapped); err != nil {
- fatalf("Unable to unwrap content in: %s Err: %v", input, err)
- }
-
- fromJSON := map[string][]uint32{}
- if err := json.Unmarshal([]byte(unwrapped), &fromJSON); err != nil {
- fatalf("Unable to unmarshal content in: %s Err: %v", input, err)
- }
-
- tables := make([]*AmbiguousTable, 0, len(fromJSON))
- for locale, chars := range fromJSON {
- table := &AmbiguousTable{Locale: locale}
- table.Confusable = make([]rune, 0, len(chars)/2)
- table.With = make([]rune, 0, len(chars)/2)
- pairs := make([]RunePair, len(chars)/2)
- for i := 0; i < len(chars); i += 2 {
- pairs[i/2].Confusable, pairs[i/2].With = rune(chars[i]), rune(chars[i+1])
- }
- sort.Slice(pairs, func(i, j int) bool {
- return pairs[i].Confusable < pairs[j].Confusable
- })
- for _, pair := range pairs {
- table.Confusable = append(table.Confusable, pair.Confusable)
- table.With = append(table.With, pair.With)
- }
- table.RangeTable = rangetable.New(table.Confusable...)
- tables = append(tables, table)
- }
- sort.Slice(tables, func(i, j int) bool {
- return tables[i].Locale < tables[j].Locale
- })
- data := map[string]any{
- "Tables": tables,
- }
-
- if err := runTemplate(generatorTemplate, output, &data); err != nil {
- fatalf("Unable to run template: %v", err)
- }
-}
-
-func runTemplate(t *template.Template, filename string, data any) error {
- buf := bytes.NewBuffer(nil)
- if err := t.Execute(buf, data); err != nil {
- return fmt.Errorf("unable to execute template: %w", err)
- }
- bs, err := format.Source(buf.Bytes())
- if err != nil {
- verbosef("Bad source:\n%s", buf.String())
- return fmt.Errorf("unable to format source: %w", err)
- }
-
- old, err := os.ReadFile(filename)
- if err != nil && !os.IsNotExist(err) {
- return fmt.Errorf("failed to read old file %s because %w", filename, err)
- } else if err == nil {
- if bytes.Equal(bs, old) {
- // files are the same don't rewrite it.
- return nil
- }
- }
-
- file, err := os.Create(filename)
- if err != nil {
- return fmt.Errorf("failed to create file %s because %w", filename, err)
- }
- defer file.Close()
- _, err = file.Write(bs)
- if err != nil {
- return fmt.Errorf("unable to write generated source: %w", err)
- }
- return nil
-}
-
-var generatorTemplate = template.Must(template.New("ambiguousTemplate").Parse(`// This file is generated by modules/charset/ambiguous/generate.go DO NOT EDIT
-// Copyright 2022 The Gitea Authors. All rights reserved.
-// SPDX-License-Identifier: MIT
-
-
-package charset
-
-import "unicode"
-
-// This file is generated from https://github.com/hediet/vscode-unicode-data/blob/main/out/ambiguous.json
-
-// AmbiguousTable matches a confusable rune with its partner for the Locale
-type AmbiguousTable struct {
- Confusable []rune
- With []rune
- Locale string
- RangeTable *unicode.RangeTable
-}
-
-// AmbiguousCharacters provides a map by locale name to the confusable characters in that locale
-var AmbiguousCharacters = map[string]*AmbiguousTable{
- {{range .Tables}}{{printf "%q:" .Locale}} {
- Confusable: []rune{ {{range .Confusable}}{{.}},{{end}} },
- With: []rune{ {{range .With}}{{.}},{{end}} },
- Locale: {{printf "%q" .Locale}},
- RangeTable: &unicode.RangeTable{
- R16: []unicode.Range16{
- {{range .RangeTable.R16 }} {Lo:{{.Lo}}, Hi:{{.Hi}}, Stride: {{.Stride}}},
- {{end}} },
- R32: []unicode.Range32{
- {{range .RangeTable.R32}} {Lo:{{.Lo}}, Hi:{{.Hi}}, Stride: {{.Stride}}},
- {{end}} },
- LatinOffset: {{.RangeTable.LatinOffset}},
- },
- },
- {{end}}
-}
-
-`))
-
-func logf(format string, args ...any) {
- fmt.Fprintf(os.Stderr, format+"\n", args...)
-}
-
-func verbosef(format string, args ...any) {
- if verbose {
- logf(format, args...)
- }
-}
-
-func fatalf(format string, args ...any) {
- logf("fatal: "+format+"\n", args...)
- os.Exit(1)
-}
diff --git a/modules/charset/ambiguous_gen.go b/modules/charset/ambiguous_gen.go
index c88ffd5aa5..669a46c91a 100644
--- a/modules/charset/ambiguous_gen.go
+++ b/modules/charset/ambiguous_gen.go
@@ -1,5 +1,5 @@
-// This file is generated by modules/charset/ambiguous/generate.go DO NOT EDIT
-// Copyright 2022 The Gitea Authors. All rights reserved.
+// This file is generated by modules/charset/generate/generate.go DO NOT EDIT
+// Copyright 2026 The Gitea Authors. All rights reserved.
// SPDX-License-Identifier: MIT
package charset
@@ -16,821 +16,837 @@ type AmbiguousTable struct {
RangeTable *unicode.RangeTable
}
-// AmbiguousCharacters provides a map by locale name to the confusable characters in that locale
-var AmbiguousCharacters = map[string]*AmbiguousTable{
- "_common": {
- Confusable: []rune{184, 383, 388, 397, 422, 423, 439, 444, 445, 448, 451, 540, 546, 547, 577, 593, 609, 611, 617, 618, 623, 651, 655, 660, 697, 699, 700, 701, 702, 706, 707, 708, 710, 712, 714, 715, 720, 727, 731, 732, 756, 760, 884, 890, 894, 895, 900, 913, 914, 917, 918, 919, 922, 924, 925, 927, 929, 932, 933, 935, 945, 947, 953, 957, 959, 961, 963, 965, 978, 988, 1000, 1010, 1011, 1017, 1018, 1029, 1030, 1032, 1109, 1110, 1112, 1121, 1140, 1141, 1198, 1199, 1211, 1213, 1216, 1231, 1248, 1281, 1292, 1307, 1308, 1309, 1357, 1359, 1365, 1370, 1373, 1377, 1379, 1382, 1392, 1400, 1404, 1405, 1409, 1412, 1413, 1417, 1472, 1475, 1493, 1496, 1497, 1503, 1505, 1523, 1549, 1575, 1607, 1632, 1633, 1637, 1639, 1643, 1645, 1726, 1729, 1748, 1749, 1776, 1777, 1781, 1783, 1793, 1794, 1795, 1796, 1984, 1994, 2036, 2037, 2042, 2307, 2406, 2429, 2534, 2538, 2541, 2662, 2663, 2666, 2691, 2790, 2819, 2848, 2918, 2920, 3046, 3074, 3174, 3202, 3302, 3330, 3360, 3430, 3437, 3458, 3664, 3792, 4125, 4160, 4327, 4351, 4608, 4816, 5024, 5025, 5026, 5029, 5033, 5034, 5035, 5036, 5038, 5043, 5047, 5051, 5053, 5056, 5058, 5059, 5070, 5071, 5074, 5076, 5077, 5081, 5082, 5086, 5087, 5090, 5094, 5095, 5102, 5107, 5108, 5120, 5167, 5171, 5176, 5194, 5196, 5229, 5231, 5234, 5261, 5290, 5311, 5441, 5500, 5501, 5511, 5551, 5556, 5573, 5598, 5610, 5616, 5623, 5741, 5742, 5760, 5810, 5815, 5825, 5836, 5845, 5846, 5868, 5869, 5941, 6147, 6153, 7428, 7439, 7441, 7452, 7456, 7457, 7458, 7462, 7555, 7564, 7837, 7935, 8125, 8126, 8127, 8128, 8175, 8189, 8190, 8192, 8193, 8194, 8195, 8196, 8197, 8198, 8199, 8200, 8201, 8202, 8208, 8209, 8210, 8218, 8219, 8228, 8232, 8233, 8239, 8242, 8249, 8250, 8257, 8259, 8260, 8270, 8275, 8282, 8287, 8450, 8458, 8459, 8460, 8461, 8462, 8464, 8465, 8466, 8467, 8469, 8473, 8474, 8475, 8476, 8477, 8484, 8488, 8490, 8492, 8493, 8494, 8495, 8496, 8497, 8499, 8500, 8505, 8509, 8517, 8518, 8519, 8520, 8521, 8544, 8548, 8553, 8556, 8557, 8558, 8559, 8560, 8564, 8569, 8572, 8573, 8574, 8722, 8725, 8726, 8727, 8739, 8744, 8746, 8758, 8764, 8868, 8897, 8899, 8959, 9075, 9076, 9082, 9213, 9585, 9587, 10088, 10089, 10094, 10095, 10098, 10099, 10100, 10101, 10133, 10134, 10187, 10189, 10201, 10539, 10540, 10741, 10744, 10745, 10799, 11397, 11406, 11410, 11412, 11416, 11418, 11422, 11423, 11426, 11427, 11428, 11429, 11430, 11432, 11436, 11450, 11462, 11466, 11468, 11472, 11474, 11576, 11577, 11599, 11601, 11604, 11605, 11613, 11840, 12034, 12035, 12295, 12308, 12309, 12339, 12448, 12755, 12756, 20022, 20031, 42192, 42193, 42194, 42195, 42196, 42198, 42199, 42201, 42202, 42204, 42205, 42207, 42208, 42209, 42210, 42211, 42214, 42215, 42218, 42219, 42220, 42222, 42224, 42226, 42227, 42228, 42232, 42233, 42237, 42239, 42510, 42564, 42567, 42719, 42731, 42735, 42801, 42842, 42858, 42862, 42872, 42889, 42892, 42904, 42905, 42911, 42923, 42930, 42931, 42932, 43826, 43829, 43837, 43847, 43848, 43854, 43858, 43866, 43893, 43905, 43907, 43923, 43945, 43946, 43951, 64422, 64423, 64424, 64425, 64426, 64427, 64428, 64429, 64830, 64831, 65072, 65101, 65102, 65103, 65112, 65128, 65165, 65166, 65257, 65258, 65259, 65260, 65282, 65284, 65285, 65286, 65287, 65290, 65291, 65293, 65294, 65295, 65296, 65297, 65298, 65299, 65300, 65301, 65302, 65303, 65304, 65305, 65308, 65309, 65310, 65312, 65313, 65314, 65315, 65316, 65317, 65318, 65319, 65320, 65321, 65322, 65323, 65324, 65325, 65326, 65327, 65328, 65329, 65330, 65331, 65332, 65333, 65334, 65335, 65336, 65337, 65338, 65339, 65340, 65341, 65342, 65343, 65344, 65345, 65346, 65347, 65348, 65349, 65350, 65351, 65352, 65353, 65354, 65355, 65356, 65357, 65358, 65359, 65360, 65361, 65362, 65363, 65364, 65365, 65366, 65367, 65368, 65369, 65370, 65371, 65372, 65373, 65512, 66178, 66182, 66183, 66186, 66192, 66194, 66197, 66198, 66199, 66203, 66208, 66209, 66210, 66213, 66219, 66224, 66225, 66226, 66228, 66255, 66293, 66305, 66306, 66313, 66321, 66325, 66327, 66330, 66335, 66336, 66338, 66564, 66581, 66587, 66592, 66604, 66621, 66632, 66740, 66754, 66766, 66770, 66794, 66806, 66835, 66838, 66840, 66844, 66845, 66853, 66854, 66855, 68176, 70864, 71430, 71434, 71438, 71439, 71840, 71842, 71843, 71844, 71846, 71849, 71852, 71854, 71855, 71858, 71861, 71864, 71867, 71868, 71872, 71873, 71874, 71875, 71876, 71878, 71880, 71882, 71884, 71893, 71894, 71895, 71896, 71900, 71904, 71909, 71910, 71913, 71916, 71919, 71922, 93960, 93962, 93974, 93992, 94005, 94010, 94011, 94015, 94016, 94018, 94019, 94033, 94034, 119060, 119149, 119302, 119309, 119311, 119314, 119315, 119318, 119338, 119350, 119351, 119354, 119355, 119808, 119809, 119810, 119811, 119812, 119813, 119814, 119815, 119816, 119817, 119818, 119819, 119820, 119821, 119822, 119823, 119824, 119825, 119826, 119827, 119828, 119829, 119830, 119831, 119832, 119833, 119834, 119835, 119836, 119837, 119838, 119839, 119840, 119841, 119842, 119843, 119844, 119845, 119847, 119848, 119849, 119850, 119851, 119852, 119853, 119854, 119855, 119856, 119857, 119858, 119859, 119860, 119861, 119862, 119863, 119864, 119865, 119866, 119867, 119868, 119869, 119870, 119871, 119872, 119873, 119874, 119875, 119876, 119877, 119878, 119879, 119880, 119881, 119882, 119883, 119884, 119885, 119886, 119887, 119888, 119889, 119890, 119891, 119892, 119894, 119895, 119896, 119897, 119899, 119900, 119901, 119902, 119903, 119904, 119905, 119906, 119907, 119908, 119909, 119910, 119911, 119912, 119913, 119914, 119915, 119916, 119917, 119918, 119919, 119920, 119921, 119922, 119923, 119924, 119925, 119926, 119927, 119928, 119929, 119930, 119931, 119932, 119933, 119934, 119935, 119936, 119937, 119938, 119939, 119940, 119941, 119942, 119943, 119944, 119945, 119946, 119947, 119948, 119949, 119951, 119952, 119953, 119954, 119955, 119956, 119957, 119958, 119959, 119960, 119961, 119962, 119963, 119964, 119966, 119967, 119970, 119973, 119974, 119977, 119978, 119979, 119980, 119982, 119983, 119984, 119985, 119986, 119987, 119988, 119989, 119990, 119991, 119992, 119993, 119995, 119997, 119998, 119999, 120000, 120001, 120003, 120005, 120006, 120007, 120008, 120009, 120010, 120011, 120012, 120013, 120014, 120015, 120016, 120017, 120018, 120019, 120020, 120021, 120022, 120023, 120024, 120025, 120026, 120027, 120028, 120029, 120030, 120031, 120032, 120033, 120034, 120035, 120036, 120037, 120038, 120039, 120040, 120041, 120042, 120043, 120044, 120045, 120046, 120047, 120048, 120049, 120050, 120051, 120052, 120053, 120055, 120056, 120057, 120058, 120059, 120060, 120061, 120062, 120063, 120064, 120065, 120066, 120067, 120068, 120069, 120071, 120072, 120073, 120074, 120077, 120078, 120079, 120080, 120081, 120082, 120083, 120084, 120086, 120087, 120088, 120089, 120090, 120091, 120092, 120094, 120095, 120096, 120097, 120098, 120099, 120100, 120101, 120102, 120103, 120104, 120105, 120107, 120108, 120109, 120110, 120111, 120112, 120113, 120114, 120115, 120116, 120117, 120118, 120119, 120120, 120121, 120123, 120124, 120125, 120126, 120128, 120129, 120130, 120131, 120132, 120134, 120138, 120139, 120140, 120141, 120142, 120143, 120144, 120146, 120147, 120148, 120149, 120150, 120151, 120152, 120153, 120154, 120155, 120156, 120157, 120159, 120160, 120161, 120162, 120163, 120164, 120165, 120166, 120167, 120168, 120169, 120170, 120171, 120172, 120173, 120174, 120175, 120176, 120177, 120178, 120179, 120180, 120181, 120182, 120183, 120184, 120185, 120186, 120187, 120188, 120189, 120190, 120191, 120192, 120193, 120194, 120195, 120196, 120197, 120198, 120199, 120200, 120201, 120202, 120203, 120204, 120205, 120206, 120207, 120208, 120209, 120211, 120212, 120213, 120214, 120215, 120216, 120217, 120218, 120219, 120220, 120221, 120222, 120223, 120224, 120225, 120226, 120227, 120228, 120229, 120230, 120231, 120232, 120233, 120234, 120235, 120236, 120237, 120238, 120239, 120240, 120241, 120242, 120243, 120244, 120245, 120246, 120247, 120248, 120249, 120250, 120251, 120252, 120253, 120254, 120255, 120256, 120257, 120258, 120259, 120260, 120261, 120263, 120264, 120265, 120266, 120267, 120268, 120269, 120270, 120271, 120272, 120273, 120274, 120275, 120276, 120277, 120278, 120279, 120280, 120281, 120282, 120283, 120284, 120285, 120286, 120287, 120288, 120289, 120290, 120291, 120292, 120293, 120294, 120295, 120296, 120297, 120298, 120299, 120300, 120301, 120302, 120303, 120304, 120305, 120306, 120307, 120308, 120309, 120310, 120311, 120312, 120313, 120315, 120316, 120317, 120318, 120319, 120320, 120321, 120322, 120323, 120324, 120325, 120326, 120327, 120328, 120329, 120330, 120331, 120332, 120333, 120334, 120335, 120336, 120337, 120338, 120339, 120340, 120341, 120342, 120343, 120344, 120345, 120346, 120347, 120348, 120349, 120350, 120351, 120352, 120353, 120354, 120355, 120356, 120357, 120358, 120359, 120360, 120361, 120362, 120363, 120364, 120365, 120367, 120368, 120369, 120370, 120371, 120372, 120373, 120374, 120375, 120376, 120377, 120378, 120379, 120380, 120381, 120382, 120383, 120384, 120385, 120386, 120387, 120388, 120389, 120390, 120391, 120392, 120393, 120394, 120395, 120396, 120397, 120398, 120399, 120400, 120401, 120402, 120403, 120404, 120405, 120406, 120407, 120408, 120409, 120410, 120411, 120412, 120413, 120414, 120415, 120416, 120417, 120419, 120420, 120421, 120422, 120423, 120424, 120425, 120426, 120427, 120428, 120429, 120430, 120431, 120432, 120433, 120434, 120435, 120436, 120437, 120438, 120439, 120440, 120441, 120442, 120443, 120444, 120445, 120446, 120447, 120448, 120449, 120450, 120451, 120452, 120453, 120454, 120455, 120456, 120457, 120458, 120459, 120460, 120461, 120462, 120463, 120464, 120465, 120466, 120467, 120468, 120469, 120471, 120472, 120473, 120474, 120475, 120476, 120477, 120478, 120479, 120480, 120481, 120482, 120483, 120484, 120488, 120489, 120492, 120493, 120494, 120496, 120497, 120499, 120500, 120502, 120504, 120507, 120508, 120510, 120514, 120516, 120522, 120526, 120528, 120530, 120532, 120534, 120544, 120546, 120547, 120550, 120551, 120552, 120554, 120555, 120557, 120558, 120560, 120562, 120565, 120566, 120568, 120572, 120574, 120580, 120584, 120586, 120588, 120590, 120592, 120602, 120604, 120605, 120608, 120609, 120610, 120612, 120613, 120615, 120616, 120618, 120620, 120623, 120624, 120626, 120630, 120632, 120638, 120642, 120644, 120646, 120648, 120650, 120660, 120662, 120663, 120666, 120667, 120668, 120670, 120671, 120673, 120674, 120676, 120678, 120681, 120682, 120684, 120688, 120690, 120696, 120700, 120702, 120704, 120706, 120708, 120718, 120720, 120721, 120724, 120725, 120726, 120728, 120729, 120731, 120732, 120734, 120736, 120739, 120740, 120742, 120746, 120748, 120754, 120758, 120760, 120762, 120764, 120766, 120776, 120778, 120782, 120783, 120784, 120785, 120786, 120787, 120788, 120789, 120790, 120791, 120792, 120793, 120794, 120795, 120796, 120797, 120798, 120799, 120800, 120801, 120802, 120803, 120804, 120805, 120806, 120807, 120808, 120809, 120810, 120811, 120812, 120813, 120814, 120815, 120816, 120817, 120818, 120819, 120820, 120821, 120822, 120823, 120824, 120825, 120826, 120827, 120828, 120829, 120830, 120831, 125127, 125131, 126464, 126500, 126564, 126592, 126596, 128844, 128872, 130032, 130033, 130034, 130035, 130036, 130037, 130038, 130039, 130040, 130041},
- With: []rune{44, 102, 98, 103, 82, 50, 51, 53, 115, 73, 33, 51, 56, 56, 63, 97, 103, 121, 105, 105, 119, 117, 121, 63, 96, 96, 96, 96, 96, 60, 62, 94, 94, 96, 96, 96, 58, 45, 105, 126, 96, 58, 96, 105, 59, 74, 96, 65, 66, 69, 90, 72, 75, 77, 78, 79, 80, 84, 89, 88, 97, 121, 105, 118, 111, 112, 111, 117, 89, 70, 50, 99, 106, 67, 77, 83, 73, 74, 115, 105, 106, 119, 86, 118, 89, 121, 104, 101, 73, 105, 51, 100, 71, 113, 87, 119, 85, 83, 79, 96, 96, 119, 113, 113, 104, 110, 110, 117, 103, 102, 111, 58, 108, 58, 108, 118, 96, 108, 111, 96, 44, 108, 111, 46, 108, 111, 86, 44, 42, 111, 111, 45, 111, 46, 73, 111, 86, 46, 46, 58, 58, 79, 108, 96, 96, 95, 58, 111, 63, 79, 56, 57, 111, 57, 56, 58, 111, 56, 79, 79, 57, 111, 111, 111, 111, 111, 111, 111, 111, 57, 111, 111, 111, 111, 111, 121, 111, 85, 79, 68, 82, 84, 105, 89, 65, 74, 69, 63, 87, 77, 72, 89, 71, 104, 90, 52, 98, 82, 87, 83, 86, 83, 76, 67, 80, 75, 100, 54, 71, 66, 61, 86, 62, 60, 96, 85, 80, 100, 98, 74, 76, 50, 120, 72, 120, 82, 98, 70, 65, 68, 68, 77, 66, 88, 120, 32, 60, 88, 73, 96, 75, 77, 58, 43, 47, 58, 58, 99, 111, 111, 117, 118, 119, 122, 114, 103, 121, 102, 121, 96, 105, 96, 126, 96, 96, 96, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 45, 45, 45, 44, 96, 46, 32, 32, 32, 96, 60, 62, 47, 45, 47, 42, 126, 58, 32, 67, 103, 72, 72, 72, 104, 73, 73, 76, 108, 78, 80, 81, 82, 82, 82, 90, 90, 75, 66, 67, 101, 101, 69, 70, 77, 111, 105, 121, 68, 100, 101, 105, 106, 73, 86, 88, 76, 67, 68, 77, 105, 118, 120, 73, 99, 100, 45, 47, 92, 42, 73, 118, 85, 58, 126, 84, 118, 85, 69, 105, 112, 97, 73, 47, 88, 40, 41, 60, 62, 40, 41, 123, 125, 43, 45, 47, 92, 84, 120, 120, 92, 47, 92, 120, 114, 72, 73, 75, 77, 78, 79, 111, 80, 112, 67, 99, 84, 89, 88, 45, 47, 57, 51, 76, 54, 86, 69, 73, 33, 79, 81, 88, 61, 92, 47, 79, 40, 41, 47, 61, 47, 92, 92, 47, 66, 80, 100, 68, 84, 71, 75, 74, 67, 90, 70, 77, 78, 76, 83, 82, 86, 72, 87, 88, 89, 65, 69, 73, 79, 85, 46, 44, 58, 61, 46, 50, 105, 86, 63, 50, 115, 50, 51, 57, 38, 58, 96, 70, 102, 117, 51, 74, 88, 66, 101, 102, 111, 114, 114, 117, 117, 121, 105, 114, 119, 122, 118, 115, 99, 111, 111, 111, 111, 111, 111, 111, 111, 40, 41, 58, 95, 95, 95, 45, 92, 108, 108, 111, 111, 111, 111, 34, 36, 37, 38, 96, 42, 43, 45, 46, 47, 48, 49, 50, 51, 52, 53, 54, 55, 56, 57, 60, 61, 62, 64, 65, 66, 67, 68, 69, 70, 71, 72, 73, 74, 75, 76, 77, 78, 79, 80, 81, 82, 83, 84, 85, 86, 87, 88, 89, 90, 91, 92, 93, 94, 95, 96, 97, 98, 99, 100, 101, 102, 103, 104, 105, 106, 107, 108, 109, 110, 111, 112, 113, 114, 115, 116, 117, 118, 119, 120, 121, 122, 123, 124, 125, 73, 66, 69, 70, 124, 88, 79, 80, 83, 84, 43, 65, 66, 67, 70, 79, 77, 84, 89, 88, 72, 90, 66, 67, 124, 77, 84, 88, 56, 42, 108, 88, 79, 67, 76, 83, 111, 99, 115, 82, 79, 85, 55, 111, 117, 78, 79, 75, 67, 86, 70, 76, 88, 46, 79, 118, 119, 119, 119, 86, 70, 76, 89, 69, 90, 57, 69, 52, 76, 79, 85, 53, 84, 118, 115, 70, 105, 122, 55, 111, 51, 57, 54, 57, 111, 117, 121, 79, 90, 87, 67, 88, 87, 67, 86, 84, 76, 73, 82, 83, 51, 62, 65, 85, 89, 96, 96, 123, 46, 51, 86, 92, 55, 70, 82, 76, 60, 62, 47, 92, 65, 66, 67, 68, 69, 70, 71, 72, 73, 74, 75, 76, 77, 78, 79, 80, 81, 82, 83, 84, 85, 86, 87, 88, 89, 90, 97, 98, 99, 100, 101, 102, 103, 104, 105, 106, 107, 108, 110, 111, 112, 113, 114, 115, 116, 117, 118, 119, 120, 121, 122, 65, 66, 67, 68, 69, 70, 71, 72, 73, 74, 75, 76, 77, 78, 79, 80, 81, 82, 83, 84, 85, 86, 87, 88, 89, 90, 97, 98, 99, 100, 101, 102, 103, 105, 106, 107, 108, 110, 111, 112, 113, 114, 115, 116, 117, 118, 119, 120, 121, 122, 65, 66, 67, 68, 69, 70, 71, 72, 73, 74, 75, 76, 77, 78, 79, 80, 81, 82, 83, 84, 85, 86, 87, 88, 89, 90, 97, 98, 99, 100, 101, 102, 103, 104, 105, 106, 107, 108, 110, 111, 112, 113, 114, 115, 116, 117, 118, 119, 120, 121, 122, 65, 67, 68, 71, 74, 75, 78, 79, 80, 81, 83, 84, 85, 86, 87, 88, 89, 90, 97, 98, 99, 100, 102, 104, 105, 106, 107, 108, 110, 112, 113, 114, 115, 116, 117, 118, 119, 120, 121, 122, 65, 66, 67, 68, 69, 70, 71, 72, 73, 74, 75, 76, 77, 78, 79, 80, 81, 82, 83, 84, 85, 86, 87, 88, 89, 90, 97, 98, 99, 100, 101, 102, 103, 104, 105, 106, 107, 108, 110, 111, 112, 113, 114, 115, 116, 117, 118, 119, 120, 121, 122, 65, 66, 68, 69, 70, 71, 74, 75, 76, 77, 78, 79, 80, 81, 83, 84, 85, 86, 87, 88, 89, 97, 98, 99, 100, 101, 102, 103, 104, 105, 106, 107, 73, 110, 111, 112, 113, 114, 115, 116, 117, 118, 119, 120, 121, 122, 65, 66, 68, 69, 70, 71, 73, 74, 75, 76, 77, 79, 83, 84, 85, 86, 87, 88, 89, 97, 98, 99, 100, 101, 102, 103, 104, 105, 106, 107, 73, 110, 111, 112, 113, 114, 115, 116, 117, 118, 119, 120, 121, 122, 65, 66, 67, 68, 69, 70, 71, 72, 73, 74, 75, 76, 77, 78, 79, 80, 81, 82, 83, 84, 85, 86, 87, 88, 89, 90, 97, 98, 99, 100, 101, 102, 103, 104, 105, 106, 107, 73, 110, 111, 112, 113, 114, 115, 116, 117, 118, 119, 120, 121, 122, 65, 66, 67, 68, 69, 70, 71, 72, 73, 74, 75, 76, 77, 78, 79, 80, 81, 82, 83, 84, 85, 86, 87, 88, 89, 90, 97, 98, 99, 100, 101, 102, 103, 104, 105, 106, 107, 73, 110, 111, 112, 113, 114, 115, 116, 117, 118, 119, 120, 121, 122, 65, 66, 67, 68, 69, 70, 71, 72, 73, 74, 75, 76, 77, 78, 79, 80, 81, 82, 83, 84, 85, 86, 87, 88, 89, 90, 97, 98, 99, 100, 101, 102, 103, 104, 105, 106, 107, 73, 110, 111, 112, 113, 114, 115, 116, 117, 118, 119, 120, 121, 122, 65, 66, 67, 68, 69, 70, 71, 72, 73, 74, 75, 76, 77, 78, 79, 80, 81, 82, 83, 84, 85, 86, 87, 88, 89, 90, 97, 98, 99, 100, 101, 102, 103, 104, 105, 106, 107, 73, 110, 111, 112, 113, 114, 115, 116, 117, 118, 119, 120, 121, 122, 65, 66, 67, 68, 69, 70, 71, 72, 73, 74, 75, 76, 77, 78, 79, 80, 81, 82, 83, 84, 85, 86, 87, 88, 89, 90, 97, 98, 99, 100, 101, 102, 103, 104, 105, 106, 107, 73, 110, 111, 112, 113, 114, 115, 116, 117, 118, 119, 120, 121, 122, 65, 66, 67, 68, 69, 70, 71, 72, 73, 74, 75, 76, 77, 78, 79, 80, 81, 82, 83, 84, 85, 86, 87, 88, 89, 90, 97, 98, 99, 100, 101, 102, 103, 104, 105, 106, 107, 73, 110, 111, 112, 113, 114, 115, 116, 117, 118, 119, 120, 121, 122, 105, 65, 66, 69, 90, 72, 73, 75, 77, 78, 79, 80, 84, 89, 88, 97, 121, 105, 118, 111, 112, 111, 117, 112, 65, 66, 69, 90, 72, 73, 75, 77, 78, 79, 80, 84, 89, 88, 97, 121, 105, 118, 111, 112, 111, 117, 112, 65, 66, 69, 90, 72, 73, 75, 77, 78, 79, 80, 84, 89, 88, 97, 121, 105, 118, 111, 112, 111, 117, 112, 65, 66, 69, 90, 72, 73, 75, 77, 78, 79, 80, 84, 89, 88, 97, 121, 105, 118, 111, 112, 111, 117, 112, 65, 66, 69, 90, 72, 73, 75, 77, 78, 79, 80, 84, 89, 88, 97, 121, 105, 118, 111, 112, 111, 117, 112, 70, 79, 73, 50, 51, 52, 53, 54, 55, 56, 57, 79, 73, 50, 51, 52, 53, 54, 55, 56, 57, 79, 73, 50, 51, 52, 53, 54, 55, 56, 57, 79, 73, 50, 51, 52, 53, 54, 55, 56, 57, 79, 73, 50, 51, 52, 53, 54, 55, 56, 57, 108, 56, 108, 111, 111, 108, 111, 67, 84, 79, 73, 50, 51, 52, 53, 54, 55, 56, 57},
- Locale: "_common",
- RangeTable: &unicode.RangeTable{
- R16: []unicode.Range16{
- {Lo: 184, Hi: 383, Stride: 199},
- {Lo: 388, Hi: 397, Stride: 9},
- {Lo: 422, Hi: 423, Stride: 1},
- {Lo: 439, Hi: 444, Stride: 5},
- {Lo: 445, Hi: 451, Stride: 3},
- {Lo: 540, Hi: 546, Stride: 6},
- {Lo: 547, Hi: 577, Stride: 30},
- {Lo: 593, Hi: 609, Stride: 16},
- {Lo: 611, Hi: 617, Stride: 6},
- {Lo: 618, Hi: 623, Stride: 5},
- {Lo: 651, Hi: 655, Stride: 4},
- {Lo: 660, Hi: 697, Stride: 37},
- {Lo: 699, Hi: 702, Stride: 1},
- {Lo: 706, Hi: 708, Stride: 1},
- {Lo: 710, Hi: 714, Stride: 2},
- {Lo: 715, Hi: 720, Stride: 5},
- {Lo: 727, Hi: 731, Stride: 4},
- {Lo: 732, Hi: 756, Stride: 24},
- {Lo: 760, Hi: 884, Stride: 124},
- {Lo: 890, Hi: 894, Stride: 4},
- {Lo: 895, Hi: 900, Stride: 5},
- {Lo: 913, Hi: 914, Stride: 1},
- {Lo: 917, Hi: 919, Stride: 1},
- {Lo: 922, Hi: 924, Stride: 2},
- {Lo: 925, Hi: 929, Stride: 2},
- {Lo: 932, Hi: 933, Stride: 1},
- {Lo: 935, Hi: 945, Stride: 10},
- {Lo: 947, Hi: 953, Stride: 6},
- {Lo: 957, Hi: 965, Stride: 2},
- {Lo: 978, Hi: 988, Stride: 10},
- {Lo: 1000, Hi: 1010, Stride: 10},
- {Lo: 1011, Hi: 1017, Stride: 6},
- {Lo: 1018, Hi: 1029, Stride: 11},
- {Lo: 1030, Hi: 1032, Stride: 2},
- {Lo: 1109, Hi: 1110, Stride: 1},
- {Lo: 1112, Hi: 1121, Stride: 9},
- {Lo: 1140, Hi: 1141, Stride: 1},
- {Lo: 1198, Hi: 1199, Stride: 1},
- {Lo: 1211, Hi: 1213, Stride: 2},
- {Lo: 1216, Hi: 1231, Stride: 15},
- {Lo: 1248, Hi: 1281, Stride: 33},
- {Lo: 1292, Hi: 1307, Stride: 15},
- {Lo: 1308, Hi: 1309, Stride: 1},
- {Lo: 1357, Hi: 1359, Stride: 2},
- {Lo: 1365, Hi: 1370, Stride: 5},
- {Lo: 1373, Hi: 1377, Stride: 4},
- {Lo: 1379, Hi: 1382, Stride: 3},
- {Lo: 1392, Hi: 1400, Stride: 8},
- {Lo: 1404, Hi: 1405, Stride: 1},
- {Lo: 1409, Hi: 1412, Stride: 3},
- {Lo: 1413, Hi: 1417, Stride: 4},
- {Lo: 1472, Hi: 1475, Stride: 3},
- {Lo: 1493, Hi: 1496, Stride: 3},
- {Lo: 1497, Hi: 1503, Stride: 6},
- {Lo: 1505, Hi: 1523, Stride: 18},
- {Lo: 1549, Hi: 1575, Stride: 26},
- {Lo: 1607, Hi: 1632, Stride: 25},
- {Lo: 1633, Hi: 1637, Stride: 4},
- {Lo: 1639, Hi: 1643, Stride: 4},
- {Lo: 1645, Hi: 1726, Stride: 81},
- {Lo: 1729, Hi: 1748, Stride: 19},
- {Lo: 1749, Hi: 1776, Stride: 27},
- {Lo: 1777, Hi: 1781, Stride: 4},
- {Lo: 1783, Hi: 1793, Stride: 10},
- {Lo: 1794, Hi: 1796, Stride: 1},
- {Lo: 1984, Hi: 1994, Stride: 10},
- {Lo: 2036, Hi: 2037, Stride: 1},
- {Lo: 2042, Hi: 2307, Stride: 265},
- {Lo: 2406, Hi: 2429, Stride: 23},
- {Lo: 2534, Hi: 2538, Stride: 4},
- {Lo: 2541, Hi: 2662, Stride: 121},
- {Lo: 2663, Hi: 2666, Stride: 3},
- {Lo: 2691, Hi: 2790, Stride: 99},
- {Lo: 2819, Hi: 2848, Stride: 29},
- {Lo: 2918, Hi: 2920, Stride: 2},
- {Lo: 3046, Hi: 3074, Stride: 28},
- {Lo: 3174, Hi: 3202, Stride: 28},
- {Lo: 3302, Hi: 3330, Stride: 28},
- {Lo: 3360, Hi: 3430, Stride: 70},
- {Lo: 3437, Hi: 3458, Stride: 21},
- {Lo: 3664, Hi: 3792, Stride: 128},
- {Lo: 4125, Hi: 4160, Stride: 35},
- {Lo: 4327, Hi: 4351, Stride: 24},
- {Lo: 4608, Hi: 5024, Stride: 208},
- {Lo: 5025, Hi: 5026, Stride: 1},
- {Lo: 5029, Hi: 5033, Stride: 4},
- {Lo: 5034, Hi: 5036, Stride: 1},
- {Lo: 5038, Hi: 5043, Stride: 5},
- {Lo: 5047, Hi: 5051, Stride: 4},
- {Lo: 5053, Hi: 5056, Stride: 3},
- {Lo: 5058, Hi: 5059, Stride: 1},
- {Lo: 5070, Hi: 5071, Stride: 1},
- {Lo: 5074, Hi: 5076, Stride: 2},
- {Lo: 5077, Hi: 5081, Stride: 4},
- {Lo: 5082, Hi: 5086, Stride: 4},
- {Lo: 5087, Hi: 5090, Stride: 3},
- {Lo: 5094, Hi: 5095, Stride: 1},
- {Lo: 5102, Hi: 5107, Stride: 5},
- {Lo: 5108, Hi: 5120, Stride: 12},
- {Lo: 5167, Hi: 5171, Stride: 4},
- {Lo: 5176, Hi: 5194, Stride: 18},
- {Lo: 5196, Hi: 5229, Stride: 33},
- {Lo: 5231, Hi: 5234, Stride: 3},
- {Lo: 5261, Hi: 5290, Stride: 29},
- {Lo: 5311, Hi: 5441, Stride: 130},
- {Lo: 5500, Hi: 5501, Stride: 1},
- {Lo: 5511, Hi: 5551, Stride: 40},
- {Lo: 5556, Hi: 5573, Stride: 17},
- {Lo: 5598, Hi: 5610, Stride: 12},
- {Lo: 5616, Hi: 5623, Stride: 7},
- {Lo: 5741, Hi: 5742, Stride: 1},
- {Lo: 5760, Hi: 5810, Stride: 50},
- {Lo: 5815, Hi: 5825, Stride: 10},
- {Lo: 5836, Hi: 5845, Stride: 9},
- {Lo: 5846, Hi: 5868, Stride: 22},
- {Lo: 5869, Hi: 5941, Stride: 72},
- {Lo: 6147, Hi: 6153, Stride: 6},
- {Lo: 7428, Hi: 7439, Stride: 11},
- {Lo: 7441, Hi: 7452, Stride: 11},
- {Lo: 7456, Hi: 7458, Stride: 1},
- {Lo: 7462, Hi: 7555, Stride: 93},
- {Lo: 7564, Hi: 7837, Stride: 273},
- {Lo: 7935, Hi: 8125, Stride: 190},
- {Lo: 8126, Hi: 8128, Stride: 1},
- {Lo: 8175, Hi: 8189, Stride: 14},
- {Lo: 8190, Hi: 8192, Stride: 2},
- {Lo: 8193, Hi: 8202, Stride: 1},
- {Lo: 8208, Hi: 8210, Stride: 1},
- {Lo: 8218, Hi: 8219, Stride: 1},
- {Lo: 8228, Hi: 8232, Stride: 4},
- {Lo: 8233, Hi: 8239, Stride: 6},
- {Lo: 8242, Hi: 8249, Stride: 7},
- {Lo: 8250, Hi: 8257, Stride: 7},
- {Lo: 8259, Hi: 8260, Stride: 1},
- {Lo: 8270, Hi: 8275, Stride: 5},
- {Lo: 8282, Hi: 8287, Stride: 5},
- {Lo: 8450, Hi: 8458, Stride: 8},
- {Lo: 8459, Hi: 8462, Stride: 1},
- {Lo: 8464, Hi: 8467, Stride: 1},
- {Lo: 8469, Hi: 8473, Stride: 4},
- {Lo: 8474, Hi: 8477, Stride: 1},
- {Lo: 8484, Hi: 8488, Stride: 4},
- {Lo: 8490, Hi: 8492, Stride: 2},
- {Lo: 8493, Hi: 8497, Stride: 1},
- {Lo: 8499, Hi: 8500, Stride: 1},
- {Lo: 8505, Hi: 8509, Stride: 4},
- {Lo: 8517, Hi: 8521, Stride: 1},
- {Lo: 8544, Hi: 8548, Stride: 4},
- {Lo: 8553, Hi: 8556, Stride: 3},
- {Lo: 8557, Hi: 8560, Stride: 1},
- {Lo: 8564, Hi: 8569, Stride: 5},
- {Lo: 8572, Hi: 8574, Stride: 1},
- {Lo: 8722, Hi: 8725, Stride: 3},
- {Lo: 8726, Hi: 8727, Stride: 1},
- {Lo: 8739, Hi: 8744, Stride: 5},
- {Lo: 8746, Hi: 8758, Stride: 12},
- {Lo: 8764, Hi: 8868, Stride: 104},
- {Lo: 8897, Hi: 8899, Stride: 2},
- {Lo: 8959, Hi: 9075, Stride: 116},
- {Lo: 9076, Hi: 9082, Stride: 6},
- {Lo: 9213, Hi: 9585, Stride: 372},
- {Lo: 9587, Hi: 10088, Stride: 501},
- {Lo: 10089, Hi: 10094, Stride: 5},
- {Lo: 10095, Hi: 10098, Stride: 3},
- {Lo: 10099, Hi: 10101, Stride: 1},
- {Lo: 10133, Hi: 10134, Stride: 1},
- {Lo: 10187, Hi: 10189, Stride: 2},
- {Lo: 10201, Hi: 10539, Stride: 338},
- {Lo: 10540, Hi: 10741, Stride: 201},
- {Lo: 10744, Hi: 10745, Stride: 1},
- {Lo: 10799, Hi: 11397, Stride: 598},
- {Lo: 11406, Hi: 11410, Stride: 4},
- {Lo: 11412, Hi: 11416, Stride: 4},
- {Lo: 11418, Hi: 11422, Stride: 4},
- {Lo: 11423, Hi: 11426, Stride: 3},
- {Lo: 11427, Hi: 11430, Stride: 1},
- {Lo: 11432, Hi: 11436, Stride: 4},
- {Lo: 11450, Hi: 11462, Stride: 12},
- {Lo: 11466, Hi: 11468, Stride: 2},
- {Lo: 11472, Hi: 11474, Stride: 2},
- {Lo: 11576, Hi: 11577, Stride: 1},
- {Lo: 11599, Hi: 11601, Stride: 2},
- {Lo: 11604, Hi: 11605, Stride: 1},
- {Lo: 11613, Hi: 11840, Stride: 227},
- {Lo: 12034, Hi: 12035, Stride: 1},
- {Lo: 12295, Hi: 12308, Stride: 13},
- {Lo: 12309, Hi: 12339, Stride: 30},
- {Lo: 12448, Hi: 12755, Stride: 307},
- {Lo: 12756, Hi: 20022, Stride: 7266},
- {Lo: 20031, Hi: 42192, Stride: 22161},
- {Lo: 42193, Hi: 42196, Stride: 1},
- {Lo: 42198, Hi: 42199, Stride: 1},
- {Lo: 42201, Hi: 42202, Stride: 1},
- {Lo: 42204, Hi: 42205, Stride: 1},
- {Lo: 42207, Hi: 42211, Stride: 1},
- {Lo: 42214, Hi: 42215, Stride: 1},
- {Lo: 42218, Hi: 42220, Stride: 1},
- {Lo: 42222, Hi: 42226, Stride: 2},
- {Lo: 42227, Hi: 42228, Stride: 1},
- {Lo: 42232, Hi: 42233, Stride: 1},
- {Lo: 42237, Hi: 42239, Stride: 2},
- {Lo: 42510, Hi: 42564, Stride: 54},
- {Lo: 42567, Hi: 42719, Stride: 152},
- {Lo: 42731, Hi: 42735, Stride: 4},
- {Lo: 42801, Hi: 42842, Stride: 41},
- {Lo: 42858, Hi: 42862, Stride: 4},
- {Lo: 42872, Hi: 42889, Stride: 17},
- {Lo: 42892, Hi: 42904, Stride: 12},
- {Lo: 42905, Hi: 42911, Stride: 6},
- {Lo: 42923, Hi: 42930, Stride: 7},
- {Lo: 42931, Hi: 42932, Stride: 1},
- {Lo: 43826, Hi: 43829, Stride: 3},
- {Lo: 43837, Hi: 43847, Stride: 10},
- {Lo: 43848, Hi: 43854, Stride: 6},
- {Lo: 43858, Hi: 43866, Stride: 8},
- {Lo: 43893, Hi: 43905, Stride: 12},
- {Lo: 43907, Hi: 43923, Stride: 16},
- {Lo: 43945, Hi: 43946, Stride: 1},
- {Lo: 43951, Hi: 64422, Stride: 20471},
- {Lo: 64423, Hi: 64429, Stride: 1},
- {Lo: 64830, Hi: 64831, Stride: 1},
- {Lo: 65072, Hi: 65101, Stride: 29},
- {Lo: 65102, Hi: 65103, Stride: 1},
- {Lo: 65112, Hi: 65128, Stride: 16},
- {Lo: 65165, Hi: 65166, Stride: 1},
- {Lo: 65257, Hi: 65260, Stride: 1},
- {Lo: 65282, Hi: 65284, Stride: 2},
- {Lo: 65285, Hi: 65287, Stride: 1},
- {Lo: 65290, Hi: 65291, Stride: 1},
- {Lo: 65293, Hi: 65305, Stride: 1},
- {Lo: 65308, Hi: 65310, Stride: 1},
- {Lo: 65312, Hi: 65373, Stride: 1},
- {Lo: 65512, Hi: 65512, Stride: 1},
+func newAmbiguousTableMap() map[string]*AmbiguousTable {
+ return map[string]*AmbiguousTable{
+ "_common": {
+ Confusable: []rune{184, 383, 388, 397, 422, 423, 439, 444, 445, 448, 451, 540, 546, 547, 577, 593, 609, 611, 617, 618, 623, 651, 655, 660, 697, 699, 700, 701, 702, 706, 707, 708, 710, 712, 714, 715, 720, 727, 731, 732, 756, 760, 884, 890, 894, 895, 900, 913, 914, 917, 918, 919, 922, 924, 925, 927, 929, 932, 933, 935, 945, 947, 953, 957, 959, 961, 963, 965, 978, 988, 1000, 1010, 1011, 1017, 1018, 1029, 1030, 1032, 1109, 1110, 1112, 1121, 1140, 1141, 1198, 1199, 1211, 1213, 1216, 1231, 1248, 1281, 1292, 1307, 1308, 1309, 1357, 1359, 1365, 1370, 1373, 1377, 1379, 1382, 1392, 1400, 1404, 1405, 1409, 1412, 1413, 1417, 1472, 1475, 1493, 1496, 1497, 1503, 1505, 1523, 1549, 1575, 1607, 1632, 1633, 1637, 1639, 1643, 1645, 1726, 1729, 1748, 1749, 1776, 1777, 1781, 1783, 1793, 1794, 1795, 1796, 1984, 1994, 2036, 2037, 2042, 2307, 2406, 2429, 2534, 2538, 2541, 2662, 2663, 2666, 2691, 2790, 2819, 2848, 2918, 2920, 3046, 3074, 3174, 3202, 3302, 3330, 3360, 3430, 3437, 3458, 3664, 3792, 4125, 4160, 4327, 4351, 4608, 4816, 5024, 5025, 5026, 5029, 5033, 5034, 5035, 5036, 5038, 5043, 5047, 5051, 5053, 5056, 5058, 5059, 5070, 5071, 5074, 5076, 5077, 5081, 5082, 5086, 5087, 5090, 5094, 5095, 5102, 5107, 5108, 5120, 5167, 5171, 5176, 5194, 5196, 5229, 5231, 5234, 5261, 5290, 5311, 5441, 5500, 5501, 5511, 5551, 5556, 5573, 5598, 5610, 5616, 5623, 5741, 5742, 5760, 5810, 5815, 5825, 5836, 5845, 5846, 5868, 5869, 5941, 6147, 6153, 7428, 7439, 7441, 7452, 7456, 7457, 7458, 7462, 7555, 7564, 7837, 7935, 8125, 8126, 8127, 8128, 8175, 8189, 8190, 8192, 8193, 8194, 8195, 8196, 8197, 8198, 8199, 8200, 8201, 8202, 8208, 8209, 8210, 8218, 8219, 8228, 8232, 8233, 8239, 8242, 8249, 8250, 8257, 8259, 8260, 8270, 8275, 8282, 8287, 8450, 8458, 8459, 8460, 8461, 8462, 8464, 8465, 8466, 8467, 8469, 8473, 8474, 8475, 8476, 8477, 8484, 8488, 8490, 8492, 8493, 8494, 8495, 8496, 8497, 8499, 8500, 8505, 8509, 8517, 8518, 8519, 8520, 8521, 8544, 8548, 8553, 8556, 8557, 8558, 8559, 8560, 8564, 8569, 8572, 8573, 8574, 8722, 8725, 8726, 8727, 8739, 8744, 8746, 8758, 8764, 8868, 8897, 8899, 8959, 9075, 9076, 9082, 9213, 9585, 9587, 10088, 10089, 10094, 10095, 10098, 10099, 10100, 10101, 10133, 10134, 10187, 10189, 10201, 10539, 10540, 10741, 10744, 10745, 10799, 11397, 11406, 11410, 11412, 11416, 11418, 11422, 11423, 11426, 11427, 11428, 11429, 11430, 11432, 11436, 11450, 11462, 11466, 11468, 11472, 11474, 11576, 11577, 11599, 11601, 11604, 11605, 11613, 11840, 12034, 12035, 12295, 12308, 12309, 12339, 12448, 12755, 12756, 20022, 20031, 42192, 42193, 42194, 42195, 42196, 42198, 42199, 42201, 42202, 42204, 42205, 42207, 42208, 42209, 42210, 42211, 42214, 42215, 42218, 42219, 42220, 42222, 42224, 42226, 42227, 42228, 42232, 42233, 42237, 42239, 42510, 42564, 42567, 42719, 42731, 42735, 42801, 42842, 42858, 42862, 42872, 42889, 42892, 42904, 42905, 42911, 42923, 42930, 42931, 42932, 43826, 43829, 43837, 43847, 43848, 43854, 43858, 43866, 43893, 43905, 43907, 43923, 43945, 43946, 43951, 64422, 64423, 64424, 64425, 64426, 64427, 64428, 64429, 64830, 64831, 65072, 65101, 65102, 65103, 65112, 65128, 65165, 65166, 65257, 65258, 65259, 65260, 65282, 65284, 65285, 65286, 65287, 65290, 65291, 65293, 65294, 65295, 65296, 65297, 65298, 65299, 65300, 65301, 65302, 65303, 65304, 65305, 65308, 65309, 65310, 65312, 65313, 65314, 65315, 65316, 65317, 65318, 65319, 65320, 65321, 65322, 65323, 65324, 65325, 65326, 65327, 65328, 65329, 65330, 65331, 65332, 65333, 65334, 65335, 65336, 65337, 65338, 65339, 65340, 65341, 65342, 65343, 65344, 65345, 65346, 65347, 65348, 65349, 65350, 65351, 65352, 65353, 65354, 65355, 65356, 65357, 65358, 65359, 65360, 65361, 65362, 65363, 65364, 65365, 65366, 65367, 65368, 65369, 65370, 65371, 65372, 65373, 65512, 66178, 66182, 66183, 66186, 66192, 66194, 66197, 66198, 66199, 66203, 66208, 66209, 66210, 66213, 66219, 66224, 66225, 66226, 66228, 66255, 66293, 66305, 66306, 66313, 66321, 66325, 66327, 66330, 66335, 66336, 66338, 66564, 66581, 66587, 66592, 66604, 66621, 66632, 66740, 66754, 66766, 66770, 66794, 66806, 66835, 66838, 66840, 66844, 66845, 66853, 66854, 66855, 68176, 70864, 71430, 71434, 71438, 71439, 71840, 71842, 71843, 71844, 71846, 71849, 71852, 71854, 71855, 71858, 71861, 71864, 71867, 71868, 71872, 71873, 71874, 71875, 71876, 71878, 71880, 71882, 71884, 71893, 71894, 71895, 71896, 71900, 71904, 71909, 71910, 71913, 71916, 71919, 71922, 93960, 93962, 93974, 93992, 94005, 94010, 94011, 94015, 94016, 94018, 94019, 94033, 94034, 119060, 119149, 119302, 119309, 119311, 119314, 119315, 119318, 119338, 119350, 119351, 119354, 119355, 119808, 119809, 119810, 119811, 119812, 119813, 119814, 119815, 119816, 119817, 119818, 119819, 119820, 119821, 119822, 119823, 119824, 119825, 119826, 119827, 119828, 119829, 119830, 119831, 119832, 119833, 119834, 119835, 119836, 119837, 119838, 119839, 119840, 119841, 119842, 119843, 119844, 119845, 119847, 119848, 119849, 119850, 119851, 119852, 119853, 119854, 119855, 119856, 119857, 119858, 119859, 119860, 119861, 119862, 119863, 119864, 119865, 119866, 119867, 119868, 119869, 119870, 119871, 119872, 119873, 119874, 119875, 119876, 119877, 119878, 119879, 119880, 119881, 119882, 119883, 119884, 119885, 119886, 119887, 119888, 119889, 119890, 119891, 119892, 119894, 119895, 119896, 119897, 119899, 119900, 119901, 119902, 119903, 119904, 119905, 119906, 119907, 119908, 119909, 119910, 119911, 119912, 119913, 119914, 119915, 119916, 119917, 119918, 119919, 119920, 119921, 119922, 119923, 119924, 119925, 119926, 119927, 119928, 119929, 119930, 119931, 119932, 119933, 119934, 119935, 119936, 119937, 119938, 119939, 119940, 119941, 119942, 119943, 119944, 119945, 119946, 119947, 119948, 119949, 119951, 119952, 119953, 119954, 119955, 119956, 119957, 119958, 119959, 119960, 119961, 119962, 119963, 119964, 119966, 119967, 119970, 119973, 119974, 119977, 119978, 119979, 119980, 119982, 119983, 119984, 119985, 119986, 119987, 119988, 119989, 119990, 119991, 119992, 119993, 119995, 119997, 119998, 119999, 120000, 120001, 120003, 120005, 120006, 120007, 120008, 120009, 120010, 120011, 120012, 120013, 120014, 120015, 120016, 120017, 120018, 120019, 120020, 120021, 120022, 120023, 120024, 120025, 120026, 120027, 120028, 120029, 120030, 120031, 120032, 120033, 120034, 120035, 120036, 120037, 120038, 120039, 120040, 120041, 120042, 120043, 120044, 120045, 120046, 120047, 120048, 120049, 120050, 120051, 120052, 120053, 120055, 120056, 120057, 120058, 120059, 120060, 120061, 120062, 120063, 120064, 120065, 120066, 120067, 120068, 120069, 120071, 120072, 120073, 120074, 120077, 120078, 120079, 120080, 120081, 120082, 120083, 120084, 120086, 120087, 120088, 120089, 120090, 120091, 120092, 120094, 120095, 120096, 120097, 120098, 120099, 120100, 120101, 120102, 120103, 120104, 120105, 120107, 120108, 120109, 120110, 120111, 120112, 120113, 120114, 120115, 120116, 120117, 120118, 120119, 120120, 120121, 120123, 120124, 120125, 120126, 120128, 120129, 120130, 120131, 120132, 120134, 120138, 120139, 120140, 120141, 120142, 120143, 120144, 120146, 120147, 120148, 120149, 120150, 120151, 120152, 120153, 120154, 120155, 120156, 120157, 120159, 120160, 120161, 120162, 120163, 120164, 120165, 120166, 120167, 120168, 120169, 120170, 120171, 120172, 120173, 120174, 120175, 120176, 120177, 120178, 120179, 120180, 120181, 120182, 120183, 120184, 120185, 120186, 120187, 120188, 120189, 120190, 120191, 120192, 120193, 120194, 120195, 120196, 120197, 120198, 120199, 120200, 120201, 120202, 120203, 120204, 120205, 120206, 120207, 120208, 120209, 120211, 120212, 120213, 120214, 120215, 120216, 120217, 120218, 120219, 120220, 120221, 120222, 120223, 120224, 120225, 120226, 120227, 120228, 120229, 120230, 120231, 120232, 120233, 120234, 120235, 120236, 120237, 120238, 120239, 120240, 120241, 120242, 120243, 120244, 120245, 120246, 120247, 120248, 120249, 120250, 120251, 120252, 120253, 120254, 120255, 120256, 120257, 120258, 120259, 120260, 120261, 120263, 120264, 120265, 120266, 120267, 120268, 120269, 120270, 120271, 120272, 120273, 120274, 120275, 120276, 120277, 120278, 120279, 120280, 120281, 120282, 120283, 120284, 120285, 120286, 120287, 120288, 120289, 120290, 120291, 120292, 120293, 120294, 120295, 120296, 120297, 120298, 120299, 120300, 120301, 120302, 120303, 120304, 120305, 120306, 120307, 120308, 120309, 120310, 120311, 120312, 120313, 120315, 120316, 120317, 120318, 120319, 120320, 120321, 120322, 120323, 120324, 120325, 120326, 120327, 120328, 120329, 120330, 120331, 120332, 120333, 120334, 120335, 120336, 120337, 120338, 120339, 120340, 120341, 120342, 120343, 120344, 120345, 120346, 120347, 120348, 120349, 120350, 120351, 120352, 120353, 120354, 120355, 120356, 120357, 120358, 120359, 120360, 120361, 120362, 120363, 120364, 120365, 120367, 120368, 120369, 120370, 120371, 120372, 120373, 120374, 120375, 120376, 120377, 120378, 120379, 120380, 120381, 120382, 120383, 120384, 120385, 120386, 120387, 120388, 120389, 120390, 120391, 120392, 120393, 120394, 120395, 120396, 120397, 120398, 120399, 120400, 120401, 120402, 120403, 120404, 120405, 120406, 120407, 120408, 120409, 120410, 120411, 120412, 120413, 120414, 120415, 120416, 120417, 120419, 120420, 120421, 120422, 120423, 120424, 120425, 120426, 120427, 120428, 120429, 120430, 120431, 120432, 120433, 120434, 120435, 120436, 120437, 120438, 120439, 120440, 120441, 120442, 120443, 120444, 120445, 120446, 120447, 120448, 120449, 120450, 120451, 120452, 120453, 120454, 120455, 120456, 120457, 120458, 120459, 120460, 120461, 120462, 120463, 120464, 120465, 120466, 120467, 120468, 120469, 120471, 120472, 120473, 120474, 120475, 120476, 120477, 120478, 120479, 120480, 120481, 120482, 120483, 120484, 120488, 120489, 120492, 120493, 120494, 120496, 120497, 120499, 120500, 120502, 120504, 120507, 120508, 120510, 120514, 120516, 120522, 120526, 120528, 120530, 120532, 120534, 120544, 120546, 120547, 120550, 120551, 120552, 120554, 120555, 120557, 120558, 120560, 120562, 120565, 120566, 120568, 120572, 120574, 120580, 120584, 120586, 120588, 120590, 120592, 120602, 120604, 120605, 120608, 120609, 120610, 120612, 120613, 120615, 120616, 120618, 120620, 120623, 120624, 120626, 120630, 120632, 120638, 120642, 120644, 120646, 120648, 120650, 120660, 120662, 120663, 120666, 120667, 120668, 120670, 120671, 120673, 120674, 120676, 120678, 120681, 120682, 120684, 120688, 120690, 120696, 120700, 120702, 120704, 120706, 120708, 120718, 120720, 120721, 120724, 120725, 120726, 120728, 120729, 120731, 120732, 120734, 120736, 120739, 120740, 120742, 120746, 120748, 120754, 120758, 120760, 120762, 120764, 120766, 120776, 120778, 120782, 120783, 120784, 120785, 120786, 120787, 120788, 120789, 120790, 120791, 120792, 120793, 120794, 120795, 120796, 120797, 120798, 120799, 120800, 120801, 120802, 120803, 120804, 120805, 120806, 120807, 120808, 120809, 120810, 120811, 120812, 120813, 120814, 120815, 120816, 120817, 120818, 120819, 120820, 120821, 120822, 120823, 120824, 120825, 120826, 120827, 120828, 120829, 120830, 120831, 125127, 125131, 126464, 126500, 126564, 126592, 126596, 128844, 128872, 130032, 130033, 130034, 130035, 130036, 130037, 130038, 130039, 130040, 130041},
+ With: []rune{44, 102, 98, 103, 82, 50, 51, 53, 115, 73, 33, 51, 56, 56, 63, 97, 103, 121, 105, 105, 119, 117, 121, 63, 96, 96, 96, 96, 96, 60, 62, 94, 94, 96, 96, 96, 58, 45, 105, 126, 96, 58, 96, 105, 59, 74, 96, 65, 66, 69, 90, 72, 75, 77, 78, 79, 80, 84, 89, 88, 97, 121, 105, 118, 111, 112, 111, 117, 89, 70, 50, 99, 106, 67, 77, 83, 73, 74, 115, 105, 106, 119, 86, 118, 89, 121, 104, 101, 73, 105, 51, 100, 71, 113, 87, 119, 85, 83, 79, 96, 96, 119, 113, 113, 104, 110, 110, 117, 103, 102, 111, 58, 108, 58, 108, 118, 96, 108, 111, 96, 44, 108, 111, 46, 108, 111, 86, 44, 42, 111, 111, 45, 111, 46, 73, 111, 86, 46, 46, 58, 58, 79, 108, 96, 96, 95, 58, 111, 63, 79, 56, 57, 111, 57, 56, 58, 111, 56, 79, 79, 57, 111, 111, 111, 111, 111, 111, 111, 111, 57, 111, 111, 111, 111, 111, 121, 111, 85, 79, 68, 82, 84, 105, 89, 65, 74, 69, 63, 87, 77, 72, 89, 71, 104, 90, 52, 98, 82, 87, 83, 86, 83, 76, 67, 80, 75, 100, 54, 71, 66, 61, 86, 62, 60, 96, 85, 80, 100, 98, 74, 76, 50, 120, 72, 120, 82, 98, 70, 65, 68, 68, 77, 66, 88, 120, 32, 60, 88, 73, 96, 75, 77, 58, 43, 47, 58, 58, 99, 111, 111, 117, 118, 119, 122, 114, 103, 121, 102, 121, 96, 105, 96, 126, 96, 96, 96, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 45, 45, 45, 44, 96, 46, 32, 32, 32, 96, 60, 62, 47, 45, 47, 42, 126, 58, 32, 67, 103, 72, 72, 72, 104, 73, 73, 76, 108, 78, 80, 81, 82, 82, 82, 90, 90, 75, 66, 67, 101, 101, 69, 70, 77, 111, 105, 121, 68, 100, 101, 105, 106, 73, 86, 88, 76, 67, 68, 77, 105, 118, 120, 73, 99, 100, 45, 47, 92, 42, 73, 118, 85, 58, 126, 84, 118, 85, 69, 105, 112, 97, 73, 47, 88, 40, 41, 60, 62, 40, 41, 123, 125, 43, 45, 47, 92, 84, 120, 120, 92, 47, 92, 120, 114, 72, 73, 75, 77, 78, 79, 111, 80, 112, 67, 99, 84, 89, 88, 45, 47, 57, 51, 76, 54, 86, 69, 73, 33, 79, 81, 88, 61, 92, 47, 79, 40, 41, 47, 61, 47, 92, 92, 47, 66, 80, 100, 68, 84, 71, 75, 74, 67, 90, 70, 77, 78, 76, 83, 82, 86, 72, 87, 88, 89, 65, 69, 73, 79, 85, 46, 44, 58, 61, 46, 50, 105, 86, 63, 50, 115, 50, 51, 57, 38, 58, 96, 70, 102, 117, 51, 74, 88, 66, 101, 102, 111, 114, 114, 117, 117, 121, 105, 114, 119, 122, 118, 115, 99, 111, 111, 111, 111, 111, 111, 111, 111, 40, 41, 58, 95, 95, 95, 45, 92, 108, 108, 111, 111, 111, 111, 34, 36, 37, 38, 96, 42, 43, 45, 46, 47, 48, 49, 50, 51, 52, 53, 54, 55, 56, 57, 60, 61, 62, 64, 65, 66, 67, 68, 69, 70, 71, 72, 73, 74, 75, 76, 77, 78, 79, 80, 81, 82, 83, 84, 85, 86, 87, 88, 89, 90, 91, 92, 93, 94, 95, 96, 97, 98, 99, 100, 101, 102, 103, 104, 105, 106, 107, 108, 109, 110, 111, 112, 113, 114, 115, 116, 117, 118, 119, 120, 121, 122, 123, 124, 125, 73, 66, 69, 70, 124, 88, 79, 80, 83, 84, 43, 65, 66, 67, 70, 79, 77, 84, 89, 88, 72, 90, 66, 67, 124, 77, 84, 88, 56, 42, 108, 88, 79, 67, 76, 83, 111, 99, 115, 82, 79, 85, 55, 111, 117, 78, 79, 75, 67, 86, 70, 76, 88, 46, 79, 118, 119, 119, 119, 86, 70, 76, 89, 69, 90, 57, 69, 52, 76, 79, 85, 53, 84, 118, 115, 70, 105, 122, 55, 111, 51, 57, 54, 57, 111, 117, 121, 79, 90, 87, 67, 88, 87, 67, 86, 84, 76, 73, 82, 83, 51, 62, 65, 85, 89, 96, 96, 123, 46, 51, 86, 92, 55, 70, 82, 76, 60, 62, 47, 92, 65, 66, 67, 68, 69, 70, 71, 72, 73, 74, 75, 76, 77, 78, 79, 80, 81, 82, 83, 84, 85, 86, 87, 88, 89, 90, 97, 98, 99, 100, 101, 102, 103, 104, 105, 106, 107, 108, 110, 111, 112, 113, 114, 115, 116, 117, 118, 119, 120, 121, 122, 65, 66, 67, 68, 69, 70, 71, 72, 73, 74, 75, 76, 77, 78, 79, 80, 81, 82, 83, 84, 85, 86, 87, 88, 89, 90, 97, 98, 99, 100, 101, 102, 103, 105, 106, 107, 108, 110, 111, 112, 113, 114, 115, 116, 117, 118, 119, 120, 121, 122, 65, 66, 67, 68, 69, 70, 71, 72, 73, 74, 75, 76, 77, 78, 79, 80, 81, 82, 83, 84, 85, 86, 87, 88, 89, 90, 97, 98, 99, 100, 101, 102, 103, 104, 105, 106, 107, 108, 110, 111, 112, 113, 114, 115, 116, 117, 118, 119, 120, 121, 122, 65, 67, 68, 71, 74, 75, 78, 79, 80, 81, 83, 84, 85, 86, 87, 88, 89, 90, 97, 98, 99, 100, 102, 104, 105, 106, 107, 108, 110, 112, 113, 114, 115, 116, 117, 118, 119, 120, 121, 122, 65, 66, 67, 68, 69, 70, 71, 72, 73, 74, 75, 76, 77, 78, 79, 80, 81, 82, 83, 84, 85, 86, 87, 88, 89, 90, 97, 98, 99, 100, 101, 102, 103, 104, 105, 106, 107, 108, 110, 111, 112, 113, 114, 115, 116, 117, 118, 119, 120, 121, 122, 65, 66, 68, 69, 70, 71, 74, 75, 76, 77, 78, 79, 80, 81, 83, 84, 85, 86, 87, 88, 89, 97, 98, 99, 100, 101, 102, 103, 104, 105, 106, 107, 73, 110, 111, 112, 113, 114, 115, 116, 117, 118, 119, 120, 121, 122, 65, 66, 68, 69, 70, 71, 73, 74, 75, 76, 77, 79, 83, 84, 85, 86, 87, 88, 89, 97, 98, 99, 100, 101, 102, 103, 104, 105, 106, 107, 73, 110, 111, 112, 113, 114, 115, 116, 117, 118, 119, 120, 121, 122, 65, 66, 67, 68, 69, 70, 71, 72, 73, 74, 75, 76, 77, 78, 79, 80, 81, 82, 83, 84, 85, 86, 87, 88, 89, 90, 97, 98, 99, 100, 101, 102, 103, 104, 105, 106, 107, 73, 110, 111, 112, 113, 114, 115, 116, 117, 118, 119, 120, 121, 122, 65, 66, 67, 68, 69, 70, 71, 72, 73, 74, 75, 76, 77, 78, 79, 80, 81, 82, 83, 84, 85, 86, 87, 88, 89, 90, 97, 98, 99, 100, 101, 102, 103, 104, 105, 106, 107, 73, 110, 111, 112, 113, 114, 115, 116, 117, 118, 119, 120, 121, 122, 65, 66, 67, 68, 69, 70, 71, 72, 73, 74, 75, 76, 77, 78, 79, 80, 81, 82, 83, 84, 85, 86, 87, 88, 89, 90, 97, 98, 99, 100, 101, 102, 103, 104, 105, 106, 107, 73, 110, 111, 112, 113, 114, 115, 116, 117, 118, 119, 120, 121, 122, 65, 66, 67, 68, 69, 70, 71, 72, 73, 74, 75, 76, 77, 78, 79, 80, 81, 82, 83, 84, 85, 86, 87, 88, 89, 90, 97, 98, 99, 100, 101, 102, 103, 104, 105, 106, 107, 73, 110, 111, 112, 113, 114, 115, 116, 117, 118, 119, 120, 121, 122, 65, 66, 67, 68, 69, 70, 71, 72, 73, 74, 75, 76, 77, 78, 79, 80, 81, 82, 83, 84, 85, 86, 87, 88, 89, 90, 97, 98, 99, 100, 101, 102, 103, 104, 105, 106, 107, 73, 110, 111, 112, 113, 114, 115, 116, 117, 118, 119, 120, 121, 122, 65, 66, 67, 68, 69, 70, 71, 72, 73, 74, 75, 76, 77, 78, 79, 80, 81, 82, 83, 84, 85, 86, 87, 88, 89, 90, 97, 98, 99, 100, 101, 102, 103, 104, 105, 106, 107, 73, 110, 111, 112, 113, 114, 115, 116, 117, 118, 119, 120, 121, 122, 105, 65, 66, 69, 90, 72, 73, 75, 77, 78, 79, 80, 84, 89, 88, 97, 121, 105, 118, 111, 112, 111, 117, 112, 65, 66, 69, 90, 72, 73, 75, 77, 78, 79, 80, 84, 89, 88, 97, 121, 105, 118, 111, 112, 111, 117, 112, 65, 66, 69, 90, 72, 73, 75, 77, 78, 79, 80, 84, 89, 88, 97, 121, 105, 118, 111, 112, 111, 117, 112, 65, 66, 69, 90, 72, 73, 75, 77, 78, 79, 80, 84, 89, 88, 97, 121, 105, 118, 111, 112, 111, 117, 112, 65, 66, 69, 90, 72, 73, 75, 77, 78, 79, 80, 84, 89, 88, 97, 121, 105, 118, 111, 112, 111, 117, 112, 70, 79, 73, 50, 51, 52, 53, 54, 55, 56, 57, 79, 73, 50, 51, 52, 53, 54, 55, 56, 57, 79, 73, 50, 51, 52, 53, 54, 55, 56, 57, 79, 73, 50, 51, 52, 53, 54, 55, 56, 57, 79, 73, 50, 51, 52, 53, 54, 55, 56, 57, 108, 56, 108, 111, 111, 108, 111, 67, 84, 79, 73, 50, 51, 52, 53, 54, 55, 56, 57},
+ Locale: "_common",
+ RangeTable: &unicode.RangeTable{
+ R16: []unicode.Range16{
+ {Lo: 184, Hi: 383, Stride: 199},
+ {Lo: 388, Hi: 397, Stride: 9},
+ {Lo: 422, Hi: 423, Stride: 1},
+ {Lo: 439, Hi: 444, Stride: 5},
+ {Lo: 445, Hi: 451, Stride: 3},
+ {Lo: 540, Hi: 546, Stride: 6},
+ {Lo: 547, Hi: 577, Stride: 30},
+ {Lo: 593, Hi: 609, Stride: 16},
+ {Lo: 611, Hi: 617, Stride: 6},
+ {Lo: 618, Hi: 623, Stride: 5},
+ {Lo: 651, Hi: 655, Stride: 4},
+ {Lo: 660, Hi: 697, Stride: 37},
+ {Lo: 699, Hi: 702, Stride: 1},
+ {Lo: 706, Hi: 708, Stride: 1},
+ {Lo: 710, Hi: 714, Stride: 2},
+ {Lo: 715, Hi: 720, Stride: 5},
+ {Lo: 727, Hi: 731, Stride: 4},
+ {Lo: 732, Hi: 756, Stride: 24},
+ {Lo: 760, Hi: 884, Stride: 124},
+ {Lo: 890, Hi: 894, Stride: 4},
+ {Lo: 895, Hi: 900, Stride: 5},
+ {Lo: 913, Hi: 914, Stride: 1},
+ {Lo: 917, Hi: 919, Stride: 1},
+ {Lo: 922, Hi: 924, Stride: 2},
+ {Lo: 925, Hi: 929, Stride: 2},
+ {Lo: 932, Hi: 933, Stride: 1},
+ {Lo: 935, Hi: 945, Stride: 10},
+ {Lo: 947, Hi: 953, Stride: 6},
+ {Lo: 957, Hi: 965, Stride: 2},
+ {Lo: 978, Hi: 988, Stride: 10},
+ {Lo: 1000, Hi: 1010, Stride: 10},
+ {Lo: 1011, Hi: 1017, Stride: 6},
+ {Lo: 1018, Hi: 1029, Stride: 11},
+ {Lo: 1030, Hi: 1032, Stride: 2},
+ {Lo: 1109, Hi: 1110, Stride: 1},
+ {Lo: 1112, Hi: 1121, Stride: 9},
+ {Lo: 1140, Hi: 1141, Stride: 1},
+ {Lo: 1198, Hi: 1199, Stride: 1},
+ {Lo: 1211, Hi: 1213, Stride: 2},
+ {Lo: 1216, Hi: 1231, Stride: 15},
+ {Lo: 1248, Hi: 1281, Stride: 33},
+ {Lo: 1292, Hi: 1307, Stride: 15},
+ {Lo: 1308, Hi: 1309, Stride: 1},
+ {Lo: 1357, Hi: 1359, Stride: 2},
+ {Lo: 1365, Hi: 1370, Stride: 5},
+ {Lo: 1373, Hi: 1377, Stride: 4},
+ {Lo: 1379, Hi: 1382, Stride: 3},
+ {Lo: 1392, Hi: 1400, Stride: 8},
+ {Lo: 1404, Hi: 1405, Stride: 1},
+ {Lo: 1409, Hi: 1412, Stride: 3},
+ {Lo: 1413, Hi: 1417, Stride: 4},
+ {Lo: 1472, Hi: 1475, Stride: 3},
+ {Lo: 1493, Hi: 1496, Stride: 3},
+ {Lo: 1497, Hi: 1503, Stride: 6},
+ {Lo: 1505, Hi: 1523, Stride: 18},
+ {Lo: 1549, Hi: 1575, Stride: 26},
+ {Lo: 1607, Hi: 1632, Stride: 25},
+ {Lo: 1633, Hi: 1637, Stride: 4},
+ {Lo: 1639, Hi: 1643, Stride: 4},
+ {Lo: 1645, Hi: 1726, Stride: 81},
+ {Lo: 1729, Hi: 1748, Stride: 19},
+ {Lo: 1749, Hi: 1776, Stride: 27},
+ {Lo: 1777, Hi: 1781, Stride: 4},
+ {Lo: 1783, Hi: 1793, Stride: 10},
+ {Lo: 1794, Hi: 1796, Stride: 1},
+ {Lo: 1984, Hi: 1994, Stride: 10},
+ {Lo: 2036, Hi: 2037, Stride: 1},
+ {Lo: 2042, Hi: 2307, Stride: 265},
+ {Lo: 2406, Hi: 2429, Stride: 23},
+ {Lo: 2534, Hi: 2538, Stride: 4},
+ {Lo: 2541, Hi: 2662, Stride: 121},
+ {Lo: 2663, Hi: 2666, Stride: 3},
+ {Lo: 2691, Hi: 2790, Stride: 99},
+ {Lo: 2819, Hi: 2848, Stride: 29},
+ {Lo: 2918, Hi: 2920, Stride: 2},
+ {Lo: 3046, Hi: 3074, Stride: 28},
+ {Lo: 3174, Hi: 3202, Stride: 28},
+ {Lo: 3302, Hi: 3330, Stride: 28},
+ {Lo: 3360, Hi: 3430, Stride: 70},
+ {Lo: 3437, Hi: 3458, Stride: 21},
+ {Lo: 3664, Hi: 3792, Stride: 128},
+ {Lo: 4125, Hi: 4160, Stride: 35},
+ {Lo: 4327, Hi: 4351, Stride: 24},
+ {Lo: 4608, Hi: 5024, Stride: 208},
+ {Lo: 5025, Hi: 5026, Stride: 1},
+ {Lo: 5029, Hi: 5033, Stride: 4},
+ {Lo: 5034, Hi: 5036, Stride: 1},
+ {Lo: 5038, Hi: 5043, Stride: 5},
+ {Lo: 5047, Hi: 5051, Stride: 4},
+ {Lo: 5053, Hi: 5056, Stride: 3},
+ {Lo: 5058, Hi: 5059, Stride: 1},
+ {Lo: 5070, Hi: 5071, Stride: 1},
+ {Lo: 5074, Hi: 5076, Stride: 2},
+ {Lo: 5077, Hi: 5081, Stride: 4},
+ {Lo: 5082, Hi: 5086, Stride: 4},
+ {Lo: 5087, Hi: 5090, Stride: 3},
+ {Lo: 5094, Hi: 5095, Stride: 1},
+ {Lo: 5102, Hi: 5107, Stride: 5},
+ {Lo: 5108, Hi: 5120, Stride: 12},
+ {Lo: 5167, Hi: 5171, Stride: 4},
+ {Lo: 5176, Hi: 5194, Stride: 18},
+ {Lo: 5196, Hi: 5229, Stride: 33},
+ {Lo: 5231, Hi: 5234, Stride: 3},
+ {Lo: 5261, Hi: 5290, Stride: 29},
+ {Lo: 5311, Hi: 5441, Stride: 130},
+ {Lo: 5500, Hi: 5501, Stride: 1},
+ {Lo: 5511, Hi: 5551, Stride: 40},
+ {Lo: 5556, Hi: 5573, Stride: 17},
+ {Lo: 5598, Hi: 5610, Stride: 12},
+ {Lo: 5616, Hi: 5623, Stride: 7},
+ {Lo: 5741, Hi: 5742, Stride: 1},
+ {Lo: 5760, Hi: 5810, Stride: 50},
+ {Lo: 5815, Hi: 5825, Stride: 10},
+ {Lo: 5836, Hi: 5845, Stride: 9},
+ {Lo: 5846, Hi: 5868, Stride: 22},
+ {Lo: 5869, Hi: 5941, Stride: 72},
+ {Lo: 6147, Hi: 6153, Stride: 6},
+ {Lo: 7428, Hi: 7439, Stride: 11},
+ {Lo: 7441, Hi: 7452, Stride: 11},
+ {Lo: 7456, Hi: 7458, Stride: 1},
+ {Lo: 7462, Hi: 7555, Stride: 93},
+ {Lo: 7564, Hi: 7837, Stride: 273},
+ {Lo: 7935, Hi: 8125, Stride: 190},
+ {Lo: 8126, Hi: 8128, Stride: 1},
+ {Lo: 8175, Hi: 8189, Stride: 14},
+ {Lo: 8190, Hi: 8192, Stride: 2},
+ {Lo: 8193, Hi: 8202, Stride: 1},
+ {Lo: 8208, Hi: 8210, Stride: 1},
+ {Lo: 8218, Hi: 8219, Stride: 1},
+ {Lo: 8228, Hi: 8232, Stride: 4},
+ {Lo: 8233, Hi: 8239, Stride: 6},
+ {Lo: 8242, Hi: 8249, Stride: 7},
+ {Lo: 8250, Hi: 8257, Stride: 7},
+ {Lo: 8259, Hi: 8260, Stride: 1},
+ {Lo: 8270, Hi: 8275, Stride: 5},
+ {Lo: 8282, Hi: 8287, Stride: 5},
+ {Lo: 8450, Hi: 8458, Stride: 8},
+ {Lo: 8459, Hi: 8462, Stride: 1},
+ {Lo: 8464, Hi: 8467, Stride: 1},
+ {Lo: 8469, Hi: 8473, Stride: 4},
+ {Lo: 8474, Hi: 8477, Stride: 1},
+ {Lo: 8484, Hi: 8488, Stride: 4},
+ {Lo: 8490, Hi: 8492, Stride: 2},
+ {Lo: 8493, Hi: 8497, Stride: 1},
+ {Lo: 8499, Hi: 8500, Stride: 1},
+ {Lo: 8505, Hi: 8509, Stride: 4},
+ {Lo: 8517, Hi: 8521, Stride: 1},
+ {Lo: 8544, Hi: 8548, Stride: 4},
+ {Lo: 8553, Hi: 8556, Stride: 3},
+ {Lo: 8557, Hi: 8560, Stride: 1},
+ {Lo: 8564, Hi: 8569, Stride: 5},
+ {Lo: 8572, Hi: 8574, Stride: 1},
+ {Lo: 8722, Hi: 8725, Stride: 3},
+ {Lo: 8726, Hi: 8727, Stride: 1},
+ {Lo: 8739, Hi: 8744, Stride: 5},
+ {Lo: 8746, Hi: 8758, Stride: 12},
+ {Lo: 8764, Hi: 8868, Stride: 104},
+ {Lo: 8897, Hi: 8899, Stride: 2},
+ {Lo: 8959, Hi: 9075, Stride: 116},
+ {Lo: 9076, Hi: 9082, Stride: 6},
+ {Lo: 9213, Hi: 9585, Stride: 372},
+ {Lo: 9587, Hi: 10088, Stride: 501},
+ {Lo: 10089, Hi: 10094, Stride: 5},
+ {Lo: 10095, Hi: 10098, Stride: 3},
+ {Lo: 10099, Hi: 10101, Stride: 1},
+ {Lo: 10133, Hi: 10134, Stride: 1},
+ {Lo: 10187, Hi: 10189, Stride: 2},
+ {Lo: 10201, Hi: 10539, Stride: 338},
+ {Lo: 10540, Hi: 10741, Stride: 201},
+ {Lo: 10744, Hi: 10745, Stride: 1},
+ {Lo: 10799, Hi: 11397, Stride: 598},
+ {Lo: 11406, Hi: 11410, Stride: 4},
+ {Lo: 11412, Hi: 11416, Stride: 4},
+ {Lo: 11418, Hi: 11422, Stride: 4},
+ {Lo: 11423, Hi: 11426, Stride: 3},
+ {Lo: 11427, Hi: 11430, Stride: 1},
+ {Lo: 11432, Hi: 11436, Stride: 4},
+ {Lo: 11450, Hi: 11462, Stride: 12},
+ {Lo: 11466, Hi: 11468, Stride: 2},
+ {Lo: 11472, Hi: 11474, Stride: 2},
+ {Lo: 11576, Hi: 11577, Stride: 1},
+ {Lo: 11599, Hi: 11601, Stride: 2},
+ {Lo: 11604, Hi: 11605, Stride: 1},
+ {Lo: 11613, Hi: 11840, Stride: 227},
+ {Lo: 12034, Hi: 12035, Stride: 1},
+ {Lo: 12295, Hi: 12308, Stride: 13},
+ {Lo: 12309, Hi: 12339, Stride: 30},
+ {Lo: 12448, Hi: 12755, Stride: 307},
+ {Lo: 12756, Hi: 20022, Stride: 7266},
+ {Lo: 20031, Hi: 42192, Stride: 22161},
+ {Lo: 42193, Hi: 42196, Stride: 1},
+ {Lo: 42198, Hi: 42199, Stride: 1},
+ {Lo: 42201, Hi: 42202, Stride: 1},
+ {Lo: 42204, Hi: 42205, Stride: 1},
+ {Lo: 42207, Hi: 42211, Stride: 1},
+ {Lo: 42214, Hi: 42215, Stride: 1},
+ {Lo: 42218, Hi: 42220, Stride: 1},
+ {Lo: 42222, Hi: 42226, Stride: 2},
+ {Lo: 42227, Hi: 42228, Stride: 1},
+ {Lo: 42232, Hi: 42233, Stride: 1},
+ {Lo: 42237, Hi: 42239, Stride: 2},
+ {Lo: 42510, Hi: 42564, Stride: 54},
+ {Lo: 42567, Hi: 42719, Stride: 152},
+ {Lo: 42731, Hi: 42735, Stride: 4},
+ {Lo: 42801, Hi: 42842, Stride: 41},
+ {Lo: 42858, Hi: 42862, Stride: 4},
+ {Lo: 42872, Hi: 42889, Stride: 17},
+ {Lo: 42892, Hi: 42904, Stride: 12},
+ {Lo: 42905, Hi: 42911, Stride: 6},
+ {Lo: 42923, Hi: 42930, Stride: 7},
+ {Lo: 42931, Hi: 42932, Stride: 1},
+ {Lo: 43826, Hi: 43829, Stride: 3},
+ {Lo: 43837, Hi: 43847, Stride: 10},
+ {Lo: 43848, Hi: 43854, Stride: 6},
+ {Lo: 43858, Hi: 43866, Stride: 8},
+ {Lo: 43893, Hi: 43905, Stride: 12},
+ {Lo: 43907, Hi: 43923, Stride: 16},
+ {Lo: 43945, Hi: 43946, Stride: 1},
+ {Lo: 43951, Hi: 64422, Stride: 20471},
+ {Lo: 64423, Hi: 64429, Stride: 1},
+ {Lo: 64830, Hi: 64831, Stride: 1},
+ {Lo: 65072, Hi: 65101, Stride: 29},
+ {Lo: 65102, Hi: 65103, Stride: 1},
+ {Lo: 65112, Hi: 65128, Stride: 16},
+ {Lo: 65165, Hi: 65166, Stride: 1},
+ {Lo: 65257, Hi: 65260, Stride: 1},
+ {Lo: 65282, Hi: 65284, Stride: 2},
+ {Lo: 65285, Hi: 65287, Stride: 1},
+ {Lo: 65290, Hi: 65291, Stride: 1},
+ {Lo: 65293, Hi: 65305, Stride: 1},
+ {Lo: 65308, Hi: 65310, Stride: 1},
+ {Lo: 65312, Hi: 65373, Stride: 1},
+ {Lo: 65512, Hi: 65512, Stride: 1},
+ },
+ R32: []unicode.Range32{
+ {Lo: 66178, Hi: 66182, Stride: 4},
+ {Lo: 66183, Hi: 66186, Stride: 3},
+ {Lo: 66192, Hi: 66194, Stride: 2},
+ {Lo: 66197, Hi: 66199, Stride: 1},
+ {Lo: 66203, Hi: 66208, Stride: 5},
+ {Lo: 66209, Hi: 66210, Stride: 1},
+ {Lo: 66213, Hi: 66219, Stride: 6},
+ {Lo: 66224, Hi: 66226, Stride: 1},
+ {Lo: 66228, Hi: 66255, Stride: 27},
+ {Lo: 66293, Hi: 66305, Stride: 12},
+ {Lo: 66306, Hi: 66313, Stride: 7},
+ {Lo: 66321, Hi: 66325, Stride: 4},
+ {Lo: 66327, Hi: 66330, Stride: 3},
+ {Lo: 66335, Hi: 66336, Stride: 1},
+ {Lo: 66338, Hi: 66564, Stride: 226},
+ {Lo: 66581, Hi: 66587, Stride: 6},
+ {Lo: 66592, Hi: 66604, Stride: 12},
+ {Lo: 66621, Hi: 66632, Stride: 11},
+ {Lo: 66740, Hi: 66754, Stride: 14},
+ {Lo: 66766, Hi: 66770, Stride: 4},
+ {Lo: 66794, Hi: 66806, Stride: 12},
+ {Lo: 66835, Hi: 66838, Stride: 3},
+ {Lo: 66840, Hi: 66844, Stride: 4},
+ {Lo: 66845, Hi: 66853, Stride: 8},
+ {Lo: 66854, Hi: 66855, Stride: 1},
+ {Lo: 68176, Hi: 70864, Stride: 2688},
+ {Lo: 71430, Hi: 71438, Stride: 4},
+ {Lo: 71439, Hi: 71840, Stride: 401},
+ {Lo: 71842, Hi: 71844, Stride: 1},
+ {Lo: 71846, Hi: 71852, Stride: 3},
+ {Lo: 71854, Hi: 71855, Stride: 1},
+ {Lo: 71858, Hi: 71867, Stride: 3},
+ {Lo: 71868, Hi: 71872, Stride: 4},
+ {Lo: 71873, Hi: 71876, Stride: 1},
+ {Lo: 71878, Hi: 71884, Stride: 2},
+ {Lo: 71893, Hi: 71896, Stride: 1},
+ {Lo: 71900, Hi: 71904, Stride: 4},
+ {Lo: 71909, Hi: 71910, Stride: 1},
+ {Lo: 71913, Hi: 71922, Stride: 3},
+ {Lo: 93960, Hi: 93962, Stride: 2},
+ {Lo: 93974, Hi: 93992, Stride: 18},
+ {Lo: 94005, Hi: 94010, Stride: 5},
+ {Lo: 94011, Hi: 94015, Stride: 4},
+ {Lo: 94016, Hi: 94018, Stride: 2},
+ {Lo: 94019, Hi: 94033, Stride: 14},
+ {Lo: 94034, Hi: 119060, Stride: 25026},
+ {Lo: 119149, Hi: 119302, Stride: 153},
+ {Lo: 119309, Hi: 119311, Stride: 2},
+ {Lo: 119314, Hi: 119315, Stride: 1},
+ {Lo: 119318, Hi: 119338, Stride: 20},
+ {Lo: 119350, Hi: 119351, Stride: 1},
+ {Lo: 119354, Hi: 119355, Stride: 1},
+ {Lo: 119808, Hi: 119845, Stride: 1},
+ {Lo: 119847, Hi: 119892, Stride: 1},
+ {Lo: 119894, Hi: 119897, Stride: 1},
+ {Lo: 119899, Hi: 119949, Stride: 1},
+ {Lo: 119951, Hi: 119964, Stride: 1},
+ {Lo: 119966, Hi: 119967, Stride: 1},
+ {Lo: 119970, Hi: 119973, Stride: 3},
+ {Lo: 119974, Hi: 119977, Stride: 3},
+ {Lo: 119978, Hi: 119980, Stride: 1},
+ {Lo: 119982, Hi: 119993, Stride: 1},
+ {Lo: 119995, Hi: 119997, Stride: 2},
+ {Lo: 119998, Hi: 120001, Stride: 1},
+ {Lo: 120003, Hi: 120005, Stride: 2},
+ {Lo: 120006, Hi: 120053, Stride: 1},
+ {Lo: 120055, Hi: 120069, Stride: 1},
+ {Lo: 120071, Hi: 120074, Stride: 1},
+ {Lo: 120077, Hi: 120084, Stride: 1},
+ {Lo: 120086, Hi: 120092, Stride: 1},
+ {Lo: 120094, Hi: 120105, Stride: 1},
+ {Lo: 120107, Hi: 120121, Stride: 1},
+ {Lo: 120123, Hi: 120126, Stride: 1},
+ {Lo: 120128, Hi: 120132, Stride: 1},
+ {Lo: 120134, Hi: 120138, Stride: 4},
+ {Lo: 120139, Hi: 120144, Stride: 1},
+ {Lo: 120146, Hi: 120157, Stride: 1},
+ {Lo: 120159, Hi: 120209, Stride: 1},
+ {Lo: 120211, Hi: 120261, Stride: 1},
+ {Lo: 120263, Hi: 120313, Stride: 1},
+ {Lo: 120315, Hi: 120365, Stride: 1},
+ {Lo: 120367, Hi: 120417, Stride: 1},
+ {Lo: 120419, Hi: 120469, Stride: 1},
+ {Lo: 120471, Hi: 120484, Stride: 1},
+ {Lo: 120488, Hi: 120489, Stride: 1},
+ {Lo: 120492, Hi: 120494, Stride: 1},
+ {Lo: 120496, Hi: 120497, Stride: 1},
+ {Lo: 120499, Hi: 120500, Stride: 1},
+ {Lo: 120502, Hi: 120504, Stride: 2},
+ {Lo: 120507, Hi: 120508, Stride: 1},
+ {Lo: 120510, Hi: 120514, Stride: 4},
+ {Lo: 120516, Hi: 120522, Stride: 6},
+ {Lo: 120526, Hi: 120534, Stride: 2},
+ {Lo: 120544, Hi: 120546, Stride: 2},
+ {Lo: 120547, Hi: 120550, Stride: 3},
+ {Lo: 120551, Hi: 120552, Stride: 1},
+ {Lo: 120554, Hi: 120555, Stride: 1},
+ {Lo: 120557, Hi: 120558, Stride: 1},
+ {Lo: 120560, Hi: 120562, Stride: 2},
+ {Lo: 120565, Hi: 120566, Stride: 1},
+ {Lo: 120568, Hi: 120572, Stride: 4},
+ {Lo: 120574, Hi: 120580, Stride: 6},
+ {Lo: 120584, Hi: 120592, Stride: 2},
+ {Lo: 120602, Hi: 120604, Stride: 2},
+ {Lo: 120605, Hi: 120608, Stride: 3},
+ {Lo: 120609, Hi: 120610, Stride: 1},
+ {Lo: 120612, Hi: 120613, Stride: 1},
+ {Lo: 120615, Hi: 120616, Stride: 1},
+ {Lo: 120618, Hi: 120620, Stride: 2},
+ {Lo: 120623, Hi: 120624, Stride: 1},
+ {Lo: 120626, Hi: 120630, Stride: 4},
+ {Lo: 120632, Hi: 120638, Stride: 6},
+ {Lo: 120642, Hi: 120650, Stride: 2},
+ {Lo: 120660, Hi: 120662, Stride: 2},
+ {Lo: 120663, Hi: 120666, Stride: 3},
+ {Lo: 120667, Hi: 120668, Stride: 1},
+ {Lo: 120670, Hi: 120671, Stride: 1},
+ {Lo: 120673, Hi: 120674, Stride: 1},
+ {Lo: 120676, Hi: 120678, Stride: 2},
+ {Lo: 120681, Hi: 120682, Stride: 1},
+ {Lo: 120684, Hi: 120688, Stride: 4},
+ {Lo: 120690, Hi: 120696, Stride: 6},
+ {Lo: 120700, Hi: 120708, Stride: 2},
+ {Lo: 120718, Hi: 120720, Stride: 2},
+ {Lo: 120721, Hi: 120724, Stride: 3},
+ {Lo: 120725, Hi: 120726, Stride: 1},
+ {Lo: 120728, Hi: 120729, Stride: 1},
+ {Lo: 120731, Hi: 120732, Stride: 1},
+ {Lo: 120734, Hi: 120736, Stride: 2},
+ {Lo: 120739, Hi: 120740, Stride: 1},
+ {Lo: 120742, Hi: 120746, Stride: 4},
+ {Lo: 120748, Hi: 120754, Stride: 6},
+ {Lo: 120758, Hi: 120766, Stride: 2},
+ {Lo: 120776, Hi: 120778, Stride: 2},
+ {Lo: 120782, Hi: 120831, Stride: 1},
+ {Lo: 125127, Hi: 125131, Stride: 4},
+ {Lo: 126464, Hi: 126500, Stride: 36},
+ {Lo: 126564, Hi: 126592, Stride: 28},
+ {Lo: 126596, Hi: 128844, Stride: 2248},
+ {Lo: 128872, Hi: 130032, Stride: 1160},
+ {Lo: 130033, Hi: 130041, Stride: 1},
+ },
+ LatinOffset: 0,
},
- R32: []unicode.Range32{
- {Lo: 66178, Hi: 66182, Stride: 4},
- {Lo: 66183, Hi: 66186, Stride: 3},
- {Lo: 66192, Hi: 66194, Stride: 2},
- {Lo: 66197, Hi: 66199, Stride: 1},
- {Lo: 66203, Hi: 66208, Stride: 5},
- {Lo: 66209, Hi: 66210, Stride: 1},
- {Lo: 66213, Hi: 66219, Stride: 6},
- {Lo: 66224, Hi: 66226, Stride: 1},
- {Lo: 66228, Hi: 66255, Stride: 27},
- {Lo: 66293, Hi: 66305, Stride: 12},
- {Lo: 66306, Hi: 66313, Stride: 7},
- {Lo: 66321, Hi: 66325, Stride: 4},
- {Lo: 66327, Hi: 66330, Stride: 3},
- {Lo: 66335, Hi: 66336, Stride: 1},
- {Lo: 66338, Hi: 66564, Stride: 226},
- {Lo: 66581, Hi: 66587, Stride: 6},
- {Lo: 66592, Hi: 66604, Stride: 12},
- {Lo: 66621, Hi: 66632, Stride: 11},
- {Lo: 66740, Hi: 66754, Stride: 14},
- {Lo: 66766, Hi: 66770, Stride: 4},
- {Lo: 66794, Hi: 66806, Stride: 12},
- {Lo: 66835, Hi: 66838, Stride: 3},
- {Lo: 66840, Hi: 66844, Stride: 4},
- {Lo: 66845, Hi: 66853, Stride: 8},
- {Lo: 66854, Hi: 66855, Stride: 1},
- {Lo: 68176, Hi: 70864, Stride: 2688},
- {Lo: 71430, Hi: 71438, Stride: 4},
- {Lo: 71439, Hi: 71840, Stride: 401},
- {Lo: 71842, Hi: 71844, Stride: 1},
- {Lo: 71846, Hi: 71852, Stride: 3},
- {Lo: 71854, Hi: 71855, Stride: 1},
- {Lo: 71858, Hi: 71867, Stride: 3},
- {Lo: 71868, Hi: 71872, Stride: 4},
- {Lo: 71873, Hi: 71876, Stride: 1},
- {Lo: 71878, Hi: 71884, Stride: 2},
- {Lo: 71893, Hi: 71896, Stride: 1},
- {Lo: 71900, Hi: 71904, Stride: 4},
- {Lo: 71909, Hi: 71910, Stride: 1},
- {Lo: 71913, Hi: 71922, Stride: 3},
- {Lo: 93960, Hi: 93962, Stride: 2},
- {Lo: 93974, Hi: 93992, Stride: 18},
- {Lo: 94005, Hi: 94010, Stride: 5},
- {Lo: 94011, Hi: 94015, Stride: 4},
- {Lo: 94016, Hi: 94018, Stride: 2},
- {Lo: 94019, Hi: 94033, Stride: 14},
- {Lo: 94034, Hi: 119060, Stride: 25026},
- {Lo: 119149, Hi: 119302, Stride: 153},
- {Lo: 119309, Hi: 119311, Stride: 2},
- {Lo: 119314, Hi: 119315, Stride: 1},
- {Lo: 119318, Hi: 119338, Stride: 20},
- {Lo: 119350, Hi: 119351, Stride: 1},
- {Lo: 119354, Hi: 119355, Stride: 1},
- {Lo: 119808, Hi: 119845, Stride: 1},
- {Lo: 119847, Hi: 119892, Stride: 1},
- {Lo: 119894, Hi: 119897, Stride: 1},
- {Lo: 119899, Hi: 119949, Stride: 1},
- {Lo: 119951, Hi: 119964, Stride: 1},
- {Lo: 119966, Hi: 119967, Stride: 1},
- {Lo: 119970, Hi: 119973, Stride: 3},
- {Lo: 119974, Hi: 119977, Stride: 3},
- {Lo: 119978, Hi: 119980, Stride: 1},
- {Lo: 119982, Hi: 119993, Stride: 1},
- {Lo: 119995, Hi: 119997, Stride: 2},
- {Lo: 119998, Hi: 120001, Stride: 1},
- {Lo: 120003, Hi: 120005, Stride: 2},
- {Lo: 120006, Hi: 120053, Stride: 1},
- {Lo: 120055, Hi: 120069, Stride: 1},
- {Lo: 120071, Hi: 120074, Stride: 1},
- {Lo: 120077, Hi: 120084, Stride: 1},
- {Lo: 120086, Hi: 120092, Stride: 1},
- {Lo: 120094, Hi: 120105, Stride: 1},
- {Lo: 120107, Hi: 120121, Stride: 1},
- {Lo: 120123, Hi: 120126, Stride: 1},
- {Lo: 120128, Hi: 120132, Stride: 1},
- {Lo: 120134, Hi: 120138, Stride: 4},
- {Lo: 120139, Hi: 120144, Stride: 1},
- {Lo: 120146, Hi: 120157, Stride: 1},
- {Lo: 120159, Hi: 120209, Stride: 1},
- {Lo: 120211, Hi: 120261, Stride: 1},
- {Lo: 120263, Hi: 120313, Stride: 1},
- {Lo: 120315, Hi: 120365, Stride: 1},
- {Lo: 120367, Hi: 120417, Stride: 1},
- {Lo: 120419, Hi: 120469, Stride: 1},
- {Lo: 120471, Hi: 120484, Stride: 1},
- {Lo: 120488, Hi: 120489, Stride: 1},
- {Lo: 120492, Hi: 120494, Stride: 1},
- {Lo: 120496, Hi: 120497, Stride: 1},
- {Lo: 120499, Hi: 120500, Stride: 1},
- {Lo: 120502, Hi: 120504, Stride: 2},
- {Lo: 120507, Hi: 120508, Stride: 1},
- {Lo: 120510, Hi: 120514, Stride: 4},
- {Lo: 120516, Hi: 120522, Stride: 6},
- {Lo: 120526, Hi: 120534, Stride: 2},
- {Lo: 120544, Hi: 120546, Stride: 2},
- {Lo: 120547, Hi: 120550, Stride: 3},
- {Lo: 120551, Hi: 120552, Stride: 1},
- {Lo: 120554, Hi: 120555, Stride: 1},
- {Lo: 120557, Hi: 120558, Stride: 1},
- {Lo: 120560, Hi: 120562, Stride: 2},
- {Lo: 120565, Hi: 120566, Stride: 1},
- {Lo: 120568, Hi: 120572, Stride: 4},
- {Lo: 120574, Hi: 120580, Stride: 6},
- {Lo: 120584, Hi: 120592, Stride: 2},
- {Lo: 120602, Hi: 120604, Stride: 2},
- {Lo: 120605, Hi: 120608, Stride: 3},
- {Lo: 120609, Hi: 120610, Stride: 1},
- {Lo: 120612, Hi: 120613, Stride: 1},
- {Lo: 120615, Hi: 120616, Stride: 1},
- {Lo: 120618, Hi: 120620, Stride: 2},
- {Lo: 120623, Hi: 120624, Stride: 1},
- {Lo: 120626, Hi: 120630, Stride: 4},
- {Lo: 120632, Hi: 120638, Stride: 6},
- {Lo: 120642, Hi: 120650, Stride: 2},
- {Lo: 120660, Hi: 120662, Stride: 2},
- {Lo: 120663, Hi: 120666, Stride: 3},
- {Lo: 120667, Hi: 120668, Stride: 1},
- {Lo: 120670, Hi: 120671, Stride: 1},
- {Lo: 120673, Hi: 120674, Stride: 1},
- {Lo: 120676, Hi: 120678, Stride: 2},
- {Lo: 120681, Hi: 120682, Stride: 1},
- {Lo: 120684, Hi: 120688, Stride: 4},
- {Lo: 120690, Hi: 120696, Stride: 6},
- {Lo: 120700, Hi: 120708, Stride: 2},
- {Lo: 120718, Hi: 120720, Stride: 2},
- {Lo: 120721, Hi: 120724, Stride: 3},
- {Lo: 120725, Hi: 120726, Stride: 1},
- {Lo: 120728, Hi: 120729, Stride: 1},
- {Lo: 120731, Hi: 120732, Stride: 1},
- {Lo: 120734, Hi: 120736, Stride: 2},
- {Lo: 120739, Hi: 120740, Stride: 1},
- {Lo: 120742, Hi: 120746, Stride: 4},
- {Lo: 120748, Hi: 120754, Stride: 6},
- {Lo: 120758, Hi: 120766, Stride: 2},
- {Lo: 120776, Hi: 120778, Stride: 2},
- {Lo: 120782, Hi: 120831, Stride: 1},
- {Lo: 125127, Hi: 125131, Stride: 4},
- {Lo: 126464, Hi: 126500, Stride: 36},
- {Lo: 126564, Hi: 126592, Stride: 28},
- {Lo: 126596, Hi: 128844, Stride: 2248},
- {Lo: 128872, Hi: 130032, Stride: 1160},
- {Lo: 130033, Hi: 130041, Stride: 1},
- },
- LatinOffset: 0,
},
- },
- "_default": {
- Confusable: []rune{160, 180, 215, 305, 921, 1009, 1040, 1042, 1045, 1047, 1050, 1052, 1053, 1054, 1056, 1057, 1058, 1059, 1061, 1068, 1072, 1073, 1075, 1077, 1086, 1088, 1089, 1091, 1093, 8211, 8216, 8217, 8245, 12494, 65281, 65283, 65288, 65289, 65292, 65306, 65307, 65311, 65374},
- With: []rune{32, 96, 120, 105, 73, 112, 65, 66, 69, 51, 75, 77, 72, 79, 80, 67, 84, 89, 88, 98, 97, 54, 114, 101, 111, 112, 99, 121, 120, 45, 96, 96, 96, 47, 33, 35, 40, 41, 44, 58, 59, 63, 126},
- Locale: "_default",
- RangeTable: &unicode.RangeTable{
- R16: []unicode.Range16{
- {Lo: 160, Hi: 180, Stride: 20},
- {Lo: 215, Hi: 305, Stride: 90},
- {Lo: 921, Hi: 1009, Stride: 88},
- {Lo: 1040, Hi: 1042, Stride: 2},
- {Lo: 1045, Hi: 1047, Stride: 2},
- {Lo: 1050, Hi: 1052, Stride: 2},
- {Lo: 1053, Hi: 1054, Stride: 1},
- {Lo: 1056, Hi: 1059, Stride: 1},
- {Lo: 1061, Hi: 1068, Stride: 7},
- {Lo: 1072, Hi: 1073, Stride: 1},
- {Lo: 1075, Hi: 1077, Stride: 2},
- {Lo: 1086, Hi: 1088, Stride: 2},
- {Lo: 1089, Hi: 1093, Stride: 2},
- {Lo: 8211, Hi: 8216, Stride: 5},
- {Lo: 8217, Hi: 8245, Stride: 28},
- {Lo: 12494, Hi: 65281, Stride: 52787},
- {Lo: 65283, Hi: 65288, Stride: 5},
- {Lo: 65289, Hi: 65292, Stride: 3},
- {Lo: 65306, Hi: 65307, Stride: 1},
- {Lo: 65311, Hi: 65374, Stride: 63},
+
+ "_default": {
+ Confusable: []rune{160, 180, 215, 305, 921, 1009, 1040, 1042, 1045, 1047, 1050, 1052, 1053, 1054, 1056, 1057, 1058, 1059, 1061, 1068, 1072, 1073, 1075, 1077, 1086, 1088, 1089, 1091, 1093, 8211, 8216, 8217, 8245, 12494, 65281, 65283, 65288, 65289, 65292, 65306, 65307, 65311, 65374},
+ With: []rune{32, 96, 120, 105, 73, 112, 65, 66, 69, 51, 75, 77, 72, 79, 80, 67, 84, 89, 88, 98, 97, 54, 114, 101, 111, 112, 99, 121, 120, 45, 96, 96, 96, 47, 33, 35, 40, 41, 44, 58, 59, 63, 126},
+ Locale: "_default",
+ RangeTable: &unicode.RangeTable{
+ R16: []unicode.Range16{
+ {Lo: 160, Hi: 180, Stride: 20},
+ {Lo: 215, Hi: 305, Stride: 90},
+ {Lo: 921, Hi: 1009, Stride: 88},
+ {Lo: 1040, Hi: 1042, Stride: 2},
+ {Lo: 1045, Hi: 1047, Stride: 2},
+ {Lo: 1050, Hi: 1052, Stride: 2},
+ {Lo: 1053, Hi: 1054, Stride: 1},
+ {Lo: 1056, Hi: 1059, Stride: 1},
+ {Lo: 1061, Hi: 1068, Stride: 7},
+ {Lo: 1072, Hi: 1073, Stride: 1},
+ {Lo: 1075, Hi: 1077, Stride: 2},
+ {Lo: 1086, Hi: 1088, Stride: 2},
+ {Lo: 1089, Hi: 1093, Stride: 2},
+ {Lo: 8211, Hi: 8216, Stride: 5},
+ {Lo: 8217, Hi: 8245, Stride: 28},
+ {Lo: 12494, Hi: 65281, Stride: 52787},
+ {Lo: 65283, Hi: 65288, Stride: 5},
+ {Lo: 65289, Hi: 65292, Stride: 3},
+ {Lo: 65306, Hi: 65307, Stride: 1},
+ {Lo: 65311, Hi: 65374, Stride: 63},
+ },
+ R32: []unicode.Range32{},
+ LatinOffset: 1,
},
- R32: []unicode.Range32{},
- LatinOffset: 1,
},
- },
- "cs": {
- Confusable: []rune{180, 305, 921, 1009, 1040, 1042, 1045, 1047, 1050, 1052, 1053, 1054, 1056, 1057, 1058, 1059, 1061, 1068, 1072, 1073, 1075, 1077, 1086, 1088, 1089, 1091, 1093, 8216, 8217, 8245, 12494, 65281, 65283, 65288, 65289, 65292, 65306, 65307, 65311, 65374},
- With: []rune{96, 105, 73, 112, 65, 66, 69, 51, 75, 77, 72, 79, 80, 67, 84, 89, 88, 98, 97, 54, 114, 101, 111, 112, 99, 121, 120, 96, 96, 96, 47, 33, 35, 40, 41, 44, 58, 59, 63, 126},
- Locale: "cs",
- RangeTable: &unicode.RangeTable{
- R16: []unicode.Range16{
- {Lo: 180, Hi: 305, Stride: 125},
- {Lo: 921, Hi: 1009, Stride: 88},
- {Lo: 1040, Hi: 1042, Stride: 2},
- {Lo: 1045, Hi: 1047, Stride: 2},
- {Lo: 1050, Hi: 1052, Stride: 2},
- {Lo: 1053, Hi: 1054, Stride: 1},
- {Lo: 1056, Hi: 1059, Stride: 1},
- {Lo: 1061, Hi: 1068, Stride: 7},
- {Lo: 1072, Hi: 1073, Stride: 1},
- {Lo: 1075, Hi: 1077, Stride: 2},
- {Lo: 1086, Hi: 1088, Stride: 2},
- {Lo: 1089, Hi: 1093, Stride: 2},
- {Lo: 8216, Hi: 8217, Stride: 1},
- {Lo: 8245, Hi: 12494, Stride: 4249},
- {Lo: 65281, Hi: 65283, Stride: 2},
- {Lo: 65288, Hi: 65289, Stride: 1},
- {Lo: 65292, Hi: 65306, Stride: 14},
- {Lo: 65307, Hi: 65311, Stride: 4},
- {Lo: 65374, Hi: 65374, Stride: 1},
+
+ "cs": {
+ Confusable: []rune{180, 305, 921, 1009, 1040, 1042, 1045, 1047, 1050, 1052, 1053, 1054, 1056, 1057, 1058, 1059, 1061, 1068, 1072, 1073, 1075, 1077, 1086, 1088, 1089, 1091, 1093, 8216, 8217, 8245, 12494, 65281, 65283, 65288, 65289, 65292, 65306, 65307, 65311, 65374},
+ With: []rune{96, 105, 73, 112, 65, 66, 69, 51, 75, 77, 72, 79, 80, 67, 84, 89, 88, 98, 97, 54, 114, 101, 111, 112, 99, 121, 120, 96, 96, 96, 47, 33, 35, 40, 41, 44, 58, 59, 63, 126},
+ Locale: "cs",
+ RangeTable: &unicode.RangeTable{
+ R16: []unicode.Range16{
+ {Lo: 180, Hi: 305, Stride: 125},
+ {Lo: 921, Hi: 1009, Stride: 88},
+ {Lo: 1040, Hi: 1042, Stride: 2},
+ {Lo: 1045, Hi: 1047, Stride: 2},
+ {Lo: 1050, Hi: 1052, Stride: 2},
+ {Lo: 1053, Hi: 1054, Stride: 1},
+ {Lo: 1056, Hi: 1059, Stride: 1},
+ {Lo: 1061, Hi: 1068, Stride: 7},
+ {Lo: 1072, Hi: 1073, Stride: 1},
+ {Lo: 1075, Hi: 1077, Stride: 2},
+ {Lo: 1086, Hi: 1088, Stride: 2},
+ {Lo: 1089, Hi: 1093, Stride: 2},
+ {Lo: 8216, Hi: 8217, Stride: 1},
+ {Lo: 8245, Hi: 12494, Stride: 4249},
+ {Lo: 65281, Hi: 65283, Stride: 2},
+ {Lo: 65288, Hi: 65289, Stride: 1},
+ {Lo: 65292, Hi: 65306, Stride: 14},
+ {Lo: 65307, Hi: 65311, Stride: 4},
+ {Lo: 65374, Hi: 65374, Stride: 1},
+ },
+ R32: []unicode.Range32{},
+ LatinOffset: 0,
},
- R32: []unicode.Range32{},
- LatinOffset: 0,
},
- },
- "de": {
- Confusable: []rune{180, 305, 921, 1009, 1040, 1042, 1045, 1047, 1050, 1052, 1053, 1054, 1056, 1057, 1058, 1059, 1061, 1068, 1072, 1073, 1075, 1077, 1086, 1088, 1089, 1091, 1093, 8216, 8217, 8245, 12494, 65281, 65283, 65288, 65289, 65292, 65306, 65307, 65311, 65374},
- With: []rune{96, 105, 73, 112, 65, 66, 69, 51, 75, 77, 72, 79, 80, 67, 84, 89, 88, 98, 97, 54, 114, 101, 111, 112, 99, 121, 120, 96, 96, 96, 47, 33, 35, 40, 41, 44, 58, 59, 63, 126},
- Locale: "de",
- RangeTable: &unicode.RangeTable{
- R16: []unicode.Range16{
- {Lo: 180, Hi: 305, Stride: 125},
- {Lo: 921, Hi: 1009, Stride: 88},
- {Lo: 1040, Hi: 1042, Stride: 2},
- {Lo: 1045, Hi: 1047, Stride: 2},
- {Lo: 1050, Hi: 1052, Stride: 2},
- {Lo: 1053, Hi: 1054, Stride: 1},
- {Lo: 1056, Hi: 1059, Stride: 1},
- {Lo: 1061, Hi: 1068, Stride: 7},
- {Lo: 1072, Hi: 1073, Stride: 1},
- {Lo: 1075, Hi: 1077, Stride: 2},
- {Lo: 1086, Hi: 1088, Stride: 2},
- {Lo: 1089, Hi: 1093, Stride: 2},
- {Lo: 8216, Hi: 8217, Stride: 1},
- {Lo: 8245, Hi: 12494, Stride: 4249},
- {Lo: 65281, Hi: 65283, Stride: 2},
- {Lo: 65288, Hi: 65289, Stride: 1},
- {Lo: 65292, Hi: 65306, Stride: 14},
- {Lo: 65307, Hi: 65311, Stride: 4},
- {Lo: 65374, Hi: 65374, Stride: 1},
+
+ "de": {
+ Confusable: []rune{180, 305, 921, 1009, 1040, 1042, 1045, 1047, 1050, 1052, 1053, 1054, 1056, 1057, 1058, 1059, 1061, 1068, 1072, 1073, 1075, 1077, 1086, 1088, 1089, 1091, 1093, 8216, 8217, 8245, 12494, 65281, 65283, 65288, 65289, 65292, 65306, 65307, 65311, 65374},
+ With: []rune{96, 105, 73, 112, 65, 66, 69, 51, 75, 77, 72, 79, 80, 67, 84, 89, 88, 98, 97, 54, 114, 101, 111, 112, 99, 121, 120, 96, 96, 96, 47, 33, 35, 40, 41, 44, 58, 59, 63, 126},
+ Locale: "de",
+ RangeTable: &unicode.RangeTable{
+ R16: []unicode.Range16{
+ {Lo: 180, Hi: 305, Stride: 125},
+ {Lo: 921, Hi: 1009, Stride: 88},
+ {Lo: 1040, Hi: 1042, Stride: 2},
+ {Lo: 1045, Hi: 1047, Stride: 2},
+ {Lo: 1050, Hi: 1052, Stride: 2},
+ {Lo: 1053, Hi: 1054, Stride: 1},
+ {Lo: 1056, Hi: 1059, Stride: 1},
+ {Lo: 1061, Hi: 1068, Stride: 7},
+ {Lo: 1072, Hi: 1073, Stride: 1},
+ {Lo: 1075, Hi: 1077, Stride: 2},
+ {Lo: 1086, Hi: 1088, Stride: 2},
+ {Lo: 1089, Hi: 1093, Stride: 2},
+ {Lo: 8216, Hi: 8217, Stride: 1},
+ {Lo: 8245, Hi: 12494, Stride: 4249},
+ {Lo: 65281, Hi: 65283, Stride: 2},
+ {Lo: 65288, Hi: 65289, Stride: 1},
+ {Lo: 65292, Hi: 65306, Stride: 14},
+ {Lo: 65307, Hi: 65311, Stride: 4},
+ {Lo: 65374, Hi: 65374, Stride: 1},
+ },
+ R32: []unicode.Range32{},
+ LatinOffset: 0,
},
- R32: []unicode.Range32{},
- LatinOffset: 0,
},
- },
- "es": {
- Confusable: []rune{180, 215, 305, 1009, 1040, 1042, 1045, 1047, 1050, 1052, 1053, 1054, 1056, 1057, 1058, 1059, 1061, 1068, 1072, 1073, 1075, 1077, 1086, 1088, 1089, 1091, 1093, 8211, 8245, 12494, 65281, 65283, 65288, 65289, 65292, 65306, 65307, 65311, 65374},
- With: []rune{96, 120, 105, 112, 65, 66, 69, 51, 75, 77, 72, 79, 80, 67, 84, 89, 88, 98, 97, 54, 114, 101, 111, 112, 99, 121, 120, 45, 96, 47, 33, 35, 40, 41, 44, 58, 59, 63, 126},
- Locale: "es",
- RangeTable: &unicode.RangeTable{
- R16: []unicode.Range16{
- {Lo: 180, Hi: 215, Stride: 35},
- {Lo: 305, Hi: 1009, Stride: 704},
- {Lo: 1040, Hi: 1042, Stride: 2},
- {Lo: 1045, Hi: 1047, Stride: 2},
- {Lo: 1050, Hi: 1052, Stride: 2},
- {Lo: 1053, Hi: 1054, Stride: 1},
- {Lo: 1056, Hi: 1059, Stride: 1},
- {Lo: 1061, Hi: 1068, Stride: 7},
- {Lo: 1072, Hi: 1073, Stride: 1},
- {Lo: 1075, Hi: 1077, Stride: 2},
- {Lo: 1086, Hi: 1088, Stride: 2},
- {Lo: 1089, Hi: 1093, Stride: 2},
- {Lo: 8211, Hi: 8245, Stride: 34},
- {Lo: 12494, Hi: 65281, Stride: 52787},
- {Lo: 65283, Hi: 65288, Stride: 5},
- {Lo: 65289, Hi: 65292, Stride: 3},
- {Lo: 65306, Hi: 65307, Stride: 1},
- {Lo: 65311, Hi: 65374, Stride: 63},
+
+ "es": {
+ Confusable: []rune{180, 215, 305, 1009, 1040, 1042, 1045, 1047, 1050, 1052, 1053, 1054, 1056, 1057, 1058, 1059, 1061, 1068, 1072, 1073, 1075, 1077, 1086, 1088, 1089, 1091, 1093, 8211, 8245, 12494, 65281, 65283, 65288, 65289, 65292, 65306, 65307, 65311, 65374},
+ With: []rune{96, 120, 105, 112, 65, 66, 69, 51, 75, 77, 72, 79, 80, 67, 84, 89, 88, 98, 97, 54, 114, 101, 111, 112, 99, 121, 120, 45, 96, 47, 33, 35, 40, 41, 44, 58, 59, 63, 126},
+ Locale: "es",
+ RangeTable: &unicode.RangeTable{
+ R16: []unicode.Range16{
+ {Lo: 180, Hi: 215, Stride: 35},
+ {Lo: 305, Hi: 1009, Stride: 704},
+ {Lo: 1040, Hi: 1042, Stride: 2},
+ {Lo: 1045, Hi: 1047, Stride: 2},
+ {Lo: 1050, Hi: 1052, Stride: 2},
+ {Lo: 1053, Hi: 1054, Stride: 1},
+ {Lo: 1056, Hi: 1059, Stride: 1},
+ {Lo: 1061, Hi: 1068, Stride: 7},
+ {Lo: 1072, Hi: 1073, Stride: 1},
+ {Lo: 1075, Hi: 1077, Stride: 2},
+ {Lo: 1086, Hi: 1088, Stride: 2},
+ {Lo: 1089, Hi: 1093, Stride: 2},
+ {Lo: 8211, Hi: 8245, Stride: 34},
+ {Lo: 12494, Hi: 65281, Stride: 52787},
+ {Lo: 65283, Hi: 65288, Stride: 5},
+ {Lo: 65289, Hi: 65292, Stride: 3},
+ {Lo: 65306, Hi: 65307, Stride: 1},
+ {Lo: 65311, Hi: 65374, Stride: 63},
+ },
+ R32: []unicode.Range32{},
+ LatinOffset: 1,
},
- R32: []unicode.Range32{},
- LatinOffset: 1,
},
- },
- "fr": {
- Confusable: []rune{215, 305, 921, 1009, 1040, 1042, 1045, 1047, 1050, 1052, 1053, 1054, 1056, 1057, 1058, 1059, 1061, 1068, 1072, 1073, 1075, 1077, 1086, 1088, 1089, 1091, 1093, 8216, 8245, 12494, 65281, 65283, 65288, 65289, 65292, 65306, 65307, 65311, 65374},
- With: []rune{120, 105, 73, 112, 65, 66, 69, 51, 75, 77, 72, 79, 80, 67, 84, 89, 88, 98, 97, 54, 114, 101, 111, 112, 99, 121, 120, 96, 96, 47, 33, 35, 40, 41, 44, 58, 59, 63, 126},
- Locale: "fr",
- RangeTable: &unicode.RangeTable{
- R16: []unicode.Range16{
- {Lo: 215, Hi: 305, Stride: 90},
- {Lo: 921, Hi: 1009, Stride: 88},
- {Lo: 1040, Hi: 1042, Stride: 2},
- {Lo: 1045, Hi: 1047, Stride: 2},
- {Lo: 1050, Hi: 1052, Stride: 2},
- {Lo: 1053, Hi: 1054, Stride: 1},
- {Lo: 1056, Hi: 1059, Stride: 1},
- {Lo: 1061, Hi: 1068, Stride: 7},
- {Lo: 1072, Hi: 1073, Stride: 1},
- {Lo: 1075, Hi: 1077, Stride: 2},
- {Lo: 1086, Hi: 1088, Stride: 2},
- {Lo: 1089, Hi: 1093, Stride: 2},
- {Lo: 8216, Hi: 8245, Stride: 29},
- {Lo: 12494, Hi: 65281, Stride: 52787},
- {Lo: 65283, Hi: 65288, Stride: 5},
- {Lo: 65289, Hi: 65292, Stride: 3},
- {Lo: 65306, Hi: 65307, Stride: 1},
- {Lo: 65311, Hi: 65374, Stride: 63},
+
+ "fr": {
+ Confusable: []rune{215, 305, 921, 1009, 1040, 1042, 1045, 1047, 1050, 1052, 1053, 1054, 1056, 1057, 1058, 1059, 1061, 1068, 1072, 1073, 1075, 1077, 1086, 1088, 1089, 1091, 1093, 8216, 8245, 12494, 65281, 65283, 65288, 65289, 65292, 65306, 65307, 65311, 65374},
+ With: []rune{120, 105, 73, 112, 65, 66, 69, 51, 75, 77, 72, 79, 80, 67, 84, 89, 88, 98, 97, 54, 114, 101, 111, 112, 99, 121, 120, 96, 96, 47, 33, 35, 40, 41, 44, 58, 59, 63, 126},
+ Locale: "fr",
+ RangeTable: &unicode.RangeTable{
+ R16: []unicode.Range16{
+ {Lo: 215, Hi: 305, Stride: 90},
+ {Lo: 921, Hi: 1009, Stride: 88},
+ {Lo: 1040, Hi: 1042, Stride: 2},
+ {Lo: 1045, Hi: 1047, Stride: 2},
+ {Lo: 1050, Hi: 1052, Stride: 2},
+ {Lo: 1053, Hi: 1054, Stride: 1},
+ {Lo: 1056, Hi: 1059, Stride: 1},
+ {Lo: 1061, Hi: 1068, Stride: 7},
+ {Lo: 1072, Hi: 1073, Stride: 1},
+ {Lo: 1075, Hi: 1077, Stride: 2},
+ {Lo: 1086, Hi: 1088, Stride: 2},
+ {Lo: 1089, Hi: 1093, Stride: 2},
+ {Lo: 8216, Hi: 8245, Stride: 29},
+ {Lo: 12494, Hi: 65281, Stride: 52787},
+ {Lo: 65283, Hi: 65288, Stride: 5},
+ {Lo: 65289, Hi: 65292, Stride: 3},
+ {Lo: 65306, Hi: 65307, Stride: 1},
+ {Lo: 65311, Hi: 65374, Stride: 63},
+ },
+ R32: []unicode.Range32{},
+ LatinOffset: 0,
},
- R32: []unicode.Range32{},
- LatinOffset: 0,
},
- },
- "it": {
- Confusable: []rune{160, 180, 215, 305, 921, 1009, 1040, 1042, 1045, 1047, 1050, 1052, 1053, 1054, 1056, 1057, 1058, 1059, 1061, 1068, 1072, 1073, 1075, 1077, 1086, 1088, 1089, 1091, 1093, 8211, 8216, 8245, 12494, 65281, 65283, 65288, 65289, 65292, 65306, 65307, 65311, 65374},
- With: []rune{32, 96, 120, 105, 73, 112, 65, 66, 69, 51, 75, 77, 72, 79, 80, 67, 84, 89, 88, 98, 97, 54, 114, 101, 111, 112, 99, 121, 120, 45, 96, 96, 47, 33, 35, 40, 41, 44, 58, 59, 63, 126},
- Locale: "it",
- RangeTable: &unicode.RangeTable{
- R16: []unicode.Range16{
- {Lo: 160, Hi: 180, Stride: 20},
- {Lo: 215, Hi: 305, Stride: 90},
- {Lo: 921, Hi: 1009, Stride: 88},
- {Lo: 1040, Hi: 1042, Stride: 2},
- {Lo: 1045, Hi: 1047, Stride: 2},
- {Lo: 1050, Hi: 1052, Stride: 2},
- {Lo: 1053, Hi: 1054, Stride: 1},
- {Lo: 1056, Hi: 1059, Stride: 1},
- {Lo: 1061, Hi: 1068, Stride: 7},
- {Lo: 1072, Hi: 1073, Stride: 1},
- {Lo: 1075, Hi: 1077, Stride: 2},
- {Lo: 1086, Hi: 1088, Stride: 2},
- {Lo: 1089, Hi: 1093, Stride: 2},
- {Lo: 8211, Hi: 8216, Stride: 5},
- {Lo: 8245, Hi: 12494, Stride: 4249},
- {Lo: 65281, Hi: 65283, Stride: 2},
- {Lo: 65288, Hi: 65289, Stride: 1},
- {Lo: 65292, Hi: 65306, Stride: 14},
- {Lo: 65307, Hi: 65311, Stride: 4},
- {Lo: 65374, Hi: 65374, Stride: 1},
+
+ "it": {
+ Confusable: []rune{160, 180, 215, 305, 921, 1009, 1040, 1042, 1045, 1047, 1050, 1052, 1053, 1054, 1056, 1057, 1058, 1059, 1061, 1068, 1072, 1073, 1075, 1077, 1086, 1088, 1089, 1091, 1093, 8211, 8216, 8245, 12494, 65281, 65283, 65288, 65289, 65292, 65306, 65307, 65311, 65374},
+ With: []rune{32, 96, 120, 105, 73, 112, 65, 66, 69, 51, 75, 77, 72, 79, 80, 67, 84, 89, 88, 98, 97, 54, 114, 101, 111, 112, 99, 121, 120, 45, 96, 96, 47, 33, 35, 40, 41, 44, 58, 59, 63, 126},
+ Locale: "it",
+ RangeTable: &unicode.RangeTable{
+ R16: []unicode.Range16{
+ {Lo: 160, Hi: 180, Stride: 20},
+ {Lo: 215, Hi: 305, Stride: 90},
+ {Lo: 921, Hi: 1009, Stride: 88},
+ {Lo: 1040, Hi: 1042, Stride: 2},
+ {Lo: 1045, Hi: 1047, Stride: 2},
+ {Lo: 1050, Hi: 1052, Stride: 2},
+ {Lo: 1053, Hi: 1054, Stride: 1},
+ {Lo: 1056, Hi: 1059, Stride: 1},
+ {Lo: 1061, Hi: 1068, Stride: 7},
+ {Lo: 1072, Hi: 1073, Stride: 1},
+ {Lo: 1075, Hi: 1077, Stride: 2},
+ {Lo: 1086, Hi: 1088, Stride: 2},
+ {Lo: 1089, Hi: 1093, Stride: 2},
+ {Lo: 8211, Hi: 8216, Stride: 5},
+ {Lo: 8245, Hi: 12494, Stride: 4249},
+ {Lo: 65281, Hi: 65283, Stride: 2},
+ {Lo: 65288, Hi: 65289, Stride: 1},
+ {Lo: 65292, Hi: 65306, Stride: 14},
+ {Lo: 65307, Hi: 65311, Stride: 4},
+ {Lo: 65374, Hi: 65374, Stride: 1},
+ },
+ R32: []unicode.Range32{},
+ LatinOffset: 1,
},
- R32: []unicode.Range32{},
- LatinOffset: 1,
},
- },
- "ja": {
- Confusable: []rune{180, 215, 305, 921, 1009, 1040, 1042, 1045, 1047, 1050, 1052, 1053, 1054, 1056, 1057, 1058, 1059, 1061, 1068, 1072, 1073, 1075, 1077, 1086, 1088, 1089, 1091, 1093, 8211, 8216, 8217, 8245, 65281, 65283, 65292, 65306, 65307},
- With: []rune{96, 120, 105, 73, 112, 65, 66, 69, 51, 75, 77, 72, 79, 80, 67, 84, 89, 88, 98, 97, 54, 114, 101, 111, 112, 99, 121, 120, 45, 96, 96, 96, 33, 35, 44, 58, 59},
- Locale: "ja",
- RangeTable: &unicode.RangeTable{
- R16: []unicode.Range16{
- {Lo: 180, Hi: 215, Stride: 35},
- {Lo: 305, Hi: 921, Stride: 616},
- {Lo: 1009, Hi: 1040, Stride: 31},
- {Lo: 1042, Hi: 1045, Stride: 3},
- {Lo: 1047, Hi: 1050, Stride: 3},
- {Lo: 1052, Hi: 1054, Stride: 1},
- {Lo: 1056, Hi: 1059, Stride: 1},
- {Lo: 1061, Hi: 1068, Stride: 7},
- {Lo: 1072, Hi: 1073, Stride: 1},
- {Lo: 1075, Hi: 1077, Stride: 2},
- {Lo: 1086, Hi: 1088, Stride: 2},
- {Lo: 1089, Hi: 1093, Stride: 2},
- {Lo: 8211, Hi: 8216, Stride: 5},
- {Lo: 8217, Hi: 8245, Stride: 28},
- {Lo: 65281, Hi: 65283, Stride: 2},
- {Lo: 65292, Hi: 65306, Stride: 14},
- {Lo: 65307, Hi: 65307, Stride: 1},
+
+ "ja": {
+ Confusable: []rune{180, 215, 305, 921, 1009, 1040, 1042, 1045, 1047, 1050, 1052, 1053, 1054, 1056, 1057, 1058, 1059, 1061, 1068, 1072, 1073, 1075, 1077, 1086, 1088, 1089, 1091, 1093, 8211, 8216, 8217, 8245, 65281, 65283, 65292, 65306, 65307},
+ With: []rune{96, 120, 105, 73, 112, 65, 66, 69, 51, 75, 77, 72, 79, 80, 67, 84, 89, 88, 98, 97, 54, 114, 101, 111, 112, 99, 121, 120, 45, 96, 96, 96, 33, 35, 44, 58, 59},
+ Locale: "ja",
+ RangeTable: &unicode.RangeTable{
+ R16: []unicode.Range16{
+ {Lo: 180, Hi: 215, Stride: 35},
+ {Lo: 305, Hi: 921, Stride: 616},
+ {Lo: 1009, Hi: 1040, Stride: 31},
+ {Lo: 1042, Hi: 1045, Stride: 3},
+ {Lo: 1047, Hi: 1050, Stride: 3},
+ {Lo: 1052, Hi: 1054, Stride: 1},
+ {Lo: 1056, Hi: 1059, Stride: 1},
+ {Lo: 1061, Hi: 1068, Stride: 7},
+ {Lo: 1072, Hi: 1073, Stride: 1},
+ {Lo: 1075, Hi: 1077, Stride: 2},
+ {Lo: 1086, Hi: 1088, Stride: 2},
+ {Lo: 1089, Hi: 1093, Stride: 2},
+ {Lo: 8211, Hi: 8216, Stride: 5},
+ {Lo: 8217, Hi: 8245, Stride: 28},
+ {Lo: 65281, Hi: 65283, Stride: 2},
+ {Lo: 65292, Hi: 65306, Stride: 14},
+ {Lo: 65307, Hi: 65307, Stride: 1},
+ },
+ R32: []unicode.Range32{},
+ LatinOffset: 1,
},
- R32: []unicode.Range32{},
- LatinOffset: 1,
},
- },
- "ko": {
- Confusable: []rune{180, 215, 305, 921, 1009, 1040, 1042, 1045, 1047, 1050, 1052, 1053, 1054, 1056, 1057, 1058, 1059, 1061, 1068, 1072, 1073, 1075, 1077, 1086, 1088, 1089, 1091, 1093, 8211, 8245, 12494, 65281, 65283, 65288, 65289, 65292, 65306, 65307, 65311, 65374},
- With: []rune{96, 120, 105, 73, 112, 65, 66, 69, 51, 75, 77, 72, 79, 80, 67, 84, 89, 88, 98, 97, 54, 114, 101, 111, 112, 99, 121, 120, 45, 96, 47, 33, 35, 40, 41, 44, 58, 59, 63, 126},
- Locale: "ko",
- RangeTable: &unicode.RangeTable{
- R16: []unicode.Range16{
- {Lo: 180, Hi: 215, Stride: 35},
- {Lo: 305, Hi: 921, Stride: 616},
- {Lo: 1009, Hi: 1040, Stride: 31},
- {Lo: 1042, Hi: 1045, Stride: 3},
- {Lo: 1047, Hi: 1050, Stride: 3},
- {Lo: 1052, Hi: 1054, Stride: 1},
- {Lo: 1056, Hi: 1059, Stride: 1},
- {Lo: 1061, Hi: 1068, Stride: 7},
- {Lo: 1072, Hi: 1073, Stride: 1},
- {Lo: 1075, Hi: 1077, Stride: 2},
- {Lo: 1086, Hi: 1088, Stride: 2},
- {Lo: 1089, Hi: 1093, Stride: 2},
- {Lo: 8211, Hi: 8245, Stride: 34},
- {Lo: 12494, Hi: 65281, Stride: 52787},
- {Lo: 65283, Hi: 65288, Stride: 5},
- {Lo: 65289, Hi: 65292, Stride: 3},
- {Lo: 65306, Hi: 65307, Stride: 1},
- {Lo: 65311, Hi: 65374, Stride: 63},
+
+ "ko": {
+ Confusable: []rune{180, 215, 305, 921, 1009, 1040, 1042, 1045, 1047, 1050, 1052, 1053, 1054, 1056, 1057, 1058, 1059, 1061, 1068, 1072, 1073, 1075, 1077, 1086, 1088, 1089, 1091, 1093, 8211, 8245, 12494, 65281, 65283, 65288, 65289, 65292, 65306, 65307, 65311, 65374},
+ With: []rune{96, 120, 105, 73, 112, 65, 66, 69, 51, 75, 77, 72, 79, 80, 67, 84, 89, 88, 98, 97, 54, 114, 101, 111, 112, 99, 121, 120, 45, 96, 47, 33, 35, 40, 41, 44, 58, 59, 63, 126},
+ Locale: "ko",
+ RangeTable: &unicode.RangeTable{
+ R16: []unicode.Range16{
+ {Lo: 180, Hi: 215, Stride: 35},
+ {Lo: 305, Hi: 921, Stride: 616},
+ {Lo: 1009, Hi: 1040, Stride: 31},
+ {Lo: 1042, Hi: 1045, Stride: 3},
+ {Lo: 1047, Hi: 1050, Stride: 3},
+ {Lo: 1052, Hi: 1054, Stride: 1},
+ {Lo: 1056, Hi: 1059, Stride: 1},
+ {Lo: 1061, Hi: 1068, Stride: 7},
+ {Lo: 1072, Hi: 1073, Stride: 1},
+ {Lo: 1075, Hi: 1077, Stride: 2},
+ {Lo: 1086, Hi: 1088, Stride: 2},
+ {Lo: 1089, Hi: 1093, Stride: 2},
+ {Lo: 8211, Hi: 8245, Stride: 34},
+ {Lo: 12494, Hi: 65281, Stride: 52787},
+ {Lo: 65283, Hi: 65288, Stride: 5},
+ {Lo: 65289, Hi: 65292, Stride: 3},
+ {Lo: 65306, Hi: 65307, Stride: 1},
+ {Lo: 65311, Hi: 65374, Stride: 63},
+ },
+ R32: []unicode.Range32{},
+ LatinOffset: 1,
},
- R32: []unicode.Range32{},
- LatinOffset: 1,
},
- },
- "pl": {
- Confusable: []rune{180, 215, 305, 921, 1009, 1040, 1042, 1045, 1047, 1050, 1052, 1053, 1054, 1056, 1057, 1058, 1059, 1061, 1068, 1072, 1073, 1075, 1077, 1086, 1088, 1089, 1091, 1093, 8216, 8217, 8245, 12494, 65281, 65283, 65288, 65289, 65292, 65306, 65307, 65311, 65374},
- With: []rune{96, 120, 105, 73, 112, 65, 66, 69, 51, 75, 77, 72, 79, 80, 67, 84, 89, 88, 98, 97, 54, 114, 101, 111, 112, 99, 121, 120, 96, 96, 96, 47, 33, 35, 40, 41, 44, 58, 59, 63, 126},
- Locale: "pl",
- RangeTable: &unicode.RangeTable{
- R16: []unicode.Range16{
- {Lo: 180, Hi: 215, Stride: 35},
- {Lo: 305, Hi: 921, Stride: 616},
- {Lo: 1009, Hi: 1040, Stride: 31},
- {Lo: 1042, Hi: 1045, Stride: 3},
- {Lo: 1047, Hi: 1050, Stride: 3},
- {Lo: 1052, Hi: 1054, Stride: 1},
- {Lo: 1056, Hi: 1059, Stride: 1},
- {Lo: 1061, Hi: 1068, Stride: 7},
- {Lo: 1072, Hi: 1073, Stride: 1},
- {Lo: 1075, Hi: 1077, Stride: 2},
- {Lo: 1086, Hi: 1088, Stride: 2},
- {Lo: 1089, Hi: 1093, Stride: 2},
- {Lo: 8216, Hi: 8217, Stride: 1},
- {Lo: 8245, Hi: 12494, Stride: 4249},
- {Lo: 65281, Hi: 65283, Stride: 2},
- {Lo: 65288, Hi: 65289, Stride: 1},
- {Lo: 65292, Hi: 65306, Stride: 14},
- {Lo: 65307, Hi: 65311, Stride: 4},
- {Lo: 65374, Hi: 65374, Stride: 1},
+
+ "pl": {
+ Confusable: []rune{180, 215, 305, 921, 1009, 1040, 1042, 1045, 1047, 1050, 1052, 1053, 1054, 1056, 1057, 1058, 1059, 1061, 1068, 1072, 1073, 1075, 1077, 1086, 1088, 1089, 1091, 1093, 8216, 8217, 8245, 12494, 65281, 65283, 65288, 65289, 65292, 65306, 65307, 65311, 65374},
+ With: []rune{96, 120, 105, 73, 112, 65, 66, 69, 51, 75, 77, 72, 79, 80, 67, 84, 89, 88, 98, 97, 54, 114, 101, 111, 112, 99, 121, 120, 96, 96, 96, 47, 33, 35, 40, 41, 44, 58, 59, 63, 126},
+ Locale: "pl",
+ RangeTable: &unicode.RangeTable{
+ R16: []unicode.Range16{
+ {Lo: 180, Hi: 215, Stride: 35},
+ {Lo: 305, Hi: 921, Stride: 616},
+ {Lo: 1009, Hi: 1040, Stride: 31},
+ {Lo: 1042, Hi: 1045, Stride: 3},
+ {Lo: 1047, Hi: 1050, Stride: 3},
+ {Lo: 1052, Hi: 1054, Stride: 1},
+ {Lo: 1056, Hi: 1059, Stride: 1},
+ {Lo: 1061, Hi: 1068, Stride: 7},
+ {Lo: 1072, Hi: 1073, Stride: 1},
+ {Lo: 1075, Hi: 1077, Stride: 2},
+ {Lo: 1086, Hi: 1088, Stride: 2},
+ {Lo: 1089, Hi: 1093, Stride: 2},
+ {Lo: 8216, Hi: 8217, Stride: 1},
+ {Lo: 8245, Hi: 12494, Stride: 4249},
+ {Lo: 65281, Hi: 65283, Stride: 2},
+ {Lo: 65288, Hi: 65289, Stride: 1},
+ {Lo: 65292, Hi: 65306, Stride: 14},
+ {Lo: 65307, Hi: 65311, Stride: 4},
+ {Lo: 65374, Hi: 65374, Stride: 1},
+ },
+ R32: []unicode.Range32{},
+ LatinOffset: 1,
},
- R32: []unicode.Range32{},
- LatinOffset: 1,
},
- },
- "pt-BR": {
- Confusable: []rune{180, 215, 305, 921, 1009, 1040, 1042, 1045, 1047, 1050, 1052, 1053, 1054, 1056, 1057, 1058, 1059, 1061, 1068, 1072, 1073, 1075, 1077, 1086, 1088, 1089, 1091, 1093, 8216, 8217, 8245, 12494, 65281, 65283, 65288, 65289, 65292, 65306, 65307, 65311, 65374},
- With: []rune{96, 120, 105, 73, 112, 65, 66, 69, 51, 75, 77, 72, 79, 80, 67, 84, 89, 88, 98, 97, 54, 114, 101, 111, 112, 99, 121, 120, 96, 96, 96, 47, 33, 35, 40, 41, 44, 58, 59, 63, 126},
- Locale: "pt-BR",
- RangeTable: &unicode.RangeTable{
- R16: []unicode.Range16{
- {Lo: 180, Hi: 215, Stride: 35},
- {Lo: 305, Hi: 921, Stride: 616},
- {Lo: 1009, Hi: 1040, Stride: 31},
- {Lo: 1042, Hi: 1045, Stride: 3},
- {Lo: 1047, Hi: 1050, Stride: 3},
- {Lo: 1052, Hi: 1054, Stride: 1},
- {Lo: 1056, Hi: 1059, Stride: 1},
- {Lo: 1061, Hi: 1068, Stride: 7},
- {Lo: 1072, Hi: 1073, Stride: 1},
- {Lo: 1075, Hi: 1077, Stride: 2},
- {Lo: 1086, Hi: 1088, Stride: 2},
- {Lo: 1089, Hi: 1093, Stride: 2},
- {Lo: 8216, Hi: 8217, Stride: 1},
- {Lo: 8245, Hi: 12494, Stride: 4249},
- {Lo: 65281, Hi: 65283, Stride: 2},
- {Lo: 65288, Hi: 65289, Stride: 1},
- {Lo: 65292, Hi: 65306, Stride: 14},
- {Lo: 65307, Hi: 65311, Stride: 4},
- {Lo: 65374, Hi: 65374, Stride: 1},
+
+ "pt-BR": {
+ Confusable: []rune{180, 215, 305, 921, 1009, 1040, 1042, 1045, 1047, 1050, 1052, 1053, 1054, 1056, 1057, 1058, 1059, 1061, 1068, 1072, 1073, 1075, 1077, 1086, 1088, 1089, 1091, 1093, 8216, 8217, 8245, 12494, 65281, 65283, 65288, 65289, 65292, 65306, 65307, 65311, 65374},
+ With: []rune{96, 120, 105, 73, 112, 65, 66, 69, 51, 75, 77, 72, 79, 80, 67, 84, 89, 88, 98, 97, 54, 114, 101, 111, 112, 99, 121, 120, 96, 96, 96, 47, 33, 35, 40, 41, 44, 58, 59, 63, 126},
+ Locale: "pt-BR",
+ RangeTable: &unicode.RangeTable{
+ R16: []unicode.Range16{
+ {Lo: 180, Hi: 215, Stride: 35},
+ {Lo: 305, Hi: 921, Stride: 616},
+ {Lo: 1009, Hi: 1040, Stride: 31},
+ {Lo: 1042, Hi: 1045, Stride: 3},
+ {Lo: 1047, Hi: 1050, Stride: 3},
+ {Lo: 1052, Hi: 1054, Stride: 1},
+ {Lo: 1056, Hi: 1059, Stride: 1},
+ {Lo: 1061, Hi: 1068, Stride: 7},
+ {Lo: 1072, Hi: 1073, Stride: 1},
+ {Lo: 1075, Hi: 1077, Stride: 2},
+ {Lo: 1086, Hi: 1088, Stride: 2},
+ {Lo: 1089, Hi: 1093, Stride: 2},
+ {Lo: 8216, Hi: 8217, Stride: 1},
+ {Lo: 8245, Hi: 12494, Stride: 4249},
+ {Lo: 65281, Hi: 65283, Stride: 2},
+ {Lo: 65288, Hi: 65289, Stride: 1},
+ {Lo: 65292, Hi: 65306, Stride: 14},
+ {Lo: 65307, Hi: 65311, Stride: 4},
+ {Lo: 65374, Hi: 65374, Stride: 1},
+ },
+ R32: []unicode.Range32{},
+ LatinOffset: 1,
},
- R32: []unicode.Range32{},
- LatinOffset: 1,
},
- },
- "qps-ploc": {
- Confusable: []rune{160, 180, 215, 305, 921, 1040, 1042, 1045, 1047, 1050, 1052, 1053, 1054, 1056, 1057, 1058, 1059, 1061, 1068, 1072, 1073, 1075, 1077, 1086, 1088, 1089, 1091, 1093, 8211, 8216, 8217, 8245, 12494, 65281, 65283, 65288, 65289, 65292, 65306, 65307, 65311, 65374},
- With: []rune{32, 96, 120, 105, 73, 65, 66, 69, 51, 75, 77, 72, 79, 80, 67, 84, 89, 88, 98, 97, 54, 114, 101, 111, 112, 99, 121, 120, 45, 96, 96, 96, 47, 33, 35, 40, 41, 44, 58, 59, 63, 126},
- Locale: "qps-ploc",
- RangeTable: &unicode.RangeTable{
- R16: []unicode.Range16{
- {Lo: 160, Hi: 180, Stride: 20},
- {Lo: 215, Hi: 305, Stride: 90},
- {Lo: 921, Hi: 1040, Stride: 119},
- {Lo: 1042, Hi: 1045, Stride: 3},
- {Lo: 1047, Hi: 1050, Stride: 3},
- {Lo: 1052, Hi: 1054, Stride: 1},
- {Lo: 1056, Hi: 1059, Stride: 1},
- {Lo: 1061, Hi: 1068, Stride: 7},
- {Lo: 1072, Hi: 1073, Stride: 1},
- {Lo: 1075, Hi: 1077, Stride: 2},
- {Lo: 1086, Hi: 1088, Stride: 2},
- {Lo: 1089, Hi: 1093, Stride: 2},
- {Lo: 8211, Hi: 8216, Stride: 5},
- {Lo: 8217, Hi: 8245, Stride: 28},
- {Lo: 12494, Hi: 65281, Stride: 52787},
- {Lo: 65283, Hi: 65288, Stride: 5},
- {Lo: 65289, Hi: 65292, Stride: 3},
- {Lo: 65306, Hi: 65307, Stride: 1},
- {Lo: 65311, Hi: 65374, Stride: 63},
+
+ "qps-ploc": {
+ Confusable: []rune{160, 180, 215, 305, 921, 1040, 1042, 1045, 1047, 1050, 1052, 1053, 1054, 1056, 1057, 1058, 1059, 1061, 1068, 1072, 1073, 1075, 1077, 1086, 1088, 1089, 1091, 1093, 8211, 8216, 8217, 8245, 12494, 65281, 65283, 65288, 65289, 65292, 65306, 65307, 65311, 65374},
+ With: []rune{32, 96, 120, 105, 73, 65, 66, 69, 51, 75, 77, 72, 79, 80, 67, 84, 89, 88, 98, 97, 54, 114, 101, 111, 112, 99, 121, 120, 45, 96, 96, 96, 47, 33, 35, 40, 41, 44, 58, 59, 63, 126},
+ Locale: "qps-ploc",
+ RangeTable: &unicode.RangeTable{
+ R16: []unicode.Range16{
+ {Lo: 160, Hi: 180, Stride: 20},
+ {Lo: 215, Hi: 305, Stride: 90},
+ {Lo: 921, Hi: 1040, Stride: 119},
+ {Lo: 1042, Hi: 1045, Stride: 3},
+ {Lo: 1047, Hi: 1050, Stride: 3},
+ {Lo: 1052, Hi: 1054, Stride: 1},
+ {Lo: 1056, Hi: 1059, Stride: 1},
+ {Lo: 1061, Hi: 1068, Stride: 7},
+ {Lo: 1072, Hi: 1073, Stride: 1},
+ {Lo: 1075, Hi: 1077, Stride: 2},
+ {Lo: 1086, Hi: 1088, Stride: 2},
+ {Lo: 1089, Hi: 1093, Stride: 2},
+ {Lo: 8211, Hi: 8216, Stride: 5},
+ {Lo: 8217, Hi: 8245, Stride: 28},
+ {Lo: 12494, Hi: 65281, Stride: 52787},
+ {Lo: 65283, Hi: 65288, Stride: 5},
+ {Lo: 65289, Hi: 65292, Stride: 3},
+ {Lo: 65306, Hi: 65307, Stride: 1},
+ {Lo: 65311, Hi: 65374, Stride: 63},
+ },
+ R32: []unicode.Range32{},
+ LatinOffset: 1,
},
- R32: []unicode.Range32{},
- LatinOffset: 1,
},
- },
- "ru": {
- Confusable: []rune{180, 215, 305, 921, 1009, 8216, 8217, 8245, 12494, 65281, 65283, 65288, 65289, 65292, 65306, 65307, 65311, 65374},
- With: []rune{96, 120, 105, 73, 112, 96, 96, 96, 47, 33, 35, 40, 41, 44, 58, 59, 63, 126},
- Locale: "ru",
- RangeTable: &unicode.RangeTable{
- R16: []unicode.Range16{
- {Lo: 180, Hi: 215, Stride: 35},
- {Lo: 305, Hi: 921, Stride: 616},
- {Lo: 1009, Hi: 8216, Stride: 7207},
- {Lo: 8217, Hi: 8245, Stride: 28},
- {Lo: 12494, Hi: 65281, Stride: 52787},
- {Lo: 65283, Hi: 65288, Stride: 5},
- {Lo: 65289, Hi: 65292, Stride: 3},
- {Lo: 65306, Hi: 65307, Stride: 1},
- {Lo: 65311, Hi: 65374, Stride: 63},
+
+ "ru": {
+ Confusable: []rune{180, 215, 305, 921, 1009, 8216, 8217, 8245, 12494, 65281, 65283, 65288, 65289, 65292, 65306, 65307, 65311, 65374},
+ With: []rune{96, 120, 105, 73, 112, 96, 96, 96, 47, 33, 35, 40, 41, 44, 58, 59, 63, 126},
+ Locale: "ru",
+ RangeTable: &unicode.RangeTable{
+ R16: []unicode.Range16{
+ {Lo: 180, Hi: 215, Stride: 35},
+ {Lo: 305, Hi: 921, Stride: 616},
+ {Lo: 1009, Hi: 8216, Stride: 7207},
+ {Lo: 8217, Hi: 8245, Stride: 28},
+ {Lo: 12494, Hi: 65281, Stride: 52787},
+ {Lo: 65283, Hi: 65288, Stride: 5},
+ {Lo: 65289, Hi: 65292, Stride: 3},
+ {Lo: 65306, Hi: 65307, Stride: 1},
+ {Lo: 65311, Hi: 65374, Stride: 63},
+ },
+ R32: []unicode.Range32{},
+ LatinOffset: 1,
},
- R32: []unicode.Range32{},
- LatinOffset: 1,
},
- },
- "tr": {
- Confusable: []rune{160, 180, 215, 921, 1009, 1040, 1042, 1045, 1047, 1050, 1052, 1053, 1054, 1056, 1057, 1058, 1059, 1061, 1068, 1072, 1073, 1075, 1077, 1086, 1088, 1089, 1091, 1093, 8211, 8245, 12494, 65281, 65283, 65288, 65289, 65292, 65306, 65307, 65311, 65374},
- With: []rune{32, 96, 120, 73, 112, 65, 66, 69, 51, 75, 77, 72, 79, 80, 67, 84, 89, 88, 98, 97, 54, 114, 101, 111, 112, 99, 121, 120, 45, 96, 47, 33, 35, 40, 41, 44, 58, 59, 63, 126},
- Locale: "tr",
- RangeTable: &unicode.RangeTable{
- R16: []unicode.Range16{
- {Lo: 160, Hi: 180, Stride: 20},
- {Lo: 215, Hi: 921, Stride: 706},
- {Lo: 1009, Hi: 1040, Stride: 31},
- {Lo: 1042, Hi: 1045, Stride: 3},
- {Lo: 1047, Hi: 1050, Stride: 3},
- {Lo: 1052, Hi: 1054, Stride: 1},
- {Lo: 1056, Hi: 1059, Stride: 1},
- {Lo: 1061, Hi: 1068, Stride: 7},
- {Lo: 1072, Hi: 1073, Stride: 1},
- {Lo: 1075, Hi: 1077, Stride: 2},
- {Lo: 1086, Hi: 1088, Stride: 2},
- {Lo: 1089, Hi: 1093, Stride: 2},
- {Lo: 8211, Hi: 8245, Stride: 34},
- {Lo: 12494, Hi: 65281, Stride: 52787},
- {Lo: 65283, Hi: 65288, Stride: 5},
- {Lo: 65289, Hi: 65292, Stride: 3},
- {Lo: 65306, Hi: 65307, Stride: 1},
- {Lo: 65311, Hi: 65374, Stride: 63},
+
+ "tr": {
+ Confusable: []rune{160, 180, 215, 921, 1009, 1040, 1042, 1045, 1047, 1050, 1052, 1053, 1054, 1056, 1057, 1058, 1059, 1061, 1068, 1072, 1073, 1075, 1077, 1086, 1088, 1089, 1091, 1093, 8211, 8245, 12494, 65281, 65283, 65288, 65289, 65292, 65306, 65307, 65311, 65374},
+ With: []rune{32, 96, 120, 73, 112, 65, 66, 69, 51, 75, 77, 72, 79, 80, 67, 84, 89, 88, 98, 97, 54, 114, 101, 111, 112, 99, 121, 120, 45, 96, 47, 33, 35, 40, 41, 44, 58, 59, 63, 126},
+ Locale: "tr",
+ RangeTable: &unicode.RangeTable{
+ R16: []unicode.Range16{
+ {Lo: 160, Hi: 180, Stride: 20},
+ {Lo: 215, Hi: 921, Stride: 706},
+ {Lo: 1009, Hi: 1040, Stride: 31},
+ {Lo: 1042, Hi: 1045, Stride: 3},
+ {Lo: 1047, Hi: 1050, Stride: 3},
+ {Lo: 1052, Hi: 1054, Stride: 1},
+ {Lo: 1056, Hi: 1059, Stride: 1},
+ {Lo: 1061, Hi: 1068, Stride: 7},
+ {Lo: 1072, Hi: 1073, Stride: 1},
+ {Lo: 1075, Hi: 1077, Stride: 2},
+ {Lo: 1086, Hi: 1088, Stride: 2},
+ {Lo: 1089, Hi: 1093, Stride: 2},
+ {Lo: 8211, Hi: 8245, Stride: 34},
+ {Lo: 12494, Hi: 65281, Stride: 52787},
+ {Lo: 65283, Hi: 65288, Stride: 5},
+ {Lo: 65289, Hi: 65292, Stride: 3},
+ {Lo: 65306, Hi: 65307, Stride: 1},
+ {Lo: 65311, Hi: 65374, Stride: 63},
+ },
+ R32: []unicode.Range32{},
+ LatinOffset: 1,
},
- R32: []unicode.Range32{},
- LatinOffset: 1,
},
- },
- "zh-hans": {
- Confusable: []rune{180, 215, 305, 921, 1009, 1040, 1042, 1045, 1047, 1050, 1052, 1053, 1054, 1056, 1057, 1058, 1059, 1061, 1068, 1072, 1073, 1075, 1077, 1086, 1088, 1089, 1091, 1093, 8245, 12494, 65281, 65288, 65289, 65306, 65374},
- With: []rune{96, 120, 105, 73, 112, 65, 66, 69, 51, 75, 77, 72, 79, 80, 67, 84, 89, 88, 98, 97, 54, 114, 101, 111, 112, 99, 121, 120, 96, 47, 33, 40, 41, 58, 126},
- Locale: "zh-hans",
- RangeTable: &unicode.RangeTable{
- R16: []unicode.Range16{
- {Lo: 180, Hi: 215, Stride: 35},
- {Lo: 305, Hi: 921, Stride: 616},
- {Lo: 1009, Hi: 1040, Stride: 31},
- {Lo: 1042, Hi: 1045, Stride: 3},
- {Lo: 1047, Hi: 1050, Stride: 3},
- {Lo: 1052, Hi: 1054, Stride: 1},
- {Lo: 1056, Hi: 1059, Stride: 1},
- {Lo: 1061, Hi: 1068, Stride: 7},
- {Lo: 1072, Hi: 1073, Stride: 1},
- {Lo: 1075, Hi: 1077, Stride: 2},
- {Lo: 1086, Hi: 1088, Stride: 2},
- {Lo: 1089, Hi: 1093, Stride: 2},
- {Lo: 8245, Hi: 12494, Stride: 4249},
- {Lo: 65281, Hi: 65288, Stride: 7},
- {Lo: 65289, Hi: 65306, Stride: 17},
- {Lo: 65374, Hi: 65374, Stride: 1},
+
+ "zh-hans": {
+ Confusable: []rune{180, 215, 305, 921, 1009, 1040, 1042, 1045, 1047, 1050, 1052, 1053, 1054, 1056, 1057, 1058, 1059, 1061, 1068, 1072, 1073, 1075, 1077, 1086, 1088, 1089, 1091, 1093, 8245, 12494, 65281, 65288, 65289, 65306, 65374},
+ With: []rune{96, 120, 105, 73, 112, 65, 66, 69, 51, 75, 77, 72, 79, 80, 67, 84, 89, 88, 98, 97, 54, 114, 101, 111, 112, 99, 121, 120, 96, 47, 33, 40, 41, 58, 126},
+ Locale: "zh-hans",
+ RangeTable: &unicode.RangeTable{
+ R16: []unicode.Range16{
+ {Lo: 180, Hi: 215, Stride: 35},
+ {Lo: 305, Hi: 921, Stride: 616},
+ {Lo: 1009, Hi: 1040, Stride: 31},
+ {Lo: 1042, Hi: 1045, Stride: 3},
+ {Lo: 1047, Hi: 1050, Stride: 3},
+ {Lo: 1052, Hi: 1054, Stride: 1},
+ {Lo: 1056, Hi: 1059, Stride: 1},
+ {Lo: 1061, Hi: 1068, Stride: 7},
+ {Lo: 1072, Hi: 1073, Stride: 1},
+ {Lo: 1075, Hi: 1077, Stride: 2},
+ {Lo: 1086, Hi: 1088, Stride: 2},
+ {Lo: 1089, Hi: 1093, Stride: 2},
+ {Lo: 8245, Hi: 12494, Stride: 4249},
+ {Lo: 65281, Hi: 65288, Stride: 7},
+ {Lo: 65289, Hi: 65306, Stride: 17},
+ {Lo: 65374, Hi: 65374, Stride: 1},
+ },
+ R32: []unicode.Range32{},
+ LatinOffset: 1,
},
- R32: []unicode.Range32{},
- LatinOffset: 1,
},
- },
- "zh-hant": {
- Confusable: []rune{180, 215, 305, 921, 1009, 1040, 1042, 1045, 1047, 1050, 1052, 1053, 1054, 1056, 1057, 1058, 1059, 1061, 1068, 1072, 1073, 1075, 1077, 1086, 1088, 1089, 1091, 1093, 8211, 12494, 65283, 65307, 65374},
- With: []rune{96, 120, 105, 73, 112, 65, 66, 69, 51, 75, 77, 72, 79, 80, 67, 84, 89, 88, 98, 97, 54, 114, 101, 111, 112, 99, 121, 120, 45, 47, 35, 59, 126},
- Locale: "zh-hant",
- RangeTable: &unicode.RangeTable{
- R16: []unicode.Range16{
- {Lo: 180, Hi: 215, Stride: 35},
- {Lo: 305, Hi: 921, Stride: 616},
- {Lo: 1009, Hi: 1040, Stride: 31},
- {Lo: 1042, Hi: 1045, Stride: 3},
- {Lo: 1047, Hi: 1050, Stride: 3},
- {Lo: 1052, Hi: 1054, Stride: 1},
- {Lo: 1056, Hi: 1059, Stride: 1},
- {Lo: 1061, Hi: 1068, Stride: 7},
- {Lo: 1072, Hi: 1073, Stride: 1},
- {Lo: 1075, Hi: 1077, Stride: 2},
- {Lo: 1086, Hi: 1088, Stride: 2},
- {Lo: 1089, Hi: 1093, Stride: 2},
- {Lo: 8211, Hi: 12494, Stride: 4283},
- {Lo: 65283, Hi: 65307, Stride: 24},
- {Lo: 65374, Hi: 65374, Stride: 1},
+
+ "zh-hant": {
+ Confusable: []rune{180, 215, 305, 921, 1009, 1040, 1042, 1045, 1047, 1050, 1052, 1053, 1054, 1056, 1057, 1058, 1059, 1061, 1068, 1072, 1073, 1075, 1077, 1086, 1088, 1089, 1091, 1093, 8211, 12494, 65283, 65307, 65374},
+ With: []rune{96, 120, 105, 73, 112, 65, 66, 69, 51, 75, 77, 72, 79, 80, 67, 84, 89, 88, 98, 97, 54, 114, 101, 111, 112, 99, 121, 120, 45, 47, 35, 59, 126},
+ Locale: "zh-hant",
+ RangeTable: &unicode.RangeTable{
+ R16: []unicode.Range16{
+ {Lo: 180, Hi: 215, Stride: 35},
+ {Lo: 305, Hi: 921, Stride: 616},
+ {Lo: 1009, Hi: 1040, Stride: 31},
+ {Lo: 1042, Hi: 1045, Stride: 3},
+ {Lo: 1047, Hi: 1050, Stride: 3},
+ {Lo: 1052, Hi: 1054, Stride: 1},
+ {Lo: 1056, Hi: 1059, Stride: 1},
+ {Lo: 1061, Hi: 1068, Stride: 7},
+ {Lo: 1072, Hi: 1073, Stride: 1},
+ {Lo: 1075, Hi: 1077, Stride: 2},
+ {Lo: 1086, Hi: 1088, Stride: 2},
+ {Lo: 1089, Hi: 1093, Stride: 2},
+ {Lo: 8211, Hi: 12494, Stride: 4283},
+ {Lo: 65283, Hi: 65307, Stride: 24},
+ {Lo: 65374, Hi: 65374, Stride: 1},
+ },
+ R32: []unicode.Range32{},
+ LatinOffset: 1,
},
- R32: []unicode.Range32{},
- LatinOffset: 1,
},
- },
+ }
}
diff --git a/modules/charset/ambiguous_gen_test.go b/modules/charset/ambiguous_gen_test.go
index d3be0b1a13..81d2e8065b 100644
--- a/modules/charset/ambiguous_gen_test.go
+++ b/modules/charset/ambiguous_gen_test.go
@@ -8,11 +8,13 @@ import (
"testing"
"unicode"
+ "code.gitea.io/gitea/modules/translation"
+
"github.com/stretchr/testify/assert"
)
func TestAmbiguousCharacters(t *testing.T) {
- for locale, ambiguous := range AmbiguousCharacters {
+ for locale, ambiguous := range globalVars().ambiguousTableMap {
assert.Equal(t, locale, ambiguous.Locale)
assert.Len(t, ambiguous.With, len(ambiguous.Confusable))
assert.True(t, sort.SliceIsSorted(ambiguous.Confusable, func(i, j int) bool {
@@ -28,4 +30,8 @@ func TestAmbiguousCharacters(t *testing.T) {
assert.True(t, found, "%c is not in %d", confusable, i)
}
}
+
+ var confusableTo rune
+ ret := isAmbiguous('𝐾', &confusableTo, AmbiguousTablesForLocale(&translation.MockLocale{})...)
+ assert.True(t, ret)
}
diff --git a/modules/charset/breakwriter.go b/modules/charset/breakwriter.go
deleted file mode 100644
index a87e846466..0000000000
--- a/modules/charset/breakwriter.go
+++ /dev/null
@@ -1,43 +0,0 @@
-// Copyright 2022 The Gitea Authors. All rights reserved.
-// SPDX-License-Identifier: MIT
-
-package charset
-
-import (
- "bytes"
- "io"
-)
-
-// BreakWriter wraps an io.Writer to always write '\n' as ' '
-type BreakWriter struct {
- io.Writer
-}
-
-// Write writes the provided byte slice transparently replacing '\n' with ' '
-func (b *BreakWriter) Write(bs []byte) (n int, err error) {
- pos := 0
- for pos < len(bs) {
- idx := bytes.IndexByte(bs[pos:], '\n')
- if idx < 0 {
- wn, err := b.Writer.Write(bs[pos:])
- return n + wn, err
- }
-
- if idx > 0 {
- wn, err := b.Writer.Write(bs[pos : pos+idx])
- n += wn
- if err != nil {
- return n, err
- }
- }
-
- if _, err = b.Writer.Write([]byte(" ")); err != nil {
- return n, err
- }
- pos += idx + 1
-
- n++
- }
-
- return n, err
-}
diff --git a/modules/charset/breakwriter_test.go b/modules/charset/breakwriter_test.go
deleted file mode 100644
index 5eeeedc4e2..0000000000
--- a/modules/charset/breakwriter_test.go
+++ /dev/null
@@ -1,68 +0,0 @@
-// Copyright 2022 The Gitea Authors. All rights reserved.
-// SPDX-License-Identifier: MIT
-
-package charset
-
-import (
- "strings"
- "testing"
-)
-
-func TestBreakWriter_Write(t *testing.T) {
- tests := []struct {
- name string
- kase string
- expect string
- wantErr bool
- }{
- {
- name: "noline",
- kase: "abcdefghijklmnopqrstuvwxyz",
- expect: "abcdefghijklmnopqrstuvwxyz",
- },
- {
- name: "endline",
- kase: "abcdefghijklmnopqrstuvwxyz\n",
- expect: "abcdefghijklmnopqrstuvwxyz ",
- },
- {
- name: "startline",
- kase: "\nabcdefghijklmnopqrstuvwxyz",
- expect: " abcdefghijklmnopqrstuvwxyz",
- },
- {
- name: "onlyline",
- kase: "\n\n\n",
- expect: " ",
- },
- {
- name: "empty",
- kase: "",
- expect: "",
- },
- {
- name: "midline",
- kase: "\nabc\ndefghijkl\nmnopqrstuvwxy\nz",
- expect: " abc defghijkl mnopqrstuvwxy z",
- },
- }
- for _, tt := range tests {
- t.Run(tt.name, func(t *testing.T) {
- buf := &strings.Builder{}
- b := &BreakWriter{
- Writer: buf,
- }
- n, err := b.Write([]byte(tt.kase))
- if (err != nil) != tt.wantErr {
- t.Errorf("BreakWriter.Write() error = %v, wantErr %v", err, tt.wantErr)
- return
- }
- if n != len(tt.kase) {
- t.Errorf("BreakWriter.Write() = %v, want %v", n, len(tt.kase))
- }
- if buf.String() != tt.expect {
- t.Errorf("BreakWriter.Write() wrote %q, want %v", buf.String(), tt.expect)
- }
- })
- }
-}
diff --git a/modules/charset/escape.go b/modules/charset/escape.go
index 92e417d1f7..8f25e7876d 100644
--- a/modules/charset/escape.go
+++ b/modules/charset/escape.go
@@ -1,10 +1,6 @@
// Copyright 2022 The Gitea Authors. All rights reserved.
// SPDX-License-Identifier: MIT
-//go:generate go run invisible/generate.go -v -o ./invisible_gen.go
-
-//go:generate go run ambiguous/generate.go -v -o ./ambiguous_gen.go ambiguous/ambiguous.json
-
package charset
import (
@@ -12,33 +8,36 @@ import (
"io"
"strings"
- "code.gitea.io/gitea/modules/log"
"code.gitea.io/gitea/modules/setting"
"code.gitea.io/gitea/modules/translation"
)
-// RuneNBSP is the codepoint for NBSP
-const RuneNBSP = 0xa0
+type EscapeOptions struct {
+ Allowed map[rune]bool
+}
-// EscapeControlHTML escapes the unicode control sequences in a provided html document
-func EscapeControlHTML(html template.HTML, locale translation.Locale, allowed ...rune) (escaped *EscapeStatus, output template.HTML) {
- sb := &strings.Builder{}
- escaped, _ = EscapeControlReader(strings.NewReader(string(html)), sb, locale, allowed...) // err has been handled in EscapeControlReader
- return escaped, template.HTML(sb.String())
+func AllowRuneNBSP() map[rune]bool {
+ return map[rune]bool{0xa0: true}
}
-// EscapeControlReader escapes the unicode control sequences in a provided reader of HTML content and writer in a locale and returns the findings as an EscapeStatus
-func EscapeControlReader(reader io.Reader, writer io.Writer, locale translation.Locale, allowed ...rune) (escaped *EscapeStatus, err error) {
- if !setting.UI.AmbiguousUnicodeDetection {
- _, err = io.Copy(writer, reader)
- return &EscapeStatus{}, err
+func EscapeOptionsForView() EscapeOptions {
+ return EscapeOptions{
+ // it's safe to see NBSP in the view, but maybe not in the diff
+ Allowed: AllowRuneNBSP(),
}
- outputStream := &HTMLStreamerWriter{Writer: writer}
- streamer := NewEscapeStreamer(locale, outputStream, allowed...).(*escapeStreamer)
+}
- if err = StreamHTML(reader, streamer); err != nil {
- streamer.escaped.HasError = true
- log.Error("Error whilst escaping: %v", err)
+// EscapeControlHTML escapes the Unicode control sequences in a provided html document
+func EscapeControlHTML(html template.HTML, locale translation.Locale, opts ...EscapeOptions) (escaped *EscapeStatus, output template.HTML) {
+ if !setting.UI.AmbiguousUnicodeDetection {
+ return &EscapeStatus{}, html
}
- return streamer.escaped, err
+ sb := &strings.Builder{}
+ escaped, _ = EscapeControlReader(strings.NewReader(string(html)), sb, locale, opts...) // err has been handled in EscapeControlReader
+ return escaped, template.HTML(sb.String())
+}
+
+// EscapeControlReader escapes the Unicode control sequences in a provided reader of HTML content and writer in a locale and returns the findings as an EscapeStatus
+func EscapeControlReader(reader io.Reader, writer io.Writer, locale translation.Locale, opts ...EscapeOptions) (*EscapeStatus, error) {
+ return escapeStream(locale, reader, writer, opts...)
}
diff --git a/modules/charset/escape_status.go b/modules/charset/escape_status.go
index 37b6ad86d4..fb9ebbb228 100644
--- a/modules/charset/escape_status.go
+++ b/modules/charset/escape_status.go
@@ -3,11 +3,9 @@
package charset
-// EscapeStatus represents the findings of the unicode escaper
+// EscapeStatus represents the findings of the Unicode escaper
type EscapeStatus struct {
- Escaped bool
- HasError bool
- HasBadRunes bool
+ Escaped bool // it means that some characters were escaped, and they can also be unescaped back
HasInvisible bool
HasAmbiguous bool
}
@@ -19,8 +17,6 @@ func (status *EscapeStatus) Or(other *EscapeStatus) *EscapeStatus {
st = &EscapeStatus{}
}
st.Escaped = st.Escaped || other.Escaped
- st.HasError = st.HasError || other.HasError
- st.HasBadRunes = st.HasBadRunes || other.HasBadRunes
st.HasAmbiguous = st.HasAmbiguous || other.HasAmbiguous
st.HasInvisible = st.HasInvisible || other.HasInvisible
return st
diff --git a/modules/charset/escape_stream.go b/modules/charset/escape_stream.go
index 29943eb858..11d09083fc 100644
--- a/modules/charset/escape_stream.go
+++ b/modules/charset/escape_stream.go
@@ -4,286 +4,415 @@
package charset
import (
+ "bytes"
"fmt"
- "regexp"
- "strings"
+ "html"
+ "io"
"unicode"
"unicode/utf8"
+ "code.gitea.io/gitea/modules/setting"
"code.gitea.io/gitea/modules/translation"
-
- "golang.org/x/net/html"
)
-// VScode defaultWordRegexp
-var defaultWordRegexp = regexp.MustCompile(`(-?\d*\.\d\w*)|([^\` + "`" + `\~\!\@\#\$\%\^\&\*\(\)\-\=\+\[\{\]\}\\\|\;\:\'\"\,\.\<\>\/\?\s\x00-\x1f]+)`)
-
-func NewEscapeStreamer(locale translation.Locale, next HTMLStreamer, allowed ...rune) HTMLStreamer {
- allowedM := make(map[rune]bool, len(allowed))
- for _, v := range allowed {
- allowedM[v] = true
- }
- return &escapeStreamer{
- escaped: &EscapeStatus{},
- PassthroughHTMLStreamer: *NewPassthroughStreamer(next),
- locale: locale,
- ambiguousTables: AmbiguousTablesForLocale(locale),
- allowed: allowedM,
- }
+type htmlChunkReader struct {
+ in io.Reader
+ readErr error
+ readBuf []byte
+ curInTag bool
}
type escapeStreamer struct {
- PassthroughHTMLStreamer
+ htmlChunkReader
+
escaped *EscapeStatus
locale translation.Locale
ambiguousTables []*AmbiguousTable
allowed map[rune]bool
+
+ out io.Writer
}
-func (e *escapeStreamer) EscapeStatus() *EscapeStatus {
- return e.escaped
+func escapeStream(locale translation.Locale, in io.Reader, out io.Writer, opts ...EscapeOptions) (*EscapeStatus, error) {
+ es := &escapeStreamer{
+ escaped: &EscapeStatus{},
+ locale: locale,
+ ambiguousTables: AmbiguousTablesForLocale(locale),
+ htmlChunkReader: htmlChunkReader{
+ in: in,
+ readBuf: make([]byte, 0, 32*1024),
+ },
+ out: out,
+ }
+
+ if len(opts) > 0 {
+ es.allowed = opts[0].Allowed
+ }
+
+ readCount := 0
+ lastIsTag := false
+ for {
+ parts, partInTag, err := es.readRunes()
+ readCount++
+ if err == io.EOF {
+ return es.escaped, nil
+ } else if err != nil {
+ return nil, err
+ }
+ for i, part := range parts {
+ if partInTag[i] {
+ lastIsTag = true
+ if _, err := out.Write(part); err != nil {
+ return nil, err
+ }
+ } else {
+ // if last part is tag, then this part is content begin
+ // if the content is the first part of the first read, then it's also content begin
+ isContentBegin := lastIsTag || (readCount == 1 && i == 0)
+ lastIsTag = false
+ if isContentBegin {
+ if part, err = es.trimAndWriteBom(part); err != nil {
+ return nil, err
+ }
+ }
+ if err = es.detectAndWriteRunes(part); err != nil {
+ return nil, err
+ }
+ }
+ }
+ }
}
-// Text tells the next streamer there is a text
-func (e *escapeStreamer) Text(data string) error {
- sb := &strings.Builder{}
- var until int
- var next int
- pos := 0
- if len(data) > len(UTF8BOM) && data[:len(UTF8BOM)] == string(UTF8BOM) {
- _, _ = sb.WriteString(data[:len(UTF8BOM)])
- pos = len(UTF8BOM)
+func (e *escapeStreamer) trimAndWriteBom(part []byte) ([]byte, error) {
+ remaining, ok := bytes.CutPrefix(part, globalVars().utf8Bom)
+ if ok {
+ part = remaining
+ if _, err := e.out.Write(globalVars().utf8Bom); err != nil {
+ return part, err
+ }
}
- dataBytes := []byte(data)
- for pos < len(data) {
- nextIdxs := defaultWordRegexp.FindStringIndex(data[pos:])
- if nextIdxs == nil {
- until = len(data)
- next = until
- } else {
- until, next = nextIdxs[0]+pos, nextIdxs[1]+pos
+ return part, nil
+}
+
+const longSentenceDetectionLimit = 20
+
+func (e *escapeStreamer) possibleLongSentence(results []detectResult, pos int) bool {
+ countBasic := 0
+ countNonASCII := 0
+ for i := max(pos-longSentenceDetectionLimit, 0); i < min(pos+longSentenceDetectionLimit, len(results)); i++ {
+ if results[i].runeType == runeTypeBasic && results[i].runeChar != ' ' {
+ countBasic++
+ }
+ if results[i].runeType == runeTypeNonASCII || results[i].runeType == runeTypeAmbiguous {
+ countNonASCII++
}
+ }
+ countChar := countBasic + countNonASCII
+ // many non-ASCII runes around, it seems to be a sentence,
+ // don't handle the invisible/ambiguous chars in it, otherwise it will be too noisy
+ return countChar != 0 && countNonASCII*100/countChar >= 50
+}
- // from pos until we know that the runes are not \r\t\n or even ' '
- runes := make([]rune, 0, next-until)
- positions := make([]int, 0, next-until+1)
+func (e *escapeStreamer) analyzeDetectResults(results []detectResult) {
+ for i := range results {
+ res := &results[i]
+ if res.runeType == runeTypeInvisible || res.runeType == runeTypeAmbiguous {
+ leftIsNonASCII := i > 0 && (results[i-1].runeType == runeTypeNonASCII || results[i-1].runeType == runeTypeAmbiguous)
+ rightIsNonASCII := i < len(results)-1 && (results[i+1].runeType == runeTypeNonASCII || results[i+1].runeType == runeTypeAmbiguous)
+ surroundingNonASCII := leftIsNonASCII || rightIsNonASCII
+ if !surroundingNonASCII {
+ if len(results) < longSentenceDetectionLimit {
+ res.needEscape = setting.UI.AmbiguousUnicodeDetection
+ } else if !e.possibleLongSentence(results, i) {
+ res.needEscape = setting.UI.AmbiguousUnicodeDetection
+ }
+ }
+ }
+ }
+}
- for pos < until {
- r, sz := utf8.DecodeRune(dataBytes[pos:])
- positions = positions[:0]
- positions = append(positions, pos, pos+sz)
- types, confusables, _ := e.runeTypes(r)
- if err := e.handleRunes(dataBytes, []rune{r}, positions, types, confusables, sb); err != nil {
- return err
+func (e *escapeStreamer) detectAndWriteRunes(part []byte) error {
+ results := e.detectRunes(part)
+ e.analyzeDetectResults(results)
+ return e.writeDetectResults(part, results)
+}
+
+func (e *htmlChunkReader) readRunes() (parts [][]byte, partInTag []bool, _ error) {
+ // we have read everything, eof
+ if e.readErr != nil && len(e.readBuf) == 0 {
+ return nil, nil, e.readErr
+ }
+
+ // not eof, and the there is space in the buffer, try to read more data
+ if e.readErr == nil && len(e.readBuf) <= cap(e.readBuf)*3/4 {
+ n, err := e.in.Read(e.readBuf[len(e.readBuf):cap(e.readBuf)])
+ e.readErr = err
+ e.readBuf = e.readBuf[:len(e.readBuf)+n]
+ }
+ if len(e.readBuf) == 0 {
+ return nil, nil, e.readErr
+ }
+
+ // try to exact tag parts and content parts
+ pos := 0
+ for pos < len(e.readBuf) {
+ var curPartEnd int
+ nextInTag := e.curInTag
+ if e.curInTag {
+ // if cur part is in tag, try to find the tag close char '>'
+ idx := bytes.IndexByte(e.readBuf[pos:], '>')
+ if idx == -1 {
+ // if no tag close char, then the whole buffer is in tag
+ curPartEnd = len(e.readBuf)
+ } else {
+ // tag part ends, switch to content part
+ curPartEnd = pos + idx + 1
+ nextInTag = !nextInTag
+ }
+ } else {
+ // if cur part is in content, try to find the tag open char '<'
+ idx := bytes.IndexByte(e.readBuf[pos:], '<')
+ if idx == -1 {
+ // if no tag open char, then the whole buffer is in content
+ curPartEnd = len(e.readBuf)
+ } else {
+ // content part ends, switch to tag part
+ curPartEnd = pos + idx
+ nextInTag = !nextInTag
}
- pos += sz
}
- for i := pos; i < next; {
- r, sz := utf8.DecodeRune(dataBytes[i:])
- runes = append(runes, r)
- positions = append(positions, i)
- i += sz
+ curPartLen := curPartEnd - pos
+ if curPartLen == 0 {
+ // if cur part is empty, only need to switch the part type
+ if e.curInTag == nextInTag {
+ panic("impossible, curPartLen is 0 but the part in tag status is not switched")
+ }
+ e.curInTag = nextInTag
+ continue
}
- positions = append(positions, next)
- types, confusables, runeCounts := e.runeTypes(runes...)
- if runeCounts.needsEscape() {
- if err := e.handleRunes(dataBytes, runes, positions, types, confusables, sb); err != nil {
- return err
+
+ // now, curPartLen can't be 0
+ curPart := make([]byte, curPartLen)
+ copy(curPart, e.readBuf[pos:curPartEnd])
+ // now we get the curPart bytes, but we can't directly use it, the last rune in it might have been cut
+ // try to decode the last rune, if it's invalid, then we cut the last byte and try again until we get a valid rune or no byte left
+ for i := curPartLen - 1; i >= 0; i-- {
+ last, lastSize := utf8.DecodeRune(curPart[i:])
+ if last == utf8.RuneError && lastSize == 1 {
+ curPartLen--
+ } else {
+ curPartLen += lastSize - 1
+ break
}
- } else {
- _, _ = sb.Write(dataBytes[pos:next])
}
- pos = next
- }
- if sb.Len() > 0 {
- if err := e.PassthroughHTMLStreamer.Text(sb.String()); err != nil {
- return err
+ if curPartLen == 0 {
+ // actually it's impossible that the part doesn't contain any valid rune,
+ // the only case is that the cap(readBuf) is too small, or the origin contain indeed doesn't contain any valid rune
+ // * try to leave the last 4 bytes (possible longest utf-8 encoding) to next round
+ // * at least consume 1 byte to avoid infinite loop
+ curPartLen = max(len(curPart)-utf8.UTFMax, 1)
+ }
+
+ // if curPartLen is not the same as curPart, it means we have cut some bytes,
+ // need to wait for more data if not eof
+ trailingCorrupted := curPartLen != len(curPart)
+
+ // finally, we get the real part we need
+ curPart = curPart[:curPartLen]
+ parts = append(parts, curPart)
+ partInTag = append(partInTag, e.curInTag)
+
+ pos += curPartLen
+ e.curInTag = nextInTag
+
+ if trailingCorrupted && e.readErr == nil {
+ // if the last part is corrupted, and we haven't reach eof, then we need to wait for more data to get the complete part
+ break
}
}
- return nil
+
+ copy(e.readBuf, e.readBuf[pos:])
+ e.readBuf = e.readBuf[:len(e.readBuf)-pos]
+ return parts, partInTag, nil
}
-func (e *escapeStreamer) handleRunes(data []byte, runes []rune, positions []int, types []runeType, confusables []rune, sb *strings.Builder) error {
- for i, r := range runes {
- switch types[i] {
- case brokenRuneType:
- if sb.Len() > 0 {
- if err := e.PassthroughHTMLStreamer.Text(sb.String()); err != nil {
- return err
- }
- sb.Reset()
+func (e *escapeStreamer) writeDetectResults(data []byte, results []detectResult) error {
+ lastWriteRawIdx := -1
+ for idx := range results {
+ res := &results[idx]
+ if !res.needEscape {
+ if lastWriteRawIdx == -1 {
+ lastWriteRawIdx = idx
}
- end := positions[i+1]
- start := positions[i]
- if err := e.brokenRune(data[start:end]); err != nil {
+ continue
+ }
+
+ if lastWriteRawIdx != -1 {
+ if _, err := e.out.Write(data[results[lastWriteRawIdx].position:res.position]); err != nil {
return err
}
- case ambiguousRuneType:
- if sb.Len() > 0 {
- if err := e.PassthroughHTMLStreamer.Text(sb.String()); err != nil {
- return err
- }
- sb.Reset()
+ lastWriteRawIdx = -1
+ }
+ switch res.runeType {
+ case runeTypeBroken:
+ if err := e.writeBrokenRune(data[res.position : res.position+res.runeSize]); err != nil {
+ return err
}
- if err := e.ambiguousRune(r, confusables[0]); err != nil {
+ case runeTypeAmbiguous:
+ if err := e.writeAmbiguousRune(res.runeChar, res.confusable); err != nil {
return err
}
- confusables = confusables[1:]
- case invisibleRuneType:
- if sb.Len() > 0 {
- if err := e.PassthroughHTMLStreamer.Text(sb.String()); err != nil {
- return err
- }
- sb.Reset()
+ case runeTypeInvisible:
+ if err := e.writeInvisibleRune(res.runeChar); err != nil {
+ return err
}
- if err := e.invisibleRune(r); err != nil {
+ case runeTypeControlChar:
+ if err := e.writeControlRune(res.runeChar); err != nil {
return err
}
default:
- _, _ = sb.WriteRune(r)
+ panic("unreachable")
+ }
+ }
+ if lastWriteRawIdx != -1 {
+ lastResult := results[len(results)-1]
+ if _, err := e.out.Write(data[results[lastWriteRawIdx].position : lastResult.position+lastResult.runeSize]); err != nil {
+ return err
}
}
return nil
}
-func (e *escapeStreamer) brokenRune(bs []byte) error {
- e.escaped.Escaped = true
- e.escaped.HasBadRunes = true
-
- if err := e.PassthroughHTMLStreamer.StartTag("span", html.Attribute{
- Key: "class",
- Val: "broken-code-point",
- }); err != nil {
- return err
- }
- if err := e.PassthroughHTMLStreamer.Text(fmt.Sprintf("<%X>", bs)); err != nil {
- return err
- }
-
- return e.PassthroughHTMLStreamer.EndTag("span")
+func (e *escapeStreamer) writeBrokenRune(_ []byte) (err error) {
+ // Although we'd like to use the original bytes to display (show the real broken content to users),
+ // however, when this "escape stream" module is applied to the content, the content has already been processed by other modules.
+ // So the invalid bytes just can't be kept till this step, in most (all) cases, the only thing we see here is utf8.RuneError
+ _, err = io.WriteString(e.out, `� `)
+ return err
}
-func (e *escapeStreamer) ambiguousRune(r, c rune) error {
- e.escaped.Escaped = true
- e.escaped.HasAmbiguous = true
-
- if err := e.PassthroughHTMLStreamer.StartTag("span", html.Attribute{
- Key: "class",
- Val: "ambiguous-code-point",
- }, html.Attribute{
- Key: "data-tooltip-content",
- Val: e.locale.TrString("repo.ambiguous_character", r, c),
- }); err != nil {
+func (e *escapeStreamer) writeEscapedCharHTML(tag1, attr, tag2, content, tag3 string) (err error) {
+ _, err = io.WriteString(e.out, tag1)
+ if err != nil {
return err
}
- if err := e.PassthroughHTMLStreamer.StartTag("span", html.Attribute{
- Key: "class",
- Val: "char",
- }); err != nil {
+ _, err = io.WriteString(e.out, html.EscapeString(attr))
+ if err != nil {
return err
}
- if err := e.PassthroughHTMLStreamer.Text(string(r)); err != nil {
+ _, err = io.WriteString(e.out, tag2)
+ if err != nil {
return err
}
- if err := e.PassthroughHTMLStreamer.EndTag("span"); err != nil {
+ _, err = io.WriteString(e.out, html.EscapeString(content))
+ if err != nil {
return err
}
+ _, err = io.WriteString(e.out, tag3)
+ return err
+}
- return e.PassthroughHTMLStreamer.EndTag("span")
+func runeToHex(r rune) string {
+ return fmt.Sprintf("[U+%04X]", r)
}
-func (e *escapeStreamer) invisibleRune(r rune) error {
+func (e *escapeStreamer) writeAmbiguousRune(r, c rune) (err error) {
e.escaped.Escaped = true
- e.escaped.HasInvisible = true
-
- if err := e.PassthroughHTMLStreamer.StartTag("span", html.Attribute{
- Key: "class",
- Val: "escaped-code-point",
- }, html.Attribute{
- Key: "data-escaped",
- Val: fmt.Sprintf("[U+%04X]", r),
- }); err != nil {
- return err
- }
- if err := e.PassthroughHTMLStreamer.StartTag("span", html.Attribute{
- Key: "class",
- Val: "char",
- }); err != nil {
- return err
- }
- if err := e.PassthroughHTMLStreamer.Text(string(r)); err != nil {
- return err
- }
- if err := e.PassthroughHTMLStreamer.EndTag("span"); err != nil {
- return err
- }
-
- return e.PassthroughHTMLStreamer.EndTag("span")
+ e.escaped.HasAmbiguous = true
+ return e.writeEscapedCharHTML(
+ ``,
+ string(r),
+ ` `,
+ )
}
-type runeCountType struct {
- numBasicRunes int
- numNonConfusingNonBasicRunes int
- numAmbiguousRunes int
- numInvisibleRunes int
- numBrokenRunes int
+func (e *escapeStreamer) writeInvisibleRune(r rune) error {
+ e.escaped.Escaped = true
+ e.escaped.HasInvisible = true
+ return e.writeEscapedCharHTML(
+ ``,
+ string(r),
+ ` `,
+ )
}
-func (counts runeCountType) needsEscape() bool {
- if counts.numBrokenRunes > 0 {
- return true
- }
- if counts.numBasicRunes == 0 &&
- counts.numNonConfusingNonBasicRunes > 0 {
- return false
+func (e *escapeStreamer) writeControlRune(r rune) error {
+ var display string
+ if r >= 0 && r <= 0x1f {
+ display = string(0x2400 + r)
+ } else if r == 0x7f {
+ display = string(rune(0x2421))
+ } else {
+ display = runeToHex(r)
}
- return counts.numAmbiguousRunes > 0 || counts.numInvisibleRunes > 0
+ return e.writeEscapedCharHTML(
+ ``,
+ string(r),
+ ` `,
+ )
}
-type runeType int
+type detectResult struct {
+ runeChar rune
+ runeType int
+ runeSize int
+ position int
+ confusable rune
+ needEscape bool
+}
const (
- basicASCIIRuneType runeType = iota // <- This is technically deadcode but its self-documenting so it should stay
- brokenRuneType
- nonBasicASCIIRuneType
- ambiguousRuneType
- invisibleRuneType
+ runeTypeBasic int = iota
+ runeTypeBroken
+ runeTypeNonASCII
+ runeTypeAmbiguous
+ runeTypeInvisible
+ runeTypeControlChar
)
-func (e *escapeStreamer) runeTypes(runes ...rune) (types []runeType, confusables []rune, runeCounts runeCountType) {
- types = make([]runeType, len(runes))
- for i, r := range runes {
- var confusable rune
+func (e *escapeStreamer) detectRunes(data []byte) []detectResult {
+ runeCount := utf8.RuneCount(data)
+ results := make([]detectResult, runeCount)
+ invisibleRangeTable := globalVars().invisibleRangeTable
+ var i int
+ var confusable rune
+ for pos := 0; pos < len(data); i++ {
+ r, runeSize := utf8.DecodeRune(data[pos:])
+ results[i].runeChar = r
+ results[i].runeSize = runeSize
+ results[i].position = pos
+ pos += runeSize
+
switch {
case r == utf8.RuneError:
- types[i] = brokenRuneType
- runeCounts.numBrokenRunes++
- case r == ' ' || r == '\t' || r == '\n':
- runeCounts.numBasicRunes++
- case e.allowed[r]:
- if r > 0x7e || r < 0x20 {
- types[i] = nonBasicASCIIRuneType
- runeCounts.numNonConfusingNonBasicRunes++
- } else {
- runeCounts.numBasicRunes++
+ results[i].runeType = runeTypeBroken
+ results[i].needEscape = true
+ case r == ' ' || r == '\t' || r == '\n' || e.allowed[r]:
+ results[i].runeType = runeTypeBasic
+ if r >= 0x80 {
+ results[i].runeType = runeTypeNonASCII
}
- case unicode.Is(InvisibleRanges, r):
- types[i] = invisibleRuneType
- runeCounts.numInvisibleRunes++
- case unicode.IsControl(r):
- types[i] = invisibleRuneType
- runeCounts.numInvisibleRunes++
+ case r < 0x20 || r == 0x7f:
+ results[i].runeType = runeTypeControlChar
+ results[i].needEscape = true
+ case unicode.Is(invisibleRangeTable, r):
+ results[i].runeType = runeTypeInvisible
+ // not sure about results[i].needEscape, will be detected separately
case isAmbiguous(r, &confusable, e.ambiguousTables...):
- confusables = append(confusables, confusable)
- types[i] = ambiguousRuneType
- runeCounts.numAmbiguousRunes++
- case r > 0x7e || r < 0x20:
- types[i] = nonBasicASCIIRuneType
- runeCounts.numNonConfusingNonBasicRunes++
- default:
- runeCounts.numBasicRunes++
+ results[i].runeType = runeTypeAmbiguous
+ results[i].confusable = confusable
+ // not sure about results[i].needEscape, will be detected separately
+ case r >= 0x80:
+ results[i].runeType = runeTypeNonASCII
+ default: // details to basic runes
}
}
- return types, confusables, runeCounts
+ return results
}
diff --git a/modules/charset/escape_test.go b/modules/charset/escape_test.go
index 9d796a0c18..4e1ff0fcf4 100644
--- a/modules/charset/escape_test.go
+++ b/modules/charset/escape_test.go
@@ -4,7 +4,6 @@
package charset
import (
- "regexp"
"strings"
"testing"
@@ -13,6 +12,7 @@ import (
"code.gitea.io/gitea/modules/translation"
"github.com/stretchr/testify/assert"
+ "github.com/stretchr/testify/require"
)
type escapeControlTest struct {
@@ -57,24 +57,24 @@ var escapeControlTests = []escapeControlTest{
status: EscapeStatus{},
},
{
- name: "hebrew",
+ name: "hebrew", // old test was wrong, such text shouldn't be escaped
text: "עד תקופת יוון העתיקה היה העיסוק במתמטיקה תכליתי בלבד: היא שימשה כאוסף של נוסחאות לחישוב קרקע, אוכלוסין וכו'. פריצת הדרך של היוונים, פרט לתרומותיהם הגדולות לידע המתמטי, הייתה בלימוד המתמטיקה כשלעצמה, מתוקף ערכה הרוחני. יחסם של חלק מהיוונים הקדמונים למתמטיקה היה דתי - למשל, הכת שאסף סביבו פיתגורס האמינה כי המתמטיקה היא הבסיס לכל הדברים. היוונים נחשבים ליוצרי מושג ההוכחה המתמטית, וכן לראשונים שעסקו במתמטיקה לשם עצמה, כלומר כתחום מחקרי עיוני ומופשט ולא רק כעזר שימושי. עם זאת, לצדה",
- result: `עד תקופת י ו ו ן העתיקה היה העיסוק במתמטיקה תכליתי בלבד: היא שימשה כאוסף של נוסחאות לחישוב קרקע, אוכלוסין וכו'. פריצת הדרך של היוונים, פרט לתרומותיהם הגדולות לידע המתמטי, הייתה בלימוד המתמטיקה כשלעצמה, מתוקף ערכה הרוחני. יחסם של חלק מהיוונים הקדמונים למתמטיקה היה דתי - למשל, הכת שאסף סביבו פיתגורס האמינה כי המתמטיקה היא הבסיס לכל הדברים. היוונים נחשבים ליוצרי מושג ההוכחה המתמטית, וכן לראשונים שעסקו במתמטיקה לשם עצמה, כלומר כתחום מחקרי עיוני ומופשט ולא רק כעזר שימושי. עם זאת, לצדה`,
- status: EscapeStatus{Escaped: true, HasAmbiguous: true},
+ result: "עד תקופת יוון העתיקה היה העיסוק במתמטיקה תכליתי בלבד: היא שימשה כאוסף של נוסחאות לחישוב קרקע, אוכלוסין וכו'. פריצת הדרך של היוונים, פרט לתרומותיהם הגדולות לידע המתמטי, הייתה בלימוד המתמטיקה כשלעצמה, מתוקף ערכה הרוחני. יחסם של חלק מהיוונים הקדמונים למתמטיקה היה דתי - למשל, הכת שאסף סביבו פיתגורס האמינה כי המתמטיקה היא הבסיס לכל הדברים. היוונים נחשבים ליוצרי מושג ההוכחה המתמטית, וכן לראשונים שעסקו במתמטיקה לשם עצמה, כלומר כתחום מחקרי עיוני ומופשט ולא רק כעזר שימושי. עם זאת, לצדה",
+ status: EscapeStatus{},
},
{
- name: "more hebrew",
+ name: "more hebrew", // old test was wrong, such text shouldn't be escaped
text: `בתקופה מאוחרת יותר, השתמשו היוונים בשיטת סימון מתקדמת יותר, שבה הוצגו המספרים לפי 22 אותיות האלפבית היווני. לסימון המספרים בין 1 ל-9 נקבעו תשע האותיות הראשונות, בתוספת גרש ( ' ) בצד ימין של האות, למעלה; תשע האותיות הבאות ייצגו את העשרות מ-10 עד 90, והבאות את המאות. לסימון הספרות בין 1000 ל-900,000, השתמשו היוונים באותן אותיות, אך הוסיפו לאותיות את הגרש דווקא מצד שמאל של האותיות, למטה. ממיליון ומעלה, כנראה השתמשו היוונים בשני תגים במקום אחד.
המתמטיקאי הבולט הראשון ביוון העתיקה, ויש האומרים בתולדות האנושות, הוא תאלס (624 לפנה"ס - 546 לפנה"ס בקירוב).[1] לא יהיה זה משולל יסוד להניח שהוא האדם הראשון שהוכיח משפט מתמטי, ולא רק גילה אותו. תאלס הוכיח שישרים מקבילים חותכים מצד אחד של שוקי זווית קטעים בעלי יחסים שווים (משפט תאלס הראשון), שהזווית המונחת על קוטר במעגל היא זווית ישרה (משפט תאלס השני), שהקוטר מחלק את המעגל לשני חלקים שווים, ושזוויות הבסיס במשולש שווה-שוקיים שוות זו לזו. מיוחסות לו גם שיטות למדידת גובהן של הפירמידות בעזרת מדידת צילן ולקביעת מיקומה של ספינה הנראית מן החוף.
בשנים 582 לפנה"ס עד 496 לפנה"ס, בקירוב, חי מתמטיקאי חשוב במיוחד - פיתגורס. המקורות הראשוניים עליו מועטים, וההיסטוריונים מתקשים להפריד את העובדות משכבת המסתורין והאגדות שנקשרו בו. ידוע שסביבו התקבצה האסכולה הפיתגוראית מעין כת פסבדו-מתמטית שהאמינה ש"הכל מספר", או ליתר דיוק הכל ניתן לכימות, וייחסה למספרים משמעויות מיסטיות. ככל הנראה הפיתגוראים ידעו לבנות את הגופים האפלטוניים, הכירו את הממוצע האריתמטי, הממוצע הגאומטרי והממוצע ההרמוני והגיעו להישגים חשובים נוספים. ניתן לומר שהפיתגוראים גילו את היותו של השורש הריבועי של 2, שהוא גם האלכסון בריבוע שאורך צלעותיו 1, אי רציונלי, אך תגליתם הייתה למעשה רק שהקטעים "חסרי מידה משותפת", ומושג המספר האי רציונלי מאוחר יותר.[2] אזכור ראשון לקיומם של קטעים חסרי מידה משותפת מופיע בדיאלוג "תאיטיטוס" של אפלטון, אך רעיון זה היה מוכר עוד קודם לכן, במאה החמישית לפנה"ס להיפאסוס, בן האסכולה הפיתגוראית, ואולי לפיתגורס עצמו.[3]`,
- result: `בתקופה מאוחרת יותר, השתמשו היוונים בשיטת סימון מתקדמת יותר, שבה הוצגו המספרים לפי 22 אותיות האלפבית היווני. לסימון המספרים בין 1 ל-9 נקבעו תשע האותיות הראשונות, בתוספת גרש ( ' ) בצד ימין של האות, למעלה; תשע האותיות הבאות ייצגו את העשרות מ-10 עד 90, והבאות את המאות. לסימון הספרות בין 1000 ל-900,000, השתמשו היוונים באותן אותיות, אך הוסיפו לאותיות את הגרש דווקא מצד שמאל של האותיות, למטה. ממיליון ומעלה, כנראה השתמשו היוונים בשני תגים במקום אחד.
+ result: `בתקופה מאוחרת יותר, השתמשו היוונים בשיטת סימון מתקדמת יותר, שבה הוצגו המספרים לפי 22 אותיות האלפבית היווני. לסימון המספרים בין 1 ל-9 נקבעו תשע האותיות הראשונות, בתוספת גרש ( ' ) בצד ימין של האות, למעלה; תשע האותיות הבאות ייצגו את העשרות מ-10 עד 90, והבאות את המאות. לסימון הספרות בין 1000 ל-900,000, השתמשו היוונים באותן אותיות, אך הוסיפו לאותיות את הגרש דווקא מצד שמאל של האותיות, למטה. ממיליון ומעלה, כנראה השתמשו היוונים בשני תגים במקום אחד.
- המתמטיקאי הבולט הראשון ביוון העתיקה, ויש האומרים בתולדות האנושות, הוא תאלס (624 לפנה"ס - 546 לפנה"ס בקירוב).[1] לא יהיה זה משולל יסוד להניח שהוא האדם הראשון שהוכיח משפט מתמטי, ולא רק גילה אותו. תאלס הוכיח שישרים מקבילים חותכים מצד אחד של שוקי זווית קטעים בעלי יחסים שווים (משפט תאלס הראשון), שהזווית המונחת על קוטר במעגל היא זווית ישרה (משפט תאלס השני), שהקוטר מחלק את המעגל לשני חלקים שווים, ושזוויות הבסיס במשולש שווה-שוקיים שוות זו לזו. מיוחסות לו גם שיטות למדידת גובהן של הפירמידות בעזרת מדידת צילן ולקביעת מיקומה של ספינה הנראית מן החוף.
+ המתמטיקאי הבולט הראשון ביוון העתיקה, ויש האומרים בתולדות האנושות, הוא תאלס (624 לפנה"ס - 546 לפנה"ס בקירוב).[1] לא יהיה זה משולל יסוד להניח שהוא האדם הראשון שהוכיח משפט מתמטי, ולא רק גילה אותו. תאלס הוכיח שישרים מקבילים חותכים מצד אחד של שוקי זווית קטעים בעלי יחסים שווים (משפט תאלס הראשון), שהזווית המונחת על קוטר במעגל היא זווית ישרה (משפט תאלס השני), שהקוטר מחלק את המעגל לשני חלקים שווים, ושזוויות הבסיס במשולש שווה-שוקיים שוות זו לזו. מיוחסות לו גם שיטות למדידת גובהן של הפירמידות בעזרת מדידת צילן ולקביעת מיקומה של ספינה הנראית מן החוף.
- בשנים 582 לפנה"ס עד 496 לפנה"ס , בקירוב, חי מתמטיקאי חשוב במיוחד - פיתגורס. המקורות הראשוניים עליו מועטים, וההיסטוריונים מתקשים להפריד את העובדות משכבת המסתורין והאגדות שנקשרו בו. ידוע שסביבו התקבצה האסכולה הפיתגוראית מעין כת פסבדו-מתמטית שהאמינה ש"הכל מספר", או ליתר דיוק הכל ניתן לכימות, וייחסה למספרים משמעויות מיסטיות. ככל הנראה הפיתגוראים ידעו לבנות את הגופים האפלטוניים, הכירו את הממוצע האריתמטי, הממוצע הגאומטרי והממוצע ההרמוני והגיעו להישגים חשובים נוספים. ניתן לומר שהפיתגוראים גילו את היותו של השורש הריבועי של 2, שהוא גם האלכסון בריבוע שאורך צלעותיו 1, אי רציונלי, אך תגליתם הייתה למעשה רק שהקטעים "חסרי מידה משותפת", ומושג המספר האי רציונלי מאוחר יותר.[2] אזכור ראשון לקיומם של קטעים חסרי מידה משותפת מופיע בדיאלוג "תאיטיטוס" של אפלטון, אך רעיון זה היה מוכר עוד קודם לכן, במאה החמישית לפנה"ס להיפאסוס, בן האסכולה הפיתגוראית, ואולי לפיתגורס עצמו.[3]`,
- status: EscapeStatus{Escaped: true, HasAmbiguous: true},
+ בשנים 582 לפנה"ס עד 496 לפנה"ס, בקירוב, חי מתמטיקאי חשוב במיוחד - פיתגורס. המקורות הראשוניים עליו מועטים, וההיסטוריונים מתקשים להפריד את העובדות משכבת המסתורין והאגדות שנקשרו בו. ידוע שסביבו התקבצה האסכולה הפיתגוראית מעין כת פסבדו-מתמטית שהאמינה ש"הכל מספר", או ליתר דיוק הכל ניתן לכימות, וייחסה למספרים משמעויות מיסטיות. ככל הנראה הפיתגוראים ידעו לבנות את הגופים האפלטוניים, הכירו את הממוצע האריתמטי, הממוצע הגאומטרי והממוצע ההרמוני והגיעו להישגים חשובים נוספים. ניתן לומר שהפיתגוראים גילו את היותו של השורש הריבועי של 2, שהוא גם האלכסון בריבוע שאורך צלעותיו 1, אי רציונלי, אך תגליתם הייתה למעשה רק שהקטעים "חסרי מידה משותפת", ומושג המספר האי רציונלי מאוחר יותר.[2] אזכור ראשון לקיומם של קטעים חסרי מידה משותפת מופיע בדיאלוג "תאיטיטוס" של אפלטון, אך רעיון זה היה מוכר עוד קודם לכן, במאה החמישית לפנה"ס להיפאסוס, בן האסכולה הפיתגוראית, ואולי לפיתגורס עצמו.[3]`,
+ status: EscapeStatus{},
},
{
name: "Mixed RTL+LTR",
@@ -111,7 +111,7 @@ then resh (ר), and finally heh (ה) (which should appear leftmost).`,
{
name: "CVE testcase",
text: "if access_level != \"user\u202E \u2066// Check if admin\u2069 \u2066\" {",
- result: `if access_level != "user` + "\u202e" + ` ` + "\u2066" + ` // Check if admin` + "\u2069" + ` ` + "\u2066" + ` " {`,
+ result: `if access_level != "user` + "\u202e" + ` ` + "\u2066" + ` // Check if admin` + "\u2069" + ` ` + "\u2066" + ` " {`,
status: EscapeStatus{Escaped: true, HasInvisible: true},
},
{
@@ -123,7 +123,7 @@ then resh (ר), and finally heh (ה) (which should appear leftmost).`,
result: `Many computer programs fail to display bidirectional text correctly.
For example, the Hebrew name Sarah ` + "\u2067" + `שרה` + "\u2066\n" +
`sin (ש) (which appears rightmost), then resh (ר), and finally heh (ה) (which should appear leftmost).` +
- "\n" + `if access_level != "user` + "\u202e" + ` ` + "\u2066" + ` // Check if admin` + "\u2069" + ` ` + "\u2066" + ` " {` + "\n",
+ "\n" + `if access_level != "user` + "\u202e" + ` ` + "\u2066" + ` // Check if admin` + "\u2069" + ` ` + "\u2066" + ` " {` + "\n",
status: EscapeStatus{Escaped: true, HasInvisible: true},
},
{
@@ -134,38 +134,22 @@ then resh (ר), and finally heh (ה) (which should appear leftmost).`,
result: "\xef\xbb\xbftest",
status: EscapeStatus{},
},
+ {
+ name: "ambiguous",
+ text: "O𝐾",
+ result: `O𝐾 `,
+ status: EscapeStatus{Escaped: true, HasAmbiguous: true},
+ },
}
func TestEscapeControlReader(t *testing.T) {
- // add some control characters to the tests
- tests := make([]escapeControlTest, 0, len(escapeControlTests)*3)
- copy(tests, escapeControlTests)
-
- // if there is a BOM, we should keep the BOM
- addPrefix := func(prefix, s string) string {
- if strings.HasPrefix(s, "\xef\xbb\xbf") {
- return s[:3] + prefix + s[3:]
- }
- return prefix + s
- }
- for _, test := range escapeControlTests {
- test.name += " (+Control)"
- test.text = addPrefix("\u001E", test.text)
- test.result = addPrefix(``+"\u001e"+` `, test.result)
- test.status.Escaped = true
- test.status.HasInvisible = true
- tests = append(tests, test)
- }
-
- re := regexp.MustCompile(`repo.ambiguous_character:\d+,\d+`) // simplify the output for the tests, remove the translation variants
- for _, tt := range tests {
+ for _, tt := range escapeControlTests {
t.Run(tt.name, func(t *testing.T) {
output := &strings.Builder{}
status, err := EscapeControlReader(strings.NewReader(tt.text), output, &translation.MockLocale{})
assert.NoError(t, err)
assert.Equal(t, tt.status, *status)
outStr := output.String()
- outStr = re.ReplaceAllString(outStr, "repo.ambiguous_character")
assert.Equal(t, tt.result, outStr)
})
}
@@ -179,3 +163,50 @@ func TestSettingAmbiguousUnicodeDetection(t *testing.T) {
_, out = EscapeControlHTML("a test", &translation.MockLocale{})
assert.EqualValues(t, `a test`, out)
}
+
+func TestHTMLChunkReader(t *testing.T) {
+ type textPart struct {
+ text string
+ isTag bool
+ }
+ testReadChunks := func(t *testing.T, chunkSize int, input string, expected []textPart) {
+ r := &htmlChunkReader{in: strings.NewReader(input), readBuf: make([]byte, 0, chunkSize)}
+ var results []textPart
+ for {
+ parts, partIsTag, err := r.readRunes()
+ if err != nil {
+ break
+ }
+ for i, part := range parts {
+ results = append(results, textPart{string(part), partIsTag[i]})
+ }
+ }
+ assert.Equal(t, expected, results, "chunk size: %d, input: %s", chunkSize, input)
+ }
+
+ testReadChunks(t, 10, "abcghi", []textPart{
+ {text: "abc", isTag: false},
+ {text: "", isTag: true},
+ {text: "gh", isTag: false},
+ // -- chunk
+ {text: "i", isTag: false},
+ })
+
+ testReadChunks(t, 10, "ghi", []textPart{
+ {text: "", isTag: true},
+ {text: "", isTag: true},
+ // -- chunk
+ {text: "ghi", isTag: false},
+ })
+
+ rune1, rune2, rune3, rune4 := "A", "é", "啊", "🌞"
+ require.Len(t, rune1, 1)
+ require.Len(t, rune2, 2)
+ require.Len(t, rune3, 3)
+ require.Len(t, rune4, 4)
+ input := "<" + rune1 + rune2 + rune3 + rune4 + ">" + rune1 + rune2 + rune3 + rune4
+ testReadChunks(t, 4, input, []textPart{{"", true}, {"Aé", false}, {"啊", false}, {"🌞", false}})
+ testReadChunks(t, 5, input, []textPart{{" ", true}, {"Aé", false}, {"啊", false}, {"🌞", false}})
+ testReadChunks(t, 6, input, []textPart{{" ", true}, {"A", false}, {"é啊", false}, {"🌞", false}})
+ testReadChunks(t, 7, input, []textPart{{" ", true}, {"A", false}, {"é啊", false}, {"🌞", false}})
+}
diff --git a/modules/charset/ambiguous/ambiguous.json b/modules/charset/generate/ambiguous.json
similarity index 100%
rename from modules/charset/ambiguous/ambiguous.json
rename to modules/charset/generate/ambiguous.json
diff --git a/modules/charset/invisible/generate.go b/modules/charset/generate/generate.go
similarity index 57%
rename from modules/charset/invisible/generate.go
rename to modules/charset/generate/generate.go
index bd57dd6c4d..16ea53fda1 100644
--- a/modules/charset/invisible/generate.go
+++ b/modules/charset/generate/generate.go
@@ -5,37 +5,86 @@ package main
import (
"bytes"
- "flag"
"fmt"
"go/format"
+ "log"
"os"
+ "sort"
"text/template"
+ "unicode"
+
+ "code.gitea.io/gitea/modules/json"
"golang.org/x/text/unicode/rangetable"
)
+// ambiguous.json provides a one to one mapping of ambiguous characters to other characters
+// See https://github.com/hediet/vscode-unicode-data/blob/main/out/ambiguous.json
+
+type AmbiguousTable struct {
+ Confusable []rune
+ With []rune
+ Locale string
+ RangeTable *unicode.RangeTable
+}
+
+type RunePair struct {
+ Confusable rune
+ With rune
+}
+
// InvisibleRunes these are runes that vscode has assigned to be invisible
// See https://github.com/hediet/vscode-unicode-data
var InvisibleRunes = []rune{
9, 10, 11, 12, 13, 32, 127, 160, 173, 847, 1564, 4447, 4448, 6068, 6069, 6155, 6156, 6157, 6158, 7355, 7356, 8192, 8193, 8194, 8195, 8196, 8197, 8198, 8199, 8200, 8201, 8202, 8203, 8204, 8205, 8206, 8207, 8234, 8235, 8236, 8237, 8238, 8239, 8287, 8288, 8289, 8290, 8291, 8292, 8293, 8294, 8295, 8296, 8297, 8298, 8299, 8300, 8301, 8302, 8303, 10240, 12288, 12644, 65024, 65025, 65026, 65027, 65028, 65029, 65030, 65031, 65032, 65033, 65034, 65035, 65036, 65037, 65038, 65039, 65279, 65440, 65520, 65521, 65522, 65523, 65524, 65525, 65526, 65527, 65528, 65532, 78844, 119155, 119156, 119157, 119158, 119159, 119160, 119161, 119162, 917504, 917505, 917506, 917507, 917508, 917509, 917510, 917511, 917512, 917513, 917514, 917515, 917516, 917517, 917518, 917519, 917520, 917521, 917522, 917523, 917524, 917525, 917526, 917527, 917528, 917529, 917530, 917531, 917532, 917533, 917534, 917535, 917536, 917537, 917538, 917539, 917540, 917541, 917542, 917543, 917544, 917545, 917546, 917547, 917548, 917549, 917550, 917551, 917552, 917553, 917554, 917555, 917556, 917557, 917558, 917559, 917560, 917561, 917562, 917563, 917564, 917565, 917566, 917567, 917568, 917569, 917570, 917571, 917572, 917573, 917574, 917575, 917576, 917577, 917578, 917579, 917580, 917581, 917582, 917583, 917584, 917585, 917586, 917587, 917588, 917589, 917590, 917591, 917592, 917593, 917594, 917595, 917596, 917597, 917598, 917599, 917600, 917601, 917602, 917603, 917604, 917605, 917606, 917607, 917608, 917609, 917610, 917611, 917612, 917613, 917614, 917615, 917616, 917617, 917618, 917619, 917620, 917621, 917622, 917623, 917624, 917625, 917626, 917627, 917628, 917629, 917630, 917631, 917760, 917761, 917762, 917763, 917764, 917765, 917766, 917767, 917768, 917769, 917770, 917771, 917772, 917773, 917774, 917775, 917776, 917777, 917778, 917779, 917780, 917781, 917782, 917783, 917784, 917785, 917786, 917787, 917788, 917789, 917790, 917791, 917792, 917793, 917794, 917795, 917796, 917797, 917798, 917799, 917800, 917801, 917802, 917803, 917804, 917805, 917806, 917807, 917808, 917809, 917810, 917811, 917812, 917813, 917814, 917815, 917816, 917817, 917818, 917819, 917820, 917821, 917822, 917823, 917824, 917825, 917826, 917827, 917828, 917829, 917830, 917831, 917832, 917833, 917834, 917835, 917836, 917837, 917838, 917839, 917840, 917841, 917842, 917843, 917844, 917845, 917846, 917847, 917848, 917849, 917850, 917851, 917852, 917853, 917854, 917855, 917856, 917857, 917858, 917859, 917860, 917861, 917862, 917863, 917864, 917865, 917866, 917867, 917868, 917869, 917870, 917871, 917872, 917873, 917874, 917875, 917876, 917877, 917878, 917879, 917880, 917881, 917882, 917883, 917884, 917885, 917886, 917887, 917888, 917889, 917890, 917891, 917892, 917893, 917894, 917895, 917896, 917897, 917898, 917899, 917900, 917901, 917902, 917903, 917904, 917905, 917906, 917907, 917908, 917909, 917910, 917911, 917912, 917913, 917914, 917915, 917916, 917917, 917918, 917919, 917920, 917921, 917922, 917923, 917924, 917925, 917926, 917927, 917928, 917929, 917930, 917931, 917932, 917933, 917934, 917935, 917936, 917937, 917938, 917939, 917940, 917941, 917942, 917943, 917944, 917945, 917946, 917947, 917948, 917949, 917950, 917951, 917952, 917953, 917954, 917955, 917956, 917957, 917958, 917959, 917960, 917961, 917962, 917963, 917964, 917965, 917966, 917967, 917968, 917969, 917970, 917971, 917972, 917973, 917974, 917975, 917976, 917977, 917978, 917979, 917980, 917981, 917982, 917983, 917984, 917985, 917986, 917987, 917988, 917989, 917990, 917991, 917992, 917993, 917994, 917995, 917996, 917997, 917998, 917999,
}
-var verbose bool
+func generateAmbiguous() {
+ bs, err := os.ReadFile("ambiguous.json")
+ if err != nil {
+ log.Fatalf("Unable to read, err: %v", err)
+ }
+
+ var unwrapped string
+ if err := json.Unmarshal(bs, &unwrapped); err != nil {
+ log.Fatalf("Unable to unwrap content in, err: %v", err)
+ }
-func main() {
- flag.Usage = func() {
- fmt.Fprintf(os.Stderr, `%s: Generate InvisibleRunesRange
+ fromJSON := map[string][]uint32{}
+ if err := json.Unmarshal([]byte(unwrapped), &fromJSON); err != nil {
+ log.Fatalf("Unable to unmarshal content in, err: %v", err)
+ }
-Usage: %[1]s [-v] [-o output.go]
-`, os.Args[0])
- flag.PrintDefaults()
+ tables := make([]*AmbiguousTable, 0, len(fromJSON))
+ for locale, chars := range fromJSON {
+ table := &AmbiguousTable{Locale: locale}
+ table.Confusable = make([]rune, 0, len(chars)/2)
+ table.With = make([]rune, 0, len(chars)/2)
+ pairs := make([]RunePair, len(chars)/2)
+ for i := 0; i < len(chars); i += 2 {
+ pairs[i/2].Confusable, pairs[i/2].With = rune(chars[i]), rune(chars[i+1])
+ }
+ sort.Slice(pairs, func(i, j int) bool {
+ return pairs[i].Confusable < pairs[j].Confusable
+ })
+ for _, pair := range pairs {
+ table.Confusable = append(table.Confusable, pair.Confusable)
+ table.With = append(table.With, pair.With)
+ }
+ table.RangeTable = rangetable.New(table.Confusable...)
+ tables = append(tables, table)
}
+ sort.Slice(tables, func(i, j int) bool {
+ return tables[i].Locale < tables[j].Locale
+ })
+ data := map[string]any{"Tables": tables}
- output := ""
- flag.BoolVar(&verbose, "v", false, "verbose output")
- flag.StringVar(&output, "o", "invisible_gen.go", "file to output to")
- flag.Parse()
+ if err := runTemplate(templateAmbiguous, "../ambiguous_gen.go", &data); err != nil {
+ log.Fatalf("Unable to run template: %v", err)
+ }
+}
+func generateInvisible() {
// First we filter the runes to remove
//
filtered := make([]rune, 0, len(InvisibleRunes))
@@ -47,8 +96,8 @@ Usage: %[1]s [-v] [-o output.go]
}
table := rangetable.New(filtered...)
- if err := runTemplate(generatorTemplate, output, table); err != nil {
- fatalf("Unable to run template: %v", err)
+ if err := runTemplate(generatorInvisible, "../invisible_gen.go", table); err != nil {
+ log.Fatalf("Unable to run template: %v", err)
}
}
@@ -59,7 +108,7 @@ func runTemplate(t *template.Template, filename string, data any) error {
}
bs, err := format.Source(buf.Bytes())
if err != nil {
- verbosef("Bad source:\n%s", buf.String())
+ log.Printf("Bad source:\n%s", buf.String())
return fmt.Errorf("unable to format source: %w", err)
}
@@ -85,37 +134,68 @@ func runTemplate(t *template.Template, filename string, data any) error {
return nil
}
-var generatorTemplate = template.Must(template.New("invisibleTemplate").Parse(`// This file is generated by modules/charset/invisible/generate.go DO NOT EDIT
-// Copyright 2022 The Gitea Authors. All rights reserved.
-// SPDX-License-Identifier: MIT
+func main() {
+ generateAmbiguous()
+ generateInvisible()
+}
+var templateAmbiguous = template.Must(template.New("ambiguousTemplate").Parse(`// This file is generated by modules/charset/generate/generate.go DO NOT EDIT
+// Copyright 2026 The Gitea Authors. All rights reserved.
+// SPDX-License-Identifier: MIT
package charset
import "unicode"
-var InvisibleRanges = &unicode.RangeTable{
- R16: []unicode.Range16{
-{{range .R16 }} {Lo:{{.Lo}}, Hi:{{.Hi}}, Stride: {{.Stride}}},
-{{end}} },
- R32: []unicode.Range32{
-{{range .R32}} {Lo:{{.Lo}}, Hi:{{.Hi}}, Stride: {{.Stride}}},
-{{end}} },
- LatinOffset: {{.LatinOffset}},
-}
-`))
+// This file is generated from https://github.com/hediet/vscode-unicode-data/blob/main/out/ambiguous.json
-func logf(format string, args ...any) {
- fmt.Fprintf(os.Stderr, format+"\n", args...)
+// AmbiguousTable matches a confusable rune with its partner for the Locale
+type AmbiguousTable struct {
+ Confusable []rune
+ With []rune
+ Locale string
+ RangeTable *unicode.RangeTable
}
-func verbosef(format string, args ...any) {
- if verbose {
- logf(format, args...)
+func newAmbiguousTableMap() map[string]*AmbiguousTable {
+ return map[string]*AmbiguousTable {
+ {{- range .Tables}}
+ {{printf "%q" .Locale}}: {
+ Confusable: []rune{ {{range .Confusable}}{{.}},{{end}} },
+ With: []rune{ {{range .With}}{{.}},{{end}} },
+ Locale: {{printf "%q" .Locale}},
+ RangeTable: &unicode.RangeTable{
+ R16: []unicode.Range16{
+ {{range .RangeTable.R16 }} {Lo:{{.Lo}}, Hi:{{.Hi}}, Stride: {{.Stride}}},
+ {{end}} },
+ R32: []unicode.Range32{
+ {{range .RangeTable.R32}} {Lo:{{.Lo}}, Hi:{{.Hi}}, Stride: {{.Stride}}},
+ {{end}} },
+ LatinOffset: {{.RangeTable.LatinOffset}},
+ },
+ },
+ {{end}}
}
}
+`))
-func fatalf(format string, args ...any) {
- logf("fatal: "+format+"\n", args...)
- os.Exit(1)
+var generatorInvisible = template.Must(template.New("invisibleTemplate").Parse(`// This file is generated by modules/charset/generate/generate.go DO NOT EDIT
+// Copyright 2026 The Gitea Authors. All rights reserved.
+// SPDX-License-Identifier: MIT
+
+package charset
+
+import "unicode"
+
+func newInvisibleRangeTable() *unicode.RangeTable {
+ return &unicode.RangeTable{
+ R16: []unicode.Range16{
+{{range .R16 }} {Lo:{{.Lo}}, Hi:{{.Hi}}, Stride: {{.Stride}}},
+ {{end}}},
+ R32: []unicode.Range32{
+{{range .R32}} {Lo:{{.Lo}}, Hi:{{.Hi}}, Stride: {{.Stride}}},
+ {{end}}},
+ LatinOffset: {{.LatinOffset}},
+ }
}
+`))
diff --git a/modules/charset/htmlstream.go b/modules/charset/htmlstream.go
deleted file mode 100644
index 61f29120a6..0000000000
--- a/modules/charset/htmlstream.go
+++ /dev/null
@@ -1,200 +0,0 @@
-// Copyright 2022 The Gitea Authors. All rights reserved.
-// SPDX-License-Identifier: MIT
-
-package charset
-
-import (
- "fmt"
- "io"
-
- "golang.org/x/net/html"
-)
-
-// HTMLStreamer represents a SAX-like interface for HTML
-type HTMLStreamer interface {
- Error(err error) error
- Doctype(data string) error
- Comment(data string) error
- StartTag(data string, attrs ...html.Attribute) error
- SelfClosingTag(data string, attrs ...html.Attribute) error
- EndTag(data string) error
- Text(data string) error
-}
-
-// PassthroughHTMLStreamer is a passthrough streamer
-type PassthroughHTMLStreamer struct {
- next HTMLStreamer
-}
-
-func NewPassthroughStreamer(next HTMLStreamer) *PassthroughHTMLStreamer {
- return &PassthroughHTMLStreamer{next: next}
-}
-
-var _ (HTMLStreamer) = &PassthroughHTMLStreamer{}
-
-// Error tells the next streamer in line that there is an error
-func (p *PassthroughHTMLStreamer) Error(err error) error {
- return p.next.Error(err)
-}
-
-// Doctype tells the next streamer what the doctype is
-func (p *PassthroughHTMLStreamer) Doctype(data string) error {
- return p.next.Doctype(data)
-}
-
-// Comment tells the next streamer there is a comment
-func (p *PassthroughHTMLStreamer) Comment(data string) error {
- return p.next.Comment(data)
-}
-
-// StartTag tells the next streamer there is a starting tag
-func (p *PassthroughHTMLStreamer) StartTag(data string, attrs ...html.Attribute) error {
- return p.next.StartTag(data, attrs...)
-}
-
-// SelfClosingTag tells the next streamer there is a self-closing tag
-func (p *PassthroughHTMLStreamer) SelfClosingTag(data string, attrs ...html.Attribute) error {
- return p.next.SelfClosingTag(data, attrs...)
-}
-
-// EndTag tells the next streamer there is a end tag
-func (p *PassthroughHTMLStreamer) EndTag(data string) error {
- return p.next.EndTag(data)
-}
-
-// Text tells the next streamer there is a text
-func (p *PassthroughHTMLStreamer) Text(data string) error {
- return p.next.Text(data)
-}
-
-// HTMLStreamWriter acts as a writing sink
-type HTMLStreamerWriter struct {
- io.Writer
- err error
-}
-
-// Write implements io.Writer
-func (h *HTMLStreamerWriter) Write(data []byte) (int, error) {
- if h.err != nil {
- return 0, h.err
- }
- return h.Writer.Write(data)
-}
-
-// Write implements io.StringWriter
-func (h *HTMLStreamerWriter) WriteString(data string) (int, error) {
- if h.err != nil {
- return 0, h.err
- }
- return h.Writer.Write([]byte(data))
-}
-
-// Error tells the next streamer in line that there is an error
-func (h *HTMLStreamerWriter) Error(err error) error {
- if h.err == nil {
- h.err = err
- }
- return h.err
-}
-
-// Doctype tells the next streamer what the doctype is
-func (h *HTMLStreamerWriter) Doctype(data string) error {
- _, h.err = h.WriteString("")
- return h.err
-}
-
-// Comment tells the next streamer there is a comment
-func (h *HTMLStreamerWriter) Comment(data string) error {
- _, h.err = h.WriteString("")
- return h.err
-}
-
-// StartTag tells the next streamer there is a starting tag
-func (h *HTMLStreamerWriter) StartTag(data string, attrs ...html.Attribute) error {
- return h.startTag(data, attrs, false)
-}
-
-// SelfClosingTag tells the next streamer there is a self-closing tag
-func (h *HTMLStreamerWriter) SelfClosingTag(data string, attrs ...html.Attribute) error {
- return h.startTag(data, attrs, true)
-}
-
-func (h *HTMLStreamerWriter) startTag(data string, attrs []html.Attribute, selfclosing bool) error {
- if _, h.err = h.WriteString("<" + data); h.err != nil {
- return h.err
- }
- for _, attr := range attrs {
- if _, h.err = h.WriteString(" " + attr.Key + "=\"" + html.EscapeString(attr.Val) + "\""); h.err != nil {
- return h.err
- }
- }
- if selfclosing {
- if _, h.err = h.WriteString("/>"); h.err != nil {
- return h.err
- }
- } else {
- if _, h.err = h.WriteString(">"); h.err != nil {
- return h.err
- }
- }
- return h.err
-}
-
-// EndTag tells the next streamer there is a end tag
-func (h *HTMLStreamerWriter) EndTag(data string) error {
- _, h.err = h.WriteString("" + data + ">")
- return h.err
-}
-
-// Text tells the next streamer there is a text
-func (h *HTMLStreamerWriter) Text(data string) error {
- _, h.err = h.WriteString(html.EscapeString(data))
- return h.err
-}
-
-// StreamHTML streams an html to a provided streamer
-func StreamHTML(source io.Reader, streamer HTMLStreamer) error {
- tokenizer := html.NewTokenizer(source)
- for {
- tt := tokenizer.Next()
- switch tt {
- case html.ErrorToken:
- if tokenizer.Err() != io.EOF {
- return tokenizer.Err()
- }
- return nil
- case html.DoctypeToken:
- token := tokenizer.Token()
- if err := streamer.Doctype(token.Data); err != nil {
- return err
- }
- case html.CommentToken:
- token := tokenizer.Token()
- if err := streamer.Comment(token.Data); err != nil {
- return err
- }
- case html.StartTagToken:
- token := tokenizer.Token()
- if err := streamer.StartTag(token.Data, token.Attr...); err != nil {
- return err
- }
- case html.SelfClosingTagToken:
- token := tokenizer.Token()
- if err := streamer.StartTag(token.Data, token.Attr...); err != nil {
- return err
- }
- case html.EndTagToken:
- token := tokenizer.Token()
- if err := streamer.EndTag(token.Data); err != nil {
- return err
- }
- case html.TextToken:
- token := tokenizer.Token()
- if err := streamer.Text(token.Data); err != nil {
- return err
- }
- default:
- return fmt.Errorf("unknown type of token: %d", tt)
- }
- }
-}
diff --git a/modules/charset/invisible_gen.go b/modules/charset/invisible_gen.go
index 812f0e34b3..ddda875a9f 100644
--- a/modules/charset/invisible_gen.go
+++ b/modules/charset/invisible_gen.go
@@ -1,36 +1,38 @@
-// This file is generated by modules/charset/invisible/generate.go DO NOT EDIT
-// Copyright 2022 The Gitea Authors. All rights reserved.
+// This file is generated by modules/charset/generate/generate.go DO NOT EDIT
+// Copyright 2026 The Gitea Authors. All rights reserved.
// SPDX-License-Identifier: MIT
package charset
import "unicode"
-var InvisibleRanges = &unicode.RangeTable{
- R16: []unicode.Range16{
- {Lo: 11, Hi: 13, Stride: 1},
- {Lo: 127, Hi: 160, Stride: 33},
- {Lo: 173, Hi: 847, Stride: 674},
- {Lo: 1564, Hi: 4447, Stride: 2883},
- {Lo: 4448, Hi: 6068, Stride: 1620},
- {Lo: 6069, Hi: 6155, Stride: 86},
- {Lo: 6156, Hi: 6158, Stride: 1},
- {Lo: 7355, Hi: 7356, Stride: 1},
- {Lo: 8192, Hi: 8207, Stride: 1},
- {Lo: 8234, Hi: 8239, Stride: 1},
- {Lo: 8287, Hi: 8303, Stride: 1},
- {Lo: 10240, Hi: 12288, Stride: 2048},
- {Lo: 12644, Hi: 65024, Stride: 52380},
- {Lo: 65025, Hi: 65039, Stride: 1},
- {Lo: 65279, Hi: 65440, Stride: 161},
- {Lo: 65520, Hi: 65528, Stride: 1},
- {Lo: 65532, Hi: 65532, Stride: 1},
- },
- R32: []unicode.Range32{
- {Lo: 78844, Hi: 119155, Stride: 40311},
- {Lo: 119156, Hi: 119162, Stride: 1},
- {Lo: 917504, Hi: 917631, Stride: 1},
- {Lo: 917760, Hi: 917999, Stride: 1},
- },
- LatinOffset: 2,
+func newInvisibleRangeTable() *unicode.RangeTable {
+ return &unicode.RangeTable{
+ R16: []unicode.Range16{
+ {Lo: 11, Hi: 13, Stride: 1},
+ {Lo: 127, Hi: 160, Stride: 33},
+ {Lo: 173, Hi: 847, Stride: 674},
+ {Lo: 1564, Hi: 4447, Stride: 2883},
+ {Lo: 4448, Hi: 6068, Stride: 1620},
+ {Lo: 6069, Hi: 6155, Stride: 86},
+ {Lo: 6156, Hi: 6158, Stride: 1},
+ {Lo: 7355, Hi: 7356, Stride: 1},
+ {Lo: 8192, Hi: 8207, Stride: 1},
+ {Lo: 8234, Hi: 8239, Stride: 1},
+ {Lo: 8287, Hi: 8303, Stride: 1},
+ {Lo: 10240, Hi: 12288, Stride: 2048},
+ {Lo: 12644, Hi: 65024, Stride: 52380},
+ {Lo: 65025, Hi: 65039, Stride: 1},
+ {Lo: 65279, Hi: 65440, Stride: 161},
+ {Lo: 65520, Hi: 65528, Stride: 1},
+ {Lo: 65532, Hi: 65532, Stride: 1},
+ },
+ R32: []unicode.Range32{
+ {Lo: 78844, Hi: 119155, Stride: 40311},
+ {Lo: 119156, Hi: 119162, Stride: 1},
+ {Lo: 917504, Hi: 917631, Stride: 1},
+ {Lo: 917760, Hi: 917999, Stride: 1},
+ },
+ LatinOffset: 2,
+ }
}
diff --git a/modules/commitstatus/commit_status.go b/modules/commitstatus/commit_status.go
index a0ab4e7186..9c6994249b 100644
--- a/modules/commitstatus/commit_status.go
+++ b/modules/commitstatus/commit_status.go
@@ -61,16 +61,17 @@ type CommitStatusStates []CommitStatusState //nolint:revive // export stutter
// According to https://docs.github.com/en/rest/commits/statuses?apiVersion=2022-11-28#get-the-combined-status-for-a-specific-reference
// > Additionally, a combined state is returned. The state is one of:
// > failure if any of the contexts report as error or failure
+// > failure if any of the contexts report as warning (Gitea specific behavior)
// > pending if there are no statuses or a context is pending
// > success if the latest status for all contexts is success
func (css CommitStatusStates) Combine() CommitStatusState {
successCnt := 0
for _, state := range css {
switch {
- case state.IsError() || state.IsFailure():
+ case state.IsError() || state.IsFailure() || state.IsWarning():
return CommitStatusFailure
case state.IsPending():
- case state.IsSuccess() || state.IsWarning() || state.IsSkipped():
+ case state.IsSuccess() || state.IsSkipped():
successCnt++
}
}
diff --git a/modules/commitstatus/commit_status_test.go b/modules/commitstatus/commit_status_test.go
index 10d8f20aa4..dc8f9ce1a5 100644
--- a/modules/commitstatus/commit_status_test.go
+++ b/modules/commitstatus/commit_status_test.go
@@ -41,7 +41,7 @@ func TestCombine(t *testing.T) {
{
name: "warning",
states: CommitStatusStates{CommitStatusWarning},
- expected: CommitStatusSuccess,
+ expected: CommitStatusFailure,
},
// 2 states
{
@@ -62,7 +62,7 @@ func TestCombine(t *testing.T) {
{
name: "pending and warning",
states: CommitStatusStates{CommitStatusPending, CommitStatusWarning},
- expected: CommitStatusPending,
+ expected: CommitStatusFailure,
},
{
name: "success and error",
@@ -77,7 +77,7 @@ func TestCombine(t *testing.T) {
{
name: "success and warning",
states: CommitStatusStates{CommitStatusSuccess, CommitStatusWarning},
- expected: CommitStatusSuccess,
+ expected: CommitStatusFailure,
},
{
name: "error and failure",
@@ -98,7 +98,7 @@ func TestCombine(t *testing.T) {
{
name: "pending, success and warning",
states: CommitStatusStates{CommitStatusPending, CommitStatusSuccess, CommitStatusWarning},
- expected: CommitStatusPending,
+ expected: CommitStatusFailure,
},
{
name: "pending, success and error",
@@ -133,7 +133,7 @@ func TestCombine(t *testing.T) {
{
name: "success, warning and skipped",
states: CommitStatusStates{CommitStatusSuccess, CommitStatusWarning, CommitStatusSkipped},
- expected: CommitStatusSuccess,
+ expected: CommitStatusFailure,
},
// All success
{
@@ -181,12 +181,12 @@ func TestCombine(t *testing.T) {
{
name: "mixed states with all success",
states: CommitStatusStates{CommitStatusSuccess, CommitStatusSuccess, CommitStatusPending, CommitStatusWarning},
- expected: CommitStatusPending,
+ expected: CommitStatusFailure,
},
{
name: "all success with warning",
states: CommitStatusStates{CommitStatusSuccess, CommitStatusSuccess, CommitStatusSuccess, CommitStatusWarning},
- expected: CommitStatusSuccess,
+ expected: CommitStatusFailure,
},
}
diff --git a/modules/dump/dumper.go b/modules/dump/dumper.go
index 02829d6a1e..2f16070704 100644
--- a/modules/dump/dumper.go
+++ b/modules/dump/dumper.go
@@ -4,6 +4,7 @@
package dump
import (
+ "archive/zip"
"context"
"errors"
"fmt"
@@ -85,7 +86,7 @@ func NewDumper(ctx context.Context, format string, output io.Writer) (*Dumper, e
var comp archives.ArchiverAsync
switch format {
case "zip":
- comp = archives.Zip{}
+ comp = archives.Zip{Compression: zip.Deflate}
case "tar":
comp = archives.Tar{}
case "tar.sz":
diff --git a/modules/emoji/emoji_data.go b/modules/emoji/emoji_data.go
index 8d0ae0a43e..ef25e3d9ea 100644
--- a/modules/emoji/emoji_data.go
+++ b/modules/emoji/emoji_data.go
@@ -4,7 +4,7 @@
package emoji
// Code generated by build/generate-emoji.go. DO NOT EDIT.
-// Sourced from https://raw.githubusercontent.com/github/gemoji/master/db/emoji.json
+// Sourced from https://raw.githubusercontent.com/rhysd/gemoji/537ff2d7e0496e9964824f7f73ec7ece88c9765a/db/emoji.json
var GemojiData = Gemoji{
{"\U0001f44d", "thumbs up", []string{"+1", "thumbsup"}, "6.0", true},
{"\U0001f44d\U0001f3ff", "thumbs up: Dark Skin Tone", []string{"+1_Dark_Skin_Tone"}, "12.0", false},
@@ -345,10 +345,12 @@ var GemojiData = Gemoji{
{"\U0001f1ee\U0001f1f4", "flag: British Indian Ocean Territory", []string{"british_indian_ocean_territory"}, "6.0", false},
{"\U0001f1fb\U0001f1ec", "flag: British Virgin Islands", []string{"british_virgin_islands"}, "6.0", false},
{"\U0001f966", "broccoli", []string{"broccoli"}, "11.0", false},
+ {"\u26d3\ufe0f\u200d\U0001f4a5", "broken chain", []string{"broken_chain"}, "15.1", false},
{"\U0001f494", "broken heart", []string{"broken_heart"}, "6.0", false},
{"\U0001f9f9", "broom", []string{"broom"}, "11.0", false},
{"\U0001f7e4", "brown circle", []string{"brown_circle"}, "12.0", false},
{"\U0001f90e", "brown heart", []string{"brown_heart"}, "12.0", false},
+ {"\U0001f344\u200d\U0001f7eb", "brown mushroom", []string{"brown_mushroom"}, "15.1", false},
{"\U0001f7eb", "brown square", []string{"brown_square"}, "12.0", false},
{"\U0001f1e7\U0001f1f3", "flag: Brunei", []string{"brunei"}, "6.0", false},
{"\U0001f9cb", "bubble tea", []string{"bubble_tea"}, "13.0", false},
@@ -838,6 +840,7 @@ var GemojiData = Gemoji{
{"\U0001f62e\u200d\U0001f4a8", "face exhaling", []string{"face_exhaling"}, "13.1", false},
{"\U0001f979", "face holding back tears", []string{"face_holding_back_tears"}, "14.0", false},
{"\U0001f636\u200d\U0001f32b\ufe0f", "face in clouds", []string{"face_in_clouds"}, "13.1", false},
+ {"\U0001fae9", "face with bags under eyes", []string{"face_with_bags_under_eyes"}, "16.0", false},
{"\U0001fae4", "face with diagonal mouth", []string{"face_with_diagonal_mouth"}, "14.0", false},
{"\U0001f915", "face with head-bandage", []string{"face_with_head_bandage"}, "8.0", false},
{"\U0001fae2", "face with open eyes and hand over mouth", []string{"face_with_open_eyes_and_hand_over_mouth"}, "14.0", false},
@@ -879,6 +882,10 @@ var GemojiData = Gemoji{
{"\U0001f1eb\U0001f1f0", "flag: Falkland Islands", []string{"falkland_islands"}, "6.0", false},
{"\U0001f342", "fallen leaf", []string{"fallen_leaf"}, "6.0", false},
{"\U0001f46a", "family", []string{"family"}, "6.0", false},
+ {"\U0001f9d1\u200d\U0001f9d1\u200d\U0001f9d2", "family: adult, adult, child", []string{"family_adult_adult_child"}, "15.1", false},
+ {"\U0001f9d1\u200d\U0001f9d1\u200d\U0001f9d2\u200d\U0001f9d2", "family: adult, adult, child, child", []string{"family_adult_adult_child_child"}, "15.1", false},
+ {"\U0001f9d1\u200d\U0001f9d2", "family: adult, child", []string{"family_adult_child"}, "15.1", false},
+ {"\U0001f9d1\u200d\U0001f9d2\u200d\U0001f9d2", "family: adult, child, child", []string{"family_adult_child_child"}, "15.1", false},
{"\U0001f468\u200d\U0001f466", "family: man, boy", []string{"family_man_boy"}, "6.0", false},
{"\U0001f468\u200d\U0001f466\u200d\U0001f466", "family: man, boy, boy", []string{"family_man_boy_boy"}, "6.0", false},
{"\U0001f468\u200d\U0001f467", "family: man, girl", []string{"family_man_girl"}, "6.0", false},
@@ -931,6 +938,7 @@ var GemojiData = Gemoji{
{"\U0001f4c1", "file folder", []string{"file_folder"}, "6.0", false},
{"\U0001f4fd\ufe0f", "film projector", []string{"film_projector"}, "7.0", false},
{"\U0001f39e\ufe0f", "film frames", []string{"film_strip"}, "7.0", false},
+ {"\U0001fac6", "fingerprint", []string{"fingerprint"}, "16.0", false},
{"\U0001f1eb\U0001f1ee", "flag: Finland", []string{"finland"}, "6.0", false},
{"\U0001f525", "fire", []string{"fire"}, "6.0", false},
{"\U0001f692", "fire engine", []string{"fire_engine"}, "6.0", false},
@@ -973,6 +981,7 @@ var GemojiData = Gemoji{
{"\U0001f91c\U0001f3fc", "right-facing fist: Medium-Light Skin Tone", []string{"fist_right_Medium-Light_Skin_Tone"}, "12.0", false},
{"\U0001f91c\U0001f3fd", "right-facing fist: Medium Skin Tone", []string{"fist_right_Medium_Skin_Tone"}, "12.0", false},
{"5\ufe0f\u20e3", "keycap: 5", []string{"five"}, "", false},
+ {"\U0001f1e8\U0001f1f6", "flag: Sark", []string{"flag_sark"}, "16.0", false},
{"\U0001f38f", "carp streamer", []string{"flags"}, "6.0", false},
{"\U0001f9a9", "flamingo", []string{"flamingo"}, "12.0", false},
{"\U0001f526", "flashlight", []string{"flashlight"}, "6.0", false},
@@ -1189,9 +1198,12 @@ var GemojiData = Gemoji{
{"\U0001f91d\U0001f3fc", "handshake: Medium-Light Skin Tone", []string{"handshake_Medium-Light_Skin_Tone"}, "12.0", false},
{"\U0001f91d\U0001f3fd", "handshake: Medium Skin Tone", []string{"handshake_Medium_Skin_Tone"}, "12.0", false},
{"\U0001f4a9", "pile of poo", []string{"hankey", "poop", "shit"}, "6.0", false},
+ {"\U0001fa89", "harp", []string{"harp"}, "16.0", false},
{"#\ufe0f\u20e3", "keycap: #", []string{"hash"}, "", false},
{"\U0001f425", "front-facing baby chick", []string{"hatched_chick"}, "6.0", false},
{"\U0001f423", "hatching chick", []string{"hatching_chick"}, "6.0", false},
+ {"\U0001f642\u200d\u2194\ufe0f", "head shaking horizontally", []string{"head_shaking_horizontally"}, "15.1", false},
+ {"\U0001f642\u200d\u2195\ufe0f", "head shaking vertically", []string{"head_shaking_vertically"}, "15.1", false},
{"\U0001f3a7", "headphone", []string{"headphones"}, "6.0", false},
{"\U0001faa6", "headstone", []string{"headstone"}, "13.0", false},
{"\U0001f9d1\u200d\u2695\ufe0f", "health worker", []string{"health_worker"}, "12.1", true},
@@ -1380,6 +1392,7 @@ var GemojiData = Gemoji{
{"\u271d\ufe0f", "latin cross", []string{"latin_cross"}, "", false},
{"\U0001f1f1\U0001f1fb", "flag: Latvia", []string{"latvia"}, "6.0", false},
{"\U0001f606", "grinning squinting face", []string{"laughing", "satisfied", "laugh"}, "6.0", false},
+ {"\U0001fabe", "leafless tree", []string{"leafless_tree"}, "16.0", false},
{"\U0001f96c", "leafy green", []string{"leafy_green"}, "11.0", false},
{"\U0001f343", "leaf fluttering in wind", []string{"leaves"}, "6.0", false},
{"\U0001f1f1\U0001f1e7", "flag: Lebanon", []string{"lebanon"}, "6.0", false},
@@ -1417,6 +1430,7 @@ var GemojiData = Gemoji{
{"\U0001f1f1\U0001f1ee", "flag: Liechtenstein", []string{"liechtenstein"}, "6.0", false},
{"\U0001fa75", "light blue heart", []string{"light_blue_heart"}, "15.0", false},
{"\U0001f688", "light rail", []string{"light_rail"}, "6.0", false},
+ {"\U0001f34b\u200d\U0001f7e9", "lime", []string{"lime"}, "15.1", false},
{"\U0001f517", "link", []string{"link"}, "6.0", false},
{"\U0001f981", "lion", []string{"lion"}, "8.0", false},
{"\U0001f444", "mouth", []string{"lips"}, "6.0", false},
@@ -1594,12 +1608,24 @@ var GemojiData = Gemoji{
{"\U0001f468\U0001f3fe\u200d\U0001f9bd", "man in manual wheelchair: Medium-Dark Skin Tone", []string{"man_in_manual_wheelchair_Medium-Dark_Skin_Tone"}, "12.0", false},
{"\U0001f468\U0001f3fc\u200d\U0001f9bd", "man in manual wheelchair: Medium-Light Skin Tone", []string{"man_in_manual_wheelchair_Medium-Light_Skin_Tone"}, "12.0", false},
{"\U0001f468\U0001f3fd\u200d\U0001f9bd", "man in manual wheelchair: Medium Skin Tone", []string{"man_in_manual_wheelchair_Medium_Skin_Tone"}, "12.0", false},
+ {"\U0001f468\u200d\U0001f9bd\u200d\u27a1\ufe0f", "man in manual wheelchair facing right", []string{"man_in_manual_wheelchair_facing_right"}, "15.1", true},
+ {"\U0001f468\U0001f3ff\u200d\U0001f9bd\u200d\u27a1\ufe0f", "man in manual wheelchair facing right: Dark Skin Tone", []string{"man_in_manual_wheelchair_facing_right_Dark_Skin_Tone"}, "12.0", false},
+ {"\U0001f468\U0001f3fb\u200d\U0001f9bd\u200d\u27a1\ufe0f", "man in manual wheelchair facing right: Light Skin Tone", []string{"man_in_manual_wheelchair_facing_right_Light_Skin_Tone"}, "12.0", false},
+ {"\U0001f468\U0001f3fe\u200d\U0001f9bd\u200d\u27a1\ufe0f", "man in manual wheelchair facing right: Medium-Dark Skin Tone", []string{"man_in_manual_wheelchair_facing_right_Medium-Dark_Skin_Tone"}, "12.0", false},
+ {"\U0001f468\U0001f3fc\u200d\U0001f9bd\u200d\u27a1\ufe0f", "man in manual wheelchair facing right: Medium-Light Skin Tone", []string{"man_in_manual_wheelchair_facing_right_Medium-Light_Skin_Tone"}, "12.0", false},
+ {"\U0001f468\U0001f3fd\u200d\U0001f9bd\u200d\u27a1\ufe0f", "man in manual wheelchair facing right: Medium Skin Tone", []string{"man_in_manual_wheelchair_facing_right_Medium_Skin_Tone"}, "12.0", false},
{"\U0001f468\u200d\U0001f9bc", "man in motorized wheelchair", []string{"man_in_motorized_wheelchair"}, "12.0", true},
{"\U0001f468\U0001f3ff\u200d\U0001f9bc", "man in motorized wheelchair: Dark Skin Tone", []string{"man_in_motorized_wheelchair_Dark_Skin_Tone"}, "12.0", false},
{"\U0001f468\U0001f3fb\u200d\U0001f9bc", "man in motorized wheelchair: Light Skin Tone", []string{"man_in_motorized_wheelchair_Light_Skin_Tone"}, "12.0", false},
{"\U0001f468\U0001f3fe\u200d\U0001f9bc", "man in motorized wheelchair: Medium-Dark Skin Tone", []string{"man_in_motorized_wheelchair_Medium-Dark_Skin_Tone"}, "12.0", false},
{"\U0001f468\U0001f3fc\u200d\U0001f9bc", "man in motorized wheelchair: Medium-Light Skin Tone", []string{"man_in_motorized_wheelchair_Medium-Light_Skin_Tone"}, "12.0", false},
{"\U0001f468\U0001f3fd\u200d\U0001f9bc", "man in motorized wheelchair: Medium Skin Tone", []string{"man_in_motorized_wheelchair_Medium_Skin_Tone"}, "12.0", false},
+ {"\U0001f468\u200d\U0001f9bc\u200d\u27a1\ufe0f", "man in motorized wheelchair facing right", []string{"man_in_motorized_wheelchair_facing_right"}, "15.1", true},
+ {"\U0001f468\U0001f3ff\u200d\U0001f9bc\u200d\u27a1\ufe0f", "man in motorized wheelchair facing right: Dark Skin Tone", []string{"man_in_motorized_wheelchair_facing_right_Dark_Skin_Tone"}, "12.0", false},
+ {"\U0001f468\U0001f3fb\u200d\U0001f9bc\u200d\u27a1\ufe0f", "man in motorized wheelchair facing right: Light Skin Tone", []string{"man_in_motorized_wheelchair_facing_right_Light_Skin_Tone"}, "12.0", false},
+ {"\U0001f468\U0001f3fe\u200d\U0001f9bc\u200d\u27a1\ufe0f", "man in motorized wheelchair facing right: Medium-Dark Skin Tone", []string{"man_in_motorized_wheelchair_facing_right_Medium-Dark_Skin_Tone"}, "12.0", false},
+ {"\U0001f468\U0001f3fc\u200d\U0001f9bc\u200d\u27a1\ufe0f", "man in motorized wheelchair facing right: Medium-Light Skin Tone", []string{"man_in_motorized_wheelchair_facing_right_Medium-Light_Skin_Tone"}, "12.0", false},
+ {"\U0001f468\U0001f3fd\u200d\U0001f9bc\u200d\u27a1\ufe0f", "man in motorized wheelchair facing right: Medium Skin Tone", []string{"man_in_motorized_wheelchair_facing_right_Medium_Skin_Tone"}, "12.0", false},
{"\U0001f935\u200d\u2642\ufe0f", "man in tuxedo", []string{"man_in_tuxedo"}, "13.0", true},
{"\U0001f935\U0001f3ff\u200d\u2642\ufe0f", "man in tuxedo: Dark Skin Tone", []string{"man_in_tuxedo_Dark_Skin_Tone"}, "12.0", false},
{"\U0001f935\U0001f3fb\u200d\u2642\ufe0f", "man in tuxedo: Light Skin Tone", []string{"man_in_tuxedo_Light_Skin_Tone"}, "12.0", false},
@@ -1618,6 +1644,12 @@ var GemojiData = Gemoji{
{"\U0001f939\U0001f3fe\u200d\u2642\ufe0f", "man juggling: Medium-Dark Skin Tone", []string{"man_juggling_Medium-Dark_Skin_Tone"}, "12.0", false},
{"\U0001f939\U0001f3fc\u200d\u2642\ufe0f", "man juggling: Medium-Light Skin Tone", []string{"man_juggling_Medium-Light_Skin_Tone"}, "12.0", false},
{"\U0001f939\U0001f3fd\u200d\u2642\ufe0f", "man juggling: Medium Skin Tone", []string{"man_juggling_Medium_Skin_Tone"}, "12.0", false},
+ {"\U0001f9ce\u200d\u2642\ufe0f\u200d\u27a1\ufe0f", "man kneeling facing right", []string{"man_kneeling_facing_right"}, "15.1", true},
+ {"\U0001f9ce\U0001f3ff\u200d\u2642\ufe0f\u200d\u27a1\ufe0f", "man kneeling facing right: Dark Skin Tone", []string{"man_kneeling_facing_right_Dark_Skin_Tone"}, "12.0", false},
+ {"\U0001f9ce\U0001f3fb\u200d\u2642\ufe0f\u200d\u27a1\ufe0f", "man kneeling facing right: Light Skin Tone", []string{"man_kneeling_facing_right_Light_Skin_Tone"}, "12.0", false},
+ {"\U0001f9ce\U0001f3fe\u200d\u2642\ufe0f\u200d\u27a1\ufe0f", "man kneeling facing right: Medium-Dark Skin Tone", []string{"man_kneeling_facing_right_Medium-Dark_Skin_Tone"}, "12.0", false},
+ {"\U0001f9ce\U0001f3fc\u200d\u2642\ufe0f\u200d\u27a1\ufe0f", "man kneeling facing right: Medium-Light Skin Tone", []string{"man_kneeling_facing_right_Medium-Light_Skin_Tone"}, "12.0", false},
+ {"\U0001f9ce\U0001f3fd\u200d\u2642\ufe0f\u200d\u27a1\ufe0f", "man kneeling facing right: Medium Skin Tone", []string{"man_kneeling_facing_right_Medium_Skin_Tone"}, "12.0", false},
{"\U0001f468\u200d\U0001f527", "man mechanic", []string{"man_mechanic"}, "", true},
{"\U0001f468\U0001f3ff\u200d\U0001f527", "man mechanic: Dark Skin Tone", []string{"man_mechanic_Dark_Skin_Tone"}, "12.0", false},
{"\U0001f468\U0001f3fb\u200d\U0001f527", "man mechanic: Light Skin Tone", []string{"man_mechanic_Light_Skin_Tone"}, "12.0", false},
@@ -1648,6 +1680,12 @@ var GemojiData = Gemoji{
{"\U0001f93d\U0001f3fe\u200d\u2642\ufe0f", "man playing water polo: Medium-Dark Skin Tone", []string{"man_playing_water_polo_Medium-Dark_Skin_Tone"}, "12.0", false},
{"\U0001f93d\U0001f3fc\u200d\u2642\ufe0f", "man playing water polo: Medium-Light Skin Tone", []string{"man_playing_water_polo_Medium-Light_Skin_Tone"}, "12.0", false},
{"\U0001f93d\U0001f3fd\u200d\u2642\ufe0f", "man playing water polo: Medium Skin Tone", []string{"man_playing_water_polo_Medium_Skin_Tone"}, "12.0", false},
+ {"\U0001f3c3\u200d\u2642\ufe0f\u200d\u27a1\ufe0f", "man running facing right", []string{"man_running_facing_right"}, "15.1", true},
+ {"\U0001f3c3\U0001f3ff\u200d\u2642\ufe0f\u200d\u27a1\ufe0f", "man running facing right: Dark Skin Tone", []string{"man_running_facing_right_Dark_Skin_Tone"}, "12.0", false},
+ {"\U0001f3c3\U0001f3fb\u200d\u2642\ufe0f\u200d\u27a1\ufe0f", "man running facing right: Light Skin Tone", []string{"man_running_facing_right_Light_Skin_Tone"}, "12.0", false},
+ {"\U0001f3c3\U0001f3fe\u200d\u2642\ufe0f\u200d\u27a1\ufe0f", "man running facing right: Medium-Dark Skin Tone", []string{"man_running_facing_right_Medium-Dark_Skin_Tone"}, "12.0", false},
+ {"\U0001f3c3\U0001f3fc\u200d\u2642\ufe0f\u200d\u27a1\ufe0f", "man running facing right: Medium-Light Skin Tone", []string{"man_running_facing_right_Medium-Light_Skin_Tone"}, "12.0", false},
+ {"\U0001f3c3\U0001f3fd\u200d\u2642\ufe0f\u200d\u27a1\ufe0f", "man running facing right: Medium Skin Tone", []string{"man_running_facing_right_Medium_Skin_Tone"}, "12.0", false},
{"\U0001f468\u200d\U0001f52c", "man scientist", []string{"man_scientist"}, "", true},
{"\U0001f468\U0001f3ff\u200d\U0001f52c", "man scientist: Dark Skin Tone", []string{"man_scientist_Dark_Skin_Tone"}, "12.0", false},
{"\U0001f468\U0001f3fb\u200d\U0001f52c", "man scientist: Light Skin Tone", []string{"man_scientist_Light_Skin_Tone"}, "12.0", false},
@@ -1684,6 +1722,12 @@ var GemojiData = Gemoji{
{"\U0001f468\U0001f3fe\u200d\U0001f4bb", "man technologist: Medium-Dark Skin Tone", []string{"man_technologist_Medium-Dark_Skin_Tone"}, "12.0", false},
{"\U0001f468\U0001f3fc\u200d\U0001f4bb", "man technologist: Medium-Light Skin Tone", []string{"man_technologist_Medium-Light_Skin_Tone"}, "12.0", false},
{"\U0001f468\U0001f3fd\u200d\U0001f4bb", "man technologist: Medium Skin Tone", []string{"man_technologist_Medium_Skin_Tone"}, "12.0", false},
+ {"\U0001f6b6\u200d\u2642\ufe0f\u200d\u27a1\ufe0f", "man walking facing right", []string{"man_walking_facing_right"}, "15.1", true},
+ {"\U0001f6b6\U0001f3ff\u200d\u2642\ufe0f\u200d\u27a1\ufe0f", "man walking facing right: Dark Skin Tone", []string{"man_walking_facing_right_Dark_Skin_Tone"}, "12.0", false},
+ {"\U0001f6b6\U0001f3fb\u200d\u2642\ufe0f\u200d\u27a1\ufe0f", "man walking facing right: Light Skin Tone", []string{"man_walking_facing_right_Light_Skin_Tone"}, "12.0", false},
+ {"\U0001f6b6\U0001f3fe\u200d\u2642\ufe0f\u200d\u27a1\ufe0f", "man walking facing right: Medium-Dark Skin Tone", []string{"man_walking_facing_right_Medium-Dark_Skin_Tone"}, "12.0", false},
+ {"\U0001f6b6\U0001f3fc\u200d\u2642\ufe0f\u200d\u27a1\ufe0f", "man walking facing right: Medium-Light Skin Tone", []string{"man_walking_facing_right_Medium-Light_Skin_Tone"}, "12.0", false},
+ {"\U0001f6b6\U0001f3fd\u200d\u2642\ufe0f\u200d\u27a1\ufe0f", "man walking facing right: Medium Skin Tone", []string{"man_walking_facing_right_Medium_Skin_Tone"}, "12.0", false},
{"\U0001f472", "person with skullcap", []string{"man_with_gua_pi_mao"}, "6.0", true},
{"\U0001f472\U0001f3ff", "person with skullcap: Dark Skin Tone", []string{"man_with_gua_pi_mao_Dark_Skin_Tone"}, "12.0", false},
{"\U0001f472\U0001f3fb", "person with skullcap: Light Skin Tone", []string{"man_with_gua_pi_mao_Light_Skin_Tone"}, "12.0", false},
@@ -1708,6 +1752,12 @@ var GemojiData = Gemoji{
{"\U0001f470\U0001f3fe\u200d\u2642\ufe0f", "man with veil: Medium-Dark Skin Tone", []string{"man_with_veil_Medium-Dark_Skin_Tone"}, "12.0", false},
{"\U0001f470\U0001f3fc\u200d\u2642\ufe0f", "man with veil: Medium-Light Skin Tone", []string{"man_with_veil_Medium-Light_Skin_Tone"}, "12.0", false},
{"\U0001f470\U0001f3fd\u200d\u2642\ufe0f", "man with veil: Medium Skin Tone", []string{"man_with_veil_Medium_Skin_Tone"}, "12.0", false},
+ {"\U0001f468\u200d\U0001f9af\u200d\u27a1\ufe0f", "man with white cane facing right", []string{"man_with_white_cane_facing_right"}, "15.1", true},
+ {"\U0001f468\U0001f3ff\u200d\U0001f9af\u200d\u27a1\ufe0f", "man with white cane facing right: Dark Skin Tone", []string{"man_with_white_cane_facing_right_Dark_Skin_Tone"}, "12.0", false},
+ {"\U0001f468\U0001f3fb\u200d\U0001f9af\u200d\u27a1\ufe0f", "man with white cane facing right: Light Skin Tone", []string{"man_with_white_cane_facing_right_Light_Skin_Tone"}, "12.0", false},
+ {"\U0001f468\U0001f3fe\u200d\U0001f9af\u200d\u27a1\ufe0f", "man with white cane facing right: Medium-Dark Skin Tone", []string{"man_with_white_cane_facing_right_Medium-Dark_Skin_Tone"}, "12.0", false},
+ {"\U0001f468\U0001f3fc\u200d\U0001f9af\u200d\u27a1\ufe0f", "man with white cane facing right: Medium-Light Skin Tone", []string{"man_with_white_cane_facing_right_Medium-Light_Skin_Tone"}, "12.0", false},
+ {"\U0001f468\U0001f3fd\u200d\U0001f9af\u200d\u27a1\ufe0f", "man with white cane facing right: Medium Skin Tone", []string{"man_with_white_cane_facing_right_Medium_Skin_Tone"}, "12.0", false},
{"\U0001f96d", "mango", []string{"mango"}, "11.0", false},
{"\U0001f45e", "man’s shoe", []string{"mans_shoe", "shoe"}, "6.0", false},
{"\U0001f570\ufe0f", "mantelpiece clock", []string{"mantelpiece_clock"}, "7.0", false},
@@ -1874,12 +1924,12 @@ var GemojiData = Gemoji{
{"\U0001f3b5", "musical note", []string{"musical_note"}, "6.0", false},
{"\U0001f3bc", "musical score", []string{"musical_score"}, "6.0", false},
{"\U0001f507", "muted speaker", []string{"mute"}, "6.0", false},
- {"\U0001f9d1\u200d\U0001f384", "mx claus", []string{"mx_claus"}, "13.0", true},
- {"\U0001f9d1\U0001f3ff\u200d\U0001f384", "mx claus: Dark Skin Tone", []string{"mx_claus_Dark_Skin_Tone"}, "12.0", false},
- {"\U0001f9d1\U0001f3fb\u200d\U0001f384", "mx claus: Light Skin Tone", []string{"mx_claus_Light_Skin_Tone"}, "12.0", false},
- {"\U0001f9d1\U0001f3fe\u200d\U0001f384", "mx claus: Medium-Dark Skin Tone", []string{"mx_claus_Medium-Dark_Skin_Tone"}, "12.0", false},
- {"\U0001f9d1\U0001f3fc\u200d\U0001f384", "mx claus: Medium-Light Skin Tone", []string{"mx_claus_Medium-Light_Skin_Tone"}, "12.0", false},
- {"\U0001f9d1\U0001f3fd\u200d\U0001f384", "mx claus: Medium Skin Tone", []string{"mx_claus_Medium_Skin_Tone"}, "12.0", false},
+ {"\U0001f9d1\u200d\U0001f384", "Mx Claus", []string{"mx_claus"}, "13.0", true},
+ {"\U0001f9d1\U0001f3ff\u200d\U0001f384", "Mx Claus: Dark Skin Tone", []string{"mx_claus_Dark_Skin_Tone"}, "12.0", false},
+ {"\U0001f9d1\U0001f3fb\u200d\U0001f384", "Mx Claus: Light Skin Tone", []string{"mx_claus_Light_Skin_Tone"}, "12.0", false},
+ {"\U0001f9d1\U0001f3fe\u200d\U0001f384", "Mx Claus: Medium-Dark Skin Tone", []string{"mx_claus_Medium-Dark_Skin_Tone"}, "12.0", false},
+ {"\U0001f9d1\U0001f3fc\u200d\U0001f384", "Mx Claus: Medium-Light Skin Tone", []string{"mx_claus_Medium-Light_Skin_Tone"}, "12.0", false},
+ {"\U0001f9d1\U0001f3fd\u200d\U0001f384", "Mx Claus: Medium Skin Tone", []string{"mx_claus_Medium_Skin_Tone"}, "12.0", false},
{"\U0001f1f2\U0001f1f2", "flag: Myanmar (Burma)", []string{"myanmar"}, "6.0", false},
{"\U0001f485", "nail polish", []string{"nail_care"}, "6.0", true},
{"\U0001f485\U0001f3ff", "nail polish: Dark Skin Tone", []string{"nail_care_Dark_Skin_Tone"}, "12.0", false},
@@ -2140,24 +2190,54 @@ var GemojiData = Gemoji{
{"\U0001f9d1\U0001f3fe\u200d\U0001f9bd", "person in manual wheelchair: Medium-Dark Skin Tone", []string{"person_in_manual_wheelchair_Medium-Dark_Skin_Tone"}, "12.0", false},
{"\U0001f9d1\U0001f3fc\u200d\U0001f9bd", "person in manual wheelchair: Medium-Light Skin Tone", []string{"person_in_manual_wheelchair_Medium-Light_Skin_Tone"}, "12.0", false},
{"\U0001f9d1\U0001f3fd\u200d\U0001f9bd", "person in manual wheelchair: Medium Skin Tone", []string{"person_in_manual_wheelchair_Medium_Skin_Tone"}, "12.0", false},
+ {"\U0001f9d1\u200d\U0001f9bd\u200d\u27a1\ufe0f", "person in manual wheelchair facing right", []string{"person_in_manual_wheelchair_facing_right"}, "15.1", true},
+ {"\U0001f9d1\U0001f3ff\u200d\U0001f9bd\u200d\u27a1\ufe0f", "person in manual wheelchair facing right: Dark Skin Tone", []string{"person_in_manual_wheelchair_facing_right_Dark_Skin_Tone"}, "12.0", false},
+ {"\U0001f9d1\U0001f3fb\u200d\U0001f9bd\u200d\u27a1\ufe0f", "person in manual wheelchair facing right: Light Skin Tone", []string{"person_in_manual_wheelchair_facing_right_Light_Skin_Tone"}, "12.0", false},
+ {"\U0001f9d1\U0001f3fe\u200d\U0001f9bd\u200d\u27a1\ufe0f", "person in manual wheelchair facing right: Medium-Dark Skin Tone", []string{"person_in_manual_wheelchair_facing_right_Medium-Dark_Skin_Tone"}, "12.0", false},
+ {"\U0001f9d1\U0001f3fc\u200d\U0001f9bd\u200d\u27a1\ufe0f", "person in manual wheelchair facing right: Medium-Light Skin Tone", []string{"person_in_manual_wheelchair_facing_right_Medium-Light_Skin_Tone"}, "12.0", false},
+ {"\U0001f9d1\U0001f3fd\u200d\U0001f9bd\u200d\u27a1\ufe0f", "person in manual wheelchair facing right: Medium Skin Tone", []string{"person_in_manual_wheelchair_facing_right_Medium_Skin_Tone"}, "12.0", false},
{"\U0001f9d1\u200d\U0001f9bc", "person in motorized wheelchair", []string{"person_in_motorized_wheelchair"}, "12.1", true},
{"\U0001f9d1\U0001f3ff\u200d\U0001f9bc", "person in motorized wheelchair: Dark Skin Tone", []string{"person_in_motorized_wheelchair_Dark_Skin_Tone"}, "12.0", false},
{"\U0001f9d1\U0001f3fb\u200d\U0001f9bc", "person in motorized wheelchair: Light Skin Tone", []string{"person_in_motorized_wheelchair_Light_Skin_Tone"}, "12.0", false},
{"\U0001f9d1\U0001f3fe\u200d\U0001f9bc", "person in motorized wheelchair: Medium-Dark Skin Tone", []string{"person_in_motorized_wheelchair_Medium-Dark_Skin_Tone"}, "12.0", false},
{"\U0001f9d1\U0001f3fc\u200d\U0001f9bc", "person in motorized wheelchair: Medium-Light Skin Tone", []string{"person_in_motorized_wheelchair_Medium-Light_Skin_Tone"}, "12.0", false},
{"\U0001f9d1\U0001f3fd\u200d\U0001f9bc", "person in motorized wheelchair: Medium Skin Tone", []string{"person_in_motorized_wheelchair_Medium_Skin_Tone"}, "12.0", false},
+ {"\U0001f9d1\u200d\U0001f9bc\u200d\u27a1\ufe0f", "person in motorized wheelchair facing right", []string{"person_in_motorized_wheelchair_facing_right"}, "15.1", true},
+ {"\U0001f9d1\U0001f3ff\u200d\U0001f9bc\u200d\u27a1\ufe0f", "person in motorized wheelchair facing right: Dark Skin Tone", []string{"person_in_motorized_wheelchair_facing_right_Dark_Skin_Tone"}, "12.0", false},
+ {"\U0001f9d1\U0001f3fb\u200d\U0001f9bc\u200d\u27a1\ufe0f", "person in motorized wheelchair facing right: Light Skin Tone", []string{"person_in_motorized_wheelchair_facing_right_Light_Skin_Tone"}, "12.0", false},
+ {"\U0001f9d1\U0001f3fe\u200d\U0001f9bc\u200d\u27a1\ufe0f", "person in motorized wheelchair facing right: Medium-Dark Skin Tone", []string{"person_in_motorized_wheelchair_facing_right_Medium-Dark_Skin_Tone"}, "12.0", false},
+ {"\U0001f9d1\U0001f3fc\u200d\U0001f9bc\u200d\u27a1\ufe0f", "person in motorized wheelchair facing right: Medium-Light Skin Tone", []string{"person_in_motorized_wheelchair_facing_right_Medium-Light_Skin_Tone"}, "12.0", false},
+ {"\U0001f9d1\U0001f3fd\u200d\U0001f9bc\u200d\u27a1\ufe0f", "person in motorized wheelchair facing right: Medium Skin Tone", []string{"person_in_motorized_wheelchair_facing_right_Medium_Skin_Tone"}, "12.0", false},
{"\U0001f935", "person in tuxedo", []string{"person_in_tuxedo"}, "9.0", true},
{"\U0001f935\U0001f3ff", "person in tuxedo: Dark Skin Tone", []string{"person_in_tuxedo_Dark_Skin_Tone"}, "12.0", false},
{"\U0001f935\U0001f3fb", "person in tuxedo: Light Skin Tone", []string{"person_in_tuxedo_Light_Skin_Tone"}, "12.0", false},
{"\U0001f935\U0001f3fe", "person in tuxedo: Medium-Dark Skin Tone", []string{"person_in_tuxedo_Medium-Dark_Skin_Tone"}, "12.0", false},
{"\U0001f935\U0001f3fc", "person in tuxedo: Medium-Light Skin Tone", []string{"person_in_tuxedo_Medium-Light_Skin_Tone"}, "12.0", false},
{"\U0001f935\U0001f3fd", "person in tuxedo: Medium Skin Tone", []string{"person_in_tuxedo_Medium_Skin_Tone"}, "12.0", false},
+ {"\U0001f9ce\u200d\u27a1\ufe0f", "person kneeling facing right", []string{"person_kneeling_facing_right"}, "15.1", true},
+ {"\U0001f9ce\U0001f3ff\u200d\u27a1\ufe0f", "person kneeling facing right: Dark Skin Tone", []string{"person_kneeling_facing_right_Dark_Skin_Tone"}, "12.0", false},
+ {"\U0001f9ce\U0001f3fb\u200d\u27a1\ufe0f", "person kneeling facing right: Light Skin Tone", []string{"person_kneeling_facing_right_Light_Skin_Tone"}, "12.0", false},
+ {"\U0001f9ce\U0001f3fe\u200d\u27a1\ufe0f", "person kneeling facing right: Medium-Dark Skin Tone", []string{"person_kneeling_facing_right_Medium-Dark_Skin_Tone"}, "12.0", false},
+ {"\U0001f9ce\U0001f3fc\u200d\u27a1\ufe0f", "person kneeling facing right: Medium-Light Skin Tone", []string{"person_kneeling_facing_right_Medium-Light_Skin_Tone"}, "12.0", false},
+ {"\U0001f9ce\U0001f3fd\u200d\u27a1\ufe0f", "person kneeling facing right: Medium Skin Tone", []string{"person_kneeling_facing_right_Medium_Skin_Tone"}, "12.0", false},
{"\U0001f9d1\u200d\U0001f9b0", "person: red hair", []string{"person_red_hair"}, "12.1", true},
{"\U0001f9d1\U0001f3ff\u200d\U0001f9b0", "person: red hair: Dark Skin Tone", []string{"person_red_hair_Dark_Skin_Tone"}, "12.0", false},
{"\U0001f9d1\U0001f3fb\u200d\U0001f9b0", "person: red hair: Light Skin Tone", []string{"person_red_hair_Light_Skin_Tone"}, "12.0", false},
{"\U0001f9d1\U0001f3fe\u200d\U0001f9b0", "person: red hair: Medium-Dark Skin Tone", []string{"person_red_hair_Medium-Dark_Skin_Tone"}, "12.0", false},
{"\U0001f9d1\U0001f3fc\u200d\U0001f9b0", "person: red hair: Medium-Light Skin Tone", []string{"person_red_hair_Medium-Light_Skin_Tone"}, "12.0", false},
{"\U0001f9d1\U0001f3fd\u200d\U0001f9b0", "person: red hair: Medium Skin Tone", []string{"person_red_hair_Medium_Skin_Tone"}, "12.0", false},
+ {"\U0001f3c3\u200d\u27a1\ufe0f", "person running facing right", []string{"person_running_facing_right"}, "15.1", true},
+ {"\U0001f3c3\U0001f3ff\u200d\u27a1\ufe0f", "person running facing right: Dark Skin Tone", []string{"person_running_facing_right_Dark_Skin_Tone"}, "12.0", false},
+ {"\U0001f3c3\U0001f3fb\u200d\u27a1\ufe0f", "person running facing right: Light Skin Tone", []string{"person_running_facing_right_Light_Skin_Tone"}, "12.0", false},
+ {"\U0001f3c3\U0001f3fe\u200d\u27a1\ufe0f", "person running facing right: Medium-Dark Skin Tone", []string{"person_running_facing_right_Medium-Dark_Skin_Tone"}, "12.0", false},
+ {"\U0001f3c3\U0001f3fc\u200d\u27a1\ufe0f", "person running facing right: Medium-Light Skin Tone", []string{"person_running_facing_right_Medium-Light_Skin_Tone"}, "12.0", false},
+ {"\U0001f3c3\U0001f3fd\u200d\u27a1\ufe0f", "person running facing right: Medium Skin Tone", []string{"person_running_facing_right_Medium_Skin_Tone"}, "12.0", false},
+ {"\U0001f6b6\u200d\u27a1\ufe0f", "person walking facing right", []string{"person_walking_facing_right"}, "15.1", true},
+ {"\U0001f6b6\U0001f3ff\u200d\u27a1\ufe0f", "person walking facing right: Dark Skin Tone", []string{"person_walking_facing_right_Dark_Skin_Tone"}, "12.0", false},
+ {"\U0001f6b6\U0001f3fb\u200d\u27a1\ufe0f", "person walking facing right: Light Skin Tone", []string{"person_walking_facing_right_Light_Skin_Tone"}, "12.0", false},
+ {"\U0001f6b6\U0001f3fe\u200d\u27a1\ufe0f", "person walking facing right: Medium-Dark Skin Tone", []string{"person_walking_facing_right_Medium-Dark_Skin_Tone"}, "12.0", false},
+ {"\U0001f6b6\U0001f3fc\u200d\u27a1\ufe0f", "person walking facing right: Medium-Light Skin Tone", []string{"person_walking_facing_right_Medium-Light_Skin_Tone"}, "12.0", false},
+ {"\U0001f6b6\U0001f3fd\u200d\u27a1\ufe0f", "person walking facing right: Medium Skin Tone", []string{"person_walking_facing_right_Medium_Skin_Tone"}, "12.0", false},
{"\U0001f9d1\u200d\U0001f9b3", "person: white hair", []string{"person_white_hair"}, "12.1", true},
{"\U0001f9d1\U0001f3ff\u200d\U0001f9b3", "person: white hair: Dark Skin Tone", []string{"person_white_hair_Dark_Skin_Tone"}, "12.0", false},
{"\U0001f9d1\U0001f3fb\u200d\U0001f9b3", "person: white hair: Light Skin Tone", []string{"person_white_hair_Light_Skin_Tone"}, "12.0", false},
@@ -2188,9 +2268,16 @@ var GemojiData = Gemoji{
{"\U0001f470\U0001f3fe", "person with veil: Medium-Dark Skin Tone", []string{"person_with_veil_Medium-Dark_Skin_Tone"}, "12.0", false},
{"\U0001f470\U0001f3fc", "person with veil: Medium-Light Skin Tone", []string{"person_with_veil_Medium-Light_Skin_Tone"}, "12.0", false},
{"\U0001f470\U0001f3fd", "person with veil: Medium Skin Tone", []string{"person_with_veil_Medium_Skin_Tone"}, "12.0", false},
+ {"\U0001f9d1\u200d\U0001f9af\u200d\u27a1\ufe0f", "person with white cane facing right", []string{"person_with_white_cane_facing_right"}, "15.1", true},
+ {"\U0001f9d1\U0001f3ff\u200d\U0001f9af\u200d\u27a1\ufe0f", "person with white cane facing right: Dark Skin Tone", []string{"person_with_white_cane_facing_right_Dark_Skin_Tone"}, "12.0", false},
+ {"\U0001f9d1\U0001f3fb\u200d\U0001f9af\u200d\u27a1\ufe0f", "person with white cane facing right: Light Skin Tone", []string{"person_with_white_cane_facing_right_Light_Skin_Tone"}, "12.0", false},
+ {"\U0001f9d1\U0001f3fe\u200d\U0001f9af\u200d\u27a1\ufe0f", "person with white cane facing right: Medium-Dark Skin Tone", []string{"person_with_white_cane_facing_right_Medium-Dark_Skin_Tone"}, "12.0", false},
+ {"\U0001f9d1\U0001f3fc\u200d\U0001f9af\u200d\u27a1\ufe0f", "person with white cane facing right: Medium-Light Skin Tone", []string{"person_with_white_cane_facing_right_Medium-Light_Skin_Tone"}, "12.0", false},
+ {"\U0001f9d1\U0001f3fd\u200d\U0001f9af\u200d\u27a1\ufe0f", "person with white cane facing right: Medium Skin Tone", []string{"person_with_white_cane_facing_right_Medium_Skin_Tone"}, "12.0", false},
{"\U0001f1f5\U0001f1ea", "flag: Peru", []string{"peru"}, "6.0", false},
{"\U0001f9eb", "petri dish", []string{"petri_dish"}, "11.0", false},
{"\U0001f1f5\U0001f1ed", "flag: Philippines", []string{"philippines"}, "6.0", false},
+ {"\U0001f426\u200d\U0001f525", "phoenix", []string{"phoenix"}, "15.1", false},
{"\u260e\ufe0f", "telephone", []string{"phone", "telephone"}, "", false},
{"\u26cf\ufe0f", "pick", []string{"pick"}, "5.2", false},
{"\U0001f6fb", "pickup truck", []string{"pickup_truck"}, "13.0", false},
@@ -2480,6 +2567,7 @@ var GemojiData = Gemoji{
{"\U0001f6fc", "roller skate", []string{"roller_skate"}, "13.0", false},
{"\U0001f1f7\U0001f1f4", "flag: Romania", []string{"romania"}, "6.0", false},
{"\U0001f413", "rooster", []string{"rooster"}, "6.0", false},
+ {"\U0001fadc", "root vegetable", []string{"root_vegetable"}, "16.0", false},
{"\U0001f339", "rose", []string{"rose"}, "6.0", false},
{"\U0001f3f5\ufe0f", "rosette", []string{"rosette"}, "7.0", false},
{"\U0001f6a8", "police car light", []string{"rotating_light"}, "6.0", false},
@@ -2613,6 +2701,7 @@ var GemojiData = Gemoji{
{"\U0001f6cd\ufe0f", "shopping bags", []string{"shopping"}, "7.0", false},
{"\U0001f6d2", "shopping cart", []string{"shopping_cart"}, "9.0", false},
{"\U0001fa73", "shorts", []string{"shorts"}, "12.0", false},
+ {"\U0001fa8f", "shovel", []string{"shovel"}, "16.0", false},
{"\U0001f6bf", "shower", []string{"shower"}, "6.0", false},
{"\U0001f990", "shrimp", []string{"shrimp"}, "9.0", false},
{"\U0001f937", "person shrugging", []string{"shrug"}, "11.0", true},
@@ -2711,6 +2800,7 @@ var GemojiData = Gemoji{
{"\U0001f578\ufe0f", "spider web", []string{"spider_web"}, "7.0", false},
{"\U0001f5d3\ufe0f", "spiral calendar", []string{"spiral_calendar"}, "7.0", false},
{"\U0001f5d2\ufe0f", "spiral notepad", []string{"spiral_notepad"}, "7.0", false},
+ {"\U0001fadf", "splatter", []string{"splatter"}, "16.0", false},
{"\U0001f9fd", "sponge", []string{"sponge"}, "11.0", false},
{"\U0001f944", "spoon", []string{"spoon"}, "9.0", false},
{"\U0001f991", "squid", []string{"squid"}, "9.0", false},
@@ -2945,7 +3035,7 @@ var GemojiData = Gemoji{
{"\U0001f51d", "TOP arrow", []string{"top"}, "6.0", false},
{"\U0001f3a9", "top hat", []string{"tophat"}, "6.0", false},
{"\U0001f32a\ufe0f", "tornado", []string{"tornado"}, "7.0", false},
- {"\U0001f1f9\U0001f1f7", "flag: Turkey", []string{"tr"}, "8.0", false},
+ {"\U0001f1f9\U0001f1f7", "flag: Türkiye", []string{"tr"}, "8.0", false},
{"\U0001f5b2\ufe0f", "trackball", []string{"trackball"}, "7.0", false},
{"\U0001f69c", "tractor", []string{"tractor"}, "6.0", false},
{"\U0001f6a5", "horizontal traffic light", []string{"traffic_light"}, "6.0", false},
@@ -3247,12 +3337,24 @@ var GemojiData = Gemoji{
{"\U0001f469\U0001f3fe\u200d\U0001f9bd", "woman in manual wheelchair: Medium-Dark Skin Tone", []string{"woman_in_manual_wheelchair_Medium-Dark_Skin_Tone"}, "12.0", false},
{"\U0001f469\U0001f3fc\u200d\U0001f9bd", "woman in manual wheelchair: Medium-Light Skin Tone", []string{"woman_in_manual_wheelchair_Medium-Light_Skin_Tone"}, "12.0", false},
{"\U0001f469\U0001f3fd\u200d\U0001f9bd", "woman in manual wheelchair: Medium Skin Tone", []string{"woman_in_manual_wheelchair_Medium_Skin_Tone"}, "12.0", false},
+ {"\U0001f469\u200d\U0001f9bd\u200d\u27a1\ufe0f", "woman in manual wheelchair facing right", []string{"woman_in_manual_wheelchair_facing_right"}, "15.1", true},
+ {"\U0001f469\U0001f3ff\u200d\U0001f9bd\u200d\u27a1\ufe0f", "woman in manual wheelchair facing right: Dark Skin Tone", []string{"woman_in_manual_wheelchair_facing_right_Dark_Skin_Tone"}, "12.0", false},
+ {"\U0001f469\U0001f3fb\u200d\U0001f9bd\u200d\u27a1\ufe0f", "woman in manual wheelchair facing right: Light Skin Tone", []string{"woman_in_manual_wheelchair_facing_right_Light_Skin_Tone"}, "12.0", false},
+ {"\U0001f469\U0001f3fe\u200d\U0001f9bd\u200d\u27a1\ufe0f", "woman in manual wheelchair facing right: Medium-Dark Skin Tone", []string{"woman_in_manual_wheelchair_facing_right_Medium-Dark_Skin_Tone"}, "12.0", false},
+ {"\U0001f469\U0001f3fc\u200d\U0001f9bd\u200d\u27a1\ufe0f", "woman in manual wheelchair facing right: Medium-Light Skin Tone", []string{"woman_in_manual_wheelchair_facing_right_Medium-Light_Skin_Tone"}, "12.0", false},
+ {"\U0001f469\U0001f3fd\u200d\U0001f9bd\u200d\u27a1\ufe0f", "woman in manual wheelchair facing right: Medium Skin Tone", []string{"woman_in_manual_wheelchair_facing_right_Medium_Skin_Tone"}, "12.0", false},
{"\U0001f469\u200d\U0001f9bc", "woman in motorized wheelchair", []string{"woman_in_motorized_wheelchair"}, "12.0", true},
{"\U0001f469\U0001f3ff\u200d\U0001f9bc", "woman in motorized wheelchair: Dark Skin Tone", []string{"woman_in_motorized_wheelchair_Dark_Skin_Tone"}, "12.0", false},
{"\U0001f469\U0001f3fb\u200d\U0001f9bc", "woman in motorized wheelchair: Light Skin Tone", []string{"woman_in_motorized_wheelchair_Light_Skin_Tone"}, "12.0", false},
{"\U0001f469\U0001f3fe\u200d\U0001f9bc", "woman in motorized wheelchair: Medium-Dark Skin Tone", []string{"woman_in_motorized_wheelchair_Medium-Dark_Skin_Tone"}, "12.0", false},
{"\U0001f469\U0001f3fc\u200d\U0001f9bc", "woman in motorized wheelchair: Medium-Light Skin Tone", []string{"woman_in_motorized_wheelchair_Medium-Light_Skin_Tone"}, "12.0", false},
{"\U0001f469\U0001f3fd\u200d\U0001f9bc", "woman in motorized wheelchair: Medium Skin Tone", []string{"woman_in_motorized_wheelchair_Medium_Skin_Tone"}, "12.0", false},
+ {"\U0001f469\u200d\U0001f9bc\u200d\u27a1\ufe0f", "woman in motorized wheelchair facing right", []string{"woman_in_motorized_wheelchair_facing_right"}, "15.1", true},
+ {"\U0001f469\U0001f3ff\u200d\U0001f9bc\u200d\u27a1\ufe0f", "woman in motorized wheelchair facing right: Dark Skin Tone", []string{"woman_in_motorized_wheelchair_facing_right_Dark_Skin_Tone"}, "12.0", false},
+ {"\U0001f469\U0001f3fb\u200d\U0001f9bc\u200d\u27a1\ufe0f", "woman in motorized wheelchair facing right: Light Skin Tone", []string{"woman_in_motorized_wheelchair_facing_right_Light_Skin_Tone"}, "12.0", false},
+ {"\U0001f469\U0001f3fe\u200d\U0001f9bc\u200d\u27a1\ufe0f", "woman in motorized wheelchair facing right: Medium-Dark Skin Tone", []string{"woman_in_motorized_wheelchair_facing_right_Medium-Dark_Skin_Tone"}, "12.0", false},
+ {"\U0001f469\U0001f3fc\u200d\U0001f9bc\u200d\u27a1\ufe0f", "woman in motorized wheelchair facing right: Medium-Light Skin Tone", []string{"woman_in_motorized_wheelchair_facing_right_Medium-Light_Skin_Tone"}, "12.0", false},
+ {"\U0001f469\U0001f3fd\u200d\U0001f9bc\u200d\u27a1\ufe0f", "woman in motorized wheelchair facing right: Medium Skin Tone", []string{"woman_in_motorized_wheelchair_facing_right_Medium_Skin_Tone"}, "12.0", false},
{"\U0001f935\u200d\u2640\ufe0f", "woman in tuxedo", []string{"woman_in_tuxedo"}, "13.0", true},
{"\U0001f935\U0001f3ff\u200d\u2640\ufe0f", "woman in tuxedo: Dark Skin Tone", []string{"woman_in_tuxedo_Dark_Skin_Tone"}, "12.0", false},
{"\U0001f935\U0001f3fb\u200d\u2640\ufe0f", "woman in tuxedo: Light Skin Tone", []string{"woman_in_tuxedo_Light_Skin_Tone"}, "12.0", false},
@@ -3271,6 +3373,12 @@ var GemojiData = Gemoji{
{"\U0001f939\U0001f3fe\u200d\u2640\ufe0f", "woman juggling: Medium-Dark Skin Tone", []string{"woman_juggling_Medium-Dark_Skin_Tone"}, "12.0", false},
{"\U0001f939\U0001f3fc\u200d\u2640\ufe0f", "woman juggling: Medium-Light Skin Tone", []string{"woman_juggling_Medium-Light_Skin_Tone"}, "12.0", false},
{"\U0001f939\U0001f3fd\u200d\u2640\ufe0f", "woman juggling: Medium Skin Tone", []string{"woman_juggling_Medium_Skin_Tone"}, "12.0", false},
+ {"\U0001f9ce\u200d\u2640\ufe0f\u200d\u27a1\ufe0f", "woman kneeling facing right", []string{"woman_kneeling_facing_right"}, "15.1", true},
+ {"\U0001f9ce\U0001f3ff\u200d\u2640\ufe0f\u200d\u27a1\ufe0f", "woman kneeling facing right: Dark Skin Tone", []string{"woman_kneeling_facing_right_Dark_Skin_Tone"}, "12.0", false},
+ {"\U0001f9ce\U0001f3fb\u200d\u2640\ufe0f\u200d\u27a1\ufe0f", "woman kneeling facing right: Light Skin Tone", []string{"woman_kneeling_facing_right_Light_Skin_Tone"}, "12.0", false},
+ {"\U0001f9ce\U0001f3fe\u200d\u2640\ufe0f\u200d\u27a1\ufe0f", "woman kneeling facing right: Medium-Dark Skin Tone", []string{"woman_kneeling_facing_right_Medium-Dark_Skin_Tone"}, "12.0", false},
+ {"\U0001f9ce\U0001f3fc\u200d\u2640\ufe0f\u200d\u27a1\ufe0f", "woman kneeling facing right: Medium-Light Skin Tone", []string{"woman_kneeling_facing_right_Medium-Light_Skin_Tone"}, "12.0", false},
+ {"\U0001f9ce\U0001f3fd\u200d\u2640\ufe0f\u200d\u27a1\ufe0f", "woman kneeling facing right: Medium Skin Tone", []string{"woman_kneeling_facing_right_Medium_Skin_Tone"}, "12.0", false},
{"\U0001f469\u200d\U0001f527", "woman mechanic", []string{"woman_mechanic"}, "", true},
{"\U0001f469\U0001f3ff\u200d\U0001f527", "woman mechanic: Dark Skin Tone", []string{"woman_mechanic_Dark_Skin_Tone"}, "12.0", false},
{"\U0001f469\U0001f3fb\u200d\U0001f527", "woman mechanic: Light Skin Tone", []string{"woman_mechanic_Light_Skin_Tone"}, "12.0", false},
@@ -3301,6 +3409,12 @@ var GemojiData = Gemoji{
{"\U0001f93d\U0001f3fe\u200d\u2640\ufe0f", "woman playing water polo: Medium-Dark Skin Tone", []string{"woman_playing_water_polo_Medium-Dark_Skin_Tone"}, "12.0", false},
{"\U0001f93d\U0001f3fc\u200d\u2640\ufe0f", "woman playing water polo: Medium-Light Skin Tone", []string{"woman_playing_water_polo_Medium-Light_Skin_Tone"}, "12.0", false},
{"\U0001f93d\U0001f3fd\u200d\u2640\ufe0f", "woman playing water polo: Medium Skin Tone", []string{"woman_playing_water_polo_Medium_Skin_Tone"}, "12.0", false},
+ {"\U0001f3c3\u200d\u2640\ufe0f\u200d\u27a1\ufe0f", "woman running facing right", []string{"woman_running_facing_right"}, "15.1", true},
+ {"\U0001f3c3\U0001f3ff\u200d\u2640\ufe0f\u200d\u27a1\ufe0f", "woman running facing right: Dark Skin Tone", []string{"woman_running_facing_right_Dark_Skin_Tone"}, "12.0", false},
+ {"\U0001f3c3\U0001f3fb\u200d\u2640\ufe0f\u200d\u27a1\ufe0f", "woman running facing right: Light Skin Tone", []string{"woman_running_facing_right_Light_Skin_Tone"}, "12.0", false},
+ {"\U0001f3c3\U0001f3fe\u200d\u2640\ufe0f\u200d\u27a1\ufe0f", "woman running facing right: Medium-Dark Skin Tone", []string{"woman_running_facing_right_Medium-Dark_Skin_Tone"}, "12.0", false},
+ {"\U0001f3c3\U0001f3fc\u200d\u2640\ufe0f\u200d\u27a1\ufe0f", "woman running facing right: Medium-Light Skin Tone", []string{"woman_running_facing_right_Medium-Light_Skin_Tone"}, "12.0", false},
+ {"\U0001f3c3\U0001f3fd\u200d\u2640\ufe0f\u200d\u27a1\ufe0f", "woman running facing right: Medium Skin Tone", []string{"woman_running_facing_right_Medium_Skin_Tone"}, "12.0", false},
{"\U0001f469\u200d\U0001f52c", "woman scientist", []string{"woman_scientist"}, "", true},
{"\U0001f469\U0001f3ff\u200d\U0001f52c", "woman scientist: Dark Skin Tone", []string{"woman_scientist_Dark_Skin_Tone"}, "12.0", false},
{"\U0001f469\U0001f3fb\u200d\U0001f52c", "woman scientist: Light Skin Tone", []string{"woman_scientist_Light_Skin_Tone"}, "12.0", false},
@@ -3337,6 +3451,12 @@ var GemojiData = Gemoji{
{"\U0001f469\U0001f3fe\u200d\U0001f4bb", "woman technologist: Medium-Dark Skin Tone", []string{"woman_technologist_Medium-Dark_Skin_Tone"}, "12.0", false},
{"\U0001f469\U0001f3fc\u200d\U0001f4bb", "woman technologist: Medium-Light Skin Tone", []string{"woman_technologist_Medium-Light_Skin_Tone"}, "12.0", false},
{"\U0001f469\U0001f3fd\u200d\U0001f4bb", "woman technologist: Medium Skin Tone", []string{"woman_technologist_Medium_Skin_Tone"}, "12.0", false},
+ {"\U0001f6b6\u200d\u2640\ufe0f\u200d\u27a1\ufe0f", "woman walking facing right", []string{"woman_walking_facing_right"}, "15.1", true},
+ {"\U0001f6b6\U0001f3ff\u200d\u2640\ufe0f\u200d\u27a1\ufe0f", "woman walking facing right: Dark Skin Tone", []string{"woman_walking_facing_right_Dark_Skin_Tone"}, "12.0", false},
+ {"\U0001f6b6\U0001f3fb\u200d\u2640\ufe0f\u200d\u27a1\ufe0f", "woman walking facing right: Light Skin Tone", []string{"woman_walking_facing_right_Light_Skin_Tone"}, "12.0", false},
+ {"\U0001f6b6\U0001f3fe\u200d\u2640\ufe0f\u200d\u27a1\ufe0f", "woman walking facing right: Medium-Dark Skin Tone", []string{"woman_walking_facing_right_Medium-Dark_Skin_Tone"}, "12.0", false},
+ {"\U0001f6b6\U0001f3fc\u200d\u2640\ufe0f\u200d\u27a1\ufe0f", "woman walking facing right: Medium-Light Skin Tone", []string{"woman_walking_facing_right_Medium-Light_Skin_Tone"}, "12.0", false},
+ {"\U0001f6b6\U0001f3fd\u200d\u2640\ufe0f\u200d\u27a1\ufe0f", "woman walking facing right: Medium Skin Tone", []string{"woman_walking_facing_right_Medium_Skin_Tone"}, "12.0", false},
{"\U0001f9d5", "woman with headscarf", []string{"woman_with_headscarf"}, "11.0", true},
{"\U0001f9d5\U0001f3ff", "woman with headscarf: Dark Skin Tone", []string{"woman_with_headscarf_Dark_Skin_Tone"}, "12.0", false},
{"\U0001f9d5\U0001f3fb", "woman with headscarf: Light Skin Tone", []string{"woman_with_headscarf_Light_Skin_Tone"}, "12.0", false},
@@ -3361,6 +3481,12 @@ var GemojiData = Gemoji{
{"\U0001f470\U0001f3fe\u200d\u2640\ufe0f", "woman with veil: Medium-Dark Skin Tone", []string{"woman_with_veil_Medium-Dark_Skin_Tone"}, "12.0", false},
{"\U0001f470\U0001f3fc\u200d\u2640\ufe0f", "woman with veil: Medium-Light Skin Tone", []string{"woman_with_veil_Medium-Light_Skin_Tone"}, "12.0", false},
{"\U0001f470\U0001f3fd\u200d\u2640\ufe0f", "woman with veil: Medium Skin Tone", []string{"woman_with_veil_Medium_Skin_Tone"}, "12.0", false},
+ {"\U0001f469\u200d\U0001f9af\u200d\u27a1\ufe0f", "woman with white cane facing right", []string{"woman_with_white_cane_facing_right"}, "15.1", true},
+ {"\U0001f469\U0001f3ff\u200d\U0001f9af\u200d\u27a1\ufe0f", "woman with white cane facing right: Dark Skin Tone", []string{"woman_with_white_cane_facing_right_Dark_Skin_Tone"}, "12.0", false},
+ {"\U0001f469\U0001f3fb\u200d\U0001f9af\u200d\u27a1\ufe0f", "woman with white cane facing right: Light Skin Tone", []string{"woman_with_white_cane_facing_right_Light_Skin_Tone"}, "12.0", false},
+ {"\U0001f469\U0001f3fe\u200d\U0001f9af\u200d\u27a1\ufe0f", "woman with white cane facing right: Medium-Dark Skin Tone", []string{"woman_with_white_cane_facing_right_Medium-Dark_Skin_Tone"}, "12.0", false},
+ {"\U0001f469\U0001f3fc\u200d\U0001f9af\u200d\u27a1\ufe0f", "woman with white cane facing right: Medium-Light Skin Tone", []string{"woman_with_white_cane_facing_right_Medium-Light_Skin_Tone"}, "12.0", false},
+ {"\U0001f469\U0001f3fd\u200d\U0001f9af\u200d\u27a1\ufe0f", "woman with white cane facing right: Medium Skin Tone", []string{"woman_with_white_cane_facing_right_Medium_Skin_Tone"}, "12.0", false},
{"\U0001f45a", "woman’s clothes", []string{"womans_clothes"}, "6.0", false},
{"\U0001f452", "woman’s hat", []string{"womans_hat"}, "6.0", false},
{"\U0001f93c\u200d\u2640\ufe0f", "women wrestling", []string{"women_wrestling"}, "9.0", false},
diff --git a/modules/eventsource/manager_run.go b/modules/eventsource/manager_run.go
index f66dc78c7e..4a42224dda 100644
--- a/modules/eventsource/manager_run.go
+++ b/modules/eventsource/manager_run.go
@@ -9,6 +9,7 @@ import (
activities_model "code.gitea.io/gitea/models/activities"
issues_model "code.gitea.io/gitea/models/issues"
+ user_model "code.gitea.io/gitea/models/user"
"code.gitea.io/gitea/modules/graceful"
"code.gitea.io/gitea/modules/json"
"code.gitea.io/gitea/modules/log"
@@ -91,7 +92,13 @@ loop:
}
for _, userStopwatches := range usersStopwatches {
- apiSWs, err := convert.ToStopWatches(ctx, userStopwatches.StopWatches)
+ u, err := user_model.GetUserByID(ctx, userStopwatches.UserID)
+ if err != nil {
+ log.Error("Unable to get user %d: %v", userStopwatches.UserID, err)
+ continue
+ }
+
+ apiSWs, err := convert.ToStopWatches(ctx, u, userStopwatches.StopWatches)
if err != nil {
if !issues_model.IsErrIssueNotExist(err) {
log.Error("Unable to APIFormat stopwatches: %v", err)
diff --git a/modules/fileicon/render.go b/modules/fileicon/render.go
index 6b2fcfa81e..5bf2a3a02e 100644
--- a/modules/fileicon/render.go
+++ b/modules/fileicon/render.go
@@ -34,7 +34,13 @@ func (p *RenderedIconPool) RenderToHTML() template.HTML {
}
func RenderEntryIconHTML(renderedIconPool *RenderedIconPool, entry *EntryInfo) template.HTML {
- if setting.UI.FileIconTheme == "material" {
+ // Use folder theme for directories and symlinks to directories
+ theme := setting.UI.FileIconTheme
+ if entry.EntryMode.IsDir() || (entry.EntryMode.IsLink() && entry.SymlinkToMode.IsDir()) {
+ theme = setting.UI.FolderIconTheme
+ }
+
+ if theme == "material" {
return DefaultMaterialIconProvider().EntryIconHTML(renderedIconPool, entry)
}
return BasicEntryIconHTML(entry)
diff --git a/modules/fileicon/render_test.go b/modules/fileicon/render_test.go
new file mode 100644
index 0000000000..d9998f3f4c
--- /dev/null
+++ b/modules/fileicon/render_test.go
@@ -0,0 +1,75 @@
+// Copyright 2026 The Gitea Authors. All rights reserved.
+// SPDX-License-Identifier: MIT
+
+package fileicon_test
+
+import (
+ "testing"
+
+ "code.gitea.io/gitea/modules/fileicon"
+ "code.gitea.io/gitea/modules/git"
+ "code.gitea.io/gitea/modules/setting"
+ "code.gitea.io/gitea/modules/test"
+
+ "github.com/stretchr/testify/assert"
+)
+
+func TestRenderEntryIconHTML_WithDifferentThemes(t *testing.T) {
+ // Test that folder icons use the folder theme
+ t.Run("FolderUsesBasicTheme", func(t *testing.T) {
+ defer test.MockVariableValue(&setting.UI.FileIconTheme, "material")()
+ defer test.MockVariableValue(&setting.UI.FolderIconTheme, "basic")()
+
+ folderEntry := &fileicon.EntryInfo{
+ BaseName: "testfolder",
+ EntryMode: git.EntryModeTree,
+ }
+
+ html := fileicon.RenderEntryIconHTML(nil, folderEntry)
+ // Basic theme renders octicon classes
+ assert.Contains(t, string(html), "octicon-file-directory-fill")
+ })
+
+ t.Run("FileUsesMaterialTheme", func(t *testing.T) {
+ defer test.MockVariableValue(&setting.UI.FileIconTheme, "material")()
+ defer test.MockVariableValue(&setting.UI.FolderIconTheme, "basic")()
+
+ fileEntry := &fileicon.EntryInfo{
+ BaseName: "test.js",
+ EntryMode: git.EntryModeBlob,
+ }
+
+ html := fileicon.RenderEntryIconHTML(nil, fileEntry)
+ // Material theme for files renders material icons
+ assert.Contains(t, string(html), "svg-mfi-")
+ })
+
+ t.Run("SymlinkToFolderUsesBasicTheme", func(t *testing.T) {
+ defer test.MockVariableValue(&setting.UI.FileIconTheme, "material")()
+ defer test.MockVariableValue(&setting.UI.FolderIconTheme, "basic")()
+
+ symlinkEntry := &fileicon.EntryInfo{
+ BaseName: "link",
+ EntryMode: git.EntryModeSymlink,
+ SymlinkToMode: git.EntryModeTree,
+ }
+
+ html := fileicon.RenderEntryIconHTML(nil, symlinkEntry)
+ // Symlinks to folders should use folder theme
+ assert.Contains(t, string(html), "octicon-file-directory-symlink")
+ })
+
+ t.Run("BothMaterialTheme", func(t *testing.T) {
+ defer test.MockVariableValue(&setting.UI.FileIconTheme, "material")()
+ defer test.MockVariableValue(&setting.UI.FolderIconTheme, "material")()
+
+ folderEntry := &fileicon.EntryInfo{
+ BaseName: "testfolder",
+ EntryMode: git.EntryModeTree,
+ }
+
+ html := fileicon.RenderEntryIconHTML(nil, folderEntry)
+ // Material theme for folders renders material folder icons
+ assert.Contains(t, string(html), "svg-mfi-")
+ })
+}
diff --git a/modules/generate/generate.go b/modules/generate/generate.go
index 2d9a3dd902..ac84504492 100644
--- a/modules/generate/generate.go
+++ b/modules/generate/generate.go
@@ -54,13 +54,13 @@ func DecodeJwtSecretBase64(src string) ([]byte, error) {
}
// NewJwtSecretWithBase64 generates a jwt secret with its base64 encoded value intended to be used for saving into config file
-func NewJwtSecretWithBase64() ([]byte, string, error) {
+func NewJwtSecretWithBase64() ([]byte, string) {
bytes := make([]byte, defaultJwtSecretLen)
- _, err := io.ReadFull(rand.Reader, bytes)
+ _, err := rand.Read(bytes)
if err != nil {
- return nil, "", err
+ panic(err) // rand.Read never fails
}
- return bytes, base64.RawURLEncoding.EncodeToString(bytes), nil
+ return bytes, base64.RawURLEncoding.EncodeToString(bytes)
}
// NewSecretKey generate a new value intended to be used by SECRET_KEY.
diff --git a/modules/generate/generate_test.go b/modules/generate/generate_test.go
index af640a60c1..f9dd20cc7f 100644
--- a/modules/generate/generate_test.go
+++ b/modules/generate/generate_test.go
@@ -25,10 +25,12 @@ func TestDecodeJwtSecretBase64(t *testing.T) {
}
func TestNewJwtSecretWithBase64(t *testing.T) {
- secret, encoded, err := NewJwtSecretWithBase64()
- assert.NoError(t, err)
+ secret, encoded := NewJwtSecretWithBase64()
assert.Len(t, secret, 32)
decoded, err := DecodeJwtSecretBase64(encoded)
assert.NoError(t, err)
assert.Equal(t, secret, decoded)
+
+ secret2, _ := NewJwtSecretWithBase64()
+ assert.NotEqual(t, secret, secret2)
}
diff --git a/modules/git/attribute/attribute.go b/modules/git/attribute/attribute.go
index 9c01cb339e..8719369df8 100644
--- a/modules/git/attribute/attribute.go
+++ b/modules/git/attribute/attribute.go
@@ -96,8 +96,8 @@ func (attrs *Attributes) GetGitlabLanguage() optional.Option[string] {
// gitlab-language may have additional parameters after the language
// ignore them and just use the main language
// https://docs.gitlab.com/ee/user/project/highlighting.html#override-syntax-highlighting-for-a-file-type
- if idx := strings.IndexByte(raw, '?'); idx >= 0 {
- return optional.Some(raw[:idx])
+ if before, _, ok := strings.Cut(raw, "?"); ok {
+ return optional.Some(before)
}
}
return attrStr
diff --git a/modules/git/attribute/batch.go b/modules/git/attribute/batch.go
index 9f805d55c5..b1e6387ade 100644
--- a/modules/git/attribute/batch.go
+++ b/modules/git/attribute/batch.go
@@ -7,7 +7,7 @@ import (
"bytes"
"context"
"fmt"
- "os"
+ "io"
"path/filepath"
"time"
@@ -20,7 +20,7 @@ import (
type BatchChecker struct {
attributesNum int
repo *git.Repository
- stdinWriter *os.File
+ stdinWriter io.WriteCloser
stdOut *nulSeparatedAttributeWriter
ctx context.Context
cancel context.CancelFunc
@@ -60,10 +60,7 @@ func NewBatchChecker(repo *git.Repository, treeish string, attributes []string)
},
}
- stdinReader, stdinWriter, err := os.Pipe()
- if err != nil {
- return nil, err
- }
+ stdinWriter, stdinWriterClose := cmd.MakeStdinPipe()
checker.stdinWriter = stdinWriter
lw := new(nulSeparatedAttributeWriter)
@@ -71,24 +68,19 @@ func NewBatchChecker(repo *git.Repository, treeish string, attributes []string)
lw.closed = make(chan struct{})
checker.stdOut = lw
+ cmd.WithEnv(envs).
+ WithDir(repo.Path).
+ WithStdoutCopy(lw)
+
go func() {
- defer func() {
- _ = stdinReader.Close()
- _ = lw.Close()
- }()
- stdErr := new(bytes.Buffer)
- err := cmd.Run(ctx, &gitcmd.RunOpts{
- Env: envs,
- Dir: repo.Path,
- Stdin: stdinReader,
- Stdout: lw,
- Stderr: stdErr,
- })
-
- if err != nil && !git.IsErrCanceledOrKilled(err) {
+ defer stdinWriterClose()
+ defer checker.cancel()
+ defer lw.Close()
+
+ err := cmd.RunWithStderr(ctx)
+ if err != nil && !gitcmd.IsErrorCanceledOrKilled(err) {
log.Error("Attribute checker for commit %s exits with error: %v", treeish, err)
}
- checker.cancel()
}()
return checker, nil
diff --git a/modules/git/attribute/checker.go b/modules/git/attribute/checker.go
index 4b313adf37..3eea31e813 100644
--- a/modules/git/attribute/checker.go
+++ b/modules/git/attribute/checker.go
@@ -68,19 +68,14 @@ func CheckAttributes(ctx context.Context, gitRepo *git.Repository, treeish strin
}
defer cancel()
- stdOut := new(bytes.Buffer)
- stdErr := new(bytes.Buffer)
-
- if err := cmd.Run(ctx, &gitcmd.RunOpts{
- Env: append(os.Environ(), envs...),
- Dir: gitRepo.Path,
- Stdout: stdOut,
- Stderr: stdErr,
- }); err != nil {
- return nil, fmt.Errorf("failed to run check-attr: %w\n%s\n%s", err, stdOut.String(), stdErr.String())
+ stdout, _, err := cmd.WithEnv(append(os.Environ(), envs...)).
+ WithDir(gitRepo.Path).
+ RunStdBytes(ctx)
+ if err != nil {
+ return nil, fmt.Errorf("failed to run check-attr: %w", err)
}
- fields := bytes.Split(stdOut.Bytes(), []byte{'\000'})
+ fields := bytes.Split(stdout, []byte{'\000'})
if len(fields)%3 != 1 {
return nil, errors.New("wrong number of fields in return from check-attr")
}
diff --git a/modules/git/batch.go b/modules/git/batch.go
deleted file mode 100644
index f9e1748b54..0000000000
--- a/modules/git/batch.go
+++ /dev/null
@@ -1,47 +0,0 @@
-// Copyright 2024 The Gitea Authors. All rights reserved.
-// SPDX-License-Identifier: MIT
-
-package git
-
-import (
- "bufio"
- "context"
-)
-
-type Batch struct {
- cancel context.CancelFunc
- Reader *bufio.Reader
- Writer WriteCloserError
-}
-
-// NewBatch creates a new batch for the given repository, the Close must be invoked before release the batch
-func NewBatch(ctx context.Context, repoPath string) (*Batch, error) {
- // Now because of some insanity with git cat-file not immediately failing if not run in a valid git directory we need to run git rev-parse first!
- if err := ensureValidGitRepository(ctx, repoPath); err != nil {
- return nil, err
- }
-
- var batch Batch
- batch.Writer, batch.Reader, batch.cancel = catFileBatch(ctx, repoPath)
- return &batch, nil
-}
-
-func NewBatchCheck(ctx context.Context, repoPath string) (*Batch, error) {
- // Now because of some insanity with git cat-file not immediately failing if not run in a valid git directory we need to run git rev-parse first!
- if err := ensureValidGitRepository(ctx, repoPath); err != nil {
- return nil, err
- }
-
- var check Batch
- check.Writer, check.Reader, check.cancel = catFileBatchCheck(ctx, repoPath)
- return &check, nil
-}
-
-func (b *Batch) Close() {
- if b.cancel != nil {
- b.cancel()
- b.Reader = nil
- b.Writer = nil
- b.cancel = nil
- }
-}
diff --git a/modules/git/batch_reader.go b/modules/git/batch_reader.go
deleted file mode 100644
index f09f4144c8..0000000000
--- a/modules/git/batch_reader.go
+++ /dev/null
@@ -1,329 +0,0 @@
-// Copyright 2020 The Gitea Authors. All rights reserved.
-// SPDX-License-Identifier: MIT
-
-package git
-
-import (
- "bufio"
- "bytes"
- "context"
- "io"
- "math"
- "strconv"
- "strings"
-
- "code.gitea.io/gitea/modules/git/gitcmd"
- "code.gitea.io/gitea/modules/log"
-
- "github.com/djherbis/buffer"
- "github.com/djherbis/nio/v3"
-)
-
-// WriteCloserError wraps an io.WriteCloser with an additional CloseWithError function
-type WriteCloserError interface {
- io.WriteCloser
- CloseWithError(err error) error
-}
-
-// ensureValidGitRepository runs git rev-parse in the repository path - thus ensuring that the repository is a valid repository.
-// Run before opening git cat-file.
-// This is needed otherwise the git cat-file will hang for invalid repositories.
-func ensureValidGitRepository(ctx context.Context, repoPath string) error {
- stderr := strings.Builder{}
- err := gitcmd.NewCommand("rev-parse").
- Run(ctx, &gitcmd.RunOpts{
- Dir: repoPath,
- Stderr: &stderr,
- })
- if err != nil {
- return gitcmd.ConcatenateError(err, (&stderr).String())
- }
- return nil
-}
-
-// catFileBatchCheck opens git cat-file --batch-check in the provided repo and returns a stdin pipe, a stdout reader and cancel function
-func catFileBatchCheck(ctx context.Context, repoPath string) (WriteCloserError, *bufio.Reader, func()) {
- batchStdinReader, batchStdinWriter := io.Pipe()
- batchStdoutReader, batchStdoutWriter := io.Pipe()
- ctx, ctxCancel := context.WithCancel(ctx)
- closed := make(chan struct{})
- cancel := func() {
- ctxCancel()
- _ = batchStdoutReader.Close()
- _ = batchStdinWriter.Close()
- <-closed
- }
-
- // Ensure cancel is called as soon as the provided context is cancelled
- go func() {
- <-ctx.Done()
- cancel()
- }()
-
- go func() {
- stderr := strings.Builder{}
- err := gitcmd.NewCommand("cat-file", "--batch-check").
- Run(ctx, &gitcmd.RunOpts{
- Dir: repoPath,
- Stdin: batchStdinReader,
- Stdout: batchStdoutWriter,
- Stderr: &stderr,
-
- UseContextTimeout: true,
- })
- if err != nil {
- _ = batchStdoutWriter.CloseWithError(gitcmd.ConcatenateError(err, (&stderr).String()))
- _ = batchStdinReader.CloseWithError(gitcmd.ConcatenateError(err, (&stderr).String()))
- } else {
- _ = batchStdoutWriter.Close()
- _ = batchStdinReader.Close()
- }
- close(closed)
- }()
-
- // For simplicities sake we'll use a buffered reader to read from the cat-file --batch-check
- batchReader := bufio.NewReader(batchStdoutReader)
-
- return batchStdinWriter, batchReader, cancel
-}
-
-// catFileBatch opens git cat-file --batch in the provided repo and returns a stdin pipe, a stdout reader and cancel function
-func catFileBatch(ctx context.Context, repoPath string) (WriteCloserError, *bufio.Reader, func()) {
- // We often want to feed the commits in order into cat-file --batch, followed by their trees and sub trees as necessary.
- // so let's create a batch stdin and stdout
- batchStdinReader, batchStdinWriter := io.Pipe()
- batchStdoutReader, batchStdoutWriter := nio.Pipe(buffer.New(32 * 1024))
- ctx, ctxCancel := context.WithCancel(ctx)
- closed := make(chan struct{})
- cancel := func() {
- ctxCancel()
- _ = batchStdinWriter.Close()
- _ = batchStdoutReader.Close()
- <-closed
- }
-
- // Ensure cancel is called as soon as the provided context is cancelled
- go func() {
- <-ctx.Done()
- cancel()
- }()
-
- go func() {
- stderr := strings.Builder{}
- err := gitcmd.NewCommand("cat-file", "--batch").
- Run(ctx, &gitcmd.RunOpts{
- Dir: repoPath,
- Stdin: batchStdinReader,
- Stdout: batchStdoutWriter,
- Stderr: &stderr,
-
- UseContextTimeout: true,
- })
- if err != nil {
- _ = batchStdoutWriter.CloseWithError(gitcmd.ConcatenateError(err, (&stderr).String()))
- _ = batchStdinReader.CloseWithError(gitcmd.ConcatenateError(err, (&stderr).String()))
- } else {
- _ = batchStdoutWriter.Close()
- _ = batchStdinReader.Close()
- }
- close(closed)
- }()
-
- // For simplicities sake we'll us a buffered reader to read from the cat-file --batch
- batchReader := bufio.NewReaderSize(batchStdoutReader, 32*1024)
-
- return batchStdinWriter, batchReader, cancel
-}
-
-// ReadBatchLine reads the header line from cat-file --batch
-// We expect: SP SP LF
-// then leaving the rest of the stream " LF" to be read
-func ReadBatchLine(rd *bufio.Reader) (sha []byte, typ string, size int64, err error) {
- typ, err = rd.ReadString('\n')
- if err != nil {
- return sha, typ, size, err
- }
- if len(typ) == 1 {
- typ, err = rd.ReadString('\n')
- if err != nil {
- return sha, typ, size, err
- }
- }
- idx := strings.IndexByte(typ, ' ')
- if idx < 0 {
- log.Debug("missing space typ: %s", typ)
- return sha, typ, size, ErrNotExist{ID: string(sha)}
- }
- sha = []byte(typ[:idx])
- typ = typ[idx+1:]
-
- idx = strings.IndexByte(typ, ' ')
- if idx < 0 {
- return sha, typ, size, ErrNotExist{ID: string(sha)}
- }
-
- sizeStr := typ[idx+1 : len(typ)-1]
- typ = typ[:idx]
-
- size, err = strconv.ParseInt(sizeStr, 10, 64)
- return sha, typ, size, err
-}
-
-// ReadTagObjectID reads a tag object ID hash from a cat-file --batch stream, throwing away the rest of the stream.
-func ReadTagObjectID(rd *bufio.Reader, size int64) (string, error) {
- var id string
- var n int64
-headerLoop:
- for {
- line, err := rd.ReadBytes('\n')
- if err != nil {
- return "", err
- }
- n += int64(len(line))
- idx := bytes.Index(line, []byte{' '})
- if idx < 0 {
- continue
- }
-
- if string(line[:idx]) == "object" {
- id = string(line[idx+1 : len(line)-1])
- break headerLoop
- }
- }
-
- // Discard the rest of the tag
- return id, DiscardFull(rd, size-n+1)
-}
-
-// ReadTreeID reads a tree ID from a cat-file --batch stream, throwing away the rest of the stream.
-func ReadTreeID(rd *bufio.Reader, size int64) (string, error) {
- var id string
- var n int64
-headerLoop:
- for {
- line, err := rd.ReadBytes('\n')
- if err != nil {
- return "", err
- }
- n += int64(len(line))
- idx := bytes.Index(line, []byte{' '})
- if idx < 0 {
- continue
- }
-
- if string(line[:idx]) == "tree" {
- id = string(line[idx+1 : len(line)-1])
- break headerLoop
- }
- }
-
- // Discard the rest of the commit
- return id, DiscardFull(rd, size-n+1)
-}
-
-// git tree files are a list:
-// SP NUL
-//
-// Unfortunately this 20-byte notation is somewhat in conflict to all other git tools
-// Therefore we need some method to convert these binary hashes to hex hashes
-
-// constant hextable to help quickly convert between binary and hex representation
-const hextable = "0123456789abcdef"
-
-// BinToHexHeash converts a binary Hash into a hex encoded one. Input and output can be the
-// same byte slice to support in place conversion without allocations.
-// This is at least 100x quicker that hex.EncodeToString
-func BinToHex(objectFormat ObjectFormat, sha, out []byte) []byte {
- for i := objectFormat.FullLength()/2 - 1; i >= 0; i-- {
- v := sha[i]
- vhi, vlo := v>>4, v&0x0f
- shi, slo := hextable[vhi], hextable[vlo]
- out[i*2], out[i*2+1] = shi, slo
- }
- return out
-}
-
-// ParseCatFileTreeLine reads an entry from a tree in a cat-file --batch stream
-// This carefully avoids allocations - except where fnameBuf is too small.
-// It is recommended therefore to pass in an fnameBuf large enough to avoid almost all allocations
-//
-// Each line is composed of:
-// SP NUL
-//
-// We don't attempt to convert the raw HASH to save a lot of time
-func ParseCatFileTreeLine(objectFormat ObjectFormat, rd *bufio.Reader, modeBuf, fnameBuf, shaBuf []byte) (mode, fname, sha []byte, n int, err error) {
- var readBytes []byte
-
- // Read the Mode & fname
- readBytes, err = rd.ReadSlice('\x00')
- if err != nil {
- return mode, fname, sha, n, err
- }
- idx := bytes.IndexByte(readBytes, ' ')
- if idx < 0 {
- log.Debug("missing space in readBytes ParseCatFileTreeLine: %s", readBytes)
- return mode, fname, sha, n, &ErrNotExist{}
- }
-
- n += idx + 1
- copy(modeBuf, readBytes[:idx])
- if len(modeBuf) >= idx {
- modeBuf = modeBuf[:idx]
- } else {
- modeBuf = append(modeBuf, readBytes[len(modeBuf):idx]...)
- }
- mode = modeBuf
-
- readBytes = readBytes[idx+1:]
-
- // Deal with the fname
- copy(fnameBuf, readBytes)
- if len(fnameBuf) > len(readBytes) {
- fnameBuf = fnameBuf[:len(readBytes)]
- } else {
- fnameBuf = append(fnameBuf, readBytes[len(fnameBuf):]...)
- }
- for err == bufio.ErrBufferFull {
- readBytes, err = rd.ReadSlice('\x00')
- fnameBuf = append(fnameBuf, readBytes...)
- }
- n += len(fnameBuf)
- if err != nil {
- return mode, fname, sha, n, err
- }
- fnameBuf = fnameBuf[:len(fnameBuf)-1]
- fname = fnameBuf
-
- // Deal with the binary hash
- idx = 0
- length := objectFormat.FullLength() / 2
- for idx < length {
- var read int
- read, err = rd.Read(shaBuf[idx:length])
- n += read
- if err != nil {
- return mode, fname, sha, n, err
- }
- idx += read
- }
- sha = shaBuf
- return mode, fname, sha, n, err
-}
-
-func DiscardFull(rd *bufio.Reader, discard int64) error {
- if discard > math.MaxInt32 {
- n, err := rd.Discard(math.MaxInt32)
- discard -= int64(n)
- if err != nil {
- return err
- }
- }
- for discard > 0 {
- n, err := rd.Discard(int(discard))
- discard -= int64(n)
- if err != nil {
- return err
- }
- }
- return nil
-}
diff --git a/modules/git/blob_gogit.go b/modules/git/blob_gogit.go
index 8c79c067c1..7cf622d180 100644
--- a/modules/git/blob_gogit.go
+++ b/modules/git/blob_gogit.go
@@ -9,24 +9,38 @@ package git
import (
"io"
+ "code.gitea.io/gitea/modules/log"
+
"github.com/go-git/go-git/v5/plumbing"
)
// Blob represents a Git object.
type Blob struct {
- ID ObjectID
+ ID ObjectID
+ repo *Repository
+ name string
+}
- gogitEncodedObj plumbing.EncodedObject
- name string
+func (b *Blob) gogitEncodedObj() (plumbing.EncodedObject, error) {
+ return b.repo.gogitRepo.Storer.EncodedObject(plumbing.AnyObject, plumbing.Hash(b.ID.RawValue()))
}
// DataAsync gets a ReadCloser for the contents of a blob without reading it all.
// Calling the Close function on the result will discard all unread output.
func (b *Blob) DataAsync() (io.ReadCloser, error) {
- return b.gogitEncodedObj.Reader()
+ obj, err := b.gogitEncodedObj()
+ if err != nil {
+ return nil, err
+ }
+ return obj.Reader()
}
// Size returns the uncompressed size of the blob
func (b *Blob) Size() int64 {
- return b.gogitEncodedObj.Size()
+ obj, err := b.gogitEncodedObj()
+ if err != nil {
+ log.Error("Error getting gogit encoded object for blob %s(%s): %v", b.name, b.ID.String(), err)
+ return 0
+ }
+ return obj.Size()
}
diff --git a/modules/git/blob_nogogit.go b/modules/git/blob_nogogit.go
index af3ce376d6..837b30fd88 100644
--- a/modules/git/blob_nogogit.go
+++ b/modules/git/blob_nogogit.go
@@ -6,8 +6,6 @@
package git
import (
- "bufio"
- "bytes"
"io"
"code.gitea.io/gitea/modules/log"
@@ -25,38 +23,28 @@ type Blob struct {
// DataAsync gets a ReadCloser for the contents of a blob without reading it all.
// Calling the Close function on the result will discard all unread output.
-func (b *Blob) DataAsync() (io.ReadCloser, error) {
- wr, rd, cancel, err := b.repo.CatFileBatch(b.repo.Ctx)
+func (b *Blob) DataAsync() (_ io.ReadCloser, retErr error) {
+ batch, cancel, err := b.repo.CatFileBatch(b.repo.Ctx)
if err != nil {
return nil, err
}
+ defer func() {
+ // if there was an error, cancel the batch right away,
+ // otherwise let the caller close it
+ if retErr != nil {
+ cancel()
+ }
+ }()
- _, err = wr.Write([]byte(b.ID.String() + "\n"))
- if err != nil {
- cancel()
- return nil, err
- }
- _, _, size, err := ReadBatchLine(rd)
+ info, contentReader, err := batch.QueryContent(b.ID.String())
if err != nil {
- cancel()
return nil, err
}
b.gotSize = true
- b.size = size
-
- if size < 4096 {
- bs, err := io.ReadAll(io.LimitReader(rd, size))
- defer cancel()
- if err != nil {
- return nil, err
- }
- _, err = rd.Discard(1)
- return io.NopCloser(bytes.NewReader(bs)), err
- }
-
+ b.size = info.Size
return &blobReader{
- rd: rd,
- n: size,
+ rd: contentReader,
+ n: info.Size,
cancel: cancel,
}, nil
}
@@ -67,30 +55,24 @@ func (b *Blob) Size() int64 {
return b.size
}
- wr, rd, cancel, err := b.repo.CatFileBatchCheck(b.repo.Ctx)
+ batch, cancel, err := b.repo.CatFileBatch(b.repo.Ctx)
if err != nil {
log.Debug("error whilst reading size for %s in %s. Error: %v", b.ID.String(), b.repo.Path, err)
return 0
}
defer cancel()
- _, err = wr.Write([]byte(b.ID.String() + "\n"))
+ info, err := batch.QueryInfo(b.ID.String())
if err != nil {
log.Debug("error whilst reading size for %s in %s. Error: %v", b.ID.String(), b.repo.Path, err)
return 0
}
- _, _, b.size, err = ReadBatchLine(rd)
- if err != nil {
- log.Debug("error whilst reading size for %s in %s. Error: %v", b.ID.String(), b.repo.Path, err)
- return 0
- }
-
b.gotSize = true
-
+ b.size = info.Size
return b.size
}
type blobReader struct {
- rd *bufio.Reader
+ rd BufferedReader
n int64
cancel func()
}
diff --git a/modules/git/catfile_batch.go b/modules/git/catfile_batch.go
new file mode 100644
index 0000000000..d13179f3ec
--- /dev/null
+++ b/modules/git/catfile_batch.go
@@ -0,0 +1,52 @@
+// Copyright 2026 The Gitea Authors. All rights reserved.
+// SPDX-License-Identifier: MIT
+
+package git
+
+import (
+ "context"
+ "io"
+)
+
+type BufferedReader interface {
+ io.Reader
+ Buffered() int
+ Peek(n int) ([]byte, error)
+ Discard(n int) (int, error)
+ ReadString(sep byte) (string, error)
+ ReadSlice(sep byte) ([]byte, error)
+ ReadBytes(sep byte) ([]byte, error)
+}
+
+type CatFileObject struct {
+ ID string
+ Type string
+ Size int64
+}
+
+type CatFileBatch interface {
+ // QueryInfo queries the object info from the git repository by its object name using "git cat-file --batch" family commands.
+ // "git cat-file" accepts "" for the object name, it can be a ref name, object id, etc. https://git-scm.com/docs/gitrevisions
+ // In Gitea, we only use the simple ref name or object id, no other complex rev syntax like "suffix" or "git describe" although they are supported by git.
+ QueryInfo(obj string) (*CatFileObject, error)
+
+ // QueryContent is similar to QueryInfo, it queries the object info and additionally returns a reader for its content.
+ // FIXME: this design still follows the old pattern: the returned BufferedReader is very fragile,
+ // callers should carefully maintain its lifecycle and discard all unread data.
+ // TODO: It needs to be refactored to a fully managed Reader stream in the future, don't let callers manually Close or Discard
+ QueryContent(obj string) (*CatFileObject, BufferedReader, error)
+}
+
+type CatFileBatchCloser interface {
+ CatFileBatch
+ Close()
+}
+
+// NewBatch creates a "batch object provider (CatFileBatch)" for the given repository path to retrieve object info and content efficiently.
+// The CatFileBatch and the readers create by it should only be used in the same goroutine.
+func NewBatch(ctx context.Context, repoPath string) (CatFileBatchCloser, error) {
+ if DefaultFeatures().SupportCatFileBatchCommand {
+ return newCatFileBatchCommand(ctx, repoPath)
+ }
+ return newCatFileBatchLegacy(ctx, repoPath)
+}
diff --git a/modules/git/catfile_batch_command.go b/modules/git/catfile_batch_command.go
new file mode 100644
index 0000000000..4e18282bf3
--- /dev/null
+++ b/modules/git/catfile_batch_command.go
@@ -0,0 +1,74 @@
+// Copyright 2026 The Gitea Authors. All rights reserved.
+// SPDX-License-Identifier: MIT
+
+package git
+
+import (
+ "context"
+ "os"
+ "path/filepath"
+ "strings"
+
+ "code.gitea.io/gitea/modules/git/gitcmd"
+ "code.gitea.io/gitea/modules/setting"
+ "code.gitea.io/gitea/modules/util"
+)
+
+// catFileBatchCommand implements the CatFileBatch interface using the "cat-file --batch-command" command
+// for git version >= 2.36
+// ref: https://git-scm.com/docs/git-cat-file#Documentation/git-cat-file.txt---batch-command
+type catFileBatchCommand struct {
+ ctx context.Context
+ repoPath string
+ batch *catFileBatchCommunicator
+}
+
+var _ CatFileBatch = (*catFileBatchCommand)(nil)
+
+func newCatFileBatchCommand(ctx context.Context, repoPath string) (*catFileBatchCommand, error) {
+ if _, err := os.Stat(repoPath); err != nil {
+ return nil, util.NewNotExistErrorf("repo %q doesn't exist", filepath.Base(repoPath))
+ }
+ return &catFileBatchCommand{ctx: ctx, repoPath: repoPath}, nil
+}
+
+func (b *catFileBatchCommand) getBatch() *catFileBatchCommunicator {
+ if b.batch != nil {
+ return b.batch
+ }
+ b.batch = newCatFileBatch(b.ctx, b.repoPath, gitcmd.NewCommand("cat-file", "--batch-command"))
+ return b.batch
+}
+
+func (b *catFileBatchCommand) QueryContent(obj string) (*CatFileObject, BufferedReader, error) {
+ if strings.Contains(obj, "\n") {
+ setting.PanicInDevOrTesting("invalid object name with newline: %q", obj)
+ }
+ _, err := b.getBatch().reqWriter.Write([]byte("contents " + obj + "\n"))
+ if err != nil {
+ return nil, nil, err
+ }
+ info, err := catFileBatchParseInfoLine(b.getBatch().respReader)
+ if err != nil {
+ return nil, nil, err
+ }
+ return info, b.getBatch().respReader, nil
+}
+
+func (b *catFileBatchCommand) QueryInfo(obj string) (*CatFileObject, error) {
+ if strings.Contains(obj, "\n") {
+ setting.PanicInDevOrTesting("invalid object name with newline: %q", obj)
+ }
+ _, err := b.getBatch().reqWriter.Write([]byte("info " + obj + "\n"))
+ if err != nil {
+ return nil, err
+ }
+ return catFileBatchParseInfoLine(b.getBatch().respReader)
+}
+
+func (b *catFileBatchCommand) Close() {
+ if b.batch != nil {
+ b.batch.Close()
+ b.batch = nil
+ }
+}
diff --git a/modules/git/catfile_batch_legacy.go b/modules/git/catfile_batch_legacy.go
new file mode 100644
index 0000000000..595043d1d2
--- /dev/null
+++ b/modules/git/catfile_batch_legacy.go
@@ -0,0 +1,89 @@
+// Copyright 2024 The Gitea Authors. All rights reserved.
+// SPDX-License-Identifier: MIT
+
+package git
+
+import (
+ "context"
+ "io"
+ "os"
+ "path/filepath"
+ "strings"
+
+ "code.gitea.io/gitea/modules/git/gitcmd"
+ "code.gitea.io/gitea/modules/setting"
+ "code.gitea.io/gitea/modules/util"
+)
+
+// catFileBatchLegacy implements the CatFileBatch interface using the "cat-file --batch" command and "cat-file --batch-check" command
+// for git version < 2.36
+// to align with "--batch-command", it creates the two commands for querying object contents and object info separately
+// ref: https://git-scm.com/docs/git-cat-file#Documentation/git-cat-file.txt---batch
+type catFileBatchLegacy struct {
+ ctx context.Context
+ repoPath string
+ batchContent *catFileBatchCommunicator
+ batchCheck *catFileBatchCommunicator
+}
+
+var _ CatFileBatchCloser = (*catFileBatchLegacy)(nil)
+
+func newCatFileBatchLegacy(ctx context.Context, repoPath string) (*catFileBatchLegacy, error) {
+ if _, err := os.Stat(repoPath); err != nil {
+ return nil, util.NewNotExistErrorf("repo %q doesn't exist", filepath.Base(repoPath))
+ }
+ return &catFileBatchLegacy{ctx: ctx, repoPath: repoPath}, nil
+}
+
+func (b *catFileBatchLegacy) getBatchContent() *catFileBatchCommunicator {
+ if b.batchContent != nil {
+ return b.batchContent
+ }
+ b.batchContent = newCatFileBatch(b.ctx, b.repoPath, gitcmd.NewCommand("cat-file", "--batch"))
+ return b.batchContent
+}
+
+func (b *catFileBatchLegacy) getBatchCheck() *catFileBatchCommunicator {
+ if b.batchCheck != nil {
+ return b.batchCheck
+ }
+ b.batchCheck = newCatFileBatch(b.ctx, b.repoPath, gitcmd.NewCommand("cat-file", "--batch-check"))
+ return b.batchCheck
+}
+
+func (b *catFileBatchLegacy) QueryContent(obj string) (*CatFileObject, BufferedReader, error) {
+ if strings.Contains(obj, "\n") {
+ setting.PanicInDevOrTesting("invalid object name with newline: %q", obj)
+ }
+ _, err := io.WriteString(b.getBatchContent().reqWriter, obj+"\n")
+ if err != nil {
+ return nil, nil, err
+ }
+ info, err := catFileBatchParseInfoLine(b.getBatchContent().respReader)
+ if err != nil {
+ return nil, nil, err
+ }
+ return info, b.getBatchContent().respReader, nil
+}
+
+func (b *catFileBatchLegacy) QueryInfo(obj string) (*CatFileObject, error) {
+ if strings.Contains(obj, "\n") {
+ setting.PanicInDevOrTesting("invalid object name with newline: %q", obj)
+ }
+ _, err := io.WriteString(b.getBatchCheck().reqWriter, obj+"\n")
+ if err != nil {
+ return nil, err
+ }
+ return catFileBatchParseInfoLine(b.getBatchCheck().respReader)
+}
+
+func (b *catFileBatchLegacy) Close() {
+ if b.batchContent != nil {
+ b.batchContent.Close()
+ b.batchContent = nil
+ }
+ if b.batchCheck != nil {
+ b.batchCheck.Close()
+ b.batchCheck = nil
+ }
+}
diff --git a/modules/git/catfile_batch_reader.go b/modules/git/catfile_batch_reader.go
new file mode 100644
index 0000000000..5727c4a8ac
--- /dev/null
+++ b/modules/git/catfile_batch_reader.go
@@ -0,0 +1,264 @@
+// Copyright 2020 The Gitea Authors. All rights reserved.
+// SPDX-License-Identifier: MIT
+
+package git
+
+import (
+ "bufio"
+ "bytes"
+ "context"
+ "errors"
+ "io"
+ "math"
+ "strconv"
+ "strings"
+ "sync/atomic"
+
+ "code.gitea.io/gitea/modules/git/gitcmd"
+ "code.gitea.io/gitea/modules/log"
+ "code.gitea.io/gitea/modules/util"
+)
+
+type catFileBatchCommunicator struct {
+ closeFunc atomic.Pointer[func(err error)]
+ reqWriter io.Writer
+ respReader *bufio.Reader
+ debugGitCmd *gitcmd.Command
+}
+
+func (b *catFileBatchCommunicator) Close(err ...error) {
+ if fn := b.closeFunc.Swap(nil); fn != nil {
+ (*fn)(util.OptionalArg(err))
+ }
+}
+
+// newCatFileBatch opens git cat-file --batch/--batch-check/--batch-command command and prepares the stdin/stdout pipes for communication.
+func newCatFileBatch(ctx context.Context, repoPath string, cmdCatFile *gitcmd.Command) *catFileBatchCommunicator {
+ ctx, ctxCancel := context.WithCancelCause(ctx)
+ stdinWriter, stdoutReader, stdPipeClose := cmdCatFile.MakeStdinStdoutPipe()
+ ret := &catFileBatchCommunicator{
+ debugGitCmd: cmdCatFile,
+ reqWriter: stdinWriter,
+ respReader: bufio.NewReaderSize(stdoutReader, 32*1024), // use a buffered reader for rich operations
+ }
+ ret.closeFunc.Store(new(func(err error) {
+ ctxCancel(err)
+ stdPipeClose()
+ }))
+
+ err := cmdCatFile.WithDir(repoPath).StartWithStderr(ctx)
+ if err != nil {
+ log.Error("Unable to start git command %v: %v", cmdCatFile.LogString(), err)
+ // ideally here it should return the error, but it would require refactoring all callers
+ // so just return a dummy communicator that does nothing, almost the same behavior as before, not bad
+ ret.Close(err)
+ return ret
+ }
+
+ go func() {
+ err := cmdCatFile.WaitWithStderr()
+ if err != nil && !errors.Is(err, context.Canceled) {
+ log.Error("cat-file --batch command failed in repo %s, error: %v", repoPath, err)
+ }
+ ret.Close(err)
+ }()
+
+ return ret
+}
+
+func (b *catFileBatchCommunicator) debugKill() (ret struct {
+ beforeClose chan struct{}
+ blockClose chan struct{}
+ afterClose chan struct{}
+},
+) {
+ ret.beforeClose = make(chan struct{})
+ ret.blockClose = make(chan struct{})
+ ret.afterClose = make(chan struct{})
+ oldCloseFunc := b.closeFunc.Load()
+ b.closeFunc.Store(new(func(err error) {
+ b.closeFunc.Store(nil)
+ close(ret.beforeClose)
+ <-ret.blockClose
+ (*oldCloseFunc)(err)
+ close(ret.afterClose)
+ }))
+ b.debugGitCmd.DebugKill()
+ return ret
+}
+
+// catFileBatchParseInfoLine reads the header line from cat-file --batch
+// We expect: SP SP LF
+// then leaving the rest of the stream " LF" to be read
+func catFileBatchParseInfoLine(rd BufferedReader) (*CatFileObject, error) {
+ typ, err := rd.ReadString('\n')
+ if err != nil {
+ return nil, err
+ }
+ if len(typ) == 1 {
+ typ, err = rd.ReadString('\n')
+ if err != nil {
+ return nil, err
+ }
+ }
+ idx := strings.IndexByte(typ, ' ')
+ if idx < 0 {
+ return nil, ErrNotExist{}
+ }
+ sha := typ[:idx]
+ typ = typ[idx+1:]
+
+ idx = strings.IndexByte(typ, ' ')
+ if idx < 0 {
+ return nil, ErrNotExist{ID: sha}
+ }
+
+ sizeStr := typ[idx+1 : len(typ)-1]
+ typ = typ[:idx]
+
+ size, err := strconv.ParseInt(sizeStr, 10, 64)
+ return &CatFileObject{ID: sha, Type: typ, Size: size}, err
+}
+
+// ReadTagObjectID reads a tag object ID hash from a cat-file --batch stream, throwing away the rest of the stream.
+func ReadTagObjectID(rd BufferedReader, size int64) (string, error) {
+ var id string
+ var n int64
+headerLoop:
+ for {
+ line, err := rd.ReadBytes('\n')
+ if err != nil {
+ return "", err
+ }
+ n += int64(len(line))
+ idx := bytes.Index(line, []byte{' '})
+ if idx < 0 {
+ continue
+ }
+
+ if string(line[:idx]) == "object" {
+ id = string(line[idx+1 : len(line)-1])
+ break headerLoop
+ }
+ }
+
+ // Discard the rest of the tag
+ return id, DiscardFull(rd, size-n+1)
+}
+
+// ReadTreeID reads a tree ID from a cat-file --batch stream, throwing away the rest of the stream.
+func ReadTreeID(rd BufferedReader, size int64) (string, error) {
+ var id string
+ var n int64
+headerLoop:
+ for {
+ line, err := rd.ReadBytes('\n')
+ if err != nil {
+ return "", err
+ }
+ n += int64(len(line))
+ idx := bytes.Index(line, []byte{' '})
+ if idx < 0 {
+ continue
+ }
+
+ if string(line[:idx]) == "tree" {
+ id = string(line[idx+1 : len(line)-1])
+ break headerLoop
+ }
+ }
+
+ // Discard the rest of the commit
+ return id, DiscardFull(rd, size-n+1)
+}
+
+// git tree files are a list:
+// SP NUL
+//
+// Unfortunately this 20-byte notation is somewhat in conflict to all other git tools
+// Therefore we need some method to convert these binary hashes to hex hashes
+
+// ParseCatFileTreeLine reads an entry from a tree in a cat-file --batch stream
+// This carefully avoids allocations - except where fnameBuf is too small.
+// It is recommended therefore to pass in an fnameBuf large enough to avoid almost all allocations
+//
+// Each line is composed of:
+// SP NUL
+//
+// We don't attempt to convert the raw HASH to save a lot of time
+func ParseCatFileTreeLine(objectFormat ObjectFormat, rd BufferedReader, modeBuf, fnameBuf, shaBuf []byte) (mode, fname, sha []byte, n int, err error) {
+ var readBytes []byte
+
+ // Read the Mode & fname
+ readBytes, err = rd.ReadSlice('\x00')
+ if err != nil {
+ return mode, fname, sha, n, err
+ }
+ idx := bytes.IndexByte(readBytes, ' ')
+ if idx < 0 {
+ log.Debug("missing space in readBytes ParseCatFileTreeLine: %s", readBytes)
+ return mode, fname, sha, n, &ErrNotExist{}
+ }
+
+ n += idx + 1
+ copy(modeBuf, readBytes[:idx])
+ if len(modeBuf) >= idx {
+ modeBuf = modeBuf[:idx]
+ } else {
+ modeBuf = append(modeBuf, readBytes[len(modeBuf):idx]...)
+ }
+ mode = modeBuf
+
+ readBytes = readBytes[idx+1:]
+
+ // Deal with the fname
+ copy(fnameBuf, readBytes)
+ if len(fnameBuf) > len(readBytes) {
+ fnameBuf = fnameBuf[:len(readBytes)]
+ } else {
+ fnameBuf = append(fnameBuf, readBytes[len(fnameBuf):]...)
+ }
+ for err == bufio.ErrBufferFull {
+ readBytes, err = rd.ReadSlice('\x00')
+ fnameBuf = append(fnameBuf, readBytes...)
+ }
+ n += len(fnameBuf)
+ if err != nil {
+ return mode, fname, sha, n, err
+ }
+ fnameBuf = fnameBuf[:len(fnameBuf)-1]
+ fname = fnameBuf
+
+ // Deal with the binary hash
+ idx = 0
+ length := objectFormat.FullLength() / 2
+ for idx < length {
+ var read int
+ read, err = rd.Read(shaBuf[idx:length])
+ n += read
+ if err != nil {
+ return mode, fname, sha, n, err
+ }
+ idx += read
+ }
+ sha = shaBuf
+ return mode, fname, sha, n, err
+}
+
+func DiscardFull(rd BufferedReader, discard int64) error {
+ if discard > math.MaxInt32 {
+ n, err := rd.Discard(math.MaxInt32)
+ discard -= int64(n)
+ if err != nil {
+ return err
+ }
+ }
+ for discard > 0 {
+ n, err := rd.Discard(int(discard))
+ discard -= int64(n)
+ if err != nil {
+ return err
+ }
+ }
+ return nil
+}
diff --git a/modules/git/catfile_batch_test.go b/modules/git/catfile_batch_test.go
new file mode 100644
index 0000000000..782d34d249
--- /dev/null
+++ b/modules/git/catfile_batch_test.go
@@ -0,0 +1,105 @@
+// Copyright 2026 The Gitea Authors. All rights reserved.
+// SPDX-License-Identifier: MIT
+
+package git
+
+import (
+ "io"
+ "os"
+ "path/filepath"
+ "testing"
+
+ "code.gitea.io/gitea/modules/test"
+
+ "github.com/stretchr/testify/assert"
+ "github.com/stretchr/testify/require"
+)
+
+func TestCatFileBatch(t *testing.T) {
+ defer test.MockVariableValue(&DefaultFeatures().SupportCatFileBatchCommand)()
+ DefaultFeatures().SupportCatFileBatchCommand = false
+ t.Run("LegacyCheck", testCatFileBatch)
+ DefaultFeatures().SupportCatFileBatchCommand = true
+ t.Run("BatchCommand", testCatFileBatch)
+}
+
+func testCatFileBatch(t *testing.T) {
+ t.Run("CorruptedGitRepo", func(t *testing.T) {
+ tmpDir := t.TempDir()
+ batch, err := NewBatch(t.Context(), tmpDir)
+ // as long as the directory exists, no error, because we can't really know whether the git repo is valid until we run commands
+ require.NoError(t, err)
+ defer batch.Close()
+
+ _, err = batch.QueryInfo("e2129701f1a4d54dc44f03c93bca0a2aec7c5449")
+ require.Error(t, err)
+ _, err = batch.QueryInfo("e2129701f1a4d54dc44f03c93bca0a2aec7c5449")
+ require.Error(t, err)
+ })
+
+ simulateQueryTerminated := func(t *testing.T, errBeforePipeClose, errAfterPipeClose error) {
+ readError := func(t *testing.T, r io.Reader, expectedErr error) {
+ if expectedErr == nil {
+ return // expectedErr == nil means this read should be skipped
+ }
+ n, err := r.Read(make([]byte, 100))
+ assert.Zero(t, n)
+ assert.ErrorIs(t, err, expectedErr)
+ }
+
+ batch, err := NewBatch(t.Context(), filepath.Join(testReposDir, "repo1_bare"))
+ require.NoError(t, err)
+ defer batch.Close()
+ _, err = batch.QueryInfo("e2129701f1a4d54dc44f03c93bca0a2aec7c5449")
+ require.NoError(t, err)
+
+ var c *catFileBatchCommunicator
+ switch b := batch.(type) {
+ case *catFileBatchLegacy:
+ c = b.batchCheck
+ _, _ = c.reqWriter.Write([]byte("in-complete-line-"))
+ case *catFileBatchCommand:
+ c = b.batch
+ _, _ = c.reqWriter.Write([]byte("info"))
+ default:
+ t.FailNow()
+ }
+
+ require.NotEqual(t, errBeforePipeClose == nil, errAfterPipeClose == nil, "must set exactly one of the expected errors")
+
+ inceptor := c.debugKill()
+ <-inceptor.beforeClose // wait for the command's Close to be called, the pipe is not closed yet
+ readError(t, c.respReader, errBeforePipeClose) // then caller will read on an open pipe which will be closed soon
+ close(inceptor.blockClose) // continue to close the pipe
+ <-inceptor.afterClose // wait for the pipe to be closed
+ readError(t, c.respReader, errAfterPipeClose) // then caller will read on a closed pipe
+ }
+ t.Run("QueryTerminated", func(t *testing.T) {
+ simulateQueryTerminated(t, io.EOF, nil) // reader is faster
+ simulateQueryTerminated(t, nil, os.ErrClosed) // pipes are closed faster
+ })
+
+ batch, err := NewBatch(t.Context(), filepath.Join(testReposDir, "repo1_bare"))
+ require.NoError(t, err)
+ defer batch.Close()
+
+ t.Run("QueryInfo", func(t *testing.T) {
+ info, err := batch.QueryInfo("e2129701f1a4d54dc44f03c93bca0a2aec7c5449")
+ require.NoError(t, err)
+ assert.Equal(t, "e2129701f1a4d54dc44f03c93bca0a2aec7c5449", info.ID)
+ assert.Equal(t, "blob", info.Type)
+ assert.EqualValues(t, 6, info.Size)
+ })
+
+ t.Run("QueryContent", func(t *testing.T) {
+ info, rd, err := batch.QueryContent("e2129701f1a4d54dc44f03c93bca0a2aec7c5449")
+ require.NoError(t, err)
+ assert.Equal(t, "e2129701f1a4d54dc44f03c93bca0a2aec7c5449", info.ID)
+ assert.Equal(t, "blob", info.Type)
+ assert.EqualValues(t, 6, info.Size)
+
+ content, err := io.ReadAll(io.LimitReader(rd, info.Size))
+ require.NoError(t, err)
+ require.Equal(t, "file1\n", string(content))
+ })
+}
diff --git a/modules/git/commit.go b/modules/git/commit.go
index a0c5955ae8..9fb786cb99 100644
--- a/modules/git/commit.go
+++ b/modules/git/commit.go
@@ -5,17 +5,13 @@
package git
import (
- "bufio"
- "bytes"
"context"
"errors"
"io"
"os/exec"
- "strconv"
"strings"
"code.gitea.io/gitea/modules/git/gitcmd"
- "code.gitea.io/gitea/modules/log"
"code.gitea.io/gitea/modules/util"
)
@@ -41,7 +37,7 @@ type CommitSignature struct {
// Message returns the commit message. Same as retrieving CommitMessage directly.
func (c *Commit) Message() string {
- return c.CommitMessage
+ return strings.ToValidUTF8(c.CommitMessage, "?")
}
// Summary returns first line of commit message.
@@ -86,109 +82,6 @@ func (c *Commit) GetCommitByPath(relpath string) (*Commit, error) {
return c.repo.getCommitByPathWithID(c.ID, relpath)
}
-// AddChanges marks local changes to be ready for commit.
-func AddChanges(ctx context.Context, repoPath string, all bool, files ...string) error {
- cmd := gitcmd.NewCommand().AddArguments("add")
- if all {
- cmd.AddArguments("--all")
- }
- cmd.AddDashesAndList(files...)
- _, _, err := cmd.RunStdString(ctx, &gitcmd.RunOpts{Dir: repoPath})
- return err
-}
-
-// CommitChangesOptions the options when a commit created
-type CommitChangesOptions struct {
- Committer *Signature
- Author *Signature
- Message string
-}
-
-// CommitChanges commits local changes with given committer, author and message.
-// If author is nil, it will be the same as committer.
-func CommitChanges(ctx context.Context, repoPath string, opts CommitChangesOptions) error {
- cmd := gitcmd.NewCommand()
- if opts.Committer != nil {
- cmd.AddOptionValues("-c", "user.name="+opts.Committer.Name)
- cmd.AddOptionValues("-c", "user.email="+opts.Committer.Email)
- }
- cmd.AddArguments("commit")
-
- if opts.Author == nil {
- opts.Author = opts.Committer
- }
- if opts.Author != nil {
- cmd.AddOptionFormat("--author='%s <%s>'", opts.Author.Name, opts.Author.Email)
- }
- cmd.AddOptionFormat("--message=%s", opts.Message)
-
- _, _, err := cmd.RunStdString(ctx, &gitcmd.RunOpts{Dir: repoPath})
- // No stderr but exit status 1 means nothing to commit.
- if err != nil && err.Error() == "exit status 1" {
- return nil
- }
- return err
-}
-
-// AllCommitsCount returns count of all commits in repository
-func AllCommitsCount(ctx context.Context, repoPath string, hidePRRefs bool, files ...string) (int64, error) {
- cmd := gitcmd.NewCommand("rev-list")
- if hidePRRefs {
- cmd.AddArguments("--exclude=" + PullPrefix + "*")
- }
- cmd.AddArguments("--all", "--count")
- if len(files) > 0 {
- cmd.AddDashesAndList(files...)
- }
-
- stdout, _, err := cmd.RunStdString(ctx, &gitcmd.RunOpts{Dir: repoPath})
- if err != nil {
- return 0, err
- }
-
- return strconv.ParseInt(strings.TrimSpace(stdout), 10, 64)
-}
-
-// CommitsCountOptions the options when counting commits
-type CommitsCountOptions struct {
- RepoPath string
- Not string
- Revision []string
- RelPath []string
- Since string
- Until string
-}
-
-// CommitsCount returns number of total commits of until given revision.
-func CommitsCount(ctx context.Context, opts CommitsCountOptions) (int64, error) {
- cmd := gitcmd.NewCommand("rev-list", "--count")
-
- cmd.AddDynamicArguments(opts.Revision...)
-
- if opts.Not != "" {
- cmd.AddOptionValues("--not", opts.Not)
- }
-
- if len(opts.RelPath) > 0 {
- cmd.AddDashesAndList(opts.RelPath...)
- }
-
- stdout, _, err := cmd.RunStdString(ctx, &gitcmd.RunOpts{Dir: opts.RepoPath})
- if err != nil {
- return 0, err
- }
-
- return strconv.ParseInt(strings.TrimSpace(stdout), 10, 64)
-}
-
-// CommitsCount returns number of total commits of until current revision.
-func (c *Commit) CommitsCount() (int64, error) {
- return CommitsCount(c.repo.Ctx, CommitsCountOptions{
- RepoPath: c.repo.Path,
- Revision: []string{c.ID.String()},
- })
-}
-
// CommitsByRange returns the specific page commits before current revision, every page's number default by CommitsRangeSize
func (c *Commit) CommitsByRange(page, pageSize int, not, since, until string) ([]*Commit, error) {
return c.repo.commitsByRangeWithTime(c.ID, page, pageSize, not, since, until)
@@ -208,7 +101,10 @@ func (c *Commit) HasPreviousCommit(objectID ObjectID) (bool, error) {
return false, nil
}
- _, _, err := gitcmd.NewCommand("merge-base", "--is-ancestor").AddDynamicArguments(that, this).RunStdString(c.repo.Ctx, &gitcmd.RunOpts{Dir: c.repo.Path})
+ _, _, err := gitcmd.NewCommand("merge-base", "--is-ancestor").
+ AddDynamicArguments(that, this).
+ WithDir(c.repo.Path).
+ RunStdString(c.repo.Ctx)
if err == nil {
return true, nil
}
@@ -347,110 +243,14 @@ func (c *Commit) GetFileContent(filename string, limit int) (string, error) {
return string(bytes), nil
}
-// GetBranchName gets the closest branch name (as returned by 'git name-rev --name-only')
-func (c *Commit) GetBranchName() (string, error) {
- cmd := gitcmd.NewCommand("name-rev")
- if DefaultFeatures().CheckVersionAtLeast("2.13.0") {
- cmd.AddArguments("--exclude", "refs/tags/*")
- }
- cmd.AddArguments("--name-only", "--no-undefined").AddDynamicArguments(c.ID.String())
- data, _, err := cmd.RunStdString(c.repo.Ctx, &gitcmd.RunOpts{Dir: c.repo.Path})
- if err != nil {
- // handle special case where git can not describe commit
- if strings.Contains(err.Error(), "cannot describe") {
- return "", nil
- }
-
- return "", err
- }
-
- // name-rev commitID output will be "master" or "master~12"
- return strings.SplitN(strings.TrimSpace(data), "~", 2)[0], nil
-}
-
-// CommitFileStatus represents status of files in a commit.
-type CommitFileStatus struct {
- Added []string
- Removed []string
- Modified []string
-}
-
-// NewCommitFileStatus creates a CommitFileStatus
-func NewCommitFileStatus() *CommitFileStatus {
- return &CommitFileStatus{
- []string{}, []string{}, []string{},
- }
-}
-
-func parseCommitFileStatus(fileStatus *CommitFileStatus, stdout io.Reader) {
- rd := bufio.NewReader(stdout)
- peek, err := rd.Peek(1)
- if err != nil {
- if err != io.EOF {
- log.Error("Unexpected error whilst reading from git log --name-status. Error: %v", err)
- }
- return
- }
- if peek[0] == '\n' || peek[0] == '\x00' {
- _, _ = rd.Discard(1)
- }
- for {
- modifier, err := rd.ReadString('\x00')
- if err != nil {
- if err != io.EOF {
- log.Error("Unexpected error whilst reading from git log --name-status. Error: %v", err)
- }
- return
- }
- file, err := rd.ReadString('\x00')
- if err != nil {
- if err != io.EOF {
- log.Error("Unexpected error whilst reading from git log --name-status. Error: %v", err)
- }
- return
- }
- file = file[:len(file)-1]
- switch modifier[0] {
- case 'A':
- fileStatus.Added = append(fileStatus.Added, file)
- case 'D':
- fileStatus.Removed = append(fileStatus.Removed, file)
- case 'M':
- fileStatus.Modified = append(fileStatus.Modified, file)
- }
- }
-}
-
-// GetCommitFileStatus returns file status of commit in given repository.
-func GetCommitFileStatus(ctx context.Context, repoPath, commitID string) (*CommitFileStatus, error) {
- stdout, w := io.Pipe()
- done := make(chan struct{})
- fileStatus := NewCommitFileStatus()
- go func() {
- parseCommitFileStatus(fileStatus, stdout)
- close(done)
- }()
-
- stderr := new(bytes.Buffer)
- err := gitcmd.NewCommand("log", "--name-status", "-m", "--pretty=format:", "--first-parent", "--no-renames", "-z", "-1").AddDynamicArguments(commitID).Run(ctx, &gitcmd.RunOpts{
- Dir: repoPath,
- Stdout: w,
- Stderr: stderr,
- })
- w.Close() // Close writer to exit parsing goroutine
- if err != nil {
- return nil, gitcmd.ConcatenateError(err, stderr.String())
- }
-
- <-done
- return fileStatus, nil
-}
-
// GetFullCommitID returns full length (40) of commit ID by given short SHA in a repository.
func GetFullCommitID(ctx context.Context, repoPath, shortID string) (string, error) {
- commitID, _, err := gitcmd.NewCommand("rev-parse").AddDynamicArguments(shortID).RunStdString(ctx, &gitcmd.RunOpts{Dir: repoPath})
+ commitID, _, err := gitcmd.NewCommand("rev-parse").
+ AddDynamicArguments(shortID).
+ WithDir(repoPath).
+ RunStdString(ctx)
if err != nil {
- if strings.Contains(err.Error(), "exit status 128") {
+ if gitcmd.IsErrorExitCode(err, 128) {
return "", ErrNotExist{shortID, ""}
}
return "", err
@@ -458,14 +258,6 @@ func GetFullCommitID(ctx context.Context, repoPath, shortID string) (string, err
return strings.TrimSpace(commitID), nil
}
-// GetRepositoryDefaultPublicGPGKey returns the default public key for this commit
-func (c *Commit) GetRepositoryDefaultPublicGPGKey(forceUpdate bool) (*GPGSettings, error) {
- if c.repo == nil {
- return nil, nil
- }
- return c.repo.GetDefaultPublicGPGKey(forceUpdate)
-}
-
func IsStringLikelyCommitID(objFmt ObjectFormat, s string, minLength ...int) bool {
maxLen := 64 // sha256
if objFmt != nil {
diff --git a/modules/git/commit_info_test.go b/modules/git/commit_info_test.go
index 51e1551d2d..1e1697b006 100644
--- a/modules/git/commit_info_test.go
+++ b/modules/git/commit_info_test.go
@@ -30,28 +30,57 @@ func cloneRepo(tb testing.TB, url string) (string, error) {
}
func testGetCommitsInfo(t *testing.T, repo1 *Repository) {
+ type expectedEntryInfo struct {
+ CommitID string
+ Size int64
+ }
+
// these test case are specific to the repo1 test repo
testCases := []struct {
CommitID string
Path string
- ExpectedIDs map[string]string
+ ExpectedIDs map[string]expectedEntryInfo
ExpectedTreeCommit string
}{
- {"8d92fc957a4d7cfd98bc375f0b7bb189a0d6c9f2", "", map[string]string{
- "file1.txt": "95bb4d39648ee7e325106df01a621c530863a653",
- "file2.txt": "8d92fc957a4d7cfd98bc375f0b7bb189a0d6c9f2",
+ {"8d92fc957a4d7cfd98bc375f0b7bb189a0d6c9f2", "", map[string]expectedEntryInfo{
+ "file1.txt": {
+ CommitID: "95bb4d39648ee7e325106df01a621c530863a653",
+ Size: 6,
+ },
+ "file2.txt": {
+ CommitID: "8d92fc957a4d7cfd98bc375f0b7bb189a0d6c9f2",
+ Size: 6,
+ },
}, "8d92fc957a4d7cfd98bc375f0b7bb189a0d6c9f2"},
- {"2839944139e0de9737a044f78b0e4b40d989a9e3", "", map[string]string{
- "file1.txt": "2839944139e0de9737a044f78b0e4b40d989a9e3",
- "branch1.txt": "9c9aef8dd84e02bc7ec12641deb4c930a7c30185",
+ {"2839944139e0de9737a044f78b0e4b40d989a9e3", "", map[string]expectedEntryInfo{
+ "file1.txt": {
+ CommitID: "2839944139e0de9737a044f78b0e4b40d989a9e3",
+ Size: 15,
+ },
+ "branch1.txt": {
+ CommitID: "9c9aef8dd84e02bc7ec12641deb4c930a7c30185",
+ Size: 8,
+ },
}, "2839944139e0de9737a044f78b0e4b40d989a9e3"},
- {"5c80b0245c1c6f8343fa418ec374b13b5d4ee658", "branch2", map[string]string{
- "branch2.txt": "5c80b0245c1c6f8343fa418ec374b13b5d4ee658",
+ {"5c80b0245c1c6f8343fa418ec374b13b5d4ee658", "branch2", map[string]expectedEntryInfo{
+ "branch2.txt": {
+ CommitID: "5c80b0245c1c6f8343fa418ec374b13b5d4ee658",
+ Size: 8,
+ },
}, "5c80b0245c1c6f8343fa418ec374b13b5d4ee658"},
- {"feaf4ba6bc635fec442f46ddd4512416ec43c2c2", "", map[string]string{
- "file1.txt": "95bb4d39648ee7e325106df01a621c530863a653",
- "file2.txt": "8d92fc957a4d7cfd98bc375f0b7bb189a0d6c9f2",
- "foo": "37991dec2c8e592043f47155ce4808d4580f9123",
+ {"feaf4ba6bc635fec442f46ddd4512416ec43c2c2", "", map[string]expectedEntryInfo{
+ "file1.txt": {
+ CommitID: "95bb4d39648ee7e325106df01a621c530863a653",
+ Size: 6,
+ },
+ "file2.txt": {
+ CommitID: "8d92fc957a4d7cfd98bc375f0b7bb189a0d6c9f2",
+ Size: 6,
+ },
+ "foo": {
+ CommitID: "37991dec2c8e592043f47155ce4808d4580f9123",
+ Size: 0,
+ },
}, "feaf4ba6bc635fec442f46ddd4512416ec43c2c2"},
}
for _, testCase := range testCases {
@@ -93,11 +122,12 @@ func testGetCommitsInfo(t *testing.T, repo1 *Repository) {
for _, commitInfo := range commitsInfo {
entry := commitInfo.Entry
commit := commitInfo.Commit
- expectedID, ok := testCase.ExpectedIDs[entry.Name()]
+ expectedInfo, ok := testCase.ExpectedIDs[entry.Name()]
if !assert.True(t, ok) {
continue
}
- assert.Equal(t, expectedID, commit.ID.String())
+ assert.Equal(t, expectedInfo.CommitID, commit.ID.String())
+ assert.Equal(t, expectedInfo.Size, entry.Size(), entry.Name())
}
}
}
@@ -173,7 +203,6 @@ func BenchmarkEntries_GetCommitsInfo(b *testing.B) {
} else if entries, err = commit.Tree.ListEntries(); err != nil {
b.Fatal(err)
}
- entries.Sort()
b.ResetTimer()
b.Run(benchmark.name, func(b *testing.B) {
for b.Loop() {
diff --git a/modules/git/commit_sha256_test.go b/modules/git/commit_sha256_test.go
index 772f5eedb2..0aefb30c95 100644
--- a/modules/git/commit_sha256_test.go
+++ b/modules/git/commit_sha256_test.go
@@ -14,33 +14,6 @@ import (
"github.com/stretchr/testify/require"
)
-func TestCommitsCountSha256(t *testing.T) {
- bareRepo1Path := filepath.Join(testReposDir, "repo1_bare_sha256")
-
- commitsCount, err := CommitsCount(t.Context(),
- CommitsCountOptions{
- RepoPath: bareRepo1Path,
- Revision: []string{"f004f41359117d319dedd0eaab8c5259ee2263da839dcba33637997458627fdc"},
- })
-
- assert.NoError(t, err)
- assert.Equal(t, int64(3), commitsCount)
-}
-
-func TestCommitsCountWithoutBaseSha256(t *testing.T) {
- bareRepo1Path := filepath.Join(testReposDir, "repo1_bare_sha256")
-
- commitsCount, err := CommitsCount(t.Context(),
- CommitsCountOptions{
- RepoPath: bareRepo1Path,
- Not: "main",
- Revision: []string{"branch1"},
- })
-
- assert.NoError(t, err)
- assert.Equal(t, int64(2), commitsCount)
-}
-
func TestGetFullCommitIDSha256(t *testing.T) {
bareRepo1Path := filepath.Join(testReposDir, "repo1_bare_sha256")
@@ -157,39 +130,3 @@ func TestHasPreviousCommitSha256(t *testing.T) {
assert.NoError(t, err)
assert.False(t, selfNot)
}
-
-func TestGetCommitFileStatusMergesSha256(t *testing.T) {
- bareRepo1Path := filepath.Join(testReposDir, "repo6_merge_sha256")
-
- commitFileStatus, err := GetCommitFileStatus(t.Context(), bareRepo1Path, "d2e5609f630dd8db500f5298d05d16def282412e3e66ed68cc7d0833b29129a1")
- assert.NoError(t, err)
-
- expected := CommitFileStatus{
- []string{
- "add_file.txt",
- },
- []string{},
- []string{
- "to_modify.txt",
- },
- }
-
- assert.Equal(t, expected.Added, commitFileStatus.Added)
- assert.Equal(t, expected.Removed, commitFileStatus.Removed)
- assert.Equal(t, expected.Modified, commitFileStatus.Modified)
-
- expected = CommitFileStatus{
- []string{},
- []string{
- "to_remove.txt",
- },
- []string{},
- }
-
- commitFileStatus, err = GetCommitFileStatus(t.Context(), bareRepo1Path, "da1ded40dc8e5b7c564171f4bf2fc8370487decfb1cb6a99ef28f3ed73d09172")
- assert.NoError(t, err)
-
- assert.Equal(t, expected.Added, commitFileStatus.Added)
- assert.Equal(t, expected.Removed, commitFileStatus.Removed)
- assert.Equal(t, expected.Modified, commitFileStatus.Modified)
-}
diff --git a/modules/git/commit_submodule.go b/modules/git/commit_submodule.go
index ff253b7eca..5e5f90c20e 100644
--- a/modules/git/commit_submodule.go
+++ b/modules/git/commit_submodule.go
@@ -16,7 +16,7 @@ func (c *Commit) GetSubModules() (*ObjectCache[*SubModule], error) {
entry, err := c.GetTreeEntryByPath(".gitmodules")
if err != nil {
if _, ok := err.(ErrNotExist); ok {
- return nil, nil
+ return nil, nil //nolint:nilnil // return nil to indicate that the submodule does not exist
}
return nil, err
}
@@ -48,5 +48,5 @@ func (c *Commit) GetSubModule(entryName string) (*SubModule, error) {
return module, nil
}
}
- return nil, nil
+ return nil, nil //nolint:nilnil // return nil to indicate that the submodule does not exist
}
diff --git a/modules/git/commit_test.go b/modules/git/commit_test.go
index 688b4e294f..d399fb377a 100644
--- a/modules/git/commit_test.go
+++ b/modules/git/commit_test.go
@@ -13,33 +13,6 @@ import (
"github.com/stretchr/testify/require"
)
-func TestCommitsCount(t *testing.T) {
- bareRepo1Path := filepath.Join(testReposDir, "repo1_bare")
-
- commitsCount, err := CommitsCount(t.Context(),
- CommitsCountOptions{
- RepoPath: bareRepo1Path,
- Revision: []string{"8006ff9adbf0cb94da7dad9e537e53817f9fa5c0"},
- })
-
- assert.NoError(t, err)
- assert.Equal(t, int64(3), commitsCount)
-}
-
-func TestCommitsCountWithoutBase(t *testing.T) {
- bareRepo1Path := filepath.Join(testReposDir, "repo1_bare")
-
- commitsCount, err := CommitsCount(t.Context(),
- CommitsCountOptions{
- RepoPath: bareRepo1Path,
- Not: "master",
- Revision: []string{"branch1"},
- })
-
- assert.NoError(t, err)
- assert.Equal(t, int64(2), commitsCount)
-}
-
func TestGetFullCommitID(t *testing.T) {
bareRepo1Path := filepath.Join(testReposDir, "repo1_bare")
@@ -186,6 +159,14 @@ ISO-8859-1`, commitFromReader.Signature.Payload)
assert.Equal(t, commitFromReader, commitFromReader2)
}
+func TestCommitMessageSanitizesInvalidUTF8(t *testing.T) {
+ commit := &Commit{
+ CommitMessage: "title \xff\n\n\nbody \xff\n\n\n",
+ }
+ assert.Equal(t, "title ?\n\n\nbody ?\n\n\n", commit.Message())
+ assert.Equal(t, "title ?", commit.Summary())
+}
+
func TestHasPreviousCommit(t *testing.T) {
bareRepo1Path := filepath.Join(testReposDir, "repo1_bare")
@@ -212,134 +193,6 @@ func TestHasPreviousCommit(t *testing.T) {
assert.False(t, selfNot)
}
-func TestParseCommitFileStatus(t *testing.T) {
- type testcase struct {
- output string
- added []string
- removed []string
- modified []string
- }
-
- kases := []testcase{
- {
- // Merge commit
- output: "MM\x00options/locale/locale_en-US.ini\x00",
- modified: []string{
- "options/locale/locale_en-US.ini",
- },
- added: []string{},
- removed: []string{},
- },
- {
- // Spaces commit
- output: "D\x00b\x00D\x00b b/b\x00A\x00b b/b b/b b/b\x00A\x00b b/b b/b b/b b/b\x00",
- removed: []string{
- "b",
- "b b/b",
- },
- modified: []string{},
- added: []string{
- "b b/b b/b b/b",
- "b b/b b/b b/b b/b",
- },
- },
- {
- // larger commit
- output: "M\x00go.mod\x00M\x00go.sum\x00M\x00modules/ssh/ssh.go\x00M\x00vendor/github.com/gliderlabs/ssh/circle.yml\x00M\x00vendor/github.com/gliderlabs/ssh/context.go\x00A\x00vendor/github.com/gliderlabs/ssh/go.mod\x00A\x00vendor/github.com/gliderlabs/ssh/go.sum\x00M\x00vendor/github.com/gliderlabs/ssh/server.go\x00M\x00vendor/github.com/gliderlabs/ssh/session.go\x00M\x00vendor/github.com/gliderlabs/ssh/ssh.go\x00M\x00vendor/golang.org/x/sys/unix/mkerrors.sh\x00M\x00vendor/golang.org/x/sys/unix/syscall_darwin.go\x00M\x00vendor/golang.org/x/sys/unix/zerrors_darwin_amd64.go\x00M\x00vendor/golang.org/x/sys/unix/zerrors_darwin_arm64.go\x00M\x00vendor/golang.org/x/sys/unix/zerrors_freebsd_386.go\x00M\x00vendor/golang.org/x/sys/unix/zerrors_freebsd_amd64.go\x00M\x00vendor/golang.org/x/sys/unix/zerrors_freebsd_arm.go\x00M\x00vendor/golang.org/x/sys/unix/zerrors_freebsd_arm64.go\x00M\x00vendor/golang.org/x/sys/unix/zerrors_linux.go\x00M\x00vendor/golang.org/x/sys/unix/ztypes_darwin_amd64.go\x00M\x00vendor/golang.org/x/sys/unix/ztypes_darwin_arm64.go\x00M\x00vendor/golang.org/x/sys/unix/ztypes_dragonfly_amd64.go\x00M\x00vendor/golang.org/x/sys/unix/ztypes_freebsd_386.go\x00M\x00vendor/golang.org/x/sys/unix/ztypes_freebsd_amd64.go\x00M\x00vendor/golang.org/x/sys/unix/ztypes_freebsd_arm.go\x00M\x00vendor/golang.org/x/sys/unix/ztypes_freebsd_arm64.go\x00M\x00vendor/golang.org/x/sys/unix/ztypes_netbsd_386.go\x00M\x00vendor/golang.org/x/sys/unix/ztypes_netbsd_amd64.go\x00M\x00vendor/golang.org/x/sys/unix/ztypes_netbsd_arm.go\x00M\x00vendor/golang.org/x/sys/unix/ztypes_netbsd_arm64.go\x00M\x00vendor/modules.txt\x00",
- modified: []string{
- "go.mod",
- "go.sum",
- "modules/ssh/ssh.go",
- "vendor/github.com/gliderlabs/ssh/circle.yml",
- "vendor/github.com/gliderlabs/ssh/context.go",
- "vendor/github.com/gliderlabs/ssh/server.go",
- "vendor/github.com/gliderlabs/ssh/session.go",
- "vendor/github.com/gliderlabs/ssh/ssh.go",
- "vendor/golang.org/x/sys/unix/mkerrors.sh",
- "vendor/golang.org/x/sys/unix/syscall_darwin.go",
- "vendor/golang.org/x/sys/unix/zerrors_darwin_amd64.go",
- "vendor/golang.org/x/sys/unix/zerrors_darwin_arm64.go",
- "vendor/golang.org/x/sys/unix/zerrors_freebsd_386.go",
- "vendor/golang.org/x/sys/unix/zerrors_freebsd_amd64.go",
- "vendor/golang.org/x/sys/unix/zerrors_freebsd_arm.go",
- "vendor/golang.org/x/sys/unix/zerrors_freebsd_arm64.go",
- "vendor/golang.org/x/sys/unix/zerrors_linux.go",
- "vendor/golang.org/x/sys/unix/ztypes_darwin_amd64.go",
- "vendor/golang.org/x/sys/unix/ztypes_darwin_arm64.go",
- "vendor/golang.org/x/sys/unix/ztypes_dragonfly_amd64.go",
- "vendor/golang.org/x/sys/unix/ztypes_freebsd_386.go",
- "vendor/golang.org/x/sys/unix/ztypes_freebsd_amd64.go",
- "vendor/golang.org/x/sys/unix/ztypes_freebsd_arm.go",
- "vendor/golang.org/x/sys/unix/ztypes_freebsd_arm64.go",
- "vendor/golang.org/x/sys/unix/ztypes_netbsd_386.go",
- "vendor/golang.org/x/sys/unix/ztypes_netbsd_amd64.go",
- "vendor/golang.org/x/sys/unix/ztypes_netbsd_arm.go",
- "vendor/golang.org/x/sys/unix/ztypes_netbsd_arm64.go",
- "vendor/modules.txt",
- },
- added: []string{
- "vendor/github.com/gliderlabs/ssh/go.mod",
- "vendor/github.com/gliderlabs/ssh/go.sum",
- },
- removed: []string{},
- },
- {
- // git 1.7.2 adds an unnecessary \x00 on merge commit
- output: "\x00MM\x00options/locale/locale_en-US.ini\x00",
- modified: []string{
- "options/locale/locale_en-US.ini",
- },
- added: []string{},
- removed: []string{},
- },
- {
- // git 1.7.2 adds an unnecessary \n on normal commit
- output: "\nD\x00b\x00D\x00b b/b\x00A\x00b b/b b/b b/b\x00A\x00b b/b b/b b/b b/b\x00",
- removed: []string{
- "b",
- "b b/b",
- },
- modified: []string{},
- added: []string{
- "b b/b b/b b/b",
- "b b/b b/b b/b b/b",
- },
- },
- }
-
- for _, kase := range kases {
- fileStatus := NewCommitFileStatus()
- parseCommitFileStatus(fileStatus, strings.NewReader(kase.output))
-
- assert.Equal(t, kase.added, fileStatus.Added)
- assert.Equal(t, kase.removed, fileStatus.Removed)
- assert.Equal(t, kase.modified, fileStatus.Modified)
- }
-}
-
-func TestGetCommitFileStatusMerges(t *testing.T) {
- bareRepo1Path := filepath.Join(testReposDir, "repo6_merge")
-
- commitFileStatus, err := GetCommitFileStatus(t.Context(), bareRepo1Path, "022f4ce6214973e018f02bf363bf8a2e3691f699")
- assert.NoError(t, err)
-
- expected := CommitFileStatus{
- []string{
- "add_file.txt",
- },
- []string{
- "to_remove.txt",
- },
- []string{
- "to_modify.txt",
- },
- }
-
- assert.Equal(t, expected.Added, commitFileStatus.Added)
- assert.Equal(t, expected.Removed, commitFileStatus.Removed)
- assert.Equal(t, expected.Modified, commitFileStatus.Modified)
-}
-
func Test_GetCommitBranchStart(t *testing.T) {
bareRepo1Path := filepath.Join(testReposDir, "repo1_bare")
repo, err := OpenRepository(t.Context(), bareRepo1Path)
diff --git a/modules/git/config.go b/modules/git/config.go
index 2eafe971b3..79aa0535e4 100644
--- a/modules/git/config.go
+++ b/modules/git/config.go
@@ -118,7 +118,9 @@ func syncGitConfig(ctx context.Context) (err error) {
}
func configSet(ctx context.Context, key, value string) error {
- stdout, _, err := gitcmd.NewCommand("config", "--global", "--get").AddDynamicArguments(key).RunStdString(ctx, nil)
+ stdout, _, err := gitcmd.NewCommand("config", "--global", "--get").
+ AddDynamicArguments(key).
+ RunStdString(ctx)
if err != nil && !gitcmd.IsErrorExitCode(err, 1) {
return fmt.Errorf("failed to get git config %s, err: %w", key, err)
}
@@ -128,8 +130,9 @@ func configSet(ctx context.Context, key, value string) error {
return nil
}
- _, _, err = gitcmd.NewCommand("config", "--global").AddDynamicArguments(key, value).RunStdString(ctx, nil)
- if err != nil {
+ if _, _, err = gitcmd.NewCommand("config", "--global").
+ AddDynamicArguments(key, value).
+ RunStdString(ctx); err != nil {
return fmt.Errorf("failed to set git global config %s, err: %w", key, err)
}
@@ -137,14 +140,14 @@ func configSet(ctx context.Context, key, value string) error {
}
func configSetNonExist(ctx context.Context, key, value string) error {
- _, _, err := gitcmd.NewCommand("config", "--global", "--get").AddDynamicArguments(key).RunStdString(ctx, nil)
+ _, _, err := gitcmd.NewCommand("config", "--global", "--get").AddDynamicArguments(key).RunStdString(ctx)
if err == nil {
// already exist
return nil
}
if gitcmd.IsErrorExitCode(err, 1) {
// not exist, set new config
- _, _, err = gitcmd.NewCommand("config", "--global").AddDynamicArguments(key, value).RunStdString(ctx, nil)
+ _, _, err = gitcmd.NewCommand("config", "--global").AddDynamicArguments(key, value).RunStdString(ctx)
if err != nil {
return fmt.Errorf("failed to set git global config %s, err: %w", key, err)
}
@@ -155,14 +158,14 @@ func configSetNonExist(ctx context.Context, key, value string) error {
}
func configAddNonExist(ctx context.Context, key, value string) error {
- _, _, err := gitcmd.NewCommand("config", "--global", "--get").AddDynamicArguments(key, regexp.QuoteMeta(value)).RunStdString(ctx, nil)
+ _, _, err := gitcmd.NewCommand("config", "--global", "--get").AddDynamicArguments(key, regexp.QuoteMeta(value)).RunStdString(ctx)
if err == nil {
// already exist
return nil
}
if gitcmd.IsErrorExitCode(err, 1) {
// not exist, add new config
- _, _, err = gitcmd.NewCommand("config", "--global", "--add").AddDynamicArguments(key, value).RunStdString(ctx, nil)
+ _, _, err = gitcmd.NewCommand("config", "--global", "--add").AddDynamicArguments(key, value).RunStdString(ctx)
if err != nil {
return fmt.Errorf("failed to add git global config %s, err: %w", key, err)
}
@@ -172,10 +175,10 @@ func configAddNonExist(ctx context.Context, key, value string) error {
}
func configUnsetAll(ctx context.Context, key, value string) error {
- _, _, err := gitcmd.NewCommand("config", "--global", "--get").AddDynamicArguments(key).RunStdString(ctx, nil)
+ _, _, err := gitcmd.NewCommand("config", "--global", "--get").AddDynamicArguments(key).RunStdString(ctx)
if err == nil {
// exist, need to remove
- _, _, err = gitcmd.NewCommand("config", "--global", "--unset-all").AddDynamicArguments(key, regexp.QuoteMeta(value)).RunStdString(ctx, nil)
+ _, _, err = gitcmd.NewCommand("config", "--global", "--unset-all").AddDynamicArguments(key, regexp.QuoteMeta(value)).RunStdString(ctx)
if err != nil {
return fmt.Errorf("failed to unset git global config %s, err: %w", key, err)
}
diff --git a/modules/git/diff.go b/modules/git/diff.go
index d185cc9277..d7732eaa29 100644
--- a/modules/git/diff.go
+++ b/modules/git/diff.go
@@ -5,71 +5,83 @@ package git
import (
"bufio"
- "bytes"
"context"
"fmt"
"io"
- "os"
"regexp"
"strconv"
"strings"
"code.gitea.io/gitea/modules/git/gitcmd"
"code.gitea.io/gitea/modules/log"
+ "code.gitea.io/gitea/modules/setting"
+ "code.gitea.io/gitea/modules/util"
)
-// RawDiffType type of a raw diff.
+// RawDiffType output format: diff or patch
type RawDiffType string
-// RawDiffType possible values.
const (
RawDiffNormal RawDiffType = "diff"
RawDiffPatch RawDiffType = "patch"
)
// GetRawDiff dumps diff results of repository in given commit ID to io.Writer.
-func GetRawDiff(repo *Repository, commitID string, diffType RawDiffType, writer io.Writer) error {
- return GetRepoRawDiffForFile(repo, "", commitID, diffType, "", writer)
+func GetRawDiff(repo *Repository, commitID string, diffType RawDiffType, writer io.Writer) (retErr error) {
+ cmd, err := getRepoRawDiffForFileCmd(repo.Ctx, repo, "", commitID, diffType, "")
+ if err != nil {
+ return fmt.Errorf("getRepoRawDiffForFileCmd: %w", err)
+ }
+ return cmd.WithStdoutCopy(writer).RunWithStderr(repo.Ctx)
}
-// GetReverseRawDiff dumps the reverse diff results of repository in given commit ID to io.Writer.
-func GetReverseRawDiff(ctx context.Context, repoPath, commitID string, writer io.Writer) error {
- stderr := new(bytes.Buffer)
- cmd := gitcmd.NewCommand("show", "--pretty=format:revert %H%n", "-R").AddDynamicArguments(commitID)
- if err := cmd.Run(ctx, &gitcmd.RunOpts{
- Dir: repoPath,
- Stdout: writer,
- Stderr: stderr,
- }); err != nil {
- return fmt.Errorf("Run: %w - %s", err, stderr)
+// GetFileDiffCutAroundLine cuts the old or new part of the diff of a file around a specific line number
+func GetFileDiffCutAroundLine(
+ repo *Repository, startCommit, endCommit, treePath string,
+ line int64, old bool, numbersOfLine int,
+) (ret string, retErr error) {
+ cmd, err := getRepoRawDiffForFileCmd(repo.Ctx, repo, startCommit, endCommit, RawDiffNormal, treePath)
+ if err != nil {
+ return "", fmt.Errorf("getRepoRawDiffForFileCmd: %w", err)
}
- return nil
+ stdoutReader, stdoutClose := cmd.MakeStdoutPipe()
+ defer stdoutClose()
+ cmd.WithPipelineFunc(func(ctx gitcmd.Context) error {
+ ret, err = CutDiffAroundLine(stdoutReader, line, old, numbersOfLine)
+ return err
+ })
+ return ret, cmd.RunWithStderr(repo.Ctx)
}
-// GetRepoRawDiffForFile dumps diff results of file in given commit ID to io.Writer according given repository
-func GetRepoRawDiffForFile(repo *Repository, startCommit, endCommit string, diffType RawDiffType, file string, writer io.Writer) error {
+// getRepoRawDiffForFile returns an io.Reader for the diff results of file in given commit ID
+// and a "finish" function to wait for the git command and clean up resources after reading is done.
+func getRepoRawDiffForFileCmd(_ context.Context, repo *Repository, startCommit, endCommit string, diffType RawDiffType, file string) (*gitcmd.Command, error) {
commit, err := repo.GetCommit(endCommit)
if err != nil {
- return err
+ return nil, err
}
var files []string
if len(file) > 0 {
files = append(files, file)
}
- cmd := gitcmd.NewCommand()
+ cmd := gitcmd.NewCommand().WithDir(repo.Path)
switch diffType {
case RawDiffNormal:
if len(startCommit) != 0 {
- cmd.AddArguments("diff", "-M").AddDynamicArguments(startCommit, endCommit).AddDashesAndList(files...)
+ cmd.AddArguments("diff").
+ AddOptionFormat("--find-renames=%s", setting.Git.DiffRenameSimilarityThreshold).
+ AddDynamicArguments(startCommit, endCommit).AddDashesAndList(files...)
} else if commit.ParentCount() == 0 {
cmd.AddArguments("show").AddDynamicArguments(endCommit).AddDashesAndList(files...)
} else {
c, err := commit.Parent(0)
if err != nil {
- return err
+ return nil, err
}
- cmd.AddArguments("diff", "-M").AddDynamicArguments(c.ID.String(), endCommit).AddDashesAndList(files...)
+ cmd.AddArguments("diff").
+ AddOptionFormat("--find-renames=%s", setting.Git.DiffRenameSimilarityThreshold).
+ AddDynamicArguments(c.ID.String(), endCommit).AddDashesAndList(files...)
}
case RawDiffPatch:
if len(startCommit) != 0 {
@@ -80,24 +92,15 @@ func GetRepoRawDiffForFile(repo *Repository, startCommit, endCommit string, diff
} else {
c, err := commit.Parent(0)
if err != nil {
- return err
+ return nil, err
}
query := fmt.Sprintf("%s...%s", endCommit, c.ID.String())
cmd.AddArguments("format-patch", "--no-signature", "--stdout").AddDynamicArguments(query).AddDashesAndList(files...)
}
default:
- return fmt.Errorf("invalid diffType: %s", diffType)
+ return nil, util.NewInvalidArgumentErrorf("invalid diff type: %s", diffType)
}
-
- stderr := new(bytes.Buffer)
- if err = cmd.Run(repo.Ctx, &gitcmd.RunOpts{
- Dir: repo.Path,
- Stdout: writer,
- Stderr: stderr,
- }); err != nil {
- return fmt.Errorf("Run: %w - %s", err, stderr)
- }
- return nil
+ return cmd, nil
}
// ParseDiffHunkString parse the diff hunk content and return
@@ -234,7 +237,7 @@ func CutDiffAroundLine(originalDiff io.Reader, line int64, old bool, numbersOfLi
}
}
if err := scanner.Err(); err != nil {
- return "", err
+ return "", fmt.Errorf("CutDiffAroundLine: scan: %w", err)
}
// No hunk found
@@ -300,43 +303,27 @@ func GetAffectedFiles(repo *Repository, branchName, oldCommitID, newCommitID str
}
oldCommitID = startCommitID
}
- stdoutReader, stdoutWriter, err := os.Pipe()
- if err != nil {
- log.Error("Unable to create os.Pipe for %s", repo.Path)
- return nil, err
- }
- defer func() {
- _ = stdoutReader.Close()
- _ = stdoutWriter.Close()
- }()
affectedFiles := make([]string, 0, 32)
// Run `git diff --name-only` to get the names of the changed files
- err = gitcmd.NewCommand("diff", "--name-only").AddDynamicArguments(oldCommitID, newCommitID).
- Run(repo.Ctx, &gitcmd.RunOpts{
- Env: env,
- Dir: repo.Path,
- Stdout: stdoutWriter,
- PipelineFunc: func(ctx context.Context, cancel context.CancelFunc) error {
- // Close the writer end of the pipe to begin processing
- _ = stdoutWriter.Close()
- defer func() {
- // Close the reader on return to terminate the git command if necessary
- _ = stdoutReader.Close()
- }()
- // Now scan the output from the command
- scanner := bufio.NewScanner(stdoutReader)
- for scanner.Scan() {
- path := strings.TrimSpace(scanner.Text())
- if len(path) == 0 {
- continue
- }
- affectedFiles = append(affectedFiles, path)
+ cmd := gitcmd.NewCommand("diff", "--name-only").AddDynamicArguments(oldCommitID, newCommitID)
+ stdoutReader, stdoutReaderClose := cmd.MakeStdoutPipe()
+ defer stdoutReaderClose()
+ err := cmd.WithEnv(env).WithDir(repo.Path).
+ WithPipelineFunc(func(ctx gitcmd.Context) error {
+ // Now scan the output from the command
+ scanner := bufio.NewScanner(stdoutReader)
+ for scanner.Scan() {
+ path := strings.TrimSpace(scanner.Text())
+ if len(path) == 0 {
+ continue
}
- return scanner.Err()
- },
- })
+ affectedFiles = append(affectedFiles, path)
+ }
+ return scanner.Err()
+ }).
+ Run(repo.Ctx)
if err != nil {
log.Error("Unable to get affected files for commits from %s to %s in %s: %v", oldCommitID, newCommitID, repo.Path, err)
}
diff --git a/modules/git/error.go b/modules/git/error.go
index 7d131345d0..1b7bdca043 100644
--- a/modules/git/error.go
+++ b/modules/git/error.go
@@ -4,8 +4,6 @@
package git
import (
- "context"
- "errors"
"fmt"
"strings"
@@ -98,28 +96,31 @@ func (err *ErrPushRejected) Unwrap() error {
// GenerateMessage generates the remote message from the stderr
func (err *ErrPushRejected) GenerateMessage() {
- messageBuilder := &strings.Builder{}
- i := strings.Index(err.StdErr, "remote: ")
- if i < 0 {
- err.Message = ""
+ // The stderr is like this:
+ //
+ // > remote: error: push is rejected .....
+ // > To /work/gitea/tests/integration/gitea-integration-sqlite/gitea-repositories/user2/repo1.git
+ // > ! [remote rejected] 44e67c77559211d21b630b902cdcc6ab9d4a4f51 -> develop (pre-receive hook declined)
+ // > error: failed to push some refs to '/work/gitea/tests/integration/gitea-integration-sqlite/gitea-repositories/user2/repo1.git'
+ //
+ // The local message contains sensitive information, so we only need the remote message
+ const prefixRemote = "remote: "
+ const prefixError = "error: "
+ pos := strings.Index(err.StdErr, prefixRemote)
+ if pos < 0 {
+ err.Message = "push is rejected"
return
}
- for {
- if len(err.StdErr) <= i+8 {
- break
- }
- if err.StdErr[i:i+8] != "remote: " {
- break
- }
- i += 8
- nl := strings.IndexByte(err.StdErr[i:], '\n')
- if nl >= 0 {
- messageBuilder.WriteString(err.StdErr[i : i+nl+1])
- i = i + nl + 1
- } else {
- messageBuilder.WriteString(err.StdErr[i:])
- i = len(err.StdErr)
+
+ messageBuilder := &strings.Builder{}
+ lines := strings.SplitSeq(err.StdErr, "\n")
+ for line := range lines {
+ line, ok := strings.CutPrefix(line, prefixRemote)
+ if !ok {
+ continue
}
+ line = strings.TrimPrefix(line, prefixError)
+ messageBuilder.WriteString(strings.TrimSpace(line) + "\n")
}
err.Message = strings.TrimSpace(messageBuilder.String())
}
@@ -140,10 +141,3 @@ func IsErrMoreThanOne(err error) bool {
func (err *ErrMoreThanOne) Error() string {
return fmt.Sprintf("ErrMoreThanOne Error: %v: %s\n%s", err.Err, err.StdErr, err.StdOut)
}
-
-func IsErrCanceledOrKilled(err error) bool {
- // When "cancel()" a git command's context, the returned error of "Run()" could be one of them:
- // - context.Canceled
- // - *exec.ExitError: "signal: killed"
- return err != nil && (errors.Is(err, context.Canceled) || err.Error() == "signal: killed")
-}
diff --git a/modules/git/foreachref/format.go b/modules/git/foreachref/format.go
index d9573a55d6..87c1c9a4ff 100644
--- a/modules/git/foreachref/format.go
+++ b/modules/git/foreachref/format.go
@@ -53,7 +53,7 @@ func (f Format) Flag() string {
var formatFlag strings.Builder
for i, field := range f.fieldNames {
// field key and field value
- formatFlag.WriteString(fmt.Sprintf("%s %%(%s)", field, field))
+ fmt.Fprintf(&formatFlag, "%s %%(%s)", field, field)
if i < len(f.fieldNames)-1 {
// note: escape delimiters to allow control characters as
@@ -72,12 +72,12 @@ func (f Format) Parser(r io.Reader) *Parser {
return NewParser(r, f)
}
-// hexEscaped produces hex-escpaed characters from a string. For example, "\n\0"
+// hexEscaped produces hex-escaped characters from a string. For example, "\n\0"
// would turn into "%0a%00".
func (f Format) hexEscaped(delim []byte) string {
- escaped := ""
+ var escaped strings.Builder
for i := range delim {
- escaped += "%" + hex.EncodeToString([]byte{delim[i]})
+ escaped.WriteString("%" + hex.EncodeToString([]byte{delim[i]}))
}
- return escaped
+ return escaped.String()
}
diff --git a/modules/git/foreachref/parser.go b/modules/git/foreachref/parser.go
index ebdc7344d0..91868076b4 100644
--- a/modules/git/foreachref/parser.go
+++ b/modules/git/foreachref/parser.go
@@ -30,9 +30,11 @@ type Parser struct {
func NewParser(r io.Reader, format Format) *Parser {
scanner := bufio.NewScanner(r)
- // default MaxScanTokenSize = 64 kiB may be too small for some references,
- // so allow the buffer to grow up to 4x if needed
- scanner.Buffer(nil, 4*bufio.MaxScanTokenSize)
+ // default Scanner.MaxScanTokenSize = 64 kiB may be too small for some references,
+ // so allow the buffer to be large enough in case the ref has long content (e.g.: a tag with long message)
+ // as long as it doesn't exceed some reasonable limit (4 MiB here, or MAX_DISPLAY_FILE_SIZE=8MiB), it is OK
+ // there are still some choices: 1. add a config option for the limit; 2. don't use scanner and write our own parser to fully handle large contents
+ scanner.Buffer(nil, 4*1024*1024)
// in addition to the reference delimiter we specified in the --format,
// `git for-each-ref` will always add a newline after every reference.
@@ -98,7 +100,7 @@ func (p *Parser) Err() error {
func (p *Parser) parseRef(refBlock string) (map[string]string, error) {
if refBlock == "" {
// must be at EOF
- return nil, nil
+ return nil, nil //nolint:nilnil // return nil to signal EOF
}
fieldValues := make(map[string]string)
@@ -113,10 +115,10 @@ func (p *Parser) parseRef(refBlock string) (map[string]string, error) {
var fieldKey string
var fieldVal string
- firstSpace := strings.Index(field, " ")
- if firstSpace > 0 {
- fieldKey = field[:firstSpace]
- fieldVal = field[firstSpace+1:]
+ before, after, ok := strings.Cut(field, " ")
+ if ok {
+ fieldKey = before
+ fieldVal = after
} else {
// could be the case if the requested field had no value
fieldKey = field
diff --git a/modules/git/git.go b/modules/git/git.go
index 161fa42196..2df83f9843 100644
--- a/modules/git/git.go
+++ b/modules/git/git.go
@@ -12,25 +12,28 @@ import (
"path/filepath"
"runtime"
"strings"
- "time"
"code.gitea.io/gitea/modules/git/gitcmd"
"code.gitea.io/gitea/modules/log"
"code.gitea.io/gitea/modules/setting"
+ "code.gitea.io/gitea/modules/tempdir"
+ "code.gitea.io/gitea/modules/testlogger"
"github.com/hashicorp/go-version"
)
-const RequiredVersion = "2.0.0" // the minimum Git version required
+const RequiredVersion = "2.6.0" // the minimum Git version required
type Features struct {
gitVersion *version.Version
- UsingGogit bool
- SupportProcReceive bool // >= 2.29
- SupportHashSha256 bool // >= 2.42, SHA-256 repositories no longer an ‘experimental curiosity’
- SupportedObjectFormats []ObjectFormat // sha1, sha256
- SupportCheckAttrOnBare bool // >= 2.40
+ UsingGogit bool
+ SupportProcReceive bool // >= 2.29
+ SupportHashSha256 bool // >= 2.42, SHA-256 repositories no longer an ‘experimental curiosity’
+ SupportedObjectFormats []ObjectFormat // sha1, sha256
+ SupportCheckAttrOnBare bool // >= 2.40
+ SupportCatFileBatchCommand bool // >= 2.36, support `git cat-file --batch-command`
+ SupportGitMergeTree bool // >= 2.40 // we also need "--merge-base"
}
var defaultFeatures *Features
@@ -57,7 +60,7 @@ func DefaultFeatures() *Features {
}
func loadGitVersionFeatures() (*Features, error) {
- stdout, _, runErr := gitcmd.NewCommand("version").RunStdString(context.Background(), nil)
+ stdout, _, runErr := gitcmd.NewCommand("version").RunStdString(context.Background())
if runErr != nil {
return nil, runErr
}
@@ -75,6 +78,8 @@ func loadGitVersionFeatures() (*Features, error) {
features.SupportedObjectFormats = append(features.SupportedObjectFormats, Sha256ObjectFormat)
}
features.SupportCheckAttrOnBare = features.CheckVersionAtLeast("2.40")
+ features.SupportCatFileBatchCommand = features.CheckVersionAtLeast("2.36")
+ features.SupportGitMergeTree = features.CheckVersionAtLeast("2.40") // we also need "--merge-base"
return features, nil
}
@@ -84,12 +89,17 @@ func parseGitVersionLine(s string) (*version.Version, error) {
return nil, fmt.Errorf("invalid git version: %q", s)
}
- // version string is like: "git version 2.29.3" or "git version 2.29.3.windows.1"
+ // version output is like: "git version {versionString}"
+ // versionString can be:
+ // * "2.5.3"
+ // * "2.29.3.windows.1"
+ // * "2.28.0.618.gf4bc123cb7": https://github.com/go-gitea/gitea/issues/12731
versionString := fields[2]
- if pos := strings.Index(versionString, "windows"); pos >= 1 {
- versionString = versionString[:pos-1]
+ versionFields := strings.Split(versionString, ".")
+ if len(versionFields) > 3 {
+ versionFields = versionFields[:3]
}
- return version.NewVersion(versionString)
+ return version.NewVersion(strings.Join(versionFields, "."))
}
func checkGitVersionCompatibility(gitVer *version.Version) error {
@@ -137,10 +147,6 @@ func InitSimple() error {
log.Warn("git module has been initialized already, duplicate init may work but it's better to fix it")
}
- if setting.Git.Timeout.Default > 0 {
- gitcmd.SetDefaultCommandExecutionTimeout(time.Duration(setting.Git.Timeout.Default) * time.Second)
- }
-
if err := gitcmd.SetExecutablePath(setting.Git.Path); err != nil {
return err
}
@@ -176,3 +182,23 @@ func InitFull() (err error) {
return syncGitConfig(context.Background())
}
+
+// RunGitTests helps to init the git module and run tests.
+// FIXME: GIT-PACKAGE-DEPENDENCY: the dependency is not right, setting.Git.HomePath is initialized in this package but used in gitcmd package
+func RunGitTests(m interface{ Run() int }) {
+ os.Exit(runGitTests(m))
+}
+
+func runGitTests(m interface{ Run() int }) int {
+ gitHomePath, cleanup, err := tempdir.OsTempDir("gitea-test").MkdirTempRandom("git-home")
+ if err != nil {
+ testlogger.Panicf("unable to create temp dir: %s", err.Error())
+ }
+ defer cleanup()
+
+ setting.Git.HomePath = gitHomePath
+ if err = InitFull(); err != nil {
+ testlogger.Panicf("failed to call Init: %s", err.Error())
+ }
+ return m.Run()
+}
diff --git a/modules/git/git_test.go b/modules/git/git_test.go
index 7a8ca74b01..e21cbe449a 100644
--- a/modules/git/git_test.go
+++ b/modules/git/git_test.go
@@ -4,42 +4,14 @@
package git
import (
- "fmt"
- "os"
"testing"
- "code.gitea.io/gitea/modules/setting"
- "code.gitea.io/gitea/modules/tempdir"
-
"github.com/hashicorp/go-version"
"github.com/stretchr/testify/assert"
)
-func testRun(m *testing.M) error {
- gitHomePath, cleanup, err := tempdir.OsTempDir("gitea-test").MkdirTempRandom("git-home")
- if err != nil {
- return fmt.Errorf("unable to create temp dir: %w", err)
- }
- defer cleanup()
-
- setting.Git.HomePath = gitHomePath
-
- if err = InitFull(); err != nil {
- return fmt.Errorf("failed to call Init: %w", err)
- }
-
- exitCode := m.Run()
- if exitCode != 0 {
- return fmt.Errorf("run test failed, ExitCode=%d", exitCode)
- }
- return nil
-}
-
func TestMain(m *testing.M) {
- if err := testRun(m); err != nil {
- _, _ = fmt.Fprintf(os.Stderr, "Test failed: %v", err)
- os.Exit(1)
- }
+ RunGitTests(m)
}
func TestParseGitVersion(t *testing.T) {
@@ -51,6 +23,10 @@ func TestParseGitVersion(t *testing.T) {
assert.NoError(t, err)
assert.Equal(t, "2.29.3", v.String())
+ v, err = parseGitVersionLine("git version 2.28.0.618.gf4bc123cb7")
+ assert.NoError(t, err)
+ assert.Equal(t, "2.28.0", v.String())
+
_, err = parseGitVersionLine("git version")
assert.Error(t, err)
diff --git a/modules/git/gitcmd/command.go b/modules/git/gitcmd/command.go
index ed2f6fb647..ee447dfd03 100644
--- a/modules/git/gitcmd/command.go
+++ b/modules/git/gitcmd/command.go
@@ -13,7 +13,6 @@ import (
"os"
"os/exec"
"path/filepath"
- "runtime"
"strings"
"time"
@@ -29,34 +28,41 @@ import (
// In most cases, it shouldn't be used. Use AddXxx function instead
type TrustedCmdArgs []internal.CmdArg
-// defaultCommandExecutionTimeout default command execution timeout duration
-var defaultCommandExecutionTimeout = 360 * time.Second
-
-func SetDefaultCommandExecutionTimeout(timeout time.Duration) {
- defaultCommandExecutionTimeout = timeout
-}
-
-// DefaultLocale is the default LC_ALL to run git commands in.
-const DefaultLocale = "C"
-
// Command represents a command with its subcommands or arguments.
type Command struct {
+ callerInfo string
prog string
args []string
- brokenArgs []string
- cmd *exec.Cmd // for debug purpose only
+ preErrors []error
configArgs []string
+ opts runOpts
+
+ cmd *exec.Cmd
+
+ cmdCtx context.Context
+ cmdCancel process.CancelCauseFunc
+ cmdFinished process.FinishedFunc
+ cmdStartTime time.Time
+
+ parentPipeFiles []*os.File
+ parentPipeReaders []*os.File
+ childrenPipeFiles []*os.File
+
+ // only os.Pipe and in-memory buffers can work with Stdin safely, see https://github.com/golang/go/issues/77227 if the command would exit unexpectedly
+ cmdStdin io.Reader
+ cmdStdout io.Writer
+ cmdStderr io.Writer
+
+ cmdManagedStderr *bytes.Buffer
}
func logArgSanitize(arg string) string {
- if strings.Contains(arg, "://") && strings.Contains(arg, "@") {
- return util.SanitizeCredentialURLs(arg)
- } else if filepath.IsAbs(arg) {
+ if filepath.IsAbs(arg) {
base := filepath.Base(arg)
dir := filepath.Dir(arg)
return ".../" + filepath.Join(filepath.Base(dir), base)
}
- return arg
+ return util.SanitizeCredentialURLs(arg)
}
func (c *Command) LogString() string {
@@ -96,6 +102,10 @@ func NewCommand(args ...internal.CmdArg) *Command {
}
}
+func (c *Command) handlePreErrorBrokenCommand(arg string) {
+ c.preErrors = append(c.preErrors, util.ErrorWrap(ErrBrokenCommand, `broken git command argument %q`, arg))
+}
+
// isSafeArgumentValue checks if the argument is safe to be used as a value (not an option)
func isSafeArgumentValue(s string) bool {
return s == "" || s[0] != '-'
@@ -123,7 +133,7 @@ func (c *Command) AddArguments(args ...internal.CmdArg) *Command {
// The values are treated as dynamic argument values. It equals to: AddArguments("--opt") then AddDynamicArguments(val).
func (c *Command) AddOptionValues(opt internal.CmdArg, args ...string) *Command {
if !isValidArgumentOption(string(opt)) {
- c.brokenArgs = append(c.brokenArgs, string(opt))
+ c.handlePreErrorBrokenCommand(string(opt))
return c
}
c.args = append(c.args, string(opt))
@@ -135,12 +145,12 @@ func (c *Command) AddOptionValues(opt internal.CmdArg, args ...string) *Command
// For example: AddOptionFormat("--opt=%s %s", val1, val2) means 1 argument: {"--opt=val1 val2"}.
func (c *Command) AddOptionFormat(opt string, args ...any) *Command {
if !isValidArgumentOption(opt) {
- c.brokenArgs = append(c.brokenArgs, opt)
+ c.handlePreErrorBrokenCommand(opt)
return c
}
// a quick check to make sure the format string matches the number of arguments, to find low-level mistakes ASAP
if strings.Count(strings.ReplaceAll(opt, "%%", ""), "%") != len(args) {
- c.brokenArgs = append(c.brokenArgs, opt)
+ c.handlePreErrorBrokenCommand(opt)
return c
}
s := fmt.Sprintf(opt, args...)
@@ -154,10 +164,10 @@ func (c *Command) AddOptionFormat(opt string, args ...any) *Command {
func (c *Command) AddDynamicArguments(args ...string) *Command {
for _, arg := range args {
if !isSafeArgumentValue(arg) {
- c.brokenArgs = append(c.brokenArgs, arg)
+ c.handlePreErrorBrokenCommand(arg)
}
}
- if len(c.brokenArgs) != 0 {
+ if len(c.preErrors) != 0 {
return c
}
c.args = append(c.args, args...)
@@ -177,7 +187,7 @@ func (c *Command) AddDashesAndList(list ...string) *Command {
func (c *Command) AddConfig(key, value string) *Command {
kv := key + "=" + value
if !isSafeArgumentValue(kv) {
- c.brokenArgs = append(c.brokenArgs, key)
+ c.handlePreErrorBrokenCommand(kv)
} else {
c.configArgs = append(c.configArgs, "-c", kv)
}
@@ -194,11 +204,9 @@ func ToTrustedCmdArgs(args []string) TrustedCmdArgs {
return ret
}
-// RunOpts represents parameters to run the command. If UseContextTimeout is specified, then Timeout is ignored.
-type RunOpts struct {
- Env []string
- Timeout time.Duration
- UseContextTimeout bool
+type runOpts struct {
+ Env []string
+ Timeout time.Duration
// Dir is the working dir for the git command, however:
// FIXME: this could be incorrect in many cases, for example:
@@ -208,19 +216,7 @@ type RunOpts struct {
// The correct approach is to use `--git-dir" global argument
Dir string
- Stdout, Stderr io.Writer
-
- // Stdin is used for passing input to the command
- // The caller must make sure the Stdin writer is closed properly to finish the Run function.
- // Otherwise, the Run function may hang for long time or forever, especially when the Git's context deadline is not the same as the caller's.
- // Some common mistakes:
- // * `defer stdinWriter.Close()` then call `cmd.Run()`: the Run() would never return if the command is killed by timeout
- // * `go { case <- parentContext.Done(): stdinWriter.Close() }` with `cmd.Run(DefaultTimeout)`: the command would have been killed by timeout but the Run doesn't return until stdinWriter.Close()
- // * `go { if stdoutReader.Read() err != nil: stdinWriter.Close() }` with `cmd.Run()`: the stdoutReader may never return error if the command is killed by timeout
- // In the future, ideally the git module itself should have full control of the stdin, to avoid such problems and make it easier to refactor to a better architecture.
- Stdin io.Reader
-
- PipelineFunc func(context.Context, context.CancelFunc) error
+ PipelineFunc func(Context) error
}
func commonBaseEnvs() []string {
@@ -251,7 +247,7 @@ func commonBaseEnvs() []string {
// CommonGitCmdEnvs returns the common environment variables for a "git" command.
func CommonGitCmdEnvs() []string {
return append(commonBaseEnvs(), []string{
- "LC_ALL=" + DefaultLocale,
+ "LC_ALL=C", // ensure git output is in English, error messages are parsed in English
"GIT_TERMINAL_PROMPT=0", // avoid prompting for credentials interactively, supported since git v2.3
}...)
}
@@ -263,185 +259,320 @@ func CommonCmdServEnvs() []string {
var ErrBrokenCommand = errors.New("git command is broken")
-// Run runs the command with the RunOpts
-func (c *Command) Run(ctx context.Context, opts *RunOpts) error {
- return c.run(ctx, 1, opts)
+func (c *Command) WithDir(dir string) *Command {
+ c.opts.Dir = dir
+ return c
}
-func (c *Command) run(ctx context.Context, skip int, opts *RunOpts) error {
- if len(c.brokenArgs) != 0 {
- log.Error("git command is broken: %s, broken args: %s", c.LogString(), strings.Join(c.brokenArgs, " "))
- return ErrBrokenCommand
- }
- if opts == nil {
- opts = &RunOpts{}
+func (c *Command) WithEnv(env []string) *Command {
+ c.opts.Env = env
+ return c
+}
+
+func (c *Command) WithTimeout(timeout time.Duration) *Command {
+ c.opts.Timeout = timeout
+ return c
+}
+
+func (c *Command) makeStdoutStderr(w *io.Writer) (PipeReader, func()) {
+ pr, pw, err := os.Pipe()
+ if err != nil {
+ c.preErrors = append(c.preErrors, err)
+ return &pipeNull{err}, func() {}
+ }
+ c.childrenPipeFiles = append(c.childrenPipeFiles, pw)
+ c.parentPipeFiles = append(c.parentPipeFiles, pr)
+ c.parentPipeReaders = append(c.parentPipeReaders, pr)
+ *w /* stdout, stderr */ = pw
+ return &pipeReader{f: pr}, func() { pr.Close() }
+}
+
+// MakeStdinPipe creates a writer for the command's stdin.
+// The returned closer function must be called by the caller to close the pipe.
+func (c *Command) MakeStdinPipe() (writer PipeWriter, closer func()) {
+ pr, pw, err := os.Pipe()
+ if err != nil {
+ c.preErrors = append(c.preErrors, err)
+ return &pipeNull{err}, func() {}
}
+ c.childrenPipeFiles = append(c.childrenPipeFiles, pr)
+ c.parentPipeFiles = append(c.parentPipeFiles, pw)
+ c.cmdStdin = pr
+ return &pipeWriter{pw}, func() { pw.Close() }
+}
- // We must not change the provided options
- timeout := opts.Timeout
- if timeout <= 0 {
- timeout = defaultCommandExecutionTimeout
+// MakeStdoutPipe creates a reader for the command's stdout.
+// The returned closer function must be called by the caller to close the pipe.
+// After the pipe reader is closed, the unread data will be discarded.
+//
+// If the process (git command) still tries to write after the pipe is closed, the Wait error will be "signal: broken pipe".
+// WithPipelineFunc + Run won't return "broken pipe" error in this case if the callback returns no error.
+// But if you are calling Start / Wait family functions, you should either drain the pipe before close it, or handle the Wait error correctly.
+func (c *Command) MakeStdoutPipe() (reader PipeReader, closer func()) {
+ return c.makeStdoutStderr(&c.cmdStdout)
+}
+
+// MakeStderrPipe is like MakeStdoutPipe, but for stderr.
+func (c *Command) MakeStderrPipe() (reader PipeReader, closer func()) {
+ return c.makeStdoutStderr(&c.cmdStderr)
+}
+
+func (c *Command) MakeStdinStdoutPipe() (stdin PipeWriter, stdout PipeReader, closer func()) {
+ stdin, stdinClose := c.MakeStdinPipe()
+ stdout, stdoutClose := c.MakeStdoutPipe()
+ return stdin, stdout, func() {
+ stdinClose()
+ stdoutClose()
}
+}
- cmdLogString := c.LogString()
- callerInfo := util.CallerFuncName(1 /* util */ + 1 /* this */ + skip /* parent */)
+func (c *Command) WithStdinBytes(stdin []byte) *Command {
+ c.cmdStdin = bytes.NewReader(stdin)
+ return c
+}
+
+func (c *Command) WithStdoutBuffer(w PipeBufferWriter) *Command {
+ c.cmdStdout = w
+ return c
+}
+
+// WithStdinCopy and WithStdoutCopy are general functions that accept any io.Reader / io.Writer.
+// In this case, Golang exec.Cmd will start new internal goroutines to do io.Copy between pipes and provided Reader/Writer.
+// If the reader or writer is blocked and never returns, then the io.Copy won't finish, then exec.Cmd.Wait won't return, which may cause deadlocks.
+// A typical deadlock example is:
+// * `r,w:=io.Pipe(); cmd.Stdin=r; defer w.Close(); cmd.Run()`: the Run() will never return because stdin reader is blocked forever and w.Close() will never be called.
+// If the reader/writer won't block forever (for example: read from a file or buffer), then these functions are safe to use.
+func (c *Command) WithStdinCopy(w io.Reader) *Command {
+ c.cmdStdin = w
+ return c
+}
+
+func (c *Command) WithStdoutCopy(w io.Writer) *Command {
+ c.cmdStdout = w
+ return c
+}
+
+// WithPipelineFunc sets the pipeline function for the command.
+// The pipeline function will be called in the Run / Wait function after the command is started successfully.
+// The function can read/write from/to the command's stdio pipes (if any).
+// The pipeline function can cancel (kill) the command by calling ctx.CancelPipeline before the command finishes.
+// The returned error of Run / Wait can be joined errors from the pipeline function, context cause, and command exit error.
+// Caller can get the pipeline function's error (if any) by UnwrapPipelineError.
+func (c *Command) WithPipelineFunc(f func(ctx Context) error) *Command {
+ c.opts.PipelineFunc = f
+ return c
+}
+
+// WithParentCallerInfo can be used to set the caller info (usually function name) of the parent function of the caller.
+// For most cases, "Run" family functions can get its caller info automatically
+// But if you need to call "Run" family functions in a wrapper function: "FeatureFunc -> GeneralWrapperFunc -> RunXxx",
+// then you can to call this function in GeneralWrapperFunc to set the caller info of FeatureFunc.
+// The caller info can only be set once.
+func (c *Command) WithParentCallerInfo(optInfo ...string) *Command {
+ if c.callerInfo != "" {
+ return c
+ }
+ if len(optInfo) > 0 {
+ c.callerInfo = optInfo[0]
+ return c
+ }
+ skip := 1 /*parent "wrap/run" functions*/ + 1 /*this function*/
+ callerFuncName := util.CallerFuncName(skip)
+ callerInfo := callerFuncName
if pos := strings.LastIndex(callerInfo, "/"); pos >= 0 {
callerInfo = callerInfo[pos+1:]
}
+ c.callerInfo = callerInfo
+ return c
+}
+
+func (c *Command) Start(ctx context.Context) (retErr error) {
+ if c.cmd != nil {
+ // this is a programming error, it will cause serious deadlock problems, so it must be fixed.
+ panic("git command has already been started")
+ }
+
+ defer func() {
+ c.closePipeFiles(c.childrenPipeFiles)
+ if retErr != nil {
+ // release the pipes to avoid resource leak since the command failed to start
+ c.closePipeFiles(c.parentPipeFiles)
+ // if error occurs, we must also finish the task, otherwise, cmdFinished will be called in "Wait" function
+ if c.cmdFinished != nil {
+ c.cmdFinished()
+ }
+ }
+ }()
+
+ if len(c.preErrors) != 0 {
+ // In most cases, such error shouldn't happen. If it happens, log it as error level with more details
+ err := errors.Join(c.preErrors...)
+ log.Error("git command: %s, error: %s", c.LogString(), err)
+ return err
+ }
+
+ cmdLogString := c.LogString()
+ if c.callerInfo == "" {
+ c.WithParentCallerInfo()
+ }
// these logs are for debugging purposes only, so no guarantee of correctness or stability
- desc := fmt.Sprintf("git.Run(by:%s, repo:%s): %s", callerInfo, logArgSanitize(opts.Dir), cmdLogString)
+ desc := fmt.Sprintf("git.Run(by:%s, repo:%s): %s", c.callerInfo, logArgSanitize(c.opts.Dir), cmdLogString)
log.Debug("git.Command: %s", desc)
_, span := gtprof.GetTracer().Start(ctx, gtprof.TraceSpanGitRun)
defer span.End()
- span.SetAttributeString(gtprof.TraceAttrFuncCaller, callerInfo)
+ span.SetAttributeString(gtprof.TraceAttrFuncCaller, c.callerInfo)
span.SetAttributeString(gtprof.TraceAttrGitCommand, cmdLogString)
- var cancel context.CancelFunc
- var finished context.CancelFunc
-
- if opts.UseContextTimeout {
- ctx, cancel, finished = process.GetManager().AddContext(ctx, desc)
+ if c.opts.Timeout <= 0 {
+ c.cmdCtx, c.cmdCancel, c.cmdFinished = process.GetManager().AddContext(ctx, desc)
} else {
- ctx, cancel, finished = process.GetManager().AddContextTimeout(ctx, timeout, desc)
+ c.cmdCtx, c.cmdCancel, c.cmdFinished = process.GetManager().AddContextTimeout(ctx, c.opts.Timeout, desc)
}
- defer finished()
- startTime := time.Now()
+ c.cmdStartTime = time.Now()
- cmd := exec.CommandContext(ctx, c.prog, append(c.configArgs, c.args...)...)
- c.cmd = cmd // for debug purpose only
- if opts.Env == nil {
- cmd.Env = os.Environ()
+ c.cmd = exec.CommandContext(c.cmdCtx, c.prog, append(c.configArgs, c.args...)...)
+ if c.opts.Env == nil {
+ c.cmd.Env = os.Environ()
} else {
- cmd.Env = opts.Env
+ c.cmd.Env = c.opts.Env
}
- process.SetSysProcAttribute(cmd)
- cmd.Env = append(cmd.Env, CommonGitCmdEnvs()...)
- cmd.Dir = opts.Dir
- cmd.Stdout = opts.Stdout
- cmd.Stderr = opts.Stderr
- cmd.Stdin = opts.Stdin
- if err := cmd.Start(); err != nil {
- return err
- }
+ process.SetSysProcAttribute(c.cmd)
+ c.cmd.Env = append(c.cmd.Env, CommonGitCmdEnvs()...)
+ c.cmd.Dir = c.opts.Dir
+ c.cmd.Stdout = c.cmdStdout
+ c.cmd.Stdin = c.cmdStdin
+ c.cmd.Stderr = c.cmdStderr
+ return c.cmd.Start()
+}
- if opts.PipelineFunc != nil {
- err := opts.PipelineFunc(ctx, cancel)
- if err != nil {
- cancel()
- _ = cmd.Wait()
- return err
- }
+func (c *Command) closePipeFiles(files []*os.File) {
+ for _, f := range files {
+ _ = f.Close()
}
+}
- err := cmd.Wait()
- elapsed := time.Since(startTime)
- if elapsed > time.Second {
- log.Debug("slow git.Command.Run: %s (%s)", c, elapsed)
+func (c *Command) discardPipeReaders(files []*os.File) {
+ for _, f := range files {
+ _, _ = io.Copy(io.Discard, f)
}
+}
- // We need to check if the context is canceled by the program on Windows.
- // This is because Windows does not have signal checking when terminating the process.
- // It always returns exit code 1, unlike Linux, which has many exit codes for signals.
- // `err.Error()` returns "exit status 1" when using the `git check-attr` command after the context is canceled.
- if runtime.GOOS == "windows" &&
- err != nil &&
- (err.Error() == "" || err.Error() == "exit status 1") &&
- cmd.ProcessState.ExitCode() == 1 &&
- ctx.Err() == context.Canceled {
- return ctx.Err()
- }
+func (c *Command) Wait() error {
+ defer func() {
+ // The reader in another goroutine might be still reading the stdout, so we shouldn't close the pipes here
+ // MakeStdoutPipe returns a closer function to force callers to close the pipe correctly
+ // Here we only need to mark the command as finished
+ c.cmdFinished()
+ }()
+
+ if c.opts.PipelineFunc != nil {
+ errPipeline := c.opts.PipelineFunc(&cmdContext{Context: c.cmdCtx, cmd: c})
+
+ if context.Cause(c.cmdCtx) == nil {
+ // if the context is not canceled explicitly, we need to discard the unread data,
+ // and wait for the command to exit normally, and then get its exit code
+ c.discardPipeReaders(c.parentPipeReaders)
+ } // else: canceled command will be killed, and the exit code is caused by kill
+
+ // after the pipeline function returns, we can safely close the pipes, then wait for the command to exit
+ c.closePipeFiles(c.parentPipeFiles)
+ errWait := c.cmd.Wait()
+ errCause := context.Cause(c.cmdCtx) // in case the cause is set during Wait(), get the final cancel cause
+
+ if unwrapped, ok := UnwrapPipelineError(errCause); ok {
+ if unwrapped != errPipeline {
+ panic("unwrapped context pipeline error should be the same one returned by pipeline function")
+ }
+ if unwrapped == nil {
+ // the pipeline function declares that there is no error, and it cancels (kills) the command ahead,
+ // so we should ignore the errors from "wait" and "cause"
+ errWait, errCause = nil, nil
+ }
+ }
- if err != nil && ctx.Err() != context.DeadlineExceeded {
- return err
+ // some legacy code still need to access the error returned by pipeline function by "==" but not "errors.Is"
+ // so we need to make sure the original error is able to be unwrapped by UnwrapPipelineError
+ return errors.Join(wrapPipelineError(errPipeline), errCause, errWait)
}
- return ctx.Err()
-}
-
-type RunStdError interface {
- error
- Unwrap() error
- Stderr() string
-}
+ // there might be other goroutines using the context or pipes, so we just wait for the command to finish
+ errWait := c.cmd.Wait()
+ elapsed := time.Since(c.cmdStartTime)
+ if elapsed > time.Second {
+ log.Debug("slow git.Command.Run: %s (%s)", c, elapsed) // TODO: no need to log this for long-running commands
+ }
-type runStdError struct {
- err error
- stderr string
- errMsg string
+ // Here the logic is different from "PipelineFunc" case,
+ // because PipelineFunc can return error if it fails, it knows whether it succeeds or fails.
+ // But in normal case, the caller just runs the git command, the command's exit code is the source of truth.
+ // If the caller need to know whether the command error is caused by cancellation, it should check the "err" by itself.
+ errCause := context.Cause(c.cmdCtx)
+ return errors.Join(errCause, errWait)
}
-func (r *runStdError) Error() string {
- // the stderr must be in the returned error text, some code only checks `strings.Contains(err.Error(), "git error")`
- if r.errMsg == "" {
- r.errMsg = ConcatenateError(r.err, r.stderr).Error()
+func (c *Command) StartWithStderr(ctx context.Context) RunStdError {
+ if c.cmdStderr != nil {
+ panic("caller-provided stderr receiver doesn't work with managed stderr buffer")
+ }
+ c.cmdManagedStderr = &bytes.Buffer{}
+ c.cmdStderr = c.cmdManagedStderr
+ err := c.Start(ctx)
+ if err != nil {
+ return &runStdError{err: err}
}
- return r.errMsg
+ return nil
}
-func (r *runStdError) Unwrap() error {
- return r.err
+func (c *Command) WaitWithStderr() RunStdError {
+ if c.cmdManagedStderr == nil {
+ panic("managed stderr buffer is not initialized")
+ }
+ errWait := c.Wait()
+ if errWait == nil {
+ // if no exec error but only stderr output, the stderr output is still saved in "c.cmdManagedStderr" and can be read later
+ return nil
+ }
+ return &runStdError{err: errWait, stderr: util.UnsafeBytesToString(c.cmdManagedStderr.Bytes())}
}
-func (r *runStdError) Stderr() string {
- return r.stderr
+func (c *Command) RunWithStderr(ctx context.Context) RunStdError {
+ if err := c.StartWithStderr(ctx); err != nil {
+ return &runStdError{err: err}
+ }
+ return c.WaitWithStderr()
}
-func IsErrorExitCode(err error, code int) bool {
- var exitError *exec.ExitError
- if errors.As(err, &exitError) {
- return exitError.ExitCode() == code
+func (c *Command) Run(ctx context.Context) (err error) {
+ if err = c.Start(ctx); err != nil {
+ return err
}
- return false
+ return c.Wait()
}
-// RunStdString runs the command with options and returns stdout/stderr as string. and store stderr to returned error (err combined with stderr).
-func (c *Command) RunStdString(ctx context.Context, opts *RunOpts) (stdout, stderr string, runErr RunStdError) {
- stdoutBytes, stderrBytes, err := c.runStdBytes(ctx, opts)
- stdout = util.UnsafeBytesToString(stdoutBytes)
- stderr = util.UnsafeBytesToString(stderrBytes)
- if err != nil {
- return stdout, stderr, &runStdError{err: err, stderr: stderr}
- }
- // even if there is no err, there could still be some stderr output, so we just return stdout/stderr as they are
- return stdout, stderr, nil
+// RunStdString runs the command and returns stdout/stderr as string. and store stderr to returned error (err combined with stderr).
+func (c *Command) RunStdString(ctx context.Context) (stdout, stderr string, runErr RunStdError) {
+ stdoutBytes, stderrBytes, runErr := c.WithParentCallerInfo().runStdBytes(ctx)
+ return util.UnsafeBytesToString(stdoutBytes), util.UnsafeBytesToString(stderrBytes), runErr
}
-// RunStdBytes runs the command with options and returns stdout/stderr as bytes. and store stderr to returned error (err combined with stderr).
-func (c *Command) RunStdBytes(ctx context.Context, opts *RunOpts) (stdout, stderr []byte, runErr RunStdError) {
- return c.runStdBytes(ctx, opts)
+// RunStdBytes runs the command and returns stdout/stderr as bytes. and store stderr to returned error (err combined with stderr).
+func (c *Command) RunStdBytes(ctx context.Context) (stdout, stderr []byte, runErr RunStdError) {
+ return c.WithParentCallerInfo().runStdBytes(ctx)
}
-func (c *Command) runStdBytes(ctx context.Context, opts *RunOpts) (stdout, stderr []byte, runErr RunStdError) {
- if opts == nil {
- opts = &RunOpts{}
- }
- if opts.Stdout != nil || opts.Stderr != nil {
- // we must panic here, otherwise there would be bugs if developers set Stdin/Stderr by mistake, and it would be very difficult to debug
+func (c *Command) runStdBytes(ctx context.Context) ([]byte, []byte, RunStdError) {
+ if c.cmdStdout != nil || c.cmdStderr != nil {
+ // it must panic here, otherwise there would be bugs if developers set other Stdin/Stderr by mistake, and it would be very difficult to debug
panic("stdout and stderr field must be nil when using RunStdBytes")
}
stdoutBuf := &bytes.Buffer{}
- stderrBuf := &bytes.Buffer{}
-
- // We must not change the provided options as it could break future calls - therefore make a copy.
- newOpts := &RunOpts{
- Env: opts.Env,
- Timeout: opts.Timeout,
- UseContextTimeout: opts.UseContextTimeout,
- Dir: opts.Dir,
- Stdout: stdoutBuf,
- Stderr: stderrBuf,
- Stdin: opts.Stdin,
- PipelineFunc: opts.PipelineFunc,
- }
-
- err := c.run(ctx, 2, newOpts)
- stderr = stderrBuf.Bytes()
- if err != nil {
- return nil, stderr, &runStdError{err: err, stderr: util.UnsafeBytesToString(stderr)}
- }
- // even if there is no err, there could still be some stderr output
- return stdoutBuf.Bytes(), stderr, nil
+ err := c.WithParentCallerInfo().WithStdoutBuffer(stdoutBuf).RunWithStderr(ctx)
+ return stdoutBuf.Bytes(), c.cmdManagedStderr.Bytes(), err
+}
+
+func (c *Command) DebugKill() {
+ _ = c.cmd.Process.Kill()
}
diff --git a/modules/git/gitcmd/command_race_test.go b/modules/git/gitcmd/command_race_test.go
deleted file mode 100644
index aee2272808..0000000000
--- a/modules/git/gitcmd/command_race_test.go
+++ /dev/null
@@ -1,38 +0,0 @@
-// Copyright 2017 The Gitea Authors. All rights reserved.
-// SPDX-License-Identifier: MIT
-
-//go:build race
-
-package gitcmd
-
-import (
- "context"
- "testing"
- "time"
-)
-
-func TestRunWithContextNoTimeout(t *testing.T) {
- maxLoops := 10
-
- // 'git --version' does not block so it must be finished before the timeout triggered.
- cmd := NewCommand("--version")
- for i := 0; i < maxLoops; i++ {
- if err := cmd.Run(t.Context(), &RunOpts{}); err != nil {
- t.Fatal(err)
- }
- }
-}
-
-func TestRunWithContextTimeout(t *testing.T) {
- maxLoops := 10
-
- // 'git hash-object --stdin' blocks on stdin so we can have the timeout triggered.
- cmd := NewCommand("hash-object", "--stdin")
- for i := 0; i < maxLoops; i++ {
- if err := cmd.Run(t.Context(), &RunOpts{Timeout: 1 * time.Millisecond}); err != nil {
- if err != context.DeadlineExceeded {
- t.Fatalf("Testing %d/%d: %v", i, maxLoops, err)
- }
- }
- }
-}
diff --git a/modules/git/gitcmd/command_test.go b/modules/git/gitcmd/command_test.go
index 544a97f64c..1af9828427 100644
--- a/modules/git/gitcmd/command_test.go
+++ b/modules/git/gitcmd/command_test.go
@@ -4,57 +4,93 @@
package gitcmd
import (
+ "context"
"fmt"
"os"
+ "strings"
"testing"
+ "time"
"code.gitea.io/gitea/modules/setting"
"code.gitea.io/gitea/modules/tempdir"
+ "code.gitea.io/gitea/modules/testlogger"
"github.com/stretchr/testify/assert"
+ "github.com/stretchr/testify/require"
)
-func TestMain(m *testing.M) {
+func testMain(m *testing.M) int {
+ // FIXME: GIT-PACKAGE-DEPENDENCY: the dependency is not right.
+ // "setting.Git.HomePath" is initialized in "git" package but really used in "gitcmd" package
gitHomePath, cleanup, err := tempdir.OsTempDir("gitea-test").MkdirTempRandom("git-home")
if err != nil {
- _, _ = fmt.Fprintf(os.Stderr, "unable to create temp dir: %v", err)
- os.Exit(1)
+ testlogger.Panicf("failed to create temp dir: %v", err)
}
defer cleanup()
setting.Git.HomePath = gitHomePath
+ return m.Run()
+}
+
+func TestMain(m *testing.M) {
+ os.Exit(testMain(m))
}
func TestRunWithContextStd(t *testing.T) {
- cmd := NewCommand("--version")
- stdout, stderr, err := cmd.RunStdString(t.Context(), &RunOpts{})
- assert.NoError(t, err)
- assert.Empty(t, stderr)
- assert.Contains(t, stdout, "git version")
-
- cmd = NewCommand("--no-such-arg")
- stdout, stderr, err = cmd.RunStdString(t.Context(), &RunOpts{})
- if assert.Error(t, err) {
- assert.Equal(t, stderr, err.Stderr())
- assert.Contains(t, err.Stderr(), "unknown option:")
- assert.Contains(t, err.Error(), "exit status 129 - unknown option:")
- assert.Empty(t, stdout)
+ {
+ cmd := NewCommand("--version")
+ stdout, stderr, err := cmd.RunStdString(t.Context())
+ assert.NoError(t, err)
+ assert.Empty(t, stderr)
+ assert.Contains(t, stdout, "git version")
}
- cmd = NewCommand()
- cmd.AddDynamicArguments("-test")
- assert.ErrorIs(t, cmd.Run(t.Context(), &RunOpts{}), ErrBrokenCommand)
+ {
+ cmd := NewCommand("ls-tree", "no-such")
+ stdout, stderr, err := cmd.RunStdString(t.Context())
+ if assert.Error(t, err) {
+ assert.Equal(t, stderr, err.Stderr())
+ stderrLower := strings.ToLower(stderr) // see: IsStdErrorNotValidObjectName
+ assert.Equal(t, "fatal: not a valid object name no-such\n", stderrLower)
+ // FIXME: GIT-CMD-STDERR: it is a bad design, the stderr should not be put in the error message
+ errLower := strings.ToLower(err.Error())
+ assert.Equal(t, "exit status 128 - fatal: not a valid object name no-such", errLower)
+ assert.Empty(t, stdout)
+ }
+ }
- cmd = NewCommand()
- cmd.AddDynamicArguments("--test")
- assert.ErrorIs(t, cmd.Run(t.Context(), &RunOpts{}), ErrBrokenCommand)
+ {
+ cmd := NewCommand("ls-tree", "no-such")
+ stdout, stderr, err := cmd.RunStdBytes(t.Context())
+ if assert.Error(t, err) {
+ assert.Equal(t, string(stderr), err.Stderr())
+ stderrLower := strings.ToLower(err.Stderr()) // see: IsStdErrorNotValidObjectName
+ assert.Equal(t, "fatal: not a valid object name no-such\n", stderrLower)
+ // FIXME: GIT-CMD-STDERR: it is a bad design, the stderr should not be put in the error message
+ errLower := strings.ToLower(err.Error())
+ assert.Equal(t, "exit status 128 - fatal: not a valid object name no-such", errLower)
+ assert.Empty(t, stdout)
+ }
+ }
+
+ {
+ cmd := NewCommand()
+ cmd.AddDynamicArguments("-test")
+ assert.ErrorIs(t, cmd.Run(t.Context()), ErrBrokenCommand)
+
+ cmd = NewCommand()
+ cmd.AddDynamicArguments("--test")
+ assert.ErrorIs(t, cmd.Run(t.Context()), ErrBrokenCommand)
+ }
- subCmd := "version"
- cmd = NewCommand().AddDynamicArguments(subCmd) // for test purpose only, the sub-command should never be dynamic for production
- stdout, stderr, err = cmd.RunStdString(t.Context(), &RunOpts{})
- assert.NoError(t, err)
- assert.Empty(t, stderr)
- assert.Contains(t, stdout, "git version")
+ {
+ subCmd := "version"
+ cmd := NewCommand().AddDynamicArguments(subCmd) // for test purpose only, the sub-command should never be dynamic for production
+ stdout, stderr, err := cmd.RunStdString(t.Context())
+ assert.NoError(t, err)
+ assert.Empty(t, stderr)
+ assert.Contains(t, stdout, "git version")
+ }
}
func TestGitArgument(t *testing.T) {
@@ -73,5 +109,34 @@ func TestCommandString(t *testing.T) {
assert.Equal(t, cmd.prog+` a "-m msg" "it's a test" "say \"hello\""`, cmd.LogString())
cmd = NewCommand("url: https://a:b@c/", "/root/dir-a/dir-b")
- assert.Equal(t, cmd.prog+` "url: https://sanitized-credential@c/" .../dir-a/dir-b`, cmd.LogString())
+ assert.Equal(t, cmd.prog+` "url: https://(masked)@c/" .../dir-a/dir-b`, cmd.LogString())
+
+ cmd = NewCommand("url: a:b@c/", "/root/dir-a/dir-b")
+ assert.Equal(t, cmd.prog+` "url: (masked)@c/" .../dir-a/dir-b`, cmd.LogString())
+}
+
+func TestRunStdError(t *testing.T) {
+ e := &runStdError{stderr: "some error"}
+ var err RunStdError = e
+
+ var asErr RunStdError
+ require.ErrorAs(t, err, &asErr)
+ require.Equal(t, "some error", asErr.Stderr())
+
+ require.ErrorAs(t, fmt.Errorf("wrapped %w", err), &asErr)
+}
+
+func TestRunWithContextTimeout(t *testing.T) {
+ t.Run("NoTimeout", func(t *testing.T) {
+ // 'git --version' does not block so it must be finished before the timeout triggered.
+ err := NewCommand("--version").Run(t.Context())
+ require.NoError(t, err)
+ })
+ t.Run("WithTimeout", func(t *testing.T) {
+ cmd := NewCommand("hash-object", "--stdin")
+ _, _, pipeClose := cmd.MakeStdinStdoutPipe()
+ defer pipeClose()
+ err := cmd.WithTimeout(1 * time.Millisecond).Run(t.Context())
+ require.ErrorIs(t, err, context.DeadlineExceeded)
+ })
}
diff --git a/modules/git/gitcmd/context.go b/modules/git/gitcmd/context.go
new file mode 100644
index 0000000000..a32f92ff3a
--- /dev/null
+++ b/modules/git/gitcmd/context.go
@@ -0,0 +1,32 @@
+// Copyright 2026 The Gitea Authors. All rights reserved.
+// SPDX-License-Identifier: MIT
+
+package gitcmd
+
+import (
+ "context"
+)
+
+type Context interface {
+ context.Context
+
+ // CancelPipeline is a helper function to cancel the command context (kill the command) with a specific error cause,
+ // it returns the same error for convenience to break the PipelineFunc easily
+ CancelPipeline(err error) error
+
+ // In the future, this interface will be extended to support stdio pipe readers/writers
+}
+
+type cmdContext struct {
+ context.Context
+ cmd *Command
+}
+
+func (c *cmdContext) CancelPipeline(err error) error {
+ // pipelineError is used to distinguish between:
+ // * context canceled by pipeline caller with/without error (normal cancellation)
+ // * context canceled by parent context (still context.Canceled error)
+ // * other causes
+ c.cmd.cmdCancel(pipelineError{err})
+ return err
+}
diff --git a/modules/git/gitcmd/error.go b/modules/git/gitcmd/error.go
new file mode 100644
index 0000000000..b674068c40
--- /dev/null
+++ b/modules/git/gitcmd/error.go
@@ -0,0 +1,108 @@
+// Copyright 2026 The Gitea Authors. All rights reserved.
+// SPDX-License-Identifier: MIT
+
+package gitcmd
+
+import (
+ "context"
+ "errors"
+ "fmt"
+ "os/exec"
+ "strings"
+)
+
+type RunStdError interface {
+ error
+ Unwrap() error
+ Stderr() string
+}
+
+type runStdError struct {
+ err error // usually the low-level error like `*exec.ExitError`
+ stderr string // git command's stderr output
+ errMsg string // the cached error message for Error() method
+}
+
+func (r *runStdError) Error() string {
+ // FIXME: GIT-CMD-STDERR: it is a bad design, the stderr should not be put in the error message
+ // But a lot of code only checks `strings.Contains(err.Error(), "git error")`
+ if r.errMsg == "" {
+ r.errMsg = fmt.Sprintf("%s - %s", r.err.Error(), strings.TrimSpace(r.stderr))
+ }
+ return r.errMsg
+}
+
+func (r *runStdError) Unwrap() error {
+ return r.err
+}
+
+func (r *runStdError) Stderr() string {
+ return r.stderr
+}
+
+func ErrorAsStderr(err error) (string, bool) {
+ var runErr RunStdError
+ if errors.As(err, &runErr) {
+ return runErr.Stderr(), true
+ }
+ return "", false
+}
+
+func StderrHasPrefix(err error, prefix string) bool {
+ stderr, ok := ErrorAsStderr(err)
+ if !ok {
+ return false
+ }
+ return strings.HasPrefix(stderr, prefix)
+}
+
+func IsErrorExitCode(err error, code int) bool {
+ var exitError *exec.ExitError
+ if errors.As(err, &exitError) {
+ return exitError.ExitCode() == code
+ }
+ return false
+}
+
+func IsErrorSignalKilled(err error) bool {
+ var exitError *exec.ExitError
+ return errors.As(err, &exitError) && exitError.String() == "signal: killed"
+}
+
+func IsErrorCanceledOrKilled(err error) bool {
+ // When "cancel()" a git command's context, the returned error of "Run()" could be one of them:
+ // - context.Canceled
+ // - *exec.ExitError: "signal: killed"
+ // TODO: in the future, we need to use unified error type from gitcmd.Run to check whether it is manually canceled
+ return errors.Is(err, context.Canceled) || IsErrorSignalKilled(err)
+}
+
+func IsStdErrorNotValidObjectName(err error) bool {
+ stderr, ok := ErrorAsStderr(err)
+ // Git is lowercasing the "fatal: Not a valid object name" error message
+ // ref: https://lore.kernel.org/git/pull.2052.git.1771836302101.gitgitgadget@gmail.com
+ return ok && strings.Contains(strings.ToLower(stderr), "fatal: not a valid object name")
+}
+
+type pipelineError struct {
+ error
+}
+
+func (e pipelineError) Unwrap() error {
+ return e.error
+}
+
+func wrapPipelineError(err error) error {
+ if err == nil {
+ return nil
+ }
+ return pipelineError{err}
+}
+
+func UnwrapPipelineError(err error) (error, bool) { //nolint:revive // this is for error unwrapping
+ var pe pipelineError
+ if errors.As(err, &pe) {
+ return pe.error, true
+ }
+ return nil, false
+}
diff --git a/modules/git/gitcmd/pipe.go b/modules/git/gitcmd/pipe.go
new file mode 100644
index 0000000000..d0ce3e2dc6
--- /dev/null
+++ b/modules/git/gitcmd/pipe.go
@@ -0,0 +1,87 @@
+// Copyright 2026 The Gitea Authors. All rights reserved.
+// SPDX-License-Identifier: MIT
+
+package gitcmd
+
+import (
+ "io"
+ "os"
+)
+
+type PipeBufferReader interface {
+ // Read should be used in the same goroutine as command's Wait
+ // When Reader in one goroutine, command's Wait in another goroutine, then the command exits, the pipe will be closed:
+ // * If the Reader goroutine reads faster, it will read all remaining data and then get io.EOF
+ // * But this io.EOF doesn't mean the Reader has gotten complete data, the data might still be corrupted
+ // * If the Reader goroutine reads slower, it will get os.ErrClosed because the os.Pipe is closed ahead when the command exits
+ //
+ // When using 2 goroutines, no clear solution to distinguish these two cases or make Reader knows whether the data is complete
+ // It should avoid using Reader in a different goroutine than the command if the Read error needs to be handled.
+ Read(p []byte) (n int, err error)
+ Bytes() []byte
+}
+
+type PipeBufferWriter interface {
+ Write(p []byte) (n int, err error)
+ Bytes() []byte
+}
+
+type PipeReader interface {
+ io.ReadCloser
+ internalOnly()
+}
+
+type pipeReader struct {
+ f *os.File
+}
+
+func (r *pipeReader) internalOnly() {}
+
+func (r *pipeReader) Read(p []byte) (n int, err error) {
+ return r.f.Read(p)
+}
+
+func (r *pipeReader) Close() error {
+ return r.f.Close()
+}
+
+type PipeWriter interface {
+ io.WriteCloser
+ internalOnly()
+}
+
+type pipeWriter struct {
+ f *os.File
+}
+
+func (w *pipeWriter) internalOnly() {}
+
+func (w *pipeWriter) Close() error {
+ return w.f.Close()
+}
+
+func (w *pipeWriter) Write(p []byte) (n int, err error) {
+ return w.f.Write(p)
+}
+
+func (w *pipeWriter) DrainBeforeClose() error {
+ return nil
+}
+
+type pipeNull struct {
+ err error
+}
+
+func (p *pipeNull) internalOnly() {}
+
+func (p *pipeNull) Read([]byte) (n int, err error) {
+ return 0, p.err
+}
+
+func (p *pipeNull) Write([]byte) (n int, err error) {
+ return 0, p.err
+}
+
+func (p *pipeNull) Close() error {
+ return nil
+}
diff --git a/modules/git/gitcmd/utils.go b/modules/git/gitcmd/utils.go
deleted file mode 100644
index ee24eb6a9a..0000000000
--- a/modules/git/gitcmd/utils.go
+++ /dev/null
@@ -1,14 +0,0 @@
-// Copyright 2025 The Gitea Authors. All rights reserved.
-// SPDX-License-Identifier: MIT
-
-package gitcmd
-
-import "fmt"
-
-// ConcatenateError concatenats an error with stderr string
-func ConcatenateError(err error, stderr string) error {
- if len(stderr) == 0 {
- return err
- }
- return fmt.Errorf("%w - %s", err, stderr)
-}
diff --git a/modules/git/gpg.go b/modules/git/gpg.go
new file mode 100644
index 0000000000..dbc5569309
--- /dev/null
+++ b/modules/git/gpg.go
@@ -0,0 +1,102 @@
+// Copyright 2015 The Gogs Authors. All rights reserved.
+// Copyright 2017 The Gitea Authors. All rights reserved.
+// SPDX-License-Identifier: MIT
+
+package git
+
+import (
+ "context"
+ "fmt"
+ "os"
+ "strings"
+ "sync"
+
+ "code.gitea.io/gitea/modules/git/gitcmd"
+ "code.gitea.io/gitea/modules/process"
+)
+
+// GPGSettings represents the default GPG settings for this repository
+type GPGSettings struct {
+ Sign bool
+ KeyID string
+ Email string
+ Name string
+ PublicKeyContent string
+ Format string
+}
+
+// LoadPublicKeyContent will load the key from gpg
+func (gpgSettings *GPGSettings) LoadPublicKeyContent() error {
+ if gpgSettings.PublicKeyContent != "" {
+ return nil
+ }
+
+ if gpgSettings.Format == SigningKeyFormatSSH {
+ content, err := os.ReadFile(gpgSettings.KeyID)
+ if err != nil {
+ return fmt.Errorf("unable to read SSH public key file: %s, %w", gpgSettings.KeyID, err)
+ }
+ gpgSettings.PublicKeyContent = string(content)
+ return nil
+ }
+ content, stderr, err := process.GetManager().Exec(
+ "gpg -a --export",
+ "gpg", "-a", "--export", gpgSettings.KeyID)
+ if err != nil {
+ return fmt.Errorf("unable to get default signing key: %s, %s, %w", gpgSettings.KeyID, stderr, err)
+ }
+ gpgSettings.PublicKeyContent = content
+ return nil
+}
+
+var (
+ loadPublicGPGKeyMutex sync.RWMutex
+ globalGPGSettings *GPGSettings
+)
+
+// GetDefaultPublicGPGKey will return and cache the default public GPG settings
+func GetDefaultPublicGPGKey(ctx context.Context, forceUpdate bool) (*GPGSettings, error) {
+ if !forceUpdate {
+ loadPublicGPGKeyMutex.RLock()
+ if globalGPGSettings != nil {
+ defer loadPublicGPGKeyMutex.RUnlock()
+ return globalGPGSettings, nil
+ }
+ loadPublicGPGKeyMutex.RUnlock()
+ }
+
+ loadPublicGPGKeyMutex.Lock()
+ defer loadPublicGPGKeyMutex.Unlock()
+
+ if globalGPGSettings != nil && !forceUpdate {
+ return globalGPGSettings, nil
+ }
+
+ globalGPGSettings = &GPGSettings{
+ Sign: true,
+ }
+
+ value, _, _ := gitcmd.NewCommand("config", "--global", "--get", "commit.gpgsign").RunStdString(ctx)
+ sign, valid := ParseBool(strings.TrimSpace(value))
+ if !sign || !valid {
+ globalGPGSettings.Sign = false
+ return globalGPGSettings, nil
+ }
+
+ signingKey, _, _ := gitcmd.NewCommand("config", "--global", "--get", "user.signingkey").RunStdString(ctx)
+ globalGPGSettings.KeyID = strings.TrimSpace(signingKey)
+
+ format, _, _ := gitcmd.NewCommand("config", "--global", "--default", SigningKeyFormatOpenPGP, "--get", "gpg.format").RunStdString(ctx)
+ globalGPGSettings.Format = strings.TrimSpace(format)
+
+ defaultEmail, _, _ := gitcmd.NewCommand("config", "--global", "--get", "user.email").RunStdString(ctx)
+ globalGPGSettings.Email = strings.TrimSpace(defaultEmail)
+
+ defaultName, _, _ := gitcmd.NewCommand("config", "--global", "--get", "user.name").RunStdString(ctx)
+ globalGPGSettings.Name = strings.TrimSpace(defaultName)
+
+ if err := globalGPGSettings.LoadPublicKeyContent(); err != nil {
+ return nil, err
+ }
+ return globalGPGSettings, nil
+}
diff --git a/modules/git/grep.go b/modules/git/grep.go
index f5f6f12041..47f66b88b2 100644
--- a/modules/git/grep.go
+++ b/modules/git/grep.go
@@ -5,14 +5,13 @@ package git
import (
"bufio"
- "bytes"
"context"
"errors"
"fmt"
- "os"
"slices"
"strconv"
"strings"
+ "time"
"code.gitea.io/gitea/modules/git/gitcmd"
"code.gitea.io/gitea/modules/util"
@@ -41,16 +40,11 @@ type GrepOptions struct {
PathspecList []string
}
-func GrepSearch(ctx context.Context, repo *Repository, search string, opts GrepOptions) ([]*GrepResult, error) {
- stdoutReader, stdoutWriter, err := os.Pipe()
- if err != nil {
- return nil, fmt.Errorf("unable to create os pipe to grep: %w", err)
- }
- defer func() {
- _ = stdoutReader.Close()
- _ = stdoutWriter.Close()
- }()
+// grepSearchTimeout is the timeout for git grep search, it should be long enough to get results
+// but not too long to cause performance issues
+const grepSearchTimeout = 30 * time.Second
+func GrepSearch(ctx context.Context, repo *Repository, search string, opts GrepOptions) ([]*GrepResult, error) {
/*
The output is like this ( "^@" means \x00):
@@ -83,15 +77,12 @@ func GrepSearch(ctx context.Context, repo *Repository, search string, opts GrepO
cmd.AddDynamicArguments(util.IfZero(opts.RefName, "HEAD"))
cmd.AddDashesAndList(opts.PathspecList...)
opts.MaxResultLimit = util.IfZero(opts.MaxResultLimit, 50)
- stderr := bytes.Buffer{}
- err = cmd.Run(ctx, &gitcmd.RunOpts{
- Dir: repo.Path,
- Stdout: stdoutWriter,
- Stderr: &stderr,
- PipelineFunc: func(ctx context.Context, cancel context.CancelFunc) error {
- _ = stdoutWriter.Close()
- defer stdoutReader.Close()
+ stdoutReader, stdoutReaderClose := cmd.MakeStdoutPipe()
+ defer stdoutReaderClose()
+ err := cmd.WithDir(repo.Path).
+ WithTimeout(grepSearchTimeout).
+ WithPipelineFunc(func(ctx gitcmd.Context) error {
isInBlock := false
rd := bufio.NewReaderSize(stdoutReader, util.IfZero(opts.MaxLineLength, 16*1024))
var res *GrepResult
@@ -117,8 +108,7 @@ func GrepSearch(ctx context.Context, repo *Repository, search string, opts GrepO
}
if line == "" {
if len(results) >= opts.MaxResultLimit {
- cancel()
- break
+ return ctx.CancelPipeline(nil)
}
isInBlock = false
continue
@@ -133,18 +123,18 @@ func GrepSearch(ctx context.Context, repo *Repository, search string, opts GrepO
}
}
return nil
- },
- })
+ }).
+ RunWithStderr(ctx)
// git grep exits by cancel (killed), usually it is caused by the limit of results
- if gitcmd.IsErrorExitCode(err, -1) && stderr.Len() == 0 {
+ if gitcmd.IsErrorExitCode(err, -1) && err.Stderr() == "" {
return results, nil
}
// git grep exits with 1 if no results are found
- if gitcmd.IsErrorExitCode(err, 1) && stderr.Len() == 0 {
+ if gitcmd.IsErrorExitCode(err, 1) && err.Stderr() == "" {
return nil, nil
}
if err != nil && !errors.Is(err, context.Canceled) {
- return nil, fmt.Errorf("unable to run git grep: %w, stderr: %s", err, stderr.String())
+ return nil, fmt.Errorf("unable to run git grep: %w", err)
}
return results, nil
}
diff --git a/modules/git/hook.go b/modules/git/hook.go
index 9a2dfae2e3..0e19387d97 100644
--- a/modules/git/hook.go
+++ b/modules/git/hook.go
@@ -45,7 +45,7 @@ func GetHook(repoPath, name string) (*Hook, error) {
}
h := &Hook{
name: name,
- path: filepath.Join(repoPath, "hooks", name+".d", name),
+ path: filepath.Join(repoPath, filepath.Join("hooks", name+".d", name)),
}
if data, err := os.ReadFile(h.path); err == nil {
h.IsActive = true
diff --git a/modules/git/key.go b/modules/git/key.go
index 8c14742f34..9d51704595 100644
--- a/modules/git/key.go
+++ b/modules/git/key.go
@@ -3,7 +3,13 @@
package git
-import "code.gitea.io/gitea/modules/setting"
+import (
+ "context"
+ "strings"
+
+ "code.gitea.io/gitea/modules/git/gitcmd"
+ "code.gitea.io/gitea/modules/setting"
+)
// Based on https://git-scm.com/docs/git-config#Documentation/git-config.txt-gpgformat
const (
@@ -24,3 +30,48 @@ func (s *SigningKey) String() string {
setting.PanicInDevOrTesting("don't call SigningKey.String() - it exposes the KeyID which might be a local file path")
return "SigningKey:" + s.Format
}
+
+// GetSigningKey returns the KeyID and git Signature for the repo
+func GetSigningKey(ctx context.Context) (*SigningKey, *Signature) {
+ if setting.Repository.Signing.SigningKey == "none" {
+ return nil, nil
+ }
+
+ if setting.Repository.Signing.SigningKey == "default" || setting.Repository.Signing.SigningKey == "" {
+ // Can ignore the error here as it means that commit.gpgsign is not set
+ value, _, _ := gitcmd.NewCommand("config", "--global", "--get", "commit.gpgsign").RunStdString(ctx)
+ sign, valid := ParseBool(strings.TrimSpace(value))
+ if !sign || !valid {
+ return nil, nil
+ }
+
+ format, _, _ := gitcmd.NewCommand("config", "--global", "--default", SigningKeyFormatOpenPGP, "--get", "gpg.format").RunStdString(ctx)
+ signingKey, _, _ := gitcmd.NewCommand("config", "--global", "--get", "user.signingkey").RunStdString(ctx)
+ signingName, _, _ := gitcmd.NewCommand("config", "--global", "--get", "user.name").RunStdString(ctx)
+ signingEmail, _, _ := gitcmd.NewCommand("config", "--global", "--get", "user.email").RunStdString(ctx)
+
+ if strings.TrimSpace(signingKey) == "" {
+ return nil, nil
+ }
+
+ return &SigningKey{
+ KeyID: strings.TrimSpace(signingKey),
+ Format: strings.TrimSpace(format),
+ }, &Signature{
+ Name: strings.TrimSpace(signingName),
+ Email: strings.TrimSpace(signingEmail),
+ }
+ }
+
+ if setting.Repository.Signing.SigningKey == "" {
+ return nil, nil
+ }
+
+ return &SigningKey{
+ KeyID: setting.Repository.Signing.SigningKey,
+ Format: setting.Repository.Signing.SigningFormat,
+ }, &Signature{
+ Name: setting.Repository.Signing.SigningName,
+ Email: setting.Repository.Signing.SigningEmail,
+ }
+}
diff --git a/modules/git/languagestats/language_stats_gogit.go b/modules/git/languagestats/language_stats_gogit.go
index 418c05b157..ec03ca3159 100644
--- a/modules/git/languagestats/language_stats_gogit.go
+++ b/modules/git/languagestats/language_stats_gogit.go
@@ -108,7 +108,7 @@ func GetLanguageStats(repo *git_module.Repository, commitID string) (map[string]
if (!isVendored.Has() && analyze.IsVendor(f.Name)) ||
enry.IsDotFile(f.Name) ||
(!isDocumentation.Has() && enry.IsDocumentation(f.Name)) ||
- enry.IsConfiguration(f.Name) {
+ (!isDetectable.Has() && enry.IsConfiguration(f.Name)) {
return nil
}
diff --git a/modules/git/languagestats/language_stats_nogogit.go b/modules/git/languagestats/language_stats_nogogit.go
index 94cf9fff8c..442313d495 100644
--- a/modules/git/languagestats/language_stats_nogogit.go
+++ b/modules/git/languagestats/language_stats_nogogit.go
@@ -22,33 +22,28 @@ import (
func GetLanguageStats(repo *git.Repository, commitID string) (map[string]int64, error) {
// We will feed the commit IDs in order into cat-file --batch, followed by blobs as necessary.
// so let's create a batch stdin and stdout
- batchStdinWriter, batchReader, cancel, err := repo.CatFileBatch(repo.Ctx)
+ batch, cancel, err := repo.CatFileBatch(repo.Ctx)
if err != nil {
return nil, err
}
defer cancel()
- writeID := func(id string) error {
- _, err := batchStdinWriter.Write([]byte(id + "\n"))
- return err
- }
-
- if err := writeID(commitID); err != nil {
+ commitInfo, batchReader, err := batch.QueryContent(commitID)
+ if err != nil {
return nil, err
}
- shaBytes, typ, size, err := git.ReadBatchLine(batchReader)
- if typ != "commit" {
+ if commitInfo.Type != "commit" {
log.Debug("Unable to get commit for: %s. Err: %v", commitID, err)
return nil, git.ErrNotExist{ID: commitID}
}
- sha, err := git.NewIDFromString(string(shaBytes))
+ sha, err := git.NewIDFromString(commitInfo.ID)
if err != nil {
log.Debug("Unable to get commit for: %s. Err: %v", commitID, err)
return nil, git.ErrNotExist{ID: commitID}
}
- commit, err := git.CommitFromReader(repo, sha, io.LimitReader(batchReader, size))
+ commit, err := git.CommitFromReader(repo, sha, io.LimitReader(batchReader, commitInfo.Size))
if err != nil {
log.Debug("Unable to get commit for: %s. Err: %v", commitID, err)
return nil, err
@@ -137,27 +132,23 @@ func GetLanguageStats(repo *git.Repository, commitID string) (map[string]int64,
if (!isVendored.Has() && analyze.IsVendor(f.Name())) ||
enry.IsDotFile(f.Name()) ||
(!isDocumentation.Has() && enry.IsDocumentation(f.Name())) ||
- enry.IsConfiguration(f.Name()) {
+ (!isDetectable.Has() && enry.IsConfiguration(f.Name())) {
continue
}
// If content can not be read or file is too big just do detection by filename
if f.Size() <= bigFileSize {
- if err := writeID(f.ID.String()); err != nil {
- return nil, err
- }
- _, _, size, err := git.ReadBatchLine(batchReader)
+ info, _, err := batch.QueryContent(f.ID.String())
if err != nil {
- log.Debug("Error reading blob: %s Err: %v", f.ID.String(), err)
return nil, err
}
- sizeToRead := size
+ sizeToRead := info.Size
discard := int64(1)
- if size > fileSizeLimit {
+ if info.Size > fileSizeLimit {
sizeToRead = fileSizeLimit
- discard = size - fileSizeLimit + 1
+ discard = info.Size - fileSizeLimit + 1
}
_, err = contentBuf.ReadFrom(io.LimitReader(batchReader, sizeToRead))
diff --git a/modules/git/languagestats/main_test.go b/modules/git/languagestats/main_test.go
index b8f9ded005..bf860f2a18 100644
--- a/modules/git/languagestats/main_test.go
+++ b/modules/git/languagestats/main_test.go
@@ -4,37 +4,11 @@
package languagestats
import (
- "fmt"
- "os"
"testing"
"code.gitea.io/gitea/modules/git"
- "code.gitea.io/gitea/modules/setting"
- "code.gitea.io/gitea/modules/util"
)
-func testRun(m *testing.M) error {
- gitHomePath, err := os.MkdirTemp(os.TempDir(), "git-home")
- if err != nil {
- return fmt.Errorf("unable to create temp dir: %w", err)
- }
- defer util.RemoveAll(gitHomePath)
- setting.Git.HomePath = gitHomePath
-
- if err = git.InitFull(); err != nil {
- return fmt.Errorf("failed to call Init: %w", err)
- }
-
- exitCode := m.Run()
- if exitCode != 0 {
- return fmt.Errorf("run test failed, ExitCode=%d", exitCode)
- }
- return nil
-}
-
func TestMain(m *testing.M) {
- if err := testRun(m); err != nil {
- _, _ = fmt.Fprintf(os.Stderr, "Test failed: %v", err)
- os.Exit(1)
- }
+ git.RunGitTests(m)
}
diff --git a/modules/git/last_commit_cache.go b/modules/git/last_commit_cache.go
index cff2556083..a013773b47 100644
--- a/modules/git/last_commit_cache.go
+++ b/modules/git/last_commit_cache.go
@@ -55,12 +55,12 @@ func (c *LastCommitCache) Put(ref, entryPath, commitID string) error {
// Get gets the last commit information by commit id and entry path
func (c *LastCommitCache) Get(ref, entryPath string) (*Commit, error) {
if c == nil || c.cache == nil {
- return nil, nil
+ return nil, nil //nolint:nilnil // return nil when cache is not available
}
commitID, ok := c.cache.Get(getCacheKey(c.repoPath, ref, entryPath))
if !ok || commitID == "" {
- return nil, nil
+ return nil, nil //nolint:nilnil // return nil when cache miss
}
log.Debug("LastCommitCache hit level 1: [%s:%s:%s]", ref, entryPath, commitID)
diff --git a/modules/git/log_name_status.go b/modules/git/log_name_status.go
index 7a5192f58b..6e6d9985ae 100644
--- a/modules/git/log_name_status.go
+++ b/modules/git/log_name_status.go
@@ -15,25 +15,12 @@ import (
"code.gitea.io/gitea/modules/container"
"code.gitea.io/gitea/modules/git/gitcmd"
-
- "github.com/djherbis/buffer"
- "github.com/djherbis/nio/v3"
+ "code.gitea.io/gitea/modules/log"
)
// LogNameStatusRepo opens git log --raw in the provided repo and returns a stdin pipe, a stdout reader and cancel function
func LogNameStatusRepo(ctx context.Context, repository, head, treepath string, paths ...string) (*bufio.Reader, func()) {
- // We often want to feed the commits in order into cat-file --batch, followed by their trees and sub trees as necessary.
- // so let's create a batch stdin and stdout
- stdoutReader, stdoutWriter := nio.Pipe(buffer.New(32 * 1024))
-
// Lets also create a context so that we can absolutely ensure that the command should die when we're done
- ctx, ctxCancel := context.WithCancel(ctx)
-
- cancel := func() {
- ctxCancel()
- _ = stdoutReader.Close()
- _ = stdoutWriter.Close()
- }
cmd := gitcmd.NewCommand()
cmd.AddArguments("log", "--name-status", "-c", "--format=commit%x00%H %P%x00", "--parents", "--no-renames", "-t", "-z").AddDynamicArguments(head)
@@ -63,25 +50,21 @@ func LogNameStatusRepo(ctx context.Context, repository, head, treepath string, p
}
cmd.AddDashesAndList(files...)
+ stdoutReader, stdoutReaderClose := cmd.MakeStdoutPipe()
+ ctx, ctxCancel := context.WithCancel(ctx)
go func() {
- stderr := strings.Builder{}
- err := cmd.Run(ctx, &gitcmd.RunOpts{
- Dir: repository,
- Stdout: stdoutWriter,
- Stderr: &stderr,
- })
- if err != nil {
- _ = stdoutWriter.CloseWithError(gitcmd.ConcatenateError(err, (&stderr).String()))
- return
+ err := cmd.WithDir(repository).RunWithStderr(ctx)
+ if err != nil && !errors.Is(err, context.Canceled) {
+ log.Error("Unable to run git command %v: %v", cmd.LogString(), err)
}
-
- _ = stdoutWriter.Close()
}()
- // For simplicities sake we'll us a buffered reader to read from the cat-file --batch
bufReader := bufio.NewReaderSize(stdoutReader, 32*1024)
- return bufReader, cancel
+ return bufReader, func() {
+ ctxCancel()
+ stdoutReaderClose()
+ }
}
// LogNameStatusRepoParser parses a git log raw output from LogRawRepo
@@ -123,7 +106,7 @@ func (g *LogNameStatusRepoParser) Next(treepath string, paths2ids map[string]int
case bufio.ErrBufferFull:
g.buffull = true
case io.EOF:
- return nil, nil
+ return nil, nil //nolint:nilnil // return nil to signal EOF
default:
return nil, err
}
@@ -138,7 +121,7 @@ func (g *LogNameStatusRepoParser) Next(treepath string, paths2ids map[string]int
case bufio.ErrBufferFull:
g.buffull = true
case io.EOF:
- return nil, nil
+ return nil, nil //nolint:nilnil // return nil to signal EOF
default:
return nil, err
}
diff --git a/modules/git/notes_gogit.go b/modules/git/notes_gogit.go
index f802443b00..340f4d5ccc 100644
--- a/modules/git/notes_gogit.go
+++ b/modules/git/notes_gogit.go
@@ -7,6 +7,7 @@ package git
import (
"context"
+ "fmt"
"io"
"code.gitea.io/gitea/modules/log"
@@ -30,7 +31,11 @@ func GetNote(ctx context.Context, repo *Repository, commitID string, note *Note)
remainingCommitID := commitID
path := ""
- currentTree := notes.Tree.gogitTree
+ currentTree, err := notes.Tree.gogitTreeObject()
+ if err != nil {
+ return fmt.Errorf("unable to get tree object for notes commit %q: %w", notes.ID.String(), err)
+ }
+
log.Trace("Found tree with ID %q while searching for git note corresponding to the commit %q", currentTree.Entries[0].Name, commitID)
var file *object.File
for len(remainingCommitID) > 2 {
diff --git a/modules/git/notes_test.go b/modules/git/notes_test.go
index 7db2dbc0b9..5abb68b102 100644
--- a/modules/git/notes_test.go
+++ b/modules/git/notes_test.go
@@ -47,5 +47,5 @@ func TestGetNonExistentNotes(t *testing.T) {
note := Note{}
err = GetNote(t.Context(), bareRepo1, "non_existent_sha", ¬e)
assert.Error(t, err)
- assert.IsType(t, ErrNotExist{}, err)
+ assert.ErrorAs(t, err, &ErrNotExist{})
}
diff --git a/modules/git/object_id_test.go b/modules/git/object_id_test.go
index 03d0c85d87..213a0cd341 100644
--- a/modules/git/object_id_test.go
+++ b/modules/git/object_id_test.go
@@ -22,4 +22,6 @@ func TestIsValidSHAPattern(t *testing.T) {
assert.Equal(t, "2e65efe2a145dda7ee51d1741299f848e5bf752e", ComputeBlobHash(Sha1ObjectFormat, []byte("a")).String())
assert.Equal(t, "473a0f4c3be8a93681a267e3b1e9a7dcda1185436fe141f7749120a303721813", ComputeBlobHash(Sha256ObjectFormat, nil).String())
assert.Equal(t, "eb337bcee2061c5313c9a1392116b6c76039e9e30d71467ae359b36277e17dc7", ComputeBlobHash(Sha256ObjectFormat, []byte("a")).String())
+ assert.True(t, IsEmptyCommitID(""))
+ assert.True(t, IsEmptyCommitID("0000000000000000000000000000000000000000"))
}
diff --git a/modules/git/parse.go b/modules/git/parse.go
index a7f5c58e89..94020e690d 100644
--- a/modules/git/parse.go
+++ b/modules/git/parse.go
@@ -27,15 +27,15 @@ func parseLsTreeLine(line []byte) (*LsTreeEntry, error) {
// \t
var err error
- posTab := bytes.IndexByte(line, '\t')
- if posTab == -1 {
+ before, after, ok := bytes.Cut(line, []byte{'\t'})
+ if !ok {
return nil, fmt.Errorf("invalid ls-tree output (no tab): %q", line)
}
entry := new(LsTreeEntry)
- entryAttrs := line[:posTab]
- entryName := line[posTab+1:]
+ entryAttrs := before
+ entryName := after
entryMode, entryAttrs, _ := bytes.Cut(entryAttrs, sepSpace)
_ /* entryType */, entryAttrs, _ = bytes.Cut(entryAttrs, sepSpace) // the type is not used, the mode is enough to determine the type
@@ -46,8 +46,8 @@ func parseLsTreeLine(line []byte) (*LsTreeEntry, error) {
entry.Size = optional.Some(size)
}
- entry.EntryMode, err = ParseEntryMode(string(entryMode))
- if err != nil || entry.EntryMode == EntryModeNoEntry {
+ entry.EntryMode = ParseEntryMode(string(entryMode))
+ if entry.EntryMode == EntryModeNoEntry {
return nil, fmt.Errorf("invalid ls-tree output (invalid mode): %q, err: %w", line, err)
}
diff --git a/modules/git/parse_gogit.go b/modules/git/parse_gogit.go
deleted file mode 100644
index 74d258de8e..0000000000
--- a/modules/git/parse_gogit.go
+++ /dev/null
@@ -1,96 +0,0 @@
-// Copyright 2018 The Gitea Authors. All rights reserved.
-// SPDX-License-Identifier: MIT
-
-//go:build gogit
-
-package git
-
-import (
- "bytes"
- "fmt"
- "strconv"
- "strings"
-
- "github.com/go-git/go-git/v5/plumbing"
- "github.com/go-git/go-git/v5/plumbing/filemode"
- "github.com/go-git/go-git/v5/plumbing/hash"
- "github.com/go-git/go-git/v5/plumbing/object"
-)
-
-// ParseTreeEntries parses the output of a `git ls-tree -l` command.
-func ParseTreeEntries(data []byte) ([]*TreeEntry, error) {
- return parseTreeEntries(data, nil)
-}
-
-func parseTreeEntries(data []byte, ptree *Tree) ([]*TreeEntry, error) {
- entries := make([]*TreeEntry, 0, 10)
- for pos := 0; pos < len(data); {
- // expect line to be of the form " \t"
- entry := new(TreeEntry)
- entry.gogitTreeEntry = &object.TreeEntry{}
- entry.ptree = ptree
- if pos+6 > len(data) {
- return nil, fmt.Errorf("Invalid ls-tree output: %s", string(data))
- }
- switch string(data[pos : pos+6]) {
- case "100644":
- entry.gogitTreeEntry.Mode = filemode.Regular
- pos += 12 // skip over "100644 blob "
- case "100755":
- entry.gogitTreeEntry.Mode = filemode.Executable
- pos += 12 // skip over "100755 blob "
- case "120000":
- entry.gogitTreeEntry.Mode = filemode.Symlink
- pos += 12 // skip over "120000 blob "
- case "160000":
- entry.gogitTreeEntry.Mode = filemode.Submodule
- pos += 14 // skip over "160000 object "
- case "040000":
- entry.gogitTreeEntry.Mode = filemode.Dir
- pos += 12 // skip over "040000 tree "
- default:
- return nil, fmt.Errorf("unknown type: %v", string(data[pos:pos+6]))
- }
-
- // in hex format, not byte format ....
- if pos+hash.Size*2 > len(data) {
- return nil, fmt.Errorf("Invalid ls-tree output: %s", string(data))
- }
- var err error
- entry.ID, err = NewIDFromString(string(data[pos : pos+hash.Size*2]))
- if err != nil {
- return nil, fmt.Errorf("invalid ls-tree output: %w", err)
- }
- entry.gogitTreeEntry.Hash = plumbing.Hash(entry.ID.RawValue())
- pos += 41 // skip over sha and trailing space
-
- end := pos + bytes.IndexByte(data[pos:], '\t')
- if end < pos {
- return nil, fmt.Errorf("Invalid ls-tree -l output: %s", string(data))
- }
- entry.size, _ = strconv.ParseInt(strings.TrimSpace(string(data[pos:end])), 10, 64)
- entry.sized = true
-
- pos = end + 1
-
- end = pos + bytes.IndexByte(data[pos:], '\n')
- if end < pos {
- return nil, fmt.Errorf("Invalid ls-tree output: %s", string(data))
- }
-
- // In case entry name is surrounded by double quotes(it happens only in git-shell).
- if data[pos] == '"' {
- var err error
- entry.gogitTreeEntry.Name, err = strconv.Unquote(string(data[pos:end]))
- if err != nil {
- return nil, fmt.Errorf("Invalid ls-tree output: %w", err)
- }
- } else {
- entry.gogitTreeEntry.Name = string(data[pos:end])
- }
-
- pos = end + 1
- entries = append(entries, entry)
- }
- return entries, nil
-}
diff --git a/modules/git/parse_gogit_test.go b/modules/git/parse_gogit_test.go
deleted file mode 100644
index 3e171d7e56..0000000000
--- a/modules/git/parse_gogit_test.go
+++ /dev/null
@@ -1,78 +0,0 @@
-// Copyright 2018 The Gitea Authors. All rights reserved.
-// SPDX-License-Identifier: MIT
-
-//go:build gogit
-
-package git
-
-import (
- "fmt"
- "testing"
-
- "github.com/go-git/go-git/v5/plumbing"
- "github.com/go-git/go-git/v5/plumbing/filemode"
- "github.com/go-git/go-git/v5/plumbing/object"
- "github.com/stretchr/testify/assert"
-)
-
-func TestParseTreeEntries(t *testing.T) {
- testCases := []struct {
- Input string
- Expected []*TreeEntry
- }{
- {
- Input: "",
- Expected: []*TreeEntry{},
- },
- {
- Input: "100644 blob 61ab7345a1a3bbc590068ccae37b8515cfc5843c 1022\texample/file2.txt\n",
- Expected: []*TreeEntry{
- {
- ID: MustIDFromString("61ab7345a1a3bbc590068ccae37b8515cfc5843c"),
- gogitTreeEntry: &object.TreeEntry{
- Hash: plumbing.Hash(MustIDFromString("61ab7345a1a3bbc590068ccae37b8515cfc5843c").RawValue()),
- Name: "example/file2.txt",
- Mode: filemode.Regular,
- },
- size: 1022,
- sized: true,
- },
- },
- },
- {
- Input: "120000 blob 61ab7345a1a3bbc590068ccae37b8515cfc5843c 234131\t\"example/\\n.txt\"\n" +
- "040000 tree 1d01fb729fb0db5881daaa6030f9f2d3cd3d5ae8 -\texample\n",
- Expected: []*TreeEntry{
- {
- ID: MustIDFromString("61ab7345a1a3bbc590068ccae37b8515cfc5843c"),
- gogitTreeEntry: &object.TreeEntry{
- Hash: plumbing.Hash(MustIDFromString("61ab7345a1a3bbc590068ccae37b8515cfc5843c").RawValue()),
- Name: "example/\n.txt",
- Mode: filemode.Symlink,
- },
- size: 234131,
- sized: true,
- },
- {
- ID: MustIDFromString("1d01fb729fb0db5881daaa6030f9f2d3cd3d5ae8"),
- sized: true,
- gogitTreeEntry: &object.TreeEntry{
- Hash: plumbing.Hash(MustIDFromString("1d01fb729fb0db5881daaa6030f9f2d3cd3d5ae8").RawValue()),
- Name: "example",
- Mode: filemode.Dir,
- },
- },
- },
- },
- }
-
- for _, testCase := range testCases {
- entries, err := ParseTreeEntries([]byte(testCase.Input))
- assert.NoError(t, err)
- if len(entries) > 1 {
- fmt.Println(testCase.Expected[0].ID)
- fmt.Println(entries[0].ID)
- }
- assert.EqualValues(t, testCase.Expected, entries)
- }
-}
diff --git a/modules/git/parse_nogogit.go b/modules/git/parse_treeentry.go
similarity index 96%
rename from modules/git/parse_nogogit.go
rename to modules/git/parse_treeentry.go
index 78a0162889..d46cd3344d 100644
--- a/modules/git/parse_nogogit.go
+++ b/modules/git/parse_treeentry.go
@@ -1,12 +1,9 @@
// Copyright 2018 The Gitea Authors. All rights reserved.
// SPDX-License-Identifier: MIT
-//go:build !gogit
-
package git
import (
- "bufio"
"bytes"
"fmt"
"io"
@@ -49,7 +46,7 @@ func parseTreeEntries(data []byte, ptree *Tree) ([]*TreeEntry, error) {
return entries, nil
}
-func catBatchParseTreeEntries(objectFormat ObjectFormat, ptree *Tree, rd *bufio.Reader, sz int64) ([]*TreeEntry, error) {
+func catBatchParseTreeEntries(objectFormat ObjectFormat, ptree *Tree, rd BufferedReader, sz int64) ([]*TreeEntry, error) {
fnameBuf := make([]byte, 4096)
modeBuf := make([]byte, 40)
shaBuf := make([]byte, objectFormat.FullLength())
diff --git a/modules/git/parse_nogogit_test.go b/modules/git/parse_treeentry_test.go
similarity index 99%
rename from modules/git/parse_nogogit_test.go
rename to modules/git/parse_treeentry_test.go
index 6594c84269..4223cbb3d7 100644
--- a/modules/git/parse_nogogit_test.go
+++ b/modules/git/parse_treeentry_test.go
@@ -1,8 +1,6 @@
// Copyright 2021 The Gitea Authors. All rights reserved.
// SPDX-License-Identifier: MIT
-//go:build !gogit
-
package git
import (
diff --git a/modules/git/pipeline/catfile.go b/modules/git/pipeline/catfile.go
index ced8532e6d..3d005e28f1 100644
--- a/modules/git/pipeline/catfile.go
+++ b/modules/git/pipeline/catfile.go
@@ -5,83 +5,34 @@ package pipeline
import (
"bufio"
- "bytes"
"context"
- "fmt"
"io"
"strconv"
"strings"
- "sync"
"code.gitea.io/gitea/modules/git/gitcmd"
- "code.gitea.io/gitea/modules/log"
)
// CatFileBatchCheck runs cat-file with --batch-check
-func CatFileBatchCheck(ctx context.Context, shasToCheckReader *io.PipeReader, catFileCheckWriter *io.PipeWriter, wg *sync.WaitGroup, tmpBasePath string) {
- defer wg.Done()
- defer shasToCheckReader.Close()
- defer catFileCheckWriter.Close()
-
- stderr := new(bytes.Buffer)
- var errbuf strings.Builder
- cmd := gitcmd.NewCommand("cat-file", "--batch-check")
- if err := cmd.Run(ctx, &gitcmd.RunOpts{
- Dir: tmpBasePath,
- Stdin: shasToCheckReader,
- Stdout: catFileCheckWriter,
- Stderr: stderr,
- }); err != nil {
- _ = catFileCheckWriter.CloseWithError(fmt.Errorf("git cat-file --batch-check [%s]: %w - %s", tmpBasePath, err, errbuf.String()))
- }
+func CatFileBatchCheck(ctx context.Context, cmd *gitcmd.Command, tmpBasePath string) error {
+ cmd.AddArguments("cat-file", "--batch-check")
+ return cmd.WithDir(tmpBasePath).RunWithStderr(ctx)
}
// CatFileBatchCheckAllObjects runs cat-file with --batch-check --batch-all
-func CatFileBatchCheckAllObjects(ctx context.Context, catFileCheckWriter *io.PipeWriter, wg *sync.WaitGroup, tmpBasePath string, errChan chan<- error) {
- defer wg.Done()
- defer catFileCheckWriter.Close()
-
- stderr := new(bytes.Buffer)
- var errbuf strings.Builder
- cmd := gitcmd.NewCommand("cat-file", "--batch-check", "--batch-all-objects")
- if err := cmd.Run(ctx, &gitcmd.RunOpts{
- Dir: tmpBasePath,
- Stdout: catFileCheckWriter,
- Stderr: stderr,
- }); err != nil {
- log.Error("git cat-file --batch-check --batch-all-object [%s]: %v - %s", tmpBasePath, err, errbuf.String())
- err = fmt.Errorf("git cat-file --batch-check --batch-all-object [%s]: %w - %s", tmpBasePath, err, errbuf.String())
- _ = catFileCheckWriter.CloseWithError(err)
- errChan <- err
- }
+func CatFileBatchCheckAllObjects(ctx context.Context, cmd *gitcmd.Command, tmpBasePath string) error {
+ return cmd.AddArguments("cat-file", "--batch-check", "--batch-all-objects").WithDir(tmpBasePath).RunWithStderr(ctx)
}
// CatFileBatch runs cat-file --batch
-func CatFileBatch(ctx context.Context, shasToBatchReader *io.PipeReader, catFileBatchWriter *io.PipeWriter, wg *sync.WaitGroup, tmpBasePath string) {
- defer wg.Done()
- defer shasToBatchReader.Close()
- defer catFileBatchWriter.Close()
-
- stderr := new(bytes.Buffer)
- var errbuf strings.Builder
- if err := gitcmd.NewCommand("cat-file", "--batch").Run(ctx, &gitcmd.RunOpts{
- Dir: tmpBasePath,
- Stdout: catFileBatchWriter,
- Stdin: shasToBatchReader,
- Stderr: stderr,
- }); err != nil {
- _ = shasToBatchReader.CloseWithError(fmt.Errorf("git rev-list [%s]: %w - %s", tmpBasePath, err, errbuf.String()))
- }
+func CatFileBatch(ctx context.Context, cmd *gitcmd.Command, tmpBasePath string) error {
+ return cmd.AddArguments("cat-file", "--batch").WithDir(tmpBasePath).RunWithStderr(ctx)
}
// BlobsLessThan1024FromCatFileBatchCheck reads a pipeline from cat-file --batch-check and returns the blobs <1024 in size
-func BlobsLessThan1024FromCatFileBatchCheck(catFileCheckReader *io.PipeReader, shasToBatchWriter *io.PipeWriter, wg *sync.WaitGroup) {
- defer wg.Done()
- defer catFileCheckReader.Close()
- scanner := bufio.NewScanner(catFileCheckReader)
- defer func() {
- _ = shasToBatchWriter.CloseWithError(scanner.Err())
- }()
+func BlobsLessThan1024FromCatFileBatchCheck(in io.ReadCloser, out io.WriteCloser) error {
+ defer out.Close()
+ scanner := bufio.NewScanner(in)
for scanner.Scan() {
line := scanner.Text()
if len(line) == 0 {
@@ -97,12 +48,12 @@ func BlobsLessThan1024FromCatFileBatchCheck(catFileCheckReader *io.PipeReader, s
}
toWrite := []byte(fields[0] + "\n")
for len(toWrite) > 0 {
- n, err := shasToBatchWriter.Write(toWrite)
+ n, err := out.Write(toWrite)
if err != nil {
- _ = catFileCheckReader.CloseWithError(err)
- break
+ return err
}
toWrite = toWrite[n:]
}
}
+ return scanner.Err()
}
diff --git a/modules/git/pipeline/lfs_common.go b/modules/git/pipeline/lfs_common.go
index 188e7d4d65..914aefbeaf 100644
--- a/modules/git/pipeline/lfs_common.go
+++ b/modules/git/pipeline/lfs_common.go
@@ -4,7 +4,6 @@
package pipeline
import (
- "fmt"
"time"
"code.gitea.io/gitea/modules/git"
@@ -26,7 +25,3 @@ type lfsResultSlice []*LFSResult
func (a lfsResultSlice) Len() int { return len(a) }
func (a lfsResultSlice) Swap(i, j int) { a[i], a[j] = a[j], a[i] }
func (a lfsResultSlice) Less(i, j int) bool { return a[j].When.After(a[i].When) }
-
-func lfsError(msg string, err error) error {
- return fmt.Errorf("LFS error occurred, %s: err: %w", msg, err)
-}
diff --git a/modules/git/pipeline/lfs_gogit.go b/modules/git/pipeline/lfs_gogit.go
index adcf8ed09c..c12397569c 100644
--- a/modules/git/pipeline/lfs_gogit.go
+++ b/modules/git/pipeline/lfs_gogit.go
@@ -6,11 +6,10 @@
package pipeline
import (
- "bufio"
+ "fmt"
"io"
"sort"
"strings"
- "sync"
"code.gitea.io/gitea/modules/git"
@@ -24,7 +23,6 @@ func FindLFSFile(repo *git.Repository, objectID git.ObjectID) ([]*LFSResult, err
resultsMap := map[string]*LFSResult{}
results := make([]*LFSResult, 0)
- basePath := repo.Path
gogitRepo := repo.GoGitRepo()
commitsIter, err := gogitRepo.Log(&gogit.LogOptions{
@@ -32,7 +30,7 @@ func FindLFSFile(repo *git.Repository, objectID git.ObjectID) ([]*LFSResult, err
All: true,
})
if err != nil {
- return nil, lfsError("failed to get GoGit CommitsIter", err)
+ return nil, fmt.Errorf("LFS error occurred, failed to get GoGit CommitsIter: err: %w", err)
}
err = commitsIter.ForEach(func(gitCommit *object.Commit) error {
@@ -66,7 +64,7 @@ func FindLFSFile(repo *git.Repository, objectID git.ObjectID) ([]*LFSResult, err
return nil
})
if err != nil && err != io.EOF {
- return nil, lfsError("failure in CommitIter.ForEach", err)
+ return nil, fmt.Errorf("LFS error occurred, failure in CommitIter.ForEach: %w", err)
}
for _, result := range resultsMap {
@@ -82,65 +80,6 @@ func FindLFSFile(repo *git.Repository, objectID git.ObjectID) ([]*LFSResult, err
}
sort.Sort(lfsResultSlice(results))
-
- // Should really use a go-git function here but name-rev is not completed and recapitulating it is not simple
- shasToNameReader, shasToNameWriter := io.Pipe()
- nameRevStdinReader, nameRevStdinWriter := io.Pipe()
- errChan := make(chan error, 1)
- wg := sync.WaitGroup{}
- wg.Add(3)
-
- go func() {
- defer wg.Done()
- scanner := bufio.NewScanner(nameRevStdinReader)
- i := 0
- for scanner.Scan() {
- line := scanner.Text()
- if len(line) == 0 {
- continue
- }
- result := results[i]
- result.FullCommitName = line
- result.BranchName = strings.Split(line, "~")[0]
- i++
- }
- }()
- go NameRevStdin(repo.Ctx, shasToNameReader, nameRevStdinWriter, &wg, basePath)
- go func() {
- defer wg.Done()
- defer shasToNameWriter.Close()
- for _, result := range results {
- i := 0
- if i < len(result.SHA) {
- n, err := shasToNameWriter.Write([]byte(result.SHA)[i:])
- if err != nil {
- errChan <- err
- break
- }
- i += n
- }
- n := 0
- for n < 1 {
- n, err = shasToNameWriter.Write([]byte{'\n'})
- if err != nil {
- errChan <- err
- break
- }
-
- }
-
- }
- }()
-
- wg.Wait()
-
- select {
- case err, has := <-errChan:
- if has {
- return nil, lfsError("unable to obtain name for LFS files", err)
- }
- default:
- }
-
- return results, nil
+ err = fillResultNameRev(repo.Ctx, repo.Path, results)
+ return results, err
}
diff --git a/modules/git/pipeline/lfs_nogogit.go b/modules/git/pipeline/lfs_nogogit.go
index d2f147854d..1d8fa63cde 100644
--- a/modules/git/pipeline/lfs_nogogit.go
+++ b/modules/git/pipeline/lfs_nogogit.go
@@ -8,46 +8,33 @@ package pipeline
import (
"bufio"
"bytes"
+ "encoding/hex"
"io"
"sort"
- "strings"
- "sync"
"code.gitea.io/gitea/modules/git"
"code.gitea.io/gitea/modules/git/gitcmd"
)
// FindLFSFile finds commits that contain a provided pointer file hash
-func FindLFSFile(repo *git.Repository, objectID git.ObjectID) ([]*LFSResult, error) {
+func FindLFSFile(repo *git.Repository, objectID git.ObjectID) (results []*LFSResult, _ error) {
+ cmd := gitcmd.NewCommand("rev-list", "--all")
+ revListReader, revListReaderClose := cmd.MakeStdoutPipe()
+ defer revListReaderClose()
+ err := cmd.WithDir(repo.Path).
+ WithPipelineFunc(func(context gitcmd.Context) (err error) {
+ results, err = findLFSFileFunc(repo, objectID, revListReader)
+ return err
+ }).RunWithStderr(repo.Ctx)
+ return results, err
+}
+
+func findLFSFileFunc(repo *git.Repository, objectID git.ObjectID, revListReader io.Reader) ([]*LFSResult, error) {
resultsMap := map[string]*LFSResult{}
results := make([]*LFSResult, 0)
-
- basePath := repo.Path
-
- // Use rev-list to provide us with all commits in order
- revListReader, revListWriter := io.Pipe()
- defer func() {
- _ = revListWriter.Close()
- _ = revListReader.Close()
- }()
-
- go func() {
- stderr := strings.Builder{}
- err := gitcmd.NewCommand("rev-list", "--all").Run(repo.Ctx, &gitcmd.RunOpts{
- Dir: repo.Path,
- Stdout: revListWriter,
- Stderr: &stderr,
- })
- if err != nil {
- _ = revListWriter.CloseWithError(gitcmd.ConcatenateError(err, (&stderr).String()))
- } else {
- _ = revListWriter.Close()
- }
- }()
-
// Next feed the commits in order into cat-file --batch, followed by their trees and sub trees as necessary.
// so let's create a batch stdin and stdout
- batchStdinWriter, batchReader, cancel, err := repo.CatFileBatch(repo.Ctx)
+ batch, cancel, err := repo.CatFileBatch(repo.Ctx)
if err != nil {
return nil, err
}
@@ -55,7 +42,7 @@ func FindLFSFile(repo *git.Repository, objectID git.ObjectID) ([]*LFSResult, err
// We'll use a scanner for the revList because it's simpler than a bufio.Reader
scan := bufio.NewScanner(revListReader)
- trees := [][]byte{}
+ trees := []string{}
paths := []string{}
fnameBuf := make([]byte, 4096)
@@ -64,14 +51,10 @@ func FindLFSFile(repo *git.Repository, objectID git.ObjectID) ([]*LFSResult, err
for scan.Scan() {
// Get the next commit ID
- commitID := scan.Bytes()
+ commitID := scan.Text()
// push the commit to the cat-file --batch process
- _, err := batchStdinWriter.Write(commitID)
- if err != nil {
- return nil, err
- }
- _, err = batchStdinWriter.Write([]byte{'\n'})
+ info, batchReader, err := batch.QueryContent(commitID)
if err != nil {
return nil, err
}
@@ -81,26 +64,20 @@ func FindLFSFile(repo *git.Repository, objectID git.ObjectID) ([]*LFSResult, err
commitReadingLoop:
for {
- _, typ, size, err := git.ReadBatchLine(batchReader)
- if err != nil {
- return nil, err
- }
-
- switch typ {
+ switch info.Type {
case "tag":
// This shouldn't happen but if it does well just get the commit and try again
- id, err := git.ReadTagObjectID(batchReader, size)
+ id, err := git.ReadTagObjectID(batchReader, info.Size)
if err != nil {
return nil, err
}
- _, err = batchStdinWriter.Write([]byte(id + "\n"))
- if err != nil {
+ if info, batchReader, err = batch.QueryContent(id); err != nil {
return nil, err
}
continue
case "commit":
// Read in the commit to get its tree and in case this is one of the last used commits
- curCommit, err = git.CommitFromReader(repo, git.MustIDFromString(string(commitID)), io.LimitReader(batchReader, size))
+ curCommit, err = git.CommitFromReader(repo, git.MustIDFromString(commitID), io.LimitReader(batchReader, info.Size))
if err != nil {
return nil, err
}
@@ -108,13 +85,13 @@ func FindLFSFile(repo *git.Repository, objectID git.ObjectID) ([]*LFSResult, err
return nil, err
}
- if _, err := batchStdinWriter.Write([]byte(curCommit.Tree.ID.String() + "\n")); err != nil {
+ if info, _, err = batch.QueryContent(curCommit.Tree.ID.String()); err != nil {
return nil, err
}
curPath = ""
case "tree":
var n int64
- for n < size {
+ for n < info.Size {
mode, fname, binObjectID, count, err := git.ParseCatFileTreeLine(objectID.Type(), batchReader, modeBuf, fnameBuf, workingShaBuf)
if err != nil {
return nil, err
@@ -124,15 +101,13 @@ func FindLFSFile(repo *git.Repository, objectID git.ObjectID) ([]*LFSResult, err
result := LFSResult{
Name: curPath + string(fname),
SHA: curCommit.ID.String(),
- Summary: strings.Split(strings.TrimSpace(curCommit.CommitMessage), "\n")[0],
+ Summary: curCommit.Summary(),
When: curCommit.Author.When,
ParentHashes: curCommit.Parents,
}
resultsMap[curCommit.ID.String()+":"+curPath+string(fname)] = &result
} else if string(mode) == git.EntryModeTree.String() {
- hexObjectID := make([]byte, objectID.Type().FullLength())
- git.BinToHex(objectID.Type(), binObjectID, hexObjectID)
- trees = append(trees, hexObjectID)
+ trees = append(trees, hex.EncodeToString(binObjectID))
paths = append(paths, curPath+string(fname)+"/")
}
}
@@ -140,11 +115,7 @@ func FindLFSFile(repo *git.Repository, objectID git.ObjectID) ([]*LFSResult, err
return nil, err
}
if len(trees) > 0 {
- _, err := batchStdinWriter.Write(trees[len(trees)-1])
- if err != nil {
- return nil, err
- }
- _, err = batchStdinWriter.Write([]byte("\n"))
+ info, _, err = batch.QueryContent(trees[len(trees)-1])
if err != nil {
return nil, err
}
@@ -155,7 +126,7 @@ func FindLFSFile(repo *git.Repository, objectID git.ObjectID) ([]*LFSResult, err
break commitReadingLoop
}
default:
- if err := git.DiscardFull(batchReader, size+1); err != nil {
+ if err := git.DiscardFull(batchReader, info.Size+1); err != nil {
return nil, err
}
}
@@ -179,56 +150,6 @@ func FindLFSFile(repo *git.Repository, objectID git.ObjectID) ([]*LFSResult, err
}
sort.Sort(lfsResultSlice(results))
-
- // Should really use a go-git function here but name-rev is not completed and recapitulating it is not simple
- shasToNameReader, shasToNameWriter := io.Pipe()
- nameRevStdinReader, nameRevStdinWriter := io.Pipe()
- errChan := make(chan error, 1)
- wg := sync.WaitGroup{}
- wg.Add(3)
-
- go func() {
- defer wg.Done()
- scanner := bufio.NewScanner(nameRevStdinReader)
- i := 0
- for scanner.Scan() {
- line := scanner.Text()
- if len(line) == 0 {
- continue
- }
- result := results[i]
- result.FullCommitName = line
- result.BranchName = strings.Split(line, "~")[0]
- i++
- }
- }()
- go NameRevStdin(repo.Ctx, shasToNameReader, nameRevStdinWriter, &wg, basePath)
- go func() {
- defer wg.Done()
- defer shasToNameWriter.Close()
- for _, result := range results {
- _, err := shasToNameWriter.Write([]byte(result.SHA))
- if err != nil {
- errChan <- err
- break
- }
- _, err = shasToNameWriter.Write([]byte{'\n'})
- if err != nil {
- errChan <- err
- break
- }
- }
- }()
-
- wg.Wait()
-
- select {
- case err, has := <-errChan:
- if has {
- return nil, lfsError("unable to obtain name for LFS files", err)
- }
- default:
- }
-
- return results, nil
+ err = fillResultNameRev(repo.Ctx, repo.Path, results)
+ return results, err
}
diff --git a/modules/git/pipeline/lfs_test.go b/modules/git/pipeline/lfs_test.go
new file mode 100644
index 0000000000..30fe2f93c2
--- /dev/null
+++ b/modules/git/pipeline/lfs_test.go
@@ -0,0 +1,38 @@
+// Copyright 2026 The Gitea Authors. All rights reserved.
+// SPDX-License-Identifier: MIT
+
+package pipeline
+
+import (
+ "testing"
+ "time"
+
+ "code.gitea.io/gitea/modules/git"
+
+ "github.com/stretchr/testify/assert"
+ "github.com/stretchr/testify/require"
+)
+
+func TestFindLFSFile(t *testing.T) {
+ repoPath := "../../../tests/gitea-repositories-meta/user2/lfs.git"
+ gitRepo, err := git.OpenRepository(t.Context(), repoPath)
+ require.NoError(t, err)
+ defer gitRepo.Close()
+
+ objectID := git.MustIDFromString("2b6c6c4eaefa24b22f2092c3d54b263ff26feb58")
+
+ stats, err := FindLFSFile(gitRepo, objectID)
+ require.NoError(t, err)
+
+ tm, err := time.Parse(time.RFC3339, "2022-12-21T17:56:42-05:00")
+ require.NoError(t, err)
+
+ assert.Len(t, stats, 1)
+ assert.Equal(t, "CONTRIBUTING.md", stats[0].Name)
+ assert.Equal(t, "73cf03db6ece34e12bf91e8853dc58f678f2f82d", stats[0].SHA)
+ assert.Equal(t, "Initial commit", stats[0].Summary)
+ assert.Equal(t, tm, stats[0].When)
+ assert.Empty(t, stats[0].ParentHashes)
+ assert.Equal(t, "master", stats[0].BranchName)
+ assert.Equal(t, "master", stats[0].FullCommitName)
+}
diff --git a/modules/git/pipeline/main_test.go b/modules/git/pipeline/main_test.go
new file mode 100644
index 0000000000..fa5832b68c
--- /dev/null
+++ b/modules/git/pipeline/main_test.go
@@ -0,0 +1,14 @@
+// Copyright 2026 The Gitea Authors. All rights reserved.
+// SPDX-License-Identifier: MIT
+
+package pipeline
+
+import (
+ "testing"
+
+ "code.gitea.io/gitea/modules/git"
+)
+
+func TestMain(m *testing.M) {
+ git.RunGitTests(m)
+}
diff --git a/modules/git/pipeline/namerev.go b/modules/git/pipeline/namerev.go
index 0081f7a26d..24de442940 100644
--- a/modules/git/pipeline/namerev.go
+++ b/modules/git/pipeline/namerev.go
@@ -4,30 +4,54 @@
package pipeline
import (
- "bytes"
+ "bufio"
"context"
- "fmt"
- "io"
+ "errors"
"strings"
- "sync"
"code.gitea.io/gitea/modules/git/gitcmd"
+
+ "golang.org/x/sync/errgroup"
)
-// NameRevStdin runs name-rev --stdin
-func NameRevStdin(ctx context.Context, shasToNameReader *io.PipeReader, nameRevStdinWriter *io.PipeWriter, wg *sync.WaitGroup, tmpBasePath string) {
- defer wg.Done()
- defer shasToNameReader.Close()
- defer nameRevStdinWriter.Close()
+func fillResultNameRev(ctx context.Context, basePath string, results []*LFSResult) error {
+ // Should really use a go-git function here but name-rev is not completed and recapitulating it is not simple
+ wg := errgroup.Group{}
+ cmd := gitcmd.NewCommand("name-rev", "--stdin", "--name-only", "--always").WithDir(basePath)
+ stdin, stdinClose := cmd.MakeStdinPipe()
+ stdout, stdoutClose := cmd.MakeStdoutPipe()
+ defer stdinClose()
+ defer stdoutClose()
- stderr := new(bytes.Buffer)
- var errbuf strings.Builder
- if err := gitcmd.NewCommand("name-rev", "--stdin", "--name-only", "--always").Run(ctx, &gitcmd.RunOpts{
- Dir: tmpBasePath,
- Stdout: nameRevStdinWriter,
- Stdin: shasToNameReader,
- Stderr: stderr,
- }); err != nil {
- _ = shasToNameReader.CloseWithError(fmt.Errorf("git name-rev [%s]: %w - %s", tmpBasePath, err, errbuf.String()))
- }
+ wg.Go(func() error {
+ scanner := bufio.NewScanner(stdout)
+ i := 0
+ for scanner.Scan() {
+ line := scanner.Text()
+ if len(line) == 0 {
+ continue
+ }
+ result := results[i]
+ result.FullCommitName = line
+ result.BranchName = strings.Split(line, "~")[0]
+ i++
+ }
+ return scanner.Err()
+ })
+ wg.Go(func() error {
+ defer stdinClose()
+ for _, result := range results {
+ _, err := stdin.Write([]byte(result.SHA))
+ if err != nil {
+ return err
+ }
+ _, err = stdin.Write([]byte{'\n'})
+ if err != nil {
+ return err
+ }
+ }
+ return nil
+ })
+ err := cmd.RunWithStderr(ctx)
+ return errors.Join(err, wg.Wait())
}
diff --git a/modules/git/pipeline/revlist.go b/modules/git/pipeline/revlist.go
index 9d4ff75434..28d4751bd8 100644
--- a/modules/git/pipeline/revlist.go
+++ b/modules/git/pipeline/revlist.go
@@ -5,65 +5,26 @@ package pipeline
import (
"bufio"
- "bytes"
"context"
- "fmt"
"io"
"strings"
- "sync"
"code.gitea.io/gitea/modules/git/gitcmd"
- "code.gitea.io/gitea/modules/log"
)
-// RevListAllObjects runs rev-list --objects --all and writes to a pipewriter
-func RevListAllObjects(ctx context.Context, revListWriter *io.PipeWriter, wg *sync.WaitGroup, basePath string, errChan chan<- error) {
- defer wg.Done()
- defer revListWriter.Close()
-
- stderr := new(bytes.Buffer)
- var errbuf strings.Builder
- cmd := gitcmd.NewCommand("rev-list", "--objects", "--all")
- if err := cmd.Run(ctx, &gitcmd.RunOpts{
- Dir: basePath,
- Stdout: revListWriter,
- Stderr: stderr,
- }); err != nil {
- log.Error("git rev-list --objects --all [%s]: %v - %s", basePath, err, errbuf.String())
- err = fmt.Errorf("git rev-list --objects --all [%s]: %w - %s", basePath, err, errbuf.String())
- _ = revListWriter.CloseWithError(err)
- errChan <- err
- }
-}
-
// RevListObjects run rev-list --objects from headSHA to baseSHA
-func RevListObjects(ctx context.Context, revListWriter *io.PipeWriter, wg *sync.WaitGroup, tmpBasePath, headSHA, baseSHA string, errChan chan<- error) {
- defer wg.Done()
- defer revListWriter.Close()
- stderr := new(bytes.Buffer)
- var errbuf strings.Builder
- cmd := gitcmd.NewCommand("rev-list", "--objects").AddDynamicArguments(headSHA)
+func RevListObjects(ctx context.Context, cmd *gitcmd.Command, tmpBasePath, headSHA, baseSHA string) error {
+ cmd.AddArguments("rev-list", "--objects").AddDynamicArguments(headSHA)
if baseSHA != "" {
cmd = cmd.AddArguments("--not").AddDynamicArguments(baseSHA)
}
- if err := cmd.Run(ctx, &gitcmd.RunOpts{
- Dir: tmpBasePath,
- Stdout: revListWriter,
- Stderr: stderr,
- }); err != nil {
- log.Error("git rev-list [%s]: %v - %s", tmpBasePath, err, errbuf.String())
- errChan <- fmt.Errorf("git rev-list [%s]: %w - %s", tmpBasePath, err, errbuf.String())
- }
+ return cmd.WithDir(tmpBasePath).RunWithStderr(ctx)
}
// BlobsFromRevListObjects reads a RevListAllObjects and only selects blobs
-func BlobsFromRevListObjects(revListReader *io.PipeReader, shasToCheckWriter *io.PipeWriter, wg *sync.WaitGroup) {
- defer wg.Done()
- defer revListReader.Close()
- scanner := bufio.NewScanner(revListReader)
- defer func() {
- _ = shasToCheckWriter.CloseWithError(scanner.Err())
- }()
+func BlobsFromRevListObjects(in io.ReadCloser, out io.WriteCloser) error {
+ defer out.Close()
+ scanner := bufio.NewScanner(in)
for scanner.Scan() {
line := scanner.Text()
if len(line) == 0 {
@@ -75,12 +36,12 @@ func BlobsFromRevListObjects(revListReader *io.PipeReader, shasToCheckWriter *io
}
toWrite := []byte(fields[0] + "\n")
for len(toWrite) > 0 {
- n, err := shasToCheckWriter.Write(toWrite)
+ n, err := out.Write(toWrite)
if err != nil {
- _ = revListReader.CloseWithError(err)
- break
+ return err
}
toWrite = toWrite[n:]
}
}
+ return scanner.Err()
}
diff --git a/modules/git/ref.go b/modules/git/ref.go
index 56b2db858a..7b63d06b38 100644
--- a/modules/git/ref.go
+++ b/modules/git/ref.go
@@ -220,3 +220,14 @@ func (ref RefName) RefWebLinkPath() string {
}
return string(refType) + "/" + util.PathEscapeSegments(ref.ShortName())
}
+
+func ParseRefSuffix(ref string) (string, string) {
+ // Partially support https://git-scm.com/docs/gitrevisions
+ if idx := strings.Index(ref, "@{"); idx != -1 {
+ return ref[:idx], ref[idx:]
+ }
+ if idx := strings.Index(ref, "^"); idx != -1 {
+ return ref[:idx], ref[idx:]
+ }
+ return ref, ""
+}
diff --git a/modules/git/remote.go b/modules/git/remote.go
index 9f12142f91..ae56c5576a 100644
--- a/modules/git/remote.go
+++ b/modules/git/remote.go
@@ -22,7 +22,7 @@ func GetRemoteAddress(ctx context.Context, repoPath, remoteName string) (string,
cmd = gitcmd.NewCommand("config", "--get").AddDynamicArguments("remote." + remoteName + ".url")
}
- result, _, err := cmd.RunStdString(ctx, &gitcmd.RunOpts{Dir: repoPath})
+ result, _, err := cmd.WithDir(repoPath).RunStdString(ctx)
if err != nil {
return "", err
}
@@ -74,9 +74,9 @@ func (err *ErrInvalidCloneAddr) Unwrap() error {
func IsRemoteNotExistError(err error) bool {
// see: https://github.com/go-gitea/gitea/issues/32889#issuecomment-2571848216
// Should not add space in the end, sometimes git will add a `:`
- prefix1 := "exit status 128 - fatal: No such remote" // git < 2.30
- prefix2 := "exit status 2 - error: No such remote" // git >= 2.30
- return strings.HasPrefix(err.Error(), prefix1) || strings.HasPrefix(err.Error(), prefix2)
+ prefix1 := "fatal: No such remote" // git < 2.30, exit status 128
+ prefix2 := "error: No such remote" // git >= 2.30. exit status 2
+ return gitcmd.StderrHasPrefix(err, prefix1) || gitcmd.StderrHasPrefix(err, prefix2)
}
// ParseRemoteAddr checks if given remote address is valid,
diff --git a/modules/git/repo.go b/modules/git/repo.go
index 38cb4592a0..1e31eb1b80 100644
--- a/modules/git/repo.go
+++ b/modules/git/repo.go
@@ -8,42 +8,24 @@ import (
"bytes"
"context"
"fmt"
- "io"
"net/url"
"os"
"path"
- "path/filepath"
"strconv"
"strings"
"time"
"code.gitea.io/gitea/modules/git/gitcmd"
"code.gitea.io/gitea/modules/proxy"
- "code.gitea.io/gitea/modules/setting"
)
-// GPGSettings represents the default GPG settings for this repository
-type GPGSettings struct {
- Sign bool
- KeyID string
- Email string
- Name string
- PublicKeyContent string
- Format string
-}
-
const prettyLogFormat = `--pretty=format:%H`
-// GetAllCommitsCount returns count of all commits in repository
-func (repo *Repository) GetAllCommitsCount() (int64, error) {
- return AllCommitsCount(repo.Ctx, repo.Path, false)
-}
-
func (repo *Repository) ShowPrettyFormatLogToList(ctx context.Context, revisionRange string) ([]*Commit, error) {
// avoid: ambiguous argument 'refs/a...refs/b': unknown revision or path not in the working tree. Use '--': 'git [...] -- [...]'
logs, _, err := gitcmd.NewCommand("log").AddArguments(prettyLogFormat).
- AddDynamicArguments(revisionRange).AddArguments("--").
- RunStdBytes(ctx, &gitcmd.RunOpts{Dir: repo.Path})
+ AddDynamicArguments(revisionRange).AddArguments("--").WithDir(repo.Path).
+ RunStdBytes(ctx)
if err != nil {
return nil, err
}
@@ -71,7 +53,7 @@ func (repo *Repository) parsePrettyFormatLogToList(logs []byte) ([]*Commit, erro
// IsRepoURLAccessible checks if given repository URL is accessible.
func IsRepoURLAccessible(ctx context.Context, url string) bool {
- _, _, err := gitcmd.NewCommand("ls-remote", "-q", "-h").AddDynamicArguments(url, "HEAD").RunStdString(ctx, nil)
+ _, _, err := gitcmd.NewCommand("ls-remote", "-q", "-h").AddDynamicArguments(url, "HEAD").RunStdString(ctx)
return err == nil
}
@@ -94,27 +76,25 @@ func InitRepository(ctx context.Context, repoPath string, bare bool, objectForma
if bare {
cmd.AddArguments("--bare")
}
- _, _, err = cmd.RunStdString(ctx, &gitcmd.RunOpts{Dir: repoPath})
+ _, _, err = cmd.WithDir(repoPath).RunStdString(ctx)
return err
}
// IsEmpty Check if repository is empty.
func (repo *Repository) IsEmpty() (bool, error) {
- var errbuf, output strings.Builder
- if err := gitcmd.NewCommand().AddOptionFormat("--git-dir=%s", repo.Path).AddArguments("rev-list", "-n", "1", "--all").
- Run(repo.Ctx, &gitcmd.RunOpts{
- Dir: repo.Path,
- Stdout: &output,
- Stderr: &errbuf,
- }); err != nil {
- if (err.Error() == "exit status 1" && strings.TrimSpace(errbuf.String()) == "") || err.Error() == "exit status 129" {
+ stdout, _, err := gitcmd.NewCommand().
+ AddOptionFormat("--git-dir=%s", repo.Path).
+ AddArguments("rev-list", "-n", "1", "--all").
+ WithDir(repo.Path).
+ RunStdString(repo.Ctx)
+ if err != nil {
+ if (gitcmd.IsErrorExitCode(err, 1) && err.Stderr() == "") || gitcmd.IsErrorExitCode(err, 129) {
// git 2.11 exits with 129 if the repo is empty
return true, nil
}
- return true, fmt.Errorf("check empty: %w - %s", err, errbuf.String())
+ return true, fmt.Errorf("check empty: %w", err)
}
-
- return strings.TrimSpace(output.String()) == "", nil
+ return strings.TrimSpace(stdout) == "", nil
}
// CloneRepoOptions options when clone a repository
@@ -129,6 +109,8 @@ type CloneRepoOptions struct {
Depth int
Filter string
SkipTLSVerify bool
+ SingleBranch bool
+ Env []string
}
// Clone clones original repository to target path.
@@ -163,6 +145,9 @@ func Clone(ctx context.Context, from, to string, opts CloneRepoOptions) error {
if opts.Filter != "" {
cmd.AddArguments("--filter").AddDynamicArguments(opts.Filter)
}
+ if opts.SingleBranch {
+ cmd.AddArguments("--single-branch")
+ }
if len(opts.Branch) > 0 {
cmd.AddArguments("-b").AddDynamicArguments(opts.Branch)
}
@@ -173,37 +158,39 @@ func Clone(ctx context.Context, from, to string, opts CloneRepoOptions) error {
}
envs := os.Environ()
- u, err := url.Parse(from)
- if err == nil {
- envs = proxy.EnvWithProxy(u)
+ if opts.Env != nil {
+ envs = opts.Env
+ } else {
+ u, err := url.Parse(from)
+ if err == nil {
+ envs = proxy.EnvWithProxy(u)
+ }
}
- stderr := new(bytes.Buffer)
- if err = cmd.Run(ctx, &gitcmd.RunOpts{
- Timeout: opts.Timeout,
- Env: envs,
- Stdout: io.Discard,
- Stderr: stderr,
- }); err != nil {
- return gitcmd.ConcatenateError(err, stderr.String())
- }
- return nil
+ return cmd.
+ WithTimeout(opts.Timeout).
+ WithEnv(envs).
+ RunWithStderr(ctx)
}
// PushOptions options when push to remote
type PushOptions struct {
- Remote string
- Branch string
- Force bool
- Mirror bool
- Env []string
- Timeout time.Duration
+ Remote string
+ LocalRefName string
+ Branch string
+ Force bool
+ ForceWithLease string
+ Mirror bool
+ Env []string
+ Timeout time.Duration
}
// Push pushs local commits to given remote branch.
func Push(ctx context.Context, repoPath string, opts PushOptions) error {
cmd := gitcmd.NewCommand("push")
- if opts.Force {
+ if opts.ForceWithLease != "" {
+ cmd.AddOptionFormat("--force-with-lease=%s", opts.ForceWithLease)
+ } else if opts.Force {
cmd.AddArguments("-f")
}
if opts.Mirror {
@@ -211,11 +198,17 @@ func Push(ctx context.Context, repoPath string, opts PushOptions) error {
}
remoteBranchArgs := []string{opts.Remote}
if len(opts.Branch) > 0 {
- remoteBranchArgs = append(remoteBranchArgs, opts.Branch)
+ var refspec string
+ if opts.LocalRefName != "" {
+ refspec = fmt.Sprintf("%s:%s", opts.LocalRefName, opts.Branch)
+ } else {
+ refspec = opts.Branch
+ }
+ remoteBranchArgs = append(remoteBranchArgs, refspec)
}
cmd.AddDashesAndList(remoteBranchArgs...)
- stdout, stderr, err := cmd.RunStdString(ctx, &gitcmd.RunOpts{Env: opts.Env, Timeout: opts.Timeout, Dir: repoPath})
+ stdout, stderr, err := cmd.WithEnv(opts.Env).WithTimeout(opts.Timeout).WithDir(repoPath).RunStdString(ctx)
if err != nil {
if strings.Contains(stderr, "non-fast-forward") {
return &ErrPushOutOfDate{StdOut: stdout, StdErr: stderr, Err: err}
@@ -231,84 +224,3 @@ func Push(ctx context.Context, repoPath string, opts PushOptions) error {
return nil
}
-
-// GetLatestCommitTime returns time for latest commit in repository (across all branches)
-func GetLatestCommitTime(ctx context.Context, repoPath string) (time.Time, error) {
- cmd := gitcmd.NewCommand("for-each-ref", "--sort=-committerdate", BranchPrefix, "--count", "1", "--format=%(committerdate)")
- stdout, _, err := cmd.RunStdString(ctx, &gitcmd.RunOpts{Dir: repoPath})
- if err != nil {
- return time.Time{}, err
- }
- commitTime := strings.TrimSpace(stdout)
- return time.Parse("Mon Jan _2 15:04:05 2006 -0700", commitTime)
-}
-
-// DivergeObject represents commit count diverging commits
-type DivergeObject struct {
- Ahead int
- Behind int
-}
-
-// GetDivergingCommits returns the number of commits a targetBranch is ahead or behind a baseBranch
-func GetDivergingCommits(ctx context.Context, repoPath, baseBranch, targetBranch string) (do DivergeObject, err error) {
- cmd := gitcmd.NewCommand("rev-list", "--count", "--left-right").
- AddDynamicArguments(baseBranch + "..." + targetBranch).AddArguments("--")
- stdout, _, err := cmd.RunStdString(ctx, &gitcmd.RunOpts{Dir: repoPath})
- if err != nil {
- return do, err
- }
- left, right, found := strings.Cut(strings.Trim(stdout, "\n"), "\t")
- if !found {
- return do, fmt.Errorf("git rev-list output is missing a tab: %q", stdout)
- }
-
- do.Behind, err = strconv.Atoi(left)
- if err != nil {
- return do, err
- }
- do.Ahead, err = strconv.Atoi(right)
- if err != nil {
- return do, err
- }
- return do, nil
-}
-
-// CreateBundle create bundle content to the target path
-func (repo *Repository) CreateBundle(ctx context.Context, commit string, out io.Writer) error {
- tmp, cleanup, err := setting.AppDataTempDir("git-repo-content").MkdirTempRandom("gitea-bundle")
- if err != nil {
- return err
- }
- defer cleanup()
-
- env := append(os.Environ(), "GIT_OBJECT_DIRECTORY="+filepath.Join(repo.Path, "objects"))
- _, _, err = gitcmd.NewCommand("init", "--bare").RunStdString(ctx, &gitcmd.RunOpts{Dir: tmp, Env: env})
- if err != nil {
- return err
- }
-
- _, _, err = gitcmd.NewCommand("reset", "--soft").AddDynamicArguments(commit).RunStdString(ctx, &gitcmd.RunOpts{Dir: tmp, Env: env})
- if err != nil {
- return err
- }
-
- _, _, err = gitcmd.NewCommand("branch", "-m", "bundle").RunStdString(ctx, &gitcmd.RunOpts{Dir: tmp, Env: env})
- if err != nil {
- return err
- }
-
- tmpFile := filepath.Join(tmp, "bundle")
- _, _, err = gitcmd.NewCommand("bundle", "create").AddDynamicArguments(tmpFile, "bundle", "HEAD").RunStdString(ctx, &gitcmd.RunOpts{Dir: tmp, Env: env})
- if err != nil {
- return err
- }
-
- fi, err := os.Open(tmpFile)
- if err != nil {
- return err
- }
- defer fi.Close()
-
- _, err = io.Copy(out, fi)
- return err
-}
diff --git a/modules/git/repo_archive.go b/modules/git/repo_archive.go
deleted file mode 100644
index e12300345f..0000000000
--- a/modules/git/repo_archive.go
+++ /dev/null
@@ -1,75 +0,0 @@
-// Copyright 2015 The Gogs Authors. All rights reserved.
-// Copyright 2020 The Gitea Authors. All rights reserved.
-// SPDX-License-Identifier: MIT
-
-package git
-
-import (
- "context"
- "fmt"
- "io"
- "path/filepath"
- "strings"
-
- "code.gitea.io/gitea/modules/git/gitcmd"
-)
-
-// ArchiveType archive types
-type ArchiveType int
-
-const (
- ArchiveUnknown ArchiveType = iota
- ArchiveZip // 1
- ArchiveTarGz // 2
- ArchiveBundle // 3
-)
-
-// String converts an ArchiveType to string: the extension of the archive file without prefix dot
-func (a ArchiveType) String() string {
- switch a {
- case ArchiveZip:
- return "zip"
- case ArchiveTarGz:
- return "tar.gz"
- case ArchiveBundle:
- return "bundle"
- }
- return "unknown"
-}
-
-func SplitArchiveNameType(s string) (string, ArchiveType) {
- switch {
- case strings.HasSuffix(s, ".zip"):
- return strings.TrimSuffix(s, ".zip"), ArchiveZip
- case strings.HasSuffix(s, ".tar.gz"):
- return strings.TrimSuffix(s, ".tar.gz"), ArchiveTarGz
- case strings.HasSuffix(s, ".bundle"):
- return strings.TrimSuffix(s, ".bundle"), ArchiveBundle
- }
- return s, ArchiveUnknown
-}
-
-// CreateArchive create archive content to the target path
-func (repo *Repository) CreateArchive(ctx context.Context, format ArchiveType, target io.Writer, usePrefix bool, commitID string) error {
- if format.String() == "unknown" {
- return fmt.Errorf("unknown format: %v", format)
- }
-
- cmd := gitcmd.NewCommand("archive")
- if usePrefix {
- cmd.AddOptionFormat("--prefix=%s", filepath.Base(strings.TrimSuffix(repo.Path, ".git"))+"/")
- }
- cmd.AddOptionFormat("--format=%s", format.String())
- cmd.AddDynamicArguments(commitID)
-
- var stderr strings.Builder
- err := cmd.Run(ctx, &gitcmd.RunOpts{
- Dir: repo.Path,
- Stdout: target,
- Stderr: &stderr,
- })
- if err != nil {
- return gitcmd.ConcatenateError(err, stderr.String())
- }
- return nil
-}
diff --git a/modules/git/repo_base_gogit.go b/modules/git/repo_base_gogit.go
index e0d0b45372..986264fd93 100644
--- a/modules/git/repo_base_gogit.go
+++ b/modules/git/repo_base_gogit.go
@@ -32,7 +32,6 @@ type Repository struct {
gogitRepo *gogit.Repository
gogitStorage *filesystem.Storage
- gpgSettings *GPGSettings
Ctx context.Context
LastCommitCache *LastCommitCache
diff --git a/modules/git/repo_base_nogogit.go b/modules/git/repo_base_nogogit.go
index 4091e70846..775bbd4a09 100644
--- a/modules/git/repo_base_nogogit.go
+++ b/modules/git/repo_base_nogogit.go
@@ -7,9 +7,9 @@
package git
import (
- "bufio"
"context"
"path/filepath"
+ "sync"
"code.gitea.io/gitea/modules/log"
"code.gitea.io/gitea/modules/util"
@@ -23,13 +23,9 @@ type Repository struct {
tagCache *ObjectCache[*Tag]
- gpgSettings *GPGSettings
-
- batchInUse bool
- batch *Batch
-
- checkInUse bool
- check *Batch
+ mu sync.Mutex
+ catFileBatchCloser CatFileBatchCloser
+ catFileBatchInUse bool
Ctx context.Context
LastCommitCache *LastCommitCache
@@ -58,69 +54,47 @@ func OpenRepository(ctx context.Context, repoPath string) (*Repository, error) {
}, nil
}
-// CatFileBatch obtains a CatFileBatch for this repository
-func (repo *Repository) CatFileBatch(ctx context.Context) (WriteCloserError, *bufio.Reader, func(), error) {
- if repo.batch == nil {
- var err error
- repo.batch, err = NewBatch(ctx, repo.Path)
+// CatFileBatch obtains a "batch object provider" for this repository.
+// It reuses an existing one if available, otherwise creates a new one.
+func (repo *Repository) CatFileBatch(ctx context.Context) (_ CatFileBatch, closeFunc func(), err error) {
+ repo.mu.Lock()
+ defer repo.mu.Unlock()
+
+ if repo.catFileBatchCloser == nil {
+ repo.catFileBatchCloser, err = NewBatch(ctx, repo.Path)
if err != nil {
- return nil, nil, nil, err
+ repo.catFileBatchCloser = nil // otherwise it is "interface(nil)" and will cause wrong logic
+ return nil, nil, err
}
}
- if !repo.batchInUse {
- repo.batchInUse = true
- return repo.batch.Writer, repo.batch.Reader, func() {
- repo.batchInUse = false
+ if !repo.catFileBatchInUse {
+ repo.catFileBatchInUse = true
+ return CatFileBatch(repo.catFileBatchCloser), func() {
+ repo.mu.Lock()
+ defer repo.mu.Unlock()
+ repo.catFileBatchInUse = false
}, nil
}
log.Debug("Opening temporary cat file batch for: %s", repo.Path)
tempBatch, err := NewBatch(ctx, repo.Path)
if err != nil {
- return nil, nil, nil, err
+ return nil, nil, err
}
- return tempBatch.Writer, tempBatch.Reader, tempBatch.Close, nil
-}
-
-// CatFileBatchCheck obtains a CatFileBatchCheck for this repository
-func (repo *Repository) CatFileBatchCheck(ctx context.Context) (WriteCloserError, *bufio.Reader, func(), error) {
- if repo.check == nil {
- var err error
- repo.check, err = NewBatchCheck(ctx, repo.Path)
- if err != nil {
- return nil, nil, nil, err
- }
- }
-
- if !repo.checkInUse {
- repo.checkInUse = true
- return repo.check.Writer, repo.check.Reader, func() {
- repo.checkInUse = false
- }, nil
- }
-
- log.Debug("Opening temporary cat file batch-check for: %s", repo.Path)
- tempBatchCheck, err := NewBatchCheck(ctx, repo.Path)
- if err != nil {
- return nil, nil, nil, err
- }
- return tempBatchCheck.Writer, tempBatchCheck.Reader, tempBatchCheck.Close, nil
+ return tempBatch, tempBatch.Close, nil
}
func (repo *Repository) Close() error {
if repo == nil {
return nil
}
- if repo.batch != nil {
- repo.batch.Close()
- repo.batch = nil
- repo.batchInUse = false
- }
- if repo.check != nil {
- repo.check.Close()
- repo.check = nil
- repo.checkInUse = false
+ repo.mu.Lock()
+ defer repo.mu.Unlock()
+ if repo.catFileBatchCloser != nil {
+ repo.catFileBatchCloser.Close()
+ repo.catFileBatchCloser = nil
+ repo.catFileBatchInUse = false
}
repo.LastCommitCache = nil
repo.tagCache = nil
diff --git a/modules/git/repo_base_nogogit_test.go b/modules/git/repo_base_nogogit_test.go
new file mode 100644
index 0000000000..a12bbb73c2
--- /dev/null
+++ b/modules/git/repo_base_nogogit_test.go
@@ -0,0 +1,26 @@
+// Copyright 2026 The Gitea Authors. All rights reserved.
+// SPDX-License-Identifier: MIT
+
+//go:build !gogit
+
+package git
+
+import (
+ "path/filepath"
+ "testing"
+
+ "github.com/stretchr/testify/require"
+)
+
+func TestRepoCatFileBatch(t *testing.T) {
+ t.Run("MissingRepoAndClose", func(t *testing.T) {
+ repo, err := OpenRepository(t.Context(), filepath.Join(testReposDir, "repo1_bare"))
+ require.NoError(t, err)
+ repo.Path = "/no-such" // when the repo is missing (it usually occurs during testing because the fixtures are synced frequently)
+ _, _, err = repo.CatFileBatch(t.Context())
+ require.Error(t, err)
+ require.NoError(t, repo.Close()) // shouldn't panic
+ })
+
+ // TODO: test more methods and concurrency queries
+}
diff --git a/modules/git/repo_blame.go b/modules/git/repo_blame.go
deleted file mode 100644
index 04f74049aa..0000000000
--- a/modules/git/repo_blame.go
+++ /dev/null
@@ -1,25 +0,0 @@
-// Copyright 2017 The Gitea Authors. All rights reserved.
-// SPDX-License-Identifier: MIT
-
-package git
-
-import (
- "fmt"
-
- "code.gitea.io/gitea/modules/git/gitcmd"
-)
-
-// LineBlame returns the latest commit at the given line
-func (repo *Repository) LineBlame(revision, path, file string, line uint) (*Commit, error) {
- res, _, err := gitcmd.NewCommand("blame").
- AddOptionFormat("-L %d,%d", line, line).
- AddOptionValues("-p", revision).
- AddDashesAndList(file).RunStdString(repo.Ctx, &gitcmd.RunOpts{Dir: path})
- if err != nil {
- return nil, err
- }
- if len(res) < 40 {
- return nil, fmt.Errorf("invalid result of blame: %s", res)
- }
- return repo.GetCommit(res[:40])
-}
diff --git a/modules/git/repo_blob.go b/modules/git/repo_blob.go
index 698b6c7074..ff930a3432 100644
--- a/modules/git/repo_blob.go
+++ b/modules/git/repo_blob.go
@@ -9,5 +9,11 @@ func (repo *Repository) GetBlob(idStr string) (*Blob, error) {
if err != nil {
return nil, err
}
- return repo.getBlob(id)
+ if id.IsZero() {
+ return nil, ErrNotExist{id.String(), ""}
+ }
+ return &Blob{
+ ID: id,
+ repo: repo,
+ }, nil
}
diff --git a/modules/git/repo_blob_gogit.go b/modules/git/repo_blob_gogit.go
deleted file mode 100644
index 66c8c2775c..0000000000
--- a/modules/git/repo_blob_gogit.go
+++ /dev/null
@@ -1,22 +0,0 @@
-// Copyright 2018 The Gitea Authors. All rights reserved.
-// SPDX-License-Identifier: MIT
-
-//go:build gogit
-
-package git
-
-import (
- "github.com/go-git/go-git/v5/plumbing"
-)
-
-func (repo *Repository) getBlob(id ObjectID) (*Blob, error) {
- encodedObj, err := repo.gogitRepo.Storer.EncodedObject(plumbing.AnyObject, plumbing.Hash(id.RawValue()))
- if err != nil {
- return nil, ErrNotExist{id.String(), ""}
- }
-
- return &Blob{
- ID: id,
- gogitEncodedObj: encodedObj,
- }, nil
-}
diff --git a/modules/git/repo_blob_nogogit.go b/modules/git/repo_blob_nogogit.go
deleted file mode 100644
index 04b0fb00ff..0000000000
--- a/modules/git/repo_blob_nogogit.go
+++ /dev/null
@@ -1,16 +0,0 @@
-// Copyright 2020 The Gitea Authors. All rights reserved.
-// SPDX-License-Identifier: MIT
-
-//go:build !gogit
-
-package git
-
-func (repo *Repository) getBlob(id ObjectID) (*Blob, error) {
- if id.IsZero() {
- return nil, ErrNotExist{id.String(), ""}
- }
- return &Blob{
- ID: id,
- repo: repo,
- }, nil
-}
diff --git a/modules/git/repo_branch.go b/modules/git/repo_branch.go
index 5d4c05bb28..1eebc72158 100644
--- a/modules/git/repo_branch.go
+++ b/modules/git/repo_branch.go
@@ -5,84 +5,20 @@
package git
import (
- "context"
- "errors"
- "strings"
-
"code.gitea.io/gitea/modules/git/gitcmd"
)
// BranchPrefix base dir of the branch information file store on git
const BranchPrefix = "refs/heads/"
-// IsReferenceExist returns true if given reference exists in the repository.
-func IsReferenceExist(ctx context.Context, repoPath, name string) bool {
- _, _, err := gitcmd.NewCommand("show-ref", "--verify").AddDashesAndList(name).RunStdString(ctx, &gitcmd.RunOpts{Dir: repoPath})
- return err == nil
-}
-
-// IsBranchExist returns true if given branch exists in the repository.
-func IsBranchExist(ctx context.Context, repoPath, name string) bool {
- return IsReferenceExist(ctx, repoPath, BranchPrefix+name)
-}
-
-func GetDefaultBranch(ctx context.Context, repoPath string) (string, error) {
- stdout, _, err := gitcmd.NewCommand("symbolic-ref", "HEAD").RunStdString(ctx, &gitcmd.RunOpts{Dir: repoPath})
- if err != nil {
- return "", err
- }
- stdout = strings.TrimSpace(stdout)
- if !strings.HasPrefix(stdout, BranchPrefix) {
- return "", errors.New("the HEAD is not a branch: " + stdout)
- }
- return strings.TrimPrefix(stdout, BranchPrefix), nil
-}
-
-// DeleteBranchOptions Option(s) for delete branch
-type DeleteBranchOptions struct {
- Force bool
-}
-
-// DeleteBranch delete a branch by name on repository.
-func (repo *Repository) DeleteBranch(name string, opts DeleteBranchOptions) error {
- cmd := gitcmd.NewCommand("branch")
-
- if opts.Force {
- cmd.AddArguments("-D")
- } else {
- cmd.AddArguments("-d")
- }
-
- cmd.AddDashesAndList(name)
- _, _, err := cmd.RunStdString(repo.Ctx, &gitcmd.RunOpts{Dir: repo.Path})
-
- return err
-}
-
-// CreateBranch create a new branch
-func (repo *Repository) CreateBranch(branch, oldbranchOrCommit string) error {
- cmd := gitcmd.NewCommand("branch")
- cmd.AddDashesAndList(branch, oldbranchOrCommit)
-
- _, _, err := cmd.RunStdString(repo.Ctx, &gitcmd.RunOpts{Dir: repo.Path})
-
- return err
-}
-
// AddRemote adds a new remote to repository.
func (repo *Repository) AddRemote(name, url string, fetch bool) error {
cmd := gitcmd.NewCommand("remote", "add")
if fetch {
cmd.AddArguments("-f")
}
- cmd.AddDynamicArguments(name, url)
-
- _, _, err := cmd.RunStdString(repo.Ctx, &gitcmd.RunOpts{Dir: repo.Path})
- return err
-}
-
-// RenameBranch rename a branch
-func (repo *Repository) RenameBranch(from, to string) error {
- _, _, err := gitcmd.NewCommand("branch", "-m").AddDynamicArguments(from, to).RunStdString(repo.Ctx, &gitcmd.RunOpts{Dir: repo.Path})
+ _, _, err := cmd.AddDynamicArguments(name, url).
+ WithDir(repo.Path).
+ RunStdString(repo.Ctx)
return err
}
diff --git a/modules/git/repo_branch_nogogit.go b/modules/git/repo_branch_nogogit.go
index 255c2974e9..f925aab3e4 100644
--- a/modules/git/repo_branch_nogogit.go
+++ b/modules/git/repo_branch_nogogit.go
@@ -8,7 +8,6 @@ package git
import (
"bufio"
- "bytes"
"context"
"io"
"strings"
@@ -18,24 +17,24 @@ import (
)
// IsObjectExist returns true if the given object exists in the repository.
+// FIXME: this function doesn't seem right, it is only used by GarbageCollectLFSMetaObjectsForRepo
func (repo *Repository) IsObjectExist(name string) bool {
if name == "" {
return false
}
- wr, rd, cancel, err := repo.CatFileBatchCheck(repo.Ctx)
+ batch, cancel, err := repo.CatFileBatch(repo.Ctx)
if err != nil {
- log.Debug("Error writing to CatFileBatchCheck %v", err)
+ log.Debug("Error opening CatFileBatch %v", err)
return false
}
defer cancel()
- _, err = wr.Write([]byte(name + "\n"))
+ info, err := batch.QueryInfo(name)
if err != nil {
- log.Debug("Error writing to CatFileBatchCheck %v", err)
+ log.Debug("Error checking object info %v", err)
return false
}
- sha, _, _, err := ReadBatchLine(rd)
- return err == nil && bytes.HasPrefix(sha, []byte(strings.TrimSpace(name)))
+ return strings.HasPrefix(info.ID, name) // FIXME: this logic doesn't seem right, why "HasPrefix"
}
// IsReferenceExist returns true if given reference exists in the repository.
@@ -44,18 +43,13 @@ func (repo *Repository) IsReferenceExist(name string) bool {
return false
}
- wr, rd, cancel, err := repo.CatFileBatchCheck(repo.Ctx)
+ batch, cancel, err := repo.CatFileBatch(repo.Ctx)
if err != nil {
- log.Debug("Error writing to CatFileBatchCheck %v", err)
+ log.Error("Error opening CatFileBatch %v", err)
return false
}
defer cancel()
- _, err = wr.Write([]byte(name + "\n"))
- if err != nil {
- log.Debug("Error writing to CatFileBatchCheck %v", err)
- return false
- }
- _, _, _, err = ReadBatchLine(rd)
+ _, err = batch.QueryInfo(name)
return err == nil
}
@@ -100,94 +94,81 @@ func callShowRef(ctx context.Context, repoPath, trimPrefix string, extraArgs git
}
func WalkShowRef(ctx context.Context, repoPath string, extraArgs gitcmd.TrustedCmdArgs, skip, limit int, walkfn func(sha1, refname string) error) (countAll int, err error) {
- stdoutReader, stdoutWriter := io.Pipe()
- defer func() {
- _ = stdoutReader.Close()
- _ = stdoutWriter.Close()
- }()
-
- go func() {
- stderrBuilder := &strings.Builder{}
- args := gitcmd.TrustedCmdArgs{"for-each-ref", "--format=%(objectname) %(refname)"}
- args = append(args, extraArgs...)
- err := gitcmd.NewCommand(args...).Run(ctx, &gitcmd.RunOpts{
- Dir: repoPath,
- Stdout: stdoutWriter,
- Stderr: stderrBuilder,
- })
- if err != nil {
- if stderrBuilder.Len() == 0 {
- _ = stdoutWriter.Close()
- return
- }
- _ = stdoutWriter.CloseWithError(gitcmd.ConcatenateError(err, stderrBuilder.String()))
- } else {
- _ = stdoutWriter.Close()
- }
- }()
-
i := 0
- bufReader := bufio.NewReader(stdoutReader)
- for i < skip {
- _, isPrefix, err := bufReader.ReadLine()
- if err == io.EOF {
- return i, nil
- }
- if err != nil {
- return 0, err
- }
- if !isPrefix {
- i++
- }
- }
- for limit == 0 || i < skip+limit {
- // The output of show-ref is simply a list:
- // SP [ LF
- sha, err := bufReader.ReadString(' ')
- if err == io.EOF {
- return i, nil
- }
- if err != nil {
- return 0, err
- }
-
- branchName, err := bufReader.ReadString('\n')
- if err == io.EOF {
- // This shouldn't happen... but we'll tolerate it for the sake of peace
- return i, nil
- }
- if err != nil {
- return i, err
- }
-
- if len(branchName) > 0 {
- branchName = branchName[:len(branchName)-1]
- }
-
- if len(sha) > 0 {
- sha = sha[:len(sha)-1]
- }
-
- err = walkfn(sha, branchName)
- if err != nil {
- return i, err
- }
- i++
- }
- // count all refs
- for limit != 0 {
- _, isPrefix, err := bufReader.ReadLine()
- if err == io.EOF {
- return i, nil
- }
- if err != nil {
- return 0, err
- }
- if !isPrefix {
- i++
- }
+ args := gitcmd.TrustedCmdArgs{"for-each-ref", "--format=%(objectname) %(refname)"}
+ args = append(args, extraArgs...)
+ cmd := gitcmd.NewCommand(args...)
+ stdoutReader, stdoutReaderClose := cmd.MakeStdoutPipe()
+ defer stdoutReaderClose()
+ cmd.WithDir(repoPath).
+ WithPipelineFunc(func(gitcmd.Context) error {
+ bufReader := bufio.NewReader(stdoutReader)
+ for i < skip {
+ _, isPrefix, err := bufReader.ReadLine()
+ if err == io.EOF {
+ return nil
+ }
+ if err != nil {
+ return err
+ }
+ if !isPrefix {
+ i++
+ }
+ }
+ for limit == 0 || i < skip+limit {
+ // The output of show-ref is simply a list:
+ // ] SP [ LF
+ sha, err := bufReader.ReadString(' ')
+ if err == io.EOF {
+ return nil
+ }
+ if err != nil {
+ return err
+ }
+
+ branchName, err := bufReader.ReadString('\n')
+ if err == io.EOF {
+ // This shouldn't happen... but we'll tolerate it for the sake of peace
+ return nil
+ }
+ if err != nil {
+ return err
+ }
+
+ if len(branchName) > 0 {
+ branchName = branchName[:len(branchName)-1]
+ }
+
+ if len(sha) > 0 {
+ sha = sha[:len(sha)-1]
+ }
+
+ err = walkfn(sha, branchName)
+ if err != nil {
+ return err
+ }
+ i++
+ }
+ // count all refs
+ for limit != 0 {
+ _, isPrefix, err := bufReader.ReadLine()
+ if err == io.EOF {
+ return nil
+ }
+ if err != nil {
+ return err
+ }
+ if !isPrefix {
+ i++
+ }
+ }
+ return nil
+ })
+ err = cmd.RunWithStderr(ctx)
+ if errPipeline, ok := gitcmd.UnwrapPipelineError(err); ok {
+ return i, errPipeline // keep the old behavior: return pipeline error directly
}
- return i, nil
+ return i, err
}
// GetRefsBySha returns all references filtered with prefix that belong to a sha commit hash
diff --git a/modules/git/repo_commit.go b/modules/git/repo_commit.go
index 6e5911f1dd..8ba3f83386 100644
--- a/modules/git/repo_commit.go
+++ b/modules/git/repo_commit.go
@@ -11,7 +11,6 @@ import (
"strconv"
"strings"
- "code.gitea.io/gitea/modules/cache"
"code.gitea.io/gitea/modules/git/gitcmd"
"code.gitea.io/gitea/modules/setting"
)
@@ -60,7 +59,11 @@ func (repo *Repository) getCommitByPathWithID(id ObjectID, relpath string) (*Com
relpath = `\` + relpath
}
- stdout, _, runErr := gitcmd.NewCommand("log", "-1", prettyLogFormat).AddDynamicArguments(id.String()).AddDashesAndList(relpath).RunStdString(repo.Ctx, &gitcmd.RunOpts{Dir: repo.Path})
+ stdout, _, runErr := gitcmd.NewCommand("log", "-1", prettyLogFormat).
+ AddDynamicArguments(id.String()).
+ AddDashesAndList(relpath).
+ WithDir(repo.Path).
+ RunStdString(repo.Ctx)
if runErr != nil {
return nil, runErr
}
@@ -75,7 +78,10 @@ func (repo *Repository) getCommitByPathWithID(id ObjectID, relpath string) (*Com
// GetCommitByPath returns the last commit of relative path.
func (repo *Repository) GetCommitByPath(relpath string) (*Commit, error) {
- stdout, _, runErr := gitcmd.NewCommand("log", "-1", prettyLogFormat).AddDashesAndList(relpath).RunStdBytes(repo.Ctx, &gitcmd.RunOpts{Dir: repo.Path})
+ stdout, _, runErr := gitcmd.NewCommand("log", "-1", prettyLogFormat).
+ AddDashesAndList(relpath).
+ WithDir(repo.Path).
+ RunStdBytes(repo.Ctx)
if runErr != nil {
return nil, runErr
}
@@ -108,7 +114,7 @@ func (repo *Repository) commitsByRangeWithTime(id ObjectID, page, pageSize int,
cmd.AddOptionFormat("--until=%s", until)
}
- stdout, _, err := cmd.RunStdBytes(repo.Ctx, &gitcmd.RunOpts{Dir: repo.Path})
+ stdout, _, err := cmd.WithDir(repo.Path).RunStdBytes(repo.Ctx)
if err != nil {
return nil, err
}
@@ -162,7 +168,7 @@ func (repo *Repository) searchCommits(id ObjectID, opts SearchCommitsOptions) ([
// search for commits matching given constraints and keywords in commit msg
addCommonSearchArgs(cmd)
- stdout, _, err := cmd.RunStdBytes(repo.Ctx, &gitcmd.RunOpts{Dir: repo.Path})
+ stdout, _, err := cmd.WithDir(repo.Path).RunStdBytes(repo.Ctx)
if err != nil {
return nil, err
}
@@ -183,7 +189,7 @@ func (repo *Repository) searchCommits(id ObjectID, opts SearchCommitsOptions) ([
hashCmd.AddDynamicArguments(v)
// search with given constraints for commit matching sha hash of v
- hashMatching, _, err := hashCmd.RunStdBytes(repo.Ctx, &gitcmd.RunOpts{Dir: repo.Path})
+ hashMatching, _, err := hashCmd.WithDir(repo.Path).RunStdBytes(repo.Ctx)
if err != nil || bytes.Contains(stdout, hashMatching) {
continue
}
@@ -198,23 +204,17 @@ func (repo *Repository) searchCommits(id ObjectID, opts SearchCommitsOptions) ([
// FileChangedBetweenCommits Returns true if the file changed between commit IDs id1 and id2
// You must ensure that id1 and id2 are valid commit ids.
func (repo *Repository) FileChangedBetweenCommits(filename, id1, id2 string) (bool, error) {
- stdout, _, err := gitcmd.NewCommand("diff", "--name-only", "-z").AddDynamicArguments(id1, id2).AddDashesAndList(filename).RunStdBytes(repo.Ctx, &gitcmd.RunOpts{Dir: repo.Path})
+ stdout, _, err := gitcmd.NewCommand("diff", "--name-only", "-z").
+ AddDynamicArguments(id1, id2).
+ AddDashesAndList(filename).
+ WithDir(repo.Path).
+ RunStdBytes(repo.Ctx)
if err != nil {
return false, err
}
return len(strings.TrimSpace(string(stdout))) > 0, nil
}
-// FileCommitsCount return the number of files at a revision
-func (repo *Repository) FileCommitsCount(revision, file string) (int64, error) {
- return CommitsCount(repo.Ctx,
- CommitsCountOptions{
- RepoPath: repo.Path,
- Revision: []string{revision},
- RelPath: []string{file},
- })
-}
-
type CommitsByFileAndRangeOptions struct {
Revision string
File string
@@ -226,76 +226,70 @@ type CommitsByFileAndRangeOptions struct {
// CommitsByFileAndRange return the commits according revision file and the page
func (repo *Repository) CommitsByFileAndRange(opts CommitsByFileAndRangeOptions) ([]*Commit, error) {
- stdoutReader, stdoutWriter := io.Pipe()
- defer func() {
- _ = stdoutReader.Close()
- _ = stdoutWriter.Close()
- }()
- go func() {
- stderr := strings.Builder{}
- gitCmd := gitcmd.NewCommand("rev-list").
- AddOptionFormat("--max-count=%d", setting.Git.CommitsRangeSize).
- AddOptionFormat("--skip=%d", (opts.Page-1)*setting.Git.CommitsRangeSize)
- gitCmd.AddDynamicArguments(opts.Revision)
-
- if opts.Not != "" {
- gitCmd.AddOptionValues("--not", opts.Not)
- }
- if opts.Since != "" {
- gitCmd.AddOptionFormat("--since=%s", opts.Since)
- }
- if opts.Until != "" {
- gitCmd.AddOptionFormat("--until=%s", opts.Until)
- }
-
- gitCmd.AddDashesAndList(opts.File)
- err := gitCmd.Run(repo.Ctx, &gitcmd.RunOpts{
- Dir: repo.Path,
- Stdout: stdoutWriter,
- Stderr: &stderr,
- })
- if err != nil {
- _ = stdoutWriter.CloseWithError(gitcmd.ConcatenateError(err, (&stderr).String()))
- } else {
- _ = stdoutWriter.Close()
- }
- }()
+ gitCmd := gitcmd.NewCommand("rev-list").
+ AddOptionFormat("--max-count=%d", setting.Git.CommitsRangeSize).
+ AddOptionFormat("--skip=%d", (opts.Page-1)*setting.Git.CommitsRangeSize)
+ gitCmd.AddDynamicArguments(opts.Revision)
- objectFormat, err := repo.GetObjectFormat()
- if err != nil {
- return nil, err
+ if opts.Not != "" {
+ gitCmd.AddOptionValues("--not", opts.Not)
+ }
+ if opts.Since != "" {
+ gitCmd.AddOptionFormat("--since=%s", opts.Since)
}
+ if opts.Until != "" {
+ gitCmd.AddOptionFormat("--until=%s", opts.Until)
+ }
+ gitCmd.AddDashesAndList(opts.File)
- length := objectFormat.FullLength()
- commits := []*Commit{}
- shaline := make([]byte, length+1)
- for {
- n, err := io.ReadFull(stdoutReader, shaline)
- if err != nil || n < length {
- if err == io.EOF {
- err = nil
+ var commits []*Commit
+ stdoutReader, stdoutReaderClose := gitCmd.MakeStdoutPipe()
+ defer stdoutReaderClose()
+ err := gitCmd.WithDir(repo.Path).
+ WithPipelineFunc(func(context gitcmd.Context) error {
+ objectFormat, err := repo.GetObjectFormat()
+ if err != nil {
+ return err
}
- return commits, err
- }
- objectID, err := NewIDFromString(string(shaline[0:length]))
- if err != nil {
- return nil, err
- }
- commit, err := repo.getCommit(objectID)
- if err != nil {
- return nil, err
- }
- commits = append(commits, commit)
- }
+
+ length := objectFormat.FullLength()
+ shaline := make([]byte, length+1)
+ for {
+ n, err := io.ReadFull(stdoutReader, shaline)
+ if err != nil || n < length {
+ if err == io.EOF {
+ err = nil
+ }
+ return err
+ }
+ objectID, err := NewIDFromString(string(shaline[0:length]))
+ if err != nil {
+ return err
+ }
+ commit, err := repo.getCommit(objectID)
+ if err != nil {
+ return err
+ }
+ commits = append(commits, commit)
+ }
+ }).
+ RunWithStderr(repo.Ctx)
+ return commits, err
}
// FilesCountBetween return the number of files changed between two commits
func (repo *Repository) FilesCountBetween(startCommitID, endCommitID string) (int, error) {
- stdout, _, err := gitcmd.NewCommand("diff", "--name-only").AddDynamicArguments(startCommitID+"..."+endCommitID).RunStdString(repo.Ctx, &gitcmd.RunOpts{Dir: repo.Path})
+ stdout, _, err := gitcmd.NewCommand("diff", "--name-only").
+ AddDynamicArguments(startCommitID + "..." + endCommitID).
+ WithDir(repo.Path).
+ RunStdString(repo.Ctx)
if err != nil && strings.Contains(err.Error(), "no merge base") {
// git >= 2.28 now returns an error if startCommitID and endCommitID have become unrelated.
// previously it would return the results of git diff --name-only startCommitID endCommitID so let's try that...
- stdout, _, err = gitcmd.NewCommand("diff", "--name-only").AddDynamicArguments(startCommitID, endCommitID).RunStdString(repo.Ctx, &gitcmd.RunOpts{Dir: repo.Path})
+ stdout, _, err = gitcmd.NewCommand("diff", "--name-only").
+ AddDynamicArguments(startCommitID, endCommitID).
+ WithDir(repo.Path).
+ RunStdString(repo.Ctx)
}
if err != nil {
return 0, err
@@ -309,13 +303,22 @@ func (repo *Repository) CommitsBetween(last, before *Commit) ([]*Commit, error)
var stdout []byte
var err error
if before == nil {
- stdout, _, err = gitcmd.NewCommand("rev-list").AddDynamicArguments(last.ID.String()).RunStdBytes(repo.Ctx, &gitcmd.RunOpts{Dir: repo.Path})
+ stdout, _, err = gitcmd.NewCommand("rev-list").
+ AddDynamicArguments(last.ID.String()).
+ WithDir(repo.Path).
+ RunStdBytes(repo.Ctx)
} else {
- stdout, _, err = gitcmd.NewCommand("rev-list").AddDynamicArguments(before.ID.String()+".."+last.ID.String()).RunStdBytes(repo.Ctx, &gitcmd.RunOpts{Dir: repo.Path})
+ stdout, _, err = gitcmd.NewCommand("rev-list").
+ AddDynamicArguments(before.ID.String() + ".." + last.ID.String()).
+ WithDir(repo.Path).
+ RunStdBytes(repo.Ctx)
if err != nil && strings.Contains(err.Error(), "no merge base") {
// future versions of git >= 2.28 are likely to return an error if before and last have become unrelated.
// previously it would return the results of git rev-list before last so let's try that...
- stdout, _, err = gitcmd.NewCommand("rev-list").AddDynamicArguments(before.ID.String(), last.ID.String()).RunStdBytes(repo.Ctx, &gitcmd.RunOpts{Dir: repo.Path})
+ stdout, _, err = gitcmd.NewCommand("rev-list").
+ AddDynamicArguments(before.ID.String(), last.ID.String()).
+ WithDir(repo.Path).
+ RunStdBytes(repo.Ctx)
}
}
if err != nil {
@@ -332,40 +335,25 @@ func (repo *Repository) CommitsBetweenLimit(last, before *Commit, limit, skip in
stdout, _, err = gitcmd.NewCommand("rev-list").
AddOptionValues("--max-count", strconv.Itoa(limit)).
AddOptionValues("--skip", strconv.Itoa(skip)).
- AddDynamicArguments(last.ID.String()).RunStdBytes(repo.Ctx, &gitcmd.RunOpts{Dir: repo.Path})
+ AddDynamicArguments(last.ID.String()).
+ WithDir(repo.Path).
+ RunStdBytes(repo.Ctx)
} else {
stdout, _, err = gitcmd.NewCommand("rev-list").
AddOptionValues("--max-count", strconv.Itoa(limit)).
AddOptionValues("--skip", strconv.Itoa(skip)).
- AddDynamicArguments(before.ID.String()+".."+last.ID.String()).RunStdBytes(repo.Ctx, &gitcmd.RunOpts{Dir: repo.Path})
+ AddDynamicArguments(before.ID.String() + ".." + last.ID.String()).
+ WithDir(repo.Path).
+ RunStdBytes(repo.Ctx)
if err != nil && strings.Contains(err.Error(), "no merge base") {
// future versions of git >= 2.28 are likely to return an error if before and last have become unrelated.
// previously it would return the results of git rev-list --max-count n before last so let's try that...
stdout, _, err = gitcmd.NewCommand("rev-list").
AddOptionValues("--max-count", strconv.Itoa(limit)).
AddOptionValues("--skip", strconv.Itoa(skip)).
- AddDynamicArguments(before.ID.String(), last.ID.String()).RunStdBytes(repo.Ctx, &gitcmd.RunOpts{Dir: repo.Path})
- }
- }
- if err != nil {
- return nil, err
- }
- return repo.parsePrettyFormatLogToList(bytes.TrimSpace(stdout))
-}
-
-// CommitsBetweenNotBase returns a list that contains commits between [before, last), excluding commits in baseBranch.
-// If before is detached (removed by reset + push) it is not included.
-func (repo *Repository) CommitsBetweenNotBase(last, before *Commit, baseBranch string) ([]*Commit, error) {
- var stdout []byte
- var err error
- if before == nil {
- stdout, _, err = gitcmd.NewCommand("rev-list").AddDynamicArguments(last.ID.String()).AddOptionValues("--not", baseBranch).RunStdBytes(repo.Ctx, &gitcmd.RunOpts{Dir: repo.Path})
- } else {
- stdout, _, err = gitcmd.NewCommand("rev-list").AddDynamicArguments(before.ID.String()+".."+last.ID.String()).AddOptionValues("--not", baseBranch).RunStdBytes(repo.Ctx, &gitcmd.RunOpts{Dir: repo.Path})
- if err != nil && strings.Contains(err.Error(), "no merge base") {
- // future versions of git >= 2.28 are likely to return an error if before and last have become unrelated.
- // previously it would return the results of git rev-list before last so let's try that...
- stdout, _, err = gitcmd.NewCommand("rev-list").AddDynamicArguments(before.ID.String(), last.ID.String()).AddOptionValues("--not", baseBranch).RunStdBytes(repo.Ctx, &gitcmd.RunOpts{Dir: repo.Path})
+ AddDynamicArguments(before.ID.String(), last.ID.String()).
+ WithDir(repo.Path).
+ RunStdBytes(repo.Ctx)
}
}
if err != nil {
@@ -390,25 +378,6 @@ func (repo *Repository) CommitsBetweenIDs(last, before string) ([]*Commit, error
return repo.CommitsBetween(lastCommit, beforeCommit)
}
-// CommitsCountBetween return numbers of commits between two commits
-func (repo *Repository) CommitsCountBetween(start, end string) (int64, error) {
- count, err := CommitsCount(repo.Ctx, CommitsCountOptions{
- RepoPath: repo.Path,
- Revision: []string{start + ".." + end},
- })
-
- if err != nil && strings.Contains(err.Error(), "no merge base") {
- // future versions of git >= 2.28 are likely to return an error if before and last have become unrelated.
- // previously it would return the results of git rev-list before last so let's try that...
- return CommitsCount(repo.Ctx, CommitsCountOptions{
- RepoPath: repo.Path,
- Revision: []string{start, end},
- })
- }
-
- return count, err
-}
-
// commitsBefore the limit is depth, not total number of returned commits.
func (repo *Repository) commitsBefore(id ObjectID, limit int) ([]*Commit, error) {
cmd := gitcmd.NewCommand("log", prettyLogFormat)
@@ -417,7 +386,7 @@ func (repo *Repository) commitsBefore(id ObjectID, limit int) ([]*Commit, error)
}
cmd.AddDynamicArguments(id.String())
- stdout, _, runErr := cmd.RunStdBytes(repo.Ctx, &gitcmd.RunOpts{Dir: repo.Path})
+ stdout, _, runErr := cmd.WithDir(repo.Path).RunStdBytes(repo.Ctx)
if runErr != nil {
return nil, runErr
}
@@ -457,10 +426,9 @@ func (repo *Repository) getBranches(env []string, commitID string, limit int) ([
stdout, _, err := gitcmd.NewCommand("for-each-ref", "--format=%(refname:strip=2)").
AddOptionFormat("--count=%d", limit).
AddOptionValues("--contains", commitID, BranchPrefix).
- RunStdString(repo.Ctx, &gitcmd.RunOpts{
- Dir: repo.Path,
- Env: env,
- })
+ WithDir(repo.Path).
+ WithEnv(env).
+ RunStdString(repo.Ctx)
if err != nil {
return nil, err
}
@@ -469,10 +437,11 @@ func (repo *Repository) getBranches(env []string, commitID string, limit int) ([
return branches, nil
}
- stdout, _, err := gitcmd.NewCommand("branch").AddOptionValues("--contains", commitID).RunStdString(repo.Ctx, &gitcmd.RunOpts{
- Dir: repo.Path,
- Env: env,
- })
+ stdout, _, err := gitcmd.NewCommand("branch").
+ AddOptionValues("--contains", commitID).
+ WithDir(repo.Path).
+ WithEnv(env).
+ RunStdString(repo.Ctx)
if err != nil {
return nil, err
}
@@ -511,39 +480,24 @@ func (repo *Repository) GetCommitsFromIDs(commitIDs []string) []*Commit {
// IsCommitInBranch check if the commit is on the branch
func (repo *Repository) IsCommitInBranch(commitID, branch string) (r bool, err error) {
- stdout, _, err := gitcmd.NewCommand("branch", "--contains").AddDynamicArguments(commitID, branch).RunStdString(repo.Ctx, &gitcmd.RunOpts{Dir: repo.Path})
+ stdout, _, err := gitcmd.NewCommand("branch", "--contains").
+ AddDynamicArguments(commitID, branch).
+ WithDir(repo.Path).
+ RunStdString(repo.Ctx)
if err != nil {
return false, err
}
return len(stdout) > 0, err
}
-func (repo *Repository) AddLastCommitCache(cacheKey, fullName, sha string) error {
- if repo.LastCommitCache == nil {
- commitsCount, err := cache.GetInt64(cacheKey, func() (int64, error) {
- commit, err := repo.GetCommit(sha)
- if err != nil {
- return 0, err
- }
- return commit.CommitsCount()
- })
- if err != nil {
- return err
- }
- repo.LastCommitCache = NewLastCommitCache(commitsCount, fullName, repo, cache.GetCache())
- }
- return nil
-}
-
// GetCommitBranchStart returns the commit where the branch diverged
func (repo *Repository) GetCommitBranchStart(env []string, branch, endCommitID string) (string, error) {
cmd := gitcmd.NewCommand("log", prettyLogFormat)
cmd.AddDynamicArguments(endCommitID)
- stdout, _, runErr := cmd.RunStdBytes(repo.Ctx, &gitcmd.RunOpts{
- Dir: repo.Path,
- Env: env,
- })
+ stdout, _, runErr := cmd.WithDir(repo.Path).
+ WithEnv(env).
+ RunStdBytes(repo.Ctx)
if runErr != nil {
return "", runErr
}
diff --git a/modules/git/repo_commit_gogit.go b/modules/git/repo_commit_gogit.go
index fc653714ad..550d153722 100644
--- a/modules/git/repo_commit_gogit.go
+++ b/modules/git/repo_commit_gogit.go
@@ -51,7 +51,10 @@ func (repo *Repository) ConvertToGitID(commitID string) (ObjectID, error) {
}
}
- actualCommitID, _, err := gitcmd.NewCommand("rev-parse", "--verify").AddDynamicArguments(commitID).RunStdString(repo.Ctx, &gitcmd.RunOpts{Dir: repo.Path})
+ actualCommitID, _, err := gitcmd.NewCommand("rev-parse", "--verify").
+ AddDynamicArguments(commitID).
+ WithDir(repo.Path).
+ RunStdString(repo.Ctx)
actualCommitID = strings.TrimSpace(actualCommitID)
if err != nil {
if strings.Contains(err.Error(), "unknown revision or path") ||
@@ -64,16 +67,6 @@ func (repo *Repository) ConvertToGitID(commitID string) (ObjectID, error) {
return NewIDFromString(actualCommitID)
}
-// IsCommitExist returns true if given commit exists in current repository.
-func (repo *Repository) IsCommitExist(name string) bool {
- hash, err := repo.ConvertToGitID(name)
- if err != nil {
- return false
- }
- _, err = repo.gogitRepo.CommitObject(plumbing.Hash(hash.RawValue()))
- return err == nil
-}
-
func (repo *Repository) getCommit(id ObjectID) (*Commit, error) {
var tagObject *object.Tag
@@ -104,7 +97,7 @@ func (repo *Repository) getCommit(id ObjectID) (*Commit, error) {
}
commit.Tree.ID = ParseGogitHash(tree.Hash)
- commit.Tree.gogitTree = tree
+ commit.Tree.resolvedGogitTreeObject = tree
return commit, nil
}
diff --git a/modules/git/repo_commit_nogogit.go b/modules/git/repo_commit_nogogit.go
index d2c66a541b..2ddb527502 100644
--- a/modules/git/repo_commit_nogogit.go
+++ b/modules/git/repo_commit_nogogit.go
@@ -6,7 +6,6 @@
package git
import (
- "bufio"
"errors"
"io"
"strings"
@@ -17,7 +16,10 @@ import (
// ResolveReference resolves a name to a reference
func (repo *Repository) ResolveReference(name string) (string, error) {
- stdout, _, err := gitcmd.NewCommand("show-ref", "--hash").AddDynamicArguments(name).RunStdString(repo.Ctx, &gitcmd.RunOpts{Dir: repo.Path})
+ stdout, _, err := gitcmd.NewCommand("show-ref", "--hash").
+ AddDynamicArguments(name).
+ WithDir(repo.Path).
+ RunStdString(repo.Ctx)
if err != nil {
if strings.Contains(err.Error(), "not a valid ref") {
return "", ErrNotExist{name, ""}
@@ -34,47 +36,31 @@ func (repo *Repository) ResolveReference(name string) (string, error) {
// GetRefCommitID returns the last commit ID string of given reference (branch or tag).
func (repo *Repository) GetRefCommitID(name string) (string, error) {
- wr, rd, cancel, err := repo.CatFileBatchCheck(repo.Ctx)
+ batch, cancel, err := repo.CatFileBatch(repo.Ctx)
if err != nil {
return "", err
}
defer cancel()
- _, err = wr.Write([]byte(name + "\n"))
- if err != nil {
- return "", err
- }
- shaBs, _, _, err := ReadBatchLine(rd)
+ info, err := batch.QueryInfo(name)
if IsErrNotExist(err) {
return "", ErrNotExist{name, ""}
+ } else if err != nil {
+ return "", err
}
-
- return string(shaBs), nil
-}
-
-// IsCommitExist returns true if given commit exists in current repository.
-func (repo *Repository) IsCommitExist(name string) bool {
- if err := ensureValidGitRepository(repo.Ctx, repo.Path); err != nil {
- log.Error("IsCommitExist: %v", err)
- return false
- }
- _, _, err := gitcmd.NewCommand("cat-file", "-e").AddDynamicArguments(name).RunStdString(repo.Ctx, &gitcmd.RunOpts{Dir: repo.Path})
- return err == nil
+ return info.ID, nil
}
func (repo *Repository) getCommit(id ObjectID) (*Commit, error) {
- wr, rd, cancel, err := repo.CatFileBatch(repo.Ctx)
+ batch, cancel, err := repo.CatFileBatch(repo.Ctx)
if err != nil {
return nil, err
}
defer cancel()
-
- _, _ = wr.Write([]byte(id.String() + "\n"))
-
- return repo.getCommitFromBatchReader(wr, rd, id)
+ return repo.getCommitWithBatch(batch, id)
}
-func (repo *Repository) getCommitFromBatchReader(wr WriteCloserError, rd *bufio.Reader, id ObjectID) (*Commit, error) {
- _, typ, size, err := ReadBatchLine(rd)
+func (repo *Repository) getCommitWithBatch(batch CatFileBatch, id ObjectID) (*Commit, error) {
+ info, rd, err := batch.QueryContent(id.String())
if err != nil {
if errors.Is(err, io.EOF) || IsErrNotExist(err) {
return nil, ErrNotExist{ID: id.String()}
@@ -82,13 +68,13 @@ func (repo *Repository) getCommitFromBatchReader(wr WriteCloserError, rd *bufio.
return nil, err
}
- switch typ {
+ switch info.Type {
case "missing":
return nil, ErrNotExist{ID: id.String()}
case "tag":
// then we need to parse the tag
// and load the commit
- data, err := io.ReadAll(io.LimitReader(rd, size))
+ data, err := io.ReadAll(io.LimitReader(rd, info.Size))
if err != nil {
return nil, err
}
@@ -100,19 +86,9 @@ func (repo *Repository) getCommitFromBatchReader(wr WriteCloserError, rd *bufio.
if err != nil {
return nil, err
}
-
- if _, err := wr.Write([]byte(tag.Object.String() + "\n")); err != nil {
- return nil, err
- }
-
- commit, err := repo.getCommitFromBatchReader(wr, rd, tag.Object)
- if err != nil {
- return nil, err
- }
-
- return commit, nil
+ return repo.getCommitWithBatch(batch, tag.Object)
case "commit":
- commit, err := CommitFromReader(repo, id, io.LimitReader(rd, size))
+ commit, err := CommitFromReader(repo, id, io.LimitReader(rd, info.Size))
if err != nil {
return nil, err
}
@@ -123,8 +99,8 @@ func (repo *Repository) getCommitFromBatchReader(wr WriteCloserError, rd *bufio.
return commit, nil
default:
- log.Debug("Unknown typ: %s", typ)
- if err := DiscardFull(rd, size+1); err != nil {
+ log.Debug("Unknown cat-file object type: %s", info.Type)
+ if err := DiscardFull(rd, info.Size+1); err != nil {
return nil, err
}
return nil, ErrNotExist{
@@ -146,16 +122,12 @@ func (repo *Repository) ConvertToGitID(commitID string) (ObjectID, error) {
}
}
- wr, rd, cancel, err := repo.CatFileBatchCheck(repo.Ctx)
+ batch, cancel, err := repo.CatFileBatch(repo.Ctx)
if err != nil {
return nil, err
}
defer cancel()
- _, err = wr.Write([]byte(commitID + "\n"))
- if err != nil {
- return nil, err
- }
- sha, _, _, err := ReadBatchLine(rd)
+ info, err := batch.QueryInfo(commitID)
if err != nil {
if IsErrNotExist(err) {
return nil, ErrNotExist{commitID, ""}
@@ -163,5 +135,5 @@ func (repo *Repository) ConvertToGitID(commitID string) (ObjectID, error) {
return nil, err
}
- return MustIDFromString(string(sha)), nil
+ return MustIDFromString(info.ID), nil
}
diff --git a/modules/git/repo_commitgraph.go b/modules/git/repo_commitgraph.go
index 331c799b33..3dac74304c 100644
--- a/modules/git/repo_commitgraph.go
+++ b/modules/git/repo_commitgraph.go
@@ -14,7 +14,7 @@ import (
// this requires git v2.18 to be installed
func WriteCommitGraph(ctx context.Context, repoPath string) error {
if DefaultFeatures().CheckVersionAtLeast("2.18") {
- if _, _, err := gitcmd.NewCommand("commit-graph", "write").RunStdString(ctx, &gitcmd.RunOpts{Dir: repoPath}); err != nil {
+ if _, _, err := gitcmd.NewCommand("commit-graph", "write").WithDir(repoPath).RunStdString(ctx); err != nil {
return fmt.Errorf("unable to write commit-graph for '%s' : %w", repoPath, err)
}
}
diff --git a/modules/git/repo_compare.go b/modules/git/repo_compare.go
index 69a7314d5c..aa25e2ec20 100644
--- a/modules/git/repo_compare.go
+++ b/modules/git/repo_compare.go
@@ -7,38 +7,17 @@ package git
import (
"bufio"
"bytes"
- "context"
"errors"
"fmt"
"io"
"os"
"path/filepath"
"regexp"
- "strconv"
"strings"
"code.gitea.io/gitea/modules/git/gitcmd"
)
-// GetMergeBase checks and returns merge base of two branches and the reference used as base.
-func (repo *Repository) GetMergeBase(tmpRemote, base, head string) (string, string, error) {
- if tmpRemote == "" {
- tmpRemote = "origin"
- }
-
- if tmpRemote != "origin" {
- tmpBaseName := RemotePrefix + tmpRemote + "/tmp_" + base
- // Fetch commit into a temporary branch in order to be able to handle commits and tags
- _, _, err := gitcmd.NewCommand("fetch", "--no-tags").AddDynamicArguments(tmpRemote).AddDashesAndList(base+":"+tmpBaseName).RunStdString(repo.Ctx, &gitcmd.RunOpts{Dir: repo.Path})
- if err == nil {
- base = tmpBaseName
- }
- }
-
- stdout, _, err := gitcmd.NewCommand("merge-base").AddDashesAndList(base, head).RunStdString(repo.Ctx, &gitcmd.RunOpts{Dir: repo.Path})
- return strings.TrimSpace(stdout), base, err
-}
-
type lineCountWriter struct {
numLines int
}
@@ -55,7 +34,6 @@ func (l *lineCountWriter) Write(p []byte) (n int, err error) {
func (repo *Repository) GetDiffNumChangedFiles(base, head string, directComparison bool) (int, error) {
// Now there is git diff --shortstat but this appears to be slower than simply iterating with --nameonly
w := &lineCountWriter{}
- stderr := new(bytes.Buffer)
separator := "..."
if directComparison {
@@ -63,109 +41,55 @@ func (repo *Repository) GetDiffNumChangedFiles(base, head string, directComparis
}
// avoid: ambiguous argument 'refs/a...refs/b': unknown revision or path not in the working tree. Use '--': 'git ] [...] -- [...]'
- if err := gitcmd.NewCommand("diff", "-z", "--name-only").AddDynamicArguments(base+separator+head).AddArguments("--").
- Run(repo.Ctx, &gitcmd.RunOpts{
- Dir: repo.Path,
- Stdout: w,
- Stderr: stderr,
- }); err != nil {
- if strings.Contains(stderr.String(), "no merge base") {
+ if err := gitcmd.NewCommand("diff", "-z", "--name-only").
+ AddDynamicArguments(base + separator + head).
+ AddArguments("--").
+ WithDir(repo.Path).
+ WithStdoutCopy(w).
+ RunWithStderr(repo.Ctx); err != nil {
+ if strings.Contains(err.Stderr(), "no merge base") {
// git >= 2.28 now returns an error if base and head have become unrelated.
// previously it would return the results of git diff -z --name-only base head so let's try that...
w = &lineCountWriter{}
- stderr.Reset()
- if err = gitcmd.NewCommand("diff", "-z", "--name-only").AddDynamicArguments(base, head).AddArguments("--").Run(repo.Ctx, &gitcmd.RunOpts{
- Dir: repo.Path,
- Stdout: w,
- Stderr: stderr,
- }); err == nil {
+ if err = gitcmd.NewCommand("diff", "-z", "--name-only").
+ AddDynamicArguments(base, head).
+ AddArguments("--").
+ WithDir(repo.Path).
+ WithStdoutCopy(w).
+ RunWithStderr(repo.Ctx); err == nil {
return w.numLines, nil
}
}
- return 0, fmt.Errorf("%w: Stderr: %s", err, stderr)
+ return 0, err
}
return w.numLines, nil
}
-// GetDiffShortStatByCmdArgs counts number of changed files, number of additions and deletions
-// TODO: it can be merged with another "GetDiffShortStat" in the future
-func GetDiffShortStatByCmdArgs(ctx context.Context, repoPath string, trustedArgs gitcmd.TrustedCmdArgs, dynamicArgs ...string) (numFiles, totalAdditions, totalDeletions int, err error) {
- // Now if we call:
- // $ git diff --shortstat 1ebb35b98889ff77299f24d82da426b434b0cca0...788b8b1440462d477f45b0088875
- // we get:
- // " 9902 files changed, 2034198 insertions(+), 298800 deletions(-)\n"
- cmd := gitcmd.NewCommand("diff", "--shortstat").AddArguments(trustedArgs...).AddDynamicArguments(dynamicArgs...)
- stdout, _, err := cmd.RunStdString(ctx, &gitcmd.RunOpts{Dir: repoPath})
- if err != nil {
- return 0, 0, 0, err
- }
-
- return parseDiffStat(stdout)
-}
-
-var shortStatFormat = regexp.MustCompile(
- `\s*(\d+) files? changed(?:, (\d+) insertions?\(\+\))?(?:, (\d+) deletions?\(-\))?`)
-
var patchCommits = regexp.MustCompile(`^From\s(\w+)\s`)
-func parseDiffStat(stdout string) (numFiles, totalAdditions, totalDeletions int, err error) {
- if len(stdout) == 0 || stdout == "\n" {
- return 0, 0, 0, nil
- }
- groups := shortStatFormat.FindStringSubmatch(stdout)
- if len(groups) != 4 {
- return 0, 0, 0, fmt.Errorf("unable to parse shortstat: %s groups: %s", stdout, groups)
- }
-
- numFiles, err = strconv.Atoi(groups[1])
- if err != nil {
- return 0, 0, 0, fmt.Errorf("unable to parse shortstat: %s. Error parsing NumFiles %w", stdout, err)
- }
-
- if len(groups[2]) != 0 {
- totalAdditions, err = strconv.Atoi(groups[2])
- if err != nil {
- return 0, 0, 0, fmt.Errorf("unable to parse shortstat: %s. Error parsing NumAdditions %w", stdout, err)
- }
- }
-
- if len(groups[3]) != 0 {
- totalDeletions, err = strconv.Atoi(groups[3])
- if err != nil {
- return 0, 0, 0, fmt.Errorf("unable to parse shortstat: %s. Error parsing NumDeletions %w", stdout, err)
- }
- }
- return numFiles, totalAdditions, totalDeletions, err
-}
-
// GetDiff generates and returns patch data between given revisions, optimized for human readability
func (repo *Repository) GetDiff(compareArg string, w io.Writer) error {
- stderr := new(bytes.Buffer)
return gitcmd.NewCommand("diff", "-p").AddDynamicArguments(compareArg).
- Run(repo.Ctx, &gitcmd.RunOpts{
- Dir: repo.Path,
- Stdout: w,
- Stderr: stderr,
- })
+ WithDir(repo.Path).
+ WithStdoutCopy(w).
+ Run(repo.Ctx)
}
// GetDiffBinary generates and returns patch data between given revisions, including binary diffs.
func (repo *Repository) GetDiffBinary(compareArg string, w io.Writer) error {
- return gitcmd.NewCommand("diff", "-p", "--binary", "--histogram").AddDynamicArguments(compareArg).Run(repo.Ctx, &gitcmd.RunOpts{
- Dir: repo.Path,
- Stdout: w,
- })
+ return gitcmd.NewCommand("diff", "-p", "--binary", "--histogram").
+ AddDynamicArguments(compareArg).
+ WithDir(repo.Path).
+ WithStdoutCopy(w).
+ Run(repo.Ctx)
}
// GetPatch generates and returns format-patch data between given revisions, able to be used with `git apply`
func (repo *Repository) GetPatch(compareArg string, w io.Writer) error {
- stderr := new(bytes.Buffer)
return gitcmd.NewCommand("format-patch", "--binary", "--stdout").AddDynamicArguments(compareArg).
- Run(repo.Ctx, &gitcmd.RunOpts{
- Dir: repo.Path,
- Stdout: w,
- Stderr: stderr,
- })
+ WithDir(repo.Path).
+ WithStdoutCopy(w).
+ Run(repo.Ctx)
}
// GetFilesChangedBetween returns a list of all files that have been changed between the given commits
@@ -182,7 +106,7 @@ func (repo *Repository) GetFilesChangedBetween(base, head string) ([]string, err
} else {
cmd.AddDynamicArguments(base, head)
}
- stdout, _, err := cmd.RunStdString(repo.Ctx, &gitcmd.RunOpts{Dir: repo.Path})
+ stdout, _, err := cmd.WithDir(repo.Path).RunStdString(repo.Ctx)
if err != nil {
return nil, err
}
diff --git a/modules/git/repo_compare_test.go b/modules/git/repo_compare_test.go
index 47fd2ca102..bf16b7cfce 100644
--- a/modules/git/repo_compare_test.go
+++ b/modules/git/repo_compare_test.go
@@ -103,7 +103,8 @@ func TestReadWritePullHead(t *testing.T) {
newCommit := "feaf4ba6bc635fec442f46ddd4512416ec43c2c2"
_, _, err = gitcmd.NewCommand("update-ref").
AddDynamicArguments(PullPrefix+"1/head", newCommit).
- RunStdString(t.Context(), &gitcmd.RunOpts{Dir: repo.Path})
+ WithDir(repo.Path).
+ RunStdString(t.Context())
if err != nil {
assert.NoError(t, err)
return
@@ -121,8 +122,9 @@ func TestReadWritePullHead(t *testing.T) {
// Remove file after the test
_, _, err = gitcmd.NewCommand("update-ref", "--no-deref", "-d").
- AddDynamicArguments(PullPrefix+"1/head").
- RunStdString(t.Context(), &gitcmd.RunOpts{Dir: repo.Path})
+ AddDynamicArguments(PullPrefix + "1/head").
+ WithDir(repo.Path).
+ RunStdString(t.Context())
assert.NoError(t, err)
}
diff --git a/modules/git/repo_gpg.go b/modules/git/repo_gpg.go
deleted file mode 100644
index a999d2dbc6..0000000000
--- a/modules/git/repo_gpg.go
+++ /dev/null
@@ -1,71 +0,0 @@
-// Copyright 2015 The Gogs Authors. All rights reserved.
-// Copyright 2017 The Gitea Authors. All rights reserved.
-// SPDX-License-Identifier: MIT
-
-package git
-
-import (
- "fmt"
- "os"
- "strings"
-
- "code.gitea.io/gitea/modules/git/gitcmd"
- "code.gitea.io/gitea/modules/process"
-)
-
-// LoadPublicKeyContent will load the key from gpg
-func (gpgSettings *GPGSettings) LoadPublicKeyContent() error {
- if gpgSettings.Format == SigningKeyFormatSSH {
- content, err := os.ReadFile(gpgSettings.KeyID)
- if err != nil {
- return fmt.Errorf("unable to read SSH public key file: %s, %w", gpgSettings.KeyID, err)
- }
- gpgSettings.PublicKeyContent = string(content)
- return nil
- }
- content, stderr, err := process.GetManager().Exec(
- "gpg -a --export",
- "gpg", "-a", "--export", gpgSettings.KeyID)
- if err != nil {
- return fmt.Errorf("unable to get default signing key: %s, %s, %w", gpgSettings.KeyID, stderr, err)
- }
- gpgSettings.PublicKeyContent = content
- return nil
-}
-
-// GetDefaultPublicGPGKey will return and cache the default public GPG settings for this repository
-func (repo *Repository) GetDefaultPublicGPGKey(forceUpdate bool) (*GPGSettings, error) {
- if repo.gpgSettings != nil && !forceUpdate {
- return repo.gpgSettings, nil
- }
-
- gpgSettings := &GPGSettings{
- Sign: true,
- }
-
- value, _, _ := gitcmd.NewCommand("config", "--get", "commit.gpgsign").RunStdString(repo.Ctx, &gitcmd.RunOpts{Dir: repo.Path})
- sign, valid := ParseBool(strings.TrimSpace(value))
- if !sign || !valid {
- gpgSettings.Sign = false
- repo.gpgSettings = gpgSettings
- return gpgSettings, nil
- }
-
- signingKey, _, _ := gitcmd.NewCommand("config", "--get", "user.signingkey").RunStdString(repo.Ctx, &gitcmd.RunOpts{Dir: repo.Path})
- gpgSettings.KeyID = strings.TrimSpace(signingKey)
-
- format, _, _ := gitcmd.NewCommand("config", "--default", SigningKeyFormatOpenPGP, "--get", "gpg.format").RunStdString(repo.Ctx, &gitcmd.RunOpts{Dir: repo.Path})
- gpgSettings.Format = strings.TrimSpace(format)
-
- defaultEmail, _, _ := gitcmd.NewCommand("config", "--get", "user.email").RunStdString(repo.Ctx, &gitcmd.RunOpts{Dir: repo.Path})
- gpgSettings.Email = strings.TrimSpace(defaultEmail)
-
- defaultName, _, _ := gitcmd.NewCommand("config", "--get", "user.name").RunStdString(repo.Ctx, &gitcmd.RunOpts{Dir: repo.Path})
- gpgSettings.Name = strings.TrimSpace(defaultName)
-
- if err := gpgSettings.LoadPublicKeyContent(); err != nil {
- return nil, err
- }
- repo.gpgSettings = gpgSettings
- return repo.gpgSettings, nil
-}
diff --git a/modules/git/repo_index.go b/modules/git/repo_index.go
index e7b3792d95..1d040d5e0a 100644
--- a/modules/git/repo_index.go
+++ b/modules/git/repo_index.go
@@ -22,7 +22,7 @@ func (repo *Repository) ReadTreeToIndex(treeish string, indexFilename ...string)
}
if len(treeish) != objectFormat.FullLength() {
- res, _, err := gitcmd.NewCommand("rev-parse", "--verify").AddDynamicArguments(treeish).RunStdString(repo.Ctx, &gitcmd.RunOpts{Dir: repo.Path})
+ res, _, err := gitcmd.NewCommand("rev-parse", "--verify").AddDynamicArguments(treeish).WithDir(repo.Path).RunStdString(repo.Ctx)
if err != nil {
return err
}
@@ -42,7 +42,7 @@ func (repo *Repository) readTreeToIndex(id ObjectID, indexFilename ...string) er
if len(indexFilename) > 0 {
env = append(os.Environ(), "GIT_INDEX_FILE="+indexFilename[0])
}
- _, _, err := gitcmd.NewCommand("read-tree").AddDynamicArguments(id.String()).RunStdString(repo.Ctx, &gitcmd.RunOpts{Dir: repo.Path, Env: env})
+ _, _, err := gitcmd.NewCommand("read-tree").AddDynamicArguments(id.String()).WithDir(repo.Path).WithEnv(env).RunStdString(repo.Ctx)
if err != nil {
return err
}
@@ -75,14 +75,14 @@ func (repo *Repository) ReadTreeToTemporaryIndex(treeish string) (tmpIndexFilena
// EmptyIndex empties the index
func (repo *Repository) EmptyIndex() error {
- _, _, err := gitcmd.NewCommand("read-tree", "--empty").RunStdString(repo.Ctx, &gitcmd.RunOpts{Dir: repo.Path})
+ _, _, err := gitcmd.NewCommand("read-tree", "--empty").WithDir(repo.Path).RunStdString(repo.Ctx)
return err
}
// LsFiles checks if the given filenames are in the index
func (repo *Repository) LsFiles(filenames ...string) ([]string, error) {
cmd := gitcmd.NewCommand("ls-files", "-z").AddDashesAndList(filenames...)
- res, _, err := cmd.RunStdBytes(repo.Ctx, &gitcmd.RunOpts{Dir: repo.Path})
+ res, _, err := cmd.WithDir(repo.Path).RunStdBytes(repo.Ctx)
if err != nil {
return nil, err
}
@@ -101,21 +101,17 @@ func (repo *Repository) RemoveFilesFromIndex(filenames ...string) error {
return err
}
cmd := gitcmd.NewCommand("update-index", "--remove", "-z", "--index-info")
- stdout := new(bytes.Buffer)
- stderr := new(bytes.Buffer)
- buffer := new(bytes.Buffer)
+ input := new(bytes.Buffer)
for _, file := range filenames {
if file != "" {
// using format: mode SP type SP sha1 TAB path
- buffer.WriteString("0 blob " + objectFormat.EmptyObjectID().String() + "\t" + file + "\000")
+ input.WriteString("0 blob " + objectFormat.EmptyObjectID().String() + "\t" + file + "\000")
}
}
- return cmd.Run(repo.Ctx, &gitcmd.RunOpts{
- Dir: repo.Path,
- Stdin: bytes.NewReader(buffer.Bytes()),
- Stdout: stdout,
- Stderr: stderr,
- })
+ return cmd.
+ WithDir(repo.Path).
+ WithStdinBytes(input.Bytes()).
+ RunWithStderr(repo.Ctx)
}
type IndexObjectInfo struct {
@@ -127,19 +123,15 @@ type IndexObjectInfo struct {
// AddObjectsToIndex adds the provided object hashes to the index at the provided filenames
func (repo *Repository) AddObjectsToIndex(objects ...IndexObjectInfo) error {
cmd := gitcmd.NewCommand("update-index", "--add", "--replace", "-z", "--index-info")
- stdout := new(bytes.Buffer)
- stderr := new(bytes.Buffer)
- buffer := new(bytes.Buffer)
+ input := new(bytes.Buffer)
for _, object := range objects {
// using format: mode SP type SP sha1 TAB path
- buffer.WriteString(object.Mode + " blob " + object.Object.String() + "\t" + object.Filename + "\000")
+ input.WriteString(object.Mode + " blob " + object.Object.String() + "\t" + object.Filename + "\000")
}
- return cmd.Run(repo.Ctx, &gitcmd.RunOpts{
- Dir: repo.Path,
- Stdin: bytes.NewReader(buffer.Bytes()),
- Stdout: stdout,
- Stderr: stderr,
- })
+ return cmd.
+ WithDir(repo.Path).
+ WithStdinBytes(input.Bytes()).
+ RunWithStderr(repo.Ctx)
}
// AddObjectToIndex adds the provided object hash to the index at the provided filename
@@ -149,7 +141,7 @@ func (repo *Repository) AddObjectToIndex(mode string, object ObjectID, filename
// WriteTree writes the current index as a tree to the object db and returns its hash
func (repo *Repository) WriteTree() (*Tree, error) {
- stdout, _, runErr := gitcmd.NewCommand("write-tree").RunStdString(repo.Ctx, &gitcmd.RunOpts{Dir: repo.Path})
+ stdout, _, runErr := gitcmd.NewCommand("write-tree").WithDir(repo.Path).RunStdString(repo.Ctx)
if runErr != nil {
return nil, runErr
}
diff --git a/modules/git/repo_object.go b/modules/git/repo_object.go
index e8f6510c23..38e16b4646 100644
--- a/modules/git/repo_object.go
+++ b/modules/git/repo_object.go
@@ -5,8 +5,6 @@
package git
import (
- "bytes"
- "io"
"strings"
"code.gitea.io/gitea/modules/git/gitcmd"
@@ -33,18 +31,12 @@ func (o ObjectType) Bytes() []byte {
return []byte(o)
}
-type EmptyReader struct{}
-
-func (EmptyReader) Read(p []byte) (int, error) {
- return 0, io.EOF
-}
-
func (repo *Repository) GetObjectFormat() (ObjectFormat, error) {
if repo != nil && repo.objectFormat != nil {
return repo.objectFormat, nil
}
- str, err := repo.hashObject(EmptyReader{}, false)
+ str, err := repo.hashObjectBytes(nil, false)
if err != nil {
return nil, err
}
@@ -58,32 +50,28 @@ func (repo *Repository) GetObjectFormat() (ObjectFormat, error) {
return repo.objectFormat, nil
}
-// HashObject takes a reader and returns hash for that reader
-func (repo *Repository) HashObject(reader io.Reader) (ObjectID, error) {
- idStr, err := repo.hashObject(reader, true)
+// HashObjectBytes returns hash for the content
+func (repo *Repository) HashObjectBytes(buf []byte) (ObjectID, error) {
+ idStr, err := repo.hashObjectBytes(buf, true)
if err != nil {
return nil, err
}
return NewIDFromString(idStr)
}
-func (repo *Repository) hashObject(reader io.Reader, save bool) (string, error) {
+func (repo *Repository) hashObjectBytes(buf []byte, save bool) (string, error) {
var cmd *gitcmd.Command
if save {
cmd = gitcmd.NewCommand("hash-object", "-w", "--stdin")
} else {
cmd = gitcmd.NewCommand("hash-object", "--stdin")
}
- stdout := new(bytes.Buffer)
- stderr := new(bytes.Buffer)
- err := cmd.Run(repo.Ctx, &gitcmd.RunOpts{
- Dir: repo.Path,
- Stdin: reader,
- Stdout: stdout,
- Stderr: stderr,
- })
+ stdout, _, err := cmd.
+ WithDir(repo.Path).
+ WithStdinBytes(buf).
+ RunStdString(repo.Ctx)
if err != nil {
return "", err
}
- return strings.TrimSpace(stdout.String()), nil
+ return strings.TrimSpace(stdout), nil
}
diff --git a/modules/git/repo_ref.go b/modules/git/repo_ref.go
index 577e17c45d..8859a93a57 100644
--- a/modules/git/repo_ref.go
+++ b/modules/git/repo_ref.go
@@ -28,7 +28,8 @@ func (repo *Repository) ListOccurrences(ctx context.Context, refType, commitSHA
default:
return nil, util.NewInvalidArgumentErrorf(`can only use "branch" or "tag" for refType, but got %q`, refType)
}
- stdout, _, err := cmd.AddArguments("--no-color", "--sort=-creatordate", "--contains").AddDynamicArguments(commitSHA).RunStdString(ctx, &gitcmd.RunOpts{Dir: repo.Path})
+ stdout, _, err := cmd.AddArguments("--no-color", "--sort=-creatordate", "--contains").
+ AddDynamicArguments(commitSHA).WithDir(repo.Path).RunStdString(ctx)
if err != nil {
return nil, err
}
diff --git a/modules/git/repo_ref_nogogit.go b/modules/git/repo_ref_nogogit.go
index 784efecc65..c58992fa9d 100644
--- a/modules/git/repo_ref_nogogit.go
+++ b/modules/git/repo_ref_nogogit.go
@@ -15,75 +15,61 @@ import (
// GetRefsFiltered returns all references of the repository that matches patterm exactly or starting with.
func (repo *Repository) GetRefsFiltered(pattern string) ([]*Reference, error) {
- stdoutReader, stdoutWriter := io.Pipe()
- defer func() {
- _ = stdoutReader.Close()
- _ = stdoutWriter.Close()
- }()
-
- go func() {
- stderrBuilder := &strings.Builder{}
- err := gitcmd.NewCommand("for-each-ref").Run(repo.Ctx, &gitcmd.RunOpts{
- Dir: repo.Path,
- Stdout: stdoutWriter,
- Stderr: stderrBuilder,
- })
- if err != nil {
- _ = stdoutWriter.CloseWithError(gitcmd.ConcatenateError(err, stderrBuilder.String()))
- } else {
- _ = stdoutWriter.Close()
- }
- }()
-
refs := make([]*Reference, 0)
- bufReader := bufio.NewReader(stdoutReader)
- for {
- // The output of for-each-ref is simply a list:
- // SP TAB [ LF
- sha, err := bufReader.ReadString(' ')
- if err == io.EOF {
- break
- }
- if err != nil {
- return nil, err
- }
- sha = sha[:len(sha)-1]
+ cmd := gitcmd.NewCommand("for-each-ref")
+ stdoutReader, stdoutReaderClose := cmd.MakeStdoutPipe()
+ defer stdoutReaderClose()
+ err := cmd.WithDir(repo.Path).
+ WithPipelineFunc(func(context gitcmd.Context) error {
+ bufReader := bufio.NewReader(stdoutReader)
+ for {
+ // The output of for-each-ref is simply a list:
+ // ] SP TAB [ LF
+ sha, err := bufReader.ReadString(' ')
+ if err == io.EOF {
+ break
+ }
+ if err != nil {
+ return err
+ }
+ sha = sha[:len(sha)-1]
- typ, err := bufReader.ReadString('\t')
- if err == io.EOF {
- // This should not happen, but we'll tolerate it
- break
- }
- if err != nil {
- return nil, err
- }
- typ = typ[:len(typ)-1]
+ typ, err := bufReader.ReadString('\t')
+ if err == io.EOF {
+ // This should not happen, but we'll tolerate it
+ break
+ }
+ if err != nil {
+ return err
+ }
+ typ = typ[:len(typ)-1]
- refName, err := bufReader.ReadString('\n')
- if err == io.EOF {
- // This should not happen, but we'll tolerate it
- break
- }
- if err != nil {
- return nil, err
- }
- refName = refName[:len(refName)-1]
+ refName, err := bufReader.ReadString('\n')
+ if err == io.EOF {
+ // This should not happen, but we'll tolerate it
+ break
+ }
+ if err != nil {
+ return err
+ }
+ refName = refName[:len(refName)-1]
- // refName cannot be HEAD but can be remotes or stash
- if strings.HasPrefix(refName, RemotePrefix) || refName == "/refs/stash" {
- continue
- }
+ // refName cannot be HEAD but can be remotes or stash
+ if strings.HasPrefix(refName, RemotePrefix) || refName == "/refs/stash" {
+ continue
+ }
- if pattern == "" || strings.HasPrefix(refName, pattern) {
- r := &Reference{
- Name: refName,
- Object: MustIDFromString(sha),
- Type: typ,
- repo: repo,
+ if pattern == "" || strings.HasPrefix(refName, pattern) {
+ r := &Reference{
+ Name: refName,
+ Object: MustIDFromString(sha),
+ Type: typ,
+ repo: repo,
+ }
+ refs = append(refs, r)
+ }
}
- refs = append(refs, r)
- }
- }
-
- return refs, nil
+ return nil
+ }).RunWithStderr(repo.Ctx)
+ return refs, err
}
diff --git a/modules/git/repo_stats.go b/modules/git/repo_stats.go
index 22082325ef..1dd77f05d4 100644
--- a/modules/git/repo_stats.go
+++ b/modules/git/repo_stats.go
@@ -5,9 +5,7 @@ package git
import (
"bufio"
- "context"
"fmt"
- "os"
"sort"
"strconv"
"strings"
@@ -43,7 +41,8 @@ func (repo *Repository) GetCodeActivityStats(fromTime time.Time, branch string)
stdout, _, runErr := gitcmd.NewCommand("rev-list", "--count", "--no-merges", "--branches=*", "--date=iso").
AddOptionFormat("--since=%s", since).
- RunStdString(repo.Ctx, &gitcmd.RunOpts{Dir: repo.Path})
+ WithDir(repo.Path).
+ RunStdString(repo.Ctx)
if runErr != nil {
return nil, runErr
}
@@ -54,15 +53,6 @@ func (repo *Repository) GetCodeActivityStats(fromTime time.Time, branch string)
}
stats.CommitCountInAllBranches = c
- stdoutReader, stdoutWriter, err := os.Pipe()
- if err != nil {
- return nil, err
- }
- defer func() {
- _ = stdoutReader.Close()
- _ = stdoutWriter.Close()
- }()
-
gitCmd := gitcmd.NewCommand("log", "--numstat", "--no-merges", "--pretty=format:---%n%h%n%aN%n%aE%n", "--date=iso").
AddOptionFormat("--since=%s", since)
if len(branch) == 0 {
@@ -71,14 +61,11 @@ func (repo *Repository) GetCodeActivityStats(fromTime time.Time, branch string)
gitCmd.AddArguments("--first-parent").AddDynamicArguments(branch)
}
- stderr := new(strings.Builder)
- err = gitCmd.Run(repo.Ctx, &gitcmd.RunOpts{
- Env: []string{},
- Dir: repo.Path,
- Stdout: stdoutWriter,
- Stderr: stderr,
- PipelineFunc: func(ctx context.Context, cancel context.CancelFunc) error {
- _ = stdoutWriter.Close()
+ stdoutReader, stdoutReaderClose := gitCmd.MakeStdoutPipe()
+ defer stdoutReaderClose()
+ err = gitCmd.
+ WithDir(repo.Path).
+ WithPipelineFunc(func(ctx gitcmd.Context) error {
scanner := bufio.NewScanner(stdoutReader)
scanner.Split(bufio.ScanLines)
stats.CommitCount = 0
@@ -129,7 +116,6 @@ func (repo *Repository) GetCodeActivityStats(fromTime time.Time, branch string)
}
}
if err = scanner.Err(); err != nil {
- _ = stdoutReader.Close()
return fmt.Errorf("GetCodeActivityStats scan: %w", err)
}
a := make([]*CodeActivityAuthor, 0, len(authors))
@@ -143,12 +129,11 @@ func (repo *Repository) GetCodeActivityStats(fromTime time.Time, branch string)
stats.AuthorCount = int64(len(authors))
stats.ChangedFiles = int64(len(files))
stats.Authors = a
- _ = stdoutReader.Close()
return nil
- },
- })
+ }).
+ RunWithStderr(repo.Ctx)
if err != nil {
- return nil, fmt.Errorf("Failed to get GetCodeActivityStats for repository.\nError: %w\nStderr: %s", err, stderr)
+ return nil, fmt.Errorf("GetCodeActivityStats: %w", err)
}
return stats, nil
diff --git a/modules/git/repo_tag.go b/modules/git/repo_tag.go
index 0cb0932459..2599236ae0 100644
--- a/modules/git/repo_tag.go
+++ b/modules/git/repo_tag.go
@@ -6,7 +6,6 @@ package git
import (
"fmt"
- "io"
"strings"
"code.gitea.io/gitea/modules/git/foreachref"
@@ -19,13 +18,17 @@ const TagPrefix = "refs/tags/"
// CreateTag create one tag in the repository
func (repo *Repository) CreateTag(name, revision string) error {
- _, _, err := gitcmd.NewCommand("tag").AddDashesAndList(name, revision).RunStdString(repo.Ctx, &gitcmd.RunOpts{Dir: repo.Path})
+ _, _, err := gitcmd.NewCommand("tag").AddDashesAndList(name, revision).WithDir(repo.Path).RunStdString(repo.Ctx)
return err
}
// CreateAnnotatedTag create one annotated tag in the repository
func (repo *Repository) CreateAnnotatedTag(name, message, revision string) error {
- _, _, err := gitcmd.NewCommand("tag", "-a", "-m").AddDynamicArguments(message).AddDashesAndList(name, revision).RunStdString(repo.Ctx, &gitcmd.RunOpts{Dir: repo.Path})
+ _, _, err := gitcmd.NewCommand("tag", "-a", "-m").
+ AddDynamicArguments(message).
+ AddDashesAndList(name, revision).
+ WithDir(repo.Path).
+ RunStdString(repo.Ctx)
return err
}
@@ -35,7 +38,7 @@ func (repo *Repository) GetTagNameBySHA(sha string) (string, error) {
return "", fmt.Errorf("SHA is too short: %s", sha)
}
- stdout, _, err := gitcmd.NewCommand("show-ref", "--tags", "-d").RunStdString(repo.Ctx, &gitcmd.RunOpts{Dir: repo.Path})
+ stdout, _, err := gitcmd.NewCommand("show-ref", "--tags", "-d").WithDir(repo.Path).RunStdString(repo.Ctx)
if err != nil {
return "", err
}
@@ -58,7 +61,7 @@ func (repo *Repository) GetTagNameBySHA(sha string) (string, error) {
// GetTagID returns the object ID for a tag (annotated tags have both an object SHA AND a commit SHA)
func (repo *Repository) GetTagID(name string) (string, error) {
- stdout, _, err := gitcmd.NewCommand("show-ref", "--tags").AddDashesAndList(name).RunStdString(repo.Ctx, &gitcmd.RunOpts{Dir: repo.Path})
+ stdout, _, err := gitcmd.NewCommand("show-ref", "--tags").AddDashesAndList(name).WithDir(repo.Path).RunStdString(repo.Ctx)
if err != nil {
return "", err
}
@@ -111,48 +114,42 @@ func (repo *Repository) GetTagInfos(page, pageSize int) ([]*Tag, int, error) {
// https://git-scm.com/docs/git-for-each-ref#Documentation/git-for-each-ref.txt-refname
forEachRefFmt := foreachref.NewFormat("objecttype", "refname:lstrip=2", "object", "objectname", "creator", "contents", "contents:signature")
- stdoutReader, stdoutWriter := io.Pipe()
- defer stdoutReader.Close()
- defer stdoutWriter.Close()
- stderr := strings.Builder{}
- rc := &gitcmd.RunOpts{Dir: repo.Path, Stdout: stdoutWriter, Stderr: &stderr}
-
- go func() {
- err := gitcmd.NewCommand("for-each-ref").
- AddOptionFormat("--format=%s", forEachRefFmt.Flag()).
- AddArguments("--sort", "-*creatordate", "refs/tags").Run(repo.Ctx, rc)
- if err != nil {
- _ = stdoutWriter.CloseWithError(gitcmd.ConcatenateError(err, stderr.String()))
- } else {
- _ = stdoutWriter.Close()
- }
- }()
-
var tags []*Tag
- parser := forEachRefFmt.Parser(stdoutReader)
- for {
- ref := parser.Next()
- if ref == nil {
- break
- }
+ var tagsTotal int
+ cmd := gitcmd.NewCommand("for-each-ref")
+ stdoutReader, stdoutReaderClose := cmd.MakeStdoutPipe()
+ defer stdoutReaderClose()
+ err := cmd.AddOptionFormat("--format=%s", forEachRefFmt.Flag()).
+ AddArguments("--sort", "-*creatordate", "refs/tags").
+ WithDir(repo.Path).
+ WithPipelineFunc(func(context gitcmd.Context) error {
+ parser := forEachRefFmt.Parser(stdoutReader)
+ for {
+ ref := parser.Next()
+ if ref == nil {
+ break
+ }
- tag, err := parseTagRef(ref)
- if err != nil {
- return nil, 0, fmt.Errorf("GetTagInfos: parse tag: %w", err)
- }
- tags = append(tags, tag)
- }
- if err := parser.Err(); err != nil {
- return nil, 0, fmt.Errorf("GetTagInfos: parse output: %w", err)
- }
+ tag, err := parseTagRef(ref)
+ if err != nil {
+ return fmt.Errorf("GetTagInfos: parse tag: %w", err)
+ }
+ tags = append(tags, tag)
+ }
+ if err := parser.Err(); err != nil {
+ return fmt.Errorf("GetTagInfos: parse output: %w", err)
+ }
- sortTagsByTime(tags)
- tagsTotal := len(tags)
- if page != 0 {
- tags = util.PaginateSlice(tags, page, pageSize).([]*Tag)
- }
+ sortTagsByTime(tags)
+ tagsTotal = len(tags)
+ if page != 0 {
+ tags = util.PaginateSlice(tags, page, pageSize).([]*Tag)
+ }
+ return nil
+ }).
+ RunWithStderr(repo.Ctx)
- return tags, tagsTotal, nil
+ return tags, tagsTotal, err
}
// parseTagRef parses a tag from a 'git for-each-ref'-produced reference.
diff --git a/modules/git/repo_tag_nogogit.go b/modules/git/repo_tag_nogogit.go
index 5f79b68a9a..a9ac040821 100644
--- a/modules/git/repo_tag_nogogit.go
+++ b/modules/git/repo_tag_nogogit.go
@@ -24,23 +24,19 @@ func (repo *Repository) IsTagExist(name string) bool {
// GetTagType gets the type of the tag, either commit (simple) or tag (annotated)
func (repo *Repository) GetTagType(id ObjectID) (string, error) {
- wr, rd, cancel, err := repo.CatFileBatchCheck(repo.Ctx)
+ batch, cancel, err := repo.CatFileBatch(repo.Ctx)
if err != nil {
return "", err
}
defer cancel()
- _, err = wr.Write([]byte(id.String() + "\n"))
- if err != nil {
- return "", err
- }
- _, typ, _, err := ReadBatchLine(rd)
+ info, err := batch.QueryInfo(id.String())
if err != nil {
if IsErrNotExist(err) {
return "", ErrNotExist{ID: id.String()}
}
return "", err
}
- return typ, nil
+ return info.Type, nil
}
func (repo *Repository) getTag(tagID ObjectID, name string) (*Tag, error) {
@@ -88,22 +84,20 @@ func (repo *Repository) getTag(tagID ObjectID, name string) (*Tag, error) {
}
// The tag is an annotated tag with a message.
- wr, rd, cancel, err := repo.CatFileBatch(repo.Ctx)
+ batch, cancel, err := repo.CatFileBatch(repo.Ctx)
if err != nil {
return nil, err
}
defer cancel()
- if _, err := wr.Write([]byte(tagID.String() + "\n")); err != nil {
- return nil, err
- }
- _, typ, size, err := ReadBatchLine(rd)
+ info, rd, err := batch.QueryContent(tagID.String())
if err != nil {
if errors.Is(err, io.EOF) || IsErrNotExist(err) {
return nil, ErrNotExist{ID: tagID.String()}
}
return nil, err
}
+ typ, size := info.Type, info.Size
if typ != "tag" {
if err := DiscardFull(rd, size+1); err != nil {
return nil, err
diff --git a/modules/git/repo_test.go b/modules/git/repo_test.go
index 813844d1ea..776c297a34 100644
--- a/modules/git/repo_test.go
+++ b/modules/git/repo_test.go
@@ -10,16 +10,6 @@ import (
"github.com/stretchr/testify/assert"
)
-func TestGetLatestCommitTime(t *testing.T) {
- bareRepo1Path := filepath.Join(testReposDir, "repo1_bare")
- lct, err := GetLatestCommitTime(t.Context(), bareRepo1Path)
- assert.NoError(t, err)
- // Time is Sun Nov 13 16:40:14 2022 +0100
- // which is the time of commit
- // ce064814f4a0d337b333e646ece456cd39fab612 (refs/heads/master)
- assert.EqualValues(t, 1668354014, lct.Unix())
-}
-
func TestRepoIsEmpty(t *testing.T) {
emptyRepo2Path := filepath.Join(testReposDir, "repo2_empty")
repo, err := OpenRepository(t.Context(), emptyRepo2Path)
@@ -29,27 +19,3 @@ func TestRepoIsEmpty(t *testing.T) {
assert.NoError(t, err)
assert.True(t, isEmpty)
}
-
-func TestRepoGetDivergingCommits(t *testing.T) {
- bareRepo1Path := filepath.Join(testReposDir, "repo1_bare")
- do, err := GetDivergingCommits(t.Context(), bareRepo1Path, "master", "branch2")
- assert.NoError(t, err)
- assert.Equal(t, DivergeObject{
- Ahead: 1,
- Behind: 5,
- }, do)
-
- do, err = GetDivergingCommits(t.Context(), bareRepo1Path, "master", "master")
- assert.NoError(t, err)
- assert.Equal(t, DivergeObject{
- Ahead: 0,
- Behind: 0,
- }, do)
-
- do, err = GetDivergingCommits(t.Context(), bareRepo1Path, "master", "test")
- assert.NoError(t, err)
- assert.Equal(t, DivergeObject{
- Ahead: 0,
- Behind: 2,
- }, do)
-}
diff --git a/modules/git/repo_tree.go b/modules/git/repo_tree.go
index 1d8c940951..e65e2441ed 100644
--- a/modules/git/repo_tree.go
+++ b/modules/git/repo_tree.go
@@ -58,17 +58,12 @@ func (repo *Repository) CommitTree(author, committer *Signature, tree *Tree, opt
cmd.AddArguments("--no-gpg-sign")
}
- stdout := new(bytes.Buffer)
- stderr := new(bytes.Buffer)
- err := cmd.Run(repo.Ctx, &gitcmd.RunOpts{
- Env: env,
- Dir: repo.Path,
- Stdin: messageBytes,
- Stdout: stdout,
- Stderr: stderr,
- })
+ stdout, _, err := cmd.WithEnv(env).
+ WithDir(repo.Path).
+ WithStdinBytes(messageBytes.Bytes()).
+ RunStdString(repo.Ctx)
if err != nil {
- return nil, gitcmd.ConcatenateError(err, stderr.String())
+ return nil, err
}
- return NewIDFromString(strings.TrimSpace(stdout.String()))
+ return NewIDFromString(strings.TrimSpace(stdout))
}
diff --git a/modules/git/repo_tree_gogit.go b/modules/git/repo_tree_gogit.go
index 40524d0c34..89d34e87da 100644
--- a/modules/git/repo_tree_gogit.go
+++ b/modules/git/repo_tree_gogit.go
@@ -26,7 +26,7 @@ func (repo *Repository) getTree(id ObjectID) (*Tree, error) {
}
tree := NewTree(repo, id)
- tree.gogitTree = gogitTree
+ tree.resolvedGogitTreeObject = gogitTree
return tree, nil
}
@@ -38,7 +38,10 @@ func (repo *Repository) GetTree(idStr string) (*Tree, error) {
}
if len(idStr) != objectFormat.FullLength() {
- res, _, err := gitcmd.NewCommand("rev-parse", "--verify").AddDynamicArguments(idStr).RunStdString(repo.Ctx, &gitcmd.RunOpts{Dir: repo.Path})
+ res, _, err := gitcmd.NewCommand("rev-parse", "--verify").
+ AddDynamicArguments(idStr).
+ WithDir(repo.Path).
+ RunStdString(repo.Ctx)
if err != nil {
return nil, err
}
diff --git a/modules/git/repo_tree_nogogit.go b/modules/git/repo_tree_nogogit.go
index 1954f85162..82a61072c9 100644
--- a/modules/git/repo_tree_nogogit.go
+++ b/modules/git/repo_tree_nogogit.go
@@ -10,24 +10,21 @@ import (
)
func (repo *Repository) getTree(id ObjectID) (*Tree, error) {
- wr, rd, cancel, err := repo.CatFileBatch(repo.Ctx)
+ batch, cancel, err := repo.CatFileBatch(repo.Ctx)
if err != nil {
return nil, err
}
defer cancel()
- _, _ = wr.Write([]byte(id.String() + "\n"))
-
- // ignore the SHA
- _, typ, size, err := ReadBatchLine(rd)
+ info, rd, err := batch.QueryContent(id.String())
if err != nil {
return nil, err
}
- switch typ {
+ switch info.Type {
case "tag":
resolvedID := id
- data, err := io.ReadAll(io.LimitReader(rd, size))
+ data, err := io.ReadAll(io.LimitReader(rd, info.Size))
if err != nil {
return nil, err
}
@@ -36,17 +33,14 @@ func (repo *Repository) getTree(id ObjectID) (*Tree, error) {
return nil, err
}
- if _, err := wr.Write([]byte(tag.Object.String() + "\n")); err != nil {
- return nil, err
- }
- commit, err := repo.getCommitFromBatchReader(wr, rd, tag.Object)
+ commit, err := repo.getCommitWithBatch(batch, tag.Object)
if err != nil {
return nil, err
}
commit.Tree.ResolvedID = resolvedID
return &commit.Tree, nil
case "commit":
- commit, err := CommitFromReader(repo, id, io.LimitReader(rd, size))
+ commit, err := CommitFromReader(repo, id, io.LimitReader(rd, info.Size))
if err != nil {
return nil, err
}
@@ -62,14 +56,14 @@ func (repo *Repository) getTree(id ObjectID) (*Tree, error) {
if err != nil {
return nil, err
}
- tree.entries, err = catBatchParseTreeEntries(objectFormat, tree, rd, size)
+ tree.entries, err = catBatchParseTreeEntries(objectFormat, tree, rd, info.Size)
if err != nil {
return nil, err
}
tree.entriesParsed = true
return tree, nil
default:
- if err := DiscardFull(rd, size+1); err != nil {
+ if err := DiscardFull(rd, info.Size+1); err != nil {
return nil, err
}
return nil, ErrNotExist{
diff --git a/modules/git/submodule.go b/modules/git/submodule.go
index 58824adc82..ed69cbe55d 100644
--- a/modules/git/submodule.go
+++ b/modules/git/submodule.go
@@ -7,7 +7,6 @@ import (
"bufio"
"context"
"fmt"
- "os"
"code.gitea.io/gitea/modules/git/gitcmd"
"code.gitea.io/gitea/modules/log"
@@ -21,22 +20,15 @@ type TemplateSubmoduleCommit struct {
// GetTemplateSubmoduleCommits returns a list of submodules paths and their commits from a repository
// This function is only for generating new repos based on existing template, the template couldn't be too large.
func GetTemplateSubmoduleCommits(ctx context.Context, repoPath string) (submoduleCommits []TemplateSubmoduleCommit, _ error) {
- stdoutReader, stdoutWriter, err := os.Pipe()
- if err != nil {
- return nil, err
- }
- opts := &gitcmd.RunOpts{
- Dir: repoPath,
- Stdout: stdoutWriter,
- PipelineFunc: func(ctx context.Context, cancel context.CancelFunc) error {
- _ = stdoutWriter.Close()
- defer stdoutReader.Close()
-
+ cmd := gitcmd.NewCommand("ls-tree", "-r", "--", "HEAD")
+ stdoutReader, stdoutReaderClose := cmd.MakeStdoutPipe()
+ defer stdoutReaderClose()
+ err := cmd.WithDir(repoPath).
+ WithPipelineFunc(func(ctx gitcmd.Context) error {
scanner := bufio.NewScanner(stdoutReader)
for scanner.Scan() {
entry, err := parseLsTreeLine(scanner.Bytes())
if err != nil {
- cancel()
return err
}
if entry.EntryMode == EntryModeCommit {
@@ -44,9 +36,8 @@ func GetTemplateSubmoduleCommits(ctx context.Context, repoPath string) (submodul
}
}
return scanner.Err()
- },
- }
- err = gitcmd.NewCommand("ls-tree", "-r", "--", "HEAD").Run(ctx, opts)
+ }).
+ Run(ctx)
if err != nil {
return nil, fmt.Errorf("GetTemplateSubmoduleCommits: error running git ls-tree: %v", err)
}
@@ -58,7 +49,7 @@ func GetTemplateSubmoduleCommits(ctx context.Context, repoPath string) (submodul
func AddTemplateSubmoduleIndexes(ctx context.Context, repoPath string, submodules []TemplateSubmoduleCommit) error {
for _, submodule := range submodules {
cmd := gitcmd.NewCommand("update-index", "--add", "--cacheinfo", "160000").AddDynamicArguments(submodule.Commit, submodule.Path)
- if stdout, _, err := cmd.RunStdString(ctx, &gitcmd.RunOpts{Dir: repoPath}); err != nil {
+ if stdout, _, err := cmd.WithDir(repoPath).RunStdString(ctx); err != nil {
log.Error("Unable to add %s as submodule to repo %s: stdout %s\nError: %v", submodule.Path, repoPath, stdout, err)
return err
}
diff --git a/modules/git/submodule_test.go b/modules/git/submodule_test.go
index d2df8b2a91..22bd5bf71e 100644
--- a/modules/git/submodule_test.go
+++ b/modules/git/submodule_test.go
@@ -32,14 +32,14 @@ func TestAddTemplateSubmoduleIndexes(t *testing.T) {
ctx := t.Context()
tmpDir := t.TempDir()
var err error
- _, _, err = gitcmd.NewCommand("init").RunStdString(ctx, &gitcmd.RunOpts{Dir: tmpDir})
+ _, _, err = gitcmd.NewCommand("init").WithDir(tmpDir).RunStdString(ctx)
require.NoError(t, err)
_ = os.Mkdir(filepath.Join(tmpDir, "new-dir"), 0o755)
err = AddTemplateSubmoduleIndexes(ctx, tmpDir, []TemplateSubmoduleCommit{{Path: "new-dir", Commit: "1234567890123456789012345678901234567890"}})
require.NoError(t, err)
- _, _, err = gitcmd.NewCommand("add", "--all").RunStdString(ctx, &gitcmd.RunOpts{Dir: tmpDir})
+ _, _, err = gitcmd.NewCommand("add", "--all").WithDir(tmpDir).RunStdString(ctx)
require.NoError(t, err)
- _, _, err = gitcmd.NewCommand("-c", "user.name=a", "-c", "user.email=b", "commit", "-m=test").RunStdString(ctx, &gitcmd.RunOpts{Dir: tmpDir})
+ _, _, err = gitcmd.NewCommand("-c", "user.name=a", "-c", "user.email=b", "commit", "-m=test").WithDir(tmpDir).RunStdString(ctx)
require.NoError(t, err)
submodules, err := GetTemplateSubmoduleCommits(t.Context(), tmpDir)
require.NoError(t, err)
diff --git a/modules/git/tree.go b/modules/git/tree.go
index a8c4929c7c..c1898b20cb 100644
--- a/modules/git/tree.go
+++ b/modules/git/tree.go
@@ -11,11 +11,21 @@ import (
"code.gitea.io/gitea/modules/git/gitcmd"
)
+type TreeCommon struct {
+ ID ObjectID
+ ResolvedID ObjectID
+
+ repo *Repository
+ ptree *Tree // parent tree
+}
+
// NewTree create a new tree according the repository and tree id
func NewTree(repo *Repository, id ObjectID) *Tree {
return &Tree{
- ID: id,
- repo: repo,
+ TreeCommon: TreeCommon{
+ ID: id,
+ repo: repo,
+ },
}
}
@@ -53,7 +63,7 @@ func (repo *Repository) LsTree(ref string, filenames ...string) ([]string, error
cmd := gitcmd.NewCommand("ls-tree", "-z", "--name-only").
AddDashesAndList(append([]string{ref}, filenames...)...)
- res, _, err := cmd.RunStdBytes(repo.Ctx, &gitcmd.RunOpts{Dir: repo.Path})
+ res, _, err := cmd.WithDir(repo.Path).RunStdBytes(repo.Ctx)
if err != nil {
return nil, err
}
@@ -69,7 +79,8 @@ func (repo *Repository) LsTree(ref string, filenames ...string) ([]string, error
func (repo *Repository) GetTreePathLatestCommit(refName, treePath string) (*Commit, error) {
stdout, _, err := gitcmd.NewCommand("rev-list", "-1").
AddDynamicArguments(refName).AddDashesAndList(treePath).
- RunStdString(repo.Ctx, &gitcmd.RunOpts{Dir: repo.Path})
+ WithDir(repo.Path).
+ RunStdString(repo.Ctx)
if err != nil {
return nil, err
}
diff --git a/modules/git/tree_blob_gogit.go b/modules/git/tree_blob_gogit.go
index f29e8f8b9e..2c0ff0e1b0 100644
--- a/modules/git/tree_blob_gogit.go
+++ b/modules/git/tree_blob_gogit.go
@@ -11,22 +11,16 @@ import (
"strings"
"github.com/go-git/go-git/v5/plumbing"
- "github.com/go-git/go-git/v5/plumbing/filemode"
- "github.com/go-git/go-git/v5/plumbing/object"
)
// GetTreeEntryByPath get the tree entries according the sub dir
func (t *Tree) GetTreeEntryByPath(relpath string) (*TreeEntry, error) {
if len(relpath) == 0 {
return &TreeEntry{
- ID: t.ID,
- // Type: ObjectTree,
- ptree: t,
- gogitTreeEntry: &object.TreeEntry{
- Name: "",
- Mode: filemode.Dir,
- Hash: plumbing.Hash(t.ID.RawValue()),
- },
+ ID: t.ID,
+ ptree: t,
+ name: "",
+ entryMode: EntryModeTree,
}, nil
}
diff --git a/modules/git/tree_entry.go b/modules/git/tree_entry.go
index 5099d8ee79..e7e4ea2d5b 100644
--- a/modules/git/tree_entry.go
+++ b/modules/git/tree_entry.go
@@ -6,12 +6,60 @@ package git
import (
"path"
- "sort"
+ "slices"
"strings"
"code.gitea.io/gitea/modules/util"
)
+// TreeEntry the leaf in the git tree
+type TreeEntry struct {
+ ID ObjectID
+
+ name string
+ ptree *Tree
+
+ entryMode EntryMode
+
+ size int64
+ sized bool
+}
+
+// Name returns the name of the entry (base name)
+func (te *TreeEntry) Name() string {
+ return te.name
+}
+
+// Mode returns the mode of the entry
+func (te *TreeEntry) Mode() EntryMode {
+ return te.entryMode
+}
+
+// IsSubModule if the entry is a submodule
+func (te *TreeEntry) IsSubModule() bool {
+ return te.entryMode.IsSubModule()
+}
+
+// IsDir if the entry is a sub dir
+func (te *TreeEntry) IsDir() bool {
+ return te.entryMode.IsDir()
+}
+
+// IsLink if the entry is a symlink
+func (te *TreeEntry) IsLink() bool {
+ return te.entryMode.IsLink()
+}
+
+// IsRegular if the entry is a regular file
+func (te *TreeEntry) IsRegular() bool {
+ return te.entryMode.IsRegular()
+}
+
+// IsExecutable if the entry is an executable file (not necessarily binary)
+func (te *TreeEntry) IsExecutable() bool {
+ return te.entryMode.IsExecutable()
+}
+
// Type returns the type of the entry (commit, tree, blob)
func (te *TreeEntry) Type() string {
switch te.Mode() {
@@ -109,49 +157,16 @@ func (te *TreeEntry) GetSubJumpablePathName() string {
// Entries a list of entry
type Entries []*TreeEntry
-type customSortableEntries struct {
- Comparer func(s1, s2 string) bool
- Entries
-}
-
-var sorter = []func(t1, t2 *TreeEntry, cmp func(s1, s2 string) bool) bool{
- func(t1, t2 *TreeEntry, cmp func(s1, s2 string) bool) bool {
- return (t1.IsDir() || t1.IsSubModule()) && !t2.IsDir() && !t2.IsSubModule()
- },
- func(t1, t2 *TreeEntry, cmp func(s1, s2 string) bool) bool {
- return cmp(t1.Name(), t2.Name())
- },
-}
-
-func (ctes customSortableEntries) Len() int { return len(ctes.Entries) }
-
-func (ctes customSortableEntries) Swap(i, j int) {
- ctes.Entries[i], ctes.Entries[j] = ctes.Entries[j], ctes.Entries[i]
-}
-
-func (ctes customSortableEntries) Less(i, j int) bool {
- t1, t2 := ctes.Entries[i], ctes.Entries[j]
- var k int
- for k = 0; k < len(sorter)-1; k++ {
- s := sorter[k]
- switch {
- case s(t1, t2, ctes.Comparer):
- return true
- case s(t2, t1, ctes.Comparer):
- return false
- }
- }
- return sorter[k](t1, t2, ctes.Comparer)
-}
-
-// Sort sort the list of entry
-func (tes Entries) Sort() {
- sort.Sort(customSortableEntries{func(s1, s2 string) bool {
- return s1 < s2
- }, tes})
-}
-
// CustomSort customizable string comparing sort entry list
-func (tes Entries) CustomSort(cmp func(s1, s2 string) bool) {
- sort.Sort(customSortableEntries{cmp, tes})
+func (tes Entries) CustomSort(cmp func(s1, s2 string) int) {
+ slices.SortFunc(tes, func(a, b *TreeEntry) int {
+ s1Dir, s2Dir := a.IsDir() || a.IsSubModule(), b.IsDir() || b.IsSubModule()
+ if s1Dir != s2Dir {
+ if s1Dir {
+ return -1
+ }
+ return 1
+ }
+ return cmp(a.Name(), b.Name())
+ })
}
diff --git a/modules/git/tree_entry_gogit_test.go b/modules/git/tree_entry_gogit_test.go
new file mode 100644
index 0000000000..ed14b45e9e
--- /dev/null
+++ b/modules/git/tree_entry_gogit_test.go
@@ -0,0 +1,27 @@
+// Copyright 2025 The Gitea Authors. All rights reserved.
+// SPDX-License-Identifier: MIT
+
+//go:build gogit
+
+package git
+
+import (
+ "testing"
+
+ "github.com/go-git/go-git/v5/plumbing/filemode"
+ "github.com/stretchr/testify/assert"
+)
+
+func TestEntryGogit(t *testing.T) {
+ cases := map[EntryMode]filemode.FileMode{
+ EntryModeBlob: filemode.Regular,
+ EntryModeCommit: filemode.Submodule,
+ EntryModeExec: filemode.Executable,
+ EntryModeSymlink: filemode.Symlink,
+ EntryModeTree: filemode.Dir,
+ }
+ for emode, fmode := range cases {
+ assert.EqualValues(t, fmode, entryModeToGogitFileMode(emode))
+ assert.EqualValues(t, emode, gogitFileModeToEntryMode(fmode))
+ }
+}
diff --git a/modules/git/tree_entry_mode.go b/modules/git/tree_entry_mode.go
index f36c07bc2a..2ceba11374 100644
--- a/modules/git/tree_entry_mode.go
+++ b/modules/git/tree_entry_mode.go
@@ -4,7 +4,6 @@
package git
import (
- "fmt"
"strconv"
)
@@ -55,21 +54,38 @@ func (e EntryMode) IsExecutable() bool {
return e == EntryModeExec
}
-func ParseEntryMode(mode string) (EntryMode, error) {
+func ParseEntryMode(mode string) EntryMode {
switch mode {
case "000000":
- return EntryModeNoEntry, nil
+ return EntryModeNoEntry
case "100644":
- return EntryModeBlob, nil
+ return EntryModeBlob
case "100755":
- return EntryModeExec, nil
+ return EntryModeExec
case "120000":
- return EntryModeSymlink, nil
+ return EntryModeSymlink
case "160000":
- return EntryModeCommit, nil
- case "040000", "040755": // git uses 040000 for tree object, but some users may get 040755 for unknown reasons
- return EntryModeTree, nil
+ return EntryModeCommit
+ case "040000":
+ return EntryModeTree
default:
- return 0, fmt.Errorf("unparsable entry mode: %s", mode)
+ // git uses 040000 for tree object, but some users may get 040755 from non-standard git implementations
+ m, _ := strconv.ParseInt(mode, 8, 32)
+ modeInt := EntryMode(m)
+ switch modeInt & 0o770000 {
+ case 0o040000:
+ return EntryModeTree
+ case 0o160000:
+ return EntryModeCommit
+ case 0o120000:
+ return EntryModeSymlink
+ case 0o100000:
+ if modeInt&0o777 == 0o755 {
+ return EntryModeExec
+ }
+ return EntryModeBlob
+ default:
+ return EntryModeNoEntry
+ }
}
}
diff --git a/modules/git/tree_entry_nogogit.go b/modules/git/tree_entry_nogogit.go
index 8fad96cdf8..0a19b38d3e 100644
--- a/modules/git/tree_entry_nogogit.go
+++ b/modules/git/tree_entry_nogogit.go
@@ -7,27 +7,6 @@ package git
import "code.gitea.io/gitea/modules/log"
-// TreeEntry the leaf in the git tree
-type TreeEntry struct {
- ID ObjectID
- ptree *Tree
-
- entryMode EntryMode
- name string
- size int64
- sized bool
-}
-
-// Name returns the name of the entry (base name)
-func (te *TreeEntry) Name() string {
- return te.name
-}
-
-// Mode returns the mode of the entry
-func (te *TreeEntry) Mode() EntryMode {
- return te.entryMode
-}
-
// Size returns the size of the entry
func (te *TreeEntry) Size() int64 {
if te.IsDir() {
@@ -36,52 +15,23 @@ func (te *TreeEntry) Size() int64 {
return te.size
}
- wr, rd, cancel, err := te.ptree.repo.CatFileBatchCheck(te.ptree.repo.Ctx)
+ batch, cancel, err := te.ptree.repo.CatFileBatch(te.ptree.repo.Ctx)
if err != nil {
log.Debug("error whilst reading size for %s in %s. Error: %v", te.ID.String(), te.ptree.repo.Path, err)
return 0
}
defer cancel()
- _, err = wr.Write([]byte(te.ID.String() + "\n"))
- if err != nil {
- log.Debug("error whilst reading size for %s in %s. Error: %v", te.ID.String(), te.ptree.repo.Path, err)
- return 0
- }
- _, _, te.size, err = ReadBatchLine(rd)
+ info, err := batch.QueryInfo(te.ID.String())
if err != nil {
log.Debug("error whilst reading size for %s in %s. Error: %v", te.ID.String(), te.ptree.repo.Path, err)
return 0
}
+ te.size = info.Size
te.sized = true
return te.size
}
-// IsSubModule if the entry is a submodule
-func (te *TreeEntry) IsSubModule() bool {
- return te.entryMode.IsSubModule()
-}
-
-// IsDir if the entry is a sub dir
-func (te *TreeEntry) IsDir() bool {
- return te.entryMode.IsDir()
-}
-
-// IsLink if the entry is a symlink
-func (te *TreeEntry) IsLink() bool {
- return te.entryMode.IsLink()
-}
-
-// IsRegular if the entry is a regular file
-func (te *TreeEntry) IsRegular() bool {
- return te.entryMode.IsRegular()
-}
-
-// IsExecutable if the entry is an executable file (not necessarily binary)
-func (te *TreeEntry) IsExecutable() bool {
- return te.entryMode.IsExecutable()
-}
-
// Blob returns the blob object the entry
func (te *TreeEntry) Blob() *Blob {
return &Blob{
diff --git a/modules/git/tree_entry_test.go b/modules/git/tree_entry_test.go
index 9ca82675e0..3df6eeab68 100644
--- a/modules/git/tree_entry_test.go
+++ b/modules/git/tree_entry_test.go
@@ -1,55 +1,57 @@
// Copyright 2017 The Gitea Authors. All rights reserved.
// SPDX-License-Identifier: MIT
-//go:build gogit
-
package git
import (
+ "math/rand/v2"
+ "slices"
+ "strings"
"testing"
- "github.com/go-git/go-git/v5/plumbing/filemode"
- "github.com/go-git/go-git/v5/plumbing/object"
"github.com/stretchr/testify/assert"
)
-func getTestEntries() Entries {
- return Entries{
- &TreeEntry{gogitTreeEntry: &object.TreeEntry{Name: "v1.0", Mode: filemode.Dir}},
- &TreeEntry{gogitTreeEntry: &object.TreeEntry{Name: "v2.0", Mode: filemode.Dir}},
- &TreeEntry{gogitTreeEntry: &object.TreeEntry{Name: "v2.1", Mode: filemode.Dir}},
- &TreeEntry{gogitTreeEntry: &object.TreeEntry{Name: "v2.12", Mode: filemode.Dir}},
- &TreeEntry{gogitTreeEntry: &object.TreeEntry{Name: "v2.2", Mode: filemode.Dir}},
- &TreeEntry{gogitTreeEntry: &object.TreeEntry{Name: "v12.0", Mode: filemode.Dir}},
- &TreeEntry{gogitTreeEntry: &object.TreeEntry{Name: "abc", Mode: filemode.Regular}},
- &TreeEntry{gogitTreeEntry: &object.TreeEntry{Name: "bcd", Mode: filemode.Regular}},
+func TestEntriesCustomSort(t *testing.T) {
+ entries := Entries{
+ &TreeEntry{name: "a-dir", entryMode: EntryModeTree},
+ &TreeEntry{name: "a-submodule", entryMode: EntryModeCommit},
+ &TreeEntry{name: "b-dir", entryMode: EntryModeTree},
+ &TreeEntry{name: "b-submodule", entryMode: EntryModeCommit},
+ &TreeEntry{name: "a-file", entryMode: EntryModeBlob},
+ &TreeEntry{name: "b-file", entryMode: EntryModeBlob},
+ }
+ expected := slices.Clone(entries)
+ for slices.Equal(expected, entries) {
+ rand.Shuffle(len(entries), func(i, j int) { entries[i], entries[j] = entries[j], entries[i] })
}
+ entries.CustomSort(strings.Compare)
+ assert.Equal(t, expected, entries)
}
-func TestEntriesSort(t *testing.T) {
- entries := getTestEntries()
- entries.Sort()
- assert.Equal(t, "v1.0", entries[0].Name())
- assert.Equal(t, "v12.0", entries[1].Name())
- assert.Equal(t, "v2.0", entries[2].Name())
- assert.Equal(t, "v2.1", entries[3].Name())
- assert.Equal(t, "v2.12", entries[4].Name())
- assert.Equal(t, "v2.2", entries[5].Name())
- assert.Equal(t, "abc", entries[6].Name())
- assert.Equal(t, "bcd", entries[7].Name())
-}
+func TestParseEntryMode(t *testing.T) {
+ tests := []struct {
+ modeStr string
+ expectMod EntryMode
+ }{
+ {"000000", EntryModeNoEntry},
+ {"000755", EntryModeNoEntry},
-func TestEntriesCustomSort(t *testing.T) {
- entries := getTestEntries()
- entries.CustomSort(func(s1, s2 string) bool {
- return s1 > s2
- })
- assert.Equal(t, "v2.2", entries[0].Name())
- assert.Equal(t, "v2.12", entries[1].Name())
- assert.Equal(t, "v2.1", entries[2].Name())
- assert.Equal(t, "v2.0", entries[3].Name())
- assert.Equal(t, "v12.0", entries[4].Name())
- assert.Equal(t, "v1.0", entries[5].Name())
- assert.Equal(t, "bcd", entries[6].Name())
- assert.Equal(t, "abc", entries[7].Name())
+ {"100644", EntryModeBlob},
+ {"100755", EntryModeExec},
+
+ {"120000", EntryModeSymlink},
+ {"120755", EntryModeSymlink},
+ {"160000", EntryModeCommit},
+ {"160755", EntryModeCommit},
+
+ {"040000", EntryModeTree},
+ {"040755", EntryModeTree},
+
+ {"777777", EntryModeNoEntry}, // invalid mode
+ }
+ for _, test := range tests {
+ mod := ParseEntryMode(test.modeStr)
+ assert.Equal(t, test.expectMod, mod, "modeStr: %s", test.modeStr)
+ }
}
diff --git a/modules/git/tree_nogogit.go b/modules/git/tree_nogogit.go
index 045d78c42c..5d951dad0d 100644
--- a/modules/git/tree_nogogit.go
+++ b/modules/git/tree_nogogit.go
@@ -14,18 +14,10 @@ import (
// Tree represents a flat directory listing.
type Tree struct {
- ID ObjectID
- ResolvedID ObjectID
- repo *Repository
-
- // parent tree
- ptree *Tree
+ TreeCommon
entries Entries
entriesParsed bool
-
- entriesRecursive Entries
- entriesRecursiveParsed bool
}
// ListEntries returns all entries of current tree.
@@ -35,30 +27,29 @@ func (t *Tree) ListEntries() (Entries, error) {
}
if t.repo != nil {
- wr, rd, cancel, err := t.repo.CatFileBatch(t.repo.Ctx)
+ batch, cancel, err := t.repo.CatFileBatch(t.repo.Ctx)
if err != nil {
return nil, err
}
defer cancel()
- _, _ = wr.Write([]byte(t.ID.String() + "\n"))
- _, typ, sz, err := ReadBatchLine(rd)
+ info, rd, err := batch.QueryContent(t.ID.String())
if err != nil {
return nil, err
}
- if typ == "commit" {
- treeID, err := ReadTreeID(rd, sz)
+
+ if info.Type == "commit" {
+ treeID, err := ReadTreeID(rd, info.Size)
if err != nil && err != io.EOF {
return nil, err
}
- _, _ = wr.Write([]byte(treeID + "\n"))
- _, typ, sz, err = ReadBatchLine(rd)
+ info, rd, err = batch.QueryContent(treeID)
if err != nil {
return nil, err
}
}
- if typ == "tree" {
- t.entries, err = catBatchParseTreeEntries(t.ID.Type(), t, rd, sz)
+ if info.Type == "tree" {
+ t.entries, err = catBatchParseTreeEntries(t.ID.Type(), t, rd, info.Size)
if err != nil {
return nil, err
}
@@ -67,14 +58,14 @@ func (t *Tree) ListEntries() (Entries, error) {
}
// Not a tree just use ls-tree instead
- if err := DiscardFull(rd, sz+1); err != nil {
+ if err := DiscardFull(rd, info.Size+1); err != nil {
return nil, err
}
}
- stdout, _, runErr := gitcmd.NewCommand("ls-tree", "-l").AddDynamicArguments(t.ID.String()).RunStdBytes(t.repo.Ctx, &gitcmd.RunOpts{Dir: t.repo.Path})
+ stdout, _, runErr := gitcmd.NewCommand("ls-tree", "-l").AddDynamicArguments(t.ID.String()).WithDir(t.repo.Path).RunStdBytes(t.repo.Ctx)
if runErr != nil {
- if strings.Contains(runErr.Error(), "fatal: Not a valid object name") || strings.Contains(runErr.Error(), "fatal: not a tree object") {
+ if gitcmd.IsStdErrorNotValidObjectName(runErr) || strings.Contains(runErr.Error(), "fatal: not a tree object") {
return nil, ErrNotExist{
ID: t.ID.String(),
}
@@ -94,25 +85,18 @@ func (t *Tree) ListEntries() (Entries, error) {
// listEntriesRecursive returns all entries of current tree recursively including all subtrees
// extraArgs could be "-l" to get the size, which is slower
func (t *Tree) listEntriesRecursive(extraArgs gitcmd.TrustedCmdArgs) (Entries, error) {
- if t.entriesRecursiveParsed {
- return t.entriesRecursive, nil
- }
-
stdout, _, runErr := gitcmd.NewCommand("ls-tree", "-t", "-r").
AddArguments(extraArgs...).
AddDynamicArguments(t.ID.String()).
- RunStdBytes(t.repo.Ctx, &gitcmd.RunOpts{Dir: t.repo.Path})
+ WithDir(t.repo.Path).
+ RunStdBytes(t.repo.Ctx)
if runErr != nil {
return nil, runErr
}
- var err error
- t.entriesRecursive, err = parseTreeEntries(stdout, t)
- if err == nil {
- t.entriesRecursiveParsed = true
- }
-
- return t.entriesRecursive, err
+ // FIXME: the "name" field is abused, here it is a full path
+ // FIXME: this ptree is not right, fortunately it isn't really used
+ return parseTreeEntries(stdout, t)
}
// ListEntriesRecursiveFast returns all entries of current tree recursively including all subtrees, no size
diff --git a/modules/gitrepo/archive.go b/modules/gitrepo/archive.go
new file mode 100644
index 0000000000..191a1bd2c0
--- /dev/null
+++ b/modules/gitrepo/archive.go
@@ -0,0 +1,80 @@
+// Copyright 2025 The Gitea Authors. All rights reserved.
+// SPDX-License-Identifier: MIT
+
+package gitrepo
+
+import (
+ "context"
+ "fmt"
+ "io"
+ "os"
+ "path"
+ "path/filepath"
+ "slices"
+ "strings"
+
+ "code.gitea.io/gitea/modules/git/gitcmd"
+ "code.gitea.io/gitea/modules/setting"
+)
+
+// CreateArchive create archive content to the target path
+func CreateArchive(ctx context.Context, repo Repository, format string, target io.Writer, usePrefix bool, commitID string, paths []string) error {
+ if format == "unknown" {
+ return fmt.Errorf("unknown format: %v", format)
+ }
+
+ cmd := gitcmd.NewCommand("archive")
+ if usePrefix {
+ cmd.AddOptionFormat("--prefix=%s", filepath.Base(strings.TrimSuffix(repo.RelativePath(), ".git"))+"/")
+ }
+ cmd.AddOptionFormat("--format=%s", format)
+ cmd.AddDynamicArguments(commitID)
+
+ paths = slices.Clone(paths)
+ for i := range paths {
+ // although "git archive" already ensures the paths won't go outside the repo, we still clean them here for safety
+ paths[i] = path.Clean(paths[i])
+ }
+ cmd.AddDynamicArguments(paths...)
+ return RunCmdWithStderr(ctx, repo, cmd.WithStdoutCopy(target))
+}
+
+// CreateBundle create bundle content to the target path
+func CreateBundle(ctx context.Context, repo Repository, commit string, out io.Writer) error {
+ tmp, cleanup, err := setting.AppDataTempDir("git-repo-content").MkdirTempRandom("gitea-bundle")
+ if err != nil {
+ return err
+ }
+ defer cleanup()
+
+ env := append(os.Environ(), "GIT_OBJECT_DIRECTORY="+filepath.Join(repoPath(repo), "objects"))
+ _, _, err = gitcmd.NewCommand("init", "--bare").WithDir(tmp).WithEnv(env).RunStdString(ctx)
+ if err != nil {
+ return err
+ }
+
+ _, _, err = gitcmd.NewCommand("reset", "--soft").AddDynamicArguments(commit).WithDir(tmp).WithEnv(env).RunStdString(ctx)
+ if err != nil {
+ return err
+ }
+
+ _, _, err = gitcmd.NewCommand("branch", "-m", "bundle").WithDir(tmp).WithEnv(env).RunStdString(ctx)
+ if err != nil {
+ return err
+ }
+
+ tmpFile := filepath.Join(tmp, "bundle")
+ _, _, err = gitcmd.NewCommand("bundle", "create").AddDynamicArguments(tmpFile, "bundle", "HEAD").WithDir(tmp).WithEnv(env).RunStdString(ctx)
+ if err != nil {
+ return err
+ }
+
+ fi, err := os.Open(tmpFile)
+ if err != nil {
+ return err
+ }
+ defer fi.Close()
+
+ _, err = io.Copy(out, fi)
+ return err
+}
diff --git a/modules/git/blame.go b/modules/gitrepo/blame.go
similarity index 70%
rename from modules/git/blame.go
rename to modules/gitrepo/blame.go
index 50cadc41c2..2352da1760 100644
--- a/modules/git/blame.go
+++ b/modules/gitrepo/blame.go
@@ -1,20 +1,28 @@
-// Copyright 2019 The Gitea Authors. All rights reserved.
+// Copyright 2025 The Gitea Authors. All rights reserved.
// SPDX-License-Identifier: MIT
-package git
+package gitrepo
import (
"bufio"
"bytes"
"context"
"io"
- "os"
+ "code.gitea.io/gitea/modules/git"
"code.gitea.io/gitea/modules/git/gitcmd"
- "code.gitea.io/gitea/modules/log"
"code.gitea.io/gitea/modules/setting"
)
+func LineBlame(ctx context.Context, repo Repository, revision, file string, line uint) (string, error) {
+ stdout, _, err := RunCmdString(ctx, repo,
+ gitcmd.NewCommand("blame").
+ AddOptionFormat("-L %d,%d", line, line).
+ AddOptionValues("-p", revision).
+ AddDashesAndList(file))
+ return stdout, err
+}
+
// BlamePart represents block of blame - continuous lines with one sha
type BlamePart struct {
Sha string
@@ -25,13 +33,11 @@ type BlamePart struct {
// BlameReader returns part of file blame one by one
type BlameReader struct {
- output io.WriteCloser
- reader io.ReadCloser
bufferedReader *bufio.Reader
done chan error
lastSha *string
ignoreRevsFile string
- objectFormat ObjectFormat
+ objectFormat git.ObjectFormat
cleanupFuncs []func()
}
@@ -122,34 +128,42 @@ func (r *BlameReader) Close() error {
err := <-r.done
r.bufferedReader = nil
- _ = r.reader.Close()
- _ = r.output.Close()
+ r.cleanup()
+ return err
+}
+
+func (r *BlameReader) cleanup() {
for _, cleanup := range r.cleanupFuncs {
- if cleanup != nil {
- cleanup()
- }
+ cleanup()
}
- return err
}
// CreateBlameReader creates reader for given repository, commit and file
-func CreateBlameReader(ctx context.Context, objectFormat ObjectFormat, repoPath string, commit *Commit, file string, bypassBlameIgnore bool) (rd *BlameReader, err error) {
- var ignoreRevsFileName string
- var ignoreRevsFileCleanup func()
+func CreateBlameReader(ctx context.Context, objectFormat git.ObjectFormat, repo Repository, commit *git.Commit, file string, bypassBlameIgnore bool) (rd *BlameReader, retErr error) {
defer func() {
- if err != nil && ignoreRevsFileCleanup != nil {
- ignoreRevsFileCleanup()
+ if retErr != nil {
+ rd.cleanup()
}
}()
+ rd = &BlameReader{
+ done: make(chan error, 1),
+ objectFormat: objectFormat,
+ }
+
cmd := gitcmd.NewCommand("blame", "--porcelain")
- if DefaultFeatures().CheckVersionAtLeast("2.23") && !bypassBlameIgnore {
- ignoreRevsFileName, ignoreRevsFileCleanup, err = tryCreateBlameIgnoreRevsFile(commit)
- if err != nil && !IsErrNotExist(err) {
+ stdoutReader, stdoutReaderClose := cmd.MakeStdoutPipe()
+ rd.bufferedReader = bufio.NewReader(stdoutReader)
+ rd.cleanupFuncs = append(rd.cleanupFuncs, stdoutReaderClose)
+
+ if git.DefaultFeatures().CheckVersionAtLeast("2.23") && !bypassBlameIgnore {
+ ignoreRevsFileName, ignoreRevsFileCleanup, err := tryCreateBlameIgnoreRevsFile(commit)
+ if err != nil && !git.IsErrNotExist(err) {
return nil, err
- }
- if ignoreRevsFileName != "" {
+ } else if err == nil {
+ rd.ignoreRevsFile = ignoreRevsFileName
+ rd.cleanupFuncs = append(rd.cleanupFuncs, ignoreRevsFileCleanup)
// Possible improvement: use --ignore-revs-file /dev/stdin on unix
// There is no equivalent on Windows. May be implemented if Gitea uses an external git backend.
cmd.AddOptionValues("--ignore-revs-file", ignoreRevsFileName)
@@ -158,40 +172,15 @@ func CreateBlameReader(ctx context.Context, objectFormat ObjectFormat, repoPath
cmd.AddDynamicArguments(commit.ID.String()).AddDashesAndList(file)
- done := make(chan error, 1)
- reader, stdout, err := os.Pipe()
- if err != nil {
- return nil, err
- }
go func() {
- stderr := bytes.Buffer{}
// TODO: it doesn't work for directories (the directories shouldn't be "blamed"), and the "err" should be returned by "Read" but not by "Close"
- err := cmd.Run(ctx, &gitcmd.RunOpts{
- UseContextTimeout: true,
- Dir: repoPath,
- Stdout: stdout,
- Stderr: &stderr,
- })
- done <- err
- _ = stdout.Close()
- if err != nil {
- log.Error("Error running git blame (dir: %v): %v, stderr: %v", repoPath, err, stderr.String())
- }
+ rd.done <- RunCmdWithStderr(ctx, repo, cmd)
}()
- bufferedReader := bufio.NewReader(reader)
- return &BlameReader{
- output: stdout,
- reader: reader,
- bufferedReader: bufferedReader,
- done: done,
- ignoreRevsFile: ignoreRevsFileName,
- objectFormat: objectFormat,
- cleanupFuncs: []func(){ignoreRevsFileCleanup},
- }, nil
+ return rd, nil
}
-func tryCreateBlameIgnoreRevsFile(commit *Commit) (string, func(), error) {
+func tryCreateBlameIgnoreRevsFile(commit *git.Commit) (string, func(), error) {
entry, err := commit.GetTreeEntryByPath(".git-blame-ignore-revs")
if err != nil {
return "", nil, err
diff --git a/modules/git/blame_sha256_test.go b/modules/gitrepo/blame_sha256_test.go
similarity index 88%
rename from modules/git/blame_sha256_test.go
rename to modules/gitrepo/blame_sha256_test.go
index c0a97bed3b..e92931d596 100644
--- a/modules/git/blame_sha256_test.go
+++ b/modules/gitrepo/blame_sha256_test.go
@@ -1,12 +1,13 @@
// Copyright 2024 The Gitea Authors. All rights reserved.
// SPDX-License-Identifier: MIT
-package git
+package gitrepo
import (
"context"
"testing"
+ "code.gitea.io/gitea/modules/git"
"code.gitea.io/gitea/modules/setting"
"github.com/stretchr/testify/assert"
@@ -17,13 +18,14 @@ func TestReadingBlameOutputSha256(t *testing.T) {
ctx, cancel := context.WithCancel(t.Context())
defer cancel()
- if isGogit {
+ if git.DefaultFeatures().UsingGogit {
t.Skip("Skipping test since gogit does not support sha256")
return
}
t.Run("Without .git-blame-ignore-revs", func(t *testing.T) {
- repo, err := OpenRepository(ctx, "./tests/repos/repo5_pulls_sha256")
+ storage := &mockRepository{path: "repo5_pulls_sha256"}
+ repo, err := OpenRepository(ctx, storage)
assert.NoError(t, err)
defer repo.Close()
@@ -47,7 +49,7 @@ func TestReadingBlameOutputSha256(t *testing.T) {
}
for _, bypass := range []bool{false, true} {
- blameReader, err := CreateBlameReader(ctx, Sha256ObjectFormat, "./tests/repos/repo5_pulls_sha256", commit, "README.md", bypass)
+ blameReader, err := CreateBlameReader(ctx, git.Sha256ObjectFormat, storage, commit, "README.md", bypass)
assert.NoError(t, err)
assert.NotNil(t, blameReader)
defer blameReader.Close()
@@ -68,7 +70,8 @@ func TestReadingBlameOutputSha256(t *testing.T) {
})
t.Run("With .git-blame-ignore-revs", func(t *testing.T) {
- repo, err := OpenRepository(ctx, "./tests/repos/repo6_blame_sha256")
+ storage := &mockRepository{path: "repo6_blame_sha256"}
+ repo, err := OpenRepository(ctx, storage)
assert.NoError(t, err)
defer repo.Close()
@@ -131,7 +134,7 @@ func TestReadingBlameOutputSha256(t *testing.T) {
for _, c := range cases {
commit, err := repo.GetCommit(c.CommitID)
assert.NoError(t, err)
- blameReader, err := CreateBlameReader(ctx, objectFormat, "./tests/repos/repo6_blame_sha256", commit, "blame.txt", c.Bypass)
+ blameReader, err := CreateBlameReader(ctx, objectFormat, storage, commit, "blame.txt", c.Bypass)
assert.NoError(t, err)
assert.NotNil(t, blameReader)
defer blameReader.Close()
diff --git a/modules/git/blame_test.go b/modules/gitrepo/blame_test.go
similarity index 89%
rename from modules/git/blame_test.go
rename to modules/gitrepo/blame_test.go
index 809d6fbcf7..0307a5fd33 100644
--- a/modules/git/blame_test.go
+++ b/modules/gitrepo/blame_test.go
@@ -1,12 +1,13 @@
// Copyright 2019 The Gitea Authors. All rights reserved.
// SPDX-License-Identifier: MIT
-package git
+package gitrepo
import (
"context"
"testing"
+ "code.gitea.io/gitea/modules/git"
"code.gitea.io/gitea/modules/setting"
"github.com/stretchr/testify/assert"
@@ -18,10 +19,10 @@ func TestReadingBlameOutput(t *testing.T) {
defer cancel()
t.Run("Without .git-blame-ignore-revs", func(t *testing.T) {
- repo, err := OpenRepository(ctx, "./tests/repos/repo5_pulls")
+ storage := &mockRepository{path: "repo5_pulls"}
+ repo, err := OpenRepository(ctx, storage)
assert.NoError(t, err)
defer repo.Close()
-
commit, err := repo.GetCommit("f32b0a9dfd09a60f616f29158f772cedd89942d2")
assert.NoError(t, err)
@@ -42,7 +43,7 @@ func TestReadingBlameOutput(t *testing.T) {
}
for _, bypass := range []bool{false, true} {
- blameReader, err := CreateBlameReader(ctx, Sha1ObjectFormat, "./tests/repos/repo5_pulls", commit, "README.md", bypass)
+ blameReader, err := CreateBlameReader(ctx, git.Sha1ObjectFormat, storage, commit, "README.md", bypass)
assert.NoError(t, err)
assert.NotNil(t, blameReader)
defer blameReader.Close()
@@ -63,7 +64,8 @@ func TestReadingBlameOutput(t *testing.T) {
})
t.Run("With .git-blame-ignore-revs", func(t *testing.T) {
- repo, err := OpenRepository(ctx, "./tests/repos/repo6_blame")
+ storage := &mockRepository{path: "repo6_blame"}
+ repo, err := OpenRepository(ctx, storage)
assert.NoError(t, err)
defer repo.Close()
@@ -127,7 +129,7 @@ func TestReadingBlameOutput(t *testing.T) {
commit, err := repo.GetCommit(c.CommitID)
assert.NoError(t, err)
- blameReader, err := CreateBlameReader(ctx, objectFormat, "./tests/repos/repo6_blame", commit, "blame.txt", c.Bypass)
+ blameReader, err := CreateBlameReader(ctx, objectFormat, storage, commit, "blame.txt", c.Bypass)
assert.NoError(t, err)
assert.NotNil(t, blameReader)
defer blameReader.Close()
diff --git a/modules/gitrepo/branch.go b/modules/gitrepo/branch.go
index 4d571f583d..4c40d1fba3 100644
--- a/modules/gitrepo/branch.go
+++ b/modules/gitrepo/branch.go
@@ -5,6 +5,8 @@ package gitrepo
import (
"context"
+ "errors"
+ "strings"
"code.gitea.io/gitea/modules/git"
"code.gitea.io/gitea/modules/git/gitcmd"
@@ -34,23 +36,61 @@ func GetBranchCommitID(ctx context.Context, repo Repository, branch string) (str
// SetDefaultBranch sets default branch of repository.
func SetDefaultBranch(ctx context.Context, repo Repository, name string) error {
- _, _, err := gitcmd.NewCommand("symbolic-ref", "HEAD").
- AddDynamicArguments(git.BranchPrefix+name).
- RunStdString(ctx, &gitcmd.RunOpts{Dir: repoPath(repo)})
+ _, _, err := RunCmdString(ctx, repo, gitcmd.NewCommand("symbolic-ref", "HEAD").
+ AddDynamicArguments(git.BranchPrefix+name))
return err
}
// GetDefaultBranch gets default branch of repository.
func GetDefaultBranch(ctx context.Context, repo Repository) (string, error) {
- return git.GetDefaultBranch(ctx, repoPath(repo))
+ stdout, _, err := RunCmdString(ctx, repo, gitcmd.NewCommand("symbolic-ref", "HEAD"))
+ if err != nil {
+ return "", err
+ }
+ stdout = strings.TrimSpace(stdout)
+ if !strings.HasPrefix(stdout, git.BranchPrefix) {
+ return "", errors.New("the HEAD is not a branch: " + stdout)
+ }
+ return strings.TrimPrefix(stdout, git.BranchPrefix), nil
}
// IsReferenceExist returns true if given reference exists in the repository.
func IsReferenceExist(ctx context.Context, repo Repository, name string) bool {
- return git.IsReferenceExist(ctx, repoPath(repo), name)
+ _, _, err := RunCmdString(ctx, repo, gitcmd.NewCommand("show-ref", "--verify").AddDashesAndList(name))
+ return err == nil
}
// IsBranchExist returns true if given branch exists in the repository.
func IsBranchExist(ctx context.Context, repo Repository, name string) bool {
return IsReferenceExist(ctx, repo, git.BranchPrefix+name)
}
+
+// DeleteBranch delete a branch by name on repository.
+func DeleteBranch(ctx context.Context, repo Repository, name string, force bool) error {
+ cmd := gitcmd.NewCommand("branch")
+
+ if force {
+ cmd.AddArguments("-D")
+ } else {
+ cmd.AddArguments("-d")
+ }
+
+ cmd.AddDashesAndList(name)
+ _, _, err := RunCmdString(ctx, repo, cmd)
+ return err
+}
+
+// CreateBranch create a new branch
+func CreateBranch(ctx context.Context, repo Repository, branch, oldbranchOrCommit string) error {
+ cmd := gitcmd.NewCommand("branch")
+ cmd.AddDashesAndList(branch, oldbranchOrCommit)
+
+ _, _, err := RunCmdString(ctx, repo, cmd)
+ return err
+}
+
+// RenameBranch rename a branch
+func RenameBranch(ctx context.Context, repo Repository, from, to string) error {
+ _, _, err := RunCmdString(ctx, repo, gitcmd.NewCommand("branch", "-m").AddDynamicArguments(from, to))
+ return err
+}
diff --git a/modules/gitrepo/cat_file.go b/modules/gitrepo/cat_file.go
new file mode 100644
index 0000000000..42ca23acde
--- /dev/null
+++ b/modules/gitrepo/cat_file.go
@@ -0,0 +1,14 @@
+// Copyright 2025 The Gitea Authors. All rights reserved.
+// SPDX-License-Identifier: MIT
+
+package gitrepo
+
+import (
+ "context"
+
+ "code.gitea.io/gitea/modules/git"
+)
+
+func NewBatch(ctx context.Context, repo Repository) (git.CatFileBatchCloser, error) {
+ return git.NewBatch(ctx, repoPath(repo))
+}
diff --git a/modules/gitrepo/clone.go b/modules/gitrepo/clone.go
new file mode 100644
index 0000000000..a0e4cc814c
--- /dev/null
+++ b/modules/gitrepo/clone.go
@@ -0,0 +1,24 @@
+// Copyright 2025 The Gitea Authors. All rights reserved.
+// SPDX-License-Identifier: MIT
+
+package gitrepo
+
+import (
+ "context"
+
+ "code.gitea.io/gitea/modules/git"
+)
+
+// CloneExternalRepo clones an external repository to the managed repository.
+func CloneExternalRepo(ctx context.Context, fromRemoteURL string, toRepo Repository, opts git.CloneRepoOptions) error {
+ return git.Clone(ctx, fromRemoteURL, repoPath(toRepo), opts)
+}
+
+// CloneRepoToLocal clones a managed repository to a local path.
+func CloneRepoToLocal(ctx context.Context, fromRepo Repository, toLocalPath string, opts git.CloneRepoOptions) error {
+ return git.Clone(ctx, repoPath(fromRepo), toLocalPath, opts)
+}
+
+func Clone(ctx context.Context, fromRepo, toRepo Repository, opts git.CloneRepoOptions) error {
+ return git.Clone(ctx, repoPath(fromRepo), repoPath(toRepo), opts)
+}
diff --git a/modules/gitrepo/command.go b/modules/gitrepo/command.go
new file mode 100644
index 0000000000..fd21b9a725
--- /dev/null
+++ b/modules/gitrepo/command.go
@@ -0,0 +1,26 @@
+// Copyright 2025 The Gitea Authors. All rights reserved.
+// SPDX-License-Identifier: MIT
+
+package gitrepo
+
+import (
+ "context"
+
+ "code.gitea.io/gitea/modules/git/gitcmd"
+)
+
+func RunCmd(ctx context.Context, repo Repository, cmd *gitcmd.Command) error {
+ return cmd.WithDir(repoPath(repo)).WithParentCallerInfo().Run(ctx)
+}
+
+func RunCmdString(ctx context.Context, repo Repository, cmd *gitcmd.Command) (string, string, gitcmd.RunStdError) {
+ return cmd.WithDir(repoPath(repo)).WithParentCallerInfo().RunStdString(ctx)
+}
+
+func RunCmdBytes(ctx context.Context, repo Repository, cmd *gitcmd.Command) ([]byte, []byte, gitcmd.RunStdError) {
+ return cmd.WithDir(repoPath(repo)).WithParentCallerInfo().RunStdBytes(ctx)
+}
+
+func RunCmdWithStderr(ctx context.Context, repo Repository, cmd *gitcmd.Command) gitcmd.RunStdError {
+ return cmd.WithDir(repoPath(repo)).WithParentCallerInfo().RunWithStderr(ctx)
+}
diff --git a/modules/gitrepo/commit.go b/modules/gitrepo/commit.go
new file mode 100644
index 0000000000..0ab17862fe
--- /dev/null
+++ b/modules/gitrepo/commit.go
@@ -0,0 +1,112 @@
+// Copyright 2025 The Gitea Authors. All rights reserved.
+// SPDX-License-Identifier: MIT
+
+package gitrepo
+
+import (
+ "context"
+ "strconv"
+ "strings"
+ "time"
+
+ "code.gitea.io/gitea/modules/git"
+ "code.gitea.io/gitea/modules/git/gitcmd"
+)
+
+// CommitsCountOptions the options when counting commits
+type CommitsCountOptions struct {
+ Not string
+ Revision []string
+ RelPath []string
+ Since string
+ Until string
+}
+
+// CommitsCount returns number of total commits of until given revision.
+func CommitsCount(ctx context.Context, repo Repository, opts CommitsCountOptions) (int64, error) {
+ cmd := gitcmd.NewCommand("rev-list", "--count")
+
+ cmd.AddDynamicArguments(opts.Revision...)
+
+ if opts.Not != "" {
+ cmd.AddOptionValues("--not", opts.Not)
+ }
+
+ if len(opts.RelPath) > 0 {
+ cmd.AddDashesAndList(opts.RelPath...)
+ }
+
+ stdout, _, err := cmd.WithDir(repoPath(repo)).RunStdString(ctx)
+ if err != nil {
+ return 0, err
+ }
+
+ return strconv.ParseInt(strings.TrimSpace(stdout), 10, 64)
+}
+
+// CommitsCountBetween return numbers of commits between two commits
+func CommitsCountBetween(ctx context.Context, repo Repository, start, end string) (int64, error) {
+ count, err := CommitsCount(ctx, repo, CommitsCountOptions{
+ Revision: []string{start + ".." + end},
+ })
+
+ if err != nil && strings.Contains(err.Error(), "no merge base") {
+ // future versions of git >= 2.28 are likely to return an error if before and last have become unrelated.
+ // previously it would return the results of git rev-list before last so let's try that...
+ return CommitsCount(ctx, repo, CommitsCountOptions{
+ Revision: []string{start, end},
+ })
+ }
+
+ return count, err
+}
+
+// FileCommitsCount return the number of files at a revision
+func FileCommitsCount(ctx context.Context, repo Repository, revision, file string) (int64, error) {
+ return CommitsCount(ctx, repo,
+ CommitsCountOptions{
+ Revision: []string{revision},
+ RelPath: []string{file},
+ })
+}
+
+// CommitsCountOfCommit returns number of total commits of until current revision.
+func CommitsCountOfCommit(ctx context.Context, repo Repository, commitID string) (int64, error) {
+ return CommitsCount(ctx, repo, CommitsCountOptions{
+ Revision: []string{commitID},
+ })
+}
+
+// AllCommitsCount returns count of all commits in repository
+func AllCommitsCount(ctx context.Context, repo Repository, hidePRRefs bool, files ...string) (int64, error) {
+ cmd := gitcmd.NewCommand("rev-list")
+ if hidePRRefs {
+ cmd.AddArguments("--exclude=" + git.PullPrefix + "*")
+ }
+ cmd.AddArguments("--all", "--count")
+ if len(files) > 0 {
+ cmd.AddDashesAndList(files...)
+ }
+
+ stdout, _, err := RunCmdString(ctx, repo, cmd)
+ if err != nil {
+ return 0, err
+ }
+
+ return strconv.ParseInt(strings.TrimSpace(stdout), 10, 64)
+}
+
+func GetFullCommitID(ctx context.Context, repo Repository, shortID string) (string, error) {
+ return git.GetFullCommitID(ctx, repoPath(repo), shortID)
+}
+
+// GetLatestCommitTime returns time for latest commit in repository (across all branches)
+func GetLatestCommitTime(ctx context.Context, repo Repository) (time.Time, error) {
+ stdout, _, err := RunCmdString(ctx, repo,
+ gitcmd.NewCommand("for-each-ref", "--sort=-committerdate", git.BranchPrefix, "--count", "1", "--format=%(committerdate)"))
+ if err != nil {
+ return time.Time{}, err
+ }
+ commitTime := strings.TrimSpace(stdout)
+ return time.Parse("Mon Jan _2 15:04:05 2006 -0700", commitTime)
+}
diff --git a/modules/gitrepo/commit_file.go b/modules/gitrepo/commit_file.go
new file mode 100644
index 0000000000..437b3b51ad
--- /dev/null
+++ b/modules/gitrepo/commit_file.go
@@ -0,0 +1,88 @@
+// Copyright 2025 The Gitea Authors. All rights reserved.
+// SPDX-License-Identifier: MIT
+
+package gitrepo
+
+import (
+ "bufio"
+ "context"
+ "io"
+
+ "code.gitea.io/gitea/modules/git/gitcmd"
+ "code.gitea.io/gitea/modules/log"
+)
+
+// CommitFileStatus represents status of files in a commit.
+type CommitFileStatus struct {
+ Added []string
+ Removed []string
+ Modified []string
+}
+
+// NewCommitFileStatus creates a CommitFileStatus
+func NewCommitFileStatus() *CommitFileStatus {
+ return &CommitFileStatus{
+ []string{}, []string{}, []string{},
+ }
+}
+
+func parseCommitFileStatus(fileStatus *CommitFileStatus, stdout io.Reader) {
+ rd := bufio.NewReader(stdout)
+ peek, err := rd.Peek(1)
+ if err != nil {
+ if err != io.EOF {
+ log.Error("Unexpected error whilst reading from git log --name-status. Error: %v", err)
+ }
+ return
+ }
+ if peek[0] == '\n' || peek[0] == '\x00' {
+ _, _ = rd.Discard(1)
+ }
+ for {
+ modifier, err := rd.ReadString('\x00')
+ if err != nil {
+ if err != io.EOF {
+ log.Error("Unexpected error whilst reading from git log --name-status. Error: %v", err)
+ }
+ return
+ }
+ file, err := rd.ReadString('\x00')
+ if err != nil {
+ if err != io.EOF {
+ log.Error("Unexpected error whilst reading from git log --name-status. Error: %v", err)
+ }
+ return
+ }
+ file = file[:len(file)-1]
+ switch modifier[0] {
+ case 'A':
+ fileStatus.Added = append(fileStatus.Added, file)
+ case 'D':
+ fileStatus.Removed = append(fileStatus.Removed, file)
+ case 'M':
+ fileStatus.Modified = append(fileStatus.Modified, file)
+ }
+ }
+}
+
+// GetCommitFileStatus returns file status of commit in given repository.
+func GetCommitFileStatus(ctx context.Context, repo Repository, commitID string) (*CommitFileStatus, error) {
+ cmd := gitcmd.NewCommand("log", "--name-status", "-m", "--pretty=format:", "--first-parent", "--no-renames", "-z", "-1")
+ stdout, stdoutClose := cmd.MakeStdoutPipe()
+ defer stdoutClose()
+ done := make(chan struct{})
+ fileStatus := NewCommitFileStatus()
+ go func() {
+ parseCommitFileStatus(fileStatus, stdout)
+ close(done)
+ }()
+ err := cmd.AddDynamicArguments(commitID).
+ WithDir(repoPath(repo)).
+ RunWithStderr(ctx)
+ if err != nil {
+ return nil, err
+ }
+
+ <-done
+ return fileStatus, nil
+}
diff --git a/modules/gitrepo/commit_file_test.go b/modules/gitrepo/commit_file_test.go
new file mode 100644
index 0000000000..ec1018eeba
--- /dev/null
+++ b/modules/gitrepo/commit_file_test.go
@@ -0,0 +1,175 @@
+// Copyright 2025 The Gitea Authors. All rights reserved.
+// SPDX-License-Identifier: MIT
+
+package gitrepo
+
+import (
+ "strings"
+ "testing"
+
+ "github.com/stretchr/testify/assert"
+)
+
+func TestParseCommitFileStatus(t *testing.T) {
+ type testcase struct {
+ output string
+ added []string
+ removed []string
+ modified []string
+ }
+
+ kases := []testcase{
+ {
+ // Merge commit
+ output: "MM\x00options/locale/locale_en-US.ini\x00",
+ modified: []string{
+ "options/locale/locale_en-US.ini",
+ },
+ added: []string{},
+ removed: []string{},
+ },
+ {
+ // Spaces commit
+ output: "D\x00b\x00D\x00b b/b\x00A\x00b b/b b/b b/b\x00A\x00b b/b b/b b/b b/b\x00",
+ removed: []string{
+ "b",
+ "b b/b",
+ },
+ modified: []string{},
+ added: []string{
+ "b b/b b/b b/b",
+ "b b/b b/b b/b b/b",
+ },
+ },
+ {
+ // larger commit
+ output: "M\x00go.mod\x00M\x00go.sum\x00M\x00modules/ssh/ssh.go\x00M\x00vendor/github.com/gliderlabs/ssh/circle.yml\x00M\x00vendor/github.com/gliderlabs/ssh/context.go\x00A\x00vendor/github.com/gliderlabs/ssh/go.mod\x00A\x00vendor/github.com/gliderlabs/ssh/go.sum\x00M\x00vendor/github.com/gliderlabs/ssh/server.go\x00M\x00vendor/github.com/gliderlabs/ssh/session.go\x00M\x00vendor/github.com/gliderlabs/ssh/ssh.go\x00M\x00vendor/golang.org/x/sys/unix/mkerrors.sh\x00M\x00vendor/golang.org/x/sys/unix/syscall_darwin.go\x00M\x00vendor/golang.org/x/sys/unix/zerrors_darwin_amd64.go\x00M\x00vendor/golang.org/x/sys/unix/zerrors_darwin_arm64.go\x00M\x00vendor/golang.org/x/sys/unix/zerrors_freebsd_386.go\x00M\x00vendor/golang.org/x/sys/unix/zerrors_freebsd_amd64.go\x00M\x00vendor/golang.org/x/sys/unix/zerrors_freebsd_arm.go\x00M\x00vendor/golang.org/x/sys/unix/zerrors_freebsd_arm64.go\x00M\x00vendor/golang.org/x/sys/unix/zerrors_linux.go\x00M\x00vendor/golang.org/x/sys/unix/ztypes_darwin_amd64.go\x00M\x00vendor/golang.org/x/sys/unix/ztypes_darwin_arm64.go\x00M\x00vendor/golang.org/x/sys/unix/ztypes_dragonfly_amd64.go\x00M\x00vendor/golang.org/x/sys/unix/ztypes_freebsd_386.go\x00M\x00vendor/golang.org/x/sys/unix/ztypes_freebsd_amd64.go\x00M\x00vendor/golang.org/x/sys/unix/ztypes_freebsd_arm.go\x00M\x00vendor/golang.org/x/sys/unix/ztypes_freebsd_arm64.go\x00M\x00vendor/golang.org/x/sys/unix/ztypes_netbsd_386.go\x00M\x00vendor/golang.org/x/sys/unix/ztypes_netbsd_amd64.go\x00M\x00vendor/golang.org/x/sys/unix/ztypes_netbsd_arm.go\x00M\x00vendor/golang.org/x/sys/unix/ztypes_netbsd_arm64.go\x00M\x00vendor/modules.txt\x00",
+ modified: []string{
+ "go.mod",
+ "go.sum",
+ "modules/ssh/ssh.go",
+ "vendor/github.com/gliderlabs/ssh/circle.yml",
+ "vendor/github.com/gliderlabs/ssh/context.go",
+ "vendor/github.com/gliderlabs/ssh/server.go",
+ "vendor/github.com/gliderlabs/ssh/session.go",
+ "vendor/github.com/gliderlabs/ssh/ssh.go",
+ "vendor/golang.org/x/sys/unix/mkerrors.sh",
+ "vendor/golang.org/x/sys/unix/syscall_darwin.go",
+ "vendor/golang.org/x/sys/unix/zerrors_darwin_amd64.go",
+ "vendor/golang.org/x/sys/unix/zerrors_darwin_arm64.go",
+ "vendor/golang.org/x/sys/unix/zerrors_freebsd_386.go",
+ "vendor/golang.org/x/sys/unix/zerrors_freebsd_amd64.go",
+ "vendor/golang.org/x/sys/unix/zerrors_freebsd_arm.go",
+ "vendor/golang.org/x/sys/unix/zerrors_freebsd_arm64.go",
+ "vendor/golang.org/x/sys/unix/zerrors_linux.go",
+ "vendor/golang.org/x/sys/unix/ztypes_darwin_amd64.go",
+ "vendor/golang.org/x/sys/unix/ztypes_darwin_arm64.go",
+ "vendor/golang.org/x/sys/unix/ztypes_dragonfly_amd64.go",
+ "vendor/golang.org/x/sys/unix/ztypes_freebsd_386.go",
+ "vendor/golang.org/x/sys/unix/ztypes_freebsd_amd64.go",
+ "vendor/golang.org/x/sys/unix/ztypes_freebsd_arm.go",
+ "vendor/golang.org/x/sys/unix/ztypes_freebsd_arm64.go",
+ "vendor/golang.org/x/sys/unix/ztypes_netbsd_386.go",
+ "vendor/golang.org/x/sys/unix/ztypes_netbsd_amd64.go",
+ "vendor/golang.org/x/sys/unix/ztypes_netbsd_arm.go",
+ "vendor/golang.org/x/sys/unix/ztypes_netbsd_arm64.go",
+ "vendor/modules.txt",
+ },
+ added: []string{
+ "vendor/github.com/gliderlabs/ssh/go.mod",
+ "vendor/github.com/gliderlabs/ssh/go.sum",
+ },
+ removed: []string{},
+ },
+ {
+ // git 1.7.2 adds an unnecessary \x00 on merge commit
+ output: "\x00MM\x00options/locale/locale_en-US.ini\x00",
+ modified: []string{
+ "options/locale/locale_en-US.ini",
+ },
+ added: []string{},
+ removed: []string{},
+ },
+ {
+ // git 1.7.2 adds an unnecessary \n on normal commit
+ output: "\nD\x00b\x00D\x00b b/b\x00A\x00b b/b b/b b/b\x00A\x00b b/b b/b b/b b/b\x00",
+ removed: []string{
+ "b",
+ "b b/b",
+ },
+ modified: []string{},
+ added: []string{
+ "b b/b b/b b/b",
+ "b b/b b/b b/b b/b",
+ },
+ },
+ }
+
+ for _, kase := range kases {
+ fileStatus := NewCommitFileStatus()
+ parseCommitFileStatus(fileStatus, strings.NewReader(kase.output))
+
+ assert.Equal(t, kase.added, fileStatus.Added)
+ assert.Equal(t, kase.removed, fileStatus.Removed)
+ assert.Equal(t, kase.modified, fileStatus.Modified)
+ }
+}
+
+func TestGetCommitFileStatusMerges(t *testing.T) {
+ bareRepo6 := &mockRepository{path: "repo6_merge"}
+
+ commitFileStatus, err := GetCommitFileStatus(t.Context(), bareRepo6, "022f4ce6214973e018f02bf363bf8a2e3691f699")
+ assert.NoError(t, err)
+
+ expected := CommitFileStatus{
+ []string{
+ "add_file.txt",
+ },
+ []string{
+ "to_remove.txt",
+ },
+ []string{
+ "to_modify.txt",
+ },
+ }
+
+ assert.Equal(t, expected.Added, commitFileStatus.Added)
+ assert.Equal(t, expected.Removed, commitFileStatus.Removed)
+ assert.Equal(t, expected.Modified, commitFileStatus.Modified)
+}
+
+func TestGetCommitFileStatusMergesSha256(t *testing.T) {
+ bareRepo6Sha256 := &mockRepository{path: "repo6_merge_sha256"}
+
+ commitFileStatus, err := GetCommitFileStatus(t.Context(), bareRepo6Sha256, "d2e5609f630dd8db500f5298d05d16def282412e3e66ed68cc7d0833b29129a1")
+ assert.NoError(t, err)
+
+ expected := CommitFileStatus{
+ []string{
+ "add_file.txt",
+ },
+ []string{},
+ []string{
+ "to_modify.txt",
+ },
+ }
+
+ assert.Equal(t, expected.Added, commitFileStatus.Added)
+ assert.Equal(t, expected.Removed, commitFileStatus.Removed)
+ assert.Equal(t, expected.Modified, commitFileStatus.Modified)
+
+ expected = CommitFileStatus{
+ []string{},
+ []string{
+ "to_remove.txt",
+ },
+ []string{},
+ }
+
+ commitFileStatus, err = GetCommitFileStatus(t.Context(), bareRepo6Sha256, "da1ded40dc8e5b7c564171f4bf2fc8370487decfb1cb6a99ef28f3ed73d09172")
+ assert.NoError(t, err)
+
+ assert.Equal(t, expected.Added, commitFileStatus.Added)
+ assert.Equal(t, expected.Removed, commitFileStatus.Removed)
+ assert.Equal(t, expected.Modified, commitFileStatus.Modified)
+}
diff --git a/modules/gitrepo/commit_test.go b/modules/gitrepo/commit_test.go
new file mode 100644
index 0000000000..05cedc39ef
--- /dev/null
+++ b/modules/gitrepo/commit_test.go
@@ -0,0 +1,45 @@
+// Copyright 2025 The Gitea Authors. All rights reserved.
+// SPDX-License-Identifier: MIT
+
+package gitrepo
+
+import (
+ "testing"
+
+ "github.com/stretchr/testify/assert"
+)
+
+func TestCommitsCount(t *testing.T) {
+ bareRepo1 := &mockRepository{path: "repo1_bare"}
+
+ commitsCount, err := CommitsCount(t.Context(), bareRepo1,
+ CommitsCountOptions{
+ Revision: []string{"8006ff9adbf0cb94da7dad9e537e53817f9fa5c0"},
+ })
+
+ assert.NoError(t, err)
+ assert.Equal(t, int64(3), commitsCount)
+}
+
+func TestCommitsCountWithoutBase(t *testing.T) {
+ bareRepo1 := &mockRepository{path: "repo1_bare"}
+
+ commitsCount, err := CommitsCount(t.Context(), bareRepo1,
+ CommitsCountOptions{
+ Not: "master",
+ Revision: []string{"branch1"},
+ })
+
+ assert.NoError(t, err)
+ assert.Equal(t, int64(2), commitsCount)
+}
+
+func TestGetLatestCommitTime(t *testing.T) {
+ bareRepo1 := &mockRepository{path: "repo1_bare"}
+ lct, err := GetLatestCommitTime(t.Context(), bareRepo1)
+ assert.NoError(t, err)
+ // Time is Sun Nov 13 16:40:14 2022 +0100
+ // which is the time of commit
+ // ce064814f4a0d337b333e646ece456cd39fab612 (refs/heads/master)
+ assert.EqualValues(t, 1668354014, lct.Unix())
+}
diff --git a/modules/gitrepo/commitgraph.go b/modules/gitrepo/commitgraph.go
new file mode 100644
index 0000000000..7310e167f6
--- /dev/null
+++ b/modules/gitrepo/commitgraph.go
@@ -0,0 +1,14 @@
+// Copyright 2025 The Gitea Authors. All rights reserved.
+// SPDX-License-Identifier: MIT
+
+package gitrepo
+
+import (
+ "context"
+
+ "code.gitea.io/gitea/modules/git"
+)
+
+func WriteCommitGraph(ctx context.Context, repo Repository) error {
+ return git.WriteCommitGraph(ctx, repoPath(repo))
+}
diff --git a/modules/gitrepo/compare.go b/modules/gitrepo/compare.go
new file mode 100644
index 0000000000..7e38d33e6f
--- /dev/null
+++ b/modules/gitrepo/compare.go
@@ -0,0 +1,71 @@
+// Copyright 2025 The Gitea Authors. All rights reserved.
+// SPDX-License-Identifier: MIT
+
+package gitrepo
+
+import (
+ "context"
+ "fmt"
+ "strconv"
+ "strings"
+
+ "code.gitea.io/gitea/modules/git/gitcmd"
+)
+
+// DivergeObject represents commit count diverging commits
+type DivergeObject struct {
+ Ahead int
+ Behind int
+}
+
+// GetDivergingCommits returns the number of commits a targetBranch is ahead or behind a baseBranch
+func GetDivergingCommits(ctx context.Context, repo Repository, baseBranch, targetBranch string) (*DivergeObject, error) {
+ cmd := gitcmd.NewCommand("rev-list", "--count", "--left-right").
+ AddDynamicArguments(baseBranch + "..." + targetBranch).AddArguments("--")
+ stdout, _, err1 := RunCmdString(ctx, repo, cmd)
+ if err1 != nil {
+ return nil, err1
+ }
+
+ left, right, found := strings.Cut(strings.Trim(stdout, "\n"), "\t")
+ if !found {
+ return nil, fmt.Errorf("git rev-list output is missing a tab: %q", stdout)
+ }
+
+ behind, err := strconv.Atoi(left)
+ if err != nil {
+ return nil, err
+ }
+ ahead, err := strconv.Atoi(right)
+ if err != nil {
+ return nil, err
+ }
+ return &DivergeObject{Ahead: ahead, Behind: behind}, nil
+}
+
+// GetCommitIDsBetweenReverse returns the last commit IDs between two commits in reverse order (from old to new) with limit.
+// If the result exceeds the limit, the old commits IDs will be ignored
+func GetCommitIDsBetweenReverse(ctx context.Context, repo Repository, startRef, endRef, notRef string, limit int) ([]string, error) {
+ genCmd := func(reversions ...string) *gitcmd.Command {
+ cmd := gitcmd.NewCommand("rev-list", "--reverse").
+ AddArguments("-n").AddDynamicArguments(strconv.Itoa(limit)).
+ AddDynamicArguments(reversions...)
+ if notRef != "" { // --not should be kept as the last parameter of git command, otherwise the result will be wrong
+ cmd.AddOptionValues("--not", notRef)
+ }
+ return cmd
+ }
+ stdout, _, err := RunCmdString(ctx, repo, genCmd(startRef+".."+endRef))
+ // example git error message: fatal: origin/main..HEAD: no merge base
+ if err != nil && strings.Contains(err.Stderr(), "no merge base") {
+ // future versions of git >= 2.28 are likely to return an error if before and last have become unrelated.
+ // previously it would return the results of git rev-list before last so let's try that...
+ stdout, _, err = RunCmdString(ctx, repo, genCmd(startRef, endRef))
+ }
+ if err != nil {
+ return nil, err
+ }
+
+ commitIDs := strings.Fields(strings.TrimSpace(stdout))
+ return commitIDs, nil
+}
diff --git a/modules/gitrepo/compare_test.go b/modules/gitrepo/compare_test.go
new file mode 100644
index 0000000000..3f7cc4f6a7
--- /dev/null
+++ b/modules/gitrepo/compare_test.go
@@ -0,0 +1,178 @@
+// Copyright 2024 The Gitea Authors. All rights reserved.
+// SPDX-License-Identifier: MIT
+
+package gitrepo
+
+import (
+ "bytes"
+ "os"
+ "path/filepath"
+ "strings"
+ "testing"
+ "time"
+
+ "code.gitea.io/gitea/modules/git/gitcmd"
+ "code.gitea.io/gitea/modules/util"
+
+ "github.com/stretchr/testify/assert"
+ "github.com/stretchr/testify/require"
+)
+
+type mockRepository struct {
+ path string
+}
+
+func (r *mockRepository) RelativePath() string {
+ return r.path
+}
+
+func commitRootTree(t *testing.T, repoDir, fileName, content, message string) string {
+ t.Helper()
+
+ require.NoError(t, gitcmd.NewCommand("read-tree", "--empty").WithDir(repoDir).Run(t.Context()))
+
+ stdout, _, err := gitcmd.NewCommand("hash-object", "-w", "--stdin").
+ WithDir(repoDir).
+ WithStdinBytes([]byte(content)).
+ RunStdString(t.Context())
+ require.NoError(t, err)
+ blobSHA := strings.TrimSpace(stdout)
+
+ _, _, err = gitcmd.NewCommand("update-index", "--add", "--replace", "--cacheinfo").
+ AddDynamicArguments("100644", blobSHA, fileName).
+ WithDir(repoDir).
+ RunStdString(t.Context())
+ require.NoError(t, err)
+
+ stdout, _, err = gitcmd.NewCommand("write-tree").WithDir(repoDir).RunStdString(t.Context())
+ require.NoError(t, err)
+ treeSHA := strings.TrimSpace(stdout)
+
+ commitTimeStr := time.Now().Format(time.RFC3339)
+ env := append(os.Environ(),
+ "GIT_AUTHOR_NAME=Test",
+ "GIT_AUTHOR_EMAIL=test@example.com",
+ "GIT_AUTHOR_DATE="+commitTimeStr,
+ "GIT_COMMITTER_NAME=Test",
+ "GIT_COMMITTER_EMAIL=test@example.com",
+ "GIT_COMMITTER_DATE="+commitTimeStr,
+ )
+
+ messageBytes := bytes.NewBufferString(message + "\n")
+ stdout, _, err = gitcmd.NewCommand("commit-tree").AddDynamicArguments(treeSHA).
+ WithEnv(env).
+ WithDir(repoDir).
+ WithStdinBytes(messageBytes.Bytes()).
+ RunStdString(t.Context())
+ require.NoError(t, err)
+
+ return strings.TrimSpace(stdout)
+}
+
+func TestMergeBaseNoCommonHistory(t *testing.T) {
+ repoDir := filepath.Join(t.TempDir(), "repo.git")
+ require.NoError(t, gitcmd.NewCommand("init").AddDynamicArguments(repoDir).Run(t.Context()))
+
+ baseCommit := commitRootTree(t, repoDir, "base.txt", "base", "base")
+ headCommit := commitRootTree(t, repoDir, "head.txt", "head", "head")
+
+ mergeBase, err := MergeBase(t.Context(), &mockRepository{path: repoDir}, baseCommit, headCommit)
+ assert.Empty(t, mergeBase)
+ assert.ErrorIs(t, err, util.ErrNotExist)
+}
+
+func TestRepoGetDivergingCommits(t *testing.T) {
+ repo := &mockRepository{path: "repo1_bare"}
+ do, err := GetDivergingCommits(t.Context(), repo, "master", "branch2")
+ assert.NoError(t, err)
+ assert.Equal(t, &DivergeObject{
+ Ahead: 1,
+ Behind: 5,
+ }, do)
+
+ do, err = GetDivergingCommits(t.Context(), repo, "master", "master")
+ assert.NoError(t, err)
+ assert.Equal(t, &DivergeObject{
+ Ahead: 0,
+ Behind: 0,
+ }, do)
+
+ do, err = GetDivergingCommits(t.Context(), repo, "master", "test")
+ assert.NoError(t, err)
+ assert.Equal(t, &DivergeObject{
+ Ahead: 0,
+ Behind: 2,
+ }, do)
+}
+
+func TestGetCommitIDsBetweenReverse(t *testing.T) {
+ repo := &mockRepository{path: "repo1_bare"}
+
+ // tests raw commit IDs
+ commitIDs, err := GetCommitIDsBetweenReverse(t.Context(), repo,
+ "8d92fc957a4d7cfd98bc375f0b7bb189a0d6c9f2",
+ "ce064814f4a0d337b333e646ece456cd39fab612",
+ "",
+ 100,
+ )
+ assert.NoError(t, err)
+ assert.Equal(t, []string{
+ "8006ff9adbf0cb94da7dad9e537e53817f9fa5c0",
+ "6fbd69e9823458e6c4a2fc5c0f6bc022b2f2acd1",
+ "37991dec2c8e592043f47155ce4808d4580f9123",
+ "feaf4ba6bc635fec442f46ddd4512416ec43c2c2",
+ "ce064814f4a0d337b333e646ece456cd39fab612",
+ }, commitIDs)
+
+ commitIDs, err = GetCommitIDsBetweenReverse(t.Context(), repo,
+ "8d92fc957a4d7cfd98bc375f0b7bb189a0d6c9f2",
+ "ce064814f4a0d337b333e646ece456cd39fab612",
+ "6fbd69e9823458e6c4a2fc5c0f6bc022b2f2acd1",
+ 100,
+ )
+ assert.NoError(t, err)
+ assert.Equal(t, []string{
+ "37991dec2c8e592043f47155ce4808d4580f9123",
+ "feaf4ba6bc635fec442f46ddd4512416ec43c2c2",
+ "ce064814f4a0d337b333e646ece456cd39fab612",
+ }, commitIDs)
+
+ commitIDs, err = GetCommitIDsBetweenReverse(t.Context(), repo,
+ "8d92fc957a4d7cfd98bc375f0b7bb189a0d6c9f2",
+ "ce064814f4a0d337b333e646ece456cd39fab612",
+ "",
+ 3,
+ )
+ assert.NoError(t, err)
+ assert.Equal(t, []string{
+ "37991dec2c8e592043f47155ce4808d4580f9123",
+ "feaf4ba6bc635fec442f46ddd4512416ec43c2c2",
+ "ce064814f4a0d337b333e646ece456cd39fab612",
+ }, commitIDs)
+
+ // test branch names instead of raw commit IDs.
+ commitIDs, err = GetCommitIDsBetweenReverse(t.Context(), repo,
+ "test",
+ "master",
+ "",
+ 100,
+ )
+ assert.NoError(t, err)
+ assert.Equal(t, []string{
+ "feaf4ba6bc635fec442f46ddd4512416ec43c2c2",
+ "ce064814f4a0d337b333e646ece456cd39fab612",
+ }, commitIDs)
+
+ // add notref to exclude test
+ commitIDs, err = GetCommitIDsBetweenReverse(t.Context(), repo,
+ "test",
+ "master",
+ "test",
+ 100,
+ )
+ assert.NoError(t, err)
+ assert.Equal(t, []string{
+ "feaf4ba6bc635fec442f46ddd4512416ec43c2c2",
+ "ce064814f4a0d337b333e646ece456cd39fab612",
+ }, commitIDs)
+}
diff --git a/modules/gitrepo/config.go b/modules/gitrepo/config.go
index c028c6afe8..9be3ef94ae 100644
--- a/modules/gitrepo/config.go
+++ b/modules/gitrepo/config.go
@@ -12,9 +12,8 @@ import (
)
func GitConfigGet(ctx context.Context, repo Repository, key string) (string, error) {
- result, _, err := gitcmd.NewCommand("config", "--get").
- AddDynamicArguments(key).
- RunStdString(ctx, &gitcmd.RunOpts{Dir: repoPath(repo)})
+ result, _, err := RunCmdString(ctx, repo, gitcmd.NewCommand("config", "--get").
+ AddDynamicArguments(key))
if err != nil {
return "", err
}
@@ -28,9 +27,8 @@ func getRepoConfigLockKey(repoStoragePath string) string {
// GitConfigAdd add a git configuration key to a specific value for the given repository.
func GitConfigAdd(ctx context.Context, repo Repository, key, value string) error {
return globallock.LockAndDo(ctx, getRepoConfigLockKey(repo.RelativePath()), func(ctx context.Context) error {
- _, _, err := gitcmd.NewCommand("config", "--add").
- AddDynamicArguments(key, value).
- RunStdString(ctx, &gitcmd.RunOpts{Dir: repoPath(repo)})
+ _, _, err := RunCmdString(ctx, repo, gitcmd.NewCommand("config", "--add").
+ AddDynamicArguments(key, value))
return err
})
}
@@ -40,9 +38,8 @@ func GitConfigAdd(ctx context.Context, repo Repository, key, value string) error
// If the key exists, it will be updated to the new value.
func GitConfigSet(ctx context.Context, repo Repository, key, value string) error {
return globallock.LockAndDo(ctx, getRepoConfigLockKey(repo.RelativePath()), func(ctx context.Context) error {
- _, _, err := gitcmd.NewCommand("config").
- AddDynamicArguments(key, value).
- RunStdString(ctx, &gitcmd.RunOpts{Dir: repoPath(repo)})
+ _, _, err := RunCmdString(ctx, repo, gitcmd.NewCommand("config").
+ AddDynamicArguments(key, value))
return err
})
}
diff --git a/modules/gitrepo/diff.go b/modules/gitrepo/diff.go
new file mode 100644
index 0000000000..0092cf0bb8
--- /dev/null
+++ b/modules/gitrepo/diff.go
@@ -0,0 +1,71 @@
+// Copyright 2025 The Gitea Authors. All rights reserved.
+// SPDX-License-Identifier: MIT
+
+package gitrepo
+
+import (
+ "context"
+ "fmt"
+ "io"
+ "regexp"
+ "strconv"
+
+ "code.gitea.io/gitea/modules/git/gitcmd"
+)
+
+// GetDiffShortStatByCmdArgs counts number of changed files, number of additions and deletions
+// TODO: it can be merged with another "GetDiffShortStat" in the future
+func GetDiffShortStatByCmdArgs(ctx context.Context, repo Repository, trustedArgs gitcmd.TrustedCmdArgs, dynamicArgs ...string) (numFiles, totalAdditions, totalDeletions int, err error) {
+ // Now if we call:
+ // $ git diff --shortstat 1ebb35b98889ff77299f24d82da426b434b0cca0...788b8b1440462d477f45b0088875
+ // we get:
+ // " 9902 files changed, 2034198 insertions(+), 298800 deletions(-)\n"
+ cmd := gitcmd.NewCommand("diff", "--shortstat").AddArguments(trustedArgs...).AddDynamicArguments(dynamicArgs...)
+ stdout, _, err := RunCmdString(ctx, repo, cmd)
+ if err != nil {
+ return 0, 0, 0, err
+ }
+
+ return parseDiffStat(stdout)
+}
+
+var shortStatFormat = regexp.MustCompile(
+ `\s*(\d+) files? changed(?:, (\d+) insertions?\(\+\))?(?:, (\d+) deletions?\(-\))?`)
+
+func parseDiffStat(stdout string) (numFiles, totalAdditions, totalDeletions int, err error) {
+ if len(stdout) == 0 || stdout == "\n" {
+ return 0, 0, 0, nil
+ }
+ groups := shortStatFormat.FindStringSubmatch(stdout)
+ if len(groups) != 4 {
+ return 0, 0, 0, fmt.Errorf("unable to parse shortstat: %s groups: %s", stdout, groups)
+ }
+
+ numFiles, err = strconv.Atoi(groups[1])
+ if err != nil {
+ return 0, 0, 0, fmt.Errorf("unable to parse shortstat: %s. Error parsing NumFiles %w", stdout, err)
+ }
+
+ if len(groups[2]) != 0 {
+ totalAdditions, err = strconv.Atoi(groups[2])
+ if err != nil {
+ return 0, 0, 0, fmt.Errorf("unable to parse shortstat: %s. Error parsing NumAdditions %w", stdout, err)
+ }
+ }
+
+ if len(groups[3]) != 0 {
+ totalDeletions, err = strconv.Atoi(groups[3])
+ if err != nil {
+ return 0, 0, 0, fmt.Errorf("unable to parse shortstat: %s. Error parsing NumDeletions %w", stdout, err)
+ }
+ }
+ return numFiles, totalAdditions, totalDeletions, err
+}
+
+// GetReverseRawDiff dumps the reverse diff results of repository in given commit ID to io.Writer.
+func GetReverseRawDiff(ctx context.Context, repo Repository, commitID string, writer io.Writer) error {
+ return RunCmdWithStderr(ctx, repo, gitcmd.NewCommand("show", "--pretty=format:revert %H%n", "-R").
+ AddDynamicArguments(commitID).
+ WithStdoutCopy(writer),
+ )
+}
diff --git a/modules/gitrepo/fetch.go b/modules/gitrepo/fetch.go
new file mode 100644
index 0000000000..0474d6111e
--- /dev/null
+++ b/modules/gitrepo/fetch.go
@@ -0,0 +1,28 @@
+// Copyright 2025 The Gitea Authors. All rights reserved.
+// SPDX-License-Identifier: MIT
+
+package gitrepo
+
+import (
+ "context"
+
+ "code.gitea.io/gitea/modules/git/gitcmd"
+ "code.gitea.io/gitea/modules/globallock"
+)
+
+// FetchRemoteCommit fetches a specific commit and its related objects from a remote
+// repository into the managed repository.
+//
+// If no reference (branch, tag, or other ref) points to the fetched commit, it will
+// be treated as unreachable and cleaned up by `git gc` after the default prune
+// expiration period (2 weeks). Ref: https://www.kernel.org/pub/software/scm/git/docs/git-gc.html
+//
+// This behavior is sufficient for temporary operations, such as determining the
+// merge base between commits.
+func FetchRemoteCommit(ctx context.Context, repo, remoteRepo Repository, commitID string) error {
+ return globallock.LockAndDo(ctx, getRepoWriteLockKey(repo.RelativePath()), func(ctx context.Context) error {
+ return RunCmd(ctx, repo, gitcmd.NewCommand("fetch", "--no-tags").
+ AddDynamicArguments(repoPath(remoteRepo)).
+ AddDynamicArguments(commitID))
+ })
+}
diff --git a/modules/gitrepo/fsck.go b/modules/gitrepo/fsck.go
index ffccff28a9..f74ca3b46a 100644
--- a/modules/gitrepo/fsck.go
+++ b/modules/gitrepo/fsck.go
@@ -12,5 +12,5 @@ import (
// Fsck verifies the connectivity and validity of the objects in the database
func Fsck(ctx context.Context, repo Repository, timeout time.Duration, args gitcmd.TrustedCmdArgs) error {
- return gitcmd.NewCommand("fsck").AddArguments(args...).Run(ctx, &gitcmd.RunOpts{Timeout: timeout, Dir: repoPath(repo)})
+ return RunCmd(ctx, repo, gitcmd.NewCommand("fsck").AddArguments(args...).WithTimeout(timeout))
}
diff --git a/modules/gitrepo/gitrepo.go b/modules/gitrepo/gitrepo.go
index fad8f70c4c..535d72ed98 100644
--- a/modules/gitrepo/gitrepo.go
+++ b/modules/gitrepo/gitrepo.go
@@ -7,9 +7,12 @@ import (
"context"
"fmt"
"io"
+ "io/fs"
+ "os"
"path/filepath"
"code.gitea.io/gitea/modules/git"
+ "code.gitea.io/gitea/modules/git/gitcmd"
"code.gitea.io/gitea/modules/reqctx"
"code.gitea.io/gitea/modules/setting"
"code.gitea.io/gitea/modules/util"
@@ -20,9 +23,9 @@ type Repository interface {
RelativePath() string // We don't assume how the directory structure of the repository is, so we only need the relative path
}
-// RelativePath should be an unix style path like username/reponame.git
-// This method should change it according to the current OS.
-func repoPath(repo Repository) string {
+// repoPath resolves the Repository.RelativePath (which is a unix-style path like "username/reponame.git")
+// to a local filesystem path according to setting.RepoRootPath
+var repoPath = func(repo Repository) string {
return filepath.Join(setting.RepoRootPath, filepath.FromSlash(repo.RelativePath()))
}
@@ -77,7 +80,12 @@ func DeleteRepository(ctx context.Context, repo Repository) error {
// RenameRepository renames a repository's name on disk
func RenameRepository(ctx context.Context, repo, newRepo Repository) error {
- if err := util.Rename(repoPath(repo), repoPath(newRepo)); err != nil {
+ dstDir := repoPath(newRepo)
+ if err := os.MkdirAll(filepath.Dir(dstDir), os.ModePerm); err != nil {
+ return fmt.Errorf("Failed to create dir %s: %w", filepath.Dir(dstDir), err)
+ }
+
+ if err := util.Rename(repoPath(repo), dstDir); err != nil {
return fmt.Errorf("rename repository directory: %w", err)
}
return nil
@@ -86,3 +94,35 @@ func RenameRepository(ctx context.Context, repo, newRepo Repository) error {
func InitRepository(ctx context.Context, repo Repository, objectFormatName string) error {
return git.InitRepository(ctx, repoPath(repo), true, objectFormatName)
}
+
+func UpdateServerInfo(ctx context.Context, repo Repository) error {
+ _, _, err := RunCmdBytes(ctx, repo, gitcmd.NewCommand("update-server-info"))
+ return err
+}
+
+func GetRepoFS(repo Repository) fs.FS {
+ return os.DirFS(repoPath(repo))
+}
+
+func IsRepoFileExist(ctx context.Context, repo Repository, relativeFilePath string) (bool, error) {
+ absoluteFilePath := filepath.Join(repoPath(repo), relativeFilePath)
+ return util.IsExist(absoluteFilePath)
+}
+
+func IsRepoDirExist(ctx context.Context, repo Repository, relativeDirPath string) (bool, error) {
+ absoluteDirPath := filepath.Join(repoPath(repo), relativeDirPath)
+ return util.IsDir(absoluteDirPath)
+}
+
+func RemoveRepoFileOrDir(ctx context.Context, repo Repository, relativeFileOrDirPath string) error {
+ absoluteFilePath := filepath.Join(repoPath(repo), relativeFileOrDirPath)
+ return util.Remove(absoluteFilePath)
+}
+
+func CreateRepoFile(ctx context.Context, repo Repository, relativeFilePath string) (io.WriteCloser, error) {
+ absoluteFilePath := filepath.Join(repoPath(repo), relativeFilePath)
+ if err := os.MkdirAll(filepath.Dir(absoluteFilePath), os.ModePerm); err != nil {
+ return nil, err
+ }
+ return os.Create(absoluteFilePath)
+}
diff --git a/modules/gitrepo/main_test.go b/modules/gitrepo/main_test.go
new file mode 100644
index 0000000000..08afdffcc6
--- /dev/null
+++ b/modules/gitrepo/main_test.go
@@ -0,0 +1,25 @@
+// Copyright 2025 The Gitea Authors. All rights reserved.
+// SPDX-License-Identifier: MIT
+
+package gitrepo
+
+import (
+ "path/filepath"
+ "testing"
+
+ "code.gitea.io/gitea/modules/git"
+ "code.gitea.io/gitea/modules/setting"
+)
+
+func TestMain(m *testing.M) {
+ // resolve repository path relative to the test directory
+ setting.SetupGiteaTestEnv()
+ giteaRoot := setting.GetGiteaTestSourceRoot()
+ repoPath = func(repo Repository) string {
+ if filepath.IsAbs(repo.RelativePath()) {
+ return repo.RelativePath() // for testing purpose only
+ }
+ return filepath.Join(giteaRoot, "modules/git/tests/repos", repo.RelativePath())
+ }
+ git.RunGitTests(m)
+}
diff --git a/modules/gitrepo/merge.go b/modules/gitrepo/merge.go
new file mode 100644
index 0000000000..92803da6fd
--- /dev/null
+++ b/modules/gitrepo/merge.go
@@ -0,0 +1,26 @@
+// Copyright 2025 The Gitea Authors. All rights reserved.
+// SPDX-License-Identifier: MIT
+
+package gitrepo
+
+import (
+ "context"
+ "fmt"
+ "strings"
+
+ "code.gitea.io/gitea/modules/git/gitcmd"
+ "code.gitea.io/gitea/modules/util"
+)
+
+// MergeBase checks and returns merge base of two commits.
+func MergeBase(ctx context.Context, repo Repository, baseCommitID, headCommitID string) (string, error) {
+ mergeBase, _, err := RunCmdString(ctx, repo, gitcmd.NewCommand("merge-base").
+ AddDashesAndList(baseCommitID, headCommitID))
+ if err != nil {
+ if gitcmd.IsErrorExitCode(err, 1) {
+ return "", util.NewNotExistErrorf("get merge-base of %s and %s failed", baseCommitID, headCommitID)
+ }
+ return "", fmt.Errorf("get merge-base of %s and %s failed: %w", baseCommitID, headCommitID, err)
+ }
+ return strings.TrimSpace(mergeBase), nil
+}
diff --git a/modules/gitrepo/merge_tree.go b/modules/gitrepo/merge_tree.go
new file mode 100644
index 0000000000..6151b1179f
--- /dev/null
+++ b/modules/gitrepo/merge_tree.go
@@ -0,0 +1,59 @@
+// Copyright 2026 The Gitea Authors. All rights reserved.
+// SPDX-License-Identifier: MIT
+
+package gitrepo
+
+import (
+ "bufio"
+ "context"
+ "fmt"
+
+ "code.gitea.io/gitea/modules/git/gitcmd"
+ "code.gitea.io/gitea/modules/util"
+)
+
+const MaxConflictedDetectFiles = 10
+
+// MergeTree performs a merge between two commits (baseRef and headRef) with an optional merge base.
+// It returns the resulting tree hash, a list of conflicted files (if any), and an error if the operation fails.
+// If there are no conflicts, the list of conflicted files will be nil.
+func MergeTree(ctx context.Context, repo Repository, baseRef, headRef, mergeBase string) (treeID string, isErrHasConflicts bool, conflictFiles []string, _ error) {
+ cmd := gitcmd.NewCommand("merge-tree", "--write-tree", "-z", "--name-only", "--no-messages").
+ AddOptionFormat("--merge-base=%s", mergeBase).
+ AddDynamicArguments(baseRef, headRef)
+
+ stdout, stdoutClose := cmd.MakeStdoutPipe()
+ defer stdoutClose()
+ cmd.WithPipelineFunc(func(ctx gitcmd.Context) error {
+ // https://git-scm.com/docs/git-merge-tree/2.38.0#OUTPUT
+ // For a conflicted merge, the output is:
+ // ]NUL
+ // NUL
+ // NUL
+ // ...
+ scanner := bufio.NewScanner(stdout)
+ scanner.Split(util.BufioScannerSplit(0))
+ for scanner.Scan() {
+ line := scanner.Text()
+ if treeID == "" { // first line is tree ID
+ treeID = line
+ continue
+ }
+ conflictFiles = append(conflictFiles, line)
+ if len(conflictFiles) >= MaxConflictedDetectFiles {
+ break
+ }
+ }
+ return scanner.Err()
+ })
+
+ err := RunCmdWithStderr(ctx, repo, cmd)
+ // For a successful, non-conflicted merge, the exit status is 0. When the merge has conflicts, the exit status is 1.
+ // A merge can have conflicts without having individual files conflict
+ // https://git-scm.com/docs/git-merge-tree/2.38.0#_mistakes_to_avoid
+ isErrHasConflicts = gitcmd.IsErrorExitCode(err, 1)
+ if err == nil || isErrHasConflicts {
+ return treeID, isErrHasConflicts, conflictFiles, nil
+ }
+ return "", false, nil, fmt.Errorf("run merge-tree failed: %w", err)
+}
diff --git a/modules/gitrepo/merge_tree_test.go b/modules/gitrepo/merge_tree_test.go
new file mode 100644
index 0000000000..9327a0c3d8
--- /dev/null
+++ b/modules/gitrepo/merge_tree_test.go
@@ -0,0 +1,82 @@
+// Copyright 2026 The Gitea Authors. All rights reserved.
+// SPDX-License-Identifier: MIT
+
+package gitrepo
+
+import (
+ "path/filepath"
+ "testing"
+
+ "code.gitea.io/gitea/modules/git/gitcmd"
+
+ "github.com/stretchr/testify/assert"
+ "github.com/stretchr/testify/require"
+)
+
+func prepareRepoDirRenameConflict(t *testing.T) string {
+ repoDir := filepath.Join(t.TempDir(), "repo-dir-rename-conflict.git")
+ require.NoError(t, gitcmd.NewCommand("init", "--bare").AddDynamicArguments(repoDir).Run(t.Context()))
+ stdin := `blob
+mark :1
+data 2
+b
+
+blob
+mark :2
+data 2
+c
+
+reset refs/heads/master
+commit refs/heads/master
+mark :3
+author test 1769202331 -0800
+committer test 1769202331 -0800
+data 2
+O
+M 100644 :1 z/b
+M 100644 :2 z/c
+
+commit refs/heads/split
+mark :4
+author test 1769202336 -0800
+committer test 1769202336 -0800
+data 2
+A
+from :3
+M 100644 :2 w/c
+M 100644 :1 y/b
+D z/b
+D z/c
+
+blob
+mark :5
+data 2
+d
+
+commit refs/heads/add
+mark :6
+author test 1769202342 -0800
+committer test 1769202342 -0800
+data 2
+B
+from :3
+M 100644 :5 z/d
+`
+ require.NoError(t, gitcmd.NewCommand("fast-import").WithDir(repoDir).WithStdinBytes([]byte(stdin)).Run(t.Context()))
+ return repoDir
+}
+
+func TestMergeTreeDirectoryRenameConflictWithoutFiles(t *testing.T) {
+ repoDir := prepareRepoDirRenameConflict(t)
+ require.DirExists(t, repoDir)
+ repo := &mockRepository{path: repoDir}
+
+ mergeBase, err := MergeBase(t.Context(), repo, "add", "split")
+ require.NoError(t, err)
+
+ treeID, conflicted, conflictedFiles, err := MergeTree(t.Context(), repo, "add", "split", mergeBase)
+ require.NoError(t, err)
+ assert.True(t, conflicted)
+ assert.Empty(t, conflictedFiles)
+ assert.Equal(t, "5e3dd4cfc5b11e278a35b2daa83b7274175e3ab1", treeID)
+}
diff --git a/modules/gitrepo/push.go b/modules/gitrepo/push.go
new file mode 100644
index 0000000000..920c317f79
--- /dev/null
+++ b/modules/gitrepo/push.go
@@ -0,0 +1,27 @@
+// Copyright 2025 The Gitea Authors. All rights reserved.
+// SPDX-License-Identifier: MIT
+
+package gitrepo
+
+import (
+ "context"
+
+ "code.gitea.io/gitea/modules/git"
+)
+
+// PushToExternal pushes a managed repository to an external remote.
+func PushToExternal(ctx context.Context, repo Repository, opts git.PushOptions) error {
+ return git.Push(ctx, repoPath(repo), opts)
+}
+
+// Push pushes from one managed repository to another managed repository.
+func Push(ctx context.Context, fromRepo, toRepo Repository, opts git.PushOptions) error {
+ opts.Remote = repoPath(toRepo)
+ return git.Push(ctx, repoPath(fromRepo), opts)
+}
+
+// PushFromLocal pushes from a local path to a managed repository.
+func PushFromLocal(ctx context.Context, fromLocalPath string, toRepo Repository, opts git.PushOptions) error {
+ opts.Remote = repoPath(toRepo)
+ return git.Push(ctx, fromLocalPath, opts)
+}
diff --git a/modules/gitrepo/ref.go b/modules/gitrepo/ref.go
index babef8b65f..5212528326 100644
--- a/modules/gitrepo/ref.go
+++ b/modules/gitrepo/ref.go
@@ -10,12 +10,10 @@ import (
)
func UpdateRef(ctx context.Context, repo Repository, refName, newCommitID string) error {
- _, _, err := gitcmd.NewCommand("update-ref").AddDynamicArguments(refName, newCommitID).RunStdString(ctx, &gitcmd.RunOpts{Dir: repoPath(repo)})
- return err
+ return RunCmd(ctx, repo, gitcmd.NewCommand("update-ref").AddDynamicArguments(refName, newCommitID))
}
func RemoveRef(ctx context.Context, repo Repository, refName string) error {
- _, _, err := gitcmd.NewCommand("update-ref", "--no-deref", "-d").
- AddDynamicArguments(refName).RunStdString(ctx, &gitcmd.RunOpts{Dir: repoPath(repo)})
- return err
+ return RunCmd(ctx, repo, gitcmd.NewCommand("update-ref", "--no-deref", "-d").
+ AddDynamicArguments(refName))
}
diff --git a/modules/gitrepo/remote.go b/modules/gitrepo/remote.go
index 20d3cd21da..3cbc34eedb 100644
--- a/modules/gitrepo/remote.go
+++ b/modules/gitrepo/remote.go
@@ -6,8 +6,6 @@ package gitrepo
import (
"context"
"errors"
- "io"
- "time"
"code.gitea.io/gitea/modules/git"
"code.gitea.io/gitea/modules/git/gitcmd"
@@ -36,9 +34,7 @@ func GitRemoteAdd(ctx context.Context, repo Repository, remoteName, remoteURL st
return errors.New("unknown remote option: " + string(options[0]))
}
}
- _, _, err := cmd.
- AddDynamicArguments(remoteName, remoteURL).
- RunStdString(ctx, &gitcmd.RunOpts{Dir: repoPath(repo)})
+ _, _, err := RunCmdString(ctx, repo, cmd.AddDynamicArguments(remoteName, remoteURL))
return err
})
}
@@ -46,7 +42,7 @@ func GitRemoteAdd(ctx context.Context, repo Repository, remoteName, remoteURL st
func GitRemoteRemove(ctx context.Context, repo Repository, remoteName string) error {
return globallock.LockAndDo(ctx, getRepoConfigLockKey(repo.RelativePath()), func(ctx context.Context) error {
cmd := gitcmd.NewCommand("remote", "rm").AddDynamicArguments(remoteName)
- _, _, err := cmd.RunStdString(ctx, &gitcmd.RunOpts{Dir: repoPath(repo)})
+ _, _, err := RunCmdString(ctx, repo, cmd)
return err
})
}
@@ -62,25 +58,3 @@ func GitRemoteGetURL(ctx context.Context, repo Repository, remoteName string) (*
}
return giturl.ParseGitURL(addr)
}
-
-// GitRemotePrune prunes the remote branches that no longer exist in the remote repository.
-func GitRemotePrune(ctx context.Context, repo Repository, remoteName string, timeout time.Duration, stdout, stderr io.Writer) error {
- return gitcmd.NewCommand("remote", "prune").AddDynamicArguments(remoteName).
- Run(ctx, &gitcmd.RunOpts{
- Timeout: timeout,
- Dir: repoPath(repo),
- Stdout: stdout,
- Stderr: stderr,
- })
-}
-
-// GitRemoteUpdatePrune updates the remote branches and prunes the ones that no longer exist in the remote repository.
-func GitRemoteUpdatePrune(ctx context.Context, repo Repository, remoteName string, timeout time.Duration, stdout, stderr io.Writer) error {
- return gitcmd.NewCommand("remote", "update", "--prune").AddDynamicArguments(remoteName).
- Run(ctx, &gitcmd.RunOpts{
- Timeout: timeout,
- Dir: repoPath(repo),
- Stdout: stdout,
- Stderr: stderr,
- })
-}
diff --git a/modules/gitrepo/repo_lock.go b/modules/gitrepo/repo_lock.go
new file mode 100644
index 0000000000..2eb89ce807
--- /dev/null
+++ b/modules/gitrepo/repo_lock.go
@@ -0,0 +1,10 @@
+// Copyright 2026 The Gitea Authors. All rights reserved.
+// SPDX-License-Identifier: MIT
+
+package gitrepo
+
+// getRepoWriteLockKey returns the global lock key for write operations on the repository.
+// Parallel write operations on the same git repository should be avoided to prevent data corruption.
+func getRepoWriteLockKey(repoStoragePath string) string {
+ return "repo-write:" + repoStoragePath
+}
diff --git a/modules/gitrepo/signing.go b/modules/gitrepo/signing.go
new file mode 100644
index 0000000000..2f77758d8c
--- /dev/null
+++ b/modules/gitrepo/signing.go
@@ -0,0 +1,14 @@
+// Copyright 2025 The Gitea Authors. All rights reserved.
+// SPDX-License-Identifier: MIT
+
+package gitrepo
+
+import (
+ "context"
+
+ "code.gitea.io/gitea/modules/git"
+)
+
+func GetSigningKey(ctx context.Context) (*git.SigningKey, *git.Signature) {
+ return git.GetSigningKey(ctx)
+}
diff --git a/modules/gitrepo/size.go b/modules/gitrepo/size.go
new file mode 100644
index 0000000000..7524bb2542
--- /dev/null
+++ b/modules/gitrepo/size.go
@@ -0,0 +1,37 @@
+// Copyright 2025 The Gitea Authors. All rights reserved.
+// SPDX-License-Identifier: MIT
+
+package gitrepo
+
+import (
+ "os"
+ "path/filepath"
+)
+
+const notRegularFileMode = os.ModeSymlink | os.ModeNamedPipe | os.ModeSocket | os.ModeDevice | os.ModeCharDevice | os.ModeIrregular
+
+// CalcRepositorySize returns the disk consumption for a given path
+func CalcRepositorySize(repo Repository) (int64, error) {
+ var size int64
+ err := filepath.WalkDir(repoPath(repo), func(_ string, entry os.DirEntry, err error) error {
+ if os.IsNotExist(err) { // ignore the error because some files (like temp/lock file) may be deleted during traversing.
+ return nil
+ } else if err != nil {
+ return err
+ }
+ if entry.IsDir() {
+ return nil
+ }
+ info, err := entry.Info()
+ if os.IsNotExist(err) { // ignore the error as above
+ return nil
+ } else if err != nil {
+ return err
+ }
+ if (info.Mode() & notRegularFileMode) == 0 {
+ size += info.Size()
+ }
+ return nil
+ })
+ return size, err
+}
diff --git a/modules/graceful/manager.go b/modules/graceful/manager.go
index ee1872b999..51bd5a2334 100644
--- a/modules/graceful/manager.go
+++ b/modules/graceful/manager.go
@@ -74,12 +74,6 @@ func (g *Manager) RunWithCancel(rc RunCanceler) {
g.RunAtShutdown(context.Background(), rc.Cancel)
g.runningServerWaitGroup.Add(1)
defer g.runningServerWaitGroup.Done()
- defer func() {
- if err := recover(); err != nil {
- log.Critical("PANIC during RunWithCancel: %v\nStacktrace: %s", err, log.Stack(2))
- g.doShutdown()
- }
- }()
rc.Run()
}
@@ -89,12 +83,6 @@ func (g *Manager) RunWithCancel(rc RunCanceler) {
func (g *Manager) RunWithShutdownContext(run func(context.Context)) {
g.runningServerWaitGroup.Add(1)
defer g.runningServerWaitGroup.Done()
- defer func() {
- if err := recover(); err != nil {
- log.Critical("PANIC during RunWithShutdownContext: %v\nStacktrace: %s", err, log.Stack(2))
- g.doShutdown()
- }
- }()
ctx := g.ShutdownContext()
pprof.SetGoroutineLabels(ctx) // We don't have a label to restore back to but I think this is fine
run(ctx)
diff --git a/modules/graceful/net_unix.go b/modules/graceful/net_unix.go
index 796e00507c..a06f78dafe 100644
--- a/modules/graceful/net_unix.go
+++ b/modules/graceful/net_unix.go
@@ -290,11 +290,11 @@ func getActiveListenersToUnlink() []bool {
func getNotifySocket() (*net.UnixConn, error) {
if err := getProvidedFDs(); err != nil {
// This error will be logged elsewhere
- return nil, nil
+ return nil, nil //nolint:nilnil // return nil when no provided FDs are available
}
if notifySocketAddr == "" {
- return nil, nil
+ return nil, nil //nolint:nilnil // return nil when notify socket is not configured
}
socketAddr := &net.UnixAddr{
diff --git a/modules/graceful/server.go b/modules/graceful/server.go
index 2525a83e77..b440f68ab5 100644
--- a/modules/graceful/server.go
+++ b/modules/graceful/server.go
@@ -11,7 +11,6 @@ import (
"os"
"strings"
"sync"
- "sync/atomic"
"syscall"
"time"
@@ -30,12 +29,15 @@ type ServeFunction = func(net.Listener) error
// Server represents our graceful server
type Server struct {
- network string
- address string
- listener net.Listener
- wg sync.WaitGroup
- state state
- lock *sync.RWMutex
+ network string
+ address string
+ listener net.Listener
+
+ lock sync.RWMutex
+ state state
+ connCounter int64
+ connEmptyCond *sync.Cond
+
BeforeBegin func(network, address string)
OnShutdown func()
PerWriteTimeout time.Duration
@@ -50,14 +52,13 @@ func NewServer(network, address, name string) *Server {
log.Info("Starting new %s server: %s:%s on PID: %d", name, network, address, os.Getpid())
}
srv := &Server{
- wg: sync.WaitGroup{},
state: stateInit,
- lock: &sync.RWMutex{},
network: network,
address: address,
PerWriteTimeout: setting.PerWriteTimeout,
PerWritePerKbTimeout: setting.PerWritePerKbTimeout,
}
+ srv.connEmptyCond = sync.NewCond(&srv.lock)
srv.BeforeBegin = func(network, addr string) {
log.Debug("Starting server on %s:%s (PID: %d)", network, addr, syscall.Getpid())
@@ -154,7 +155,7 @@ func (srv *Server) Serve(serve ServeFunction) error {
GetManager().RegisterServer()
err := serve(srv.listener)
log.Debug("Waiting for connections to finish... (PID: %d)", syscall.Getpid())
- srv.wg.Wait()
+ srv.waitForActiveConnections()
srv.setState(stateTerminate)
GetManager().ServerDone()
// use of closed means that the listeners are closed - i.e. we should be shutting down - return nil
@@ -178,16 +179,62 @@ func (srv *Server) setState(st state) {
srv.state = st
}
+func (srv *Server) waitForActiveConnections() {
+ srv.lock.Lock()
+ for srv.connCounter > 0 {
+ srv.connEmptyCond.Wait()
+ }
+ srv.lock.Unlock()
+}
+
+func (srv *Server) wrapConnection(c net.Conn) (net.Conn, error) {
+ srv.lock.Lock()
+ defer srv.lock.Unlock()
+
+ if srv.state != stateRunning {
+ _ = c.Close()
+ return nil, syscall.EINVAL // same as AcceptTCP
+ }
+
+ srv.connCounter++
+ return &wrappedConn{Conn: c, server: srv}, nil
+}
+
+func (srv *Server) removeConnection(_ *wrappedConn) {
+ srv.lock.Lock()
+ defer srv.lock.Unlock()
+
+ srv.connCounter--
+ if srv.connCounter <= 0 {
+ srv.connEmptyCond.Broadcast()
+ }
+}
+
+// closeAllConnections forcefully closes all active connections
+func (srv *Server) closeAllConnections() {
+ srv.lock.Lock()
+ if srv.connCounter > 0 {
+ log.Warn("After graceful shutdown period, %d connections are still active. Forcefully close.", srv.connCounter)
+ srv.connCounter = 0 // OS will close all the connections after the process exits, so we just assume there is no active connection now
+ }
+ srv.lock.Unlock()
+ srv.connEmptyCond.Broadcast()
+}
+
type filer interface {
File() (*os.File, error)
}
type wrappedListener struct {
net.Listener
- stopped bool
- server *Server
+ server *Server
}
+var (
+ _ net.Listener = (*wrappedListener)(nil)
+ _ filer = (*wrappedListener)(nil)
+)
+
func newWrappedListener(l net.Listener, srv *Server) *wrappedListener {
return &wrappedListener{
Listener: l,
@@ -195,46 +242,24 @@ func newWrappedListener(l net.Listener, srv *Server) *wrappedListener {
}
}
-func (wl *wrappedListener) Accept() (net.Conn, error) {
- var c net.Conn
- // Set keepalive on TCPListeners connections.
+func (wl *wrappedListener) Accept() (c net.Conn, err error) {
if tcl, ok := wl.Listener.(*net.TCPListener); ok {
+ // Set keepalive on TCPListeners connections if possible, see http.tcpKeepAliveListener
tc, err := tcl.AcceptTCP()
if err != nil {
return nil, err
}
- _ = tc.SetKeepAlive(true) // see http.tcpKeepAliveListener
- _ = tc.SetKeepAlivePeriod(3 * time.Minute) // see http.tcpKeepAliveListener
+ _ = tc.SetKeepAlive(true)
+ _ = tc.SetKeepAlivePeriod(3 * time.Minute)
c = tc
} else {
- var err error
c, err = wl.Listener.Accept()
if err != nil {
return nil, err
}
}
- closed := int32(0)
-
- c = &wrappedConn{
- Conn: c,
- server: wl.server,
- closed: &closed,
- perWriteTimeout: wl.server.PerWriteTimeout,
- perWritePerKbTimeout: wl.server.PerWritePerKbTimeout,
- }
-
- wl.server.wg.Add(1)
- return c, nil
-}
-
-func (wl *wrappedListener) Close() error {
- if wl.stopped {
- return syscall.EINVAL
- }
-
- wl.stopped = true
- return wl.Listener.Close()
+ return wl.server.wrapConnection(c)
}
func (wl *wrappedListener) File() (*os.File, error) {
@@ -244,17 +269,14 @@ func (wl *wrappedListener) File() (*os.File, error) {
type wrappedConn struct {
net.Conn
- server *Server
- closed *int32
- deadline time.Time
- perWriteTimeout time.Duration
- perWritePerKbTimeout time.Duration
+ server *Server
+ deadline time.Time
}
func (w *wrappedConn) Write(p []byte) (n int, err error) {
- if w.perWriteTimeout > 0 {
- minTimeout := time.Duration(len(p)/1024) * w.perWritePerKbTimeout
- minDeadline := time.Now().Add(minTimeout).Add(w.perWriteTimeout)
+ if w.server.PerWriteTimeout > 0 {
+ minTimeout := time.Duration(len(p)/1024) * w.server.PerWritePerKbTimeout
+ minDeadline := time.Now().Add(minTimeout).Add(w.server.PerWriteTimeout)
w.deadline = w.deadline.Add(minTimeout)
if minDeadline.After(w.deadline) {
@@ -266,19 +288,6 @@ func (w *wrappedConn) Write(p []byte) (n int, err error) {
}
func (w *wrappedConn) Close() error {
- if atomic.CompareAndSwapInt32(w.closed, 0, 1) {
- defer func() {
- if err := recover(); err != nil {
- select {
- case <-GetManager().IsHammer():
- // Likely deadlocked request released at hammertime
- log.Warn("Panic during connection close! %v. Likely there has been a deadlocked request which has been released by forced shutdown.", err)
- default:
- log.Error("Panic during connection close! %v", err)
- }
- }
- }()
- w.server.wg.Done()
- }
+ w.server.removeConnection(w)
return w.Conn.Close()
}
diff --git a/modules/graceful/server_hooks.go b/modules/graceful/server_hooks.go
index 9b67589571..b800c32503 100644
--- a/modules/graceful/server_hooks.go
+++ b/modules/graceful/server_hooks.go
@@ -5,7 +5,6 @@ package graceful
import (
"os"
- "runtime"
"code.gitea.io/gitea/modules/log"
)
@@ -48,26 +47,8 @@ func (srv *Server) doShutdown() {
}
func (srv *Server) doHammer() {
- defer func() {
- // We call srv.wg.Done() until it panics.
- // This happens if we call Done() when the WaitGroup counter is already at 0
- // So if it panics -> we're done, Serve() will return and the
- // parent will goroutine will exit.
- if r := recover(); r != nil {
- log.Error("WaitGroup at 0: Error: %v", r)
- }
- }()
if srv.getState() != stateShuttingDown {
return
}
- log.Warn("Forcefully shutting down parent")
- for {
- if srv.getState() == stateTerminate {
- break
- }
- srv.wg.Done()
-
- // Give other goroutines a chance to finish before we forcibly stop them.
- runtime.Gosched()
- }
+ srv.closeAllConnections()
}
diff --git a/modules/graceful/server_http.go b/modules/graceful/server_http.go
index 7c855ac64e..77a2c3b6f8 100644
--- a/modules/graceful/server_http.go
+++ b/modules/graceful/server_http.go
@@ -12,7 +12,12 @@ import (
func newHTTPServer(network, address, name string, handler http.Handler) (*Server, ServeFunction) {
server := NewServer(network, address, name)
+ protocols := http.Protocols{}
+ protocols.SetHTTP1(true)
+ protocols.SetHTTP2(true) // HTTP/2 can only be used when Gitea is configured to use TLS
+ protocols.SetUnencryptedHTTP2(true) // Allow HTTP/2 without TLS, in case Gitea is behind a reverse proxy
httpServer := http.Server{
+ Protocols: &protocols,
Handler: handler,
BaseContext: func(net.Listener) context.Context { return GetManager().HammerContext() },
}
diff --git a/modules/hcaptcha/hcaptcha_test.go b/modules/hcaptcha/hcaptcha_test.go
index 5906faf17c..6b207bfb77 100644
--- a/modules/hcaptcha/hcaptcha_test.go
+++ b/modules/hcaptcha/hcaptcha_test.go
@@ -8,7 +8,6 @@ import (
"io"
"net/http"
"net/url"
- "os"
"strings"
"testing"
"time"
@@ -20,10 +19,6 @@ const (
dummyToken = "10000000-aaaa-bbbb-cccc-000000000001"
)
-func TestMain(m *testing.M) {
- os.Exit(m.Run())
-}
-
type mockTransport struct{}
func (mockTransport) RoundTrip(req *http.Request) (*http.Response, error) {
diff --git a/modules/highlight/highlight.go b/modules/highlight/highlight.go
index 77f24fa3f3..dca28588e4 100644
--- a/modules/highlight/highlight.go
+++ b/modules/highlight/highlight.go
@@ -5,221 +5,159 @@
package highlight
import (
- "bufio"
"bytes"
- "fmt"
gohtml "html"
"html/template"
- "io"
- "path"
- "path/filepath"
- "strings"
"sync"
- "code.gitea.io/gitea/modules/analyze"
"code.gitea.io/gitea/modules/log"
"code.gitea.io/gitea/modules/setting"
"code.gitea.io/gitea/modules/util"
"github.com/alecthomas/chroma/v2"
- "github.com/alecthomas/chroma/v2/formatters/html"
- "github.com/alecthomas/chroma/v2/lexers"
+ chromahtml "github.com/alecthomas/chroma/v2/formatters/html"
"github.com/alecthomas/chroma/v2/styles"
- lru "github.com/hashicorp/golang-lru/v2"
)
-// don't index files larger than this many bytes for performance purposes
+// don't highlight files larger than this many bytes for performance purposes
const sizeLimit = 1024 * 1024
-var (
- // For custom user mapping
- highlightMapping = map[string]string{}
-
- once sync.Once
-
- cache *lru.TwoQueueCache[string, any]
+type globalVarsType struct {
+ highlightMapping map[string]string
+ githubStyles *chroma.Style
+}
- githubStyles = styles.Get("github")
+var (
+ globalVarsMu sync.Mutex
+ globalVarsPtr *globalVarsType
)
-// NewContext loads custom highlight map from local config
-func NewContext() {
- once.Do(func() {
- highlightMapping = setting.GetHighlightMapping()
+func globalVars() *globalVarsType {
+ // in the future, the globalVars might need to be re-initialized when settings change, so don't use sync.Once here
+ globalVarsMu.Lock()
+ defer globalVarsMu.Unlock()
+ if globalVarsPtr == nil {
+ globalVarsPtr = &globalVarsType{}
+ globalVarsPtr.githubStyles = styles.Get("github")
+ globalVarsPtr.highlightMapping = setting.GetHighlightMapping()
+ }
+ return globalVarsPtr
+}
- // The size 512 is simply a conservative rule of thumb
- c, err := lru.New2Q[string, any](512)
- if err != nil {
- panic(fmt.Sprintf("failed to initialize LRU cache for highlighter: %s", err))
+// UnsafeSplitHighlightedLines splits highlighted code into lines preserving HTML tags
+// It always includes '\n', '\n' can appear at the end of each line or in the middle of HTML tags
+// The '\n' is necessary for copying code from web UI to preserve original code lines
+// ATTENTION: It uses the unsafe conversion between string and []byte for performance reason
+// DO NOT make any modification to the returned [][]byte slice items
+func UnsafeSplitHighlightedLines(code template.HTML) (ret [][]byte) {
+ buf := util.UnsafeStringToBytes(string(code))
+ lineCount := bytes.Count(buf, []byte("\n")) + 1
+ ret = make([][]byte, 0, lineCount)
+ nlTagClose := []byte("\n")
+ for {
+ pos := bytes.IndexByte(buf, '\n')
+ if pos == -1 {
+ if len(buf) > 0 {
+ ret = append(ret, buf)
+ }
+ return ret
+ }
+ // Chroma highlighting output sometimes have "" right after \n, sometimes before.
+ // * "text\n "
+ // * "text \n"
+ if bytes.HasPrefix(buf[pos:], nlTagClose) {
+ pos1 := bytes.IndexByte(buf[pos:], '>')
+ if pos1 != -1 {
+ pos += pos1
+ }
}
- cache = c
- })
+ ret = append(ret, buf[:pos+1])
+ buf = buf[pos+1:]
+ }
}
-// Code returns a HTML version of code string with chroma syntax highlighting classes and the matched lexer name
-func Code(fileName, language, code string) (output template.HTML, lexerName string) {
- NewContext()
+func htmlEscape(code string) template.HTML {
+ return template.HTML(gohtml.EscapeString(code))
+}
+// RenderCodeSlowGuess tries to get a lexer by file name and language first,
+// if not found, it will try to guess the lexer by code content, which is slow (more than several hundreds of milliseconds).
+func RenderCodeSlowGuess(fileName, language, code string) (output template.HTML, lexer chroma.Lexer, lexerDisplayName string) {
// diff view newline will be passed as empty, change to literal '\n' so it can be copied
// preserve literal newline in blame view
if code == "" || code == "\n" {
- return "\n", ""
+ return "\n", nil, ""
}
if len(code) > sizeLimit {
- return template.HTML(template.HTMLEscapeString(code)), ""
- }
-
- var lexer chroma.Lexer
-
- if len(language) > 0 {
- lexer = lexers.Get(language)
-
- if lexer == nil {
- // Attempt stripping off the '?'
- if idx := strings.IndexByte(language, '?'); idx > 0 {
- lexer = lexers.Get(language[:idx])
- }
- }
+ return htmlEscape(code), nil, ""
}
- if lexer == nil {
- if val, ok := highlightMapping[path.Ext(fileName)]; ok {
- // use mapped value to find lexer
- lexer = lexers.Get(val)
- }
- }
-
- if lexer == nil {
- if l, ok := cache.Get(fileName); ok {
- lexer = l.(chroma.Lexer)
- }
- }
-
- if lexer == nil {
- lexer = lexers.Match(fileName)
- if lexer == nil {
- lexer = lexers.Fallback
- }
- cache.Add(fileName, lexer)
- }
-
- return CodeFromLexer(lexer, code), formatLexerName(lexer.Config().Name)
+ lexer = detectChromaLexerWithAnalyze(fileName, language, util.UnsafeStringToBytes(code)) // it is also slow
+ return RenderCodeByLexer(lexer, code), lexer, formatLexerName(lexer.Config().Name)
}
-// CodeFromLexer returns a HTML version of code string with chroma syntax highlighting classes
-func CodeFromLexer(lexer chroma.Lexer, code string) template.HTML {
- formatter := html.New(html.WithClasses(true),
- html.WithLineNumbers(false),
- html.PreventSurroundingPre(true),
+// RenderCodeByLexer returns a HTML version of code string with chroma syntax highlighting classes
+func RenderCodeByLexer(lexer chroma.Lexer, code string) template.HTML {
+ formatter := chromahtml.New(chromahtml.WithClasses(true),
+ chromahtml.WithLineNumbers(false),
+ chromahtml.PreventSurroundingPre(true),
)
- htmlbuf := bytes.Buffer{}
- htmlw := bufio.NewWriter(&htmlbuf)
-
iterator, err := lexer.Tokenise(nil, code)
if err != nil {
log.Error("Can't tokenize code: %v", err)
- return template.HTML(template.HTMLEscapeString(code))
+ return htmlEscape(code)
}
+
+ htmlBuf := &bytes.Buffer{}
// style not used for live site but need to pass something
- err = formatter.Format(htmlw, githubStyles, iterator)
+ err = formatter.Format(htmlBuf, globalVars().githubStyles, iterator)
if err != nil {
log.Error("Can't format code: %v", err)
- return template.HTML(template.HTMLEscapeString(code))
+ return htmlEscape(code)
}
-
- _ = htmlw.Flush()
- // Chroma will add newlines for certain lexers in order to highlight them properly
- // Once highlighted, strip them here, so they don't cause copy/paste trouble in HTML output
- return template.HTML(strings.TrimSuffix(htmlbuf.String(), "\n"))
+ return template.HTML(util.UnsafeBytesToString(htmlBuf.Bytes()))
}
-// File returns a slice of chroma syntax highlighted HTML lines of code and the matched lexer name
-func File(fileName, language string, code []byte) ([]template.HTML, string, error) {
- NewContext()
-
- if len(code) > sizeLimit {
- return PlainText(code), "", nil
+// RenderFullFile returns a slice of chroma syntax highlighted HTML lines of code and the matched lexer name
+func RenderFullFile(fileName, language string, code []byte) ([]template.HTML, string) {
+ if language == LanguagePlaintext || len(code) > sizeLimit {
+ return renderPlainText(code), formatLexerName(LanguagePlaintext)
}
-
- formatter := html.New(html.WithClasses(true),
- html.WithLineNumbers(false),
- html.PreventSurroundingPre(true),
- )
-
- var lexer chroma.Lexer
-
- // provided language overrides everything
- if language != "" {
- lexer = lexers.Get(language)
- }
-
- if lexer == nil {
- if val, ok := highlightMapping[filepath.Ext(fileName)]; ok {
- lexer = lexers.Get(val)
- }
- }
-
- if lexer == nil {
- guessLanguage := analyze.GetCodeLanguage(fileName, code)
-
- lexer = lexers.Get(guessLanguage)
- if lexer == nil {
- lexer = lexers.Match(fileName)
- if lexer == nil {
- lexer = lexers.Fallback
- }
- }
- }
-
+ lexer := detectChromaLexerWithAnalyze(fileName, language, code)
lexerName := formatLexerName(lexer.Config().Name)
-
- iterator, err := lexer.Tokenise(nil, string(code))
- if err != nil {
- return nil, "", fmt.Errorf("can't tokenize code: %w", err)
- }
-
- tokensLines := chroma.SplitTokensIntoLines(iterator.Tokens())
- htmlBuf := &bytes.Buffer{}
-
- lines := make([]template.HTML, 0, len(tokensLines))
- for _, tokens := range tokensLines {
- iterator = chroma.Literator(tokens...)
- err = formatter.Format(htmlBuf, githubStyles, iterator)
- if err != nil {
- return nil, "", fmt.Errorf("can't format code: %w", err)
- }
- lines = append(lines, template.HTML(htmlBuf.String()))
- htmlBuf.Reset()
+ rendered := RenderCodeByLexer(lexer, util.UnsafeBytesToString(code))
+ unsafeLines := UnsafeSplitHighlightedLines(rendered)
+ lines := make([]template.HTML, len(unsafeLines))
+ for idx, lineBytes := range unsafeLines {
+ lines[idx] = template.HTML(util.UnsafeBytesToString(lineBytes))
}
-
- return lines, lexerName, nil
+ return lines, lexerName
}
-// PlainText returns non-highlighted HTML for code
-func PlainText(code []byte) []template.HTML {
- r := bufio.NewReader(bytes.NewReader(code))
- m := make([]template.HTML, 0, bytes.Count(code, []byte{'\n'})+1)
- for {
- content, err := r.ReadString('\n')
- if err != nil && err != io.EOF {
- log.Error("failed to read string from buffer: %v", err)
- break
- }
- if content == "" && err == io.EOF {
- break
+// renderPlainText returns non-highlighted HTML for code
+func renderPlainText(code []byte) []template.HTML {
+ lines := make([]template.HTML, 0, bytes.Count(code, []byte{'\n'})+1)
+ pos := 0
+ for pos < len(code) {
+ var content []byte
+ nextPos := bytes.IndexByte(code[pos:], '\n')
+ if nextPos == -1 {
+ content = code[pos:]
+ pos = len(code)
+ } else {
+ content = code[pos : pos+nextPos+1]
+ pos += nextPos + 1
}
- s := template.HTML(gohtml.EscapeString(content))
- m = append(m, s)
+ lines = append(lines, htmlEscape(util.UnsafeBytesToString(content)))
}
- return m
+ return lines
}
func formatLexerName(name string) string {
- if name == "fallback" {
+ if name == LanguagePlaintext || name == chromaLexerFallback {
return "Plaintext"
}
-
return util.ToTitleCaseNoLower(name)
}
diff --git a/modules/highlight/highlight_test.go b/modules/highlight/highlight_test.go
index b36de98c5c..211132b255 100644
--- a/modules/highlight/highlight_test.go
+++ b/modules/highlight/highlight_test.go
@@ -108,12 +108,17 @@ c=2
),
lexerName: "Python",
},
+ {
+ name: "test.sql",
+ code: "--\nSELECT",
+ want: []template.HTML{"--\n ", `SELECT `},
+ lexerName: "SQL",
+ },
}
for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) {
- out, lexerName, err := File(tt.name, "", []byte(tt.code))
- assert.NoError(t, err)
+ out, lexerName := RenderFullFile(tt.name, "", []byte(tt.code))
assert.Equal(t, tt.want, out)
assert.Equal(t, tt.lexerName, lexerName)
})
@@ -176,8 +181,26 @@ c=2`),
for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) {
- out := PlainText([]byte(tt.code))
+ out := renderPlainText([]byte(tt.code))
assert.Equal(t, tt.want, out)
})
}
}
+
+func TestUnsafeSplitHighlightedLines(t *testing.T) {
+ ret := UnsafeSplitHighlightedLines("")
+ assert.Empty(t, ret)
+
+ ret = UnsafeSplitHighlightedLines("a")
+ assert.Len(t, ret, 1)
+ assert.Equal(t, "a", string(ret[0]))
+
+ ret = UnsafeSplitHighlightedLines("\n")
+ assert.Len(t, ret, 1)
+ assert.Equal(t, "\n", string(ret[0]))
+
+ ret = UnsafeSplitHighlightedLines("a \nb\n ")
+ assert.Len(t, ret, 2)
+ assert.Equal(t, "a \n", string(ret[0]))
+ assert.Equal(t, "b\n ", string(ret[1]))
+}
diff --git a/modules/highlight/lexerdetect.go b/modules/highlight/lexerdetect.go
new file mode 100644
index 0000000000..fe430f463f
--- /dev/null
+++ b/modules/highlight/lexerdetect.go
@@ -0,0 +1,311 @@
+// Copyright 2026 The Gitea Authors. All rights reserved.
+// SPDX-License-Identifier: MIT
+
+package highlight
+
+import (
+ "path"
+ "strings"
+ "sync"
+
+ "code.gitea.io/gitea/modules/analyze"
+ "code.gitea.io/gitea/modules/log"
+
+ "github.com/alecthomas/chroma/v2"
+ "github.com/alecthomas/chroma/v2/lexers"
+ "github.com/go-enry/go-enry/v2"
+)
+
+const (
+ mapKeyLowerPrefix = "lower/"
+ LanguagePlaintext = "plaintext"
+ chromaLexerFallback = "fallback"
+)
+
+// chromaLexers is fully managed by us to do fast lookup for chroma lexers by file name or language name
+// Don't use lexers.Get because it is very slow in many cases (iterate all rules, filepath glob match, etc.)
+var chromaLexers = sync.OnceValue(func() (ret struct {
+ conflictingExtLangMap map[string]string
+ conflictingAliasLangMap map[string]string
+
+ lowerNameMap map[string]chroma.Lexer // lexer name (lang name) in lower-case
+ fileBaseMap map[string]chroma.Lexer
+ fileExtMap map[string]chroma.Lexer
+ fileParts []struct {
+ part string
+ lexer chroma.Lexer
+ }
+},
+) {
+ ret.lowerNameMap = make(map[string]chroma.Lexer)
+ ret.fileBaseMap = make(map[string]chroma.Lexer)
+ ret.fileExtMap = make(map[string]chroma.Lexer)
+
+ // Chroma has conflicts in file extension for different languages,
+ // When we need to do fast render, there is no way to detect the language by content,
+ // So we can only choose some default languages for the conflicted file extensions.
+ ret.conflictingExtLangMap = map[string]string{
+ ".as": "ActionScript 3", // ActionScript
+ ".asm": "NASM", // TASM, NASM, RGBDS Assembly, Z80 Assembly
+ ".ASM": "NASM",
+ ".bas": "VB.net", // QBasic
+ ".bf": "Beef", // Brainfuck
+ ".fs": "FSharp", // Forth
+ ".gd": "GDScript", // GDScript3
+ ".h": "C", // Objective-C
+ ".hcl": "Terraform", // HCL
+ ".hh": "C++", // HolyC
+ ".inc": "PHP", // ObjectPascal, POVRay, SourcePawn, PHTML
+ ".m": "Objective-C", // Matlab, Mathematica, Mason
+ ".mc": "Mason", // MonkeyC
+ ".network": "SYSTEMD", // INI
+ ".php": "PHP", // PHTML
+ ".php3": "PHP", // PHTML
+ ".php4": "PHP", // PHTML
+ ".php5": "PHP", // PHTML
+ ".pl": "Perl", // Prolog, Raku
+ ".pm": "Perl", // Promela, Raku
+ ".pp": "ObjectPascal", // Puppet
+ ".s": "ArmAsm", // GAS
+ ".S": "ArmAsm", // R, GAS
+ ".service": "SYSTEMD", // INI
+ ".socket": "SYSTEMD", // INI
+ ".sql": "SQL", // MySQL
+ ".t": "Perl", // Raku
+ ".ts": "TypeScript", // TypoScript
+ ".v": "V", // verilog
+ ".xslt": "HTML", // XML
+ }
+ // use widely used language names as the default mapping to resolve name alias conflict
+ ret.conflictingAliasLangMap = map[string]string{
+ "hcl": "HCL", // Terraform
+ "v": "V", // verilog
+ }
+
+ isPlainPattern := func(key string) bool {
+ return !strings.ContainsAny(key, "*?[]") // only support simple patterns
+ }
+
+ setFileNameMapWithLowerKey := func(m map[string]chroma.Lexer, key string, lexer chroma.Lexer) {
+ if _, conflict := m[key]; conflict {
+ panic("duplicate key in lexer map: " + key + ", need to add it to conflictingExtLangMap")
+ }
+ m[key] = lexer
+ m[mapKeyLowerPrefix+strings.ToLower(key)] = lexer
+ }
+
+ processFileName := func(fileName string, lexer chroma.Lexer) bool {
+ if isPlainPattern(fileName) {
+ // full base name match
+ setFileNameMapWithLowerKey(ret.fileBaseMap, fileName, lexer)
+ return true
+ }
+ if strings.HasPrefix(fileName, "*") {
+ // ext name match: "*.js"
+ fileExt := strings.Trim(fileName, "*")
+ if isPlainPattern(fileExt) {
+ presetName := ret.conflictingExtLangMap[fileExt]
+ if presetName == "" || lexer.Config().Name == presetName {
+ setFileNameMapWithLowerKey(ret.fileExtMap, fileExt, lexer)
+ }
+ return true
+ }
+ }
+ if strings.HasSuffix(fileName, "*") {
+ // part match: "*.env.*"
+ filePart := strings.Trim(fileName, "*")
+ if isPlainPattern(filePart) {
+ ret.fileParts = append(ret.fileParts, struct {
+ part string
+ lexer chroma.Lexer
+ }{
+ part: filePart,
+ lexer: lexer,
+ })
+ return true
+ }
+ }
+ return false
+ }
+
+ expandGlobPatterns := func(patterns []string) []string {
+ // expand patterns like "file.[ch]" to "file.c" and "file.h", only one pair of "[]" is supported, enough for current Chroma lexers
+ for idx, s := range patterns {
+ idx1 := strings.IndexByte(s, '[')
+ idx2 := strings.IndexByte(s, ']')
+ if idx1 != -1 && idx2 != -1 && idx2 > idx1+1 {
+ left, mid, right := s[:idx1], s[idx1+1:idx2], s[idx2+1:]
+ patterns[idx] = left + mid[0:1] + right
+ for i := 1; i < len(mid); i++ {
+ patterns = append(patterns, left+mid[i:i+1]+right)
+ }
+ }
+ }
+ return patterns
+ }
+
+ processLexerNameAliases := func(lexer chroma.Lexer) {
+ cfg := lexer.Config()
+ lowerName := strings.ToLower(cfg.Name)
+ if _, conflicted := ret.lowerNameMap[lowerName]; conflicted {
+ panic("duplicate language name in lexer map: " + lowerName)
+ }
+ ret.lowerNameMap[lowerName] = lexer
+
+ for _, name := range cfg.Aliases {
+ lowerName := strings.ToLower(name)
+ if overriddenName, overridden := ret.conflictingAliasLangMap[lowerName]; overridden && overriddenName != cfg.Name {
+ continue
+ }
+ if existingLexer, conflict := ret.lowerNameMap[lowerName]; conflict && existingLexer.Config().Name != cfg.Name {
+ panic("duplicate alias in lexer map: " + name + ", conflict between " + existingLexer.Config().Name + " and " + cfg.Name)
+ }
+ ret.lowerNameMap[lowerName] = lexer
+ }
+ }
+
+ // the main loop: build our lookup maps for lexers
+ for _, lexer := range lexers.GlobalLexerRegistry.Lexers {
+ cfg := lexer.Config()
+ processLexerNameAliases(lexer)
+ for _, s := range expandGlobPatterns(cfg.Filenames) {
+ if !processFileName(s, lexer) {
+ panic("unsupported file name pattern in lexer: " + s)
+ }
+ }
+ for _, s := range expandGlobPatterns(cfg.AliasFilenames) {
+ if !processFileName(s, lexer) {
+ panic("unsupported alias file name pattern in lexer: " + s)
+ }
+ }
+ }
+
+ // final check: make sure the default overriding mapping is correct, nothing is missing
+ for lowerName, lexerName := range ret.conflictingAliasLangMap {
+ if lexer, ok := ret.lowerNameMap[lowerName]; !ok || lexer.Config().Name != lexerName {
+ panic("missing default name-lang mapping for: " + lowerName)
+ }
+ }
+ for ext, lexerName := range ret.conflictingExtLangMap {
+ if lexer, ok := ret.fileExtMap[ext]; !ok || lexer.Config().Name != lexerName {
+ panic("missing default ext-lang mapping for: " + ext)
+ }
+ }
+ return ret
+})
+
+func normalizeFileNameLang(fileName, fileLang string) (string, string) {
+ fileName = path.Base(fileName)
+ fileLang, _, _ = strings.Cut(fileLang, "?") // maybe, the value from gitattributes might contain `?` parameters?
+ ext := path.Ext(fileName)
+ // the "lang" might come from enry or gitattributes, it has different naming for some languages
+ switch fileLang {
+ case "F#":
+ fileLang = "FSharp"
+ case "Pascal":
+ fileLang = "ObjectPascal"
+ case "C":
+ if ext == ".C" || ext == ".H" {
+ fileLang = "C++"
+ }
+ }
+ return fileName, fileLang
+}
+
+func DetectChromaLexerByFileName(fileName, fileLang string) chroma.Lexer {
+ lexer, _ := detectChromaLexerByFileName(fileName, fileLang)
+ return lexer
+}
+
+func detectChromaLexerByFileName(fileName, fileLang string) (_ chroma.Lexer, byLang bool) {
+ fileName, fileLang = normalizeFileNameLang(fileName, fileLang)
+ fileExt := path.Ext(fileName)
+
+ // apply custom mapping for file extension, highest priority, for example:
+ // * ".my-js" -> ".js"
+ // * ".my-html" -> "HTML"
+ if fileExt != "" {
+ if val, ok := globalVars().highlightMapping[fileExt]; ok {
+ if strings.HasPrefix(val, ".") {
+ fileName = "dummy" + val
+ fileLang = ""
+ } else {
+ fileLang = val
+ }
+ }
+ }
+
+ // try to use language for lexer name
+ if fileLang != "" {
+ lexer := chromaLexers().lowerNameMap[strings.ToLower(fileLang)]
+ if lexer != nil {
+ return lexer, true
+ }
+ }
+
+ if fileName == "" {
+ return lexers.Fallback, false
+ }
+
+ // try base name
+ {
+ baseName := path.Base(fileName)
+ if lexer, ok := chromaLexers().fileBaseMap[baseName]; ok {
+ return lexer, false
+ } else if lexer, ok = chromaLexers().fileBaseMap[mapKeyLowerPrefix+strings.ToLower(baseName)]; ok {
+ return lexer, false
+ }
+ }
+
+ if fileExt == "" {
+ return lexers.Fallback, false
+ }
+
+ // try ext name
+ {
+ if lexer, ok := chromaLexers().fileExtMap[fileExt]; ok {
+ return lexer, false
+ } else if lexer, ok = chromaLexers().fileExtMap[mapKeyLowerPrefix+strings.ToLower(fileExt)]; ok {
+ return lexer, false
+ }
+ }
+
+ // try file part match, for example: ".env.local" for "*.env.*"
+ // it assumes that there must be a dot in filename (fileExt isn't empty)
+ for _, item := range chromaLexers().fileParts {
+ if strings.Contains(fileName, item.part) {
+ return item.lexer, false
+ }
+ }
+ return lexers.Fallback, false
+}
+
+// detectChromaLexerWithAnalyze returns a chroma lexer by given file name, language and code content. All parameters can be optional.
+// When code content is provided, it will be slow if no lexer is found by file name or language.
+// If no lexer is found, it will return the fallback lexer.
+func detectChromaLexerWithAnalyze(fileName, lang string, code []byte) chroma.Lexer {
+ lexer, byLang := detectChromaLexerByFileName(fileName, lang)
+
+ // if lang is provided, and it matches a lexer, use it directly
+ if byLang {
+ return lexer
+ }
+
+ // if a lexer is detected and there is no conflict for the file extension, use it directly
+ fileExt := path.Ext(fileName)
+ _, hasConflicts := chromaLexers().conflictingExtLangMap[fileExt]
+ if !hasConflicts && lexer != lexers.Fallback {
+ return lexer
+ }
+
+ // try to detect language by content, for best guessing for the language
+ // when using "code" to detect, analyze.GetCodeLanguage is slow, it iterates many rules to detect language from content
+ analyzedLanguage := analyze.GetCodeLanguage(fileName, code)
+ lexer = DetectChromaLexerByFileName(fileName, analyzedLanguage)
+ if lexer == lexers.Fallback {
+ if analyzedLanguage != enry.OtherLanguage {
+ log.Warn("No chroma lexer found for enry detected language: %s (file: %s), need to fix the language mapping between enry and chroma.", analyzedLanguage, fileName)
+ }
+ }
+ return lexer
+}
diff --git a/modules/highlight/lexerdetect_test.go b/modules/highlight/lexerdetect_test.go
new file mode 100644
index 0000000000..a06053be0c
--- /dev/null
+++ b/modules/highlight/lexerdetect_test.go
@@ -0,0 +1,116 @@
+// Copyright 2026 The Gitea Authors. All rights reserved.
+// SPDX-License-Identifier: MIT
+
+package highlight
+
+import (
+ "strings"
+ "testing"
+
+ "github.com/alecthomas/chroma/v2/lexers"
+ "github.com/stretchr/testify/assert"
+)
+
+func BenchmarkDetectChromaLexerByFileName(b *testing.B) {
+ for b.Loop() {
+ // BenchmarkDetectChromaLexerByFileName-12 18214717 61.35 ns/op
+ DetectChromaLexerByFileName("a.sql", "")
+ }
+}
+
+func BenchmarkDetectChromaLexerWithAnalyze(b *testing.B) {
+ b.StopTimer()
+ code := []byte(strings.Repeat("SELECT * FROM table;\n", 1000))
+ b.StartTimer()
+ for b.Loop() {
+ // BenchmarkRenderCodeSlowGuess-12 87946 13310 ns/op
+ detectChromaLexerWithAnalyze("a", "", code)
+ }
+}
+
+func BenchmarkChromaAnalyze(b *testing.B) {
+ b.StopTimer()
+ code := strings.Repeat("SELECT * FROM table;\n", 1000)
+ b.StartTimer()
+ for b.Loop() {
+ // comparing to detectChromaLexerWithAnalyze (go-enry), "chroma/lexers.Analyse" is very slow
+ // BenchmarkChromaAnalyze-12 519 2247104 ns/op
+ lexers.Analyse(code)
+ }
+}
+
+func BenchmarkRenderCodeByLexer(b *testing.B) {
+ b.StopTimer()
+ code := strings.Repeat("SELECT * FROM table;\n", 1000)
+ lexer := DetectChromaLexerByFileName("a.sql", "")
+ b.StartTimer()
+ for b.Loop() {
+ // Really slow ....... the regexp2 used by Chroma takes most of the time
+ // BenchmarkRenderCodeByLexer-12 22 47159038 ns/op
+ RenderCodeByLexer(lexer, code)
+ }
+}
+
+func TestDetectChromaLexer(t *testing.T) {
+ globalVars().highlightMapping[".my-html"] = "HTML"
+ t.Cleanup(func() { delete(globalVars().highlightMapping, ".my-html") })
+
+ casesWithContent := []struct {
+ fileName string
+ language string
+ content string
+ expected string
+ }{
+ {"test.v", "", "", "V"},
+ {"test.v", "any-lang-name", "", "V"},
+
+ {"any-file", "javascript", "", "JavaScript"},
+ {"any-file", "", "/* vim: set filetype=python */", "Python"},
+ {"any-file", "", "", "fallback"},
+
+ {"test.fs", "", "", "FSharp"},
+ {"test.fs", "F#", "", "FSharp"},
+ {"test.fs", "", "let x = 1", "FSharp"},
+
+ {"test.c", "", "", "C"},
+ {"test.C", "", "", "C++"},
+ {"OLD-CODE.PAS", "", "", "ObjectPascal"},
+ {"test.my-html", "", "", "HTML"},
+
+ {"a.php", "", "", "PHP"},
+ {"a.sql", "", "", "SQL"},
+ {"dhcpd.conf", "", "", "ISCdhcpd"},
+ {".env.my-production", "", "", "Bash"},
+
+ {"a.hcl", "", "", "HCL"}, // not the same as Chroma, enry detects "*.hcl" as "HCL"
+ {"a.hcl", "HCL", "", "HCL"},
+ {"a.hcl", "Terraform", "", "Terraform"},
+ }
+ for _, c := range casesWithContent {
+ lexer := detectChromaLexerWithAnalyze(c.fileName, c.language, []byte(c.content))
+ if assert.NotNil(t, lexer, "case: %+v", c) {
+ assert.Equal(t, c.expected, lexer.Config().Name, "case: %+v", c)
+ }
+ }
+
+ casesNameLang := []struct {
+ fileName string
+ language string
+ expected string
+ byLang bool
+ }{
+ {"a.v", "", "V", false},
+ {"a.v", "V", "V", true},
+ {"a.v", "verilog", "verilog", true},
+ {"a.v", "any-lang-name", "V", false},
+
+ {"a.hcl", "", "Terraform", false}, // not the same as enry
+ {"a.hcl", "HCL", "HCL", true},
+ {"a.hcl", "Terraform", "Terraform", true},
+ }
+ for _, c := range casesNameLang {
+ lexer, byLang := detectChromaLexerByFileName(c.fileName, c.language)
+ assert.Equal(t, c.expected, lexer.Config().Name, "case: %+v", c)
+ assert.Equal(t, c.byLang, byLang, "case: %+v", c)
+ }
+}
diff --git a/modules/htmlutil/html.go b/modules/htmlutil/html.go
index efbc174b2e..8dbfe0c22e 100644
--- a/modules/htmlutil/html.go
+++ b/modules/htmlutil/html.go
@@ -6,6 +6,7 @@ package htmlutil
import (
"fmt"
"html/template"
+ "io"
"slices"
"strings"
)
@@ -31,7 +32,7 @@ func ParseSizeAndClass(defaultSize int, defaultClass string, others ...any) (int
return size, class
}
-func HTMLFormat(s template.HTML, rawArgs ...any) template.HTML {
+func htmlFormatArgs(s template.HTML, rawArgs []any) []any {
if !strings.Contains(string(s), "%") || len(rawArgs) == 0 {
panic("HTMLFormat requires one or more arguments")
}
@@ -50,5 +51,35 @@ func HTMLFormat(s template.HTML, rawArgs ...any) template.HTML {
args[i] = template.HTMLEscapeString(fmt.Sprint(v))
}
}
- return template.HTML(fmt.Sprintf(string(s), args...))
+ return args
+}
+
+func HTMLFormat(s template.HTML, rawArgs ...any) template.HTML {
+ return template.HTML(fmt.Sprintf(string(s), htmlFormatArgs(s, rawArgs)...))
+}
+
+func HTMLPrintf(w io.Writer, s template.HTML, rawArgs ...any) (int, error) {
+ return fmt.Fprintf(w, string(s), htmlFormatArgs(s, rawArgs)...)
+}
+
+func HTMLPrint(w io.Writer, s template.HTML) (int, error) {
+ return io.WriteString(w, string(s))
+}
+
+func HTMLPrintTag(w io.Writer, tag template.HTML, attrs map[string]string) (written int, err error) {
+ n, err := io.WriteString(w, "<"+string(tag))
+ written += n
+ if err != nil {
+ return written, err
+ }
+ for k, v := range attrs {
+ n, err = fmt.Fprintf(w, ` %s="%s"`, template.HTMLEscapeString(k), template.HTMLEscapeString(v))
+ written += n
+ if err != nil {
+ return written, err
+ }
+ }
+ n, err = io.WriteString(w, ">")
+ written += n
+ return written, err
}
diff --git a/modules/httpcache/httpcache.go b/modules/httpcache/httpcache.go
index dd3efab7a5..e23cf0a92a 100644
--- a/modules/httpcache/httpcache.go
+++ b/modules/httpcache/httpcache.go
@@ -60,21 +60,6 @@ func CacheControlForPrivateStatic() *CacheControlOptions {
}
}
-// HandleGenericETagCache handles ETag-based caching for a HTTP request.
-// It returns true if the request was handled.
-func HandleGenericETagCache(req *http.Request, w http.ResponseWriter, etag string) (handled bool) {
- if len(etag) > 0 {
- w.Header().Set("Etag", etag)
- if checkIfNoneMatchIsValid(req, etag) {
- w.WriteHeader(http.StatusNotModified)
- return true
- }
- }
- // not sure whether it is a public content, so just use "private" (old behavior)
- SetCacheControlInHeader(w.Header(), CacheControlForPrivateStatic())
- return false
-}
-
// checkIfNoneMatchIsValid tests if the header If-None-Match matches the ETag
func checkIfNoneMatchIsValid(req *http.Request, etag string) bool {
ifNoneMatch := req.Header.Get("If-None-Match")
@@ -89,10 +74,18 @@ func checkIfNoneMatchIsValid(req *http.Request, etag string) bool {
return false
}
-// HandleGenericETagTimeCache handles ETag-based caching with Last-Modified caching for a HTTP request.
+func HandleGenericETagPublicCache(req *http.Request, w http.ResponseWriter, etag string, lastModified *time.Time) bool {
+ return handleGenericETagTimeCache(req, w, etag, lastModified, CacheControlForPublicStatic())
+}
+
+func HandleGenericETagPrivateCache(req *http.Request, w http.ResponseWriter, etag string, lastModified *time.Time) bool {
+ return handleGenericETagTimeCache(req, w, etag, lastModified, CacheControlForPrivateStatic())
+}
+
+// handleGenericETagTimeCache handles ETag-based caching with Last-Modified caching for the HTTP request.
// It returns true if the request was handled.
-func HandleGenericETagTimeCache(req *http.Request, w http.ResponseWriter, etag string, lastModified *time.Time) (handled bool) {
- if len(etag) > 0 {
+func handleGenericETagTimeCache(req *http.Request, w http.ResponseWriter, etag string, lastModified *time.Time, cacheControlOpts *CacheControlOptions) (handled bool) {
+ if etag != "" {
w.Header().Set("Etag", etag)
}
if lastModified != nil && !lastModified.IsZero() {
@@ -100,7 +93,7 @@ func HandleGenericETagTimeCache(req *http.Request, w http.ResponseWriter, etag s
w.Header().Set("Last-Modified", lastModified.UTC().Format(http.TimeFormat))
}
- if len(etag) > 0 {
+ if etag != "" {
if checkIfNoneMatchIsValid(req, etag) {
w.WriteHeader(http.StatusNotModified)
return true
@@ -117,7 +110,6 @@ func HandleGenericETagTimeCache(req *http.Request, w http.ResponseWriter, etag s
}
}
- // not sure whether it is a public content, so just use "private" (old behavior)
- SetCacheControlInHeader(w.Header(), CacheControlForPrivateStatic())
+ SetCacheControlInHeader(w.Header(), cacheControlOpts)
return false
}
diff --git a/modules/httpcache/httpcache_test.go b/modules/httpcache/httpcache_test.go
index d81f06097c..d510cbe4d7 100644
--- a/modules/httpcache/httpcache_test.go
+++ b/modules/httpcache/httpcache_test.go
@@ -6,92 +6,73 @@ package httpcache
import (
"net/http"
"net/http/httptest"
- "strings"
"testing"
+ "time"
+
+ "code.gitea.io/gitea/modules/util"
"github.com/stretchr/testify/assert"
)
-func countFormalHeaders(h http.Header) (c int) {
- for k := range h {
- // ignore our headers for internal usage
- if strings.HasPrefix(k, "X-Gitea-") {
- continue
- }
- c++
- }
- return c
-}
-
func TestHandleGenericETagCache(t *testing.T) {
- etag := `"test"`
-
- t.Run("No_If-None-Match", func(t *testing.T) {
- req := &http.Request{Header: make(http.Header)}
- w := httptest.NewRecorder()
-
- handled := HandleGenericETagCache(req, w, etag)
-
- assert.False(t, handled)
- assert.Equal(t, 2, countFormalHeaders(w.Header()))
- assert.Contains(t, w.Header(), "Cache-Control")
- assert.Contains(t, w.Header(), "Etag")
- assert.Equal(t, etag, w.Header().Get("Etag"))
- })
- t.Run("Wrong_If-None-Match", func(t *testing.T) {
- req := &http.Request{Header: make(http.Header)}
- w := httptest.NewRecorder()
-
- req.Header.Set("If-None-Match", `"wrong etag"`)
-
- handled := HandleGenericETagCache(req, w, etag)
-
- assert.False(t, handled)
- assert.Equal(t, 2, countFormalHeaders(w.Header()))
- assert.Contains(t, w.Header(), "Cache-Control")
- assert.Contains(t, w.Header(), "Etag")
- assert.Equal(t, etag, w.Header().Get("Etag"))
- })
- t.Run("Correct_If-None-Match", func(t *testing.T) {
- req := &http.Request{Header: make(http.Header)}
- w := httptest.NewRecorder()
-
- req.Header.Set("If-None-Match", etag)
-
- handled := HandleGenericETagCache(req, w, etag)
-
- assert.True(t, handled)
- assert.Equal(t, 1, countFormalHeaders(w.Header()))
- assert.Contains(t, w.Header(), "Etag")
- assert.Equal(t, etag, w.Header().Get("Etag"))
- assert.Equal(t, http.StatusNotModified, w.Code)
- })
- t.Run("Multiple_Wrong_If-None-Match", func(t *testing.T) {
- req := &http.Request{Header: make(http.Header)}
- w := httptest.NewRecorder()
-
- req.Header.Set("If-None-Match", `"wrong etag", "wrong etag "`)
-
- handled := HandleGenericETagCache(req, w, etag)
-
- assert.False(t, handled)
- assert.Equal(t, 2, countFormalHeaders(w.Header()))
- assert.Contains(t, w.Header(), "Cache-Control")
- assert.Contains(t, w.Header(), "Etag")
- assert.Equal(t, etag, w.Header().Get("Etag"))
- })
- t.Run("Multiple_Correct_If-None-Match", func(t *testing.T) {
- req := &http.Request{Header: make(http.Header)}
- w := httptest.NewRecorder()
-
- req.Header.Set("If-None-Match", `"wrong etag", `+etag)
-
- handled := HandleGenericETagCache(req, w, etag)
+ matchedEtag := `"matched-etag"`
+ lastModifiedTime := new(time.Date(2021, time.January, 2, 15, 4, 5, 0, time.FixedZone("test-zone", 8*3600)))
+ lastModified := lastModifiedTime.UTC().Format(http.TimeFormat)
+ cacheControl := "max-age=0, private, must-revalidate, no-transform"
+ type testCase struct {
+ name string
+ reqHeaders map[string]string
+ wantHandled bool
+ wantHeaders map[string]string
+ wantStatus int
+ }
+ cases := []testCase{
+ {
+ name: "No If-None-Match",
+ wantHandled: false,
+ wantHeaders: map[string]string{"Last-Modified": lastModified, "Cache-Control": cacheControl, "Etag": matchedEtag},
+ },
+ {
+ name: "Mismatched If-None-Match",
+ reqHeaders: map[string]string{"If-None-Match": `"mismatched-etag"`},
+ wantHandled: false,
+ wantHeaders: map[string]string{"Last-Modified": lastModified, "Cache-Control": cacheControl, "Etag": matchedEtag},
+ },
+ {
+ name: "Matched If-None-Match",
+ reqHeaders: map[string]string{"If-None-Match": matchedEtag},
+ wantHandled: true,
+ wantHeaders: map[string]string{"Last-Modified": lastModified, "Cache-Control": "", "Etag": matchedEtag},
+ wantStatus: http.StatusNotModified,
+ },
+ {
+ name: "Multiple Mismatched If-None-Match",
+ reqHeaders: map[string]string{"If-None-Match": `"mismatched-etag1", "mismatched-etag2"`},
+ wantHandled: false,
+ wantHeaders: map[string]string{"Last-Modified": lastModified, "Cache-Control": cacheControl, "Etag": matchedEtag},
+ },
+ {
+ name: "Multiple Matched If-None-Match",
+ reqHeaders: map[string]string{"If-None-Match": `"mismatched-etag", ` + matchedEtag},
+ wantHandled: true,
+ wantHeaders: map[string]string{"Last-Modified": lastModified, "Cache-Control": "", "Etag": matchedEtag},
+ wantStatus: http.StatusNotModified,
+ },
+ }
- assert.True(t, handled)
- assert.Equal(t, 1, countFormalHeaders(w.Header()))
- assert.Contains(t, w.Header(), "Etag")
- assert.Equal(t, etag, w.Header().Get("Etag"))
- assert.Equal(t, http.StatusNotModified, w.Code)
- })
+ for _, tc := range cases {
+ t.Run(tc.name, func(t *testing.T) {
+ req := httptest.NewRequest(http.MethodGet, "http://example.com/test", nil)
+ for k, v := range tc.reqHeaders {
+ req.Header.Set(k, v)
+ }
+ w := httptest.NewRecorder()
+ assert.Equal(t, tc.wantHandled, HandleGenericETagPrivateCache(req, w, matchedEtag, lastModifiedTime))
+ resp := w.Result()
+ for k, v := range tc.wantHeaders {
+ assert.Equal(t, v, resp.Header.Get(k))
+ }
+ assert.Equal(t, tc.wantStatus, util.Iif(resp.StatusCode == http.StatusOK, 0, resp.StatusCode))
+ })
+ }
}
diff --git a/modules/httplib/content_disposition.go b/modules/httplib/content_disposition.go
new file mode 100644
index 0000000000..da23dae221
--- /dev/null
+++ b/modules/httplib/content_disposition.go
@@ -0,0 +1,65 @@
+// Copyright 2026 The Gitea Authors. All rights reserved.
+// SPDX-License-Identifier: MIT
+
+package httplib
+
+import (
+ "mime"
+ "strings"
+
+ "code.gitea.io/gitea/modules/setting"
+)
+
+type ContentDispositionType string
+
+const (
+ ContentDispositionInline ContentDispositionType = "inline"
+ ContentDispositionAttachment ContentDispositionType = "attachment"
+)
+
+func needsEncodingRune(b rune) bool {
+ return (b < ' ' || b > '~') && b != '\t'
+}
+
+// getSafeName replaces all invalid chars in the filename field by underscore
+func getSafeName(s string) (_ string, needsEncoding bool) {
+ var out strings.Builder
+ for _, b := range s {
+ if needsEncodingRune(b) {
+ needsEncoding = true
+ out.WriteRune('_')
+ } else {
+ out.WriteRune(b)
+ }
+ }
+ return out.String(), needsEncoding
+}
+
+func EncodeContentDispositionAttachment(filename string) string {
+ return encodeContentDisposition(ContentDispositionAttachment, filename)
+}
+
+func EncodeContentDispositionInline(filename string) string {
+ return encodeContentDisposition(ContentDispositionInline, filename)
+}
+
+// encodeContentDisposition encodes a correct Content-Disposition Header
+func encodeContentDisposition(t ContentDispositionType, filename string) string {
+ safeFilename, needsEncoding := getSafeName(filename)
+ result := mime.FormatMediaType(string(t), map[string]string{"filename": safeFilename})
+ // No need for the utf8 encoding
+ if !needsEncoding {
+ return result
+ }
+ utf8Result := mime.FormatMediaType(string(t), map[string]string{"filename": filename})
+
+ // The mime package might have unexpected results in other go versions
+ // Make tests instance fail, otherwise use the default behavior of the go mime package
+ if !strings.HasPrefix(result, string(t)+"; filename=") || !strings.HasPrefix(utf8Result, string(t)+"; filename*=") {
+ setting.PanicInDevOrTesting("Unexpected mime package result %s", result)
+ return utf8Result
+ }
+
+ encodedFileName := strings.TrimPrefix(utf8Result, string(t))
+ return result + encodedFileName
+}
diff --git a/modules/httplib/content_disposition_test.go b/modules/httplib/content_disposition_test.go
new file mode 100644
index 0000000000..bf5040e107
--- /dev/null
+++ b/modules/httplib/content_disposition_test.go
@@ -0,0 +1,64 @@
+// Copyright 2026 The Gitea Authors. All rights reserved.
+// SPDX-License-Identifier: MIT
+
+package httplib
+
+import (
+ "mime"
+ "strings"
+ "testing"
+
+ "github.com/stretchr/testify/assert"
+ "github.com/stretchr/testify/require"
+)
+
+func TestContentDisposition(t *testing.T) {
+ type testEntry struct {
+ disposition ContentDispositionType
+ filename string
+ header string
+ }
+ table := []testEntry{
+ {disposition: ContentDispositionInline, filename: "test.txt", header: "inline; filename=test.txt"},
+ {disposition: ContentDispositionInline, filename: "test❌.txt", header: "inline; filename=test_.txt; filename*=utf-8''test%E2%9D%8C.txt"},
+ {disposition: ContentDispositionInline, filename: "test ❌.txt", header: "inline; filename=\"test _.txt\"; filename*=utf-8''test%20%E2%9D%8C.txt"},
+ {disposition: ContentDispositionInline, filename: "\"test.txt", header: "inline; filename=\"\\\"test.txt\""},
+ {disposition: ContentDispositionInline, filename: "hello\tworld.txt", header: "inline; filename=\"hello\tworld.txt\""},
+ {disposition: ContentDispositionAttachment, filename: "hello\tworld.txt", header: "attachment; filename=\"hello\tworld.txt\""},
+ {disposition: ContentDispositionAttachment, filename: "hello\nworld.txt", header: "attachment; filename=hello_world.txt; filename*=utf-8''hello%0Aworld.txt"},
+ {disposition: ContentDispositionAttachment, filename: "hello\rworld.txt", header: "attachment; filename=hello_world.txt; filename*=utf-8''hello%0Dworld.txt"},
+ }
+
+ // Check the needsEncodingRune replacer ranges except tab that is checked above
+ // Any change in behavior should fail here
+ for c := ' '; !needsEncodingRune(c); c++ {
+ var header string
+ switch {
+ case strings.ContainsAny(string(c), ` (),/:;<=>?@[]`):
+ header = "inline; filename=\"hello" + string(c) + "world.txt\""
+ case strings.ContainsAny(string(c), `"\`):
+ // This document advises against for backslash in quoted form:
+ // https://datatracker.ietf.org/doc/html/rfc6266#appendix-D
+ // However the mime package is not generating the filename* in this scenario
+ header = "inline; filename=\"hello\\" + string(c) + "world.txt\""
+ default:
+ header = "inline; filename=hello" + string(c) + "world.txt"
+ }
+ table = append(table, testEntry{
+ disposition: ContentDispositionInline,
+ filename: "hello" + string(c) + "world.txt",
+ header: header,
+ })
+ }
+
+ for _, entry := range table {
+ t.Run(string(entry.disposition)+"_"+entry.filename, func(t *testing.T) {
+ encoded := encodeContentDisposition(entry.disposition, entry.filename)
+ assert.Equal(t, entry.header, encoded)
+ disposition, params, err := mime.ParseMediaType(encoded)
+ require.NoError(t, err)
+ assert.Equal(t, string(entry.disposition), disposition)
+ assert.Equal(t, entry.filename, params["filename"])
+ })
+ }
+}
diff --git a/modules/httplib/serve_test.go b/modules/httplib/serve_test.go
index 78b88c9b5f..419085237c 100644
--- a/modules/httplib/serve_test.go
+++ b/modules/httplib/serve_test.go
@@ -12,11 +12,13 @@ import (
"strings"
"testing"
+ "code.gitea.io/gitea/modules/typesniffer"
+
"github.com/stretchr/testify/assert"
"github.com/stretchr/testify/require"
)
-func TestServeContentByReader(t *testing.T) {
+func TestServeUserContentByReader(t *testing.T) {
data := "0123456789abcdef"
test := func(t *testing.T, expectedStatusCode int, expectedContent string) {
@@ -27,7 +29,7 @@ func TestServeContentByReader(t *testing.T) {
}
reader := strings.NewReader(data)
w := httptest.NewRecorder()
- ServeContentByReader(r, w, int64(len(data)), reader, &ServeHeaderOptions{})
+ ServeUserContentByReader(r, w, int64(len(data)), reader, ServeHeaderOptions{})
assert.Equal(t, expectedStatusCode, w.Code)
if expectedStatusCode == http.StatusPartialContent || expectedStatusCode == http.StatusOK {
assert.Equal(t, strconv.Itoa(len(expectedContent)), w.Header().Get("Content-Length"))
@@ -58,7 +60,7 @@ func TestServeContentByReader(t *testing.T) {
})
}
-func TestServeContentByReadSeeker(t *testing.T) {
+func TestServeUserContentByFile(t *testing.T) {
data := "0123456789abcdef"
tmpFile := t.TempDir() + "/test"
err := os.WriteFile(tmpFile, []byte(data), 0o644)
@@ -76,7 +78,7 @@ func TestServeContentByReadSeeker(t *testing.T) {
defer seekReader.Close()
w := httptest.NewRecorder()
- ServeContentByReadSeeker(r, w, nil, seekReader, &ServeHeaderOptions{})
+ ServeUserContentByFile(r, w, seekReader, ServeHeaderOptions{})
assert.Equal(t, expectedStatusCode, w.Code)
if expectedStatusCode == http.StatusPartialContent || expectedStatusCode == http.StatusOK {
assert.Equal(t, strconv.Itoa(len(expectedContent)), w.Header().Get("Content-Length"))
@@ -106,3 +108,36 @@ func TestServeContentByReadSeeker(t *testing.T) {
test(t, http.StatusPartialContent, data[1:])
})
}
+
+func TestServeSetHeaderContentRelated(t *testing.T) {
+ cases := []struct {
+ contentType string
+ csp string
+ }{
+ {"", serveHeaderCspDefault},
+ {"any", serveHeaderCspDefault},
+ {"application/pdf", serveHeaderCspPdf},
+ {"application/pdf; other", serveHeaderCspPdf},
+ {"audio/mp4", serveHeaderCspAudioVideo},
+ {"video/ogg; other", serveHeaderCspAudioVideo},
+ {typesniffer.MimeTypeImageSvg, serveHeaderCspDefault},
+ }
+ for _, c := range cases {
+ w := httptest.NewRecorder()
+ serveSetHeaderContentRelated(w, c.contentType)
+ csp := w.Header().Get("Content-Security-Policy")
+ assert.Equal(t, c.csp, csp, "content-type: %s", c.contentType)
+ assert.Equal(t, "nosniff", w.Header().Get("X-Content-Type-Options")) // it should always be there
+ }
+
+ // make sure sandboxed
+ require.Contains(t, serveHeaderCspDefault, "; sandbox")
+}
+
+func TestServeSetHeaders(t *testing.T) {
+ w := httptest.NewRecorder()
+ ServeSetHeaders(w, ServeHeaderOptions{Filename: "foo.zip"})
+ assert.Equal(t, "attachment; filename=foo.zip", w.Header().Get("Content-Disposition"))
+ ServeSetHeaders(w, ServeHeaderOptions{Filename: "foo.zip", ContentDisposition: ContentDispositionInline})
+ assert.Equal(t, "inline; filename=foo.zip", w.Header().Get("Content-Disposition"))
+}
diff --git a/modules/httplib/url.go b/modules/httplib/url.go
index 2a1376b8d4..a689c9e98e 100644
--- a/modules/httplib/url.go
+++ b/modules/httplib/url.go
@@ -24,7 +24,18 @@ func urlIsRelative(s string, u *url.URL) bool {
if len(s) > 1 && (s[0] == '/' || s[0] == '\\') && (s[1] == '/' || s[1] == '\\') {
return false
}
- return u != nil && u.Scheme == "" && u.Host == ""
+ if u == nil {
+ return false // invalid URL
+ }
+ if u.Scheme != "" || u.Host != "" {
+ return false // absolute URL with scheme or host
+ }
+ // Now, the URL is likely a relative URL
+ // HINT: GOLANG-HTTP-REDIRECT-BUG: Golang security vulnerability: "http.Redirect" calls "path.Clean" and changes the meaning of a path
+ // For example, `/a/../\b` will be changed to `/\b`, then it hits the first checked pattern and becomes an open redirect to "{current-scheme}://b"
+ // For a valid relative URL, its "path" shouldn't contain `\` because such char must be escaped.
+ // So if the "path" contains `\`, it is not a valid relative URL, then we can prevent open redirect.
+ return !strings.Contains(u.Path, "\\")
}
// IsRelativeURL detects if a URL is relative (no scheme or host)
@@ -35,14 +46,14 @@ func IsRelativeURL(s string) bool {
func getRequestScheme(req *http.Request) string {
// https://developer.mozilla.org/en-US/docs/Web/HTTP/Headers/X-Forwarded-Proto
- if s := req.Header.Get("X-Forwarded-Proto"); s != "" {
- return s
+ if proto, ok := parseForwardedProtoValue(req.Header.Get("X-Forwarded-Proto")); ok {
+ return proto
}
- if s := req.Header.Get("X-Forwarded-Protocol"); s != "" {
- return s
+ if proto, ok := parseForwardedProtoValue(req.Header.Get("X-Forwarded-Protocol")); ok {
+ return proto
}
- if s := req.Header.Get("X-Url-Scheme"); s != "" {
- return s
+ if proto, ok := parseForwardedProtoValue(req.Header.Get("X-Url-Scheme")); ok {
+ return proto
}
if s := req.Header.Get("Front-End-Https"); s != "" {
return util.Iif(s == "on", "https", "http")
@@ -53,6 +64,13 @@ func getRequestScheme(req *http.Request) string {
return ""
}
+func parseForwardedProtoValue(val string) (string, bool) {
+ if val == "http" || val == "https" {
+ return val, true
+ }
+ return "", false
+}
+
// GuessCurrentAppURL tries to guess the current full public URL (with sub-path) by http headers. It always has a '/' suffix, exactly the same as setting.AppURL
// TODO: should rename it to GuessCurrentPublicURL in the future
func GuessCurrentAppURL(ctx context.Context) string {
@@ -61,6 +79,10 @@ func GuessCurrentAppURL(ctx context.Context) string {
// GuessCurrentHostURL tries to guess the current full host URL (no sub-path) by http headers, there is no trailing slash.
func GuessCurrentHostURL(ctx context.Context) string {
+ // "never" means always trust ROOT_URL and skip any request header detection.
+ if setting.PublicURLDetection == setting.PublicURLNever {
+ return strings.TrimSuffix(setting.AppURL, setting.AppSubURL+"/")
+ }
// Try the best guess to get the current host URL (will be used for public URL) by http headers.
// At the moment, if site admin doesn't configure the proxy headers correctly, then Gitea would guess wrong.
// There are some cases:
diff --git a/modules/httplib/url_test.go b/modules/httplib/url_test.go
index 0ffb0cac05..373693693b 100644
--- a/modules/httplib/url_test.go
+++ b/modules/httplib/url_test.go
@@ -23,6 +23,7 @@ func TestIsRelativeURL(t *testing.T) {
"foo",
"/",
"/foo?k=%20#abc",
+ "/foo?k=\\",
}
for _, s := range rel {
assert.True(t, IsRelativeURL(s), "rel = %q", s)
@@ -32,6 +33,8 @@ func TestIsRelativeURL(t *testing.T) {
"\\\\",
"/\\",
"\\/",
+ "/a/../\\b",
+ "/any\\thing",
"mailto:a@b.com",
"https://test.com",
}
@@ -44,6 +47,7 @@ func TestGuessCurrentHostURL(t *testing.T) {
defer test.MockVariableValue(&setting.AppURL, "http://cfg-host/sub/")()
defer test.MockVariableValue(&setting.AppSubURL, "/sub")()
headersWithProto := http.Header{"X-Forwarded-Proto": {"https"}}
+ maliciousProtoHeaders := http.Header{"X-Forwarded-Proto": {"http://attacker.host/?trash="}}
t.Run("Legacy", func(t *testing.T) {
defer test.MockVariableValue(&setting.PublicURLDetection, setting.PublicURLLegacy)()
@@ -57,6 +61,9 @@ func TestGuessCurrentHostURL(t *testing.T) {
// if "X-Forwarded-Proto" exists, then use it and "Host" header
ctx = context.WithValue(t.Context(), RequestContextKey, &http.Request{Host: "req-host:3000", Header: headersWithProto})
assert.Equal(t, "https://req-host:3000", GuessCurrentHostURL(ctx))
+
+ ctx = context.WithValue(t.Context(), RequestContextKey, &http.Request{Host: "req-host:3000", Header: maliciousProtoHeaders})
+ assert.Equal(t, "http://cfg-host", GuessCurrentHostURL(ctx))
})
t.Run("Auto", func(t *testing.T) {
@@ -73,6 +80,24 @@ func TestGuessCurrentHostURL(t *testing.T) {
ctx = context.WithValue(t.Context(), RequestContextKey, &http.Request{Host: "req-host:3000", Header: headersWithProto})
assert.Equal(t, "https://req-host:3000", GuessCurrentHostURL(ctx))
+
+ ctx = context.WithValue(t.Context(), RequestContextKey, &http.Request{Host: "req-host:3000", Header: maliciousProtoHeaders})
+ assert.Equal(t, "http://req-host:3000", GuessCurrentHostURL(ctx))
+ })
+
+ t.Run("Never", func(t *testing.T) {
+ defer test.MockVariableValue(&setting.PublicURLDetection, setting.PublicURLNever)()
+
+ assert.Equal(t, "http://cfg-host", GuessCurrentHostURL(t.Context()))
+
+ ctx := context.WithValue(t.Context(), RequestContextKey, &http.Request{Host: "req-host:3000"})
+ assert.Equal(t, "http://cfg-host", GuessCurrentHostURL(ctx))
+
+ ctx = context.WithValue(t.Context(), RequestContextKey, &http.Request{Host: "req-host:3000", TLS: &tls.ConnectionState{}})
+ assert.Equal(t, "http://cfg-host", GuessCurrentHostURL(ctx))
+
+ ctx = context.WithValue(t.Context(), RequestContextKey, &http.Request{Host: "req-host:3000", Header: headersWithProto})
+ assert.Equal(t, "http://cfg-host", GuessCurrentHostURL(ctx))
})
}
diff --git a/modules/indexer/code/bleve/bleve.go b/modules/indexer/code/bleve/bleve.go
index c233f491e3..010ee39660 100644
--- a/modules/indexer/code/bleve/bleve.go
+++ b/modules/indexer/code/bleve/bleve.go
@@ -4,7 +4,6 @@
package bleve
import (
- "bufio"
"context"
"fmt"
"io"
@@ -17,6 +16,7 @@ import (
"code.gitea.io/gitea/modules/charset"
"code.gitea.io/gitea/modules/git"
"code.gitea.io/gitea/modules/git/gitcmd"
+ "code.gitea.io/gitea/modules/gitrepo"
"code.gitea.io/gitea/modules/indexer"
path_filter "code.gitea.io/gitea/modules/indexer/code/bleve/token/path"
"code.gitea.io/gitea/modules/indexer/code/internal"
@@ -150,7 +150,7 @@ func NewIndexer(indexDir string) *Indexer {
}
}
-func (b *Indexer) addUpdate(ctx context.Context, batchWriter git.WriteCloserError, batchReader *bufio.Reader, commitSha string,
+func (b *Indexer) addUpdate(ctx context.Context, catFileBatch git.CatFileBatch, commitSha string,
update internal.FileUpdate, repo *repo_model.Repository, batch *inner_bleve.FlushingBatch,
) error {
// Ignore vendored files in code search
@@ -163,7 +163,7 @@ func (b *Indexer) addUpdate(ctx context.Context, batchWriter git.WriteCloserErro
var err error
if !update.Sized {
var stdout string
- stdout, _, err = gitcmd.NewCommand("cat-file", "-s").AddDynamicArguments(update.BlobSha).RunStdString(ctx, &gitcmd.RunOpts{Dir: repo.RepoPath()})
+ stdout, _, err = gitrepo.RunCmdString(ctx, repo, gitcmd.NewCommand("cat-file", "-s").AddDynamicArguments(update.BlobSha))
if err != nil {
return err
}
@@ -176,16 +176,11 @@ func (b *Indexer) addUpdate(ctx context.Context, batchWriter git.WriteCloserErro
return b.addDelete(update.Filename, repo, batch)
}
- if _, err := batchWriter.Write([]byte(update.BlobSha + "\n")); err != nil {
- return err
- }
-
- _, _, size, err = git.ReadBatchLine(batchReader)
+ info, batchReader, err := catFileBatch.QueryContent(update.BlobSha)
if err != nil {
return err
}
-
- fileContents, err := io.ReadAll(io.LimitReader(batchReader, size))
+ fileContents, err := io.ReadAll(io.LimitReader(batchReader, info.Size))
if err != nil {
return err
} else if !typesniffer.DetectContentType(fileContents).IsText() {
@@ -202,7 +197,7 @@ func (b *Indexer) addUpdate(ctx context.Context, batchWriter git.WriteCloserErro
RepoID: repo.ID,
CommitID: commitSha,
Filename: update.Filename,
- Content: string(charset.ToUTF8DropErrors(fileContents, charset.ConvertOpts{})),
+ Content: string(charset.ToUTF8DropErrors(fileContents)),
Language: analyze.GetCodeLanguage(update.Filename, fileContents),
UpdatedAt: time.Now().UTC(),
})
@@ -217,18 +212,17 @@ func (b *Indexer) addDelete(filename string, repo *repo_model.Repository, batch
func (b *Indexer) Index(ctx context.Context, repo *repo_model.Repository, sha string, changes *internal.RepoChanges) error {
batch := inner_bleve.NewFlushingBatch(b.inner.Indexer, maxBatchSize)
if len(changes.Updates) > 0 {
- gitBatch, err := git.NewBatch(ctx, repo.RepoPath())
+ catfileBatch, err := gitrepo.NewBatch(ctx, repo)
if err != nil {
return err
}
- defer gitBatch.Close()
+ defer catfileBatch.Close()
for _, update := range changes.Updates {
- if err := b.addUpdate(ctx, gitBatch.Writer, gitBatch.Reader, sha, update, repo, batch); err != nil {
+ if err := b.addUpdate(ctx, catfileBatch, sha, update, repo, batch); err != nil {
return err
}
}
- gitBatch.Close()
}
for _, filename := range changes.RemovedFilenames {
if err := b.addDelete(filename, repo, batch); err != nil {
diff --git a/modules/indexer/code/bleve/token/path/path.go b/modules/indexer/code/bleve/token/path/path.go
index 6dfc12f146..e00bb695e2 100644
--- a/modules/indexer/code/bleve/token/path/path.go
+++ b/modules/indexer/code/bleve/token/path/path.go
@@ -27,7 +27,7 @@ func TokenFilterConstructor(config map[string]any, cache *registry.Cache) (analy
func (s *TokenFilter) Filter(input analysis.TokenStream) analysis.TokenStream {
if len(input) == 1 {
- // if there is only one token, we dont need to generate the reversed chain
+ // if there is only one token, we don't need to generate the reversed chain
return generatePathTokens(input, false)
}
diff --git a/modules/indexer/code/elasticsearch/elasticsearch.go b/modules/indexer/code/elasticsearch/elasticsearch.go
index b08d837a2a..9d170528ad 100644
--- a/modules/indexer/code/elasticsearch/elasticsearch.go
+++ b/modules/indexer/code/elasticsearch/elasticsearch.go
@@ -4,7 +4,6 @@
package elasticsearch
import (
- "bufio"
"context"
"fmt"
"io"
@@ -16,6 +15,7 @@ import (
"code.gitea.io/gitea/modules/charset"
"code.gitea.io/gitea/modules/git"
"code.gitea.io/gitea/modules/git/gitcmd"
+ "code.gitea.io/gitea/modules/gitrepo"
"code.gitea.io/gitea/modules/indexer"
"code.gitea.io/gitea/modules/indexer/code/internal"
indexer_internal "code.gitea.io/gitea/modules/indexer/internal"
@@ -138,7 +138,7 @@ const (
}`
)
-func (b *Indexer) addUpdate(ctx context.Context, batchWriter git.WriteCloserError, batchReader *bufio.Reader, sha string, update internal.FileUpdate, repo *repo_model.Repository) ([]elastic.BulkableRequest, error) {
+func (b *Indexer) addUpdate(ctx context.Context, catFileBatch git.CatFileBatch, sha string, update internal.FileUpdate, repo *repo_model.Repository) ([]elastic.BulkableRequest, error) {
// Ignore vendored files in code search
if setting.Indexer.ExcludeVendored && analyze.IsVendor(update.Filename) {
return nil, nil
@@ -148,7 +148,7 @@ func (b *Indexer) addUpdate(ctx context.Context, batchWriter git.WriteCloserErro
var err error
if !update.Sized {
var stdout string
- stdout, _, err = gitcmd.NewCommand("cat-file", "-s").AddDynamicArguments(update.BlobSha).RunStdString(ctx, &gitcmd.RunOpts{Dir: repo.RepoPath()})
+ stdout, _, err = gitrepo.RunCmdString(ctx, repo, gitcmd.NewCommand("cat-file", "-s").AddDynamicArguments(update.BlobSha))
if err != nil {
return nil, err
}
@@ -161,16 +161,12 @@ func (b *Indexer) addUpdate(ctx context.Context, batchWriter git.WriteCloserErro
return []elastic.BulkableRequest{b.addDelete(update.Filename, repo)}, nil
}
- if _, err := batchWriter.Write([]byte(update.BlobSha + "\n")); err != nil {
- return nil, err
- }
-
- _, _, size, err = git.ReadBatchLine(batchReader)
+ info, batchReader, err := catFileBatch.QueryContent(update.BlobSha)
if err != nil {
return nil, err
}
- fileContents, err := io.ReadAll(io.LimitReader(batchReader, size))
+ fileContents, err := io.ReadAll(io.LimitReader(batchReader, info.Size))
if err != nil {
return nil, err
} else if !typesniffer.DetectContentType(fileContents).IsText() {
@@ -190,7 +186,7 @@ func (b *Indexer) addUpdate(ctx context.Context, batchWriter git.WriteCloserErro
Doc(map[string]any{
"repo_id": repo.ID,
"filename": update.Filename,
- "content": string(charset.ToUTF8DropErrors(fileContents, charset.ConvertOpts{})),
+ "content": string(charset.ToUTF8DropErrors(fileContents)),
"commit_id": sha,
"language": analyze.GetCodeLanguage(update.Filename, fileContents),
"updated_at": timeutil.TimeStampNow(),
@@ -209,14 +205,14 @@ func (b *Indexer) addDelete(filename string, repo *repo_model.Repository) elasti
func (b *Indexer) Index(ctx context.Context, repo *repo_model.Repository, sha string, changes *internal.RepoChanges) error {
reqs := make([]elastic.BulkableRequest, 0)
if len(changes.Updates) > 0 {
- batch, err := git.NewBatch(ctx, repo.RepoPath())
+ batch, err := gitrepo.NewBatch(ctx, repo)
if err != nil {
return err
}
defer batch.Close()
for _, update := range changes.Updates {
- updateReqs, err := b.addUpdate(ctx, batch.Writer, batch.Reader, sha, update, repo)
+ updateReqs, err := b.addUpdate(ctx, batch, sha, update, repo)
if err != nil {
return err
}
@@ -224,7 +220,6 @@ func (b *Indexer) Index(ctx context.Context, repo *repo_model.Repository, sha st
reqs = append(reqs, updateReqs...)
}
}
- batch.Close()
}
for _, filename := range changes.RemovedFilenames {
@@ -398,7 +393,7 @@ func (b *Indexer) Search(ctx context.Context, opts *internal.SearchOptions) (int
elastic.NewHighlight().
Field("content").
Field("filename").
- NumOfFragments(0). // return all highting content on fragments
+ NumOfFragments(0). // return all highlighting content on fragments
HighlighterType("fvh"),
).
Sort("_score", false).
@@ -431,7 +426,7 @@ func (b *Indexer) Search(ctx context.Context, opts *internal.SearchOptions) (int
elastic.NewHighlight().
Field("content").
Field("filename").
- NumOfFragments(0). // return all highting content on fragments
+ NumOfFragments(0). // return all highlighting content on fragments
HighlighterType("fvh"),
).
Sort("_score", false).
diff --git a/modules/indexer/code/git.go b/modules/indexer/code/git.go
index f1513d66b0..a17b10551d 100644
--- a/modules/indexer/code/git.go
+++ b/modules/indexer/code/git.go
@@ -11,13 +11,14 @@ import (
repo_model "code.gitea.io/gitea/models/repo"
"code.gitea.io/gitea/modules/git"
"code.gitea.io/gitea/modules/git/gitcmd"
+ "code.gitea.io/gitea/modules/gitrepo"
"code.gitea.io/gitea/modules/indexer/code/internal"
"code.gitea.io/gitea/modules/log"
"code.gitea.io/gitea/modules/setting"
)
func getDefaultBranchSha(ctx context.Context, repo *repo_model.Repository) (string, error) {
- stdout, _, err := gitcmd.NewCommand("show-ref", "-s").AddDynamicArguments(git.BranchPrefix+repo.DefaultBranch).RunStdString(ctx, &gitcmd.RunOpts{Dir: repo.RepoPath()})
+ stdout, _, err := gitrepo.RunCmdString(ctx, repo, gitcmd.NewCommand("show-ref", "-s").AddDynamicArguments(git.BranchPrefix+repo.DefaultBranch))
if err != nil {
return "", err
}
@@ -34,7 +35,7 @@ func getRepoChanges(ctx context.Context, repo *repo_model.Repository, revision s
needGenesis := len(status.CommitSha) == 0
if !needGenesis {
hasAncestorCmd := gitcmd.NewCommand("merge-base").AddDynamicArguments(status.CommitSha, revision)
- stdout, _, _ := hasAncestorCmd.RunStdString(ctx, &gitcmd.RunOpts{Dir: repo.RepoPath()})
+ stdout, _, _ := gitrepo.RunCmdString(ctx, repo, hasAncestorCmd) // FIXME: error is not handled
needGenesis = len(stdout) == 0
}
@@ -87,7 +88,7 @@ func parseGitLsTreeOutput(stdout []byte) ([]internal.FileUpdate, error) {
// genesisChanges get changes to add repo to the indexer for the first time
func genesisChanges(ctx context.Context, repo *repo_model.Repository, revision string) (*internal.RepoChanges, error) {
var changes internal.RepoChanges
- stdout, _, runErr := gitcmd.NewCommand("ls-tree", "--full-tree", "-l", "-r").AddDynamicArguments(revision).RunStdBytes(ctx, &gitcmd.RunOpts{Dir: repo.RepoPath()})
+ stdout, _, runErr := gitrepo.RunCmdBytes(ctx, repo, gitcmd.NewCommand("ls-tree", "--full-tree", "-l", "-r").AddDynamicArguments(revision))
if runErr != nil {
return nil, runErr
}
@@ -100,7 +101,7 @@ func genesisChanges(ctx context.Context, repo *repo_model.Repository, revision s
// nonGenesisChanges get changes since the previous indexer update
func nonGenesisChanges(ctx context.Context, repo *repo_model.Repository, revision string) (*internal.RepoChanges, error) {
diffCmd := gitcmd.NewCommand("diff", "--name-status").AddDynamicArguments(repo.CodeIndexerStatus.CommitSha, revision)
- stdout, _, runErr := diffCmd.RunStdString(ctx, &gitcmd.RunOpts{Dir: repo.RepoPath()})
+ stdout, _, runErr := gitrepo.RunCmdString(ctx, repo, diffCmd)
if runErr != nil {
// previous commit sha may have been removed by a force push, so
// try rebuilding from scratch
@@ -118,7 +119,7 @@ func nonGenesisChanges(ctx context.Context, repo *repo_model.Repository, revisio
updateChanges := func() error {
cmd := gitcmd.NewCommand("ls-tree", "--full-tree", "-l").AddDynamicArguments(revision).
AddDashesAndList(updatedFilenames...)
- lsTreeStdout, _, err := cmd.RunStdBytes(ctx, &gitcmd.RunOpts{Dir: repo.RepoPath()})
+ lsTreeStdout, _, err := gitrepo.RunCmdBytes(ctx, repo, cmd)
if err != nil {
return err
}
diff --git a/modules/indexer/code/gitgrep/gitgrep.go b/modules/indexer/code/gitgrep/gitgrep.go
index 6f6e0b47b9..5fbd7201ef 100644
--- a/modules/indexer/code/gitgrep/gitgrep.go
+++ b/modules/indexer/code/gitgrep/gitgrep.go
@@ -24,7 +24,7 @@ func indexSettingToGitGrepPathspecList() (list []string) {
return list
}
-func PerformSearch(ctx context.Context, page int, repoID int64, gitRepo *git.Repository, ref git.RefName, keyword string, searchMode indexer.SearchModeType) (searchResults []*code_indexer.Result, total int, err error) {
+func PerformSearch(ctx context.Context, page int, repoID int64, gitRepo *git.Repository, ref git.RefName, keyword string, searchMode indexer.SearchModeType) (searchResults []*code_indexer.Result, total int64, err error) {
grepMode := git.GrepModeWords
switch searchMode {
case indexer.SearchModeExact:
@@ -47,7 +47,7 @@ func PerformSearch(ctx context.Context, page int, repoID int64, gitRepo *git.Rep
return nil, 0, fmt.Errorf("gitRepo.GetRefCommitID: %w", err)
}
- total = len(res)
+ total = int64(len(res))
pageStart := min((page-1)*setting.UI.RepoSearchPagingNum, len(res))
pageEnd := min(page*setting.UI.RepoSearchPagingNum, len(res))
res = res[pageStart:pageEnd]
diff --git a/modules/indexer/code/internal/util.go b/modules/indexer/code/internal/util.go
index fa958be473..5d62a5ccb9 100644
--- a/modules/indexer/code/internal/util.go
+++ b/modules/indexer/code/internal/util.go
@@ -17,20 +17,20 @@ func FilenameIndexerID(repoID int64, filename string) string {
}
func ParseIndexerID(indexerID string) (int64, string) {
- index := strings.IndexByte(indexerID, '_')
- if index == -1 {
+ before, after, ok := strings.Cut(indexerID, "_")
+ if !ok {
log.Error("Unexpected ID in repo indexer: %s", indexerID)
}
- repoID, _ := internal.ParseBase36(indexerID[:index])
- return repoID, indexerID[index+1:]
+ repoID, _ := internal.ParseBase36(before)
+ return repoID, after
}
func FilenameOfIndexerID(indexerID string) string {
- index := strings.IndexByte(indexerID, '_')
- if index == -1 {
+ _, after, ok := strings.Cut(indexerID, "_")
+ if !ok {
log.Error("Unexpected ID in repo indexer: %s", indexerID)
}
- return indexerID[index+1:]
+ return after
}
// FilenameMatchIndexPos returns the boundaries of its first seven lines.
diff --git a/modules/indexer/code/search.go b/modules/indexer/code/search.go
index a7a5d7d2e3..b5eb5116b0 100644
--- a/modules/indexer/code/search.go
+++ b/modules/indexer/code/search.go
@@ -72,10 +72,11 @@ func writeStrings(buf *bytes.Buffer, strs ...string) error {
func HighlightSearchResultCode(filename, language string, lineNums []int, code string) []*ResultLine {
// we should highlight the whole code block first, otherwise it doesn't work well with multiple line highlighting
- hl, _ := highlight.Code(filename, language, code)
- highlightedLines := strings.Split(string(hl), "\n")
+ lexer := highlight.DetectChromaLexerByFileName(filename, language)
+ hl := highlight.RenderCodeByLexer(lexer, code)
+ highlightedLines := highlight.UnsafeSplitHighlightedLines(hl)
- // The lineNums outputted by highlight.Code might not match the original lineNums, because "highlight" removes the last `\n`
+ // The lineNums outputted by render might not match the original lineNums, because "highlight" removes the last `\n`
lines := make([]*ResultLine, min(len(highlightedLines), len(lineNums)))
for i := range lines {
lines[i] = &ResultLine{
@@ -129,7 +130,7 @@ func searchResult(result *internal.SearchResult, startIndex, endIndex int) (*Res
}
// PerformSearch perform a search on a repository
-func PerformSearch(ctx context.Context, opts *SearchOptions) (int, []*Result, []*SearchResultLanguages, error) {
+func PerformSearch(ctx context.Context, opts *SearchOptions) (int64, []*Result, []*SearchResultLanguages, error) {
if opts == nil || len(opts.Keyword) == 0 {
return 0, nil, nil, nil
}
@@ -148,5 +149,5 @@ func PerformSearch(ctx context.Context, opts *SearchOptions) (int, []*Result, []
return 0, nil, nil, err
}
}
- return int(total), displayResults, resultLanguages, nil
+ return total, displayResults, resultLanguages, nil
}
diff --git a/modules/indexer/issues/elasticsearch/elasticsearch_test.go b/modules/indexer/issues/elasticsearch/elasticsearch_test.go
index dc329c07dd..cb9ed3889d 100644
--- a/modules/indexer/issues/elasticsearch/elasticsearch_test.go
+++ b/modules/indexer/issues/elasticsearch/elasticsearch_test.go
@@ -30,7 +30,11 @@ func TestElasticsearchIndexer(t *testing.T) {
require.Eventually(t, func() bool {
resp, err := http.Get(url)
- return err == nil && resp.StatusCode == http.StatusOK
+ if err != nil {
+ return false
+ }
+ defer resp.Body.Close()
+ return resp.StatusCode == http.StatusOK
}, time.Minute, time.Second, "Expected elasticsearch to be up")
indexer := NewIndexer(url, fmt.Sprintf("test_elasticsearch_indexer_%d", time.Now().Unix()))
diff --git a/modules/indexer/issues/meilisearch/meilisearch.go b/modules/indexer/issues/meilisearch/meilisearch.go
index b7fae6ee9a..5715cf4794 100644
--- a/modules/indexer/issues/meilisearch/meilisearch.go
+++ b/modules/indexer/issues/meilisearch/meilisearch.go
@@ -124,7 +124,7 @@ func (b *Indexer) Delete(_ context.Context, ids ...int64) error {
}
for _, id := range ids {
- _, err := b.inner.Client.Index(b.inner.VersionedIndexName()).DeleteDocument(strconv.FormatInt(id, 10))
+ _, err := b.inner.Client.Index(b.inner.VersionedIndexName()).DeleteDocument(strconv.FormatInt(id, 10), nil)
if err != nil {
return err
}
diff --git a/modules/indexer/issues/meilisearch/meilisearch_test.go b/modules/indexer/issues/meilisearch/meilisearch_test.go
index a32cbdd6de..81a27487bb 100644
--- a/modules/indexer/issues/meilisearch/meilisearch_test.go
+++ b/modules/indexer/issues/meilisearch/meilisearch_test.go
@@ -36,7 +36,11 @@ func TestMeilisearchIndexer(t *testing.T) {
require.Eventually(t, func() bool {
resp, err := http.Get(url)
- return err == nil && resp.StatusCode == http.StatusOK
+ if err != nil {
+ return false
+ }
+ defer resp.Body.Close()
+ return resp.StatusCode == http.StatusOK
}, time.Minute, time.Second, "Expected meilisearch to be up")
indexer := NewIndexer(url, key, fmt.Sprintf("test_meilisearch_indexer_%d", time.Now().Unix()))
diff --git a/modules/json/json.go b/modules/json/json.go
index 444dc8526a..d053f91cf7 100644
--- a/modules/json/json.go
+++ b/modules/json/json.go
@@ -8,8 +8,6 @@ import (
"encoding/binary"
"encoding/json" //nolint:depguard // this package wraps it
"io"
-
- jsoniter "github.com/json-iterator/go"
)
// Encoder represents an encoder for json
@@ -31,71 +29,7 @@ type Interface interface {
Indent(dst *bytes.Buffer, src []byte, prefix, indent string) error
}
-var (
- // DefaultJSONHandler default json handler
- DefaultJSONHandler Interface = JSONiter{jsoniter.ConfigCompatibleWithStandardLibrary}
-
- _ Interface = StdJSON{}
- _ Interface = JSONiter{}
-)
-
-// StdJSON implements Interface via encoding/json
-type StdJSON struct{}
-
-// Marshal implements Interface
-func (StdJSON) Marshal(v any) ([]byte, error) {
- return json.Marshal(v)
-}
-
-// Unmarshal implements Interface
-func (StdJSON) Unmarshal(data []byte, v any) error {
- return json.Unmarshal(data, v)
-}
-
-// NewEncoder implements Interface
-func (StdJSON) NewEncoder(writer io.Writer) Encoder {
- return json.NewEncoder(writer)
-}
-
-// NewDecoder implements Interface
-func (StdJSON) NewDecoder(reader io.Reader) Decoder {
- return json.NewDecoder(reader)
-}
-
-// Indent implements Interface
-func (StdJSON) Indent(dst *bytes.Buffer, src []byte, prefix, indent string) error {
- return json.Indent(dst, src, prefix, indent)
-}
-
-// JSONiter implements Interface via jsoniter
-type JSONiter struct {
- jsoniter.API
-}
-
-// Marshal implements Interface
-func (j JSONiter) Marshal(v any) ([]byte, error) {
- return j.API.Marshal(v)
-}
-
-// Unmarshal implements Interface
-func (j JSONiter) Unmarshal(data []byte, v any) error {
- return j.API.Unmarshal(data, v)
-}
-
-// NewEncoder implements Interface
-func (j JSONiter) NewEncoder(writer io.Writer) Encoder {
- return j.API.NewEncoder(writer)
-}
-
-// NewDecoder implements Interface
-func (j JSONiter) NewDecoder(reader io.Reader) Decoder {
- return j.API.NewDecoder(reader)
-}
-
-// Indent implements Interface, since jsoniter don't support Indent, just use encoding/json's
-func (j JSONiter) Indent(dst *bytes.Buffer, src []byte, prefix, indent string) error {
- return json.Indent(dst, src, prefix, indent)
-}
+var DefaultJSONHandler = getDefaultJSONHandler()
// Marshal converts object as bytes
func Marshal(v any) ([]byte, error) {
diff --git a/modules/json/json_test.go b/modules/json/json_test.go
index ace7167913..2fa4da4cf7 100644
--- a/modules/json/json_test.go
+++ b/modules/json/json_test.go
@@ -4,6 +4,7 @@
package json
import (
+ "bytes"
"testing"
"github.com/stretchr/testify/assert"
@@ -16,3 +17,12 @@ func TestGiteaDBJSONUnmarshal(t *testing.T) {
err = UnmarshalHandleDoubleEncode([]byte(""), &m)
assert.NoError(t, err)
}
+
+func TestIndent(t *testing.T) {
+ buf := &bytes.Buffer{}
+ err := Indent(buf, []byte(`{"a":1}`), ">", " ")
+ assert.NoError(t, err)
+ assert.Equal(t, `{
+> "a": 1
+>}`, buf.String())
+}
diff --git a/modules/json/jsonlegacy.go b/modules/json/jsonlegacy.go
new file mode 100644
index 0000000000..81d644d4f4
--- /dev/null
+++ b/modules/json/jsonlegacy.go
@@ -0,0 +1,25 @@
+// Copyright 2025 The Gitea Authors. All rights reserved.
+// SPDX-License-Identifier: MIT
+
+//go:build !goexperiment.jsonv2
+
+package json
+
+import (
+ "encoding/json" //nolint:depguard // this package wraps it
+ "io"
+)
+
+func getDefaultJSONHandler() Interface {
+ return jsonV1{}
+}
+
+func MarshalKeepOptionalEmpty(v any) ([]byte, error) {
+ return DefaultJSONHandler.Marshal(v)
+}
+
+func NewDecoderCaseInsensitive(reader io.Reader) Decoder {
+ return DefaultJSONHandler.NewDecoder(reader)
+}
+
+type Value = json.RawMessage
diff --git a/modules/json/jsonv1.go b/modules/json/jsonv1.go
new file mode 100644
index 0000000000..55ec4736b9
--- /dev/null
+++ b/modules/json/jsonv1.go
@@ -0,0 +1,34 @@
+// Copyright 2025 The Gitea Authors. All rights reserved.
+// SPDX-License-Identifier: MIT
+
+package json
+
+import (
+ "bytes"
+ "encoding/json" //nolint:depguard // this package wraps it
+ "io"
+)
+
+type jsonV1 struct{}
+
+var _ Interface = jsonV1{}
+
+func (jsonV1) Marshal(v any) ([]byte, error) {
+ return json.Marshal(v)
+}
+
+func (jsonV1) Unmarshal(data []byte, v any) error {
+ return json.Unmarshal(data, v)
+}
+
+func (jsonV1) NewEncoder(writer io.Writer) Encoder {
+ return json.NewEncoder(writer)
+}
+
+func (jsonV1) NewDecoder(reader io.Reader) Decoder {
+ return json.NewDecoder(reader)
+}
+
+func (jsonV1) Indent(dst *bytes.Buffer, src []byte, prefix, indent string) error {
+ return json.Indent(dst, src, prefix, indent)
+}
diff --git a/modules/json/jsonv2.go b/modules/json/jsonv2.go
new file mode 100644
index 0000000000..c4afc9513b
--- /dev/null
+++ b/modules/json/jsonv2.go
@@ -0,0 +1,95 @@
+// Copyright 2025 The Gitea Authors. All rights reserved.
+// SPDX-License-Identifier: MIT
+
+//go:build goexperiment.jsonv2
+
+package json
+
+import (
+ "bytes"
+ jsonv1 "encoding/json" //nolint:depguard // this package wraps it
+ "encoding/json/jsontext" //nolint:depguard // this package wraps it
+ jsonv2 "encoding/json/v2" //nolint:depguard // this package wraps it
+ "io"
+)
+
+// JSONv2 implements Interface via encoding/json/v2
+// Requires GOEXPERIMENT=jsonv2 to be set at build time
+type JSONv2 struct {
+ marshalOptions jsonv2.Options
+ marshalKeepOptionalEmptyOptions jsonv2.Options
+ unmarshalOptions jsonv2.Options
+ unmarshalCaseInsensitiveOptions jsonv2.Options
+}
+
+var jsonV2 JSONv2
+
+func init() {
+ commonMarshalOptions := []jsonv2.Options{
+ jsonv2.FormatNilSliceAsNull(true),
+ jsonv2.FormatNilMapAsNull(true),
+ }
+ jsonV2.marshalOptions = jsonv2.JoinOptions(commonMarshalOptions...)
+ jsonV2.unmarshalOptions = jsonv2.DefaultOptionsV2()
+
+ // By default, "json/v2" omitempty removes all `""` empty strings, no matter where it comes from.
+ // v1 has a different behavior: if the `""` is from a null pointer, or a Marshal function, it is kept.
+ // Golang issue: https://github.com/golang/go/issues/75623 encoding/json/v2: unable to make omitempty work with pointer or Optional type with goexperiment.jsonv2
+ jsonV2.marshalKeepOptionalEmptyOptions = jsonv2.JoinOptions(append(commonMarshalOptions, jsonv1.OmitEmptyWithLegacySemantics(true))...)
+
+ // Some legacy code uses case-insensitive matching (for example: parsing oci.ImageConfig)
+ jsonV2.unmarshalCaseInsensitiveOptions = jsonv2.JoinOptions(jsonv2.MatchCaseInsensitiveNames(true))
+}
+
+func getDefaultJSONHandler() Interface {
+ return &jsonV2
+}
+
+func MarshalKeepOptionalEmpty(v any) ([]byte, error) {
+ return jsonv2.Marshal(v, jsonV2.marshalKeepOptionalEmptyOptions)
+}
+
+func (j *JSONv2) Marshal(v any) ([]byte, error) {
+ return jsonv2.Marshal(v, j.marshalOptions)
+}
+
+func (j *JSONv2) Unmarshal(data []byte, v any) error {
+ return jsonv2.Unmarshal(data, v, j.unmarshalOptions)
+}
+
+func (j *JSONv2) NewEncoder(writer io.Writer) Encoder {
+ return &jsonV2Encoder{writer: writer, opts: j.marshalOptions}
+}
+
+func (j *JSONv2) NewDecoder(reader io.Reader) Decoder {
+ return &jsonV2Decoder{reader: reader, opts: j.unmarshalOptions}
+}
+
+// Indent implements Interface using standard library (JSON v2 doesn't have Indent yet)
+func (*JSONv2) Indent(dst *bytes.Buffer, src []byte, prefix, indent string) error {
+ return jsonv1.Indent(dst, src, prefix, indent)
+}
+
+type jsonV2Encoder struct {
+ writer io.Writer
+ opts jsonv2.Options
+}
+
+func (e *jsonV2Encoder) Encode(v any) error {
+ return jsonv2.MarshalWrite(e.writer, v, e.opts)
+}
+
+type jsonV2Decoder struct {
+ reader io.Reader
+ opts jsonv2.Options
+}
+
+func (d *jsonV2Decoder) Decode(v any) error {
+ return jsonv2.UnmarshalRead(d.reader, v, d.opts)
+}
+
+func NewDecoderCaseInsensitive(reader io.Reader) Decoder {
+ return &jsonV2Decoder{reader: reader, opts: jsonV2.unmarshalCaseInsensitiveOptions}
+}
+
+type Value = jsontext.Value
diff --git a/modules/lfs/content_store.go b/modules/lfs/content_store.go
index 0d9c0c98ac..be1e6c8e90 100644
--- a/modules/lfs/content_store.go
+++ b/modules/lfs/content_store.go
@@ -104,7 +104,7 @@ func (s *ContentStore) Verify(pointer Pointer) (bool, error) {
}
// ReadMetaObject will read a git_model.LFSMetaObject and return a reader
-func ReadMetaObject(pointer Pointer) (io.ReadSeekCloser, error) {
+func ReadMetaObject(pointer Pointer) (storage.Object, error) {
contentStore := NewContentStore()
return contentStore.Get(pointer)
}
diff --git a/modules/lfs/http_client_test.go b/modules/lfs/http_client_test.go
index 179bcdb29a..3e5ee9ec60 100644
--- a/modules/lfs/http_client_test.go
+++ b/modules/lfs/http_client_test.go
@@ -193,7 +193,7 @@ func TestHTTPClientDownload(t *testing.T) {
},
{
endpoint: "https://invalid-json-response.io",
- expectedError: "invalid json",
+ expectedError: "/(invalid json|invalid character)/",
},
{
endpoint: "https://valid-batch-request-download.io",
@@ -258,7 +258,11 @@ func TestHTTPClientDownload(t *testing.T) {
return nil
})
if c.expectedError != "" {
- assert.ErrorContains(t, err, c.expectedError)
+ if strings.HasPrefix(c.expectedError, "/") && strings.HasSuffix(c.expectedError, "/") {
+ assert.Regexp(t, strings.Trim(c.expectedError, "/"), err.Error())
+ } else {
+ assert.ErrorContains(t, err, c.expectedError)
+ }
} else {
assert.NoError(t, err)
}
@@ -297,7 +301,7 @@ func TestHTTPClientUpload(t *testing.T) {
},
{
endpoint: "https://invalid-json-response.io",
- expectedError: "invalid json",
+ expectedError: "/(invalid json|invalid character)/",
},
{
endpoint: "https://valid-batch-request-upload.io",
@@ -352,7 +356,11 @@ func TestHTTPClientUpload(t *testing.T) {
return io.NopCloser(new(bytes.Buffer)), objectError
})
if c.expectedError != "" {
- assert.ErrorContains(t, err, c.expectedError)
+ if strings.HasPrefix(c.expectedError, "/") && strings.HasSuffix(c.expectedError, "/") {
+ assert.Regexp(t, strings.Trim(c.expectedError, "/"), err.Error())
+ } else {
+ assert.ErrorContains(t, err, c.expectedError)
+ }
} else {
assert.NoError(t, err)
}
diff --git a/modules/lfs/pointer_scanner_gogit.go b/modules/lfs/pointer_scanner_gogit.go
index e153b8e24e..ccfb16b6c0 100644
--- a/modules/lfs/pointer_scanner_gogit.go
+++ b/modules/lfs/pointer_scanner_gogit.go
@@ -15,7 +15,7 @@ import (
)
// SearchPointerBlobs scans the whole repository for LFS pointer files
-func SearchPointerBlobs(ctx context.Context, repo *git.Repository, pointerChan chan<- PointerBlob, errChan chan<- error) {
+func SearchPointerBlobs(ctx context.Context, repo *git.Repository, pointerChan chan<- PointerBlob) error {
gitRepo := repo.GoGitRepo()
err := func() error {
@@ -49,14 +49,7 @@ func SearchPointerBlobs(ctx context.Context, repo *git.Repository, pointerChan c
return nil
})
}()
- if err != nil {
- select {
- case <-ctx.Done():
- default:
- errChan <- err
- }
- }
close(pointerChan)
- close(errChan)
+ return err
}
diff --git a/modules/lfs/pointer_scanner_nogogit.go b/modules/lfs/pointer_scanner_nogogit.go
index c37a93e73b..29f5d0e346 100644
--- a/modules/lfs/pointer_scanner_nogogit.go
+++ b/modules/lfs/pointer_scanner_nogogit.go
@@ -8,96 +8,84 @@ package lfs
import (
"bufio"
"context"
+ "errors"
"io"
"strconv"
"strings"
- "sync"
"code.gitea.io/gitea/modules/git"
+ "code.gitea.io/gitea/modules/git/gitcmd"
"code.gitea.io/gitea/modules/git/pipeline"
+ "code.gitea.io/gitea/modules/util"
+
+ "golang.org/x/sync/errgroup"
)
// SearchPointerBlobs scans the whole repository for LFS pointer files
-func SearchPointerBlobs(ctx context.Context, repo *git.Repository, pointerChan chan<- PointerBlob, errChan chan<- error) {
- basePath := repo.Path
-
- catFileCheckReader, catFileCheckWriter := io.Pipe()
- shasToBatchReader, shasToBatchWriter := io.Pipe()
- catFileBatchReader, catFileBatchWriter := io.Pipe()
+func SearchPointerBlobs(ctx context.Context, repo *git.Repository, pointerChan chan<- PointerBlob) error {
+ cmd1AllObjs, cmd3BatchContent := gitcmd.NewCommand(), gitcmd.NewCommand()
- wg := sync.WaitGroup{}
- wg.Add(4)
+ cmd1AllObjsStdout, cmd1AllObjsStdoutClose := cmd1AllObjs.MakeStdoutPipe()
+ defer cmd1AllObjsStdoutClose()
- // Create the go-routines in reverse order.
+ cmd3BatchContentIn, cmd3BatchContentOut, cmd3BatchContentClose := cmd3BatchContent.MakeStdinStdoutPipe()
+ defer cmd3BatchContentClose()
+ // Create the go-routines in reverse order (update: the order is not needed any more, the pipes are properly prepared)
+ wg := errgroup.Group{}
// 4. Take the output of cat-file --batch and check if each file in turn
// to see if they're pointers to files in the LFS store
- go createPointerResultsFromCatFileBatch(ctx, catFileBatchReader, &wg, pointerChan)
+ wg.Go(func() error {
+ return createPointerResultsFromCatFileBatch(cmd3BatchContentOut, pointerChan)
+ })
// 3. Take the shas of the blobs and batch read them
- go pipeline.CatFileBatch(ctx, shasToBatchReader, catFileBatchWriter, &wg, basePath)
+ wg.Go(func() error {
+ return pipeline.CatFileBatch(ctx, cmd3BatchContent, repo.Path)
+ })
// 2. From the provided objects restrict to blobs <=1k
- go pipeline.BlobsLessThan1024FromCatFileBatchCheck(catFileCheckReader, shasToBatchWriter, &wg)
+ wg.Go(func() error {
+ return pipeline.BlobsLessThan1024FromCatFileBatchCheck(cmd1AllObjsStdout, cmd3BatchContentIn)
+ })
// 1. Run batch-check on all objects in the repository
- if !git.DefaultFeatures().CheckVersionAtLeast("2.6.0") {
- revListReader, revListWriter := io.Pipe()
- shasToCheckReader, shasToCheckWriter := io.Pipe()
- wg.Add(2)
- go pipeline.CatFileBatchCheck(ctx, shasToCheckReader, catFileCheckWriter, &wg, basePath)
- go pipeline.BlobsFromRevListObjects(revListReader, shasToCheckWriter, &wg)
- go pipeline.RevListAllObjects(ctx, revListWriter, &wg, basePath, errChan)
- } else {
- go pipeline.CatFileBatchCheckAllObjects(ctx, catFileCheckWriter, &wg, basePath, errChan)
- }
- wg.Wait()
-
+ wg.Go(func() error {
+ return pipeline.CatFileBatchCheckAllObjects(ctx, cmd1AllObjs, repo.Path)
+ })
+ err := wg.Wait()
close(pointerChan)
- close(errChan)
+ return err
}
-func createPointerResultsFromCatFileBatch(ctx context.Context, catFileBatchReader *io.PipeReader, wg *sync.WaitGroup, pointerChan chan<- PointerBlob) {
- defer wg.Done()
+func createPointerResultsFromCatFileBatch(catFileBatchReader io.ReadCloser, pointerChan chan<- PointerBlob) error {
defer catFileBatchReader.Close()
bufferedReader := bufio.NewReader(catFileBatchReader)
buf := make([]byte, 1025)
-loop:
for {
- select {
- case <-ctx.Done():
- break loop
- default:
- }
-
// File descriptor line: sha
sha, err := bufferedReader.ReadString(' ')
if err != nil {
- _ = catFileBatchReader.CloseWithError(err)
- break
+ return util.Iif(errors.Is(err, io.EOF), nil, err)
}
sha = strings.TrimSpace(sha)
// Throw away the blob
if _, err := bufferedReader.ReadString(' '); err != nil {
- _ = catFileBatchReader.CloseWithError(err)
- break
+ return err
}
sizeStr, err := bufferedReader.ReadString('\n')
if err != nil {
- _ = catFileBatchReader.CloseWithError(err)
- break
+ return err
}
size, err := strconv.Atoi(sizeStr[:len(sizeStr)-1])
if err != nil {
- _ = catFileBatchReader.CloseWithError(err)
- break
+ return err
}
pointerBuf := buf[:size+1]
if _, err := io.ReadFull(bufferedReader, pointerBuf); err != nil {
- _ = catFileBatchReader.CloseWithError(err)
- break
+ return err
}
pointerBuf = pointerBuf[:size]
// Now we need to check if the pointerBuf is an LFS pointer
@@ -105,7 +93,6 @@ loop:
if !pointer.IsValid() {
continue
}
-
pointerChan <- PointerBlob{Hash: sha, Pointer: pointer}
}
}
diff --git a/modules/lfs/shared.go b/modules/lfs/shared.go
index cd9488e3db..e04c089e51 100644
--- a/modules/lfs/shared.go
+++ b/modules/lfs/shared.go
@@ -66,6 +66,21 @@ type Link struct {
ExpiresAt *time.Time `json:"expires_at,omitempty"`
}
+func NewLink(href string) *Link {
+ return &Link{Href: href}
+}
+
+func (l *Link) WithHeader(k, v string) *Link {
+ if v == "" {
+ return l
+ }
+ if l.Header == nil {
+ l.Header = make(map[string]string)
+ }
+ l.Header[k] = v
+ return l
+}
+
// ObjectError defines the JSON structure returned to the client in case of an error.
type ObjectError struct {
Code int `json:"code"`
diff --git a/modules/lfstransfer/backend/backend.go b/modules/lfstransfer/backend/backend.go
index f4e6157091..92f08eac13 100644
--- a/modules/lfstransfer/backend/backend.go
+++ b/modules/lfstransfer/backend/backend.go
@@ -95,7 +95,7 @@ func (g *GiteaBackend) Batch(_ string, pointers []transfer.BatchItem, args trans
var respBody lfs.BatchResponse
err = json.Unmarshal(respBytes, &respBody)
if err != nil {
- g.logger.Log("json umarshal error", err)
+ g.logger.Log("json unmarshal error", err)
return nil, err
}
diff --git a/modules/lfstransfer/backend/lock.go b/modules/lfstransfer/backend/lock.go
index 2c3c16a9bb..5bfa3a89c3 100644
--- a/modules/lfstransfer/backend/lock.go
+++ b/modules/lfstransfer/backend/lock.go
@@ -69,7 +69,7 @@ func (g *giteaLockBackend) Create(path, refname string) (transfer.Lock, error) {
var respBody lfslock.LFSLockResponse
err = json.Unmarshal(respBytes, &respBody)
if err != nil {
- g.logger.Log("json umarshal error", err)
+ g.logger.Log("json unmarshal error", err)
return nil, err
}
@@ -202,7 +202,7 @@ func (g *giteaLockBackend) queryLocks(v url.Values) ([]transfer.Lock, string, er
var respBody lfslock.LFSLockList
err = json.Unmarshal(respBytes, &respBody)
if err != nil {
- g.logger.Log("json umarshal error", err)
+ g.logger.Log("json unmarshal error", err)
return nil, "", err
}
diff --git a/modules/lfstransfer/logger.go b/modules/lfstransfer/logger.go
index 517c2d9ba1..dfb9c0bb66 100644
--- a/modules/lfstransfer/logger.go
+++ b/modules/lfstransfer/logger.go
@@ -17,5 +17,5 @@ func newLogger() transfer.Logger {
}
// Log implements transfer.Logger
-func (g *GiteaLogger) Log(msg string, itms ...any) {
+func (g *GiteaLogger) Log(msg string, items ...any) {
}
diff --git a/modules/log/init.go b/modules/log/init.go
index 3fb5200ad7..ccaab50de3 100644
--- a/modules/log/init.go
+++ b/modules/log/init.go
@@ -35,10 +35,10 @@ func init() {
}
}
-func newProcessTypedContext(parent context.Context, desc string) (ctx context.Context, cancel context.CancelFunc) {
+func newProcessTypedContext(parent context.Context, desc string) (context.Context, context.CancelFunc) {
// the "process manager" also calls "log.Trace()" to output logs, so if we want to create new contexts by the manager, we need to disable the trace temporarily
process.TraceLogDisable(true)
defer process.TraceLogDisable(false)
- ctx, _, cancel = process.GetManager().AddTypedContext(parent, desc, process.SystemProcessType, false)
- return ctx, cancel
+ ctx, _, finished := process.GetManager().AddTypedContext(parent, desc, process.SystemProcessType, false)
+ return ctx, context.CancelFunc(finished)
}
diff --git a/modules/log/logger_global.go b/modules/log/logger_global.go
index 07c25cd62f..2bc8c4f449 100644
--- a/modules/log/logger_global.go
+++ b/modules/log/logger_global.go
@@ -18,6 +18,7 @@ func GetLevel() Level {
}
func Log(skip int, level Level, format string, v ...any) {
+ // codeql[disable-next-line=go/clear-text-logging]
GetLogger(DEFAULT).Log(skip+1, &Event{Level: level}, format, v...)
}
diff --git a/modules/log/logger_impl.go b/modules/log/logger_impl.go
index 551c1454aa..b15dc2f28d 100644
--- a/modules/log/logger_impl.go
+++ b/modules/log/logger_impl.go
@@ -5,6 +5,7 @@ package log
import (
"context"
+ "net/url"
"reflect"
"runtime"
"strings"
@@ -226,6 +227,8 @@ func (l *LoggerImpl) Log(skip int, event *Event, format string, logArgs ...any)
}
} else if ls := asLogStringer(v); ls != nil {
msgArgs[i] = logStringFormatter{v: ls}
+ } else if str, ok := v.(string); ok {
+ msgArgs[i] = protectSensitiveInfo(str)
}
}
@@ -235,6 +238,24 @@ func (l *LoggerImpl) Log(skip int, event *Event, format string, logArgs ...any)
l.SendLogEvent(event)
}
+func protectSensitiveInfo(s string) string {
+ u, err := url.Parse(s)
+ if err != nil || (u.Scheme != "http" && u.Scheme != "https") || u.Host == "" {
+ return s
+ }
+ q := u.Query()
+ for _, vals := range q {
+ for i := range vals {
+ vals[i] = "_"
+ }
+ }
+ masked := &url.URL{Scheme: u.Scheme, Host: u.Host, Path: u.Path, RawQuery: q.Encode()}
+ if u.User != nil {
+ masked.User = url.User("_masked_")
+ }
+ return masked.String()
+}
+
func (l *LoggerImpl) GetLevel() Level {
return Level(l.level.Load())
}
diff --git a/modules/log/logger_test.go b/modules/log/logger_test.go
index a74139dc51..6e38610ddd 100644
--- a/modules/log/logger_test.go
+++ b/modules/log/logger_test.go
@@ -177,3 +177,10 @@ func TestLoggerExpressionFilter(t *testing.T) {
assert.Equal(t, []string{"foo\n", "foo bar\n", "by filename\n"}, w1.FetchLogs())
}
+
+func TestProtectSensitiveInfo(t *testing.T) {
+ assert.Empty(t, protectSensitiveInfo(""))
+ assert.Equal(t, "mailto:user@example.com", protectSensitiveInfo("mailto:user@example.com"))
+ assert.Equal(t, "https://example.com", protectSensitiveInfo("https://example.com"))
+ assert.Equal(t, "https://_masked_@example.com/path?k=_", protectSensitiveInfo("https://u:p@example.com/path?k=v#hash"))
+}
diff --git a/modules/log/misc.go b/modules/log/misc.go
index c9d230e4ac..a58b3757da 100644
--- a/modules/log/misc.go
+++ b/modules/log/misc.go
@@ -20,6 +20,7 @@ func BaseLoggerToGeneralLogger(b BaseLogger) Logger {
var _ Logger = (*baseToLogger)(nil)
func (s *baseToLogger) Log(skip int, event *Event, format string, v ...any) {
+ // codeql[disable-next-line=go/clear-text-logging]
s.base.Log(skip+1, event, format, v...)
}
diff --git a/modules/markup/asciicast/asciicast.go b/modules/markup/asciicast/asciicast.go
index d86d61d7c4..b3af5eef09 100644
--- a/modules/markup/asciicast/asciicast.go
+++ b/modules/markup/asciicast/asciicast.go
@@ -20,14 +20,12 @@ func init() {
// See https://github.com/asciinema/asciinema/blob/develop/doc/asciicast-v2.md
type Renderer struct{}
-// Name implements markup.Renderer
func (Renderer) Name() string {
return "asciicast"
}
-// Extensions implements markup.Renderer
-func (Renderer) Extensions() []string {
- return []string{".cast"}
+func (Renderer) FileNamePatterns() []string {
+ return []string{"*.cast"}
}
const (
@@ -35,12 +33,10 @@ const (
playerSrcAttr = "data-asciinema-player-src"
)
-// SanitizerRules implements markup.Renderer
func (Renderer) SanitizerRules() []setting.MarkupSanitizerRule {
return []setting.MarkupSanitizerRule{{Element: "div", AllowAttr: playerSrcAttr}}
}
-// Render implements markup.Renderer
func (Renderer) Render(ctx *markup.RenderContext, _ io.Reader, output io.Writer) error {
rawURL := fmt.Sprintf("%s/%s/%s/raw/%s/%s",
setting.AppSubURL,
diff --git a/modules/markup/camo.go b/modules/markup/camo.go
index 7e2583469d..f07d62d4f9 100644
--- a/modules/markup/camo.go
+++ b/modules/markup/camo.go
@@ -11,7 +11,6 @@ import (
"strings"
"code.gitea.io/gitea/modules/setting"
- "code.gitea.io/gitea/modules/util"
)
// CamoEncode encodes a lnk to fit with the go-camo and camo proxy links. The purposes of camo-proxy are:
@@ -27,7 +26,7 @@ func CamoEncode(link string) string {
macSum := b64encode(mac.Sum(nil))
encodedURL := b64encode([]byte(link))
- return util.URLJoin(setting.Camo.ServerURL, macSum, encodedURL)
+ return strings.TrimSuffix(setting.Camo.ServerURL, "/") + "/" + macSum + "/" + encodedURL
}
func b64encode(data []byte) string {
diff --git a/modules/markup/common/footnote.go b/modules/markup/common/footnote.go
index 1ece436c66..e552a28237 100644
--- a/modules/markup/common/footnote.go
+++ b/modules/markup/common/footnote.go
@@ -405,9 +405,9 @@ func (r *FootnoteHTMLRenderer) renderFootnoteLink(w util.BufWriter, source []byt
if entering {
n := node.(*FootnoteLink)
is := strconv.Itoa(n.Index)
- _, _ = w.WriteString(`
`
- defer test.MockVariableValue(&markup.RenderBehaviorForTesting.DisableAdditionalAttributes, true)()
result, err := markdown.RenderString(markup.NewTestRenderContext(localMetas), input)
assert.NoError(t, err)
assert.Equal(t, expected, string(result))
+
+ t.Run("LocalCommitAndCompare", func(t *testing.T) {
+ input := `http://localhost:3000/user/repo/commit/88fc37a3c0a4dda553bdcfc80c178a58247f42fb
+http://localhost:3000/user/repo/compare/88fc37a3c0a4dda553bdcfc80c178a58247f42fb...12fc37a3c0a4dda553bdcfc80c178a58247f42fb#hash`
+
+ expected := `88fc37a3c0
+88fc37a3c0...12fc37a3c0 (hash)
+`
+ result, err := markdown.RenderString(markup.NewTestRenderContext(localMetas), input)
+ assert.NoError(t, err)
+ assert.Equal(t, expected, string(result))
+ })
}
func TestMarkdownLink(t *testing.T) {
@@ -545,5 +575,28 @@ func TestMarkdownLink(t *testing.T) {
assert.Equal(t, `link1
link2
link3
+`, string(result))
+
+ input = "https://example.com/__init__.py"
+ result, err = markdown.RenderString(markup.NewTestRenderContext("/base", localMetas), input)
+ assert.NoError(t, err)
+ assert.Equal(t, `https://example.com/__init__.py
+`, string(result))
+}
+
+func TestMarkdownUlDir(t *testing.T) {
+ defer test.MockVariableValue(&markup.RenderBehaviorForTesting.DisableAdditionalAttributes, false)()
+ result, err := markdown.RenderString(markup.NewTestRenderContext(), `
+* a
+ * b
+`)
+ assert.NoError(t, err)
+ assert.Equal(t, `
`, string(result))
}
diff --git a/modules/markup/markdown/meta.go b/modules/markup/markdown/meta.go
index e76b253ecd..6ddd892110 100644
--- a/modules/markup/markdown/meta.go
+++ b/modules/markup/markdown/meta.go
@@ -60,8 +60,8 @@ func ExtractMetadata(contents string, out any) (string, error) {
return string(body), err
}
-// ExtractMetadata consumes a markdown file, parses YAML frontmatter,
-// and returns the frontmatter metadata separated from the markdown content
+// ExtractMetadataBytes consumes a Markdown content, parses YAML frontmatter,
+// and returns the frontmatter metadata separated from the Markdown content
func ExtractMetadataBytes(contents []byte, out any) ([]byte, error) {
var front, body []byte
diff --git a/modules/markup/markdown/prefixed_id.go b/modules/markup/markdown/prefixed_id.go
deleted file mode 100644
index 63d7fadc0a..0000000000
--- a/modules/markup/markdown/prefixed_id.go
+++ /dev/null
@@ -1,59 +0,0 @@
-// Copyright 2024 The Gitea Authors. All rights reserved.
-// SPDX-License-Identifier: MIT
-
-package markdown
-
-import (
- "bytes"
- "fmt"
-
- "code.gitea.io/gitea/modules/container"
- "code.gitea.io/gitea/modules/markup/common"
- "code.gitea.io/gitea/modules/util"
-
- "github.com/yuin/goldmark/ast"
-)
-
-type prefixedIDs struct {
- values container.Set[string]
-}
-
-// Generate generates a new element id.
-func (p *prefixedIDs) Generate(value []byte, kind ast.NodeKind) []byte {
- dft := []byte("id")
- if kind == ast.KindHeading {
- dft = []byte("heading")
- }
- return p.GenerateWithDefault(value, dft)
-}
-
-// GenerateWithDefault generates a new element id.
-func (p *prefixedIDs) GenerateWithDefault(value, dft []byte) []byte {
- result := common.CleanValue(value)
- if len(result) == 0 {
- result = dft
- }
- if !bytes.HasPrefix(result, []byte("user-content-")) {
- result = append([]byte("user-content-"), result...)
- }
- if p.values.Add(util.UnsafeBytesToString(result)) {
- return result
- }
- for i := 1; ; i++ {
- newResult := fmt.Sprintf("%s-%d", result, i)
- if p.values.Add(newResult) {
- return []byte(newResult)
- }
- }
-}
-
-// Put puts a given element id to the used ids table.
-func (p *prefixedIDs) Put(value []byte) {
- p.values.Add(util.UnsafeBytesToString(value))
-}
-
-func newPrefixedIDs() *prefixedIDs {
- return &prefixedIDs{
- values: make(container.Set[string]),
- }
-}
diff --git a/modules/markup/markdown/toc.go b/modules/markup/markdown/toc.go
deleted file mode 100644
index a11b9d0390..0000000000
--- a/modules/markup/markdown/toc.go
+++ /dev/null
@@ -1,59 +0,0 @@
-// Copyright 2020 The Gitea Authors. All rights reserved.
-// SPDX-License-Identifier: MIT
-
-package markdown
-
-import (
- "net/url"
-
- "code.gitea.io/gitea/modules/translation"
-
- "github.com/yuin/goldmark/ast"
-)
-
-// Header holds the data about a header.
-type Header struct {
- Level int
- Text string
- ID string
-}
-
-func createTOCNode(toc []Header, lang string, detailsAttrs map[string]string) ast.Node {
- details := NewDetails()
- summary := NewSummary()
-
- for k, v := range detailsAttrs {
- details.SetAttributeString(k, []byte(v))
- }
-
- summary.AppendChild(summary, ast.NewString([]byte(translation.NewLocale(lang).TrString("toc"))))
- details.AppendChild(details, summary)
- ul := ast.NewList('-')
- details.AppendChild(details, ul)
- currentLevel := 6
- for _, header := range toc {
- if header.Level < currentLevel {
- currentLevel = header.Level
- }
- }
- for _, header := range toc {
- for currentLevel > header.Level {
- ul = ul.Parent().(*ast.List)
- currentLevel--
- }
- for currentLevel < header.Level {
- newL := ast.NewList('-')
- ul.AppendChild(ul, newL)
- currentLevel++
- ul = newL
- }
- li := ast.NewListItem(currentLevel * 2)
- a := ast.NewLink()
- a.Destination = []byte("#" + url.QueryEscape(header.ID))
- a.AppendChild(a, ast.NewString([]byte(header.Text)))
- li.AppendChild(li, a)
- ul.AppendChild(ul, li)
- }
-
- return details
-}
diff --git a/modules/markup/markdown/transform_heading.go b/modules/markup/markdown/transform_heading.go
deleted file mode 100644
index a229a7b1a4..0000000000
--- a/modules/markup/markdown/transform_heading.go
+++ /dev/null
@@ -1,32 +0,0 @@
-// Copyright 2024 The Gitea Authors. All rights reserved.
-// SPDX-License-Identifier: MIT
-
-package markdown
-
-import (
- "fmt"
-
- "code.gitea.io/gitea/modules/markup"
- "code.gitea.io/gitea/modules/util"
-
- "github.com/yuin/goldmark/ast"
- "github.com/yuin/goldmark/text"
-)
-
-func (g *ASTTransformer) transformHeading(_ *markup.RenderContext, v *ast.Heading, reader text.Reader, tocList *[]Header) {
- for _, attr := range v.Attributes() {
- if _, ok := attr.Value.([]byte); !ok {
- v.SetAttribute(attr.Name, fmt.Appendf(nil, "%v", attr.Value))
- }
- }
- txt := v.Text(reader.Source()) //nolint:staticcheck // Text is deprecated
- header := Header{
- Text: util.UnsafeBytesToString(txt),
- Level: v.Level,
- }
- if id, found := v.AttributeString("id"); found {
- header.ID = util.UnsafeBytesToString(id.([]byte))
- }
- *tocList = append(*tocList, header)
- g.applyElementDir(v)
-}
diff --git a/modules/markup/markdown/transform_list.go b/modules/markup/markdown/transform_list.go
index c89ad2f2cf..6cafa8ff78 100644
--- a/modules/markup/markdown/transform_list.go
+++ b/modules/markup/markdown/transform_list.go
@@ -81,5 +81,16 @@ func (g *ASTTransformer) transformList(_ *markup.RenderContext, v *ast.List, rc
v.AppendChild(v, newChild)
}
}
- g.applyElementDir(v)
+
+ nestedList := false
+ for p := v.Parent(); p != nil; p = p.Parent() {
+ if _, ok := p.(*ast.List); ok {
+ nestedList = true
+ break
+ }
+ }
+ if !nestedList {
+ // "dir=auto" should be only added to top-level "ul". https://github.com/go-gitea/gitea/issues/35058
+ g.applyElementDir(v)
+ }
}
diff --git a/modules/markup/mdstripper/mdstripper.go b/modules/markup/mdstripper/mdstripper.go
index 5a6504416a..bf69051e87 100644
--- a/modules/markup/mdstripper/mdstripper.go
+++ b/modules/markup/mdstripper/mdstripper.go
@@ -46,7 +46,7 @@ func (r *stripRenderer) Render(w io.Writer, source []byte, doc ast.Node) error {
coalesce := prevSibIsText
r.processString(
w,
- v.Text(source), //nolint:staticcheck // Text is deprecated
+ v.Value(source),
coalesce)
if v.SoftLineBreak() {
r.doubleSpace(w)
@@ -165,7 +165,6 @@ func StripMarkdownBytes(rawBytes []byte) ([]byte, []string) {
),
goldmark.WithParserOptions(
parser.WithAttribute(),
- parser.WithAutoHeadingID(),
),
goldmark.WithRendererOptions(
html.WithUnsafe(),
diff --git a/modules/markup/orgmode/orgmode.go b/modules/markup/orgmode/orgmode.go
index 93c335d244..fd3071645a 100644
--- a/modules/markup/orgmode/orgmode.go
+++ b/modules/markup/orgmode/orgmode.go
@@ -5,7 +5,6 @@ package orgmode
import (
"fmt"
- "html"
"html/template"
"io"
"strings"
@@ -17,7 +16,6 @@ import (
"code.gitea.io/gitea/modules/setting"
"github.com/alecthomas/chroma/v2"
- "github.com/alecthomas/chroma/v2/lexers"
"github.com/niklasfasching/go-org/org"
)
@@ -33,20 +31,16 @@ var (
_ markup.PostProcessRenderer = (*renderer)(nil)
)
-// Name implements markup.Renderer
func (renderer) Name() string {
return "orgmode"
}
-// NeedPostProcess implements markup.PostProcessRenderer
func (renderer) NeedPostProcess() bool { return true }
-// Extensions implements markup.Renderer
-func (renderer) Extensions() []string {
- return []string{".org"}
+func (renderer) FileNamePatterns() []string {
+ return []string{"*.org"}
}
-// SanitizerRules implements markup.Renderer
func (renderer) SanitizerRules() []setting.MarkupSanitizerRule {
return []setting.MarkupSanitizerRule{}
}
@@ -57,40 +51,20 @@ func Render(ctx *markup.RenderContext, input io.Reader, output io.Writer) error
htmlWriter.HighlightCodeBlock = func(source, lang string, inline bool, params map[string]string) string {
defer func() {
if err := recover(); err != nil {
+ // catch the panic, log the error and return empty result
log.Error("Panic in HighlightCodeBlock: %v\n%s", err, log.Stack(2))
- panic(err)
}
}()
- w := &strings.Builder{}
- lexer := lexers.Get(lang)
- if lexer == nil && lang == "" {
- lexer = lexers.Analyse(source)
- if lexer == nil {
- lexer = lexers.Fallback
- }
- lang = strings.ToLower(lexer.Config().Name)
- }
+ lexer := highlight.DetectChromaLexerByFileName("", lang) // don't use content to detect, it is too slow
+ lexer = chroma.Coalesce(lexer)
+ sb := &strings.Builder{}
// include language-x class as part of commonmark spec
- if err := ctx.RenderInternal.FormatWithSafeAttrs(w, ``, lang); err != nil {
- return ""
- }
- if lexer == nil {
- if _, err := w.WriteString(html.EscapeString(source)); err != nil {
- return ""
- }
- } else {
- lexer = chroma.Coalesce(lexer)
- if _, err := w.WriteString(string(highlight.CodeFromLexer(lexer, source))); err != nil {
- return ""
- }
- }
- if _, err := w.WriteString(" "); err != nil {
- return ""
- }
-
- return w.String()
+ _ = ctx.RenderInternal.FormatWithSafeAttrs(sb, ``, strings.ToLower(lexer.Config().Name))
+ _, _ = sb.WriteString(string(highlight.RenderCodeByLexer(lexer, source)))
+ _, _ = sb.WriteString(" ")
+ return sb.String()
}
w := &orgWriter{rctx: ctx, HTMLWriter: htmlWriter}
diff --git a/modules/markup/render_link.go b/modules/markup/render_link.go
index 9cc83095ff..c3a95622ac 100644
--- a/modules/markup/render_link.go
+++ b/modules/markup/render_link.go
@@ -5,28 +5,47 @@ package markup
import (
"context"
+ "net/url"
+ "path"
"strings"
"code.gitea.io/gitea/modules/httplib"
"code.gitea.io/gitea/modules/setting"
- "code.gitea.io/gitea/modules/util"
)
+// resolveLinkRelative tries to resolve the link relative to the "{base}/{cur}", and returns the final link.
+// It only resolves the link, doesn't do any sanitization or validation, invalid links will be returned as is.
func resolveLinkRelative(ctx context.Context, base, cur, link string, absolute bool) (finalLink string) {
- if IsFullURLString(link) {
- return link
+ linkURL, err := url.Parse(link)
+ if err != nil {
+ return link // invalid URL, return as is
}
+ if linkURL.Scheme != "" || linkURL.Host != "" {
+ return link // absolute URL, return as is
+ }
+
if strings.HasPrefix(link, "/") {
if strings.HasPrefix(link, base) && strings.Count(base, "/") >= 4 {
- // a trick to tolerate that some users were using absolute paths (the old gitea's behavior)
+ // a trick to tolerate that some users were using absolute paths (the old Gitea's behavior)
+ // if the link is likely "{base}/src/main" while "{base}" is something like "/owner/repo"
finalLink = link
} else {
- finalLink = util.URLJoin(base, "./", link)
+ // need to resolve the link relative to "{base}"
+ cur = ""
+ }
+ } // else: link is relative to "{base}/{cur}"
+
+ if finalLink == "" {
+ finalLink = strings.TrimSuffix(base, "/") + path.Join("/"+cur, "/"+linkURL.EscapedPath())
+ finalLink = strings.TrimSuffix(finalLink, "/")
+ if linkURL.RawQuery != "" {
+ finalLink += "?" + linkURL.RawQuery
+ }
+ if linkURL.Fragment != "" {
+ finalLink += "#" + linkURL.Fragment
}
- } else {
- finalLink = util.URLJoin(base, "./", cur, link)
}
- finalLink = strings.TrimSuffix(finalLink, "/")
+
if absolute {
finalLink = httplib.MakeAbsoluteURL(ctx, finalLink)
}
diff --git a/modules/markup/render_link_test.go b/modules/markup/render_link_test.go
index 972e15308c..045b728c8d 100644
--- a/modules/markup/render_link_test.go
+++ b/modules/markup/render_link_test.go
@@ -18,8 +18,16 @@ func TestResolveLinkRelative(t *testing.T) {
assert.Equal(t, "/a/b", resolveLinkRelative(ctx, "/a", "b", "", false))
assert.Equal(t, "/a/b/c", resolveLinkRelative(ctx, "/a", "b", "c", false))
assert.Equal(t, "/a/c", resolveLinkRelative(ctx, "/a", "b", "/c", false))
+ assert.Equal(t, "/a/c#id", resolveLinkRelative(ctx, "/a", "b", "/c#id", false))
+ assert.Equal(t, "/a/%2f?k=/", resolveLinkRelative(ctx, "/a", "b", "/%2f/?k=/", false))
+ assert.Equal(t, "/a/b/c?k=v#id", resolveLinkRelative(ctx, "/a", "b", "c/?k=v#id", false))
+ assert.Equal(t, "%invalid", resolveLinkRelative(ctx, "/a", "b", "%invalid", false))
assert.Equal(t, "http://localhost:3000/a", resolveLinkRelative(ctx, "/a", "", "", true))
+ // absolute link is returned as is
+ assert.Equal(t, "mailto:user@domain.com", resolveLinkRelative(ctx, "/a", "", "mailto:user@domain.com", false))
+ assert.Equal(t, "http://other/path/", resolveLinkRelative(ctx, "/a", "", "http://other/path/", false))
+
// some users might have used absolute paths a lot, so if the prefix overlaps and has enough slashes, we should tolerate it
assert.Equal(t, "/owner/repo/foo/owner/repo/foo/bar/xxx", resolveLinkRelative(ctx, "/owner/repo/foo", "", "/owner/repo/foo/bar/xxx", false))
assert.Equal(t, "/owner/repo/foo/bar/xxx", resolveLinkRelative(ctx, "/owner/repo/foo/bar", "", "/owner/repo/foo/bar/xxx", false))
diff --git a/modules/markup/render_test.go b/modules/markup/render_test.go
new file mode 100644
index 0000000000..3b89d8485e
--- /dev/null
+++ b/modules/markup/render_test.go
@@ -0,0 +1,31 @@
+// Copyright 2026 The Gitea Authors. All rights reserved.
+// SPDX-License-Identifier: MIT
+
+package markup
+
+import (
+ "strings"
+ "testing"
+
+ "github.com/stretchr/testify/assert"
+ "github.com/stretchr/testify/require"
+)
+
+func TestRenderIFrame(t *testing.T) {
+ render := func(ctx *RenderContext, opts ExternalRendererOptions) string {
+ sb := &strings.Builder{}
+ require.NoError(t, RenderIFrame(ctx, &opts, sb))
+ return sb.String()
+ }
+
+ ctx := NewRenderContext(t.Context()).
+ WithRelativePath("tree-path").
+ WithMetas(map[string]string{"user": "test-owner", "repo": "test-repo", "RefTypeNameSubURL": "src/branch/master"})
+
+ // the value is read from config RENDER_CONTENT_SANDBOX, empty means "disabled"
+ ret := render(ctx, ExternalRendererOptions{ContentSandbox: ""})
+ assert.Equal(t, ``, ret)
+
+ ret = render(ctx, ExternalRendererOptions{ContentSandbox: "allow"})
+ assert.Equal(t, ``, ret)
+}
diff --git a/modules/markup/renderer.go b/modules/markup/renderer.go
index 82e9348706..c62c28ad2a 100644
--- a/modules/markup/renderer.go
+++ b/modules/markup/renderer.go
@@ -14,8 +14,8 @@ import (
// Renderer defines an interface for rendering markup file to HTML
type Renderer interface {
- Name() string // markup format name
- Extensions() []string
+ Name() string // markup format name, also the renderer type, also the external tool name
+ FileNamePatterns() []string
SanitizerRules() []setting.MarkupSanitizerRule
Render(ctx *RenderContext, input io.Reader, output io.Writer) error
}
@@ -43,26 +43,52 @@ type RendererContentDetector interface {
}
var (
- extRenderers = make(map[string]Renderer)
- renderers = make(map[string]Renderer)
+ fileNameRenderers = make(map[string]Renderer)
+ renderers = make(map[string]Renderer)
)
// RegisterRenderer registers a new markup file renderer
func RegisterRenderer(renderer Renderer) {
+ // TODO: need to handle conflicts
renderers[renderer.Name()] = renderer
- for _, ext := range renderer.Extensions() {
- extRenderers[strings.ToLower(ext)] = renderer
+}
+
+func RefreshFileNamePatterns() {
+ // TODO: need to handle conflicts
+ fileNameRenderers = make(map[string]Renderer)
+ for _, renderer := range renderers {
+ for _, ext := range renderer.FileNamePatterns() {
+ fileNameRenderers[strings.ToLower(ext)] = renderer
+ }
}
}
-// GetRendererByFileName get renderer by filename
-func GetRendererByFileName(filename string) Renderer {
- extension := strings.ToLower(path.Ext(filename))
- return extRenderers[extension]
+func DetectRendererTypeByFilename(filename string) Renderer {
+ basename := path.Base(strings.ToLower(filename))
+ ext1 := path.Ext(basename)
+ if renderer := fileNameRenderers[basename]; renderer != nil {
+ return renderer
+ }
+ if renderer := fileNameRenderers["*"+ext1]; renderer != nil {
+ return renderer
+ }
+ if basename, ok := strings.CutSuffix(basename, ext1); ok {
+ ext2 := path.Ext(basename)
+ if renderer := fileNameRenderers["*"+ext2+ext1]; renderer != nil {
+ return renderer
+ }
+ }
+ return nil
}
-// DetectRendererType detects the markup type of the content
-func DetectRendererType(filename string, sniffedType typesniffer.SniffedType, prefetchBuf []byte) string {
+// DetectRendererTypeByPrefetch detects the markup type of the content
+func DetectRendererTypeByPrefetch(filename string, sniffedType typesniffer.SniffedType, prefetchBuf []byte) string {
+ if filename != "" {
+ byExt := DetectRendererTypeByFilename(filename)
+ if byExt != nil {
+ return byExt.Name()
+ }
+ }
for _, renderer := range renderers {
if detector, ok := renderer.(RendererContentDetector); ok && detector.CanRender(filename, sniffedType, prefetchBuf) {
return renderer.Name()
@@ -71,18 +97,12 @@ func DetectRendererType(filename string, sniffedType typesniffer.SniffedType, pr
return ""
}
-// DetectMarkupTypeByFileName returns the possible markup format type via the filename
-func DetectMarkupTypeByFileName(filename string) string {
- if parser := GetRendererByFileName(filename); parser != nil {
- return parser.Name()
- }
- return ""
-}
-
func PreviewableExtensions() []string {
- extensions := make([]string, 0, len(extRenderers))
- for extension := range extRenderers {
- extensions = append(extensions, extension)
+ exts := make([]string, 0, len(fileNameRenderers))
+ for p := range fileNameRenderers {
+ if s, ok := strings.CutPrefix(p, "*"); ok {
+ exts = append(exts, s)
+ }
}
- return extensions
+ return exts
}
diff --git a/modules/markup/sanitizer_default.go b/modules/markup/sanitizer_default.go
index 7fdf66c4bc..447cf4807e 100644
--- a/modules/markup/sanitizer_default.go
+++ b/modules/markup/sanitizer_default.go
@@ -56,6 +56,11 @@ func (st *Sanitizer) createDefaultPolicy() *bluemonday.Policy {
policy.AllowAttrs("src", "autoplay", "controls").OnElements("video")
+ // Native support of " "
+ // ATTENTION: it only works with "auto" theme, because "media" query doesn't work with the theme chosen by end user manually.
+ // For example: browser's color scheme is "dark", but end user chooses "light" theme. Maybe it needs JS to help to make it work.
+ policy.AllowAttrs("media", "srcset").OnElements("source")
+
policy.AllowAttrs("loading").OnElements("img")
// Allow generally safe attributes (reference: https://github.com/jch/html-pipeline)
@@ -81,11 +86,12 @@ func (st *Sanitizer) createDefaultPolicy() *bluemonday.Policy {
"data-markdown-generated-content", "data-attr-class",
}
generalSafeElements := []string{
- "h1", "h2", "h3", "h4", "h5", "h6", "h7", "h8", "br", "b", "i", "strong", "em", "a", "pre", "code", "img", "tt",
+ "h1", "h2", "h3", "h4", "h5", "h6", "h7", "h8", "br", "b", "center", "i", "strong", "em", "a", "pre", "code", "img", "tt",
"div", "ins", "del", "sup", "sub", "p", "ol", "ul", "table", "thead", "tbody", "tfoot", "blockquote", "label",
"dl", "dt", "dd", "kbd", "q", "samp", "var", "hr", "ruby", "rt", "rp", "li", "tr", "td", "th", "s", "strike", "summary",
"details", "caption", "figure", "figcaption",
"abbr", "bdo", "cite", "dfn", "mark", "small", "span", "time", "video", "wbr",
+ "picture", "source",
}
// FIXME: Need to handle longdesc in img but there is no easy way to do it
policy.AllowAttrs(generalSafeAttrs...).OnElements(generalSafeElements...)
diff --git a/modules/markup/sanitizer_default_test.go b/modules/markup/sanitizer_default_test.go
index e5ba018e1b..e66f00c02f 100644
--- a/modules/markup/sanitizer_default_test.go
+++ b/modules/markup/sanitizer_default_test.go
@@ -58,6 +58,9 @@ func TestSanitizer(t *testing.T) {
`my custom URL scheme `, `my custom URL scheme `,
`my custom URL scheme `, `my custom URL scheme `,
+ // picture
+ ` `, ` `,
+
// Disallow dangerous url schemes
`bad `, `bad`,
`bad `, `bad`,
diff --git a/modules/markup/sanitizer_description_test.go b/modules/markup/sanitizer_description_test.go
index ca72491f26..51833414f4 100644
--- a/modules/markup/sanitizer_description_test.go
+++ b/modules/markup/sanitizer_description_test.go
@@ -16,7 +16,7 @@ func TestDescriptionSanitizer(t *testing.T) {
`THUMBS UP `, `THUMBS UP `,
`Hello World `, `Hello World `,
` `, ``,
- `https://example.com `, `https://example.com `,
+ `https://example.com `, `https://example.com `,
`data `, `data`,
`Important! `, `Important!`,
`Click me! Nothing to see here. `, `Click me! Nothing to see here.`,
diff --git a/modules/migration/file_format.go b/modules/migration/file_format.go
index e8b6891ca1..fd6ac45a21 100644
--- a/modules/migration/file_format.go
+++ b/modules/migration/file_format.go
@@ -12,10 +12,17 @@ import (
"code.gitea.io/gitea/modules/json"
"code.gitea.io/gitea/modules/log"
- "github.com/santhosh-tekuri/jsonschema/v5"
+ "github.com/santhosh-tekuri/jsonschema/v6"
"gopkg.in/yaml.v3"
)
+// schemaLoader implements jsonschema.URLLoader
+type schemaLoader struct{}
+
+func (l *schemaLoader) Load(url string) (any, error) {
+ return openSchema(url)
+}
+
// Load project data from file, with optional validation
func Load(filename string, data any, validation bool) error {
isJSON := strings.HasSuffix(filename, ".json")
@@ -43,7 +50,7 @@ func unmarshal(bs []byte, data any, isJSON bool) error {
func getSchema(filename string) (*jsonschema.Schema, error) {
c := jsonschema.NewCompiler()
- c.LoadURL = openSchema
+ c.UseLoader(&schemaLoader{})
return c.Compile(filename)
}
diff --git a/modules/migration/file_format_test.go b/modules/migration/file_format_test.go
index da997f645b..fd7db9074b 100644
--- a/modules/migration/file_format_test.go
+++ b/modules/migration/file_format_test.go
@@ -7,7 +7,7 @@ import (
"strings"
"testing"
- "github.com/santhosh-tekuri/jsonschema/v5"
+ "github.com/santhosh-tekuri/jsonschema/v6"
"github.com/stretchr/testify/assert"
)
diff --git a/modules/migration/options.go b/modules/migration/options.go
index 163aa0cfaa..0f73c55ac4 100644
--- a/modules/migration/options.go
+++ b/modules/migration/options.go
@@ -40,5 +40,7 @@ type MigrateOptions struct {
MirrorInterval string `json:"mirror_interval"`
AWSAccessKeyID string
- AWSSecretAccessKey string
+ AWSSecretAccessKey string `json:",omitempty"`
+
+ AWSSecretAccessKeyEncrypted string `json:"aws_secret_access_key_encrypted,omitempty"`
}
diff --git a/modules/migration/release.go b/modules/migration/release.go
index f92cf25e7b..e25e7e4428 100644
--- a/modules/migration/release.go
+++ b/modules/migration/release.go
@@ -10,9 +10,12 @@ import (
// ReleaseAsset represents a release asset
type ReleaseAsset struct {
- ID int64
- Name string
- ContentType *string `yaml:"content_type"`
+ ID int64
+ Name string
+
+ // There was a field "ContentType (content_type)" because Some forges can provide that for assets,
+ // but we don't need it when migrating, so the field is omitted here.
+
Size *int
DownloadCount *int `yaml:"download_count"`
Created time.Time
diff --git a/modules/migration/schemas_bindata.go b/modules/migration/schemas_bindata.go
index 695c2c1135..2f0e254408 100644
--- a/modules/migration/schemas_bindata.go
+++ b/modules/migration/schemas_bindata.go
@@ -8,7 +8,6 @@
package migration
import (
- "io"
"io/fs"
"path"
"sync"
@@ -16,6 +15,8 @@ import (
_ "embed"
"code.gitea.io/gitea/modules/assetfs"
+
+ "github.com/santhosh-tekuri/jsonschema/v6"
)
//go:embed bindata.dat
@@ -25,6 +26,11 @@ var BuiltinAssets = sync.OnceValue(func() fs.FS {
return assetfs.NewEmbeddedFS(bindata)
})
-func openSchema(filename string) (io.ReadCloser, error) {
- return BuiltinAssets().Open(path.Base(filename))
+func openSchema(filename string) (any, error) {
+ f, err := BuiltinAssets().Open(path.Base(filename))
+ if err != nil {
+ return nil, err
+ }
+ defer f.Close()
+ return jsonschema.UnmarshalJSON(f)
}
diff --git a/modules/migration/schemas_dynamic.go b/modules/migration/schemas_dynamic.go
index dca109d6af..46db879285 100644
--- a/modules/migration/schemas_dynamic.go
+++ b/modules/migration/schemas_dynamic.go
@@ -6,14 +6,15 @@
package migration
import (
- "io"
"net/url"
"os"
"path"
"path/filepath"
+
+ "github.com/santhosh-tekuri/jsonschema/v6"
)
-func openSchema(s string) (io.ReadCloser, error) {
+func openSchema(s string) (any, error) {
u, err := url.Parse(s)
if err != nil {
return nil, err
@@ -34,5 +35,10 @@ func openSchema(s string) (io.ReadCloser, error) {
filename = filepath.Join("modules/migration/schemas", basename)
}
}
- return os.Open(filename)
+ f, err := os.Open(filename)
+ if err != nil {
+ return nil, err
+ }
+ defer f.Close()
+ return jsonschema.UnmarshalJSON(f)
}
diff --git a/modules/migration/uploader.go b/modules/migration/uploader.go
index 65752e248e..dd34ffb17a 100644
--- a/modules/migration/uploader.go
+++ b/modules/migration/uploader.go
@@ -14,6 +14,7 @@ type Uploader interface {
CreateMilestones(ctx context.Context, milestones ...*Milestone) error
CreateReleases(ctx context.Context, releases ...*Release) error
SyncTags(ctx context.Context) error
+ SyncBranches(ctx context.Context) error
CreateLabels(ctx context.Context, labels ...*Label) error
CreateIssues(ctx context.Context, issues ...*Issue) error
CreateComments(ctx context.Context, comments ...*Comment) error
diff --git a/modules/nosql/manager.go b/modules/nosql/manager.go
index 375c2b5d00..9d3ab49c9a 100644
--- a/modules/nosql/manager.go
+++ b/modules/nosql/manager.go
@@ -20,7 +20,7 @@ var manager *Manager
// Manager is the nosql connection manager
type Manager struct {
ctx context.Context
- finished context.CancelFunc
+ finished process.FinishedFunc
mutex sync.Mutex
RedisConnections map[string]*redisClientHolder
diff --git a/modules/optional/option.go b/modules/optional/option.go
index cbecf86987..a278723bef 100644
--- a/modules/optional/option.go
+++ b/modules/optional/option.go
@@ -67,3 +67,17 @@ func ParseBool(s string) Option[bool] {
}
return Some(v)
}
+
+func AssignPtrValue[T comparable](changed *bool, target, src *T) {
+ if src != nil && *src != *target {
+ *target = *src
+ *changed = true
+ }
+}
+
+func AssignPtrString[TO, FROM ~string](changed *bool, target *TO, src *FROM) {
+ if src != nil && string(*src) != string(*target) {
+ *target = TO(*src)
+ *changed = true
+ }
+}
diff --git a/modules/optional/serialization.go b/modules/optional/serialization.go
index b120a0edf6..345ce56268 100644
--- a/modules/optional/serialization.go
+++ b/modules/optional/serialization.go
@@ -37,7 +37,7 @@ func (o *Option[T]) UnmarshalYAML(value *yaml.Node) error {
func (o Option[T]) MarshalYAML() (any, error) {
if !o.Has() {
- return nil, nil
+ return nil, nil //nolint:nilnil // return nil to indicate no value to marshal
}
value := new(yaml.Node)
diff --git a/modules/optional/serialization_test.go b/modules/optional/serialization_test.go
index cf81a94cfc..c059294bbb 100644
--- a/modules/optional/serialization_test.go
+++ b/modules/optional/serialization_test.go
@@ -15,12 +15,17 @@ import (
)
type testSerializationStruct struct {
- NormalString string `json:"normal_string" yaml:"normal_string"`
- NormalBool bool `json:"normal_bool" yaml:"normal_bool"`
- OptBool optional.Option[bool] `json:"optional_bool,omitempty" yaml:"optional_bool,omitempty"`
- OptString optional.Option[string] `json:"optional_string,omitempty" yaml:"optional_string,omitempty"`
+ NormalString string `json:"normal_string" yaml:"normal_string"`
+ NormalBool bool `json:"normal_bool" yaml:"normal_bool"`
+ OptBool optional.Option[bool] `json:"optional_bool,omitempty" yaml:"optional_bool,omitempty"`
+
+ // It causes an undefined behavior: should the "omitempty" tag only omit "null", or also the empty string?
+ // The behavior is inconsistent between json and v2 packages, and there is no such use case in Gitea.
+ // If anyone really needs it, they can use json.MarshalKeepOptionalEmpty to revert the v1 behavior
+ OptString optional.Option[string] `json:"optional_string,omitempty" yaml:"optional_string,omitempty"`
+
OptTwoBool optional.Option[bool] `json:"optional_two_bool" yaml:"optional_two_bool"`
- OptTwoString optional.Option[string] `json:"optional_twostring" yaml:"optional_two_string"`
+ OptTwoString optional.Option[string] `json:"optional_two_string" yaml:"optional_two_string"`
}
func TestOptionalToJson(t *testing.T) {
@@ -32,7 +37,7 @@ func TestOptionalToJson(t *testing.T) {
{
name: "empty",
obj: new(testSerializationStruct),
- want: `{"normal_string":"","normal_bool":false,"optional_two_bool":null,"optional_twostring":null}`,
+ want: `{"normal_string":"","normal_bool":false,"optional_two_bool":null,"optional_two_string":null}`,
},
{
name: "some",
@@ -44,12 +49,12 @@ func TestOptionalToJson(t *testing.T) {
OptTwoBool: optional.None[bool](),
OptTwoString: optional.None[string](),
},
- want: `{"normal_string":"a string","normal_bool":true,"optional_bool":false,"optional_string":"","optional_two_bool":null,"optional_twostring":null}`,
+ want: `{"normal_string":"a string","normal_bool":true,"optional_bool":false,"optional_string":"","optional_two_bool":null,"optional_two_string":null}`,
},
}
for _, tc := range tests {
t.Run(tc.name, func(t *testing.T) {
- b, err := json.Marshal(tc.obj)
+ b, err := json.MarshalKeepOptionalEmpty(tc.obj)
assert.NoError(t, err)
assert.Equal(t, tc.want, string(b), "gitea json module returned unexpected")
@@ -75,7 +80,7 @@ func TestOptionalFromJson(t *testing.T) {
},
{
name: "some",
- data: `{"normal_string":"a string","normal_bool":true,"optional_bool":false,"optional_string":"","optional_two_bool":null,"optional_twostring":null}`,
+ data: `{"normal_string":"a string","normal_bool":true,"optional_bool":false,"optional_string":"","optional_two_bool":null,"optional_two_string":null}`,
want: testSerializationStruct{
NormalString: "a string",
NormalBool: true,
@@ -169,7 +174,7 @@ normal_bool: true
optional_bool: false
optional_string: ""
optional_two_bool: null
-optional_twostring: null
+optional_two_string: null
`,
want: testSerializationStruct{
NormalString: "a string",
diff --git a/modules/packages/composer/metadata.go b/modules/packages/composer/metadata.go
index 6035eae8ca..3aac7058aa 100644
--- a/modules/packages/composer/metadata.go
+++ b/modules/packages/composer/metadata.go
@@ -4,8 +4,13 @@
package composer
import (
+ "archive/tar"
"archive/zip"
+ "compress/bzip2"
+ "compress/gzip"
+ "errors"
"io"
+ "io/fs"
"path"
"regexp"
"strings"
@@ -29,8 +34,10 @@ var (
ErrInvalidVersion = util.NewInvalidArgumentErrorf("package version is invalid")
)
-// Package represents a Composer package
-type Package struct {
+// PackageInfo represents Composer package info
+type PackageInfo struct {
+ Filename string
+
Name string
Version string
Type string
@@ -44,7 +51,7 @@ type Metadata struct {
Description string `json:"description,omitempty"`
Readme string `json:"readme,omitempty"`
Keywords []string `json:"keywords,omitempty"`
- Comments Comments `json:"_comments,omitempty"`
+ Comments Comments `json:"_comment,omitempty"`
Homepage string `json:"homepage,omitempty"`
License Licenses `json:"license,omitempty"`
Authors []Author `json:"authors,omitempty"`
@@ -75,7 +82,7 @@ func (l *Licenses) UnmarshalJSON(data []byte) error {
if err := json.Unmarshal(data, &values); err != nil {
return err
}
- *l = Licenses(values)
+ *l = values
}
return nil
}
@@ -97,7 +104,7 @@ func (c *Comments) UnmarshalJSON(data []byte) error {
if err := json.Unmarshal(data, &values); err != nil {
return err
}
- *c = Comments(values)
+ *c = values
}
return nil
}
@@ -111,39 +118,121 @@ type Author struct {
var nameMatch = regexp.MustCompile(`\A[a-z0-9]([_\.-]?[a-z0-9]+)*/[a-z0-9](([_\.]?|-{0,2})[a-z0-9]+)*\z`)
-// ParsePackage parses the metadata of a Composer package file
-func ParsePackage(r io.ReaderAt, size int64) (*Package, error) {
- archive, err := zip.NewReader(r, size)
+type ReadSeekAt interface {
+ io.Reader
+ io.ReaderAt
+ io.Seeker
+ Size() int64
+}
+
+func readPackageFileZip(r ReadSeekAt, filename string, limit int) ([]byte, error) {
+ archive, err := zip.NewReader(r, r.Size())
if err != nil {
return nil, err
}
for _, file := range archive.File {
- if strings.Count(file.Name, "/") > 1 {
- continue
- }
- if strings.HasSuffix(strings.ToLower(file.Name), "composer.json") {
+ filePath := path.Clean(file.Name)
+ if util.AsciiEqualFold(filePath, filename) {
f, err := archive.Open(file.Name)
if err != nil {
return nil, err
}
defer f.Close()
- return ParseComposerFile(archive, path.Dir(file.Name), f)
+ return util.ReadWithLimit(f, limit)
+ }
+ }
+ return nil, fs.ErrNotExist
+}
+
+func readPackageFileTar(r io.Reader, filename string, limit int) ([]byte, error) {
+ tarReader := tar.NewReader(r)
+ for {
+ header, err := tarReader.Next()
+ if err == io.EOF {
+ break
+ } else if err != nil {
+ return nil, err
+ }
+
+ filePath := path.Clean(header.Name)
+ if util.AsciiEqualFold(filePath, filename) {
+ return util.ReadWithLimit(tarReader, limit)
}
}
- return nil, ErrMissingComposerFile
+ return nil, fs.ErrNotExist
}
-// ParseComposerFile parses a composer.json file to retrieve the metadata of a Composer package
-func ParseComposerFile(archive *zip.Reader, pathPrefix string, r io.Reader) (*Package, error) {
+const (
+ pkgExtZip = ".zip"
+ pkgExtTarGz = ".tar.gz"
+ pkgExtTarBz2 = ".tar.bz2"
+)
+
+func detectPackageExtName(r ReadSeekAt) (string, error) {
+ headBytes := make([]byte, 4)
+ _, err := r.ReadAt(headBytes, 0)
+ if err != nil {
+ return "", err
+ }
+ _, err = r.Seek(0, io.SeekStart)
+ if err != nil {
+ return "", err
+ }
+ switch {
+ case headBytes[0] == 'P' && headBytes[1] == 'K':
+ return pkgExtZip, nil
+ case string(headBytes[:3]) == "BZh":
+ return pkgExtTarBz2, nil
+ case headBytes[0] == 0x1f && headBytes[1] == 0x8b:
+ return pkgExtTarGz, nil
+ }
+ return "", util.NewInvalidArgumentErrorf("not a valid package file")
+}
+
+func readPackageFile(pkgExt string, r ReadSeekAt, filename string, limit int) ([]byte, error) {
+ _, err := r.Seek(0, io.SeekStart)
+ if err != nil {
+ return nil, err
+ }
+
+ switch pkgExt {
+ case pkgExtZip:
+ return readPackageFileZip(r, filename, limit)
+ case pkgExtTarBz2:
+ bzip2Reader := bzip2.NewReader(r)
+ return readPackageFileTar(bzip2Reader, filename, limit)
+ case pkgExtTarGz:
+ gzReader, err := gzip.NewReader(r)
+ if err != nil {
+ return nil, err
+ }
+ return readPackageFileTar(gzReader, filename, limit)
+ }
+ return nil, util.NewInvalidArgumentErrorf("not a valid package file")
+}
+
+// ParsePackage parses the metadata of a Composer package file
+func ParsePackage(r ReadSeekAt, optVersion ...string) (*PackageInfo, error) {
+ pkgExt, err := detectPackageExtName(r)
+ if err != nil {
+ return nil, err
+ }
+ dataComposerJSON, err := readPackageFile(pkgExt, r, "composer.json", 10*1024*1024)
+ if errors.Is(err, fs.ErrNotExist) {
+ return nil, ErrMissingComposerFile
+ } else if err != nil {
+ return nil, err
+ }
+
var cj struct {
Name string `json:"name"`
Version string `json:"version"`
Type string `json:"type"`
Metadata
}
- if err := json.NewDecoder(r).Decode(&cj); err != nil {
+ if err := json.Unmarshal(dataComposerJSON, &cj); err != nil {
return nil, err
}
@@ -151,6 +240,9 @@ func ParseComposerFile(archive *zip.Reader, pathPrefix string, r io.Reader) (*Pa
return nil, ErrInvalidName
}
+ if cj.Version == "" {
+ cj.Version = util.OptionalArg(optVersion)
+ }
if cj.Version != "" {
if _, err := version.NewSemver(cj.Version); err != nil {
return nil, ErrInvalidVersion
@@ -168,17 +260,23 @@ func ParseComposerFile(archive *zip.Reader, pathPrefix string, r io.Reader) (*Pa
if cj.Readme == "" {
cj.Readme = "README.md"
}
- f, err := archive.Open(path.Join(pathPrefix, cj.Readme))
- if err == nil {
- // 10kb limit for readme content
- buf, _ := io.ReadAll(io.LimitReader(f, 10*1024))
- cj.Readme = string(buf)
- _ = f.Close()
- } else {
+ dataReadmeMd, _ := readPackageFile(pkgExt, r, cj.Readme, 10*1024)
+
+ // FIXME: legacy problem, the "Readme" field is abused, it should always be the path to the readme file
+ if len(dataReadmeMd) == 0 {
cj.Readme = ""
+ } else {
+ cj.Readme = string(dataReadmeMd)
}
- return &Package{
+ // FIXME: legacy format: strings.ToLower(fmt.Sprintf("%s.%s.zip", strings.ReplaceAll(cp.Name, "/", "-"), cp.Version)), doesn't read good
+ pkgFilename := strings.ReplaceAll(cj.Name, "/", "-")
+ if cj.Version != "" {
+ pkgFilename += "." + cj.Version
+ }
+ pkgFilename += pkgExt
+ return &PackageInfo{
+ Filename: pkgFilename,
Name: cj.Name,
Version: cj.Version,
Type: cj.Type,
diff --git a/modules/packages/composer/metadata_test.go b/modules/packages/composer/metadata_test.go
index a5e317daf1..4eca4d92e7 100644
--- a/modules/packages/composer/metadata_test.go
+++ b/modules/packages/composer/metadata_test.go
@@ -4,14 +4,19 @@
package composer
import (
+ "archive/tar"
"archive/zip"
"bytes"
+ "compress/gzip"
+ "io"
"strings"
"testing"
"code.gitea.io/gitea/modules/json"
+ "github.com/dsnet/compress/bzip2"
"github.com/stretchr/testify/assert"
+ "github.com/stretchr/testify/require"
)
const (
@@ -26,8 +31,10 @@ const (
license = "MIT"
)
-const composerContent = `{
+func buildComposerContent(version string) string {
+ return `{
"name": "` + name + `",
+ "version": "` + version + `",
"description": "` + description + `",
"type": "` + packageType + `",
"license": "` + license + `",
@@ -44,8 +51,9 @@ const composerContent = `{
"require": {
"php": ">=7.2 || ^8.0"
},
- "_comments": "` + comments + `"
+ "_comment": "` + comments + `"
}`
+}
func TestLicenseUnmarshal(t *testing.T) {
var l Licenses
@@ -73,16 +81,34 @@ func TestParsePackage(t *testing.T) {
archive := zip.NewWriter(&buf)
for name, content := range files {
w, _ := archive.Create(name)
- w.Write([]byte(content))
+ _, _ = w.Write([]byte(content))
+ }
+ _ = archive.Close()
+ return buf.Bytes()
+ }
+
+ createArchiveTar := func(comp func(io.Writer) io.WriteCloser, files map[string]string) []byte {
+ var buf bytes.Buffer
+ w := comp(&buf)
+ archive := tar.NewWriter(w)
+ for name, content := range files {
+ hdr := &tar.Header{
+ Name: name,
+ Mode: 0o600,
+ Size: int64(len(content)),
+ }
+ _ = archive.WriteHeader(hdr)
+ _, _ = archive.Write([]byte(content))
}
- archive.Close()
+ _ = w.Close()
+ _ = archive.Close()
return buf.Bytes()
}
t.Run("MissingComposerFile", func(t *testing.T) {
data := createArchive(map[string]string{"dummy.txt": ""})
- cp, err := ParsePackage(bytes.NewReader(data), int64(len(data)))
+ cp, err := ParsePackage(bytes.NewReader(data))
assert.Nil(t, cp)
assert.ErrorIs(t, err, ErrMissingComposerFile)
})
@@ -90,7 +116,7 @@ func TestParsePackage(t *testing.T) {
t.Run("MissingComposerFileInRoot", func(t *testing.T) {
data := createArchive(map[string]string{"sub/sub/composer.json": ""})
- cp, err := ParsePackage(bytes.NewReader(data), int64(len(data)))
+ cp, err := ParsePackage(bytes.NewReader(data))
assert.Nil(t, cp)
assert.ErrorIs(t, err, ErrMissingComposerFile)
})
@@ -98,7 +124,7 @@ func TestParsePackage(t *testing.T) {
t.Run("InvalidComposerFile", func(t *testing.T) {
data := createArchive(map[string]string{"composer.json": ""})
- cp, err := ParsePackage(bytes.NewReader(data), int64(len(data)))
+ cp, err := ParsePackage(bytes.NewReader(data))
assert.Nil(t, cp)
assert.Error(t, err)
})
@@ -106,7 +132,7 @@ func TestParsePackage(t *testing.T) {
t.Run("InvalidPackageName", func(t *testing.T) {
data := createArchive(map[string]string{"composer.json": "{}"})
- cp, err := ParsePackage(bytes.NewReader(data), int64(len(data)))
+ cp, err := ParsePackage(bytes.NewReader(data))
assert.Nil(t, cp)
assert.ErrorIs(t, err, ErrInvalidName)
})
@@ -114,7 +140,7 @@ func TestParsePackage(t *testing.T) {
t.Run("InvalidPackageVersion", func(t *testing.T) {
data := createArchive(map[string]string{"composer.json": `{"name": "gitea/composer-package", "version": "1.a.3"}`})
- cp, err := ParsePackage(bytes.NewReader(data), int64(len(data)))
+ cp, err := ParsePackage(bytes.NewReader(data))
assert.Nil(t, cp)
assert.ErrorIs(t, err, ErrInvalidVersion)
})
@@ -122,22 +148,21 @@ func TestParsePackage(t *testing.T) {
t.Run("InvalidReadmePath", func(t *testing.T) {
data := createArchive(map[string]string{"composer.json": `{"name": "gitea/composer-package", "readme": "sub/README.md"}`})
- cp, err := ParsePackage(bytes.NewReader(data), int64(len(data)))
+ cp, err := ParsePackage(bytes.NewReader(data))
assert.NoError(t, err)
assert.NotNil(t, cp)
assert.Empty(t, cp.Metadata.Readme)
})
- t.Run("Valid", func(t *testing.T) {
- data := createArchive(map[string]string{"composer.json": composerContent, "README.md": readme})
-
- cp, err := ParsePackage(bytes.NewReader(data), int64(len(data)))
- assert.NoError(t, err)
+ assertValidPackage := func(t *testing.T, data []byte, version, filename string) {
+ cp, err := ParsePackage(bytes.NewReader(data))
+ require.NoError(t, err)
assert.NotNil(t, cp)
+ assert.Equal(t, filename, cp.Filename)
assert.Equal(t, name, cp.Name)
- assert.Empty(t, cp.Version)
+ assert.Equal(t, version, cp.Version)
assert.Equal(t, description, cp.Metadata.Description)
assert.Equal(t, readme, cp.Metadata.Readme)
assert.Len(t, cp.Metadata.Comments, 1)
@@ -149,5 +174,25 @@ func TestParsePackage(t *testing.T) {
assert.Equal(t, packageType, cp.Type)
assert.Len(t, cp.Metadata.License, 1)
assert.Equal(t, license, cp.Metadata.License[0])
+ }
+
+ t.Run("ValidZip", func(t *testing.T) {
+ data := createArchive(map[string]string{"composer.json": buildComposerContent(""), "README.md": readme})
+ assertValidPackage(t, data, "", "gitea-composer-package.zip")
+ })
+
+ t.Run("ValidTarBz2", func(t *testing.T) {
+ data := createArchiveTar(func(w io.Writer) io.WriteCloser {
+ bz2Writer, _ := bzip2.NewWriter(w, nil)
+ return bz2Writer
+ }, map[string]string{"composer.json": buildComposerContent("1.0"), "README.md": readme})
+ assertValidPackage(t, data, "1.0", "gitea-composer-package.1.0.tar.bz2")
+ })
+
+ t.Run("ValidTarGz", func(t *testing.T) {
+ data := createArchiveTar(func(w io.Writer) io.WriteCloser {
+ return gzip.NewWriter(w)
+ }, map[string]string{"composer.json": buildComposerContent(""), "README.md": readme})
+ assertValidPackage(t, data, "", "gitea-composer-package.tar.gz")
})
}
diff --git a/modules/packages/container/metadata.go b/modules/packages/container/metadata.go
index 3ef0684d13..d8a48120af 100644
--- a/modules/packages/container/metadata.go
+++ b/modules/packages/container/metadata.go
@@ -103,7 +103,9 @@ func ParseImageConfig(mediaType string, r io.Reader) (*Metadata, error) {
func parseOCIImageConfig(r io.Reader) (*Metadata, error) {
var image oci.Image
- if err := json.NewDecoder(r).Decode(&image); err != nil {
+ // FIXME: JSON-KEY-CASE: here seems a abuse of the case-insensitive decoding feature, spec is case-sensitive
+ // https://github.com/opencontainers/image-spec/blob/main/schema/config-schema.json
+ if err := json.NewDecoderCaseInsensitive(r).Decode(&image); err != nil {
return nil, err
}
diff --git a/modules/packages/container/metadata_test.go b/modules/packages/container/metadata_test.go
index 0f2d702925..2a6389a8f6 100644
--- a/modules/packages/container/metadata_test.go
+++ b/modules/packages/container/metadata_test.go
@@ -22,6 +22,8 @@ func TestParseImageConfig(t *testing.T) {
repositoryURL := "https://gitea.com/gitea"
documentationURL := "https://docs.gitea.com"
+ // FIXME: JSON-KEY-CASE: the test case is not right, the config fields are capitalized in the spec
+ // https://github.com/opencontainers/image-spec/blob/main/schema/config-schema.json
configOCI := `{"config": {"labels": {"` + labelAuthors + `": "` + author + `", "` + labelLicenses + `": "` + license + `", "` + labelURL + `": "` + projectURL + `", "` + labelSource + `": "` + repositoryURL + `", "` + labelDocumentation + `": "` + documentationURL + `", "` + labelDescription + `": "` + description + `"}}, "history": [{"created_by": "do it 1"}, {"created_by": "dummy #(nop) do it 2"}]}`
metadata, err := ParseImageConfig(oci.MediaTypeImageManifest, strings.NewReader(configOCI))
diff --git a/modules/packages/content_store.go b/modules/packages/content_store.go
index 57974515e2..4c61233b5e 100644
--- a/modules/packages/content_store.go
+++ b/modules/packages/content_store.go
@@ -36,8 +36,8 @@ func (s *ContentStore) ShouldServeDirect() bool {
return setting.Packages.Storage.ServeDirect()
}
-func (s *ContentStore) GetServeDirectURL(key BlobHash256Key, filename, method string, reqParams url.Values) (*url.URL, error) {
- return s.store.URL(KeyToRelativePath(key), filename, method, reqParams)
+func (s *ContentStore) GetServeDirectURL(key BlobHash256Key, filename, method string, reqParams *storage.ServeDirectOptions) (*url.URL, error) {
+ return s.store.ServeDirectURL(KeyToRelativePath(key), filename, method, reqParams)
}
// FIXME: Workaround to be removed in v1.20
diff --git a/modules/packages/cran/metadata.go b/modules/packages/cran/metadata.go
index 0b0bfb07c6..0856565e10 100644
--- a/modules/packages/cran/metadata.go
+++ b/modules/packages/cran/metadata.go
@@ -34,7 +34,7 @@ var (
var (
fieldPattern = regexp.MustCompile(`\A\S+:`)
namePattern = regexp.MustCompile(`\A[a-zA-Z][a-zA-Z0-9\.]*[a-zA-Z0-9]\z`)
- versionPattern = regexp.MustCompile(`\A[0-9]+(?:[.\-][0-9]+){1,3}\z`)
+ versionPattern = regexp.MustCompile(`\A[0-9]+(?:[.\-][0-9]+)+\z`)
authorReplacePattern = regexp.MustCompile(`[\[\(].+?[\]\)]`)
)
diff --git a/modules/packages/cran/metadata_test.go b/modules/packages/cran/metadata_test.go
index ff68c34c51..1d652a4a05 100644
--- a/modules/packages/cran/metadata_test.go
+++ b/modules/packages/cran/metadata_test.go
@@ -128,13 +128,22 @@ func TestParseDescription(t *testing.T) {
})
t.Run("InvalidVersion", func(t *testing.T) {
- for _, version := range []string{"1", "1 0", "1.2.3.4.5", "1-2-3-4-5", "1.", "1.0.", "1-", "1-0-"} {
+ for _, version := range []string{"1", "1 0", "1.", "1.0.", "1-", "1-0-"} {
p, err := ParseDescription(createDescription(packageName, version))
assert.Nil(t, p)
assert.ErrorIs(t, err, ErrInvalidVersion)
}
})
+ t.Run("ValidVersionManyComponents", func(t *testing.T) {
+ for _, version := range []string{"0.3.4.0.2", "1.2.3.4.5", "1-2-3-4-5"} {
+ p, err := ParseDescription(createDescription(packageName, version))
+ assert.NoError(t, err)
+ assert.NotNil(t, p)
+ assert.Equal(t, version, p.Version)
+ }
+ })
+
t.Run("Valid", func(t *testing.T) {
p, err := ParseDescription(createDescription(packageName, packageVersion))
assert.NoError(t, err)
diff --git a/modules/packages/nuget/metadata.go b/modules/packages/nuget/metadata.go
index 5124627395..ae15e4ec83 100644
--- a/modules/packages/nuget/metadata.go
+++ b/modules/packages/nuget/metadata.go
@@ -140,7 +140,7 @@ type nuspecPackage struct {
func ParsePackageMetaData(r io.ReaderAt, size int64) (*Package, error) {
archive, err := zip.NewReader(r, size)
if err != nil {
- return nil, err
+ return nil, util.NewInvalidArgumentErrorf("unable to parse package meta: %v", err)
}
for _, file := range archive.File {
diff --git a/modules/packages/nuget/symbol_extractor.go b/modules/packages/nuget/symbol_extractor.go
index 9c952e1f10..5e398151e8 100644
--- a/modules/packages/nuget/symbol_extractor.go
+++ b/modules/packages/nuget/symbol_extractor.go
@@ -42,7 +42,7 @@ func (l PortablePdbList) Close() {
func ExtractPortablePdb(r io.ReaderAt, size int64) (PortablePdbList, error) {
archive, err := zip.NewReader(r, size)
if err != nil {
- return nil, err
+ return nil, util.NewInvalidArgumentErrorf("unable to extract portable pdb: %v", err)
}
var pdbs PortablePdbList
@@ -142,8 +142,8 @@ func ParseDebugHeaderID(r io.ReadSeeker) (string, error) {
if _, err := r.Read(b); err != nil {
return "", err
}
- if i := bytes.IndexByte(b, 0); i != -1 {
- buf.Write(b[:i])
+ if before, _, ok := bytes.Cut(b, []byte{0}); ok {
+ buf.Write(before)
return buf.String(), nil
}
buf.Write(b)
diff --git a/modules/packages/rpm/metadata.go b/modules/packages/rpm/metadata.go
index f4f78c2cab..d8ac7ea75f 100644
--- a/modules/packages/rpm/metadata.go
+++ b/modules/packages/rpm/metadata.go
@@ -46,10 +46,11 @@ type Package struct {
}
type VersionMetadata struct {
- License string `json:"license,omitempty"`
- ProjectURL string `json:"project_url,omitempty"`
- Summary string `json:"summary,omitempty"`
- Description string `json:"description,omitempty"`
+ License string `json:"license,omitempty"`
+ ProjectURL string `json:"project_url,omitempty"`
+ Summary string `json:"summary,omitempty"`
+ Description string `json:"description,omitempty"`
+ Updates []*Update `json:"updates,omitempty"`
}
type FileMetadata struct {
@@ -296,3 +297,43 @@ func getChangelogs(h *rpmutils.RpmHeader) []*Changelog {
}
return changelogs
}
+
+type DateAttr struct {
+ Date string `xml:"date,attr" json:"date"`
+}
+
+type Update struct {
+ From string `xml:"from,attr" json:"from"`
+ Status string `xml:"status,attr" json:"status"`
+ Type string `xml:"type,attr" json:"type"`
+ Version string `xml:"version,attr" json:"version"`
+ ID string `xml:"id" json:"id"`
+ Title string `xml:"title" json:"title"`
+ Severity string `xml:"severity" json:"severity"`
+ Description string `xml:"description" json:"description"`
+ Issued *DateAttr `xml:"issued" json:"issued"`
+ Updated *DateAttr `xml:"updated" json:"updated"`
+ References []*Reference `xml:"references>reference" json:"references"`
+ PkgList []*Collection `xml:"pkglist>collection" json:"pkg_list"`
+}
+
+type Reference struct {
+ Href string `xml:"href,attr" json:"href"`
+ ID string `xml:"id,attr" json:"id"`
+ Title string `xml:"title,attr" json:"title"`
+ Type string `xml:"type,attr" json:"type"`
+}
+
+type Collection struct {
+ Short string `xml:"short,attr" json:"short"`
+ Packages []*UpdatePackage `xml:"package" json:"packages"`
+}
+
+type UpdatePackage struct {
+ Arch string `xml:"arch,attr" json:"arch"`
+ Name string `xml:"name,attr" json:"name"`
+ Release string `xml:"release,attr" json:"release"`
+ Src string `xml:"src,attr" json:"src"`
+ Version string `xml:"version,attr" json:"version"`
+ Filename string `xml:"filename" json:"filename"`
+}
diff --git a/modules/packages/rubygems/metadata.go b/modules/packages/rubygems/metadata.go
index 8a9794860e..5c01abc743 100644
--- a/modules/packages/rubygems/metadata.go
+++ b/modules/packages/rubygems/metadata.go
@@ -9,6 +9,7 @@ import (
"io"
"regexp"
"strings"
+ "sync"
"code.gitea.io/gitea/modules/util"
"code.gitea.io/gitea/modules/validation"
@@ -25,7 +26,9 @@ var (
ErrInvalidVersion = util.NewInvalidArgumentErrorf("package version is invalid")
)
-var versionMatcher = regexp.MustCompile(`\A[0-9]+(?:\.[0-9a-zA-Z]+)*(?:-[0-9A-Za-z-]+(?:\.[0-9A-Za-z-]+)*)?\z`)
+var versionMatcher = sync.OnceValue(func() *regexp.Regexp {
+ return regexp.MustCompile(`\A[0-9]+(?:\.[0-9a-zA-Z]+)*(?:-[0-9A-Za-z-]+(?:\.[0-9A-Za-z-]+)*)?\z`)
+})
// Package represents a RubyGems package
type Package struct {
@@ -128,7 +131,7 @@ func (r requirement) AsVersionRequirement() []VersionRequirement {
continue
}
version, ok := versionInt.(string)
- if !ok || version == "0" {
+ if !ok || (version == "0" && restriction == ">=") {
continue
}
@@ -176,7 +179,7 @@ func parseMetadataFile(r io.Reader) (*Package, error) {
return nil, ErrInvalidName
}
- if !versionMatcher.MatchString(spec.Version.Version) {
+ if !versionMatcher().MatchString(spec.Version.Version) {
return nil, ErrInvalidVersion
}
diff --git a/modules/packages/rubygems/metadata_test.go b/modules/packages/rubygems/metadata_test.go
index ec2fa08b6b..9a98c06653 100644
--- a/modules/packages/rubygems/metadata_test.go
+++ b/modules/packages/rubygems/metadata_test.go
@@ -4,42 +4,30 @@
package rubygems
import (
- "archive/tar"
- "bytes"
- "encoding/base64"
- "io"
"testing"
+ "code.gitea.io/gitea/modules/test"
+
"github.com/stretchr/testify/assert"
)
func TestParsePackageMetaData(t *testing.T) {
- createArchive := func(filename string, content []byte) io.Reader {
- var buf bytes.Buffer
- tw := tar.NewWriter(&buf)
- hdr := &tar.Header{
- Name: filename,
- Mode: 0o600,
- Size: int64(len(content)),
- }
- tw.WriteHeader(hdr)
- tw.Write(content)
- tw.Close()
- return &buf
- }
-
t.Run("MissingMetadataFile", func(t *testing.T) {
- data := createArchive("dummy.txt", []byte{0})
-
+ data := test.WriteTarArchive(map[string]string{"dummy.txt": ""})
rp, err := ParsePackageMetaData(data)
assert.ErrorIs(t, err, ErrMissingMetadataFile)
assert.Nil(t, rp)
})
t.Run("Valid", func(t *testing.T) {
- content, _ := base64.StdEncoding.DecodeString("H4sICHC/I2EEAG1ldGFkYXRhAAEeAOH/bmFtZTogZwp2ZXJzaW9uOgogIHZlcnNpb246IDEKWw35Tx4AAAA=")
- data := createArchive("metadata.gz", content)
-
+ metadataContent := test.CompressGzip(`
+name: g
+version:
+ version: 1
+`)
+ data := test.WriteTarArchive(map[string]string{
+ "metadata.gz": metadataContent.String(),
+ })
rp, err := ParsePackageMetaData(data)
assert.NoError(t, err)
assert.NotNil(t, rp)
@@ -47,17 +35,86 @@ func TestParsePackageMetaData(t *testing.T) {
}
func TestParseMetadataFile(t *testing.T) {
- content, _ := base64.StdEncoding.DecodeString(`H4sIAMe7I2ECA9VVTW/UMBC9+1eYXvaUbJpSQBZUHJAqDlwK4kCFIseZzZrGH9iTqisEv52Js9nd
-0KqggiqRXWnX45n3ZuZ5nCzL+JPQ15ulq7+AQnEORoj3HpReaSVRO8usNCB4qxEku4YQySbuCPo4
-bjHOd07HeZGfMt9JXLlgBB9imOxx7UIULOPnCZMMLsDXXgeiYbW2jQ6C0y9TELBSa6kJ6/IzaySS
-R1mUx1nxIitPeFGI9M2L6eGfWAMebANWaUgktzN9M3lsKNmxutBb1AYyCibbNhsDFu+q9GK/Tc4z
-d2IcLBl9js5eHaXFsLyvXeNz0LQyL/YoLx8EsiCMBZlx46k6sS2PDD5AgA5kJPNKdhH2elWzOv7n
-uv9Q9Aau/6ngP84elvNpXh5oRVlB5/yW7BH0+qu0G4gqaI/JdEHBFBS5l+pKtsARIjIwUnfj8Le0
-+TrdJLl2DG5A9SjrjgZ1mG+4QbAD+G4ZZBUap6qVnnzGf6Rwp+vliBRqtnYGPBEKvkb0USyXE8mS
-dVoR6hj07u0HZgAl3SRS8G/fmXcRK20jyq6rDMSYQFgidamqkXbbuspLXE/0k7GphtKqe67GuRC/
-yjAbmt9LsOMp8xMamFkSQ38fP5EFjdz8LA4do2C69VvqWXAJgrPbKZb58/xZXrKoW6ttW13Bhvzi
-4ftn7/yUxd4YGcglvTmmY8aGY3ZwRn4CqcWcidUGAAA=`)
- rp, err := parseMetadataFile(bytes.NewReader(content))
+ content := test.CompressGzip(`--- !ruby/object:Gem::Specification
+name: gitea
+version: !ruby/object:Gem::Version
+ version: 1.0.5
+platform: ruby
+authors:
+- Gitea
+autorequire:
+bindir: bin
+cert_chain: []
+date: 2021-08-23 00:00:00.000000000 Z
+dependencies:
+- !ruby/object:Gem::Dependency
+ name: runtime-dep
+ requirement: !ruby/object:Gem::Requirement
+ requirements:
+ - - ">="
+ - !ruby/object:Gem::Version
+ version: 1.2.0
+ - - "<"
+ - !ruby/object:Gem::Version
+ version: '2.0'
+ type: :runtime
+ prerelease: false
+ version_requirements: !ruby/object:Gem::Requirement
+ requirements:
+ - - ">="
+ - !ruby/object:Gem::Version
+ version: 1.2.0
+ - - "<"
+ - !ruby/object:Gem::Version
+ version: '2.0'
+- !ruby/object:Gem::Dependency
+ name: dev-dep
+ requirement: !ruby/object:Gem::Requirement
+ requirements:
+ - - "~>"
+ - !ruby/object:Gem::Version
+ version: '0'
+ type: :development
+ prerelease: false
+ version_requirements: !ruby/object:Gem::Requirement
+ requirements:
+ - - "~>"
+ - !ruby/object:Gem::Version
+ version: '5.2'
+description: RubyGems package test
+email: rubygems@gitea.io
+executables: []
+extensions: []
+extra_rdoc_files: []
+files:
+- lib/gitea.rb
+homepage: https://gitea.io/
+licenses:
+- MIT
+metadata: {}
+post_install_message:
+rdoc_options: []
+require_paths:
+- lib
+required_ruby_version: !ruby/object:Gem::Requirement
+ requirements:
+ - - ">="
+ - !ruby/object:Gem::Version
+ version: 2.3.0
+required_rubygems_version: !ruby/object:Gem::Requirement
+ requirements:
+ - - ">="
+ - !ruby/object:Gem::Version
+ version: '0'
+requirements: []
+rubyforge_project:
+rubygems_version: 2.7.6.2
+signing_key:
+specification_version: 4
+summary: Gitea package
+test_files: []
+`)
+ rp, err := parseMetadataFile(content)
assert.NoError(t, err)
assert.NotNil(t, rp)
@@ -84,5 +141,5 @@ yjAbmt9LsOMp8xMamFkSQ38fP5EFjdz8LA4do2C69VvqWXAJgrPbKZb58/xZXrKoW6ttW13Bhvzi
assert.Equal(t, "dev-dep", rp.Metadata.DevelopmentDependencies[0].Name)
assert.Len(t, rp.Metadata.DevelopmentDependencies[0].Version, 1)
assert.Equal(t, "~>", rp.Metadata.DevelopmentDependencies[0].Version[0].Restriction)
- assert.Equal(t, "5.2", rp.Metadata.DevelopmentDependencies[0].Version[0].Version)
+ assert.Equal(t, "0", rp.Metadata.DevelopmentDependencies[0].Version[0].Version)
}
diff --git a/modules/packages/swift/metadata.go b/modules/packages/swift/metadata.go
index 78925c6e6d..d0137f8dfe 100644
--- a/modules/packages/swift/metadata.go
+++ b/modules/packages/swift/metadata.go
@@ -47,6 +47,7 @@ type Metadata struct {
Keywords []string `json:"keywords,omitempty"`
RepositoryURL string `json:"repository_url,omitempty"`
License string `json:"license,omitempty"`
+ LicenseURL string `json:"license_url,omitempty"`
Author Person `json:"author"`
Manifests map[string]*Manifest `json:"manifests,omitempty"`
}
@@ -67,7 +68,8 @@ type SoftwareSourceCode struct {
Keywords []string `json:"keywords,omitempty"`
CodeRepository string `json:"codeRepository,omitempty"`
License string `json:"license,omitempty"`
- Author Person `json:"author"`
+ LicenseURL string `json:"licenseURL,omitempty"`
+ Author *Person `json:"author,omitempty"`
ProgrammingLanguage ProgrammingLanguage `json:"programmingLanguage"`
RepositoryURLs []string `json:"repositoryURLs,omitempty"`
}
@@ -181,26 +183,31 @@ func ParsePackage(sr io.ReaderAt, size int64, mr io.Reader) (*Package, error) {
if err := json.NewDecoder(mr).Decode(&ssc); err != nil {
return nil, err
}
-
p.Metadata.Description = ssc.Description
p.Metadata.Keywords = ssc.Keywords
p.Metadata.License = ssc.License
- author := Person{
- Name: ssc.Author.Name,
- GivenName: ssc.Author.GivenName,
- MiddleName: ssc.Author.MiddleName,
- FamilyName: ssc.Author.FamilyName,
- }
- // If Name is not provided, generate it from individual name components
- if author.Name == "" {
- author.Name = author.String()
+ p.Metadata.LicenseURL = ssc.LicenseURL
+ if ssc.Author != nil {
+ author := Person{
+ Name: ssc.Author.Name,
+ GivenName: ssc.Author.GivenName,
+ MiddleName: ssc.Author.MiddleName,
+ FamilyName: ssc.Author.FamilyName,
+ }
+ // If Name is not provided, generate it from individual name components
+ if author.Name == "" {
+ author.Name = author.String()
+ }
+ p.Metadata.Author = author
}
- p.Metadata.Author = author
p.Metadata.RepositoryURL = ssc.CodeRepository
if !validation.IsValidURL(p.Metadata.RepositoryURL) {
p.Metadata.RepositoryURL = ""
}
+ if !validation.IsValidURL(p.Metadata.LicenseURL) {
+ p.Metadata.LicenseURL = ""
+ }
p.RepositoryURLs = ssc.RepositoryURLs
}
diff --git a/modules/packages/swift/metadata_test.go b/modules/packages/swift/metadata_test.go
index 461773cbfc..440bcb9fac 100644
--- a/modules/packages/swift/metadata_test.go
+++ b/modules/packages/swift/metadata_test.go
@@ -4,11 +4,12 @@
package swift
import (
- "archive/zip"
"bytes"
"strings"
"testing"
+ "code.gitea.io/gitea/modules/test"
+
"github.com/hashicorp/go-version"
"github.com/stretchr/testify/assert"
)
@@ -18,36 +19,24 @@ const (
packageVersion = "1.0.1"
packageDescription = "Package Description"
packageRepositoryURL = "https://gitea.io/gitea/gitea"
+ packageLicenseURL = "https://opensource.org/license/mit"
packageAuthor = "KN4CK3R"
packageLicense = "MIT"
)
func TestParsePackage(t *testing.T) {
- createArchive := func(files map[string][]byte) *bytes.Reader {
- var buf bytes.Buffer
- zw := zip.NewWriter(&buf)
- for filename, content := range files {
- w, _ := zw.Create(filename)
- w.Write(content)
- }
- zw.Close()
- return bytes.NewReader(buf.Bytes())
- }
-
t.Run("MissingManifestFile", func(t *testing.T) {
- data := createArchive(map[string][]byte{"dummy.txt": {}})
-
- p, err := ParsePackage(data, data.Size(), nil)
+ data := test.WriteZipArchive(map[string]string{"dummy.txt": ""})
+ p, err := ParsePackage(bytes.NewReader(data.Bytes()), int64(data.Len()), nil)
assert.Nil(t, p)
assert.ErrorIs(t, err, ErrMissingManifestFile)
})
t.Run("ManifestFileTooLarge", func(t *testing.T) {
- data := createArchive(map[string][]byte{
- "Package.swift": make([]byte, maxManifestFileSize+1),
+ data := test.WriteZipArchive(map[string]string{
+ "Package.swift": strings.Repeat("a", maxManifestFileSize+1),
})
-
- p, err := ParsePackage(data, data.Size(), nil)
+ p, err := ParsePackage(bytes.NewReader(data.Bytes()), int64(data.Len()), nil)
assert.Nil(t, p)
assert.ErrorIs(t, err, ErrManifestFileTooLarge)
})
@@ -56,12 +45,12 @@ func TestParsePackage(t *testing.T) {
content1 := "// swift-tools-version:5.7\n//\n// Package.swift"
content2 := "// swift-tools-version:5.6\n//\n// Package@swift-5.6.swift"
- data := createArchive(map[string][]byte{
- "Package.swift": []byte(content1),
- "Package@swift-5.5.swift": []byte(content2),
+ data := test.WriteZipArchive(map[string]string{
+ "Package.swift": content1,
+ "Package@swift-5.5.swift": content2,
})
- p, err := ParsePackage(data, data.Size(), nil)
+ p, err := ParsePackage(bytes.NewReader(data.Bytes()), int64(data.Len()), nil)
assert.NotNil(t, p)
assert.NoError(t, err)
@@ -77,14 +66,13 @@ func TestParsePackage(t *testing.T) {
})
t.Run("WithMetadata", func(t *testing.T) {
- data := createArchive(map[string][]byte{
- "Package.swift": []byte("// swift-tools-version:5.7\n//\n// Package.swift"),
+ data := test.WriteZipArchive(map[string]string{
+ "Package.swift": "// swift-tools-version:5.7\n//\n// Package.swift",
})
p, err := ParsePackage(
- data,
- data.Size(),
- strings.NewReader(`{"name":"`+packageName+`","version":"`+packageVersion+`","description":"`+packageDescription+`","keywords":["swift","package"],"license":"`+packageLicense+`","codeRepository":"`+packageRepositoryURL+`","author":{"givenName":"`+packageAuthor+`"},"repositoryURLs":["`+packageRepositoryURL+`"]}`),
+ bytes.NewReader(data.Bytes()), int64(data.Len()),
+ strings.NewReader(`{"name":"`+packageName+`","version":"`+packageVersion+`","description":"`+packageDescription+`","keywords":["swift","package"],"license":"`+packageLicense+`","licenseURL":"`+packageLicenseURL+`","codeRepository":"`+packageRepositoryURL+`","author":{"givenName":"`+packageAuthor+`"},"repositoryURLs":["`+packageRepositoryURL+`"]}`),
)
assert.NotNil(t, p)
assert.NoError(t, err)
@@ -97,6 +85,7 @@ func TestParsePackage(t *testing.T) {
assert.Equal(t, packageDescription, p.Metadata.Description)
assert.ElementsMatch(t, []string{"swift", "package"}, p.Metadata.Keywords)
assert.Equal(t, packageLicense, p.Metadata.License)
+ assert.Equal(t, packageLicenseURL, p.Metadata.LicenseURL)
assert.Equal(t, packageAuthor, p.Metadata.Author.Name)
assert.Equal(t, packageAuthor, p.Metadata.Author.GivenName)
assert.Equal(t, packageRepositoryURL, p.Metadata.RepositoryURL)
@@ -104,14 +93,13 @@ func TestParsePackage(t *testing.T) {
})
t.Run("WithExplicitNameField", func(t *testing.T) {
- data := createArchive(map[string][]byte{
- "Package.swift": []byte("// swift-tools-version:5.7\n//\n// Package.swift"),
+ data := test.WriteZipArchive(map[string]string{
+ "Package.swift": "// swift-tools-version:5.7\n//\n// Package.swift",
})
authorName := "John Doe"
p, err := ParsePackage(
- data,
- data.Size(),
+ bytes.NewReader(data.Bytes()), int64(data.Len()),
strings.NewReader(`{"name":"`+packageName+`","version":"`+packageVersion+`","description":"`+packageDescription+`","author":{"name":"`+authorName+`","givenName":"John","familyName":"Doe"}}`),
)
assert.NotNil(t, p)
@@ -122,15 +110,30 @@ func TestParsePackage(t *testing.T) {
assert.Equal(t, "Doe", p.Metadata.Author.FamilyName)
})
+ t.Run("WithEmptyJSONMetadata", func(t *testing.T) {
+ data := test.WriteZipArchive(map[string]string{
+ "Package.swift": "// swift-tools-version:5.7\n//\n// Package.swift",
+ })
+
+ p, err := ParsePackage(
+ bytes.NewReader(data.Bytes()), int64(data.Len()),
+ strings.NewReader(`{}`),
+ )
+ assert.NotNil(t, p)
+ assert.NoError(t, err)
+ assert.NotNil(t, p.Metadata)
+ assert.Empty(t, p.Metadata.Author.Name)
+ assert.Empty(t, p.RepositoryURLs)
+ })
+
t.Run("NameFieldGeneration", func(t *testing.T) {
- data := createArchive(map[string][]byte{
- "Package.swift": []byte("// swift-tools-version:5.7\n//\n// Package.swift"),
+ data := test.WriteZipArchive(map[string]string{
+ "Package.swift": "// swift-tools-version:5.7\n//\n// Package.swift",
})
// Test with only individual name components - Name should be auto-generated
p, err := ParsePackage(
- data,
- data.Size(),
+ bytes.NewReader(data.Bytes()), int64(data.Len()),
strings.NewReader(`{"author":{"givenName":"John","middleName":"Q","familyName":"Doe"}}`),
)
assert.NotNil(t, p)
diff --git a/modules/packages/terraform/lock.go b/modules/packages/terraform/lock.go
new file mode 100644
index 0000000000..3c326c04e9
--- /dev/null
+++ b/modules/packages/terraform/lock.go
@@ -0,0 +1,100 @@
+// Copyright 2026 The Gitea Authors. All rights reserved.
+// SPDX-License-Identifier: MIT
+
+package terraform
+
+import (
+ "context"
+ "errors"
+ "io"
+ "time"
+
+ "code.gitea.io/gitea/models/db"
+ packages_model "code.gitea.io/gitea/models/packages"
+ "code.gitea.io/gitea/modules/json"
+ "code.gitea.io/gitea/modules/util"
+
+ "xorm.io/builder"
+)
+
+const LockFile = "terraform.lock"
+
+// LockInfo is the metadata for a terraform lock.
+type LockInfo struct {
+ ID string `json:"ID"`
+ Operation string `json:"Operation"`
+ Info string `json:"Info"`
+ Who string `json:"Who"`
+ Version string `json:"Version"`
+ Created time.Time `json:"Created"`
+ Path string `json:"Path"`
+}
+
+func (l *LockInfo) IsLocked() bool {
+ return l.ID != ""
+}
+
+func ParseLockInfo(r io.Reader) (*LockInfo, error) {
+ var lock LockInfo
+ err := json.NewDecoder(r).Decode(&lock)
+ if err != nil {
+ return nil, err
+ }
+ // ID is required. Rest is less important.
+ if lock.ID == "" {
+ return nil, util.NewInvalidArgumentErrorf("terraform lock is missing an ID")
+ }
+ return &lock, nil
+}
+
+// GetLock returns the terraform lock for the given package.
+// Lock is empty if no lock exists.
+func GetLock(ctx context.Context, packageID int64) (LockInfo, error) {
+ var lock LockInfo
+ locks, err := packages_model.GetPropertiesByName(ctx, packages_model.PropertyTypePackage, packageID, LockFile)
+ if err != nil {
+ return lock, err
+ }
+ if len(locks) == 0 || locks[0].Value == "" {
+ return lock, nil
+ }
+
+ err = json.Unmarshal([]byte(locks[0].Value), &lock)
+ return lock, err
+}
+
+// SetLock sets the terraform lock for the given package.
+func SetLock(ctx context.Context, packageID int64, lock *LockInfo) error {
+ jsonBytes, err := json.Marshal(lock)
+ if err != nil {
+ return err
+ }
+
+ return updateLock(ctx, packageID, string(jsonBytes), builder.Eq{"value": ""})
+}
+
+// RemoveLock removes the terraform lock for the given package.
+func RemoveLock(ctx context.Context, packageID int64) error {
+ return updateLock(ctx, packageID, "", builder.Neq{"value": ""})
+}
+
+func updateLock(ctx context.Context, refID int64, value string, cond builder.Cond) error {
+ pp := packages_model.PackageProperty{RefType: packages_model.PropertyTypePackage, RefID: refID, Name: LockFile}
+ ok, err := db.GetEngine(ctx).Get(&pp)
+ if err != nil {
+ return err
+ }
+ if ok {
+ n, err := db.GetEngine(ctx).Where("ref_type=? AND ref_id=? AND name=?", packages_model.PropertyTypePackage, refID, LockFile).And(cond).Cols("value").Update(&packages_model.PackageProperty{Value: value})
+ if err != nil {
+ return err
+ }
+ if n == 0 {
+ return errors.New("failed to update lock state")
+ }
+
+ return nil
+ }
+ _, err = packages_model.InsertProperty(ctx, packages_model.PropertyTypePackage, refID, LockFile, value)
+ return err
+}
diff --git a/modules/packages/terraform/state.go b/modules/packages/terraform/state.go
new file mode 100644
index 0000000000..5763128699
--- /dev/null
+++ b/modules/packages/terraform/state.go
@@ -0,0 +1,38 @@
+// Copyright 2026 The Gitea Authors. All rights reserved.
+// SPDX-License-Identifier: MIT
+
+package terraform
+
+import (
+ "io"
+
+ "code.gitea.io/gitea/modules/json"
+ "code.gitea.io/gitea/modules/util"
+)
+
+// Note: this is a subset of the Terraform state file format as the full one has two forms.
+// If needed, it can be expanded in the future.
+
+type State struct {
+ Serial uint64 `json:"serial"`
+ Lineage string `json:"lineage"`
+}
+
+// ParseState parses the required parts of Terraform state file
+func ParseState(r io.Reader) (*State, error) {
+ var state State
+ err := json.NewDecoder(r).Decode(&state)
+ if err != nil {
+ return nil, err
+ }
+ // Serial starts at 1; 0 means it wasn't set in the state file
+ if state.Serial == 0 {
+ return nil, util.NewInvalidArgumentErrorf("state serial is missing")
+ }
+ // Lineage should always be set
+ if state.Lineage == "" {
+ return nil, util.NewInvalidArgumentErrorf("state lineage is missing")
+ }
+
+ return &state, nil
+}
diff --git a/modules/private/hook.go b/modules/private/hook.go
index 215996b9b9..ce87ccd801 100644
--- a/modules/private/hook.go
+++ b/modules/private/hook.go
@@ -37,7 +37,7 @@ type HookOptions struct {
PushTrigger repository.PushTrigger
DeployKeyID int64 // if the pusher is a DeployKey, then UserID is the repo's org user.
IsWiki bool
- ActionPerm int
+ ActionsTaskID int64 // if the pusher is an Actions user, the task ID
}
// SSHLogOption ssh log options
diff --git a/modules/process/manager.go b/modules/process/manager.go
index 661511ce8d..c51d6c76f9 100644
--- a/modules/process/manager.go
+++ b/modules/process/manager.go
@@ -13,6 +13,7 @@ import (
"time"
"code.gitea.io/gitea/modules/gtprof"
+ "code.gitea.io/gitea/modules/util"
)
// TODO: This packages still uses a singleton for the Manager.
@@ -27,12 +28,14 @@ var (
DefaultContext = context.Background()
)
-// IDType is a pid type
-type IDType string
+type (
+ // IDType is a pid type
+ IDType string
-// FinishedFunc is a function that marks that the process is finished and can be removed from the process table
-// - it is simply an alias for context.CancelFunc and is only for documentary purposes
-type FinishedFunc = context.CancelFunc
+ CancelCauseFunc func(cause ...error)
+ // FinishedFunc is a function that marks that the process is finished and can be removed from the process table
+ FinishedFunc func()
+)
var (
traceDisabled atomic.Int64
@@ -84,6 +87,10 @@ func GetManager() *Manager {
return manager
}
+func cancelCauseFunc(cancelCause context.CancelCauseFunc) CancelCauseFunc {
+ return func(cause ...error) { cancelCause(util.OptionalArg(cause)) }
+}
+
// AddContext creates a new context and adds it as a process. Once the process is finished, finished must be called
// to remove the process from the process table. It should not be called until the process is finished but must always be called.
//
@@ -92,11 +99,10 @@ func GetManager() *Manager {
//
// Most processes will not need to use the cancel function but there will be cases whereby you want to cancel the process but not immediately remove it from the
// process table.
-func (pm *Manager) AddContext(parent context.Context, description string) (ctx context.Context, cancel context.CancelFunc, finished FinishedFunc) {
- ctx, cancel = context.WithCancel(parent)
-
- ctx, _, finished = pm.Add(ctx, description, cancel, NormalProcessType, true)
-
+func (pm *Manager) AddContext(parent context.Context, description string) (context.Context, CancelCauseFunc, FinishedFunc) {
+ ctx, ctxCancel := context.WithCancelCause(parent)
+ cancel := cancelCauseFunc(ctxCancel)
+ ctx, _, finished := pm.Add(ctx, description, cancel, NormalProcessType, true)
return ctx, cancel, finished
}
@@ -108,11 +114,10 @@ func (pm *Manager) AddContext(parent context.Context, description string) (ctx c
//
// Most processes will not need to use the cancel function but there will be cases whereby you want to cancel the process but not immediately remove it from the
// process table.
-func (pm *Manager) AddTypedContext(parent context.Context, description, processType string, currentlyRunning bool) (ctx context.Context, cancel context.CancelFunc, finished FinishedFunc) {
- ctx, cancel = context.WithCancel(parent)
-
- ctx, _, finished = pm.Add(ctx, description, cancel, processType, currentlyRunning)
-
+func (pm *Manager) AddTypedContext(parent context.Context, description, processType string, currentlyRunning bool) (context.Context, CancelCauseFunc, FinishedFunc) {
+ ctx, ctxCancel := context.WithCancelCause(parent)
+ cancel := cancelCauseFunc(ctxCancel)
+ ctx, _, finished := pm.Add(ctx, description, cancel, processType, currentlyRunning)
return ctx, cancel, finished
}
@@ -124,21 +129,23 @@ func (pm *Manager) AddTypedContext(parent context.Context, description, processT
//
// Most processes will not need to use the cancel function but there will be cases whereby you want to cancel the process but not immediately remove it from the
// process table.
-func (pm *Manager) AddContextTimeout(parent context.Context, timeout time.Duration, description string) (ctx context.Context, cancel context.CancelFunc, finished FinishedFunc) {
+func (pm *Manager) AddContextTimeout(parent context.Context, timeout time.Duration, description string) (context.Context, CancelCauseFunc, FinishedFunc) {
if timeout <= 0 {
// it's meaningless to use timeout <= 0, and it must be a bug! so we must panic here to tell developers to make the timeout correct
panic("the timeout must be greater than zero, otherwise the context will be cancelled immediately")
}
-
- ctx, cancel = context.WithTimeout(parent, timeout)
-
- ctx, _, finished = pm.Add(ctx, description, cancel, NormalProcessType, true)
-
+ ctx, ctxCancelTimeout := context.WithTimeout(parent, timeout)
+ ctx, ctxCancelCause := context.WithCancelCause(ctx)
+ cancel := func(cause ...error) {
+ ctxCancelCause(util.OptionalArg(cause))
+ ctxCancelTimeout()
+ }
+ ctx, _, finished := pm.Add(ctx, description, cancel, NormalProcessType, true)
return ctx, cancel, finished
}
// Add create a new process
-func (pm *Manager) Add(ctx context.Context, description string, cancel context.CancelFunc, processType string, currentlyRunning bool) (context.Context, IDType, FinishedFunc) {
+func (pm *Manager) Add(ctx context.Context, description string, cancel CancelCauseFunc, processType string, currentlyRunning bool) (context.Context, IDType, FinishedFunc) {
parentPID := GetParentPID(ctx)
pm.mutex.Lock()
diff --git a/modules/process/process.go b/modules/process/process.go
index 06a28c4a60..d81f5ffa1d 100644
--- a/modules/process/process.go
+++ b/modules/process/process.go
@@ -4,7 +4,6 @@
package process
import (
- "context"
"time"
)
@@ -21,7 +20,7 @@ type process struct {
ParentPID IDType
Description string
Start time.Time
- Cancel context.CancelFunc
+ Cancel CancelCauseFunc
Type string
}
diff --git a/modules/public/manifest.go b/modules/public/manifest.go
new file mode 100644
index 0000000000..f807244c89
--- /dev/null
+++ b/modules/public/manifest.go
@@ -0,0 +1,164 @@
+// Copyright 2026 The Gitea Authors. All rights reserved.
+// SPDX-License-Identifier: MIT
+
+package public
+
+import (
+ "io"
+ "path"
+ "sync"
+ "sync/atomic"
+ "time"
+
+ "code.gitea.io/gitea/modules/json"
+ "code.gitea.io/gitea/modules/log"
+ "code.gitea.io/gitea/modules/setting"
+)
+
+type manifestEntry struct {
+ File string `json:"file"`
+ Name string `json:"name"`
+ IsEntry bool `json:"isEntry"`
+ CSS []string `json:"css"`
+}
+
+type manifestDataStruct struct {
+ paths map[string]string // unhashed path -> hashed path
+ names map[string]string // hashed path -> entry name
+ modTime int64
+ checkTime time.Time
+}
+
+var (
+ manifestData atomic.Pointer[manifestDataStruct]
+ manifestFS = sync.OnceValue(AssetFS)
+)
+
+const manifestPath = "assets/.vite/manifest.json"
+
+func parseManifest(data []byte) (map[string]string, map[string]string) {
+ var manifest map[string]manifestEntry
+ if err := json.Unmarshal(data, &manifest); err != nil {
+ log.Error("Failed to parse frontend manifest: %v", err)
+ return nil, nil
+ }
+
+ paths := make(map[string]string)
+ names := make(map[string]string)
+ for _, entry := range manifest {
+ if !entry.IsEntry || entry.Name == "" {
+ continue
+ }
+ // Build unhashed key from file path: "js/index.js", "css/theme-gitea-dark.css"
+ dir := path.Dir(entry.File)
+ ext := path.Ext(entry.File)
+ key := dir + "/" + entry.Name + ext
+ paths[key] = entry.File
+ names[entry.File] = entry.Name
+ // Map associated CSS files, e.g. "css/index.css" -> "css/index.B3zrQPqD.css"
+ // FIXME: INCORRECT-VITE-MANIFEST-PARSER: the logic is wrong, Vite manifest doesn't work this way
+ // It just happens to be correct for the current modules dependencies
+ for _, css := range entry.CSS {
+ cssKey := path.Dir(css) + "/" + entry.Name + path.Ext(css)
+ paths[cssKey] = css
+ names[css] = entry.Name
+ }
+ }
+ return paths, names
+}
+
+func reloadManifest(existingData *manifestDataStruct) *manifestDataStruct {
+ now := time.Now()
+ data := existingData
+ if data != nil && now.Sub(data.checkTime) < time.Second {
+ // a single request triggers multiple calls to getHashedPath
+ // do not check the manifest file too frequently
+ return data
+ }
+
+ f, err := manifestFS().Open(manifestPath)
+ if err != nil {
+ log.Error("Failed to open frontend manifest: %v", err)
+ return data
+ }
+ defer f.Close()
+
+ fi, err := f.Stat()
+ if err != nil {
+ log.Error("Failed to stat frontend manifest: %v", err)
+ return data
+ }
+
+ needReload := data == nil || fi.ModTime().UnixNano() != data.modTime
+ if !needReload {
+ return data
+ }
+ manifestContent, err := io.ReadAll(f)
+ if err != nil {
+ log.Error("Failed to read frontend manifest: %v", err)
+ return data
+ }
+ return storeManifestFromBytes(manifestContent, fi.ModTime().UnixNano(), now)
+}
+
+func storeManifestFromBytes(manifestContent []byte, modTime int64, checkTime time.Time) *manifestDataStruct {
+ paths, names := parseManifest(manifestContent)
+ data := &manifestDataStruct{
+ paths: paths,
+ names: names,
+ modTime: modTime,
+ checkTime: checkTime,
+ }
+ manifestData.Store(data)
+ return data
+}
+
+func getManifestData() *manifestDataStruct {
+ data := manifestData.Load()
+
+ // In production the manifest is immutable (embedded in the binary).
+ // In dev mode, check if it changed on disk (for watch-frontend).
+ if data == nil || !setting.IsProd {
+ data = reloadManifest(data)
+ }
+ if data == nil {
+ data = &manifestDataStruct{}
+ }
+ return data
+}
+
+// AssetURI returns the URI for a frontend asset.
+// It may return a relative path or a full URL depending on the StaticURLPrefix setting.
+// In Vite dev mode, known entry points are mapped to their source paths
+// so the reverse proxy serves them from the Vite dev server.
+// In production, it resolves the content-hashed path from the manifest.
+func AssetURI(originPath string) string {
+ if IsViteDevMode() {
+ if src := viteDevSourceURL(originPath); src != "" {
+ return src
+ }
+ // it should be caused by incorrect vite config
+ setting.PanicInDevOrTesting("Failed to locate local path for managed asset URI: %s", originPath)
+ }
+
+ // Try to resolve an unhashed asset path (origin path) to its content-hashed path from the frontend manifest.
+ // Example: "js/index.js" -> "js/index.C6Z2MRVQ.js"
+ data := getManifestData()
+ assetPath := data.paths[originPath]
+ if assetPath == "" {
+ // it should be caused by either: "incorrect vite config" or "user's custom theme"
+ assetPath = originPath
+ if !setting.IsProd {
+ log.Warn("Failed to find managed asset URI for origin path: %s", originPath)
+ }
+ }
+
+ return setting.StaticURLPrefix + "/assets/" + assetPath
+}
+
+// AssetNameFromHashedPath returns the asset entry name for a given hashed asset path.
+// Example: returns "theme-gitea-dark" for "css/theme-gitea-dark.CyAaQnn5.css".
+// Returns empty string if the path is not found in the manifest.
+func AssetNameFromHashedPath(hashedPath string) string {
+ return getManifestData().names[hashedPath]
+}
diff --git a/modules/public/manifest_test.go b/modules/public/manifest_test.go
new file mode 100644
index 0000000000..acfeaa6dbe
--- /dev/null
+++ b/modules/public/manifest_test.go
@@ -0,0 +1,80 @@
+// Copyright 2026 The Gitea Authors. All rights reserved.
+// SPDX-License-Identifier: MIT
+
+package public
+
+import (
+ "testing"
+ "time"
+
+ "code.gitea.io/gitea/modules/setting"
+ "code.gitea.io/gitea/modules/test"
+
+ "github.com/stretchr/testify/assert"
+)
+
+func TestViteManifest(t *testing.T) {
+ defer test.MockVariableValue(&setting.IsProd, true)()
+
+ const testManifest = `{
+ "web_src/js/index.ts": {
+ "file": "js/index.C6Z2MRVQ.js",
+ "name": "index",
+ "src": "web_src/js/index.ts",
+ "isEntry": true,
+ "css": ["css/index.B3zrQPqD.css"]
+ },
+ "web_src/css/themes/theme-gitea-dark.css": {
+ "file": "css/theme-gitea-dark.CyAaQnn5.css",
+ "name": "theme-gitea-dark",
+ "src": "web_src/css/themes/theme-gitea-dark.css",
+ "isEntry": true
+ },
+ "web_src/js/features/eventsource.sharedworker.ts": {
+ "file": "js/eventsource.sharedworker.Dug1twio.js",
+ "name": "eventsource.sharedworker",
+ "src": "web_src/js/features/eventsource.sharedworker.ts",
+ "isEntry": true
+ },
+ "_chunk.js": {
+ "file": "js/chunk.abc123.js",
+ "name": "chunk"
+ }
+}`
+
+ t.Run("EmptyManifest", func(t *testing.T) {
+ storeManifestFromBytes([]byte(``), 0, time.Now())
+ assert.Equal(t, "/assets/js/index.js", AssetURI("js/index.js"))
+ assert.Equal(t, "/assets/css/theme-gitea-dark.css", AssetURI("css/theme-gitea-dark.css"))
+ assert.Equal(t, "", AssetNameFromHashedPath("css/no-such-file.css"))
+ })
+
+ t.Run("ParseManifest", func(t *testing.T) {
+ storeManifestFromBytes([]byte(testManifest), 0, time.Now())
+ paths, names := manifestData.Load().paths, manifestData.Load().names
+
+ // JS entries
+ assert.Equal(t, "js/index.C6Z2MRVQ.js", paths["js/index.js"])
+ assert.Equal(t, "js/eventsource.sharedworker.Dug1twio.js", paths["js/eventsource.sharedworker.js"])
+
+ // Associated CSS from JS entries
+ assert.Equal(t, "css/index.B3zrQPqD.css", paths["css/index.css"])
+
+ // CSS-only entries
+ assert.Equal(t, "css/theme-gitea-dark.CyAaQnn5.css", paths["css/theme-gitea-dark.css"])
+
+ // Non-entry chunks should not be included
+ assert.Empty(t, paths["js/chunk.js"])
+
+ // Names: hashed path -> entry name
+ assert.Equal(t, "index", names["js/index.C6Z2MRVQ.js"])
+ assert.Equal(t, "index", names["css/index.B3zrQPqD.css"])
+ assert.Equal(t, "theme-gitea-dark", names["css/theme-gitea-dark.CyAaQnn5.css"])
+ assert.Equal(t, "eventsource.sharedworker", names["js/eventsource.sharedworker.Dug1twio.js"])
+
+ // Test Asset related functions
+ assert.Equal(t, "/assets/js/index.C6Z2MRVQ.js", AssetURI("js/index.js"))
+ assert.Equal(t, "/assets/css/theme-gitea-dark.CyAaQnn5.css", AssetURI("css/theme-gitea-dark.css"))
+ assert.Equal(t, "theme-gitea-dark", AssetNameFromHashedPath("css/theme-gitea-dark.CyAaQnn5.css"))
+ })
+}
diff --git a/modules/public/mime_types.go b/modules/public/mime_types.go
index 32bdf3bfa2..fa4691c6a9 100644
--- a/modules/public/mime_types.go
+++ b/modules/public/mime_types.go
@@ -3,38 +3,48 @@
package public
-import "strings"
+import (
+ "mime"
+ "strings"
+ "sync"
+)
-// wellKnownMimeTypesLower comes from Golang's builtin mime package: `builtinTypesLower`, see the comment of detectWellKnownMimeType
-var wellKnownMimeTypesLower = map[string]string{
- ".avif": "image/avif",
- ".css": "text/css; charset=utf-8",
- ".gif": "image/gif",
- ".htm": "text/html; charset=utf-8",
- ".html": "text/html; charset=utf-8",
- ".jpeg": "image/jpeg",
- ".jpg": "image/jpeg",
- ".js": "text/javascript; charset=utf-8",
- ".json": "application/json",
- ".mjs": "text/javascript; charset=utf-8",
- ".pdf": "application/pdf",
- ".png": "image/png",
- ".svg": "image/svg+xml",
- ".wasm": "application/wasm",
- ".webp": "image/webp",
- ".xml": "text/xml; charset=utf-8",
+// wellKnownMimeTypesLower comes from Golang's builtin mime package: `builtinTypesLower`,
+// see the comment of DetectWellKnownMimeType
+var wellKnownMimeTypesLower = sync.OnceValue(func() map[string]string {
+ return map[string]string{
+ ".avif": "image/avif",
+ ".css": "text/css; charset=utf-8",
+ ".gif": "image/gif",
+ ".htm": "text/html; charset=utf-8",
+ ".html": "text/html; charset=utf-8",
+ ".jpeg": "image/jpeg",
+ ".jpg": "image/jpeg",
+ ".js": "text/javascript; charset=utf-8",
+ ".json": "application/json",
+ ".mjs": "text/javascript; charset=utf-8",
+ ".pdf": "application/pdf",
+ ".png": "image/png",
+ ".svg": "image/svg+xml",
+ ".wasm": "application/wasm",
+ ".webp": "image/webp",
+ ".xml": "text/xml; charset=utf-8",
- // well, there are some types missing from the builtin list
- ".txt": "text/plain; charset=utf-8",
-}
+ // well, there are some types missing from the builtin list
+ ".txt": "text/plain; charset=utf-8",
+ }
+})
-// detectWellKnownMimeType will return the mime-type for a well-known file ext name
+// DetectWellKnownMimeType will return the mime-type for a well-known file ext name
// The purpose of this function is to bypass the unstable behavior of Golang's mime.TypeByExtension
// mime.TypeByExtension would use OS's mime-type config to overwrite the well-known types (see its document).
// If the user's OS has incorrect mime-type config, it would make Gitea can not respond a correct Content-Type to browsers.
// For example, if Gitea returns `text/plain` for a `.js` file, the browser couldn't run the JS due to security reasons.
-// detectWellKnownMimeType makes the Content-Type for well-known files stable.
-func detectWellKnownMimeType(ext string) string {
+// DetectWellKnownMimeType makes the Content-Type for well-known files stable.
+func DetectWellKnownMimeType(ext string) string {
ext = strings.ToLower(ext)
- return wellKnownMimeTypesLower[ext]
+ if s, ok := wellKnownMimeTypesLower()[ext]; ok {
+ return s
+ }
+ return mime.TypeByExtension(ext)
}
diff --git a/modules/public/public.go b/modules/public/public.go
index a7eace1538..bb4721a48d 100644
--- a/modules/public/public.go
+++ b/modules/public/public.go
@@ -18,6 +18,8 @@ import (
"code.gitea.io/gitea/modules/log"
"code.gitea.io/gitea/modules/setting"
"code.gitea.io/gitea/modules/util"
+
+ "github.com/go-chi/cors"
)
func CustomAssets() *assetfs.Layer {
@@ -28,6 +30,15 @@ func AssetFS() *assetfs.LayeredFS {
return assetfs.Layered(CustomAssets(), BuiltinAssets())
}
+func AssetsCors() func(next http.Handler) http.Handler {
+ // static assets need to be served for external renders (sandboxed)
+ return cors.Handler(cors.Options{
+ AllowedOrigins: []string{"*"},
+ AllowedMethods: []string{"HEAD", "GET"},
+ MaxAge: 3600 * 24,
+ })
+}
+
// FileHandlerFunc implements the static handler for serving files in "public" assets
func FileHandlerFunc() http.HandlerFunc {
assetFS := AssetFS()
@@ -36,7 +47,7 @@ func FileHandlerFunc() http.HandlerFunc {
resp.WriteHeader(http.StatusMethodNotAllowed)
return
}
- handleRequest(resp, req, assetFS, req.URL.Path)
+ handleRequest(resp, req, http.FS(assetFS), req.URL.Path)
}
}
@@ -51,9 +62,9 @@ func parseAcceptEncoding(val string) container.Set[string] {
}
// setWellKnownContentType will set the Content-Type if the file is a well-known type.
-// See the comments of detectWellKnownMimeType
+// See the comments of DetectWellKnownMimeType
func setWellKnownContentType(w http.ResponseWriter, file string) {
- mimeType := detectWellKnownMimeType(path.Ext(file))
+ mimeType := DetectWellKnownMimeType(path.Ext(file))
if mimeType != "" {
w.Header().Set("Content-Type", mimeType)
}
diff --git a/modules/public/vitedev.go b/modules/public/vitedev.go
new file mode 100644
index 0000000000..7cfe692390
--- /dev/null
+++ b/modules/public/vitedev.go
@@ -0,0 +1,204 @@
+// Copyright 2026 The Gitea Authors. All rights reserved.
+// SPDX-License-Identifier: MIT
+
+package public
+
+import (
+ "net/http"
+ "net/http/httputil"
+ "net/url"
+ "os"
+ "path/filepath"
+ "strings"
+ "sync/atomic"
+ "time"
+
+ "code.gitea.io/gitea/modules/httplib"
+ "code.gitea.io/gitea/modules/log"
+ "code.gitea.io/gitea/modules/setting"
+ "code.gitea.io/gitea/modules/util"
+ "code.gitea.io/gitea/modules/web/routing"
+)
+
+const viteDevPortFile = "public/assets/.vite/dev-port"
+
+var viteDevProxy atomic.Pointer[httputil.ReverseProxy]
+
+func getViteDevServerBaseURL() string {
+ portFile := filepath.Join(setting.StaticRootPath, viteDevPortFile)
+ portContent, _ := os.ReadFile(portFile)
+ port := strings.TrimSpace(string(portContent))
+ if port == "" {
+ return ""
+ }
+ return "http://localhost:" + port
+}
+
+func getViteDevProxy() *httputil.ReverseProxy {
+ if proxy := viteDevProxy.Load(); proxy != nil {
+ return proxy
+ }
+
+ viteDevServerBaseURL := getViteDevServerBaseURL()
+ if viteDevServerBaseURL == "" {
+ return nil
+ }
+
+ target, err := url.Parse(viteDevServerBaseURL)
+ if err != nil {
+ log.Error("Failed to parse Vite dev server base URL %s, err: %v", viteDevServerBaseURL, err)
+ return nil
+ }
+
+ // there is a strange error log (from Golang's HTTP package)
+ // 2026/03/28 19:50:13 modules/log/misc.go:72:(*loggerToWriter).Write() [I] Unsolicited response received on idle HTTP channel starting with "HTTP/1.1 400 Bad Request\r\n\r\n"; err=
+ // maybe it is caused by that the Vite dev server doesn't support keep-alive connections? or different keep-alive timeouts?
+ transport := &http.Transport{
+ IdleConnTimeout: 5 * time.Second,
+ ResponseHeaderTimeout: 5 * time.Second,
+ }
+ log.Info("Proxying Vite dev server requests to %s", target)
+ proxy := &httputil.ReverseProxy{
+ Transport: transport,
+ Rewrite: func(r *httputil.ProxyRequest) {
+ r.SetURL(target)
+ r.Out.Host = target.Host
+ },
+ ModifyResponse: func(resp *http.Response) error {
+ // add a header to indicate the Vite dev server port,
+ // make developers know that this request is proxied to Vite dev server and which port it is
+ resp.Header.Add("X-Gitea-Vite-Dev-Server", viteDevServerBaseURL)
+ return nil
+ },
+ ErrorHandler: func(w http.ResponseWriter, r *http.Request, err error) {
+ if r.Context().Err() != nil {
+ return // request cancelled (e.g. client disconnected), silently ignore
+ }
+ log.Error("Error proxying to Vite dev server: %v", err)
+ http.Error(w, "Error proxying to Vite dev server: "+err.Error(), http.StatusBadGateway)
+ },
+ }
+ viteDevProxy.Store(proxy)
+ return proxy
+}
+
+// ViteDevMiddleware proxies matching requests to the Vite dev server.
+// It is registered as middleware in non-production mode and lazily discovers
+// the Vite dev server port from the port file written by the viteDevServerPortPlugin.
+// It is needed because there are container-based development, only Gitea web server's port is exposed.
+func ViteDevMiddleware(next http.Handler) http.Handler {
+ return http.HandlerFunc(func(resp http.ResponseWriter, req *http.Request) {
+ if !isViteDevRequest(req) {
+ next.ServeHTTP(resp, req)
+ return
+ }
+ proxy := getViteDevProxy()
+ if proxy == nil {
+ next.ServeHTTP(resp, req)
+ return
+ }
+ routing.MarkLongPolling(resp, req)
+ proxy.ServeHTTP(resp, req)
+ })
+}
+
+var viteDevModeCheck atomic.Pointer[struct {
+ isDev bool
+ time time.Time
+}]
+
+// IsViteDevMode returns true if the Vite dev server port file exists and the server is alive
+func IsViteDevMode() bool {
+ if setting.IsProd {
+ return false
+ }
+
+ now := time.Now()
+ lastCheck := viteDevModeCheck.Load()
+ if lastCheck != nil && time.Now().Sub(lastCheck.time) < time.Second {
+ return lastCheck.isDev
+ }
+
+ viteDevServerBaseURL := getViteDevServerBaseURL()
+ if viteDevServerBaseURL == "" {
+ return false
+ }
+
+ req := httplib.NewRequest(viteDevServerBaseURL+"/web_src/js/__vite_dev_server_check", "GET")
+ resp, _ := req.Response()
+ if resp != nil {
+ _ = resp.Body.Close()
+ }
+ isDev := resp != nil && resp.StatusCode == http.StatusOK
+ viteDevModeCheck.Store(&struct {
+ isDev bool
+ time time.Time
+ }{
+ isDev: isDev,
+ time: now,
+ })
+ return isDev
+}
+
+func detectWebSrcPath(webSrcPath string) string {
+ localPath := util.FilePathJoinAbs(setting.StaticRootPath, "web_src", webSrcPath)
+ if _, err := os.Stat(localPath); err == nil {
+ return setting.AppSubURL + "/web_src/" + webSrcPath
+ }
+ return ""
+}
+
+func viteDevSourceURL(name string) string {
+ if strings.HasPrefix(name, "css/theme-") {
+ // Only redirect built-in themes to Vite source; custom themes are served from custom/public/assets/css/
+ themeFilePath := "css/themes/" + strings.TrimPrefix(name, "css/")
+ if srcPath := detectWebSrcPath(themeFilePath); srcPath != "" {
+ return srcPath
+ }
+ }
+ // try to map ".js" files to ".ts" files
+ pathPrefix, ok := strings.CutSuffix(name, ".js")
+ if ok {
+ if srcPath := detectWebSrcPath(pathPrefix + ".ts"); srcPath != "" {
+ return srcPath
+ }
+ }
+ // for all others that the names match
+ return detectWebSrcPath(name)
+}
+
+// isViteDevRequest returns true if the request should be proxied to the Vite dev server.
+// Ref: Vite source packages/vite/src/node/constants.ts and packages/vite/src/shared/constants.ts
+func isViteDevRequest(req *http.Request) bool {
+ if req.Header.Get("Upgrade") == "websocket" {
+ wsProtocol := req.Header.Get("Sec-WebSocket-Protocol")
+ return wsProtocol == "vite-hmr" || wsProtocol == "vite-ping"
+ }
+ path := req.URL.Path
+
+ // vite internal requests
+ if strings.HasPrefix(path, "/@vite/") /* HMR client */ ||
+ strings.HasPrefix(path, "/@fs/") /* out-of-root file access, see vite.config.ts: fs.allow */ ||
+ strings.HasPrefix(path, "/@id/") /* virtual modules */ {
+ return true
+ }
+
+ // local source requests (VITE-DEV-SERVER-SECURITY: don't serve sensitive files outside the allowed paths)
+ if strings.HasPrefix(path, "/node_modules/") ||
+ strings.HasPrefix(path, "/public/assets/") ||
+ strings.HasPrefix(path, "/web_src/") {
+ return true
+ }
+
+ // Vite uses a path relative to project root and adds "?import" to non-JS/CSS asset imports:
+ // - {WebSite}/public/assets/... (e.g. SVG icons from "{RepoRoot}/public/assets/img/svg/")
+ // - {WebSite}/assets/emoji.json: it is an exception for the frontend assets, it is imported by JS code, but:
+ // - KEEP IN MIND: all static frontend assets are served from "{AssetFS}/assets" to "{WebSite}/assets" by Gitea Web Server
+ // - "{AssetFS}" is a layered filesystem from "{RepoRoot}/public" or embedded assets, and user's custom files in "{CustomPath}/public"
+ // - "{RepoRoot}/assets/emoji.json" just happens to have the dir name "assets", it is not related to frontend assets
+ // - BAD DESIGN: indeed it is a "conflicted and polluted name" sample
+ if path == "/assets/emoji.json" {
+ return true
+ }
+ return false
+}
diff --git a/modules/queue/workerqueue.go b/modules/queue/workerqueue.go
index 0f5b105551..d8b0722caf 100644
--- a/modules/queue/workerqueue.go
+++ b/modules/queue/workerqueue.go
@@ -21,7 +21,7 @@ import (
// It can use different underlying (base) queue types
type WorkerPoolQueue[T any] struct {
ctxRun context.Context
- ctxRunCancel context.CancelFunc
+ ctxRunCancel process.FinishedFunc
shutdownDone chan struct{}
shutdownTimeout atomic.Int64 // in case some buggy handlers (workers) would hang forever, "shutdown" should finish in predictable time
diff --git a/modules/recaptcha/recaptcha.go b/modules/recaptcha/recaptcha.go
index 1777d169c1..224fa38eee 100644
--- a/modules/recaptcha/recaptcha.go
+++ b/modules/recaptcha/recaptcha.go
@@ -13,7 +13,6 @@ import (
"code.gitea.io/gitea/modules/json"
"code.gitea.io/gitea/modules/setting"
- "code.gitea.io/gitea/modules/util"
)
// Response is the structure of JSON returned from API
@@ -24,17 +23,16 @@ type Response struct {
ErrorCodes []ErrorCode `json:"error-codes"`
}
-const apiURL = "api/siteverify"
-
// Verify calls Google Recaptcha API to verify token
func Verify(ctx context.Context, response string) (bool, error) {
post := url.Values{
"secret": {setting.Service.RecaptchaSecret},
"response": {response},
}
+
+ reqURL := strings.TrimSuffix(setting.Service.RecaptchaURL, "/") + "/api/siteverify"
// Basically a copy of http.PostForm, but with a context
- req, err := http.NewRequestWithContext(ctx, http.MethodPost,
- util.URLJoin(setting.Service.RecaptchaURL, apiURL), strings.NewReader(post.Encode()))
+ req, err := http.NewRequestWithContext(ctx, http.MethodPost, reqURL, strings.NewReader(post.Encode()))
if err != nil {
return false, fmt.Errorf("Failed to create CAPTCHA request: %w", err)
}
diff --git a/modules/references/references.go b/modules/references/references.go
index 592bd4cbe4..ef3568ebea 100644
--- a/modules/references/references.go
+++ b/modules/references/references.go
@@ -248,7 +248,7 @@ func FindAllIssueReferencesMarkdown(content string) []IssueReference {
func findAllIssueReferencesMarkdown(content string) []*rawReference {
bcontent, links := mdstripper.StripMarkdownBytes([]byte(content))
- return findAllIssueReferencesBytes(bcontent, links)
+ return findAllIssueReferencesBytes(bcontent, links, []byte(content))
}
func convertFullHTMLReferencesToShortRefs(re *regexp.Regexp, contentBytes *[]byte) {
@@ -326,7 +326,7 @@ func FindAllIssueReferences(content string) []IssueReference {
} else {
log.Debug("No GiteaIssuePullPattern pattern")
}
- return rawToIssueReferenceList(findAllIssueReferencesBytes(contentBytes, []string{}))
+ return rawToIssueReferenceList(findAllIssueReferencesBytes(contentBytes, []string{}, nil))
}
// FindRenderizableReferenceNumeric returns the first unvalidated reference found in a string.
@@ -406,7 +406,8 @@ func FindRenderizableReferenceAlphanumeric(content string) *RenderizableReferenc
}
// FindAllIssueReferencesBytes returns a list of unvalidated references found in a byte slice.
-func findAllIssueReferencesBytes(content []byte, links []string) []*rawReference {
+// originalContent is optional and used to detect closing/reopening keywords for URL references.
+func findAllIssueReferencesBytes(content []byte, links []string, originalContent []byte) []*rawReference {
ret := make([]*rawReference, 0, 10)
pos := 0
@@ -470,10 +471,27 @@ func findAllIssueReferencesBytes(content []byte, links []string) []*rawReference
default:
continue
}
- // Note: closing/reopening keywords not supported with URLs
- bytes := []byte(parts[1] + "/" + parts[2] + sep + parts[4])
- if ref := getCrossReference(bytes, 0, len(bytes), true, false); ref != nil {
+ refBytes := []byte(parts[1] + "/" + parts[2] + sep + parts[4])
+ if ref := getCrossReference(refBytes, 0, len(refBytes), true, false); ref != nil {
ref.refLocation = nil
+ // Detect closing/reopening keywords by finding the URL position in original content
+ if originalContent != nil {
+ if idx := bytes.Index(originalContent, []byte(link)); idx > 0 {
+ // For markdown links [text](url), find the opening bracket before the URL
+ // to properly detect keywords like "closes [text](url)"
+ searchStart := idx
+ if idx >= 2 && originalContent[idx-1] == '(' {
+ // Find the matching '[' for this markdown link
+ bracketIdx := bytes.LastIndex(originalContent[:idx-1], []byte{'['})
+ if bracketIdx >= 0 {
+ searchStart = bracketIdx
+ }
+ }
+ action, location := findActionKeywords(originalContent, searchStart)
+ ref.action = action
+ ref.actionLocation = location
+ }
+ }
ret = append(ret, ref)
}
}
diff --git a/modules/references/references_test.go b/modules/references/references_test.go
index a15ae99f79..5922a9f5a9 100644
--- a/modules/references/references_test.go
+++ b/modules/references/references_test.go
@@ -227,6 +227,62 @@ func TestFindAllIssueReferences(t *testing.T) {
testFixtures(t, fixtures, "default")
+ // Test closing/reopening keywords with URLs (issue #27549)
+ // Uses the same AppURL as testFixtures (https://gitea.com:3000/)
+ urlFixtures := []testFixture{
+ {
+ "Closes [this issue](https://gitea.com:3000/user/repo/issues/123)",
+ []testResult{
+ {123, "user", "repo", "123", false, XRefActionCloses, nil, &RefSpan{Start: 0, End: 6}, ""},
+ },
+ },
+ {
+ "This fixes [#456](https://gitea.com:3000/org/project/issues/456)",
+ []testResult{
+ {456, "org", "project", "456", false, XRefActionCloses, nil, &RefSpan{Start: 5, End: 10}, ""},
+ },
+ },
+ {
+ "Reopens [PR](https://gitea.com:3000/owner/repo/pulls/789)",
+ []testResult{
+ {789, "owner", "repo", "789", true, XRefActionReopens, nil, &RefSpan{Start: 0, End: 7}, ""},
+ },
+ },
+ {
+ "See [issue](https://gitea.com:3000/user/repo/issues/100) but closes [another](https://gitea.com:3000/user/repo/issues/200)",
+ []testResult{
+ {100, "user", "repo", "100", false, XRefActionNone, nil, nil, ""},
+ {200, "user", "repo", "200", false, XRefActionCloses, nil, &RefSpan{Start: 61, End: 67}, ""},
+ },
+ },
+ }
+
+ testFixtures(t, urlFixtures, "url-keywords")
+
+ // Test bare URLs (not markdown links) with closing keywords
+ // These use FindAllIssueReferences (non-markdown) which converts full URLs to short refs first
+ setting.AppURL = "https://gitea.com:3000/"
+ bareURLTests := []struct {
+ name string
+ input string
+ expected XRefAction
+ }{
+ {"Fixes bare URL", "Fixes https://gitea.com:3000/org/project/issues/456", XRefActionCloses},
+ {"Fixes with colon", "Fixes: https://gitea.com:3000/org/project/issues/456", XRefActionCloses},
+ {"Closes bare URL", "Closes https://gitea.com:3000/user/repo/issues/123", XRefActionCloses},
+ {"Closes with colon", "Closes: https://gitea.com:3000/user/repo/issues/123", XRefActionCloses},
+ }
+
+ for _, tt := range bareURLTests {
+ t.Run(tt.name, func(t *testing.T) {
+ refs := FindAllIssueReferences(tt.input)
+ assert.Len(t, refs, 1, "Expected 1 reference for: %s", tt.input)
+ if len(refs) > 0 {
+ assert.Equal(t, tt.expected, refs[0].Action, "Expected action %v for: %s", tt.expected, tt.input)
+ }
+ })
+ }
+
type alnumFixture struct {
input string
issue string
diff --git a/modules/repository/branch.go b/modules/repository/branch.go
index 30aa0a6e85..0a8f7cc464 100644
--- a/modules/repository/branch.go
+++ b/modules/repository/branch.go
@@ -17,6 +17,13 @@ import (
"code.gitea.io/gitea/modules/timeutil"
)
+// SyncResult describes a reference update detected during sync.
+type SyncResult struct {
+ RefName git.RefName
+ OldCommitID string
+ NewCommitID string
+}
+
// SyncRepoBranches synchronizes branch table with repository branches
func SyncRepoBranches(ctx context.Context, repoID, doerID int64) (int64, error) {
repo, err := repo_model.GetRepositoryByID(ctx, repoID)
@@ -33,18 +40,19 @@ func SyncRepoBranches(ctx context.Context, repoID, doerID int64) (int64, error)
}
defer gitRepo.Close()
- return SyncRepoBranchesWithRepo(ctx, repo, gitRepo, doerID)
+ count, _, err := SyncRepoBranchesWithRepo(ctx, repo, gitRepo, doerID)
+ return count, err
}
-func SyncRepoBranchesWithRepo(ctx context.Context, repo *repo_model.Repository, gitRepo *git.Repository, doerID int64) (int64, error) {
+func SyncRepoBranchesWithRepo(ctx context.Context, repo *repo_model.Repository, gitRepo *git.Repository, doerID int64) (int64, []*SyncResult, error) {
objFmt, err := gitRepo.GetObjectFormat()
if err != nil {
- return 0, fmt.Errorf("GetObjectFormat: %w", err)
+ return 0, nil, fmt.Errorf("GetObjectFormat: %w", err)
}
if objFmt.Name() != repo.ObjectFormatName {
repo.ObjectFormatName = objFmt.Name()
if err = repo_model.UpdateRepositoryColsWithAutoTime(ctx, repo, "object_format_name"); err != nil {
- return 0, fmt.Errorf("UpdateRepositoryColsWithAutoTime: %w", err)
+ return 0, nil, fmt.Errorf("UpdateRepositoryColsWithAutoTime: %w", err)
}
}
@@ -52,7 +60,7 @@ func SyncRepoBranchesWithRepo(ctx context.Context, repo *repo_model.Repository,
{
branches, _, err := gitRepo.GetBranchNames(0, 0)
if err != nil {
- return 0, err
+ return 0, nil, err
}
log.Trace("SyncRepoBranches[%s]: branches[%d]: %v", repo.FullName(), len(branches), branches)
for _, branch := range branches {
@@ -67,7 +75,7 @@ func SyncRepoBranchesWithRepo(ctx context.Context, repo *repo_model.Repository,
RepoID: repo.ID,
})
if err != nil {
- return 0, err
+ return 0, nil, err
}
for _, branch := range branches {
dbBranches[branch.Name] = branch
@@ -77,11 +85,12 @@ func SyncRepoBranchesWithRepo(ctx context.Context, repo *repo_model.Repository,
var toAdd []*git_model.Branch
var toUpdate []*git_model.Branch
var toRemove []int64
+ var syncResults []*SyncResult
for branch := range allBranches {
dbb := dbBranches[branch]
commit, err := gitRepo.GetBranchCommit(branch)
if err != nil {
- return 0, err
+ return 0, nil, err
}
if dbb == nil {
toAdd = append(toAdd, &git_model.Branch{
@@ -92,7 +101,12 @@ func SyncRepoBranchesWithRepo(ctx context.Context, repo *repo_model.Repository,
PusherID: doerID,
CommitTime: timeutil.TimeStamp(commit.Committer.When.Unix()),
})
- } else if commit.ID.String() != dbb.CommitID {
+ syncResults = append(syncResults, &SyncResult{
+ RefName: git.RefNameFromBranch(branch),
+ OldCommitID: "",
+ NewCommitID: commit.ID.String(),
+ })
+ } else if commit.ID.String() != dbb.CommitID || dbb.IsDeleted {
toUpdate = append(toUpdate, &git_model.Branch{
ID: dbb.ID,
RepoID: repo.ID,
@@ -102,19 +116,29 @@ func SyncRepoBranchesWithRepo(ctx context.Context, repo *repo_model.Repository,
PusherID: doerID,
CommitTime: timeutil.TimeStamp(commit.Committer.When.Unix()),
})
+ syncResults = append(syncResults, &SyncResult{
+ RefName: git.RefNameFromBranch(branch),
+ OldCommitID: dbb.CommitID,
+ NewCommitID: commit.ID.String(),
+ })
}
}
for _, dbBranch := range dbBranches {
if !allBranches.Contains(dbBranch.Name) && !dbBranch.IsDeleted {
toRemove = append(toRemove, dbBranch.ID)
+ syncResults = append(syncResults, &SyncResult{
+ RefName: git.RefNameFromBranch(dbBranch.Name),
+ OldCommitID: dbBranch.CommitID,
+ NewCommitID: "",
+ })
}
}
log.Trace("SyncRepoBranches[%s]: toAdd: %v, toUpdate: %v, toRemove: %v", repo.FullName(), toAdd, toUpdate, toRemove)
if len(toAdd) == 0 && len(toRemove) == 0 && len(toUpdate) == 0 {
- return int64(len(allBranches)), nil
+ return int64(len(allBranches)), syncResults, nil
}
if err := db.WithTx(ctx, func(ctx context.Context) error {
@@ -140,7 +164,7 @@ func SyncRepoBranchesWithRepo(ctx context.Context, repo *repo_model.Repository,
return nil
}); err != nil {
- return 0, err
+ return 0, nil, err
}
- return int64(len(allBranches)), nil
+ return int64(len(allBranches)), syncResults, nil
}
diff --git a/modules/repository/commits.go b/modules/repository/commits.go
index 878fdc1603..a3e253e998 100644
--- a/modules/repository/commits.go
+++ b/modules/repository/commits.go
@@ -15,6 +15,7 @@ import (
"code.gitea.io/gitea/modules/cache"
"code.gitea.io/gitea/modules/cachegroup"
"code.gitea.io/gitea/modules/git"
+ "code.gitea.io/gitea/modules/gitrepo"
"code.gitea.io/gitea/modules/log"
"code.gitea.io/gitea/modules/setting"
api "code.gitea.io/gitea/modules/structs"
@@ -72,7 +73,7 @@ func ToAPIPayloadCommit(ctx context.Context, emailUsers map[string]*user_model.U
committerUsername = committer.Name
}
- fileStatus, err := git.GetCommitFileStatus(ctx, repo.RepoPath(), commit.Sha1)
+ fileStatus, err := gitrepo.GetCommitFileStatus(ctx, repo, commit.Sha1)
if err != nil {
return nil, fmt.Errorf("FileStatus [commit_sha1: %s]: %w", commit.Sha1, err)
}
diff --git a/modules/repository/create.go b/modules/repository/create.go
index a75598a84b..f5fb92df40 100644
--- a/modules/repository/create.go
+++ b/modules/repository/create.go
@@ -6,44 +6,15 @@ package repository
import (
"context"
"fmt"
- "os"
- "path/filepath"
git_model "code.gitea.io/gitea/models/git"
repo_model "code.gitea.io/gitea/models/repo"
+ "code.gitea.io/gitea/modules/gitrepo"
)
-const notRegularFileMode = os.ModeSymlink | os.ModeNamedPipe | os.ModeSocket | os.ModeDevice | os.ModeCharDevice | os.ModeIrregular
-
-// getDirectorySize returns the disk consumption for a given path
-func getDirectorySize(path string) (int64, error) {
- var size int64
- err := filepath.WalkDir(path, func(_ string, entry os.DirEntry, err error) error {
- if os.IsNotExist(err) { // ignore the error because some files (like temp/lock file) may be deleted during traversing.
- return nil
- } else if err != nil {
- return err
- }
- if entry.IsDir() {
- return nil
- }
- info, err := entry.Info()
- if os.IsNotExist(err) { // ignore the error as above
- return nil
- } else if err != nil {
- return err
- }
- if (info.Mode() & notRegularFileMode) == 0 {
- size += info.Size()
- }
- return nil
- })
- return size, err
-}
-
// UpdateRepoSize updates the repository size, calculating it using getDirectorySize
func UpdateRepoSize(ctx context.Context, repo *repo_model.Repository) error {
- size, err := getDirectorySize(repo.RepoPath())
+ size, err := gitrepo.CalcRepositorySize(repo)
if err != nil {
return fmt.Errorf("updateSize: %w", err)
}
diff --git a/modules/repository/create_test.go b/modules/repository/create_test.go
index 68b0f4dea1..a3fca02c25 100644
--- a/modules/repository/create_test.go
+++ b/modules/repository/create_test.go
@@ -8,6 +8,7 @@ import (
repo_model "code.gitea.io/gitea/models/repo"
"code.gitea.io/gitea/models/unittest"
+ "code.gitea.io/gitea/modules/gitrepo"
"github.com/stretchr/testify/assert"
)
@@ -16,7 +17,7 @@ func TestGetDirectorySize(t *testing.T) {
assert.NoError(t, unittest.PrepareTestDatabase())
repo, err := repo_model.GetRepositoryByID(t.Context(), 1)
assert.NoError(t, err)
- size, err := getDirectorySize(repo.RepoPath())
+ size, err := gitrepo.CalcRepositorySize(repo)
assert.NoError(t, err)
repo.Size = 8165 // real size on the disk
assert.Equal(t, repo.Size, size)
diff --git a/modules/repository/env.go b/modules/repository/env.go
index 78e06f86fb..ed2c6fef81 100644
--- a/modules/repository/env.go
+++ b/modules/repository/env.go
@@ -11,24 +11,26 @@ import (
repo_model "code.gitea.io/gitea/models/repo"
user_model "code.gitea.io/gitea/models/user"
"code.gitea.io/gitea/modules/setting"
+ "code.gitea.io/gitea/modules/util"
)
// env keys for git hooks need
const (
- EnvRepoName = "GITEA_REPO_NAME"
- EnvRepoUsername = "GITEA_REPO_USER_NAME"
- EnvRepoID = "GITEA_REPO_ID"
- EnvRepoIsWiki = "GITEA_REPO_IS_WIKI"
- EnvPusherName = "GITEA_PUSHER_NAME"
- EnvPusherEmail = "GITEA_PUSHER_EMAIL"
- EnvPusherID = "GITEA_PUSHER_ID"
- EnvKeyID = "GITEA_KEY_ID" // public key ID
- EnvDeployKeyID = "GITEA_DEPLOY_KEY_ID"
- EnvPRID = "GITEA_PR_ID"
- EnvPushTrigger = "GITEA_PUSH_TRIGGER"
- EnvIsInternal = "GITEA_INTERNAL_PUSH"
- EnvAppURL = "GITEA_ROOT_URL"
- EnvActionPerm = "GITEA_ACTION_PERM"
+ EnvRepoName = "GITEA_REPO_NAME"
+ EnvRepoUsername = "GITEA_REPO_USER_NAME"
+ EnvRepoID = "GITEA_REPO_ID"
+ EnvRepoIsWiki = "GITEA_REPO_IS_WIKI"
+ EnvPusherName = "GITEA_PUSHER_NAME"
+ EnvPusherEmail = "GITEA_PUSHER_EMAIL"
+ EnvPusherID = "GITEA_PUSHER_ID"
+ EnvKeyID = "GITEA_KEY_ID" // public key ID
+ EnvDeployKeyID = "GITEA_DEPLOY_KEY_ID"
+ EnvPRID = "GITEA_PR_ID"
+ EnvPRIndex = "GITEA_PR_INDEX" // not used by Gitea at the moment, it is for custom git hooks
+ EnvPushTrigger = "GITEA_PUSH_TRIGGER"
+ EnvIsInternal = "GITEA_INTERNAL_PUSH"
+ EnvAppURL = "GITEA_ROOT_URL"
+ EnvActionsTaskID = "GITEA_ACTIONS_TASK_ID"
)
type PushTrigger string
@@ -50,38 +52,42 @@ func InternalPushingEnvironment(doer *user_model.User, repo *repo_model.Reposito
// PushingEnvironment returns an os environment to allow hooks to work on push
func PushingEnvironment(doer *user_model.User, repo *repo_model.Repository) []string {
- return FullPushingEnvironment(doer, doer, repo, repo.Name, 0)
+ return FullPushingEnvironment(doer, doer, repo, repo.Name, 0, 0)
}
-// FullPushingEnvironment returns an os environment to allow hooks to work on push
-func FullPushingEnvironment(author, committer *user_model.User, repo *repo_model.Repository, repoName string, prID int64) []string {
- isWiki := "false"
- if strings.HasSuffix(repoName, ".wiki") {
- isWiki = "true"
+func DoerPushingEnvironment(doer *user_model.User, repo *repo_model.Repository, isWiki bool) []string {
+ env := []string{
+ EnvAppURL + "=" + setting.AppURL,
+ EnvRepoName + "=" + repo.Name + util.Iif(isWiki, ".wiki", ""),
+ EnvRepoUsername + "=" + repo.OwnerName,
+ EnvRepoID + "=" + strconv.FormatInt(repo.ID, 10),
+ EnvRepoIsWiki + "=" + strconv.FormatBool(isWiki),
+ EnvPusherName + "=" + doer.Name,
+ EnvPusherID + "=" + strconv.FormatInt(doer.ID, 10),
+ }
+ if !doer.KeepEmailPrivate {
+ env = append(env, EnvPusherEmail+"="+doer.Email)
+ }
+ if taskID, isActionsUser := user_model.GetActionsUserTaskID(doer); isActionsUser {
+ env = append(env, EnvActionsTaskID+"="+strconv.FormatInt(taskID, 10))
}
+ return env
+}
+// FullPushingEnvironment returns an os environment to allow hooks to work on push
+func FullPushingEnvironment(author, committer *user_model.User, repo *repo_model.Repository, repoName string, prID, prIndex int64) []string {
+ isWiki := strings.HasSuffix(repoName, ".wiki")
authorSig := author.NewGitSig()
committerSig := committer.NewGitSig()
-
environ := append(os.Environ(),
"GIT_AUTHOR_NAME="+authorSig.Name,
"GIT_AUTHOR_EMAIL="+authorSig.Email,
"GIT_COMMITTER_NAME="+committerSig.Name,
"GIT_COMMITTER_EMAIL="+committerSig.Email,
- EnvRepoName+"="+repoName,
- EnvRepoUsername+"="+repo.OwnerName,
- EnvRepoIsWiki+"="+isWiki,
- EnvPusherName+"="+committer.Name,
- EnvPusherID+"="+strconv.FormatInt(committer.ID, 10),
- EnvRepoID+"="+strconv.FormatInt(repo.ID, 10),
EnvPRID+"="+strconv.FormatInt(prID, 10),
- EnvAppURL+"="+setting.AppURL,
+ EnvPRIndex+"="+strconv.FormatInt(prIndex, 10),
"SSH_ORIGINAL_COMMAND=gitea-internal",
)
-
- if !committer.KeepEmailPrivate {
- environ = append(environ, EnvPusherEmail+"="+committer.Email)
- }
-
+ environ = append(environ, DoerPushingEnvironment(committer, repo, isWiki)...)
return environ
}
diff --git a/modules/repository/repo.go b/modules/repository/repo.go
index ad4a53b858..76125f5e61 100644
--- a/modules/repository/repo.go
+++ b/modules/repository/repo.go
@@ -53,7 +53,8 @@ func SyncRepoTags(ctx context.Context, repoID int64) error {
}
defer gitRepo.Close()
- return SyncReleasesWithTags(ctx, repo, gitRepo)
+ _, err = SyncReleasesWithTags(ctx, repo, gitRepo)
+ return err
}
// StoreMissingLfsObjectsInRepository downloads missing LFS objects
@@ -62,7 +63,9 @@ func StoreMissingLfsObjectsInRepository(ctx context.Context, repo *repo_model.Re
pointerChan := make(chan lfs.PointerBlob)
errChan := make(chan error, 1)
- go lfs.SearchPointerBlobs(ctx, gitRepo, pointerChan, errChan)
+ go func() {
+ errChan <- lfs.SearchPointerBlobs(ctx, gitRepo, pointerChan)
+ }()
downloadObjects := func(pointers []lfs.Pointer) error {
err := lfsClient.Download(ctx, pointers, func(p lfs.Pointer, content io.ReadCloser, objectError error) error {
@@ -150,13 +153,12 @@ func StoreMissingLfsObjectsInRepository(ctx context.Context, repo *repo_model.Re
}
}
- err, has := <-errChan
- if has {
+ err := <-errChan
+ if err != nil {
log.Error("Repo[%-v]: Error enumerating LFS objects for repository: %v", repo, err)
- return err
}
- return nil
+ return err
}
// shortRelease to reduce load memory, this struct can replace repo_model.Release
@@ -177,13 +179,14 @@ func (shortRelease) TableName() string {
// upstream. Hence, after each sync we want the release set to be
// identical to the upstream tag set. This is much more efficient for
// repositories like https://github.com/vim/vim (with over 13000 tags).
-func SyncReleasesWithTags(ctx context.Context, repo *repo_model.Repository, gitRepo *git.Repository) error {
+func SyncReleasesWithTags(ctx context.Context, repo *repo_model.Repository, gitRepo *git.Repository) ([]*SyncResult, error) {
log.Debug("SyncReleasesWithTags: in Repo[%d:%s/%s]", repo.ID, repo.OwnerName, repo.Name)
tags, _, err := gitRepo.GetTagInfos(0, 0)
if err != nil {
- return fmt.Errorf("unable to GetTagInfos in pull-mirror Repo[%d:%s/%s]: %w", repo.ID, repo.OwnerName, repo.Name, err)
+ return nil, fmt.Errorf("unable to GetTagInfos in pull-mirror Repo[%d:%s/%s]: %w", repo.ID, repo.OwnerName, repo.Name, err)
}
var added, deleted, updated int
+ var syncResults []*SyncResult
err = db.WithTx(ctx, func(ctx context.Context) error {
dbReleases, err := db.Find[shortRelease](ctx, repo_model.FindReleasesOptions{
RepoID: repo.ID,
@@ -194,7 +197,45 @@ func SyncReleasesWithTags(ctx context.Context, repo *repo_model.Repository, gitR
return fmt.Errorf("unable to FindReleases in pull-mirror Repo[%d:%s/%s]: %w", repo.ID, repo.OwnerName, repo.Name, err)
}
+ dbReleasesByID := make(map[int64]*shortRelease, len(dbReleases))
+ dbReleasesByTag := make(map[string]*shortRelease, len(dbReleases))
+ for _, release := range dbReleases {
+ dbReleasesByID[release.ID] = release
+ dbReleasesByTag[release.TagName] = release
+ }
+
inserts, deletes, updates := calcSync(tags, dbReleases)
+ syncResults = make([]*SyncResult, 0, len(inserts)+len(deletes)+len(updates))
+ for _, tag := range inserts {
+ syncResults = append(syncResults, &SyncResult{
+ RefName: git.RefNameFromTag(tag.Name),
+ OldCommitID: "",
+ NewCommitID: tag.Object.String(),
+ })
+ }
+ for _, deleteID := range deletes {
+ release := dbReleasesByID[deleteID]
+ if release == nil {
+ continue
+ }
+ syncResults = append(syncResults, &SyncResult{
+ RefName: git.RefNameFromTag(release.TagName),
+ OldCommitID: release.Sha1,
+ NewCommitID: "",
+ })
+ }
+ for _, tag := range updates {
+ release := dbReleasesByTag[tag.Name]
+ oldSha := ""
+ if release != nil {
+ oldSha = release.Sha1
+ }
+ syncResults = append(syncResults, &SyncResult{
+ RefName: git.RefNameFromTag(tag.Name),
+ OldCommitID: oldSha,
+ NewCommitID: tag.Object.String(),
+ })
+ }
//
// make release set identical to upstream tags
//
@@ -233,15 +274,15 @@ func SyncReleasesWithTags(ctx context.Context, repo *repo_model.Repository, gitR
return fmt.Errorf("unable to update tag %s for pull-mirror Repo[%d:%s/%s]: %w", tag.Name, repo.ID, repo.OwnerName, repo.Name, err)
}
}
- added, deleted, updated = len(deletes), len(updates), len(inserts)
+ added, deleted, updated = len(inserts), len(deletes), len(updates)
return nil
})
if err != nil {
- return fmt.Errorf("unable to rebuild release table for pull-mirror Repo[%d:%s/%s]: %w", repo.ID, repo.OwnerName, repo.Name, err)
+ return nil, fmt.Errorf("unable to rebuild release table for pull-mirror Repo[%d:%s/%s]: %w", repo.ID, repo.OwnerName, repo.Name, err)
}
log.Trace("SyncReleasesWithTags: %d tags added, %d tags deleted, %d tags updated", added, deleted, updated)
- return nil
+ return syncResults, nil
}
func calcSync(destTags []*git.Tag, dbTags []*shortRelease) ([]*git.Tag, []int64, []*git.Tag) {
diff --git a/modules/session/db.go b/modules/session/db.go
index 7b5be1bc70..577e20a45e 100644
--- a/modules/session/db.go
+++ b/modules/session/db.go
@@ -5,6 +5,7 @@ package session
import (
"context"
+ "fmt"
"log"
"sync"
@@ -121,12 +122,12 @@ func (p *DBProvider) Read(sid string) (session.RawStore, error) {
}
// Exist returns true if session with given ID exists.
-func (p *DBProvider) Exist(sid string) bool {
+func (p *DBProvider) Exist(sid string) (bool, error) {
has, err := auth.ExistSession(dbContext(), sid)
if err != nil {
- panic("session/DB: error checking existence: " + err.Error())
+ return false, fmt.Errorf("session/DB: error checking existence: %w", err)
}
- return has
+ return has, nil
}
// Destroy deletes a session by session ID.
@@ -155,12 +156,12 @@ func (p *DBProvider) Regenerate(oldsid, sid string) (_ session.RawStore, err err
}
// Count counts and returns number of sessions.
-func (p *DBProvider) Count() int {
+func (p *DBProvider) Count() (int, error) {
total, err := auth.CountSessions(dbContext())
if err != nil {
- panic("session/DB: error counting records: " + err.Error())
+ return 0, fmt.Errorf("session/DB: error counting records: %w", err)
}
- return int(total)
+ return int(total), nil
}
// GC calls GC to clean expired sessions.
diff --git a/modules/session/redis.go b/modules/session/redis.go
index d89d8bc6e2..083869f4e1 100644
--- a/modules/session/redis.go
+++ b/modules/session/redis.go
@@ -135,10 +135,12 @@ func (p *RedisProvider) Init(maxlifetime int64, configs string) (err error) {
// Read returns raw session store by session ID.
func (p *RedisProvider) Read(sid string) (session.RawStore, error) {
psid := p.prefix + sid
- if !p.Exist(sid) {
+ if exist, err := p.Exist(sid); err == nil && !exist {
if err := p.c.Set(graceful.GetManager().HammerContext(), psid, "", p.duration).Err(); err != nil {
return nil, err
}
+ } else if err != nil {
+ return nil, err
}
var kv map[any]any
@@ -159,9 +161,9 @@ func (p *RedisProvider) Read(sid string) (session.RawStore, error) {
}
// Exist returns true if session with given ID exists.
-func (p *RedisProvider) Exist(sid string) bool {
+func (p *RedisProvider) Exist(sid string) (bool, error) {
v, err := p.c.Exists(graceful.GetManager().HammerContext(), p.prefix+sid).Result()
- return err == nil && v == 1
+ return err == nil && v == 1, err
}
// Destroy deletes a session by session ID.
@@ -174,13 +176,18 @@ func (p *RedisProvider) Regenerate(oldsid, sid string) (_ session.RawStore, err
poldsid := p.prefix + oldsid
psid := p.prefix + sid
- if p.Exist(sid) {
+ if exist, err := p.Exist(sid); err != nil {
+ return nil, err
+ } else if exist {
return nil, fmt.Errorf("new sid '%s' already exists", sid)
- } else if !p.Exist(oldsid) {
+ }
+ if exist, err := p.Exist(oldsid); err == nil && !exist {
// Make a fake old session.
- if err = p.c.Set(graceful.GetManager().HammerContext(), poldsid, "", p.duration).Err(); err != nil {
+ if err := p.c.Set(graceful.GetManager().HammerContext(), poldsid, "", p.duration).Err(); err != nil {
return nil, err
}
+ } else if err != nil {
+ return nil, err
}
// do not use Rename here, because the old sid and new sid may be in different redis cluster slot.
@@ -211,12 +218,9 @@ func (p *RedisProvider) Regenerate(oldsid, sid string) (_ session.RawStore, err
}
// Count counts and returns number of sessions.
-func (p *RedisProvider) Count() int {
+func (p *RedisProvider) Count() (int, error) {
size, err := p.c.DBSize(graceful.GetManager().HammerContext()).Result()
- if err != nil {
- return 0
- }
- return int(size)
+ return int(size), err
}
// GC calls GC to clean expired sessions.
diff --git a/modules/session/virtual.go b/modules/session/virtual.go
index 2e29b5fc6f..597b9e55c1 100644
--- a/modules/session/virtual.go
+++ b/modules/session/virtual.go
@@ -59,17 +59,18 @@ func (o *VirtualSessionProvider) Init(gcLifetime int64, config string) error {
func (o *VirtualSessionProvider) Read(sid string) (session.RawStore, error) {
o.lock.RLock()
defer o.lock.RUnlock()
- if o.provider.Exist(sid) {
+ if exist, err := o.provider.Exist(sid); err == nil && exist {
return o.provider.Read(sid)
+ } else if err != nil {
+ return nil, fmt.Errorf("check if '%s' exist failed: %w", sid, err)
}
kv := make(map[any]any)
- kv["_old_uid"] = "0"
return NewVirtualStore(o, sid, kv), nil
}
// Exist returns true if session with given ID exists.
-func (o *VirtualSessionProvider) Exist(sid string) bool {
- return true
+func (o *VirtualSessionProvider) Exist(sid string) (bool, error) {
+ return true, nil
}
// Destroy deletes a session by session ID.
@@ -87,7 +88,7 @@ func (o *VirtualSessionProvider) Regenerate(oldsid, sid string) (session.RawStor
}
// Count counts and returns number of sessions.
-func (o *VirtualSessionProvider) Count() int {
+func (o *VirtualSessionProvider) Count() (int, error) {
o.lock.RLock()
defer o.lock.RUnlock()
return o.provider.Count()
@@ -158,13 +159,17 @@ func (s *VirtualStore) Release() error {
// Now need to lock the provider
s.p.lock.Lock()
defer s.p.lock.Unlock()
- if oldUID, ok := s.data["_old_uid"]; (ok && (oldUID != "0" || len(s.data) > 1)) || (!ok && len(s.data) > 0) {
+ if len(s.data) > 0 {
// Now ensure that we don't exist!
realProvider := s.p.provider
- if !s.released && realProvider.Exist(s.sid) {
- // This is an error!
- return fmt.Errorf("new sid '%s' already exists", s.sid)
+ if !s.released {
+ if exist, err := realProvider.Exist(s.sid); err == nil && exist {
+ // This is an error!
+ return fmt.Errorf("new sid '%s' already exists", s.sid)
+ } else if err != nil {
+ return fmt.Errorf("check if '%s' exist failed: %w", s.sid, err)
+ }
}
realStore, err := realProvider.Read(s.sid)
if err != nil {
diff --git a/modules/setting/actions.go b/modules/setting/actions.go
index 34346b62cf..7a91ecb593 100644
--- a/modules/setting/actions.go
+++ b/modules/setting/actions.go
@@ -4,6 +4,7 @@
package setting
import (
+ "errors"
"fmt"
"strings"
"time"
@@ -25,10 +26,12 @@ var (
EndlessTaskTimeout time.Duration `ini:"ENDLESS_TASK_TIMEOUT"`
AbandonedJobTimeout time.Duration `ini:"ABANDONED_JOB_TIMEOUT"`
SkipWorkflowStrings []string `ini:"SKIP_WORKFLOW_STRINGS"`
+ WorkflowDirs []string `ini:"WORKFLOW_DIRS"`
}{
Enabled: true,
DefaultActionsURL: defaultActionsURLGitHub,
SkipWorkflowStrings: []string{"[skip ci]", "[ci skip]", "[no ci]", "[skip actions]", "[actions skip]"},
+ WorkflowDirs: []string{".gitea/workflows", ".github/workflows"},
}
)
@@ -119,5 +122,20 @@ func loadActionsFrom(rootCfg ConfigProvider) error {
return fmt.Errorf("invalid [actions] LOG_COMPRESSION: %q", Actions.LogCompression)
}
+ workflowDirs := make([]string, 0, len(Actions.WorkflowDirs))
+ for _, dir := range Actions.WorkflowDirs {
+ dir = strings.TrimSpace(dir)
+ if dir == "" {
+ continue
+ }
+ dir = strings.ReplaceAll(dir, `\`, `/`)
+ dir = strings.TrimRight(dir, "/")
+ workflowDirs = append(workflowDirs, dir)
+ }
+ if len(workflowDirs) == 0 {
+ return errors.New("[actions] WORKFLOW_DIRS must contain at least one entry")
+ }
+ Actions.WorkflowDirs = workflowDirs
+
return nil
}
diff --git a/modules/setting/actions_test.go b/modules/setting/actions_test.go
index 353cc657fa..5c7ab268c1 100644
--- a/modules/setting/actions_test.go
+++ b/modules/setting/actions_test.go
@@ -97,6 +97,65 @@ STORAGE_TYPE = minio
assert.Equal(t, "actions_artifacts", filepath.Base(Actions.ArtifactStorage.Path))
}
+func Test_WorkflowDirs(t *testing.T) {
+ oldActions := Actions
+ defer func() {
+ Actions = oldActions
+ }()
+
+ tests := []struct {
+ name string
+ iniStr string
+ wantDirs []string
+ wantErr bool
+ }{
+ {
+ name: "default",
+ iniStr: `[actions]`,
+ wantDirs: []string{".gitea/workflows", ".github/workflows"},
+ },
+ {
+ name: "single dir",
+ iniStr: "[actions]\nWORKFLOW_DIRS = .github/workflows",
+ wantDirs: []string{".github/workflows"},
+ },
+ {
+ name: "custom order",
+ iniStr: "[actions]\nWORKFLOW_DIRS = .github/workflows,.gitea/workflows",
+ wantDirs: []string{".github/workflows", ".gitea/workflows"},
+ },
+ {
+ name: "whitespace trimming",
+ iniStr: "[actions]\nWORKFLOW_DIRS = .gitea/workflows , .github/workflows ",
+ wantDirs: []string{".gitea/workflows", ".github/workflows"},
+ },
+ {
+ name: "trailing slash normalization",
+ iniStr: "[actions]\nWORKFLOW_DIRS = .gitea/workflows/,.github/workflows/",
+ wantDirs: []string{".gitea/workflows", ".github/workflows"},
+ },
+ {
+ name: "only commas and whitespace",
+ iniStr: "[actions]\nWORKFLOW_DIRS = , , ,",
+ wantErr: true,
+ },
+ }
+
+ for _, tt := range tests {
+ t.Run(tt.name, func(t *testing.T) {
+ cfg, err := NewConfigProviderFromData(tt.iniStr)
+ require.NoError(t, err)
+ err = loadActionsFrom(cfg)
+ if tt.wantErr {
+ require.Error(t, err)
+ return
+ }
+ require.NoError(t, err)
+ assert.Equal(t, tt.wantDirs, Actions.WorkflowDirs)
+ })
+ }
+}
+
func Test_getDefaultActionsURLForActions(t *testing.T) {
oldActions := Actions
oldAppURL := AppURL
diff --git a/modules/setting/admin.go b/modules/setting/admin.go
index fde291ade9..782c73f0cc 100644
--- a/modules/setting/admin.go
+++ b/modules/setting/admin.go
@@ -5,6 +5,7 @@ package setting
import (
"code.gitea.io/gitea/modules/container"
+ "code.gitea.io/gitea/modules/log"
)
// Admin settings
@@ -15,12 +16,33 @@ var Admin struct {
ExternalUserDisableFeatures container.Set[string]
}
+var validUserFeatures = container.SetOf(
+ UserFeatureDeletion,
+ UserFeatureManageSSHKeys,
+ UserFeatureManageGPGKeys,
+ UserFeatureManageMFA,
+ UserFeatureManageCredentials,
+ UserFeatureChangeUsername,
+ UserFeatureChangeFullName,
+)
+
func loadAdminFrom(rootCfg ConfigProvider) {
sec := rootCfg.Section("admin")
Admin.DisableRegularOrgCreation = sec.Key("DISABLE_REGULAR_ORG_CREATION").MustBool(false)
Admin.DefaultEmailNotification = sec.Key("DEFAULT_EMAIL_NOTIFICATIONS").MustString("enabled")
Admin.UserDisabledFeatures = container.SetOf(sec.Key("USER_DISABLED_FEATURES").Strings(",")...)
Admin.ExternalUserDisableFeatures = container.SetOf(sec.Key("EXTERNAL_USER_DISABLE_FEATURES").Strings(",")...).Union(Admin.UserDisabledFeatures)
+
+ for feature := range Admin.UserDisabledFeatures {
+ if !validUserFeatures.Contains(feature) {
+ log.Warn("USER_DISABLED_FEATURES contains unknown feature %q", feature)
+ }
+ }
+ for feature := range Admin.ExternalUserDisableFeatures {
+ if !validUserFeatures.Contains(feature) && !Admin.UserDisabledFeatures.Contains(feature) {
+ log.Warn("EXTERNAL_USER_DISABLE_FEATURES contains unknown feature %q", feature)
+ }
+ }
}
const (
diff --git a/modules/setting/attachment.go b/modules/setting/attachment.go
index 5d420c987c..30e5cfbff1 100644
--- a/modules/setting/attachment.go
+++ b/modules/setting/attachment.go
@@ -16,13 +16,9 @@ var Attachment AttachmentSettingType
func loadAttachmentFrom(rootCfg ConfigProvider) (err error) {
Attachment = AttachmentSettingType{
AllowedTypes: ".avif,.cpuprofile,.csv,.dmp,.docx,.fodg,.fodp,.fods,.fodt,.gif,.gz,.jpeg,.jpg,.json,.jsonc,.log,.md,.mov,.mp4,.odf,.odg,.odp,.ods,.odt,.patch,.pdf,.png,.pptx,.svg,.tgz,.txt,.webm,.webp,.xls,.xlsx,.zip",
-
- // FIXME: this size is used for both "issue attachment" and "release attachment"
- // The design is not right, these two should be different settings
- MaxSize: 2048,
-
- MaxFiles: 5,
- Enabled: true,
+ MaxSize: 100,
+ MaxFiles: 5,
+ Enabled: true,
}
sec, _ := rootCfg.GetSection("attachment")
if sec == nil {
diff --git a/modules/setting/config.go b/modules/setting/config.go
index 4c5d2df7d8..a41734a843 100644
--- a/modules/setting/config.go
+++ b/modules/setting/config.go
@@ -4,6 +4,7 @@
package setting
import (
+ "strings"
"sync"
"code.gitea.io/gitea/modules/log"
@@ -11,8 +12,8 @@ import (
)
type PictureStruct struct {
- DisableGravatar *config.Value[bool]
- EnableFederatedAvatar *config.Value[bool]
+ DisableGravatar *config.Option[bool]
+ EnableFederatedAvatar *config.Option[bool]
}
type OpenWithEditorApp struct {
@@ -22,15 +23,18 @@ type OpenWithEditorApp struct {
type OpenWithEditorAppsType []OpenWithEditorApp
+// ToTextareaString is only used in templates, for help prompt only
+// TODO: OPEN-WITH-EDITOR-APP-JSON: Because there is no "rich UI", a plain text editor is used to manage the list of apps
+// Maybe we can use some better formats like Yaml in the future, then a simple textarea can manage the config clearly
func (t OpenWithEditorAppsType) ToTextareaString() string {
- ret := ""
+ var ret strings.Builder
for _, app := range t {
- ret += app.DisplayName + " = " + app.OpenURL + "\n"
+ ret.WriteString(app.DisplayName + " = " + app.OpenURL + "\n")
}
- return ret
+ return ret.String()
}
-func DefaultOpenWithEditorApps() OpenWithEditorAppsType {
+func openWithEditorAppsDefaultValue() OpenWithEditorAppsType {
return OpenWithEditorAppsType{
{
DisplayName: "VS Code",
@@ -48,13 +52,14 @@ func DefaultOpenWithEditorApps() OpenWithEditorAppsType {
}
type RepositoryStruct struct {
- OpenWithEditorApps *config.Value[OpenWithEditorAppsType]
- GitGuideRemoteName *config.Value[string]
+ OpenWithEditorApps *config.Option[OpenWithEditorAppsType]
+ GitGuideRemoteName *config.Option[string]
}
type ConfigStruct struct {
Picture *PictureStruct
Repository *RepositoryStruct
+ Instance *InstanceStruct
}
var (
@@ -66,12 +71,16 @@ func initDefaultConfig() {
config.SetCfgSecKeyGetter(&cfgSecKeyGetter{})
defaultConfig = &ConfigStruct{
Picture: &PictureStruct{
- DisableGravatar: config.ValueJSON[bool]("picture.disable_gravatar").WithFileConfig(config.CfgSecKey{Sec: "picture", Key: "DISABLE_GRAVATAR"}),
- EnableFederatedAvatar: config.ValueJSON[bool]("picture.enable_federated_avatar").WithFileConfig(config.CfgSecKey{Sec: "picture", Key: "ENABLE_FEDERATED_AVATAR"}),
+ DisableGravatar: config.NewOption[bool]("picture.disable_gravatar").WithDefaultSimple(true).WithFileConfig(config.CfgSecKey{Sec: "picture", Key: "DISABLE_GRAVATAR"}),
+ EnableFederatedAvatar: config.NewOption[bool]("picture.enable_federated_avatar").WithFileConfig(config.CfgSecKey{Sec: "picture", Key: "ENABLE_FEDERATED_AVATAR"}),
},
Repository: &RepositoryStruct{
- OpenWithEditorApps: config.ValueJSON[OpenWithEditorAppsType]("repository.open-with.editor-apps"),
- GitGuideRemoteName: config.ValueJSON[string]("repository.git-guide-remote-name").WithDefault("origin"),
+ OpenWithEditorApps: config.NewOption[OpenWithEditorAppsType]("repository.open-with.editor-apps").WithEmptyAsDefault().WithDefaultFunc(openWithEditorAppsDefaultValue),
+ GitGuideRemoteName: config.NewOption[string]("repository.git-guide-remote-name").WithEmptyAsDefault().WithDefaultSimple("origin"),
+ },
+ Instance: &InstanceStruct{
+ WebBanner: config.NewOption[WebBannerType]("instance.web_banner"),
+ MaintenanceMode: config.NewOption[MaintenanceModeType]("instance.maintenance_mode"),
},
}
}
diff --git a/modules/setting/config/value.go b/modules/setting/config/value.go
index 301c60f5e8..c01f41303c 100644
--- a/modules/setting/config/value.go
+++ b/modules/setting/config/value.go
@@ -5,6 +5,7 @@ package config
import (
"context"
+ "reflect"
"sync"
"code.gitea.io/gitea/modules/json"
@@ -16,18 +17,31 @@ type CfgSecKey struct {
Sec, Key string
}
-type Value[T any] struct {
+// OptionInterface is used to overcome Golang's generic interface limitation
+type OptionInterface interface {
+ GetDefaultValue() any
+}
+
+type Option[T any] struct {
mu sync.RWMutex
cfgSecKey CfgSecKey
dynKey string
- def, value T
+ value T
+ defSimple T
+ defFunc func() T
+ emptyAsDef bool
+ has bool
revision int
}
-func (value *Value[T]) parse(key, valStr string) (v T) {
- v = value.def
+func (opt *Option[T]) GetDefaultValue() any {
+ return opt.DefaultValue()
+}
+
+func (opt *Option[T]) parse(key, valStr string) (v T) {
+ v = opt.DefaultValue()
if valStr != "" {
if err := json.Unmarshal(util.UnsafeStringToBytes(valStr), &v); err != nil {
log.Error("Unable to unmarshal json config for key %q, err: %v", key, err)
@@ -36,7 +50,35 @@ func (value *Value[T]) parse(key, valStr string) (v T) {
return v
}
-func (value *Value[T]) Value(ctx context.Context) (v T) {
+func (opt *Option[T]) HasValue(ctx context.Context) bool {
+ _, _, has := opt.ValueRevision(ctx)
+ return has
+}
+
+func (opt *Option[T]) Value(ctx context.Context) (v T) {
+ v, _, _ = opt.ValueRevision(ctx)
+ return v
+}
+
+func isZeroOrEmpty(v any) bool {
+ if v == nil {
+ return true // interface itself is nil
+ }
+ r := reflect.ValueOf(v)
+ if r.IsZero() {
+ return true
+ }
+
+ if r.Kind() == reflect.Slice || r.Kind() == reflect.Map {
+ if r.IsNil() {
+ return true
+ }
+ return r.Len() == 0
+ }
+ return false
+}
+
+func (opt *Option[T]) ValueRevision(ctx context.Context) (v T, rev int, has bool) {
dg := GetDynGetter()
if dg == nil {
// this is an edge case: the database is not initialized but the system setting is going to be used
@@ -44,55 +86,96 @@ func (value *Value[T]) Value(ctx context.Context) (v T) {
panic("no config dyn value getter")
}
- rev := dg.GetRevision(ctx)
+ rev = dg.GetRevision(ctx)
// if the revision in the database doesn't change, use the last value
- value.mu.RLock()
- if rev == value.revision {
- v = value.value
- value.mu.RUnlock()
- return v
+ opt.mu.RLock()
+ if rev == opt.revision {
+ v = opt.value
+ has = opt.has
+ opt.mu.RUnlock()
+ return v, rev, has
}
- value.mu.RUnlock()
+ opt.mu.RUnlock()
// try to parse the config and cache it
var valStr *string
- if dynVal, has := dg.GetValue(ctx, value.dynKey); has {
+ if dynVal, hasDbValue := dg.GetValue(ctx, opt.dynKey); hasDbValue {
valStr = &dynVal
- } else if cfgVal, has := GetCfgSecKeyGetter().GetValue(value.cfgSecKey.Sec, value.cfgSecKey.Key); has {
+ } else if cfgVal, hasCfgValue := GetCfgSecKeyGetter().GetValue(opt.cfgSecKey.Sec, opt.cfgSecKey.Key); hasCfgValue {
valStr = &cfgVal
}
if valStr == nil {
- v = value.def
+ v = opt.DefaultValue()
+ has = false
} else {
- v = value.parse(value.dynKey, *valStr)
+ v = opt.parse(opt.dynKey, *valStr)
+ if opt.emptyAsDef && isZeroOrEmpty(v) {
+ v = opt.DefaultValue()
+ } else {
+ has = true
+ }
}
- value.mu.Lock()
- value.value = v
- value.revision = rev
- value.mu.Unlock()
- return v
+ opt.mu.Lock()
+ opt.value = v
+ opt.revision = rev
+ opt.has = has
+ opt.mu.Unlock()
+ return v, rev, has
+}
+
+func (opt *Option[T]) DynKey() string {
+ return opt.dynKey
+}
+
+// WithDefaultFunc sets the default value with a function
+// The "def" value might be changed during runtime (e.g.: Unmarshal with default), so it shouldn't use the same pointer or slice
+func (opt *Option[T]) WithDefaultFunc(f func() T) *Option[T] {
+ opt.defFunc = f
+ return opt
}
-func (value *Value[T]) DynKey() string {
- return value.dynKey
+func (opt *Option[T]) WithDefaultSimple(def T) *Option[T] {
+ v := any(def)
+ switch v.(type) {
+ case string, bool, int, int8, int16, int32, int64, uint, uint8, uint16, uint32, uint64:
+ default:
+ // TODO: use reflect to support convertible basic types like `type State string`
+ r := reflect.ValueOf(v)
+ if r.Kind() != reflect.Struct {
+ panic("invalid type for default value, use WithDefaultFunc instead")
+ }
+ }
+ opt.defSimple = def
+ return opt
}
-func (value *Value[T]) WithDefault(def T) *Value[T] {
- value.def = def
- return value
+func (opt *Option[T]) WithEmptyAsDefault() *Option[T] {
+ opt.emptyAsDef = true
+ return opt
}
-func (value *Value[T]) DefaultValue() T {
- return value.def
+func (opt *Option[T]) DefaultValue() T {
+ if opt.defFunc != nil {
+ return opt.defFunc()
+ }
+ return opt.defSimple
}
-func (value *Value[T]) WithFileConfig(cfgSecKey CfgSecKey) *Value[T] {
- value.cfgSecKey = cfgSecKey
- return value
+func (opt *Option[T]) WithFileConfig(cfgSecKey CfgSecKey) *Option[T] {
+ opt.cfgSecKey = cfgSecKey
+ return opt
+}
+
+var allConfigOptions = map[string]OptionInterface{}
+
+func NewOption[T any](dynKey string) *Option[T] {
+ v := &Option[T]{dynKey: dynKey}
+ allConfigOptions[dynKey] = v
+ return v
}
-func ValueJSON[T any](dynKey string) *Value[T] {
- return &Value[T]{dynKey: dynKey}
+func GetConfigOption(dynKey string) OptionInterface {
+ return allConfigOptions[dynKey]
}
diff --git a/modules/setting/config_env.go b/modules/setting/config_env.go
index 409588dc44..e956e34439 100644
--- a/modules/setting/config_env.go
+++ b/modules/setting/config_env.go
@@ -51,10 +51,10 @@ func decodeEnvSectionKey(encoded string) (ok bool, section, key string) {
for _, unescapeIdx := range escapeStringIndices {
preceding := encoded[last:unescapeIdx[0]]
if !inKey {
- if splitter := strings.Index(preceding, "__"); splitter > -1 {
- section += preceding[:splitter]
+ if before, after, cutOk := strings.Cut(preceding, "__"); cutOk {
+ section += before
inKey = true
- key += preceding[splitter+2:]
+ key += after
} else {
section += preceding
}
@@ -65,7 +65,7 @@ func decodeEnvSectionKey(encoded string) (ok bool, section, key string) {
decodedBytes := make([]byte, len(toDecode)/2)
for i := 0; i < len(toDecode)/2; i++ {
// Can ignore error here as we know these should be hexadecimal from the regexp
- byteInt, _ := strconv.ParseInt(toDecode[2*i:2*i+2], 16, 0)
+ byteInt, _ := strconv.ParseInt(toDecode[2*i:2*i+2], 16, 8)
decodedBytes[i] = byte(byteInt)
}
if inKey {
@@ -77,9 +77,9 @@ func decodeEnvSectionKey(encoded string) (ok bool, section, key string) {
}
remaining := encoded[last:]
if !inKey {
- if splitter := strings.Index(remaining, "__"); splitter > -1 {
- section += remaining[:splitter]
- key += remaining[splitter+2:]
+ if before, after, cutOk := strings.Cut(remaining, "__"); cutOk {
+ section += before
+ key += after
} else {
section += remaining
}
@@ -111,21 +111,21 @@ func decodeEnvironmentKey(prefixGitea, suffixFile, envKey string) (ok bool, sect
func EnvironmentToConfig(cfg ConfigProvider, envs []string) (changed bool) {
for _, kv := range envs {
- idx := strings.IndexByte(kv, '=')
- if idx < 0 {
+ before, after, ok := strings.Cut(kv, "=")
+ if !ok {
continue
}
// parse the environment variable to config section name and key name
- envKey := kv[:idx]
- envValue := kv[idx+1:]
+ envKey := before
+ envValue := after
ok, sectionName, keyName, useFileValue := decodeEnvironmentKey(EnvConfigKeyPrefixGitea, EnvConfigKeySuffixFile, envKey)
if !ok {
continue
}
// use environment value as config value, or read the file content as value if the key indicates a file
- keyValue := envValue
+ keyValue := envValue //nolint:staticcheck // false positive
if useFileValue {
fileContent, err := os.ReadFile(envValue)
if err != nil {
@@ -167,24 +167,13 @@ func EnvironmentToConfig(cfg ConfigProvider, envs []string) (changed bool) {
return changed
}
-// InitGiteaEnvVars initializes the environment variables for gitea
-func InitGiteaEnvVars() {
+func UnsetUnnecessaryEnvVars() {
// Ideally Gitea should only accept the environment variables which it clearly knows instead of unsetting the ones it doesn't want,
- // but the ideal behavior would be a breaking change, and it seems not bringing enough benefits to end users,
- // so at the moment we could still keep "unsetting the unnecessary environments"
+ // but the ideal behavior would be a breaking change, and it seems not bringing enough benefits to end users.
+ // So at the moment we just keep "unsetting the unnecessary environment variables".
// HOME is managed by Gitea, Gitea's git should use "HOME/.gitconfig".
// But git would try "XDG_CONFIG_HOME/git/config" first if "HOME/.gitconfig" does not exist,
// then our git.InitFull would still write to "XDG_CONFIG_HOME/git/config" if XDG_CONFIG_HOME is set.
_ = os.Unsetenv("XDG_CONFIG_HOME")
}
-
-func InitGiteaEnvVarsForTesting() {
- InitGiteaEnvVars()
- _ = os.Unsetenv("GIT_AUTHOR_NAME")
- _ = os.Unsetenv("GIT_AUTHOR_EMAIL")
- _ = os.Unsetenv("GIT_AUTHOR_DATE")
- _ = os.Unsetenv("GIT_COMMITTER_NAME")
- _ = os.Unsetenv("GIT_COMMITTER_EMAIL")
- _ = os.Unsetenv("GIT_COMMITTER_DATE")
-}
diff --git a/modules/setting/config_option_instance.go b/modules/setting/config_option_instance.go
new file mode 100644
index 0000000000..6d97055a75
--- /dev/null
+++ b/modules/setting/config_option_instance.go
@@ -0,0 +1,58 @@
+// Copyright 2026 The Gitea Authors. All rights reserved.
+// SPDX-License-Identifier: MIT
+
+package setting
+
+import (
+ "time"
+
+ "code.gitea.io/gitea/modules/setting/config"
+)
+
+// WebBannerType fields are directly used in templates,
+// do remember to update the template if you change the fields
+type WebBannerType struct {
+ DisplayEnabled bool
+ ContentMessage string
+ StartTimeUnix int64
+ EndTimeUnix int64
+}
+
+func (b WebBannerType) ShouldDisplay() bool {
+ if !b.DisplayEnabled || b.ContentMessage == "" {
+ return false
+ }
+ now := time.Now().Unix()
+ if b.StartTimeUnix > 0 && now < b.StartTimeUnix {
+ return false
+ }
+ if b.EndTimeUnix > 0 && now > b.EndTimeUnix {
+ return false
+ }
+ return true
+}
+
+type MaintenanceModeType struct {
+ AdminWebAccessOnly bool
+ StartTimeUnix int64
+ EndTimeUnix int64
+}
+
+func (m MaintenanceModeType) IsActive() bool {
+ if !m.AdminWebAccessOnly {
+ return false
+ }
+ now := time.Now().Unix()
+ if m.StartTimeUnix > 0 && now < m.StartTimeUnix {
+ return false
+ }
+ if m.EndTimeUnix > 0 && now > m.EndTimeUnix {
+ return false
+ }
+ return true
+}
+
+type InstanceStruct struct {
+ WebBanner *config.Option[WebBannerType]
+ MaintenanceMode *config.Option[MaintenanceModeType]
+}
diff --git a/modules/setting/config_provider.go b/modules/setting/config_provider.go
index e9e051e56d..a734f3bf8f 100644
--- a/modules/setting/config_provider.go
+++ b/modules/setting/config_provider.go
@@ -41,6 +41,7 @@ type ConfigSection interface {
HasKey(key string) bool
NewKey(name, value string) (ConfigKey, error)
Key(key string) ConfigKey
+ DeleteKey(key string)
Keys() []ConfigKey
ChildSections() []ConfigSection
}
@@ -51,6 +52,7 @@ type ConfigProvider interface {
Sections() []ConfigSection
NewSection(name string) (ConfigSection, error)
GetSection(name string) (ConfigSection, error)
+ DeleteSection(name string)
Save() error
SaveTo(filename string) error
@@ -168,6 +170,10 @@ func (s *iniConfigSection) Keys() (keys []ConfigKey) {
return keys
}
+func (s *iniConfigSection) DeleteKey(key string) {
+ s.sec.DeleteKey(key)
+}
+
func (s *iniConfigSection) ChildSections() (sections []ConfigSection) {
for _, s := range s.sec.ChildSections() {
sections = append(sections, &iniConfigSection{s})
@@ -249,6 +255,10 @@ func (p *iniConfigProvider) GetSection(name string) (ConfigSection, error) {
return &iniConfigSection{sec: sec}, nil
}
+func (p *iniConfigProvider) DeleteSection(name string) {
+ p.ini.DeleteSection(name)
+}
+
var errDisableSaving = errors.New("this config can't be saved, developers should prepare a new config to save")
// Save saves the content into file
@@ -338,23 +348,6 @@ func deprecatedSettingDB(rootCfg ConfigProvider, oldSection, oldKey string) {
}
}
-// NewConfigProviderForLocale loads locale configuration from source and others. "string" if for a local file path, "[]byte" is for INI content
-func NewConfigProviderForLocale(source any, others ...any) (ConfigProvider, error) {
- iniFile, err := ini.LoadSources(ini.LoadOptions{
- IgnoreInlineComment: true,
- UnescapeValueCommentSymbols: true,
- IgnoreContinuation: true,
- }, source, others...)
- if err != nil {
- return nil, fmt.Errorf("unable to load locale ini: %w", err)
- }
- iniFile.BlockMode = false
- return &iniConfigProvider{
- ini: iniFile,
- loadedFromEmpty: true,
- }, nil
-}
-
func init() {
ini.PrettyFormat = false
}
diff --git a/modules/setting/config_provider_test.go b/modules/setting/config_provider_test.go
index 63121f0074..dcbe280e82 100644
--- a/modules/setting/config_provider_test.go
+++ b/modules/setting/config_provider_test.go
@@ -113,24 +113,6 @@ func TestNewConfigProviderFromFile(t *testing.T) {
assert.Equal(t, "[foo]\nk1 = a\n\n[bar]\nk1 = b\n", string(bs))
}
-func TestNewConfigProviderForLocale(t *testing.T) {
- // load locale from file
- localeFile := t.TempDir() + "/locale.ini"
- _ = os.WriteFile(localeFile, []byte(`k1=a`), 0o644)
- cfg, err := NewConfigProviderForLocale(localeFile)
- assert.NoError(t, err)
- assert.Equal(t, "a", cfg.Section("").Key("k1").String())
-
- // load locale from bytes
- cfg, err = NewConfigProviderForLocale([]byte("k1=foo\nk2=bar"))
- assert.NoError(t, err)
- assert.Equal(t, "foo", cfg.Section("").Key("k1").String())
- cfg, err = NewConfigProviderForLocale([]byte("k1=foo\nk2=bar"), []byte("k2=xxx"))
- assert.NoError(t, err)
- assert.Equal(t, "foo", cfg.Section("").Key("k1").String())
- assert.Equal(t, "xxx", cfg.Section("").Key("k2").String())
-}
-
func TestDisableSaving(t *testing.T) {
testFile := t.TempDir() + "/test.ini"
_ = os.WriteFile(testFile, []byte("k1=a\nk2=b"), 0o644)
diff --git a/modules/setting/cors.go b/modules/setting/cors.go
index 5260887d9d..a4906b8ae3 100644
--- a/modules/setting/cors.go
+++ b/modules/setting/cors.go
@@ -15,13 +15,11 @@ var CORSConfig = struct {
MaxAge time.Duration
AllowCredentials bool
Headers []string
- XFrameOptions string
}{
- AllowDomain: []string{"*"},
- Methods: []string{"GET", "HEAD", "POST", "PUT", "PATCH", "DELETE", "OPTIONS"},
- Headers: []string{"Content-Type", "User-Agent"},
- MaxAge: 10 * time.Minute,
- XFrameOptions: "SAMEORIGIN",
+ AllowDomain: []string{"*"},
+ Methods: []string{"GET", "HEAD", "POST", "PUT", "PATCH", "DELETE", "OPTIONS"},
+ Headers: []string{"Content-Type", "User-Agent"},
+ MaxAge: 10 * time.Minute,
}
func loadCorsFrom(rootCfg ConfigProvider) {
diff --git a/modules/setting/git.go b/modules/setting/git.go
index 48a4e7f30d..29fd3daf8a 100644
--- a/modules/setting/git.go
+++ b/modules/setting/git.go
@@ -5,6 +5,7 @@ package setting
import (
"path/filepath"
+ "regexp"
"strings"
"time"
@@ -17,54 +18,47 @@ var Git = struct {
HomePath string
DisableDiffHighlight bool
- MaxGitDiffLines int
- MaxGitDiffLineCharacters int
- MaxGitDiffFiles int
- CommitsRangeSize int // CommitsRangeSize the default commits range size
- BranchesRangeSize int // BranchesRangeSize the default branches range size
- VerbosePush bool
- VerbosePushDelay time.Duration
- GCArgs []string `ini:"GC_ARGS" delim:" "`
- EnableAutoGitWireProtocol bool
- PullRequestPushMessage bool
- LargeObjectThreshold int64
- DisableCoreProtectNTFS bool
- DisablePartialClone bool
- Timeout struct {
- Default int
+ MaxGitDiffLines int
+ MaxGitDiffLineCharacters int
+ MaxGitDiffFiles int
+ CommitsRangeSize int // CommitsRangeSize the default commits range size
+ BranchesRangeSize int // BranchesRangeSize the default branches range size
+ VerbosePush bool
+ VerbosePushDelay time.Duration
+ GCArgs []string `ini:"GC_ARGS" delim:" "`
+ EnableAutoGitWireProtocol bool
+ PullRequestPushMessage bool
+ LargeObjectThreshold int64
+ DisableCoreProtectNTFS bool
+ DisablePartialClone bool
+ DiffRenameSimilarityThreshold string
+ Timeout struct {
Migrate int
Mirror int
- Clone int
- Pull int
GC int `ini:"GC"`
} `ini:"git.timeout"`
}{
- DisableDiffHighlight: false,
- MaxGitDiffLines: 1000,
- MaxGitDiffLineCharacters: 5000,
- MaxGitDiffFiles: 100,
- CommitsRangeSize: 50,
- BranchesRangeSize: 20,
- VerbosePush: true,
- VerbosePushDelay: 5 * time.Second,
- GCArgs: []string{},
- EnableAutoGitWireProtocol: true,
- PullRequestPushMessage: true,
- LargeObjectThreshold: 1024 * 1024,
- DisablePartialClone: false,
+ DisableDiffHighlight: false,
+ MaxGitDiffLines: 1000,
+ MaxGitDiffLineCharacters: 5000,
+ MaxGitDiffFiles: 100,
+ CommitsRangeSize: 50,
+ BranchesRangeSize: 20,
+ VerbosePush: true,
+ VerbosePushDelay: 5 * time.Second,
+ GCArgs: []string{},
+ EnableAutoGitWireProtocol: true,
+ PullRequestPushMessage: true,
+ LargeObjectThreshold: 1024 * 1024,
+ DisablePartialClone: false,
+ DiffRenameSimilarityThreshold: "50%",
Timeout: struct {
- Default int
Migrate int
Mirror int
- Clone int
- Pull int
GC int `ini:"GC"`
}{
- Default: 360,
Migrate: 600,
Mirror: 300,
- Clone: 300,
- Pull: 300,
GC: 60,
},
}
@@ -117,4 +111,9 @@ func loadGitFrom(rootCfg ConfigProvider) {
} else {
Git.HomePath = filepath.Clean(Git.HomePath)
}
+
+ // validate for a integer percentage between 0% and 100%
+ if !regexp.MustCompile(`^([0-9]|[1-9][0-9]|100)%$`).MatchString(Git.DiffRenameSimilarityThreshold) {
+ log.Fatal("Invalid git.DIFF_RENAME_SIMILARITY_THRESHOLD: %s", Git.DiffRenameSimilarityThreshold)
+ }
}
diff --git a/modules/setting/incoming_email.go b/modules/setting/incoming_email.go
index 4e433dde60..bf9f7f9776 100644
--- a/modules/setting/incoming_email.go
+++ b/modules/setting/incoming_email.go
@@ -12,10 +12,11 @@ import (
"code.gitea.io/gitea/modules/log"
)
+const IncomingEmailTokenPlaceholder = "%{token}"
+
var IncomingEmail = struct {
Enabled bool
ReplyToAddress string
- TokenPlaceholder string `ini:"-"`
Host string
Port int
UseTLS bool `ini:"USE_TLS"`
@@ -28,7 +29,6 @@ var IncomingEmail = struct {
}{
Mailbox: "INBOX",
DeleteHandledMessage: true,
- TokenPlaceholder: "%{token}",
MaximumMessageSize: 10485760,
}
@@ -54,19 +54,10 @@ func checkReplyToAddress() error {
return errors.New("name must not be set")
}
- c := strings.Count(IncomingEmail.ReplyToAddress, IncomingEmail.TokenPlaceholder)
- switch c {
- case 0:
- return fmt.Errorf("%s must appear in the user part of the address (before the @)", IncomingEmail.TokenPlaceholder)
- case 1:
- default:
- return fmt.Errorf("%s must appear only once", IncomingEmail.TokenPlaceholder)
- }
-
- parts := strings.Split(IncomingEmail.ReplyToAddress, "@")
- if !strings.Contains(parts[0], IncomingEmail.TokenPlaceholder) {
- return fmt.Errorf("%s must appear in the user part of the address (before the @)", IncomingEmail.TokenPlaceholder)
+ placeholderCount := strings.Count(IncomingEmail.ReplyToAddress, IncomingEmailTokenPlaceholder)
+ userPart, _, _ := strings.Cut(IncomingEmail.ReplyToAddress, "@")
+ if placeholderCount != 1 || !strings.Contains(userPart, IncomingEmailTokenPlaceholder) {
+ return fmt.Errorf("%s must appear in the user part of the address (before the @)", IncomingEmailTokenPlaceholder)
}
-
return nil
}
diff --git a/modules/setting/indexer_test.go b/modules/setting/indexer_test.go
index 8f0437be8a..498f8752a2 100644
--- a/modules/setting/indexer_test.go
+++ b/modules/setting/indexer_test.go
@@ -65,7 +65,7 @@ func checkGlobMatch(t *testing.T, globstr string, list []indexerMatchList) {
}
}
if !found {
- assert.Equal(t, m.position, -1, "Test string `%s` doesn't match `%s` anywhere; expected @%d", m.value, globstr, m.position)
+ assert.Equal(t, -1, m.position, "Test string `%s` doesn't match `%s` anywhere; expected @%d", m.value, globstr, m.position)
}
}
}
diff --git a/modules/setting/lfs.go b/modules/setting/lfs.go
index 7f2d0ae159..3ec21860ae 100644
--- a/modules/setting/lfs.go
+++ b/modules/setting/lfs.go
@@ -81,10 +81,7 @@ func loadLFSFrom(rootCfg ConfigProvider) error {
jwtSecretBase64 := loadSecret(rootCfg.Section("server"), "LFS_JWT_SECRET_URI", "LFS_JWT_SECRET")
LFS.JWTSecretBytes, err = generate.DecodeJwtSecretBase64(jwtSecretBase64)
if err != nil {
- LFS.JWTSecretBytes, jwtSecretBase64, err = generate.NewJwtSecretWithBase64()
- if err != nil {
- return fmt.Errorf("error generating JWT Secret for custom config: %v", err)
- }
+ LFS.JWTSecretBytes, jwtSecretBase64 = generate.NewJwtSecretWithBase64()
// Save secret
saveCfg, err := rootCfg.PrepareSaving()
diff --git a/modules/setting/mailer_test.go b/modules/setting/mailer_test.go
index ceef35b051..7e1c988568 100644
--- a/modules/setting/mailer_test.go
+++ b/modules/setting/mailer_test.go
@@ -6,17 +6,19 @@ package setting
import (
"testing"
+ "code.gitea.io/gitea/modules/test"
+
"github.com/stretchr/testify/assert"
)
func Test_loadMailerFrom(t *testing.T) {
kases := map[string]*Mailer{
- "smtp.mydomain.com": {
- SMTPAddr: "smtp.mydomain.com",
+ "smtp.mydomain.test": {
+ SMTPAddr: "smtp.mydomain.test",
SMTPPort: "465",
},
- "smtp.mydomain.com:123": {
- SMTPAddr: "smtp.mydomain.com",
+ "smtp.mydomain.test:123": {
+ SMTPAddr: "smtp.mydomain.test",
SMTPPort: "123",
},
":123": {
@@ -39,3 +41,30 @@ func Test_loadMailerFrom(t *testing.T) {
})
}
}
+
+func TestLoadSettingsForInstallMailServiceFlags(t *testing.T) {
+ defer test.MockVariableValue(&Service)()
+ defer test.MockVariableValue(&MailService)()
+
+ cfg, err := NewConfigProviderFromData(`
+[database]
+DB_TYPE = postgres
+
+[mailer]
+ENABLED = true
+SMTP_ADDR = 127.0.0.1
+SMTP_PORT = 465
+FROM = noreply@example.com
+
+[service]
+REGISTER_EMAIL_CONFIRM = true
+ENABLE_NOTIFY_MAIL = true
+`)
+ assert.NoError(t, err)
+ loadDBSetting(cfg)
+ loadServiceFrom(cfg)
+ loadMailsFrom(cfg)
+
+ assert.True(t, Service.RegisterEmailConfirm)
+ assert.True(t, Service.EnableNotifyMail)
+}
diff --git a/modules/setting/oauth2.go b/modules/setting/oauth2.go
index ae2a9d7bee..8e0210aa51 100644
--- a/modules/setting/oauth2.go
+++ b/modules/setting/oauth2.go
@@ -133,16 +133,13 @@ func loadOAuth2From(rootCfg ConfigProvider) {
// FIXME: at the moment, no matter oauth2 is enabled or not, it must generate a "oauth2 JWT_SECRET"
// Because this secret is also used as GeneralTokenSigningSecret (as a quick not-that-breaking fix for some legacy problems).
- // Including: CSRF token, account validation token, etc ...
+ // Including: account validation token, etc ...
// In main branch, the signing token should be refactored (eg: one unique for LFS/OAuth2/etc ...)
jwtSecretBase64 := loadSecret(sec, "JWT_SECRET_URI", "JWT_SECRET")
if InstallLock {
jwtSecretBytes, err := generate.DecodeJwtSecretBase64(jwtSecretBase64)
if err != nil {
- jwtSecretBytes, jwtSecretBase64, err = generate.NewJwtSecretWithBase64()
- if err != nil {
- log.Fatal("error generating JWT secret: %v", err)
- }
+ jwtSecretBytes, jwtSecretBase64 = generate.NewJwtSecretWithBase64()
saveCfg, err := rootCfg.PrepareSaving()
if err != nil {
log.Fatal("save oauth2.JWT_SECRET failed: %v", err)
@@ -162,10 +159,7 @@ var generalSigningSecret atomic.Pointer[[]byte]
func GetGeneralTokenSigningSecret() []byte {
old := generalSigningSecret.Load()
if old == nil || len(*old) == 0 {
- jwtSecret, _, err := generate.NewJwtSecretWithBase64()
- if err != nil {
- log.Fatal("Unable to generate general JWT secret: %v", err)
- }
+ jwtSecret, _ := generate.NewJwtSecretWithBase64()
if generalSigningSecret.CompareAndSwap(old, &jwtSecret) {
return jwtSecret
}
diff --git a/modules/setting/packages.go b/modules/setting/packages.go
index b598424064..38ee2ad55e 100644
--- a/modules/setting/packages.go
+++ b/modules/setting/packages.go
@@ -16,30 +16,31 @@ var (
Storage *Storage
Enabled bool
- LimitTotalOwnerCount int64
- LimitTotalOwnerSize int64
- LimitSizeAlpine int64
- LimitSizeArch int64
- LimitSizeCargo int64
- LimitSizeChef int64
- LimitSizeComposer int64
- LimitSizeConan int64
- LimitSizeConda int64
- LimitSizeContainer int64
- LimitSizeCran int64
- LimitSizeDebian int64
- LimitSizeGeneric int64
- LimitSizeGo int64
- LimitSizeHelm int64
- LimitSizeMaven int64
- LimitSizeNpm int64
- LimitSizeNuGet int64
- LimitSizePub int64
- LimitSizePyPI int64
- LimitSizeRpm int64
- LimitSizeRubyGems int64
- LimitSizeSwift int64
- LimitSizeVagrant int64
+ LimitTotalOwnerCount int64
+ LimitTotalOwnerSize int64
+ LimitSizeAlpine int64
+ LimitSizeArch int64
+ LimitSizeCargo int64
+ LimitSizeChef int64
+ LimitSizeComposer int64
+ LimitSizeConan int64
+ LimitSizeConda int64
+ LimitSizeContainer int64
+ LimitSizeCran int64
+ LimitSizeDebian int64
+ LimitSizeGeneric int64
+ LimitSizeGo int64
+ LimitSizeHelm int64
+ LimitSizeMaven int64
+ LimitSizeNpm int64
+ LimitSizeNuGet int64
+ LimitSizePub int64
+ LimitSizePyPI int64
+ LimitSizeRpm int64
+ LimitSizeRubyGems int64
+ LimitSizeSwift int64
+ LimitSizeTerraformState int64
+ LimitSizeVagrant int64
DefaultRPMSignEnabled bool
}{
@@ -86,6 +87,7 @@ func loadPackagesFrom(rootCfg ConfigProvider) (err error) {
Packages.LimitSizeRpm = mustBytes(sec, "LIMIT_SIZE_RPM")
Packages.LimitSizeRubyGems = mustBytes(sec, "LIMIT_SIZE_RUBYGEMS")
Packages.LimitSizeSwift = mustBytes(sec, "LIMIT_SIZE_SWIFT")
+ Packages.LimitSizeTerraformState = mustBytes(sec, "LIMIT_SIZE_TERRAFORM_STATE")
Packages.LimitSizeVagrant = mustBytes(sec, "LIMIT_SIZE_VAGRANT")
Packages.DefaultRPMSignEnabled = sec.Key("DEFAULT_RPM_SIGN_ENABLED").MustBool(false)
return nil
diff --git a/modules/setting/picture.go b/modules/setting/picture.go
index fafae45bab..d20a110b6c 100644
--- a/modules/setting/picture.go
+++ b/modules/setting/picture.go
@@ -22,9 +22,7 @@ var (
RenderedSizeFactor: 2,
}
- GravatarSource string
- DisableGravatar bool // Depreciated: migrated to database
- EnableFederatedAvatar bool // Depreciated: migrated to database
+ GravatarSource string
RepoAvatar = struct {
Storage *Storage
@@ -65,29 +63,12 @@ func loadAvatarsFrom(rootCfg ConfigProvider) error {
GravatarSource = source
}
- DisableGravatar = sec.Key("DISABLE_GRAVATAR").MustBool(GetDefaultDisableGravatar())
- deprecatedSettingDB(rootCfg, "", "DISABLE_GRAVATAR")
- EnableFederatedAvatar = sec.Key("ENABLE_FEDERATED_AVATAR").MustBool(GetDefaultEnableFederatedAvatar(DisableGravatar))
- deprecatedSettingDB(rootCfg, "", "ENABLE_FEDERATED_AVATAR")
+ deprecatedSettingDB(rootCfg, "picture", "DISABLE_GRAVATAR")
+ deprecatedSettingDB(rootCfg, "picture", "ENABLE_FEDERATED_AVATAR")
return nil
}
-func GetDefaultDisableGravatar() bool {
- return OfflineMode
-}
-
-func GetDefaultEnableFederatedAvatar(disableGravatar bool) bool {
- v := !InstallLock
- if OfflineMode {
- v = false
- }
- if disableGravatar {
- v = false
- }
- return v
-}
-
func loadRepoAvatarFrom(rootCfg ConfigProvider) error {
sec := rootCfg.Section("picture")
diff --git a/modules/setting/repository.go b/modules/setting/repository.go
index 90c4f22ad2..9ae64fcd94 100644
--- a/modules/setting/repository.go
+++ b/modules/setting/repository.go
@@ -18,6 +18,12 @@ const (
RepoCreatingPublic = "public"
)
+// enumerates the values for [repository.pull-request] DEFAULT_TITLE_SOURCE
+const (
+ RepoPRTitleSourceFirstCommit = "first-commit"
+ RepoPRTitleSourceAuto = "auto"
+)
+
// ItemsPerPage maximum items per page in forks, watchers and stars of a repo
const ItemsPerPage = 40
@@ -86,9 +92,10 @@ var (
DefaultMergeMessageOfficialApproversOnly bool
PopulateSquashCommentWithCommitMessages bool
AddCoCommitterTrailers bool
- TestConflictingPatchesWithGitApply bool
RetargetChildrenOnMerge bool
DelayCheckForInactiveDays int
+ DefaultDeleteBranchAfterMerge bool
+ DefaultTitleSource string
} `ini:"repository.pull-request"`
// Issue Setting
@@ -100,6 +107,8 @@ var (
Release struct {
AllowedTypes string
DefaultPagingNum int
+ FileMaxSize int64
+ MaxFiles int64
} `ini:"repository.release"`
Signing struct {
@@ -208,9 +217,10 @@ var (
DefaultMergeMessageOfficialApproversOnly bool
PopulateSquashCommentWithCommitMessages bool
AddCoCommitterTrailers bool
- TestConflictingPatchesWithGitApply bool
RetargetChildrenOnMerge bool
DelayCheckForInactiveDays int
+ DefaultDeleteBranchAfterMerge bool
+ DefaultTitleSource string
}{
WorkInProgressPrefixes: []string{"WIP:", "[WIP]"},
// Same as GitHub. See
@@ -227,6 +237,7 @@ var (
AddCoCommitterTrailers: true,
RetargetChildrenOnMerge: true,
DelayCheckForInactiveDays: 7,
+ DefaultTitleSource: RepoPRTitleSourceAuto,
},
// Issue settings
@@ -241,9 +252,13 @@ var (
Release: struct {
AllowedTypes string
DefaultPagingNum int
+ FileMaxSize int64
+ MaxFiles int64
}{
AllowedTypes: "",
DefaultPagingNum: 10,
+ FileMaxSize: 2048,
+ MaxFiles: 5,
},
// Signing settings
diff --git a/modules/setting/security.go b/modules/setting/security.go
index 153b6bc944..152bcffd9f 100644
--- a/modules/setting/security.go
+++ b/modules/setting/security.go
@@ -14,6 +14,12 @@ import (
)
// Security settings
+var Security = struct {
+ // TODO: move more settings to this struct in future
+ XFrameOptions string
+}{
+ XFrameOptions: "SAMEORIGIN",
+}
var (
InstallLock bool
@@ -25,6 +31,7 @@ var (
ReverseProxyAuthEmail string
ReverseProxyAuthFullName string
ReverseProxyLimit int
+ ReverseProxyLogoutRedirect string
ReverseProxyTrustedProxies []string
MinPasswordLength int
ImportLocalPaths bool
@@ -36,8 +43,6 @@ var (
PasswordCheckPwn bool
SuccessfulTokensCacheSize int
DisableQueryAuthToken bool
- CSRFCookieName = "_csrf"
- CSRFCookieHTTPOnly = true
RecordUserSignupMetadata = false
TwoFactorAuthEnforced = false
)
@@ -105,7 +110,6 @@ func generateSaveInternalToken(rootCfg ConfigProvider) {
func loadSecurityFrom(rootCfg ConfigProvider) {
sec := rootCfg.Section("security")
- InstallLock = HasInstallLock(rootCfg)
LogInRememberDays = sec.Key("LOGIN_REMEMBER_DAYS").MustInt(31)
SecretKey = loadSecret(sec, "SECRET_KEY_URI", "SECRET_KEY")
if SecretKey == "" {
@@ -121,6 +125,7 @@ func loadSecurityFrom(rootCfg ConfigProvider) {
ReverseProxyAuthFullName = sec.Key("REVERSE_PROXY_AUTHENTICATION_FULL_NAME").MustString("X-WEBAUTH-FULLNAME")
ReverseProxyLimit = sec.Key("REVERSE_PROXY_LIMIT").MustInt(1)
+ ReverseProxyLogoutRedirect = sec.Key("REVERSE_PROXY_LOGOUT_REDIRECT").String()
ReverseProxyTrustedProxies = sec.Key("REVERSE_PROXY_TRUSTED_PROXIES").Strings(",")
if len(ReverseProxyTrustedProxies) == 0 {
ReverseProxyTrustedProxies = []string{"127.0.0.0/8", "::1/128"}
@@ -139,10 +144,16 @@ func loadSecurityFrom(rootCfg ConfigProvider) {
log.Fatal("The provided password hash algorithm was invalid: %s", sec.Key("PASSWORD_HASH_ALGO").MustString(""))
}
- CSRFCookieHTTPOnly = sec.Key("CSRF_COOKIE_HTTP_ONLY").MustBool(true)
PasswordCheckPwn = sec.Key("PASSWORD_CHECK_PWN").MustBool(false)
SuccessfulTokensCacheSize = sec.Key("SUCCESSFUL_TOKENS_CACHE_SIZE").MustInt(20)
+ deprecatedSetting(rootCfg, "cors", "X_FRAME_OPTIONS", "security", "X_FRAME_OPTIONS", "v1.26.0")
+ if sec.HasKey("X_FRAME_OPTIONS") {
+ Security.XFrameOptions = sec.Key("X_FRAME_OPTIONS").MustString(Security.XFrameOptions)
+ } else {
+ Security.XFrameOptions = rootCfg.Section("cors").Key("X_FRAME_OPTIONS").MustString(Security.XFrameOptions)
+ }
+
twoFactorAuth := sec.Key("TWO_FACTOR_AUTH").String()
switch twoFactorAuth {
case "":
diff --git a/modules/setting/server.go b/modules/setting/server.go
index cedca32da9..1085e052a3 100644
--- a/modules/setting/server.go
+++ b/modules/setting/server.go
@@ -15,7 +15,6 @@ import (
"code.gitea.io/gitea/modules/json"
"code.gitea.io/gitea/modules/log"
- "code.gitea.io/gitea/modules/util"
)
// Scheme describes protocol types
@@ -44,6 +43,7 @@ const (
const (
PublicURLAuto = "auto"
PublicURLLegacy = "legacy"
+ PublicURLNever = "never"
)
// Server settings
@@ -72,9 +72,6 @@ var (
// It maps to ini:"LOCAL_ROOT_URL" in [server]
LocalURL string
- // AssetVersion holds an opaque value that is used for cache-busting assets
- AssetVersion string
-
// appTempPathInternal is the temporary path for the app, it is only an internal variable
// DO NOT use it directly, always use AppDataTempDir
appTempPathInternal string
@@ -91,7 +88,6 @@ var (
RedirectOtherPort bool
RedirectorUseProxyProtocol bool
PortToRedirect string
- OfflineMode bool
CertFile string
KeyFile string
StaticRootPath string
@@ -163,7 +159,7 @@ func MakeManifestData(appName, appURL, absoluteAssetURL string) []byte {
}
// MakeAbsoluteAssetURL returns the absolute asset url prefix without a trailing slash
-func MakeAbsoluteAssetURL(appURL, staticURLPrefix string) string {
+func MakeAbsoluteAssetURL(appURL *url.URL, staticURLPrefix string) string {
parsedPrefix, err := url.Parse(strings.TrimSuffix(staticURLPrefix, "/"))
if err != nil {
log.Fatal("Unable to parse STATIC_URL_PREFIX: %v", err)
@@ -171,11 +167,12 @@ func MakeAbsoluteAssetURL(appURL, staticURLPrefix string) string {
if err == nil && parsedPrefix.Hostname() == "" {
if staticURLPrefix == "" {
- return strings.TrimSuffix(appURL, "/")
+ return strings.TrimSuffix(appURL.String(), "/")
}
// StaticURLPrefix is just a path
- return util.URLJoin(appURL, strings.TrimSuffix(staticURLPrefix, "/"))
+ appHostURL := &url.URL{Scheme: appURL.Scheme, Host: appURL.Host}
+ return appHostURL.String() + "/" + strings.Trim(staticURLPrefix, "/")
}
return strings.TrimSuffix(staticURLPrefix, "/")
@@ -286,8 +283,8 @@ func loadServerFrom(rootCfg ConfigProvider) {
defaultAppURL := string(Protocol) + "://" + Domain + ":" + HTTPPort
AppURL = sec.Key("ROOT_URL").MustString(defaultAppURL)
- PublicURLDetection = sec.Key("PUBLIC_URL_DETECTION").MustString(PublicURLLegacy)
- if PublicURLDetection != PublicURLAuto && PublicURLDetection != PublicURLLegacy {
+ PublicURLDetection = sec.Key("PUBLIC_URL_DETECTION").MustString(PublicURLAuto)
+ if PublicURLDetection != PublicURLAuto && PublicURLDetection != PublicURLLegacy && PublicURLDetection != PublicURLNever {
log.Fatal("Invalid PUBLIC_URL_DETECTION value: %s", PublicURLDetection)
}
@@ -316,9 +313,7 @@ func loadServerFrom(rootCfg ConfigProvider) {
Domain = urlHostname
}
- AbsoluteAssetURL = MakeAbsoluteAssetURL(AppURL, StaticURLPrefix)
- AssetVersion = strings.ReplaceAll(AppVer, "+", "~") // make sure the version string is clear (no real escaping is needed)
-
+ AbsoluteAssetURL = MakeAbsoluteAssetURL(appURL, StaticURLPrefix)
manifestBytes := MakeManifestData(AppName, AppURL, AbsoluteAssetURL)
ManifestData = `application/json;base64,` + base64.StdEncoding.EncodeToString(manifestBytes)
@@ -346,7 +341,6 @@ func loadServerFrom(rootCfg ConfigProvider) {
RedirectOtherPort = sec.Key("REDIRECT_OTHER_PORT").MustBool(false)
PortToRedirect = sec.Key("PORT_TO_REDIRECT").MustString("80")
RedirectorUseProxyProtocol = sec.Key("REDIRECTOR_USE_PROXY_PROTOCOL").MustBool(UseProxyProtocol)
- OfflineMode = sec.Key("OFFLINE_MODE").MustBool(true)
if len(StaticRootPath) == 0 {
StaticRootPath = AppWorkPath
}
@@ -370,6 +364,10 @@ func loadServerFrom(rootCfg ConfigProvider) {
}
}
+ // TODO: GOLANG-HTTP-TMPDIR: Some Golang packages (like "http") use os.TempDir() to create temporary files when uploading files.
+ // So ideally we should set the TMPDIR environment variable to make them use our managed temp directory.
+ // But there is no clear place to set it currently, for example: when running "install" page, the AppDataPath is not ready yet, then AppDataTempDir won't work
+
EnableGzip = sec.Key("ENABLE_GZIP").MustBool()
EnablePprof = sec.Key("ENABLE_PPROF").MustBool(false)
PprofDataPath = sec.Key("PPROF_DATA_PATH").MustString(filepath.Join(AppWorkPath, "data/tmp/pprof"))
diff --git a/modules/setting/session.go b/modules/setting/session.go
index 19a05ce2c2..cb9b6024ba 100644
--- a/modules/setting/session.go
+++ b/modules/setting/session.go
@@ -10,6 +10,7 @@ import (
"code.gitea.io/gitea/modules/json"
"code.gitea.io/gitea/modules/log"
+ "code.gitea.io/gitea/modules/util"
)
// SessionConfig defines Session settings
@@ -49,10 +50,8 @@ func loadSessionFrom(rootCfg ConfigProvider) {
checkOverlappedPath("[session].PROVIDER_CONFIG", SessionConfig.ProviderConfig)
}
SessionConfig.CookieName = sec.Key("COOKIE_NAME").MustString("i_like_gitea")
- SessionConfig.CookiePath = AppSubURL
- if SessionConfig.CookiePath == "" {
- SessionConfig.CookiePath = "/"
- }
+ // HINT: INSTALL-PAGE-COOKIE-INIT: the cookie system is not properly initialized on the Install page, so there is no CookiePath
+ SessionConfig.CookiePath = util.IfZero(AppSubURL, "/")
SessionConfig.Secure = sec.Key("COOKIE_SECURE").MustBool(strings.HasPrefix(strings.ToLower(AppURL), "https://"))
SessionConfig.Gclifetime = sec.Key("GC_INTERVAL_TIME").MustInt64(86400)
SessionConfig.Maxlifetime = sec.Key("SESSION_LIFE_TIME").MustInt64(86400)
diff --git a/modules/setting/setting.go b/modules/setting/setting.go
index e14997801f..58ef3c8660 100644
--- a/modules/setting/setting.go
+++ b/modules/setting/setting.go
@@ -14,6 +14,7 @@ import (
"code.gitea.io/gitea/modules/log"
"code.gitea.io/gitea/modules/optional"
"code.gitea.io/gitea/modules/user"
+ "code.gitea.io/gitea/modules/util"
)
// settings
@@ -28,8 +29,10 @@ var (
CfgProvider ConfigProvider
IsWindows bool
- // IsInTesting indicates whether the testing is running. A lot of unreliable code causes a lot of nonsense error logs during testing
- // TODO: this is only a temporary solution, we should make the test code more reliable
+ // IsInTesting indicates whether the testing is running (unit test or integration test). It can be used for:
+ // * Skip nonsense error logs during testing caused by unreliable code (TODO: this is only a temporary solution, we should make the test code more reliable)
+ // * Panic in dev or testing mode to make the problem more obvious and easier to debug
+ // * Mock some functions or options to make testing easier (eg: session store, time, URL detection, etc.)
IsInTesting = false
)
@@ -57,6 +60,10 @@ func IsRunUserMatchCurrentUser(runUser string) (string, bool) {
return currentUser, runUser == currentUser
}
+func IsInE2eTesting() bool {
+ return os.Getenv("GITEA_TEST_E2E") == "true"
+}
+
// PrepareAppDataPath creates app data directory if necessary
func PrepareAppDataPath() error {
// FIXME: There are too many calls to MkdirAll in old code. It is incorrect.
@@ -108,6 +115,9 @@ func LoadCommonSettings() {
// loadCommonSettingsFrom loads common configurations from a configuration provider.
func loadCommonSettingsFrom(cfg ConfigProvider) error {
+ // a lot of logic depends on InstallLock value, so it must be loaded before any other settings
+ InstallLock = HasInstallLock(cfg)
+
// WARNING: don't change the sequence except you know what you are doing.
loadRunModeFrom(cfg)
loadLogGlobalFrom(cfg)
@@ -154,32 +164,38 @@ func loadCommonSettingsFrom(cfg ConfigProvider) error {
func loadRunModeFrom(rootCfg ConfigProvider) {
rootSec := rootCfg.Section("")
+ mustNotRunAsRoot(rootSec)
+
+ runModeValue := os.Getenv("GITEA_RUN_MODE")
+ runModeValue = util.IfZero(runModeValue, rootSec.Key("RUN_MODE").String())
+ // non-dev mode is treated as prod mode, to protect users from accidentally running in dev mode if there is a typo in this value.
+ IsProd = !strings.EqualFold(runModeValue, "dev") // TODO: can use case-sensitive comparing in the future
+ RunMode = util.Iif(IsProd, "prod", "dev")
+
+ // there is a separate check: mustCurrentRunUserMatch (IsRunUserMatchCurrentUser)
RunUser = rootSec.Key("RUN_USER").MustString(user.CurrentUsername())
+}
- // The following is a purposefully undocumented option. Please do not run Gitea as root. It will only cause future headaches.
- // Please don't use root as a bandaid to "fix" something that is broken, instead the broken thing should instead be fixed properly.
- unsafeAllowRunAsRoot := ConfigSectionKeyBool(rootSec, "I_AM_BEING_UNSAFE_RUNNING_AS_ROOT")
- unsafeAllowRunAsRoot = unsafeAllowRunAsRoot || optional.ParseBool(os.Getenv("GITEA_I_AM_BEING_UNSAFE_RUNNING_AS_ROOT")).Value()
- RunMode = os.Getenv("GITEA_RUN_MODE")
- if RunMode == "" {
- RunMode = rootSec.Key("RUN_MODE").MustString("prod")
+func mustNotRunAsRoot(rootSec ConfigSection) {
+ if os.Getuid() != 0 {
+ return
}
- // non-dev mode is treated as prod mode, to protect users from accidentally running in dev mode if there is a typo in this value.
- RunMode = strings.ToLower(RunMode)
- if RunMode != "dev" {
- RunMode = "prod"
+ mustRunAsRoot := os.Getenv("SNAP") != "" && os.Getenv("SNAP_NAME") != "" // snap container runs the app as uid=0
+ if mustRunAsRoot {
+ return
}
- IsProd = RunMode != "dev"
- // check if we run as root
- if os.Getuid() == 0 {
- if !unsafeAllowRunAsRoot {
- // Special thanks to VLC which inspired the wording of this messaging.
- log.Fatal("Gitea is not supposed to be run as root. Sorry. If you need to use privileged TCP ports please instead use setcap and the `cap_net_bind_service` permission")
- }
- log.Critical("You are running Gitea using the root user, and have purposely chosen to skip built-in protections around this. You have been warned against this.")
+ // The following is a purposefully undocumented option. Please do not run Gitea as root. It will only cause future headaches.
+ // Please don't use root as a bandaid to "fix" something that is broken, instead the broken thing should instead be fixed properly.
+ allowRunAsRoot := ConfigSectionKeyBool(rootSec, "I_AM_BEING_UNSAFE_RUNNING_AS_ROOT") || // check gitea config
+ optional.ParseBool(os.Getenv("GITEA_I_AM_BEING_UNSAFE_RUNNING_AS_ROOT")).Value() // check gitea env var
+
+ if !allowRunAsRoot {
+ // Special thanks to VLC which inspired the wording of this messaging.
+ log.Fatal("Gitea is not supposed to be run as root. If you need to use privileged TCP ports please instead use `setcap` and the `cap_net_bind_service` permission.")
}
+ log.Warn("You are running Gitea using the root user, and have purposely chosen to skip built-in protections around this. You have been warned against this.")
}
// HasInstallLock checks the install-lock in ConfigProvider directly, because sometimes the config file is not loaded into setting variables yet.
@@ -192,7 +208,7 @@ func mustCurrentRunUserMatch(rootCfg ConfigProvider) {
if HasInstallLock(rootCfg) {
currentUser, match := IsRunUserMatchCurrentUser(RunUser)
if !match {
- log.Fatal("Expect user '%s' but current user is: %s", RunUser, currentUser)
+ log.Fatal("Expect user '%s' (RUN_USER in app.ini) but current user is: %s", RunUser, currentUser)
}
}
}
@@ -223,7 +239,7 @@ func LoadSettings() {
func LoadSettingsForInstall() {
loadDBSetting(CfgProvider)
loadServiceFrom(CfgProvider)
- loadMailerFrom(CfgProvider)
+ loadMailsFrom(CfgProvider)
}
var configuredPaths = make(map[string]string)
@@ -240,4 +256,5 @@ func PanicInDevOrTesting(msg string, a ...any) {
if !IsProd || IsInTesting {
panic(fmt.Sprintf(msg, a...))
}
+ log.Error(msg, a...)
}
diff --git a/modules/setting/setting_test.go b/modules/setting/setting_test.go
index f77ee65974..13575f52a6 100644
--- a/modules/setting/setting_test.go
+++ b/modules/setting/setting_test.go
@@ -4,6 +4,7 @@
package setting
import (
+ "net/url"
"testing"
"code.gitea.io/gitea/modules/json"
@@ -12,18 +13,26 @@ import (
)
func TestMakeAbsoluteAssetURL(t *testing.T) {
- assert.Equal(t, "https://localhost:2345", MakeAbsoluteAssetURL("https://localhost:1234", "https://localhost:2345"))
- assert.Equal(t, "https://localhost:2345", MakeAbsoluteAssetURL("https://localhost:1234/", "https://localhost:2345"))
- assert.Equal(t, "https://localhost:2345", MakeAbsoluteAssetURL("https://localhost:1234/", "https://localhost:2345/"))
- assert.Equal(t, "https://localhost:1234/foo", MakeAbsoluteAssetURL("https://localhost:1234", "/foo"))
- assert.Equal(t, "https://localhost:1234/foo", MakeAbsoluteAssetURL("https://localhost:1234/", "/foo"))
- assert.Equal(t, "https://localhost:1234/foo", MakeAbsoluteAssetURL("https://localhost:1234/", "/foo/"))
- assert.Equal(t, "https://localhost:1234/foo", MakeAbsoluteAssetURL("https://localhost:1234/foo", "/foo"))
- assert.Equal(t, "https://localhost:1234/foo", MakeAbsoluteAssetURL("https://localhost:1234/foo/", "/foo"))
- assert.Equal(t, "https://localhost:1234/foo", MakeAbsoluteAssetURL("https://localhost:1234/foo/", "/foo/"))
- assert.Equal(t, "https://localhost:1234/bar", MakeAbsoluteAssetURL("https://localhost:1234/foo", "/bar"))
- assert.Equal(t, "https://localhost:1234/bar", MakeAbsoluteAssetURL("https://localhost:1234/foo/", "/bar"))
- assert.Equal(t, "https://localhost:1234/bar", MakeAbsoluteAssetURL("https://localhost:1234/foo/", "/bar/"))
+ appURL1, _ := url.Parse("https://localhost:1234")
+ appURL2, _ := url.Parse("https://localhost:1234/")
+ appURLSub1, _ := url.Parse("https://localhost:1234/foo")
+ appURLSub2, _ := url.Parse("https://localhost:1234/foo/")
+
+ // static URL is an absolute URL, so should be used
+ assert.Equal(t, "https://localhost:2345", MakeAbsoluteAssetURL(appURL1, "https://localhost:2345"))
+ assert.Equal(t, "https://localhost:2345", MakeAbsoluteAssetURL(appURL1, "https://localhost:2345/"))
+
+ assert.Equal(t, "https://localhost:1234/foo", MakeAbsoluteAssetURL(appURL1, "/foo"))
+ assert.Equal(t, "https://localhost:1234/foo", MakeAbsoluteAssetURL(appURL2, "/foo"))
+ assert.Equal(t, "https://localhost:1234/foo", MakeAbsoluteAssetURL(appURL1, "/foo/"))
+
+ assert.Equal(t, "https://localhost:1234/foo", MakeAbsoluteAssetURL(appURLSub1, "/foo"))
+ assert.Equal(t, "https://localhost:1234/foo", MakeAbsoluteAssetURL(appURLSub2, "/foo"))
+ assert.Equal(t, "https://localhost:1234/foo", MakeAbsoluteAssetURL(appURLSub1, "/foo/"))
+
+ assert.Equal(t, "https://localhost:1234/bar", MakeAbsoluteAssetURL(appURLSub1, "/bar"))
+ assert.Equal(t, "https://localhost:1234/bar", MakeAbsoluteAssetURL(appURLSub2, "/bar"))
+ assert.Equal(t, "https://localhost:1234/bar", MakeAbsoluteAssetURL(appURLSub1, "/bar/"))
}
func TestMakeManifestData(t *testing.T) {
diff --git a/modules/setting/storage.go b/modules/setting/storage.go
index ee246158d9..9ee3f01633 100644
--- a/modules/setting/storage.go
+++ b/modules/setting/storage.go
@@ -172,11 +172,11 @@ func getStorageSectionByType(rootCfg ConfigProvider, typ string) (ConfigSection,
targetType := targetSec.Key("STORAGE_TYPE").String()
if targetType == "" {
if !IsValidStorageType(StorageType(typ)) {
- return nil, 0, fmt.Errorf("unknow storage type %q", typ)
+ return nil, 0, fmt.Errorf("unknown storage type %q", typ)
}
targetSec.Key("STORAGE_TYPE").SetValue(typ)
} else if !IsValidStorageType(StorageType(targetType)) {
- return nil, 0, fmt.Errorf("unknow storage type %q for section storage.%v", targetType, typ)
+ return nil, 0, fmt.Errorf("unknown storage type %q for section storage.%v", targetType, typ)
}
return targetSec, targetSecIsTyp, nil
@@ -202,7 +202,7 @@ func getStorageTargetSection(rootCfg ConfigProvider, name, typ string, sec Confi
}
}
- // check stoarge name thirdly
+ // check storage name thirdly
targetSec, _ := rootCfg.GetSection(storageSectionName + "." + name)
if targetSec != nil {
targetType := targetSec.Key("STORAGE_TYPE").String()
diff --git a/modules/setting/testenv.go b/modules/setting/testenv.go
new file mode 100644
index 0000000000..853521c328
--- /dev/null
+++ b/modules/setting/testenv.go
@@ -0,0 +1,72 @@
+// Copyright 2026 The Gitea Authors. All rights reserved.
+// SPDX-License-Identifier: MIT
+
+package setting
+
+import (
+ "fmt"
+ "os"
+ "path/filepath"
+ "runtime"
+ "strings"
+
+ "code.gitea.io/gitea/modules/util"
+)
+
+var giteaTestSourceRoot *string
+
+func GetGiteaTestSourceRoot() string {
+ return *giteaTestSourceRoot
+}
+
+func SetupGiteaTestEnv() {
+ if giteaTestSourceRoot != nil {
+ return // already initialized
+ }
+
+ IsInTesting = true
+ giteaRoot := os.Getenv("GITEA_TEST_ROOT")
+ if giteaRoot == "" {
+ _, filename, _, _ := runtime.Caller(0)
+ giteaRoot = filepath.Dir(filepath.Dir(filepath.Dir(filename)))
+ fixturesDir := filepath.Join(giteaRoot, "models", "fixtures")
+ if _, err := os.Stat(fixturesDir); err != nil {
+ panic("in gitea source code directory, fixtures directory not found: " + fixturesDir)
+ }
+ }
+
+ appWorkPathBuiltin = giteaRoot
+ AppWorkPath = giteaRoot
+ AppPath = filepath.Join(giteaRoot, "gitea") + util.Iif(IsWindows, ".exe", "")
+ StaticRootPath = giteaRoot // need to load assets (options, public) from the source code directory for testing
+
+ // giteaConf (GITEA_CONF) must be relative because it is used in the git hooks as "$GITEA_ROOT/$GITEA_CONF"
+ giteaConf := os.Getenv("GITEA_TEST_CONF")
+ if giteaConf == "" {
+ // By default, use sqlite.ini for testing, then IDE like GoLand can start the test process with debugger.
+ // It's easier for developers to debug bugs step by step with a debugger.
+ // Notice: when doing "ssh push", Gitea executes sub processes, debugger won't work for the sub processes.
+ giteaConf = "tests/sqlite.ini"
+ _, _ = fmt.Fprintf(os.Stderr, "Environment variable GITEA_TEST_CONF not set - defaulting to %s\n", giteaConf)
+ if !EnableSQLite3 {
+ _, _ = fmt.Fprintf(os.Stderr, "sqlite3 requires: -tags sqlite,sqlite_unlock_notify\n")
+ os.Exit(1)
+ }
+ }
+ // CustomConf must be absolute path to make tests pass,
+ CustomConf = filepath.Join(AppWorkPath, giteaConf)
+
+ // also unset unnecessary env vars for testing (only keep "GITEA_TEST_*" ones)
+ UnsetUnnecessaryEnvVars()
+ for _, env := range os.Environ() {
+ if strings.HasPrefix(env, "GIT_") || (strings.HasPrefix(env, "GITEA_") && !strings.HasPrefix(env, "GITEA_TEST_")) {
+ k, _, _ := strings.Cut(env, "=")
+ _ = os.Unsetenv(k)
+ }
+ }
+
+ // TODO: some git repo hooks (test fixtures) still use these env variables, need to be refactored in the future
+ _ = os.Setenv("GITEA_ROOT", giteaRoot)
+ _ = os.Setenv("GITEA_CONF", giteaConf) // test fixture git hooks use "$GITEA_ROOT/$GITEA_CONF" in their scripts
+ giteaTestSourceRoot = &giteaRoot
+}
diff --git a/modules/setting/ui.go b/modules/setting/ui.go
index 13cb0f5c66..722341a71e 100644
--- a/modules/setting/ui.go
+++ b/modules/setting/ui.go
@@ -25,10 +25,10 @@ var UI = struct {
ReactionMaxUserNum int
MaxDisplayFileSize int64
ShowUserEmail bool
- DefaultShowFullName bool
DefaultTheme string
Themes []string
FileIconTheme string
+ FolderIconTheme string
Reactions []string
ReactionsLookup container.Set[string] `ini:"-"`
CustomEmojis []string
@@ -42,6 +42,15 @@ var UI = struct {
AmbiguousUnicodeDetection bool
+ // TODO: DefaultShowFullName is introduced by https://github.com/go-gitea/gitea/pull/6710
+ // But there are still many edge cases:
+ // * Many places still use "username", not respecting this setting
+ // * Many places use "Full Name" if it is not empty, cause inconsistent UI for users who have set their full name but some others don't
+ // * Even if DefaultShowFullName=false, many places still need to show the full name
+ // For most cases, either "username" or "username (Full Name)" should be used and are good enough.
+ // Only in very few cases (e.g.: unimportant lists, narrow layout), "username" or "Full Name" can be used.
+ DefaultShowFullName bool
+
Notification struct {
MinTimeout time.Duration
TimeoutStep time.Duration
@@ -88,6 +97,7 @@ var UI = struct {
MaxDisplayFileSize: 8388608,
DefaultTheme: `gitea-auto`,
FileIconTheme: `material`,
+ FolderIconTheme: `basic`,
Reactions: []string{`+1`, `-1`, `laugh`, `hooray`, `confused`, `heart`, `rocket`, `eyes`},
CustomEmojis: []string{`git`, `gitea`, `codeberg`, `gitlab`, `github`, `gogs`},
CustomEmojisMap: map[string]string{"git": ":git:", "gitea": ":gitea:", "codeberg": ":codeberg:", "gitlab": ":gitlab:", "github": ":github:", "gogs": ":gogs:"},
diff --git a/modules/storage/azureblob.go b/modules/storage/azureblob.go
index e7297cec77..a273a7770d 100644
--- a/modules/storage/azureblob.go
+++ b/modules/storage/azureblob.go
@@ -8,6 +8,7 @@ import (
"errors"
"fmt"
"io"
+ "net/http"
"net/url"
"os"
"path"
@@ -246,16 +247,53 @@ func (a *AzureBlobStorage) Delete(path string) error {
return convertAzureBlobErr(err)
}
-// URL gets the redirect URL to a file. The presigned link is valid for 5 minutes.
-func (a *AzureBlobStorage) URL(path, name, _ string, reqParams url.Values) (*url.URL, error) {
- blobClient := a.getBlobClient(path)
+func (a *AzureBlobStorage) getSasURL(b *blob.Client, template sas.BlobSignatureValues) (string, error) {
+ urlParts, err := blob.ParseURL(b.URL())
+ if err != nil {
+ return "", err
+ }
+
+ var t time.Time
+ if urlParts.Snapshot == "" {
+ t = time.Time{}
+ } else {
+ t, err = time.Parse(blob.SnapshotTimeFormat, urlParts.Snapshot)
+ if err != nil {
+ return "", err
+ }
+ }
+
+ template.ContainerName = urlParts.ContainerName
+ template.BlobName = urlParts.BlobName
+ template.SnapshotTime = t
+ template.Version = sas.Version
+
+ qps, err := template.SignWithSharedKey(a.credential)
+ if err != nil {
+ return "", err
+ }
+
+ endpoint := b.URL() + "?" + qps.Encode()
+
+ return endpoint, nil
+}
+
+func (a *AzureBlobStorage) ServeDirectURL(storePath, name, method string, reqParams *ServeDirectOptions) (*url.URL, error) {
+ blobClient := a.getBlobClient(storePath)
+
+ startTime := time.Now().UTC()
+
+ param := prepareServeDirectOptions(reqParams, name)
- // TODO: OBJECT-STORAGE-CONTENT-TYPE: "browser inline rendering images/PDF" needs proper Content-Type header from storage
- startTime := time.Now()
- u, err := blobClient.GetSASURL(sas.BlobPermissions{
- Read: true,
- }, time.Now().Add(5*time.Minute), &blob.GetSASURLOptions{
- StartTime: &startTime,
+ u, err := a.getSasURL(blobClient, sas.BlobSignatureValues{
+ Permissions: (&sas.BlobPermissions{
+ Read: method == http.MethodGet || method == http.MethodHead,
+ Write: method == http.MethodPut,
+ }).String(),
+ StartTime: startTime,
+ ExpiryTime: startTime.Add(5 * time.Minute),
+ ContentDisposition: param.ContentDisposition,
+ ContentType: param.ContentType,
})
if err != nil {
return nil, convertAzureBlobErr(err)
diff --git a/modules/storage/azureblob_test.go b/modules/storage/azureblob_test.go
index b3791b4916..b5d5d0fecc 100644
--- a/modules/storage/azureblob_test.go
+++ b/modules/storage/azureblob_test.go
@@ -14,12 +14,13 @@ import (
"github.com/stretchr/testify/assert"
)
-func TestAzureBlobStorageIterator(t *testing.T) {
+func TestAzureBlobStorage(t *testing.T) {
if os.Getenv("CI") == "" {
t.Skip("azureBlobStorage not present outside of CI")
return
}
- testStorageIterator(t, setting.AzureBlobStorageType, &setting.Storage{
+ storageType := setting.AzureBlobStorageType
+ config := &setting.Storage{
AzureBlobConfig: setting.AzureBlobStorageConfig{
// https://learn.microsoft.com/azure/storage/common/storage-use-azurite?tabs=visual-studio-code#ip-style-url
Endpoint: "http://devstoreaccount1.azurite.local:10000",
@@ -28,7 +29,25 @@ func TestAzureBlobStorageIterator(t *testing.T) {
AccountKey: "Eby8vdM02xNOcqFlqUwJPLlmEtlCDXJ1OUzFT50uSRZ6IFsuFq2UVErCz4I6tq/K1SZFPTOtr/KBHBeksoGMGw==",
Container: "test",
},
- })
+ }
+ table := []struct {
+ name string
+ test func(t *testing.T, typStr Type, cfg *setting.Storage)
+ }{
+ {
+ name: "iterator",
+ test: testStorageIterator,
+ },
+ {
+ name: "testBlobStorageURLContentTypeAndDisposition",
+ test: testBlobStorageURLContentTypeAndDisposition,
+ },
+ }
+ for _, entry := range table {
+ t.Run(entry.name, func(t *testing.T) {
+ entry.test(t, storageType, config)
+ })
+ }
}
func TestAzureBlobStoragePath(t *testing.T) {
diff --git a/modules/storage/helper.go b/modules/storage/helper.go
index f6c3d5eebb..30d96a33ad 100644
--- a/modules/storage/helper.go
+++ b/modules/storage/helper.go
@@ -30,7 +30,7 @@ func (s discardStorage) Delete(_ string) error {
return fmt.Errorf("%s", s)
}
-func (s discardStorage) URL(_, _, _ string, _ url.Values) (*url.URL, error) {
+func (s discardStorage) ServeDirectURL(_, _, _ string, _ *ServeDirectOptions) (*url.URL, error) {
return nil, fmt.Errorf("%s", s)
}
diff --git a/modules/storage/helper_test.go b/modules/storage/helper_test.go
index 3cba1e13c0..ae64c8aca4 100644
--- a/modules/storage/helper_test.go
+++ b/modules/storage/helper_test.go
@@ -37,7 +37,7 @@ func Test_discardStorage(t *testing.T) {
assert.Error(t, err, string(tt))
}
{
- got, err := tt.URL("path", "name", "GET", nil)
+ got, err := tt.ServeDirectURL("path", "name", "GET", nil)
assert.Nil(t, got)
assert.Errorf(t, err, string(tt))
}
diff --git a/modules/storage/local.go b/modules/storage/local.go
index 8a1776f606..04e3e05f95 100644
--- a/modules/storage/local.go
+++ b/modules/storage/local.go
@@ -5,6 +5,7 @@ package storage
import (
"context"
+ "errors"
"fmt"
"io"
"net/url"
@@ -27,25 +28,32 @@ type LocalStorage struct {
// NewLocalStorage returns a local files
func NewLocalStorage(ctx context.Context, config *setting.Storage) (ObjectStorage, error) {
+ // prepare storage root path
if !filepath.IsAbs(config.Path) {
- return nil, fmt.Errorf("LocalStorageConfig.Path should have been prepared by setting/storage.go and should be an absolute path, but not: %q", config.Path)
- }
- log.Info("Creating new Local Storage at %s", config.Path)
- if err := os.MkdirAll(config.Path, os.ModePerm); err != nil {
- return nil, err
+ return nil, fmt.Errorf("LocalStorage config.Path should have been prepared by setting/storage.go and should be an absolute path, but not: %q", config.Path)
}
+ storageRoot := util.FilePathJoinAbs(config.Path)
- if config.TemporaryPath == "" {
- config.TemporaryPath = filepath.Join(config.Path, "tmp")
+ // prepare storage temporary path
+ storageTmp := config.TemporaryPath
+ if storageTmp == "" {
+ storageTmp = filepath.Join(storageRoot, "tmp")
+ }
+ if !filepath.IsAbs(storageTmp) {
+ return nil, fmt.Errorf("LocalStorage config.TemporaryPath should be an absolute path, but not: %q", config.TemporaryPath)
}
- if !filepath.IsAbs(config.TemporaryPath) {
- return nil, fmt.Errorf("LocalStorageConfig.TemporaryPath should be an absolute path, but not: %q", config.TemporaryPath)
+ storageTmp = util.FilePathJoinAbs(storageTmp)
+
+ // create the storage root if not exist
+ log.Info("Creating new Local Storage at %s", storageRoot)
+ if err := os.MkdirAll(storageRoot, os.ModePerm); err != nil {
+ return nil, err
}
return &LocalStorage{
ctx: ctx,
- dir: config.Path,
- tmpdir: config.TemporaryPath,
+ dir: storageRoot,
+ tmpdir: storageTmp,
}, nil
}
@@ -108,44 +116,59 @@ func (l *LocalStorage) Stat(path string) (os.FileInfo, error) {
return os.Stat(l.buildLocalPath(path))
}
-// Delete delete a file
+func (l *LocalStorage) deleteEmptyParentDirs(localFullPath string) {
+ for parent := filepath.Dir(localFullPath); len(parent) > len(l.dir); parent = filepath.Dir(parent) {
+ if err := os.Remove(parent); err != nil {
+ // since the target file has been deleted, parent dir error is not related to the file deletion itself.
+ break
+ }
+ }
+}
+
+// Delete deletes the file in storage and removes the empty parent directories (if possible)
func (l *LocalStorage) Delete(path string) error {
- return util.Remove(l.buildLocalPath(path))
+ localFullPath := l.buildLocalPath(path)
+ err := util.Remove(localFullPath)
+ l.deleteEmptyParentDirs(localFullPath)
+ return err
}
-// URL gets the redirect URL to a file
-func (l *LocalStorage) URL(path, name, _ string, reqParams url.Values) (*url.URL, error) {
+func (l *LocalStorage) ServeDirectURL(path, name, _ string, reqParams *ServeDirectOptions) (*url.URL, error) {
return nil, ErrURLNotSupported
}
+func (l *LocalStorage) normalizeWalkError(err error) error {
+ if errors.Is(err, os.ErrNotExist) {
+ // ignore it because the file may be deleted during the walk, and we don't care about it
+ return nil
+ }
+ return err
+}
+
// IterateObjects iterates across the objects in the local storage
func (l *LocalStorage) IterateObjects(dirName string, fn func(path string, obj Object) error) error {
dir := l.buildLocalPath(dirName)
- return filepath.WalkDir(dir, func(path string, d os.DirEntry, err error) error {
- if err != nil {
+ return filepath.WalkDir(dir, func(path string, d os.DirEntry, errWalk error) error {
+ if err := l.ctx.Err(); err != nil {
return err
}
- select {
- case <-l.ctx.Done():
- return l.ctx.Err()
- default:
+ if errWalk != nil {
+ return l.normalizeWalkError(errWalk)
}
- if path == l.dir {
- return nil
- }
- if d.IsDir() {
+ if path == l.dir || d.IsDir() {
return nil
}
+
relPath, err := filepath.Rel(l.dir, path)
if err != nil {
- return err
+ return l.normalizeWalkError(err)
}
obj, err := os.Open(path)
if err != nil {
- return err
+ return l.normalizeWalkError(err)
}
defer obj.Close()
- return fn(relPath, obj)
+ return fn(filepath.ToSlash(relPath), obj)
})
}
diff --git a/modules/storage/local_test.go b/modules/storage/local_test.go
index 0592fd716b..29c13539d0 100644
--- a/modules/storage/local_test.go
+++ b/modules/storage/local_test.go
@@ -4,11 +4,14 @@
package storage
import (
+ "os"
+ "strings"
"testing"
"code.gitea.io/gitea/modules/setting"
"github.com/stretchr/testify/assert"
+ "github.com/stretchr/testify/require"
)
func TestBuildLocalPath(t *testing.T) {
@@ -53,6 +56,49 @@ func TestBuildLocalPath(t *testing.T) {
}
}
+func TestLocalStorageDelete(t *testing.T) {
+ rootDir := t.TempDir()
+ st, err := NewLocalStorage(t.Context(), &setting.Storage{Path: rootDir})
+ require.NoError(t, err)
+
+ assertExists := func(t *testing.T, path string, exists bool) {
+ _, err = os.Stat(rootDir + "/" + path)
+ if exists {
+ require.NoError(t, err)
+ } else {
+ require.ErrorIs(t, err, os.ErrNotExist)
+ }
+ }
+
+ _, err = st.Save("dir/sub1/1-a.txt", strings.NewReader(""), -1)
+ require.NoError(t, err)
+ _, err = st.Save("dir/sub1/1-b.txt", strings.NewReader(""), -1)
+ require.NoError(t, err)
+ _, err = st.Save("dir/sub2/2-a.txt", strings.NewReader(""), -1)
+ require.NoError(t, err)
+
+ assertExists(t, "dir/sub1/1-a.txt", true)
+ assertExists(t, "dir/sub1/1-b.txt", true)
+ assertExists(t, "dir/sub2/2-a.txt", true)
+
+ require.NoError(t, st.Delete("dir/sub1/1-a.txt"))
+ assertExists(t, "dir/sub1", true)
+ assertExists(t, "dir/sub1/1-a.txt", false)
+ assertExists(t, "dir/sub1/1-b.txt", true)
+ assertExists(t, "dir/sub2/2-a.txt", true)
+
+ require.NoError(t, st.Delete("dir/sub1/1-b.txt"))
+ assertExists(t, ".", true)
+ assertExists(t, "dir/sub1", false)
+ assertExists(t, "dir/sub1/1-a.txt", false)
+ assertExists(t, "dir/sub1/1-b.txt", false)
+ assertExists(t, "dir/sub2/2-a.txt", true)
+
+ require.NoError(t, st.Delete("dir/sub2/2-a.txt"))
+ assertExists(t, ".", true)
+ assertExists(t, "dir", false)
+}
+
func TestLocalStorageIterator(t *testing.T) {
testStorageIterator(t, setting.LocalStorageType, &setting.Storage{Path: t.TempDir()})
}
diff --git a/modules/storage/minio.go b/modules/storage/minio.go
index 6993ac2d92..ace78bb610 100644
--- a/modules/storage/minio.go
+++ b/modules/storage/minio.go
@@ -23,11 +23,7 @@ import (
"github.com/minio/minio-go/v7/pkg/credentials"
)
-var (
- _ ObjectStorage = &MinioStorage{}
-
- quoteEscaper = strings.NewReplacer("\\", "\\\\", `"`, "\\\"")
-)
+var _ ObjectStorage = &MinioStorage{}
type minioObject struct {
*minio.Object
@@ -278,37 +274,16 @@ func (m *MinioStorage) Delete(path string) error {
return convertMinioErr(err)
}
-// URL gets the redirect URL to a file. The presigned link is valid for 5 minutes.
-func (m *MinioStorage) URL(storePath, name, method string, serveDirectReqParams url.Values) (*url.URL, error) {
- // copy serveDirectReqParams
- reqParams, err := url.ParseQuery(serveDirectReqParams.Encode())
- if err != nil {
- return nil, err
- }
+func (m *MinioStorage) ServeDirectURL(storePath, name, method string, opt *ServeDirectOptions) (*url.URL, error) {
+ reqParams := url.Values{}
- // Here we might not know the real filename, and it's quite inefficient to detect the mine type by pre-fetching the object head.
- // So we just do a quick detection by extension name, at least if works for the "View Raw File" for an LFS file on the Web UI.
- // Detect content type by extension name, only support the well-known safe types for inline rendering.
- // TODO: OBJECT-STORAGE-CONTENT-TYPE: need a complete solution and refactor for Azure in the future
- ext := path.Ext(name)
- inlineExtMimeTypes := map[string]string{
- ".png": "image/png",
- ".jpg": "image/jpeg",
- ".jpeg": "image/jpeg",
- ".gif": "image/gif",
- ".webp": "image/webp",
- ".avif": "image/avif",
- // ATTENTION! Don't support unsafe types like HTML/SVG due to security concerns: they can contain JS code, and maybe they need proper Content-Security-Policy
- // HINT: PDF-RENDER-SANDBOX: PDF won't render in sandboxed context, it seems fine to render it inline
- ".pdf": "application/pdf",
-
- // TODO: refactor with "modules/public/mime_types.go", for example: "DetectWellKnownSafeInlineMimeType"
+ param := prepareServeDirectOptions(opt, name)
+ // minio does not ignore empty params
+ if param.ContentType != "" {
+ reqParams.Set("response-content-type", param.ContentType)
}
- if mimeType, ok := inlineExtMimeTypes[ext]; ok {
- reqParams.Set("response-content-type", mimeType)
- reqParams.Set("response-content-disposition", "inline")
- } else {
- reqParams.Set("response-content-disposition", fmt.Sprintf(`attachment; filename="%s"`, quoteEscaper.Replace(name)))
+ if param.ContentDisposition != "" {
+ reqParams.Set("response-content-disposition", param.ContentDisposition)
}
expires := 5 * time.Minute
@@ -323,6 +298,7 @@ func (m *MinioStorage) URL(storePath, name, method string, serveDirectReqParams
// IterateObjects iterates across the objects in the miniostorage
func (m *MinioStorage) IterateObjects(dirName string, fn func(path string, obj Object) error) error {
opts := minio.GetObjectOptions{}
+ // FIXME: this loop is not right and causes resource leaking, see the comment of ListObjects
for mObjInfo := range m.client.ListObjects(m.ctx, m.bucket, minio.ListObjectsOptions{
Prefix: m.buildMinioDirPrefix(dirName),
Recursive: true,
diff --git a/modules/storage/minio_test.go b/modules/storage/minio_test.go
index 2726d765dd..5c15ee1ed6 100644
--- a/modules/storage/minio_test.go
+++ b/modules/storage/minio_test.go
@@ -16,12 +16,13 @@ import (
"github.com/stretchr/testify/assert"
)
-func TestMinioStorageIterator(t *testing.T) {
+func TestMinioStorage(t *testing.T) {
if os.Getenv("CI") == "" {
t.Skip("minioStorage not present outside of CI")
return
}
- testStorageIterator(t, setting.MinioStorageType, &setting.Storage{
+ storageType := setting.MinioStorageType
+ config := &setting.Storage{
MinioConfig: setting.MinioStorageConfig{
Endpoint: "minio:9000",
AccessKeyID: "123456",
@@ -29,7 +30,25 @@ func TestMinioStorageIterator(t *testing.T) {
Bucket: "gitea",
Location: "us-east-1",
},
- })
+ }
+ table := []struct {
+ name string
+ test func(t *testing.T, typStr Type, cfg *setting.Storage)
+ }{
+ {
+ name: "iterator",
+ test: testStorageIterator,
+ },
+ {
+ name: "testBlobStorageURLContentTypeAndDisposition",
+ test: testBlobStorageURLContentTypeAndDisposition,
+ },
+ }
+ for _, entry := range table {
+ t.Run(entry.name, func(t *testing.T) {
+ entry.test(t, storageType, config)
+ })
+ }
}
func TestMinioStoragePath(t *testing.T) {
diff --git a/modules/storage/storage.go b/modules/storage/storage.go
index 1868817c05..e19c421ba8 100644
--- a/modules/storage/storage.go
+++ b/modules/storage/storage.go
@@ -10,8 +10,11 @@ import (
"io"
"net/url"
"os"
+ "path"
+ "code.gitea.io/gitea/modules/httplib"
"code.gitea.io/gitea/modules/log"
+ "code.gitea.io/gitea/modules/public"
"code.gitea.io/gitea/modules/setting"
)
@@ -56,6 +59,37 @@ type Object interface {
Stat() (os.FileInfo, error)
}
+// ServeDirectOptions customizes HTTP headers for a generated signed URL.
+type ServeDirectOptions struct {
+ // Overrides the automatically detected MIME type.
+ ContentType string
+}
+
+// Safe defaults are applied only when not explicitly overridden by the caller.
+func prepareServeDirectOptions(optsOptional *ServeDirectOptions, name string) (ret struct {
+ ContentType string
+ ContentDisposition string
+},
+) {
+ // Here we might not know the real filename, and it's quite inefficient to detect the MIME type by pre-fetching the object head.
+ // So we just do a quick detection by extension name, at least it works for the "View Raw File" for an LFS file on the Web UI.
+ // TODO: OBJECT-STORAGE-CONTENT-TYPE: need a complete solution and refactor for Azure in the future
+
+ if optsOptional != nil {
+ ret.ContentType = optsOptional.ContentType
+ }
+ name = path.Base(name)
+ if ret.ContentType == "" {
+ ext := path.Ext(name)
+ ret.ContentType = public.DetectWellKnownMimeType(ext)
+ }
+ // When using ServeDirect, the URL is from the object storage's web server,
+ // it is not the same origin as Gitea server, so it should be safe enough to use "inline" to render the content directly.
+ // If a browser doesn't support the content type to be displayed inline, browser will download with the filename.
+ ret.ContentDisposition = httplib.EncodeContentDispositionInline(name)
+ return ret
+}
+
// ObjectStorage represents an object storage to handle a bucket and files
type ObjectStorage interface {
Open(path string) (Object, error)
@@ -67,8 +101,21 @@ type ObjectStorage interface {
Stat(path string) (os.FileInfo, error)
Delete(path string) error
- URL(path, name, method string, reqParams url.Values) (*url.URL, error)
- IterateObjects(path string, iterator func(path string, obj Object) error) error
+
+ // ServeDirectURL generates a "serve-direct" URL for the specified blob storage file,
+ // end user (browser) will use this URL to access the file directly from the object storage, bypassing Gitea server.
+ // Usually the link is time-limited (a few minutes) and contains a signature to ensure security.
+ // The generated URL must NOT use the same origin as Gitea server, otherwise it will cause security issues.
+ // * method defines which HTTP method is permitted for certain storage providers (e.g., MinIO).
+ // * opt allows customizing the Content-Type and Content-Disposition headers.
+ // TODO: need to merge "ServeDirect()" check into this function, avoid duplicate code and potential inconsistency.
+ ServeDirectURL(path, name, method string, opt *ServeDirectOptions) (*url.URL, error)
+
+ // IterateObjects calls the iterator function for each object in the storage with the given path as prefix
+ // The "fullPath" argument in callback is the full path in this storage.
+ // * IterateObjects("", ...): iterate all objects in this storage
+ // * IterateObjects("sub-path", ...): iterate all objects with "sub-path" as prefix in this storage, the "fullPath" will be like "sub-path/xxx"
+ IterateObjects(basePath string, iterator func(fullPath string, obj Object) error) error
}
// Copy copies a file from source ObjectStorage to dest ObjectStorage
@@ -131,7 +178,7 @@ var (
// Actions represents actions storage
Actions ObjectStorage = uninitializedStorage
- // Actions Artifacts represents actions artifacts storage
+ // ActionsArtifacts Artifacts represents actions artifacts storage
ActionsArtifacts ObjectStorage = uninitializedStorage
)
diff --git a/modules/storage/storage_test.go b/modules/storage/storage_test.go
index 08f274e74b..83ee2ef793 100644
--- a/modules/storage/storage_test.go
+++ b/modules/storage/storage_test.go
@@ -4,12 +4,14 @@
package storage
import (
+ "net/http"
"strings"
"testing"
"code.gitea.io/gitea/modules/setting"
"github.com/stretchr/testify/assert"
+ "github.com/stretchr/testify/require"
)
func testStorageIterator(t *testing.T, typStr Type, cfg *setting.Storage) {
@@ -50,3 +52,53 @@ func testStorageIterator(t *testing.T, typStr Type, cfg *setting.Storage) {
assert.Len(t, expected, count)
}
}
+
+type expectedServeDirectHeaders struct {
+ ContentType string
+ ContentDisposition string
+}
+
+func testSingleBlobStorageURLContentTypeAndDisposition(t *testing.T, s ObjectStorage, path, name string, expected expectedServeDirectHeaders, reqParams *ServeDirectOptions) {
+ u, err := s.ServeDirectURL(path, name, http.MethodGet, reqParams)
+ require.NoError(t, err)
+ resp, err := http.Get(u.String())
+ require.NoError(t, err)
+ defer resp.Body.Close()
+ if expected.ContentType != "" {
+ assert.Equal(t, expected.ContentType, resp.Header.Get("Content-Type"))
+ }
+ if expected.ContentDisposition != "" {
+ assert.Equal(t, expected.ContentDisposition, resp.Header.Get("Content-Disposition"))
+ }
+}
+
+func testBlobStorageURLContentTypeAndDisposition(t *testing.T, typStr Type, cfg *setting.Storage) {
+ s, err := NewStorage(typStr, cfg)
+ assert.NoError(t, err)
+
+ testFilename := "test.txt"
+ _, err = s.Save(testFilename, strings.NewReader("dummy-content"), -1)
+ assert.NoError(t, err)
+
+ testSingleBlobStorageURLContentTypeAndDisposition(t, s, testFilename, "test.txt", expectedServeDirectHeaders{
+ ContentType: "text/plain; charset=utf-8",
+ ContentDisposition: `inline; filename=test.txt`,
+ }, nil)
+
+ testSingleBlobStorageURLContentTypeAndDisposition(t, s, testFilename, "test.pdf", expectedServeDirectHeaders{
+ ContentType: "application/pdf",
+ ContentDisposition: `inline; filename=test.pdf`,
+ }, nil)
+
+ testSingleBlobStorageURLContentTypeAndDisposition(t, s, testFilename, "test.wasm", expectedServeDirectHeaders{
+ ContentDisposition: `inline; filename=test.wasm`,
+ }, nil)
+
+ testSingleBlobStorageURLContentTypeAndDisposition(t, s, testFilename, "test.wasm", expectedServeDirectHeaders{
+ ContentType: "application/wasm",
+ ContentDisposition: `inline; filename=test.wasm`,
+ }, &ServeDirectOptions{
+ ContentType: "application/wasm",
+ })
+ assert.NoError(t, s.Delete(testFilename))
+}
diff --git a/modules/structs/activity.go b/modules/structs/activity.go
index 9085495593..b896adfed5 100644
--- a/modules/structs/activity.go
+++ b/modules/structs/activity.go
@@ -12,7 +12,7 @@ type Activity struct {
UserID int64 `json:"user_id"` // Receiver user
// the type of action
//
- // enum: create_repo,rename_repo,star_repo,watch_repo,commit_repo,create_issue,create_pull_request,transfer_repo,push_tag,comment_issue,merge_pull_request,close_issue,reopen_issue,close_pull_request,reopen_pull_request,delete_tag,delete_branch,mirror_sync_push,mirror_sync_create,mirror_sync_delete,approve_pull_request,reject_pull_request,comment_pull,publish_release,pull_review_dismissed,pull_request_ready_for_review,auto_merge_pull_request
+ // enum: ["create_repo","rename_repo","star_repo","watch_repo","commit_repo","create_issue","create_pull_request","transfer_repo","push_tag","comment_issue","merge_pull_request","close_issue","reopen_issue","close_pull_request","reopen_pull_request","delete_tag","delete_branch","mirror_sync_push","mirror_sync_create","mirror_sync_delete","approve_pull_request","reject_pull_request","comment_pull","publish_release","pull_review_dismissed","pull_request_ready_for_review","auto_merge_pull_request"]
OpType string `json:"op_type"`
// The ID of the user who performed the action
ActUserID int64 `json:"act_user_id"`
diff --git a/modules/structs/activitypub.go b/modules/structs/activitypub.go
deleted file mode 100644
index 39a6c1ac2a..0000000000
--- a/modules/structs/activitypub.go
+++ /dev/null
@@ -1,10 +0,0 @@
-// Copyright 2022 The Gitea Authors. All rights reserved.
-// SPDX-License-Identifier: MIT
-
-package structs
-
-// ActivityPub type
-type ActivityPub struct {
- // Context defines the JSON-LD context for ActivityPub
- Context string `json:"@context"`
-}
diff --git a/modules/structs/hook.go b/modules/structs/hook.go
index 57af38464a..99c1535155 100644
--- a/modules/structs/hook.go
+++ b/modules/structs/hook.go
@@ -19,6 +19,8 @@ var ErrInvalidReceiveHook = errors.New("Invalid JSON payload received over webho
type Hook struct {
// The unique identifier of the webhook
ID int64 `json:"id"`
+ // Optional human-readable name for the webhook
+ Name string `json:"name"`
// The type of the webhook (e.g., gitea, slack, discord)
Type string `json:"type"`
// Branch filter pattern to determine which branches trigger the webhook
@@ -51,7 +53,7 @@ type CreateHookOptionConfig map[string]string
// CreateHookOption options when create a hook
type CreateHookOption struct {
// required: true
- // enum: dingtalk,discord,gitea,gogs,msteams,slack,telegram,feishu,wechatwork,packagist
+ // enum: ["dingtalk","discord","gitea","gogs","msteams","slack","telegram","feishu","wechatwork","packagist"]
// The type of the webhook to create
Type string `json:"type" binding:"Required"`
// required: true
@@ -66,6 +68,8 @@ type CreateHookOption struct {
// default: false
// Whether the webhook should be active upon creation
Active bool `json:"active"`
+ // Optional human-readable name for the webhook
+ Name string `json:"name" binding:"MaxSize(255)"`
}
// EditHookOption options when modify one hook
@@ -80,6 +84,8 @@ type EditHookOption struct {
AuthorizationHeader string `json:"authorization_header"`
// Whether the webhook is active and will be triggered
Active *bool `json:"active"`
+ // Optional human-readable name
+ Name *string `json:"name,omitzero" binding:"MaxSize(255)"`
}
// Payloader payload is some part of one hook
diff --git a/modules/structs/issue.go b/modules/structs/issue.go
index 2540481d0f..fd29727a43 100644
--- a/modules/structs/issue.go
+++ b/modules/structs/issue.go
@@ -14,6 +14,8 @@ import (
)
// StateType issue state type
+//
+// swagger:enum StateType
type StateType string
const (
@@ -21,10 +23,11 @@ const (
StateOpen StateType = "open"
// StateClosed pr is closed
StateClosed StateType = "closed"
- // StateAll is all
- StateAll StateType = "all"
)
+// StateAll is a query parameter filter value, not a valid object state.
+const StateAll = "all"
+
// PullRequestMeta PR info if an issue is a PR
type PullRequestMeta struct {
HasMerged bool `json:"merged"`
@@ -58,15 +61,11 @@ type Issue struct {
Labels []*Label `json:"labels"`
Milestone *Milestone `json:"milestone"`
// deprecated
- Assignee *User `json:"assignee"`
- Assignees []*User `json:"assignees"`
- // Whether the issue is open or closed
- //
- // type: string
- // enum: open,closed
- State StateType `json:"state"`
- IsLocked bool `json:"is_locked"`
- Comments int `json:"comments"`
+ Assignee *User `json:"assignee"`
+ Assignees []*User `json:"assignees"`
+ State StateType `json:"state"`
+ IsLocked bool `json:"is_locked"`
+ Comments int `json:"comments"`
// swagger:strfmt date-time
Created time.Time `json:"created_at"`
// swagger:strfmt date-time
@@ -82,6 +81,8 @@ type Issue struct {
Repo *RepositoryMeta `json:"repository"`
PinOrder int `json:"pin_order"`
+ // The version of the issue content for optimistic locking
+ ContentVersion int `json:"content_version"`
}
// CreateIssueOption options to create one issue
@@ -115,6 +116,8 @@ type EditIssueOption struct {
// swagger:strfmt date-time
Deadline *time.Time `json:"due_date"`
RemoveDeadline *bool `json:"unset_due_date"`
+ // The current version of the issue content to detect conflicts during editing
+ ContentVersion *int `json:"content_version"`
}
// EditDeadlineOption options for creating a deadline
@@ -132,6 +135,8 @@ type IssueDeadline struct {
}
// IssueFormFieldType defines issue form field type, can be "markdown", "textarea", "input", "dropdown" or "checkboxes"
+//
+// swagger:enum IssueFormFieldType
type IssueFormFieldType string
const (
@@ -168,7 +173,8 @@ func (iff IssueFormField) VisibleInContent() bool {
}
// IssueFormFieldVisible defines issue form field visible
-// swagger:model
+//
+// swagger:enum IssueFormFieldVisible
type IssueFormFieldVisible string
const (
diff --git a/modules/structs/issue_milestone.go b/modules/structs/issue_milestone.go
index 226c613d47..dd8bdc6cda 100644
--- a/modules/structs/issue_milestone.go
+++ b/modules/structs/issue_milestone.go
@@ -40,7 +40,7 @@ type CreateMilestoneOption struct {
// swagger:strfmt date-time
// Deadline is the due date for the milestone
Deadline *time.Time `json:"due_on"`
- // enum: open,closed
+ // enum: ["open","closed"]
// State indicates the initial state of the milestone
State string `json:"state"`
}
@@ -52,6 +52,7 @@ type EditMilestoneOption struct {
// Description provides updated details about the milestone
Description *string `json:"description"`
// State indicates the updated state of the milestone
+ // enum: ["open","closed"]
State *string `json:"state"`
// Deadline is the updated due date for the milestone
Deadline *time.Time `json:"due_on"`
diff --git a/modules/structs/notifications.go b/modules/structs/notifications.go
index cee5da6624..d7aa0783dc 100644
--- a/modules/structs/notifications.go
+++ b/modules/structs/notifications.go
@@ -40,7 +40,7 @@ type NotificationSubject struct {
// Type indicates the type of the notification subject
Type NotifySubjectType `json:"type" binding:"In(Issue,Pull,Commit,Repository)"`
// State indicates the current state of the notification subject
- State StateType `json:"state"`
+ State NotifySubjectStateType `json:"state"`
}
// NotificationCount number of unread notifications
@@ -49,7 +49,22 @@ type NotificationCount struct {
New int64 `json:"new"`
}
+// NotifySubjectStateType represents the state of a notification subject
+// swagger:enum NotifySubjectStateType
+type NotifySubjectStateType string
+
+const (
+ // NotifySubjectStateOpen is an open subject
+ NotifySubjectStateOpen NotifySubjectStateType = "open"
+ // NotifySubjectStateClosed is a closed subject
+ NotifySubjectStateClosed NotifySubjectStateType = "closed"
+ // NotifySubjectStateMerged is a merged pull request
+ NotifySubjectStateMerged NotifySubjectStateType = "merged"
+)
+
// NotifySubjectType represent type of notification subject
+//
+// swagger:enum NotifySubjectType
type NotifySubjectType string
const (
diff --git a/modules/structs/org.go b/modules/structs/org.go
index c3d70ebf00..723689cb53 100644
--- a/modules/structs/org.go
+++ b/modules/structs/org.go
@@ -60,29 +60,27 @@ type CreateOrgOption struct {
// The location of the organization
Location string `json:"location" binding:"MaxSize(50)"`
// possible values are `public` (default), `limited` or `private`
- // enum: public,limited,private
+ // enum: ["public","limited","private"]
Visibility string `json:"visibility" binding:"In(,public,limited,private)"`
// Whether repository administrators can change team access
RepoAdminChangeTeamAccess bool `json:"repo_admin_change_team_access"`
}
-// TODO: make EditOrgOption fields optional after https://gitea.com/go-chi/binding/pulls/5 got merged
-
// EditOrgOption options for editing an organization
type EditOrgOption struct {
// The full display name of the organization
- FullName string `json:"full_name" binding:"MaxSize(100)"`
- // The email address of the organization
- Email string `json:"email" binding:"MaxSize(255)"`
+ FullName *string `json:"full_name" binding:"MaxSize(100)"`
+ // The email address of the organization; use empty string to clear
+ Email *string `json:"email" binding:"MaxSize(255)"`
// The description of the organization
- Description string `json:"description" binding:"MaxSize(255)"`
+ Description *string `json:"description" binding:"MaxSize(255)"`
// The website URL of the organization
- Website string `json:"website" binding:"ValidUrl;MaxSize(255)"`
+ Website *string `json:"website" binding:"ValidUrl;MaxSize(255)"`
// The location of the organization
- Location string `json:"location" binding:"MaxSize(50)"`
+ Location *string `json:"location" binding:"MaxSize(50)"`
// possible values are `public`, `limited` or `private`
- // enum: public,limited,private
- Visibility string `json:"visibility" binding:"In(,public,limited,private)"`
+ // enum: ["public","limited","private"]
+ Visibility *string `json:"visibility" binding:"In(,public,limited,private)"`
// Whether repository administrators can change team access
RepoAdminChangeTeamAccess *bool `json:"repo_admin_change_team_access"`
}
diff --git a/modules/structs/org_team.go b/modules/structs/org_team.go
index d34de5b6d2..f730a5681c 100644
--- a/modules/structs/org_team.go
+++ b/modules/structs/org_team.go
@@ -16,7 +16,7 @@ type Team struct {
Organization *Organization `json:"organization"`
// Whether the team has access to all repositories in the organization
IncludesAllRepositories bool `json:"includes_all_repositories"`
- // enum: none,read,write,admin,owner
+ // enum: ["none","read","write","admin","owner"]
Permission string `json:"permission"`
// example: ["repo.code","repo.issues","repo.ext_issues","repo.wiki","repo.pulls","repo.releases","repo.projects","repo.ext_wiki"]
// Deprecated: This variable should be replaced by UnitsMap and will be dropped in later versions.
@@ -35,7 +35,7 @@ type CreateTeamOption struct {
Description string `json:"description" binding:"MaxSize(255)"`
// Whether the team has access to all repositories in the organization
IncludesAllRepositories bool `json:"includes_all_repositories"`
- // enum: read,write,admin
+ // enum: ["read","write","admin"]
Permission string `json:"permission"`
// example: ["repo.actions","repo.code","repo.issues","repo.ext_issues","repo.wiki","repo.ext_wiki","repo.pulls","repo.releases","repo.projects","repo.ext_wiki"]
// Deprecated: This variable should be replaced by UnitsMap and will be dropped in later versions.
@@ -54,7 +54,7 @@ type EditTeamOption struct {
Description *string `json:"description" binding:"MaxSize(255)"`
// Whether the team has access to all repositories in the organization
IncludesAllRepositories *bool `json:"includes_all_repositories"`
- // enum: read,write,admin
+ // enum: ["read","write","admin"]
Permission string `json:"permission"`
// example: ["repo.code","repo.issues","repo.ext_issues","repo.wiki","repo.pulls","repo.releases","repo.projects","repo.ext_wiki"]
// Deprecated: This variable should be replaced by UnitsMap and will be dropped in later versions.
diff --git a/modules/structs/pull.go b/modules/structs/pull.go
index 7cc58217a0..cd2ffbe719 100644
--- a/modules/structs/pull.go
+++ b/modules/structs/pull.go
@@ -91,6 +91,8 @@ type PullRequest struct {
// The pin order for the pull request
PinOrder int `json:"pin_order"`
+ // The version of the pull request content for optimistic locking
+ ContentVersion int `json:"content_version"`
}
// PRBranchInfo information about a branch
@@ -140,6 +142,8 @@ type CreatePullRequestOption struct {
Reviewers []string `json:"reviewers"`
// The list of team reviewer names
TeamReviewers []string `json:"team_reviewers"`
+ // Whether maintainers can edit the pull request
+ AllowMaintainerEdit *bool `json:"allow_maintainer_edit"`
}
// EditPullRequestOption options when modify pull request
@@ -166,6 +170,8 @@ type EditPullRequestOption struct {
RemoveDeadline *bool `json:"unset_due_date"`
// Whether to allow maintainer edits
AllowMaintainerEdit *bool `json:"allow_maintainer_edit"`
+ // The current version of the pull request content to detect conflicts during editing
+ ContentVersion *int `json:"content_version"`
}
// ChangedFile store information about files affected by the pull request
diff --git a/modules/structs/pull_review.go b/modules/structs/pull_review.go
index e93e4e9720..de0677efab 100644
--- a/modules/structs/pull_review.go
+++ b/modules/structs/pull_review.go
@@ -8,6 +8,8 @@ import (
)
// ReviewStateType review state type
+//
+// swagger:enum ReviewStateType
type ReviewStateType string
const (
@@ -21,10 +23,11 @@ const (
ReviewStateRequestChanges ReviewStateType = "REQUEST_CHANGES"
// ReviewStateRequestReview review is requested from user
ReviewStateRequestReview ReviewStateType = "REQUEST_REVIEW"
- // ReviewStateUnknown state of pr is unknown
- ReviewStateUnknown ReviewStateType = ""
)
+// ReviewStateUnknown is an internal sentinel for unknown review state, not a valid API value.
+const ReviewStateUnknown = ""
+
// PullReview represents a pull request review
type PullReview struct {
ID int64 `json:"id"`
@@ -72,7 +75,7 @@ type PullReviewComment struct {
HTMLPullURL string `json:"pull_request_url"`
}
-// CreatePullReviewOptions are options to create a pull review
+// CreatePullReviewOptions are options to create a pull request review
type CreatePullReviewOptions struct {
Event ReviewStateType `json:"event"`
Body string `json:"body"`
@@ -91,19 +94,19 @@ type CreatePullReviewComment struct {
NewLineNum int64 `json:"new_position"`
}
-// SubmitPullReviewOptions are options to submit a pending pull review
+// SubmitPullReviewOptions are options to submit a pending pull request review
type SubmitPullReviewOptions struct {
Event ReviewStateType `json:"event"`
Body string `json:"body"`
}
-// DismissPullReviewOptions are options to dismiss a pull review
+// DismissPullReviewOptions are options to dismiss a pull request review
type DismissPullReviewOptions struct {
Message string `json:"message"`
Priors bool `json:"priors"`
}
-// PullReviewRequestOptions are options to add or remove pull review requests
+// PullReviewRequestOptions are options to add or remove pull request review requests
type PullReviewRequestOptions struct {
Reviewers []string `json:"reviewers"`
TeamReviewers []string `json:"team_reviewers"`
diff --git a/modules/structs/repo.go b/modules/structs/repo.go
index c1c85837fc..7cd64fd7a4 100644
--- a/modules/structs/repo.go
+++ b/modules/structs/repo.go
@@ -58,26 +58,28 @@ type Repository struct {
Fork bool `json:"fork"`
Template bool `json:"template"`
// the original repository if this repository is a fork, otherwise null
- Parent *Repository `json:"parent,omitempty"`
- Mirror bool `json:"mirror"`
- Size int `json:"size"`
- Language string `json:"language"`
- LanguagesURL string `json:"languages_url"`
- HTMLURL string `json:"html_url"`
- URL string `json:"url"`
- Link string `json:"link"`
- SSHURL string `json:"ssh_url"`
- CloneURL string `json:"clone_url"`
- OriginalURL string `json:"original_url"`
- Website string `json:"website"`
- Stars int `json:"stars_count"`
- Forks int `json:"forks_count"`
- Watchers int `json:"watchers_count"`
- OpenIssues int `json:"open_issues_count"`
- OpenPulls int `json:"open_pr_counter"`
- Releases int `json:"release_counter"`
- DefaultBranch string `json:"default_branch"`
- Archived bool `json:"archived"`
+ Parent *Repository `json:"parent,omitempty"`
+ Mirror bool `json:"mirror"`
+ Size int `json:"size"`
+ Language string `json:"language"`
+ LanguagesURL string `json:"languages_url"`
+ HTMLURL string `json:"html_url"`
+ URL string `json:"url"`
+ Link string `json:"link"`
+ SSHURL string `json:"ssh_url"`
+ CloneURL string `json:"clone_url"`
+ OriginalURL string `json:"original_url"`
+ Website string `json:"website"`
+ Stars int `json:"stars_count"`
+ Forks int `json:"forks_count"`
+ Watchers int `json:"watchers_count"`
+ BranchCount int `json:"branch_count"`
+ OpenIssues int `json:"open_issues_count"`
+ OpenPulls int `json:"open_pr_counter"`
+ Releases int `json:"release_counter"`
+ DefaultBranch string `json:"default_branch"`
+ DefaultTargetBranch string `json:"default_target_branch,omitempty"`
+ Archived bool `json:"archived"`
// swagger:strfmt date-time
Created time.Time `json:"created_at"`
// swagger:strfmt date-time
@@ -112,7 +114,7 @@ type Repository struct {
Internal bool `json:"internal"`
MirrorInterval string `json:"mirror_interval"`
// ObjectFormatName of the underlying git repository
- // enum: sha1,sha256
+ // enum: ["sha1","sha256"]
ObjectFormatName string `json:"object_format_name"`
// swagger:strfmt date-time
MirrorUpdated time.Time `json:"mirror_updated"`
@@ -134,7 +136,7 @@ type CreateRepoOption struct {
// Whether the repository is private
Private bool `json:"private"`
// Label-Set to use
- IssueLabels string `json:"issue_labels"`
+ IssueLabels string `json:"issue_labels" binding:"MaxSize(255)"`
// Whether the repository should be auto-initialized?
AutoInit bool `json:"auto_init"`
// Whether the repository is template
@@ -142,16 +144,16 @@ type CreateRepoOption struct {
// Gitignores to use
Gitignores string `json:"gitignores"`
// License to use
- License string `json:"license"`
+ License string `json:"license" binding:"MaxSize(100)"`
// Readme of the repository to create
- Readme string `json:"readme"`
+ Readme string `json:"readme" binding:"MaxSize(255)"`
// DefaultBranch of the repository (used when initializes and in template)
DefaultBranch string `json:"default_branch" binding:"GitRefName;MaxSize(100)"`
// TrustModel of the repository
- // enum: default,collaborator,committer,collaboratorcommitter
+ // enum: ["default","collaborator","committer","collaboratorcommitter"]
TrustModel string `json:"trust_model"`
- // ObjectFormatName of the underlying git repository
- // enum: sha1,sha256
+ // ObjectFormatName of the underlying git repository, empty string for default (sha1)
+ // enum: ["sha1","sha256"]
ObjectFormatName string `json:"object_format_name" binding:"MaxSize(6)"`
}
@@ -292,6 +294,21 @@ type RenameBranchRepoOption struct {
Name string `json:"name" binding:"Required;GitRefName;MaxSize(100)"`
}
+// UpdateBranchRepoOption options when updating a branch reference in a repository
+// swagger:model
+type UpdateBranchRepoOption struct {
+ // New commit SHA (or any ref) the branch should point to
+ //
+ // required: true
+ NewCommitID string `json:"new_commit_id" binding:"Required"`
+
+ // Expected old commit SHA of the branch; if provided it must match the current tip
+ OldCommitID string `json:"old_commit_id"`
+
+ // Force update even if the change is not a fast-forward
+ Force bool `json:"force"`
+}
+
// TransferRepoOption options when transfer a repository's ownership
// swagger:model
type TransferRepoOption struct {
@@ -361,7 +378,7 @@ type MigrateRepoOptions struct {
// required: true
RepoName string `json:"repo_name" binding:"Required;AlphaDashDot;MaxSize(100)"`
- // enum: git,github,gitea,gitlab,gogs,onedev,gitbucket,codebase,codecommit
+ // enum: ["git","github","gitea","gitlab","gogs","onedev","gitbucket","codebase","codecommit"]
Service string `json:"service"`
AuthUsername string `json:"auth_username"`
AuthPassword string `json:"auth_password"`
diff --git a/modules/structs/repo_actions.go b/modules/structs/repo_actions.go
index b491d6ccce..92ca9bccce 100644
--- a/modules/structs/repo_actions.go
+++ b/modules/structs/repo_actions.go
@@ -196,12 +196,27 @@ type ActionRunner struct {
Name string `json:"name"`
Status string `json:"status"`
Busy bool `json:"busy"`
+ Disabled bool `json:"disabled"`
Ephemeral bool `json:"ephemeral"`
Labels []*ActionRunnerLabel `json:"labels"`
}
+// EditActionRunnerOption represents the editable fields for a runner.
+// swagger:model
+type EditActionRunnerOption struct {
+ // required: true
+ Disabled *bool `json:"disabled"`
+}
+
// ActionRunnersResponse returns Runners
type ActionRunnersResponse struct {
Entries []*ActionRunner `json:"runners"`
TotalCount int64 `json:"total_count"`
}
+
+// RunDetails returns workflow_dispatch runid and url
+type RunDetails struct {
+ WorkflowRunID int64 `json:"workflow_run_id"`
+ RunURL string `json:"run_url"`
+ HTMLURL string `json:"html_url"`
+}
diff --git a/modules/structs/repo_collaborator.go b/modules/structs/repo_collaborator.go
index 9ede7f075a..6b315df403 100644
--- a/modules/structs/repo_collaborator.go
+++ b/modules/structs/repo_collaborator.go
@@ -5,7 +5,7 @@ package structs
// AddCollaboratorOption options when adding a user as a collaborator of a repository
type AddCollaboratorOption struct {
- // enum: read,write,admin
+ // enum: ["read","write","admin"]
// Permission level to grant the collaborator
Permission *string `json:"permission"`
}
diff --git a/modules/structs/repo_file.go b/modules/structs/repo_file.go
index 99efe19e4f..53ce5aeae2 100644
--- a/modules/structs/repo_file.go
+++ b/modules/structs/repo_file.go
@@ -8,12 +8,14 @@ import "time"
// FileOptions options for all file APIs
type FileOptions struct {
- // message (optional) for the commit of this file. if not supplied, a default message will be used
+ // message (optional) is the commit message of the changes. If not supplied, a default message will be used
Message string `json:"message"`
- // branch (optional) to base this file from. if not given, the default branch is used
+ // branch (optional) is the base branch for the changes. If not supplied, the default branch is used
BranchName string `json:"branch" binding:"GitRefName;MaxSize(100)"`
- // new_branch (optional) will make a new branch from `branch` before creating the file
+ // new_branch (optional) will make a new branch from base branch for the changes. If not supplied, the changes will be committed to the base branch
NewBranchName string `json:"new_branch" binding:"GitRefName;MaxSize(100)"`
+ // force_push (optional) will do a force-push if the new branch already exists
+ ForcePush bool `json:"force_push"`
// `author` and `committer` are optional (if only one is given, it will be used for the other, otherwise the authenticated user will be used)
Author Identity `json:"author"`
Committer Identity `json:"committer"`
@@ -22,13 +24,6 @@ type FileOptions struct {
Signoff bool `json:"signoff"`
}
-type FileOptionsWithSHA struct {
- FileOptions
- // the blob ID (SHA) for the file that already exists, it is required for changing existing files
- // required: true
- SHA string `json:"sha" binding:"Required"`
-}
-
func (f *FileOptions) GetFileOptions() *FileOptions {
return f
}
@@ -39,7 +34,7 @@ type FileOptionsInterface interface {
var _ FileOptionsInterface = (*FileOptions)(nil)
-// CreateFileOptions options for creating files
+// CreateFileOptions options for creating a file
// Note: `author` and `committer` are optional (if only one is given, it will be used for the other, otherwise the authenticated user will be used)
type CreateFileOptions struct {
FileOptions
@@ -48,16 +43,21 @@ type CreateFileOptions struct {
ContentBase64 string `json:"content"`
}
-// DeleteFileOptions options for deleting files (used for other File structs below)
+// DeleteFileOptions options for deleting a file
// Note: `author` and `committer` are optional (if only one is given, it will be used for the other, otherwise the authenticated user will be used)
type DeleteFileOptions struct {
- FileOptionsWithSHA
+ FileOptions
+ // the blob ID (SHA) for the file to delete
+ // required: true
+ SHA string `json:"sha" binding:"Required"`
}
-// UpdateFileOptions options for updating files
+// UpdateFileOptions options for updating or creating a file
// Note: `author` and `committer` are optional (if only one is given, it will be used for the other, otherwise the authenticated user will be used)
type UpdateFileOptions struct {
- FileOptionsWithSHA
+ FileOptions
+ // the blob ID (SHA) for the file that already exists to update, or leave it empty to create a new file
+ SHA string `json:"sha"`
// content must be base64 encoded
// required: true
ContentBase64 string `json:"content"`
@@ -72,7 +72,7 @@ type ChangeFileOperation struct {
// indicates what to do with the file: "create" for creating a new file, "update" for updating an existing file,
// "upload" for creating or updating a file, "rename" for renaming a file, and "delete" for deleting an existing file.
// required: true
- // enum: create,update,upload,rename,delete
+ // enum: ["create","update","upload","rename","delete"]
Operation string `json:"operation" binding:"Required"`
// path to the existing or new file
// required: true
diff --git a/modules/svg/svg.go b/modules/svg/svg.go
index fded9d0873..234b1f8c13 100644
--- a/modules/svg/svg.go
+++ b/modules/svg/svg.go
@@ -8,13 +8,32 @@ import (
"html/template"
"path"
"strings"
+ "sync"
gitea_html "code.gitea.io/gitea/modules/htmlutil"
"code.gitea.io/gitea/modules/log"
"code.gitea.io/gitea/modules/public"
)
-var svgIcons map[string]string
+type svgIconItem struct {
+ html string
+ mocking bool
+}
+
+type svgCacheKey struct {
+ icon string
+ size int
+ class string
+}
+
+var (
+ svgIcons map[string]svgIconItem
+
+ svgCacheMu sync.Mutex
+ svgCache sync.Map
+ svgCacheCount int
+ svgCacheLimit = 10000
+)
const defaultSize = 16
@@ -26,7 +45,7 @@ func Init() error {
return err
}
- svgIcons = make(map[string]string, len(files))
+ svgIcons = make(map[string]svgIconItem, len(files))
for _, file := range files {
if path.Ext(file) != ".svg" {
continue
@@ -35,7 +54,7 @@ func Init() error {
if err != nil {
log.Error("Failed to read SVG file %s: %v", file, err)
} else {
- svgIcons[file[:len(file)-4]] = string(Normalize(bs, defaultSize))
+ svgIcons[file[:len(file)-4]] = svgIconItem{html: string(Normalize(bs, defaultSize))}
}
}
return nil
@@ -43,10 +62,13 @@ func Init() error {
func MockIcon(icon string) func() {
if svgIcons == nil {
- svgIcons = make(map[string]string)
+ svgIcons = make(map[string]svgIconItem)
}
orig, exist := svgIcons[icon]
- svgIcons[icon] = fmt.Sprintf(` `, icon, defaultSize, defaultSize)
+ svgIcons[icon] = svgIconItem{
+ html: fmt.Sprintf(` `, icon, defaultSize, defaultSize),
+ mocking: true,
+ }
return func() {
if exist {
svgIcons[icon] = orig
@@ -58,8 +80,28 @@ func MockIcon(icon string) func() {
// RenderHTML renders icons - arguments icon name (string), size (int), class (string)
func RenderHTML(icon string, others ...any) template.HTML {
+ result, _ := renderHTML(icon, others...)
+ return result
+}
+
+func renderHTML(icon string, others ...any) (_ template.HTML, usingCache bool) {
+ if icon == "" {
+ return "", false
+ }
size, class := gitea_html.ParseSizeAndClass(defaultSize, "", others...)
- if svgStr, ok := svgIcons[icon]; ok {
+ if svgItem, ok := svgIcons[icon]; ok {
+ svgStr := svgItem.html
+ // fast path for default size and no classes
+ if size == defaultSize && class == "" {
+ return template.HTML(svgStr), false
+ }
+
+ cacheKey := svgCacheKey{icon, size, class}
+ cachedHTML, cached := svgCache.Load(cacheKey)
+ if cached && !svgItem.mocking {
+ return cachedHTML.(template.HTML), true
+ }
+
// the code is somewhat hacky, but it just works, because the SVG contents are all normalized
if size != defaultSize {
svgStr = strings.Replace(svgStr, fmt.Sprintf(`width="%d"`, defaultSize), fmt.Sprintf(`width="%d"`, size), 1)
@@ -68,8 +110,24 @@ func RenderHTML(icon string, others ...any) template.HTML {
if class != "" {
svgStr = strings.Replace(svgStr, `class="`, fmt.Sprintf(`class="%s `, class), 1)
}
- return template.HTML(svgStr)
+ result := template.HTML(svgStr)
+
+ if !svgItem.mocking {
+ // no need to double-check, the rendering is fast enough and the cache is just an optimization
+ svgCacheMu.Lock()
+ if svgCacheCount >= svgCacheLimit {
+ svgCache.Clear()
+ svgCacheCount = 0
+ }
+ svgCacheCount++
+ svgCache.Store(cacheKey, result)
+ svgCacheMu.Unlock()
+ }
+
+ return result, false
}
+
// during test (or something wrong happens), there is no SVG loaded, so use a dummy span to tell that the icon is missing
- return template.HTML(fmt.Sprintf("%s(%d/%s) ", template.HTMLEscapeString(icon), size, template.HTMLEscapeString(class)))
+ dummy := template.HTML(fmt.Sprintf("%s(%d/%s) ", template.HTMLEscapeString(icon), size, template.HTMLEscapeString(class)))
+ return dummy, false
}
diff --git a/modules/svg/svg_test.go b/modules/svg/svg_test.go
new file mode 100644
index 0000000000..a42f57cec6
--- /dev/null
+++ b/modules/svg/svg_test.go
@@ -0,0 +1,54 @@
+// Copyright 2026 The Gitea Authors. All rights reserved.
+// SPDX-License-Identifier: MIT
+
+package svg
+
+import (
+ "testing"
+
+ "code.gitea.io/gitea/modules/test"
+
+ "github.com/stretchr/testify/assert"
+)
+
+func TestRenderHTMLCache(t *testing.T) {
+ const svgRealContent = "RealContent"
+ svgIcons = map[string]svgIconItem{
+ "test": {html: `` + svgRealContent + ` `},
+ }
+
+ // default params: no cache entry
+ _, usingCache := renderHTML("test")
+ assert.False(t, usingCache)
+ _, usingCache = renderHTML("test")
+ assert.False(t, usingCache)
+
+ // non-default params: cached
+ _, usingCache = renderHTML("test", 24)
+ assert.False(t, usingCache)
+ _, usingCache = renderHTML("test", 24)
+ assert.True(t, usingCache)
+
+ // mocked svg shouldn't be cached
+ revertMock := MockIcon("test")
+ mockedHTML, usingCache := renderHTML("test", 24)
+ assert.False(t, usingCache)
+ assert.NotContains(t, mockedHTML, svgRealContent)
+ revertMock()
+ realHTML, usingCache := renderHTML("test", 24)
+ assert.True(t, usingCache)
+ assert.Contains(t, realHTML, svgRealContent)
+
+ t.Run("CacheWithLimit", func(t *testing.T) {
+ assert.NotZero(t, svgCacheCount)
+ const testLimit = 3
+ defer test.MockVariableValue(&svgCacheLimit, testLimit)()
+ for i := range 10 {
+ _, usingCache = renderHTML("test", 100+i)
+ assert.False(t, usingCache)
+ _, usingCache = renderHTML("test", 100+i)
+ assert.True(t, usingCache)
+ assert.LessOrEqual(t, svgCacheCount, testLimit)
+ }
+ })
+}
diff --git a/modules/sync/status_pool.go b/modules/sync/status_pool.go
deleted file mode 100644
index 6f075d54b7..0000000000
--- a/modules/sync/status_pool.go
+++ /dev/null
@@ -1,57 +0,0 @@
-// Copyright 2016 The Gogs Authors. All rights reserved.
-// SPDX-License-Identifier: MIT
-
-package sync
-
-import (
- "sync"
-
- "code.gitea.io/gitea/modules/container"
-)
-
-// StatusTable is a table maintains true/false values.
-//
-// This table is particularly useful for un/marking and checking values
-// in different goroutines.
-type StatusTable struct {
- lock sync.RWMutex
- pool container.Set[string]
-}
-
-// NewStatusTable initializes and returns a new StatusTable object.
-func NewStatusTable() *StatusTable {
- return &StatusTable{
- pool: make(container.Set[string]),
- }
-}
-
-// StartIfNotRunning sets value of given name to true if not already in pool.
-// Returns whether set value was set to true
-func (p *StatusTable) StartIfNotRunning(name string) bool {
- p.lock.Lock()
- added := p.pool.Add(name)
- p.lock.Unlock()
- return added
-}
-
-// Start sets value of given name to true in the pool.
-func (p *StatusTable) Start(name string) {
- p.lock.Lock()
- p.pool.Add(name)
- p.lock.Unlock()
-}
-
-// Stop sets value of given name to false in the pool.
-func (p *StatusTable) Stop(name string) {
- p.lock.Lock()
- p.pool.Remove(name)
- p.lock.Unlock()
-}
-
-// IsRunning checks if value of given name is set to true in the pool.
-func (p *StatusTable) IsRunning(name string) bool {
- p.lock.RLock()
- exists := p.pool.Contains(name)
- p.lock.RUnlock()
- return exists
-}
diff --git a/modules/sync/status_pool_test.go b/modules/sync/status_pool_test.go
deleted file mode 100644
index e2e48862f5..0000000000
--- a/modules/sync/status_pool_test.go
+++ /dev/null
@@ -1,31 +0,0 @@
-// Copyright 2017 The Gitea Authors. All rights reserved.
-// SPDX-License-Identifier: MIT
-
-package sync
-
-import (
- "testing"
-
- "github.com/stretchr/testify/assert"
-)
-
-func Test_StatusTable(t *testing.T) {
- table := NewStatusTable()
-
- assert.False(t, table.IsRunning("xyz"))
-
- table.Start("xyz")
- assert.True(t, table.IsRunning("xyz"))
-
- assert.False(t, table.StartIfNotRunning("xyz"))
- assert.True(t, table.IsRunning("xyz"))
-
- table.Stop("xyz")
- assert.False(t, table.IsRunning("xyz"))
-
- assert.True(t, table.StartIfNotRunning("xyz"))
- assert.True(t, table.IsRunning("xyz"))
-
- table.Stop("xyz")
- assert.False(t, table.IsRunning("xyz"))
-}
diff --git a/modules/tempdir/tempdir.go b/modules/tempdir/tempdir.go
index 22c2e4ea16..e5e928e449 100644
--- a/modules/tempdir/tempdir.go
+++ b/modules/tempdir/tempdir.go
@@ -19,7 +19,7 @@ type TempDir struct {
}
func (td *TempDir) JoinPath(elems ...string) string {
- return filepath.Join(append([]string{td.base, td.sub}, elems...)...)
+ return filepath.Join(append([]string{td.base, td.sub}, filepath.Join(elems...))...)
}
// MkdirAllSub works like os.MkdirAll, but the base directory must exist
diff --git a/modules/templates/base.go b/modules/templates/base.go
index 2c2f35bbed..c8697cc7ef 100644
--- a/modules/templates/base.go
+++ b/modules/templates/base.go
@@ -4,9 +4,6 @@
package templates
import (
- "slices"
- "strings"
-
"code.gitea.io/gitea/modules/assetfs"
"code.gitea.io/gitea/modules/setting"
)
@@ -18,23 +15,3 @@ func AssetFS() *assetfs.LayeredFS {
func CustomAssets() *assetfs.Layer {
return assetfs.Local("custom", setting.CustomPath, "templates")
}
-
-func ListWebTemplateAssetNames(assets *assetfs.LayeredFS) ([]string, error) {
- files, err := assets.ListAllFiles(".", true)
- if err != nil {
- return nil, err
- }
- return slices.DeleteFunc(files, func(file string) bool {
- return strings.HasPrefix(file, "mail/") || !strings.HasSuffix(file, ".tmpl")
- }), nil
-}
-
-func ListMailTemplateAssetNames(assets *assetfs.LayeredFS) ([]string, error) {
- files, err := assets.ListAllFiles(".", true)
- if err != nil {
- return nil, err
- }
- return slices.DeleteFunc(files, func(file string) bool {
- return !strings.HasPrefix(file, "mail/") || !strings.HasSuffix(file, ".tmpl")
- }), nil
-}
diff --git a/modules/templates/helper.go b/modules/templates/helper.go
index e454bce4bd..f81be1255a 100644
--- a/modules/templates/helper.go
+++ b/modules/templates/helper.go
@@ -6,29 +6,27 @@ package templates
import (
"fmt"
+ "html"
"html/template"
"net/url"
"strconv"
"strings"
+ "sync"
"time"
- user_model "code.gitea.io/gitea/models/user"
"code.gitea.io/gitea/modules/base"
"code.gitea.io/gitea/modules/htmlutil"
"code.gitea.io/gitea/modules/markup"
+ "code.gitea.io/gitea/modules/public"
"code.gitea.io/gitea/modules/setting"
"code.gitea.io/gitea/modules/svg"
"code.gitea.io/gitea/modules/templates/eval"
"code.gitea.io/gitea/modules/util"
"code.gitea.io/gitea/services/gitdiff"
- "code.gitea.io/gitea/services/webtheme"
)
-// NewFuncMap returns functions for injecting to templates
-func NewFuncMap() template.FuncMap {
+func newFuncMapWebPage() template.FuncMap {
return map[string]any{
- "ctx": func() any { return nil }, // template context function
-
"DumpVar": dumpVar,
"NIL": func() any { return nil },
@@ -41,8 +39,6 @@ func NewFuncMap() template.FuncMap {
"QueryEscape": queryEscape,
"QueryBuild": QueryBuild,
"SanitizeHTML": SanitizeHTML,
- "URLJoin": util.URLJoin,
- "DotEscape": dotEscape,
"PathEscape": url.PathEscape,
"PathEscapeSegments": util.PathEscapeSegments,
@@ -63,6 +59,7 @@ func NewFuncMap() template.FuncMap {
// -----------------------------------------------------------------
// time / number / format
+ "ShortSha": base.ShortSha,
"FileSize": base.FileSize,
"CountFmt": countFmt,
"Sec2Hour": util.SecToHours,
@@ -73,6 +70,9 @@ func NewFuncMap() template.FuncMap {
return strconv.FormatInt(time.Since(startTime).Nanoseconds()/1e6, 10) + "ms"
},
+ "AssetURI": public.AssetURI,
+ "ScriptImport": scriptImport,
+
// -----------------------------------------------------------------
// setting
"AppName": func() string {
@@ -84,25 +84,12 @@ func NewFuncMap() template.FuncMap {
"AssetUrlPrefix": func() string {
return setting.StaticURLPrefix + "/assets"
},
- "AppUrl": func() string {
- // The usage of AppUrl should be avoided as much as possible,
- // because the AppURL(ROOT_URL) may not match user's visiting site and the ROOT_URL in app.ini may be incorrect.
- // And it's difficult for Gitea to guess absolute URL correctly with zero configuration,
- // because Gitea doesn't know whether the scheme is HTTP or HTTPS unless the reverse proxy could tell Gitea.
- return setting.AppURL
- },
"AppVer": func() string {
return setting.AppVer
},
- "AppDomain": func() string { // documented in mail-templates.md
+ "AppDomain": func() string { // TODO: helm registry still uses it, need to use current request host in the future
return setting.Domain
},
- "AssetVersion": func() string {
- return setting.AssetVersion
- },
- "DefaultShowFullName": func() bool {
- return setting.UI.DefaultShowFullName
- },
"ShowFooterTemplateLoadTime": func() bool {
return setting.Other.ShowFooterTemplateLoadTime
},
@@ -130,7 +117,6 @@ func NewFuncMap() template.FuncMap {
"DisableWebhooks": func() bool {
return setting.DisableWebhooks
},
- "UserThemeName": userThemeName,
"NotificationSettings": func() map[string]any {
return map[string]any{
"MinTimeout": int(setting.UI.Notification.MinTimeout / time.Millisecond),
@@ -149,8 +135,7 @@ func NewFuncMap() template.FuncMap {
"ReactionToEmoji": reactionToEmoji,
// -----------------------------------------------------------------
- // misc
- "ShortSha": base.ShortSha,
+ // misc (TODO: move them to MiscUtils to avoid bloating the main func map)
"ActionContent2Commits": ActionContent2Commits,
"IsMultilineCommitMessage": isMultilineCommitMessage,
"CommentMustAsDiff": gitdiff.CommentMustAsDiff,
@@ -184,11 +169,6 @@ func queryEscape(s string) template.URL {
return template.URL(url.QueryEscape(s))
}
-// dotEscape wraps a dots in names with ZWJ [U+200D] in order to prevent auto-linkers from detecting these as urls
-func dotEscape(raw string) string {
- return strings.ReplaceAll(raw, ".", "\u200d.\u200d")
-}
-
// iif is an "inline-if", similar util.Iif[T] but templates need the non-generic version,
// and it could be simply used as "{{iif expr trueVal}}" (omit the falseVal).
func iif(condition any, vals ...any) any {
@@ -217,16 +197,6 @@ func evalTokens(tokens ...any) (any, error) {
return n.Value, err
}
-func userThemeName(user *user_model.User) string {
- if user == nil || user.Theme == "" {
- return setting.UI.DefaultTheme
- }
- if webtheme.IsThemeAvailable(user.Theme) {
- return user.Theme
- }
- return setting.UI.DefaultTheme
-}
-
func isQueryParamEmpty(v any) bool {
return v == nil || v == false || v == 0 || v == int64(0) || v == ""
}
@@ -322,3 +292,30 @@ func QueryBuild(a ...any) template.URL {
}
return template.URL(s)
}
+
+var globalVars = sync.OnceValue(func() (ret struct {
+ scriptImportRemainingPart string
+},
+) {
+ // add onerror handler to alert users when the script fails to load:
+ // * for end users: there were many users reporting that "UI doesn't work", actually they made mistakes in their config
+ // * for developers: help them to remember to run "make watch-frontend" to build frontend assets
+ // the message will be directly put in the onerror JS code's string
+ onScriptErrorPrompt := `Please make sure the asset files can be accessed.`
+ if !setting.IsProd {
+ onScriptErrorPrompt += `\n\nFor development, run: make watch-frontend.`
+ }
+ onScriptErrorJS := fmt.Sprintf(`alert('Failed to load asset file from ' + this.src + '. %s')`, onScriptErrorPrompt)
+ ret.scriptImportRemainingPart = `onerror="` + html.EscapeString(onScriptErrorJS) + `">`
+ return ret
+})
+
+func scriptImport(path string, typ ...string) template.HTML {
+ if len(typ) > 0 {
+ if typ[0] == "module" {
+ return template.HTML(`