aboutsummaryrefslogtreecommitdiff
blob: aca52e986ab642db056b44dbce0dc0fe6264d2d0 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
package models

import (
	"strconv"
)

type GithubPullRequest struct {
	Id          string `pg:",pk"`
	Closed      bool
	Url         string
	Title       string
	CreatedAt   string
	UpdatedAt   string
	CiState     string
	CiStateLink string
	Labels      []GitHubPullRequestLabelNode
	Comments    int
	Files       []GitHubPullRequestFileNode
	Author      string
}

type PackageToGithubPullRequest struct {
	Id                  string `pg:",pk"`
	PackageAtom         string
	GithubPullRequestId string
}

// -- raw json models

type GitHubPullRequestQueryResult struct {
	Data GitHubPullRequestQueryResultData `json:"data"`
}

func (res *GitHubPullRequestQueryResult) HasNextPage() bool {
	return res.Data.Search.PageInfo.HasNextPage
}

func (res *GitHubPullRequestQueryResult) EndCursor() string {
	return res.Data.Search.PageInfo.EndCursor
}

func (res *GitHubPullRequestQueryResult) AppendPullRequest(pullRequests map[int]*GithubPullRequest) {
	for _, rawObject := range res.Data.Search.Edges {
		pullRequest := rawObject.Node
		var ciState, ciStateLink string
		if pullRequest.Commits.Nodes != nil && len(pullRequest.Commits.Nodes) > 0 {
			ciState = pullRequest.Commits.Nodes[0].Commit.Status.State

			if pullRequest.Commits.Nodes[0].Commit.Status.Contexts != nil && len(pullRequest.Commits.Nodes[0].Commit.Status.Contexts) > 0 {
				ciStateLink = pullRequest.Commits.Nodes[0].Commit.Status.Contexts[0].TargetUrl
			}
		}

		pullRequests[pullRequest.Number] = &GithubPullRequest{
			Id:          strconv.Itoa(pullRequest.Number),
			Closed:      pullRequest.Closed,
			Url:         pullRequest.Url,
			Title:       pullRequest.Title,
			CreatedAt:   pullRequest.CreatedAt,
			UpdatedAt:   pullRequest.UpdatedAt,
			CiState:     ciState,
			CiStateLink: ciStateLink,
			Labels:      pullRequest.CreateLabelsArray(),
			Comments:    pullRequest.Comments.TotalCount,
			Files:       pullRequest.CreateFilesArray(),
			Author:      pullRequest.Author.Login,
		}
	}
}

func (node *GitHubPullRequestSearchNode) CreateLabelsArray() []GitHubPullRequestLabelNode {
	labels := make([]GitHubPullRequestLabelNode, len(node.Labels.Edges))
	for i, label := range node.Labels.Edges {
		labels[i] = label.Node
	}
	return labels
}

func (node *GitHubPullRequestSearchNode) CreateFilesArray() []GitHubPullRequestFileNode {
	labels := make([]GitHubPullRequestFileNode, len(node.Files.Edges))
	for i, label := range node.Files.Edges {
		labels[i] = label.Node
	}
	return labels
}

type GitHubPullRequestQueryResultData struct {
	Search GitHubPullRequestSearchResult `json:"search"`
}

type GitHubPullRequestSearchResult struct {
	PageInfo GitHubPullRequestSearchPageInfo `json:"pageInfo"`
	Edges    []GitHubPullRequestSearchEdge   `json:"edges"`
}

type GitHubPullRequestSearchPageInfo struct {
	HasNextPage bool   `json:"hasNextPage"`
	StartCursor string `json:"startCursor"`
	EndCursor   string `json:"endCursor"`
}

type GitHubPullRequestSearchEdge struct {
	Node GitHubPullRequestSearchNode `json:"node"`
}

type GitHubPullRequestSearchNode struct {
	Number    int                       `json:"number"`
	Closed    bool                      `json:"closed"`
	Url       string                    `json:"url"`
	Title     string                    `json:"title"`
	CreatedAt string                    `json:"createdAt"`
	UpdatedAt string                    `json:"updatedAt"`
	Comments  GitHubPullRequestComments `json:"comments"`
	Files     GitHubPullRequestFiles    `json:"files"`
	Author    GitHubPullRequestAuthor   `json:"author"`
	Labels    GitHubPullRequestLabels   `json:"labels"`
	Commits   GitHubPullRequestCommits  `json:"commits"`
}

type GitHubPullRequestCommits struct {
	Nodes []GitHubPullRequestCommitNode `json:"nodes"`
}

type GitHubPullRequestCommitNode struct {
	Commit GitHubPullRequestCommit `json:"commit"`
}

type GitHubPullRequestCommit struct {
	CommitUrl string                        `json:"commitUrl"`
	Oid       string                        `json:"oid"`
	Status    GitHubPullRequestCommitStatus `json:"status"`
}

type GitHubPullRequestCommitStatus struct {
	State    string                                 `json:"state"`
	Contexts []GitHubPullRequestCommitStatusContext `json:"contexts"`
}

type GitHubPullRequestCommitStatusContext struct {
	State       string `json:"state"`
	TargetUrl   string `json:"targetUrl"`
	Description string `json:"description"`
	Context     string `json:"context"`
}

type GitHubPullRequestLabels struct {
	Edges []GitHubPullRequestLabelEdge `json:"edges"`
}

type GitHubPullRequestLabelEdge struct {
	Node GitHubPullRequestLabelNode `json:"node"`
}

type GitHubPullRequestLabelNode struct {
	Name  string `json:"name"`
	Color string `json:"color"`
}

type GitHubPullRequestAuthor struct {
	Login string `json:"login"`
}

type GitHubPullRequestFiles struct {
	Edges []GitHubPullRequestFileEdge `json:"edges"`
}

type GitHubPullRequestFileEdge struct {
	Node GitHubPullRequestFileNode `json:"node"`
}

type GitHubPullRequestFileNode struct {
	Path      string `json:"path"`
	Additions int    `json:"additions"`
	Deletions int    `json:"deletions"`
}

type GitHubPullRequestComments struct {
	TotalCount int `json:"totalCount"`
}