diff --git a/modules/activitypub/comment.go b/modules/activitypub/comment.go index 8e76c24c4..97985f65b 100644 --- a/modules/activitypub/comment.go +++ b/modules/activitypub/comment.go @@ -16,7 +16,7 @@ import ( ) // Create a comment -func Comment(ctx context.Context, note ap.Note) error { +func Comment(ctx context.Context, note *ap.Note) error { actorUser, err := personIRIToUser(ctx, note.AttributedTo.GetLink()) if err != nil { return err diff --git a/modules/activitypub/issue.go b/modules/activitypub/issue.go index e1dd0b787..01bd35e5c 100644 --- a/modules/activitypub/issue.go +++ b/modules/activitypub/issue.go @@ -11,6 +11,7 @@ import ( ) // Create an issue -func Issue(ctx context.Context, ticket forgefed.Ticket) { +func Issue(ctx context.Context, ticket *forgefed.Ticket) error { // TODO + return nil } diff --git a/modules/activitypub/pull_request.go b/modules/activitypub/pull_request.go index aefda8da3..3ed766a28 100644 --- a/modules/activitypub/pull_request.go +++ b/modules/activitypub/pull_request.go @@ -6,7 +6,6 @@ package activitypub import ( "context" - "fmt" "strings" issues_model "code.gitea.io/gitea/models/issues" @@ -16,7 +15,7 @@ import ( pull_service "code.gitea.io/gitea/services/pull" ) -func PullRequest(ctx context.Context, ticket forgefed.Ticket) { +func PullRequest(ctx context.Context, ticket *forgefed.Ticket) error { // TODO: Clean this up actorUser, err := personIRIToUser(ctx, ticket.AttributedTo.GetLink()) @@ -62,6 +61,5 @@ func PullRequest(ctx context.Context, ticket forgefed.Ticket) { Type: issues_model.PullRequestGitea, } - err = pull_service.NewPullRequest(ctx, targetRepo, prIssue, []int64{}, []string{}, pr, []int64{}) - fmt.Println(err) + return pull_service.NewPullRequest(ctx, targetRepo, prIssue, []int64{}, []string{}, pr, []int64{}) } diff --git a/routers/api/v1/activitypub/repo.go b/routers/api/v1/activitypub/repo.go index 784be7b6d..ea600bcc6 100644 --- a/routers/api/v1/activitypub/repo.go +++ b/routers/api/v1/activitypub/repo.go @@ -96,6 +96,7 @@ func RepoInbox(ctx *context.APIContext) { } ap.ItemTyperFunc = forgefed.GetItemByType + ap.JSONItemUnmarshal = forgefed.JSONUnmarshalerFn var activity ap.Activity err = activity.UnmarshalJSON(body) if err != nil { @@ -122,31 +123,38 @@ func RepoInbox(ctx *context.APIContext) { // Process activity switch activity.Type { case ap.CreateType: - switch activity.Object.(ap.Object).Type { - case forgefed.RepositoryType: - // Fork created by remote instance - activitypub.ReceiveFork(ctx, activity) - case forgefed.TicketType: - // New issue or pull request - ticket := activity.Object.(forgefed.Ticket) - if ticket.Origin != nil { - // New pull request - activitypub.PullRequest(ctx, ticket) - } else { - // New issue - activitypub.Issue(ctx, ticket) + err = ap.OnObject(activity.Object, func(o *ap.Object) error { + switch o.Type { + case forgefed.RepositoryType: + // Fork created by remote instance + return activitypub.ReceiveFork(ctx, activity) + case forgefed.TicketType: + // New issue or pull request + return forgefed.OnTicket(o, func(t *forgefed.Ticket) error { + if t.Origin != nil { + // New pull request + return activitypub.PullRequest(ctx, t) + } else { + // New issue + return activitypub.Issue(ctx, t) + } + }) + case ap.NoteType: + // New comment + return activitypub.Comment(ctx, o) } - case ap.NoteType: - // New comment - activitypub.Comment(ctx, activity.Object.(ap.Note)) - } + return nil + }) case ap.LikeType: - activitypub.ReceiveStar(ctx, activity) + err = activitypub.ReceiveStar(ctx, activity) default: log.Info("Incoming unsupported ActivityStreams type: %s", activity.Type) ctx.PlainText(http.StatusNotImplemented, "ActivityStreams type not supported") return } + if err != nil { + ctx.ServerError("Error when processing: %s", err) + } ctx.Status(http.StatusNoContent) }