-
Notifications
You must be signed in to change notification settings - Fork 5
Expand file tree
/
Copy pathpost_comment.py
More file actions
76 lines (62 loc) · 2.45 KB
/
post_comment.py
File metadata and controls
76 lines (62 loc) · 2.45 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
import os
import sys
import requests
def post_comment(repo_owner, repo_name, pr_number, github_token):
# Get PR author
pr_url = f"https://api.github.com/repos/{repo_owner}/{repo_name}/pulls/{pr_number}"
headers = {
"Authorization": f"token {github_token}",
"Accept": "application/vnd.github.v3+json"
}
pr_response = requests.get(pr_url, headers=headers)
pr_author = pr_response.json()["user"]["login"]
# Get PR stats
query = f"""
query($owner:String!, $repo:String!) {{
repository(owner:$owner, name:$repo) {{
pullRequests(first:100, orderBy:{{field:CREATED_AT, direction:DESC}}) {{
totalCount
nodes {{
author {{
login
}}
additions
deletions
}}
}}
}}
}}
"""
variables = {
"owner": repo_owner,
"repo": repo_name,
"author": pr_author
}
graphql_url = "https://api.github.com/graphql"
response = requests.post(graphql_url, json={"query": query, "variables": variables}, headers=headers)
# print(response.json())
data = response.json()["data"]["repository"]["pullRequests"]
total_prs = data["totalCount"]
recent_prs = data["nodes"][:10]
total_additions = sum(pr["additions"] for pr in recent_prs)
total_deletions = sum(pr["deletions"] for pr in recent_prs)
comment1 = f""
# Prepare comment
# comment = f"""
# 📊 **Contributor Stats for @{pr_author}:**
# - **Total PRs Merged:** {total_prs}
# - **Recent Contributions (last 10 PRs):**
# - Lines Added: {total_additions}
# - Lines Deleted: {total_deletions}
# Keep up the great work! 🚀
# 
# """
# Post comment
comment_url = f"https://api.github.com/repos/{repo_owner}/{repo_name}/issues/{pr_number}/comments"
requests.post(comment_url, json={"body": comment1}, headers=headers)
if __name__ == "__main__":
repo_owner = sys.argv[1]
repo_name = sys.argv[2]
pr_number = sys.argv[3]
github_token = sys.argv[4]
post_comment(repo_owner, repo_name, pr_number, github_token)