1 # This file is part of NIT ( http://www.nitlanguage.org ).
3 # Copyright 2014-2015 Alexandre Terrasa <alexandre@moz-code.org>
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
9 # http://www.apache.org/licenses/LICENSE-2.0
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.
17 # Generate Github events from repo data.
19 # Mainly used for testing and history importation.
20 module events_generator
24 # Github events generator
26 # Generates events from repo data.
29 # API client used to get github data.
32 # Gen a fake id for events
33 fun gen_event_id
: String do return get_time
.to_s
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
)
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
)
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
)
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
)
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
)
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
)
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
)
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
)
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
)
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
)
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
)