mirror of
https://lab.forgefriends.org/friendlyforgeformat/gof3.git
synced 2025-10-06 02:52:49 +02:00
forges/forgejo: organizations (part 2)
This commit is contained in:
35
README.md
35
README.md
@@ -8,15 +8,42 @@ As a CLI or as a library, GoF3 provides a single operation: mirroring. The origi
|
||||
* make f3-cli
|
||||
* ./f3-cli mirror -h
|
||||
|
||||
## Running
|
||||
## Example
|
||||
|
||||
### To F3
|
||||
|
||||
Login to https://code.forgejo.org and obtain an application token with
|
||||
read permissions at https://code.forgejo.org/user/settings/applications.
|
||||
|
||||
```sh
|
||||
f3-cli mirror \
|
||||
--from-path /forge/users/root/projects/test \
|
||||
--from-type forgejo --from-forgejo-url http://0.0.0.0:8781 --from-forgejo-user root --from-forgejo-password Wrobyak4 \
|
||||
--to-type filesystem --to-filesystem-directory /tmp/root-test
|
||||
--from-type forgejo --from-forgejo-url https://code.forgejo.org \
|
||||
--from-forgejo-token $codetoken \
|
||||
--from-path /forge/organizations/actions/projects/cascading-pr \
|
||||
--to-type filesystem --to-filesystem-directory /tmp/cascading-pr
|
||||
```
|
||||
|
||||
### From F3
|
||||
|
||||
Run a local Forgejo instance with `serials=1 tests/setup-forgejo.sh` and obtain
|
||||
an application token with:
|
||||
|
||||
```sh
|
||||
docker exec --user 1000 forgejo1 forgejo admin user generate-access-token -u root --raw --scopes 'all,sudo'
|
||||
```
|
||||
|
||||
Mirror issues
|
||||
|
||||
```sh
|
||||
f3-cli mirror \
|
||||
--from-type filesystem --from-filesystem-directory /tmp/cascading-pr \
|
||||
--from-path /forge/organizations/actions/projects/cascading-pr/issues \
|
||||
--to-type forgejo --to-forgejo-url http://0.0.0.0:8781 \
|
||||
--to-forgejo-token $localtoken
|
||||
```
|
||||
|
||||
Visit them at http://0.0.0.0:8781/actions/cascading-pr/issues
|
||||
|
||||
## Testing
|
||||
|
||||
### Requirements
|
||||
|
@@ -10,6 +10,10 @@ type Organization struct {
|
||||
Name string `json:"name"`
|
||||
}
|
||||
|
||||
func (o *Organization) GetName() string {
|
||||
return o.Name
|
||||
}
|
||||
|
||||
func (o *Organization) Clone() Interface {
|
||||
clone := &Organization{}
|
||||
*clone = *o
|
||||
|
@@ -59,9 +59,10 @@ func (o *nodeDriver) getKind() generic.Kind {
|
||||
func (o *nodeDriver) IsNull() bool { return false }
|
||||
|
||||
func (o *nodeDriver) GetIDFromName(ctx context.Context, name string) generic.NodeID {
|
||||
kind := o.getKind()
|
||||
if kind != generic.KindRoot && kind != f3_tree.KindProjects && kind != f3_tree.KindUsers {
|
||||
panic(fmt.Errorf("unxpected kind %s", kind))
|
||||
switch o.getKind() {
|
||||
case generic.KindRoot, f3_tree.KindProjects, f3_tree.KindUsers, f3_tree.KindOrganizations:
|
||||
default:
|
||||
panic(fmt.Errorf("unxpected kind %s", o.getKind()))
|
||||
}
|
||||
for _, child := range o.GetNode().List(ctx) {
|
||||
child.Get(ctx)
|
||||
|
@@ -117,24 +117,37 @@ func (o *project) Get(ctx context.Context) bool {
|
||||
func (o *project) Put(ctx context.Context) generic.NodeID {
|
||||
owner := f3_tree.GetOwner(o.GetNode()).ToFormat()
|
||||
var ownerName string
|
||||
var isOrganization bool
|
||||
switch v := owner.(type) {
|
||||
case *f3.User:
|
||||
ownerName = v.UserName
|
||||
o.maybeSudoName(ownerName)
|
||||
case *f3.Organization:
|
||||
panic(fmt.Errorf("not implemented"))
|
||||
ownerName = v.Name
|
||||
isOrganization = true
|
||||
default:
|
||||
panic(fmt.Errorf("Put unexpected type %T", owner))
|
||||
}
|
||||
defer o.notSudo()
|
||||
|
||||
if o.forked == nil {
|
||||
repo, _, err := o.getClient().CreateRepo(forgejo_sdk.CreateRepoOption{
|
||||
Name: o.forgejoProject.Name,
|
||||
Description: o.forgejoProject.Description,
|
||||
Private: o.forgejoProject.Private,
|
||||
DefaultBranch: o.forgejoProject.DefaultBranch,
|
||||
})
|
||||
var repo *forgejo_sdk.Repository
|
||||
var err error
|
||||
if isOrganization {
|
||||
repo, _, err = o.getClient().CreateOrgRepo(ownerName, forgejo_sdk.CreateRepoOption{
|
||||
Name: o.forgejoProject.Name,
|
||||
Description: o.forgejoProject.Description,
|
||||
Private: o.forgejoProject.Private,
|
||||
DefaultBranch: o.forgejoProject.DefaultBranch,
|
||||
})
|
||||
} else {
|
||||
repo, _, err = o.getClient().CreateRepo(forgejo_sdk.CreateRepoOption{
|
||||
Name: o.forgejoProject.Name,
|
||||
Description: o.forgejoProject.Description,
|
||||
Private: o.forgejoProject.Private,
|
||||
DefaultBranch: o.forgejoProject.DefaultBranch,
|
||||
})
|
||||
}
|
||||
if err != nil {
|
||||
panic(err)
|
||||
}
|
||||
|
@@ -40,6 +40,7 @@ function setup_forgejo() {
|
||||
-e "FORGEJO__queue__TYPE=immediate" \
|
||||
-e "FORGEJO__queue.push_update__TYPE=immediate" \
|
||||
-e "FORGEJO__repository__ENABLE_PUSH_CREATE_USER=true" \
|
||||
-e "FORGEJO__repository__ENABLE_PUSH_CREATE_ORG=true" \
|
||||
-e "FORGEJO__repository__DEFAULT_PUSH_CREATE_PRIVATE=false" \
|
||||
-e "FORGEJO__service__DEFAULT_KEEP_EMAIL_PRIVATE=true" \
|
||||
-d codeberg.org/forgejo-experimental/forgejo:1.22.0-test
|
||||
|
Reference in New Issue
Block a user