mirror of
https://codeberg.org/forgejo/forgejo.git
synced 2024-11-12 17:56:16 +00:00
rename star -> ForgeLike
This commit is contained in:
parent
4473fb788a
commit
3ab2d9a449
34
models/forgefed/activity.go
Normal file
34
models/forgefed/activity.go
Normal 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
|
||||||
|
}
|
|
@ -12,18 +12,18 @@ import (
|
||||||
|
|
||||||
func Test_StarMarshalJSON(t *testing.T) {
|
func Test_StarMarshalJSON(t *testing.T) {
|
||||||
type testPair struct {
|
type testPair struct {
|
||||||
item Star
|
item ForgeLike
|
||||||
want []byte
|
want []byte
|
||||||
wantErr error
|
wantErr error
|
||||||
}
|
}
|
||||||
|
|
||||||
tests := map[string]testPair{
|
tests := map[string]testPair{
|
||||||
"empty": {
|
"empty": {
|
||||||
item: Star{},
|
item: ForgeLike{},
|
||||||
want: nil,
|
want: nil,
|
||||||
},
|
},
|
||||||
"with ID": {
|
"with ID": {
|
||||||
item: Star{
|
item: ForgeLike{
|
||||||
Activity: ap.Activity{
|
Activity: ap.Activity{
|
||||||
Actor: ap.IRI("https://repo.prod.meissa.de/api/v1/activitypub/user-id/1"),
|
Actor: ap.IRI("https://repo.prod.meissa.de/api/v1/activitypub/user-id/1"),
|
||||||
Type: "Like",
|
Type: "Like",
|
||||||
|
@ -51,17 +51,17 @@ func Test_StarMarshalJSON(t *testing.T) {
|
||||||
func Test_StarUnmarshalJSON(t *testing.T) {
|
func Test_StarUnmarshalJSON(t *testing.T) {
|
||||||
type testPair struct {
|
type testPair struct {
|
||||||
item []byte
|
item []byte
|
||||||
want *Star
|
want *ForgeLike
|
||||||
wantErr error
|
wantErr error
|
||||||
}
|
}
|
||||||
|
|
||||||
tests := map[string]testPair{
|
tests := map[string]testPair{
|
||||||
"with ID": {
|
"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"}`),
|
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: &Star{
|
want: &ForgeLike{
|
||||||
Activity: ap.Activity{
|
Activity: ap.Activity{
|
||||||
Actor: ap.IRI("https://repo.prod.meissa.de/api/activitypub/user-id/1"),
|
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"),
|
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 {
|
for name, tt := range tests {
|
||||||
t.Run(name, func(t *testing.T) {
|
t.Run(name, func(t *testing.T) {
|
||||||
got := new(Star)
|
got := new(ForgeLike)
|
||||||
err := got.UnmarshalJSON(tt.item)
|
err := got.UnmarshalJSON(tt.item)
|
||||||
if (err != nil || tt.wantErr != nil) && tt.wantErr.Error() != err.Error() {
|
if (err != nil || tt.wantErr != nil) && tt.wantErr.Error() != err.Error() {
|
||||||
t.Errorf("UnmarshalJSON() error = \"%v\", wantErr \"%v\"", err, tt.wantErr)
|
t.Errorf("UnmarshalJSON() error = \"%v\", wantErr \"%v\"", err, tt.wantErr)
|
|
@ -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
|
|
||||||
}
|
|
|
@ -74,7 +74,7 @@ func RepositoryInbox(ctx *context.APIContext) {
|
||||||
// - name: body
|
// - name: body
|
||||||
// in: body
|
// in: body
|
||||||
// schema:
|
// schema:
|
||||||
// "$ref": "#/definitions/Star"
|
// "$ref": "#/definitions/ForgeLike"
|
||||||
// responses:
|
// responses:
|
||||||
// "204":
|
// "204":
|
||||||
// "$ref": "#/responses/empty"
|
// "$ref": "#/responses/empty"
|
||||||
|
@ -84,7 +84,7 @@ func RepositoryInbox(ctx *context.APIContext) {
|
||||||
repository := ctx.Repo.Repository
|
repository := ctx.Repo.Repository
|
||||||
log.Info("RepositoryInbox: repo: %v", 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)
|
log.Info("RepositoryInbox: activity:%v", activity)
|
||||||
|
|
||||||
// parse actorID (person)
|
// parse actorID (person)
|
||||||
|
|
|
@ -900,7 +900,7 @@ func Routes() *web.Route {
|
||||||
m.Get("", activitypub.Repository)
|
m.Get("", activitypub.Repository)
|
||||||
m.Post("/inbox", // ToDo: Post or Put?
|
m.Post("/inbox", // ToDo: Post or Put?
|
||||||
// TODO: bind ativities here
|
// TODO: bind ativities here
|
||||||
bind(forgefed.Star{}),
|
bind(forgefed.ForgeLike{}),
|
||||||
// TODO: activitypub.ReqHTTPSignature(),
|
// TODO: activitypub.ReqHTTPSignature(),
|
||||||
activitypub.RepositoryInbox)
|
activitypub.RepositoryInbox)
|
||||||
}, context_service.RepositoryIDAssignmentAPI())
|
}, context_service.RepositoryIDAssignmentAPI())
|
||||||
|
|
|
@ -16,7 +16,7 @@ import (
|
||||||
// swagger:response parameterBodies
|
// swagger:response parameterBodies
|
||||||
type swaggerParameterBodies struct {
|
type swaggerParameterBodies struct {
|
||||||
// in:body
|
// in:body
|
||||||
Star ffed.Star
|
Star ffed.ForgeLike
|
||||||
|
|
||||||
// in:body
|
// in:body
|
||||||
AddCollaboratorOption api.AddCollaboratorOption
|
AddCollaboratorOption api.AddCollaboratorOption
|
||||||
|
|
Loading…
Reference in a new issue