cc8b6a4ff6528b5f352e716fe99ec005c12d6116
[nit.git] / contrib / nitrpg / src / events_generator.nit
1 # This file is part of NIT ( http://www.nitlanguage.org ).
2 #
3 # Copyright 2014-2015 Alexandre Terrasa <alexandre@moz-code.org>
4 #
5 # Licensed under the Apache License, Version 2.0 (the "License");
6 # you may not use this file except in compliance with the License.
7 # You may obtain a copy of the License at
8 #
9 # http://www.apache.org/licenses/LICENSE-2.0
10 #
11 # Unless required by applicable law or agreed to in writing, software
12 # distributed under the License is distributed on an "AS IS" BASIS,
13 # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14 # See the License for the specific language governing permissions and
15 # limitations under the License.
16
17 # Generate Github events from repo data.
18 #
19 # Mainly used for testing and history importation.
20 module events_generator
21
22 import github::events
23
24 # Github events generator
25 #
26 # Generates events from repo data.
27 class EventsGenerator
28
29 # API client used to get github data.
30 var api: GithubAPI
31
32 # Issues
33
34 # Generate a new IssuesEvent from an issue.
35 fun issues_event(action: String, issue: Issue): IssuesEvent do
36 var e = new IssuesEvent(api)
37 e.action = action
38 e.repo = issue.repo
39 e.issue = issue
40 return e
41 end
42
43 # Generate a new IssuesEvent with an `opened` action.
44 fun issue_open(issue: Issue): IssuesEvent do return issues_event("opened", issue)
45
46 # Generate a new IssuesEvent with an `closed` action.
47 fun issue_close(issue: Issue): IssuesEvent do return issues_event("closed", issue)
48
49 # Generate a new IssuesEvent with an `reopened` action.
50 fun issue_reopen(issue: Issue): IssuesEvent do return issues_event("reopened", issue)
51
52 # Generate a new IssuesEvent from a IssueEvent.
53 fun issue_raw_event(issue: Issue, event: IssueEvent): IssuesEvent do
54 var e = issues_event(event.event, issue)
55 e.lbl = event.labl
56 e.assignee = event.assignee
57 return e
58 end
59
60 # Pull requests
61
62 # Generate a new PullRequestEvent from a `pull` request.
63 fun pull_event(action: String, pull: PullRequest): PullRequestEvent do
64 var e = new PullRequestEvent(api)
65 e.action = action
66 e.repo = pull.repo
67 e.pull = pull
68 return e
69 end
70
71 # Generate a new PullRequestEvent with an `opened` action.
72 fun pull_open(pull: PullRequest): PullRequestEvent do return pull_event("opened", pull)
73
74 # Generate a new PullRequestEvent with an `closed` action.
75 fun pull_close(pull: PullRequest): PullRequestEvent do return pull_event("closed", pull)
76
77 # Generate a new PullRequestEvent with an `reopened` action.
78 fun pull_reopen(pull: PullRequest): PullRequestEvent do return pull_event("reopened", pull)
79
80 # Generate a new PullRequestEvent from a IssueEvent.
81 fun pull_raw_event(pull: PullRequest, event: IssueEvent): PullRequestEvent do
82 return pull_event(event.event, pull)
83 end
84
85 # Generate a new IssueCommentEvent from a IssueComment.
86 fun issue_comment_event(issue: Issue, comment: IssueComment): IssueCommentEvent do
87 var e = new IssueCommentEvent(api)
88 e.action = "created"
89 e.repo = issue.repo
90 e.issue = issue
91 e.comment = comment
92 return e
93 end
94 end