-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathgh-hook-mr.py
More file actions
executable file
·87 lines (67 loc) · 1.84 KB
/
gh-hook-mr.py
File metadata and controls
executable file
·87 lines (67 loc) · 1.84 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
#!/usr/bin/env python3
# github pull request update script
#
# Script changes patch version.
# Note: version changed only on pull request update event.
import cgi
from dotenv import load_dotenv
import pickle
import sys
import time
import json
from io import StringIO
import sys, urllib
import re
from pathlib import Path
from github3 import login
import os
ghpath = Path.home() / '.env'
load_dotenv(dotenv_path=str(ghpath))
gh_token = os.getenv("GH_TOKEN")
if not gh_token:
print("GitHub token missing!")
sys.exit(1)
qin = sys.stdin.read()
print("Content-type: text/html\n")
print("""<!DOCTYPE HTML>
<html>
<head>
<meta charset="utf-8">
<title>some title</title>
</head>
<body>""")
io = StringIO(qin)
js = json.load(io)
gh = login(token=gh_token)
action = js['action']
if action == "synchronize" or action == "opened":
print("<h1>action is %s, process</h1>" % action)
else:
print("<h1>action is %s, do nothing</h1>" % action)
print("</body></html>")
sys.exit(0)
pr_num = js['pull_request']['number']
#pr = repo.pull_request(pr_num)
issue = gh.issue("OpenDataPlane", "odp", pr_num)
branch = js['pull_request']['base']['ref']
print("branch = %s\n" % branch)
title = issue.title
version = 0
for m in re.finditer(r'\[PATCH.*v([0-9]+)\]', title):
version = int(m.group(1))
version += 1
m = re.search(r"\[PATCH.*?\] (.*)", title)
if m:
title = m.group(1)
if branch == "api-next":
issue.edit(title="[PATCH API-NEXT v%d] %s" % (version, title))
elif branch == "devel/native-drivers":
issue.edit(title="[PATCH NATIVE-DRIVERS v%d] %s" % (version, title))
elif branch == "2.0":
issue.edit(title="[PATCH 2.0 v%d] %s" % (version, title))
else:
issue.edit(title="[PATCH v%d] %s" % (version, title))
print(issue.title)
print("body_text %s\n" % issue.body_text)
print("<h1>all ok!</h1>")
print("</body></html>")