-
Notifications
You must be signed in to change notification settings - Fork 0
/
code.py
81 lines (62 loc) · 1.93 KB
/
code.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
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
"""
Author: Savana Rohit
Date: June 4, 2023
Description: This Python code retrieves GitHub pull request summaries within a date range.
"""
from datetime import datetime, timedelta
import os
from dotenv import load_dotenv
from github import Github
from tabulate import tabulate
# Environment variables loading
load_dotenv()
# GitHub API
github_api_key = os.getenv("GITHUB_API_KEY")
# GitHub connection instance
g = Github(github_api_key, timeout=20)
# GitHub Repo name
repo = g.get_repo("facebook/react")
# Time Period of a week
end_date = datetime.now()
start_date = end_date - timedelta(days=7)
# Last Week's Pull requests
pulls = repo.get_pulls(state="all", sort="created", base="main")
pulls_last_week = [pull for pull in pulls if start_date <= pull.created_at <= end_date]
# Pull requests summary format
pulls_data = []
for pull in pulls_last_week:
pulls_data.append([pull.number, pull.title, pull.state])
# Pull request summary table
table = tabulate(pulls_data, headers=["Number", "Title", "State"], tablefmt="grid")
# Count of pull requests by state
counts = {"open": 0, "closed": 0, "merged": 0}
for pull in pulls_last_week:
state = pull.state.lower()
if state in counts:
if state == "open":
counts["open"] += 1
elif state == "closed":
counts["closed"] += 1
elif state == "merged":
counts["merged"] += 1
# Summary table with counts
summary = tabulate(counts.items(), headers=["State", "Count"], tablefmt="grid")
# Email details
From = input("Enter your email address (From):")
To = input("Enter the recipient's email address (To):")
Subject = "GitHub Pull Request Summary"
# Email Summary body
body = f"""
Dear Manager,
Here is the summary of pull requests in the last week for the facebook/react repository:
Summary:
{summary}
Complete Table
{table}
Best regards,
Your Name
"""
print("From", From, "\n")
print("To", To, "\n")
print("Subject", Subject, "\n")
print(body, "\n")