Merge: concurrent_collections: Add implementation of has method
[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 # Gen a fake id for events
33 fun gen_event_id: String do return get_time.to_s
34
35 # Issues
36
37 # Generate a new IssuesEvent from an issue.
38 fun issues_event(repo: Repo, action: String, issue: Issue): IssuesEvent do
39 return new IssuesEvent(gen_event_id, action, repo, issue)
40 end
41
42 # Generate a new IssuesEvent with an `opened` action.
43 fun issue_open(repo: Repo, issue: Issue): IssuesEvent do
44 return issues_event(repo, "opened", issue)
45 end
46
47 # Generate a new IssuesEvent with an `closed` action.
48 fun issue_close(repo: Repo, issue: Issue): IssuesEvent do
49 return issues_event(repo, "closed", issue)
50 end
51
52 # Generate a new IssuesEvent with an `reopened` action.
53 fun issue_reopen(repo: Repo, issue: Issue): IssuesEvent do
54 return issues_event(repo, "reopened", issue)
55 end
56
57 # Generate a new IssuesEvent from a IssueEvent.
58 fun issue_raw_event(repo: Repo, issue: Issue, event: IssueEvent): IssuesEvent do
59 return new IssuesEvent(event.id.to_s, event.event, repo, issue, event.labl, event.assignee)
60 end
61
62 # Generate a new IssueCommentEvent from a IssueComment.
63 fun issue_comment_event(repo: Repo, issue: Issue, comment: IssueComment): IssueCommentEvent do
64 return new IssueCommentEvent(gen_event_id, "created", repo, issue, comment)
65 end
66
67 # Pull requests
68
69 # Generate a new PullRequestEvent from a `pull` request.
70 fun pull_event(repo: Repo, action: String, pull: PullRequest): PullRequestEvent do
71 return new PullRequestEvent(gen_event_id, action, repo, pull.number, pull)
72 end
73
74 # Generate a new PullRequestEvent with an `opened` action.
75 fun pull_open(repo: Repo, pull: PullRequest): PullRequestEvent do
76 return pull_event(repo, "opened", pull)
77 end
78
79 # Generate a new PullRequestEvent with an `closed` action.
80 fun pull_close(repo: Repo, pull: PullRequest): PullRequestEvent do
81 return pull_event(repo, "closed", pull)
82 end
83
84 # Generate a new PullRequestEvent with an `reopened` action.
85 fun pull_reopen(repo: Repo, pull: PullRequest): PullRequestEvent do
86 return pull_event(repo, "reopened", pull)
87 end
88
89 # Generate a new PullRequestEvent from a IssueEvent.
90 fun pull_raw_event(repo: Repo, pull: PullRequest, event: IssueEvent): PullRequestEvent do
91 return new PullRequestEvent(event.id.to_s, event.event, repo, pull.number, pull)
92 end
93 end