Objects in F3 may have references to other objects:
- Issues reference the User that created them
- Comments contain text fields where references to Issues and Pull Requests can be found
- etc.
For all forges (Gitea, GitHub, etc.) these references are exclusively interpreted as relative to the forge. While an issue comment can contain a URL to a pull request that resides on another forge, it will not be parsed or recognized.
These references in F3 can be converted into full URIs that can be included in ForgeFed and used as ids
. When parsing F3 files they can also be relative to where the parser is within the hierarchy. Here are a few examples:
- URI:
https://example.com/user/1234/project/458/issue/1/comment/435
- Issue 1 interpreted while parsing
https://example.com/user/1234/project/458
is the equivalent of the URIhttps://example.com/user/1234/project/458/issue/1
The currently implementation needs a few new codepaths to manage references for mirroring purposes because they need to be transformed from being relative to the originating forge into being relative to the destination forge.
-
GetReferences
is added to ContainerObjectInterface returning all the references found in the object as a list of tuples:- fieldname of the reference as a string matching a JSON field in the object format
- the reference as a
ContainerObjectInterface
- the list of parents (each of them
ContainerObjectInterface
)
For instance,
GetReferences
on an Issue would return (“poster_id”, *ForgeUser{ID: 43}, *Forge). -
SetReferences
is added to ContainerObjectInterface with a list of tuples (seeGetReferences
). The existing references are replaced with those given in argument. -
RemapReferences is added to ContainerInterface with the following arguments:
- A list of references (tuples returned by
GetReferences
) of the same type (i.e. User, Comment etc.) - the list of parents (each of them
ContainerObjectInterface
) to which each of these reference belong (they must be at the same level of the hierarchy)
and returning the modified list of references with identifiers replaced as instructed by the map of identifiers obtained from the parent common to each object. If there is no mapping, the reference is set to the zero value.
For instance, if an issue comment contains a text that references pull request number 23 and the identifier map has a record that pull request number 23 is mirrored into pull request number 435, it will be modified accordingly. - A list of references (tuples returned by
The context in which the methods are called is the Mirror method. For each object that about to be Upsert (except if they are identical and no action is done), call GetReferences
and RemapReferences
. The remapped references are Upsert before the object that contains them to guarantee they exist (assuming there is no cyclic references). SetReferences
is then called on the object with the remapped references to perform the substitution. The object can now be Upsert: its references have been updated.
For instance, if the “poster_id” of an Issue is user 34 and is mapped into user 584, the “poster_id” field will be updated from 34 to 584 before the issue is Upsert.