mirror of
https://codeberg.org/forgejo/forgejo.git
synced 2024-11-09 16:55:16 +00:00
Refactor if conditional to switch, use split up functions
This commit is contained in:
parent
75ee273f40
commit
976256bf3d
|
@ -229,6 +229,8 @@ func RepositoryInbox(ctx *context.APIContext) {
|
|||
// "204":
|
||||
// "$ref": "#/responses/empty"
|
||||
|
||||
var user *user_model.User
|
||||
|
||||
log.Info("RepositoryInbox: repo %v, %v", ctx.Repo.Repository.OwnerName, ctx.Repo.Repository.Name)
|
||||
activity := web.GetForm(ctx).(*forgefed.Star)
|
||||
log.Info("RepositoryInbox: Activity.Source %v", activity.Source)
|
||||
|
@ -264,23 +266,35 @@ func RepositoryInbox(ctx *context.APIContext) {
|
|||
panic(fmt.Errorf("searching for user failed: %v", err))
|
||||
}
|
||||
|
||||
if len(users) == 0 {
|
||||
// ToDo: We need a remote server with federation enabled to properly test this
|
||||
|
||||
switch len(users) {
|
||||
case 0:
|
||||
{
|
||||
body, err := getBody(remoteStargazer, ctx.Repo.Owner.HTMLURL(), ctx)
|
||||
if err != nil {
|
||||
panic(fmt.Errorf("http get failed: %v", err))
|
||||
}
|
||||
|
||||
person, err := unmarshallPersonJSON(body)
|
||||
if err != nil {
|
||||
panic(fmt.Errorf("getting user failed: %v", err))
|
||||
}
|
||||
|
||||
// create user
|
||||
err = createFederatedUserFromPerson(ctx, person, remoteStargazer)
|
||||
user, err = createFederatedUserFromPerson(person, remoteStargazer)
|
||||
if err != nil {
|
||||
panic(fmt.Errorf("createUser: %w", err))
|
||||
panic(fmt.Errorf("create federated user: %w", err))
|
||||
}
|
||||
err = saveFederatedUserRecord(ctx, user)
|
||||
if err != nil {
|
||||
panic(fmt.Errorf("save user: %w", err))
|
||||
}
|
||||
}
|
||||
case 1:
|
||||
{
|
||||
user = users[0]
|
||||
log.Info("%v", user)
|
||||
}
|
||||
default:
|
||||
{
|
||||
panic(fmt.Errorf("found more than one matches for federated users"))
|
||||
}
|
||||
}
|
||||
|
||||
} else {
|
||||
|
|
Loading…
Reference in a new issue