rename star -> ForgeLike

This commit is contained in:
Michael Jerger 2024-01-03 18:29:12 +01:00
parent 4473fb788a
commit 3ab2d9a449
6 changed files with 46 additions and 43 deletions

View file

@ -0,0 +1,34 @@
// Copyright 2023 The Forgejo Authors. All rights reserved.
// SPDX-License-Identifier: MIT
package forgefed
import (
"code.gitea.io/gitea/modules/validation"
ap "github.com/go-ap/activitypub"
)
// ForgeLike activity data type
// swagger:model
type ForgeLike struct {
// swagger:ignore
ap.Activity
}
func (s ForgeLike) MarshalJSON() ([]byte, error) {
return s.Activity.MarshalJSON()
}
func (s *ForgeLike) UnmarshalJSON(data []byte) error {
return s.Activity.UnmarshalJSON(data)
}
func (s ForgeLike) Validate() []string {
var result []string
result = append(result, validation.ValidateNotEmpty(string(s.Type), "type")...)
result = append(result, validation.ValidateNotEmpty(s.Actor.GetID().String(), "actor")...)
result = append(result, validation.ValidateNotEmpty(s.Object.GetID().String(), "object")...)
result = append(result, validation.ValidateNotEmpty(s.StartTime.String(), "startTime")...)
return result
}

View file

@ -12,18 +12,18 @@ import (
func Test_StarMarshalJSON(t *testing.T) {
type testPair struct {
item Star
item ForgeLike
want []byte
wantErr error
}
tests := map[string]testPair{
"empty": {
item: Star{},
item: ForgeLike{},
want: nil,
},
"with ID": {
item: Star{
item: ForgeLike{
Activity: ap.Activity{
Actor: ap.IRI("https://repo.prod.meissa.de/api/v1/activitypub/user-id/1"),
Type: "Like",
@ -51,17 +51,17 @@ func Test_StarMarshalJSON(t *testing.T) {
func Test_StarUnmarshalJSON(t *testing.T) {
type testPair struct {
item []byte
want *Star
want *ForgeLike
wantErr error
}
tests := map[string]testPair{
"with ID": {
item: []byte(`{"source":"forgejo","type":"Star","actor":"https://repo.prod.meissa.de/api/activitypub/user-id/1","object":"https://codeberg.org/api/activitypub/repository-id/1"}`),
want: &Star{
item: []byte(`{"type":"Like","actor":"https://repo.prod.meissa.de/api/activitypub/user-id/1","object":"https://codeberg.org/api/activitypub/repository-id/1"}`),
want: &ForgeLike{
Activity: ap.Activity{
Actor: ap.IRI("https://repo.prod.meissa.de/api/activitypub/user-id/1"),
Type: "Star",
Type: "Like",
Object: ap.IRI("https://codeberg.org/api/activitypub/repository-id/1"),
},
},
@ -70,7 +70,7 @@ func Test_StarUnmarshalJSON(t *testing.T) {
for name, tt := range tests {
t.Run(name, func(t *testing.T) {
got := new(Star)
got := new(ForgeLike)
err := got.UnmarshalJSON(tt.item)
if (err != nil || tt.wantErr != nil) && tt.wantErr.Error() != err.Error() {
t.Errorf("UnmarshalJSON() error = \"%v\", wantErr \"%v\"", err, tt.wantErr)

View file

@ -1,31 +0,0 @@
// Copyright 2023 The Forgejo Authors. All rights reserved.
// SPDX-License-Identifier: MIT
package forgefed
import (
"code.gitea.io/gitea/modules/validation"
ap "github.com/go-ap/activitypub"
)
// Star activity data type
// swagger:model
type Star struct {
// swagger:ignore
ap.Activity
}
func (a Star) MarshalJSON() ([]byte, error) {
return a.Activity.MarshalJSON()
}
func (s *Star) UnmarshalJSON(data []byte) error {
return s.UnmarshalJSON(data)
}
func (s Star) Validate() []string {
var result []string
result = append(result, validation.ValidateNotEmpty(string(s.Type), "type")...)
return result
}

View file

@ -74,7 +74,7 @@ func RepositoryInbox(ctx *context.APIContext) {
// - name: body
// in: body
// schema:
// "$ref": "#/definitions/Star"
// "$ref": "#/definitions/ForgeLike"
// responses:
// "204":
// "$ref": "#/responses/empty"
@ -84,7 +84,7 @@ func RepositoryInbox(ctx *context.APIContext) {
repository := ctx.Repo.Repository
log.Info("RepositoryInbox: repo: %v", repository)
activity := web.GetForm(ctx).(*forgefed.Star)
activity := web.GetForm(ctx).(*forgefed.ForgeLike)
log.Info("RepositoryInbox: activity:%v", activity)
// parse actorID (person)

View file

@ -900,7 +900,7 @@ func Routes() *web.Route {
m.Get("", activitypub.Repository)
m.Post("/inbox", // ToDo: Post or Put?
// TODO: bind ativities here
bind(forgefed.Star{}),
bind(forgefed.ForgeLike{}),
// TODO: activitypub.ReqHTTPSignature(),
activitypub.RepositoryInbox)
}, context_service.RepositoryIDAssignmentAPI())

View file

@ -16,7 +16,7 @@ import (
// swagger:response parameterBodies
type swaggerParameterBodies struct {
// in:body
Star ffed.Star
Star ffed.ForgeLike
// in:body
AddCollaboratorOption api.AddCollaboratorOption