This repository was archived by the owner on Feb 22, 2023. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathpull_request_reporter.py
More file actions
70 lines (51 loc) · 2.16 KB
/
Copy pathpull_request_reporter.py
File metadata and controls
70 lines (51 loc) · 2.16 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
import argparse
# from email.policy import default
import os
from modules import github_request
from modules import send_email
from modules import dot_env
import datetime
parser = argparse.ArgumentParser(
description='Summarize pull requests and send summary email.')
parser = argparse.ArgumentParser()
parser.add_argument(
'-r', '--repository', help='Repository to retrieve pull requests from', action='store', type=str, required=False, default="hashicorp/terraform-provider-azurerm")
parser.add_argument(
'-e', '--email', help='Email to send pull request summary to', action='store', type=str, required=False)
parser.add_argument(
'-d', '--daysago', help='Number of days ago to get latest pull requests.', type=int, action='store', required=False, default=7)
parser.add_argument(
'-f', '--formatedEmail', help='Use CSS formated email', action='store_true', required=False)
args = parser.parse_args()
dot_env.load_env()
if not hasattr(args, 'email'):
print("Using Default Email in .env file")
args.email = os.environ.get('DEFAULT_EMAIL')
previous_date = datetime.datetime.now() - datetime.timedelta(days=args.daysago)
print("Connecting to Github API")
gh = github_request.init_github()
print(f"Retrieving Pull Requests Updated After {previous_date.date()}")
prs = github_request.get_pull_request(
gh, args.repository, previous_date)
if args.formatedEmail:
html_body = github_request.html_body_template(
args.repository, previous_date, prs['details'], prs['summary']
)
else:
html_body = github_request.html_body(
args.repository, previous_date, prs['details'], prs['summary'])
summary_output = f"""
--------------------------------
Retrieved Pull Requests Summary:
* Repo: {args.repository}
* Sent to Email: {args.email}
* Pull Requests Updated After: {previous_date.date()}
* Open PRs: {prs['summary']['open']}
* Closed PRs: {prs['summary']['closed']}
* Draft PRs: {prs['summary']['draft']}
--------------------------------
"""
print(summary_output)
print("Sending email.....")
send_email.send("crazyspammer@kazisolutions.com", args.email,
f"Github Pull Request Report for {args.repository}", html_body)