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 # Various implementations of `GameReactor` can be found here.
22 # Reacts to event that can affect players (like giving nitcoins).
26 # Nitcoins rewarded when the player opens a new pull request.
29 # Nitcoins rewarded when the player reviews a pull request.
30 var nc_pull_review
= 2
32 # Nitcoins rewarded when the player has a commit merged.
33 var nc_commit_merged
= 1
35 redef fun react_event
(game
, e
) do e
.react_player_event
(self, game
)
38 redef class GithubEvent
39 # Reacts to a player related event.
41 # Called by `PlayerReactor::react_event`.
43 private fun react_player_event
(reactor
: PlayerReactor, game
: Game) do end
46 redef class PullRequestEvent
48 # Rewards player for opened pull requests.
49 redef fun react_player_event
(r
, game
) do
50 var player
= pull
.user
.player
(game
)
51 if action
== "opened" then
52 player
.nitcoins
+= r
.nc_pull_open
54 else if action
== "closed" and pull
.merged
then
55 player
.nitcoins
+= pull
.commits
* r
.nc_commit_merged
61 redef class IssueCommentEvent
63 # Rewards player for review comments.
65 # Actuallty we look if the comment contains the string `"+1"`.
67 # TODO only give nitcoins if reviewers < 2
68 redef fun react_player_event
(r
, game
) do
69 # FIXME use a more precise way to locate reviews
70 if comment
.body
.has
("\\+1\\b".to_re
) then
71 var player
= comment
.user
.player
(game
)
72 player
.nitcoins
+= r
.nc_pull_review