-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathbitbucket_tests.py
More file actions
61 lines (47 loc) · 1.89 KB
/
bitbucket_tests.py
File metadata and controls
61 lines (47 loc) · 1.89 KB
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
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
import arrow
from pybitbucket.bitbucket import Client
from pybitbucket.pullrequest import PullRequest
from pybitbucket.repository import Repository
from pybitbucket.auth import BasicAuthenticator
bitbucket = Client(
BasicAuthenticator(
'', # Username
'', # Password/API Key
'', # E-mail
)
)
def get_user_for_activity(activity):
for value in activity.values():
if 'user' in value:
return value['user']
elif 'author' in value:
return value['author']
repositories = [repo.slug for repo in Repository.find_repositories_by_owner_and_role(role='owner', client=bitbucket)]
for repo in repositories:
print("------- {repo} -------".format(repo=repo))
for pr in PullRequest.find_pullrequests_for_repository_by_state(repo, client=bitbucket):
print("...")
if type(pr) == dict:
continue
activity = list(pr.activity())
# Get approvals
approvals = filter(lambda a: 'approval' in a, activity)
print("Approvers:", [(a['approval']['user']['display_name'], a['approval']['user']['links']['avatar']) for a in approvals])
# Get last update
print("Updated on:", arrow.get(pr.updated_on).datetime)
print("Updated by:", get_user_for_activity(activity[0])['display_name'])
# Get author
print("Author:", pr.author.display_name)
#
print("Key:", "{repo}-{pr_id}".format(repo=repo.upper(), pr_id=pr.id))
# Get task count
print("Task count:", pr.task_count)
# Get last build
statuses = list(pr.statuses())
if 'pagelen' in statuses[0]:
statuses.pop()
statuses = sorted(statuses, key=lambda s: arrow.get(s['updated_on']).datetime, reverse=True)
print("Build count:", len(statuses))
if len(statuses):
print("Last build status:", statuses[0]['state'])
print("allgood")