-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathcommitLogger.py
33 lines (26 loc) · 931 Bytes
/
commitLogger.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
import mysql.connector
import os
import subprocess
COMMIT = os.getenv('GIT_COMMIT')
TIME = subprocess.check_output('git show -s --format=%ci', shell=True)
MESSAGE = subprocess.check_output('git log --format=%B -n 1', shell=True)
USER = subprocess.check_output('git log -1 | grep Author | cut -d " " -f2', shell=True)
mydb = mysql.connector.connect(
host="localhost",
user="root",
password="bidalgo",
database="mysql"
)
mycursor = mydb.cursor()
mycursor.execute("""CREATE TABLE IF NOT EXISTS commits (
row_id int NOT NULL AUTO_INCREMENT,
commit_id VARCHAR(255),
commit_time VARCHAR(255),
commit_message VARCHAR(255),
commit_user VARCHAR(255),
PRIMARY KEY(row_id))""")
sql = "INSERT INTO commits (commit_id, commit_time, commit_message, commit_user) VALUES (%s, %s, %s, %s)"
val = (COMMIT, TIME, MESSAGE, USER)
mycursor.execute(sql, val)
mydb.commit()
print(mycursor.rowcount, "record inserted.")