You cannot select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
forgejo/modules
Aravinth Manivannan fa73cbf5a7
Store the foreign ID of issues during migration (#18446)
Storing the foreign identifier of an imported issue in the database is a prerequisite to implement idempotent migrations or mirror for issues. It is a baby step towards mirroring that introduces a new table.

At the moment when an issue is created by the Gitea uploader, it fails if the issue already exists. The Gitea uploader could be modified so that, instead of failing, it looks up the database to find an existing issue. And if it does it would update the issue instead of creating a new one. However this is not currently possible because an information is missing from the database: the foreign identifier that uniquely represents the issue being migrated is not persisted. With this change, the foreign identifier is stored in the database and the Gitea uploader will then be able to run a query to figure out if a given issue being imported already exists.

The implementation of mirroring for issues, pull requests, releases, etc. can be done in three steps:

1. Store an identifier for the element being mirrored (issue, pull request...) in the database (this is the purpose of these changes)
2. Modify the Gitea uploader to be able to update an existing repository with all it contains (issues, pull request...) instead of failing if it exists
3. Optimize the Gitea uploader to speed up the updates, when possible.

The second step creates code that does not yet exist to enable idempotent migrations with the Gitea uploader. When a migration is done for the first time, the behavior is not changed. But when a migration is done for a repository that already exists, this new code is used to update it.

The third step can use the code created in the second step to optimize and speed up migrations. For instance, when a migration is resumed, an issue that has an update time that is not more recent can be skipped and only newly created issues or updated ones will be updated. Another example of optimization could be that a webhook notifies Gitea when an issue is updated. The code triggered by the webhook would download only this issue and call the code created in the second step to update the issue, as if it was in the process of an idempotent migration.

The ForeignReferences table is added to contain local and foreign ID pairs relative to a given repository. It can later be used for pull requests and other artifacts that can be mirrored. Although the foreign id could be added as a single field in issues or pull requests, it would need to be added to all tables that represent something that can be mirrored. Creating a new table makes for a simpler and more generic design. The drawback is that it requires an extra lookup to obtain the information. However, this extra information is only required during migration or mirroring and does not impact the way Gitea currently works.

The foreign identifier of an issue or pull request is similar to the identifier of an external user, which is stored in reactions, issues, etc. as OriginalPosterID and so on. The representation of a user is however different and the ability of users to link their account to an external user at a later time is also a logic that is different from what is involved in mirroring or migrations. For these reasons, despite some commonalities, it is unclear at this time how the two tables (foreign reference and external user) could be merged together.

The ForeignID field is extracted from the issue migration context so that it can be dumped in files with dump-repo and later restored via restore-repo.

The GetAllComments downloader method is introduced to simplify the implementation and not overload the Context for the purpose of pagination. It also clarifies in which context the comments are paginated and in which context they are not.

The Context interface is no longer useful for the purpose of retrieving the LocalID and ForeignID since they are now both available from the PullRequest and Issue struct. The Reviewable and Commentable interfaces replace and serve the same purpose.

The Context data member of PullRequest and Issue becomes a DownloaderContext to clarify that its purpose is not to support in memory operations while the current downloader is acting but is not otherwise persisted. It is, for instance, used by the GitLab downloader to store the IsMergeRequest boolean and sort out issues.

---
[source](https://lab.forgefriends.org/forgefriends/forgefriends/-/merge_requests/36)

Signed-off-by: Loïc Dachary <loic@dachary.org>
Co-authored-by: Loïc Dachary <loic@dachary.org>
2 years ago
..
activitypub format with gofumpt (#18184) 2 years ago
analyze Use git attributes to determine generated and vendored status for language stats and diffs (#16773) 3 years ago
appstate format with gofumpt (#18184) 2 years ago
auth RSS/Atom support for Repos (#19055) 2 years ago
avatar format with gofumpt (#18184) 2 years ago
base format with gofumpt (#18184) 2 years ago
cache format with gofumpt (#18184) 2 years ago
charset Don't treat BOM escape sequence as hidden character. (#18909) 2 years ago
context RSS/Atom support for Repos (#19055) 2 years ago
convert API: Return primary language and repository language stats API URL (#18396) 2 years ago
csv format with gofumpt (#18184) 2 years ago
doctor Delete old git.NewCommand() and use it as git.NewCommandContext() (#18552) 2 years ago
emoji format with gofumpt (#18184) 2 years ago
eventsource Simplify parameter types (#18006) 3 years ago
generate Use base32 for 2FA scratch token (#18384) 2 years ago
git rm .sample hooks which aren't used (#19101) 2 years ago
gitgraph Change git.cmd to RunWithContext (#18693) 2 years ago
graceful Immediately Hammer if second kill is sent (#18823) 2 years ago
hcaptcha hCaptcha Support (#12594) 4 years ago
highlight format with gofumpt (#18184) 2 years ago
hostmatcher Simplify parameter types (#18006) 3 years ago
httpcache format with gofumpt (#18184) 2 years ago
httplib refactor httplib (#18338) 2 years ago
indexer Prevent Stats Indexer reporting error if repo dir missing (#18870) 2 years ago
json Make gitea, gitea-vet future-proof (#18361) 2 years ago
lfs Improve SyncMirrors logging (#19045) 2 years ago
log migrations: add test for importing pull requests in gitea uploader (#18752) 2 years ago
markup Support ignore all santize for external renderer (#18984) 2 years ago
metrics format with gofumpt (#18184) 2 years ago
migration Store the foreign ID of issues during migration (#18446) 2 years ago
nosql [API] Allow removing issues (#18879) 2 years ago
notification [API] Allow removing issues (#18879) 2 years ago
options format with gofumpt (#18184) 2 years ago
password Fixed assert statements. (#16089) 3 years ago
pprof refactor: move from io/ioutil to io and os package (#17109) 3 years ago
private Validate migration files (#18203) 2 years ago
process format with gofumpt (#18184) 2 years ago
proxy Return nil proxy function if proxy not enabled (#16742) 3 years ago
public Fix mime-type detection for HTTP server (#18370) 2 years ago
queue Add number in queue status to monitor page (#18712) 2 years ago
recaptcha refactor: move from io/ioutil to io and os package (#17109) 3 years ago
references format with gofumpt (#18184) 2 years ago
repository Improve SyncMirrors logging (#19045) 2 years ago
secret Use `CryptoRandomBytes` instead of `CryptoRandomString` (#18439) 2 years ago
session format with gofumpt (#18184) 2 years ago
setting Update golang.org/x/crypto (#19097) 2 years ago
ssh Update golang.org/x/crypto (#19097) 2 years ago
storage Fix lfs bug (#19072) 2 years ago
structs Add config option to disable "Update branch by rebase" (#18745) 2 years ago
svg refactor: move from io/ioutil to io and os package (#17109) 3 years ago
sync Fix missing unlock in uniquequeue (#9790) 5 years ago
templates Fix display time of milestones (#18753) 2 years ago
test format with gofumpt (#18184) 2 years ago
timeutil format with gofumpt (#18184) 2 years ago
translation Refactor i18n, use Locale to provide i18n/translation related functions (#18648) 2 years ago
typesniffer format with gofumpt (#18184) 2 years ago
updatechecker format with gofumpt (#18184) 2 years ago
upload Simplify parameter types (#18006) 3 years ago
uri Prevent NPE if gitea uploader fails to open url (#18080) 3 years ago
user Add gitea-vet (#10948) 4 years ago
util use go1.18 to build gitea (#19099) 2 years ago
validation format with gofumpt (#18184) 2 years ago
web Fix route wrap (#18360) 2 years ago