-
Notifications
You must be signed in to change notification settings - Fork 12
/
Copy pathasync_github_pull_request.py
46 lines (34 loc) · 1.23 KB
/
async_github_pull_request.py
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
from finite_state_machine import StateMachine, transition
async def async_is_approved_or_is_admin(machine, user):
return machine.num_approvals >= 1 or user.is_admin
def sync_is_approved_or_is_admin(machine, user):
return machine.num_approvals >= 1 or user.is_admin
class GitHubPullRequest(StateMachine):
"""State Machine to represent a GitHub Pull Request workflow"""
def __init__(self):
self.state = "opened"
self.num_approvals = 0
self.changes_request = False
@transition(source="opened", target="opened")
async def approve(self):
self.num_approvals += 1
@transition(source="opened", target="opened")
async def request_changes(self):
self.changes_request = True
@transition(source="opened", target="closed")
async def close_pull_request(self):
pass
@transition(
source="opened",
target="merged",
conditions=[async_is_approved_or_is_admin],
)
async def fully_async_merge_pull_request(self, user):
pass
@transition(
source="opened",
target="merged",
conditions=[sync_is_approved_or_is_admin],
)
async def async_merge_pull_request_with_sync_condition(self, user):
pass