MCPcopy Create free account
hub / github.com/OpenCSGs/csghub-server / CreateRepoDiscussion

Method CreateRepoDiscussion

component/discussion.go:26–59  ·  view source on GitHub ↗
(ctx context.Context, req CreateRepoDiscussionRequest)

Source from the content-addressed store, hash-verified

24}
25
26func (c *DiscussionComponent) CreateRepoDiscussion(ctx context.Context, req CreateRepoDiscussionRequest) (*CreateDiscussionResponse, error) {
27 //TODO:check if the user can access the repo
28
29 //get repo by namespace and name
30 repo, err := c.rs.FindByPath(ctx, req.RepoType, req.Namespace, req.Name)
31 if err != nil {
32 return nil, fmt.Errorf("failed to find repo by path '%s/%s/%s': %w", req.RepoType, req.Namespace, req.Name, err)
33 }
34 user, err := c.us.FindByUsername(ctx, req.CurrentUser)
35 if err != nil {
36 return nil, fmt.Errorf("failed to find user by username '%s': %w", req.CurrentUser, err)
37 }
38 discussion, err := c.ds.Create(ctx, database.Discussion{
39 Title: req.Title,
40 DiscussionableID: repo.ID,
41 DiscussionableType: database.DiscussionableTypeRepo,
42 UserID: user.ID,
43 })
44 if err != nil {
45 return nil, fmt.Errorf("failed to create discussion: %w", err)
46 }
47 resp := &CreateDiscussionResponse{
48 ID: discussion.ID,
49 User: &DiscussionResponse_User{
50 ID: user.ID,
51 Username: user.Username,
52 Avatar: user.Avatar,
53 },
54 Title: discussion.Title,
55 CommentCount: discussion.CommentCount,
56 CreatedAt: discussion.CreatedAt,
57 }
58 return resp, nil
59}
60
61func (c *DiscussionComponent) GetDiscussion(ctx context.Context, id int64) (*ShowDiscussionResponse, error) {
62 discussion, err := c.ds.FindByID(ctx, id)

Callers

nothing calls this directly

Calls 3

FindByUsernameMethod · 0.80
FindByPathMethod · 0.45
CreateMethod · 0.45

Tested by

no test coverage detected