forked from phpmyadmin/scripts
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathphpmyadmin-reports
More file actions
executable file
·176 lines (147 loc) · 4.39 KB
/
phpmyadmin-reports
File metadata and controls
executable file
·176 lines (147 loc) · 4.39 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
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
#! /usr/bin/env python3
# -*- coding: utf-8 -*-
# Copyright © 2016 Michal Čihař <[email protected]>
#
# phpMyAdmin work reports generator
#
# Requirements:
#
# * Python 3
# * PyGithub
# * python-dateutil
import sys
from datetime import datetime, timedelta
from argparse import ArgumentParser
import dateutil.parser
try:
from github import Github
except ImportError:
print('PyGithub is required, please install it')
print(' * using pip: pip3 install PyGithub')
print(' * using apt: apt install python3-github')
sys.exit(1)
# Settings
# List of projects to report
PROJECTS = (
'phpmyadmin/phpmyadmin',
'phpmyadmin/phpmyadmin-security',
'phpmyadmin/docker',
'phpmyadmin/website',
'phpmyadmin/sql-parser',
'phpmyadmin/motranslator',
'phpmyadmin/private',
'phpmyadmin/shapefile',
'phpmyadmin/simple-math',
'phpmyadmin/localized_docs',
)
# Only include commits not present elsewhere from this repository
PROJECT_EXTRA_COMMITS = (
'phpmyadmin/phpmyadmin-security',
)
def get_parser():
"""Create command line argument parser."""
parser = ArgumentParser(
description='phpMyAdmin work reporting tool, generates list of commits and issues handled in given period',
)
parser.add_argument(
'-u', '--user',
required=True,
help='GitHub username, used for both reporting and authentication'
)
parser.add_argument(
'-t', '--token',
required=True,
help='GitHub authentication token'
)
parser.add_argument(
'-s', '--start-date',
type=dateutil.parser.parse,
default=datetime.now() - timedelta(days=7),
help='Starting datetime, defaults to 7 days ago'
)
parser.add_argument(
'-e', '--end-date',
type=dateutil.parser.parse,
default=datetime.now(),
help='Ending datetime, defaults to current timestamp'
)
parser.add_argument(
'-f', '--format',
choices=('markdown', ),
default='markdown',
help='Output format',
)
return parser
def get_repo_data(gh, user, name, start, end):
"""Get data for single repository"""
repo = gh.get_repo(name)
commits = []
issues = []
all_commits = repo.get_commits(author=user, since=start, until=end)
for commit in all_commits:
# skip merge commits
if len(commit.parents) == 1:
commits.append(commit)
all_issues = repo.get_issues(
assignee=user, state='closed', sort='updated', direction='desc'
)
for issue in all_issues:
if issue.updated_at < start:
break
if issue.closed_at > end:
continue
if issue.closed_at < start:
continue
issues.append(issue)
return issues, commits
def get_data(user, token, start, end):
"""Retrieves data from github"""
gh = Github(user, token)
issues = []
commits = []
commit_set = set()
for project in PROJECTS:
issues_new, commits_new = get_repo_data(gh, user, project, start, end)
# Include all issues
issues.extend(issues_new)
if project in PROJECT_EXTRA_COMMITS:
# Only include commits not seen so far from this repo
for commit in commits_new:
sha = commit.sha[:7]
if sha not in commit_set:
commits.append(commit)
commit_set.add(sha)
else:
# Include all commits
commits.extend(commits_new)
commit_set.update([commit.sha[:7] for commit in commits_new])
return issues, commits
def markdown_report(issues, commits):
"""Displays report in markdown"""
print()
print('Handled issues:')
print()
for issue in issues:
print('* [#{0} {1}]({2})'.format(
issue.number,
issue.title,
issue.html_url,
))
print()
print('Commits:')
print()
for commit in commits:
print('* [{0} - {2}]({1})'.format(
commit.sha[:7],
commit.html_url,
commit.commit.message.split('\n')[0]
))
def main(params):
"""Main program"""
parser = get_parser()
args = parser.parse_args(params)
issues, commits = get_data(args.user, args.token, args.start_date, args.end_date)
if args.format == 'markdown':
markdown_report(issues, commits)
if __name__ == '__main__':
main(sys.argv[1:])