mirror of
https://codeberg.org/forgejo/forgejo.git
synced 2024-12-25 01:10:37 +00:00
fix linting
This commit is contained in:
parent
3b244d673b
commit
3ef57385ec
6 changed files with 24 additions and 54 deletions
|
@ -811,12 +811,12 @@ func ValidateUser(u *User, cols ...string) error {
|
|||
return nil
|
||||
}
|
||||
|
||||
func (user User) Validate() []string {
|
||||
func (u User) Validate() []string {
|
||||
var result []string
|
||||
if err := ValidateUser(&user); err != nil {
|
||||
if err := ValidateUser(&u); err != nil {
|
||||
result = append(result, err.Error())
|
||||
}
|
||||
if err := ValidateEmail(user.Email); err != nil {
|
||||
if err := ValidateEmail(u.Email); err != nil {
|
||||
result = append(result, err.Error())
|
||||
}
|
||||
return result
|
||||
|
|
|
@ -65,7 +65,7 @@ func FindFederatedUser(ctx context.Context, externalID string,
|
|||
if err != nil {
|
||||
return nil, nil, err
|
||||
} else if !has {
|
||||
return nil, nil, fmt.Errorf("User %v for federated user is missing.", federatedUser.UserID)
|
||||
return nil, nil, fmt.Errorf("User %v for federated user is missing", federatedUser.UserID)
|
||||
}
|
||||
|
||||
if res, err := validation.IsValid(*user); !res {
|
||||
|
|
|
@ -22,10 +22,10 @@ import (
|
|||
"github.com/google/uuid"
|
||||
)
|
||||
|
||||
func LikeActivity(ctx *context.APIContext, form any, repositoryId int64) (error, int, string) {
|
||||
func LikeActivity(ctx *context.APIContext, form any, repositoryID int64) (int, string, error) {
|
||||
activity := form.(*forgefed.ForgeLike)
|
||||
if res, err := validation.IsValid(activity); !res {
|
||||
return err, http.StatusNotAcceptable, "Invalid activity"
|
||||
return http.StatusNotAcceptable, "Invalid activity", err
|
||||
}
|
||||
log.Info("Activity validated:%v", activity)
|
||||
|
||||
|
@ -33,69 +33,69 @@ func LikeActivity(ctx *context.APIContext, form any, repositoryId int64) (error,
|
|||
actorURI := activity.Actor.GetID().String()
|
||||
rawActorID, err := forgefed.NewActorID(actorURI)
|
||||
if err != nil {
|
||||
return err, http.StatusInternalServerError, "Invalid ActorID"
|
||||
return http.StatusInternalServerError, "Invalid ActorID", err
|
||||
}
|
||||
federationHost, err := forgefed.FindFederationHostByFqdn(ctx, rawActorID.Host)
|
||||
if err != nil {
|
||||
return err, http.StatusInternalServerError, "Could not loading FederationHost"
|
||||
return http.StatusInternalServerError, "Could not loading FederationHost", err
|
||||
}
|
||||
if federationHost == nil {
|
||||
result, err := CreateFederationHostFromAP(ctx, rawActorID)
|
||||
if err != nil {
|
||||
return err, http.StatusNotAcceptable, "Invalid FederationHost"
|
||||
return http.StatusNotAcceptable, "Invalid FederationHost", err
|
||||
}
|
||||
federationHost = result
|
||||
}
|
||||
if !activity.IsNewer(federationHost.LatestActivity) {
|
||||
return fmt.Errorf("Activity already processed"), http.StatusNotAcceptable, "Activity out of order."
|
||||
return http.StatusNotAcceptable, "Activity out of order.", fmt.Errorf("Activity already processed")
|
||||
}
|
||||
actorID, err := forgefed.NewPersonID(actorURI, string(federationHost.NodeInfo.Source))
|
||||
if err != nil {
|
||||
return err, http.StatusNotAcceptable, "Invalid PersonID"
|
||||
return http.StatusNotAcceptable, "Invalid PersonID", err
|
||||
}
|
||||
log.Info("Actor accepted:%v", actorID)
|
||||
|
||||
// parse objectID (repository)
|
||||
objectID, err := forgefed.NewRepositoryID(activity.Object.GetID().String(), string(forgefed.ForgejoSourceType))
|
||||
if err != nil {
|
||||
return err, http.StatusNotAcceptable, "Invalid objectId"
|
||||
return http.StatusNotAcceptable, "Invalid objectId", err
|
||||
}
|
||||
if objectID.ID != fmt.Sprint(repositoryId) {
|
||||
return err, http.StatusNotAcceptable, "Invalid objectId"
|
||||
if objectID.ID != fmt.Sprint(repositoryID) {
|
||||
return http.StatusNotAcceptable, "Invalid objectId", err
|
||||
}
|
||||
log.Info("Object accepted:%v", objectID)
|
||||
|
||||
// Check if user already exists
|
||||
user, _, err := user.FindFederatedUser(ctx, actorID.ID, federationHost.ID)
|
||||
if err != nil {
|
||||
return err, http.StatusInternalServerError, "Searching for user failed"
|
||||
return http.StatusInternalServerError, "Searching for user failed", err
|
||||
}
|
||||
if user != nil {
|
||||
log.Info("Found local federatedUser: %v", user)
|
||||
} else {
|
||||
user, _, err = CreateUserFromAP(ctx, actorID, federationHost.ID)
|
||||
if err != nil {
|
||||
return err, http.StatusInternalServerError, "Error creating federatedUser"
|
||||
return http.StatusInternalServerError, "Error creating federatedUser", err
|
||||
}
|
||||
log.Info("Created federatedUser from ap: %v", user)
|
||||
}
|
||||
log.Info("Got user:%v", user.Name)
|
||||
|
||||
// execute the activity if the repo was not stared already
|
||||
alreadyStared := repo.IsStaring(ctx, user.ID, repositoryId)
|
||||
alreadyStared := repo.IsStaring(ctx, user.ID, repositoryID)
|
||||
if !alreadyStared {
|
||||
err = repo.StarRepo(ctx, user.ID, repositoryId, true)
|
||||
err = repo.StarRepo(ctx, user.ID, repositoryID, true)
|
||||
if err != nil {
|
||||
return err, http.StatusNotAcceptable, "Error staring"
|
||||
return http.StatusNotAcceptable, "Error staring", err
|
||||
}
|
||||
}
|
||||
federationHost.LatestActivity = activity.StartTime
|
||||
err = forgefed.UpdateFederationHost(ctx, federationHost)
|
||||
if err != nil {
|
||||
return err, http.StatusNotAcceptable, "Error updating federatedHost"
|
||||
return http.StatusNotAcceptable, "Error updating federatedHost", err
|
||||
}
|
||||
|
||||
return nil, 0, ""
|
||||
return 0, "", nil
|
||||
}
|
||||
|
||||
func CreateFederationHostFromAP(ctx *context.APIContext, actorID forgefed.ActorID) (*forgefed.FederationHost, error) {
|
||||
|
|
|
@ -58,8 +58,8 @@ func (s *Service) Register(
|
|||
// TODO: agent_labels should be removed from pb after Gitea 1.20 released.
|
||||
// Old version runner's agent_labels slice is not empty and labels slice is empty.
|
||||
// And due to compatibility with older versions, it is temporarily marked as Deprecated in pb, so use `//nolint` here.
|
||||
if len(req.Msg.AgentLabels) > 0 && len(req.Msg.Labels) == 0 { //nolint:staticcheck
|
||||
labels = req.Msg.AgentLabels //nolint:staticcheck
|
||||
if len(req.Msg.AgentLabels) > 0 && len(req.Msg.Labels) == 0 {
|
||||
labels = req.Msg.AgentLabels
|
||||
}
|
||||
|
||||
// create new runner
|
||||
|
|
|
@ -73,7 +73,7 @@ func RepositoryInbox(ctx *context.APIContext) {
|
|||
log.Info("RepositoryInbox: repo: %v", repository)
|
||||
|
||||
form := web.GetForm(ctx)
|
||||
err, httpStatus, title := forgefed.LikeActivity(ctx, form, repository.ID)
|
||||
httpStatus, title, err := forgefed.LikeActivity(ctx, form, repository.ID)
|
||||
if err != nil {
|
||||
ctx.Error(httpStatus, title, err)
|
||||
}
|
||||
|
|
|
@ -4,10 +4,8 @@
|
|||
package activitypub
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"net/http"
|
||||
|
||||
"code.gitea.io/gitea/models/db"
|
||||
"code.gitea.io/gitea/models/forgefed"
|
||||
"code.gitea.io/gitea/modules/activitypub"
|
||||
"code.gitea.io/gitea/modules/context"
|
||||
|
@ -17,34 +15,6 @@ import (
|
|||
"github.com/go-ap/jsonld"
|
||||
)
|
||||
|
||||
// Respond with a ActivityStreams Collection
|
||||
func responseCollection(ctx *context.APIContext, iri string, listOptions db.ListOptions, items []string, count int64) {
|
||||
collection := ap.OrderedCollectionNew(ap.IRI(iri))
|
||||
collection.First = ap.IRI(iri + "?page=1")
|
||||
collection.TotalItems = uint(count)
|
||||
if listOptions.Page == 0 {
|
||||
response(ctx, collection)
|
||||
return
|
||||
}
|
||||
|
||||
page := ap.OrderedCollectionPageNew(collection)
|
||||
page.ID = ap.IRI(fmt.Sprintf("%s?page=%d", iri, listOptions.Page))
|
||||
if listOptions.Page > 1 {
|
||||
page.Prev = ap.IRI(fmt.Sprintf("%s?page=%d", iri, listOptions.Page-1))
|
||||
}
|
||||
if listOptions.Page*listOptions.PageSize < int(count) {
|
||||
page.Next = ap.IRI(fmt.Sprintf("%s?page=%d", iri, listOptions.Page+1))
|
||||
}
|
||||
for _, item := range items {
|
||||
err := page.OrderedItems.Append(ap.IRI(item))
|
||||
if err != nil {
|
||||
ctx.ServerError("Append", err)
|
||||
}
|
||||
}
|
||||
|
||||
response(ctx, page)
|
||||
}
|
||||
|
||||
// Respond with an ActivityStreams object
|
||||
func response(ctx *context.APIContext, v interface{}) {
|
||||
binary, err := jsonld.WithContext(
|
||||
|
|
Loading…
Reference in a new issue