gitforge/services/repository
forgejo-backport-action 6bfbcb691a [v16.0/forgejo] fix: only expand recognized variables when generating repo (#13388)
**Backport:** https://codeberg.org/forgejo/forgejo/pulls/12917

I noticed that when generating a repo from a template repo, if a file in the template repo contains an unrecognized variable reference (not part of the set of variables that Forgejo replaces), it attempts to expand it anyway, and ultimately replaces it with just the variable name, stripping off the `$` or `${}`. For example, if a file contains `Authorization: Bearer ${ACCESS_TOKEN}`, in the generated repo this will be changed to `Authorization: Bearer ACCESS_TOKEN` which is unexpected and undesired.

I considered whether it would be possible to fix this by simply making the function passed to `os.Expand()` return `${VARIABLE_NAME}` instead of just `VARIABLE_NAME` for unrecognized keys, but this wouldn't work because it's not possible to distinguish between `$VARIABLE_NAME` and `${VARIABLE_NAME}` syntax, so some variable references would get mangled anyway. Instead, I fixed it by adding a simple regex and using that to perform the replacements instead of `os.Expand()`. I added unit tests and updated one of the generated repo integration tests to validate the functionality.

Co-authored-by: Brandon Rothweiler <bdr9@noreply.codeberg.org>
Reviewed-on: https://codeberg.org/forgejo/forgejo/pulls/13388
Reviewed-by: Gusted <gusted@noreply.codeberg.org>
2026-07-10 01:31:55 +02:00
..
archiver chore: move all test blank imports in a single package (#10662) 2026-01-02 05:32:32 +01:00
commitstatus chore: add modernizer linter (#11936) 2026-04-02 03:29:37 +02:00
files feat: adds option to force overwrite new branch for /contents route (#12663) 2026-06-06 16:45:57 +02:00
gitgraph chore: add modernizer linter (#11936) 2026-04-02 03:29:37 +02:00
adopt.go feat: replace repo based server-side hooks with centralised hooks (#10397) 2026-04-27 22:34:46 +02:00
adopt_test.go chore: add modernizer linter (#11936) 2026-04-02 03:29:37 +02:00
avatar.go feat: serve downsized versions of avatars (#11242) 2026-05-16 12:04:05 +02:00
avatar_test.go
branch.go
cache.go
check.go fix: cleanup data before migration retry (#12370) 2026-05-05 12:41:42 +02:00
collaboration.go [v16.0/forgejo] feat: granular settings for watched repo units (#13385) 2026-07-09 20:56:52 +02:00
collaboration_test.go
commit.go chore: ensure consistent import aliasing for services and models (#10253) 2025-11-30 17:00:57 +01:00
contributors_graph.go
contributors_graph_test.go
create.go fix: cleanup data before migration retry (#12370) 2026-05-05 12:41:42 +02:00
create_test.go fix: cleanup data before migration retry (#12370) 2026-05-05 12:41:42 +02:00
delete.go [v16.0/forgejo] feat: granular settings for watched repo units (#13385) 2026-07-09 20:56:52 +02:00
fork.go feat: replace repo based server-side hooks with centralised hooks (#10397) 2026-04-27 22:34:46 +02:00
fork_test.go
generate.go [v16.0/forgejo] fix: only expand recognized variables when generating repo (#13388) 2026-07-10 01:31:55 +02:00
generate_repo_commit.go fix: remove template file from generated repo (#11691) 2026-03-17 23:39:10 +01:00
generate_repo_commit_legacy.go fix: remove template file from generated repo (#11691) 2026-03-17 23:39:10 +01:00
generate_test.go [v16.0/forgejo] fix: only expand recognized variables when generating repo (#13388) 2026-07-10 01:31:55 +02:00
hooks.go feat: replace repo based server-side hooks with centralised hooks (#10397) 2026-04-27 22:34:46 +02:00
init.go
lfs.go
lfs_test.go fix test: revert unneeded test change with unintended consequences (#12281) 2026-04-27 23:05:18 +02:00
main_test.go
migrate.go fix: compliance with [migrations].ALLOWED_DOMAINS, ...BLOCKED_DOMAINS, and ....ALLOW_LOCALNETWORKS for git & LFS ops (#13129) 2026-06-23 23:40:25 +02:00
push.go [v16.0/forgejo] feat: granular settings for watched repo units (#13385) 2026-07-09 20:56:52 +02:00
repository.go fix: cleanup data before migration retry (#12370) 2026-05-05 12:41:42 +02:00
repository_test.go fix: allow repository deletion when referenced by a repo-specific access token (#11927) 2026-04-01 16:05:20 +02:00
review.go
review_test.go
setting.go
star.go
sync_fork.go
template.go
transfer.go [v16.0/forgejo] feat: granular settings for watched repo units (#13385) 2026-07-09 20:56:52 +02:00
transfer_test.go