Some checks failed
cache-seeder / prune (push) Has been skipped
cache-seeder / frontend (push) Failing after 3s
cache-seeder / python (push) Failing after 3s
cache-seeder / gobuild (push) Failing after 4s
cache-seeder / lint (bindata, lint-backend) (push) Failing after 3s
giteabot backport / giteabot (push) Has been skipped
giteabot / giteabot (push) Has been skipped
cache-prune / prune (push) Has been skipped
release-nightly-snapcraft / build-and-publish (ubuntu-24.04) (push) Has been cancelled
release-nightly-snapcraft / build-and-publish (ubuntu-24.04-arm) (push) Has been cancelled
release-nightly / nightly-binary (push) Has been cancelled
release-nightly / nightly-container (push) Has been cancelled
cron-renovate / cron-renovate (push) Has been skipped
53 lines
1.4 KiB
Go
53 lines
1.4 KiB
Go
// Copyright 2023 The Gitea Authors. All rights reserved.
|
|
// SPDX-License-Identifier: MIT
|
|
|
|
package convert
|
|
|
|
import (
|
|
"context"
|
|
|
|
activities_model "gitea.dev/models/activities"
|
|
perm_model "gitea.dev/models/perm"
|
|
access_model "gitea.dev/models/perm/access"
|
|
user_model "gitea.dev/models/user"
|
|
"gitea.dev/modules/log"
|
|
api "gitea.dev/modules/structs"
|
|
)
|
|
|
|
func ToActivity(ctx context.Context, ac *activities_model.Action, doer *user_model.User) *api.Activity {
|
|
p, err := access_model.GetDoerRepoPermission(ctx, ac.Repo, doer)
|
|
if err != nil {
|
|
log.Error("GetDoerRepoPermission[%d]: %v", ac.RepoID, err)
|
|
p.AccessMode = perm_model.AccessModeNone
|
|
}
|
|
|
|
result := &api.Activity{
|
|
ID: ac.ID,
|
|
UserID: ac.UserID,
|
|
OpType: ac.OpType.String(),
|
|
ActUserID: ac.ActUserID,
|
|
ActUser: ToUser(ctx, ac.ActUser, doer),
|
|
RepoID: ac.RepoID,
|
|
Repo: ToRepo(ctx, ac.Repo, p),
|
|
RefName: ac.RefName,
|
|
IsPrivate: ac.IsPrivate,
|
|
Content: ac.Content,
|
|
Created: ac.CreatedUnix.AsTime(),
|
|
}
|
|
|
|
if ac.Comment != nil {
|
|
result.CommentID = ac.CommentID
|
|
result.Comment = ToAPIComment(ctx, ac.Repo, ac.Comment)
|
|
}
|
|
|
|
return result
|
|
}
|
|
|
|
func ToActivities(ctx context.Context, al activities_model.ActionList, doer *user_model.User) []*api.Activity {
|
|
result := make([]*api.Activity, 0, len(al))
|
|
for _, ac := range al {
|
|
result = append(result, ToActivity(ctx, ac, doer))
|
|
}
|
|
return result
|
|
}
|