this repo has no description
1package db
2
3import (
4 "sort"
5 "time"
6)
7
8type ProfileTimelineEvent struct {
9 EventAt time.Time
10 Type string
11 *Issue
12 *Pull
13 *Repo
14}
15
16func MakeProfileTimeline(e Execer, forDid string) ([]ProfileTimelineEvent, error) {
17 timeline := []ProfileTimelineEvent{}
18
19 pulls, err := GetPullsByOwnerDid(e, forDid)
20 if err != nil {
21 return timeline, err
22 }
23
24 for _, pull := range pulls {
25 repo, err := GetRepoByAtUri(e, string(pull.RepoAt))
26 if err != nil {
27 return timeline, err
28 }
29
30 timeline = append(timeline, ProfileTimelineEvent{
31 EventAt: pull.Created,
32 Type: "pull",
33 Pull: &pull,
34 Repo: repo,
35 })
36 }
37
38 issues, err := GetIssuesByOwnerDid(e, forDid)
39 if err != nil {
40 return timeline, err
41 }
42
43 for _, issue := range issues {
44 repo, err := GetRepoByAtUri(e, string(issue.RepoAt))
45 if err != nil {
46 return timeline, err
47 }
48
49 timeline = append(timeline, ProfileTimelineEvent{
50 EventAt: *issue.Created,
51 Type: "issue",
52 Issue: &issue,
53 Repo: repo,
54 })
55 }
56
57 repos, err := GetAllReposByDid(e, forDid)
58 if err != nil {
59 return timeline, err
60 }
61
62 for _, repo := range repos {
63 timeline = append(timeline, ProfileTimelineEvent{
64 EventAt: repo.Created,
65 Type: "repo",
66 Repo: &repo,
67 })
68 }
69
70 sort.Slice(timeline, func(i, j int) bool {
71 return timeline[i].EventAt.After(timeline[j].EventAt)
72 })
73
74 return timeline, nil
75}