mirror of
https://codeberg.org/forgejo/forgejo.git
synced 2024-12-27 18:19:17 +00:00
5ae2dbcb14
Now that my colleague just posted a wonderful blog post https://blog.datalad.org/posts/forgejo-runner-podman-deployment/ on forgejo runner, some time I will try to add that damn codespell action to work on CI here ;) meanwhile some typos managed to sneak in and this PR should address them (one change might be functional in a test -- not sure if would cause a fail or not) ### Release notes - [ ] I do not want this change to show in the release notes. - [ ] I want the title to show in the release notes with a link to this pull request. - [ ] I want the content of the `release-notes/<pull request number>.md` to be be used for the release notes instead of the title. Reviewed-on: https://codeberg.org/forgejo/forgejo/pulls/4857 Reviewed-by: Earl Warren <earl-warren@noreply.codeberg.org> Co-authored-by: Yaroslav Halchenko <debian@onerussian.com> Co-committed-by: Yaroslav Halchenko <debian@onerussian.com>
66 lines
1.8 KiB
Go
66 lines
1.8 KiB
Go
// Copyright 2023, 2024 The Forgejo Authors. All rights reserved.
|
|
// SPDX-License-Identifier: MIT
|
|
|
|
package forgefed
|
|
|
|
import (
|
|
"time"
|
|
|
|
"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 NewForgeLike(actorIRI, objectIRI string, startTime time.Time) (ForgeLike, error) {
|
|
result := ForgeLike{}
|
|
result.Type = ap.LikeType
|
|
result.Actor = ap.IRI(actorIRI) // That's us, a User
|
|
result.Object = ap.IRI(objectIRI) // That's them, a Repository
|
|
result.StartTime = startTime
|
|
if valid, err := validation.IsValid(result); !valid {
|
|
return ForgeLike{}, err
|
|
}
|
|
return result, nil
|
|
}
|
|
|
|
func (like ForgeLike) MarshalJSON() ([]byte, error) {
|
|
return like.Activity.MarshalJSON()
|
|
}
|
|
|
|
func (like *ForgeLike) UnmarshalJSON(data []byte) error {
|
|
return like.Activity.UnmarshalJSON(data)
|
|
}
|
|
|
|
func (like ForgeLike) IsNewer(compareTo time.Time) bool {
|
|
return like.StartTime.After(compareTo)
|
|
}
|
|
|
|
func (like ForgeLike) Validate() []string {
|
|
var result []string
|
|
result = append(result, validation.ValidateNotEmpty(string(like.Type), "type")...)
|
|
result = append(result, validation.ValidateOneOf(string(like.Type), []any{"Like"}, "type")...)
|
|
if like.Actor == nil {
|
|
result = append(result, "Actor should not be nil.")
|
|
} else {
|
|
result = append(result, validation.ValidateNotEmpty(like.Actor.GetID().String(), "actor")...)
|
|
}
|
|
if like.Object == nil {
|
|
result = append(result, "Object should not be nil.")
|
|
} else {
|
|
result = append(result, validation.ValidateNotEmpty(like.Object.GetID().String(), "object")...)
|
|
}
|
|
result = append(result, validation.ValidateNotEmpty(like.StartTime.String(), "startTime")...)
|
|
if like.StartTime.IsZero() {
|
|
result = append(result, "StartTime was invalid.")
|
|
}
|
|
|
|
return result
|
|
}
|