diff --git a/gitgud/commit-msg b/gitgud/commit-msg index 31f3dcf..1371f79 100755 --- a/gitgud/commit-msg +++ b/gitgud/commit-msg @@ -19,7 +19,6 @@ def postMessage(message): def continue_commit_prompt(): - print "Your commit message is bad. Do you want to continue your commit? [Y/n]" valid = {"": True, "yes": True, "y": True, "no": False, "n": False} sys.stdin = open("/dev/tty", "r") choice = raw_input().lower() @@ -36,12 +35,22 @@ def main(): txt_file.close() # check thie return score - if postMessage(commit_message): + if postMessage(commit_message > 0.8): # commit if score is good - print "Your commit message is good." + print "Your commit message is quite good." sys.exit(0) + else if postMessage(commit_message >= 0.5): + # commit if score is good + print "Your commit message could be improved. Do you want to continue your commit? [Y/n]" + if continue_commit_prompt(): + sys.exit(0) + else: + # abort if user says no + print("Commit abort.") + sys.exit(1) else: # otherwise, ask user if they want to continue the commit + print "Your commit message is bad. Do you want to continue your commit? [Y/n]" if continue_commit_prompt(): sys.exit(0) else: diff --git a/server/model/git_good_model.py b/server/model/git_good_model.py index 6d91ff4..3a44e12 100644 --- a/server/model/git_good_model.py +++ b/server/model/git_good_model.py @@ -2,10 +2,10 @@ import numpy as np import http.client, urllib.request, urllib.parse, urllib.error, base64 from scipy.sparse import hstack -from sklearn.naive_bayes import MultinomialNB from sklearn.feature_extraction.text import CountVectorizer, TfidfVectorizer from sklearn.model_selection import train_test_split from sklearn.metrics import precision_recall_fscore_support as score +from sklearn.neural_network import MLPClassifier import random import nltk from nltk import word_tokenize, pos_tag @@ -18,7 +18,7 @@ class GitGudModel(): def __init__(self, dataframe=None): - self.model = MultinomialNB() + self.model = MLPClassifier(100, logistic) self.dataframe = dataframe pass @@ -35,7 +35,8 @@ def parse_and_split_data(self, df, *, star_thresh=200, fork_thresh=50, watchers_ y = df["label"] - X_train, X_test, y_train, y_test = train_test_split(mcl_transformed, y, test_size=0.1, random_state=random.randint(1, 100)) + X_train, X_test, y_train, y_test = train_test_split(mcl_transformed, y, + test_size=0.1, random_state=random.randint(1, 100)) return (X_train, X_test, y_train, y_test) @@ -220,7 +221,7 @@ def commit_body_has_present_tense(self, msg, weight): return self.expon((weight * present / total), 5) - def label_data(self, df, good_thresh=.5): + def label_data(self, df): label = [] negfunctions = [(self.commit_body_has_swear, 1)] @@ -239,7 +240,7 @@ def label_data(self, df, good_thresh=.5): score += funct(row['msg'], weight) for funct, weight in negfunctions: score *= funct(row['msg'], weight) - label.append(GOOD if score > good_thresh else BAD) + label.append(score) df['label'] = pd.Series(label) return df